akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int n; long long cnt;
int A[1000000]; vector<int> G;

void Insert(int A[], int n, int g){
  for(int i=g;i<n;++i){
    int v=A[i]; int j=i-g;
    while(j>=0&&A[j]>v){
      A[j+g]=A[j]; j-=g;++cnt;
    }
    A[j+g]=v;
  }
}

void Shell(int A[], int n){
  for(int h=1;;){
    if(h>n)break;
    G.push_back(h);
    h = 3*h+1;
  }
  for(int i=G.size()-1;i>=0;--i) Insert(A, n, G[i]);
}

int main() {
    cin >> n;
    for(int i=0;i<n;++i) scanf("%d",&A[i]);
    Shell(A, n);
    cout<<G.size() << endl;
    for(int i=G.size()-1;i>=0;--i){
      cout << G[i];
      if(i) cout << " ";
    }
    cout << endl << cnt << endl;
    for(int i=0;i<n;++i) cout << A[i] << endl;
    return 0;
}

Measured memory_bytes: 7064
from collections import deque
def bisect(arr,x):
    l,r=-1,len(arr)
    while(r-l>1):
        mid=(l+r)//2
        if x>arr[mid][0]:
            l=mid
        else:
            r=mid
    return arr[l]

N,Q=map(int,input().split())

h=deque([(N-1,N-1)])
w=deque([(N-1,N-1)])
Black=(N-2)**2
for i in range(Q):
    t,x=map(int,input().split())
    x-=1
    if t==1:
        if x<h[0][0]:
            h.appendleft((x,w[0][0]))
            Black-=(w[0][0]-1)
        else:
            b=bisect(h,x)
            Black-=(b[1]-1)
    else:
        if x<w[0][0]:
            w.appendleft((x,h[0][0]))
            Black-=(h[0][0]-1)
        else:
            b=bisect(w,x)
            Black-=(b[1]-1)
print(Black)

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

int main(){
    int A, B;
    cin >> A >> B;
    
    int max;

    if(B > 0)   max = A + B;
    else    max = A - B;
    
    if(max < A*B)   max = A*B;
    
    cout << max << endl;
    
}




Measured memory_bytes: 256
import java.util.*;

public class Main {
public static void main(String[] args) throws Exception {
    	 Scanner sc = new Scanner(System.in);
    	 double r = sc.nextDouble();
    	 System.out.print(String.format("%.6f",r*r*Math.PI));
    	 System.out.print(" ");
    	 System.out.println(String.format("%.6f",r*(Math.PI*2)));
     }
}



Measured memory_bytes: 28200
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
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...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int num;
    cin >> num;
    int curr = 0, time = 0;
    while(curr < num) {
        time++;
        curr += time;
    }
    cout << time;
}

Measured memory_bytes: 3464
n = int(input())
s = input()

ans = [3*10**5]
white = [0]
black = [0]
for i in range(n):
    if s[i] == ".":
        white.append(white[i] + 1)
        black.append(black[i])
    else:
        white.append(white[i])
        black.append(black[i] + 1)
#print(white)
#print(black)
for i in range(n+1):
    ans.append(black[i] + white[n]-white[i])

print(min(ans))

Measured memory_bytes: 68064
//q002.cpp
//Sat Sep 19 15:36:41 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n;
	cin >> n;
	int ans = 0;
	for(int i=1;i<=n;i++){
		if(i%2==0)continue;
		int tmp = 0;
		for (int j=1;j<=i;j++){
			if (i%j==0)tmp++;
		}
		if(tmp==8)ans++;
	}


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3604
n,k=map(int,input().split())
w=[int(input()) for i in range(n)]
left=max(w)-1;right=sum(w)
mid=0
while left+1<right:
    mid=(left+right)//2
    sum=0;count=1
    for wi in w:
        if wi+sum>mid:
            sum=wi
            count+=1
        else:
            sum+=wi
    if count<=k:
        right=mid
    else:
        left=mid

print(right)


Measured memory_bytes: 9564
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int n; cin >> n;
    VI p(n); REP(i,n) cin >> p[i];
    out(SUM(p,MAX(p)/-2));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n, a, b, repeat, ans, cycles;

int main () {
    cin >> n >> a >> b;
    repeat = a+b;
    cycles = n/(repeat);
    ans = a*cycles;
    n -= repeat*cycles;
    if (n > a) ans += a;
    else ans += n;
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}
/*
ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}*/
int main() {
	cin >> n;
	vector<ll> a(n);
	vector<ll> dp(1000010,0);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll res = 0;
	rep(i, n) {
		if (dp[a[i]] == 0) {
			for (ll j = 1; j <= pow(10, 6) / a[i]; ++j) {
				dp[j * a[i]] = 1;
			}
			if (i == n - 1 || a[i + 1] != a[i]) {
				++res;
			}
		}
	}
	cout << res << endl;
}


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

char mat[1001][1001];

int J[1001][1001] = {}, O[1001][1001] = {}, I[1001][1001] = {};

int main(){
    int h, w, k;
    cin >> h >> w >> k;

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> mat[i][j];
        }
    }

    J[1][1] = (mat[1][1] == 'J');
    O[1][1] = (mat[1][1] == 'O');
    I[1][1] = (mat[1][1] == 'I');

    for(int i = 2; i <= h; i++){
        J[i][1] += J[i-1][1];
        O[i][1] += O[i-1][1];
        I[i][1] += I[i-1][1];
        if(mat[i][1] == 'J')  J[i][1]++;
        if(mat[i][1] == 'O')  O[i][1]++;
        if(mat[i][1] == 'I')  I[i][1]++;
    }

    for(int j = 2; j <= w; j++){
        J[1][j] += J[1][j-1];
        O[1][j] += O[1][j-1];
        I[1][j] += I[1][j-1];
        if(mat[1][j] == 'J')  J[1][j]++;
        if(mat[1][j] == 'O')  O[1][j]++;
        if(mat[1][j] == 'I')  I[1][j]++;
    }

    for(int i = 2; i <= h; i++){
        for(int j = 2; j <= w; j++){
            J[i][j] = (mat[i][j] == 'J') + J[i-1][j] + J[i][j-1] - J[i-1][j-1];
            O[i][j] = (mat[i][j] == 'O') + O[i-1][j] + O[i][j-1] - O[i-1][j-1];
            I[i][j] = (mat[i][j] == 'I') + I[i-1][j] + I[i][j-1] - I[i-1][j-1];
        }
    }

    int a, b, c, d;
    for(int i = 0; i < k; i++){
        cin >> a >> b >> c >> d;
        int jungle = J[c][d]-J[a-1][d]-J[c][b-1]+J[a-1][b-1];
        int ocean = O[c][d]-O[a-1][d]-O[c][b-1]+O[a-1][b-1];
        int ice = I[c][d]-I[a-1][d]-I[c][b-1]+I[a-1][b-1];
        cout << jungle << " " << ocean << " " << ice << endl;
    }

    return 0;
}


Measured memory_bytes: 15604
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k;
  cin >> n >> k;
  int zero = 0;
  int half = 0;
  FOR(i,1,n+1){
    if(i%k==0) zero++;
    if(k%2==0 && i%k==k/2) half++;
  }
  cout << (ll)zero*zero*zero + (ll)half*half*half << endl;
  return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
INF = float('inf')
d = [[INF for i in range(N)] for _ in range(N)]
edge = []
for i in range(N):
    d[i][i] = 0
for i in range(M):
    a,b,c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
    edge.append([a-1,b-1,c])
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j],d[i][k]+d[k][j])
ans = 0
for a,b,c in edge:
    if d[a][b]!=c:
        ans += 1
print(ans)


Measured memory_bytes: 46572
def f():
     h,w = map(int,input().split())
     field = []
     for i in range(h):
          field.append(list(input()))
          
     que = []
     for i in range(h):
          for j in range(w):
               if field[i][j] == "#":
                    que.append([i,j])
     if que == []:
          print(0)
          return
     cnt = 0
     while que != []:
          que1 = []
          for p in que:
               for v in [[1,0],[0,1],[-1,0],[0,-1]]:
                    newx,newy = p[1]+v[1],p[0]+v[0]
                    if (0<=newx) and (newx<w) and (0<=newy) and (newy<h):
                         if field[newy][newx] == ".":
                              field[newy][newx] = "#"
                              que1.append([newy,newx])
          que = que1
          cnt += 1
     print(cnt-1)
     return
f()

Measured memory_bytes: 177596
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;
const int mod = 998244353;
int arr[N];
int main()
{
   // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int n, k;
    scanf("%d %d", &n, &k);
    vector<pair<int, int>> vec;
    arr[n] = 1;
    arr[n + 1] = 0;
    int a, b;
    while (k--)
    {
        scanf("%d %d", &a, &b);
        vec.emplace_back(a, b);
    }
    for (int i = n - 1; i; --i)
    {
        arr[i] = arr[i + 1];
        for (auto p : vec)
        {
            a = i + p.first;
            b = i + p.second;
            a = min(a, n + 1);
            b = min(b, n + 1);
            int v = arr[a] - arr[b + 1] + mod;
            v %= mod;
            arr[i] = (arr[i] + v) % mod;
        }
    }
    printf("%d\n", (arr[1] - arr[2] + mod) % mod);
}

Measured memory_bytes: 4476
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

Vec p, c;

ll solve(ll d, ll g){
	if(g <= 0) return 0;
	if(d == 0) return LINF;

	ll x = solve(d - 1, g);
	ll y = p[d - 1] + solve(d - 1, g - p[d - 1] * d - c[d - 1]);
	ll t = min(p[d - 1] - 1, g / d + !!(g % d));
	ll z = t + solve(d - 1, g - t * d);
	return min({x, y, z});
}

int main(void){
	ll d, g;
	cin >> d >> g;
	g /= 100;
	p.resize(d);
	c.resize(d);
	rep(i, d) cin >> p[i] >> c[i];
	rep(i, d) c[i] /= 100;

	co(solve(d, g));

	return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <vector> 

using namespace std; 

int main() { 
  int n, w;
  cin>>n>>w; 
  long int a[n][2];
  vector<vector<long int>> dp(n+1, vector<long int>(w+1,0)); 
  for (int i=0;i<n;i++) { 
    cin>>a[i][0]>>a[i][1]; 
  } 
  
  for (int i=1;i<=n;i++) { 
    for (int j=1;j<=w;j++) { 
      if (a[i-1][0] <= j) {
          dp[i][j] = max(dp[i-1][j], dp[i-1][j-a[i-1][0]] + a[i-1][1]); 
      }
      else 
        dp[i][j] = dp[i-1][j];
     // cout<<dp[i][j]<<" ";
    }
   // cout<<endl;
  }
  cout<<dp[n][w]<<endl;
}


Measured memory_bytes: 80256
#include <iostream>
#include <vector>

int BALLNUM = 10;

	static int data[10];
class balldata
{
private:
	//static std::vector <int> data;
	//int ballnum;
public:
	balldata(int datanum);
	static void enter();
	static void answer();
	static bool check();
	static bool check(int num,int right,int left);
};




int main()
{
	balldata ball(BALLNUM);

int N;
	std::cin >> N;
	for (int i = 0; i < N; i++)
	{
		ball.enter();
		ball.answer();
	}
}


balldata::balldata(int datanum)
{
	//ballnum = datanum;
	//data.resize(datanum);
}



void balldata::enter()
{
	for (int i = 0; i < 10; i++)
	{
		std::cin >> data[i];
	}
	return;
}

bool balldata::check(int num,int right,int left)
{
	//if (num == data.size())return true;
	if (num == 10)return true;
	if (balldata::check(num + 1, right, data[num])&&left<data[num]){ return true; }
	if (balldata::check(num + 1, data[num], left)&&right<data[num]){ return true; }

	return false;
}
bool check()
{
	return balldata::check(0, 0, 0);
}

void balldata::answer()
{ 
	if (balldata::check(0, 0, 0))
	{
		std::cout << "YES" << std::endl;
	}
	else
	{
		std::cout << "NO" << std::endl;
	}
}

Measured memory_bytes: 1152
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
template<typename T> inline void in(T &e){cin>>e;}
template<typename T> inline void out(T e){cout<<e<<endl;}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

char grid[102][102];

int a,b;

signed main(){
    io();
    rep(y,102){
        rep(x,102) grid[x][y]='.';
    }
    REP(y,51,102){
        rep(x,102) grid[x][y]='#';
    }
    cin>>a>>b;
    for(int x=1,y=1,c=1;c<b;x+=2,c++){
        if(x==101){
            x-=99;
            y+=2;
        }else if(x==102){
            x-=101;
            y+=2;
        }
        grid[x][y]='#';
    }

    for(int x=1,y=52,c=1;c<a;x+=2,c++){
        if(x==101){
            x-=99;
            y+=2;
        }else if(x==102){
            x-=101;
            y+=2;
        }
        grid[x][y]='.';
    }
    
    printf("100 100\n");
    REP(y,1,101){
        REP(x,1,101) printf("%c",grid[x][y]);
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ALL(a) a.begin(),a.end()

int main(){
    ll N;
    cin >> N;
    vector<int> v(N);
    for(int i = 0; i < N; i++ )cin >> v[i];
    priority_queue<double, vector<double> ,greater<double>> PQ;
    for(int i = 0; i < N; i++) PQ.push((double)v[i]);
    double ans = PQ.top();PQ.pop();
    while(!PQ.empty()){
        double t1 = PQ.top(); PQ.pop();
        ans = (t1 + ans)/2;
    }
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
s = input()

ans = 0
n = len(s) - 1
for i in range(2 ** n):
    op = [''] * n
    for j in range(n):
        if ((i >> j) & 1):
            op[n - j - 1] = '+'
    formula = ''
    for p_n, p_o in zip(s,op+['']):
        formula += (p_n+p_o)
    ans += eval(formula)

print(ans)

Measured memory_bytes: 40304
def examB():
    N, A, B = LI()
    cur = 0
    for i in range(1,N+1):
        judge = 0; icur = i
        while(icur>0):
            judge +=icur%10
            icur //=10
        if A<=judge<=B:
            cur +=i
    print(cur)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()


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

int keta(long x) {
  return x ? 1 + keta(x/10): 0;
}

int main() {
  long n;
  cin >> n;
  int ans = 100;
  for (long i = 1; i * i <= n; i++) {
    if (n % i != 0) continue;
    int a = keta(i);
    int b = keta(n / i);
    ans = min(ans, max(a, b));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <cstdio>
using namespace std;

#define ll long long
#define vecint vector<int>
#define listint list<int>
#define Pii pair<int, int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define MOD 1000000007
#define NIL -1

// void printarray(ll box[],int N){
//   for(int i=0;i<N;i++){
//     cout << box[i] << " ";
//   }
//   cout << endl;
// }

int main(){
  int N;
  ll box[100000];
  ll x;
  ll ans=0;
  cin>>N>>x;
  rep(i,N){
    cin>>box[i];
  }
  rep(i,N-1){
    if(box[i]+box[i+1]>x){
      ll c=box[i]+box[i+1]-x;
      if(box[i+1]>=c){
        box[i+1]-=c;
        ans+=c;
        // printarray(box,N);
      }else{
        box[i]-=c-box[i+1];
        ans+=c;
        box[i+1]=0;
        // printarray(box,N);
      }
    }
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	int A, B;
	cin >> A >> B;
	cout << max(A + B, max(A - B, A * B)) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

Scanner in = new Scanner(System.in);
int[] vx = {-1, 0, 1, 0};
int[] vy = {0, 1, 0, -1};

public void run() {
while (true) {
int n = in.nextInt();
if (n == 0) break;
int[] x = new int[n];
int[] y = new int[n];

x[0] = y[0] = 0;

int minX = 0, minY = 0, maxX = 0, maxY = 0;

for (int i = 0; i < n - 1; i++) {
int c = in.nextInt(), d = in.nextInt();
x[i+1] = x[c] + vx[d];
minX = Math.min(minX, x[i+1]);
maxX = Math.max(maxX, x[i+1]);
y[i+1] = y[c] + vy[d];
minY = Math.min(minY, y[i+1]);
maxY = Math.max(maxY, y[i+1]);
}

System.out.println((maxX - minX + 1) + " " + (maxY - minY + 1));
}
}
}

Measured memory_bytes: 34384
n = gets.to_i
r = $stdin.readlines.map(&:chomp).map(&:to_i)

maxv = -Float::INFINITY
minv = r[0]

1.upto(n - 1) do |i|
  maxv = [maxv, r[i] - minv].max
  minv = [minv, r[i]].min
end

puts maxv

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

int main(){
    
    int x, y;
    cin>>x>>y;
    
    while( x > 0 || y > 0){
        if(y < x) swap(x,y);
        cout<<x<<" "<<y<<endl;
        cin>>x>>y;
    }
    
    
    return 0;
}


Measured memory_bytes: 2980
# -*- coding: utf-8 -*-
# 標準入力を取得
N, M = list(map(int, input().split()))
k, s = [], []
for m in range(M):
    l = list(map(int, input().split()))
    k.append(l[0])
    s.append(l[1:])
p = list(map(int, input().split()))

# 求解処理
ans = 0
for bit in range(1 << N):
    is_light_on = True
    for m in range(M):
        on_count = 0
        for s_i in s[m]:
            if ((bit >> (s_i - 1)) & 1):
                on_count += 1
        if on_count % 2 != p[m]:
            is_light_on = False
            break
    if is_light_on:
        ans += 1

# 結果出力
print(ans)


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(i,k) cin >> l[i] >> r[i];
  vector<mint> dp(n+1);
  vector<mint> dpsum(n+1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    rep(j,k) {
      // [l[i], r[i]]
      int li = i-r[j];
      int ri = i-l[j];
      if (ri < 0) continue;
      li = max(li,1);
      dp[i] += dpsum[ri]-dpsum[li-1]; //dp[li]~dp[ri];
    }
    dpsum[i] = dpsum[i-1]+dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}



Measured memory_bytes: 6400
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████   
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬╬╬██╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<60
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef pair<int,int> P;
typedef vector<vector<P>> Graph;

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

  int n;
  cin >> n;
  
  if(n == 3 || n == 5 || n == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
 
  return 0;
}

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

ll n, k;
vector<ll> a;
bool check(ll mid) {
	ll cnt = 0;
	for (int i = 1;i < n;i++) {
		if (a[i]) {
			ll y = mid / a[i];
			if (a[i] > 0) {
				if (a[i] * y != mid and mid > 0) y++;
				cnt += lower_bound(a.begin(), a.begin() + i, y) - a.begin();
			}
			else {
				if (a[i] * y != mid and mid > 0) y--;
				cnt += (a.begin() + i) - upper_bound(a.begin(), a.begin() + i, y);
			}
		}
		else {
			cnt += mid > 0 ? i : 0;
		}
	}
	return cnt < k;
}

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

	cin >> n >> k;
	a.resize(n);
	loop(n) cin >> a[i];
	sort(iter(a));
	ll l = -1000000000000000000, r = 1000000000000000001;
	while (l < r) {
		ll mid = avg(l, r);
		if (check(mid)) l = mid + 1;
		else r = mid;
	}
	cout << l - 1 << endl;
	return 0;
}



Measured memory_bytes: 1792
fn main() {
    let buf = io::read_string();
    let mut sc = io::Scanner::new(&buf);
    let a: usize = sc.read();
    let b: usize = sc.read();
    println!("{}", (a-1)*(b-1));
}

#[allow(dead_code)]
mod io {
    use std;
    use std::io::Read;
    use std::str::{FromStr, SplitWhitespace};
    pub struct Scanner<'a> {
        pub iter: SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.iter
                .next()
                .unwrap()
                .parse()
                .ok()
                .expect("parsing failed")
        }
        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
    }
    pub fn read_string() -> String {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){

ll int N;
cin >> N;

vector<ll int> L(N);
rep(i,N){
	cin >> L[i];
	}

if(N<3){
	cout << "0";
	return 0;
}
else{}
ll int counter=0;
for(ll int i=0;i<N-2;i++){
	for(ll int j=i+1;j<N-1;j++){
		for(ll int k=j+1;k<N;k++){
			if(L[i]!=L[j] && L[j]!=L[k] && L[i]!=L[k] && 
					L[i]+L[j]>L[k] &&L[i]+L[k]>L[j] &&L[k]+L[j]>L[i] ){
				counter+=1;
//				cout << L[i] << L[j] << L[k] <<endl;
			}
			else{}
		}
	}
}
cout << counter;

		       












	return 0;

}



Measured memory_bytes: 3628
W, H, N = map(int, input().split())

LL = []

for j in range(H):
    L = []
    for i in range(W):
        L.append(0)
    LL.append(L)

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        # ans -= x * H
        for j in range(H):
            LL[j][:x] = [1 for k in range(x)]
    elif a == 2:
        # ans -= (W - x) * H
        for j in range(H):
            LL[j][x:] = [1 for k in range(x)]
    elif a == 3:
        # ans -= W * y
        cnt = 0
        for j in range(H):
            if cnt >= H - y:
                LL[j] = [1 for k in range(x)]
            cnt += 1
    else:
        # ans -= W * (H - y)
        for j in range(H - y):
            LL[j] = [1 for k in range(x)]

ans = 0
for i in LL:
    for j in i:
        if j == 0:
            ans += 1

print(ans)

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

using namespace std;

int abs(int x){
	if(x<0)return -x;
	return x;
}
int main(){
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)cin>>arr[i];
	int DP[n];
	DP[n-1]=0;
	for(int i=n-2;i>-1;i--){
		DP[i]=DP[i+1]+abs(arr[i]-arr[i+1]);
		if(i<n-2)DP[i]=min(DP[i],DP[i+2]+abs(arr[i]-arr[i+2]));
	}
	cout<<DP[0]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)    cerr<<#x<<" : "<<x<<endl;
#define trace2(x,y) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<" | "<<#z<<" : "<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int main(){
    int n;
    cin>>n;
    vector <pair <int, pair<int,int> > > v;
    v.push_back({0,{0,0}});
    for(int i=0;i<n;i++){
        int t,x,y;
        cin>>t>>x>>y;
        v.push_back({t,{x,y}});        
    }
    bool ans=true;
    for(int i=1;i<=n;i++){
        int tc=v[i].F;int tp=v[i-1].F;
        int td=tc-tp;
        int cd=((v[i].S.F-v[i-1].S.F)+(v[i].S.S-v[i-1].S.S));
        if(td < cd)
        {
            ans=false;
        }
        if(td >= cd){
            if(td % 2 ==1 && cd % 2 ==0 )ans=false;
        }
    }
    if(ans)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 1912
from itertools import permutations
N=int(input())
arr=[list(map(int,input().split())) for i in range(N)]

def dis(x):
    c=0
    for i in range(N-1):
        aa=arr[x[i]][0]-arr[x[i+1]][0]
        bb=arr[x[i]][1]-arr[x[i+1]][1]
        c+=(aa**2+bb**2)**(0.5)
    return c
 
count=0
ans=0
for i in permutations(range(0,N),N):
    count+=1
    ans+=dis(i)

print(ans/count)


Measured memory_bytes: 9272
#include "bits/stdc++.h"

using namespace std;



int main() {
	int N,M ;
	cin >> N >> M;
	vector<int>A(M);
	int day = 0;
	for (int i = 0;i<M;++i) {
		cin >> A[i];
		day += A[i];
	}
	if (day <= N) {
		cout << N - day <<endl;
	}
	else{
		cout << "-1" << endl;
	}
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n;
  cin >> n;
  vector<vll> a(n, vll(2));
  long double avg = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a[i][0];
    avg += a[i][0];
    a[i][1] = i;
  }
  avg /= n;
  ll m = -1;
  sort(all(a));
  for (ll i = 0; i < n; i++) {
    if (a[i][0] == avg) {
      cout << a[i][1] << endl;
      return 0;
    }
    if (a[i][0] > avg) {
      while (i > 0 && a[i][0] == a[i - 1][0]) i--;
      m = i;
      break;
    }
  }
  if (m == 0) {
    cout << a[m][1] << endl;
    return 0;
  }
  ll x = m - 1;
  while (x > 0 && a[x][0] == a[x - 1][0]) x--;
  //cout << a[m][0] - avg << " " << avg - a[x][0] << endl;
  if (a[m][0] - avg > avg - a[x][0]) cout << a[x][1] << endl;
  else if (a[m][0] - avg < avg - a[x][0]) cout << a[m][1] << endl;
  else {
    cout << min(a[x][1], a[m][1]) << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int n, min, max, compare;
	long sum;
	sum = 0;
	min = 1000000;
	max = -1000000;
	scanf("%d", &n);
	while (scanf("%d", &compare) == 1) {
		if (n == 1) {
			min = max = sum = compare;
			break;
		}
		if (compare <= min) min = compare;
		if (compare >= max) max = compare;
		sum += compare;
	}
	printf("%d %d %ld\n", min, max, sum);
	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

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

void solve(){
    while(true){
        string enc;
        cin >> enc;
        if(enc=="#") break;

        int num=0;
        set<string> s1,s2;
        function<void(const int,string&,vector<bool>&)> rec=[&](const int k,string &res,vector<bool> &done){
            if(k==enc.size()){
                ++num;
                s1.insert(res);
                s2.insert(res);
                return;
            }
            if(!done[enc[k]-'a'] and enc[k]!='z'){
                ++res[k];
                done[enc[k]-'a']=true;
                rec(k+1,res,done);
                --res[k];
                done[enc[k]-'a']=false;
            }
            if(enc[k]=='a' or done[enc[k]-'a'-1]) rec(k+1,res,done);
        };
        {
            string res=enc;
            vector<bool> done(26,false);
            rec(0,res,done);
        }

        cout << num << endl;
        if(num<=10) for(const auto &dec:s1) cout << dec << endl;
        else{
            {
                int i=0;
                for(auto it=s1.begin(); i!=5; ++i,++it) cout << *it << endl;
            }
            {
                int i=0;
                vector<string> ans;
                for(auto it=s2.rbegin(); i!=5; ++i,++it) ans.emplace_back(*it);
                reverse(ans.begin(),ans.end());
                for(const auto &tmp:ans) cout << tmp << endl;
            }
        }
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}

Measured memory_bytes: 7124
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    int ans=1;
    int nax=0;
    for(int i=1;i<=n;i++){
        int hoge=i;
        for(int j=1;j<=100;j++){
            if(hoge%2==1 || hoge==0){
                nax=max(nax,j);
                if(nax==j) ans=i;
                break;
            }else{
                hoge/=2;
            }
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
/*
ID: arthurc4
TASK: test
LANG: C++11
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++)
#define REPb(j, d, c) \
for (int j = int(d); j >= int(c); j--)
#define pb \
push_back
#define ff \
first
#define ss \
second

ll dp_max_value[100001];
ll dp_item_used[100001][100];

int main()
{
	//ifstream cin("input.txt");
	//ifstream cin("test.in");
	//ofstream cout("test.out");

	// I think we can do this in O(NW) space and time

	int n, W;
	cin >> n >> W;

	vector<pair<ll,ll>> WV;

	REP(i,1,n)
	{
		ll w, v;
		cin >> w >> v;
		WV.pb({w,v});
	}

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

	ll global_max_value=0;

	REP(i,1,W)
	{
		ll best_include=-1; // don't include anything
		ll max_value=0;

		REP(j,0,n-1)
		{
			if(WV[j].ff > i) break;

			if(dp_item_used[i-WV[j].ff][j]) continue;

			if(WV[j].ss + dp_max_value[i-WV[j].ff] > max_value)
			{
				max_value = WV[j].ss + dp_max_value[i-WV[j].ff];
				best_include = j;
			}
		}

		if(best_include!=-1)
		{
			dp_max_value[i]=max_value;

			dp_item_used[i][best_include]=true;
		
			REP(k,0,99)
			{
				if(dp_item_used[i-WV[best_include].ff][k]) dp_item_used[i][k]=true;
			}
		}

		// cout << i << " " << dp_max_value[i] << endl;

		// REP(j,0,n-1)
		// {
		// 	if(dp_item_used[i][j]) cout << j << " ";
		// }
		// cout << endl;

		global_max_value=max(global_max_value,dp_max_value[i]);
	}

	// cout << endl;

	// for(auto e:WV)
	// {
	// 	cout << e.ff << " " << e.ss << endl;
	// }

	// cout << endl;

	cout << global_max_value << endl;

	return 0;
}

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

int main() {
	long long n,k,i,ans=0,cur,res;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> k;
		if(k%2==1){
			ans++;
		}
	}
	if(ans%2==0){
		cout << "YES";
	}else{
		cout << "NO";
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int N,A,B,P,sum=129;
    int S[3]={0};
    cin >> N;
    cin >> A >> B;
    for(int i=0;i<N;i++){
        cin >> P;
        if(P<=A)S[0]++;
        else if(P>=B+1)S[2]++;
        else S[1]++;
    }
    for(int j=0;j<3;j++){
        if(S[j]<sum)sum=S[j];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

int biMatch(const vector<vector<int>>& adj, int ln) { // adj: [0,ln)->inL [ln,n)->inR
    int n = adj.size();
    vector<int> matchTo(n, -1);
    vector<bool> used(n, false);
    function<bool(int)> dfs = [&](int v) {
        for(int nv : adj[v]) if(!used[nv]) {
            used[nv] = true;
            if(matchTo[nv] < 0 || dfs(matchTo[nv])) {
                matchTo[v] = nv;
                matchTo[nv] = v;
                return true;
            }
        }
        return false;
    };
    int ans = 0;
    for(int v : in(ln)) if(matchTo[v] < 0) {
        used.assign(n, false);
        if(dfs(v)) ++ans;
    }
    return ans;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int INF(1e9);
    int n, m, q;
    while(cin >> n >> m >> q && n) {
        vector<vector<int>> dist(n, vector<int>(n, INF));
        for(int i : in(n)) dist[i][i] = 0;
        for(int _ : in(m)) {
            int u, v, d;
            cin >> u >> v >> d;
            dist[u][v] = dist[v][u] = d;
        }
        for(int k : in(n))
            for(int i : in(n))
                for(int j : in(n))
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        vector<pair<int, int>> query(q);
        for(auto& p : query) cin >> p.second >> p.first;
        sort(query.begin(), query.end());
        vector<vector<int>> adj(q * 2);
        for(int i : in(q)) {
            for(int j : in(i + 1, q)) {
                int u, v, t1, t2;
                tie(t1, u) = query[i];
                tie(t2, v) = query[j];
                if(t2 - t1 >= dist[u][v]) {
                    adj[i].emplace_back(j + q);
                    adj[j + q].emplace_back(i);
                }
            }
        }
        cout << q - biMatch(adj, q) << endl;
    }
    return 0;
}

Measured memory_bytes: 7928