akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
a = input()
b = input()
if a[2] == b[0] and a[1] == b[1] and a[0] == b[2]:
    print("YES")
else:
    print("NO")
"""

#B
"""
n = I()
n = int(math.sqrt(n))
print(n**2)
"""

#C
n = I()
a = LI()
a.sort()
b = LI()
b.sort()
c = LI()
c.sort()
ans = 0
for i in b:
    x = bisect.bisect_left(a, i)
    x = x * (n - bisect.bisect_right(c, i))
    ans += x
print(ans)

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

using namespace std;
using ll = long long int;

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

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

    vector<vector<int>> E(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        E[b].push_back(a);
        E[a].push_back(b);
    }

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        bool ok = true;
        for (auto to : E[i])
        {
            if (H[i] <= H[to])
            {
                ok = false;
                break;
            }
        }

        if (ok)
        {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    VV<char> grid(n, V<char>(n));
    rep(i, n) rep(j, n) cin >> grid[i][j];
    int ans = 0;
    rep(i, n) {
        VV<char> now(n, V<char>(n));
        rep(j, n) rep(k, n) now[(i+j)%n][k] = grid[j][k];
        bool ok = true;
        rep(j, n) rep(k, n) if(now[j][k]!=now[k][j]) ok = false;
        if(ok) ans += n;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3784
#include "bits/stdc++.h"
using namespace std;

int main()
{
	int x;
	cin >> x;

	int kouka500;
	int kouka5;

	kouka500 = x / 500;
	kouka5 = (x % 500) / 5;

	int ans = 1000 * kouka500 + 5 * kouka5;

	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    int N;
    cin >> N;
    vector<long long> A(N);
    long long total = 0;

    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    for(int i = 1; i < N; i++){
        if(A.at(i-1) > A.at(i)){ // 前の人の方が大きい場合
            total += A.at(i-1) - A.at(i);
            A.at(i) = A.at(i-1);
        }
    }


    cout << total << endl;

}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repp(i, m, n) for (int i = m; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  vector<pair<int,int>> x(N);
  rep(i, N) cin >> x[i].first >> x[i].second;
  sort(all(x));
  
  map<pair<int,int>,int> map;
  
  rep(i, N) repp(j, i+1, N) {
    map[make_pair(x[i].first-x[j].first, x[i].second-x[j].second)]++;
  }
  
  int a = 0;
  for(auto p : map) a = max(a, p.second);
  cout << N - a << endl;

}

Measured memory_bytes: 384
string_lis = raw_input().split()

dic = {}
max_len = ''
for string in string_lis:
    if not string in dic:
        dic[string] = 1
    else:
        dic[string] = dic[string] + 1
    if len(max_len) == 0:
        max_len = string
    elif len(max_len) < len(string):
        max_len = string
        
max_count = sorted(dic.items(), key=lambda x: x[1], reverse=True)[0][0]

print max_count, max_len

Measured memory_bytes: 4220
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define M_PI 3.14159265358979323846
#define __LOCAL

#ifdef __LOCAL
#define DBG(X) cout << #X << " = " << (X) << endl;
#define SAY(X) cout << (X) << endl;
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int n,m,x;
vector<int> V,W;

int main()
{
    fast_io();
    string S,T;
    string ans;
    cin >> n ;
    cin >> S >> T;
    for(int i=0;i<n;i++){
        ans += S[i];
        ans += T[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, (int)vec.size() - 1)std::cout << vec[i] << " ";
	if(!vec.empty())std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int main() {
	int a,b;
	std::cin>>a>>b;
	if(8<std::max(a,b))puts(":(");
	else puts("Yay!");
	return 0;
}

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

int n,d1,d2,c;
int a[610][610];

void color(int d) {
	int w=0;
	while (d%4==0) d/=4,w++;
	if (d&1) {
		for (int i=0;i<2*n;i++)
			for (int j=0;j<2*n;j++)
				if ((((i>>w)&1)^((j>>w)&1)))
					a[i][j]=1;
	} else
	{
		for (int i=0;i<2*n;i++)
			for (int j=0;j<2*n;j++)
				if ((i>>w)&1)
					a[i][j]=1;
	}
}

int main() {
	scanf("%d%d%d",&n,&d1,&d2);
	color(d1); color(d2);
	for (int i=0;i<2*n;i++)
		for (int j=0;j<2*n;j++)
			if (c<n*n && !a[i][j])
				printf("%d %d\n",i,j),c++;
	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  
  cout << (char)(s1[0] - 32);
  cout << (char)(s2[0] - 32);
  cout << (char)(s3[0] - 32) << endl;
  
  return 0;
}

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

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


int main() {
    ll n, ans=1;
    cin >> n;

    rep(i, n ) {
        ll tmp;
        cin >> tmp;
        ans = lcm(ans, tmp);
    }

    cout << ans << endl;


    return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

const ll mod = 1e9+7;
//const ll mod = 998244353;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	rep(i, m)cin>>a[i];

	vector<ll> dp(n+9,0);
	dp[0] = 1;
	rep(i,m){
		dp[a[i]] = -1;
	}

	For(i,0,n){
		if(dp[i] == -1) continue;
		dp[i] %= mod;
		if(dp[i+1] != -1) dp[i+1] += dp[i];
		if(dp[i+2] != -1) dp[i+2] += dp[i];
	}
	cout << dp[n] % mod << endl;
}


Measured memory_bytes: 4236
// B - Multiplication2
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    int zero = 0;
    for(int i=0; i<n; i++) if(a[i] == 0) zero++;
    if(zero>0){ cout << 0 << endl; return 0; }

    long long prod = 1;
    for(int i=0; i<n; i++){
        if(a[i]<=1000000000000000000/prod)prod *= a[i];
        else{ cout << -1 << endl; return 0; }
    }
    cout << prod << endl;
    return 0;
}

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

using namespace std;

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

  map<int, int> mpd;
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    mpd[d]++;
  }

  int m;
  cin >> m;

  map<int, int> mpt;
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    mpt[t]++;
  }

  bool yes = true;
  for (auto i : mpt) {
    yes &= i.second <= mpd[i.first];
  }

  cout << (yes ? "YES" : "NO") << endl;

  return 0;
}

Measured memory_bytes: 18944
N = int(input())
M = {'R': [], 'L':[], 'U': [], 'D': [], 'X': [], 'Y': []}
for _ in range(N):
  x, y, d = input().split()
  if d in ['R', 'L']:
    M[d].append(int(x))
    M['Y'].append(int(y))
  else:
    M['X'].append(int(x))
    M[d].append(int(y))
for d in 'RLDUXY':
  M[d] = sorted(M[d])
T = [0] * 13
T[0] = M['X'][0] - M['R'][0] if M['X'] and M['R'] else -1
T[1] = M['L'][0] - M['X'][0] if M['X'] and M['L'] else -1
T[2] = (M['L'][0] - M['R'][0]) / 2 if M['L'] and M['R'] else -1
T[3] = M['X'][-1] - M['R'][-1] if M['X'] and M['R'] else -1
T[4] = M['L'][-1] - M['X'][-1] if M['X'] and M['L'] else -1
T[5] = (M['L'][-1] - M['R'][-1]) / 2 if M['L'] and M['R'] else -1
T[6] = M['Y'][-1] - M['U'][-1] if M['Y'] and M['U'] else -1
T[7] = M['D'][-1] - M['Y'][-1] if M['Y'] and M['D'] else -1
T[8] = (M['D'][-1] - M['U'][-1]) / 2 if M['D'] and M['U'] else -1
T[9] = M['Y'][0] - M['U'][0] if M['Y'] and M['U'] else -1
T[10] = M['D'][0] - M['Y'][0] if M['Y'] and M['D'] else -1
T[11] = (M['D'][0] - M['U'][0]) / 2 if M['D'] and M['U'] else -1
Rect = [-1] * 13
for i, t in enumerate(T):
  if t < 0:
    continue
  R = []
  L = []
  U = []
  D = []
  if M['R']:
    R.append(M['R'][-1] + t)
    L.append(M['R'][0] + t)
  if M['L']:
    R.append(M['L'][-1] - t)
    L.append(M['L'][0] - t)
  if M['U']:
    U.append(M['U'][-1] + t)
    D.append(M['U'][0] + t)
  if M['D']:
    U.append(M['D'][-1] - t)
    D.append(M['D'][0] - t)
  if M['X']:
    R.append(M['X'][-1])
    L.append(M['X'][0])
  if M['Y']:
    U.append(M['Y'][-1])
    D.append(M['Y'][0])
  Rect[i] = (max(R) - min(L)) * (max(U) - min(D))
print(min([r for r in Rect if r >= 0]))

Measured memory_bytes: 11884
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstdlib>

using namespace std;

//const int SP = 2100000000;
int n, m;
int l, r, d;
int a[100005];
int b[100005];
bool ans = true;
vector<int> vx[100005], wt[100005];

void dfs(int p, int q)
{
    if(b[p])
    {
        if(a[p] != q) printf("No"), exit(0);
        return;
    }
    b[p] = true;
    a[p] = q;
    for(int i = 0; i < vx[p].size(); i++)
    {
        dfs(vx[p][i], wt[p][i] + q);
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++)
    {
        scanf("%d%d%d", &l, &r, &d);
        vx[l].push_back(r);
        vx[r].push_back(l);
        wt[l].push_back(d);
        wt[r].push_back(-d);
    }
    for(int i = 1; i <= n; i++)
    {
        if(!b[i]) dfs(i, 0);
    }
    printf("Yes");
    return 0;
}


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

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> xv(n);
  vector<int> yv(m);
  int xmax = x;
  int ymin = y;
  rep(i, n) {
    cin >> xv[i];
    xmax = max(xmax, xv[i]);
  }
  rep(i, m) {
    cin >> yv[i];
    ymin = min(ymin, yv[i]);
  }
  
  if(xmax < ymin) cout << "No War" << endl;
  else cout << "War" << endl;
  return 0;
}
    

Measured memory_bytes: 3572
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int a,b;
	cin>>a>>b;
	if(a<=b)cout<<a<<endl;
	else cout<<a-1<<endl;
	
	
	return 0;
}


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

// 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 = 1000000007;
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, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
	int N, M;
	cin >> N >> M;
	vector<mint>Ans(N + 1); 
	vector<int>memo(N + 1);
	Ans[0] = 1;
	for (int m = 0; m < M; ++m) {
		int num;
		cin >> num;
		memo[num] = 1;
	}	
	for (int m = 1; m <= N; ++m) {
		if (1 == memo[m]) {
			continue;
		}
		if (m-1 >=0) {
			if (1 != memo[m - 1]) {
				Ans[m] += Ans[m - 1];
			}
		}
		if (m-2 >=0) {
			if (1 != memo[m-2]) {
				Ans[m] += Ans[m - 2];
			}
		}
	}
	cout << Ans[N]<<endl;
	return 0;
}

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

int main() { /* ここに書く */
  
  int A,B,C,D,F,S;
  cin >> A >> B >> C >> D ;
  
  F = C/B;
  if(C%B != 0){
    F++;}
  
  S = A/D;
  if(A%D != 0){
    S++;}
  
  if(F > S){
    cout << "No" << endl;}
  
  else{
    cout << "Yes" << endl;}
  
}

Measured memory_bytes: 3636
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int x;
    cin>>x;
    if(x>=30){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int const d=80*(80*2+1); //path from(0,0) to (h,w) 
int const d2=d*2;
int a[88][88];
bitset<d2>dp[88][88];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int h,w; cin >> h >> w;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin >> a[i][j];
		}
	}
	int x;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin >> x;
			a[i][j] = abs(x-a[i][j]);
		}
	}
	dp[0][0][d-a[0][0]]=1;
	dp[0][0][d+a[0][0]]=1;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(i){
				dp[i][j]|=dp[i-1][j]<<a[i][j]; 
				dp[i][j]|=dp[i-1][j]>>a[i][j];
			}
			if(j){
				dp[i][j]|=dp[i][j-1]<<a[i][j];
				dp[i][j]|=dp[i][j-1]>>a[i][j];
			}		
		}
	}
	int ans = d2;
	for(int k=0; k<d2; k++){
		if(dp[h-1][w-1][k]==1){
			ans = min(ans,abs(k-d));
		}
	}
	cout << ans << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 22656
import java.util.*;
import java.lang.Math;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	
      	int a = sc.nextInt();
      	int b = sc.nextInt();  
         
      	if(a == 1) a = 14;
      	if(b == 1) b = 14;
      
      	if(a == b) System.out.println("Draw");
      	else if(a > b) System.out.println("Alice");
      	else if(b > a) System.out.println("Bob");
        
	}
}


Measured memory_bytes: 35704
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int M;
    cin >> M;
    long long sum_=0;
    long long ans=0;
    for(int i=0; i<M; i++){
        long long d, c;
        cin >> d >> c;
        sum_+=d*c;
        ans+=c;
    }
    ans--;
    while(sum_>=10){
        ans+=sum_/10;
        sum_=sum_/10+sum_%10;
    }
    cout << ans << endl;
}

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

int main() {
	int n ;
	cin>>n;
	int arr[n];
	for(int i = 0 ; i < n ; ++i)cin>>arr[i];
	int res = 0 ;
	int m[n];
	int mn = arr[0];
	m[0] = arr[0];
	for(int i = 1 ; i < n ; ++i){
	if(arr[i] < mn)mn = arr[i];
	m[i] = mn;
	}
	for(int i = 0 ; i < n ; ++i)if(arr[i] == m[i])++res;
	cout<<res;
	return 0;
}

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

int n, m, h, k;
int amida[1001][1001];
bool bar[1001][1001];
bool though[1001][1001];
int a[100000], b[100000];
int main()
{
  while(cin >> n >> m >> h >> k && (n || m || h || k)){

    //chap1
    memset(bar, false, sizeof bar);
    memset(though, false, sizeof though);
    
    for(int i = 1; i <= n; i++)
      cin >> amida[h - 1][i];
    for(int i = 0; i < m; i++)
      cin >> a[i] >> b[i];
    for(int i = 0; i < m; i++)
      bar[b[i]][a[i]] = true;

    //chap2
    for(int i = 1; i <= k; i++)
      though[0][i] = true;
    
    for(int i = 0; i < h - 1; i++){
      for(int j = 1; j <= n; j++){
	if(though[i][j]){
	  if(bar[i + 1][j])
	    though[i + 1][j + 1] = true;
	  else if(bar[i + 1][j - 1])
	    though[i + 1][j - 1] = true;
	  else
	    though[i + 1][j] = true;
	}
      }
    }
    
    //chap3
    for(int i = h - 1; i > 0; i--){
      for(int j = 1; j <= n; j++){
	if(bar[i][j])
	  amida[i - 1][j] = amida[i][j + 1];	
	else if(bar[i][j - 1])
	  amida[i - 1][j] = amida[i][j - 1];	
	else
	  amida[i - 1][j] = amida[i][j];
      }
    }

    //chap4
    int def_sum = 0;
    for(int i = 1; i <= k; i++)
      def_sum += amida[0][i];
    int ans = def_sum;
    
    for(int i = 0; i < m; i++){
      if(though[b[i] - 1][a[i]] && !though[b[i] - 1][a[i] + 1])
	ans = min(ans, def_sum - amida[b[i] - 1][a[i]] + amida[b[i] - 1][a[i] + 1]);
      else if(!though[b[i] - 1][a[i]] && though[b[i] - 1][a[i] + 1])
	ans = min(ans, def_sum - amida[b[i] - 1][a[i] + 1] + amida[b[i] - 1][a[i]]);
    }

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

Measured memory_bytes: 7820
def main()

    # stdin = $stdin.readlines.map {|i| i.chomp().to_i }
    stdin =  gets.chomp.split(" ").map {|i| i.chomp().to_i }
    n = stdin[0]
    d = stdin[1]

    com = n/(d*2+1)
    if n%(d*2+1)==0
        print com
    else
        print com+1
    end


end
main()

Measured memory_bytes: 1788
#ABC128 C
N, M = (int(_) for _ in input().split())
A = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
    for j, S in enumerate(A):
        if P[j] ^ sum(i >> k-1 & 1 for k in S) & 1:
            break
    else:
        ans += 1
print(ans)

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

int main() {

  while(1){
  
  int n,x;
  
  cin >> n >> x ;

  if(x==0&&n==0) break;

  int ans=0;

  for (int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(i==j) continue;
      for (int k=1;k<=n;k++){
        if(k==j||k==i) continue;
        else if(i+j+k==x) ans++;
        
      }
    }
  }//三重全探索のうち、添え字が一つでも重複するものは除く
  
  cout << ans/6 << endl;//並べ方のバリエーションで3!=6だけダブりがある

  }
  
  return 0;
}


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

int main() {
    while (true) {
        int result=1000000;
        int n; cin >> n;
        if (n==0) break;
        vector<int> A(n);
        for (int i=0;i<n;i++) {
            cin >> A.at(i);
            if (i >= 1) {
                for (int j=0;j<i;j++) {
                    if (abs(A.at(i) - A.at(j)) < result) result = abs(A.at(i) - A.at(j));
                }
            }
        }
        cout << result << endl;
    }
}


Measured memory_bytes: 3100
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef double db;

db d, t, s;

int main() {
	cin >> d >> t >> s;
	
	if (d / s <= t) {
		cout << "Yes" <<endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3720
main :: IO ()
main = do
  [a,b,k] <- map read . words <$> getLine
  putStr . unlines . map show $ solve a b k

solve :: Int -> Int -> Int -> [Int]
solve a b k | 2*k >= b - a +2 = [a..b]
            | otherwise = [a..(a+k-1)] ++ [(b-k+1)..b]


Measured memory_bytes: 636
'''Yoshichiの日記
あみだくじ。
0本目からスタートし、W本の長さH + 1までにを任意の線を引いた時
K本目にたどり着くパターンは何パターンあるか答えよ。
現在の位置状態での線の引き方を全列挙し、DP(メモ化再帰)を用いて答える。
x → 現在の位置
y → 現在の進み具合
for分のi → 現在の位置にいる時の線の配置状態(1が隣接へつながっているとき)
for分のj → NGパターンの列挙(隣へ繋がっているかつ、
                   次の隣へも線が引かれている状態)
'''
from collections import defaultdict
h, w, k = map(int, input().split())
memo = defaultdict(lambda:defaultdict(int))
def dfs(x, y):
    if y == h:
        if x == k - 1:
            return 1
        else:
            return 0
    if y in memo[x]:
        return memo[x][y]
    ans = 0
    for i in range(1 << w - 1):
        flg = True
        for j in range(w - 2):
            if i & (1 << j) and i & (1 << j + 1):
                flg = False
                break
        if flg:
            nx = x
            if x > 0 and i & (1 << x - 1):
                nx = x - 1
            elif i & (1 << x):
                nx = x + 1
            ans += dfs(nx, y + 1)
            ans %= 1000000000 + 7
    memo[x][y] = ans
    return ans
print(dfs(0, 0))

Measured memory_bytes: 3436
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    string s;
    cin>>s;

    bool ok=true;

    int n=s.size();

    if(s[0]=='0') ok=false;
    if(s[n-1]=='1')  ok=false;
    REP(i,n-1){
        if(s[i]!=s[n-2-i]) ok=false;
    }

    if(ok){
        queue<int> que;
        vector<pair<int,int>> ans;
        bool cur_ok=true;
        int bv=0;
        s[n-1]='1';
        REP2(i,1,n){
            if(s[i]=='1'){
                ans.push_back(make_pair(bv+1,i+1));
                bv=i;
            }
        }

        REP2(i,1,n){
            if(s[i]=='0'&&i!=n-1){
                que.push(i);
            }else{
                while(!que.empty()){
                    int v=que.front();
                    que.pop();
                    ans.push_back(make_pair(v+1,i+1));
                }
            }
        }
        REP(i,ans.size()){
            cout<<ans[i].first<<" "<<ans[i].second<<endl;
        }
    }else{
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 4748
#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
namespace rng {
    using namespace boost;
    using namespace boost::range;
    using namespace boost::adaptors;
}

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
constexpr auto color_s_ = "\033[2m\033[33m", color_e_ = "\033[0m";
template<class T> void trace_(const T& v) { cerr << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cerr << "\n"; for (const auto& v : m) { trace_(v); cerr << "\n"; } }
template<class T> void trace_(const char* s, const T& v) { cerr << color_s_ << s << "="; trace_(v); cerr << color_e_ << "\n"; cerr.flush(); }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { cerr << color_s_; for (; *s != ','; ++s) { cerr << *s; } cerr << "="; trace_(v); cerr << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i : irange(1, n)) {
        int an;
        cin >> an;
        an--;
        a[an]++;
    }
    for (int an : a) {
        cout << an << nl;
    }
}


Measured memory_bytes: 3972
import sys


def input():
    return sys.stdin.readline()[:-1]


def comb(n, k):
    nCk = 1
    MOD = 10**9+7

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1, k+1):
        nCk *= pow(i, MOD-2, MOD)
        nCk %= MOD
    return nCk


def main():
    mod = 10**9+7
    N, a, b = map(int, input().split())
    ans = pow(2, N, mod)-1 - comb(N, a) - comb(N, b)
    print(ans % mod)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
{-# LANGUAGE BangPatterns #-}

import Data.Bits
import Data.List
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Data.Coerce

newtype BitFlag = BF Int

initFlag :: BitFlag
initFlag = BF (bit 3 .|. bit 5 .|. bit 7)

{-# INLINE lenFlag #-}
lenFlag :: BitFlag -> Int
lenFlag = coerce (popCount :: Int -> Int)

{-# INLINE testFlag #-}
testFlag :: Int -> BitFlag -> Bool
testFlag = coerce (flip testBit :: Int -> Int -> Bool)

{-# INLINE killFlag #-}
killFlag :: Int -> BitFlag -> BitFlag
killFlag = coerce (flip clearBit :: Int -> Int -> Int)
  
gen :: Int -> BitFlag -> Int -> Int -> (Int,Bool)
gen 0 _ till acc
  | acc <= till = (1,True)
  | otherwise   = (0,False)
gen n !xs till !acc = foldr count out [3,5..7] 0
  where
    count | lenFlag xs < n
            = \ !k cont !left ->
                let (!now, hasMore)
                      = gen (n-1) (killFlag k xs) till (10*acc + k) 
                in if hasMore then
                     cont (left + now)
                   else
                     (left + now, False)
          | otherwise
            = \ !k cont !left ->
              if not (testFlag k xs) then
                cont left
              else let (!now,hasMore)
                         = gen (n-1) (killFlag k xs) till (10*acc + k)
                   in if hasMore then
                        cont (left + now)
                      else
                        (left + now, False)
    out !left = (left, True)
  
cNum :: Int -> Int
cNum !till = foldr count out [3,4..9] 0
  where
    count !n cont !left = if hasMore then
                            cont (left + now)
                          else
                            left + now
      where
        (!now, hasMore) = gen n initFlag till 0
    out = id

main :: IO ()
main = getLine >>= print . cNum . read 


Measured memory_bytes: 892
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            switch(s)
            {
                case "Sunny":
                    Console.WriteLine("Cloudy");
                    break;


                case "Cloudy":
                    Console.WriteLine("Rainy");
                    break;

                case "Rainy":
                    Console.WriteLine("Sunny");
                    break;
            }
        }
    }
}



Measured memory_bytes: 11092
import static java.util.Arrays.deepToString;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	int[] num2idx;
	V[] vs;
	
	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			int n = sc.nextInt();
			if (n == 0) break;
			num2idx = new int[1001];
			vs = new V[n];
			for (int i = 0; i < n; i++) {
				V v = new V();
				v.num = sc.nextInt();
				v.x = sc.nextInt();
				v.y = sc.nextInt();
				vs[i] = v;
				num2idx[v.num] = i;
			}
			
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					int d2 = dist2(vs[i].x, vs[i].y, vs[j].x, vs[j].y);
					if (d2 <= 50 * 50) {
						double dd = Math.sqrt(d2);
						vs[i].add(new E(vs[j], dd));
						vs[j].add(new E(vs[i], dd));
					}
				}
			}
			
			int m = sc.nextInt();
			for (int mi = 0; mi < m; mi++) {
				int s = num2idx[sc.nextInt()];
				int g = num2idx[sc.nextInt()];
				List<V> res = dijk(vs[s], vs[g]);
				if (res == null) 
					System.out.println("NA");
				else {
					System.out.print(res.get(0).num);
					for (int i = 1; i < res.size(); i++)
						System.out.print(" " + res.get(i).num);
					System.out.println();
				}
			}
		}
	}

	List<V> dijk(V s, V t) {
		for (V v : vs) v.dist = 1001001001;
		t.prev = null;
		s.prev = s;
		s.dist = 0;
		PriorityQueue<E> pq = new PriorityQueue<E>();
		pq.add(new E(s, 0));
		while (!pq.isEmpty()) {
			V cur = pq.poll().to;
			if (cur == t) break;
			for (E e : cur) {
				if (e.to.dist > e.dist + cur.dist) {
					e.to.dist = e.dist + cur.dist;
					e.to.prev = cur;
					pq.add(new E(e.to, e.to.dist));
				}
			}
		}
		
		if (t.prev == null) return null;
		List<V> route = new ArrayList<V>();
		V b = t;
		while (b.prev != b) {
			route.add(b);
			b = b.prev;
		}
		route.add(b);
		Collections.reverse(route);
		return route;
	}
	
	int dist2(int x1, int y1, int x2, int y2) {
		int dx = x1 - x2;
		int dy = y1 - y2;
		return dx * dx + dy * dy;
	}
	
	class V extends ArrayList<E> {
		int num;
		int x, y;
		double dist;
		V prev;
	}
	class E implements Comparable<E> {
		V to;
		double dist;
		E(V to, double dist) {
			this.to = to;
			this.dist = dist;
		}
		@Override
		public int compareTo(E o) {
			double c = dist - o.dist;
			if (c < 0) return -1;
			if (c > 0) return 1;
			return 0;
		}
	}
}

Measured memory_bytes: 20816
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
const ll INF = 1e15;
const ld eps = 1e-6;
int main() {
	ll N, M;
	cin >> N >> M;
	vector<vector<ll>> es(N);
	vector<ll> dim(N);
	for (int i = 0;i < M;i++) {
		ll x, y;
		cin >> x >> y;
		x--; y--;
		dim[y]++;
		es[x].push_back(y);
	}
	queue<ll> ok;
	for (int i = 0;i < N;i++) {
		if (dim[i] == 0)
			ok.push(i);
	}
	ll ans = 0;
	vector<ll> dist(N, 0);
	while (!ok.empty()) {
		ll now = ok.front();
		ok.pop();
		for (int i = 0;i < es[now].size();i++) {
			dist[es[now][i]] = max(dist[es[now][i]], dist[now] + 1);
			ans = max(dist[es[now][i]], ans);
			dim[es[now][i]]--;
			if (dim[es[now][i]] == 0)
				ok.push(es[now][i]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7296
a1,b1 = map(int,input().split())
a2,b2 = map(int,input().split())
a3,b3 = map(int,input().split())
a4,b4 = map(int,input().split())
a5,b5 = map(int,input().split())
a6,b6 = map(int,input().split())
a7,b7 = map(int,input().split())


print(a1 - b1)
print(a2 - b2)
print(a3 - b3)
print(a4 - b4)
print(a5 - b5)
print(a6 - b6)
print(a7 - b7)


Measured memory_bytes: 5592
import itertools
N = input()
t = map(int,input().split())
cnt = 0
list = itertools.combinations(t,3)
for i in list:
    if i[0]+i[1]>i[2] and i[1]+i[2]>i[0] and i[2]+i[0]>i[1] and i[0]!=i[1] and i[1]!=i[2] and i[2]!=i[0]:
        cnt += 1
     

print(cnt)

Measured memory_bytes: 9140
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-3;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int n; ll a[3000];
bool chked[3000][3000];
ll ans[3000][3000];
ll dfs(int le, int ri) {
	if (ri < le)return 0;
	if (chked[le][ri])return ans[le][ri];
	chked[le][ri] = true;
	ll res = 0;
	int id = (n - (ri-le+1)) % 2;
	if (id == 0) {
		ll sle = a[le] + dfs(le + 1, ri);
		ll sri = a[ri] + dfs(le, ri - 1);
		res = max(sle, sri);
	}
	if (id == 1) {
		ll sle = -a[le] + dfs(le + 1, ri);
		ll sri = -a[ri] + dfs(le, ri - 1);
		res = min(sle, sri);
	}
	return ans[le][ri] = res;
}
int main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	cout << dfs(0, n - 1) << endl;
	//stop
	return 0;
}

Measured memory_bytes: 79616
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
bool OK[MAXN];
int cnt[MAXN];

int main() {
    int N, M;
    cin >> N >> M;
    int ans = 0, pen = 0;
    for (int i = 0; i < M; i++) {
        int num;
        string s;
        cin >> num >> s;
        if (OK[num]) continue;
        if (s == "WA") {
            cnt[num]++;
        } else {
            ans++;
            pen += cnt[num];
            OK[num] = 1;
        }
    }
    printf("%d %d\n", ans, pen);
    return 0;
}


Measured memory_bytes: 768
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    H, N = Scanner.map_int()
    A, B = [0] * N, [0] * N
    for i in range(N):
        A[i], B[i] = Scanner.map_int()
    INF = 10 ** 10
    dp = [INF for _ in range(H + 1)]
    dp[0] = 0
    for i in range(H + 1):
        for j in range(N):
            k = max(0, i - A[j])
            dp[i] = min(dp[i], dp[k] + B[j])
    print(dp[H])


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


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

int main() {
    int n, l, sum, minTaste;

    cin >> n >> l;

    sum = 0;
    minTaste = l;

    for (int i = 0; i < n; i++) {
        sum += l+i;
        if (abs(minTaste) > abs(l+i)) {
            minTaste = l+i;
        }
    }

    cout << sum - minTaste << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int n,d,x;cin>>n>>d>>x;
    ll ans =x;
    rep(i,n){
        int tmp;cin>>tmp;
        ans = ans +(d-1)/tmp+1;
    }
    co(ans);
}

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

using namespace std;

typedef long long ll;

int n;
ll arr[100100];
ll res, mini = 0;

int main() {
	int i;

	scanf("%d",&n);
	for (i=0;i<n;i++) scanf("%lld",&arr[i]);
	for (i=0;i<n;i++) {
		res += (arr[i]-1)/(mini+1);
		if ((arr[i]-1)/(mini+1)>0) arr[i] = 1;
		mini = max(mini,arr[i]);
	}
	printf("%lld\n",res);

    return 0;
}


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

using namespace std;

#define sz 200005
#define ll long long
ll arr[sz];
ll freq[sz];

int main()
{
	int N;
	cin>>N;
	memset(freq, 0, sizeof(freq));
	for(int i=0; i<N; i++){
		cin>>arr[i];
		freq[arr[i]] ++;
	}

	ll answer=0;
	for(int j=0; j<sz; j++){
		answer += freq[j] * (freq[j] - 1) / 2;
	}

	for(int k=0; k<N; k++){
		// cout<<freq[arr[k]]<<" ";
		// if(freq[arr[k]] <= 1){
		// 	cout<<answer<<"\n";
		// 	continue;
		// }
		ll this_ch = freq[arr[k]] * (freq[arr[k]] - 1) / 2;
		ll n_ch = (freq[arr[k]] - 1) * (freq[arr[k]] - 2) / 2;
		// cout << "this_ch " << this_ch << " n_ch " << n_ch << " ";
		cout<<answer - this_ch + n_ch<<"\n";
	}
	return 0;
}


Measured memory_bytes: 5760
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var graph, bitor;

var myOut = main();
if(myOut !== undefined)console.log(myOut);
function main(){
  var n = o.a();
  var a = [], b = [];
  graph = xArray("[]",n);
  bitor = xArray(0,n-1);
  for(var i = 0; i < n-1; i++){
    var s = o.a()-1, t = o.a()-1;
    a[i] = Math.min(s,t), b[i] = Math.max(s,t);
    graph[s].push(t);
    graph[t].push(s);
  }
  var m = o.a();
  for(var i = 0; i < m; i++){
    var u = o.a()-1, v = o.a()-1;
    var bit = 1 << i;
    var vv = dfs(u,v,-1,[]);
    for(var j = 1; j < vv.length; j++){
      var p = Math.min(vv[j-1],vv[j]), q = vv[j-1]+vv[j]-p;
      for(var k = 0;;k++){
        if(a[k] === p && b[k] === q){
          bitor[k] |= bit;
          break;
        }
      }
    }
  }
  var mb = 1<<m;
  var dp = xArray(0,mb);
  dp[0] = 1;
  for(var j = 0; j < n-1; j++){
    if(bitor[j] === 0){
      for(var i = 0; i < mb; i++)dp[i] *= 2;
    }else{
      for(var i = mb; i--;){
        if((i|bitor[j]) === i)dp[i] *= 2;
        else dp[i|bitor[j]] += dp[i];
      }
    }
  }
  return dp[mb-1];
}

function dfs(s,g,p,V){
  V.push(s);
  if(g === s)return V;
  for(var v of graph[s]){
    if(v === p)continue;
    var q = dfs(v,g,s,V);
    if(q)return q;
  }
  V.pop();
}

Measured memory_bytes: 126720
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n-1):
 m=a.index(min(a[i:]),i)
 if a[i]>a[m]:
  a[i],a[m]=a[m],a[i];c+=1
print(*a)
print(c)


Measured memory_bytes: 5612