akhauriyash/Code-Regression huggingface dataset:
import math
def make_divisors(n):
    divisors = []
    for i in range(1, int(math.sqrt(n))+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors 
def main():
    n = int(input())
    r = len(make_divisors(n-1)) - 1
    d = make_divisors(n)
    for i in d:
        if i == 1:
            continue
        if i == 2:
            r += 1
            continue
        t = n
        while t % i == 0:
            t = t // i
        t = t % i
        if t == 1:
            r += 1
    return r
print(main())


Measured memory_bytes: 38896
// https://beta.atcoder.jp/contests/abc093

#include <iostream>
#include <algorithm>
#include <array>
using namespace std;

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

    array<int, 3> N = {};
    cin >> N[0] >> N[1] >> N[2];
    if (N[0] == N[1] && N[1] == N[2])
    {
        cout << 0 << endl;
        return 0;
    }

    sort(N.begin(), N.end());

    int diff_0 = N[2] - N[0];
    int diff_1 = N[2] - N[1];
    if ((diff_0 + diff_1) % 2 == 0)
    {
        cout << (diff_0 + diff_1) / 2 << endl;
    }
    else
    {
        cout << (diff_0 + diff_1) / 2 + 2 << endl;
    }

    return 0;
}


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

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

using namespace std;

int main(){
    int a, b; cin >> a >> b;
    string s; cin >> s;

    REPI(i, a + b + 1){
        if(i == a){
            if(s[i] != '-'){
                cout << "No"; return 0;
            }
        }else{
            if(s[i] == '-'){
                cout << "No"; return 0;
            }
        }
    }cout << "Yes";
}


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

using namespace std;
typedef long long ll;

int main()
{
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> c(n,0);
    vector<vector<int>> a(n,vector<int>(m,0));
    for(int i=0;i<n;i++)
    {
        cin >> c[i];
        for(int j=0;j<m;j++) cin >> a[i][j];
    }
    int res=(1<<30);
    for(int mask=0;mask<(1<<n);mask++)
    {
        vector<int> v(m,0);
        int b=0;
        for(int i=0;i<n;i++)
        {
            if(!(mask&(1<<i))) continue;
            b+=c[i];
            for(int j=0;j<m;j++) v[j]+=a[i][j];
        }
        bool ok=1;
        for(int j=0;j<m;j++) ok&=(v[j]>=x);
        if(ok) res=min(res,b);
    }
    if(res!=(1<<30)) cout << res << endl;
    else cout << -1 << endl;
    return 0;
}


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

int main () {
	int a[33] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k; cin >> k;
    cout << a[k];
	return 0;
}


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

int main(){
    int n, k;
    ll ans = 0;
    cin >> n >> k;
    for (int b = k + 1; b < n + 1; b ++){
        ll u = n / b;
        ll tmp = u * (b - k);
        if (n % b > 0) tmp += max(ll(0), ll(n % b - max(1, k) + 1));
        ans += tmp;
    }
    cout << ans << endl;
}

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

#define FASTIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using ll = long long;


int main() {
	FASTIO
	ll h, w, ch, cw, dh, dw;
	cin >> h >> w >> ch >> cw >> dh >> dw;
	vector<string> s(h);
	for (string &i : s) {
		cin >> i;
	}
	vector<vector<bool>> vis(h + 1, vector<bool>(w + 1, false));
	struct Edge {
		ll a, b, c;
	};
	deque<Edge> q;
	ch--, cw--, dh--, dw--;
	q.push_back({ch, cw, 0});
	while (!q.empty()) {
		auto[r, c, v] = q.front();
		q.pop_front();
		if (r == dh && c == dw) {
			return cout << v << endl, 0;
		}
		if (vis[r][c]) {
			continue;
		}
		vis[r][c] = 1;
		for (ll dr : {1, 0, -1}) {
			for (ll dc : {1, 0, -1}) {
				if (abs(dr) == abs(dc)) {
					continue;
				}
				ll nr = r + dr, nc = c + dc;
				if (nc < 0 || nc >= w || nr < 0 || nr >= h || vis[nr][nc] || s[nr][nc] == '#')continue;
				q.push_front({nr, nc, v});
			}
		}
		for (ll dr : {-2, -1, 0, 1, 2}) {
			for (ll dc : {-2, -1, 0, 1, 2}) {
				ll nc = c + dc, nr = r + dr;
				if (nc < 0 || nr < 0 || nr >= h || nc >= w || vis[nr][nc] || s[nr][nc] == '#')continue;
				q.push_back({nr, nc, v + 1});
			}
		}

	}
	cout << -1 << endl;
}



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

using ll = long long;

constexpr ll inf{ numeric_limits<ll>::max() / 101 };

struct FordFulkerson {
    using T = tuple<ll, ll, ll>; // to, cap, rev
    vector<vector<T>> G;
    vector<bool> used;
    FordFulkerson(ll N) :G(N), used(N) {}
    ll dfs(ll v, ll t, ll f) {
        if(v == t) return f;
        used[v] = true;
        for(auto& e : G[v]) {
            ll to, cap, rev; tie(to, cap, rev) = e;
            if(used[to] || cap <= 0) continue;
            ll res{ dfs(to, t, min(f, cap)) };
            if(res <= 0) continue;
            get<1>(e) -= res;
            get<1>(G[to][rev]) += res;
            return res;
        }
        return 0;
    }
    void add_edge(ll from, ll to, ll cap) {
        G[from].emplace_back(to, cap, G[to].size());
        G[to].emplace_back(from, 0, G[from].size() - 1);
    }
    ll max_flow(ll s, ll t) {
        ll res{}, flow{ 1 };
        for(;flow; res += flow) {
            fill(used.begin(), used.end(), false);
            flow = dfs(s, t, inf);
        }
        return res;
    }
};

ll N, a[101], ans;
int main() {
    cin >> N;
    FordFulkerson ff(N + 2);
    for(int i{ 1 }; i <= N; ++i) cin >> a[i];
    for(int i{ 1 }; i <= N; ++i) {
        if(a[i] > 0) ans += a[i], ff.add_edge(i, N + 1, a[i]);
        else ff.add_edge(0, i, -a[i]);
        for(int j{ i * 2 }; j <= N; j += i)
            ff.add_edge(i, j, inf);
    }
    cout << ans - ff.max_flow(0, N + 1) << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
cnt=1
li=[]
x=[0]
for i in range(n-1):
    if a[i+1]==a[i]:
        cnt+=1
    else:
        cnt=1
    if cnt==2:
        li.append(a[i+1])
    if cnt==4:
        x.append(a[i+1])

if len(li)>=2:
    print(max(li[0]*li[1],max(x)**2))
else:
    print(0)

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

ll n, m, a, b, c, x, y;
string s;

int main() {
    cin >> a >> b >> c >> x >> y;

    ll mini = 1e18;
    REP(i, max(x, y)*2 + 1) {
        mini = min(mini, i*c + max(0LL, x-i/2)*a + max(0LL, y-i/2)*b);
    }
    std::cout << mini << '\n';

    return 0;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>), (<*), (*>), (<$))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getl (wrds toInt) >>= print

solve :: [Int] -> Int
solve = length . nub

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine


Measured memory_bytes: 508
#include <stdio.h>
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 1000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MAX_INT = (1 << 31) - 1;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("battleship.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //int TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a * b, c * d);
    return 0;
}


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

using namespace std;

typedef long long ll;

const int maxn = 200100;

int n, a[maxn];

ll sadness(ll b) {
    ll ret = 0;
    for (int i = 0; i < n; i++)
        ret += abs(a[i] - (b + i + 1));
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0);

    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    /*
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] -= i+1;
    }

    sort(a, a + n);
    int b = a[n/2];
    
    ll ans = 0;
    for (int i = 0; i < n; i++)
        ans += abs(a[i] - b);
    cout << ans << ednl;
    */


    ll lo = -2e9, hi = 2e9;
    while (hi - lo > 5) {
        ll m1 = lo + (hi - lo) / 3, m2 = lo + 2 * (hi - lo) / 3;
        ll r1 = sadness(m1), r2 = sadness(m2);
        if (r1 > r2) lo = m1;
        else hi = m2;
    }

    ll ret = sadness(lo);
    for (ll i = lo + 1; i <= hi; i++)
        ret = min(ret, sadness(i));
    cout << ret << endl;
}

Measured memory_bytes: 1024
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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<_>>()
    };

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"5
10 4 8 7 3"# => "2",
r#"7
4 4 5 6 6 5 5"# => "3",
r#"4
1 2 3 4"# => "0",
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
        h: [u64; n],
    }
    let mut ans = 0;
    let mut m = 0;

    for i in 1..n {
        if h[i - 1] >= h[i] {
            m += 1;
        } else {
            m = 0;
        }
        ans = std::cmp::max(ans, m);
    }

    ans.to_string()
}

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

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

int N;
int A[200005], sum[200005];

int solve(int l, int r, int mid) {
    int lsum, rsum;

    int mind = -1;
    FOR(i, mid, N) {
        lsum = l > 0 ? sum[i] - sum[l - 1] : sum[i];
        rsum = sum[r] - sum[i];
        if (mind == -1 || mind > abs(rsum - lsum)) {
            mid = i;
            mind = abs(rsum - lsum);
        } else {
            break;
        }
    }
    return mid;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> N;
    REP(i, N) { cin >> A[i]; }

    sum[0] = A[0];
    FOR(i, 1, N - 1) { sum[i] = sum[i - 1] + A[i]; }

    int lmid = 0;
    int rmid = 0;
    int ans = INF;
    REP(mid, N) {
        lmid = solve(0, mid, lmid);
        rmid = solve(mid + 1, N - 1, max(rmid, mid + 1));
        int sum1 = sum[lmid];
        int sum2 = sum[mid] - sum[lmid];
        int sum3 = sum[rmid] - sum[mid];
        int sum4 = sum[N - 1] - sum[rmid];
        int minsum = min({sum1, sum2, sum3, sum4});
        int maxsum = max({sum1, sum2, sum3, sum4});

        ans = min(ans, abs(maxsum - minsum));
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> resr(n + 1), resg(n + 1), resb(n + 1);
	rep(i, n) {
		if (s[i] == 'R') resr[i]++;
		if (s[i] == 'G') resg[i]++;
		if (s[i] == 'B') resb[i]++;
		resr[i + 1] += resr[i];
		resg[i + 1] += resg[i];
		resb[i + 1] += resb[i];
	}
	ll ans = 0;
	rep(i, n - 2) {
		for (int j = i + 1; j < n - 1; ++j) {
			if (s[i] == 'R' && s[j] == 'G') {
				ans += resb[n] - resb[j];
				int tmp = j + (j - i);
				if (j + (j - i) > n) continue;
				if (s[tmp] == 'B') ans--;
			}
			if (s[i] == 'R' && s[j] == 'B') {
				ans += resg[n] - resg[j];
				int tmp = j + (j - i);
				if (j + (j - i) > n) continue;
				if (s[tmp] == 'G') ans--;
			}
			if (s[i] == 'G' && s[j] == 'R') {
				ans += resb[n] - resb[j];
				int tmp = j + (j - i);
				if (j + (j - i) > n) continue;
				if (s[tmp] == 'B') ans--;
			}
			if (s[i] == 'B' && s[j] == 'R') {
				ans += resg[n] - resg[j];
				int tmp = j + (j - i);
				if (j + (j - i) > n) continue;
				if (s[tmp] == 'G') ans--;
			}
			if (s[i] == 'B' && s[j] == 'G') {
				ans += resr[n] - resr[j];
				int tmp = j + (j - i);
				if (j + (j - i) > n) continue;
				if (s[tmp] == 'R') ans--;
			}
			if (s[i] == 'G' && s[j] == 'B') {
				ans += resr[n] - resr[j];
				int tmp = j + (j - i);
				if (j + (j - i) > n) continue;
				if (s[tmp] == 'R') ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;

using namespace std;

int main(){
    string s;   cin >> s;
    int l = s.length();
    int cnt = 0;
    for(int i=0; i<l; i++) if(s[i] != s[l-i-1]) cnt++;
    print(cnt/2);
}

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

int main(){
    int x,y;
    cin>>x>>y;
    rep(i,x+1){

     if((2*i+4*(x-i))==y){
        cout<<"Yes";
        return 0;
    
        }
    }
cout<<"No";
return 0;
}

Measured memory_bytes: 3636
using System;

namespace ARC071_E___TrBBnsformBBtion
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();

            var accumAS = new int[S.Length + 1];
            for (int i = 1; i < S.Length + 1; i++) accumAS[i] = accumAS[i - 1] + (S[i - 1] == 'B' ? 2 : 1);

            var accumBS = new int[S.Length + 1];
            for (int i = 1; i < S.Length + 1; i++) accumBS[i] = accumBS[i - 1] + (S[i - 1] == 'A' ? 2 : 1);

            var accumAT = new int[T.Length + 1];
            for (int i = 1; i < T.Length + 1; i++) accumAT[i] = accumAT[i - 1] + (T[i - 1] == 'B' ? 2 : 1);

            var accumBT = new int[T.Length + 1];
            for (int i = 1; i < T.Length + 1; i++) accumBT[i] = accumBT[i - 1] + (T[i - 1] == 'A' ? 2 : 1);



            var q = int.Parse(Console.ReadLine());
            for (int i = 0; i < q; i++)
            {
                var abcd = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                var a = abcd[0]; var b = abcd[1]; var c = abcd[2]; var d = abcd[3];

                var partAS = accumAS[b] - accumAS[a - 1];
                var partAT = accumAT[d] - accumAT[c - 1];
                var partBS = accumBS[b] - accumBS[a - 1];
                var partBT = accumBT[d] - accumBT[c - 1];
                var canConversion = (Math.Abs(partAT - partAS) % 3 == 0) || (Math.Abs(partBT - partBS) % 3 == 0);
                Console.WriteLine(canConversion ? "YES" : "NO");
            }
        }
    }
}


Measured memory_bytes: 17720
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int main(){
  string s; cin >> s;
  int s_size = s.size();
  char w[4] = {'N','W','S','E'};
  map<char,bool> mp; for(c:w){mp[c] = false;}
  REP(i,s_size){
    char temp = s[i];
    mp[temp] = true;
    bool check = true; for(c:w){check *= mp[c];}
    if(check){break;}
  }
  if( (mp['N']==mp['S']) && (mp['W']==mp['E']) ){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }
}
  

Measured memory_bytes: 256
import itertools

N = int(input())
P = tuple([int(x) for x in input().split()])
Q = tuple([int(x) for x in input().split()])
numbers = []
for i in range(N):
    numbers.append(i + 1)
numbers = tuple(numbers)

combination = sorted(list(itertools.permutations(numbers)))

a = combination.index(P)
b = combination.index(Q)

print(abs(a - b))

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

const int M=1e5+5;
vector<int> g[M];

int dp[M];
int dfs(int u)
{
	if(dp[u]) return dp[u];
	for(int v:g[u])
		dp[u]=max(dp[u],dfs(v));
	return ++dp[u];
}

int main()
{
	int n,m; cin>>n>>m;
	int u,v;
	for(int i=0;i<m;i++)
	{
		cin>>u>>v;
		g[u].push_back(v);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=max(ans,dfs(i));
	cout<<ans-1<<endl;
	return 0;
}


Measured memory_bytes: 7424
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)

    num = 0
    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if len(co) == 1 and len(ce) == 1:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = min(num_o_1 + num_e_2, num_o_2 + num_e_1)
    print(num)
    return

def len2(l):
    n = 0
    for i in l:
        n += 1
    return n

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()


Measured memory_bytes: 29836
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()
#define INF 1e9 + 7
using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;
typedef long long ll;

int GetDigit(int x) {
    int digit = 0;
    while (x) {
        x /= 10;
        digit++;
    }
    return digit;
}

main() {
    ll a,b;
    cin >> a >> b;
    if(a%2 != b%2){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << (a + b) / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
	int n = sc.nextInt();
    int m = sc.nextInt();
    int gs[] = new int[m];
    int ts[] = new int[m];
    boolean imp = true;
    List iList = new ArrayList<Integer>();
    
    for(int i = 0; i < m;i++) {
      gs[i] = sc.nextInt();
      ts[i] = sc.nextInt();
      if(gs[i] == 1) iList.add(ts[i]);
      if(ts[i] == n) iList.add(gs[i]);
    }
    Collections.sort(iList);
   	
    for(int i = 0;i < iList.size()-1 && imp;i++){
         if((int)iList.get(i) == (int)iList.get(i+1)) imp = false;
    }

    if(imp) System.out.println("IMPOSSIBLE");
    else System.out.println("POSSIBLE");

  }
}


Measured memory_bytes: 67064
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)

const int inf = 1001001000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int digitsum(int i){
    int t = i;
    int ret = 0;
    while(t){
        ret += t%10;
        t /= 10;
    }
    return ret;
}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << (a-c)/(b+c) << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
using ll = long long;

int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<char>>s(h,vector<char>(w));
  vector<vector<int>>dp(h+1,vector<int>(w+1,INF));
  rep(i,h)rep(j,w)cin>>s[i][j];
  dp[0][1]=0;
  rep(i,h)rep(j,w){
    int x=dp[i][j+1];
    int y=dp[i+1][j];
    if(s[i][j]=='#'){
      if((i-1<0||s[i-1][j]!=s[i][j]))x++;
      if(j-1<0||s[i][j-1]!=s[i][j])y++;
    }
    dp[i+1][j+1]=min(x,y);
  }
  cout<<dp[h][w]<<endl;
  return(0);
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.append(X)
y.append(Y)
x_min, y_min, x_max, y_max = min(x), min(y), max(x), max(y)

if x_max >= y_min and y_max >= x_min:
    print("War")
else:
    print("No War")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;

int main(void){
    int h , a ;
    cin >> h >> a;
    int result;
    result = ceil((double)h/(double)a);
    cout << result << endl;
}

Measured memory_bytes: 256
s = input()

a = int(s[:2])
b = int(s[2:])


if a==0:
    if b > 12 or b==0:
        print('NA')
    else:
        print('YYMM')
elif a<=12:
    if b == 0:
        print('MMYY')
    elif b <=12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if b == 0:
        print('NA')
    elif b<=12:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int n, x[20], y[20];
bool parallel(int i, int j, int k, int l){
	ll dx1 = x[i] - x[j];
	ll dy1 = y[i] - y[j];
	ll dx2 = x[k] - x[l];
	ll dy2 = y[k] - y[l];
	return dx1 * dy2 == dx2 * dy1;
}
int num[1 << 16];

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	cin >> n;
	rep(i, n) cin >> x[i] >> y[i];
	rep(mask, 1 << n){
		rep(i, n) rep(j, i) if((mask >> i & 1) && (mask >> j & 1)){
			int cnt = 0;
			rep(k, n) rep(l, k) if((mask >> k & 1) && (mask >> l & 1) && parallel(i, j, k, l)) cnt++;
			num[mask] = max(num[mask], cnt * (cnt - 1) / 2);
		}
	}
	
	rep(i, 1 << n) for(int j = i; j; j = j - 1 & i) num[i] = max(num[i], num[j] + num[i ^ j]);
	cout << num[(1 << n) - 1] << endl;
	
	return 0;
}

Measured memory_bytes: 3420
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, k;
	cin >> k >> n;
	vector<int> a(n);
	for (auto &t : a) cin >> t;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int dl = (a[(i + 1) % n] - a[i]);
		dl %= k;
		dl += k;
		dl %= k;
		ans = max(ans, dl);
	}
	cout << k - ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define FIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define fore(x,a,b) for(int x=a,qwe=b; x<qwe; x++)
using namespace std;
typedef long long ll;
int N, M;
map<int,int> m;
int main(){
  cin >> N;
  fore(x,0,N){
    int tmp; cin >> tmp;
    m[tmp]++;
  }
  cin >> M;
  int can=1;
  fore(x,0,M){
    int tmp; cin >> tmp;
    m[tmp]--;
    can &= m[tmp]>=0;
  }
  cout << (can ? "YES" : "NO")<<"\n";
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL((a))), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  ll N;
  cin >> N;
  Vll A(N), B(N), C(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  REP(i, N) cin >> C[i];
  SORT(A); SORT(B); SORT(C);
  Vll B_possible(N);
  REP(i, N)
  {
    if (i != 0 && B[i] == B[i-1])
    {
      B_possible[i] = B_possible[i-1];
      continue;
    }
    ll x = B[i];
    auto Iter = lower_bound(ALL(A), x);
    ll count = Iter - A.begin();
    B_possible[i] = count;
  }
  REP(i, N-1) B_possible[i+1] += B_possible[i];
  ll tmp1, tmp2;
  ll ans = 0;
  REP(i, N)
  {
    if (i != 0 && C[i] == tmp1)
    {
      ans += tmp2;
      continue;
    }
    ll x = C[i];
    auto Iter = lower_bound(ALL(B), x);
    ll count = Iter - B.begin();
    tmp1 = C[i];
    if (count == 0) tmp2 = 0;
    else tmp2 = B_possible[count-1];
    ans += tmp2;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){

  int n,m; cin >> n >> m;
  vector<int> a(m);
  vector<int> result(n);
  for(int i = 0; i < n; i++) result[i] = i;
  for(int i = 0; i < m; i++){
    cin >> a[i];
    a[i]--;
    swap(result[a[i]],result[a[i]+1]);
  }
  sort(a.begin(),a.end());

  int ans = m;
  do{
    vector<int> perm(n);
    for(int i = 0; i < n; i++) perm[i] = i;
    for(int i = 0; i < m; i++){
      swap(perm[a[i]],perm[a[i]+1]);
    }
    if(perm == result){
      vector<int> h(n,0);
      int res = 0;
      for(int i = 0; i < m; i++){
        h[a[i]] = h[a[i]+1] = max(h[a[i]]+1,h[a[i]+1]+1);
        res = max(res,h[a[i]]);
      }
      ans = min(ans,res);
    }
  }while(next_permutation(a.begin(),a.end()));
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;	// 998244353
using ll = long long;
using namespace std;

const int bound = 100010;
vector<int> candy;

int memo[bound];
bool visited[bound];

int dfs( int n ){
	if( visited[n] == true ) return memo[n];
	visited[n] = true;
	int ans = inf;
	for( auto c : candy ){
		if( n-c >= 0 ) ans = min(ans, dfs(n-c)+1);
	}
	return memo[n] = ans;
}

int main(){
	int n; cin >> n;
	visited[0] = true;
	candy.push_back(1);
	for( int k = 6; k < bound; k *= 6 ) candy.push_back(k);
	for( int k = 9; k < bound; k *= 9 ) candy.push_back(k);
	cout << dfs(n) << endl;
}

Measured memory_bytes: 5376
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

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

    ll N, M;
    cin >> N >> M;

    struct Edge {
        ll to, c;
    };
    //edges[i][j] := 頂点iに路線jでいるときコスト0で行ける次の頂点
    vector<map<ll, vector<ll>>> edges(N);
    for (ll i = 0; i < M; i++) {
        ll p, q, c;
        cin >> p >> q >> c;
        p--; q--; c--;
        edges[p][c].push_back(q);
        edges[q][c].push_back(p);
    }

    constexpr ll INF = INT_MAX;
    vector<map<ll, pair<bool, ll>>> cost(N);
    struct Element {
        ll node, cost, c;
        bool operator>(const Element& rhs) const {
            return cost > rhs.cost;
        }
    };
    priority_queue<Element, vector<Element>, greater<Element>> pq;

    cost[0][-1] = { true, 0 };
    pq.push({ 0, 0, -1 });

    while (!pq.empty()) {
        Element t = pq.top();
        pq.pop();

        if (cost[t.node][t.c].first && t.cost > cost[t.node][t.c].second) {
            continue;
        }

        if (t.c == -1) {
            for (auto p : edges[t.node]) {
                ll new_cost = t.cost + 1;
                for (auto next : p.second) {
                    if (!cost[next][p.first].first || new_cost < cost[next][p.first].second) {
                        cost[next][p.first].first = true;
                        cost[next][p.first].second = new_cost;
                        pq.push({ next, new_cost, p.first });
                    }
                }
            }
        } else {
            ll new_cost = t.cost;
            for (auto next : edges[t.node][t.c]) {
                if (!cost[next][t.c].first || new_cost < cost[next][t.c].second) {
                    cost[next][t.c].first = true;
                    cost[next][t.c].second = new_cost;
                    pq.push({ next, new_cost, t.c });
                }
            }
            //-1への遷移
            if (!cost[t.node][-1].first || new_cost < cost[t.node][-1].second) {
                cost[t.node][-1].first = true;
                cost[t.node][-1].second = new_cost;
                pq.push({ t.node, new_cost, -1 });
            }

        }
    }

    ll ans = (cost[N - 1][-1].first ? cost[N - 1][-1].second : INF);

    cout << (ans == INF ? -1 : ans) << endl;
}

Measured memory_bytes: 89900
#include<stdio.h>

int main()
{
	int n,m;
	while(scanf("%d %d",&n,&m) != EOF)
	{
		int ans = 0;
		if(n == 0 && m == 0)
		{
			break;
		}
		for(int i = 1; i < n -1; i++)
		{
			for(int j = i + 1; j < n; j++)
			{
				for(int k = j + 1; k < n + 1; k++)
				{
					if(m == i + j + k)
					{
						ans++;
					}
				}
			}
			
		}
		printf("%d\n", ans);
	}
	return 0;
}


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

int main() {

  int N , A ;
  
  cin >> N >> A ;
  
  if (A >= N ) {
    cout << "Yes" << endl;
  }
  else if ( A >= N % 500 ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
size = int(input())
lists = input().split()
i = 0
nada = 0
twos = 0
fours = 0
while i < size:
	if int(lists[i]) % 4 == 0:
		fours += 1
	elif int(lists[i]) % 2 == 0:
		twos += 1
	else:
		nada += 1
	i += 1
if fours == 0 and nada + twos % 2 > 0:
	print("No")
elif nada + twos % 2 - 1<= fours:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 11096
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
from functools import partial, reduce
from operator import mul
prod = partial(reduce, mul)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from bisect import bisect

def main():
    N = II()
    X = LI()  # coordinate of hotels
    X.append(INF)  # banpei
    L = II()  # max move distance/day
    Q = II()
    AB = []  # two hotel (a,b)
    for _ in range(Q):
        AB.append(LI_())
    Unreachs = [[] for _ in range(N)]
    # 1day
    for i, x in enumerate(X[:-1]):
        u = bisect(X, x + L)
        Unreachs[i].append(u)
    # day 2, 4, 8, ...
    updated = True
    while updated:
        updated = False
        for i in range(N):
            u = Unreachs[Unreachs[i][-1] - 1][-1]
            updated = updated or (u != Unreachs[i][-1])
            Unreachs[i].append(u)
    # solve
    for a, b in AB:
        if a > b:
            a, b = b, a
        ans = 0
        while True:
            k = bisect(Unreachs[a], b) - 1
            if k < 0:
                ans += 1
                break
            ans += 2 ** k
            a = Unreachs[a][k] - 1
        print(ans)
    return 0

main()

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

int main(int argc, char const* argv[]) {
	int A, B, C, X;
	scanf("%d %d %d %d", &A, &B, &C, &X);
	int ans = 0;
	for (int i = 0; i < A + 1; i++) {
		if (500 * i > X) {
			continue;
		}
		for (int j = 0; j < B + 1; j++) {
			if (500 * i + 100 * j > X) {
				continue;
			}
			for (int k = 0; k < C + 1; k++) {
				if (500 * i + 100 * j + 50 * k == X) {
					ans++;
					break;
				}
			}
		}
	}
	printf("%d", ans);
	return 0;
}


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

#include "bits/stdc++.h"
using namespace std;

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

	vector<int> H(N);
	REP(i, N) {
		cin >> H[i];
	}

	int max_step = 0;
	int step = 0;
	int now_h = H[0];
	for (int i = 1; i < N; i++) {
		if (H[i] <= now_h) {
			step++;
		}
		else {
			max_step = max(step, max_step);
			step = 0;
		}
		now_h = H[i];
	}
	max_step = max(step, max_step);

	cout << max_step << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
#define p1 1000000007
#define p2 91815541
#define base 517619
#define delta 250001
#define ll long long
using namespace std;
const int N=250100;
int n,pos,a[N*2],l,r;
ll ans;
char s[N];
struct Hash
{
	ll a,b;
	void print()
	{
		printf("%lld %lld\n",a,b);
	}
}z[N*2];
Hash h[N*2],now,add;
map <Hash,int> mp;
inline ll m_pow(ll a,int b,int mod)
{
	ll ans=1;
	while (b)
	{
		if (b&1) ans=(ans*a)%mod;
		b>>=1;
		a=(a*a)%mod;
	}
	return ans;
}
bool operator <(Hash a,Hash b){return(a.a<b.a || (a.a==b.a && a.b<b.b));}
Hash operator -(Hash a,Hash b){a.a=(a.a-b.a+p1)%p1;a.b=(a.b-b.b+p2)%p2;return a;}
Hash operator +(Hash a,Hash b){a.a=(a.a+b.a)%p1;a.b=(a.b+b.b)%p2;return a;}
Hash operator *(Hash a,Hash b){a.a=(a.a*b.a)%p1;a.b=(a.b*b.b)%p2;return a;}
Hash operator *(Hash a,ll b){a.a=(a.a*b)%p1;a.b=(a.b*b)%p2;return a;}
Hash operator +(Hash a,ll b){a.a=(a.a+b%p1)%p1;a.b=(a.b+b%p2)%p2;return a;}
Hash operator -(Hash a,ll b){a.a=(a.a-b%p1+p1)%p1;a.b=(a.b-b%p2+p2)%p2;return a;}
Hash operator /(Hash a,Hash b)
{
	a.a=(a.a*m_pow(b.a,p1-2,p1))%p1;
	a.b=(a.b*m_pow(b.b,p2-2,p2))%p2;
	return a;
}
signed main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	pos=250000;l=inf;r=0;
	for (int i=1;i<=n;i++)
	{
		l=min(l,pos);r=max(r,pos);
		if (s[i]=='+') a[pos]++;
		if (s[i]=='-') a[pos]--;
		if (s[i]=='>') pos++;
		if (s[i]=='<') pos--;
	}
	z[0].a=1;z[0].b=1;
	for (int i=1;i<=r;i++) z[i]=z[i-1]*base;
	pos=250000;
//	for (int i=l;i<=r;i++) add=add+z[i]*delta;
//	for (int i=l;i<=r;i++) h[0]=h[0]+z[i]*delta;
	for (int i=1;i<=n;i++)
	{
		h[i]=h[i-1];
		if (s[i]=='+') h[i]=h[i]+z[pos];
		if (s[i]=='-') h[i]=h[i]-z[pos];
		if (s[i]=='>') pos++;
		if (s[i]=='<') pos--;
	}
	now=h[n];h[0].a=h[0].b=0;
	for (int i=1;i<=n;i++) mp[h[i]]++;
	pos=250000;
	for (int i=1;i<=n;i++)
	{
//		(now*z[pos-250000]+h[0]).print();
		if (pos>250000) ans+=mp[now*z[pos-250000]+h[0]];
		else ans+=mp[now/z[250000-pos]+h[0]];
		mp[h[i]]--;
		if (s[i]=='+') h[0]=h[0]+z[pos];
		if (s[i]=='-') h[0]=h[0]-z[pos];
		if (s[i]=='>') pos++;
		if (s[i]=='<') pos--;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 43144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin>>h>>w;
 
  for(int i=0;i<w+2;i++)
  	cout<<"#";
  cout<<endl;
  for(int i=0;i<h;i++){
  	string a;
  	cin>>a;
  	cout<<"#"<<a<<"#"<<endl;
  }
  for(int i=0;i<w+2;i++)
  	cout<<"#";
  cout<<endl;
} 

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException  e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}
	public static int H, W; 
	public static char[][] map; 
	public static long[][] dp; 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc = new FastReader(); 
		H = sc.nextInt(); W = sc.nextInt();
		map = new char[H+10][W+10];
		dp = new long[H+10][W+10]; 
		for (int i=0; i<=H; i++) {
			Arrays.fill(dp[i], -1);
		}
		for (int i=0; i<H; i++) {
			map[i] = sc.next().toCharArray(); 
		}
		System.out.println(rc(0, 0)%1000000007);
	}
	public static long rc(int r, int c) {
		if (!isValid(r, c) || map[r][c]=='#') {
			return 0; 
		}
		if (dp[r][c]!=-1) {
			return dp[r][c]; 
		}
		else if (r==H-1 && c==W-1){
			return 1; 
		}
		else {
			
			return dp[r][c] = (rc(r+1, c) + rc(r, c+1))%1000000007; 
		}

	}
	public static boolean isValid(int r, int c) {
		if (r>=0 && r<H && c>=0 && c<W) {
			return true; 
		}
		return false; 
	}

}


Measured memory_bytes: 51560
s = int(input())
n = list(map(int,input().split()))
S = []
count=0
for i in range(1,len(n)-1):
    S = []
    S.extend(n[i-1:i+2])
    S.sort()
    if S[1]==n[i]:
        count+=1
    del S    
print(count)

Measured memory_bytes: 3060
line = input()
a, b, c, k = line.split(" ")
a, b, c, k = int(a), int(b), int(c), int(k)

if a > k:
    print(1*k)
elif a + b >= k:
    print(a)
else:
    k = k - (a+b)
    print(a - k)


Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int remainBlood[101];

int main() {
	int n, k;
	while(cin >> n >> k, n || k) {
		for (int i = 0; i < k; i++) {
			cin >> remainBlood[i];
		}

		bool satisfied = true;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < k; j++) {
				int amo;
				cin >> amo;
				remainBlood[j] -= amo;
				if(remainBlood[j] < 0) {
					satisfied = false;
				}
			}
		}

		cout << (satisfied ? "Yes" : "No") << endl;
	}
	return 0;
}

Measured memory_bytes: 856
(N, M) = list(map(int, input().split()))
p = [input() for _ in range(M)]


array_flag = [False] * N
array_cnt = [0] * N
for i in p:
    (pos, result) = i.split()
    pos = int(pos) - 1
    
    if result == 'AC':
        array_flag[pos] = True
    else:
        if array_flag[pos] == True:
            continue
        else:
            array_cnt[pos] += 1

answerd_cnt = 0
penalty_cnt = 0
for i in range(len(array_flag)):
    if array_flag[i] == True:
        answerd_cnt += 1
        penalty_cnt += array_cnt[i]

print(answerd_cnt, penalty_cnt)



Measured memory_bytes: 11804
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x <<  " " << x << endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int inf = 1e9 + 5;
const int mod = 1e9 + 7;

template <typename T>void print(T v){ for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(2)<<*i<<" ";cout<<endl; }
template <typename T>void print_vv(T v, bool same_line=true){for(auto i= 0; i<v.size(); i++){cout<<"{";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(3)<<v[i][j]<<",";}cout<<"},";if(same_line) cout<<endl;}cout<<endl;}

void add_self(int &a, int b){
    a+=b;
    if(a>=mod)
        a-=mod;
}

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

        vvi can(n, vi(n));
        //   g g g
        // b
        // b
        // b
        for(int i=0; i<n; i++)
            for(int j=0; j<n; j++)
                cin>>can[i][j];

        vi dp(1<<n);
        dp[0] = 1;
        // mask represents the girls matched : 
        // ex 1 0 1 1 : 0th, 1st, 3rd girl is matched and hence unavailable
        for(int mask=0; mask<(1<<n)-1; mask++){
            int boy = __builtin_popcount(mask); // boy to match
            for(int girl=0; girl<n; girl++){
                if(can[boy][girl] && !( mask & (1<<girl) ) ){ // if girl is available
                    int matched_mask = mask | (1<<girl); // match girl in mask (set girl bit = 1)
                    // dp[matched_mask] = dp[matched_mask] + dp[mask];
                    add_self(dp[matched_mask], dp[mask]);
                }
            }
        }

        cout<<dp[(1<<n)-1]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 8576
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD= 998244353;
//Variables End

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

ll modexp(ll pow,ll num){
	ll ret=1;
	while(pow){
		if(pow&1) ret = mul(ret,num);
		num = mul(num,num);
		pow/=2;
	}
	return ret;
}
ll modinv(ll num){
	return modexp(MOD-2,num);
}

bool comp(pair<int,int> &a, pair<int,int> &b){
	if(a.S-a.F==b.S-b.F)return a.F > b.F;
	else return a.S+b.F > a.F+b.S;
}
void solve(){
	int n;cin>>n;
	vector<pair<int,int>> neg,pos;
	int last=0,cur=0;
	for(int i=0;i<n;i++){
		string s;cin>>s;
		stack<char> st;
		for(int j=0;j<s.length();j++){
			if(st.empty() || st.top()==')' || s[j]=='(') st.push(s[j]);
			else st.pop();
		}
		int open=0,close=0;
		while(!st.empty() && st.top()=='(')open++,st.pop();
		while(!st.empty() && st.top()==')')close++,st.pop();
		if(open!=0 && close!=0){
			if(open>=close)pos.pb({close,open});
			else neg.pb({close,open});
		}
		else last+=close,cur+=open;
	}
	
	sort(all(pos));
	sort(all(neg),comp);
	for(int i=0;i<pos.size();i++){
		if(pos[i].F>cur){
			cout<<"No"<<endl;
			return;
		}
		cur = cur - pos[i].F + pos[i].S;
	}
	for(int i=0;i<neg.size();i++){
		if(neg[i].F>cur){
			cout<<"No"<<endl;
			return;
		}
		cur = cur - neg[i].F + neg[i].S;
	}
	
	if(cur!=last)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	 
}
int main()
{
    ios
    int ti=1;
    //cin>>ti;
    for(int i=1;i<=ti;i++)
    {
		solve();        
    }
    return 0;
        
}


Measured memory_bytes: 5268
n = int(input())

btns = []
for i in range(n):
    btn = int(input())
    btns.append(btn)


def solve(btns, n):

    attempts = 0
    current = 1

    while True:
        if attempts >= n:
            print("-1")
            return
        
        if current == 2:
            print(attempts)
            return

        current = btns[current-1]
        attempts += 1

solve(btns, n)

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

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

    vector<int> b;
    int tmp;
    rep(i,m){
        cin>>tmp;
        b.push_back(tmp);
    }

    int ans=0;
    rep(i,n){
        int sum=0;
        rep(j,m){
            cin>>tmp;
            sum+=tmp*b[j];
        }
        sum+=c;
        if(sum>0)ans++;
    }

    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if ((a * b) % 2 == 0)
            System.out.println("Even");
        else
            System.out.println("Odd");
    }
}

Measured memory_bytes: 25300