akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main() {

  int R;

  std::cin >> R;

  if (R < 1200) {
    std::cout << "ABC" << std::endl;
  } else if (1200 <= R && R < 2800) {
    std::cout << "ARC" << std::endl;
  } else {
    std::cout << "AGC" << std::endl;
  }
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    map<int, int> ev, od;
    
    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        if(i % 2){
            ev[t]++;
        }else{
            od[t]++;
        }
    }
    
    vector<pair<int, int>> ve, vo;
    for(auto t: ev){
        ve.push_back({t.second, t.first});
    }
    for(auto t: od){
        vo.push_back({t.second, t.first});
    }
    sort(ve.rbegin(), ve.rend());
    sort(vo.rbegin(), vo.rend());
    if(ve[0].second == vo[0].second){
        int a = ve[0].first;
        int b = vo[0].first;
        //cout << a << "," << b << endl;
        if(vo.size() > 1) a += vo[1].first;
        if(ve.size() > 1) b += ve[1].first;
        //cout << a << "," << b << endl;
        cout << n - max(a,b) << endl;
    }else{
        cout << n - ve[0].first - vo[0].first << endl;
    }
    
    return 0;
}

Measured memory_bytes: 6136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001;
const int NMAX=8;

int main()
{

	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	char c='0';
	vector <int> st,ed;
	st.emplace_back(0);
	ed.emplace_back(0);
	rep(i,n){
		char now=s[i];
	//	cout<<s[i]<<endl;
		if (s[i]=='1' and c=='0'){
			st.emplace_back(i);
		}
		if (s[i]=='0' and c=='1'){
			ed.emplace_back(i);
		}
		c=s[i];
	}
	if (ed.size()<st.size())ed.emplace_back(n);
	else {
		st.emplace_back(n);
		ed.emplace_back(n);
	}
//	rep(i,3) cout<<st[i]<<endl;
	int ans=0;
	if (st.size()<=k+1)ans=n;
	else{
		rep(i,(st.size()-k)){
			ans=max(ans,ed[i+k]-st[i]);
		}
	}
	cout<<ans;
}


Measured memory_bytes: 1020
#　入力
x,y = map(int,input().split())

#　タプル
X =  (1, 3, 5, 7, 8, 10, 12)
Y =  (4, 6, 9, 11 )

if x in X and y in X:
    print('Yes')

elif x in Y and y in Y:
    print('Yes')

else:
    print('No')

Measured memory_bytes: 3060
#include<stdio.h>
int c[200002];
void merge(int i,int j,int *s){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d]=s[b];
        b++;
      }
      else if(j<b){
        c[d]=s[a];
        a++;
      }
      else if(s[a]<s[b]){
        c[d]=s[a];
        a++;
      }
      else{
        c[d]=s[b];
        b++;
      }
    }
    for(d=i;d<=j;d++)
      s[d]=c[d];
  }
}

int main(){
  int i,n,check=0;
  scanf("%d",&n);
  int a[n+2];
  for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
  merge(1,n,a);
  for(i=1;i<n;i++)
    if(a[i]==a[i+1])
      check=1;
  if(check==1)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}


Measured memory_bytes: 1664
AV = [int(x) for x in input().split()]
BW = [int(x) for x in input().split()]
A = AV[0]
V = AV[1]
B = BW[0]
W = BW[1]
T = int(input())
T = float(T)
D = abs(A-B)
S = V-W
if S>0:
    T1 = float(D/S)
    if T1<=T:
        print('YES')
    else:
        print('NO')
else:
    print('NO')

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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

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

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

    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        a[x-1] = i;
    }

    int ans = 0;
    for (int i = 0; i < n; ++i)
        if (i == 0 || a[i] < a[i - 1]) {
            int j = i + 1;
            while (j != n && a[j - 1] < a[j])
                ++j;
            ans = max(ans, j - i);
        }
    cout << n - ans << "\n";

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(b-a == c-b) co("YES");
  else co("NO");
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.File;
import java.util.*;

public class Main {

    public static StringBuilder output = new StringBuilder();

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next().trim();
        Solver solver = new Solver();
        solver.solve(s);
        System.out.println(output);
    }

}

class Solver {
    public void solve(String s) {
        String ans = "";
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != 'B') {
                ans += s.charAt(i);
            } else {
                // Delete last character
                if (ans.length() > 0) {
                    ans = ans.substring(0, ans.length() - 1);
                }
            }
        }
        Main.output.append(ans);
    }
}

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

def nCr(n,r):

    r = min(n-r,r)
    if r == 0: return 1
    # reduceは第一引数で与えた関数を第二引数のiterbleのそれぞれで実行した結果をもどす
    over = reduce(mul, range(n, n - r, -1), 1)
    under = reduce(mul, range(1,r + 1), 1)
    return over // under



MOD = 10**9+7
N,K = map(int, input().split())

for i in range(1, K+1):
    blue = nCr(K-1, i-1)
    red = nCr(N-K+1, i)
    if N-K+1 >= i:
       print(blue*red%MOD)
    else:
        print(0)

Measured memory_bytes: 3944
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

const int MAX_N = 1e5;

int par[MAX_N]; // 親
int depth[MAX_N]; // 木の深さ

// n要素で初期化
void init(int n) {
	rep(i, 0, n) {
		par[i] = i;
		depth[i] = 0;
	}
}

// 木の根を求める
int find(int x) {
	if(par[x] == x) return x;
	else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(depth[x] < depth[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if(depth[x] == depth[y]) depth[x]++;
	}
}

// xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}


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

	int N, M;
	cin >> N >> M;
	init(N);
	int p[N];
	rep(i, 0, N) cin >> p[i];

	rep(i, 0, M) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		unite(x, y);
	}

	int rsl = 0;
	rep(i, 0, N) {
		p[i]--;
		if(same(p[i], i)) rsl++;
	}
	cout << rsl << endl;

}


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

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

using namespace std;

#define MAX 100010
int V,E;
int s[MAX],t[MAX];

int main() {
  cin >> V >> E;
  rep(i,E) cin >> s[i] >> t[i];
  map<int,int> mp;
  rep(i,E) { ++mp[s[i]]; ++mp[t[i]]; }
  for(auto v : mp) {
    if( v.second % 2 == 1 ) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int n;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n;
  cout << n * (n+1) / 2 - n << endl;
  return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;
public class Main{



	public static void main(String[] args){
		solve();





	}
	static void solve(){

		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if(A == B){
			System.out.println(C);
		}else if(B == C){
			System.out.println(A);
		}else{
			System.out.println(B);
		}
	}
}

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

using namespace std;
#define int long long
const int MAX = 200002;
const int MOD = 1000000007;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
    COMinit();
   int n,m,k;
   cin>>n>>m>>k;
   
 int p=0;
  for(int i=1;i<n;i++){
      p=(p+(n-i)*i*m*m)%MOD;
  }
   for(int i=1;i<m;i++){
      p=(p+(m-i)*i*n*n)%MOD;
  }
p=(p*COM(n*m-2,k-2))%MOD;
cout<<p;
    
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int ans = 0;
  rep(i, N) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      ans++;
    };
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3584
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
#include <unordered_map>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int main() {
#define int long long
	iostream::sync_with_stdio(false);
	cin.tie(0);
	long long n, a, b;
	cin >> n >> a >> b;
	int final_gyaku = 0;
	if (a >= b) {
		swap(a, b);
		final_gyaku = 1;
	}
	vector<int> boo;
	boo.push_back(n + 1);
	boo.push_back(n - b + 1);
	int cnt = 0;
	int required_do = a-1;
	for (int q = n - b; q >= 1; --q) {
		cnt++;
		if (cnt == b || required_do == q) {
			cnt = 0;
			boo.push_back(q);
			required_do--;
		}
	}
	if (required_do != 0) {
		cout << -1 << endl;
		return 0;
	}
	vector<int> ans;
	for (int i = boo.size()-2; i >= 0;--i) {
		for (int q = boo[i] - 1; q >= boo[i + 1]; --q) {
			ans.push_back(q);
		}
	}
	if (ans.size() != n) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < ans.size(); ++i) {
		if (final_gyaku == 0) {
			cout << ans[i] << " ";
		}
		else {
			cout << n - ans[i] + 1 << " ";
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 7664
#include<bits/stdc++.h>
using namespace std;
int main(){
    #define int long long
    const int mod=1000000007;
    int n,k;
    cin>>n>>k;
    int a[n];
    vector<int>sei;
    vector<int>fu;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>=0)sei.push_back(a[i]);
        else fu.push_back(-a[i]);
    }
    sort(sei.begin(),sei.end(),greater<int>());
    sort(fu.begin(),fu.end(),greater<int>());
    long long x=1;
    if(sei.size()==0){//コーナーケース
        if(k%2){
            for(int i=fu.size()-k;i<fu.size();i++){
                x*=fu[i];
                x%=mod;
            }
            cout<<mod-x<<endl;
        }
        else{
            for(int i=0;i<k;i++){
                x*=fu[i];
                x%=mod;
            }
            cout<<x<<endl;
        }
        return 0;
    }
    if(n==k){
        for(int i=0;i<fu.size();i++){
            x*=fu[i];
            x%=mod;
        }
        for(int i=0;i<sei.size();i++){
            x*=sei[i];
            x%=mod;
        }
        if(fu.size()%2)cout<<mod-x<<endl;
        else cout<<x<<endl;
        return 0;
    }
    //負を偶数個選ぶことで、必ず非負になる
    int best=0;//最も良い、負を選ぶ個数
    for(int i=2;i<=k;i+=2){
        if(i>fu.size() || k-i>sei.size())continue;
        if(fu[i-2]*fu[i-1]>sei[k-i]*sei[k-i+1])best=i;
    }
    for(int i=0;i<best;i++){
        x*=fu[i];
        x%=mod;
    }
    for(int i=0;i<k-best;i++){
        x*=sei[i];
        x%=mod;
    }
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 6616
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

    int N = Integer.parseInt(sc.next());

    long count = IntStream.rangeClosed(1, N)
      .mapToObj(String::valueOf)
      .filter(s -> s.length() % 2 != 0)
      .count();
    
    System.out.println(count);
  }
}

Measured memory_bytes: 30784
// Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
//If you are not doing well now just stick to it and learn new things one day you will be...
//Compete with yourself
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll)x.size()
#define all(x) x.begin(),x.end()
#define trav(a,x) for(auto &a:x)
#define fr(i,a,b)  for(ll i=a;i<=b;i++)
#define fr1(i,a)   for(ll i=0;i<a;i++)
#define frr(i,a,b) for(ll i=b;i>=a;i--)
#define frr1(i,a)   for(ll i=a-1;i>=0;i--)
#define sorta(a,n) sort(a,a+n)
#define sortd(a,n) sort(a,a+n,greater<ll>())
#define sorva(a) sort(a.begin(),a.end())
#define sortvd(a) sort(a.begin(),a.end(),greater<ll>())
#define tc(t) while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
using vi= vector<ll>;
using vvi= vector<vi>;
using vb =vector<bool>;
using vc =vector<char>;
using vs =vector<string>;
using vld =vector<ld>;
using pii =pair<ll,ll>;
using psi =pair<string,ll>;
using pci =pair<char,ll>;
using vpii =vector<pii>;
//}}}template*/
ll const mod=1e9+7;
ll const maxn=1e5+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modinverse(ll a, ll m){
    return powm(a,m-2,m);
}
bool prime(ll x){
    if(x<=1)return false;
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;
    return true;
}
ll divisor(ll x){
    ll cnt=0;
    for(int i=1;i<=sqrt(x);i++){
        if(x%i==0){
            if(i!=x/i)cnt+=2;
            else cnt+=1;
        }
    }
    return cnt;
}
vector<ll> sieve(ll n) {    
    bool prim[n+1];
    memset(prim, true, sizeof(prim));
    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) {
            for (int i=p*p; i<=n; i += p)
                prim[i] = false;
        }
    }
    vector<ll>v;
    for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);
    return v;
}
vi a;
ll n;
ll const N=1e5+5;
ll dp[N];
ll fun(ll pos){
    if(pos==n-1)return 0;
    if(pos>n-1)return inf;
    ll &ans=dp[pos];
    if(ans!=-1)return ans;
    ans=0;
    if(pos+2<=n-1){
        return ans=min(abs(a[pos+1]-a[pos])+fun(pos+1),abs(a[pos+2]-a[pos])+fun(pos+2));
    }
    return ans=abs(a[pos+1]-a[pos])+fun(pos+1);
}
void solve(){
    cin>>n;
    a.resize(n);
    for(int i=0;i<n;i++)cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<fun(0);

}
int main(){

    fio;
    clock_t zzzz = clock();
    ll T;
    T=1;
    // cin>>T;
    while(T--){
        solve();
    } 
    debug("Total Time: %.3f\n", (double)(clock() - zzzz) / CLOCKS_PER_SEC);
   return 0;
}




Measured memory_bytes: 8020
#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: putc;
using io :: print;
const int N=1e5+5;
int deg[N],tot,head[N],nxt[N<<1],adj[N<<1],size,ans[N],ans0[N];
inline void addedge(ri x,ri y){
	nxt[++tot]=head[x];
	adj[head[x]=tot]=y;
}
inline void dfs(ri x,ri fa){
//	printf("dfs %d %d\n",x,fa);
	ri y,i,len=1+deg[x]-(fa!=0),l,r;
	if(len==1)
		++size,
		ans[size]=size;
	else{ 
		l=size+1;r=size+len-1;
		for(i=l+1;i<=r;++i) ans[++size]=i;
		ans[++size]=l;
	} 
	for(i=head[x];i;i=nxt[i])
		if((y=adj[i])!=fa&&deg[y]>1){
			dfs(y,x);
			return;
		}
	++size;
	ans[size]=size;
}
inline bool check(int *p1,int *p2,ri n){
	for(ri i=1;i<=n;++i)
		if(p1[i]!=p2[i])
			return p1[i]<p2[i];
	return false;
}
int main(){
	ri n,i,x,y,cnt,s,t;
	gi(n);
	if(n==2) return puts("1 2"),0;
	for(i=1;i^n;++i)
		gi(x),gi(y),
		++deg[x],++deg[y],
		addedge(x,y),
		addedge(y,x);
	s=t=0;
	for(x=1;x<=n;++x)
		if(deg[x]>1){
			cnt=0;
			for(i=head[x];i;i=nxt[i])
				cnt+=deg[adj[i]]>1;
			if(cnt>2) return puts("-1"),0;
			if(cnt<=1){
				if(!s)
					s=x;
				else
					t=x;
			}
		}
	for(i=head[s];i;i=nxt[i])
		if(deg[x=adj[i]]==1)
			break;
	size=0;
	dfs(x,0);
	if(t){
		for(i=1;i<=n;++i) ans0[i]=ans[i];
		for(i=head[t];i;i=nxt[i])
			if(deg[x=adj[i]]==1)
				break;
	//	printf("check %d\n",x);
		size=0;
		dfs(x,0);
	//	for(i=1;i<=n;++i) printf("%d ",ans[i]);
	//	puts("");
		if(check(ans0,ans,n))
			for(i=1;i<=n;++i) ans[i]=ans0[i]; 
	}
	for(i=1;i<=n;++i) print(ans[i]),putc(' ');
	putc('\n');//*/
	return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e15+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll N;
	ll a[1005];

	cin >> N;
	rep(i,N) cin >> a[i];

	pair<ll,vector<int>> ans = {-INF, vector<int>(0)};
	ll dp[1005][1005] = {};
	queue<pair<ll,vector<int>>> que[1005];
	que[1].emplace(a[0], vector<int>(0));
	reps(i,2,N) que[i].emplace(-INF, vector<int>(0));
	reps(i,1,N){
		while( !que[i].empty() ){
			chmax(ans, que[i].front() );
			auto u = que[i].front().X;
			auto v = que[i].front().Y;
			que[i].pop();
			{
				auto _v = v;
				_v.push_back(0);
				if( que[i+1].empty() || que[i+1].front().X < a[i] ){
					if(!que[i+1].empty()) que[i+1].pop();
					que[i+1].emplace(a[i], _v);
				}
			}
			for(int j=1; i+j*2<=N; j++){
				auto _v = v;
				_v.push_back(j);
				//que[i+j*2].emplace(u + a[i+j*2-1], _v);
				if( que[i+j*2].empty() || que[i+j*2].front().X < u + a[i+j*2-1] ){
					if(!que[i+j*2].empty()) que[i+j*2].pop();
					que[i+j*2].emplace(u + a[i+j*2-1], _v);
				}
			}
		}
	}
	while( !que[N].empty() ){
		chmax(ans, que[N].front() );
		que[N].pop();
	}

	cout << ans.X << endl;

	int pos = 0;
	bool f = false;
	vector<int> ope;
	for(auto t: ans.Y){
		//cout << t << ", ";
		if( t == 0 || (t == 1 && f) ){
			ope.push_back(1);
			pos++;
		}else{
			f = false;
			rrep(j,t) ope.push_back(j + 2);
			pos += t*2;
		}
	}
	//cout << endl;
	while(pos < N-1) ope.push_back(N-pos), pos++;

	cout << ope.size() << endl;
	for(auto t: ope) cout << t << endl;

	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

void chmax(int &a,int b) { a=max(a,b); }
void chmin(int &a,int b) { a=min(a,b); }

//-----------------------------------------------------------------------------

int n,m;
int sum;
int t[100];

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

	cin>>n;
	REP(i,n) {
		cin>>t[i];
		sum+=t[i];
	}
	cin>>m;
	REP(i,m) {
		int p,x;cin>>p>>x;p--;
		cout<<sum-t[p]+x<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
<?php
  $n = fgets(STDIN);
  $input = trim(fgets(STDIN));
  $a = explode(" ", $input);
  $count = 0;
  $flg = true;
  while ($flg){
    for ($i=0; $i<$n; $i++){
      if ($a[$i]%2 == 0){
        $a[$i] /= 2;
      }
      else {
        $flg = false;
        echo $count;
        break;
      }
    }
    $count++;
  }
  exit;
?>

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N,A;
    cin>>N>>A;
    
    for(int i=0;i<=A;i++){
        if((N-i)%500==0){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (__typeof(n) i = 0; i < n; i++)
#define repo(i, n) for (__typeof(n) i = 1; i <= n; i++)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
#define a(a)         \
    for (auto i : a) \
        cout << i << " ";
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main()
{
    ll n, x;
    cin >> n;
    vector<pair<ll, ll>> v;
    rep(i, n)
    {
        cin >> x;
        v.pb(mp(x, i + 1));
    }
    sort(v.begin(), v.end());
    rep(i, n)
    {
        cout << v[i].second << " ";
    }
    return 0;
}

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

int gcd(int a,int b){
    if(a<b){
        int now=a;
        a=b;
        b=a;
    }

    int r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }

    return b;
}



/* 値を入れ替える関数 */
void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}




/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
    int n;
    scanf("%d",&n);
    int ans=100;
    int i;
    for(i=0;i<n;i++){
      int a;
      scanf("%d",&a);
      int count=0;
      while(a%2==0){
        a/=2;
        count++;
      }

      if(count<ans){
        ans=count;
      }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int mx = 100005;
const int md = 1e9+7;
int n;
long long k, a[55][55], ans[55][55], an;
bool o = true;

int main(){
    scanf("%d%lld", &n, &k);
    rep(j,n) rep(i,n) scanf("%lld", &a[i][j]);
    while(k){
        if(k&1){
            if(o){
                rep(i,n) rep(j,n) ans[i][j] = a[i][j];
                o = false;
            }else{
                long long tmp[55][55] = {};
                rep(i,n) rep(j,n) rep(k,n) (tmp[i][j] += ans[i][k] * a[k][j]) %= md;
                rep(i,n) rep(j,n) ans[i][j] = tmp[i][j];
            }
        }
        long long tmp[55][55] = {};
        rep(i,n) rep(j,n) rep(k,n) (tmp[i][j] += a[i][k] * a[k][j]) %= md;
        rep(i,n) rep(j,n) a[i][j] = tmp[i][j];
        k /= 2;
    }
    rep(i,n) rep(j,n) an += ans[i][j];
    printf("%lld\n", an%md);
}

Measured memory_bytes: 384
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 6e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double r;
main() {
  file("threesum");
  ios;
  cin >> r;
  double ans = 2.0 * PI * r;
  cout << fixed << setprecision(12) << ans;
  return 0;
}
/**

*/


Measured memory_bytes: 3828
s = input()
start = 0
end = 0
flag1 = True
flag2 = True
for i in range(len(s)):
    if s[i] == "A" and flag1 == True:
        start = i
        flag1 = False
    elif s[i] == "Z":
        end = i
slNnm = (end + 1) - start
print(slNnm)


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

//#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((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())

using namespace std;

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

const int MOD = 1000000007;

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

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    string s;
    cin >> n >> s;

    int ans = 0, x = 0;
    REP(i, n) {
        switch (s[i]){
            case 'I':
                x++;
                break;
            case 'D':
                x--;
                break;
        }
        ans = max(ans,x);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {

  std::string ans;
  for(int i=0; i<3; i++) {
    std::string c; std::cin >> c;
    ans += c[i];
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int N;

	cin >> N;
	int hun, ten, one;
	hun = N / 100;
	ten = (N - (hun * 100)) / 10;
	one = N - ((hun * 100) + (ten * 10));
	if (hun == one)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a,b,c,d;
    scanf("%d %d %d",&a,&b,&c);
    while(a>b||b>c){
        if(a>b){
            d=a;
            a=b;
            b=d;
        }
        if(b>c){
            d=b;
            b=c;
            c=d;
        }
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}

Measured memory_bytes: 1852
#include <iostream>
#include <queue>
#include <string>
using namespace  std;

typedef pair<string, int> PAIR;

void fnInput(int& rnQtm, queue<PAIR>& rqPPrc)
{
  int nMaxProc;
  cin >> nMaxProc >> rnQtm;
  
  for (int i = 0; i < nMaxProc; i++)
  {
    string sPrcNam;
    int nPrcTim;
    cin >> sPrcNam >> nPrcTim;
    rqPPrc.push(PAIR(sPrcNam, nPrcTim));
  }
}

void fnSchedule(int nQtm, queue<PAIR>& rqPPrc)
{
  int nTtlTim = 0;
  while (rqPPrc.size())
  {
    PAIR PProcess = rqPPrc.front(); rqPPrc.pop(); 
    if (PProcess.second > nQtm)
    {
      PProcess.second -= nQtm;
      rqPPrc.push(PProcess);
      nTtlTim += nQtm;
    }
    else
    {
      nTtlTim += PProcess.second;
      cout << PProcess.first << " " << nTtlTim << endl;
    }
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int nQtm;
  queue<PAIR> qPPrc;
  
  fnInput(nQtm, qPPrc);
  fnSchedule(nQtm, qPPrc);

  return 0;
}

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

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

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> s(H+2,vector<char>(W+2,'.'));
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin>>s.at(i).at(j);
    }
  }

  bool flag=true;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(s.at(i).at(j)=='.'){
        continue;
      }
      bool sub_flag=false;
      for(int k=0;k<4;k++){
        if(s.at(i+dx[k]).at(j+dy[k])=='#'){
          sub_flag=true;
        }
      }
      if(!sub_flag){
        flag=false;
        break;
      }
    }
    if(!flag){
      break;
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main(){
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  long long ans=0;
  if(a[0]>x){
    ans+=a[0]-x;
    a[0]=x;
  }
  for(int i=1;i<n;i++){
    if(a[i]+a[i-1]>x){
      ans+=a[i]+a[i-1]-x;
      a[i]=x-a[i-1];
      if(a[i]<0){
        a[i-1]-=a[i];
        a[i]=0;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)



signed main(){
  int h,w,x,y;
  cin>>h>>w>>x>>y;
  if(h*w%2==1&&(x+y)%2==1){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}




Measured memory_bytes: 3100
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  vll as(n);
  rep(i, n) {
    cin >> as[i];
    as[i]--;
  }

  ll ans = 0;
  rep(i, n) {
    if (i == as[as[i]]) ans++;
  }
  ans /= 2;
  cout << ans << endl;

  return 0;
}


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

const int maxn = 100010;
int n, a[maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        bool flag1 = 1, flag2 = 1;
        int j = i;
        for (; j <= n; j++) {
            if (!flag1 && !flag2) break;
            flag1 &= (a[j] <= a[j + 1]);
            flag2 &= (a[j] >= a[j + 1]);
        }
        i = j - 1, ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,-1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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 main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll x;
    cin >> x;
    ll ans = 0;
    ans += (x/500)*1000;
    x %= 500;
    ans += (x/5)*5;
    cout << ans << enld;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
#define tl 1'000'000'007
int mmax= 100000;
void erasuru(vector<int> &A,vector<int>&B){
    
    A[0] = 0; // 0は素数ではない
    A[1] = 0; // 1は素数ではない
    
    for(size_t i=2; i*i<=mmax; ++i) // 0からsqrt(max)まで調べる
        if(A[i]) // iが素数ならば
            for(size_t j=2; i*j<=mmax; ++j) // (max以下の)iの倍数は
                A[i*j] = 0;      // 素数ではない
    vector<int> C;
    C= A;
    for(int i=1; i<=mmax; i+=2){
        if(A[i]==1 && A[(i+1)/2]==0){
            C[i]= 0;
        }
        // cout << i << ":" << A[i] << endl;
    }
    C[2]= 0;
    FOR(i,1,mmax+1){
        // cout << i << ":" << A[i] << endl;
        B[i]= C[i] +B[i-1];
    }
    
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> A(mmax+1,1);
    vector<int> B(mmax+1,0);
    erasuru(A,B);
    int q;
    cin >> q;
    int cnt= 0;
    int a,b;
    vector<int> ans(q);
    // cout << B[1]<< endl;
    // REP(i,54){
    //     cout << i << " : " << B[i] << endl;
    // }
    REP(i,q){
        cin >> a >> b;
        // cout << B[b] << " " << B[a-1]  << endl;
        ans[i]= B[b]-B[a-1];
        cout << ans[i] << endl;
        // return 0;
    }
    // REP(i,q){
    // }
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

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

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<long long> as(n);
    vector<pair<long long, int>> tmp(n);
    for (int i = 0; i < n; ++i) {
        cin >> as[i];
        tmp[i] = make_pair(as[i], i);
    }
    vector<int> index_by_size(n);
    sort(tmp.begin(), tmp.end());
    for (int i = 0; i < n; ++i) {
        index_by_size[i] = tmp[i].second;
    }
    vector<vector<long long>> mem(n, vector<long long>(n, -1LL));
    function<long long (int, int)> calc = [&](int a, int b) {
        if (a > b) return 0LL;
        if (mem[a][b] != -1LL) return mem[a][b];
        int to_place = index_by_size[b - a];
        long long choice_left = abs(a - to_place) * as[to_place] + calc(a + 1, b);
        long long choice_right = abs(b - to_place) * as[to_place] + calc(a, b - 1);
        return mem[a][b] = max(choice_left, choice_right);
    };
    cout << calc(0, n - 1) << endl;
    return 0;
}


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

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

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

const int MAX = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N;

int main(){
    cin >> N;
    cout << N * N * N << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
//#define scanf scanf_s
int main()
{
	int n, i;
	long long sum=0;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)
			sum += i;
	}
	printf("%lld", sum);
}

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

double INF = 1e100;
double EPS = 1e-12;
typedef long long int ll;

typedef pair < int,int > PII;
typedef pair < ll,ll > PLL;
#define F first
#define S second
ostream& operator<<(ostream & os, PLL h)
{
	return os << "( " << h.F << ", " << h.S << " )" << endl;

}
PLL operator+ (PLL a, ll x)     {return {a.F + x, a.S + x} ;}
PLL operator- (PLL a, ll x)     {return {a.F - x, a.S - x} ;}
PLL operator* (PLL a, ll x)     {return {a.F * x, a.S * x} ;}
PLL operator+(PLL x, PLL y) { return {x.F + y.F,x.S + y.S} ;}
PLL operator-(PLL x,PLL y) { return {x.F - y.F, x.S - y.S} ;}
PLL operator*(PLL x,PLL y) { return {x.F * y.F , x.S * y.S} ;}
PLL operator%(PLL x,PLL y) { return {x.F % y.F, x.S % y.S} ;}

PLL base = {37,41};
PLL M = {1e9+21, 1e9+9};

int const N = 1e6 + 5;
int const LOG = 11;


int main(){

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    for(auto &ch : s)
        ch = (char)(((ch -'A' + n) % 26) + 'A');
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define i64 long long int
i64 m[3001][3001];
i64 mp=998244353;
int a[3001];
i64 f(int i,int s)
{
    if((i==0)&&(s==0)) return 1;
    if(i==0) return 0;
    if(m[i][s]!=-1) return m[i][s];
    if(s-a[i]>=0)
        m[i][s]=((2*f(i-1,s))%mp+f(i-1,s-a[i]))%mp;
    else m[i][s]=(2*f(i-1,s))%mp;
    return m[i][s];
}

int main()
{
   int n,s,i,j;
   i64 b;
   scanf("%d %d",&n,&s);
   for(i=1;i<=n;i++) scanf("%d",&a[i]);
   for(i=0;i<=n;i++)
   {
       for(j=0;j<=s;j++)
        m[i][j]=-1;
   }
   b=f(n,s);
   printf("%lld",b);
    return 0;
}


Measured memory_bytes: 72332
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    int E, Y;
    scanf("%d %d", &E, &Y);
    if (E == 0) {
        if (Y < 1912) printf("%c%d\n", 'M', Y-1867);
        else if (Y >= 1912 && Y < 1926) printf("%c%d\n", 'T', Y-1911);
        else if (Y >= 1926 && Y < 1989) printf("%c%d\n", 'S', Y-1925);
        else printf("%c%d\n", 'H', Y-1988);
    }
    else if (E == 1) printf("%d\n", 1867+Y);
    else if (E == 2) printf("%d\n", 1911+Y);
    else if (E == 3) printf("%d\n", 1925+Y);
    else printf("%d\n", 1988+Y);
    return 0;
}




Measured memory_bytes: 2760
#include <stdio.h>

const int MAXN = 3005;

double p[MAXN];
double dp[MAXN][MAXN];
bool used[MAXN][MAXN];
int n;

double solve(int pos, int tails) {
    if (pos >= n) {
        return n - tails > tails;
    }
    if (used[pos][tails]) return dp[pos][tails];

    double& ans = dp[pos][tails];
    ans = p[pos] * solve(pos + 1, tails) + (1 - p[pos]) * solve(pos + 1, tails + 1);
    used[pos][tails] = true;
    return ans;
}

int main(void) {
    scanf(" %d", &n);
    for (int i = 0; i < n; i++) {
        scanf(" %lf", &p[i]);
    }
    double ans = solve(0, 0);
    printf("%.12f\n", ans);

    return 0;
}


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

int main()
{
	double N, h, n, w;

	cin >> N;

	for (h = 1; h <= 3500; h++) {
		for (n = 1; n <= 3500; n++) {
			if (4 / N - 1 / h - 1 / n > 0) {
				long long int w2 = 1 / (4 / N - 1 / h - 1 / n);
				if (w2 <= 350000) {
					w = w2;
					if (w > 0 && 4 / N == 1 / h + 1 / n + 1 / w) {
						cout << h << " " << n << " " << w << endl;
						return 0;
					}
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int main(void){
    int N, i, temp, ans;
    scanf("%d", &N);
    vector<int> p;
    for(i=0; i<N; i++){
        scanf("%d", &temp);
        p.push_back(temp);
    }
    auto itr=max_element(p.begin(), p.end());
    temp=*itr;
    *itr=temp/2;
    ans=accumulate(p.begin(), p.end(), 0);
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 256