akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int n, m, q, r, mid, lo, hi;
bool check, tcheck = 1;

int main() {
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++) cin >> a[i];
    cin >> m;
    int b[m];
    for (int i=0; i<m; i++) cin >> b[i];
    for (int i=0; i<m; i++) {
        r = b[i];
        check = 0;
        mid = n/2;
        lo = 0;
        hi = n-1;
        while (!check) {
            if (r < a[mid]) {
                hi = mid;
            }
            else {
                if (r > a[mid]) lo = mid;
                else check = 1;
            }
            mid = (lo + hi)/2;
            if (lo + 1>= hi) break;
        }
        if (r == a[lo]) check = 1;
        if (r == a[hi]) check = 1;
        tcheck = tcheck & check;
    }
    cout << tcheck << endl;
}


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


int main() {
   
   int n, d;
   cin >> n >> d;
   
   vector<vector<int>> v(n, vector<int>(d));
   
   for (int i=0; i<n; i++) {
       for (int j=0; j<d; j++)
          cin >> v.at(i).at(j);
   }
   
   int ans =0;
   
   for (int i=0; i<n-1; i++) {
      for (int j=i+1; j<n; j++) {
        int distance = 0;
          for (int k=0; k<d; k++) {
              distance += pow(v.at(i).at(k) - v.at(j).at(k), 2);
          }
          if (ceil(sqrt(distance)) == floor(sqrt(distance))) ans++;
      }
   }
   cout << ans << endl;
}

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

using namespace std;

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    //freopen("input.txt", "r", stdin);

    int n;
    cin>>n;

    string s;
    cin>>s;

    if(n%2==0)
    {
        string a, b;

        a=s.substr(0, n/2);
        b=s.substr(n/2, n-1);

        //cout<<a<<endl<<b<<endl;

        if(a==b)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define mp make_pair
#define pb push_back
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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; }

template<class T> inline auto __lcm(T& a, T& b) 
{ return a * b / __gcd(a, b); }

int main() {
    int N;  cin >> N;
    vector<int> d(N);
    rep(i, N) cin >> d[i];

    sort(all(d));
    if (d[d.size()/2] == d[d.size()/2-1]) print(0);
    else print(d[d.size()/2] - d[d.size()/2-1]);

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    cin>>a>>b;
    if(b<10) c=10;
    else if(b==100) c=1000;
    else c=100;
    int n=a*c+b;
    for(int i=1;i*i<=n;i++){
        if(i*i==n){cout<<"Yes"<<endl;return 0;}
        
    }
    cout<<"No"<<endl;
}


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

#include <iostream>
#include <fstream>

#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>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

std::vector<int> get(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

class DPreparingBoxes {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> a(N);
        REP(i, N) cin >> a[i];

        map<int, int> found;
        vector<int> b(N);
        REV(i, N, 1) {
            if (found.count(i)) {
                int d = found[i];
                if (d == a[i - 1]) {
                    b[i - 1] = 0;
                } else {
                    b[i - 1] = 1;
                }
            } else {
                b[i - 1] = a[i - 1];
            }
            auto v = get(i);
            for (int val : v) {
                found[val] += b[i - 1];
                found[val] %= 2;
            }
        }

        vector<int> res;
        REP(i, N) {
            if (b[i] == 0) continue;
            res.push_back(i+1);
        }
        cout << res.size() << endl;
        REP(i, res.size()) cout << res[i] << " ";
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DPreparingBoxes solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 11380
N = int(input())
l = len(str(N))
if N < 2:
    print(0)
elif N % 2 == 1:
    print(0)
else:
    ans = 0

    for i in range(1, 2*l):
        tmp = 0
        ans += (N // 10**i)
        tmp += (N // (10 * (5**i)))
        tmp -= N // (10 * (10**i))
        ans += max(tmp, 0)

    print(ans)


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


using namespace std;
typedef long long ll;

int main()
{
	int K, N;
	vector<int> A;
	cin >> K >> N;
	A.resize(N);
	for (int i = 0; i < N; i++)
		cin >> A[i];

	int dif = INT_MAX;
	int dis = INT_MAX;
	int x0, x1;
	for (int i = 0; i < N; i++) {
		x0 = A[i];
		if (i == N - 1)
			x1 = A[0];
		else
			x1 = A[i + 1];
		int dis0 = x1 - x0;
		int dis1 = x0 - x1;
		while (dis0 < 0) dis0 += K;
		while (dis1 < 0) dis1 += K;
		int sub = abs(dis0 - dis1);
		if (sub < dif) {
			dif = sub;
			dis = max(dis0, dis1);
		}
	}
	cout << dis << endl;


	return 0;
}

Measured memory_bytes: 1024
n,a,b=map(int,input().split())
s=input()
d=[str(c) for c in s]
for i in range(n):
    if d[i]=="c":
        print("No")
    elif a+b==0:
        print("No")
    elif d[i]=="a":
        print("Yes")
        a-=1
    elif d[i]=="b":
        if b==0:
            print("No")
        else:
            print("Yes")
            b-=1


Measured memory_bytes: 4784
from collections import Counter
n = int(input())
l = Counter([input() for _ in range(n)])
a = sorted(list(l.items()),key=lambda x:x[1])[::-1]
t = a[0][1]
q = []
for i in range(len(l)):
  if t == a[i][1]:
    q.append(a[i][0])
  else:
    break
c = sorted(q)
print(*c,sep="\n")


Measured memory_bytes: 50448
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
#define root 1, n, 1
#define ls l, mid, k << 1
#define rs mid + 1, r, k << 1 | 1
using namespace std;

namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
// getchar
#define gc()                                                     \
    (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), \
                 (iS == iT ? EOF : *iS++))                       \
              : *iS++)
// print the remaining part
inline void flush() {
    fwrite(obuf, 1, oS - obuf, stdout);
    oS = obuf;
}
// putchar
inline void putc(char x) {
    *oS++ = x;
    if (oS == oT) flush();
}
// input a signed integer
template <class I>
inline void read(I &x) {
    for (f = 1, c = gc(); c < '0' || c > '9'; c = gc())
        if (c == '-') f = -1;
    for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15);
    x *= f;
}
// print a signed integer
template <class I>
inline void print(I x) {
    if (!x) putc('0');
    if (x < 0) putc('-'), x = -x;
    while (x) qu[++qr] = x % 10 + '0', x /= 10;
    while (qr) putc(qu[qr--]);
}
// no need to call flush at the end manually!
struct Flusher_ {
    ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io::print;
using io::putc;
using io::read;

int n, k;
int p[500005];

struct Seg {
    int tmn[2000006];
    void build(int l, int r, int k) {
        tmn[k] = n + 1;
        if (l == r) return;
        int mid = l + r >> 1;
        build(ls), build(rs);
    }
    int query(int l, int r, int k, int st, int en) {
        if (st > r || en < l) return n + 1;
        if (st <= l && en >= r) return tmn[k];
        int mid = l + r >> 1;
        return min(query(ls, st, en), query(rs, st, en));
    }
    void ins(int l, int r, int k, int pos, int v) {
        tmn[k] = v;
        if (l == r) return;
        int mid = l + r >> 1;
        (pos <= mid) ? ins(ls, pos, v) : ins(rs, pos, v);
    }
} seg;

int hd[500005], nx[1000006], to[1000006], cnt;
int deg[500005];
void add(int f, int t) { nx[++cnt] = hd[f], hd[f] = cnt, to[cnt] = t; }
priority_queue<int, vector<int>, greater<int> > q;
int res[500005], rc;
void work() {
    for (int i = 1; i <= n; ++i) !deg[i] ? q.push(i) : void();
    while (!q.empty()) {
        int u = q.top();
        q.pop(), res[u] = ++rc;
        for (int i = hd[u]; i; i = nx[i])
            !(--deg[to[i]]) ? q.push(to[i]) : void();
    }
    return;
}
int main() {
    read(n), read(k);
    for (int i = 1, x; i <= n; ++i) read(x), p[x] = i;
    seg.build(root);
    for (int i = n, j; i >= 1; --i) {
        j = seg.query(root, p[i] + 1, p[i] + k - 1);
        (j > n) ? void() : (deg[p[j]]++, add(p[i], p[j]));
        j = seg.query(root, p[i] - k + 1, p[i] - 1);
        (j > n) ? void() : (deg[p[j]]++, add(p[i], p[j]));
        seg.ins(root, p[i], i);
    }
    work();
    for (int i = 1; i <= n; ++i) print(res[i]), putc('\n');
    return 0;
}

Measured memory_bytes: 29216
s = input()
n = len(s) + 1
ans = [0] * n

tmp = 1
ens = list(enumerate(s))
for i, c in ens:
    if c == '<':
        ans[i + 1] = tmp
        tmp += 1
    else:
        tmp = 1

tmp = 1
for i, c in reversed(ens):
    if c == '>':
        ans[i] = max(ans[i], tmp)
        tmp += 1
    else:
        tmp = 1
print(sum(ans))


Measured memory_bytes: 75564
//#define _USE_MATH_DEFINES
#include <iostream>
//#include <stdio.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <cmath>
//#include <time.h>

using namespace std;


int main(){

	int d,x,y,S;


	while (cin >> d){
		S = 0;
		x = 0;
		while (x < 600 -d){
			x += d;
			y = x*x;
			S += d * y;
		}
		cout << S << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <cmath>
#include <iostream>

using namespace std;

int main(){
  int d;
  int ans;

  while(cin>>d){
    ans=0;
    for(int i=1;i<600/d;i++)ans+=pow((i*d),2)*d;
    cout<<ans<<endl;
}
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
//setprecision(12)
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int x, y; cin >> x >> y;
    rep(i,x+1) {
        if(i*2+(x-i)*4==y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<P> vec;
    vec.push_back(P(1,S[0]-'0'));
    for(int i=1; i<N; i++){
        if(S[i] != S[i-1]){
            vec.push_back(P(1,S[i]-'0'));
        }else{
            vec.back().first++;
        }
    }
    int ans = 0;
    int r = 0;
    int now = 0;
    for(int l=0; l<vec.size(); l++){
        while(r<vec.size()){
            if(K == 0 and vec[r].second == 0) break;
            now += vec[r].first;
            if(vec[r].second == 0) K--;
            r++;
        }
        chmax(ans,now);
        now -= vec[l].first;
        if(vec[l].second == 0) K++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  	cin>>a[i];
  int dp[n+1];
  dp[1]=0;
  dp[2]=abs(a[1]-a[0]);
  for(int i=3;i<=n;i++)
  	dp[i]=min((abs(a[i-1]-a[i-2])+dp[i-1]),(abs(a[i-1]-a[i-3])+dp[i-2]));
  cout<<dp[n]<<endl;
}

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;
const int INF = 1e+9;

const int N = 100;
int n;
int s[N+1];       //M_i : s[i-1] x s[i] (i=1,...,n)
int dp[N+1][N+1]; //dp[i][j] = (M_i * ... * M_j)????????????????¨?????????°???????°????(1<=i<=j<=n)

int main() {
  int i, j, k, l;
  scanf("%d ", &n);
  for (i=0; i<n; i++) scanf("%d%d ", s+i, s+i+1);
  for (i=1; i<=n; i++) dp[i][i] = 0;  //1????????????????¨?????????°???0
  for (l=2; l<=n; l++)  //M_i ... M_i????????°???????????§????????????
    for (i=1; i<=n-l+1; i++) {
      j = i + l - 1; 
      dp[i][j] = INF;
      for (k=i; k<j; k++)
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + s[i-1]*s[k]*s[j]);
    }

  printf("%d\n", dp[1][n]);

  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  
  long N10=1, N9=1, N8=1;
  for (int i = 0; i < N; i++) {
    N10 = (10*N10)%1000000007;
    N9 = (9*N9)%1000000007;
    N8 = (8*N8)%1000000007;
  }
  // M = 10^N - 2*9^N + 8^N
  // cout << M << endl;
  cout << (2*1000000007 + N10 - 2*N9 + N8)%1000000007 << endl;
}

Measured memory_bytes: 3588
use std::io::stdin;
use std::str::FromStr;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn read_str_as_char_vec() -> Vec<char> {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().chars().collect()
}

fn read_str_as_T<T>() -> T
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().unwrap()
}

fn main() {
    let in_vec: Vec<isize> = read_line();
    let y = in_vec[0];
    let x = in_vec[1];

    let a_base = x - 2 * y;
    let b_base = -1 * x + 4 * y;
    if a_base % 2 == 0 && a_base >= 0 && b_base % 2 == 0 && b_base >= 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2132
#include<stdio.h>
 char a[100000],c;
int main()
{
  int i,j,t;
  j=0;
  while(scanf("%s",a)!=EOF)
  {  for(i=0;(c=a[i])!='\0';i++,i++)
     {
         a[j]=a[i];
         j++;
     }
    a[j]='\0';
    printf("%s",a);
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
#define LOCAL
using namespace std;
// using namespace atcoder;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {}
    int root(int x) {
      if (d[x] < 0) return x;
      return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
      x = root(x); y = root(y);
      if (x == y) return false;
      if (d[x] > d[y]) swap(x,y);
      d[x] += d[y];
      d[y] = x;
      return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    int size(int x) { return -d[root(x)];}
  };
signed main(){
    int n,m;cin >>n >>m;
    UnionFind uf(n);
    rep(i,m){
        int a,b;cin >> a >> b;
        a--;b--;
        uf.unite(a,b);
    }
    int ret = 0;
    vector<int> vis(n);
    rep(i,n){
        int x = uf.root(i);
        if(vis[x])continue;
        vis[x] = 1;
        ret++;
    }
    cout <<ret-1 << endl;


    return 0;
}

Measured memory_bytes: 4840
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};//RDLU
int main(){
	int n;
	string s;
	cin>>s;
	n=s.size();
	if(s[0]=='0'||s[n-1]=='1'||s[n-2]=='0'){
		cout<<-1<<endl;
		return 0;
	}
	rep(i,n-1)if(i!=n-2-i&&s[i]!=s[n-2-i]){
		cout<<-1<<endl;
		return 0;
	}
	s[n-1]='1';
	int t=0;
	loop(i,1,n)if(s[i]=='1'){
		int w=i+1;
		rep(j,i-t){
			cout<<w<<" "<<t+j+1<<endl;
		}
		t=i;
	}
}


/*
string s="RDLU";
int main(){
	int n;
	cin>>n;
	vvi in(n,vi(2));
	rep(i,n)rep(j,2)cin>>in[i][j];
	
	int t=-1;
	bool h=true;
	rep(i,n){
		int tt=(abs(in[i][0])+abs(in[i][1]))%2;
		if(t==-1)t=tt;
		else if(t!=tt)h=false;
	}
	if(!h){
		cout<<-1<<endl;
		return 0;
	}
	rep(i,n)rep(j,2)if(abs(in[i][j])>10)return 1;
	
	int m=40-t;
	cout<<m<<endl;
	rep(i,m-1)cout<<1<<" ";
	cout<<1<<endl;
	
	rep(i,n){
		int co=m;
		int x=0,y=0;
		while(1){
			if(x==in[i][0]&&y==in[i][1])break;
			if(x<in[i][0]){cout<<"R";x++;}
			else if(x>in[i][0]){cout<<"L";x--;}
			else if(y<in[i][1]){cout<<"U";y++;}
			else if(y>in[i][1]){cout<<"D";y--;}
			co--;
		}
		if(co%2)return 1;
		while(co){
			cout<<"RL";
			co-=2;
		}
		cout<<endl;
	}
	
}
*/








Measured memory_bytes: 1664
import java.util.Scanner;

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

		int n = sc.nextInt();

		int[] base = new int[n];

		for (int i=0;i<n;i++) {
			base[i]=sc.nextInt();
		}

		System.out.println(bs(base,1,1000*1000*1000+1));


	}

	static int bs (int[] base, int min, int max) {
		if (min+1 == max) {
			return min;
		}

		int mid = min+(max-min)/2;
		int n = base.length;
		Bit bit = new Bit(2*n+1); // 0 to 2n
		int tmp = n;
		long tmp2 = 0;

		for (int i=0;i<n;i++) {
			bit.add(tmp,1);
			tmp+=(base[i]>=mid?1:-1);
			tmp2+=bit.sum(tmp+1);
		}

		if (tmp2*4 >= (long)n*(n+1)) {
			return bs(base, mid, max);
		} else {
			return bs(base, min, mid);
		}
	}
}

class Bit {
	//0-indexed
	int n;
	long[] values;
	public Bit(int n) {
		this.n=n;
		values = new long[n];
	}
	void add(int pos, int val) {
		for (int i=pos;i<n;i|=(i+1)) {
			values[i]+=val;
		}
	}
	long sum(int a) {
		int ans = 0;
		for (int i=a-1;i>=0;i=(i&(i+1))-1) {
			ans += values[i];
		}
		return ans;
	}
}


Measured memory_bytes: 66908
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using std::vector;

template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

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



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

int main() {
    
    int N;
    cin >> N;
    double ans = (N - N / 2)/(double) N;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,e,s) for(register int i=e; i<=s; i++)

int read() {
    int ch=getchar(),x=0,f=1;
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int main() {
    stack<int> s;
    char a[1000+10];
    while(scanf("%s",a+1)!=EOF) {
        if(a[1]=='+') {
            int x,y;
            x=s.top();
            s.pop();
            y=s.top();
            s.pop();
            
            s.push(x+y);
        }
        else if(a[1]=='-') {
            int x,y;
            x=s.top();
            s.pop();
            y=s.top();
            s.pop();
            s.push(y-x);
        }
        else if(a[1]=='*') {
            int x,y;
            x=s.top();
            s.pop();
            y=s.top();
            s.pop();
            s.push(x*y);
        }
        else
            s.push(atoi(a+1));
    }
    cout<<s.top()<<endl;
}


Measured memory_bytes: 3248
#include<iostream>
#include<map>
#include<cstdlib>
using namespace std;

typedef long long int lli;
const int inf = 1<<30;

int Ai[100010];
int temp[100010];

int main(){
  int N;
  cin>>N;
  for(int i=0;i<N;++i){
    cin>>Ai[i];
  }

  map<int,int> smap;
  for(int i=0;i<N;++i){
    smap[Ai[i]] = 0;
  }
  int index = 0;
  for(auto it=smap.begin();it!=smap.end();it++,++index){
    it->second = index;
  }
  for(int i=0;i<N;++i){
    temp[smap[Ai[i]]] = abs(i-smap[Ai[i]])%2;
  }
  int ans = 0;
  for(int i=0;i<N;++i){
    ans += temp[i];
  }
  cout<<ans/2<<endl;
  //  for(int i=0;i<N;++i) cout<<temp[i]<<endl;
  return 0;
}


Measured memory_bytes: 5760
import java.util.*;

public class Main
{
  static int n;
  static long[] a;
  static Long[][][] memo;
  public static void main(String[]  args)
  {
	Scanner in = new Scanner(System.in);
 	n = in.nextInt();
    a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = in.nextLong();
    memo = new Long[2][n][n];
    System.out.println(dp(0, 0, n-1));
    in.close();
  }
  
  public static long dp(int who, int l, int r)
  {
    if (l == r)
      return a[l];
    if (memo[who][l][r] != null)
      return memo[who][l][r];
    long ans = -(long)1e18;
    ans = Math.max(ans, a[l]-dp(1-who, l+1, r));
    ans = Math.max(ans, a[r]-dp(1-who, l, r-1));
    return memo[who][l][r] = ans;
  }
}

Measured memory_bytes: 231812
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll func(string s)
{
    ll n=s.size();
    ll i;
       for(i=0;i<n/2;i++)
   {
       if(s[i]!=s[n-i-1])
       {
           return 0;
       }
   }
   return 1;
}
int main()
{
   string s,s1,s2;
   cin>>s;
   ll n;
   n=s.size();
   ll i,j,temp=0;
   if(func(s)==0)
   {
       cout<<"No"<<endl;

       return 0;
   }
   s1=s.substr(0,(n/2));
    if(func(s1)==0)
   {
       cout<<"No"<<endl;

       return 0;
   }
   s2=s.substr((n/2)+1,n/2);
  if(func(s2)==0)
   {
       cout<<"No"<<endl;

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

return 0;
}


Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int a, p; cin >> a >> p;
  print((a * 3 + p) / 2);

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define ll long long
#define hh puts("")
#define pc putchar
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
using namespace std;
int n;
double ans;
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-ff;ch=getchar();}
    while(isdigit(ch)){ret=(ret<<3)+(ret<<1)+ch-'0';ch=getchar();}
    return ret*ff;
}
void write(int x){
    if(x<0){x=-x;putchar('-');}
    if(x>9) write(x/10);
    putchar(x%10+48);
}
signed main(){
	n=read();
	for(int i=1;i<=n;i++){
		ans+=1./read();
	}
	printf("%.7lf",1./ans);
    return 0;
}

Measured memory_bytes: 256
import sys
N, P = map(int, sys.stdin.readline().rstrip().split())
A = list(map(int, sys.stdin.readline().rstrip().split()))

kisu = 0
gusu = 0
for a in A:
    if a % 2 == 1:
        kisu += 1
    else:
        gusu += 1

total = 2 ** N # 全場合の数

# 階乗の事前計算
x = [1]
res = 1
for i in range(1, N + 1):
    res *= i
    x.append(res)

def cmb(n, r):
    return x[n] // (x[r] * x[n - r])

ans = 0 # 偶数になる場合の数

for k in range(kisu + 1):
    if k % 2 == 0:
        # 奇数が偶数個（0個含む） + 偶数が0個以上
        ans += cmb(kisu, k) * (2 ** gusu)

if P == 0:
    print(ans)
else:
    print(total - ans)

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> a >> b >> c;
    Yn(a + b >= c)
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ull ma(ull a,ull b)
{
    return max(a,b);
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
	int n,w;
	cin>>n>>w;
	vector<vector<ull>> dp(n+1,vector<ull> (w+1));

	for(int i=1;i<n+1;i++)
	{
		int s;
		ull v;
		cin>>s>>v;


		for (int j=0;j<w+1;j++)
			{
				if(s>j)
                    {dp[i][j]=dp[i-1][j];}
				else
				{dp[i][j]=ma(dp[i-1][j-1], dp[i-1][j-s]+v);}
			}
	}
	cout<<dp[n][w];





    return 0;
}


Measured memory_bytes: 80256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

void solve() {
  int r, c, n;
  cin >> r >> c >> n;
  map<int, int> bMap, rMap, tMap, lMap;
  for(int i = 0; i < n; i++) {
    int xa, ya, xb, yb;
    cin >> xa >> ya >> xb >> yb;
    if(xa != 0 && xa != r && ya != 0 && ya != c) continue;
    if(xb != 0 && xb != r && yb != 0 && yb != c) continue;
    if(xa == 0) tMap[ya] = i;
    else if(ya == c) rMap[xa] = i;
    else if(xa == r) bMap[-ya] = i;
    else {
      assert(ya == 0);
      lMap[-xa] = i;
    }
    if(xb == 0) tMap[yb] = i;
    else if(yb == c) rMap[xb] = i;
    else if(xb == r) bMap[-yb] = i;
    else {
      assert(yb == 0);
      lMap[-xb] = i;
    }

  }
  stack<int> s;
  for(auto x: tMap) {
    if(!s.empty() && s.top() == x.second) s.pop();
    else s.push(x.second);
  }
  for(auto x: rMap) {
    if(!s.empty() && s.top() == x.second) s.pop();
    else s.push(x.second);
  }
  for(auto x: bMap) {
    if(!s.empty() && s.top() == x.second) s.pop();
    else s.push(x.second);
  }
  for(auto x: lMap) {
    if(!s.empty() && s.top() == x.second) s.pop();
    else s.push(x.second);
  }
  if(s.empty()) cout << "YES\n";
  else cout << "NO\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 9984
#include "bits/stdc++.h"
using namespace std;
char a[10000], b[10000];
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	cin >> a;
	cin >> b;
	int lena = strlen(a);
	int lenb = strlen(b);
	if (lena != lenb) {printf("NO\n"); return 0;}
	for (int i = 0; i < lena; i++) {
		if (a[i] != b[lena - i - 1]) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define sqr(x) ((x)*(x))
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define y1 asdfghjkl
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const ll N = 2e5;
const ll INF = 1e18 + 7;
 
void boost() {
     ios_base :: sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
}
void file() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
}
ll fast_pow(ll a, ll b){
	ll res = a, ret = 1;
	while(b){
		if(b&1)
			ret = (ret*res)%mod;
		res = (res*res)%mod;
		b>>=1;
	}
	return ret;
}
int main() {
	boost();
	string s;
	cin >> s;
	if(s[s.size() - 1] == 's')
		cout << s << "es";
	else 
		cout << s << "s";
	return 0;
}

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

#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
#define nrep(i,a,b) for(int i=int(a);i>=int(b);--i)
#define trv(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define watch(x) cout<<"\n"<<#x<<" is "<<x<<"\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ZERO(box) memset(box, 0, sizeof(box));
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define chkbit(s, b) (s & (1<<b))
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1e9+7;


void solve(){
	ll a,b,h;
    cin>>a>>b>>h;
    cout<<(h*(a+b))/2;
}


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

*/

Measured memory_bytes: 256
from sys import exit
# A,B,C = [int(n) for n in input().split()]
N = int(input())
P = [int(input()) for _ in range(N)]
P = sorted(P)
P[-1] = P[-1]//2
print(sum(P))
# S = str(input())
# L = len(S)
# T = str(input())
# exit()


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


int main(){
  int s,m,u=0; cin>>s;
  bool mmyy=false;
  bool yymm=false;
  
  m=s/100;
  u=s%100;
   if(m<=12&&1<=m){
     mmyy=true;
   }
   if(u<=12&&1<=u){
     yymm=true;    }

  
   if(yymm&&mmyy)cout<<"AMBIGUOUS"<<endl;
  else if(yymm)cout<<"YYMM"<<endl;
  else if(mmyy)cout<<"MMYY"<<endl;
  else cout<<"NA"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <cassert>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

struct UF{
  vector<int> par, dep, sz;
  UF(int n){
		n++;
    par.resize(n), dep.resize(n, 0), sz.resize(n, 1);
    re(i, n) par[i] = i;
  }
  int find(int xu){
    if(par[xu] == xu) return xu;
    return par[xu] = find(par[xu]);
  }
  void unite(int xu, int yu){
    xu=find(xu), yu=find(yu);
    if(xu == yu) return;
    if(dep[xu] < dep[yu]) sz[yu] += sz[xu], par[xu] = yu;
    else par[yu] = xu, sz[xu] += sz[yu];
    if(dep[xu] == dep[yu]) dep[xu]++;
  }
  bool same(int xu, int yu){ return find(xu) == find(yu);}
};
int main(){
  ll n, m;std::cin >> n >> m;
  UF uf(n);
  for(int i=0;i<m;i++){
    ll a, b;std::cin >> a >> b;
    uf.unite(a-1, b-1);
  }
  ll ans = 0;
  for(int i=0;i<n;i++) if(uf.find(i)==i) ans++;
  std::cout << ans-1 << '\n';
}


Measured memory_bytes: 4580
def main():
    s=int(input())
    if(s<600):
        print(8)
    elif(s<800):
        print(7)
    elif(s<1000):
        print(6)
    elif(s<1200):
        print(5)
    elif(s<1400):
        print(4)
    elif(s<1600):
        print(3)
    elif(s<1800):
        print(2)
    elif(s<2000):
        print(1)

main()


Measured memory_bytes: 8920
use proconio::input;
use std::collections::HashMap;

fn main() {
  input! {
    n: usize,
    a: [i64; n],
  };
  
  let mut counts: HashMap<i64, i64> = HashMap::new();
  
  for x in a {
    if let Some(&count) = counts.get(&x) {
      counts.insert(x, count+1);
    } else {
      counts.insert(x, 1);
    }
  }
  
  let mut pairs: Vec<i64> = Vec::new();
  
  for (&x, &count) in &counts {
    for _ in 0..(count/2) {
      pairs.push(x);
    }
  }
  
  // 降順に並び替え
  pairs.sort_by_key(|&x| -x);
  
  if pairs.len() < 2 {
    println!("0");
  } else {
    println!("{}", pairs[0] * pairs[1]);
  }
}

Measured memory_bytes: 7204
#include <stdio.h>
#include <string.h>
#include <math.h>

int main() {

    int n, a;
    scanf("%d", &n);

    int arr[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a);
        if (a % 2 != 0) {
            printf("0");
            return 0;
        }
        arr[i] = a;

    }

    int isCheck;
    int cnt = 1;
    while (1) {

        isCheck = 1;

        for (int j = 0; j < n; j++) {
            if (arr[j] % (int)pow(2, cnt) != 0) {

                isCheck = 0;
                break;
            }
        }

        if (isCheck == 0) {
            printf("%d", cnt - 1);
            break;
        } else {
            cnt++;
        }

    }

    return 0;

} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//最大公約数
ll gcd(ll a,ll b)
{
    if(a%b == 0)
        return b;
    else
        return gcd(b, a % b);
}

int main(){
    int n, m;
    cin >> n >> m;
    ll ans = 0;
    bool flag[30];
    bool f[30];
    int i;
    for (int i = 0; i < m;i++)
    {
        flag[i] = false;
        f[i] = false;
    }
        for (int i = 0; i < n; i++)
        {
            for (int i = 0; i < m; i++)
            {
                flag[i] = false;
                //f[i] = false;
            }
            int k;
            cin >> k;
            for (int j = 0; j < k; j++)
            {
                int n;
                cin >> n;
                flag[n-1] = true;
            }
            for (int j = 0; j < m; j++)
            {
                if (i == 0)
                {
                    if (flag[j] == true)
                        f[j] = true;
                }
                else
                {
                    if (flag[j] == true && f[j] == true)
                        f[j] == true;
                    else
                    {
                        f[j] = false;
                    }
                }
            }
          
        }
        
        
            for (int i = 0; i < m; i++)
            {
                if (f[i] == true)
                {
                    ans++;
                }
            }
        cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(void) {
  string s;
  cin >> s;
  
  int n = 0;
  
  for(int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      n += 1;
    } else {
      continue;
    }
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int h[510001]={},w[510001]={},n,m,i,j,p[1500],k;
int main(){
  while(1){
    cin>>n>>m;if(n==0)break;
    for(i=0;i<n;i++){
      cin>>p[i];
      for(j=i,k=0;j>=0;j--)k+=p[j],h[k]++;
    }
    n=k;
    for(i=0;i<m;i++){
      cin>>p[i];
      for(j=i,k=0;j>=0;j--)k+=p[j],w[k]++;
    }
    if(k<n)k=n;
    n=0;
    for(i=1;i<=k;i++)n+=h[i]*w[i],h[i]=w[i]=0;
    cout<<n<<endl;
  }
  return 0;
}

Measured memory_bytes: 5144
// スタックサイズ: 100MB

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }



int main() {
	fastio;

	ll N, Q, K;
	cin >> N;
	vector<pll> G[100000];
	rep(i, N - 1) {
		ll a, b, c;
		cin >> a >> b >> c;
		--a, --b;
		G[a].push_back(pll(b, c)); G[b].push_back(pll(a, c));
	}
	cin >> Q >> K;
	--K;

	vll d(N, INF);
	d[K] = 0;
	queue<ll> que;
	que.push(K);
	while (!que.empty()) {
		ll from = que.front(); que.pop();
		rep(i, (ll)G[from].size()) {
			if (d[G[from][i].first] == INF) {
				d[G[from][i].first] = d[from] + G[from][i].second;
				que.push(G[from][i].first);
			}
		}
	}
	


	rep(i, Q) {
		ll x, y;
		cin >> x >> y;
		--x, --y;
		cout << d[x] + d[y] << endl;
	}
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define debug(x) (cout << "#x = " << (x) << '\n')

using namespace std;
typedef long long ll;

inline char gc() {
	static char buf[100000], *p1 = buf, *p2 = buf;
	return (p1 == p2) && (p2 = (p1 = buf) +
		fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
}

#define dd ch = getchar()
template <class T>
inline void read(T &x) {
	x = 0;
	int f = 0; char dd;
	for (; !isdigit(ch); dd) f ^= (ch == '-');
	for (; isdigit(ch); dd)  x = (x << 1) + (x << 3) + (ch ^ 48);
	x = f? -x: x;
}
#undef dd

template <class T>
inline void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 | 48);
}

template <class T>
inline void wrn(T x) {
	write(x), putchar(' ');
}

template <class T>
inline void wln(T x) {
	write(x), putchar('\n');
}

template <class T>
inline void wlnn(T x, T y) {
	wrn(x), wln(y);
}

ll n, Ans = 1e17, x[111];

int main()
{
	read(n);
	for (int i = 1; i <= n; ++i) read(x[i]);
	for (int i = 1; i <= 100; ++i) {
		ll sum = 0;
		for (int j = 1; j <= n; ++j) sum += (x[j] - i) * (x[j] - i);
		Ans = min(Ans, sum);
	}
	return wln(Ans), 0;
}

/*

*/




Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		System.out.println(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5) ? "Yes" : "No");
	}
}


Measured memory_bytes: 35596
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)



// // aのp乗を求める関数
// ll modpow(ll a, int p)  {
//   if (p == 0) return 1;
//   if (p%2 == 0) {
//     int halfP = p / 2;
//     ll half = modpow(a, halfP);
//     return half * half % MOD;
//   }
//   else  {
//     return a * modpow(a, p-1) % MOD;
//   }
// }
//
//
// /// aCbを求める関数
// ll mod_combination(int a, int b)  {
//   if (b > a-b)  return mod_combination(a, a-b);
//   ll ansMul = 1;
//   ll ansDiv = 1;
//   rep(i, b) {
//     ansMul *= (a - i);
//     ansDiv *= (i + 1);
//     ansMul %= MOD;
//     ansDiv %= MOD;
//   }
//   ll ans = ansMul * modpow(ansDiv, MOD-2) % MOD;
//   return ans;
// }

ll gcd(ll m, ll n) {
  // m = max(m, n);
  // n = min(m, n);
  if (n > m)  m, n = n, m;
  if (n == 0) return m;
  return gcd(n, m%n);
}


int main(void){
	int N; cin >> N;
  ll A[N-1];
  rep(i, N) cin >> A[i];
  ll ans = A[0];
  reps(i,N-1) {
    ans = gcd(ans, A[i]);
    // cout << ans << endl;
  }
  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  map<char, int> mp;
  rep(i, H) {
    cin >> A[i];
    rep(j, W) mp[A[i][j]]++;
  }
  bool ok = true;
  if(H%2==0 && W%2==0) {
    for(auto ele: mp) if(ele.second%4!=0) ok = false;
  } else if(H%2==0 || W%2==0) {
    int cnt = (H%2==0 ? H : W)/2;
    for(auto ele: mp) {
      if(ele.second%2!=0) ok = false;
      else if(ele.second%4!=0) {
        if(cnt==0) ok = false;
        cnt--;
      }
    }
  } else {
    int cnt = (H-1)/2+(W-1)/2;
    int one = 0;
    for(auto ele: mp) {
      if(ele.second%2!=0) one++;
      else if(ele.second%4!=0) {
        if(cnt==0) ok = false;
        cnt--;
      }
    }
    if(one != 1) ok = false;
  }
  cout << (ok ? "Yes" : "No") << "\n";
  return 0;
}


Measured memory_bytes: 3664
#include<cstdio>
using namespace std;
int main()
{
	
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int k;
	scanf("%d",&k);
	int f=0;
	for(int i=1;i<=k;i++)
	{
		if(b<=a) 
		{
		  b=b*2;
		}else if(c<=b)
		{
			c=c*2;
		}
	}
	if(a<b&&b<c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
 } 

Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, x;
	cin >> N;
	vector<int> qs;
	for(int i=0;i<N;i++){
		cin >> x;
		qs.push_back(x);
	}

	long long sum = accumulate(qs.begin(), qs.end(), 0);

	int M, y;
	vector<pair<int, int>> px;
	cin >> M;
	for(int i=0;i<M;i++){
		cin >> x >> y;
		px.push_back({x,y});
	}

	int temp = sum;
	for(int i=0;i<M;i++){
		temp = sum;
		x = px[i].first;
		temp-=qs[x-1];
		temp+=px[i].second;
		cout << temp << "\n";
	}
	return 0;
}

Measured memory_bytes: 3608