akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>
#include <set>
#include <map>
#

#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

typedef complex<int> POINT;
template <class T>
class vevector : public vector<vector<T>>
{
public:
	using vector<vector<T>>::operator []; 
	T& operator [](const POINT &index) { return (*this)[index.real()][index.imag()]; }
};

template <class T> T read() { T t; cin >> t; return t; }
template <> POINT read<POINT>() { int x, y; cin >> x >> y; return POINT(x, y); }
template <class T> vector<T> read(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i,n) v.push_back(read<T>(m)); return v; }
template <class T> void write(const T &t) { cout << t << endl; }
template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; }

template <class T> void write(const vector<T> &v)
{
	ostringstream ss; 
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	cout << s.substr(0, s.length() - 1) << endl;
}

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__

void solve();
int main() { solve(); return 0; }

vector<unsigned char> isPrime;
vector<int> primes;
void initPrimes(int n)
{
	isPrime = vector<unsigned char>(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	FOR(i, 2, n)
	{
		if (!isPrime[i]) continue;
		primes.push_back(i);
		for (int j = i * 2; j <= n; j += i)
			isPrime[j] = false;
	}
}
/// template end ///

void solve()
{
	while (true)
	{
		READ(int, e);
		if (!(e)) { break; }
		
		int ez = pow(e, 1/3.0) + 2; // cbrt
		int ey = sqrt(e) + 2;
		
		int minimumM = INF;
		REP(z, ez) REP(y, ey) 
		{
			int x = e - z*z*z - y*y;
			if (x < 0) break;
			minimumM = min(minimumM, x + y + z);
		}
		write(minimumM);
	}
}

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

int main() {
    // エラトステネスのふるい
    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
  for (int i = 2; i < MAX; ++i) {
    if (!is_prime[i]) continue;
    for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
  }
  vector<int> a(MAX, 0);
  for (int i = 0; i < MAX; i++) {
    if (i % 2 == 0) continue;
    if (is_prime[i] && is_prime[(1 + i)/2]) a[i] = 1;
  }
    vector<int> s(MAX+1, 0);
    for (int i = 0; i < MAX; i++) s[i+1] = s[i] + a[i];
    
    int Q; cin >> Q;
    for (int q = 0; q < Q; q++) {
    int l, r;
    cin >> l >> r;
    r++;
  
        cout << s[r] - s[l] << endl;
    }
    }

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdint.h>

int main(void) {
  int N;
  scanf("%d", &N);

  int minus = 0;
  int min = 1000000001;
  int64_t sum = 0;
  for(int i = 0; i < N; i++) {
    int64_t A;
    scanf("%ld", &A);
    int64_t B = (A < 0) ? -A : A; 
    sum += B;
    if(A < 0) minus++;
    if(B < min) min = B;
  }

  if(minus % 2) {
    sum -= min*2;
  }
  printf("%ld\n", sum);
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
const int INFN = 12e5 + 5;
const int MAXN = 12;
int A[MAXN][MAXN];
int C[MAXN];
int M, N, X;

int main() {
  scanf(" %d%d%d", &N, &M, &X);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &C[i]);
    for (int j = 0; j < M; ++j) {
      scanf("%d", &A[i][j]);
    }
  }
  int L = 1 << N;
  int ret = INFN;
  for (int mask = 1; mask < L; ++mask) {
    int B[MAXN]{ };
    int cost = 0;
    for (int bit = 0; bit < N; ++bit) {
      if ((mask >> bit) & 1) {
        for (int j = 0; j < M; ++j) {
          B[j] += A[bit][j];
        }
        cost += C[bit];
      }
    }
    auto pred = [](int u) { return (u >= X); };
    if (std::all_of(B, B + M, pred)) {
      ret = std::min(cost, ret);
    }
  }
  if (ret == INFN) {
    ret = -1;
  }
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 3172
//Created Time:2019年09月28日 星期六 20时05分47秒
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int a[100005], b[100005];

bool cmp(int x, int y){
	return a[x] < a[y];
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a + i), b[i] = i;
	sort(b + 1, b + 1 + n, cmp);
	for(int i = 1; i <= n; ++i) printf("%d ", b[i]);
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) {
        cin >> A[i];
    }

    map<int, int> G;
    rep(i, N) {
        G[A[i]]++;
    }

    bool ok = true;
    switch (G.size()) {
        case 1:
            if (A[0] != 0) ok = false;
            break;
        case 2:
            for (auto x: G) {
                if (x.first == 0) {
                    if (x.second != (N / 3)) {
                        ok = false;
                    }
                } else {
                    if (x.second != (2 * N / 3)) {
                        ok = false;
                    }
                }
            }
            break;
        case 3:
            {
                ll y = 0;
                for (auto x: G) {
                    if (x.second != (N / 3)) ok = false;
                    y ^= x.first;
                }
                if (y != 0) ok = false;
            }
            break;
        default:
            ok = false;
            break;
    }

    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 7232
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,m,t,b,s=0,i,max=0,c=0,cnt=0,j,k;
    cin>>n;
    ll a[n+1];
    set <ll> ss;
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(i=0;i<n-2;i++){
        for(j=i+1;j<n-1;j++){
                if(a[i]==a[j])continue;
            for(k=j+1;k<n;k++){
                if(a[j]==a[k] || a[k]==a[i])continue;
               else if((a[i]+a[j])>a[k]){
                    c++;

               }
            }

        }

    }
cout<<c<<endl;


}


Measured memory_bytes: 3592
S = gets.chomp

ANS = []
def insert_pm(s, i)
  (ANS << s; return) if i == 0
  ['+', '-'].each{|o|
    wk = s[0, i] + o + s[i..-1]
    insert_pm(wk, i-1)
  }
end

insert_pm(S, 3)

ANS.each{|ans|
  if eval(ans) == 7 then
    puts ans + '=7'
    break
  end
}


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};
vector<ll>graph[N];
ll ar[N];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n, m, i, j, u, v, cnt = 0, ans = 0;
    cin >> n >> m;
    for(i = 1; i <= n; i++){
        cin >> ar[i];
    }
    for(i = 0; i < m; i++){
        cin >> u >> v;
        graph[u].eb(v);
        graph[v].eb(u);
    }
    for(i = 1; i <= n; i++){
        cnt = 0;
        for(auto adj: graph[i]){
            if(ar[i] > ar[adj]){
                cnt++;
            }
        }
        if(cnt == graph[i].size()){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 14928
import math
N, D = map(int, input().split())
X = []
ans = 0
for i in range(N):
	x = list(map(int, input().split()))
	X.append(x)
	for j in range(i):
		l = 0
		for k in range(D):
			l += (X[j][k] - x[k]) ** 2
		r = math.sqrt(l)
		if l - math.floor(r) ** 2 == 0:
			ans += 1
print(ans)

Measured memory_bytes: 3064
r,c = tuple([int(x) for x in raw_input().split(" ")])

A = []

for i in range(r):
    A.append([int(x) for x in raw_input().split(" ")])

for lst in A:
    lst.append(sum(lst))
    print(" ".join([str(x) for x in lst]))

lst2=[0 for x in range(c)]
for i in range(c):
   for j in range(r):
       lst2[i] += A[j][i]

lst2.append(sum(lst2))
print " ".join([str(x) for x in lst2])

Measured memory_bytes: 4308
url = "https://atcoder.jp//contests/abc076/tasks/abc076_b"

def main():
    N = int(input())
    K = int(input())
    ans = 1
    for i in range(N):
        ans = min(ans * 2, ans + K)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n=int(input())
a=[int(x) for x in input().split()]
cnt=0
ans=0
i=0
while i<len(a)-1:
    if a[i]>=a[i+1]:
        cnt+=1
    else:
        ans=max(ans,cnt)
        cnt=0
    i+=1
    ans=max(ans,cnt)
print(ans)


Measured memory_bytes: 85396
def roof(a, b):
    if a%b == 0:
        return a//b
    else:
        return a//b + 1

N, A, B = map(int, input().split())
H = [int(input()) for i in range(N)]

low, high = 0, 10**9
while high - low > 1:
    mid = (low + high)//2
    count = 0
    for i in range(N):
        if H[i] - (B * mid) > 0:
            count += roof(H[i]-(B*mid), A-B)
    if count > mid:
        low = mid
    else:
        high = mid
print(high)

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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    int ans;
    sort(d.begin(), d.end());
    ans = d[n/2] - d[n/2 -1];

    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define mp make_pair

#define F first
#define S second

using ll = long long;
using namespace std;

void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

const int mod = 1000000007;
const int INF = 1e+9;

int main() {
    int n; cin >> n;
    ll a[100010][3];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }

    ll dp[100010][3];
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < 3; j++) {
            dp[i][j] = 0;
        }
    }

    // jとkが一致していなければ更新
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j != k) {
                    chmax(dp[i+1][k], dp[i][j]+a[i][k]);
                }
            }
        }
    }

    ll res = 0;
    for (int i = 0; i < 3; i++) chmax(res, dp[n][i]);
    cout << res << endl;
}


Measured memory_bytes: 4992
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    vector<long long> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    vector<long long> sums(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        sums[i + 1] = sums[i] + A[i];
    }

    const long long MOD = 1000000007;

    long long res = 0;
    long long total = sums.back();
    for (int i = 0; i < n; ++i) {
        total -= A[i];
        res += (A[i] * (total % MOD)) % MOD;
        res %= MOD;
    }

    cout << res << '\n';


    return 0;
}

Measured memory_bytes: 6280
#include <iostream>

using namespace std;
int b[110];
int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n - 1;i++){
		cin >> b[i];
	}
	int ans = b[n - 2];
	for(i=0;i<n - 1;i++){
		if(i==0) ans += b[i];
		else ans += min(b[i - 1],b[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N (1<<20)
using namespace std;
typedef long long ll;
string str;
int bit[N+1],n;
int a[N];

int sum(int i){
  int res=0;
  while(i>0){
    res+=bit[i];
    i-=i&-i;
  }
  return res;
}

void add(int i,int x){
  while(i<=n){
    bit[i]+=x;
    i+=i&-i;
  }
}

ll solve(){
  n=str.size();
  int cnt[30]={},cnt2[30]={};
  for(int i=0;i<n;i++)cnt[str[i]-'a']++;
  for(int i=0;i<30;i++)if(cnt[i]%2)return -1;
  
  int A=0;
  stack <int> stk[30];
  
  for(int i=0;i<n;i++){
    int idx=str[i]-'a';
    if(cnt[idx]/2>cnt2[idx]){
      stk[idx].push(A);
      A++;
      cnt2[idx]++;
      a[i]=A;
    }
    else {
      a[i]=n-stk[idx].top();
      stk[idx].pop();
    }
  }

  ll ans=0;
  for(int j=0;j<n;j++){
    ans+=j-sum(a[j]);
    add(a[j],1);
  }
  return ans;
}


int main(){
  cin>>str;
  cout <<solve()<<endl;  
  return 0;
}

Measured memory_bytes: 5948
N = int(input())
S = list(input())
MOD = 10**9+7
BW = "BW"
ans = 1
hoge = 0
for i in range(2*N):
    if S[i] == BW[i%2]:
        hoge += 1
    else:
        ans *= hoge
        ans %= MOD
        hoge -= 1
if hoge != 0:
    ans = 0
for i in range(1,N+1):
    ans *= i
    ans %= MOD
print(ans)

Measured memory_bytes: 61680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  int n, t;
  cin >> n >> t;
  vector<int> cost(n), time(n);
  priority_queue<int, vector<int>, greater<int>> q;
  for (int i = 0; i < n; i++) {
    cin >> cost.at(i) >> time.at(i);
    if (time.at(i) <= t) q.push(cost.at(i));
  }
  if (q.size() == 0) cout << "TLE" << endl;
  else cout << q.top() << endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  ll T1 = nextLong();
  ll T2 = nextLong();
  ll A1 = nextLong();
  ll A2 = nextLong();
  ll B1 = nextLong();
  ll B2 = nextLong();

  if (A1 < B1) {
    swap(A1, B1);
    swap(A2, B2);
  }

  ll D1A = T1 * A1;
  ll D2A = T1 * A1 + T2 * A2;
  ll D1B = T1 * B1;
  ll D2B = T1 * B1 + T2 * B2;

  if (D1A == D1B) {
    cout << "infinity" << endl;
    return 0;
  }
  if (D2A == D2B) {
    cout << "infinity" << endl;
    return 0;
  }
  if (D2A > D2B) {
    cout << 0 << endl;
    return 0;
  }

  ll H1 = (A1 - B1) * T1;
  ll H2 = -(H1 + (A2 - B2) * T2);

  ll n = H1 / H2 + 1;

  ll ans = 2 * (n) - 1;
  if ( -(n-1)*H2 + H1 == 0) ans--;

  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
res = 0
if N == 1:
    print(A1[0]+A2[0])
    exit()
for i in range(2):
    for j in range(N):
        temp = sum(A1[i:j])+sum(A2[j-1:N])
        if temp > res:
            res = temp
print(res)

Measured memory_bytes: 38700
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

# ACが出ていない問題のWAは数えない
N, M = map(int, input().split())
flag = ["WA"]*(N+1)
WAcnt = [0]*(N+1)
ans = {"AC":0, "WA":0}

for _ in range(M):
  i, s = input().split()
  ind = int(i)
  s = s.decode()
  if flag[ind] == "AC":
    continue
  if s == "AC":
    ans[s] += 1
    ans["WA"] += WAcnt[ind]
    flag[ind] = s
  else:
    WAcnt[ind] += 1
    

print(ans["AC"], ans["WA"])    

Measured memory_bytes: 10096
fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let k: i32 = read();

    for i in a..b+1 {
        if (a <= i && i <= a+k-1) || (b-k+1 <= i && i <= b) {
            println!("{}", i);
        }
    }
}

// 以下関数

use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub const MOD: u64 = 1_000_000_007;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}

pub fn abs(n: i32) -> i32 {
    if n >= 0 {
        n
    } else {
        -n
    }
}

pub fn max(n: i32, m: i32) -> i32 {
    if n >= m {
        n
    } else {
        m
    }
}

pub fn min(n: i32, m: i32) -> i32 {
    if n <= m {
        n
    } else {
        m
    }
}

pub fn factorial(n: u32) -> u32 {
    if n == 0 {
        return 1;
    }
    let mut r = n;
    for i in 0..n - 1 {
        r *= n - i - 1;
    }
    r
}

pub fn combination(n: u32, m: u32) -> u32 {
    factorial(n) / factorial(m) / factorial(n - m)
}


Measured memory_bytes: 4352
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

//const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<typename T> // T: type of cost
struct BIT {
	int n;
	vector<T> d;
	BIT(int n = 0) :n(n), d(n + 1) {}
	void add(int i, T x = 1) {
		for (i++; i <= n; i += i & -i) {
			d[i] += x;
		}
	}
	T sum(int i) {
		T x = 0;
		for (i++; i; i -= i & -i) {
			x += d[i];
		}
		return x;
	}

	long long inversion(vector<T> a) {
		long long ans = 0;
		for (int j = 0; j < a.size(); j++) {
			ans += sum(a[j]);
			add(a[j], 1);
		}
		return ans;
	}
};
ll n, k;
ll a[200020];

int main(void) {
	cin >> n >> k;
	vector<ll> c(n + 1, 0);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		a[i] -= k;
		c[i + 1] += c[i] + a[i];
	}
	if (n == 1) {
		if (a[0] >= 0) {
			cout << 1 << endl;
		}
		else {
			cout << 0 << endl;
		}
		return 0;
	}
	//cを座標圧縮する
	vector<ll> b(n+1);
	for (int i = 0; i < n+1; i++)
	{
		b[i] = c[i];
	}
	sort(all(b));
	UNIQUE(b);
	for (int i = 0; i < n+1; i++)
	{
		c[i] = lower_bound(all(b), c[i]) - b.begin() + 1;
	}
	
	BIT<ll> bt(200020);
	cout << bt.inversion(c) << endl;
	return 0;
}

Measured memory_bytes: 8064
/*

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

*/

#include<bits/stdc++.h>
#include<assert.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0);
#define fo(i,s,n) for(int i=s;i<n;i++)
#define mod 1000000007
#define umap unordered_map
#define pb(x) push_back(x)
#define all(x) (x).begin(), (x).end()
#define lb() lower_bound()
#define ub() upper_bound()
#define PI 3.14159265
#define S second
#define F first 
//fill(all(vec), 1);to fill vector with a number
//if (S.count(key)) returns 1 if set or map contain key else return 0
ll nCr(ll n,ll r)
{
	r = min(r,n-r);
	if(r<0)
		 return 0;
	if(r == 0)
		return 1;
	ll ans = 1;
	for(ll i = 1;i<=r;i++)
	{
		ans = ans*(n-i+1)/i;
    }
	return ans;
 		
}


ll logn(int n, int r) 
{ 
     return (n > r - 1) ? 1 + logn(n / r, r) : 0; 
} 


ll power(ll a,ll b) {
	if(b == 1) return a;
	if(b == 0) return 1;
	ll m1 = power(a,b/2);
	if(b%2) return m1*m1*a;
	return m1*m1;
}


bool isprime(ll a)
{
    if(a<=1)
        return false;
    if(a==2||a==3)
        return true;
    if(a%2==0||a%3==0)
        return false;
    for(ll i=5;i*i<=a;i=i+6)
    {
        if(a%i==0||a%(i+2)==0)
            return false;
    }
    return true;

}
/*********************//*********************///*********************///*********************//
ll t;

void solve()
{
    int n;
    cin>>n;
    if(n>=30)
    {
        cout<<"Yes"<<endl;
        
    }
    else
    {
        cout<<"No"<<endl;
    }
    
}



int main()
{
    Fast
/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
*/
    //cin>>t;
    t=1;
    for(ll i=1;i<=t;i++)
    {
      solve();
    }

    
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
int a, b, k;

int main() {
    std::vector<int> vec;
    std::cin >> a >> b >> k;
    int c = std::min(a, b);
    int counter = 0;
    for (int i = 1; i <= c; i++) {
        if (a % i == 0 && b % i == 0) {
            vec.push_back(i);
        }
    }
    std::cout << *(vec.end() - k) << std::endl;
}


Measured memory_bytes: 256
#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() {
  string S;
  cin >> S;
  int N = S.size();

  vector<int> ans(N, 0);
  char target = 'R';
  int posR, posL, num;
  rep(i, N) {
    if (S.at(i) == target) {
      num++;
    } else {
      if (target == 'R') {
        target = 'L';
        posR = i - 1;
        posL = i;
        ans.at(posR) += (num + 1) / 2;
        ans.at(posL) += num / 2;
      } else {
        target = 'R';
        ans.at(posR) += num / 2;
        ans.at(posL) += (num + 1) / 2;
      }
      num = 1;
    }
  }
  ans.at(posR) += num / 2;
  ans.at(posL) += (num + 1) / 2;

  rep(i, N) {
    if (i != N - 1) {
      cout << ans.at(i) << " ";
    } else {
      cout << ans.at(i) << endl;
    }
  }
  return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int N, M;
vector<int> G[100];
bool visited[100];

int dfs(int from, int cnt) {
   if (cnt >= N-1) {
      return 1;
   }

   visited[from] = true;
   int ret = 0;
   for (int to : G[from]) {
      if (visited[to]) continue;
      // debug2(from, to)
      ret += dfs(to, cnt+1);
   }
   visited[from] = false;

   return ret;
}

int main() {
   cin >> N >> M;
   rep (i, M) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      G[a].push_back(b);
      G[b].push_back(a);
   }

   cout << dfs(0, 0) << endl;

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

signed main(){
	int H, W; 
	scanf("%d %d", &H, &W);
	vector<vector<char> > field(H, vector<char> (W));
	vector<int> data(26, 0);
	for(int i = 0; i < H; i++){
		string s; cin >> s;
		for(int j = 0; j < W; j++) {
			field[i][j] = s[j];
			data[field[i][j] - 'a']++;
		}
	}
	bool ok = true;
	int x = H % 2, y = W % 2;
	if(!x && !y){
		for(int i = 0; i < 26; i++) if(data[i] % 4 != 0) ok = false;
	}
	else{
		int g1, g2, g4;
		if(x && y) g1 = 1, g2 = H/2 + W/2, g4 = (H/2) * (W/2);
		else{
			if(!x) swap(H, W);
			g1 = 0, g2 = W / 2, g4 = (H/2) * (W/2);
		}
		int num = 0;
		for(int j = 0; j < 26; j++){
			if(data[j] % 2 == 1) {data[j]--; num++;};
			if(num == g1) break;
		}
		num = 0;
		for(int j = 0; j < 26; j++){
			while(data[j] >= 4) { data[j] -= 4; num++;}; 
			if(num == g4) break;
		}
		num = 0;
		for(int j = 0; j < 26; j++){
			while(data[j] >= 2) {data[j] -= 2; num++;};
			if(num == g2) break;
		}
		for(int i = 0; i < 26; i++){
			if(data[i]) ok = false;
		}
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}
	

Measured memory_bytes: 3660
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Whist solver = new Whist();
        solver.solve(1, in, out);
        out.close();
    }

    static class Whist {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            while (true) {
                String trump = in.nextLine();
                if (trump.equals("#")) break;
                String[][] cards = new String[4][];
                for (int i = 0; i < 4; i++) {
                    cards[i] = in.nextLine().split(" ");
                    assert cards[i].length == 13;
                }
                int ns = 0, ew = 0;
                // NESW
                int par = 0;
                for (int i = 0; i < 13; i++) {
                    int win = par;
                    String pcard = cards[par][i];
                    boolean tr = false;
                    for (int j = 0; j < 4; j++) {
                        if (trump.charAt(0) == cards[j][i].charAt(1)) {
                            win = j;
                            tr = true;
                            break;
                        }
                        if (par != j) {
                            if (pcard.charAt(1) != cards[j][i].charAt(1)) continue;
                            if (comp(cards[j][i].charAt(0), cards[win][i].charAt(0))) {
                                win = j;
                            }
                        }
                    }
                    if (tr) {
                        for (int j = 0; j < 4; j++) {
                            if (trump.charAt(0) == cards[j][i].charAt(1)) {
                                if (comp(cards[j][i].charAt(0), cards[win][i].charAt(0))) {
                                    win = j;
                                }
                            }
                        }
                    }
                    if (win % 2 == 0) ns++;
                    else ew++;
                    par = win;
                }
                out.println((ns < ew ? "EW" : "NS") + " " + Integer.toString(Math.max(ns, ew) - 6));
            }
        }

        public boolean comp(char c1, char c2) {
            if (c1 == 'A') return true;
            if (c2 == 'A') return false;
            int n1 = c1 == 'T' ? 10 : c1 == 'J' ? 11 : c1 == 'Q' ? 12 : c1 == 'K' ? 13 : c1 - '0';
            int n2 = c2 == 'T' ? 10 : c2 == 'J' ? 11 : c2 == 'Q' ? 12 : c2 == 'K' ? 13 : c2 - '0';
            return n1 > n2;
        }

    }
}

Measured memory_bytes: 28308
#include<stdio.h>


int IsPrime(int n) {
	if (n < 2) return 0;
	if (n == 2) return 1;

	int count = 0;
	int i, j, k;
	int flg[n];

	for (i = 1; i <= n; i++)
		flg[i] = 1;

	for (j = 2; j <= n; j++) {
		if (flg[j] == 1) count++;
		for (k = j * 2; k <= n; k += j)
			flg[k] = 0;
	}
	return count;
}

int main(void)
{
	int n[30];
	int i,j,a=0;
	int count = 0;

	while(scanf("%d",&n[a]) != EOF && a < 30)
		if ((1 <= n[a]) && (n[a] <= 999999)) {
			a++;
		}

	for (i = 0; i < a; i++) {
		count = IsPrime(n[i]);
		printf("%d\n",count);
	}
	return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) begin(n),end(n)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int a, b;
	cin >> a >> b;
	if(a + b >= 10) cout << "error" << endl;
	else cout << a + b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

static const long long MOD = 998244353;
static const long long MAX = 200005;


long long mod_pow(long long x, long long n) {
    if (n==0) return 1;
    long long res = mod_pow(x * x % MOD, n/2);
    if (n&1) res = res * x % MOD;
    return res;
}

long long fac[MAX], finv[MAX], inv[MAX]; 

void init_comb() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long combination(long long n, long long k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

ll ans;
ll n, m, k;

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

    init_comb();

    ll color = (m*mod_pow(m-1, n-k-1))%MOD;

    for (int i=k; i>=0; i--) {
        ans = (ans + (combination(n-1, i)*color)%MOD)%MOD;
        color = (color*(m-1)) % MOD;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 8324
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

m = (10**9) + 7
n = int(input())
if n == 1:
    print(0)
else:
    print((pow(10,n,m) - pow(9,n,m)*2 + pow(8,n,m))%m)

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


#define ONSPEED ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define f(i,x,n) for(i=x;i<n;i++)
#define rf(i,x,n) for(i=n;i>x;i--)
#define ll long long
#define GCD(a,b) __gcd(a,b)
#define ff first
#define ss second
#define adios return 0;

/*
tacet aquilae
*/

int main()
{
    ONSPEED;
    ll t,n,k,a,b,c,d,s=0,i,j,flag;
    string x,y;
    cin>>n>>a>>b;
    if(n==1)
    {
    	if(a==b) cout<<"1\n";
    	else cout<<"0\n";
    }
    else{
    	if(a>b) cout<<"0\n";
    	else{
    		cout<<(b-a)*(n-2)+1;
    	}
    }

    adios;
}
	


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

#define ll long long
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int W, H;
int b[30][30];
int ans;

void dfs(int y, int x, int turn) {
   if (turn > 10) return;

   for (int i = 0; i < 4; i++) {
      // 動ける範囲かを判定
      int ty = y+dy[i], tx = x+dx[i];
      if (ty<0 || ty>= H || tx<0 || tx>=W || b[ty][tx]==1) continue;

      // 障害物にぶつかるまで進む。範囲外ならreturn;
      // ゴールなら値更新
      int ny = y, nx = x;
      while (1) {
         ny += dy[i], nx += dx[i];
         if (ny<0 || ny>= H || nx<0 || nx>=W) break;
         if (b[ny][nx] == 1) { // 障害物にぶつかる
            b[ny][nx] = 0;
            dfs(ny-dy[i], nx-dx[i], turn+1);
            b[ny][nx] = 1;
            break;
         }
         if (b[ny][nx] == 3) {
            ans = min(ans, turn);
            break;
         }
      }
   }
}

int main() {
   while (cin >> W >> H, W) {
      int sy = 0, sx = 0;
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            cin >> b[i][j];
            if (b[i][j] == 2) {
               sy = i, sx = j;
            }
         }
      }
      ans = 100;
      dfs(sy, sx, 1);
      cout << (ans==100 ? -1 : ans) << endl;
   }

   return 0;
}


Measured memory_bytes: 3084
import sys

b0="A"
b1="B"
b2="AB"
b3="O"
b={b0:0,b1:0,b2:0,b3:0}
for s in sys.stdin:
    i=s.index(',')+1
    b[s[i:-1]]+=1
print b[b0]
print b[b1]
print b[b2]
print b[b3]

Measured memory_bytes: 4200
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<bitset>
#include<tuple>
#include<time.h>
#include<list>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



i64 h;
void solve(){
	cin >> h;
	
	i64 cnt = 1;
	while(h >= cnt){
		cnt <<= 1;
	}
	cout << cnt-1 << endl;
}

int main(){
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
using PQ = priority_queue<T>;
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(),v.end());
    vector<pair<int, int>> u(m);
    PQ<int> q;
    for (int i = 0; i < m; ++i) {
        scanf("%d %d", &u[i].second, &u[i].first);
    }
    for (int i = 0; i < n; ++i) {
        q.emplace(v[i]);
    }
    sort(u.begin(),u.end(), greater<>());
    int cnt = 0;
    for (int i = 0; i < m; ++i) {
        while(cnt < n && u[i].second){
            q.emplace(u[i].first);
            u[i].second--;
            cnt++;
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += q.top(); q.pop();
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string a, b;
    cin >> a >> b;
    cout << ((a == b) ? 'H' : 'D') << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f+"\n", a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func ints(cnt int, a ...interface{}) {
	format := strings.Repeat("%d"+" ", cnt)
	format = strings.TrimRight(format, " ") + "\n"
	scanf(format, a...)
}

func intSlice(cnt int) []int {
	a := make([]int, cnt)
	for i := 0; i < cnt; i++ {
		scanf("%d", &a[i])
	}
	return a
}

func strs(cnt int, a ...interface{}) {
	format := strings.Repeat("%s"+" ", cnt)
	format = strings.TrimRight(format, " ") + "\n"
	scanf(format, a...)
}

type intsDesc []int

func (v intsDesc) Len() int           { return len(v) }
func (v intsDesc) Swap(i, j int)      { v[i], v[j] = v[j], v[i] }
func (v intsDesc) Less(i, j int) bool { return v[i] > v[j] }

func main() {
	defer writer.Flush()

	var a, b int
	ints(2, &a, &b)

	n := b - a
	h := (1 + (n - 1)) * (n - 1) / 2
	printf("%d", h-a)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
vector<int> *graph;
vector<bool> zero_indeg(100001,1);
int dp[100001];

int solve(int node){
	if(dp[node]!=-1){
		return dp[node];
	}
	int bestChild=0;
	bool leaf=1;
	for (int x: graph[node]){
		leaf=0;
		bestChild = max(bestChild, solve(x));
	}
	return dp[node] = leaf?0:1 + bestChild;
}

int main(){
	int n,e,x,y;
	memset(dp,-1,sizeof(dp));
	scanf("%d%d",&n,&e);
	graph = new vector<int>[n+1];
	
	for(int i=0; i<e;i++)
		scanf("%d%d",&x,&y),graph[x].push_back(y),zero_indeg[y]=0;
	
	
	int mx = 0;
	for (int i=1;i<=n ;i++){
		if(zero_indeg[i]){
			solve(i);
			mx = max(mx, dp[i]);
		}
	}
	printf("%d", mx);
	return 0;
}


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

using namespace std;

int main()
{
	int k = 0;
	for(;;){
		char MAP[8][8];
		int cont = 0;
		int air_cont = 0;
		bool canCont = false;
		
		for(int i = 0; i < 8; i++){
			for(int j = 0; j < 8; j++){
				cin >> MAP[i][j];
				if(cin.eof()){
					return 0;
				}
			}
		}
		//ツ債カツ端ツづーツ個ゥツづつつッツづつゥツづァツ催古」ツづ個ブツδ債ッツクツつェツ個ゥツづつつゥツづゥツづ慊づづ個凝ウツ板陳青板づーツ記ツ録
		for(int i = 0; i < 8; i++){
			for(int j = 0; j < 8; j++){
				if(MAP[i][j] == '1'){
					cont++;
					if(cont == 1){
						canCont = true;
					}
					if(cont == 4){
						//ツδ仰ーツプツ仰ュツ青ァツ終ツ猟ケ
						goto FIN;
					}
				}
				else if(canCont == true && MAP[i][j] == '0'){
					air_cont++;
				}
			}
		}
		
		FIN:;
		
		switch(air_cont){
			case 0:
				cout << "C" << endl;
				break;
			case 5:
				cout << "G" << endl;
				break;
			case 6:
				cout << "A" << endl;
				break;
			case 7:
				cout << "E" << endl;
				break;
			case 12:
				cout << "D" << endl;
				break;
			case 14:
				cout << "F" << endl;
				break;
			case 21:
				cout << "B" << endl;
				break;
			default:
				cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
    int ans = 0, cnt = 1;
    int n;

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int a;
        scanf("%d", &a);
        if (a == cnt)
            cnt++;
        else
            ans++;
    }

    if (cnt == 1)
        puts("-1");
    else
        printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int L,R; cin>>L>>R;
  if(R-L>3000){
    cout<<0<<endl;
    return 0;
  }
  int best=3000;
  for(int i=L; i<=R; i++){
    for(int j=i+1; j<=R; j++){
      best=min(best,(i*j)%2019);
    }
  }
  cout<<best<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
int main(){
    int n;
    int count = 0;
    cin >> n;
    int tmp;
    for(int i = 1; i <= n; i++){
        cin >> tmp;
        if((i % 2 == 1) && (tmp % 2 == 1)){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,i,l;
    while(scanf("%d",&n)==1){
        char a[n];
        scanf("\n");
        scanf("%s",a);
        if(n%2!=0){
            printf("No\n");
        }
        else{
            l=(n/2)-1;
            for(i=0;i<=l;i++){
                if(a[i]!=a[l+i+1]){
                    printf("No\n");
                    break;
                }
            }
            if(i==l+1)
                printf("Yes\n");
        }
    }
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {

	void run() {
		Scanner sc = new Scanner(System.in);
		double[][] p = new double[3][2];
		for (int i = 0; i < 3; ++i) {
			p[i][0] = sc.nextDouble();
			p[i][1] = sc.nextDouble();
		}
		p[1][0] -= p[0][0];
		p[1][1] -= p[0][1];
		p[2][0] -= p[0][0];
		p[2][1] -= p[0][1];
		double a = dist(p[1]);
		double b = dist(p[2]);
		double c = dist(new double[] { p[1][0] - p[2][0], p[1][1] - p[2][1] });
		double s = 0.5
				* Math.sqrt(dist(p[1]) * dist(p[1]) * dist(p[2]) * dist(p[2]) - dot(p[1], p[2]) * dot(p[1], p[2]));
		double r = 2 * s / (a + b + c);
		double d = Math.max(a, Math.max(b, c));
		System.out.println(d * r / (2 * r + d));
	}

	double dist(double[] p) {
		double x = p[0];
		double y = p[1];
		return Math.sqrt(x * x + y * y);
	}

	double dot(double[] p1, double[] p2) {
		return p1[0] * p2[0] + p1[1] * p2[1];
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 24016
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int inf = 1e9;
const int mod = 1e9+7;

int main() {
	ll x;
	cin >> x;
	ll a1 = x / 11LL;

	ll t = x % 11LL;
	ll a2 = t - 6;

	ll ans;
	if (a2 > 0) ans = a1*2 + 2LL;
	else if (a2 > -6) ans = a1*2 + 1LL;
	else ans = a1 * 2;

	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K,N;
    cin >> K >> N;
    ll A[200010];
    rep(i,0,N) cin >> A[i];
    ll max_val = K - A[N-1] + A[0];
    rep(i,0,N-1) max_val = max(max_val, A[i+1] - A[i]);
    print(K - max_val);
    

}

Measured memory_bytes: 1792
def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    for r in range(H):
        for c in range(W):
            if S[r][c] == '.': continue
            bl = False
            if r > 0:
                bl |= (S[r - 1][c] == S[r][c])
            if r < H - 1:
                bl |= (S[r + 1][c] == S[r][c])
            if c > 0:
                bl |= (S[r][c - 1] == S[r][c])
            if c < W - 1:
                bl |= (S[r][c + 1] == S[r][c])
            if not bl:
                print('No')
                return
    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9232
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define all(x) begin(x), end(x)
#define lowbit(x) ((x) & -(x))
#define EB emplace_back
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define maxn 1005
using namespace std;

struct DSU {
    vector<int> s, p;
    DSU(int sz) : s(sz + 1, 1), p(sz + 1, -1) {}
    int find(int x) {
        return (p[x] == -1) ? x : (p[x] = find(p[x]));
    }
    bool join(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(s[x] < s[y]) swap(x, y);
        s[x] += s[y]; p[y] = x;
        return true;
    }
    int cnt() {
        int ret = 0;
        for(int i = 1; i < SZ(p); i++) {
            if(p[i] == -1) ret++;
        }
        return ret;
    }
};

int mx[4] = {0, 0, -1, 1};
int my[4] = {-1, 1, 0, 0};
char mp[maxn][maxn];
int id[maxn][maxn];
int n, m;

bool cool(int i, int j) {
    if(i < 0 || i >= n) return false;
    if(j < 0 || j >= m) return false;
    return mp[i][j] == '#';
}

int solve() {
    int R = 0, C = 0;
    for(int i = 0; i < n; i++) {
        int cnt = 0;
        if(mp[i][0] == '#') cnt++;
        if(mp[i][m - 1] == '#') cnt++;
        for(int j = 1; j < m; j++) {
            if(mp[i][j - 1] != mp[i][j]) cnt++;
        }
        if(cnt > 2) return -1;
        if(cnt) R++;
    }
    for(int j = 0; j < m; j++) {
        int cnt = 0;
        if(mp[0][j] == '#') cnt++;
        if(mp[n - 1][j] == '#') cnt++;
        for(int i = 1; i < n; i++) {
            if(mp[i - 1][j] != mp[i][j]) cnt++;
        }
        if(cnt > 2) return -1;
        if(cnt) C++;
    }
    if((R + C) > 0 && (R != n || C != m)) return -1;
    DSU loli(n * m);
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(mp[i][j] == '.') cnt++;
            else {
                for(int k = 0; k < 4; k++) {
                    int ii = i + mx[k];
                    int jj = j + my[k];
                    if(cool(ii, jj)) {
                        loli.join(id[i][j], id[ii][jj]);
                    }
                }
            }
        }
    }
    return loli.cnt() - cnt;
}


int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
    /*cin >> n >> m; int tot = 0;
    for(int i = 0; i < n; i++) {
        cin >> mp[i];
        for(int j = 0; j < m; j++)
            id[i][j] = ++tot;
    }
    cout << solve() << '\n';*/
    int a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    if((b - a) & 1) puts("IMPOSSIBLE");
    else printf("%d\n", (a + b) / 2);
    return 0;
}










Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll dpl[200010][2], dpr[200010][2], a[200010], ans;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    dpl[i][0] = dpl[i][1] = dpr[i][0] = dpr[i][1] = -1000000000000000;
  }
  dpl[0][0] = -10000000000000000;
  dpl[1][0] = a[1];
  dpl[0][1] = a[0];
  dpl[1][1] = -10000000000000000;
  dpl[2][0] = a[2];
  for (int i = 0; i < n - 2; i++) {
    if (i % 2) {
      dpl[i + 2][0] = max(dpl[i + 2][0], dpl[i][0] + a[i + 2]);
      if (i + 3 < n) {
        dpl[i + 3][0] = max(dpl[i + 3][0], dpl[i][0] + a[i + 3]);
      }
    } else {
      dpl[i + 2][1] = max(dpl[i + 2][1], dpl[i][1] + a[i + 2]);
      dpl[i + 2][0] = max(dpl[i + 2][0], dpl[i][0] + a[i + 2]);
      if (i + 3 < n) {
        dpl[i + 3][0] = max(dpl[i + 3][0], dpl[i][1] + a[i + 3]);
      }
      if (i + 4 < n) {
        dpl[i + 4][0] = max(dpl[i + 4][0], dpl[i][1] + a[i + 4]);
      }
    }
  }
  printf("%lld\n", max(dpl[n - 1][0], dpl[n - 2][(n + 1) % 2]));
}

Measured memory_bytes: 9504