akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int c[3][3]; rep(i,3) rep(j,3) cin >> c[i][j];

  string result = "Yes";
  if (c[0][0]-c[1][0]!=c[0][1]-c[1][1]) result = "No";
  if (c[0][0]-c[1][0]!=c[0][2]-c[1][2]) result = "No";
  if (c[1][0]-c[2][0]!=c[1][1]-c[2][1]) result = "No";
  if (c[1][0]-c[2][0]!=c[1][2]-c[2][2]) result = "No";

  if (c[0][0]-c[0][1]!=c[1][0]-c[1][1]) result = "No";
  if (c[0][0]-c[0][1]!=c[2][0]-c[2][1]) result = "No";
  if (c[0][1]-c[0][2]!=c[1][1]-c[1][2]) result = "No";
  if (c[0][1]-c[0][2]!=c[2][1]-c[2][2]) result = "No";

  cout << result << endl;
  return 0;
}

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

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e19);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class COneQuadrillionAndOneDalmatians {
public:
  static void solve(istream &cin, ostream &cout) {
    int N;
    cin >> N;
    int digit;
    rep(i, 100) {
      if (i != 0) N -= bpm(26, i);
      if (bpm(26, i + 1) + 1 > N) {
        digit = i + 1;
        break;
      }
    }
    string temp = "abcdefghijklmnopqrstuvwxyz";
    string ans{};
    for (int i = digit; i >= 1; i--) {
      rep(j, 26) {
        if (N >= bpm(26, i - 1) * j + 1 and N < bpm(26, i - 1) * (j + 1) + 1) {
          ans += temp[j];
          N -= bpm(26, i - 1) * j;
          break;
        }
      }
    }
    cout << ans << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  COneQuadrillionAndOneDalmatians solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	double ms, ml;
	double m;
	double y;
	
	ml = 0;
	ms = 0;
	
	while (scanf("%lf", &m) != EOF){
		
		if (m > ml){
			ml = m;
		}
		
		if ((ms > m) || ms == 0){
			ms = m;
		}
	}
	
	y = ml * 1.0 - ms * 1.0;
	
	printf("%f\n", y);
	
	return (0);
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    vector<vector<int>> data(3,vector<int>(3));
    int a;
    for (int i=0; i<3; i++){
        for (int j=0; j<3; j++){
            cin>>a;
            data[i][j]=a;
        }
    }
    int n, b;
    cin>>n;
    for (int i=0; i<n; i++){
        cin>>b;
        for (int i=0; i<3; i++){
            for (int j=0; j<3; j++){
                if (data[i][j]==b){
                    data[i][j]=0;
                }
            }
        }
    }
    int count=0;
    for (int i=0; i<3; i++){
        if (data[i][0]==0 and data[i][1]==0 and data[i][2]==0){
            count+=1;
        }
        else if (data[0][i]==0 and data[1][i]==0 and data[2][i]==0){
            count+=1;
        }
    }
    if (data[0][0]==0 and data[1][1]==0 and data[2][2]==0){
            count+=1;
    }
    if (data[2][0]==0 and data[1][1]==0 and data[0][2]==0){
            count+=1;
    }
    if (count>=1){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, x;
  cin >> n >> x;

  ll pre;
  ll cre = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    if (i > 0) {
      ll b = a + pre;
      ll del = max(0LL, b - x);
      cre += del;
      a = max(0LL, a - del);
    }
    pre = a;
    //cout << a << endl;
  }

  cout << cre << endl;

  return 0;
}


Measured memory_bytes: 3644
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, x = map(int, input().split())
num_count = int(input())
number_list = [0] * num_count
for i in range(num_count):
    number_list[i] = int(input())

bingo_map = [[a, b, c], [d, e, f], [g, h, x]]
bingo_answer = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

def bingo(bingo_map, number_list):
    for number in number_list:
        for i, bingo_row in enumerate(bingo_map):
            if number in bingo_row:
                for j, bingo_number in enumerate(bingo_row):
                    if bingo_number == number:
                        bingo_answer[i][j] = 1


def check_bingo():
    return (all(bingo_answer[0]) or all(bingo_answer[1]) or all(bingo_answer[2]) or
    all([bingo_answer[0][0], bingo_answer[1][0], bingo_answer[2][0]]) or
    all([bingo_answer[0][1], bingo_answer[1][1], bingo_answer[2][1]]) or
    all([bingo_answer[0][2], bingo_answer[1][2], bingo_answer[2][2]]) or
    all([bingo_answer[0][0], bingo_answer[1][1], bingo_answer[2][2]]) or
    all([bingo_answer[2][0], bingo_answer[1][1], bingo_answer[0][2]]))

bingo(bingo_map, number_list)

if (check_bingo()):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#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 <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
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 < (n); i++)

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

Measured memory_bytes: 3604
#include<iostream>
using namespace std;
int main(){
    string s;
    int i;
    cin >> s;
    int count = 700;
    for (i = 0; i < 3;i++){
        if(s[i]=='o'){
            count=count+100;
            }
    }        
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

constexpr int MOD = 998244353;
struct mint
{
	int v;
	mint():v(0){}
	mint(int v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); 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 operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(int k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(int n, int k) {
		if(n-k<k) k=n-k;
		mint num(1), dom(1);
		for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; }
		return num/dom;
	}
};
std::istream& operator>>(std::istream&i,mint&a){ int t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


signed main() {
	int n;
	std::cin >> n;
	mint ans = mint(3).pow(n);
	mint com = 1;
	for(int i=0;i<n/2;i++) {
		mint x = com;
		com*=n-i;
		com/=i+1;
		x*=mint(2).pow(i);
		ans-=mint(2)*x;
	}
	print(ans);

	return 0;
}


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

using namespace std;

typedef long long ll;

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

	double pi = 3.1415926535;
	double r;
	cin >> r;

	cout << fixed << setprecision(10);
	cout << 2.0 * pi * r << endl;

}


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

int main() {
  int n;
  cin >> n;
  vector<char> s(n);
  for(int i=0;i<n;i++){
   cin >> s.at(i);
  }
  
  int k;
  cin >> k;
  for(int i=0;i<n;i++){
   if(s.at(i)!=s.at(k-1)){
    s.at(i)='*'; 
   }
    cout << s.at(i);
  }
  
  
}

Measured memory_bytes: 256
// #define __LOCAL_DEBUG__
#include<bits/stdc++.h>
using namespace std;
#ifdef __LOCAL_DEBUG__
# define _debug(x) { cerr << "\033[94m" << __func__ << " " << #x << ": " << (x) << "\n\033[0m"; }
#else
# define _debug(...) {((void) 0);}
#endif
#define REP(i, n) for (int i = (0); i < (n); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define EACH(x, arr) for (auto& x : arr) 
#define ITR(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define CLR(x, v) memset(x, v, sizeof (x))
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
using LL = long long;
using PII = pair<int, int>;
using VI = vector<int>;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 5005;

int n, m;
void MAIN() {
    int a, b;
    cin >> a >> b;
    if (b % a == 0) cout << (a + b) << endl;
    else cout <<  b - a << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int TC = 1;
    // cin >> TC;
    REP(tc, TC) {
        // cout << "Case " << tc + 1 << ": ";
        MAIN();
    }
    return 0;
}


Measured memory_bytes: 256
list_a=[]
list_b=[]
list_c=[]
N=int(input())
for i in range(N):
   a,b,c=map(int,input().split())
   list_a.append(a)
   list_b.append(b)
   list_c.append(c)

for i in range(N):
   list_a[i],list_b[i],list_c[i]=sorted([list_a[i],list_b[i],list_c[i]])
   x=list_a[i]
   y=list_b[i]
   z=list_c[i]
   if x**2+y**2==z**2:
      print("YES")
   else:
      print("NO")




Measured memory_bytes: 5712
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
void fastios() { ios_base::sync_with_stdio(0); cin.tie(0); }

static const int N = 10005;

struct vertex {
	int id;
	int d;
	bool operator<(const vertex & another) const {
		return (d != another.d ? d>another.d : id>another.id);
	}
};

struct edge {
	int end;
	int w;
};

int main() {
	fastios();
	int n;
	cin >> n;
	vector<vector<edge>> E(N);
	Loop(i, n) {
		int u, k;
		cin >> u >> k;
		Loop(i, k) {
			int v, c;
			cin >> v >> c;
			E[u].push_back({ v,c });
		}
	}

	priority_queue<vertex> pq;
	vi color(N, 0), dist(N, 0);
	pq.push({ 0,0 });
	int cnt = 0;
	while (pq.size() > 0) {
		if (cnt == n) break;
		vertex v = pq.top();
		pq.pop();
		if (color[v.id] == 1) continue;
		dist[v.id] = v.d;
		color[v.id] = 1;
		cnt++;
		Loop(j, E[v.id].size()) {
			pq.push({ E[v.id][j].end, dist[v.id] + E[v.id][j].w });
		}
	}
	Loop(i, n) {
		cout << i << " " << dist[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 12044
//DFSテンプレート
fun main(args: Array<String>) {
    var (N, U, V) = listOfInt()
    U -= 1; V -= 1
    val G = Array<MutableList<Int>>(N) { mutableListOf<Int>() }
    repeat(N - 1) {
        val (a, b) = listOfInt(-1)
        G[a].add(b)
        G[b].add(a)
    }
    var dist = Array<Int>(N) { 0 }
    tailrec fun dfs(v: Int, d: Int = 0, p: Int = -1) {
        dist[v] = d
        for (u in G[v]) {
            if (u == p) continue
            dfs(u, d + 1, v)
        }
    }
    fun calcDist(s: Int): Array<Int> {
        dist = Array<Int>(N) { 0 }
        dfs(s)
        return dist
    }
    val distU = calcDist(U)
    val distV = calcDist(V)

    var max = 0
    repeat(N) {
        if (distU[it] < distV[it]) {
            max = Math.max(max, distV[it])
        }
    }
    val ans = max - 1
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }

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

int main() {
  int K;
  cin >> K;
  int sum = 0;
  for(int a = 1; a <= K; a++){
    for(int b = 1; b <= K; b++){
      for(int c = 1; c <= K; c++){
        sum += __gcd(a,__gcd(b,c));
      }
    }
  }
  cout << sum << endl;
}


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

int main() {
  int N; cin >> N;
  int a = N % 10;
  if (a==2||a==4||a==5||a==7||a==9) cout << "hon" << endl;
  else if (a!=3) cout << "pon" << endl;
  else cout << "bon" << endl;
}

Measured memory_bytes: 3644
inf = 10 ** 20


def solve(n, m, weights):
    score = [-inf] * n
    score[0] = 0
    pred = [-1] * n

    for step in range(n):
        for edge, c in weights.items():
            a, b = edge
            if score[b] < score[a] + c:
                score[b] = score[a] + c
                pred[b] = a

    b = n - 1
    while b != 0:
        a = pred[b]
        c = weights[(a, b)]
        if score[b] < score[a] + c:
            return 'inf'
        b = a
    return score[n-1]


def solve2(n, m, weights):
    score = [-inf] * n
    score[0] = 0
    pred = [-1] * n

    for step in range(n):
        for edge, c in weights.items():
            a, b = edge
            if score[b] < score[a] + c:
                score[b] = score[a] + c
                pred[b] = a

    res = score[n-1]

    for step in range(n):
        for edge, c in weights.items():
            a, b = edge
            if score[b] < score[a] + c:
                score[b] = score[a] + c
                pred[b] = a

    if res < score[n-1]:
        return 'inf'
    return res


def main():
    n, m = map(int, input().split())
    weights = {}
    for _ in range(m):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        weights[(a, b)] = c

    res = solve2(n, m, weights)
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define for(i,a,b) for(int i=a;i<b;i++)
#define sort(a,b) sort(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
 
int main() {
  string a;
  ci(a);
  if(a[0]>=a[1]&&a[0]>=a[2])
    co((a[0]-'0')*100+(a[0]-'0')*10+(a[0]-'0'));
  else
    co(((a[0]-'0')+1)*100+((a[0]-'0')+1)*10+(a[0]-'0')+1);
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var a int
	fmt.Scan(&a)
	li := make([]int, a)
	for i:=0; i<a; i++ {
		fmt.Scan(&li[i])
	}
	ans :=0
	for i:=0; i<a-1; i++ {
		for j:=i+1; j<a; j++ {
			ans += li[i]*li[j]
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>


using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main()
{
   ll n;
   cin >> n;
   vector<ll> a(n-1);
   for(int i = 0;i < n-1;i++)
   {
     cin >> a[i];
   }
   vector<ll> ans(n);
   for(int i = 0;i < n;i++)
   {
     ans[i] = 0;
   }
   for(int i = 0;i < n-1;i++)
   {
     ans[a[i]-1]++;
   }
   for(int i = 0;i < n;i++)
   {
     cout << ans[i] << endl;
   }
}


Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define INF 100000000
int main(){
    ll N,A,B;
    cin>>N>>A>>B;
    if(B>N*A)cout<<N*A<<endl;
    else cout<<B<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=4000000000000000000;
ll MOD=1000000007;


int main() {
   ll l,r;
   ll mod=2019;
   cin >> l >> r;
   ll ans=2019;
   if (r-l>2019) {cout << 0 << endl;return 0;}
   for (ll i=0;l+i<=r;i++){
       for (ll j=i+1;l+j<=r;j++){
           ans=min(ans,(((l+i)%mod)*((l+j)%mod))%mod);
       }
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
W = [input() for _ in range(N)]
flag = True
b = W[0][-1]
for i in range(1,N): 
  if b == W[i][0]:
    b = W[i][-1]
  else:
    flag = False
    break
    
if int(len(W))!=len(set(W)):
  flag = False

if flag == True:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;
using int64 = long long;
#define ForInt(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define ForIntInit(i, begin, end) for (int i = (begin); i < (end); ++i)
#define ForItr(it, itBegin, itEnd) for (auto (it) = (itBegin); (it) != (itEnd); ++(it))


int main()
{
	string s;
	cin >> s;
	int n = s.length();
	vector<tuple<int, int, int, int>> block;
	int i = 0;
	while (i < n)
	{
		int sr = i;
		for (; s[i] == 'R'; ++i)
		{
		}
		int er = i - 1;
		int sl = i;
		for (; s[i] == 'L' && i < n; ++i)
		{
		}
		int el = i - 1;
		block.emplace_back(sr, er, sl, el);
	}

	int j = 0;
	ForItr(it, block.begin(), block.end())
	{
		int sr = get<0>(*it);
		int er = get<1>(*it);
		int sl = get<2>(*it);
		int el = get<3>(*it);

		int rr = (sl - sr + 1) / 2;
		int rl = sl - sr - rr;
		int ll = (el - er + 1) / 2;
		int lr = el - er - ll;

		for (; j < er; ++j)
		{
			cout << (j ? " " : "") << 0;
		}
		cout << (j ? " " : "") << (rr + lr);
		++j;
		cout << " " << (ll + rl);
		++j;
		for (; j <= el; ++j)
		{
			cout << " " << 0;
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

int c[1010][1010];
int D;




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

  ll ans = 0;
  REP(i, 60){
    ll one = 0, zero = 0;
    REP(j, n){
      if(a[j] >> i & 1) one++;
      else zero++;
    }
    ll tmp =((ll)1 << i) % MOD;
    ll d = one * zero % MOD;
    tmp = tmp * d % MOD;
    ans = (ans + tmp) % MOD;
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main(){
    int ans, i, j, N, K, l;
    string S, T;
    char k;

    cin >> N >> S >> K;

    ans = 0;
    k = S[K-1];
    l = S.length();

    for (i=0; i<l; i++){
        if (S[i] != k) S[i] = '*';
    }

    cout << S << '\n';
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define MOD 1000000007
inline void Add(int &x,int y){
    x=(x+y>=MOD)?(x+y-MOD):(x+y);
}

#define MAXN 50
#define MAXM (2*MAXN-1)
int N,M;
int A[MAXM+5],dp[MAXN+5][MAXM+5][MAXM+5];

int main(){
    scanf("%d",&N),M=2*N-1;
    for(int i=1;i<=M;i++)
        scanf("%d",A+i);
    sort(A+1,A+M+1);
    dp[N][0][0]=1;
    for(int i=N;i>=1;i--){
        int L=A[i]!=A[i-1],R=A[M-i+1]!=A[M-i+2];
        for(int j=0;j<=M;j++){
            for(int k=0;k<=M;k++){
                if(!dp[i][j][k])
                    continue;
                Add(dp[i-1][j+L][k+R],dp[i][j][k]);
                for(int p=0;p<j+L;p++)
                    Add(dp[i-1][p][k+R+1],dp[i][j][k]);
                for(int p=0;p<k+R;p++)
                    Add(dp[i-1][j+L+1][p],dp[i][j][k]);
            }
        }
    }
    int Ans=0;
    for(int i=0;i<=M;i++)
        for(int j=0;j<=M;j++)
            Add(Ans,dp[1][i][j]);
    printf("%d\n",Ans);
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n, v) rep(i, n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1, 0, -1, 0}, y_pos[4] = {0, 1, 0, -1};
int ctoi(char c)
{
	if (c >= '0' && c <= '9')
	{
		return c - '0';
	}
	return 0;
}

char upper(char c)
{
	return c - 0x20;
}

char lower(char c)
{
	return c + 0x20;
}

void unique_vector(vector<int> &v)
{
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
	std::fill((T *)array, (T *)(array + N), val);
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y)
{
	if (y == 0)
		return x;
	return gcd(y, x % y);
}

//最小公倍数
ll lcm(ll x, ll y)
{
	ll g = gcd(x, y);
	return x / g * y;
}

ll myPow(ll x, ll n, ll m)
{
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

//素因数分解
map<ll, ll> prime_factor(ll n)
{
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++)
	{
		while (n % i == 0)
		{
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1)
		ret[n] = 1;
	return ret;
}

int main()
{
	int k;
	cin >> k;
	int total = 9;
	int numValue[100][11];
	if(k < 10){
		cout << k << endl;
		return 0;
	}
	rep(i,100){
		rep(k,11){
			numValue[i][k] = 0;
		}
	}
	rep(i,10){
		numValue[0][i] = 1;
	}
	int count = 1;
	while (true)
	{
		bool Con = true;
		rep(i, 10)
		{
			if (i == 0)
			{
				numValue[count][0] = numValue[count - 1][0] + numValue[count - 1][1];
				continue;
			}
			else if (i < 9)
			{
				numValue[count][i] = numValue[count - 1][i - 1] + numValue[count - 1][i] + numValue[count - 1][i + 1];
			}
			else
			{
				numValue[count][9] = numValue[count - 1][9] + numValue[count - 1][8];
			}
			total += numValue[count][i];
			if(total >= k){
				Con = false;
				string s = to_string(i);
				int hit = i;
				for (int p = count - 1; p >= 0; p--)
				{
					rep(l, 3){
						if (total - numValue[p][hit + 1 - l] < k)
						{
							hit += 1 - l;
							s += to_string(hit);
							break;
						}
						else
						{
							total -= numValue[p][hit + 1 - l];
						}
					}
				}
				cout << s << endl;
				break;
			}
		}
		count++;
		if (!Con)
		{
			break;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;

struct job_t
{
    int64_t duration;
    int64_t limit;
};

int main()
{
    size_t n;
    cin >> n;
    vector<job_t> jobs(n);
    for(auto& j : jobs)
    {
        cin >> j.duration >> j.limit;
    }
    
    sort(begin(jobs), end(jobs), [](auto& x, auto& y){ return x.limit < y.limit; });
    
    int64_t sd = 0;
    for(const auto& j : jobs)
    {
        sd += j.duration;
        if(j.limit < sd)
        {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = Read().Int();
            var l = new int[n];
            var r = ReadSplit();
            for (int i = 0; i < n; i++)
            {
                l[i] = r[i].Int();
            }

            long x = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                if (i % 2 == 0)
                {
                    x += l[i];
                }
                else
                {
                    x -= l[i];
                }
            }
            x /= 2;

            var ans = new long[n];
            
            var startLeft = x;
            var right = x;
            ans[0] = x * 2;
            for (int j = 0; j < n; j++)
            {
                if (j == n - 1)
                {
                    break;
                }
                else
                {
                    var left = l[j] - right;
                    right = left;
                    ans[j + 1] = left * 2;
                }
            }
            var sb = new StringBuilder();
            for (int i = 0; i < n; i++)
            {
                sb.Append(ans[i]);
                sb.Append(" ");
            }
            WriteRead(sb);
        }
        
        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 30520
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define mod1 998244353 
#define inf 1000000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'



int main()
{
    fastio;
    #ifdef APNA_IO
        start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);    
    #endif

    ll n;cin>>n;
    ll a[n+1],b[n];
    for(ll i=0;i<=n;i++)
        cin>>a[i];
    for(ll j=0;j<n;j++)
        cin>>b[j];

    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        ans+=min(a[i],b[i]);
        b[i]-=min(a[i],b[i]);

        ans+=min(b[i],a[i+1]);
        a[i+1]-=min(b[i],a[i+1]);
    }
    cout<<ans;





    #ifdef APNA_IO
        end_routine();
    #endif
}


Measured memory_bytes: 1792
// https://atcoder.jp/contests/diverta2019/tasks/diverta2019_a
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: i32, k: i32
    };
    println!("{}", n-k+1);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include<algorithm>

using namespace std;

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

    if((S.length()) == 2){
        cout << S << endl;
    }else{
        reverse(S.begin(), S.end());
        cout << S << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def main():
    X, Y, Z = map(int, input().split())
    # 人と人の間，また椅子の端と人の間には， 少なくとも Z センチメートル間を開ける必要があります。
    print((X - Z) // (Y + Z))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
# include <string.h>
# include <iostream>
#include <bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
	int list[100001] = {0};
	int N = 0; 
	int temp = 0;
	cin >> N;
	
    for ( int i = 0; i < N; i++ ) {
    	cin >> temp;
    	list[temp-1] = i;
    } // for
    
    for ( int i = 0; i < N ; i++ ) {
    	cout << list[i] +1 << " " ;
    } // for
	
  
} // main()

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int n,a[N],b[N],f[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  for(int i=1;i<=n;i++){
    cin>>b[i];
  }
  int ans=0;
  int L=0,R=0;
  for(int i=1;i<=n;i++)f[i]=i;
  do{
    int sta=0;
    for(int i=1;i<=n;i++){
      if(a[i]!=f[i]){
        sta=1;
        break;
      }
    }
    if(!sta)break;
    L++;
  }while(next_permutation(f+1,f+1+n));

  for(int i=1;i<=n;i++)f[i]=i;
  do{
    int sta=0;
    for(int i=1;i<=n;i++){
      if(b[i]!=f[i]){
        sta=1;
        break;
      }
    }

    if(!sta)break;
    R++;
  }while(next_permutation(f+1,f+1+n));

  cout<<abs(L-R)<<endl;
  return 0;
}

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

using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    if(a <= 0 && b >= 0) {
        cout << "Zero"  << endl;
        return 0;
    }
    else if(a > 0 && b > 0) {
        cout << "Positive" << endl;
    }
    else if(a < 0 && b < 0) {
        int num = 1 + abs(b - a);
        if(num & 1) cout << "Negative" << endl;
        else cout << "Positive" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] d = new int[k];
		
		for(int i = 0; i < k; i++) d[i] = sc.nextInt();
		
		loop: while(true) {
			String s = String.valueOf(n);

			for(int i : d) {
				if(s.contains(String.valueOf(i))) {
					n++;
					continue loop;
				}
			}
			
			out.println(n);
			return;
			
		}
		
	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

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

int main(){
    long long n;
    cin >> n;
    char arare[n];
    for(int i=0; i<n; i++){
        cin >> arare[i];
    }
    bool ans=false;
    for(int i=0; i<n; i++){
        if(arare[i] == 'Y'){
            ans = true;
        }
    }

    if(ans){
        cout << "Four" << endl;
    }
    else{
        cout << "Three" << endl;
    }
}

Measured memory_bytes: 3596
import numpy as np

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

max_base = [30, 22, 15, 14, 13, 12, 11, 10, 9]
base = np.array([i for i in range(max_base[K-2])])

base = K**base

target = np.array([N]*max_base[K-2])

index = np.where(base <= target, 1, 0)

print(np.sum(index))

Measured memory_bytes: 17964
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int N = 1000;

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

	int h, w, a, b;
	cin >> h >> w >> a >> b;

	int n = 0, m = 0;
	for (; n <= h; ++n) {
		// n: how many rows have 'a' ones
		// m: how many columns have 'b' ones
		int cou = n * a + (h - n) * (w - a);
		for (m = 0; m <= w; ++m) {
			int off = m * b + (w - m) * (h - b);
			if (cou == off) break;
		}
		if (m <= w) break;
	}
	if (n > h) {
		cout << "NO\n";
	} else {
		vector<pair<int, int>> need(w);
		for (int x = 0; x < m; ++x) need[x] = {b, x};
		for (int x = m; x < w; ++x) need[x] = {h - b, x};

		for (int y = 0; y < h; ++y) {
			sort(need.begin(), need.end());
			vector<int> rev(w);
			for (int x = 0; x < w; ++x) rev[need[x].second] = x;

			int cou = (n > 0 ? a : w - a);
			if (n > 0) --n;

			for (int x = 0; x < w; ++x) {
				if (rev[x] >= w - cou) {
					--need[rev[x]].first;
					cout << '1';
				} else {
					cout << '0';
				}
			}
			cout << '\n';
		}
	}
}


Measured memory_bytes: 1280
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

#define INF (int64_t)(1e+14)

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;
    vector<int> a(3 * n);
    for (int i = 0; i < 3 * n; i++) cin >> a.at(i);
    
    vector<int64_t> left_sum(n + 1, 0), right_sum(n + 1, 0);
    priority_queue<int, vector<int>, greater<int>> left_q;
    
    for (int i = 0; i < n; i++) {
        left_sum.at(0) += a.at(i);
        left_q.push(a.at(i));
    }
    
    for (int i = 0; i < n; i++) {
        left_sum.at(i + 1) = left_sum.at(i);
        left_sum.at(i + 1) += a.at(n + i);
        left_q.push(a.at(n + i));
        left_sum.at(i + 1) -= left_q.top();
        left_q.pop();
    }
    
    priority_queue<int> right_q;
    
    for (int i = n - 1; i >= 0; i--) {
        right_sum.at(n) += a.at(2 * n + i);
        right_q.push(a.at(2 * n + i));
    }
    
    for (int i = n - 1; i >= 0; i--) {
        right_sum.at(i) = right_sum.at(i + 1);
        right_sum.at(i) += a.at(n + i);
        right_q.push(a.at(n + i));
        right_sum.at(i) -= right_q.top();
        right_q.pop();
    }
    
    int64_t ans = -INF;
    for (int i = 0; i < n + 1; i++) {
        ans = max(ans, left_sum.at(i) - right_sum.at(i));
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4216
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define setbits(x) __builtin_popcountll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x; cin>>x; while(x--)
#define pb push_back
#define ll long long
#define inf INT_MAX
#define ninf INT_MIN
#define pi 3.14159265358979323846264338327950
 
const int mod=1e9+7;
int main()
{
    map<string,int> m;
  w(x)
  {
      string s; cin>>s;
      m[s]++;
  }
  cout<<m.size();
   return 0;
} 


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

int main() {
  int n, m, X, Y, mx = -1000, my = 1000;
  cin >> n >> m >> X >> Y;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mx = max(mx, x);
  }
  for (int i = 0; i < m; i++) {
    int y;
    cin >> y;
    my = min(my, y);
  }
  bool b = false;
  for (int i = mx + 1; i <= my; i++) {
    if (i > X && i <= Y)
      b = true;
      break;
  }
  if (b) cout << "No War" << endl;
  else cout << "War" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main(){
	int64_t n;

    cin >> n;
	
	int64_t mini = 10000000000;
	
	for(int i=1; i<=sqrt(n); i++) {
		
		if(n%i != 0) continue;
		
		else {
			
			int b = log10(n / i) + 1;
			int a = log10(i) + 1;
			
			int res = max(a,b);
			
			if (mini >= res) mini = res;
		}

	}
	cout << mini <<endl;
	
    return 0;

}


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

typedef long double LL;

using namespace std;

#define rep(i,n) for(auto i=0*(n);i<(n);++i)
typedef complex<LL> P;
typedef vector<P> Poly;

LL dot(P a,P b){return real(conj(a)*b);}
LL cross(P a,P b){return imag(conj(a)*b);}
namespace std{
    bool operator<(const P &l,const P &r){
        return l.real()==r.real()?l.imag()<r.imag():l.real()<r.real();
    }
};
const LL EPS=0;
int cww(P a,P b,P c){
    b-=a;
    c-=a;
    if(cross(b,c)>EPS)return 1;
    if(cross(b,c)<-EPS)return -1;
    if(dot(b,c)<0)return 2;
    if(norm(b)<norm(c))return -2;
    return 0;

}

Poly convex_hull(Poly p){
    int n=p.size();
    if(n==1)return p;
    Poly res(2*n);
    int k=0,t;
    sort(p.begin(),p.end());
    for(int i=0;i<n;i++){
        while(k>1&&cww(res[k-2],res[k-1],p[i])!=1)k--;
        res[k++]=p[i];
    }
    t=k;
    for(int i=n-2;i>=0;i--){
        while(k>t&&cww(res[k-2],res[k-1],p[i])!=1)k--;
        res[k++]=p[i];
    }
    res.resize(k-1);
    return res;
}
bool isis_ss(P sa,P sb,P ta, P tb){
    return cww(sa,sb,ta)*cww(sa,sb,tb)<=0&&
        cww(ta,tb,sa)*cww(ta,tb,sb)<=0;
}
bool intersected_Poly(Poly p,Poly q){
    int n=p.size();
    int m=q.size();
    if(m>=3)
    for(int i=0;i<n;i++){
        bool f=true;
        for(int j=0;j<m;j++){
            if(cww(q[j],q[(j+1)%m],p[i])==-1)f=false;
        }
        if(f)return true;
    }
    if(n>=3)
    for(int i=0;i<m;i++){
        bool f=true;
        for(int j=0;j<n;j++){
            if(cww(p[j],p[(j+1)%n],q[i])==-1)f=false;
        }
        if(f)return true;
    }
    // cout<<n<<m<<endl;
    if(n==1&&m==1){
        return false;
    }
    else if(n==1){
        for(int i=0;i<m;i++){
            // cout<<cww(q[i],q[(i+1)%m],p[0])<<endl;
            if(cww(q[i],q[(i+1)%m],p[0])==0)return true;
        }
    }
    else if(m==1){
        for(int i=0;i<n;i++){
            if(cww(p[i],p[(i+1)%n],q[0])==0)return true;
        }
    }
    else 
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(isis_ss(p[i],p[(i+1)%n],q[j],q[(j+1)%m]))return true;
        }
    }
    return false;

}
#define PRO "YES"
#define SHUMI "NO"
int main(){
    for(int n,m;cin>>n>>m,n+m;){
        vector<P> b(n),w(m);
        for(int i=0;i<n;i++){
            LL x,y;cin>>x>>y;
            b[i]=P(x,y);
        }
        for(int i=0;i<m;i++){
             LL x,y;cin>>x>>y;
            w[i]=P(x,y);
        }
        b=convex_hull(b);
        w=convex_hull(w);
        
        if(intersected_Poly(b,w))cout<<SHUMI<<endl;
        else cout<<PRO<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 3276
def solve(l):
    if len(l)<2:
        return max(0,l[0])
    m=10**18
    a=0
    for i in range(len(l)):
        if l[i]<1:
            if i+1<len(l):
                a+=solve(l[i+1:])
            else:
                l=l[:i]
            break
        m=min(m,l[i])
    l=l[:i+1]
    for i in range(len(l)):
        l[i]-=m
    return solve(l)+a+m*(m!=10**18)

n=int(input())
*h,=map(int,input().split())
print(solve(h))

Measured memory_bytes: 39280