akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 1100;
int matrix[maxn][maxn], n;
set<pair<int,int> > battles;
int pntr[maxn];

void update(int x) {
	pntr[x]++;
}

void update_battles(int x) {
	int f = matrix[x][pntr[x]];
	int s = matrix[f][pntr[f]];

	if(s == x) {
		battles.insert(mp(min(f, x), max(f, x)));
	}
}

int main() {
	cin>>n;

	for(int i=1;i<=n;i++) {
		for(int j=1;j<n;j++) {
			cin>>matrix[i][j];
		}
		pntr[i] = 1;
	}

	int total = 0;
	for(int i=1;i<=n;i++) {
		int f = matrix[i][1];
		int s = matrix[f][1];
		if(s == i) battles.insert(mp(min(f, i), max(f, i)));
	}

	int d = 0;
	while(2*total < n*(n-1)) {
		if(battles.size() == 0) {
			cout<<"-1\n";
			return 0;
		}

		total += battles.size();
		set<pair<int,int> > old = battles;

		for(auto i:battles) {
			update(i.first);
			update(i.second);
		}

		for(auto i:battles) {
			update_battles(i.first);
			update_battles(i.second);
		}

		for(auto i:old) battles.erase(i);
		d++;
	}
	cout<<d<<"\n";
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define loop(i, a, b) for(li i=a; i<=b; i++)
#define stuff ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<li, li> lii;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ii> vii;
typedef vector<lii> vlii;
li mod = 1e9+7;
li expo(li base, li exponent)
{
	li ans=1;
	while(exponent)
	{
		if(exponent&1) ans = (ans*base)%mod;
		base = (base*base)%mod;
		exponent >>= 1;
	}
	return ans;
}
li gcd(li x, li y)
{
	if(y==0) return x;
	return gcd(y, x%y);
}


typedef tree<li, null_type, less<li>,
rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const li N = 2001;
li dp[N][N];
li n;
vector<lii> ar;
li calc(li i, li j)
{
	li ind = i+j;
	if(ind==n) return 0;
	if(dp[i][j]!=-1) return dp[i][j];
	li pos = ar[ind].se, val = ar[ind].fi;
	// cout << val*(abs(pos-i-1)) << endl;
	li ans = max(val*(abs(pos-i-1))+calc(i+1, j), val*(abs(pos-(n-j)))+calc(i, j+1));
	return dp[i][j] = ans;
}
int main()
{
	stuff;
	// #ifndef ONLINE_JUDGE 
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
	// #endif

	memset(dp, -1, sizeof(dp));
	// li n;
	cin >> n; 
	ar.resize(n);
	// vector<lii> ar(n);
	loop(i, 0, n-1)
	{
		cin >> ar[i].fi;
		ar[i].se = i+1;
	}
	sort(ar.begin(), ar.end(), greater<lii>());
	
	cout << calc(0, 0);
	return 0;
}


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

int main(void) {
  int N;
  cin >> N;
  vector<long long> orga(N);
  for(int i=0;i<N;i++){
    cin >> orga[i];
  }

  long long sum = 0;
  long long cnt = 0;
  long long mincnt = 1e18;
  for(int sign=0;sign<=1;sign++){
    vector<long long> a(orga);
    cnt = 0;
    sum = 0;
    for(int i=0;i<N;i++){
      if(i == 0){
        if(sign == 0 && a[0] >= 0){
          long long diff = abs(a[0]) + 1;
          a[i] -= diff;
          cnt += diff;
        }
        if(sign == 1 && a[0] <= 0){
          long long diff = abs(a[0]) + 1;
          a[i] += diff;
          cnt += diff;
        }
      }
      else if(sum + a[i] == 0){
        if(sum < 0){
          cnt++;
          a[i]++;
        }else if(sum > 0){
          cnt++;
          a[i]--;
        }
      }
      else if(sum < 0 && sum + a[i] < 0){
        long long diff = abs(sum + a[i]) + 1;
        cnt += diff;
        a[i] += diff;
      }
      else if(sum > 0 && sum + a[i] > 0){
        long long diff = abs(sum + a[i]) + 1;
        cnt += diff;
        a[i] -= diff;
      }
      sum += a[i];
    }
    mincnt = min(cnt,mincnt);
    for(int i=0;i<N;i++){
      cerr << a[i] << " ";
    }cerr << endl;
  }
  cout << mincnt << endl;
  return 0;
}

Measured memory_bytes: 1804
#include<bits/stdc++.h>
using namespace std;
int n,a[10010],cnt;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]!=i) cnt++;
	}
	if(cnt==0||cnt==2) cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//Remove below header file if c++ version greater than 14
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)


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

ll lcm(ll a, ll b) {
	return a /gcd(a, b) *b;
}
typedef pair<int,int> pii;
const int mod = 1e9+7;

ll xorr(ll n){

    if(n%4==0)
        return n;

    else if(n%4==1)
        return 1;

    else if(n%4==2)
        return n+1;

    else
        return 0;



}

int main() {

   ll a,b;
   cin>>a>>b;

   if(a==0)
      cout<<(xorr(a)^xorr(b));

   else
      cout<<(xorr(a-1)^xorr(b));


























    return 0;

      }


Measured memory_bytes: 256
//include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

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

//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 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, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
//--------------------------------------------
constexpr double EPS = 1e-10;
constexpr double PI = 3.141592653589793;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main() {
    LL tmp {0}, ans {INT_MAX};
    int n, k; cin >> n >> k;
    vector<int> x(n);
    REP (i, n) cin >> x[i];
    REP (i, n - k + 1) {
        tmp = (x[i + k - 1] - x[i]) + min(abs(x[i]), abs(x[i + k - 1]));
        ans = min(ans, tmp);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 640
def partial_sum(arr)
  s = 0
  arr.map do |elt|
    s += elt
  end
end

n = gets.to_i
s = gets.chomp.chars

sum_w = partial_sum(s.map { |c| c == 'W' ? 1 : 0 })
sum_e = partial_sum(s.map { |c| c == 'E' ? 1 : 0 }.reverse).reverse

puts 0.upto(n-1).map { |i| sum_w[i] + sum_e[i] }.min - 1


Measured memory_bytes: 44032
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
	string a = "CODEFESTIVAL2016";
	string b;
	cin >> b;
	int ans = 0;
	for(int i = 0 ; i < 16 ; i++){
		if(a[i] != b[i]) ans++;
	}
	cout << ans;
}
/*
5 5
1 1 1 1 0
1 1 1 0 0
1 1 1 0 0 
1 1 1 1 0
1 1 1 1 0
*/

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

using namespace std;
int main(void){
    while(1){
       string str;
       cin>>str;
       if(str[0]=='0'){
          break;
       }
       int sum=0;
       for(int i=0;i<str.size();i++){
          sum+=str[i]-'0';
       }
       cout <<sum<<endl;
   }
   return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }


int dp[3010][3010];

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

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

    // 復元
    string ans = "";
    int i = s.size(), j = t.size();
    while (i>0 && j>0){
        // (i-1, j) -> (i, j)と遷移
        if (dp[i][j] == dp[i-1][j]) i--;
        // (i, j-1) -> (i, j)と遷移
        else if (dp[i][j] == dp[i][j-1]) j--;
        // (i-1, j-1) -> (i, j)と遷移
        // つまりs[i-1] == t[i-1]で、ナナメに遷移してきた
        else {
            ans += s[i-1];
            i--; j--;
        }
    }
    // 逆順に復元したので、ひっくり返す
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 35584
let N = Int(readLine()!)!
let a = readLine()!.characters.split(" ").map{Int(String($0))!} + [0]
var cnt = 1
var ans = 0
for i in 1...N {
  if a[i-1] == a[i] {
    cnt += 1
  } else {
    ans += cnt/2
    cnt = 1
  }
}
print(ans)

Measured memory_bytes: 4080
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    }
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}


int main(){
    ll n;
    cin >> n;
    sieve(100100);
    while (true){
        if (IsPrime[n]){
            cout << n << endl;
            break;
        }
        n++;
    }
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N, M;
  cin >> N >> M;
  vector<int> x(M), y(M);
  rep(i, M) {
    cin >> x[i] >> y[i];
    x[i]--, y[i]--;
  }

  vector<int> num(N, 1);
  vector<bool> red(N, false);
  red[0] = true;

  rep(i, M) {
    int from = x[i], to = y[i];

    if (red[from]) {
      red[to] = true;
      if (num[from] == 1)
        red[from] = false;
    }

    num[from]--, num[to]++;
  }

  int ans = 0;
  rep(i, N) {
    if (red[i])
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2688
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n) 
{ v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i]; }
template<class T, class U> void read_n(vector<pair<T, U>>& v, size_t n)
{ v = vector<pair<T, U>>(n); 
  for (lli i=0; i<n; ++i) cin >> v[i].first >> v[i].second; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s;
int main() {
  cin >> s;
  sort(begin(s), end(s));
  auto ans = s == "abc" ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> blue(n);
    for (int i = 0; i < n; i++) {
        cin >> blue[i];
    }
    int m;
    cin >> m;
    vector<string> red(m);
    for (int i = 0; i < m; i++) {
        cin >> red[i];
    }

    int ans = 0;
    auto calc = [&](string s) {
        int buf = 0;
        for (string t: blue) {
            if (t == s) buf++;
        }
        for (string t: red) {
            if (t == s) buf--;
        }
        return buf;
    };

    for (string t: blue) {
        ans = max(ans, calc(t));
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(long long i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<ll, ll>;
const int mod = 1000000007;

ll dp[2005][2005];

int main(){
    ll n;
    cin >> n;
    vector<P> a(n);
    rep(i, n) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    
    rep(i, n+1) {
        if (i==0) continue;
        rep(j, i+1) {
            ll k = i-j;
            ll v = a[i-1].first;
            ll id = a[i-1].second;
            if (j>0) {
                dp[j][k] = max(dp[j][k], dp[j-1][k]+v*abs(id-j+1));
            }
            if (k>0) {
                dp[j][k] = max(dp[j][k], dp[j][k-1]+v*abs(n-k-id));
            }
            //cout << j << " " << k << " " << dp[j][k] << endl;
        }
    }
    ll ans = 0;
    rep(i, n+1) {
        ans = max(ans, dp[i][n-i]);
    }
    
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 26296
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if(u == s) cout << a - 1 << " " << b;
	else cout << a << " " << b - 1;
	return 0;
} 

Measured memory_bytes: 256
max_num = 10**5+5
eratos_thenes_sieve = [0,0] + [1]*max_num
n = 2 #素数
while n*n <= max_num:
  if eratos_thenes_sieve[n]:#
    for i in range(2*n, max_num, n):
      eratos_thenes_sieve[i] = 0
  n += 1
  
isLike2017 = [0] * max_num
cumulativeSums = [0]
for i in range(max_num):
  if eratos_thenes_sieve[i] and eratos_thenes_sieve[(i+1)//2]:
    isLike2017[i] = 1
  cumulativeSums.append(cumulativeSums[-1] + isLike2017[i])
  
  
q = int(input())

for i in range(q):
  l, r = map(int, input().split())
  print(cumulativeSums[r+1] - cumulativeSums[l])

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

int main() {
	string s,t={},w,ans[4]={"dream","dreamer","erase","eraser"};
	bool can = true;
	cin >> s;
	reverse(s.begin(),s.end());
	for(int i=0;i<4;i++) reverse(ans[i].begin(),ans[i].end());
	
	while(s.size() > t.size()){
		for(int i=0;i<4;i++){
            		string w = t;
            		t += ans[i];
            		can = true;
            		 for(int j=w.size();j<=t.size()-1;j++){
	            		if(s[j] != t[j]){
	            			can = false;
	            			break;
	            		 }
            		}
		 if(can == false) t = w;
            	 else break;
		}
		 if(can == false) break;
	}
	if(can) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 696
import math
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))

dp = [-1 for j in range(n)]
dp[0]=0
for i in range(n):
    for j in range(min(k,n-i-1)):
        temp = dp[i] + abs(a[i]-a[i+j+1])
        if(dp[i+j+1]==-1 or dp[i+j+1] > temp):
            dp[i+j+1] = temp
print(dp[-1])

Measured memory_bytes: 56544
import sys
x,y = map(int,input().split())

#2a+4b =y
#a+b =x
#b=x-a
#y =2a+4(x-a)=4x-2a

for i in range(x+1):
    if y == 4*x-2*i:
        print("Yes")
        sys.exit()
else:
    print("No")

    

Measured memory_bytes: 9040
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define ranger(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define repr(i, b) for (int i = (b)-1; i >= 0; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

signed main() {
	int h, w, k;
	cin >> h >> w >> k;

	vector<string> s(h);
	rep(i, h) cin >> s[i];

	auto ans = vectors(h, w, 0LL);

	int num = 1;
	rep(i, h) {
		rep(j, w) {
			if (s[i][j] == '#') { ans[i][j] = num++; }
		}
	}


	rep(i, h) {
		rep(j, w - 1) {
			if (ans[i][j] != 0 and ans[i][j + 1] == 0)
				ans[i][j + 1] = ans[i][j];
		}
		ranger(j, w, 1) {
			if (ans[i][j] != 0 and ans[i][j - 1] == 0)
				ans[i][j - 1] = ans[i][j];
		}
	}

	rep(i,w){
		rep(j,h - 1){
			if (ans[j][i] != 0 and ans[j + 1][i] == 0)
				ans[j + 1][i] = ans[j][i];
		}
		ranger(j,h, 1){
			if (ans[j][i] != 0 and ans[j - 1][i] == 0)
				ans[j - 1][i] = ans[j][i];
		}
	}

	rep(i, h) {
		rep(j, w) { 
			if(j) cout << ' ';
			cout << ans[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 1664
#include <iostream>

using namespace std;

#define MAX 10000

struct Node {
	int p, left, right;
};

Node T[MAX];

void preParse(int u) {
	if (u == -1) return;
	cout << " " << u;
	preParse(T[u].left);
	preParse(T[u].right);
}

void inParse(int u) {
	if (u == -1) return;
	inParse(T[u].left);
	cout << " " << u;
	inParse(T[u].right);
}

void postParse(int u) {
	if (u == -1) return;
	postParse(T[u].left);
	postParse(T[u].right);
	cout << " " << u;
}

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; ++i) T[i].p = -1;
	int id, left, right;
	for (int i = 0; i < n; ++i) {
		cin >> id >> left >> right;
		T[id].left = left;
		T[id].right = right;
		if (left != -1) T[left].p = id;
		if (right != -1) T[right].p = id;
	}
	int root;
	for (int i = 0; i < n; ++i)
		if (T[i].p == -1) root = i;
	cout << "Preorder" << endl;
	preParse(root);
	cout << endl;
	cout << "Inorder" << endl;
	inParse(root);
	cout << endl;
	cout << "Postorder" << endl;
	postParse(root);
	cout << endl;

	return 0;
}


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

using namespace std;

int main() {
    int N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;
    string s;
    cin >> s;

    map<char, int> mp;
    mp['r'] = P;
    mp['s'] = R;
    mp['p'] = S;

    vector<bool> win(N, false);
    int ans = 0;
    for (int i = 0; i <K ; ++i) {
        win[i] = true;
        ans += mp[s[i]];
    }

    for (int i = K; i < s.length(); ++i) {
        if (win[i - K] == true and s[i] == s[i - K]) {
            win[i] = false;
        } else {
            ans += mp[s[i]];
            win[i] = true;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111




	void solve(){


		ini(n);
		int morty[n];
		int morty1[n];
		int rick = 0;
		FOR(i,0,n)in(morty[i]);
		priority_queue<pair<int,int> > tmp;
		FOR(i,0,n){
			in(morty1[i]);
			if(morty1[i]>morty[i]){
				tmp.push(make_pair(morty1[i],i));
			}
		}
		while(tmp.size()){
			pair<int,int> tmp1;
			tmp1 = tmp.top();
			tmp.pop();
			if(tmp1.first > morty1[tmp1.second-1==-1?(n-1):tmp1.second-1]+morty1[tmp1.second+1 == n?0:tmp1.second+1]){
				if((morty1[tmp1.second]-morty[tmp1.second])%(morty1[tmp1.second-1==-1?(n-1):tmp1.second-1]+morty1[tmp1.second+1 == n?0:tmp1.second+1]) == 0){
					rick+=(morty1[tmp1.second]-morty[tmp1.second])/(morty1[tmp1.second-1==-1?(n-1):tmp1.second-1]+morty1[tmp1.second+1 == n?0:tmp1.second+1]);
					morty1[tmp1.second] = morty[tmp1.second];
				}
				else{
					morty1[tmp1.second] = tmp1.first%(morty1[tmp1.second-1==-1?(n-1):tmp1.second-1]+morty1[tmp1.second+1 == n?0:tmp1.second+1]);
					rick+=tmp1.first/(morty1[tmp1.second-1==-1?(n-1):tmp1.second-1]+morty1[tmp1.second+1 == n?0:tmp1.second+1]);
					if(morty1[tmp1.second]<morty[tmp1.second])return out(-1);
					tmp.push(make_pair(morty1[tmp1.second],tmp1.second));
				}
				
			}
			else{
				return out(-1);
			}
			
		}
		out(rick);
		


	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 9200
import java.util.Scanner;

//B - AcCepted
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        if (check(S))
            System.out.println("AC");
        else
            System.out.println("WA");
        sc.close();
    }

    static boolean check(String s) {
        if (s.charAt(0) != 'A') return false;
        int cnt = 0;
        for (int i = 1; i < s.length(); i++)
            if (i >= 2 && i <= s.length() - 2) {
                if (s.charAt(i) == 'C') {
                    if (++cnt > 1) return false;
                }else if (!Character.isLowerCase(s.charAt(i)))
                    return false;
            } else if (!Character.isLowerCase(s.charAt(i)))
                return false;
        return cnt == 1;
    }
}


Measured memory_bytes: 23764
# 参考・参照サイト
# https://ikatakos.com/pot/programming_algorithm/contest_history/atcoder/2019/0106_educational_dp_2

# require 'pry'
N = gets.to_i
ind = -1
height = gets.split.map do |high|
  ind += 1
  t = high.to_i
  [t, ind]
end
beauty = gets.split.map(&:to_i)
# p height
# binding.pry
n2 = 1 << N.bit_length
OFFSET = n2 - 1
@data = Array.new((n2 << 1) - 1, 0)

def update(k, x)
  i = k + OFFSET
  while i >= 0
    if @data[i] < x
      @data[i] = x
    else
      break
    end
    i = (i - 1) / 2
  end
end

def get_max(k)
  i = k + OFFSET
  ret = @data[i]
  while i > 0
    if i % 2 == 0
      ret = @data[i-1] if ret < @data[i-1]
    end
    i = (i - 1) / 2
  end
  return ret
end

srt = height.sort_by{|x|x[0]}
srt.each do |v, i|
  update(i , get_max(i) + beauty[i])
end
puts @data[0]

Measured memory_bytes: 47000
import math
n = float(input())
ans = n / 1.08
ansu = math.ceil(ans)
ansd = math.floor(ans)
if math.floor(ansu * 1.08) == n:
    print(ansu)
elif math.floor(ansd * 1.08) == n:
    print(ansd)
else:
    print(":(")

Measured memory_bytes: 3060
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
Pt=[0,p,r,s]
Ans=[0]*k
Prev=[0]*k
for i in range(n):
  if t[i]=="r":
    cur=1
  elif t[i]=="s":
    cur=2
  else:
    cur=3
  ii=i%k
  if Prev[ii]==cur:
    Prev[ii]=0
  else:
    Ans[ii]+=Pt[cur]
    Prev[ii]=cur
print(sum(Ans))

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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;
    int a;
    ll total = 0;
    int res = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        res |= a;
        // total += a;
    }
    // if (total & 1) {
    if (res & 1) {
        cout << "first" << '\n';
    } else {
        cout << "second" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
//Problem A
#include<bits/stdc++.h>
using namespace std;
const int N=111;
int n,a[N],s,mx,id=-1;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]),s+=a[i];
    for(int i=0;i<n;i++){
        int w=abs(s-a[i]*n);
        if(id==-1||w<mx)mx=w,id=i;
    }
    printf("%d",id);
    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<utility>
#include<climits>
using namespace std;

class MinHeap{
    vector<pair<int, int>> edges;
    int sz;
    int parent(int i){return (i-1)/2;}
    int left(int i){return 2*i+1;}
    int right(int i){return 2*i+2;}
    void heapify(int i){
        int m = i, l = left(i), r = right(i);
        if(l < sz && edges[l].second < edges[i].second) m = l;
        if(r < sz && edges[r].second < edges[m].second) m = r;
        if(m != i){
            swap(edges[m], edges[i]);
            heapify(m);
        }
    }
public:
    MinHeap(): sz(0), edges(500000) {}
    pair<int, int> extractMin(){
        swap(edges[0], edges[sz-1]);
        sz--;
        heapify(0);
        return edges[sz];
    }
    void insert(pair<int, int> edge){
        int i = sz, p = parent(i);
        edges[i] = edge;
        sz++;
        while(p >= 0 && edges[p].second > edges[i].second){
            swap(edges[i], edges[p]);
            i = p;
            p = parent(i);
        }
    }
    bool empty(){
        return sz == 0;
    }
};

void dijkstra(vector<int>& dist, vector<vector<pair<int, int>>>& adjlist, MinHeap& heap, const int& r){
    heap.insert(make_pair(r, 0));
    while(!heap.empty()){
        pair<int, int> min_edge = heap.extractMin();
        int u = min_edge.first;
        for(int i = 0; i < adjlist[u].size(); i++){
            int v = adjlist[u][i].first, d = adjlist[u][i].second; 
            if(dist[v] > dist[u] + d){
                dist[v] = dist[u] + d;
                heap.insert(make_pair(v, d));
            }
        }
    }
}

int main(){
    int v, e, r, s, t, d;
    cin >> v >> e >> r;
    MinHeap heap = MinHeap();
    vector<vector<pair<int, int>>> adjlist(v);
    vector<int> dist(v, INT_MAX);
    dist[r] = 0;
    for(int i = 0; i < e; i++){
        cin >> s >> t >> d;
        adjlist[s].push_back(make_pair(t, d));
    }
    dijkstra(dist, adjlist, heap, r);
    for(int d : dist){
        if(d == INT_MAX) cout << "INF\n";
        else cout << d << endl;
    }
}



Measured memory_bytes: 15664
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        char[] str = scanner.next().toCharArray();
        int N = scanner.nextInt();
        int[] dist = new int[str.length];
        for(int i=0; i<str.length; i++)
        {
            dist[i] = 'z' - str[i];
        }
        for(int i=0; i<str.length-1; i++)
        {
            if(str[i] != 'a' && dist[i] < N)
            {
                str[i] = 'a';
                N -= dist[i] + 1;
            }
        }
        N = N % 26;
        int distanceToA = 26 - dist[dist.length-1] - 1;
        str[str.length-1] = (char)('a' + ((distanceToA + N) % 26));
        System.out.println(new String(str));
    }
}

Measured memory_bytes: 14540
package main

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

func main() {
	fsc := NewFastScanner()
	A, B, C, X, Y := fsc.NextInt(), fsc.NextInt(), fsc.NextInt(), fsc.NextInt(), fsc.NextInt()
	var result int64
	var tmp int64
	result = int64(1 << 50)
	for z := 0; z <= 200000; z += 2 {
		x := IntMax(0, X-z/2)
		y := IntMax(0, Y-z/2)
		tmp = int64(A*x + B*y + C*z)
		result = Int64Min(result, tmp)
	}
	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}

func (s *FastScanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


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

int main() {
    int D;
    cin >> D;
    vector<int> c(26);
    vector<vector<int>> s(D, vector<int>(26));
    vector<int> last(26);
    vector<int> chose(D);
    rep(i, 26) cin >> c[i];
    rep(i, D) {
        rep(j, 26) cin >> s[i][j];
    }
    rep(d, D) {
        int minus = 0;
        rep(i, 26) {
            minus += c[i] * (d - last[i]);
        }
        int m = -2000000;
        rep(i, 26) {
            int q = s[d][i] - minus + c[i] * (d - last[i]);
            m = max(m, q);
            if (m == q) chose[d] = i;
        }
        last[chose[d]] = d;
    }
    rep(d, D) cout << chose[d]+1 << endl;
}


Measured memory_bytes: 3672
n = int(input())
if (400<=n and n<=599):
    print(8)
elif (600<=n and n<=799):
    print(7)
elif (800<=n and n<=999):
    print(6)
elif (1000<=n and n<=1199):
    print(5)
elif (1200<=n and n<=1399):
    print(4)
elif (n<=1599):
    print(3)
elif (n<=1799):
    print(2)
else:
    print(1)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll n,m,ans=0;
void Main(){
    cin>>m;
    ll sum=0;
    For(i,0,m) {
        ll a,b;cin>>a>>b;
        sum+=a*b;
        ans+=b;
    }
    ans+=(sum-1)/9;
    cout<<ans-1<<endl;
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a, b, c;
  scanf ("%d %d %d", &a, &b, &c);
  if(1<=a<=100 && 1<=b<=100 && 1<=c<=100){
  if (a == b && b == c){
    printf("%d\n", 1);
  } else if ( a != b && b != c && a !=c){
    printf("%d\n", 3);
  } else {
    printf("%d\n", 2);
  }
  } else {
    printf ("%s\n", "Invalid!");
  }
  return 0;
}

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

int main() {
  int64_t K,A,B;
  cin>>K>>A>>B;
  
  if(B-A<=2){
    cout<<1+K<<endl;
  }
  else{
    if(K<=A){
      cout<<1+K<<endl;
    }
    else{
      int64_t S=A+((K-A+1)/2)*(B-A)+(K-A+1)%2;
      cout<<max(1+K,S)<<endl;
    }
  }
  
}

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

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

struct BipartiteGraph {
  int N;
  vector<vector<int>> G;
  vector<int> coler;
  BipartiteGraph() {}
  BipartiteGraph(int N) : N(N), G(N), coler(N) {}
  void add_edge(int s, int t) {
    G[s].emplace_back(t);
  }
  bool is_bipartite_graph() {
    for (int i = 0; i < N; i++) coler[i] = 0;
    for (int i = 0; i < N; i++) {
      if (coler[i]) continue;
      int c = 1;
      coler[i] = c;
      stack<int> S;
      S.emplace(i);
      while (!S.empty()) {
        int v = S.top(); S.pop();
        for (auto &u : G[v]) {
          if (coler[u] == coler[v]) return false;
          if (coler[u]) continue;
          coler[u] = -coler[v];
          S.emplace(u);
        }
      }
    }
    return true;
  }
  pii get_count() {
    if (!is_bipartite_graph()) return pii(-1, -1);
    int b = 0, w = 0;
    for (int i = 0; i < N; i++) b += coler[i] > 0, w += coler[i] < 0;
    return pii(b, w);
  }
};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N, M;
  cin >> N >> M;
  BipartiteGraph BG(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    A--, B--;
    BG.add_edge(A, B);
    BG.add_edge(B, A);
  }
  pii p = BG.get_count();
  cout << (p != pii(-1, -1) ? (ll)p.first * p.second - M : (ll)N * (N - 1) / 2 - M) << endl;

  return 0;
}

Measured memory_bytes: 6272
n, m = map(int, input().split())
#リスト内包表記でaに入れる
a = [int(input()) for _ in range(m)]

#MODに'1000000007'を入れる
MOD = 10**9 + 7
#zに集合を作成する
z = set(a)
 
#i段目までにたどりつく方法を順に求める
x = [0 for _ in range(n + 1)]
#0段目の場合1とする
x[0] = 1
#1段目の場合は集合の中に1が含まれていないかどうか、含まれていない:1、含まれている:0
x[1] = int(1 not in z)
#2段目以降の場合
for i in range(2, n + 1):
#集合の中にiが含まれていない場合
    if i not in z:
#i段目に1段か2段で上ってきた経路数を足して、MODで割る、dp[i]に蓄積する
        x[i] = (x[i - 1] + x[i - 2]) % MOD
print(x[n])

Measured memory_bytes: 13192
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val s = sc.next()
  val q = sc.nextInt()

  val front = mutableListOf<String>()
  val back = mutableListOf<String>()
  var order = true
  for (i in 1..q) {
    val ti = sc.nextInt()
    if (ti == 1) {
      order = !order
    } else {
      val fi = sc.nextInt()
      val ci = sc.next()
      if ((order && fi ==1) || (!order && fi == 2)) {
        front.add(ci)
      } else {
        back.add(ci)
      }
    }
  }

  var ans = front.reversed().joinToString("") + s + back.joinToString("")

  if (order) {
    println(ans)
    return
  }
  println(ans.reversed())
}

Measured memory_bytes: 77688
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define mod 998244353
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define endl "\n"
    #define pii pair<ll,ll>
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

/**********************************************************************************************************************/
const int mxH=10, mxW=1e3;
int h, w, k, ans=1e9;
string s[mxH];
vector<int> v[mxW];
signed main()/*Check flow...question galat mat padhna */
{
    fast;   
    cin >> h >> w >> k;
	for(int i=0; i<h; ++i)
		cin >> s[i];
	for(int i=0; i<1<<h-1; ++i) 
    {
		int count=__builtin_popcount(i);
		for(int j=0; j<w; ++j) 
        {
			int cnt=0;
			for(int k=0; k<h; ++k) 
            {
				cnt+=s[k][j]&1;
				if(i>>k&1) 
                {
					v[j].push_back(cnt);
					cnt=0;
				}
			}
			v[j].push_back(cnt);
			for(int vi : v[j])
				if(vi>k)
					count=1e9;
		}
		vector<int> u(v[0].size());
		for(int j=0; j<w; ++j) 
        {
			bool div=0;
			for(int l=0; l<u.size(); ++l)
				div|=u[l]+v[j][l]>k;
			if(div) 
            {
				++count;
				u=vector<int>(u.size());
			}
			for(int l=0; l<u.size(); ++l)
				u[l]+=v[j][l];
			v[j].clear();
		}
		ans=min(count, ans);
	}
	cout <<ans<<endl;;
}      

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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<bool> ch(10, 0);
	char c;
	for (int i = 0; i < K; i++) {
		cin >> c;
		ch[c - '0'] = true;
	}
	while (true) {
		bool flag = true;
		int NN = N;
		while (NN) {
			if (ch[NN % 10]) {
				flag = false;
				break;
			}
			NN /= 10;
		}
		if (flag)
			break;
		N++;
	}
	cout << N << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int i = K; i < N; i++) {
        if(A[i] > A[i-K]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


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

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

    Graph G(n);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    vector<int> dist(n, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while(!que.empty()){
        int v = que.front();
        que.pop();

        for(int nv: G[v]){
            if(dist[nv] != -1) continue;

            dist[nv] = dist[v] + 1;
            que.push(nv); 
        }
    }

    vector<int> ans(n);
    for(int i = 1; i < n; i++){
        int v = n;
        int v_d = n;
        for(int nv: G[i]){
            if(v_d > dist[nv]){
                v_d = dist[nv];
                v = nv;
            }
        }
        ans[i] = v+1;
    }

    cout << "Yes" << endl;
    for(int i = 1; i < n; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 10508
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        String[] s = sc.next().split("");

        int a = Integer.parseInt(s[0] + s[1]);
        int b = Integer.parseInt(s[2] + s[3]);

        boolean flgA = false;
        boolean flgB = false;

        if (1 <= a && a <= 12) {
            flgA = true;
        }

        if (1 <= b && b <= 12) {
            flgB = true;
        }

        sc.close();

        if (!flgA && flgB) {
            System.out.println("YYMM");
        } else if (flgA && !flgB) {
            System.out.println("MMYY");
        } else if (flgA && flgB) {
            System.out.println("AMBIGUOUS");
        } else {
            System.out.println("NA");
        }
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  vector<ll> v;
  ll asum = 0;
  REP(i, N) {
    cin >> A[i];
    asum += A[i];
  }

  ll ans = 0, hituyo = 0;
  ll bsum = 0;
  REP(i, N) {
    cin >> B[i];
    bsum += B[i];
    if (A[i] - B[i] < 0) {
      ans++;
      hituyo += B[i] - A[i];
    }
    v.PB(A[i] - B[i]);
  }
  if (asum < bsum) {
    cout << -1 << endl;
    return 0;
  }

  cerr << ans << ' ' << hituyo << endl;
  sort(ALL(v), greater<ll>());
  ll sum = 0, cnt = -1;
  for (ll i = 0; i < v.size(); i++) {
    if (sum >= hituyo) {
      cnt = i;
      break;
    }
    sum += v[i];
  }
  ans += cnt;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2936
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
 
using namespace std;
 
int32_t main ()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}

	int money = 1000;

	//int ans=0;
	int best_sell=0;
	int cant=0;
	int best_item=INT_MAX;

	for(int i=0;i<n;i++){
		if(v[i]<best_item){
			best_item=v[i];
			money+=best_sell;
			cant = money/v[i];
			//ans+=best_sell;
			best_sell=0;
		}
		else if(i && v[i]<v[i-1]){
			best_item=v[i];
			money+=best_sell;
			cant = money/v[i];
			//ans+=best_sell;
			best_sell=0;
		}
		else if(i==n-1){
			best_sell=max(best_sell,(v[i]-best_item)*cant);
			money+=best_sell;
		}
		else{
			best_sell=max(best_sell,(v[i]-best_item)*cant);
		}
	//	cout<<best_item<<"   "<<money<<endl;
	}

	cout<<money<<endl;	
	
	return 0;
}


Measured memory_bytes: 3680
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int s;cin >> s;
    int i=2;
    int f,tmp=s;
    while(1){
        if(tmp%2==0){
            f=tmp/2;
        }
        else{
            f=3*tmp+1;
        }
        
        if(f==2 && tmp==4){
            cout << i+2 << endl;
            return 0;
        }
        if(f==1 && tmp==2){
            cout << i+2 << endl;
            return 0;
        }
        if(f==4 && tmp==1){
            cout << i+2 << endl;
            return 0;
        }
        
        tmp=f;
        i++;
    }
}




Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
const int Maxn = 2e5 + 5;
int ct[Maxn];
 
int main()
{
    string ss;
    int cnt;
    cin >> ss;
    memset(ct, 0, sizeof(ct));
    for (int i = 0; i < ss.size(); i++) {
        cnt = ss[i] - 'a' + 1;
        ct[cnt]++;
    }
    for (int i = 1; i <= 26; i++){
        if(ct[i] == 0){
            printf("%c\n", 'a' + i - 1);
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 1280
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
a = A[0]
for i in range(1,N):
    a = gcd(a,A[i])
if K<=A[-1] and K%a==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

int main() {
    double d;
    while (cin >> d, d >= 0.0000000) {
        int n = floor(d);
        if (n >= 1 << 8) {
            cout << "NA" << endl;
            continue;
        }

        string str;
        while (n) {
            str = (n % 2 == 0 ? "0" : "1") + str;
            n /= 2;
        }
        while (str.size() < 8) str = "0" + str;
        str += ".";

        double s = d - (double)floor(d);
        double v[] = {0.5, 0.25, 0.125, 0.0625};
        for (int i = 0; i < 4; i++) {
            if (s >= v[i]) {
                s -= v[i];
                str += "1";
            } else {
                str += "0";
            }
        }
        if (s) {
            cout << "NA" << endl;
        } else {
            cout << str << endl;
        }
    }

    return 0;
}

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

int main() {
  int n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll xoracc = 0;
  ll sum = 0;
  ll ans = 0;
  ll r = 0;
  for(int l=0; l<n; l++) {
    while(r<n) {
      if((xoracc^a[r])!=sum+a[r]) break;
      xoracc^=a[r];
      sum+=a[r];
      r++;
    }
    ans += r-l;
    sum-=a[l];
    xoracc^=a[l];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
bool prime[1000005];
int main(){
	memset(prime, 0, sizeof prime);
	vector<int>primes;
	for(int i=2;i<=1000000;i++){
		if(!prime[i]){
			for(int j=2*i;j<=1000000;j+=i){
				prime[j]=true;
			}
			primes.push_back(i);
		}
	}
	long long x;
	cin>>x;
	long long ans=0;
	for(int i=0;i<primes.size();i++){
		int cnt=0;
		while(x%primes[i]==0){
			x/=primes[i];
			cnt++;
		}
		for(int i=0;i<100;i++){
			if((i+1)*i/2>cnt){
				ans+=i-1;
				break;
			}
		}
	}
	if(x!=1){
		ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 4724