akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      sx: i64,
      sy: i64,
      tx: i64,
      ty: i64,
    }
    debug!(sx, sy, tx, ty);

    let mut dy = 1;
    while sy + dy <= ty {
        print!("{}", 'U');
        dy += 1;
    }

    let mut dx = 1;
    while sx + dx <= tx {
        print!("{}", 'R');
        dx += 1;
    }

    let mut dy = -1;
    while ty + dy >= sy {
        print!("{}", 'D');
        dy -= 1;
    }

    let mut dx = -1;
    while tx + dx >= sx {
        print!("{}", 'L');
        dx -= 1;
    }


    // 2
    print!("{}", 'L');
    let mut dy = 1;
    while sy + dy <= ty+1 {
        print!("{}", 'U');
        dy += 1;
    }

    let mut dx = 1;
    while sx - 1 + dx <= tx {
        print!("{}", 'R');
        dx += 1;
    }
    print!("{}", "DR");

    let mut dy = -1;
    while ty + dy >= sy-1 {
        print!("{}", 'D');
        dy -= 1;
    }

    let mut dx = -1;
    while tx + 1 + dx >= sx {
        print!("{}", 'L');
        dx -= 1;
    }
    print!("{}", 'U');
    println!();
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x,y,z,k;
  cin>>x>>y>>z>>k;
  vector<ll>a(x),b(y),c(z);
  rep(i,x)cin>>a[i];
  rep(i,y)cin>>b[i];
  rep(i,z)cin>>c[i];
  vector<ll>ab(x*y),ans(k*z);
  rep(i,x)rep(j,y)
  {
    ll tab=a[i]+b[j];
    ab[i*y+j]=tab;
  }
  sort(all(ab),greater<ll>());
  ab.resize(k);
  rep(i,k)rep(j,z)
  {
    ans[i*z+j]=ab[i]+c[j];
  }
  sort(all(ans),greater<ll>());
  rep(i,k)
  {
    cout<<ans[i]<<"\n";
  }
  cout<<flush;
  return 0;

}


Measured memory_bytes: 31744
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define ll long long 
ll n;
ll dig(ll x)
{
	if (x < 10)
	{
		return x;
	}
	int sum = 0;
	while (x)
	{
		sum += x % 10;
		x /= 10;
	}
	return sum;
}
int main()
{
	cin >> n;
	ll t = n;
	ll cnt = dig(n);
	if (t%cnt == 0)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n, d, ans = 0;
    scanf("%d %d", &n, &d);
    ans = n / (2 * d + 1);
    if(n % (2 * d + 1) != 0){
        ans++;
    }
    printf("%d\n", ans);
    
    return 0;
}

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

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

vector<int> p(n);
for (int i = 0; i < n; i++) {
    cin >> p.at(i);
}

int ans = 0;
for (int i = 0; i < n - 2; i++) {
    if ((p.at(i + 1) > p.at(i) && p.at(i + 1) < p.at(i + 2)) || (p.at(i + 1) < p.at(i) && p.at(i + 1) > p.at(i + 2))) {
        ans++;
    }
}
cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	char x;
	cin>>x;
	if(x>=65 && x<=90)
	cout<<"A"<<"\n";
	else if(x>=97 && x<=122)
	{
		cout<<"a"<<"\n";
	}
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vector<P> p(n);
  rep(i, n) cin >> p[i].first >> p[i].second;
  sort(all(p));
  ll a;
  bool ra = false;
  if(n % 2)
    a = p[n / 2].first;
  else {
    if((p[n / 2 - 1].first + p[n / 2].first) % 2) ra = true;
    a = (p[n / 2 - 1].first + p[n / 2].first) / 2;
  }
  rep(i, n) swap(p[i].first, p[i].second);
  sort(all(p));
  ll b;
  bool rb = false;
  if(n % 2)
    b = p[n / 2].first;
  else {
    if((p[n / 2 - 1].first + p[n / 2].first) % 2) rb = true;
    b = (p[n / 2 - 1].first + p[n / 2].first) / 2;
  }
  ll ans;
  if(n % 2) {
    ans = b - a + 1;
  } else {
    ans = (b - a) * 2 + 1;
    if(ra) ans--;
    if(rb) ans++;
  }
  cout << ans << endl;
}

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

using ll = int64_t;

#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 ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, m; std::cin >> n >> m;
  vi wacnt(n), isAC(n);
  rep(i, m) {
    int p; std::cin >> p;
    string s; std::cin >> s;
    p--;
    if (s[0] == 'A')
      isAC[p] = true;
    else if (!isAC[p])
      wacnt[p]++;
  }
  int wa = 0, ac = 0;
  rep(i, n) {
    if (isAC[i]) ac++, wa += wacnt[i];
  }
  std::cout << ac << ' ' << wa << "\n";
}


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

map<int,int> val;
int a,d;
int f(int x){
	if( !val.count(x) ) val[x] = a+(x-1)*d;
	return val[x];
}


signed main(){
	string s;
	cin >> s;
	map<char,int> v;
	for( auto c : s ){
		v[c]++;
	}
	int ans = 0;
	while(true){
		int ok = 0;
		for(int i = 'a' ; i <= 'z' ; i++){
			int len = 0;
			if(v[i]){
				
				ok = 1;
				int cnt = 0;
				for(int j = i ; j <= 'z' ; j++){
					if( v[j] == 0 ) break;
					v[j]--;
					cnt++;
				}
				ans += min(cnt,3);
				break;
			}
		}
		if(!ok) break;
	}
	while(true){
		int ok = 0;
		for(int i = '0' ; i <= '9' ; i++){
			int len = 0;
			if(v[i]){
				ok = 1;
				int cnt = 0;
				for(int j = i ; j <= '9' ; j++){
					if( v[j] == 0 ) break;
					v[j]--;
					cnt++;
				}
				ans += min(cnt,3);
				break;
			}
		}
		if(!ok) break;
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<long long> A;
    for (auto i = 0; i < N; i++)
    {
        long long x;
        cin >> x;
        A.push_back(x);
    }

    sort(A.begin(), A.end());
    int mcounter = 0;
    for (int i = 0; i < N; i++)
    {
        if (A[i] < 0)
            mcounter++;
        else
        {
            break;
        }    
    }
    long long max = 0;
    long long Abs=1000000000;
    for (int i = 0; i < N; i++)
    {
        Abs=min(Abs,abs(A[i]));
        max += abs(A[i]);
    }
    if (mcounter % 2 == 0){
        cout <<max <<endl;
        return 0;
    }
    else{
        max=max-2*Abs;
        cout <<max <<endl;
        return 0;
    }
   
    return 0;
}


Measured memory_bytes: 1400
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a) cout<<k;
	else if(k<=(a+b)) cout<<a;
	else if(k<=(a+b+c)) cout<<a-(k-(a+b));
	else cout<<a-c;
	cout<<endl;
}
signed main()
{
	
		/***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/
 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
		
	}
	TIME
	return 0;
}

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

using namespace std;

int main(){
	string s;

	while(cin>>s){
		int ans=0;
		if(s=="#")break;

		int num[35]={0};
		
		string r="yuiophjklnm";

		for(int i=0;i<s.size();i++){
			for(int j=0;j<r.size();j++){
				if(s[i]==r[j]){
					num[i]=1;
					break;
				}
			}
		}

		for(int i=0;i<s.size()-1;i++){
			if(num[i]!=num[i+1])ans++;
		}
		cout<<ans<<endl;

	}

	return 0;
}

Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	for(int i=0;i<=x;i++){
		if(i*4+(x-i)*2==y){
			cout<<"Yes"<<endl;
			return(0);
		}
	}
	
	cout<<"No"<<endl;
return(0);
}

Measured memory_bytes: 3632
N = int(input())
alist = list(map(int,input().split()))
gray , brown ,green , sky , blue , yellow , orange  ,red , top = 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
for a in alist:
    if a < 400:
        gray += 1
    elif a < 800:
        brown += 1
    elif a < 1200:
        green += 1
    elif a < 1600:
        sky += 1
    elif a < 2000:
        blue += 1
    elif a < 2400:    
        yellow += 1
    elif a < 2800:  
        orange += 1
    elif a < 3200:
        red += 1
    else:
        top += 1  
cmin = 0
cmax = 0
if  gray > 0:
    cmin += 1
    cmax += 1
if  brown > 0:
    cmin += 1
    cmax += 1
if  green > 0:
    cmin += 1
    cmax += 1
if  sky > 0:
    cmin += 1
    cmax += 1
if  blue > 0:
    cmin += 1
    cmax += 1
if  yellow > 0:
    cmin += 1
    cmax += 1
if  orange > 0:
    cmin += 1
    cmax += 1
if  red > 0:
    cmin += 1
    cmax += 1
if  top > 0:
    if cmin == 0:
        cmin += 1
    cmax += top
print(cmin ,cmax)

Measured memory_bytes: 3064
/*
問題: "Breadth First Search"
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C&lang=jp
所要時間: 30分
学んだこと: 幅優先探索の実装はキューを用いて行えばよいこと。
着席位置: 左・中央
*/

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

//constexpr int Inf = 1 << 30;

class Graph {
protected:
	vector< vector<int> > adjl;
public:
	Graph(int n) : adjl(n) {}
	void PushAdjl(int pl, int val) { adjl[pl].push_back(val); }
};

class BFGraph : public Graph {
private:
	vector<int> distance;
	queue<int> que;
public:
	BFGraph(int n) : Graph(n), distance(n, -1) {}
	void BreadthFirstSearch(int begin);
	void ShowDistanceAll();
};

void BFGraph::BreadthFirstSearch(int begin = 0) {
	que.push(begin);
	distance[begin] = 0;
	while (!que.empty()) {
		int f = que.front();
		que.pop();
		for(auto i = adjl[f].begin();i!=adjl[f].end();++i)
			if (distance[*i] == -1) {
				que.push(*i);
				distance[*i] = distance[f] + 1;
			}
	}
}

void BFGraph::ShowDistanceAll() {
	for (int i = 0; i < distance.size(); i++)
		cout << i + 1 << " " << distance[i] << endl;
}

int main() {
	int n;
	cin >> n;
	BFGraph bfg(n);
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int t;
			cin >> t;
			bfg.PushAdjl(u-1, t-1);
		}
	}
	bfg.BreadthFirstSearch();
	bfg.ShowDistanceAll();
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

vector<set<int>> mm;
vector<set<int>> km;

vector<bool> seen;
vector<int> group_memo;
vector<int> group_size;
int group_id = 0;

void rec(int person)
{
  seen[person] = true;
  group_memo[person] = group_id;
  group_size[group_id]++;
  for (auto next : mm[person])
  {
    if (seen[next] == false) rec(next);
  }
  return;
}

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

  mm.assign(n + 1, set<int>());
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    mm[a].insert(b);
    mm[b].insert(a);
  }

  km.assign(n + 1, set<int>());
  for (int i = 0; i < k; i++)
  {
    int c, d;
    cin >> c >> d;
    km[c].insert(d);
    km[d].insert(c);
  }

  seen.assign(n + 1, false);
  group_memo.assign(n + 1, -1);
  group_size.assign(n + 1, 0);

  for (int i = 1; i <= n; i++)
  {
    if (seen[i] == false)
    {
      rec(i);
    }
    group_id++;
  }

  for (int i = 1; i <= n; i++)
  {
    if (group_memo[i] == -1)
    {
      cout << 0 << endl;
      continue;
    }

    int ans = group_size[group_memo[i]] - 1;
    for (auto m : mm[i])
    {
      if (group_memo[m] == group_memo[i]) ans--;
    }
    for (auto k : km[i])
    {
      if (group_memo[k] == group_memo[i]) ans--;
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 30848
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double D,T,S;
    scanf("%lf %lf %lf",&D,&T,&S);
    float x=D/S;
    if(x<=T)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 3808
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int n;

int main() {

	cin >> n;

	if (n % 2 == 1) {
		cout << (n / 2 + 1) / (double)(n) << endl;
	}
	else {
		cout << 0.5 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

vector <int> ans[100001];

int main(){
    int N, M;
    cin >> N >> M;
    vector <int> P, Y;
    
    for(int i = 0; i < M; i++){
        int sub;
        cin >> sub;
        P.push_back(sub);
        cin >> sub;
        Y.push_back(sub);
        ans[P[i]].push_back(Y[i]);
    }

    for(int i = 1; i <= N; i++){
        sort(ans[i].begin(), ans[i].end());
    }
    
    for(int i = 0; i < M; i++){
        cout << setfill('0') << setw(6) << P[i];
        cout << setfill('0') << setw(6) << int(lower_bound(ans[P[i]].begin(), ans[P[i]].end(), Y[i]) - ans[P[i]].begin()) + 1 << "\n";
    }
}

Measured memory_bytes: 7792
n, m = [int(i) for i in input().split()]
data = [int(i) for i in input().split()]

if len(data) < m:
  print('No')
  exit()

total = sum(data)

data.sort(reverse=True)

for d in data[:m]:
  if d < total / (4 * m):
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n,k,i,h,ans=0;
  cin >> n >> k;
  for (i=0;i<n;i++){
    cin >> h;
    if (h>=k) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,A,B;
  cin>>X>>A>>B;
  if(A-B>=0)
    cout<<"delicious"<<endl;
  else if(B-A<=X)
    cout<<"safe"<<endl;
  else
    cout<<"dangerous"<<endl;
 
}


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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;
using vb=vector<bool>;using vs=vector<string>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<typename T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<'('<<p.fst<<", "<<p.snd<<')';}
template<class T>ostream&operator<<(ostream&o,const vector<T>&t){o<<"{";rep(i,sz(t))o<<t[i]<<",";o<<"}";return o;}
#define out(args...){vector<string> a_r_g_s=__split(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> __split(const string& s,char c){vector<string>v;stringstream ss(s);string x;while(getline(ss,x,c))v.emplace_back(x);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T,typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){if(*it==" 1"||*it=="1")cerr<<endl;else cerr<<it->substr((*it)[0]==' ',it->length())<<" = "<<a<<", ";e_r_r(++it, args...);}

void Main() {
  int n = read<int>();
  vector<int> A(n);
  rep(i, n) A[i] = read<int>();

  map<int, int> co;
  forr(a, A) co[a]++;

  int o = 0, e = 0;
  forr(nc, co) {
    if (nc.snd % 2) o++;
    else e++;
  }
  int m = e % 2;

  int ans = o + e - m;

  cout << ans << endl;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 5376
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
typedef long long ll;

int n,m,q,ans;
vector<int> a,b,c,d;

void dfs(vector<int> v){
    if(v.size()==n+1){
        int sum=0;
        for(int i=0;i<q;i++){
            if(v[b[i]]-v[a[i]]==c[i]) sum+=d[i];
        }
        ans=max(ans,sum);
        return;
    }
    v.push_back(v.back());
    while(v.back()<=m){
        dfs(v);
        v.back()++;
    }
}

int main(){
    cin>>n>>m>>q;
    a=b=c=d=vector<int>(q);
    for(int i=0;i<q;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    dfs(vector<int>(1,1));
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main()
{
  int n;
  cin >> n;
  if (n % 1000 == 0)
    cout << "0" << endl;
  else
    cout << 1000 - (n % 1000) << endl;
}


Measured memory_bytes: 3632
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x/GCD(x,y)*y;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{

int N,M;
cin>>N>>M;

map<int,int> A;

int K;
int L;

rep(i,N){
cin>>K;
rep(j,K){
cin>>L;
++A[L-1];
}
}

int x=0;

rep(i,M) if(A[i]==N){++x;}

cout<<x<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using L = long long;
#define F first
#define S second
#define I XH[i]
#define R for(L i=0;i<N;i++)
#define W P.front
using V= pair<L,L>;

L N,D,A,n=0,r=0,t;
V XH[200005];
queue<V>P;
int main() {cin>>N>>D>>A;R{cin>>I.F>>I.S;}sort(XH,XH+N);R{while(!P.empty()&&P.front().F<I.F){n-=P.front().S;P.pop();}I.S-=n;if(I.S>0){t=(I.S+A-1)/A;r+=t;P.push({I.F+2*D,t*A});n+=t*A;}}cout<<r;} 

Measured memory_bytes: 4992
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

const int MAXN = 100005;
const int MAXD = 15;

int visited[MAXN][MAXD], color[MAXN];

const int MAXQ = 100005;
int qv[MAXQ], qd[MAXQ], qc[MAXQ];

int n, m, q;

vector< vector<int> > adj;

void dfs(int u, int d, int c) {
    visited[u][d] = 1;

    if (!color[u]) color[u] = c;

    if (d == 0) return;

    for (auto& v : adj[u]) {
        if (!visited[v][d-1]) {
            dfs(v, d-1, c);
        }
    }
}

int main() {
    GI(n);
    GI(m);

    adj.resize(n+1);

    int a, b;

    FORN(i, m) {
        GI(a);
        GI(b);

        adj[a].PB(b);
        adj[b].PB(a);
    }

    memset(visited, 0, sizeof visited);
    memset(color, 0, sizeof color);

    GI(q);

    FORN(i, q) {
        GI(qv[i]);
        GI(qd[i]);
        GI(qc[i]);
    }

    FORD(i, q) {
        if (!visited[qv[i]][qd[i]]) {
            dfs(qv[i], qd[i], qc[i]);
        }
    }

    FOR1(i, n) {
        printf("%d\n", color[i]);
    }

    return 0;
}

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

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define BASE 77747
#define PI acos(-1.0)
#define MAXLEN 29

typedef std::pair <int, int> pii;
typedef long long ll;
typedef std::vector <ll> vll;

using namespace std;

ll add(ll a, ll b) {
	return (a + b) % MOD;
}
ll mul(ll a, ll b) {
	return (a * b) % MOD;
}

ll pp[100001];
ll a[100000], b[100000], c[100000];
string str;

int main() {
	pp[0] = 1;
	for (int i = 1; i <= 100000; i++) pp[i] = mul(pp[i - 1], 3);
	cin >> str;
	ll cur = 0, all = 0;
	for (int i = 0; i < str.length(); i++) if (str[i] == '?') all++;
	for (int i = 0; i < str.length(); i++) {
		if (i == 0) {
			if (str[i] == 'A') a[i] = 1;
			else if (str[i] == '?') {
				cur++;
			}
			continue;
		} 
		a[i] = a[i - 1];
		b[i] = b[i - 1];
		c[i] = c[i - 1];
		if (str[i] == 'A')
			a[i] = add(a[i - 1], 1);
		else if (str[i] == 'B') 
			b[i] = add(b[i - 1], add(mul(a[i - 1], pp[cur]), mul(cur, pp[max(0LL, cur - 1)]))); 
		else if (str[i] == 'C')
			c[i] = add(c[i - 1], mul(b[i - 1], pp[all - cur]));
		else {
			c[i] = add(c[i - 1], mul(b[i - 1], pp[all - cur - 1]));
			b[i] = add(mul(b[i - 1], 3), add(mul(a[i - 1], pp[cur]), mul(cur, pp[max(0LL, cur - 1)]))); 
			cur++;
		}
	}
	cout << c[str.length() - 1] << endl;
	return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include <iomanip>

int main(){

    int a, b;
    std::cin >> a >> b;

    int d = a / b;
    int r = a % b;
    double f = (double) a / (double) b;

    std::cout << d << " " << r << " ";
    std::cout << std::fixed << std::setprecision(7) << f << std::endl;

    return 0;
}


Measured memory_bytes: 3284
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
ll longinf=1ll<<60;
int inf=1<<29;
int dh[]={1,-1,0,0};
int dw[]={0,0,1,-1};
//mleしなければぜんぶllでかく。

int main(){
      cin.tie(0);
      ios::sync_with_stdio(false);
      ll k,a,b;
      cin>>k>>a>>b;
      if(a>=b-1){
            cout<<k+1<<endl;
      }
      else{
            if(k<a){
                  cout<<k+1<<endl;
            }
            else{
                  ll nowbis=1;
                  k-=(a-1);
                  nowbis=a;
                  //cout<<nowbis<<endl;
                  nowbis+=((k/2)*(b-a));
                  //cout<<nowbis<<endl;
                  k-=((k/2)*2);
                  nowbis+=k;
                  cout<<nowbis<<endl;
            }
      }
      return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int cnt[8];
int h,w,n,sx,sy;
char s[200005],t[200005];
int main()
{
	scanf("%d%d%d%d%d",&h,&w,&n,&sx,&sy);
	scanf("%s",&s);
	scanf("%s",&t);
	for(int i=0;i<n;i++)
	{
		if(s[i]=='L')
		cnt[0]++;
		if(s[i]=='R')
		cnt[1]++;
		if(s[i]=='U')
		cnt[2]++;
		if(s[i]=='D')
		cnt[3]++;
		if(sy-cnt[0]+cnt[5]<=0)
		{
			cout << "NO" << endl;
			return 0;
		}
		if(sy+cnt[1]-cnt[4]>w)
		{
			cout << "NO" << endl;
			return 0;
		}
		if(sx-cnt[2]+cnt[7]<=0)
		{
			cout << "NO" << endl;
			return 0;
		}
		if(sx+cnt[3]-cnt[6]>h)
		{
			cout << "NO" << endl;
			return 0;
		}
		if(t[i]=='L'&&sy-cnt[4]+cnt[1]-1>0)
		cnt[4]++;
		if(t[i]=='R'&&sy+cnt[5]+1-cnt[0]<=w)
		cnt[5]++;
		if(t[i]=='U'&&sx-cnt[6]-1+cnt[3]>0)
		cnt[6]++;
		if(t[i]=='D'&&sx+cnt[7]+1-cnt[2]<=h)
		cnt[7]++;
	}
	cout << "YES" << endl;
    return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    char C[H][W];
    long long D[H][W], M=1000000007;
    for (int i = 0; i < H; i++)
    {
        for (int y = 0; y < W; y++)
        {
            cin >> C[i][y];
        }
    }
    D[0][0] = 1;
    for (int i = 0; i < H; i++)
    {
        for (int y = 0; y < W; y++)
        {
            if (C[i][y] == '.' && (i != 0 || y != 0))
            {
                if (i == 0)
                {
                    D[i][y] = D[i][y-1] % M;
                }
                else if (y == 0)
                {
                    D[i][y] = D[i-1][y] % M;
                }
                else
                {
                    D[i][y] = (D[i-1][y]+D[i][y-1]) % M;
                }
            }
            else if (i != 0 || y != 0)
            {
                D[i][y] = 0;
            }
        }
    }
    cout << D[H-1][W-1];
    return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main(){
    int m, n;
    cin >> n >> m;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int sum = 0,count = 0;
    for (int i = 0; i < n; i++)
        sum += a[i];
    for (int i = 0; i < n; i++)
        if (4 * m * a[i] >= sum)
            count++;
    if(count >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int i,x,y,z,a;
	x=2001;
	y=2001;
	for(i=0;i<3;i++){
		cin>>a;
		if(x>a) x=a;
	}
	for(i=0;i<2;i++){
		cin>>a;
		if(y>a) y=a;
	}
	z=x+y-50;
	cout<<z<<endl;
	return 0;
}



Measured memory_bytes: 3116
INF=9999999

n=int(input())
dp=[INF for i in range(n+1)]
dp[-1]=0
for i in range(n,0,-1):
    e6=1
    while 6**e6<=i:
        dp[i-6**e6]=min(dp[i]+1,dp[i-6**e6])
        e6+=1
    e9=1
    while 9**e9<=i:
        dp[i-9**e9]=min(dp[i]+1,dp[i-9**e9])
        e9+=1
ans=INF
for i in range(n):
    if dp[i]==0:
        continue
    ans=min(ans,i+dp[i])
if ans==INF:
    ans=n
print(ans)


Measured memory_bytes: 3864
#include<bits/stdc++.h> 
using namespace std; 
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define forp(i,a,b) for (int i = a; i <b; i++)
#define forn(i,a,b) for (int i = a; i >b; i--)
#define mod 1000000007
#define PI 3.14159265
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;


long long int fact(long long int n)
{
  if(n==0 || n==1)
  return 1;
  else
  return (n*fact(n-1)%mod)%mod;
}

int prime(long long int n)
{
  for(int i=2;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      return 0;
    }
  }
  return 1;
}

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

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

int check_palin(string s)
{
  string str=s;
  reverse(str.begin(),str.end());
  if(str==s)
  return 1;
  else 
  return 0;
}

  
// Function to find the permutations 
// void findPermutations(int a[], int n) 
// { 
  
//     // Sort the given array 
//     sort(a, a + n); 
  
//     // Find all possible permutations 
//     cout << "Possible permutations are:\n"; 
//     do { 
//         forp(i,0,n)
//           cout<<a[i]<<" ";
//         cout<<"\n"; 
//     } while (next_permutation(a, a + n)); 
// }

int main() 
{ 
  fast_io

int n,m,k,ans=1,c=0;
cin>>n>>k;
string s[n];

forp(i,0,n)
cin>>s[i];

sort(s,s+n);

forp(i,0,n)
cout<<s[i];
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#include<math.h>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const ll N= 1e8;
inline void fastio()
{ 
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i <= s.length();i++)
        {
            if(s[i]!=t[i])
                ans++;
        }
    cout << ans;
    return 0;
}



Measured memory_bytes: 3916
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((s)),(s).begin(),TL<char>)
# define UPPER(s)    transform(ALL((s)),(s).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n, k, l, a[202020];
LL cnt[202020];
template<class V> struct BIT {
	BIT() {}  // [L, R)
	int NV; vector<V> bit; BIT(int n) { init(n); }void init(int n) { NV = 1; while (NV<n)NV *= 2; bit.resize(NV); }
	V operator[](int e) { V s = 0; e++; while (e) s += bit[e - 1], e -= e&-e; return s; }
	void add(int e, V v) { e++; while (e <= NV) bit[e - 1] += v, e += e&-e; }
	int lower_bound(V val) {
		V tv = 0; int i, ent = 0; for (i = NV - 1; i >= 0; i--)
			if (tv + bit[ent + (1 << i) - 1] <= val)tv += bit[ent + (1 << i) - 1], ent += (1 << i); return ent;
	}
	V sum(int L, int R) {
		V res = 0; if (R) res += operator[](R - 1); if (L) res -= operator[](L - 1); return res;
	}
	void clear() { bit.clear(); }
};

LL calc(int mid) {
	BIT<LL> bit(n+1);
	bit.add(0, 1);
	REP(i, min(n, k - 1)) {
		if (i) cnt[i] = cnt[i - 1];
		else cnt[i] = 0;
		if (a[i] <= mid) cnt[i]++;
	}

	LL ret = 0;
	for (int r = k - 1; r < n; r++) {
		cnt[r] = cnt[r - 1];
		if (a[r] <= mid) cnt[r]++;
		bit.add(cnt[r - k + 1], 1);
		if (0 <= cnt[r] - k + 1) ret += bit.sum(0,cnt[r] - k + 1);
	}
	return ret;
}

int main() {
	cin >> n >> k >> l;
	REP(i, n)cin >> a[i];
	int left = 0, right = n;
	while (right - left > 1) {
		int mid = (left + right) / 2;
		if (l <=calc(mid))right = mid;
		else left = mid;
	}
	cout << right << endl;
}


Measured memory_bytes: 8272
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -9999999999
for i in range(1, 2 ** 10):
    s = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if i >> k & 1 and F[j][k] == 1:
                cnt += 1
        s += P[j][cnt]
    ans = max(ans, s)
print(ans)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<tuple<string,int,int>> a(N);
  for(int i=0;i<N;i++){
    get<2>(a.at(i))=i+1;
    cin >> get<0>(a.at(i)) >> get<1>(a.at(i));
  }
  for(int i=0;i<N;i++)
    get<1>(a.at(i))=100-get<1>(a.at(i));
  sort(a.begin(),a.end());
  for(int i=0;i<N;i++)
    cout << get<2>(a.at(i)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  long  N, A, B;
  cin >> N >> A >> B;
  
  if(N % (A + B) <= A){
    cout << N / (A + B) * A + N % (A + B) << endl;
  }
  
  else if(N % (A + B) > A){
    cout << N / (A + B) * A + A << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 200000
int main(){
  int i=0,minv=0,R[N],j=0,n=0,maxv=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
  }
  minv=R[0];
  maxv=R[1]-R[0];
  for(j=1;j<=n-1;j++){
    if(maxv<R[j]-minv) maxv=R[j]-minv;
    if(minv>R[j]) minv=R[j];
  }
  printf("%d\n",maxv);
  return 0;
}

Measured memory_bytes: 1376
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b;
	if(a+b==3) cout<<3<<endl;
	if(a+b==4) cout<<2<<endl;
	if(a+b==5) cout<<1<<endl;
	return 0;
	
 } 

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

using namespace std;

string f(char c) {
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
        return "vowel";
    }

    return "consonant";
}

int main() {

    char c;
    cin >> c;

    string result = f(c);
    cout << result << endl;

    return 0;
}


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

int main() {
  int A, B, C, D, left, right;
  cin >> A >> B >> C >> D;
  left = A + B;
  right = C + D;
  if(left == right){
    cout << "Balanced" << endl;
  }
  if(left < right){
    cout << "Right" << endl;
  }
  if(left > right){
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 3604
def reverse_polish_notation(exp):
    priority = {'+':0,'-':0,'/':1,'*':1}
    exp = deque(exp)
    stack = deque()
    buffer = deque()
    
    while len(exp):
        token = exp.pop()
        if token.isnumeric():
            buffer.append(token)
        elif token == '(':
            while True:
                token = stack.pop()
                if token == ')':
                    break
                buffer.append(token)
        elif token == ')':
            stack.append(token)
        else:
            while len(stack):
                if stack[-1] == ')' or priority[stack[-1]] <= priority[token]:
                    break
                buffer.append(stack.pop())
            stack.append(token)
    
    while len(stack):
        buffer.append(stack.pop())
        
    return buffer    

def power(x, n, p):
    if n == 0:
        return 1
    res = power(x * x % p, n // 2, p)
    if n & 1:
        res = res * x % p
    return res

from collections import deque
def getval(p, exp):
    exp = reverse_polish_notation(exp)
    stack = deque()
    while len(exp):
        token = exp.popleft()
        if token.isnumeric():
            stack.append(int(token))
        else:
            a, b = stack.pop(), stack.pop()
            if token == '+':
                stack.append((a + b) % p)
            elif token == '-':
                stack.append((a - b) % p)
            elif token == '*':
                stack.append((a * b) % p)
            elif token == '/':
                if b == 0:
                    stack.append(float('nan'))
                else:
                    stack.append((a * power(b, p - 2, p)) % p)

    return stack.pop()

import sys
import math
import re
f = sys.stdin


pattern = re.compile('(\d+|\D)')
while True:
    p, exp = f.readline().split(':')
    if p == '0':
        break
    exp = ''.join(exp.split()).strip()
    
    val = getval(int(p), pattern.findall(exp))
    if math.isnan(val):
        print('NG')
    else:
        print('{} = {} (mod {})'.format(exp, val, p))

Measured memory_bytes: 8824
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    long long oo = 0xffffffffffff;

    int A, B, Q;
    cin>>A>>B>>Q;
    vector<long long> s(A+4);
    s[0] = -oo;
    s[1] = -oo+1;
    for (int i=0; i<A; i++)
        cin>>s[i+2];
    s[A+2] = oo-1;
    s[A+3] = oo;
    vector<long long> t(B+4);
    t[0] = -oo;
    t[1] = -oo+1;
    for (int i=0; i<B; i++)
        cin>>t[i+2];
    t[B+2] = oo-1;
    t[B+3] = oo;

    auto index = [&](vector<long long> &v, long long x)
    {
        return (int)(lower_bound(v.begin(), v.end(), x) - v.begin());
    };

    for (int i=0; i<Q; i++)
    {
        long long x;
        cin>>x;

        long long ans = oo;
        for (int b=0; b<8; b++)
        {
            int st = b&1;
            int d1 = b>>1&1;
            int d2 = b>>2&1;

            vector<long long> &v1 = st==0 ? s : t;
            vector<long long> &v2 = st==0 ? t : s;

            long long x2 = v1[index(v1, x)-d1];
            long long x3 = v2[index(v2, x2)-d2];
            ans = min(ans, abs(x-x2)+abs(x2-x3));
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
//#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
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; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << "NO" << endl;return 0
#define MM <<" "<<
#define Endl endl
int MOD;

int BE(int b,int e){
    int r=1;
    while(e){
        if(e&1){
            r=(r*b)%MOD;
        }
        b=(b*b)%MOD;
        e >>=1;
    }
    return r;
}


vector<int> coefficient_construction(vector<pair<int,int>> A){
    int N=A.size();
    vector<int> x(N),y(N);
    map<int,int> inv_memo;
    vector<int> P(N,0),Q(N,0),R(N+1,0),Rt(N+1,0),Rh(N+1,0);
    for(int i=0;i<N;i++){
        x[i]=A[i].first;
        y[i]=A[i].second;
    }
    for(int i=0;i<N;i++){
        Q[i]=y[i];
    }
    for(int i=0;i<N;i++){
        for(int k=0;k<N;k++){
            if(i==k)continue;
            int tmp=(x[i]-x[k]+MOD)%MOD;
            if(inv_memo[tmp]==0){
                inv_memo[tmp]=BE(tmp,MOD-2);
            }
            Q[i]=(Q[i]*inv_memo[tmp])%MOD;
        }
    }
    R[0]=1;
    for(int j=0;j<N;j++){
        for(int i=0;i<N;i++){
            Rt[i]=R[i];
            R[i]=0;
        }
        for(int i=0;i<j+2;i++){
            if(i==0){
                R[0]=(-(Rt[0]*x[j])%MOD+MOD)%MOD;//jはx_j
            }else{
                R[i]=(Rt[i-1]-((Rt[i]*x[j])%MOD) + MOD)%MOD;
            }
        }
    }
    for(int j=0;j<N;j++){
        for(int i=0;i<N+1;i++){
            Rh[i]=0;
        }
        for(int i=N-1;i>=0;i--){
            if(i==N-1){
                Rh[N-1]=R[N];
            }else{
                Rh[i]=(R[i+1]+(Rh[i+1]*x[j])%MOD)%MOD;
            }
        }
        for(int i=0;i<N;i++){
            P[i]=(P[i]+((Q[j]*Rh[i])%MOD))%MOD;
        }
    }
    return P;
}

signed main(void){
    int p;
    int A[3141];
    vector<pair<int,int>> X;
    vector<int> Y;
    cin >> p;
    MOD=p;
    REP(i,p){
        cin >> A[i];
    }
    REP(i,p){
        X.push_back({i,A[i]});
    }
    Y= coefficient_construction(X);
    REP(i,Y.size()){
        cout << Y[i] << " ";
    }cout << endl;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF (1<<30);

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

  ll ans = 0LL;
  ll cnt = 1LL;
  while (H > 0LL) {
    H /= 2LL;
    ans += cnt;
    cnt *= 2LL;
  }

  cout << ans << endl;


  return 0;
}


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

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

cout<<cnt<<endl;
// system("pause");
return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
-- import Data.List
-- rInt s = read s :: Int

main = do
   ls <- zip [1..] .lines <$> getContents
   mapM putStrLn $ map (\(i,l) -> "Case " ++ (show i) ++ ": " ++ l) $ takeWhile (\(i,l) -> l /= "0") ls

Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  sort(d);
  int ans = 0;
  for(int i=d.front();i<=d.back();i++){
    auto lb = lower_bound(d.begin(),d.end(),i);
    if(lb == d.begin() + n/2) ans ++;
    if(lb > d.begin() + n/2) break;
  }
  cout << ans << endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


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

    int n;
    cin >> n;

    ll work = 0;
    bool f = true;

    vector<P> vp;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        vp.emplace_back(b, a);
    }

    sort(all(vp));

    rep(i, n){
        work += vp[i].second;
        if(work > vp[i].first){
            f = false;
            break;
        }
    }


    cout << (f ? "Yes" : "No") << endl;


    return 0;
}



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

int main(){
  int N;
  string A,B,C; 
  cin >> N >> A >> B >> C;
  int cnt = 0;
  for(int i = 0; i < N; i++){
    if(A[i] == B[i]){
      if(A[i] != C[i]){
        cnt++;
      }
    } else {
      if(A[i] != C[i]){
        if(B[i] != C[i]){
          cnt += 2;
         } else {
          cnt++;
        }
       } else {
        cnt++;
       }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;

int main(){
    int N;
    cin >> N;
    double x[N];
    string u[N];
    double ans=0;
    for(int i=0;i<N;i++){
        cin >> x[i] >> u[i];
        if(u[i]=="JPY"){
            ans+=x[i];
        }else{
            ans+=x[i]*380000.0;
        }
    }
    printf("%.8f\n",ans);
}

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

int main()
{
	int X, N;
	bool exist[102] = {false};
	scanf("%d%d", &X, &N);
	for (int i = 0; i < N; i++) {
		int p;
		scanf("%d", &p);
		exist[p] = true;
	}

	int ans = -1;
	int mina = std::abs(-1 - X);
	for (int t = 0; t <= 101; t++) {
		int a = std::abs(t - X);
		if (!exist[t] && a < mina) {
			mina = a;
			ans = t;
		}
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
int main()
{
    IOS;
    //freopen("inputfile.txt","r",stdin);
    ll n;cin>>n;
   ll ar[n];
   ll sum = 0,ans=0;
    for(ll i=0;i<n;i++)
    {
        cin>>ar[i];
        ans += (ar[i]%MOD*sum);
        sum += ar[i]%MOD;
        sum%= MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 5128