akhauriyash/Code-Regression huggingface dataset:
import scala.io.StdIn
import scala.collection.mutable.ArrayBuffer

object Main extends App {

  val n = StdIn.readLine().trim.toInt
  class Point(val x: Double, val y: Double){
    override def toString: String = {
      f"$x%.8f $y%.8f"
    }
  }
  
  final val start = new Point(0, 0)
  final val end   = new Point(100, 0)
  final val th = scala.math.Pi * 60.0 / 180.0

  @inline def calcuPoint(p1: Point, p2: Point, a: Double, b: Double) = new Point((a*p1.x+b*p2.x)/3.0, (a*p1.y+b*p2.y)/3.0)
  
  
  def koch(d: Double, p1: Point, p2: Point, ret: ArrayBuffer[Point]): Unit = {
    if(d != 0){
      val s = calcuPoint(p1, p2, 2.0, 1.0) 
      val t = calcuPoint(p1, p2, 1.0, 2.0)
      val u = new Point((t.x - s.x)*math.cos(th) - (t.y - s.y)*math.sin(th) + s.x,
                        (t.x - s.x)*math.sin(th) + (t.y - s.y)*math.cos(th) + s.y)
      
      koch(d-1, p1, s, ret)
      // println(s)
      ret += s
      
      koch(d-1, s, u, ret)
      //println(u)
      ret += u
      
      koch(d-1, u, t, ret)
      // println(t)
      ret += t

      koch(d-1, t, p2, ret)

    }
  }
  
  var result = ArrayBuffer.empty[Point]

  //println(start)
  result += start
  koch(n, start, end, result)
  result += end
  
  //result.foreach(println)
  println(result.mkString(f"%n"))
  
}


Measured memory_bytes: 59076
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using ll = long long;
using namespace std;

const long long MOD = 1000000007;
const ll LINF = 1LL << 50;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
  int N;
  cin >> N;
  //vector<ll> hn(100010, 0);
  vector<ll> dp(1000010, LINF);

  int ninemax = 0;
  while (true){
    if (N < pow(9,ninemax)){
      break;
    } else{
      ninemax +=1;
    }
  }
  int sixmax = 0;
  while (true){
    if (N < pow(6,sixmax)){
      break;
    } else{
      sixmax +=1;
    }
  }

  int ans = 0;

  // initialize
  REP(n,N+1){
    dp.at(n) = n;
  }
  for (int n = 0; n<=N; n++){
    for (int m = 0; m < ninemax; m++) chmin(dp.at(n+pow(9,m)), dp.at(n)+1);
    for (int m = 0; m < sixmax;  m++) chmin(dp.at(n+pow(6,m)), dp.at(n)+1);
  }

  cout << dp.at(N) << endl;

}


Measured memory_bytes: 8192
def abc():
    n, m = map(int, input().split())
    d = {}
    for i in range(m):
        a, b = map(int, input().split())
        d[a] = d.get(a, 0) + 1
        d[b] = d.get(b, 0) + 1
    for i in range(1, n+1):
        print(d.get(i, 0))


abc()


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define lli long long int
#define pii pair<int,int>
#define ppi pair<pii,pii>
#define forn(i, n) for(int i=0;i<n;i++)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;

const int MAXN = 1000001;

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int n;
lli A[MAXN];
lli num[MAXN];
lli memo[MAXN][4];
bool vis[MAXN][4];

lli sum(int i,int j) {
	return num[j] - (i ? num[i - 1] : 0);
}

lli go(lli a, int f) {
	if(!a && f == 1) return 2;
	return a % 2 == f;
}

lli DP(int id,int f) {
	if(id == n) return 0;
	if(vis[id][f]) return memo[id][f];
	vis[id][f] = 1;
	lli ans = 1LL<<60;
	if(f == 0) ans = min(min(DP(id + 1, 1) + go(sum(id, id), 1), DP(id + 1, 2) + go(sum(id, id), 0)), DP(id + 1, 0) + sum(id, id));
	if(f == 1) ans = min(DP(id + 1, 1) + go(sum(id, id), 1), DP(id + 1, 2) + go(sum(id, id), 0));
	if(f == 2) ans = min(DP(id + 1, 2) + go(sum(id, id), 0), DP(id + 1, 3) + go(sum(id, id), 1));
	if(f == 3) ans = DP(id + 1, 3) + go(sum(id, id), 1);
	ans = min(ans, sum(id, n - 1));
	return memo[id][f] = ans;
}

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

	forn(i, n) cin>>A[i];
	forn(i, n) if(i) num[i] = A[i] + num[i - 1]; else num[i] = A[i];

	lli ans = DP(0, 0);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 30976
#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>;


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

  if (S.length() <= K) {
    cout << S << endl;
  } else {
    rep(i, K) cout << S[i];
    cout << "..." << endl;
  }
  return 0;
}


Measured memory_bytes: 3596
a = []
for i in range(3):
    a.append(list(map(int, input().split())))
n = int(input())

b = []
for i in range(n):
    b.append(int(input()))

card = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if a[j][k] == b[i]:
                card[j][k] = True

yes = "Yes"
no = 'No'

answer = no

for i in range(3):
    if card[0][i] and card[1][i] and card[2][i]:
        answer = yes
for i in range(3):
    if card[i][0] and card[i][1] and card[i][2]:
        answer = yes
if card[0][0] and card[1][1] and card[2][2]:
    answer = yes
if card[0][2] and card[1][1] and card[2][0]:
    answer = yes

print(answer)

Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
string a, b, c;
int nr;
int to_int(string s)
{
    int z = 0;
    for(auto i : s)
    {
        z = z * 10 + i - '0';
    }
    return z;
}
int main()
{
     cin >> a >> b;
     c = a + b;
     nr = to_int(c);
     int rad = sqrt(nr);
     double dr = sqrt(nr);
     if(rad == dr)
        cout << "Yes";
     else cout << "No";
     return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <array>
#include <queue>
#include <set>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

#define MOD 1'000'000'007

int main()
{
    int N, M;
    cin >> N >> M;

    vector<int> a(M);
    vector<int> broken(N+2, 0);
    REP(i, M)
    {
        cin >> a[i];
        broken[a[i]] = 1;
    }

    vector<int> memo(N+2, 0);
    if (broken[1] == 0)
    {
        memo[1] = 1;
    }
    if (broken[2] == 0)
    {
        memo[2] = 1;
    }
    for (int floor = 1; floor <= N; floor++)
    {
        // cout << "floor " << floor << ": ";
        if (broken[floor] == 0)
        {
            memo[floor] = (memo[floor] + memo[floor-2]) % MOD;
            memo[floor] = (memo[floor] + memo[floor-1]) % MOD;
        }
        // cout << memo[floor];
        // cout << endl;
    }    

    cout << memo[N] << endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <stdlib.h>
#include <math.h>

#define max(a,b) ((a) > (b) ? (a) : (b))

int main(){
	int n,x[100],y[100];
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&x[i]);
	}
	for(int i = 0; i < n; i++){
		scanf("%d",&y[i]);
	}

	double m1=0,m2=0,m3=0,minf=0;
	for(int i = 0; i < n; i++){
		m1 += abs(x[i]-y[i]);
		m2 += pow(x[i]-y[i],2);
		m3 += pow(abs(x[i]-y[i]),3);
		minf = max(abs(x[i]-y[i]),minf);
	}
	m2 = sqrt(m2);
	m3 = pow(m3,1.0/3);

	printf("%.6f\n%.6f\n%.6f\n%.6f\n",m1,m2,m3,minf);

	return 0;
}

Measured memory_bytes: 2904
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n, m, p, q; vector<int> t;
    
    cin >> n; for(int i = 0; i < n; i++) { cin >> p >> q; t.push_back(p * 60 + q); }
    cin >> m; for(int i = 0; i < m; i++) { cin >> p >> q; t.push_back(p * 60 + q); }
    
    sort(t.begin(), t.end());
    
    int count_ = 0;
    
    for(int i = 1; i < t.size(); i++)
    {
        if(t[i - 1] != t[i])
        {
            if(count_) { printf(" "); }
            
            printf("%d:%02d", t[i - 1] / 60, t[i - 1] % 60);
            
            count_++;
        }
    }
    
    printf(" %d:%02d\n", t[n + m - 1] / 60, t[n + m - 1] % 60);
    
    return 0;
}

Measured memory_bytes: 3288
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define Set set<int>
#define int long long
#define P pair<int,int>
const int maxn = 1e6+5;
const int INF = 1e17 +6;
using namespace std;
int n,m,a[maxn],b[maxn],ans;
int32_t main()
{
    IOS;
    string k;
    cin>>k;
    int num=0;
    for(auto i:k)
    {
        if(i=='o')n++;
        num++;
    }
    if(n+15-num>=8)cout<<"YES";
    else cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<tuple>
#include<climits>
#include<algorithm>
using namespace std;

enum{X, Y, DEPTH};
typedef tuple<int, int, int> Node;

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

int m, n;
vector<vector<int>> field;

int bfs(int start_x, int start_y, bool write) {
    int result = 0;
    vector<vector<int>> visited(m, vector<int>(n, 0));
    queue<Node> q;
    q.push(Node(start_x, start_y, 0));
    while(!q.empty()) {
        int x = get<X>(q.front());
        int y = get<Y>(q.front());
        int depth = get<DEPTH>(q.front());
        q.pop();
        if(visited[x][y]) continue;
        visited[x][y] = 1;
        if(field[x][y] <= depth) continue;
        if(write) field[x][y] = depth;
        ++result;
        for(int i = 0; i < 6; ++i) {
            int nx = x + dx[y & 1][i];
            int ny = y + dy[y & 1][i];
            if(nx < 0 || m <= nx || ny < 0 || n <= ny) continue;
            q.push(Node(nx, ny, depth + 1));
        }
    }
    return result;
}

int main() {
    int s, t;
    int x, y;
    while(cin >> m >> n, m | n) {
        field = vector<vector<int>>(m, vector<int>(n, INT_MAX));
        for(cin >> s; s > 0; --s) {
            cin >> x >> y;
            bfs(x - 1, y - 1, true);
        }
        int answer = 0;
        for(cin >> t; t > 0; --t) {
            cin >> x >> y;
            answer = max(answer, bfs(x - 1, y - 1, false));
        }
        cout << answer << endl;
    }
}

Measured memory_bytes: 1248
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
class FastIO
{
    static const int rdata_sz = (1 << 22), wdata_sz = (1 << 22);
    char rdata[rdata_sz], wdata[wdata_sz], *rb, *wb;
    char tmp_s[10];

public:
    FastIO()
    {
        fread(rdata, 1, rdata_sz, stdin);
        rb = rdata;
        wb = wdata;
    }
    ~FastIO()
    {
        fwrite(wdata, 1, wb - wdata, stdout);
    }

    template <typename T>
    inline void read(T &x)
    {
        bool neg = false;
        x = 0;
        while ((*rb < '0' || *rb > '9') && *rb != '-')
            ++rb;
        while ('0' <= *rb && *rb <= '9')
        {
            x = 10 * x + (*rb - '0');
            ++rb;
        }
        if (neg)
            x = -x;
    }

#define pc(x) *(wb++) = x
    template <typename T>
    inline void write(T x)
    {
        if (x == 0)
        {
            pc('0');
            pc(' ');
            return;
        }
        char *t = tmp_s;
        while (x)
        {
            T y = x / 10;
            *(t++) = (x - y * 10) + '0';
            x = y;
        }
        while (t != tmp_s)
            pc(*(--t));
        pc(' ');
    }
#undef pc
};
unsigned int par[500001];
unsigned int ran[500001];
//要素xが所属する木の根を再帰的に発見する
inline unsigned int root(unsigned int x)
{
    if (par[x] == x)
        return x;
    return par[x] = root(par[x]); //経路圧縮
}
//要素xが属する木と要素yが属する木の併合
inline void unite(unsigned int x, unsigned int y)
{
    unsigned int rx = root(x);
    unsigned int ry = root(y);
    if (rx == ry)
        return; //同じ木に属してたらそのまま
    if (ran[rx] < ran[ry])
    {
        par[rx] = ry; //根がryの木に併合
    }
    else
    {
        par[ry] = rx; //根がrxの木に併合
        if (ran[rx] == ran[ry])
            ran[rx]++;
    }
}
//要素xが属する木と要素yが属する木が同じならtrueを返す
inline bool same(unsigned int x,unsigned int y)
{
    return root(x) == root(y);
}
int main()
{
    FastIO io;
    unsigned int N, Q;
    io.read(N);
    io.read(Q);
    for (unsigned int i = 0; i < N; i++)
    {
        par[i] = i;
        ran[i] = 0;
    }
    for (unsigned int i = 0; i < Q; i++)
    {
        unsigned int a, b, c;
        io.read(a);
        io.read(b);
        io.read(c);
        if (a == 1)
            if (same(b, c))
                io.write(1);
            else
                io.write(0);
        if (a == 0)
            unite(b, c);
    }
    return 0;
}


Measured memory_bytes: 7204
#include <iostream>

using namespace std;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int r = 0;
    for (; a >= b; b *= 2) {
        r++;
    }

    for (; b >= c; c *= 2) {
        r++;
    }

    cout << (r <= k ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3596
// AOJ Volume 1 Problem 0195 What is the Most Popular Shop in Tokaichi?

#include <stdio.h>

int main(void)
{
    int i;
    int s1, s2;
    int max, store;
    
    while (1){
        max = store = 0;
        for (i = 0; i < 5; i++){
            scanf("%d%d", &s1, &s2);
            if (s1 == 0 && s2 == 0){
                return (0);
            }
            
            if (max < s1 + s2){
                max = s1 + s2;
                store = i;
            }
        }
        printf("%c %d\n", 'A' + store, max);
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll sum = 0;
    rep(i, n) sum += a[i] - 1;
    cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10); // debuged

    int T;
    // cin >> T;
    T = 1;

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

// 1 枚の皿が i 個, 2 枚の皿が j 個, 3 枚の皿が k 個
// すべてなくなるまでの回数の期待値
// (i, j, k) = ((i - 1, j, k) + 1) * i/n + ... + ((i, j, k) + 1) * (n-i-j-k)/n
// n(i, j, k) = ((i - 1, j, k) + 1) * i + ... + ((i, j, k) + 1) * (n-i-j-k)
// (i+j+k)(i, j, k) = (i - 1, j, k) * i + ... + n
int n;
double dp[303][303][303];
double dfs(int i, int j, int k) {
  // cout << i << " " << j << " " << k << endl;
  if (dp[i][j][k] != -1) return dp[i][j][k];
  if (i + j + k == 0) return dp[i][j][k] = 0; // debuged 1 to 0, 操作回数 0

  double ret = 0;
  if (i) ret += dfs(i - 1, j, k) * i;
  if (j) ret += dfs(i + 1, j - 1, k) * j;
  if (k) ret += dfs(i, j + 1, k - 1) * k;
  ret += n;
  ret /= (i + j + k);
  return dp[i][j][k] = ret;
}

void solve() {
  fill_n(**dp, 303 * 303 * 303, -1);
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> b(4);
  rep(i, n) {
    b[a[i]]++;
  }
  cout << dfs(b[1], b[2], b[3]) << endl;
  /*
  rep(i, b[1] + 1) {
    cout << endl;
    rep(j, b[2] + 1) { rep(k, b[3] + 1) cout << dp[i][j][k] << " "; cout << endl; }
  }
  */
}


Measured memory_bytes: 217728
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    cout << t+s << endl;
    return 0;
}

Measured memory_bytes: 3588
/**
 *    author:  nayan_000
**/
#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define pqll priority_queue<ll>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) ll a[n+f];for(ll hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define ub upper_bound
#define lb lower_bound
#define mapp map<ll,ll>
#define mem(x) memset(x,0,sizeof(x))
#define all(v) v.begin(),v.end()
#define qll queue<ll>
#define sll set<ll>
#define inf LLONG_MAX


int main()
{
	fastio;
	ll n,k,i=1,rep=1,j=0,si;
	cin>>n>>k;
	inp(a,n,1);
	sll s;
	vll v;
	s.insert(i);
	v.pb(1);
	while(1)
	{
		i=a[i];
		if(s.count(i)>0)
			break;
		s.insert(i);
		v.pb(i);
	}
	rep=i;
	for(i=0;i<v.size();i++)
	{
		if(v[i]==rep)
		{
			j=i;
			break;
		}
	}
	si=v.size()-j;
	if(k<v.size())
		cout<<v[k];
	else
	{
		k-=j;
		k%=si;
		cout<<v[j+k];
	}
	return 0;
}

Measured memory_bytes: 15532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int sx = in(),sy = in(),tx = in(),ty = in();
    REP(i,ty-sy)cout << 'U';
    REP(i,tx-sx)cout << 'R';
    REP(i,ty-sy)cout << 'D';
    REP(i,tx-sx)cout << 'L';
    cout << 'L';
    REP(i,ty-sy+1)cout << 'U';
    REP(i,tx-sx+1)cout << 'R';
    cout << 'D';
    cout << 'R';
    REP(i,ty-sy+1)cout << 'D';
    REP(i,tx-sx+1)cout << 'L';
    cout << 'U';
    cout << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a, b, c, d;

	scanf("%d %d %d %d", &a, &b, &c, &d);

	if (a + b > c + d) {
		printf("Left\n");
	}
	else if (a + b < c + d) {
		printf("Right\n");
	}
	else {
		printf("Balanced\n");
	}

	return 0;
}

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T>
vector<vector<T> > make_v(size_t a,size_t b){
  return vector<vector<T> >(a,make_v<T>(b));
}
template<typename T>
vector<vector<vector<T> > > make_v(size_t a,size_t b,size_t c){
  return vector<vector<vector<T> > > (a,make_v<T>(b,c));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> s(h+1);
  for(Int i=1;i<=h;i++) cin>>s[i],s[i]=s[i][0]+s[i]+s[i][w-1];
  s[0]=s[1];
  //for(Int i=0;i<=h;i++) cout<<s[i]<<endl;
  auto check=[&](Int y,Int x,Int z){
    Int a=0,b=0;
    for(Int i=0;i<2;i++){
      for(Int j=0;j<2;j++){
	a+=s[y-i][x-j];
	b+=s[y-i][x-j+1];
      }
    }
    if(z==0) return b%2==0;
    if(z==2) return a%2==0;
    return a%2==0 && b%2==0;
  };
  
  auto dp=make_v<Int>(3,h+1,w+2);
  fill_v(dp,0);
  for(Int k=0;k<3;k++){
    for(Int i=1;i<=h;i++){
      for(Int j=1;j<=w;j++){
	if(check(i,j,k)) dp[k][i][j]=dp[k][i-1][j]+1;
	else dp[k][i][j]=1;
	//cout<<dp[k][i][j];
      }
      //cout<<endl;
    }
    //cout<<endl;
  }
  
  Int ans=0;
  for(Int i=1;i<=h;i++){
    using P = pair<Int, Int>;
    stack<P> s;
    for(Int j=1;j<=w;j++){
      int pos=j;
      while(!s.empty()&&s.top().first>dp[1][i][j]){
	pos=s.top().second;
	chmax(ans,(j-pos)*s.top().first);
	chmax(ans,(j-pos+1)*min(s.top().first,dp[2][i][j]));
	s.pop();
      }
      s.emplace(dp[0][i][j],pos);
    }
    while(!s.empty()){
      chmax(ans,(w-s.top().second+1)*s.top().first);
      s.pop();
    }
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 133632
import 'dart:collection';
import 'dart:convert';
import 'dart:io';

void main(List<String> args) async {
//  Stopwatch sw = Stopwatch()..start();
  final NM = stdin
      .readLineSync()
      .split(' ')
      .map(
        (x) => int.parse(x),
      )
      .toList();
  final N = NM[0];
  final M = NM[1];
  // N個
  final trees = List.generate(N, (i) => []);
  final roomPairs = stdin.transform(utf8.decoder).transform(LineSplitter());
  await roomPairs.forEach((rawRoomPair) {
    final roomPair = rawRoomPair
        .split(' ')
        .map(
          (x) => int.parse(x),
        )
        .toList();
    trees[roomPair[0] - 1].add(roomPair[1] - 1);
    trees[roomPair[1] - 1].add(roomPair[0] - 1);
  });
//  for (int i = 0; i < M; i++) {
//    final roomPair = stdin
//        .readLineSync()
//        .split(' ')
//        .map(
//          (x) => int.parse(x),
//        )
//        .toList();

//  }
//  print('${sw.elapsed}');
  // 初期条件
  final dists = List.generate(N, (i) => -1);
  dists[0] = 0;
  final queue = Queue<int>();
  queue.add(0);
  while (queue.isNotEmpty) {
    final v = queue.removeFirst();
    trees[v].forEach(
      (roomNo) {
        if (dists[roomNo] != -1) {
          return;
        } else {
//          dists[roomNo] = dists[v] + 1;
          dists[roomNo] = v + 1;
          queue.add(roomNo);
        }
      },
    );
  }
//  print('${sw.elapsed}');
  print('Yes');
  for (int i = 1; i < N; i++) {
    final d = dists[i];
    print(d);
//    print(dists.indexOf(d - 1) + 1);
  }
//  print('${sw.elapsed}');
}


Measured memory_bytes: 95560
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int n;
  cin >> n;
  for(int i=1;i<=9;i++){
    if(n % i != 0) continue;
    if(n / i <= 9 && n / i >= 1){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}



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

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

	vector<int> x(n);
	for (int i = 0; i < n; i++) cin >> x[i];

	int ans = 2147483647;
	for (int p = 1; p <= 100; p++) {
		int tmpSum = 0;
		for (int i = 0; i < n; i++) {
			tmpSum += (x[i] - p) * (x[i] - p);
		}
		ans = min(ans, tmpSum);
	}

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

Measured memory_bytes: 256
X,N = map(int,input().split())
p = list(map(int, input().split()))

i = 0

if X not in p:
  print(X)

else:
  while True:
    i += 1
    if X - i not in p:
      print(X-i)
      break
    if X+i not in p:
      print(X+i)
      break


Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep0(i, n){
        cin >> a[i];
        --a[i];
    }
    vector<bool> c(n,false);
    ll to = 0;
    while (1) {
        if(c[to])break;
        c[to] = true;
        to = a[to];
    }
    ll o = to;//閉路に入る町
    ll cnt = 0;//閉路に入るまでのテレポート数
    to = 0;
    while (1) {
        if(to == o)break;
        to = a[to];
        ++cnt;
    }
    if(k <= cnt){
        ll i = 0;
        to = 0;
        while (1) {
            if(i == k)break;
            to = a[to];
            ++i;
        }
        pf(to + 1);
    }else{
        vector<ll> t(0);
        to = o;
        vector<bool> check(n,false);
        while (1) {
            if(check[to])break;
            check[to] = true;
            t.push_back(to + 1);
            to = a[to];
        }
        pf(t[(k - cnt) % t.size()]);
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

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

  // 各色ごとに出現位置をvectorに落とす
  vector<int> r;
  vector<int> g;
  vector<int> b;

  rep(i, n) {
    char c = s[i];
    if (c == 'R') {
      r.push_back(i);
    } else if (c == 'G') {
      g.push_back(i);
    } else {
      b.push_back(i);
    }
  }

  ull sum = 0;
  // RGB
  for (int i : r) {
    // i = R が入っている位置
    for (int y = g.size() - 1; y >= 0; y--) {
      int j = g[y];
      // j = G が入っている位置
      if (i > j) {
        break;
      }
      for (int z = b.size() - 1; z >= 0; z--) {
        int k = b[z];
        // k = B が入っている位置
        if (j > k) {
          break;
        }
        if (k - j != j - i) {
          // printf("%d %d %d\n", i, j, k);
          sum++;
        }
      }
    }
    for (int y = b.size() - 1; y >= 0; y--) {
      int j = b[y];
      // j = B が入っている位置
      if (i > j) {
        break;
      }
      for (int z = g.size() - 1; z >= 0; z--) {
        int k = g[z];
        // k = G が入っている位置
        if (j > k) {
          break;
        }
        if (k - j != j - i) {
          // printf("%d %d %d\n", i, j, k);
          sum++;
        }
      }
    }
  }
  // BRG
  for (int i : b) {
    // i = B が入っている位置
    for (int y = r.size() - 1; y >= 0; y--) {
      int j = r[y];
      // j = R が入っている位置
      if (i > j) {
        break;
      }
      for (int z = g.size() - 1; z >= 0; z--) {
        int k = g[z];
        // k = G が入っている位置
        if (j > k) {
          break;
        }
        if (k - j != j - i) {
          // printf("%d %d %d\n", i, j, k);
          sum++;
        }
      }
    }
    for (int y = g.size() - 1; y >= 0; y--) {
      int j = g[y];
      // j = G が入っている位置
      if (i > j) {
        break;
      }
      for (int z = r.size() - 1; z >= 0; z--) {
        int k = r[z];
        // k = R が入っている位置
        if (j > k) {
          break;
        }
        if (k - j != j - i) {
          // printf("%d %d %d\n", i, j, k);
          sum++;
        }
      }
    }
  }
  // GRB
  for (int i : g) {
    // i = G が入っている位置
    for (int y = r.size() - 1; y >= 0; y--) {
      int j = r[y];
      // j = R が入っている位置
      if (i > j) {
        break;
      }
      for (int z = b.size() - 1; z >= 0; z--) {
        int k = b[z];
        // k = B が入っている位置
        if (j > k) {
          break;
        }
        if (k - j != j - i) {
          // printf("%d %d %d\n", i, j, k);
          sum++;
        }
      }
    }
    for (int y = b.size() - 1; y >= 0; y--) {
      int j = b[y];
      // j = B が入っている位置
      if (i > j) {
        break;
      }
      for (int z = r.size() - 1; z >= 0; z--) {
        int k = r[z];
        // k = R が入っている位置
        if (j > k) {
          break;
        }
        if (k - j != j - i) {
          // printf("%d %d %d\n", i, j, k);
          sum++;
        }
      }
    }
  }

  cout << sum;
}

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

using namespace std;

inline int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}

inline void tbd() {
	cout << "TBD" << endl;
}

inline void heisei() {
	cout << "Heisei" << endl;
}

inline int  month(string s) {
	if (ctoi(s.at(5)) > 0) {
		return 0;
	}
	else if (ctoi(s.at(5)) == 0) {
		if (ctoi(s.at(6)) > 4) {
			return 0;
		}
		else if (ctoi(s.at(6)) == 4) {
			return 1;
		}
		else if (ctoi(s.at(6)) < 4) {
			return 2;
		}
	}

	cout << "ERR";
}
int main() {
	string s;
	cin >> s;

		switch (month(s))
		{
			cout << "in switch" << endl;
			cout << month(s) << endl;
		case 0: tbd(); break;
		case 1:
			if (ctoi(s.at(8)) < 3) {
				heisei();
			}
			else if (ctoi(s.at(8)) == 3 && ctoi(s.at(9)) == 0) {
				heisei();
			}
			else {
				tbd();
			}
			break;
		case 2: heisei(); break;
		default: cout << "error" << endl;
		}
	
}

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

int main(void){
  int i, j, k, n, *a;

  scanf("%d", &n);
  while(n != 0){
    a = (int *)malloc(sizeof(int)*n);
    for(i=0, j=0; i < n; i++){
      scanf("%d", &a[i]);
    }
    k = a[0];
    for(i=1, j=0; i < n; i++){
      if(a[i] > k){
	k = a[i];
      }
      if((a[i]>=0 && a[j]>=0) || (a[i]<0 && a[j]<0)){
	a[j] += a[i];
      }else{
	j++;
	a[j] = a[i];
      }
    }
    for(i=0; i <= j; i++){
      if(a[i] > k){
	k = a[i];
      }
      if(a[i] < 0)  continue;
      if(i+2 <= j && a[i]+a[i+1] > 0){
	a[i+2] += a[i]+a[i+1];
	i++;
      }
    }
    printf("%d\n", k);
    free(a);
    scanf("%d", &n);
  }
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const int N = 1e2+9, M = 1e5+9, OO = 0x3f3f3f3f,MOD = 1e9 + 7;
int memo[M][2],arr[N],n,k;
int solve(int rem=k,bool player=1)
{

  int &ret = memo[rem][player];
  if(~ret) return ret;

  ret = 0;
  for(int i=0;i<n;++i)  if(rem>=arr[i]) ret  |= !solve(rem-arr[i],!player);

  return ret;
}
int main()
{
  memset(memo,-1,sizeof memo);

  scanf("%d%d",&n,&k);
  for(int i=0;i<n;++i) scanf("%d",arr+i);
  
  if(solve()) puts("First");
  else  puts("Second");
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 8832
import java.util.*;

public class Main {
    private static long solve(int N, int[] a) {
        long[][] score = new long[N][N];
        int parity = N % 2;

        for (int i = N-1; i >=0; i--)
            score[i][i] = parity == 1 ? a[i]: -a[i];

        for (int e = 1; e < N; e++)
            for (int s = e - 1, turn = 1-parity; s >= 0; s--, turn = 1-turn)
                score[s][e] = turn == 1 ?
                    Math.max(score[s][e - 1] + a[e], score[s + 1][e] + a[s])
                    : Math.min(score[s][e - 1] - a[e], score[s + 1][e] - a[s]);

        return score[0][N-1];
    }

    public static long run(Scanner scanner) {
        int N = scanner.nextInt();
        int[] a = new int[N];
        for (int i=0; i < N; i++) a[i] = scanner.nextInt();

        return solve(N, a);
    }

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            System.out.println(run(scanner));
        }
        //Tests.run();
    }
}

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

using namespace std;

int main() {
	int a;
  	string s;
  	cin >> a;
  	cin >> s;
  	
  	if (a >= 3200) {
    	cout << s << endl;
    } else {
    	cout << "red" << 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;
int main(){
    int n;
    cin>>n;
    string s[n];
    rep(i,n){
        cin>>s[i];
        if(s[i]=="Y"){
            cout<<"Four"<<endl;
            return 0;
        }
    }
    cout<<"Three"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

int main() {
    int n; cin >> n;
    string x; cin >> x;
    int cnt = 0;
    rep(i, n) if (x[i]=='1') ++cnt;
    vector<ll> mod1(n, 1), mod2(n, 1);
    ll cnt1 = cnt + 1; 
    ll cnt2 = max(cnt - 1, 1);
    rng(i, 1, n) {
        mod1[i] = (mod1[i-1] * 2) % cnt1;
        mod2[i] = (mod2[i-1] * 2) % cnt2;
    }
    ll m1 = 0, m2 = 0;
    rep(i, n) {
        if (x[n-i-1] == '1') {
            m1 += mod1[i];
            m2 += mod2[i];
            m1 %= cnt1;
            m2 %= cnt2;
        }
    } 
    vector<ll> tans(n);
    rep(i, n) {
        if (x[i]=='0') {
            ll a = mod1[n-i-1] + m1;
            a %= cnt1;
            tans[i] = a; 
        } else {
            if (cnt==1) tans[i] = -1;
            else {
                ll a = m2 - mod2[n-i-1];
                a = (a+cnt2) % cnt2;
                tans[i] = a; 
            }
        } 
    } 
    vector<ll> ans(n);
    rep(i, n) {
        ll a = tans[i];
        if (a < 0) {
            ans[i] = 0;
            continue;
        }
        int cnt = 1;
        while (a) {
            ll ta = a;
            ll p = 0;
            while (ta) {
                if(ta&1) ++p;
                ta >>= 1;
            }  
            a %= p;
            ++cnt;
        }
        ans[i] = cnt;
    }
    for(int a: ans) cout << a << endl; 
    /*   
    rep(i,n) {
        cout << i << ","  << tans[i] << "," << ans[i] << endl;
    }
    */
    return 0;
}


Measured memory_bytes: 9636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N, M;
  cin >> N >> M;
  int ans = 0;
  rep(i, M)
  {
    int A;
    cin >> A;
    ans += A;
  }
  ans = N - ans;
  if(ans < 0)
    ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
31min 41sec
"""
"""
<がn個連続するとき、0からnまでの自然数を並べればよい。
>がn個連続するとき、nから0までの自然数を並べればよい。
これらのときの和は、n*(n+1)//2。
><と並んだときは、間に0が挟まれるので考えなくいていい。
<>と並んだときは、連続する数が小さいほうから1個取り除くことにする。
"""
def main():
    S = input()
    N = len(S)
    compressed_list = []
    now_direction = S[0]
    now_counter = 0
    for i in range(N):
        if S[i] == now_direction:
            now_counter += 1
        else:
            compressed_list.append([now_direction, now_counter])
            now_direction = S[i]
            now_counter = 1
    compressed_list.append([now_direction, now_counter])
    answer = 0
    for i in range(len(compressed_list)):
        n = compressed_list[i][1]
        if compressed_list[i][0] == "<":
            if i <= len(compressed_list)-2 and \
                compressed_list[i][1] <= compressed_list[i+1][1]:
                n -= 1
        else:
            if i >= 1 and \
                compressed_list[i-1][1] > compressed_list[i][1]:
                n -= 1
        answer += n*(n+1)//2
    print(answer)
    return

if __name__ == "__main__":
    main()



Measured memory_bytes: 29084
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

bool f(const vector<int>& v1, const vector<int>& v2) {
    int c1 = accumulate(v1.begin(), v1.end(), 0);
    int c2 = accumulate(v2.begin(), v2.end(), 0);
    if (c1 < c2) return false;
    if (c1 > c2) return true;
    c1 = 0, c2 = 0;
    for (int i = 9; i >= 0; i--) {
        c1 += v1[i];
        c2 += v2[i];
        if (c1 > c2) return true;
        if (c1 < c2) return false;
    }
    return true;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v = {0,2,5,5,4,5,6,3,7,6};
    vector<pair<int, int>> vp;
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        vp.push_back(make_pair(v[a], -a));
    }
    sort(vp.begin(), vp.end());
    for (int i = 0; i < m; i++) {
        vp[i].second *= -1;
    }
    vector<vector<vector<int>>> res(m, vector<vector<int>>(n + 1, vector<int>(0)));
    vector<int> base(10, 0);
    for (int i = 0; i * vp[0].first <= n; i++) {
        base[vp[0].second] += i;
        res[0][n - i * vp[0].first] = base;
        base[vp[0].second] = 0;
    }
    for (int i = 0; i < m - 1; i++) {
        for (int j = 0; j <= n; j++) {
            if (res[i][j].size() == 0) continue;
            vector<int> digit = res[i][j];
            
            for (int k = j / vp[i + 1].first; k >= 0; k--) {
                int remain = j - k * vp[i + 1].first;
                digit[vp[i + 1].second] += k;
                if (res[i + 1][remain].size() == 0 || f(digit, res[i + 1][remain])) {
                    res[i + 1][remain] = digit;
                }
                digit[vp[i + 1].second] -= k;
            }
        }
    }
    string s;
    for (int i = 0; i < 10; i++) {
        s += string(res[m - 1][0][i], i + '0');
    }
    sort(s.begin(), s.end(), greater<char>());
    cout << s << endl;
}


Measured memory_bytes: 9476
#include<bits/stdc++.h>
using namespace std;
int main()
{
int now=-1;int ans=0;
int n; cin>>n;
while (n--)
{
	int tmp;cin>>tmp;
	if (tmp>=now)
	{
		now=tmp;
		ans++;
	}
}
cout<<ans<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <stdio.h>

#define mMin(a, b) ((a) < (b))? (a): (b)

unsigned long min;		/* 10^4/1*10^4 = 10^8(27bit) */

int A[1000], B[1000];
unsigned long D[10001];

int main(void){
	int H, N, i, j;
	
	scanf("%d%d",&H, &N);
	
	for (i = 0; i < N; i++){
		scanf("%d%d", A + i, B + i);
	}
	
	/* ライフ1からHまで最小魔力でMonster倒すテーブルを作成 */
	for (i = 1; i <= H; i++){
		min = 0xFFFFFFFF;

		for (j = 0; j < N; j++){
			if (A[j] < i){
				min = mMin(D[i - A[j]] + B[j], min);
			}
			else{
				min = mMin(B[j], min);
			}
		}
		D[i] = min;
	}
	
	printf("%lu\n", D[H]);
	
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static String S;
	boolean flg = false;

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		long N = sc.nextLong();
		long count = 0;
		for (long i = 1; i <= N; i++) {
			if (String.valueOf(i).length() % 2 == 1) {
				count++;
			}
		}
		System.out.println(count);
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

Measured memory_bytes: 28372
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		char ch[];
		
		int n, res;
		while(!(string = reader.readLine()).equals("0")){
			n = Integer.valueOf(string);
			
			int map[][] = new int[n][n];
			int sum[][] = new int[n + 1][n + 1];
			ch = reader.readLine().toCharArray();
			for(int i = 0; i < n; i++){
				map[0][i] = (ch[i] == '.' ? 1 : 0);
				
				if(i > 0){
					sum[1][i + 1] = sum[1][i] + map[0][i];
				}else{
					sum[1][i + 1] = map[0][i];
				}
			}
			for(int i = 1; i < n; i++){
				ch = reader.readLine().toCharArray();
				for(int j = 0; j < n; j++){
					map[i][j] = (ch[j] == '.' ? 1 : 0) + map[i - 1][j];
					
					if(j > 0){
						sum[i + 1][j + 1] = sum[i + 1][j] + map[i][j];
					}else{
						sum[i + 1][1] = map[i][0];
					}
				}
			}
			
			if(sum[n][n] == 0){
				System.out.println(0);
				continue;
			}
			res = 1;
			x : for(int w = n + 1; w > 0; w--){
				for(int i = n; i > 0; i--){
					if(i - w < 0) break;
					for(int j = n; j > 0; j--){
						if(j - w < 0) break;
						
						if(sum[i][j] - sum[i - w][j] - sum[i][j - w] + sum[i - w][j - w] == w * w){
							res = w;
							break x;
						}
					}
				}
			}
			System.out.println(res);
		}
		reader.close();
	}
}

Measured memory_bytes: 66940
#include<bits/stdc++.h>
using namespace std;
double a[4][4];
int main()
{
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)cin>>a[i][j];
	if(a[1][2]+a[2][3]+a[3][1]+a[1][3]+a[2][1]+a[3][2]==(a[1][1]+a[2][2]+a[3][3])*2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int N;
    cin >> W >> H >> N;
    vector<pii>v(N);
    erep(e,v) cin >> e.first >> e.second,--e.first,--e.second;
    v.push_back(pii(0,0));
    v.push_back(pii(W-1,H-1));
    int s = N,t = N+1;
    vector<vector<int>>edge(N+2,vector<int>(N+2,INF));
    vector<vector<int>>d(N+2,vector<int>(1000+ 100,INF));
    priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>>que;
    
    rep(i,N+2)rep(j,N+2)edge[i][j] = abs(v[i].first - v[j].first) + abs(v[i].second - v[j].second);
    que.push({0,s,0});
    d[s][0] = 0;
    while(!que.empty()){
        auto top = que.top();
        int dist = top.front(),v = top[1],cost = top[2];
        que.pop();
        if (dist > d[v][cost])continue;
        rep(nv,edge[v].size()){
            if(nv == v)continue;
            int ncost = edge[v][nv] - cost -(v != s and nv != t);
            cmax(ncost,0LL);
            if(d[nv][ncost] > dist + ncost){
                d[nv][ncost] = dist + ncost;
                que.push({d[nv][ncost],nv,ncost});
            }
        }
    }
    cout << *min_element(all(d[t])) << endl;
}





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

using namespace std;
typedef long long ll;

vector <int> dfs(vector<int> b, vector<int> ans)
{

  int n = b.size();
  //  for( int i=0;i<n;i++ )
  //    cout << b[i];
  //  cout << endl;
  if( n == 0 )
    {
      reverse(ans.begin(), ans.end());
      return ans;
    }

  for( int i=0;i<n;i++ )
    if( b[i]>n )
      return {};

  for( int i=n-1;i>=0;--i )
    {
      if( b[i] == i+1 )
	{
	  auto a = ans;
	  a.push_back(i);
	  auto x = b;
	  x.erase(x.begin()+(i));
	  auto t = dfs(x, a);
	  if( t.size()!=0 )
	    return t;
	  break;
	}
    }
  return {};
}
  
int main()
{
  int N;
  cin >> N;
  vector<int>b(N);
  for( int i=0;i<N;i++ )
    cin >> b[i];

  for( int i=0;i<N;i++ )
    if( (b[i]-1)>i )
      {
	cout << -1 << endl;
	return 0;
      }
  
  vector<int> ans = dfs(b, {});
  if( ans.size() == 0)
    cout << -1 << endl;
  else
    for( int i=0;i<N;i++ )
      cout << ans[i]+1 << endl;
  return 0;
}


Measured memory_bytes: 384