akhauriyash/Code-Regression huggingface dataset:
a,b,c=map(int,input().split())
count=0
if a%2==1 or b%2==1 or c%2==1:
    print(0)
elif a==b==c:
    print(-1)
else:
    while a%2==0 and b%2==0 and c%2==0 and (a+b+c)%2==0:
        a_i=a
        b_i=b
        c_i=c
        a=b_i//2+c_i//2
        b=a_i//2+c_i//2
        c=a_i//2+b_i//2
        count+=1
    print(count)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
	int a, b[1000] = { 0 };
	cin >> a;
	for (int i = 0;i<a; i++){
		cin >> b[i];
	}
	for (int i = a-1; i>=0; i--){
		cout << b[i];
		if (i>0){
			cout << " ";
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3020
# include <iostream>
# include <stdint.h>
# include <stdio.h>
# include <math.h>
#include <cstdlib>
# include <algorithm>
# include <string>
using namespace std;
int main(){
   
  int n,ans=0;
  cin>>n;
  while(n--){
    int a;
    cin>>a;
    int i=2;
    while(i*i<=a && a%i)i++;
    if(a%i||a==2)ans++; 
  }
  cout<<ans<<endl;


	return 0;
}



Measured memory_bytes: 3088
import numpy as np

N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]

B = np.array(B)
A = np.array(A)

result = np.dot(A, B) + C
print(np.sum(result > 0))

Measured memory_bytes: 21408
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int a[4], b[4];
	while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
		int hit = 0, blow = 0;
		for (int i = 0; i < 4; i++) {
			if (a[i] == b[i])hit++;
			for (int j = 0; j < 4; j++) {
				if (i == j)continue;
				if (a[i] == b[j])blow++;
			}
		}
		cout << hit << " " << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 3008
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end
a = []
rep 4 do
    a << gif
end

puts min(a[0],a[1])+min(a[2],a[3])


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

struct edge { int to, cost; };
typedef pair<int, int> P;
typedef pair<string, int> SP;
#define rep(i, a, b) for(int i = a; i < b; ++i)

const int INF = 1e9 + 7;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // vvvi V (50, vvi(50, vi(2500)));

    string S;
    cin >> S;
    if(S == "ABC"){
        cout << "ARC" << endl;
    }
    else{
        cout << "ABC" << endl;
    }

    return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s;
    cin>>s;
    int bgn0=0,bgn1=0;
    for(int i = 0; i < s.size(); i++)
    {
        if(i%2==0) //0,2,4,...
        {
            if(s[i]=='0') bgn1++;
            else bgn0++;
        }
        else
        {
            if(s[i]=='1') bgn1++;
            else bgn0++;
        }
    }
    cout<<min(bgn0,bgn1)<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
	set<int> s;
	int n;
	cin>>n;
	int x;
	cin>>x;
	s.insert(x);
	for(int i=1;i<n;i++)
	{
		cin>>x;
		if(s.find(x)!=s.end())
		 {cout<<"NO"; return 0;}
        else s.insert(x);
	}
    
	cout<<"YES";
	return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}


int main(){
	ll K;
	cin >> K;
	cout << 50 << endl;
	FOR(i,0,50){
		ll n = K/50 + (i<K%50);
		ll m = K-n;
		ll a = 50-1+n*50-m;
		cout << a;
		cout << (i==49?'\n':' '); 
	}

}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
MOD = 10**9+7
dp = [[0]*W for i in range(H+1)]
dp[0][0] = 1
ls = []
for h in range(2**(W-1)):
  log = ''
  flag = True
  for x in range(W-1):
    if h%2==1 and flag:
      log += '1'
      flag = False
    else:
      log += '0'
      flag = True
    h >>= 1
  ls += [log]
if W==1:
  ls = ['0']
ls = set(ls)
for i in range(H):
  for j in range(W):
#    print(dp[-1], j)
    for log in ls:
      if j==0:
        if log[j]=='1':
          dp[i+1][j+1] += dp[i][j]%MOD
        else:
          dp[i+1][j] += dp[i][j]%MOD
      elif j==W-1:
        if log[j-1]=='1':
          dp[i+1][j-1] += dp[i][j]%MOD
        else:
          dp[i+1][j] += dp[i][j]%MOD
      else:
        if log[j-1]=='1':
          dp[i+1][j-1] += dp[i][j]%MOD
        elif log[j]=='1':
          dp[i+1][j+1] += dp[i][j]%MOD
        else:
          dp[i+1][j] += dp[i][j]%MOD
print(dp[-1][K-1]%MOD)

Measured memory_bytes: 41968
use io::*;
use std::*;

fn solve(N: i64, W: i64, w: Vec<i64>, v: Vec<i64>) {
    let mut dp = vec![0; W as usize + 1];
    for (weight, value) in w.iter().zip(v.iter()) {
        for i in (1..dp.len()).rev() {
            dp[i] = cmp::max(dp[i],
                             match i as i64 - weight {
                                 d if d < 0 => 0,
                                 d => dp[d as usize] + value,
                             })
        }
    }
    println!("{}", dp.last().unwrap());
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut N: i64;
    N = scanner.next();
    let mut W: i64;
    W = scanner.next();
    let mut w: Vec<i64> = vec![0i64; (N) as usize];
    let mut v: Vec<i64> = vec![0i64; (N) as usize];
    for i in 0..(N) as usize {
        w[i] = scanner.next();
        v[i] = scanner.next();
    }
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(N, W, w, v))
        .unwrap()
        .join()
        .unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 8572
S = input()
ans = False
if(S[0]=="A" and S[2:len(S)-1].find("C") != -1 and S.count("C") == 1):
    S = S.replace("C","c")
    ans = S[1:].islower()
if(ans):
    print("AC")
else:
    print("WA")

Measured memory_bytes: 38256
import itertools
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
o=0
h=0
u=list(itertools.permutations(range(1,n+1)))
for i in range(len(u)):
    if u[i]==p:
        h=i
    if u[i]==q:
        o=i
print(abs(h-o))

Measured memory_bytes: 45168
#include<bits/stdc++.h>
#define MOD 1000000007
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
ll dp[1001][1001];
ll fact[1001];
ll ppow(ll a) {
	ll b=MOD-2;
	ll res = 1;
	while (b) {
		if (b & 1)res = (res*a) % MOD;
		a = (a*a) % MOD;
		b >>= 1;
	}
	return res;
}
ll comb(ll a, ll b) {
	return (((fact[a] * ppow(fact[a - b])) % MOD)*ppow(fact[b])) % MOD;
}
int main() {
	fact[0] = 1;
	int n, a, b, c, d; scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
	for (int i = 1; i <= n; i++)fact[i] = (fact[i - 1] * i) % MOD;
	rep(i, n)dp[i][0] = 1;
	for (int i = a - 1; i < b; i++) {
		for (int j = 0; j <= n; j++) {
			if (j)(dp[i + 1][j] += dp[i][j]) %= MOD;
			if (j - c*(i + 1) < 0)continue;
			ll y = 1, t = n - j;
			rep(p, c - 1) {
				(y *= comb(t + i + 1, t)) %= MOD;
				t += i + 1;
			}
			for (int k = c; j - k*(i + 1) >= 0 && k <= d; k++) {
				(y *= comb(t + i + 1, t)) %= MOD;
				ll o = y;
				(o *= ppow(fact[k])) %= MOD;
				(dp[i + 1][j] += dp[i][j - k*(i + 1)] * o) %= MOD;
				t += i + 1;
			}
		}
	}
	cout << dp[b][n] << endl;
}


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

int main(){
  int n, a;
  cin >> n;
  set<int> d;
  rep(i,n){
    cin >> a;
    d.insert(a);
  }
  cout << d.size() << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>

int main(){
    
    int mula=1;
    int count=0;
    int brpKali;    //4
    scanf("%d", &brpKali);
    int tambahBrp;  //3
    scanf("%d", &tambahBrp);
    for(int i=0;i<(brpKali-count);i++){
        while(mula<=tambahBrp){
            if(count>=brpKali){
                break;
            }
            mula*=2;
//            printf("dikali 2 jadi %d\n", mula);
            count++;

        }
        if(count>=brpKali){
            break;
        }
        mula+=tambahBrp;
//        printf("ditambah 3 jadi %d\n", mula);
    }
printf("%d\n", mula);


    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
	int n;
	long long int k;
	cin>>n>>k;
	long long int a[n+1]; 
	long long int dp[n+1][k+1],cumsum[n+1][k+1];
	for (int i = 1; i <= n; ++i)
	{
		/* code */cin>>a[i];
	}
	cumsum[1][0] = 1;
	for(int i=1;i<=k;i++)
	{
		if(a[1]>=i)
			{
				dp[1][i] = 1;
				cumsum[1][i] = cumsum[1][i-1] + 1;
			}
		else {dp[1][i] = 0;cumsum[1][i] = cumsum[1][i-1];} 
	}
	dp[0][0] = 1;
	dp[1][0] = 1;
	for (int i = 0; i <= n; ++i)
	{
		dp[i][0] = 1;
		cumsum[i][0] = 1;
	}
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(j >= a[i] + 1)dp[i][j] = (cumsum[i - 1][j] - cumsum[i - 1][j - a[i] - 1]+mod)%mod; 
			else dp[i][j] = (cumsum[i - 1][j])%mod;
			cumsum[i][j] = (cumsum[i][j-1] + dp[i][j])%mod;

		}
	}
	cout<<dp[n][k]%mod<<endl;
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	bool color[8] = {};
	int mincolor = 0;
	int maxcolor = 0;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if (a < 3200)
		{
			if (!color[a/400])
			{
				color[a/400] = true;
				mincolor++;
				maxcolor++;
			}
		}
		else maxcolor++;
	}
	mincolor = max(1, mincolor);
	cout << mincolor << " " << maxcolor << endl;
	return 0;
}


Measured memory_bytes: 256
N, M, K = map(int, input().split())
mod = 998244353

b = str(bin(mod-2))[2:]
blis = []
for _ in range(len(b)):
  if b[-_-1] == '1':
    blis.append(_)

def modinv(a):
  if a == 1:
    return 1
  else:
    res = 1
    n = len(b)
    li = []
    for _ in range(n):
      li.append(a%mod)
      a = a*a%mod
    for item in blis:
      res = res * li[item] %mod
    return res
"""      
inv = [0,1]
for i in range(2, N):
  inv.append((-inv[mod%i]*(mod//i))%mod)
"""
if N == 1:
  print(M)
  exit()

m = [1]
s = 1
for _ in range(N-1):
  s = s*(M-1)%mod
  m.append(s)

ncombi = [1]
c = 1
for k in range(K):
  c = c*(N-1-k)*modinv(k+1)
  c %= mod
  ncombi.append(c)

"""
olis = ncombi
for k in range(N-1):
  nlis = [1]
  for  j in range(len(olis)-1):
    nlis.append(olis[j]+olis[j+1])
  nlis.append(1)
  olis = nlis
  #print(olis)
ncombi = olis
"""
ans = 0
for k in range(K+1):
  ans = ans + m[-k -1]*ncombi[k]
  ans %= mod

ans = ans*M%mod

print(ans)

Measured memory_bytes: 103236
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<cctype>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define pq priority_queue
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 1000000009
#define init(x) memset(x,0,sizeof(x))
//需要重载的运算符：   = +=
template <class T>
struct bit{
    vector<T> a;
    int n;//size
    inline void initialize(){n=0;a.clear();}
    inline void initialize(int sz,T val){n=sz;a.clear();a.resize(sz,val);}
    inline bool empty(){return !n;}
    inline int size(){return n;}
    inline void resize(int s,T val){n=s;a.resize(s,val);}
    inline int lowbit(int x){return -x&x;}
    inline T sum(int pos){
        T res=a[pos];pos-=lowbit(pos);
        while(pos>0){res+=a[pos];pos-=lowbit(pos);}
        return res;
    }
    inline void modify(int pos,T val){//modify val(plus)
        while(pos<=n){a[pos]+=val;pos+=lowbit(pos);}
    }
};
ll n,k,p=1,ans=0;
ll a[200005],s[200005];
bit<ll> B;
vl v;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for (int i=1;i<=n;++i){
        cin>>a[i];a[i]-=k;s[i]=s[i-1]+a[i];v.pb(s[i]);
    }
    v.pb(0);
    sort(v.begin(),v.end());
    for (int i=0;i<=n;++i) a[i]=lower_bound(v.begin(),v.end(),s[i])-v.begin()+1;
    B.initialize();B.resize(n+3,0);
    for (int i=0;i<=n;++i){
        ans+=B.sum(a[i]);
        B.modify(a[i],1);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,i,l,j,lim;
	cin>>n;
	lim=sqrt(n);
	for(i=1;i<=lim;i++){
		if(n%i==0){
			j=n/i;
			l=i;
		}
	}
	cout<<j+l-2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    if(m/2 - n < 0){
        cout << m/2 << endl;
        return 0;
    }
    ll ans = min((m/2-n)/2 + n, m/2 - (m/2-n)/2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int height[N];
  for (int i=0; i<N; i++) {
    cin >> height[i];
  }
  int count = 1;
  bool flag = false;
  for (int j=1; j<N; j++) {
    for (int k=0; k<j; k++) {
      if (height[j] < height[k]) {
        flag = true;
        break;
      }
    }
    if (flag) {
      flag=false;
    } else {
      count += 1;
    }
  }
  cout << count << endl;
}

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

#define pb push_back
#define mp make_pair
#define size(n) ( int( n.size() ) )
#define sqr(n) ( (n) * (n) )
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 5;
vector < int > cycle, path, g[N], cval[N];
int to[N], vis[N], n, inCycle[N], parent[N], mex[N], st, ans = 0, nxtMex[N], cmex[N];

void Clear(){
    for ( int i = 1; i <= n; i++ ){
        vis[i] = 0;
    }
}

void dfs( int v ){
    mex[v] = 0;
    vector < int > val;
    for ( int j = 0; j < size(g[v]); j++ ){
        int u = g[v][j];
        if ( !inCycle[u] && u != parent[v] ){
            parent[u] = v;
            dfs(u);
            val.pb( mex[u] );
        }
    }
    sort( val.begin(), val.end() );
    cval[st] = val;
    for( int j = 0; j < size(val); j++ ){
        if ( val[j] == mex[v] ){
            mex[v]++;
        }
    }
}

void check( int s, int mexx, int fll ){
    int prv, res = 1;
    cmex[s] = mexx;
    vector < int > val;
    val.pb(mexx);
    int start = s;
    for ( int i = 1; i <= size(cycle) - 1; i++ ){
        prv = s;
        s = to[s];
        if ( cmex[prv] == mex[s] ){
            cmex[s] = nxtMex[s];
        }
        else{
            cmex[s] = mex[s];
        }
        val.pb( cmex[s] );
    }
    for ( int i = 1; i < size(val); i++ ){
        if ( val[i] == val[i-1] ){
            res = 0;
        }
    }
    if ( val[0] == val.back() ){
        res = 0;
    }
    if ( fll ){
        if ( val.back() != mex[start] ){
            res = 0;
        }
    }
    if ( res ){
        ans = 1;
    }
}

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int v;
    scanf("%d",&n);
    for ( int i = 1; i <= n; i++ ){
        scanf("%d",&v);
        to[i] = v;
        g[v].pb(i);
    }
    Clear();
    v = 1;
    while( !vis[v] ){
        vis[v] = 1;
        path.pb(v);
        v = to[v];
    }
    for ( int i = 0; i < size(path); i++ ){
        if ( path[i] == v ){
            for ( int j = i; j < size(path); j++ ){
                cycle.pb( path[j] );
                inCycle[ path[j] ] = 1;
            }
        }
    }
    for ( int i = 0; i < size(cycle); i++ ){
        st = cycle[i];
        dfs( cycle[i] );
        nxtMex[st] = mex[st] + 1;
        for ( int j = 0; j < size(cval[st]); j++ ){
            if ( nxtMex[st] == cval[st][j] ){
                nxtMex[st]++;
            }
        }
    }
    check( cycle[0], mex[ cycle[0] ], 0 );
    v = cycle[0];
    check( v, nxtMex[v], 1 );
    if ( !ans ){
        puts("IMPOSSIBLE");
    }
    else{
        puts("POSSIBLE");
    }
    return 0;
}


Measured memory_bytes: 24040
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1e9 + 7;

int dp[575][7][7][7];

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

	dp[3][0][2][1] = -1;
	dp[3][0][1][2] = -1;
	dp[3][2][0][1] = -1;
	for(int i=0;i<4;++i){
		for(int j=0;j<4;++j){
			for(int k=0;k<4;++k){
				++dp[3][i][j][k];
			}
		}
	} 

	auto check = [&](int j,int k,int l, int m){
								 if(j==0 && k==2 && l==1) return false;
								 if(j==0 && k==1 && l==2) return false;
								 if(j==2 && k==0 && l==1) return false;
								 if(j==0 && l==2 && m==1) return false;
								 if(k==0 && l==2 && m==1) return false;
								 if(k==0 && l==1 && m==2) return false;
								 if(k==2 && l==0 && m==1) return false;
								 if(j==0 && k==2 && m==1) return false;
								 return true;
							 };
	
	for(int i=0;i<n;++i){
		for(int j=0;j<4;++j){
			for(int k=0;k<4;++k){
				for(int l=0;l<4;++l){
					for(int m=0;m<4;++m){
						if(check(j,k,l,m)) (dp[i+1][k][l][m] += dp[i][j][k][l]) %= MOD;
					}
				}
			}
		}
	}

	int ans=0;
	for(int i=0;i<4;++i){
		for(int j=0;j<4;++j){
			for(int k=0;k<4;++k){
				(ans += dp[n][i][j][k]) %= MOD;
			}
		}
	}
	cout << ans << endl;
 
  return 0;
}


Measured memory_bytes: 384
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    //    ifstream in("input.txt");
    //    cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s1, s2;
    cin >> s1;
    cin >> s2;
    
    for (int i = 0; i < s1.size(); ++i)
    {
        bool isSame = true;
        rep(k, s1.size())
        {
            int init_idx = k - i;
            if (init_idx < 0) init_idx = int(s1.size()) + init_idx;
            if (s2[k] != s1[init_idx]) isSame = false;
        }
        if (isSame)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int t = sc.nextInt();

        if (t <= X) {
            System.out.println(X - t);
        } else {
            System.out.println(0);
        }
    }
}


Measured memory_bytes: 21588
using System;
using System.Collections.Generic;
using System.Linq;

public struct Task
{
    public long NeedTime;
    public long DeadLine;

    public Task(long needTime, long deadLine)
    {
        NeedTime = needTime;
        DeadLine = deadLine;
    }
}

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var task = new Task[N];
        for (int i = 0; i < N; i++)
        {
            var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            task[i] = new Task(vals[0], vals[1]);
        }

        task = task.OrderByDescending(t => t.DeadLine).ToArray();
        var current = task.First().DeadLine;
        var ok = true;
        foreach (var t in task)
        {
            current = Math.Min(current, t.DeadLine) - t.NeedTime;
            if (current < 0)
            {
                ok = false;
                break;
            }

        }

        Console.WriteLine(ok ? "Yes" : "No");
    }
}

Measured memory_bytes: 31244
import java.util.Scanner;
   public class Main{
    public void so(){
        Scanner sc=new Scanner(System.in);
        int s = 0;
        int cnt = 1;
        int a = sc.nextInt();
         
        while(a != 0){
        for(int i=1; i<=a; i++){
            int sina = sc.nextInt();
             if(sina >= 2){
                 cnt ++;
            }else if(sina == 1){
                 s ++;
            }
        }
            if(cnt >= 2){
                System.out.println(cnt+s);
            }else{
                System.out.println("NA");
            }
              s = 0;
             cnt = 1;
             a = sc.nextInt();
        }
          }
        public static void main(String[]args){
        Main obj = new Main();
        obj.so();
    }
}

Measured memory_bytes: 158552
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

/*------------------------------------------------------------------------*/

void solve();

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

    solve();
}

void solve() {
    ll n, m;
    std::cin >> n >> m;

    vll a(n);
    for (ll i = 0; i < n; i++)
        std::cin >> a[i];

    std::sort(a.begin(), a.end());

    for (ll i = 0; i < m; i++) {
        auto j = std::lower_bound(a.begin(), a.end(), a[n - 1] / 2);
        a.insert(j, a[n - 1] / 2);
        a.erase(a.end() - 1);
    }

    ll ans = std::accumulate(a.begin(), a.end(), 0LL);

    std::cout << ans << '\n';
}


Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int k=n%10;
  if(k==3)  cout<<"bon";
  else if(k==0||k==1||k==6||k==8) cout<<"pon";
  else cout<<"hon";
  return 0;
}

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

//x[a]で定義される配列を降順に並び替える
void sort_array(int x[],int a){
	int i,j,tmp;
	for(i=0;i<a-1;i++){
		for(j = i+1;j < a ; j++){
			if(x[i] < x[j]){
				tmp = x[i];
				x[i] = x[j];
                x[j] = tmp;
			}
		}
	}
}	

int main(){
	int x[10];
	int i;
	for(i = 0; i< 10; i++)
	{
		cin >> x[i];
	}
	sort_array(x , 10);
	cout << x[0] << endl;
	cout << x[1] << endl;
	cout << x[2] << endl;
	return 0;
}

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

int main()
{
    int M, D;
    cin >> M >> D;
    int ans = 0;
    for (int i = 1; i <= M; ++i){
        for (int j = 1; j <= D; ++j){
            int d1, d10;
            d10 = j / 10;
            d1 = j % 10;
            if(i == d10*d1 && d1 >= 2 && d10 >=2){
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());
            if (input >= 0 && input <= 86400)
            {
                var span = TimeSpan.FromSeconds(input);
                Console.WriteLine("{0}:{1}:{2}",
                    span.Hours,
                    span.Minutes,
                    span.Seconds);
            }
        }
    }
}

Measured memory_bytes: 5664
#include <algorithm>
#include <array>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <stack>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define MOD ((ll)1000000007)

int main(int argc, char const *argv[])
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int N;
	ll M;
	cin >> N >> M;

	vector<int> A(N, 0);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	// 昇順でソート
	sort(A.begin(), A.end());

	// min_happiness以上の幸福度を獲得可能な握手パターンがM以上あるか
	auto isOK = [&](int min_happiness) {
		ll count_shake = 0;
		// i番目との握手を固定
		for (int i = 0; i < N; i++)
		{
			// 合計の幸福度がmin_happiness以上となる最小のj
			int bound = min_happiness - A[i];
			int j = lower_bound(A.begin(), A.end(), bound) - A.begin();
			// min_happiness以上を達成可能な握手パターン数を加算
			count_shake += N - j;
		}
		return count_shake >= M;
	};

	// isOKがtrueとなる最大のmin_happinessを二分探索
	int left = 0;
	int right = A.back() * 2 + 1; // 1度の握手で獲得可能な幸福度の最大値
	while (right - left > 1)
	{
		int pivot = left + (right - left) / 2;
		if (isOK(pivot))
		{
			// OKの場合、min_happinessをもっと大きくできる
			left = pivot;
		}
		else
		{
			// NGの場合、min_happinessを緩和
			right = pivot;
		}
	}

	// 累積和を計算
	vector<ll> cumsum(N + 1, 0);
	for (int i = 0; i < N; i++)
	{
		cumsum[i + 1] = cumsum[i] + A[i];
	}

	// 合計幸福度を計算
	ll total_happiness = 0;
	ll count = 0;
	for (int i = 0; i < N; i++)
	{
		// 合計の幸福度がleft - A[i]以上となる最小のj
		int j = lower_bound(A.begin(), A.end(), left - A[i]) - A.begin();
		count += N - j;
		total_happiness += cumsum[N] - cumsum[j]; // 各jの幸福度の合計
		total_happiness += (ll)A[i] * (N - j);	// iの幸福度の合計
	}

	total_happiness -= (ll)left * (count - M);
	cout << total_happiness << endl;

	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;

int main(void) {
	i64 p1 = 0, p2 = 0;
	string s;
	cin >> s;
	for (i64 i = 0; i < s.size(); i++) {
		if (i % 2) {
			if (s[i] == '0') p1++;
			if (s[i] == '1') p2++;
		}
		else {
			if (s[i] == '1') p1++;
			if (s[i] == '0') p2++;
		}
	}
	
	cout << min(p1, p2) << endl;
}

Measured memory_bytes: 512
from itertools import product
def main():
    def is_753(s):
        return '7' in s and '5' in s and '3' in s

    S = input()
    N = int(S)
    r = 0
    for i in range(len(S)):
        for j in product('753', repeat=i + 1):
            t = ''.join(j)
            if int(t) <= N and is_753(t):
                r += 1
    return r
print(main())


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
 
using namespace std;
 
int main(void){
    string str;
    cin >> str;
    long long c[26];
    fill(c,c+26,0);
    long long n = str.length();
    for(int i=0; i<n; i++){
        c[str[i]-'a']++;
    }
    
    long long sum;
    sum = n*(n-1)/2;
    for(int i=0; i<26;i++){
        sum -= c[i]*(c[i]-1)/2;
    }
    cout << sum+1 << endl;
 
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn=900003,mod=1000000007;
int Plus(int x,int y){return (x+=y)>=mod?x-mod:x;}
void Pluseq(int &x,int y){if((x+=y)>=mod)x-=mod;}
int Minus(int x,int y){return Plus(x,mod-y);}
void Minuseq(int &x,int y){Pluseq(x,mod-y);}
int mul(long long x,int y){return x*y%mod;}
void muleq(int &x,int y){x=mul(x,y);}
int qpow(int x,int y){
    int ans=1;
    while(y){
        if(y&1)muleq(ans,x);
        muleq(x,x);
        y>>=1;
    }
    return ans;
}
int p3[maxn],fac[maxn],facinv[maxn],f[maxn];
int C(int n,int m){return n<m?0:mul(mul(fac[n],facinv[m]),facinv[n-m]);}
int main(){
    p3[0]=fac[0]=1;
    for(int i=1;i<maxn;i++)p3[i]=mul(p3[i-1],3),fac[i]=mul(fac[i-1],i);
    facinv[maxn-1]=qpow(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)facinv[i]=mul(facinv[i+1],i+1);
    int n,m,k,ans=0;
    scanf("%d%d%d",&n,&m,&k);
    if(m>k)swap(m,k);
    f[n]=1;
    for(int i=n+1;i<=n+m;i++)f[i]=mul(2,f[i-1]);
    for(int i=n+m+1;i<=n+k;i++)f[i]=Minus(mul(2,f[i-1]),C(i-n-1,m));
    for(int i=n+k+1;i<=n+m+k;i++)f[i]=Minus(mul(2,f[i-1]),Plus(C(i-n-1,i-n-k-1),C(i-n-1,m)));
    for(int i=n;i<=n+m+k;i++)Pluseq(ans,mul(mul(C(i-1,n-1),f[i]),p3[n+m+k-i]));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 16720
N, M = map(int, input().split())
lis = [[x, -1] for x in range(1, N + 1)]
Blis = [list(map(int, input().split())) for _ in range(M)]
inc = int(N*(N - 1)/2)
ans = [x for x in range(M)]
ans[M - 1] = inc
def root(a):
    if lis[a - 1][1] < 0:
        return lis[a - 1][0]
    else:
        k = root(lis[a - 1][1])
        lis[a - 1][1] = k
        return k
def size(a):
    return -lis[root(a) - 1][1]
def connect(a, b):
    A = root(a)
    B = root(b)
    if A == B:
        return None
    else:
        if size(A) < size(B):
            A, B = B, A
        lis[A - 1][1] += lis[B - 1][1]
        lis[B - 1][1] = A
for i in reversed(range(0, M)):
    if root(Blis[i][0]) != root(Blis[i][1]):
        ans[i - 1] = ans[i] - size(Blis[i][0])*size(Blis[i][1])
    else:
      ans[i - 1] = ans[i]
    connect(Blis[i][0], Blis[i][1])
ans[M - 1] = inc    
for i in range(M):
  print(ans[i])

Measured memory_bytes: 46256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m, q;
int a[55], b[55], c[55], d[55];

int A[11];
int res = 0;

void calc(int i, int k) {
    if (i == n) {
        int sum = 0;
        for (int j = 0; j < q; j++) {
            if (A[b[j]] - A[a[j]] == c[j])
                sum += d[j];
        }
        res = max(res, sum);
    } else {
        A[i] = k;
        for (int j = k; j <= m; j++) {
            calc(i+1, j);
        }
    }
}

int solve() {
    for (int i = 1; i <= m; i++) {
        calc(0, i);
    }
    return res;
}

void input() {
    cin >> n >> m >> q;
    for (int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3132
using System;
using System.Collections;
using System.Linq;


public class ABC077_Rotation
{
	public static void Main()
	{
		double N = double.Parse(Console.ReadLine());
        bool b = false;
        double heihou;
        while(b == false){
            heihou = Math.Sqrt(N);
            if(heihou - Math.Floor(heihou) == 0){
                b = true;
                break;
            }
            N--; 
        }
        Console.WriteLine(N);
	}
}

Measured memory_bytes: 13140
N = int(input())
A = list(map(int,input().split()))
ave = sum(A) / N
ave_A = [0]*N
output = 10000007
for i in range(N):
  ave_A[i] = abs(A[i] - ave)
for i in range(N):
  output = min(output, ave_A[i])
print(ave_A.index(output))

Measured memory_bytes: 9180
#include <iostream>
using namespace std;
int main(){
    int a,b,c,i,x;
    a =0;
    b =0;
    c =0;
    for (int n=0;n<10;n++){
        cin >> i;
        if (c < i)
            c = i;
        if (b < c){
            x = b;
            b = c;
            c = x;
        }
        if (a < b){
            x = a;
            a = b;
            b = x;
        }

    }
    cout << a << endl << b << endl << c << endl;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <algorithm>
using namespace std;
int h[200200], v[200200];
const int N = 1 << 18;
long long b[N+N];
void update(int p, long long x) {
	p += N;
	b[p] = x;
	while (p > 1) {
		p >>= 1;
		b[p] = max(b[p+p], b[p+p+1]);
	}
}
long long get(int x) {
	long long r = 0;
	int p = 1;
	for (int i = 17; i >= 0; i--) {
		if (x >> i & 1) {
			r = max(b[p+p], r);
			p = p + p + 1;
		} else {
			p += p;
		}
	}
	return r;
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
		--h[i];
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &v[i]);
		update(h[i], get(h[i]) + v[i]);
	}
	printf("%lld\n", *max_element(b + N, b + N + n));
	return 0;
}


Measured memory_bytes: 5376
//ABC130A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << min({a+b,b+c,c+a}) << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = ReadLongs();
            var N = inputs[0];
            var Y = inputs[1];

            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j <= N; j++)
                {
                    if (9000 * i + 4000 * j == Y - 1000 * N)
                    {
                        var k = N - i - j;
                        if (k < 0) continue;
                        return string.Join(" ", i, j, k);
                    }
                }
            }

            return "-1 -1 -1";
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 11348
#include "bits/stdc++.h"
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;

  vector<vector<char>> dt((H + 1), vector<char>((W + 1), '0'));

  for(int i = 0; i < H; i++)
  {
    for(int j = 0; j < W; j++)
    {
      cin >> dt.at(i).at(j);
      if (dt.at(i).at(j) == '#') {
        dt.at(i).at(W) = '1';
        dt.at(H).at(j) = '1';
      }
    }
  }

  for(int i = 0; i < H; i++)
  {
    for(int j = 0; j < W; j++)
    {
      if (dt.at(i).at(W) == '0' || dt.at(H).at(j) == '0') {
        continue;
      }else{
        cout << dt.at(i).at(j);
      }
    }
    if (dt.at(i).at(W) == '1') {
      cout << endl;
    }
  }

  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { int u, v, cost; };
int mod = 1000000007;
vector<int>V;
signed main() {
	int n; cin >> n;
	
	while (n) {
		V.push_back(abs(n)%2);
		if (n %2!=0) {
			if (n >= 0) {
				n /= 2;
				n *= -1;
			}
			else {
				n *= -1;
				n++;
				n /= 2;
			}
		}
		else n /= (-2);
	}
	if (V.empty())V.push_back(0);
	for (int i = V.size() - 1; i >= 0; i--)cout << V[i];
	cout << endl;
}


Measured memory_bytes: 384
n,A,B,c,d=map(int,input().split())
s=input()
b=B-1
a=A-1
t=0
while t<2*n:
  if a!=c-1:
    if a+1<n and s[a+1]=='.' and a+1!=b:
      a+=1
    elif a+2<n and s[a+2]=='.' and a+2!=b and a+2<=c-1:
      a+=2
    else:
      if b+1<n and s[b+1]=='.' and b+1!=a:
        b+=1
      elif b+2<n and s[b+2]=='.' and b+2!=a and b+2<=d-1:
        b+=2
  else:
    if b!=d-1:
      if b+1<n and s[b+1]=='.' and b+1!=a:
        b+=1
      elif b+2<n and s[b+2]=='.' and b+2!=a and b+2<=d-1:
        b+=2
  t+=1
if a==c-1 and b==d-1:
  print('Yes')
else:
  print('No')

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

using namespace std;

typedef long long ll;

int main() {
    string s;
    cin >> s;
    int n = (int) s.size();

    ll sum = 0;
    for (int bit = 0; bit < 1 << (n - 1); ++bit) {
        ll tmp = s[0] - '0';
        for (int i = 0; i < n - 1; ++i) {
            if (bit >> i & 1) {
                sum += tmp;
                tmp = s[i + 1] - '0';
            } else {
                (tmp *= 10) += s[i + 1] - '0';
            }
        }
        sum += tmp;
    }

    cout << sum << endl;
}

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

mi = 1e15
cnt = 0
for i in range(N):
  if A[i] < 0:
    cnt += 1
    A[i] = -A[i]
  if mi > A[i]:
    mi = A[i]

Ans = sum(A)
if cnt % 2 == 1:
  Ans -= mi * 2

print(Ans)


Measured memory_bytes: 14412
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k, ans = 0, x;
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> x; 
        if(x <= k / 2) ans += x * 2;
        else ans += (k - x) * 2;
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

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

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}


template <typename T>
void vecOutPadding(vector<T>& vec, string pad = " ") {
	for (const T& elem : vec)
		cout << elem << pad;
}

template <typename T>
void matOut(vector<vector<T>>& mat) {
	for (const auto& row : mat) {
		for (const T& col : row)
			cout << col << " ";
		cout << endl;
	}
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	ll Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;

	ll L1 = min({ 4 * Q, 2 * H, S });
	ll L2 = min(2 * L1, D);

	if (2 * L1 == L2) {
		cout << N * L1 << endl;
	}
	else {
		cout << N / 2 * L2 + (N % 2) * L1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
bool comp(const pair<long long int,long long int> a, const pair<long long int,long long int> b)
{
  if(a.first != b.first)
  {
    return a.first < b.first;
  }
    return a.second > b.second;
}
int main()
{
  int n;
  cin >> n;
  vector<pair<long long int,long long int> > v;
  for(int i = 0;i < n;i++)
  {
    long long int a,b;
    cin >> a >> b;
    v.push_back(make_pair(b,a));
  }
  sort(v.begin(),v.end(),comp);
  long long int work_sum = 0;
  for(int i = 0;i < n;i++)
  {
    work_sum = work_sum + v[i].second;
    if(v[i].first < work_sum)
    {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
 
  return 0;
}

Measured memory_bytes: 6384
using System;
using System.Collections.Generic;

class Program
{
    static int Max(int n, int[] rate)
    {
        int maxer = rate[1] - rate[0];
        int miner = rate[0];

        for (int i = 1; i < n; i++)
        {
            maxer = maxer > rate[i] - miner ? maxer : rate[i] - miner;
            miner = miner < rate[i] ? miner : rate[i];           
        }

        return maxer;
    }

    static void Main(string[] args)
    {

        int n = int.Parse(Console.ReadLine());
        int max = 0;
        var rate = new int[n];
        
        for (int i = 0; i < n; i++)
        {
            rate[i] = int.Parse(Console.ReadLine());
        }

        max = Max(n, rate);

        Console.WriteLine(max);       

    }
}


Measured memory_bytes: 20316