akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
#define INF 10000000
typedef long long ll;
using namespace std;
void Clear(vector<vector<int>> &A, int a, int b, int value){
    REP(int,i,0,a)
        REP(int,j,0,b) A[i][j] = value;
}
int main (void) {
    int H, W, ans;
    scanf("%d %d", &H, &W);
    char S[H][W];
    vector<vector<int>> Distance(H,vector<int>(W));
    REP(int,i,0,H){
        REP(int,j,0,W){
            cin >> S[i][j];
        }
    }
    ans = 0;
    REP(int,sx,0,W){
        REP(int,sy,0,H){
            REP(int,gx,0,W){
                REP(int,gy,0,H){
                    if ( S[sy][sx] == '.' && S[gy][gx] == '.' && ( sx != gx || sy != gy ) ){
                        Clear(Distance,H,W,INF);
                        queue<pair<int, int>> q;
                        q.push(make_pair(sx,sy));
                        Distance[sy][sx] = 0;
                        while(!q.empty()){
                            int x = q.front().first;
                            int y = q.front().second;
                            q.pop();
                            REP(int,i,0,4){
                                int nx,ny;
                                if ( i == 0 ){
                                    nx = x + 1;
                                    ny = y;
                                }
                                if ( i == 1 ){
                                    nx = x - 1;
                                    ny = y;
                                }
                                if ( i == 2 ){
                                    nx = x;
                                    ny = y + 1;
                                }
                                if ( i == 3 ){
                                    nx = x;
                                    ny = y - 1;
                                }
                                if ( nx < W && nx >= 0 && ny < H && ny >= 0 ){
                                    if ( S[ny][nx] == '#' ) continue;
                                    if ( Distance[ny][nx] > Distance[y][x] + 1 ){
                                        Distance[ny][nx] = Distance[y][x] + 1;
                                        q.push(make_pair(nx,ny));
                                    }
                                }
                            }
                        }
                        ans = max(ans, Distance[gy][gx]);
                    }
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,x;
    cin >> n >> m >> x;
     
    int c[n];
    int adj[n][m];
    f(i,0,n){
        cin >> c[i];
        for(int j = 0;j < m;j++){
            int x;
            cin >> x;
            adj[i][j] = x;
        }
    }
    int ans = LINF;
    for(int i = 0;i < (1ll<<n);i++){
        int sum[20] = {},csum = 0;
        f(j,0,n){
            if(i&(1<<j)){
                csum += c[j];
                f(k,0,m){
                    sum[k] += adj[j][k];
                }
            }
            int c = 1;
            f(i,0,m){
                if(sum[i] < x){
                    c = 0;
                    break;
                }
            } 
            if(c){
                ans = min(ans,csum);
            }
        }
    }
    cout << (ans == LINF ?-1:ans);

    return 0;
}
 

Measured memory_bytes: 3652
N,K = map(int,input().split())
L=list(map(int,input().split()))
A=[0]*N


for i in range(N):
    t=(L[i]+1)*L[i]/2*(1/L[i])
    A[i]=t
s=0
t=sum(A[:K])
s=max(s,t)
for i in range(N-K):
    t+=(A[i+K]-A[i])
    s=max(s,t)

print(s)    


Measured memory_bytes: 25604
N, Q = map(int, input().split())
S = input()

sum_list = [0]
for i in range(N-1):
    sum_list.append(sum_list[-1] + (1 if S[i:i+2] == 'AC' else 0))

for j in range(Q):
    l, r = map(int, input().split())
    print(sum_list[r-1] - sum_list[l-1])


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

map<pair<int,int>,int> mp;
long long ans[10];
int lr[]={-1,-1,-1,1,1,1,0,0,0},ud[]={1,0,-1,1,0,-1,1,0,-1};

main()
{
    long long h,w,n;

    scanf("%lld %lld %lld",&h,&w,&n);
    ans[0]+=(h-2)*(w-2);
    for(int i=0;i<n;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        for(int j=0;j<9;j++)
        {
            int ga=a+lr[j],gb=b+ud[j];
            //printf("%d %d\n",lr[j],ud[j]);
            if(ga<=1||ga>=h||gb<=1||gb>=w)continue;
            //printf("%d a:%d b:%d val:%d\n",j,ga,gb,mp[{ga,gb}]);
            ans[mp[{ga,gb}]]--;
            mp[{ga,gb}]++;
            ans[mp[{ga,gb}]]++;
        }
    }
    for(int i=0;i<10;i++)
    {
        printf("%lld\n",ans[i]);
    }
}


Measured memory_bytes: 56448
import sys
input = sys.stdin.readline
sys.setrecursionlimit(500000)

N,Q = map(int,input().split())
G = [[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int,input().split())
  a-=1;b-=1 #頂点を0indexに
  G[a].append(b);G[b].append(a)
#query = {}
ans = [0 for _ in range(N)]
for i in range(Q):
  p,x = map(int,input().split())
  p-=1
  ans[p] += x

def dfs(v,par): #vが今いる頂点、parが親。
  if par != -1:
    ans[v] += ans[par]
  for u in G[v]:
    if u != par:
      dfs(u,v)
dfs(0,-1)
print(*ans)
  
  

Measured memory_bytes: 221756
#include<stdio.h>

int main ()
{
	long long int n;
	scanf("%lld",&n);

	long long int p[n];

	for (int i=0;i<n;i++)
		scanf("%lld",&p[i]);

	long long int count=0;

	for (int i=1;i<n-1;i++)
		if (((p[i]<p[i-1])&&(p[i]>p[i+1]))   ||   ((p[i]>p[i-1])&&(p[i]<p[i+1])))
			count++;

	printf("%lld\n",count);

	return 0;
}


Measured memory_bytes: 128
#pragma GCC optimze("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll inf=1e18, N=100005;
inline ll mult(ll x,ll y){x%=hell;y%=hell;return (1LL*x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
inline ll powMod(ll base,ll expo){
	if(base==0)return 0;
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base); 
		expo>>=1;
	}
	return ans;
}
void solve(){
	ll n, k;
	cin>>n>>k;
	vector<ll> a(n);
	for(auto &x : a)
		cin>>x;
	vector<ll> dp(k+1,0);
	rep(i,0,k+1){
		for(auto x : a)
			if(i>=x and !dp[i-x])
				dp[i]=1;
	}
	dp[k]==1?cout<<"First":cout<<"Second";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    string S; cin >> S;
    int A[4];
    rep(i,4){
        A[i]=S[i]-'0';
    }
    rep(i,(1<<3)){
        int sum=A[0];
        string T;
        rep(j,3){
            T+=S[j];    
            if(1 & (i>>j)) {
                sum+=A[j+1];
                T+='+';
            }
            else {
                sum-=A[j+1];
                T+='-';
            }
        }
        T+=S[3];
        T+="=7";
        if(sum==7) {
            cout << T << endl;
            return 0;
        } 
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
const int X = 2002;
const int Y = 4004;

vector<ll> fact(8008, 1);
vector<ll> inv_fact(8008, 1);

ll pow_mod(ll a, ll b, ll m){
    ll ret = 1;
    while (b > 0) {
        if (b & 1) {
            ret = ret * a % m;
        }
        a = a * a % m;
        b >>= 1;
    }
    return ret;
}

ll inv_mod(ll a, ll m){
    return pow_mod(a, m - 2, m);
}
void pre_fact(){
    repd(i, 1, 8008){
        fact[i] = (fact[i - 1] * i) % mod;
        inv_fact[i] = inv_mod(fact[i], mod);
    }
}

ll comb(int n, int m){
    return ((fact[n] * inv_fact[m]) % mod * inv_fact[n - m]) % mod;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    pre_fact();
    vector<vector<ll>> dp(Y, vector<ll>(Y, 0));
    
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    
    ll sub = 0;
    rep(i, N){
        cin >> A[i] >> B[i];
        dp[X - A[i]][X - B[i]]++;
        (sub += comb(2 * (A[i] + B[i]), 2 * A[i])) %= mod;
    }
    
    rep(i, Y) rep(j, Y){
        if(i > 0) (dp[i][j] += dp[i - 1][j]) %= mod;
        if(j > 0) (dp[i][j] += dp[i][j - 1]) %= mod;
//        if(i + 1 < Y) (dp[i + 1][j] += dp[i][j]) %= mod;
//        if(j + 1 < Y) (dp[i][j + 1] += dp[i][j]) %= mod;
    }
    
    ll ret = 0;
    rep(i, N) {
        (ret += dp[X + A[i]][X + B[i]]) %= mod;
    }
    
    (ret -= sub) %= mod;
    
    (((ret *= inv_mod(2, mod)) %= mod) += mod) %= mod;
    
    
    output(ret, 0);
    
    
    
    return 0;
}

Measured memory_bytes: 127360
#include <iostream>

using namespace std;

int main(){
    int a,b,c,k,diff,x=234;
    cin>>a>>b;
    if(a<b){
     c=a;
     k=b-a;}
    else{ 
     c=b;
     k=a-b;}
     
     k=k/2;
     k=k+c;
     
    if(a>k&&b>k){
        int p=b-k;
        int q=a-k;
        if(p==q)
         x = 0;
    }
    if(a<k&&b<k){
        int p=k-b;
        int q=k-a;
        if(p==q)
         x = 0;
    }
    if(a<k&&b>k){
        int p=b-k;
        int q=k-a;
        if(p==q)
         x = 0;
    }
    if(a>k&&b<k){
        int p=k-b;
        int q=a-k;
        if(p==q)
         x = 0;
    }
    if(x==0)
     cout<<k;
    else 
     cout<<"IMPOSSIBLE";
     
    return 0;
}


Measured memory_bytes: 256
use std::io::{stdout, Write, BufWriter};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    let out = stdout();
    //let mut out = out.lock();
    let mut out = BufWriter::new(out.lock());

    input!{
        s: chars,
    };

    for c in s.iter() {
        if *c == '7' {
            //writeln!(out, "Yes").unwrap();
            out.write(b"Yes\n").unwrap();
            return ();
        }
    }
    out.write(b"No\n").unwrap();
}

Measured memory_bytes: 2128
#include<iostream>
#include<cstdio>

using namespace std;

short dp[5001][5001];

int n,m;

short max2(short a,short b){
	if(a>b)return a;
	return b;
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b,x;
		scanf("%d%d%d",&b,&a,&x);
		a--,b--;
		dp[a][b]=max2(dp[a][b],x+1);
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(dp[j][i]>0)cnt++;
			dp[j][i+1]=max2(dp[j][i+1],dp[j][i]-1);
			dp[j+1][i+1]=max2(dp[j+1][i+1],dp[j][i]-1);
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 50036
#include <cstdio>
#include <vector>

struct Permutation{
  std::vector<int> ps;
  Permutation(){
  }
  Permutation(int N):ps(N){
    for(int i=0;i<N;i++){
      ps[i]=i;
    }
  }
  void read(int N){
    ps.resize(N);
    for(int i=0;i<N;i++){
      scanf("%d",&ps[i]);
      ps[i]--;
    }
  }
  int operator[](int index)const{
    return ps[index];
  }
  int& operator[](int index){
    return ps[index];
  }
  struct Permutation inv()const{
    struct Permutation res(ps.size());
    for(int i=0;i<ps.size();i++){
      res[ps[i]]=i;
    }
    return res;
  }
};
struct Permutation operator*(struct Permutation p,struct Permutation q){
  int N=p.ps.size();
  struct Permutation res(N);
  for(int i=0;i<N;i++){
    res[i]=p[q[i]];
  }
  return res;
}

struct Permutation exp[30];

struct Permutation seq[10];

int main(){
  int N,K;
  scanf("%d %d",&N,&K);
  K--;
  seq[0].read(N);
  seq[1].read(N);
  for(int i=2;i<10;i++){
    seq[i]=seq[i-1]*seq[i-2].inv();
  }
  exp[0]=seq[1]*seq[0].inv()*seq[1].inv()*seq[0];
  for(int k=1;k<30;k++){
    exp[k]=exp[k-1]*exp[k-1];
  }
  int full=(K-4)/6;
  struct Permutation pre(N);
  for(int k=0;k<30;k++){
    if(full&(1<<k)){
      pre=pre*exp[k];
    }
  }
  struct Permutation res=pre*seq[K-full*6]*pre.inv();
  for(int i=0;i<N;i++){
    if(i) printf(" ");
    printf("%d",res.ps[i]+1);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 18728
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define int ll
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// int MOD = 998244353;
int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){
	
	int a,b,c,d;
	cin >> a >> b >> c >> d;

	while(1){
		c -= b;
		if(c <= 0){
			cout << "Yes" << endl;
			return 0;
		}
		a -= d;
		if(a <= 0){
			cout << "No" << endl;
			return 0;
		}
	}

	
	
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://atcoder.jp/contests/abc164/tasks/abc164_b


Measured memory_bytes: 3624
using System;

namespace Atcoder_047
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = Int32.Parse(input[0].ToString());
            int b = Int32.Parse(input[1].ToString());
            int c = Int32.Parse(input[2].ToString());

            if ( a+b == c || b + c == a || a + c == b)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <math.h>
#include <cctype>
using namespace std;
char s[1000];
int main(){
    for(int i=1;i<=6;i++){
        cin >> s[i];
    }
    if(s[3] == s[4]){
        if(s[5] == s[6]){
            cout << "Yes" << endl;
            return 0;
        }
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    if(a<b&&b<c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;


}



Measured memory_bytes: 3168
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <iostream>
#include <queue>
#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int parseDate(const string &s){
  int y, m, d;
  sscanf(s.c_str(), "%04d/%02d/%02d", &y, &m, &d);
  return y * 10000 + m * 100 + d;
}

int main(){
  const int n = getInt();
  vector<string> title(n);
  vector<string> auther(n);
  vector<int> date(n);

  REP(i,n){
    string dt;
    cin >> title[i] >> auther[i] >> dt;
    date[i] = parseDate(dt);
  }

  const int q = getInt();
  REP(i,q){
    string t, a, df, dt;
    cin >> t >> a >> df >> dt;

    REP(j,n){
      if(t != "*" && title[j].find(t) == string::npos) goto next;
      if(a != "*" && auther[j].find(a) == string::npos) goto next;
      if(df != "*" && parseDate(df) > date[j]) goto next;
      if(dt != "*" && parseDate(dt) < date[j]) goto next;
      printf("%s\n", title[j].c_str());
      next:;
    }

    if(i != q - 1) puts("");
  }

  return 0;
}

Measured memory_bytes: 1264
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}
use input::*;
use std::collections::VecDeque;
fn main() {
    let mut a = input_line_str().chars().collect::<VecDeque<_>>();
    let mut b = input_line_str().chars().collect::<VecDeque<_>>();
    let mut c = input_line_str().chars().collect::<VecDeque<_>>();

    let mut next = 'a';

    loop {
        let po = match next {
            'a' => &mut a,
            'b' => &mut b,
            'c' => &mut c,
            _ => &mut a,
        };
        if po.len() == 0 {
            p(next.to_uppercase().next().unwrap());
            break;
        }
        next = po.pop_front().unwrap();
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int N; cin>>N;
    int A[N];
    rep(i,N)cin>>A[i];
    ll cnt=0;
    ll h=A[0]; 
    for(int i=1; i<N; i++){
        if(A[i]<h){
            cnt+=(h-A[i]);
        }
        else h=A[i];
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 4360
d = {}
n,k = map(int, input().split())
for _ in range(n):
    a,b = map(int, input().split())
    if d.setdefault(a):
        d[a] = d[a] + b
    else:
        d[a] = b
for key in sorted(d):
    k -= d[key]
    if k<=0:
        print(key)
        break

Measured memory_bytes: 10592
#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))


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 gcd(T a, T b) { while (b) { a = a%b; swap(a, b); } return a; }

int yes(char c)
{
	string acgt = "ACGT";
	
	int fnd = acgt.find(c);

	return fnd != -1;
}

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

	string str;
	cin >> str;

	str = '?' + str;

	int mx = 0;

	for (int i = 1; i < (int)str.size(); i++)
	{
		int j = i;

		for (; j < (int)str.size(); j++)
		{
			if (!yes(str[j]))
			{
				break;
			}
		}

		mx = max(mx,j - i);
	}

	cout << mx << endl;


	return 0;
}

Measured memory_bytes: 256
S=[i for i in range(1,14)]
H=[i for i in range(1,14)]
C=[i for i in range(1,14)]
D=[i for i in range(1,14)]
cards=int(input())
for i in range(0,cards):
    mark,rank=input().split()
    rank=int(rank)
    if mark=="S":
        S.remove(rank)
    elif mark=="H":
        H.remove(rank)
    elif mark=="C":
        C.remove(rank)
    elif mark=="D":
        D.remove(rank)
for i in S:
    print("S",i)
for i in H:
    print("H",i)
for i in C:
    print("C",i)
for i in D:
    print("D",i)

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

constexpr int INF = 1e9;

double W(vector<int> const& x, vector<int> const& y, double d) {
    double lb = INF, ub = -INF;
    const int N = x.size();
    for(int i=0; i<N; ++i) {
        double x1 = x[i], y1 = y[i];
        double x2 = x[(i+1)%N], y2 = y[(i+1)%N];
        if((x1 - d) * (x2 - d) <= 0 && x1 != x2) {
            double is = y1 + (y2 - y1) * (d - x1) / (x2 - x1);
            lb = min(lb, is);
            ub = max(ub, is);
        }
    }
    return max(0.0, ub - lb);
}

int main() {
    int M, N;
    while(cin >> M >> N, M) {
        vector<int> x1(M), x2(N), y1(M), z2(N);
        for(int i=0; i<M; ++i) {
            cin >> x1[i] >> y1[i];
        }
        for(int i=0; i<N; ++i) {
            cin >> x2[i] >> z2[i];
        }
        int min1 = INF, max1 = -INF;
        int min2 = INF, max2 = -INF;
        vector<int> xs;
        for(int i=0; i<M; ++i) {
            min1 = min(min1, x1[i]);
            max1 = max(max1, x1[i]);
            xs.push_back(x1[i]);
        }
        for(int i=0; i<N; ++i) {
            min2 = min(min2, x2[i]);
            max2 = max(max2, x2[i]);
            xs.push_back(x2[i]);
        }
        sort(xs.begin(), xs.end());
        
        double res = 0;
        for(int i=0; i<xs.size()-1; ++i) {
            double a = xs[i], b = xs[i+1], c = (a + b) / 2;
            if(min1 <= c && c <= max1 && min2 <= c && c <= max2) {
                double fa = W(x1, y1, a) * W(x2, z2, a);
                double fb = W(x1, y1, b) * W(x2, z2, b);
                double fc = W(x1, y1, c) * W(x2, z2, c);
                res += (b - a) / 6 * (fa + 4 * fc + fb);
            }
        }
        cout << fixed << setprecision(10) << res << endl;
    }
}


Measured memory_bytes: 3292
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;


struct edge { int from; int to; };

int n, m;
vector<edge>v;


bool check(int s) {
	vector<int>vis(n, 0);
	vector<edge>edges;
	rep(i, 0, m) {
		if (i != s) { 
			edges.push_back({v[i].from,v[i].to});
			edges.push_back({ v[i].to,v[i].from });
		}
	}

	queue<int>que;
	que.push(0);
	vis[0] = 1;
	while (!que.empty()) {
		int q = que.front();
		que.pop();

		for (auto x : edges) {
			if (x.from == q && vis[x.to] == 0) {
				vis[x.to] = 1;
				que.push(x.to);
			}
		}

	}

	int cnt = 0;
	rep(i, 0, n) {
		if (vis[i] == 1)cnt++;
	}
	if (cnt != n)return 1;
	else return 0;
}



int main() {
	cin >> n >> m;
	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		v.push_back({a,b});
	}
	



	int ans = 0;
	rep(i, 0, m) {
		if (check(i))ans++;
	}

	cout << ans << endl;


	return 0;
}

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

// 内部定数
#define D_ARRAY_MAX		100000									// 最大配列数

// 内部変数
static int si1Array[D_ARRAY_MAX];								// 配列
static int siACnt;												// 配列数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 配列数取得
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &siACnt);

	// 配列数でループ
	int liMax = -1;
	int liMNo;
	for (i = 0; i < siACnt; i++) {

		// 配列取得
#ifdef D_TEST
		fscanf(szpFpT, "%d", &si1Array[i]);
#else
		fscanf(stdin, "%d", &si1Array[i]);
#endif

		// ２倍
		si1Array[i] *= 2;

		// 最大値更新
		if (liMax < si1Array[i]) {
			liMax = si1Array[i];
			liMNo = i;
		}
	}
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif

	// 中間値に近い値を取得
	int liCenter = liMax / 2;
	int liNVal = INT_MAX;
	int liNAbs = abs(liNVal - liCenter);
	for (i = 0; i < siACnt; i++) {

		// 最大値以外
		if (i == liMNo) {
			continue;
		}

		// 中間値に近い値を更新
		int liAbs = abs(si1Array[i] - liCenter);
		if (liNAbs > liAbs) {
			liNAbs = liAbs;
			liNVal = si1Array[i];
		}
	}

	// 結果セット
	sprintf(lc1Out, "%d %d\n", liMax / 2, liNVal / 2);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

typedef struct
{
  int id, time;
} Team;

class LessTime
{
public:
  bool operator() (const Team& lhs, const Team& rhs) const
  {
    return lhs.time < rhs.time;
  }
};

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    vector<Team> team(n);
    for (int i = 0; i < n; ++i) {
      cin >> team[i].id;
      int m1, s1, m2, s2, m3, s3, m4, s4;
      cin >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      team[i].time = m1*60+s1 + m2*60+s2 + m3*60+s3 + m4*60+s4;
    }
    sort(team.begin(), team.end(), LessTime());

    cout << team[0].id << endl;
    cout << team[1].id << endl;
    cout << team[n-2].id << endl;
  }
  return 0;
}

Measured memory_bytes: 948
import sys
sys.setrecursionlimit(int(3e6))
N=int(input())
h=list(map(int,input().split()))

memo=[-1 for i in range(N)]
memo[0]=0
def dp(i):
    if memo[i]!=-1:
        return memo[i]
    cos=dp(i-1)+abs(h[i]-h[i-1])
    if i-2>=0:
        cos=min(cos,dp(i-2)+abs(h[i]-h[i-2]))
    memo[i]=cos
    return cos
print(dp(N-1))

Measured memory_bytes: 93588
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>

typedef long long llong;
using namespace std;

int main() {
	char IPT[210];
	char BUF[210];
	int m;
	int h;
	int IPTlen;

	while (1) {
		scanf("%s", IPT);
		if (IPT[0] == '-')break;
		IPTlen = strlen(IPT);
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> h;
			for (int j = 0; j + h <= IPTlen; j++) {
				BUF[j] = IPT[j + h];
				IPT[j + h] = '\0';
			}
			strcat(BUF, IPT);
			strcpy(IPT, BUF);
		}
		cout << IPT << '\n';

	}
	return 0;
}



Measured memory_bytes: 3216
def main():
  import sys
  import numpy as np
  from scipy.sparse import csr_matrix
  from scipy.sparse.csgraph import floyd_warshall as f
  t=np.fromstring(sys.stdin.buffer.read(),'i',sep=' ')
  n,m,l=t[:3]
  m=m*3+3
  print('\n'.join((f(f(csr_matrix((t[5:m:3],(t[3:m:3],t[4:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n).astype(int)%n-1).astype(str).tolist()))
main()

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

char a[501][501];

int main(){
    int N,i,j;
    scanf("%d",&N);
    int nonblack=1;
    for (i = 0; i < N; i++) {
	for (j = 0; j < N; j++) {
            scanf(" %c", &a[i][j]);
            if(a[i][j]=='#') nonblack=0;
    	}
    }
    if(nonblack) {
        printf("-1\n");
        return 0;
    }
    
    // non-full columns
    int cnt1=0;
    for(j=0;j<N;j++){
        for(i=0;i<N;i++){
            if(a[i][j]=='.'){
                cnt1++;
                break;
            }
        }
    }
    // shortest step to fill one row
    int cnt2=N+1;
    for(i=0;i<N;i++){
        // #white in i-th row
        int cnt=0;
        for(j=0;j<N;j++){
            if(a[i][j]=='.'){
                cnt++;
            }
        }
        // if i-th column has black
        int has=0;
        for(j=0;j<N;j++){
            if(a[j][i]=='#'){
                has=1;
                break;
            }
        }
        if(!has){
            // make i-th column 1 black at first
            cnt++;
        }
        if(cnt2>cnt) cnt2=cnt;
    }
    printf("%d\n",cnt1+cnt2);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
using namespace std;
int h,w,n;
string s;
int main(){
	cin>>s;
	if(s.size()==2){
		if(s[0]==s[1])cout<<1<<" "<<2<<endl;
		else cout<<-1<<" "<<-1<<endl;
		return 0;
	}
	
	for(int i=2;i<s.size();i++){
		if(s[i]==s[i-1]){
			cout<<i-1<<" "<<i+1<<endl;
			return 0;
		}
		if(s[i-2]==s[i-1]){
			cout<<i-1<<" "<<i+1<<endl;
			return 0;
		}
		if(s[i]==s[i-2]){
			cout<<i-1<<" "<<i+1<<endl;
			return 0;
		}
	}
	cout<<"-1 -1\n";
	return 0;
}

Measured memory_bytes: 512
if __name__ == '__main__':
    n, m, x = list(map(int, input().split()))
    
    c = []
    a = []
    
    def calc_price(bit):
        price_total = 0
        learn_total = [0] * m #理解度
        
        for i in range(n):
            if (bit >> i) & 1:
                price_total += c[i]
                learn = a[i]
                for j, la in enumerate(learn):
                    learn_total[j] += la
        
        if check(learn_total):
            return price_total
        else:
            return INF
        
    def check(learn_total):
        for i in range(m):
            if learn_total[i] < x:
                return False
        return True
    
    for i in range(n):
        c_temp, *a_temp = list(map(int, input().split()))
        c.append(c_temp)
        a.append(a_temp)
        
    INF = float("inf")
    ans = INF
    
    for bit in range(1 << n):
        price = calc_price(bit)
        ans = min(ans, price)
    
    if ans == INF:
        print(-1)
    else:
        print(ans)

Measured memory_bytes: 74504
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll w;
    cin >> n >> w;
    VL v[4];
    ll w1;
    REP(i, n){
        ll wi, vi;
        cin >> wi >> vi;
        if(i == 0) w1 = wi;
        v[wi - w1].push_back(vi);
    }
    REP(i, 4) sort(v[i].begin(), v[i].end(), greater<int>());

    ll ans = 0;
    FOR(i, 0, v[0].size()){
        FOR(j, 0, v[1].size()){
            FOR(k, 0, v[2].size()){
                FOR(l, 0, v[3].size()){
                    ll sum_v = 0;
                    REP(m, i) sum_v += v[0][m];
                    REP(m, j) sum_v += v[1][m];
                    REP(m, k) sum_v += v[2][m];
                    REP(m, l) sum_v += v[3][m];
                    ll sum_w = i*w1 + j*(w1+1) + k*(w1+2) + l*(w1+3);
                    if(sum_w <= w) ans = max(ans, sum_v);
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
lis = list(map(int, input().split()))

def calc_tem(H):
    return abs(A - ((T*1000) - (H*6)) / 1000)

new_lis = list(map(calc_tem, lis))
ans = new_lis.index(min(new_lis)) + 1

print(ans)

Measured memory_bytes: 9224
unittest
{
	assert( [ "3", "6", "2", "6" ].parse.expand.solve == 1 );
	assert( [ "4", "2", "5", "5", "2" ].parse.expand.solve == 0 );
	assert( [ "6", "12", "22", "16", "22", "18", "12" ].parse.expand.solve == 2 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	auto as = new long[ n ];
	foreach( ref a; as )
	{
		input.popFront;
		a = input.front.strip.to!( long );
	}
	return tuple( as );
}

auto solve( long[] as )
{
	return as.sort().group.map!( ( a ) => a[ 1 ] % 2 ).sum;
}


Measured memory_bytes: 3708
// Problem : C - Traveling
// Contest : AtCoder Regular Contest 089
// URL : https://atcoder.jp/contests/arc089/tasks/arc089_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define cerr if(1)cerr
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;

int n, cnt = 0, t[N], x[N], y[N];

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> t[i] >> x[i] >> y[i];
		int moves = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
		int lim = t[i] - t[i - 1];
		if (moves <= lim && (lim - moves) % 2 == 0) {
			cnt++;
		}
	}
	if (cnt == n) {
		puts("Yes");
	} else {
		puts("No");
	}
}


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

int main(){
  int a,b,c,x,y;cin>>a>>b>>c>>x>>y;
  c*=2;
  set<int>s;
  s.insert(max(x,y)*c);
  s.insert(a*x+b*y);
  s.insert(min(x,y)*c+abs(x-y)*(x>y?a:b));

  cout<<*begin(s)<<endl;
}

Measured memory_bytes: 256
S = input()
N = S.count('W')

B = [b for b in range(1, N + 1) if S[b-1] == 'B']
W = [w for w in range(N+1, len(S)+1) if S[w-1] == 'W']
# assert len(B) == len(W)

ans = 0
for b, w in zip(B, W):
    ans += w - b

print(ans)

Measured memory_bytes: 11400
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

int main()
{
	int n[4] = {};
	for (size_t i = 0; i < 3; i++)
	{
		int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		n[tmp1-1]++;
		n[tmp2-1]++;
	}

	for (size_t i = 0; i < 4; i++)
	{
		if (n[i] == 0 || n[i] == 3)
		{
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<utility>

using namespace std;

int f_abs(int a){
    if (a > 0) return a;
    else return -a;
}

int main(){
    int n;
    scanf("%d", &n);
    int t[n], x[n], y[n];
    for(int i = 0; i < n; i++){
        scanf("%d %d %d", &t[i], &x[i], &y[i]);
    }
    pair<int, int> state = make_pair(0,0);
    int Time = 0;
    for(int i = 0; i < n; i++){
        int del = t[i] - Time - (f_abs(state.first - x[i]) + f_abs(state.second - y[i]));
        if (del >= 0 && del % 2 == 0) continue;
        else {
            puts("No");
            return 0;
        }
    } 
    puts("Yes");
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }


long long int value(long long int x, long long int A, long long int B) {
	return floor(A * x / B) - A * floor(x / B);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);

	int N, M;
	cin >> N >> M;
	vi H(N);
	vi A(M), B(M);
	rep(i, N) {
		cin >> H.at(i);
	}
	rep(i, M) {
		cin >> A.at(i) >> B.at(i);
	}

	vi flag(N);
	rep(i, N) {
		flag.at(i) = 1;
	}
	rep(i, M) {
		if (H.at(A.at(i) - 1) >= H.at(B.at(i) - 1)) {
			flag.at(B.at(i) - 1) = 0;
		}
		if (H.at(A.at(i) - 1) <= H.at(B.at(i) - 1)) {
			flag.at(A.at(i) - 1) = 0;
		}
	}

	cout << accumulate(all(flag), 0);

	return 0;
}


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

//Zeller's conguence

int main()
{
    int maxSize = 0;
    int maxNum = 0;
    string maxStr ;
    string maxNumString ;
    string input;
    map<string, int> m;
    while (cin >> input)
    {
        if (maxSize < input.length())
        {
            maxSize = input.length();
            maxStr = input;
        }
        if (m[input] == 0)
            m[input] = 1;
        else
            m[input]++;

        if (maxNum < m[input])
        {
            maxNum = m[input];
            maxNumString = input;
        }
    }
    cout << maxNumString << " " << maxStr << endl;
    return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int a , sum ;
    cin >>a >> sum ;
    int legs = 0 ;
    int cl = 0, tl = 0;
    int c = 0 , t = 0 ;
    for(int i = 0; i <=a ; i++)
    {
        c = i;
        t = a - i;
        cl = 2 * c ;
        tl = 4 * t ;
        legs = cl + tl ;
        if(legs == sum)
        {
            cout <<"Yes\n";
            return 0 ;
        }
    }
    cout <<"No\n" ;
}


Measured memory_bytes: 3632
s = list(input())
lp = []
cnt = 1
kugiri = []
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        lp.append((s[i], cnt))
        kugiri.append(i)
        cnt = 1
lp.append((s[-1], cnt))
ans = [0]*len(s)
for i in range(0,len(lp),2):
    r = lp[i][1]
    l = lp[i+1][1]
    if (r-l) % 2 == 0:
        ans[kugiri[i]] = (r+l)//2
        ans[kugiri[i]+1] = (r+l)//2
    elif max(l,r) % 2 == 0 and r > l:
        ans[kugiri[i]] = (r+l)//2
        ans[kugiri[i]+1] = (r+l+1)//2
    elif max(l,r) % 2 == 0 and r < l:
        ans[kugiri[i]] = (r+l+1)//2
        ans[kugiri[i]+1] = (r+l)//2
    elif max(l,r) % 2 != 0 and r > l:
        ans[kugiri[i]] = (r+l+1)//2
        ans[kugiri[i]+1] = (r+l)//2
    else:
        ans[kugiri[i]] = (r+l)//2
        ans[kugiri[i]+1] = (r+l+1)//2
print(*ans)




Measured memory_bytes: 18156
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
P = LIST()

P.append(-1)

## pattern 1
# ans = 0
# i = 0
#
# while i < N:
#     if P[i] == i+1:
#         ans += 1
#         if P[i+1] == i+2:
#             i += 1
#     i += 1
#
# print(ans)

## pattern 2
ans = 0
i = 0
for i in range(N):
    if P[i] == i+1:
        P[i], P[i+1] = P[i+1], P[i]
        ans += 1

print(ans)


Measured memory_bytes: 21916
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;
ll gcd(ll a,ll b){
    return b ? gcd(b,a%b):a;
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

ll f(ll x,int c,int d){
    ll res = x;
    res -= x/c;
    res -= x/d;
    res += x/lcm(c,d);
    return res;
}

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = f(b,c,d)-f(a-1,c,d);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int a,b,c;
	int r;
	cin>>a>>b>>c;
	while(1){
		if(a>b)	swap(a,b);
		r=b%a;
		if(r==0)	break;
		b=a;
		a=r;
	}
	if(c%a==0)	cout<<"YES"<<endl;
	else		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
tuple=input()
list=tuple.split()
list=[int(i) for i in list]
N=list[0]
Y=list[1]
for i in range(int(Y/10000)+1):
    for j in range(int((Y-10000*i)/5000)+1):
            if 10000*i+5000*j+1000*(N-i-j)==Y :
                print(i,j,N-i-j)
                exit()
print("-1 -1 -1")


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

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    #print(b[j],K - a[i])
    j -= 1
  ans = max(ans, i + j)
  #print("ans",ans)
print(ans)

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

using namespace std;

char s[2001], t[2001];
int dp[2001][2001][2];

int m, n;

int main()
{
	scanf("%d %d", &m, &n);
	scanf("%s", s); scanf("%s", t);
	int ans = 0;
	memset(dp, 0, sizeof(dp));
	for (int i = m; i >= 0; --i)
	{
		for (int j = n; j >= 0; --j)
		{
			dp[i][j][0] = max((s[i] == 'O') ? dp[i + 1][j][1] + 1 : 0, (t[j] == 'O') ? dp[i][j + 1][1] + 1 : 0);
			dp[i][j][1] = max((s[i] == 'I') ? dp[i + 1][j][0] + 1 : 0, (t[j] == 'I') ? dp[i][j + 1][0] + 1 : 0);
			if (s[i] == 'I' || t[j] == 'I')
			{
				dp[i][j][0] = max(dp[i][j][0], 1);
				dp[i][j][1] = max(dp[i][j][1], 1);
			}
			ans = max(dp[i][j][1], ans);
		}
	}
	printf("%d\n", (ans == 0) ? 0 : (ans - 1) / 2 * 2 + 1);
	return 0;
}

Measured memory_bytes: 33976
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

typedef long long ll;

const ll MOD = 1e9 + 7;

class BPapersPlease {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;
        vector<int> a(N);
        REP(i,0,N) in >> a[i];
        bool approve = true;
        REP(i,0,N) {
            if (a[i] % 2 == 0 && (a[i] % 3 != 0 && a[i] % 5 != 0)) {
                approve = false;
                break;
            }
        }
        out << (approve ? "APPROVED" : "DENIED") << "\n";
    }
};


signed main() {
    BPapersPlease solver;
    std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256