akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define LL long long int
using namespace std;

const int N = 1e6 + 5;

int sp[N], pc[N], a[N];

void solve() {
    int n;
    cin >> n;
    for (int i=0;i<n;++i) {
        int x; cin >> x;
        sp[x]++;
        pc[x] = 1;
    }
    for (int i=1;i<N;++i) if (sp[i] > 0) {
        if (sp[i] > 1) pc[i] = 0;
        for (int j=i+i;j<N;j+=i) pc[j] = 0;
    }
    int ans = 0;
    for (int i=1;i<N;++i) ans += pc[i];
    cout << ans << '\n';
} 
int main() {
    FASTIO;
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

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

using namespace std;

int main(){
    int n;
    int64_t k;
    cin >> n >> k;
    vector<int> A(n);
    for (auto &a: A) cin >> a;

    map<int, vector<int>> M;

    for (int i = 0; i < n; i++){
        M[A[i]].push_back(i);
    }

    int i = 0;
    int c = 0;
    while (true){
        int a = A[i];
        auto p = upper_bound(M[a].begin(), M[a].end(), i);
        if (p == M[a].end()){
            p = M[a].begin();
            c++;
        }

        i = *p;
        i = (i + 1) % n;

        if (i == 0)
            break;
    }

    c++;
    k %= c;
    i = 0;

    while (true){
        int a = A[i];
        auto p = upper_bound(M[a].begin(), M[a].end(), i);
        if (p == M[a].end()){
            p = M[a].begin();
            k--;
        }

        if (k == 0)
            break;

        i = *p;
        i = (i + 1) % n;
    }

    for (; i < n; i++){
        int a = A[i];
        auto p = upper_bound(M[a].begin(), M[a].end(), i);
        if (p == M[a].end()){
            cout << A[i] << " ";
            continue;
        }
        i = *p;
    }
    cout << endl;

}

Measured memory_bytes: 24960
#include <bits/stdc++.h> 
using namespace std;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
inline ll mul(ll a,ll b){
  a=(a+MOD)%MOD;
  b=(b+MOD)%MOD;
  ll c=a*b;
  c=(c+MOD)%MOD;
  return c;
}
inline ll add(ll a,ll b){
  a=(a+MOD)%MOD;
  b=(b+MOD)%MOD;
  ll ans=(a+b);
  ans=(ans+MOD)%MOD;
  return ans;
}

ll power(ll a,ll b,ll c){
  ll ans=1;
  while(b){
    if(b&1){
      ans=mul(ans,a);
    }
    a=mul(a,a);
    b=b/2;
  }
  return ans;
}
inline ll max(ll a,ll b){return a>b?a:b;}
inline ll min(ll a,ll b){return a<b?a:b;}
int main()
{
  ll n,k; cin>>n>>k;
  ll a[n];
  for(int i=0;i<n;++i)cin>>a[i];
    ll dp[n];
  dp[0]=0;
  for(int i=1;i<n;++i){
    dp[i]=INT_MAX;
    for(int j=1;j<=k&&i-j>=0;j++)dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
  }
cout<<dp[n-1];
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
  int h,w,n,maxP,minP,i,result = 0;
  scanf("%d", &h);
  scanf("%d", &w);
  scanf("%d", &n);
  
  if(h >= w){
    maxP = h;
    minP = w;
  }else{
    maxP = w;
    minP = h;
  }
  
  for(result=1;result<=minP;result++){
    if(result * maxP >= n) break;
  }
  printf("%d", result);
  
  return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
    cin>>a[i];}
    int dp[n];
    dp[n-1]=0;
    dp[n-2]=abs(a[n-1]-a[n-2]);
  for(int i=(n-3);i>=0;i--){
dp[i]=min(abs(a[i+1]-a[i])+dp[i+1],abs(a[i+2]-a[i])+dp[i+2]);

  }
  cout<<dp[0];


    return 0;}


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

struct Node{
    int key;
    struct Node *right, *left, *parent;
};

struct Node *root, *NIL;

void insert(int k){
  struct Node *y = NIL;
  struct Node *x =root;
  struct Node *z;

  z = malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else  x = x->right;
  }
  z->parent = y;
  if(y == NIL)  root = z;
  else{
    if(z->key < y->key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}

void inorder(struct Node *u){
  if(u == NIL)  return ;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
  if(u == NIL)  return ;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(void){
  int n, i, x;
  char s[20];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s", s);
    if(strcmp(s, "insert")==0){
      scanf("%d", &x);
      insert(x);
    }
    else if(strcmp(s ,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 25128
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	while (true) {
		int d, e; cin >> d >> e;
		if (d == 0 && e == 0)return 0;

		double ans = INF;
		for (int i = 0; i < d; i++) {
			int y = d - i;

			double diff = abs(sqrt(i*i + y * y) - e);

			ans = min(ans, diff);
		}

		cout << fixed << setprecision(12);
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;


int main() {
  int N;
  cin >> N;
  vector<int> A;
  int ans[100000];

  ans[0] = 0;
  rep(i, N) {
    int a;
    cin >> a;
    A.push_back(a);
    if (i % 2 == 0) {
      ans[0] += a;
    } else {
      ans[0] -= a;
    }
  }

  rep1(i, N-1) {
    ans[i] = -ans[i - 1] + A[i - 1] * 2;
  }

  rep(i, N - 1) cout << ans[i] << " ";
  cout << ans[N - 1] << endl;

  return 0;
}


Measured memory_bytes: 2168
//g++ -std=c++14 test.cpp -o test.out
 
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//引用元：https://drken1215.hatenablog.com/entry/2020/09/27/080300
template<class Monoid> struct SegmentTree {
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func F;
    const Monoid UNITY;
    int SIZE_R;
    vector<Monoid> dat;
    
    SegmentTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
    void init(int n) {
        SIZE_R = 1;
        while (SIZE_R < n) SIZE_R *= 2;
        dat.assign(SIZE_R * 2, UNITY);
    }
    
    /* set, a is 0-indexed */
    void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
    void build() {
        for (int k = SIZE_R - 1; k > 0; --k)
            dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    /* update a, a is 0-indexed */
    void update(int a, const Monoid &v) {
        //まず最下段の、元の配列に相当する箇所を更新
        int k = a + SIZE_R;
        dat[k] = v;
        //登りながら更新
        while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    /* query [a, b), a and b are 0-indexed */
    Monoid query(int a, int b) {
        Monoid vleft = UNITY, vright = UNITY;
        for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
            if (left & 1) vleft = F(vleft, dat[left++]);
            if (right & 1) vright = F(dat[--right], vright);
        }                                                                                                              
        return F(vleft, vright);
    }
    inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }
    
    /* debug */
    void print() {
        for (int i = 0; i < SIZE_R; ++i) {
            cout << (*this)[i];
            if (i != SIZE_R-1) cout << ",";
        }
        cout << endl;
    }
};

LL N,K;
LL A[300000];

LL ans;

void solve(){
    //ラストがiで終わるような数列の最大の長さをdp[i]とする
    const LL MAX_A =　300000;
    auto func = [&](LL a,LL b) { return max(a,b); };
    SegmentTree<LL> st(MAX_A+1,func,0);
    for(int i=0;i<N;i++){
        LL left = max(0LL,A[i]-K);
        LL right = min(MAX_A,A[i]+K);
        LL cand = st.query(left,right+1);
        st.update(A[i],cand+1);
    }
    ans = st.query(1,MAX_A+1);
}
 
int main(){
	cin >> N >> K;
    for(int i=0;i<N;i++) cin >> A[i];
 
    solve();

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

Measured memory_bytes: 13408
program ABC_077_A_Rotation
   implicit none
   integer i, countN
   character(3) c1, c2
   read(*, *) c1, c2
   countN = 0
   do i = 1, 3
       if(c1(i:i) == c2(4-i:4-i)) then
	       countN = countN + 1
	   end if
   end do
   if(countN == 3) then
       write(*, *) 'YES'
   else
       write(*, *) 'NO'
   end if
end program ABC_077_A_Rotation

Measured memory_bytes: 384
a,b=map(int,input().split())

if a%2==0:
  if b%2==1:
    if (b-a+1)%4==0:
      print('0')
    else:
      print('1')
  else:
    if (b-a)%4==0:
      print(b)
    else:
      print(b^1)
else:
  if b%2==1:
    if (b-a)%4==0:
      print(a)
    else:
      print(a^1)
  else:
    if (b-a-1)%4==0:
      print(a^b)
    else:
      print(a^b^1)

Measured memory_bytes: 3064
import numpy as np


H, W = map(int, input().split())
s = np.array([[c for c in input()] for i in range(H)]) == '.'
s_t = s.transpose()

dp_l = np.zeros((W, H), dtype=int)
dp_r = np.zeros((W, H), dtype=int)
dp_u = np.zeros((H, W), dtype=int)
dp_d = np.zeros((H, W), dtype=int)

dp_l[0] = s_t[0]
dp_r[W-1] = s_t[W-1]
dp_u[0] = s[0]
dp_d[H-1] = s[H-1]

for i in range(1, W):
    dp_l[i] = s_t[i] * (dp_l[i-1] + 1)

for i in reversed(range(W-1)):
    dp_r[i] = s_t[i] * (dp_r[i+1] + 1)

for i in range(1, H):
    dp_u[i] = s[i] * (dp_u[i-1] + 1)

for i in reversed(range(H-1)):
    dp_d[i] = s[i] * (dp_d[i+1] + 1)

cnts = dp_l + dp_r + dp_d.transpose() + dp_u.transpose()
print(max(np.amax(cnts, 0)) - 3)

Measured memory_bytes: 222680
def main():
    n = int(input())
    s = [input() for _ in range(n)]
    ans = ""
    ans += "AC x " + str(s.count("AC")) + "\n"
    ans += "WA x " + str(s.count("WA")) + "\n"
    ans += "TLE x " + str(s.count("TLE")) + "\n"
    ans += "RE x " + str(s.count("RE")) + "\n"
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 16160
#include <stdio.h>

int main()
{
	int i, X, N, p, flag[102] = {};
	scanf("%d %d", &X, &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &p);
		flag[p] = 1;
	}
	for (i = 0; i <= 100; i++) {
		if (flag[X-i] == 0) {
			printf("%d\n", X - i);
			break;
		} else if (flag[X+i] == 0) {
			printf("%d\n", X + i);
			break;
		}
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1684
N = int(input())
alist = list(map(int, input().split()))

ans = 0


def canDiv(val):
    cnt = 0
    while True:
        if val % 2 == 0:
            cnt += 1
            val //= 2
        else:
            return cnt


for a in alist:
    ans += canDiv(a)

print(ans)


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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<int> t;
    { // compress 1
        int cur = 0;
        for(int i = 0; i < n; ++i) {
            if(s[i] == '0') {
                if(cur > 0) t.push_back(cur);
                t.push_back(0);
                cur = 0;
            } else {
                cur += 1;
            }
        }
        if(cur > 0) {
            t.push_back(cur);
        }
    }

    n = t.size();
    // 0: all left, 1: one left, 2: one used, 3: all used
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(4, vector<int>(4, -1)));
    dp[0][0][0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 4; ++j) {
            for(int k = 0; k < 4; ++k) {
                if(dp[i][j][k] == -1) continue;
                if(j & 2 && t[i] > 0) {
                    { // use left
                        const int nj = t[i] > 1;
                        const int nk = t[i] == 1 ? 3 : 2;
                        const int prf = k == 1 ? 1 : (k == 2 ? t[i - 2] - 1 : t[i - 2]);
                        dp[i + 1][nj][nk] = max(dp[i + 1][nj][nk], dp[i][j][k] + prf);
                    }
                    // use right (leave one)
                    if(t[i] > 1) {
                        dp[i + 1][1][1] = max(dp[i + 1][1][1], dp[i][j][k] + t[i] - 1);
                    }
                    // use right (use all)
                    dp[i + 1][0][3] = max(dp[i + 1][0][3], dp[i][j][k] + t[i]);
                }
                // do nothing
                if(t[i] > 0) {
                    dp[i + 1][1][0] = max(dp[i + 1][1][0], dp[i][j][k]);
                } else {
                    dp[i + 1][(j << 1) & 3][k] = max(dp[i + 1][(j << 1) & 3][k], dp[i][j][k]);
                }
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < 4; ++i) {
        for(int j = 0; j < 4; ++j) {
            ans = max(dp[n][i][j], ans);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 131576
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int n; cin>>n;
  int c=0;
  int now=1;
  rep(i,n){
    int a; cin>>a;
    if(a==now)
    now++;
    else
    c++;
  }
  if(now==1)
  cout<<-1<<endl;
  else
  cout<<c<<endl;

  return 0;
}


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

using namespace std;

const int md = (int) 1e9 + 7;

inline int mul(int x, int y) {
  return (int) ((long long) x * y % md);
}

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  string s;
  cin >> n >> s;
  vector<int> cnt(26);
  for (auto c : s) {
    ++cnt[c - 'a'];
  }
  int ans = 1;
  for (auto x : cnt) {
    ans = mul(ans, x + 1);
  }
  cout << ans - 1 << "\n";
  return 0;
}


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

bool solve(string S) {
    stack<char> stk;
    stk.push('#');
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == '(')
            stk.push('(');
        else if (S[i] == '[')
            stk.push('[');
        else if (S[i] == ')') {
            if (stk.top() != '(') return false;
            stk.pop();
        } else if (S[i] == ']') {
            if (stk.top() != '[') return false;
            stk.pop();
        }
    }
    return (stk.top() == '#');
}

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

    string S;
    while (1) {
        getline(cin, S);
        if (S[0] == '.') break;
        cout << (solve(S) ? "yes" : "no") << endl;
    }
}


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

int main() {
	int n;scanf("%d",&n);
	for(int i=0;i<=10000;i++){
		int d=n-i,k=n+i;
		string s=to_string(d);
		string u=s;reverse(u.begin(),u.end());
		if(s==u){
			cout<<s<<endl;
			return 0;
		}
		s=to_string(k);
		u=s;reverse(u.begin(),u.end());
		if(s==u){
			cout<<s<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3316
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    ll n, ans=1e15;
    cin>>n;
    vector<ll> v(n);
    rep(i,0,n){
        cin>>v[i];
    }

    // start with positive value
    {
        vector<ll> a = v;
        ll t = 0, s = 0;
        if (a[0]<=0){
            t += abs(1-a[0]);
            a[0] += 1-a[0];
        }
        s = a[0];
        // printf("a[%d]=%d, s=%d\n",0,a[0],s);

        rep(i,1,n){
            if (s<0){
                // make a[i] positive
                if (a[i] <= -s ){
                    t += abs(1 -s -a[i]);
                    a[i] += 1 -s -a[i];
                }
            } else {
                // make a[i] negative
                if (a[i] >= -s ){
                    t += abs(-1-s-a[i]);
                    a[i] += -1-s-a[i];
                }
            }
            s += a[i];
            // printf("a[%d]=%d, s=%d\n",i,a[i],s);
        }
        // cout<<"t with positive = "<<t<<endl;
        ans = min(ans, t);
    }

    // start with negative value
    {
        vector<ll> a = v;
        ll t = 0, s = 0;
        if (a[0]>=0){
            t += abs(-1-a[0]);
            a[0] += -1-a[0];
        }
        s = a[0];
        // printf("a[%d]=%d, s=%d\n",0,a[0],s);

        rep(i,1,n){
            if (s<0){
                // make a[i] positive
                if (a[i] <= -s ){
                    t += abs(1 -s -a[i]);
                    a[i] += 1 -s -a[i];
                }
            } else {
                // make a[i] negative
                if (a[i] >= -s ){
                    t += abs(-1-s-a[i]);
                    a[i] += -1-s-a[i];
                }
            }
            s += a[i];
            // printf("a[%d]=%d, s=%d\n",i,a[i],s);
        }
        // cout<<"t with positive = "<<t<<endl;
        ans = min(ans, t);
    }

    cout<<ans<<endl;

    return 0;
}


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

static class Program
{
    static bool Ok(int N, int M, int V, int P, int[] A, int j)
    {
        if (A[j] + M < A[P - 1]) { return false; }
        long sum = Math.BigMul(M, P - 1);
        for (int i = P - 1; i < N; ++i)
        {
            sum += (i == j) ? M : Math.Min(A[j] + M - A[i], M);
        }
        return sum >= Math.BigMul(M, V);
    }

    static int Solve(int N, int M, int V, int P, int[] A)
    {
        if (Ok(N, M, V, P, A, N - 1)) { return N; }
        int ok = P - 1;
        int ng = N - 1;
        while (ng - ok >= 2)
        {
            int i = (ok + ng) / 2;
            if (Ok(N, M, V, P, A, i)) { ok = i; } else { ng = i; }
        }
        return ng;
    }

    static void Main(string[] args)
    {
        var V = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Array.Sort(A, (a, b) => b.CompareTo(a));
        Console.WriteLine(Solve(V[0], V[1], V[2], V[3], A));
    }
}


Measured memory_bytes: 20576
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int len = sc.nextInt();

		BigDecimal wSide = new BigDecimal((double)len/3);
		BigDecimal tSide = new BigDecimal((double)len/3);
		BigDecimal hSide = new BigDecimal((double)len/3);

		BigDecimal result = wSide.multiply(tSide).multiply(hSide);

		System.out.print(result);
		sc.close();
	}
}


Measured memory_bytes: 21588
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;

const ll MOD_CONST = 1000000007;



int main()
{
	int n;
	cin >> n;
	vector<int> c(n);
	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;
		p--;
		c[p] = i;
	}

	multiset<int> s;
	
	
	for (int i = 0; i < 2; i++) {
		s.insert(-1);
		s.insert(n);
	}

	ll ans = 0;

	for (int i = n-1; i >=0; i--) {
		
		auto it = s.lower_bound(c[i]);
		it++;
		it++;
		vector<int> x(4);

		for (int j = 0; j < 4; j++) {
			it--;
			x[j] = *it;
			//cout << x[j] << " ";
		}
		//cout << endl;

		ll cnt =1LL * (x[0] - x[1]) * (c[i] - x[2]);
		cnt += 1LL *(x[2] - x[3]) * (x[1] - c[i]);
		
		ans += cnt * (i + 1);
		s.insert(c[i]);
	}
	cout << ans << endl;

}  



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

#define N 2000

int main(void)
{
    int n, x, y;
    cin >> n >> x >> y;
    x--;  y--;
    vector< vector<int> > G(n);
    for (int i = 0; i < n-1; i++){
        G.at(i).push_back(i+1);
        G.at(i+1).push_back(i);
        if (i == x){
            G[x].push_back(y);
            G[y].push_back(x);
        }
    }  

    queue<int> searchVertex;
    vector< vector<int> > dpDist(n, vector<int>(n, -1));
    
    for (int i = 0; i < n; i++){
        searchVertex.push(i);
        dpDist.at(i).at(i) = 0;
        while (searchVertex.empty() == 0){
            int now = searchVertex.front();
            searchVertex.pop();
            for (int next : G[now]){
                if(dpDist.at(i).at(next) == -1){
                    searchVertex.push(next);
                    dpDist.at(i).at(next) = dpDist.at(i).at(now) + 1;
                }
            }
        }
    }
    
    vector<int> list(N+1, 0);
    for (int i = 0; i < n; i++){
        for (int j = i; j < n; j++){
            list.at( dpDist.at(i).at(j) ) = list.at( dpDist.at(i).at(j) ) + 1; 
        }
    }
    for (int i = 1; i < n; i++){
        cout << list.at(i) << endl;
    }

    return 0;
}


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


int main(){
	int n,p,q;
	while(cin>>n>>p>>q,n|p|q){
		p=p/100*60+p%100;
		q=q/100*60+q%100;
		vector<pair<int,int> > v;
		int ans=0;
		for(int i=0;i<n;i++){
			int k,prev=p;
			cin>>k;
			for(int j=0;j<k;j++){
				int a,b;
				cin>>a>>b;
				a=a/100*60+a%100;
				b=b/100*60+b%100;
				v.push_back(make_pair(prev,a));
				prev=b;
			}
			v.push_back(make_pair(prev,q));
		}
		sort(v.begin(),v.end());
		int a=p,b=p;
		for(int i=0;i<v.size();i++){
			if(v[i].first<=b){
				b=max(b,v[i].second);
			}else{
				ans=max(ans,b-a);
				a=v[i].first;
				b=v[i].second;
			}
		}
		cout<<max(ans,b-a)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
n = int(input())
t0 = int(0)
x0 = int(0)
y0 = int(0)

def solve(n):
    global t0, x0, y0
    for i in range(n):
        t, x, y = map(int, input().split())
        if t - t0 < abs(x - x0) + abs(y - y0):
            return "No"
        if ((t - t0) - (abs(x - x0) + abs(y - y0))) % 2 == 1:
            return "No"
        x0 = x
        y0 = y
        t0 = t        
    return "Yes"    

print(solve(n))


Measured memory_bytes: 3064
/*
.....   .   .   .   .
  .    . .   . .   . .
  .   .....   .   .....
  .  .     .  .  .     .
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
   
using namespace std;
   
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
   
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}



#define left left228
#define right right228
#define set set228

const int maxn = 200 * 1000 + 228;

int n;
int a[maxn];

struct block
{
    int len, d;
    block() {}
    block(int _len, int _d) {
        len = _len;
        d = _d;
    }
};

int D;
vector<block> v;

void add(block b) {
    if (v.empty()) {
        v.push_back(b);
    } else {
        if (v.back().d == b.d) {
            v.back().len += b.len;
        } else {
            v.push_back(b);
        }
    }
}

void del(int k) {
    while (v.back().len <= k) {
        k -= v.back().len;
        v.pop_back();
    }
    if (k) {
        v.back().len -= k;
    }
}

void inclast() {
    if (v.back().len == 1) {
        int curd = v.back().d;
        v.pop_back();
        add({1, curd + 1});
    } else {
        --v.back().len;
        int d = v.back().d;
        add({1, d + 1});
    }
}

void inc() {
    if (v.back().d != D - 1) {
        inclast();
    } else {
        int len = v.back().len;
        v.pop_back();
        inclast();
        add({len, 0});
    }
}

bool check(int x) {
    D = x;
    v.clear();
    v.push_back({a[1], 0});
    for (int i = 2; i <= n; ++i) {
        if (a[i] > a[i - 1]) {
            add(block(a[i] - a[i - 1], 0));
        } else {
            del(a[i - 1] - a[i]);
            if ((int)v.size() == 1 && v[0].d == x - 1) {
                return 0;
            }
            inc();
        }
    }
    return 1;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    int l = 0, r = n;
    while (r - l > 1) {
        int mid = (l + r) >> 1;
        if (check(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r << '\n';
    return 0;
}
  
  
  
  

Measured memory_bytes: 1024
#include<cstdio>
int n,a,b,k=0,t=1,s,d;
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(;t<=n;t++)
	{
    	s=0,d=t;
    	while(d)
    	{
        	s+=d%10,d/=10;
    	}
    	if(s>=a&&s<=b)
		{
        	k+=t;
    	}
	}
	printf("%d\n",k);
}

Measured memory_bytes: 128
//g++ -std=c++11 -Wall -O2 -o main.exe main.cpp
//g++ -std=c++14 -Wall -O2 -o main.exe main.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <queue>
#include <stack>
#include <tuple>

using namespace std;

#define spc " "
#define com ", "

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p_ii;

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

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

    vector<int> num, d(k);
    for(int i = 0; i < k; i++) cin >> d[i];
    int in = 0;
    for(int i = 0; i < 10; i++){
        if(i != d[in]) num.push_back(i);
        else{
            if(in < k) in++;
        }
    }

    int ans = n;
    while(1){
        int t = ans;
        bool flag = true;
        while(t && flag){
            int tt = t % 10;
            t /= 10;
            flag = false;
            for(int i: num){
                if(tt == i){
                    flag = true;
                    break;
                }
            }
        }

        if(flag){
            cout << ans << endl;
            return 0;
        }
        ans++;
    }

    return 0;
}

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

#define ll long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair


int main() {
    IOS
    int k,x;
    cin>>k>>x;
    if(k*500 >= x)
      cout<<"Yes"<<endl;
    else 
      cout<<"No"<<endl;
}


Measured memory_bytes: 256
n,m,*a = map(int,open(0).read().split())
mod = 10**9+7
s = [i-j-2 for i,j in zip(a+[n+1],[-1]+a)]
if -1 in s:
  print(0)
  exit()
f = [1,1]
for i in range(2,max(s)+1):
  f.append(f[i-1]+f[i-2])
ans = 1
for i in s:
  ans *= f[i]
print(ans%mod)

Measured memory_bytes: 460020
import sys
from itertools import product

inf = float('inf')

n, *target = map(int, sys.stdin.readline().split())
target = [None] + target
*l,  = map(int, sys.stdin.read().split())

def main():
    costs = []
    for p in product(range(4), repeat=n):
        tmp = [[] for _ in range(4)]
        p = list(p)
        for i in range(n):
            tmp[p[i]].append(l[i])

        cost = [0] * 4
        for i in range(1, 4):
            if not tmp[i]:
                break
            cost[i] += 10 * (len(tmp[i]) - 1)
            cost[i] += abs(target[i] - sum(tmp[i]))
        else:
            costs.append(sum(cost))

    return min(costs)

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 5020
#include <stdio.h>

int main(void)
{
    int n;
    int m;
    int i;
    int flag;
    
    while (1){
        scanf("%d", &n);
        if (n == -1){
            break;
        }
        flag = 0;
        for (i = 30; i >= 2; i -= 2){
            m = (n >> i) & 3;
            if (m != 0){
                flag = 1;
            }
            if (flag == 1){
                printf("%d", m);
            }
        }
        printf("%d\n", n & 3);
    }
    return (0);
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<cmath>
#include<limits>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    unsigned long long int h,w,t,k;
    cin>>h>>w;
    if(h==1||w==1){
        cout<<1<<endl;
        return 0;
    }
    else if(h%2==1){
        if(w%2==1){
            t=((h/2)+1)*((w/2)+1);
            k=(h/2)*(w/2);
        }
        else{
            t=((h/2)+1)*(w/2);
            k=(h/2)*(w/2);
        }
    }
    else{
        if(w%2==1){
            t=(h/2)*((w/2)+1);
            k=((h/2))*(w/2);
        }
        else{
            t=(h/2)*(w/2);
            k=((h/2))*(w/2);
        }
    }
    /*
    cout<<t<<endl;
    cout<<k<<endl;
    */
    cout<<t+k<<endl;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(20);
    string s,t;cin >> s >> t;
    int a,b;cin >> a >> b;
    string u;cin >> u;
    if(s == u)a--;else b--;
    cout << a << " " << b << '\n';

    return 0;
}


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

using namespace std;

const int MAXN = 1e5 + 10;

int n, arr[MAXN];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	sort(arr, arr + n, greater<int>());
	int id = -1;
	for (int i = 0; i < n; i++)
	{
		arr[i] -= i + 1;
		if (arr[i] >= 0)
		{
			id = i;
		}
	}
	int go = 0;
	for (int i = id + 1; i < n; i++)
	{
		if (arr[i] == (id - i))
		{
			go++;
		}
		else
		{
			break;
		}
	}
	if ((arr[id] | go) & 1)
	{
		cout << "First\n";
	}
	else
	{
		cout << "Second\n";
	}
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1e18

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int N,K;
map<int,int>Map;
vi a;
void input(){
	cin>>N>>K;
	a.resize(N+1);
	rep(i,N){
		cin>>a[i];
		Map[a[i]]++;
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	vi tmp;
	for(auto it=Map.begin();it!=Map.end();it++){
		tmp.pb(it->second);	
	}
	sort(ALL(tmp));
	int ans=0;
	int len=tmp.size();
	rep(i,max(0,len-K)){
		ans+=tmp[i];
	}
	P(ans)
	return 0;
}



Measured memory_bytes: 11640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = ll(1e18) + 1;  // 1e18 は doubleなので整数に直す

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

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

  ll l = -INF;
  ll r = INF;
  while (l + 1 < r) {
    ll x = (l + r) / 2;
    bool ok = [&] {
      ll tot = 0;
      for (int i = 0; i < n; i++) {
        if(a[i] < 0) {
          // 負
          int l = -1, r = n;
          while(l + 1 < r) {
            int c = (l + r) / 2;
            if(a[c] * a[i] < x) {
              r = c;
            } else {
              l = c;
            }
          }
          tot += n - r;
        } else {
          // 正
          int l = -1, r = n;
          while(l + 1 < r) {
            int c = (l + r) / 2;
            if(a[c] * a[i] < x) {
              l = c;
            } else {
              r = c;
            }
          }
          tot += r;
        }
        if(a[i] * a[i] < x) {
          tot--; // 対角線の余計なカウントを消す
        }
      }
      tot /= 2; // 斜め半分の余計なカウントを消す
      return tot < k;
    }();

    if(ok) {
      l = x;
    } else {
      r = x;
    }
  }

  cout << l << endl;

  return 0;
}

Measured memory_bytes: 1920
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, q;
//[s,t)でXを通行止めにする
struct A {
	int s, t, x;
};
A a[500000];
int d[500000];
vector<int> e[500000];
vector<int> f[500000];
struct C {
	int i;
};
bool operator<(C e,C d) {
	return a[e.i].x < a[d.i].x;
}
bool operator>(C e,C d) {
	return a[e.i].x > a[d.i].x;
}
bool can[500000];
signed main() {
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> a[i].s >> a[i].t >> a[i].x;
	}
	for (int i = 0; i < q; i++) {
		cin >> d[i];
	}
	for (int i = 0; i < n; i++) {
		e[lower_bound(d, d + q, a[i].s - a[i].x) - d].push_back(i);
		f[lower_bound(d, d + q, a[i].t - a[i].x) - d].push_back(i);
	}
	priority_queue<C, vector<C>, greater<C>>p;
	for (int i =0; i < q; i++) {
		for (int j = 0; j < e[i].size(); j++) {
			p.push(C{ e[i][j] });
			can[e[i][j]] = 1;
		}
		for (int j = 0; j < f[i].size(); j++) {
			can[f[i][j]] = 0;
		}
		while (!p.empty() && !can[p.top().i]) {
			p.pop();
		}
		if (p.empty()) {
			cout << -1 << endl;
		}
		else {
			cout << a[p.top().i].x << endl;
		}
	}
}

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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
    while(true){
        int n, r; cin >> n >> r;
        if(n == 0)break;
        vector<int> l(n+1);
        for(int i = 1; i <= n; i++){
            l[i] = i;
        }
        for(int i = 0; i < r; i++){
            int p,c; cin >> p >> c;
            int b = n-p-c+2;
            for(int j = 0; j < c; j++){
                l.push_back(l[b]);
                l.erase(l.begin() + b);
            }
        }
        cout << l.back() << endl;
    }

    return 0;
}




Measured memory_bytes: 3100
from collections import deque
import sys
import copy

N_MAX = 200000 + 5
INF = 10**9 + 7
sys.setrecursionlimit(N_MAX)
MOD = 10**9 + 7


### BFS ###

nextH = [0, 1, 0, -1]
nextW = [1, 0, -1, 0]


def bfs(u, S):

    S[u[0]][u[1]] = 0  # state を変更

    q = deque()
    q.append(u)
    m = 0
    while q:
        u = q.popleft()
        for h, w in zip(nextH, nextW):
            h += u[0]
            w += u[1]
            if not (0 <= h < len(S) and 0 <= w < len(S[0])):
                continue

            if S[h][w] == '.':  # state を確認
                S[h][w] = S[u[0]][u[1]] + 1  # state を変更
                m = max(m, S[h][w])
                q.append((h, w))
    
    return m


def main():

    H, W = map(int, sys.stdin.readline().rstrip().split())
    S = []
    for _ in range(H):
        S.append([x for x in sys.stdin.readline().rstrip()])

    # print(S)

    m = 0
    for h in range(H):
        for w in range(W):
            D = copy.deepcopy(S)
            if S[h][w] == '.':
                m = max(m, bfs((h, w), D))

    print(m)


main()


Measured memory_bytes: 9624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll k;cin >> k;
    ll a=100;
    ll cnt=0;
    while(true){
        cnt++;
        a+=a/100;
        if(k<=a){
            cout << cnt <<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;



ll N,ans;
ll a[101];


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


	cin >> N;
	FOR(i, 0, N) {
		cin >> a[i];
		if ((i + 1) % 2 == 1 && a[i] % 2 == 1)ans++;
	}
	cout << ans << endl;


}

Measured memory_bytes: 3608
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, K = map(int, readline().split())
grid = [list(readline().decode().rstrip()) for _ in range(H)]
black_cnt = 0
a = [0]*H
b = [0]*W
for i in range(H):
  for j in range(W):
    if grid[i][j] == '#':
      a[i] += 1
      b[j] += 1
      black_cnt += 1
if black_cnt < K:
  print(0)
  sys.exit()
erase_cnt = black_cnt-K
N = H+W
ans = 0
for bit in range(1 << N):
    cnt = 0
    tmp_a = []
    tmp_b = []
    for i in range(N):
        if (bit >> i) & 1:       
            if i < H:
                tmp_a.append(i)
                cnt += a[i]
            else:
                tmp_b.append(i-H)
                cnt += b[i-H]
    for j in range(len(tmp_a)) :
        for k in range(len(tmp_b)):
            if grid[tmp_a[j]][tmp_b[k]] == '#':
                 cnt -= 1
    if cnt == erase_cnt:
        ans +=1
print(ans)

Measured memory_bytes: 9224
// 树状数组 Binary Indexed Tree
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;

const int maxn = 200002;

int n, h[maxn], a[maxn];
long long f[maxn], tr[maxn];

int lowbit(int x) {
	return x&(-x);
}

long long query(int lim) {
	int x = lim-1;
	long long res = 0;

	while (x > 0) {
		res = max(tr[x], res);

		x -= lowbit(x);
	}

	return res;
}

void insert(int x, long long y) {
	while (x <= n) {
		tr[x] = max(tr[x], y);
		x += lowbit(x);
	}
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> h[i];

	for (int i = 1; i <= n; ++i)
		cin >> a[i];

	for (int i = 1; i <= n; ++i) {
		f[i] = query(h[i]) + a[i];

		insert(h[i], f[i]);
	}

	cout << query(n+1) << endl;

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main(void){
    int bfr[5][4][11] = { { {0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0} },
                          { {0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0} },
                          { {0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0} },
                          { {0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0} },
                          { {0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0} } };
    int n, cnt, b, f, r, v;

    cin >> n;
    
    for( cnt = 0; cnt < n; cnt++ ){
        cin >> b >> f >> r >> v;

        bfr[b][f][r] += v;
    }

    for( b = 1; b < 5; b++ ){
        for( f = 1; f < 4; f++ ){
            for( r = 1; r < 11; r++ ){
                cout << ' ' << bfr[b][f][r];
            }
            cout << endl;
        }
        if( b < 4 ) cout << "####################" << endl;
    }
}


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

int main(){
  char b;
  cin >> b;
  
  if (b == 'A') cout << 'T' << endl;
  else if (b == 'T') cout << 'A' << endl;
  else if (b == 'G') cout << 'C' << endl;
  else cout << 'G' << endl;
}

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

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

int main()
{
    int n;
    double ans = 0.0;
    cin >> n;
    vector<double> a(n);
    rep(i, n) cin >> a[i];

    rep(i, n)
    {
        ans += 1.0 / a[i];
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
template<int BUFSIZE>
struct ans_buf {
  char buf[BUFSIZE];
  int i;
  ans_buf(): i(0) {}
  void putZ(unsigned int v, char delim='\n') {
    unsigned int k = 1;
    while(k <= v/10) k*=10;
    for(; k>0; v%=k, k/=10) buf[i++] = (v/k)+'0';
    buf[i++] = delim;
  }
  void out() { std::fwrite(buf, 1, i, stdout); }
};
char inbuf[1<<17];
unsigned int getZ() {
  unsigned int v = 0; int c;
  while((c = getchar_unlocked()) >= '0') v=v*10+c-'0';
  return v;
}

int const MAXN = 3e5;
int const MAXA = 6.4e5;
int N, m[MAXN], d[MAXN+1];

int main() {
  std::setbuf(stdin, inbuf);
  N = getZ();
  std::fill_n(m, N, 0);
  for(int i = 0; i < N; ++i) ++m[getZ()-1];
  std::fill_n(d, N+1, 0);
  for(int i = 0; i < N; ++i) ++d[m[i]];
 
  ans_buf<MAXA> buf;
  int sum_D = 0, sum_iD = N, k = 1;
  for(int ans = N; ans >= 1; --ans) {
    sum_D += d[ans];
    sum_iD -= d[ans]*ans;
    int next_k = sum_iD/ans + sum_D + 1;
    for(int i = k; i < next_k; ++i) buf.putZ(ans);
    k = next_k;
  }
  while(k <= N) { buf.putZ(0); ++k; }
  buf.out();
  return 0;
}



Measured memory_bytes: 3840
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.IOException;
import java.util.stream.Stream;
import java.util.Arrays;
import java.util.function.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        String line = getContents().get(1);
        System.out.println(line);
        int[] xs = Arrays.stream(line.split(" ")).mapToInt(Integer::parseInt).toArray();
        int v;
        for(int i = 1, len = xs.length; i < len; ++i){
            v = xs[i];
            int j = i - 1;
            while(j >= 0 && xs[j] > v){
                xs[j + 1] = xs[j];
                --j;
            }
            xs[j + 1] = v;
            System.out.println(String.join(" ", Arrays.stream(xs).mapToObj(String::valueOf).toArray(String[]::new)));
        }
    }
    
    public static ArrayList<String> getContents() throws IOException{
        String line;
        ArrayList<String> list = new ArrayList<String>();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while((line = br.readLine()) != null) list.add(line);
        
        return list;
    }
}


Measured memory_bytes: 32164