akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const int Inf = 1e9;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  string a, b;
  cin >> a >> b;
  int n = a.size();
  vector <int> goL(n, Inf), goR(n, Inf);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (b[(i + j) % n] == '1') {
        goR[i] = j;
        break;
      }
    }
    for (int j = 0; j < n; ++j) {
      if (b[(i - j + n) % n] == '1') {
        goL[i] = j;
        break;
      }
    }
  }
  int ans = Inf; 
  for (int shift = 0; shift < n; ++shift) {
    string c = a;
    rotate(c.begin(), c.begin() + shift, c.end());
    vector <pair <int, int>> need_go;
    int need = 0;
    for (int i = 0; i < n; ++i) {
      if (c[i] != b[i]) {
        ++need;
        int pos = (i + shift + n) % n;
        need_go.push_back({goL[pos], goR[pos]}); 
      }
    }
    sort(need_go.begin(), need_go.end(), [&] (pair <int, int> f, pair <int, int> s) {
      if (f.first != s.first) return f.first > s.first;
      else return f.second > s.second;
    });
    vector <pair <int, int>> nw;
    int mx = -1;
    for (auto p : need_go) {
      if (p.second > mx) {
        nw.push_back(p);
        mx = p.second;
      }
    }
    int can_r = n - shift;
    int can_l = shift;
    for (int i = 0; i <= (int)nw.size(); ++i) {
      int mx_l = 0, mx_r = 0;
      if (i > 0) {
        mx_r = nw[i - 1].second;
      }
      if (i < (int)nw.size()) {
        mx_l = nw[i].first;
      }
      ans = min(ans, need + 2 * mx_l + mx_r + abs(can_r - mx_r));
      ans = min(ans, need + 2 * mx_r + mx_l + abs(can_l - mx_l));
    }
    /*for (int mx_l = 0; mx_l < n; ++mx_l) {
      for (int mx_r = 0; mx_r < n; ++mx_r) {
        bool bad = false;
        for (auto p : need_go) {
          if (p.first > mx_l && p.second > mx_r) {
            bad = true;
          }
        } 
        if (!bad) {
          int can_r = n - shift;
          int can_l = shift;
          ans = min(ans, need + 2 * mx_l + mx_r + abs(can_r - mx_r));
          ans = min(ans, need + 2 * mx_r + mx_l + abs(can_l - mx_l));
        }
      }
    }*/
  } 
  if (ans == Inf) cout << "-1\n";
  else cout << ans << '\n';
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main() {
	int N;
	int ans = 1;
	int max = 0;

	cin >> N;
	
	vector<int> H(N);

	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	
	for (int k = 1; k < N; k++) {
		for (int i = 0; i < k; i++) {
			if (max < H[i]) {
			max = H[i];
		}

    	}		
		if (max <= H[k])ans++;
		max = 0;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
int N,A,B;
ll v[60];
ii dp[60];

//bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

bool comp(ii a,ii b) {
  return a.first * b.second == b.first * a.second;
}

bool LT(ii a, ii b) {
  return a.first * b.second < b.first * a.second;
}

ii calc_max() {
  sort(v,v+N,greater<ll>());
  ii maxi = ii(-1,-1);
  REP(i,A,B+1) {
    ll sum = 0;
    rep(j,i) sum += v[j];
    if( maxi == ii(-1,-1) ) {
      maxi = ii(sum,i);
      continue;
    }
    if( LT(maxi,ii(sum,i)) ) {
      maxi = ii(sum,i);
      //cout << sum << " / " << i << " = ";
      //printf("%.10f\n",maxi);
    }
  }
  return maxi;
}

int main() {
  if( 0 ) {
    cout << 50 << " " << 25 << " " << 50 << endl;
    rep(i,50) {
      if( i == 0 ) {
	cout << 2 << endl;
      } else {
	cout << 1 << endl;
      }
    }
    return 0;
  }
  cin >> N >> A >> B;
  rep(i,N) cin >> v[i];
  /*
  vector<ll> vec;
  rep(i,N) vec.push_back(v[i]);
  sort(vec.begin(),vec.end());
  vec.erase(unique(vec.begin(),vec.end()),vec.end());
  rep(i,N) v[i] = lower_bound(vec.begin(),vec.end(),v[i]) - vec.begin();
  */
  ii maxi = calc_max();
  printf("%.10f\n",maxi.first/(double)maxi.second);
  ll cnt = 0;
  rep(j,N+1) dp[j] = ii(0,0);
  dp[0] = ii(0,1);

  rep(j,N) {
    for(int k=N;k>=0;--k) {
      if( dp[k+1].first < dp[k].first + v[j] ) {
	dp[k+1].first = dp[k].first + v[j];
	dp[k+1].second = dp[k].second;
      } else if( dp[k+1].first == dp[k].first + v[j] ) {
	dp[k+1].second += dp[k].second;
      }
    }
  }
  REP(j,A,B+1) {
    //puts("");
    //cout << dp[j].first << " / " << j << endl;
    //printf("%.10f\n",dp[j].first/(double)j);
    //cout << dp[j].second << endl;
    if( comp(maxi,ii(dp[j].first,j)) ) {
      //cout << "IN" << endl;
      cnt += dp[j].second;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;

const int N = 2e5 + 3;
const int M = 1e6 + 6;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 3;
const int SM = 1e3 + 7;
const double EPS = 3e-16;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	string s; long long k;
	cin >> s >> k;
	
	long long n = int(s.size());
	
	if(n == 1) return cout << k / 2, 0;
	else if(n == 2) return cout << (s[0] == s[1]) * k, 0;
	
	long long a = 0, b = 0, counter = 0;
	while(a < n && s[a] == s[n - 1]) a++;
	while(b < n && s[0] == s[n - b - 1]) b++;
	
	if(a == n) return cout << n * k / 2, 0;
	
	for(long long i = 0; i < n - 1; i++){
		if(s[i] == s[i + 1]){
			counter++, i++;
		}
	}
	
	cout << (counter * k) - ((a / 2) + (b / 2) - ((a + b) / 2)) * (k - 1);
	return 0;
}


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

int main(){
  string S;
  cin >> S;
  int num = stoi(S);
  int l,r;
  l = num/100;
  r = num%100;

  bool bl = true;
  bool br = true;
  if(l < 1 || l > 12){
    bl = false;
  }
  if(r < 1 || r > 12){
    br = false;
  }
  if(bl && br){
    cout << "AMBIGUOUS" << endl;
  }else if(bl){
    cout << "MMYY" << endl;
  }else if(br){
    cout << "YYMM" << endl;
  }else{
    cout << "NA" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
A_list = list(map(int, input().split()))

def gcd(x,y):
    if x > y:
        x, y = y, x
    if x == 0:
        return y
    return gcd(y%x, x)

gcd_num = 0
for i in range(len(A_list)):
    gcd_num = gcd(gcd_num, A_list[i])
print(gcd_num)

Measured memory_bytes: 15020
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int n, m;

int arr[100010];
vector<pair<int, int>> vp;
bool comp(const pair<int, int>&a, const pair<int, int>&b) {
    if(a.first == b.first){
        return a.second < b.second;
    }
    return a.first < b.first;
}
int main() {
    //cout << fixed << setprecision(15);
    cin >> n >> m;
    REP(i, n) cin >> arr[i];
    sort(arr, arr+n);


    REP(j, m){
        int B, C; cin >> B >> C;
        vp.push_back({C, B});
    }
    sort(all(vp), comp);
    reverse(all(vp));

    int idx = 0; bool c = false;
    for(int i=0; i<m; ++i){
        for(int j=0; j<vp[i].second; ++j){
            if(idx<n && arr[idx] < vp[i].first){
                arr[idx] = vp[i].first;
                idx++;
            }else{
                c = true;
            }
        }
        if(c) break;
    }

    LL sum = 0;
    REP(i, n) sum += arr[i];
    cout << sum << endl;

    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){
    ll X; cin >> X;
    if(X == 3 || X == 5 || X == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

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;

int main(){
  ll a,v,b,w,t;
  cin >>a >>v >>b >>w >>t;
  ll dis = abs(a-b);
  ll dis2 = (v-w)*t;
  if(dis<=dis2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int main(void){
	long long a[100001];
	for (int i = 0; i < 100001; i++){
		a[i] = 0;
	}
	long long c;
	long long k;
	long long s;
	long long p, q;
	long long n, m;
	long long x, y, z;
	c = 0;
	s = 0;
	q = 0;
	scanf("%lld", &n);
	for (int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
		s = s + a[i];
	}
	a[n] = a[0];
	s = s * 2;
	if (s%n != 0)q = 1;
	s = s / n;
	if (s % (n + 1) != 0)q = 1;
	s = s / (n + 1);
	k = s;
	for (int i = 0; i < n; i++){
			x = a[i] - a[i + 1]+k;
if(x<0)q=1;
			y = x / n;
			z = x% n;
			c = c + y;
			if (z != 0)q = 1;
			}

	if (s != c)q = 1;
	if (q == 1)	printf("NO\n");
	else	printf("YES\n");

	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <utility>
#include <memory>
#include <valarray>

using namespace std;

using ll = long long int;
#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanInt(L);
    scanInt(T);
    vector<int> X(N);
    vector<char> W(N);
    loop(i, N){
        scanInt(Xi);
        scanInt(Wi);
        X[i] = Xi;
        W[i] = Wi;
    }
    vector<int> result(N);
    loop(i, N){
        if (W[i] == 1){
            result[i] = X[i] + T;
        }else{
            result[i] = X[i] - T;
        }
        // printf("%d ", result[i]);
        while (result[i] < 0) result[i] += L;
        result[i] %= L;
        // printf("%d\n", result[i]);
    }
    sort(result.begin(), result.end());
    int times = 0;
    loop(i, N){
        if (W[i] == 1){
            const int temp = L - X[i];
            if (temp <= T){
                times += ((T - temp) / L + 1);
            }
        }else{
            const int temp = X[i];
            if (temp < T){
                if ((T - temp) % L){
                    times -= ((T - temp) / L + 1);
                }else{
                    times -= ((T - temp) / L);
                }
            }
        }
    }
    if (times < 0) times += N * (-times / N + 1);
    times %= N;
    loop(i, N){
        printf("%d\n", result[(i + times) % N]);
    }
}


Measured memory_bytes: 2048
K, N = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
B = A.copy()
for i in range(len(A)-1):
    B.append(A[i]+K)

min_ = float('inf')
for i in range(len(A)):
    if B[i+N-1]-B[i] < min_:
        min_ = B[i+N-1]-B[i]

print(min_)


Measured memory_bytes: 32308
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;

int main(){
  ll N,K;
  ll A[2000];
  ll shokou[2000] = {}, kouhi[2000] = {};
  cin >> N >> K;
  for(int i=0;i<N;i++) cin >> A[i];
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(A[i] > A[j]) kouhi[i]++;
      if(i > j) continue;
      if(A[i] > A[j]) shokou[i]++;
    }
  }
  ll sum = 0; 
  for(int i=0;i<N;i++){
    sum += shokou[i]*K + kouhi[i]*((K*(K-1)/2)%MOD); 
  }
  cout << sum%MOD;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, i, j;
	int flag = 0;

	scanf("%d", &a);

	for (i = 1; i < 10; i++)
	{
		for (j = 1; j < 10; j++)
		{
			if (i*j == a)
			{
				flag = 1;
				break;
			}
		}
	}

	if (flag)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MAX 7368791
using namespace std;

int main()
{
	int m, n;
	while (cin >> m >> n, m || n) {
		vector<bool> thieve(MAX + 1, false);
		for (int i = m; ;i++) {
			if (thieve[i]) {
				continue;
			}
			if (n) {
				n--;
				for (int j = i; j <= MAX; j += i) {
					thieve[j] = true;
				}
			}
			else {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3952
#include<iostream>
#include<string>
#include<unordered_set>
using namespace std;
int main(){
  string s;
  cin>>s;
  s = s+'T'; 
  int x[2];
  cin>>x[0]>>x[1];
  unordered_set<int> can[2]; // candidates
  can[0].insert(0);
  can[1].insert(0);
  int dir = 0;
  for(int i=0;i<s.size();){
     int c=0;
     while(s[i+c]=='F') c++;
     unordered_set<int> tmp;
     for(auto cc:can[dir]){
        tmp.insert(cc+c);
        if(i>0) tmp.insert(cc-c);
     }
     can[dir] = tmp;
     i+=c+1;
     cerr<<c<<i<<dir<<endl;
     dir ^= 1;
  }
  if(can[0].find(x[0])!=can[0].end() && can[1].find(x[1])!=can[1].end() )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


    

Measured memory_bytes: 896
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
 
char s[10000], t[10000];
int main(){
    int ans = 1000000;
    scanf("%s%s", s, t);
    int n = strlen(s), m = strlen(t);
    for (int i = 0; i <= n-m; i++) {
        int now = 0;
        for (int j = 0; j < m; j++) 
            if (s[i+j] != t[j]) now++;
        if (now < ans) ans = now;
    }
    printf("%d", ans);
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    int N;
    cin >> N;
    vi p(N);
    int dif = 0;
    REP(i,N)cin >> p[i];
    for (int i = 0; i < N; i++){
        if(p[i]!=(i+1)) dif++;
    }

    if(dif==2||dif==0)cout << "YES" << endl;
    else cout << "NO" << endl;
    
}



Measured memory_bytes: 256
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
const char bn = '\n';
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int64 N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    bool ans = false;
    REP(k,N+1){
        int64 low = A + (-k*D + (N-1-k)*C);
        int64 high = A + (-k*C + (N-1-k)*D);
        if(low<=B and B<=high) ans = true;
    }

    if(ans)cout << "YES" << bn;
    else cout << "NO" << bn;
}

Measured memory_bytes: 256
import java.io.*;
import java.io.ObjectInputStream.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	//final static long MOD = 998244353;

	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		slove(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void slove(String[] args) throws Exception{

		int N = nextInt();
		long[] a = nextLongs();
		long[] b = nextLongs();

		long sumA = 0;
		long sumB = 0;
		long op=0;


		for(int i=0;i<N;i++) {
			sumA+=a[i];
			sumB+=b[i];
			if(a[i]<b[i]){
				op+=(b[i]-a[i]-1+2)/2;
			}
		}
		long d = sumB-sumA;
		if(d>=op) {
			pw.println("Yes");
		}else {
			pw.println("No");
		}
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}



Measured memory_bytes: 27604
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = 0;
    rep(i, 0, n){
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
multiset<int> se;
int n,x;
int main()
{
	scanf("%d",&n);
	se.clear();
	for(int i=1;i<=n;i++)
		scanf("%d",&x),se.insert(x);
	scanf("%d",&n);
	bool flag=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(se.count(x))
			se.erase(se.find(x));
		else
			flag=1;
	}
	puts(flag?"NO":"YES");
	return 0;
}

Measured memory_bytes: 9600
def main():
    n = int(input())

    def q(i):
        print(i, )
        s = str(input())
        if s == 'Vacant':
            exit()
        else:
            return s

    x = q(n-1)
    x = q(0)

    def ok(m):
        if m == 0:
            return False
        else:
            if (m%2 == 0 and q(m) != x) or (m%2 == 1 and q(m) == x):
                return True
            else:
                return False

    l = 0
    r = n-1
    while l+1 < r:
        c = (l+r)//2
        if ok(c):
            r = c
        else:
            l = c

if __name__ == '__main__':
    main()

Measured memory_bytes: 38852
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
vector<vector<bool> > graph;

const long long INF = 1LL << 61;


int main(){
    int H, W, K;
    cin >> H >> W >> K;

    graph.assign(H, vector<bool>());


    for(int h=0; h<H; ++h){
        string s;
        cin >> s;
        for(int w=0; w<W; ++w){
            int flag = s[w] - '0';
            graph[h].push_back(flag);
        }
    }

    //答え
    long long ans = INF;

    //横の切り方はbit全探索2^H通り
    for(int bit=0; bit< (1 << (H-1)); ++bit){
        int group = 0;
        vector<int> id(H);
        //どのグループに属するかを決める
        for(int h=0; h<H; ++h){
            id[h] = group;
            if(bit >> h & 1){
                group++;
            }
        }
        group++;

        //各グループに今何個入っているか
        vector<vector<int>> group_nums(group, vector<int>(W));
        for(int h=0; h<H; ++h){
            for(int w=0; w<W; ++w){
                int group = id[h];
                if(graph[h][w] == true){
                    group_nums[group][w]++;
                }
            }
        }


        //縦に何回切るかを貪欲に計算
        bool skip = false;
        vector<vector<int>> group_cumsum(group, vector<int>(W));
        //縦の累積を初期化
        for(int i=0; i<group; ++i){
            group_cumsum[i][0] = group_nums[i][0];
        }

        for(int i=0; i<group; ++i){
            for(int w=0; w<W; ++w){
                if(group_nums[i][w] > K){
                    skip = true;
                }
            }
        }


        if(!skip){
            long long tate = 0;
            int w=1;
            //一個ずつ切るか見ていく
            while(w < W){
                bool is_cut = false;
                for(int i=0; i<group; ++i){
                    long long next_num = group_cumsum[i][w-1] + group_nums[i][w];
                    if(next_num > K){
                        is_cut = true;
                    }
                }

                if(is_cut == true){
                    //カットする
                    tate++;
                    //そうすると次の累積和はgraph[g][w]に初期化される.
                    for(int i=0; i<group; ++i){
                        group_cumsum[i][w] = group_nums[i][w];
                        
                    }                    
                }else{
                    //カットしない場合は累積和を増やす
                    for(int i=0; i<group; ++i){
                        group_cumsum[i][w] = group_cumsum[i][w-1] + group_nums[i][w];
                        
                    }
                }
                w++;
            }

            long long cut_num = tate + (group-1);
            ans = min(ans, cut_num);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3672
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():

    N =int(input())
    H =list(map(int,input().split()))
    count =1
    hiest =H[0]
    for i in range(1,N):
        if hiest <=H[i]:
            count +=1
            hiest =H[i]

    print(count)

if __name__ == "__main__":
    main()


Measured memory_bytes: 61688
n=int(input())
a=list(map(lambda x:int(x)%4,input().split()))
b0=a.count(0)
b1=a.count(1)+a.count(3)
b2=a.count(2)
if b2 > 0:
    print('Yes' if b0 >= b1  else 'No')
else:
    print('Yes' if b0 >=b1-1 else 'No')


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

using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define GCD(a,b) __gcd(a,b)
#define IO() assert(freopen("in.in", "rt", stdin)), assert(freopen("out.out", "wt", stdout))
#define FastIO() ios::sync_with_stdio(false),cin.tie(0);
#define clr(arr,val) memset(arr,val,sizeof(arr))
#define INF 0x9f9f9f9f9f9f9f9f
#ifdef _LOCAL_DEFINE
template<typename...T>
void debug(T&... args) 
{
  ((cerr<<args<<" "),...);
  cerr<<endl;
}
#endif

typedef long long LL;
typedef pair<int,int> pi;
const LL MOD = 1e9 + 7;
const int N = 1e6 + 9, M = 1e7, OO = 0x7f7f7f7f;

const double EPS = 1e-10,PI=acos(-1.0);

//Number Theory
inline bool dCMP(const long double &a, const long double &b) { return fabsl(a - b) < EPS;}

//Geometry 
inline double MintoDeg(double min){return min/60;}
inline double to_Radian(double deg){return deg*PI/180.0;}
inline double to_Degree(double radian){if(radian<0) radian+=2*PI; return radian*180/PI ;}
inline double fixAngle(double A){return A>1 ? 1 : (A<-1 ? -1 : A);}
struct point { 
  double x, y;
  point() { x = y = 0.0; }
  point(double _x, double _y) : x(_x), y(_y) {}
  bool operator < (point other) const { // override less than operator
  if (fabs(x - other.x) > EPS) return x < other.x;
  
  return y < other.y; 
  }
  bool operator == (point other) const {
  return (fabs(x - other.x) < EPS && (fabs(y - other.y) < EPS)); 
  }   
};
LL power(LL x, LL p, LL m){
  LL res = 1;
  while(p){
    if(p&1)	res = (res%m * x%m)%m;
    x = (x%m * x%m)%m;
    p >>= 1;
  }
  return res;
}
int freq[N];
int main()
{
  int n,sz=0;
  scanf("%d",&n);
  for(int i=0;i<n;++i)
  {
    int x;
    scanf("%d",&x);
    freq[x]++;
    if(freq[x]==1) sz++;
  }
  if(sz&1) printf("%d\n",sz);
  else printf("%d",sz-1);

  #ifdef _LOCAL_DEFINE
    cerr << clock()*1.0/CLOCKS_PER_SEC<<endl;
  #endif
    
  return 0;
}

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

#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

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

    if(u == s)a--;
    else if(u == t)b--;

    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>

using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
typedef unsigned long long LL;
typedef long long ll;
typedef pair<int,int> PII;
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};

int m, d;

int main()
{  
    cin >> m >> d;
    int ans = 0;
    int l1 = d / 10;
    int l2 = d % 10;
    for(int i = 2; i <= l1; i ++)
    {
        for(int j = 2; j <= 9; j ++)
        {
            if(i * j <= m && (10 * i + j) <= d)
            {
                 ans ++;
            }
        }
    }
    cout << ans << endl;
     return 0;
}

Measured memory_bytes: 256
/*
h3110_fr13nd,
 
AUTHOR : @sam_jn
*/
 
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<pair<int, int>, null_type, less_equal<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define in(a, n) for(int i = 0; i < n; i++) cin >> a[i];
#define ot1(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define ot2(a, n) for(int i = 0; i < n; i++) cout << a[i] << "\n";
ll pwr(ll a, ll b);
ll pwr(ll a, ll b, ll m);
int baap[200002];
int find(int i);  
bool Union(int x, int y);
ll inv(ll x) {return pwr(x, MOD - 2, MOD);}

//----------------------------------SOLUTION-BELOW-------------------------------------------// 
void solve(){       

    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes";
    else cout << "No";    
}
int main(){
                                                            // #ifndef ONLINE_JUDGE    
                                                            // freopen("../input", "r", stdin);
                                                            // freopen("../output", "w", stdout);
                                                            // #else
                                                            // // online submission
                                                            // #endif
    boost
    int _ = 1;
    // cout << 0 << endl;
    // cin >> _;
    while(_--){
        solve();
        cout << endl;
    }
}
 
 
//--------------------------------------DEFININTIONS---------------------------------------
ll pwr(ll a, ll b){
    if(b == 0)
        return 1 ;
    ll c = pwr(a, b/2) ;
    c = c * c;
    if(b % 2)
        return c*a;
    return c ;
}
ll pwr(ll a, ll b, ll m){
    if(b == 0)
        return 1;
    ll c = pwr(a, b/2, m) % m ;
    c = (c * c) % m;    
    if(b % 2)
        return (c * a%m) % m;
    return c ;
}
int find(int i)  
{  
    if (baap[i] != i)  
        baap[i] = find(baap[i]);  
  
    return baap[i];  
}
 
bool Union(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x == y) return false;
    baap[x] = y;
    return true;
}

Measured memory_bytes: 256
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  cout << max(a - 1, 0) + ((b >= a) ? 1 : 0) << endl;
  return 0;
}


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

vector<int> par;
vector<int> RA;

void Re(int a){
  par.resize(a);
  RA.resize(a);
  for(int i=0;i<a;i++){
    par[i]=i;
  }
}
int root(int a){
  if(a==par[a]){
    return a;
  }
  else{
    return par[a]=root(par[a]);
  }
}
void UN(int a,int b){
  a=root(a);
  b=root(b);
  if(a==b){
    return;
  }
  else if(RA[a]<RA[b]){
    par[a]=b;
  }
  else{
    par[b]=a;
  }
  if(RA[a]==RA[b]){
    RA[a]++;
  }
}
bool same(int a,int b){
  if(root(a)==root(b)){
    return true;
  }
  else{
    return false;
  }
}


int main() {
  int N,M;
  cin>>N>>M;
  Re(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    UN(a,b);
  }
  vector<int> p(N);
  for(int i=0;i<N ;i++){
    p[root(i)]++;
  }
  int Z=0;
  for(int i=0;i<N;i++){
    Z=max(Z,p[i]);
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 5632
<?php
error_reporting(0);
//$A = explode(" ",trim(fgets(STDIN)));
//list($A,$B) = explode(" ",trim(fgets(STDIN)));
$s = trim(fgets(STDIN));
$t = trim(fgets(STDIN));
$S = str_split($s);
$T = str_split($t);
asort($S);
arsort($T);
$ss = implode($S,"");
$tt = implode($T,"");

if (strcmp($ss,$tt)<0) {
  printf("Yes\n");
}
else {
  printf("No\n");
}


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

int main(void)
{
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++)
    {
        int val;
        cin >> val;
        p[i] = val - 1;
    }

    int cnt = 0;
    int loc = 0;
    for (int i = 0; i < N; i++)
    {
        if (p[i] == i)
        {
            if (loc == 0)
            {
                cnt++;
                loc = 1;
            }
            else
            {
                loc = 0;
            }
        }
        else
        {
            loc = 0;
        }
    }

    cout << cnt << endl;

    return 0;
}


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

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

int main()
{
    ll n, x; cin >> n >> x;
    cout << 3 * (n - gcd(n, x)) << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true) {
			int num1 = sc.nextInt();
			String ope = sc.next();
			int num2 = sc.nextInt();

			if(ope.equals("?")) break;

			int ans = 0;
			switch(ope) {
				case "+":
					ans = num1 + num2;
					break;
				case "-":
					ans = num1 - num2;
					break;
				case "/":
					ans = num1 / num2;
					break;
				case "*":
					ans = num1 * num2;
					break;
			}
			System.out.println(ans);
		}

		sc.close();

	}

}


Measured memory_bytes: 26164
package main

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

var sc = bufio.NewScanner(os.Stdin)

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


func main() {
	sc.Split(bufio.ScanWords)
    a := nextInt()
    b := nextInt()
  	c := nextInt()
  	d := nextInt()
  
  start := 0
  if (a > c) {
    start = a
  } else {
    start = c
  }
  
  end := 0
  if (b > d) {
    end = d
  } else {
    end = b
  }
  if end - start > 0 {
  	fmt.Println(end - start)
  } else {
  	fmt.Println(0)
  }
}


Measured memory_bytes: 640
# include <iostream>
using namespace std;
typedef long long ll;

ll min(ll a, ll b, ll c){
  return min(a, min(b,c));
}

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans;
  if(a%2 == b%2) ans = (b-a)/2;
  else{
    ans = min(a-1, n-b) + 1 + (b-a-1)/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
n,k = map(int,input().split())
coin = [0]*n
while k > 1:
    for i in range(min(int(k-1/1e10),n)):
        coin[i] += 1
    k /= 2
ans = 0
for i in range(n):
    ans += 1 / (2**coin[i] * n)
print(ans)


Measured memory_bytes: 3828
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#define int long long
typedef long long ll;
using namespace std;

ll N, Q, A[20], M[200], count=0;
vector<string> ANS;

void dfs(int id, int sum){
    if(id==N){
        for(int i=0;i<Q;i++) if(sum == M[i]) ANS[i] = "yes";
        return;
    }
    dfs(id+1, sum);
    dfs(id+1, sum+A[id]);
}

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    cin >> Q;
    for(int i=0;i<Q;i++) {
        cin >> M[i];
        ANS.push_back("no");
    }
    dfs(0, 0);
    for(int i=0;i<Q;i++) cout << ANS[i] << endl;
    return 0;
}


Measured memory_bytes: 3232
//author: Harsh :)
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define maxN 100007
using namespace std;
int main(){
  fastio;
  string a;
  cin>>a;
  ll n=a.length();
  string b;
  cin>>b;
  if(b.substr(0,n)==a) cout<<"Yes";
  else cout<<"No";

  return 0;
}


Measured memory_bytes: 3576
from operator import mul
from functools import reduce

def nCr(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

n, a, b = (int(x) for x in input().split())
V = list(int(x) for x in input().split())
V.sort(reverse=True)

avg = sum(V[:a]) / a
k = V[:a].count(V[a - 1])
m = V.count(V[a - 1])
if k == a:
    ans = sum(nCr(m, i) for i in range(k, min(m, b) + 1))
else:
    ans = nCr(m, k)
print(avg)
print(ans)


Measured memory_bytes: 67624
N,M,X=map(int,input().split())
C=[list(map(int,input().split())) for i in range(N)]
INF=float("inf")
ans=INF

for i in range(1,2**N):
    skills=[0]*M
    total_cost=0
    for j in range(N):
        if ((i>>j)&1):
            total_cost+=C[j][0]
            for k in range(M):
                skills[k]+=C[j][k+1]
    if min(skills)>=X:
        ans=min(ans,total_cost)
        
print(ans if ans != INF else -1)

Measured memory_bytes: 9148
N=int(input())
H=list(map(int,input().split()))
now=0
max=0
count=0
while now<N-1:
  if H[now]>=H[now+1]:
    count+=1
    now+=1
  else:
    now+=1
    if count>max:
      max=count
    count=0
if count>max:
    max=count
print(max)


Measured memory_bytes: 14224
import math


def combinations_count(n, r):
    if n >= r:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0


N, K = map(int, input().split())
mod = int(1e+9 + 7)
for i in range(1, K+1):
    print(int(combinations_count(N-K+1, i) * combinations_count(K-1, i-1) % mod))


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

constexpr int inf = 1e9 + 7;
constexpr ll inf_ll = 1e18L + 7;

template <typename T>
void mini(T& a, T b) {
  a = min(a, b);
}

template <typename T>
void maxi(T& a, T b) {
  a = max(a, b);
}

void add_it(int& a, int b) {
  a += b;
  if (a >= inf) a -= inf;
}

void sub_it(int& a, int b) {
  a -= b;
  if (a < 0) a += inf;
}

int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> A(n);
  for (int& a : A) scanf("%d", &a);

  auto cost = [&](int i, int j) -> ll {
    ll c = 0;
    for (int x = i; x <= j; ++x) c += A[x];
    return c;
  };

  constexpr ll INF = 1e18L + 7;
  vector<vector<ll>> dp(n, vector<ll>(n, 0));
  for (int L = 2; L <= n; ++L) {
    for (int i = 0; i + L <= n; ++i) {
      int j = i + L - 1;
      ll sum = cost(i, j);
      dp[i][j] = INF;
      for (int k = i; k < j; ++k)
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum);
    }
  }
  cout << dp[0][n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int b[100];
int id,w,W,Q;
string s;

int main(){
	while(cin>>W>>Q){
		if(!W)return 0;
		fill(b,b+W,-1);
		while(Q--){
			cin>>s;
			if(s=="s"){
				cin>>id>>w;
				int l=0,pos=-1;
				for(int i=0;i<W;i++){
					if(b[i]==-1)l++;
					else l=0;
					if(l==w){pos=i-w+1;break;}
				}
				if(pos>=0){
					cout<<pos<<endl;
					for(int i=pos;i<pos+w;i++)b[i]=id;
				}
				else cout<<"impossible"<<endl;
			}
			else{
				cin>>id;
				for(int i=0;i<W;i++)if(b[i]==id)b[i]=-1;
			}
		}
		cout<<"END"<<endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30

using namespace std;

int n;
vector<int> v,v2;
bool used[101],used2[101];

int getNext(int y,int type)
{
	if(type == 0)
	{
		if(v[y] == 2)
		{
			while(y-1 >= 0 && v[y] == 2) y--;
		}
		if(v[y] == 1)
		{
			while(y+1 < n && v[y+1] == 1) y++;
		}
		return y;
	}
	else
	{
		if(v2[y] == 2)
		{
			while(y-1 >= 0 && v2[y] == 2) y--;
		}
		if(v2[y] == 1)
		{
			while(y+1 < n && v2[y+1] == 1) y++;
		}
		return y;
	}
}

int main()
{
	while(cin >> n && n)
	{
		v.clear();
		v2.clear();

		v.resize(n);
		v2.resize(n);

		rep(i,n) cin >> v[i];
		rep(i,n) cin >> v2[i];

		int ans = INF;

		//start 0
		rep(i,101)
		{
			used[i] = false;
			used2[i] = false;
		}

		queue<pair<int,pair<int,int> > > que;
		que.push(make_pair(0,make_pair(0,0)));

		while(que.size())
		{
			int turn = que.front().first;
			pair<int,int> p = que.front().second;
			int y = p.first;
			int type = p.second;

			que.pop();

			int ny = getNext(y,type);
			if(type == 0) 
			{
				if(used[ny]) continue;
				else used[ny] = true;
			}
			else 
			{
				if(used2[ny]) continue;
				else used2[ny] = true;
			}

			if(ny == n-1)
			{
				ans = min(ans,turn);
			}
			
			rep(i,3)
			{
				if(type == 0)
				{
					if(0 <= ny+i && ny+i < n && !used2[ny+i])
					{
						que.push(make_pair(turn+1,make_pair(ny+i,1)));
					}
				}
				else
				{
					if(0 <= ny+i && ny+i < n && !used[ny+i])
					{
						que.push(make_pair(turn+1,make_pair(ny+i,0)));
					}
				}
			}
		}

		//start 1
		rep(i,101)
		{
			used[i] = false;
			used2[i] = false;
		}
		queue<pair<int,pair<int,int> > > que2;
		que2.push(make_pair(0,make_pair(0,1)));
		
		while(que2.size())
		{
			int turn = que2.front().first;
			pair<int,int> p = que2.front().second;
			int y = p.first;
			int type = p.second;

			que2.pop();

			int ny = getNext(y,type);
			if(type == 0) 
			{
				if(used[ny]) continue;
				else used[ny] = true;
			}
			else 
			{
				if(used2[ny]) continue;
				else used2[ny] = true;
			}

			if(ny == n-1)
			{
				ans = min(ans,turn);
			}

			rep(i,3)
			{
				if(type == 0)
				{
					if(0 <= ny+i && ny+i < n && !used2[ny+i])
					{
						que2.push(make_pair(turn+1,make_pair(ny+i,1)));
					}
				}
				else
				{
					if(0 <= ny+i && ny+i < n && !used[ny+i])
					{
						que2.push(make_pair(turn+1,make_pair(ny+i,0)));
					}
				}
			}
		}

		if(ans == INF) cout << "NA" << endl;	
		else cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 1220
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int []arr=new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=scn.nextInt();
		}
		Arrays.sort(arr);
		double den=Math.pow(2, n-1);
		double sum=0;
		for(int i=0,j=1;i<n;i++) {
			if(i<2) {
				sum+=arr[i];
			}else {
				sum+=arr[i]*Math.pow(2, j);
				j++;
			}
		}
		double s=sum/den;
		//System.out.println(sum+" "+den);
		System.out.println(s);
	}

}


Measured memory_bytes: 21716
#include<stdio.h>
int main(void)
{
	int i, ans;
	char str[3][120];
	int count[3] = {0};
	char current;
	
	
	for(i=0; i<3; i++){
		scanf("%s", str[i]);
	}
	
	current = str[0][0];
	count[0]++;
	
	while(1){
		
		switch(current){
			case 'a':
				current = str[0][count[0]++];
			
				if(current == '\0'){
					printf("A\n");
					return 0;
				}
				
				break;
				
			case 'b':
				current = str[1][count[1]++];
				
				if(current == '\0'){
					printf("B\n");
					return 0;
				}
				
				break;
				
			case 'c':
				current = str[2][count[2]++];
				
				if(current == '\0'){
					printf("C\n");
					return 0;
				}
				
				break;
		}
		
	}
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0
for i in range(N):
    if A[i] < B[i]:
        count += A[i]
        B[i] -= A[i]
    else:
        count += B[i]
        B[i] = 0
    if A[i+1] < B[i]:
        count += A[i+1]
        B[i] -= A[i+1]
        A[i+1] = 0
    else:
        count += B[i]
        A[i+1] -= B[i]
        B[i] = 0
        
print(count)


Measured memory_bytes: 24028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

int main(){
  int i,j;
  ll n,k;
  cin>>n>>k;
  ll p[n];
  for(i=0;i<n;i++) cin>>p[i];
  ll s=0;
  for(i=0;i<k;i++){
    s+=p[i];
  }
  ll m=s;
  for(i=k;i<n;i++){
    s=s+p[i]-p[i-k];
    m=max(m,s);
  }
  cout<<fixed<<setprecision(15)<<(m+k)/2.0<<endl;

  return 0;
}

Measured memory_bytes: 1792
n, k = map(int, input().split())

l = [True]
for _ in range(n):
    l.append(False)
    
for _ in range(k):
    d = int(input())
    al = map(int, input().split())
    for a in al:
        if l[a] == False:
            l[a] = True
    
count = 0
for v in l:
    if v == False:
        count += 1
        
print(count)

Measured memory_bytes: 9196
R, G ,B, N = map(int,input().split(" "))

cnt = 0
for i in range(0,N//R+1):
    for j in range(0,N//G+1):
        if R*i + G*j > N:
            break
        
        if (N - R*i - G*j) % B == 0:
            cnt += 1
            
print(cnt)

Measured memory_bytes: 40428
#include <iostream>
#include <vector>

int main(void)
{
    int N;
    std::cin >> N;

    std::vector<int> A1(N);
    std::vector<int> A2(N);

    for (int i = 0; i < N; ++i) {
        std::cin >> A1[i];
    }
    for (int i = 0; i < N; ++i) {
        std::cin >> A2[i];
    }

    std::vector<int> cum1(N, A1[0]);
    for (int i = 1; i < N; ++i) {
        cum1[i] = cum1[i-1] + A1[i];
    }

    std::vector<int> cum2(N, A2[N-1]);
    for (int i = N - 2; i >= 0; --i) {
        cum2[i] = cum2[i+1] + A2[i];
    }

    int maxsum = 0;
    for (int i = 0; i < N; ++i) {
        const int tmp = cum1[i] + cum2[i];
        maxsum = (tmp > maxsum) ? tmp : maxsum;
    }

    std::cout << maxsum << std::endl;

    return 0;
}

Measured memory_bytes: 256
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
###############################################################################\
s=input()
a="Sunny"
b="Cloudy"
c="Rainy"
if s==a:
	print(b)
elif s==b:
	print(c)
else:
	print(a)


Measured memory_bytes: 62056