akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main(){
    std::vector<pair<float, int> > valuelst;
    std::vector<long long> value;
    long long x;
    for(int i=0; i!=4; i++){
        scanf("%lld", &x);
        valuelst.push_back(make_pair(float(x)*pow(2, 2-i), i));
        value.push_back(x);
    }
    sort(valuelst.begin(), valuelst.end());

    long long N;
    scanf("%lld", &N);
    N*=4;
    long long cost=0;
    for(int i=0; i!=4; i++){
        int t = valuelst[i].second;
        cost+=value[t]*(N/(0x1<<t));
        N%=(0x1<<t);
        if(N==0) break;
    }
    printf("%lld\n", cost);
    return 0;
}

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

#define Long long long

int main(){
  int n;
  cin >> n;
	set<string> S;
 	while(n--){
      string a;
	  cin >> a;
      S.insert(a);
    }
  cout << S.size() ;
  return 0;
}

Measured memory_bytes: 19140
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main(){
  int n, m; cin >> n >> m;
  vector<vector<pii>> v(n); v1i a(n), b(n, 1e7); b[0] = 0;
  rep(i, m){
    int a, b; cin >> a >> b; --a; --b;
    v[a].push_back({b, 1}); v[b].push_back({a, 1});
  }
  deque<int> d;
  d.push_back(0);
  int tmp;
  while(!d.empty()){
    tmp = d.front();
    d.pop_front();
    for(auto e: v[tmp]){
      if(b[tmp] + 1 < b[e.fi]){
        b[e.fi] = b[tmp] + 1;
        a[e.fi] = tmp + 1;
        d.push_back(e.fi);
      }
    }
  }
  cout << "Yes\n";
  rep(i, n-1) cout << a[i+1] << "\n";
  return 0;
}

Measured memory_bytes: 12584
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int a, b;
    cin >> a >> b;
    if(a == b){
        cout << "Draw" << endl;
    } else {
        if(a == 1){
            cout << "Alice" << endl;            
        } else if(b == 1){
            cout << "Bob" << endl;            
        } else {
            if(a > b){
                cout << "Alice" << endl;            
            } else {
                cout << "Bob" << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    XY = [[int(x) for x in input().split()] for _ in range(N)]

    arr1 = []
    arr2 = []
    for x, y in XY:
        arr1.append(x - y)
        arr2.append(x + y)

    print(max(abs(max(arr1) - min(arr1)), abs(max(arr2) - min(arr2))))





if __name__ == '__main__':
    main()


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

#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;

const int N = 100005;

int n, m, x, y, z;
vector <int> g[N];

int used[N];
void dfs(int v) {
    used[v] = 1;
    for (int i : g[v]) {
        if (used[i] == 0) {
            dfs(i);
        }
    }
}

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> x >> y >> z;
        g[x].pb(y);
        g[y].pb(x);
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
        if (used[i] == 0) {
            dfs(i);
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 9216
use strict;
use warnings;

main();

sub main {
	my $in = <STDIN>;
	my $out = 0;

	$out += int($in/100);
	$in  -= 100*int($in/100);
   	$out += int($in/10);
	$in  -= 10*int($in/10);
   	$out += $in;
	
	printf("%d\n",$out);

	1;
}


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
	int a, b, add, sub, mul, max;
  	scanf("%d%d", &a, &b);
  	add = a + b; sub = a - b; mul = a * b;
	max = add;
  	if (max < sub) max = sub;
  	if (max < mul) max = mul;
  	
  	printf("%d", max);
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1
MOD = 10 ** 9 + 7


S = input().rstrip()
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1  # 桁数

for i in range(len(S)):
    x = S[-(i + 1)]
    if x == '?':
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= MOD
    else:  # 数字
        k = int(x)
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= MOD
    mul = mul * 10 % 13

print(dp[len(S)][5])


Measured memory_bytes: 62300
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;


int main() {
    int A,B,C;

    cin >> A >> B >> C;
    int amari = A%B;
    bool can =false;

    for(int i=0;i<B;i++){
        can = ((amari*(i+1))%B==C);
        if(can)break;
    }

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


}



Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int cnt,cnt1,N,num[50],sum=0,b=0;
	scanf("%d",&N);
	for(cnt=0;cnt<N;cnt++){
		scanf("%d",&num[cnt]);
	}
	for(cnt=0;cnt<N;cnt++){
		for(cnt1=b;cnt1<N;cnt1++){
			if(cnt==cnt1){
				continue;
			}else{
				sum+=(num[cnt]*num[cnt1]);
			}
		}
		b++;
	}
	printf("%d",sum);
}


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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-12;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=50000;
    rep(y,1,P){
        ll x=mod(y*k);
        
        if(abs(x)<=P||x+P>=i_7){
            if(x+P>=i_7){
                x-=i_7;
            }
            cout<<x<<"/"<<y<<endl;
            //cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
typedef vector<ll> vl;
//////////////////////////


bool b[3][3];
void yes(){
    cout<<"Yes";
    exit(0);
}

int main(){fastio
    ll a[3][3];
    rep(i,0,2)rep(j,0,2)cin>>a[i][j];
    ll n;cin>>n;
    while(n--){
        ll k;cin>>k;
        rep(i,0,2)rep(j,0,2){
            if(a[i][j]==k)b[i][j]=true;
        }
    }
    rep(i,0,2){
        bool f=true;
        rep(j,0,2)if(!b[i][j])f=false;
        if(f)yes();
    }
    rep(j,0,2){
        bool f=true;
        rep(i,0,2)if(!b[i][j])f=false;
        if(f)yes();
    }
    {
        bool f=true;
        rep(j,0,2){
            if(!b[j][j])f=false;
        }
        if(f)yes();
    }
    {
        bool f=true;
        rep(j,0,2){
            if(!b[2-j][j])f=false;
        }
        if(f)yes();
    }
    cout<<"No";
    
    return 0;
}


Measured memory_bytes: 3640
//file_name:ABC105_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&y);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);
    ll m;
    cin >> m;
    ll a[n+1] = {};
    ll sum[n+1] = {};
    srep(i,1,n+1){
        scanf("%lld",&a[i]);
        sum[i] = sum[i-1]+a[i];
        sum[i] %= m;
    }
    sort(sum,sum+n+1);

    
    ll ans = 0;
    ll count = 1;
    srep(i,1,n+1){
        if(sum[i]==sum[i-1]){
            count++;
        }else{
            ans += (count*(count-1))/2;
            count = 1;
        }
    }
    ans += (count*(count-1))/2;



    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
main()
{
    int q;
    long long int n,p;
    vector <int> A;
    cin>>q;
    while(q--)
    {
    cin>>n;
    if(n==0)
    {
        cin>>p;
        A.push_back(p);
    }
    else if(n==1)
    {
        cin>>p;
        cout<<A[p]<<endl;
    }
    else
        A.pop_back();
    }
}



Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
const long long MOD =1000000000+7;
void solve(int a){cout<<( a?"Yes":"No")<<endl;}

int main()
{
	int h,w;
	int ans=0;
	
	cin >> h >> w;
	vector<string> s(h + 1, "");
	vector<vector<int>> up(h+1,vector<int>(w+1,0));
	vector<vector<int>> down(h + 1, vector<int>(w + 1, 0));
	vector<vector<int>> left(h + 1, vector<int>(w + 1, 0));
	vector<vector<int>> right(h + 1, vector<int>(w + 1, 0));
	vector<vector<int>> dp(h + 1, vector<int>(w + 1, 0));
	for (int i = 0; i < h; i++)
	{
		cin >>s[i];
	}

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(s[i][j] == '.'){
				left[i][j] =1+((j==0)?0:left[i][j-1]);
				up[i][j]=1+((i==0)?0:up[i-1][j]);
				//cout<<left[i][j]<<" ";
			}
		}
	}

	for (int i = h-1; i >= 0; i--)
	{
		for (int j = w-1; j >= 0; j--)
		{
			if (s[i][j] == '.')
			{
				right[i][j] = 1 + ((j == w-1) ? 0 : right[i][j + 1]);
				down[i][j] = 1 +( (i == h-1) ? 0 : down[i + 1][j]);
			}
		}
	}

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			chmax(ans,up[i][j]+down[i][j]+right[i][j]+left[i][j]-3);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 82944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    double n, k;
    cin >> n >> k;

    double ans = 0;
    rep(i, 1, n + 1) {
        double tmp = i;
        double p = 1;
        if (i >= k) ans += (1 / n);
        else {
            while (tmp < k) {
                tmp *= 2;
                p *= 0.5;
            }
            ans += (1 / n) * p;
        }
    }
    cout << setprecision(12) << ans << endl;
    return 0;
}


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

#define endl '\n'
#define endt '\t'
#define ends ' '
#define die(x) return cout << x << endl, 0;
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << '[' << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7; 

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

const int MAXN = 5e5 + 5;

typedef basic_string<int> bint;
bint N;

bint F(int x) {
	bint X;
	while (x) {
		X.push_back(x % 10);
		x /= 10;
	}
	return X;
}
bint Sum(bint A, bint B) {
	if (sz(A) < sz(B)) swap(A, B);
	while (sz(B) < sz(A)) B.push_back(0);
	bint C(sz(A) + 1, 0);
	for (int i = 0; i < sz(A); i++) {
		int c = C[i] + A[i] + B[i];
		C[i] = c % 10;
		C[i + 1] = c / 10;
	}
	if (C.back() == 0) C.pop_back();
	return C;
}
bint Mul9(bint A) {
	bint C(sz(A) + 1, 0);
	for (int i = 0; i < sz(A); i++) {
		int c = C[i] + 9 * A[i];
		C[i] = c  % 10;
		C[i + 1] = c / 10;
	}
	if (C.back() == 0) C.pop_back();
	return C;
}
void Print(bint A) { reverse(all(A)); for (int i : A) cerr << i; cerr << endl; }
bool IsVal(int k) {
	bint M = Mul9(Sum(N, F(k)));
	int s = 0;
	for (int i : M) s += i;
	return s <= 9 * k;
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	#ifdef LOCAL
	ifstream cin("sample.in");
	#endif

	string S; cin >> S; reverse(all(S));
	for (char c : S) N.push_back(c - '0');

	int dw = 0, up = sz(S);
	while (up - dw > 1) {
		int md = (dw + up) >> 1;
		if (IsVal(md)) up = md;
		else dw = md;
	}
	cout << up << endl;

	return 0;
}

Measured memory_bytes: 14660
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster
    int x,ans;

    for(int i=1; i<=5; i++)
    {
        cin>>x;

        if(x==0)
            ans=i;
    }

    cout<<ans<<endl;




    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int cnt=0;
    for (int i=1;i<=n;i++)
    {
        getchar();
        for (int j=1;j<=m;j++)
        {
            char ch=getchar();
            if (ch=='#') cnt++;
        }
    }
    puts((cnt == n+m-1)?"Possible":"Impossible");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int N_size;
char N[110];
int K;

ll rec(int i, int p, bool high) {
    if(i >= N_size) return (p >= K) ? 1LL : 0LL;
    if(p >= K) return 1LL;
    ll k = N[i] - '0';
    if(high){
        ll res = 0LL;
        res += rec(i+1, p, (k > 0 ? false : true));
        if(k > 1) res += (k-1LL)*rec(i+1, p+1, false);
        if(k > 0) res += rec(i+1, p+1, true);
        return res;
    }
    
    return rec(i+1, p, false) + 9*rec(i+1, p+1, false);
}

void solve(){
    ll res = 0;
    int k = N[0] - '0';
    res = rec(1, 0, false) + (k-1)*rec(1, 1, false) + rec(1, 1, true);
    printf("%lld\n", res);
}

int main()
{
    scanf("%s", N);
    scanf("%d", &K);
    N_size = strlen(N);
    solve();
    return 0;
}

Measured memory_bytes: 256
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
10
ZABCDBABCQ
---+/
/+---test
33
ABCCABCBABCCABACBCBBABCBCBCBCABCB
---+/

void main(string[] args) {
  const N = readln.chomp.to!long;
  const S = readln.chomp;

  long ans;
  long offset;
  while (true) {
    const x  = S[offset..$].indexOf("ABC");
    if (x == -1) break;
    offset += x + 1;
    ++ans;
  }
  ans.writeln;
}


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

int main() {
  int H,W;
  cin >> H >> W;
  vector <string> s(H) ;
  for ( int i=0 ; i<H ; i++){
    cin >> s.at(i) ;
  }
  for ( int i=0 ; i< W+2 ; i++ ) {
    cout << '#' ;
  }
  cout << endl ;
  for ( int i=0 ; i<H ; i++){
  cout << '#' << s.at(i) << '#' << endl;
  }
  for ( int i=0 ; i< W+2 ; i++ ) {
    cout << '#' ;
  }
  cout << endl ;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, a, b) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << '\n';

template <class T> vector<T> xor_span(vector<T> a) {
  int k = 0;
  for (int i = 0; i < 8 * int(sizeof(T)); i++) {
    auto p = find_if(a.begin() + k, a.end(), [i](T x) { return x & T(1) << i; });
    if (p == a.end()) continue;
    swap(a[k], *p);
    for (int j = 0; j < int(a.size()); j++)
      if (j != k && (a[j] & T(1) << i)) a[j] ^= a[k];
    k++;
  }
  return a.resize(k), a;
}

bool check(LL x, vector<LL> v) {
  while (x) {
    auto p = find_if(v.begin(), v.end(), [x](LL y) { return x & y; });
    if (p == v.end()) return false;
    x ^= *p;
    LL tt = *p;
    for (auto &y: v) y ^= tt;
    *p = v.back();
    v.pop_back();
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  vector<LL> a(n);
  FI(i,0,n-1) scanf("%lld", &a[i]);
  LL ans = 0;
  for (LL x: a) ans ^= x;
  LL mask = 0;
  for (int i = 61; i >= 0; --i) {
    if (1LL << i & ans) continue;
    LL nmask = mask | 1LL << i;
    vector<LL> b;
    for (LL x: a) {
      LL y = x & nmask;
      if (y) b.push_back(y);
    }
    auto v = xor_span(b);
    LL tmp = 0;
    for (auto x: v) tmp ^= x;
    if (tmp == nmask) mask = nmask;
  }
  cout << ans + mask * 2LL << endl;
}


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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 2010;
const int mod = 1e9+7;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,k;

int f[maxn][maxn];

int fac[maxn*maxn],inv[maxn*maxn];

int Cnk(int n,int k){
	return 1LL*fac[n]*inv[k]%mod*inv[n-k]%mod;
}

void Work(){
	if(k==1)return void(puts("1"));
	f[n+1][n+1]=1;
	RREP(i,n+1,1)
		RREP(j,n,1)if(i>=j){
			if(i<=n)f[i][j]=f[i+1][j];
			if(i>j)f[i][j]=(f[i][j]+1LL*f[i][j+1]*Cnk(n-i+(n-j+1)*(k-1),k-2))%mod;
			//cout<<i<<' '<<j<<' '<<f[i][j]<<endl;
		}
	REP(i,1,n)f[1][1]=1LL*f[1][1]*i%mod;
	iout(f[1][1]);
}

void Init(){
	read(n,k);
	fac[0]=1;REP(i,1,n*k)fac[i]=1LL*fac[i-1]*i%mod;
	REP(i,0,n*k)inv[i]=fexp(fac[i],mod-2);
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 47488
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;

int i,j,k,m,n,a,b,c;

int main(){
    scanf("%d%d%d",&a,&b,&c);
    for(i=1;i<=1000;i++){
        if((a*i)%b==c){
    		printf("YES");
            return 0;
        }
    }
    printf("NO");
    return 0;
}

Measured memory_bytes: 256
# 木の深さ優先探索
import sys

sys.setrecursionlimit(100000+10)


def add_edge(u, v, distance ):
	G[u].append([v, distance])
	G[v].append([u, distance])

def dfs(vertex, distance_from_start):
	global colors

	colors[vertex] = distance_from_start % 2

	for info in G[vertex]:
		v = info[0]
		if colors[v] >= 0: 
			#探索済み
			pass
		else:
			dfs(v, distance_from_start + info[1])

n = int(input())
edges = [list(map(int, input().split())) for _ in range(n-1)]

G = [[] for _ in range(n)] #グラフの隣接リスト表現
for edge in edges:
	add_edge(edge[0]-1, edge[1]-1, edge[2])

colors = [-1] * n
colors[0] = 0

dfs(0, 0)

for i in range(n):
	print(colors[i])


Measured memory_bytes: 106420
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, l;
    cin >> n >> l;
    int a[n], b[n], c[n];
    rep(i, n) {
        a[i] = l + i;
        b[i] = abs(l + i);
        c[i] = abs(l + i);
        //cout << b[i] << endl;
    }
    sort(b, b + n);
    //rep(i, n)cout << b[i] << endl;
    int j = 0;
    rep(i, n) if(c[i] == b[0]) j = i;
    int sum = 0;
    rep(i, n){
        if(i != j) sum += a[i];
    }
    cout << sum << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define clr(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=100010;
int n;
ll a[maxn],ans,maxx,tep,b[maxn];
priority_queue<ll >qmax;
priority_queue<ll ,vector<ll>,greater<ll> >qmin;
void cal(){
	ans=0;
	ll p1=qmin.top(),p2=qmin.top();
	qmin.pop();
	int flag=0;
	while((!qmin.empty())||(!qmax.empty())){
		if(flag==0){
			flag=1;
			if(!qmax.empty()){
				ans+=abs(qmax.top()-p1);
				p1=qmax.top();
				qmax.pop();
			}
			if(!qmax.empty()){
				ans+=abs(qmax.top()-p2);
				p2=qmax.top();
				qmax.pop();
			}
		}else if(flag==1){
			flag=0;
			if(!qmin.empty()){
				ans+=abs(qmin.top()-p1);
				p1=qmin.top();
				qmin.pop();
			}
			if(!qmin.empty()){
				ans+=abs(qmin.top()-p2);
				p2=qmin.top();
				qmin.pop();
			}
		}
	}
	maxx=max(maxx,ans);
}
int main() {
	cin>>n;
	ans=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=(n/2);i++){
		qmin.push(a[i]);
	}
	for(int i=(n/2)+1;i<=n;i++)
	{
		qmax.push(a[i]);
	}
	cal();
	for(int i=1;i<=(n-n/2);i++){
		qmin.push(a[i]);
	}
	for(int i=(n-n/2)+1;i<=n;i++)
	{
		qmax.push(a[i]);
	}
	cal();
	printf("%lld\n",maxx);
}

Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int h,w,k;
    cin >> h >> w >> k;
    vector<vector<int>> a(h+1, vector<int>(w+1, 0));
    for(int i=0;i<h;++i) {
        string s;
        cin >> s;
        for(int j=0;j<w;++j) {
            if(s[j] == '1') a[i+1][j+1] = 1;
        }
    }

    for(int i=1;i<=h;++i) {
        for(int j=1;j<=w;++j) {
            a[i][j] += a[i-1][j] + a[i][j-1] - a[i-1][j-1];
        }
    }

    int ans = INF;
    for(int bi=0;bi<(1<<(h-1));++bi) {
        int tmpans = 0;
        for(int i=0;i<h;++i) {
            if(bi & (1<<i)) ++tmpans;
        }
        int prev_j = 0;
        vector<int> cutj;
        for(int j=1;j<=w-1;++j) {
            int prev_i = 0;
            bool needs_cut = false;
            for(int i=1;i<=h;++i) {
                int cnt_ij = a[i][j+1] - a[i][prev_j] - a[prev_i][j+1] + a[prev_i][prev_j];
                if(cnt_ij > k) {
                    needs_cut = true;
                    break;
                }
                if(bi & (1<<(i-1))) {
                    prev_i = i;
                }
            }
            if(needs_cut) {
                ++tmpans;
                prev_j = j;
                cutj.push_back(j);
            }
        }

        cutj.push_back(w);
        bool is_ok = true;
        prev_j = 0;
        for(int j: cutj) {
            int prev_i = 0;
            for(int i=1;i<=h&&is_ok;++i) {
                if(i == h || (bi & (1<<(i-1)))) {
                    int cnt_ij = a[i][j] - a[i][prev_j] - a[prev_i][j] + a[prev_i][prev_j];
                    if(cnt_ij > k) {
                        is_ok = false;
                    }
                    prev_i = i;
                }
            }
            prev_j = j;
        }
        if(is_ok) {
            ans = min(tmpans, ans);
        }
        // cerr << bitset<5>(bi) << ": " << tmpans << endl;
    }

    cout << ans << endl;
}


Measured memory_bytes: 384
#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 <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
#include <complex>
typedef complex<double> P;
int main() {
	int query;
	cin >> query;
	REP(i, query) {
		double a, b, c, d, e, f, g, h;
		cin >> a >> b >> c >> d >> e >> f >> g >> h;
		P line1 = P(c - a, d - b);
		P line2 = P(g - e, h - f);
		double hoge = line1.real() * line2.imag() - line1.imag() * line2.real();
		if (abs(hoge) < eps) {
			cout << 2 << endl;
			continue;
		}
		hoge = line1.real() * line2.real() + line1.imag() * line2.imag();
		if (abs(hoge) < eps) {
			cout << 1 << endl;
			continue;
		}
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 3228
N = int(input())
S = input()
r = []
g = []
b = []
for i in range(N):
    if S[i] == 'R':
        r.append(i)
    elif S[i] == 'G':
        g.append(i)
    else:
        b.append(i)
ans = 0
R = len(r)
G = len(g)
for i in range(R):
    for j in range(G):
        x = r[i]
        y = g[j]
        if x > y:
            x, y = y, x
        num = len(b)
        if 2 * x - y >= 0 and S[2 * x - y] == 'B':
            num -= 1
        if (x+y)%2 == 0 and S[(x+y)//2] == 'B':
            num -= 1
        if 2 * y - x < N and S[2 * y - x] == 'B':
            num -= 1
        ans += num
print(ans)

Measured memory_bytes: 70052
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
    ll n;
    cin>>n;
	ll a[n],sum=0;
	ll freq[100005];
	rep(i,0,100005)freq[i]=0;
	rep(i,0,n){
		cin>>a[i];
		sum+=a[i];
		freq[a[i]]++;
	}
	ll q;
	cin>>q;
	while(q--){
		ll b,c;
		cin>>b>>c;
		sum=sum-freq[b]*b+freq[b]*c;
		ll temp=freq[b];
		freq[b]=0;
		freq[c]+=temp;
		cout<<sum<<endl;
	}
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


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

int sum[555][555];

int main(){
  int N,M,Q; cin>>N>>M>>Q;
  rep(i,M){
    int L,R; cin>>L>>R; L--, R--;
    sum[L][R]++;
  }
  rep(i,N) rep(j,N) sum[i][j+1]+=sum[i][j];
  rep(i,N) for(int j=N;j>0;j--) sum[j-1][i]+=sum[j][i];
  while(Q--){
    int p,q; cin>>p>>q; p--,q--;
    cout<<sum[p][q]<<endl;
  }
  return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
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; }

int main(){
    char s[200001];
    scanf("%s",s);
    int sz=strlen(s),sum=0;
    vector<int> v(sz),vv(sz),vsum(sz+1);
    v[0]=1;
    vsum[0] =0;

    for(int i=0; i<sz; ++i){
        if(i!=0) v[i] = (v[i-1]*10)%2019;
        vv[i] = (v[i]*((int)s[sz-i-1] -48))%2019;
        vsum[i+1] = (vsum[i]+vv[i])%2019;
    }

    vector<int> smap(2019);
    rep(i,sz+1){
        ++smap[vsum[i]];
    }
    rep(i,2019){
        if(smap[i]!=0){
            int tmp=smap[i];
            sum+=tmp*(tmp-1)/2;
        }
    }

    
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 5780
#                           जय श्री राम

import sys; import math; from collections import *
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, input().split())
def get_list(): return list(get_ints())
def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")

UGLYMOD = int(1e9+7); SEXYMOD = 998244353; MAXN = int(1e5)

#sys.stdin  = open("input.txt","r"); sys.stdout = open("output.txt","w")

# for _testcases_ in range(int(input())):
n = input()
if n >= 'a' and n <= 'z':
    print('a')
else:
    print('A')


'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )
Link may be copy-pasted here if it's taken from other source.
DO NOT PLAGIARISE.
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

const bool key[26] = {
	1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1
};

int main() {
	string s;
	while (cin >> s, s != "#") {
		int ans = 0;
		int num = s[0] - 'a';
		bool pre = key[num];
		REP(i, 1, s.size()) {
			num = s[i] - 'a';
			if (pre != key[num]) {
				ans++;
				pre = key[num];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// get a integer
		String N = sc.next();
		String output = "";
		
		for (int i = 0; i < N.length(); i++) {
			int output_size = output.length();
			if(N.charAt(i) == 'B') {
				if(output_size > 0) {
					output = output.substring(0, output_size - 1);
				}
			} else {
				output = output + N.substring(i, i+1); 
			}
			
		}
				
		// output
		System.out.println(output);
	}
}

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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  LL dp[n+1][4][4][4];
  for(int j=0;j<4;j++){
    for(int k=0;k<4;k++){
      for(int l=0;l<4;l++){
        dp[0][j][k][l]=1;
      }
    }
  }
  dp[0][1][2][0]=dp[0][1][0][2]=dp[0][2][1][0]=0;
  for(int i=1;i<=n-3;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
        for(int l=0;l<4;l++){
          dp[i][j][k][l]=0;
          for(int m=0;m<4;m++){
            dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][k][l][m])%MOD;
          }
        }
      }
    }
    dp[i][1][2][0]=dp[i][1][0][2]=dp[i][2][1][0]=0;
    for(int j=1;j<4;j++){
      if(j!=2)
      dp[i][1][j][2]=(dp[i][1][j][2]-dp[i-1][j][2][0]+MOD)%MOD;
    }
    for(int j=1;j<4;j++){
      dp[i][1][2][j]=(dp[i][1][2][j]-dp[i-1][2][j][0]+MOD)%MOD;
    }
  }
  LL ans=0;
  for(int j=0;j<4;j++){
    for(int k=0;k<4;k++){
      for(int l=0;l<4;l++){
        ans=(ans+dp[n-3][j][k][l])%MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
  	int n,a;
  	char ch;
  
 	cin >> n;
  
    vector<int> s(13,0),h(13),c(13),d(13);
  
  	for(int i = 0;i < n;i++){
      cin >> ch >> a;
      
      switch(ch){
        case 'S' : s.at(a-1)++;break;
        case 'H' : h.at(a-1)++;break;
        case 'C' : c.at(a-1)++;break;
        case 'D' : d.at(a-1)++;break;
      }
      
    }
  
  	for(int i = 0;i < 13;i++){
      if(s.at(i) == 0)
        cout << "S "<< i+1 << endl;
    }
	for(int i = 0;i < 13;i++){
      if(h.at(i) == 0)
        cout << "H " << i+1 << endl;
    }
 	for(int i = 0;i < 13;i++){
      if(c.at(i) == 0)
        cout << "C " << i+1 << endl;
    }
	for(int i = 0;i < 13;i++){
      if(d.at(i) == 0)
        cout << "D " << i+1 << endl;
    }
}


Measured memory_bytes: 3108
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n; cin >> n;
    int p[30]; rep(i, n) cin >> p[i];
    int cnt = 0;
    rep1(i, n - 2) {
        if(p[i - 1] < p[i] && p[i] < p[i + 1]) {
            cnt ++; continue;
        }
        else if(p[i - 1] > p[i] && p[i] > p[i + 1]) {
            cnt ++; continue;
        }
    }
    cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N;
vector<Int> A,B;

int main(void) {
    cin>>N;

    for(int i = 0;i <= N;i++) {
        Int a;
        cin>>a;
        A.push_back(a);
    }
    for(int i = 0;i < N;i++) {
        Int b;
        cin>>b;
        B.push_back(b);
    }

    Int ans = 0;
    for(int i = 0;i < N;i++) {
        Int t;
        t = min(A[i],B[i]);
        ans += t;
        B[i] -= t;
        t = min(A[i+1],B[i]);
        A[i+1] -= t;
        ans += t;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 2676
import heapq

N,M = list(map(int,input().split()))
works = [list(map(int,input().split())) for i in range(N)]

works.sort()
day = 1
ans = 0
candidates = []
for work in works:
    if work[0] == day:
        heapq.heappush(candidates,-work[1])
    else:
        if M < work[0]:
            break
        while day < work[0]:
            if candidates:
                ans += -heapq.heappop(candidates)
            day += 1
        heapq.heappush(candidates,-work[1])

while day <= M:
    if candidates:
        ans += -heapq.heappop(candidates)
    day += 1

print(ans)

Measured memory_bytes: 31596
#include<stdio.h>

struct edge{
		int from;
		int to;
		int cost;
};

struct edge es[2000];

int d[1000];
int n,m;
int co[100][100];
#define inf 200000000
#define min(a,b) ((a)<(b)?(a):(b))

void shortest(int s){
		int i;
		int f=0;
		for(i=0;i<=n;i++)d[i]=inf;
		d[s]=0;
		while(1){
				f=0;
				for(i=0;i<m;i++){
						struct edge e;
						e.from=es[i].from;
						e.to=es[i].to;
						e.cost=es[i].cost;
						if(d[e.from]!=inf&&d[e.to]>d[e.from]+e.cost){
								d[e.to]=d[e.from]+e.cost;
								f=1;
						}if(d[e.to]!=inf&&d[e.from]>d[e.to]+e.cost){
								d[e.from]=d[e.to]+e.cost;
								f=1;
						}
				}
				if(f==0)break;
		}
		for(i=0;i<n;i++){
				co[s][i]=min(co[s][i],d[i]);
				co[i][s]=co[s][i];
		}
}
int main(){
		int i,j;
		scanf("%d%d",&n,&m);
		for(i=0;i<m;i++){
				scanf("%d%d%d",&es[i].from,&es[i].to,&es[i].cost);
				es[i].from--;
				es[i].to--;
			}
		for(i=0;i<100;i++){
				for(j=0;j<100;j++){
						co[i][j]=inf;
				}
		}
		for(i=0;i<n;i++)shortest(i);
		int ans=m,anss[1000]={0};
		for(i=0;i<m;i++){
			for(j=0;j<n;j++){
				if(co[j][es[i].from]+es[i].cost==co[j][es[i].to])anss[i]=1;
			}
		}
		for(i=0;i<m;i++){
			ans-=anss[i];
		}
		/*for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				printf("%d,",co[i][j]);
			}puts("");
		}*/
		printf("%d\n",ans);
		return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

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

	int res = 0;
	int M = H[0];
	for(int i = 0; i < N; i++){
		if(M <= H[i]) res++;
		M = max(M, H[i]);
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  string O,E;
  cin >> O >> E;

  for(int i=0;i<E.size();++i) cout << O.at(i) << E.at(i);
  if(O.size()!=E.size()) cout << O.at(O.size()-1);
  cout << endl;

  return 0;
}


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


#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";

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



template <class T> inline T biton(T n, T pos)
{
    return n | ((T)1 << pos);
}
template <class T> inline T bitoff(T n, T pos)
{
    return n & ~((T)1 << pos);
}
template <class T> inline T ison(T n, T pos)
{
    return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b)
{
    while (b)
    {
        a = a % b;
        swap(a, b);
    }
    return a;
}
template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
};

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif


void solve()
{
    int n;
    cin>>n;

    set<int> st;

    for(int i=0;i<n;i++){
        int it;
        cin>>it;
        st.insert(it);
    }

    if(n==st.size()){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int t = 1;

    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<vector<int>> A(3,vector<int>(N));
  for(int i=0;i<3;i++){
    for(int j=0;j<N;j++){
      cin >> A[i][j];
    }
    sort(A[i].begin(),A[i].end());
  }
  vector<vector<long long>> cumsum(3,vector<long long>(N+1)); // count, cumsum
  for(int j=0;j<N;j++) cumsum[2][j]=N-j;
  for(int i=1;i>=0;i--){
    for(int j=N-1;j>=0;j--){
      int k=upper_bound(A[i+1].begin(),A[i+1].end(),A[i][j])-A[i+1].begin();
      cumsum[i][j]=cumsum[i][j+1]+cumsum[i+1][k];
    }
  }
  cout<<cumsum[0][0];
  return 0;
}

Measured memory_bytes: 4600
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define N 200002
const int p=1e9+7;
struct node
{
    int s[2][2];
    friend node operator*(node a,node b)
    {
        node ret;memset(ret.s,0,sizeof(ret.s));
        for(int i=0;i<2;i++)for(int j=0;j<2;j++)for(int k=0;k<2;k++)
        ret.s[i][j]=(ret.s[i][j]+1ll*a.s[i][k]*b.s[k][j]%p)%p;return ret;
    }
}dw,md,st;
int n,m;
ll k;
char ch[1002][1002],s[1002][1002];
inline int ksm(int d,ll tk){int ret=1;while(tk){if(tk&1)ret=1ll*ret*d%p;d=1ll*d*d%p;tk>>=1;}return ret;}
inline node ksmm(node d,ll tk){node ret=dw;while(tk){if(tk&1)ret=ret*d;d=d*d;tk>>=1;}return ret;}
int main()
{
    scanf("%d%d%lld",&n,&m,&k);
    for(int i=1;i<=n;i++)scanf("%s",ch[i]+1);
    bool ud=false,lr=false;
    for(int i=1;i<=m;i++)if(ch[1][i]=='#'&&ch[n][i]=='#')ud=true;
    for(int i=1;i<=n;i++)if(ch[i][1]=='#'&&ch[i][m]=='#')lr=true;
    int ct=0,s1=0,s2=0;
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(ch[i][j]=='#')ct++;
    if((!ud)&&(!lr)){printf("%d\n",ksm(ct,k-1));return 0;}
    if(ud&&lr){puts("1");return 0;}
    if(ud)
    {
        for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)s[j][i]=ch[i][j];
        swap(n,m);
        for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)ch[i][j]=s[i][j];
    }dw.s[0][0]=dw.s[1][1]=1;
    for(int i=1;i<=n;i++)for(int j=1;j<m;j++)if(ch[i][j]=='#'&&ch[i][j+1]=='#')s1++;
    for(int i=1;i<=n;i++)if(ch[i][1]=='#'&&ch[i][m]=='#')s2++;
    md.s[0][0]=ct,md.s[0][1]=s1,md.s[1][1]=s2;st.s[0][0]=ct,st.s[0][1]=s1;
    if(k==1){puts("1");return 0;}
    md=ksmm(md,k-2);st=st*md;
    printf("%d\n",(st.s[0][0]-st.s[0][1]+p)%p);
}


Measured memory_bytes: 5708