akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define DR(i,a,b) for (int i=(b); i-->(a);)
#define D(i,n) DR(i,0,n)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream &operator<<(ostream &os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i];
    return os;
}
const bool debug = 1;
const int INF = 9e18;

V<int> w;
V<V<int>> g;
void dfs(int u, int par, int d) {
    MA(w[d], S(g[u]) - (par != -1));
    for (int v : g[u]) if (v != par)
        dfs(v, u, d+1);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    g.resize(n);
    F(_,n-1) {
        int a,b; cin>>a>>b;
        a--, b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    int best = INF, leafs = INF;
    auto up = [&](int l) {
        int d = 1;
        F(i,n) if (w[i]) {
            d++;
            l *= w[i];
        }
        if (best > d || (best == d && leafs > l)) {
            best = d;
            leafs = l;
        }
    };
    F(u,n) {
        w.assign(n,0);
        dfs(u, -1, 0);
        up(1);
        for (int v : g[u]) {
            w.assign(n,0);
            dfs(u, v, 0);
            dfs(v, u, 0);
            up(2);
        }
    }
    cout<<best<<" "<<leafs<<"\n";
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

vector<int> G[200100];
ll X[200100];
bool isvisit[200100];

void dfs(int v, ll sum){
    isvisit[v] = true;
    X[v] += sum;
    for(int i = 0; i < G[v].size(); i++){
        int next = G[v][i];
        if(isvisit[next]) continue;
        dfs(next, X[v]);
    }
}

int main(){
    ll N, Q;
    cin >> N >> Q;
    REP(i,N-1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    REP(i,Q){
        int p;
        ll x;
        cin >> p >> x;
        p--;
        X[p] += x;
    }

    dfs(0, 0);

    REP(i,N){
        cout << X[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 24448
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[100010];
int a[100010][30];
int main()
{
	while(scanf("%s",s)!=EOF)
	{
		bool p=false;
		int l=strlen(s),i;
		if(l==2)
		{
			if(s[0]==s[1])
			{
				printf("1 2\n");
				continue;
			}
		}
		else
		for(i=2;i<l;i++)
		{
			if(s[i]==s[i-1]||s[i]==s[i-2])
			{
				p=true;
				break;
			}
		}
		if(p)
		{
			printf("%d %d\n",i-1,i+1);
		}
		else
		printf("-1 -1\n");
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n, m; cin >> n >> m;
    vector<vector<int>> a(20);
    for (int i = 0; i < m; i++) {
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int x; cin >> x;
            a[i].push_back(x);
        }
    }
    vector<int> p(m);
    for (int &x : p) {
        cin >> x;
    }
    int res = 0;
    for (int mask = 0; mask < (1 << n); mask++) {
        bitset<20> lit;
        for (int j = 0; j < n; j++) {
            if (mask & (1 << j)) {
                lit[j + 1] = 1;
            }
        }
        int cnt = 0;
        for (int i = 0; i < m; i++) {
            int tot = 0;
            for (int &x : a[i]) {
                if (lit[x]) {
                    tot++;
                }
            }
            if (tot % 2 == p[i]) {
                cnt++;
            }
        }
        res += (cnt == m);
    }
    cout << res << "\n";
}


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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

constexpr double eps = 1e-8;
inline constexpr bool eq(double a, double b) { return fabs(a - b) < eps; }

//-----点-----//
struct Point
{
    double x, y;

    constexpr Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}

    Point &operator+=(const Point &p) { x += p.x, y += p.y; return *this; }
    Point &operator-=(const Point &p) { x -= p.x, y -= p.y; return *this; }
    Point &operator*=(const double k) { x *= k, y *= k; return *this; }
    Point &operator/=(const double k) { x /= k, y /= k; return *this; }
};

inline Point operator+(const Point &p, const Point &q) { return Point(p) += q; }
inline Point operator-(const Point &p, const Point &q) { return Point(p) -= q; }
inline Point operator*(const Point &p, const double k) { return Point(p) *= k; }
inline Point operator/(const Point &p, const double k) { return Point(p) /= k; }

inline Point operator+(const Point &p) { return p; }
inline Point operator-(const Point &p) { return Point(-p.x, -p.y); }

inline constexpr bool operator==(const Point &p, const Point &q) { return eq(p.x, q.x) && eq(p.y, q.y); }
inline constexpr bool operator!=(const Point &p, const Point &q) { return !(p == q); }

inline double norm2(const Point &p) { return p.x * p.x + p.y * p.y; }
inline double norm(const Point &p) { return sqrt(p.x * p.x + p.y * p.y); }
inline double arg(const Point &p) { return atan2(p.y, p.x); }

inline double dot(const Point &p, const Point &q) { return p.x * q.x + p.y * q.y; }
inline double cross(const Point &p, const Point &q) { return p.x * q.y - p.y * q.x; }

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

//-----直線-----//
struct Line
{
    Point a, b;
    Line(Point a, Point b) : a(a), b(b) {} /* 2点a, bを通る直線 */
};

/* 
 * "射影" (直線 l に点 p から垂線を引いた交点を求める)
 * verified at: https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/1/CGL_1_A
 */
Point projection(const Line &l, const Point &p)
{
    Point d = l.b - l.a; // 直線 l の方向ベクトル
    Point h = d * (dot(p - l.a, d) / norm2(d)); // 正射影ベクトル
    return l.a + h;
}

/* 
 * "反射" (直線 l に関して点 p と対称な点を求める)
 * verified at: https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/1/CGL_1_B
 */
Point reflection(const Line &l, const Point &p) { return p + (projection(l, p) - p) * 2.0; }

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

    Point p0, p1; cin >> p0 >> p1;
    int q; cin >> q;
    while (q--) {
        Point p2; cin >> p2;
        Point u = p1 - p0, v = p2 - p0;
        if (cross(u, v) > eps) cout << "COUNTER_CLOCKWISE\n";
        else if (cross(u, v) < -eps) cout << "CLOCKWISE\n";
        else if (dot(u, v) < 0) cout << "ONLINE_BACK\n";
        else if (norm(u) < norm(v)) cout << "ONLINE_FRONT\n";
        else cout << "ON_SEGMENT\n";
    }
    return 0;
}



Measured memory_bytes: 3304
from functools import lru_cache
import sys
sys.setrecursionlimit(1000000)
P = 10**9+7
@lru_cache(maxsize=None)
def subcalc(l, r):
    if l < 0 or r < 0:
        print("ERROR")
        print("l, r =", l, r)
        print(1//0)
    if l > r: return 0
    if r == 0: return 1
    aa, bb = l.bit_length(), r.bit_length()
    if aa == bb:
        return subcalc(l-(1<<aa-1), r-(1<<bb-1))
    if (r & (r+1) == 0) and (l == 0):
        return pow(3, r.bit_length(), P)
    t = (subcalc(l, r-(1<<bb-1)) + subcalc(l, (1<<bb-1)-1) + subcalc(0, r-(1<<bb-1))) % P
    # print("subcalc", l, r, t)
    return t

@lru_cache(maxsize=None)
def calc(L, R):
    if L < 0 or R < 0:
        print("ERROR")
        print("l, r =", l, r)
        print(1//0)
    if L > R: return 0
    a = L.bit_length()
    b = R.bit_length()
    if b > a:
        t = (calc(L, (1<<b-1)-1) + calc(1<<b-1, R)) % P
        # print("calc", L, R, t)
        return t
    
        
        
    a = 1 << L.bit_length() - 1 if L else 0
    t = subcalc(L-a, R-a)
    # print("calc", L, R, t)
    return t

L, R = map(int, input().split())
print(calc(L, R))


Measured memory_bytes: 3684
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

ll n;

vector<int> calc(ll x, int lim) {
    vector<int> ret;

    if (x == 1) {
        return ret;
    }

    if (x & 1) {
        ret = calc(x - 1, lim - 1);
        ret.insert(ret.begin(), lim);
    }
    else {
        ret = calc(x / 2, lim - 1);
        ret.pb(lim);
    }

    return ret;
}

void solve() {
    scanf("%lld", &n);
    vector<int> vv = calc(n + 1, 100);

    for (int i = 1; i <= 100; ++i) {
        vv.pb(i);
    }

    printf("%d\n", vv.size());

    for (int i = 0; i < vv.size(); ++i) {
        printf("%d", vv[i]);
        printf(i + 1 == vv.size() ? "\n" : " ");
    }
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
from math import sqrt
from time import perf_counter
t0=perf_counter()
N=int(input())
A=list(map(int,input().split()))
A.sort()
def main():
    a=0
    s=set()
    t=0
    if A[0]!=1:
        for i in A:
            if i in s:
                if t==i:
                    a-=1
                    t=0
                continue
            for j in range(2,int(sqrt(i)+1.1)):
                if i%j:
                    continue
                if j in s:
                    break
                if i//j in s:
                    break
            else:
                t=i
                a+=1
            s.add(i)
            if perf_counter()-t0>1.9:
                a=N
                break                
    else:
        if N>1 and A[1]==1:
            a=0
        else:
            a=1
    print(a)
main()

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

#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll N, M, sum_a;

  void init() {
    scanf("%lld %lld", &N, &M);
    ll a;
    rep(i, M) {
      scanf("%lld", &a);
      sum_a += a;
    }
  }

  void solve() {
    if(sum_a > N) printf("-1\n");
    else printf("%lld\n", N-sum_a);
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	char c[4];
	char d[4];

	scanf("%s", c);
	scanf("%s", d);

	if(c[0]==d[2]&&c[1]==d[1]&&c[2]==d[0]){
		printf("YES\n");
	}else{
		printf("NO\n");
	}

	return 0;
}


Measured memory_bytes: 256
use std::io;
fn get_parms() -> Vec<u32> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("stdin error");
    return buf
        .split_whitespace()
        .map(|x| x.parse().expect("Parse failed"))
        .collect();
}

fn main() {
    let seconds = get_parms()[0];
    let second = seconds % 60;
    let minute = seconds / 60 % 60;
    let hour = seconds / 3600;
    println!("{}:{}:{}", hour, minute, second);
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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; }

// union by size + path having
class UnionFind {
public:

    //素集合の要素の親（木構造の根）を配列*3で保持している．初期状態では頂点間の辺は存在せず，孤立した状態のため，自分自身を根として初期化している（par: parent の略）．
    vector <ll> par;

    // 各集合（木）の大きさ．根をたどるとその木の大きさが返されるように実装されている．この配列を用意しておくとある頂点の連結成分の大きさを簡単に求められる
    vector <ll> siz;

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
    int N, M, x, y;
    cin >> N >> M;
    vector<int> p(N), correct(N);
    rep(i, N) {
        cin >> x;
        x--;
        p.at(i) = x; // p[i] に x が入っている
        correct.at(x) = i; // 現在 x が入っている座標は　i　である
    }
    UnionFind uf(N);
    rep(i, M){
        cin >> x >> y;
        x--;
        y--;
        uf.merge(x, y);
    }
    rep(i, N){
        if(p.at(i) == i) continue;
        else if(uf.issame(i, correct.at(i))) {
            p.at(correct.at(i)) = p.at(i); // p[i] は交換元の座標に入れる
            correct.at(p.at(i)) = correct.at(i);
            correct.at(i) = i;
            p.at(i) = i;
        }
    }
    int ans = 0;
    rep(i, N) {
        if(p.at(i) == i) ans++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 5572
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

template<typename Monoid>
struct SegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;      // モノイドに対して二項演算を行う関数オブジェクト
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1){
        sz = 1;
        while(sz < n)   sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x){
        seg[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    void update(int k, const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k >>= 1){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    Monoid query(int a, int b){
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){
            if(a & 1)   L = f(L, seg[a++]);
            if(b & 1)   R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const{
        return seg[k + sz];
    }
};

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

    int n, m;
    string s;
    cin >> n >> m >> s;
    SegmentTree<P> dp(n + 1, [](P a, P b){return min(a, b);}, P(INF, -1));
    dp.update(0, P(0, 0));
    for(int i = 1; i <= n; ++i){
        if(s[i] == '1') continue;
        int left = max(0, i - m), right = i + 1;
        P p = dp.query(left, right);
        dp.update(i, P(p.first + 1, i));
    }
    if(dp[n].first >= INF){
        cout << -1 << "\n";
        return 0;
    }
    vector<int> res;
    int pos = n;
    int cnt = dp[n].first;
    while(cnt > 0){
        int left = max(0, pos - m), right = pos;
        P p = dp.query(left, right);
        res.push_back(pos - p.second);
        cnt = p.first, pos = p.second;
    }
    reverse(res.begin(), res.end());
    int sz = res.size();
    for(int i = 0; i < sz; ++i) cout << res[i] << ((i == sz - 1) ? "\n" : " ");
}

Measured memory_bytes: 6092
import java.util.*;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for(int tmp = 0; tmp < n; tmp++) {
			int hn = sc.nextInt();
			list.add(hn);
		}
		int result = 0;
		
		for(int tmp1 = 0; tmp1 < n; tmp1++) {
			int x = list.get(tmp1);
			boolean flag = false;
			for(int tmp2 = 0; tmp2 < tmp1; tmp2++) {
				if(x < list.get(tmp2)) {
					flag = true;
				}
			}
			if(!flag) {
				result += 1;
			}
		}
		
		System.out.println(result);
	}
}

Measured memory_bytes: 23124
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	ll n, t;
	cin >> n;
	vector<ll> v;
	for (int i = 0; i < n; i++) {
		cin >> t;
		v.push_back(t);
	}
	sort(v.begin(), v.end(), greater<ll>());
	ll ret = 0;
	for (int i = 1; i < n / 2; i++) {
		ret += 2 * v[i];
	}
	ret += v[0];
	if (n & 1) {
		ret += v[n/2];
	}
	cout << ret << endl;
	return 0;
}


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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;

    int h,w,k;
    cin>>h>>w>>k;

    int maskh=(1<<h)-1;
    int maskw=(1<<w)-1;

    char arr[h][w];

    for(int i=0;i<h;i++) {
        for(int j=0;j<w;j++) {
            cin>>arr[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<maskh;i++) {
        for(int j=0;j<maskw;j++) {
            int black=0;
            for(int x=0;x<h;x++) {
                for(int y=0;y<w;y++) {
                    if((((i>>x)&1)==0) && ((j>>y)&1)==0 && arr[x][y]=='#') {
                        black++;
                    }
                }
            }
            if(black==k) {
                ans++;
            }
        }
    }

    cout<<ans<<endl;
}




Measured memory_bytes: 3620
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//int n = sc.nextInt();
		//String[][] array = new String[100][500];
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list_origin=new ArrayList<Integer>();
		String s = sc.next();
		String t = sc.next();

		List<String> list_s= new ArrayList<String>(Arrays.asList(s.split("")));
		List<String> list_t= new ArrayList<String>(Arrays.asList(t.split("")));
		int count=0;

		for(int i=0;3>i;i++) {
			String a = list_s.get(i);
			String b = list_t.get(i);
			if(a.equals(b)) {
				count++;
			}
		}

		System.out.println(count);




	}

}

Measured memory_bytes: 21712
import math
n=int(input())
a=list(map(int,input().split()))
q=int(input())
for i in range(q):
    k=int(input())
    t=0
    max=n-1
    min=0
    while max-min>1:
        nn=math.floor((max+min)/2)
        if a[nn]==k:
            t=1
            print("1")
            break
        elif a[nn]<=k:
            min=nn
        elif a[nn]>=k:
            max=nn
    if t==0:
        if a[max]==k or a[min]==k:
            t=1
            print("1")
        else:
            print("0")


Measured memory_bytes: 17240
#include <bits/stdc++.h>
#define gc() getchar()
using namespace std;

int in()
{
    int n = 0, c = 0;
    do {n = 10*n + (c & 0xf); c = gc();} while ('0'<=c && c<='9');
    return n;
}

int main()
{
    int n = in();
    vector<int> a(n); for (int i=0; i<n; i++) a.at(i) = in();

    int count = 0;
    for (int i=0; i<n; i+=2)
    {
        if (a.at(i) % 2 == 1) count++;
    }

    printf("%d\n", count);
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	vector<char> ans;
	int count=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='0'){
			ans.push_back('0');
			count++;
		}
		if(s[i]=='1'){
			ans.push_back('1');
			count++;
		}
		if(ans.size()>=1&&s[i]=='B'){
			ans.pop_back();
			count--;
		}
	}
	for(int i=0;i<ans.size();i++){
		cout<<ans[i];
	}
	cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
const ll mod1 = 123456789;
const int maxx = 1005;
ll q, t, n, m, T, k, ans, a[maxn], b[maxn], c[maxn], f[maxx][maxx];
priority_queue<ll> pr;
string s, str;
char ss[maxx][maxx];
map<ll, ll> mp;
void sol()
{
    cin >> n;
    ll mx = 1e16;
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i];
    }
    for(int i = n - 1; i >= 0; i--)
    {
        for(int j = i; j >= 0; j --)
        {
            if(i == n - 1)f[i][j] = (j == 0 ? a[i] : 0);
            else
                f[i][j] = min(a[i] + f[i+1][a[i] > 100 ? j + 1 : j], j > 0 ? f[i+1][j-1] : mx);
        }
    }
    cout << f[0][0];
}

char ch;
string gach[10000007];
struct dang
{
    ll val, sl;
};
dang st[maxn];
bool lt(const dang &x, const dang &y)
{
    return x.val < y.val;
}
void bs(ll c[], ll v, ll n)
{
    ll lf = 1, rt = n, mid, x;
    while(lf <= rt)
    {
        mid = (lf + rt) / 2;
        if(c[mid]*2 < v)lf = mid + 1;
        else rt = mid - 1;
    }
    if(c[lf]*2==v)--ans;
    /*x = lf;
    lf = 1, rt = n, mid;
    while(lf <= rt)
    {
        mid = (lf + rt) / 2;
        if(c[mid]*2 <= v)lf = mid + 1;
        else rt = mid - 1;
    }
    if(c[rt]*2 == v)ans -= (rt - x + 1);*/
}

ll mu(ll k, ll n)
{
    ll kq = 1;
    while(n)
    {
        if(n % 2 == 1)kq = (kq * k) % mod;
        k = (k * k) % mod;
        n /= 2;
    }
    return kq;
}
void test()
{
    //ll c[maxn], d[maxn];
    cin >> n >> k;
    ans = 0;
    for(int i = k; i > 0; i --)
    {
        a[i] = mu(k/i, n);
        for(int j = i * 2; j <= k; j += i)
            a[i] -= a[j];
        a[i] = (a[i] + mod * mod) % mod;
        ans += a[i] * i;
        ans %= mod;
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    test();
}


Measured memory_bytes: 316880
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ans = [0]
    t = 0
    for i in range(n):
        t += a[i]
        ans.append(t)
    ans = collections.Counter(ans)
    t = 0
    for k, v in ans.items():
        t += (v * (v - 1) // 2)
    print(t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 110160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
#define pb push_back
#define mp make_pair

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll d = c - a - b;
    if(d > 0 && d * d > 4 * a * b){
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
    int a[5][205], dp[5][105];
    memset(dp, 0, sizeof(dp));
    memset(a, 0, sizeof(a));

    int n;
    cin >> n;
    for(int i=1; i<=2; i++) for(int j=1; j<=n; j++) cin >> a[i][j];
    for(int i=1; i<=2; i++) {
        for(int j=1; j<=n; j++) {
            dp[i][j] = max(dp[i][j-1], dp[i-1][j]) + a[i][j];
        }
    }
    cout << dp[2][n] << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int k,s;cin>>k>>s;int sum=0;
	for(int i=0;i<=k;i++){
		for(int j=0;j<=k;j++){
			int z=s-i-j;
			if(z<=k&&z>=0){
				sum++;
			}
		}
	}cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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() {
  string s;
  cin >> s;

  string ans;
  rep(i, s.size()) {
    if (s[i] == 'B') {
      if (ans.size())
        ans.pop_back();
    } else {
      ans.pb(s[i]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long inf = 1ll<<61;
const double eps = 0.000000000001;
typedef pair<int, int> P;
typedef pair<int ,P> PP;
struct edge { int to; int to2; int cost; };
int a[200006], b[200006];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i] >> b[i];
	vector<P>V;
	rep(i, n)V.push_back(P(b[i], a[i]));
	sort(V.begin(), V.end());
	int sum = 0;
	rep(i, n) {
		sum += V[i].second;
		if (V[i].first < sum) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}

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

using namespace std;

int sqr(int x) {
	return x*x;
}

int n, a[105];

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	int ans = 0x7fffffff;
	for (int x = -100; x <= 100; ++x) {
		int sum = 0;
		for (int j = 0; j < n; ++j)
			sum += sqr(x-a[j]);
		ans = min(sum, ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import bisect

n = int(input())
d = list(map(int, input().split()))
 
d.sort()

ans = 0

for b in range(n):
    for a in range(b):
        ab = d[a] + d[b]
        r = bisect.bisect_left(d, ab)
        l = b+1
        ans += max(0, r-l)

print(ans)

Measured memory_bytes: 42972
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;

bool comp(const int& a, const int& b) {
	return a > b;
}

int main()
{
	ll N, M,ANS;
	cin >> N >> M;
	ANS = N * (N - 1) / 2;
	ANS = ANS + M * (M - 1) / 2;
	cout << ANS << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int x=0,ans=0;
    scanf("%d",&x);
    while(x>=500)
    {
      x-=500;
      ans+=1000;
    }
    while(x>=5)
    {
      x-=5;
      ans+=5;
    }
    printf("%d",ans);
  return 0;
}

Measured memory_bytes: 1700
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

int main(void) {

	ll a, b, c;
	cin >> a >> b;

	c = (b - a);

	cout << (c)*(c - 1) / 2 - a << endl;

	return 0;
}


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

using namespace std;

using ll = long long;

int main() {
   ios_base::sync_with_stdio(false);
   int N; ll T;
   cin >> N >> T;
   vector<ll> ones;
   vector<pair<ll, ll>> vals;
   for (int i = 0; i < N; ++i) {
      ll a, b;
      cin >> a >> b;
      b += a;
      ++a, ++b;
      if (a == 1) {
         ones.emplace_back(b);
      } else {
         vals.emplace_back(a, b);
      }
   }
   sort(ones.begin(), ones.end());
   sort(vals.begin(), vals.end(), [&](pair<ll, ll> a, pair<ll, ll> b) {
      return b.first * a.second + b.second < a.first * b.second + a.second;
   });
   vector<ll> dp(42, T + 1);
   dp[0] = 0;
   for (auto v : vals) {
      ll a, b;
      tie(a, b) = v;
      for (int i = 40; i >= 0; --i) {
         if (dp[i] <= T) {
            dp[i + 1] = min(dp[i + 1], a * dp[i] + b);
         }
      }
   }
   int ans = 0;
   for (int z = 0; z < 42; ++z) {
      if (dp[z] <= T) {
         int cans = z;
         ll curT = dp[z];
         for (ll v : ones) {
            if (curT + v > T) break;
            cans++;
            curT += v;
         }
         ans = max(ans, cans);
      }
   }
   cout << ans << "\n";
   return 0;
}


Measured memory_bytes: 6256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 3005
#define MOD 1000000007
using namespace std;
int n, dp[M][M], pre[M];
char in[M];
int main()
{
    scanf("%d%s",&n, in+1);
    
    REP(i,0,n-1) dp[1][i] = 1;
    REP(i,2,n) {
        MSET(pre, 0);
        pre[0] = dp[i-1][0];
        REP(j,1,n-1) pre[j] = (pre[j-1] + dp[i-1][j]) % MOD;

        REP(j,0,n-i) {
            if (in[i-1]=='<') {
                dp[i][j] = pre[j];
            } else {
                int tmp = pre[n-1];
                tmp = (tmp-pre[j])%MOD;
                if (tmp < 0) tmp += MOD;
                dp[i][j] = tmp;
            }
        }
    }
    
    printf("%d\n", dp[n][0]);
    return 0;
}


Measured memory_bytes: 31388
def foo(S,W):
    kosu=0
    S = S.lower()
    S = S.split()
    for i in range(len(S)):
        if S[i] == W:
            kosu+=1
    return kosu

x=0
W=input()
S=input()
while S != "END_OF_TEXT":
    x += foo(S,W)
    S = input()

print(x)



Measured memory_bytes: 5560
#include"bits/stdc++.h"
using namespace std;
int main()
{
	int a[3]={0};
	char c;
	scanf("%c",&c);
	a[c-'a']=1;
	scanf("%c",&c);
	a[c-'a']=1;
	scanf("%c",&c);
	a[c-'a']=1;
	if(a[0]==1&&a[1]==1&&a[2]==1)
		printf("Yes");
	else
		printf("No");
} 

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    akari<pair<i64, i64>> ps(n);
    for (int i = 0; i < n; i++)
    {
        cin >> ps[i].first >> ps[i].second;
    }
    sort(ps.begin(), ps.end());
    akari<i64> ls1(n), rs1(n), ls2(n), rs2(n);
    ls1[0] = ps[0].first;
    rs1[0] = ps[0].second;
    for (int i = 1; i < n; i++)
    {
        ls1[i] = ps[i].first;
        rs1[i] = min(rs1[i - 1], ps[i].second);
    }
    ls2[n - 1] = ps[n - 1].first;
    rs2[n - 1] = ps[n - 1].second;
    for (int i = n - 2; i >= 0; i--)
    {
        ls2[i] = max(ls2[i + 1], ps[i].first);
        rs2[i] = min(rs2[i + 1], ps[i].second);
    }
    i64 ans = 0;
    for (int i = 0; i < n - 1; i++)
    {
        //print(rs1[i] - ls1[i] + i64(1), rs2[i + 1] - ls2[i + 1] + i64(1));
        ans = max(ans, max(rs1[i] - ls1[i] + i64(1), i64(0)) + max(rs2[i + 1] - ls2[i + 1] + i64(1), i64(0)));
    }
    for (int i = 1; i < n - 1; i++)
    {
        ans = max(ans, ps[i].second - ps[i].first + i64(1) + max(min(rs2[i + 1], rs1[i - 1]) - ls2[i] + i64(1), i64(0)));
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 4992
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

n, mod = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

ele_id = 1
# dp[v][i] = (頂点vから出るi番目の有向辺に関する部分木のDPの値)
# dp[v][i] = (c, m)
# c = 頂点vから出るi番目の有向辺に関する部分木の塗り方の数
# m = 頂点vから出るi番目の有向辺に関する部分木の頂点数
dp = [[ele_id] * len(graph[i]) for i in range(n)]
ans = [ele_id] * n

add_func = lambda x: x + 1
merge_func = lambda a, b: a * b % mod


def dfs1(v, v_p):
    dp_cum = ele_id
    for i, v_next in enumerate(graph[v]):
        if v_next == v_p:
            continue
        dp[v][i] = dfs1(v_next, v)
        dp_cum = merge_func(dp_cum, dp[v][i])
    return add_func(dp_cum)


def dfs2(v, v_p, dp_vp):
    for i, v_next in enumerate(graph[v]):
        if v_next == v_p:
            dp[v][i] = dp_vp

    dp_l = [ele_id] * (len(graph[v]) + 1)
    dp_r = [ele_id] * (len(graph[v]) + 1)
    for i in range(len(graph[v])):
        dp_l[i + 1] = merge_func(dp_l[i], dp[v][i])
    for i in reversed(range(len(graph[v]))):
        dp_r[i] = merge_func(dp_r[i + 1], dp[v][i])

    ans[v] = add_func(dp_l[-1])

    for i, v_next in enumerate(graph[v]):
        if v_next == v_p:
            continue
        dfs2(v_next, v, add_func(merge_func(dp_l[i], dp_r[i + 1])))


dfs1(0, -1)
# print(*dp, sep='\n')
dfs2(0, -1, ele_id)
for ans_i in ans:
    print(ans_i - 1)


Measured memory_bytes: 147232
h,w = map(int,input().split())
a = []
for _ in range(h):a.append(input())
for _ in range(w + 2):print("#",end="")
print()
for i in range(h):
    print("#",end="")
    print(a[i],end="")
    print("#")
for _ in range(w + 2):print("#",end="")

Measured memory_bytes: 9056
import java.io.IOException;
import java.util.Scanner;
 
class Main {
 
    public static void main(String[] args) throws IOException {
 
        Scanner scanner = new Scanner(System.in);
 
        int r = scanner.nextInt();
        int c = scanner.nextInt();
        int[][] list = new int[r][c];
        int[] sumR = new int[r];
        int[] sumC = new int[c];
        int sumRC = 0;
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                list[i][j] = scanner.nextInt();
            }
        }
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                sumR[i] += list[i][j];
            }
        }
         
        for (int i = 0; i < list[0].length; i++) {
            for (int j = 0; j < list.length; j++) {
                sumC[i] += list[j][i];
            }
            sumRC += sumC[i];
        }
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                System.out.print(list[i][j] + " ");
            }
            System.out.println(sumR[i] + "");
        }
         
        for (int num : sumC) {
            System.out.print(num + " ");
        }
        System.out.print(sumRC + "\n");
    }
}

Measured memory_bytes: 42840
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int p = sc.nextInt();
    a *= 3;
    a += p;
    int ans = a / 2;
    System.out.println(ans);
  }
}


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int N;
  cin >> N;
  if (N == 1)
    cout << '0' << endl;
  else
    cout << '1' << endl;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>

int main( void ) {
	char str1[ 100000 ], str2[ 100000 ], fig, tmp;
	int n, idx1, idx2, sum;

	while ( scanf( "%d", &n ), n ) {
		scanf( "%s", str1 );

		while ( n-- ) {
			idx1 = idx2 = 0;
			while ( ( fig = str1[ idx1 ] ) != '\0' ) {
				for ( sum = 1; ( tmp = str1[ ++idx1 ] ) != '\0' && fig == tmp; sum++ ) ;

				sprintf( str2 + idx2++, "%d%c", sum, fig );
				do {
					idx2++;
				} while ( sum /= 10 );
			}

			strcpy( str1, str2 );
		}

		printf( "%s\n", str1 );
	}

	return 0;
}

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

const long long int DIV = 1000000007;

int N;
long long int A[1000000];

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

	int t[3] = {0,0,0};
 	long long int ans = 1;
	for(int i = 0; i < N; i++){
		int same = 0;
		if(t[0] == A[i]) same++;
		if(t[1] == A[i]) same++;
		if(t[2] == A[i]) same++;
		ans *= same;
		ans %= DIV;

		if(t[0] == A[i]) t[0]++;
		else if(t[1] == A[i]) t[1]++;
		else t[2]++;

//	cout << ans << endl;
	}
	/*
	if(t[0] != t[1] && t[0] != t[2] && t[1] != t[2]){
//		ans *= 6;
		ans %= DIV;
	}
	else if(t[0] == t[1] && t[0] == t[2]){
		ans %= DIV;
	}
	else{
		ans *= 3;
		ans %= DIV;
	}
	*/
	cout << ans << endl;

	return 0;
}


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

#define FOR(i, a, b) for (int (i) = (a); (i) < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cerr << #x << " " << x << endl
#define eb emplace_back
#define _ << " " <<
typedef long long ll;
typedef std::pair<int, int> ii;
#define X first
#define Y second
#define double long double
typedef double db;
using namespace std;

const int MaxN = 400;
const int Mod = 1e9 + 7;

int N;
string p[MaxN];

int norm(int x){
  x = x % N;
  if (x < 0) x += N;
  return x;
}

bool good(int A) {
  REP(i, N) REP(j, N){
    if (p[norm(j-A)][i] != p[norm(i-A)][j]) return false;
  }
  return true;
}

void solve(){
  ll cnt = 0;
  
  for (int A = 0; A < N; A++) {
    if (good(A)) cnt += N;
  }

  cout << cnt << endl;
}

void load(){
  scanf("%d", &N);
  REP(i, N) cin>>p[i];
}

int main(){
//  ios_base::sync_with_stdio(false);
  load();	
  solve();
  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#define rng(x1, y1, x2, y2) (sum[y2][x2] + sum[y1][x1] - sum[y2][x1] - sum[y1][x2])
using namespace std;
int H, W, ra, o, a[40][40], sum[40][40], dp[40][40][40][40];
int solve(int x1, int y1, int x2, int y2) {
	if (dp[y1][x1][y2][x2] != -1) return dp[y1][x1][y2][x2];
	int rng_ = rng(x1, y1, x2, y2);
	int ret = 1000000 + rng_;
	for (int i = x1 + 1; i < x2; i++) {
		int petl = rng(x1, y1, i, y2);
		int petr = rng(i, y1, x2, y2);
		if (min(petl, petr) >= o) {
			int resl = solve(x1, y1, i, y2);
			int resr = solve(i, y1, x2, y2);
			int res = (resl + resr) / 1000000 * 1000000 + min(resl % 1000000, resr % 1000000);
			ret = max(ret, res);
		}
	}
	for (int i = y1 + 1; i < y2; i++) {
		int petl = rng(x1, y1, x2, i);
		int petr = rng(x1, i, x2, y2);
		if (min(petl, petr) >= o) {
			int resl = solve(x1, y1, x2, i);
			int resr = solve(x1, i, x2, y2);
			int res = (resl + resr) / 1000000 * 1000000 + min(resl % 1000000, resr % 1000000);
			ret = max(ret, res);
		}
	}
	return dp[y1][x1][y2][x2] = ret;
}
int main() {
	while (cin >> H >> W >> ra, H) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) cin >> a[i][j];
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + a[i][j];
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				for (int k = i + 1; k <= H; k++) {
					for (int l = j + 1; l <= W; l++) dp[i][j][k][l] = -1;
				}
			}
		}
		o = sum[H][W] - ra;
		int ret = solve(0, 0, W, H);
		cout << ret / 1000000 << ' ' << ret % 1000000 - o << endl;
	}
}

Measured memory_bytes: 8992
/*****include*****/
#include <iostream>
#include <fstream>

/*****デバッグ定義*****/
//#define DEBUG
#define INF 10000
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/
int Field[20][20];

/*****その他関数置き場*****/
int djikstra(int start,int goal,int townnum){
	int *dis;
	bool *used;
	int town;
	int res;
	dis = new int [townnum];
	used = new bool [townnum];
	for(int i=0;i<townnum;i++){
		dis[i] = INF;
		used[i] = false;
	}
	dis[start] = 0;
	while(true){
		town = -1;
		for(int i=0;i<townnum;i++){
			if(!used[i] && (town == -1 || dis[town] > dis[i])){
				town = i;
			}
		}
		if(town == -1)	break;
		used[town] = true;
		for(int i=0;i<townnum;i++){
			if(dis[i] > dis[town] + Field[town][i]){
				dis[i] = dis[town] + Field[town][i];
			}
		}
	}
	
	/*for(int i=0;i<townnum;i++)	cout << dis[i] << " ";
	cout << endl;*/
	res = dis[goal];
	delete used;
	delete dis;
	return res;
}
/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	int townnum;
	int rootnum;
	int ts,tg,value,price;
	int cost=0;
	int t1,t2,c1,c2;
	/*****処理部*****/
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			Field[i][j] = INF;
		}
	}
	cin >> townnum >> rootnum;
	for(int i=0;i<rootnum;i++){
		scanf("%d,%d,%d,%d",&t1,&t2,&c1,&c2);
		//cin >> t1 >> ',' >> t2 >> ',' >> c1 >> ',' >> c2;
		Field[t1-1][t2-1] = c1;Field[t2-1][t1-1] = c2;
		Field[t1-1][t1-1] = 0;Field[t2-1][t2-1] = 0;
	}
	scanf("%d,%d,%d,%d",&ts,&tg,&value,&price);
	//cout << ts << " " << tg << " " << townnum <<endl;
	cost = 0;
	cost += djikstra(ts-1,tg-1,townnum);
	cost += djikstra(tg-1,ts-1,townnum);
	cout << (value - price - cost) << endl;
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

Measured memory_bytes: 1240
#include <stdio.h>
int main(void){
	int count = 0, n, h[100] = {0};
	scanf("%d", &n);getchar();
	for(int i = 0; i < n; i++){
		scanf("%d", &h[i]);getchar();
	}
	for(int i = 0; i < n; i++){
		int lookable = 1;
		for(int j = 0; j < i; j++){
			if(h[j] > h[i]){
				lookable = 0;
			}
		}
		if(lookable){
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

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

int N;

void solve() {
    cin >> N;
    
    // 整数部、小数部合わせて10桁
    cout.precision(10);
    
    cout << (double)(N-N/2) / (double)N << endl;
    
    return;
}

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

Measured memory_bytes: 256
L, R = map(int, input().split())

res = 2019

modL = L % 2019
div = 2019 - modL
#2019の倍数を含む場合、最小値=0
if L + div <= R:
    res = 0    

else:
    for i in range(L, R):
        for j in range(i+1, R+1):
            val = ((i % 2019) * (j % 2019)) % 2019
            if val < res:
                res = val

print(res)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int P = sc.nextInt();
		char[] c = sc.next().toCharArray();
		int[] v = new int[N];
		for(int i=0; i<N; i++)
			v[i] = c[i]-'0';
		
		if(P==2 || P==5) {
			long ans = 0;
			for(int i=0; i<N; i++) {
				if(v[i]%P==0) {
					ans += i+1;
				}
			}
			System.out.println(ans);
			sc.close();
			return;
		}
		
		int[] mod = new int[P];
		long ans = 0;
		long a = 1; // a = 10000000...
		long b = 0;
		
		mod[v[0]%P]++;
		a *= 10;
		ans += mod[0];
		mod[0]++;

		for(int i=1; i<N; i++) {
			b = (b*10+v[i])%P;
			int index = (int)(((P-(b%P)) * rev(a, P))%P);
			ans += mod[index];
			mod[index]++;
			a = (a * 10)%P;
		}
		
		System.out.println(ans);
		sc.close();
	}
	
	static long rev(long a, long MOD) {
		return pow(a, MOD-2, MOD);
	}
	
	static long pow(long a, long b, long MOD) {
		long ans = 1;
		while(b>0) {
			if((b&1)!=0) {
				ans = (ans * a)%MOD;
			}
			b>>=1;
			a = (a*a)%MOD;
		}
		return ans;
	}

}



Measured memory_bytes: 31572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=100000000000000005;
const int maxn=1e6+5;
const int mod=433494437;
ll n,m,p;
bool vis[maxn];
int prime[maxn];
ll cnt=0;
void set_prime()
{
    for(int i=1;i<maxn;i++)
        vis[i]=(i==1?false:true);//假设除了1以外都是素数
    for(int i=2;i<maxn;i++)
    {
        if(vis[i]) prime[++cnt]=i;
        for(int j=1;j<=cnt&&i*prime[j]<maxn;j++)
        {
            vis[i*prime[j]]=false;
            if(i%prime[j]==0) break;//保证被筛的是他最小的质因子
        }
    }
}
int main()
{
    set_prime();
    scanf("%lld",&n);
    ll l=1,r=cnt;
    ll ans=-1;
    while(l<=r)
    {
        ll mid=(l+r)/2;
        if(prime[mid]>=n)
        {
            r=mid-1;
            ans=mid;
        }
        else
            l=mid+1;
    }
    printf("%d\n",prime[ans]);
    return 0;
}


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

int main(){
  int N; cin>>N;
  int X[N];
  vector<int> v(N);
  rep(i,N){
    cin>>X[i];
    v[i]=X[i];
  }
  sort(v.begin(),v.end());
  int mid=N/2-1;
  rep(i,N){
    if(X[i]<=v[mid]){
      cout<<v[mid+1]<<endl;
    }else{
      cout<<v[mid]<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3712