akhauriyash/Code-Regression huggingface dataset:
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let s = it.next().unwrap().as_bytes();
    let n = s.len();
    let k = it.next().unwrap().parse::<usize>().unwrap();
    let mut dp = vec![vec![vec![0; n]; n]; k+1];
    for d in (1..n).rev() {
        for i in 0..k+1 {
            for j in 0..n-d {
                dp[i][j+1][j+d] = std::cmp::max(dp[i][j+1][j+d], dp[i][j][j+d]);
                dp[i][j][j+d-1] = std::cmp::max(dp[i][j][j+d-1], dp[i][j][j+d]);
                let next_i = i + if s[j] == s[j+d] { 0 } else { 1 };
                if next_i > k { continue; }
                dp[next_i][j+1][j+d-1] = std::cmp::max(dp[next_i][j+1][j+d-1], dp[i][j][j+d] + 2);
            }
        }
    }
    let mut res = 0;
    for i in 0..k+1 {
        for j in 0..n {
            for l in 0..n {
                res = std::cmp::max(res, dp[i][j][l] + if j == l { 1 } else { 0 });
            }
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 121084
a = []
while True:
    b = map(int, raw_input().split())
    if b == [0, 0]:
        break
    a.append(b)
for list in a:
    n, x = list
    c = 0
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if i + j + k == x - 3 and i < j and j < k:
                    c += 1
    print c

Measured memory_bytes: 6404
#include <stdio.h>

int main(){
    
    int x,y;
    while(1){
        scanf("%d %d", &x, &y);
        if(x==0 && y==0)break;
        if(x >= y) printf("%d %d\n", y, x);
        else if(x < y) printf("%d %d\n", x, y);
        //if(x > y) printf("%d %d\n", x, y);
    }
}
 


Measured memory_bytes: 2572
/*input
1000000000000000 5
*/

#include <bits/stdc++.h>

using namespace std;

int64_t a; int b, c; char s[10];
int main(int argc, char const *argv[]) {
  scanf("%lld %s", &a, s);
  b = s[0] - '0';
  if (s[1] == '.') {
    if (s[3] < '0') s[3] = '0';
    c = (s[2] - '0') * 10 + s[3] - '0';
  }
  cout << (b * a) + (c * a / 100);

  return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int X,Y,Z,K;
  
  while(cin >> X >> Y >> Z >> K){
    vector<LLI> A(X), B(Y), C(Z); cin >> A >> B >> C;

    vector<LLI> ab;
    for(auto a : A) for(auto b : B) ab.push_back(a+b);

    sort(ALL(ab));
    reverse(ALL(ab));

    vector<LLI> ans;
    REP(i,min(K,(int)ab.size())) for(auto c : C) ans.push_back(ab[i]+c);
    sort(ALL(ans));
    reverse(ALL(ans));

    REP(i,K){
      cout << ans[i] << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 43368
#include<bits/stdc++.h>
using namespace std;
char a[55],b[55];
int l;
int main()
{
    scanf("%s%s",a,b);
    l=strlen(b);
    for(int i=0;i<l;i++)
        printf("%c%c",a[i],b[i]); 
    if(strlen(a)>strlen(b))
        printf("%c",a[l]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node {int parent,left,right;};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d){
  if(u == NIL ) return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left !=NIL){
    h1 = setHeight(T[u].left)+1;
  }
  if(T[u].right != NIL){
    h2 = setHeight(T[u].right)+1;
  }
  return H[u]=(h1>h2 ? h1:h2);
}

int getSibling(int u){
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
     return T[T[u].parent].left;
     if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
	return T[T[u].parent].right;
	return NIL;
	}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg=0;
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if(T[u].parent == NIL){
    printf("root\n");
  } else if (T[u].left == NIL && T[u].right == NIL) {
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

int main() {
  int v,l,r,root=0;
  scanf("%d", &n);

  for( int i=0;i<n;i++) T[i].parent = NIL;

  for(int i=0;i<n;i++){
    scanf("%d %d %d", &v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }

  for(int i=0;i<n;i++) if(T[i].parent==NIL) root=i;

  setDepth(root,0);
  setHeight(root);

  for(int i = 0;i<n;i++) print(i);

  return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    int ans = 0;
    ll need = 0;
    vector<ll> delta;
    ll ASum = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        ASum += a[i];
    }
    ll Bsum = 0;
    for(int i = 0; i < n; i++) {
        cin >> b[i];
        Bsum += b[i];
        if(a[i] < b[i]) {
            ans++;
            need += b[i] - a[i];
        }
        if(a[i] > b[i]) {
            delta.push_back(a[i] - b[i]);
        }
    }
    if(ASum < Bsum) {
        cout << "-1" << endl;
        return 0;
    }
    sort(delta.begin(), delta.end(), greater<ll>());
    for(int i = 0; i < delta.size(); i++) {
        if(need <= 0) break;
        ans++;
        need -= delta[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2428
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)

typedef unsigned long long ull;
typedef long long ll;

const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

using namespace std;
using P = pair<int,int>;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
  ll n;
  cin >> n;
  
  vector<ll> a(n); ll sum = 1;
  rep(i, n) {
      cin >> a[i];
      if (a[i] == 0) 
      {
          cout << 0 << endl;
          return 0;
      }
    //   cout << sum << endl;
  }
  rep(i, n) {
      // sum *= a[i];
      // if (sum > INF) WA
      if (a[i] > INF/sum) 
      {
          cout << "-1" << endl;
          return 0;
      }
      sum *= a[i];
    //   bool check = __builtin_mul_overflow(sum, );
    //   if (check) 
    //   {
    //       cout << "-1" << endl;
    //       return 0;
    //   }
  }

  if (sum > INF) cout << "-1" << endl;
  else cout << sum << endl;
//   cout << INF << endl;
  return 0;
}

Measured memory_bytes: 4056
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321
#define PI 3.14159265358979323846264
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
ll MOD = 1999;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

char s[300005];
int L[300005], R[300005];
int main() {
	int n;
	scanf("%d%s", &n, s+1);
	fup(i, 1, n, 1)
	{
		L[i] = L[i - 1];
		if (s[i] == 'W')L[i]++;
	}
	fdn(i, n, 1, 1)
	{
		R[i] = R[i + 1];
		if (s[i] == 'E')R[i]++;
	}
	int ans = INF;
	fup(i, 1, n, 1)
	{
		ans = min(ans, L[i - 1] + R[i + 1]);
	}
	printf("%d", ans);
}

Measured memory_bytes: 2944
n,k = map(int,input().split())
ans = 0

if k > 0:
    for i in range(k+1,n+1):
        a = n // i
        b = n % i
        ans += (a * (i-k) + (max(0,b-(k-1))))
else:
    ans = n ** 2
    
print(ans)

Measured memory_bytes: 40176
N, L = map(int, input().split())

apple = [L+i-1 for i in range(1,N+1)]

if 0 in apple:
    print(sum(apple))
elif max(apple) < 0:
    print(sum(apple) - max(apple))
elif min(apple) > 0:
    print(sum(apple) - min(apple))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int L;
	string S[2];
	cin >> L >> S[0] >> S[1];
	int N[2];
	vector<int> pos0[2];
	for(int k = 0; k < 2; k++) {
		for(int i = 1; i < L; i++)
			if(S[k][i] == S[k][i-1]) pos0[k].push_back(i-1);
		N[k] = pos0[k].size();
	}
	if(N[0]+N[1] == 0) {
		if(S[0][0] == S[1][0]) cout << "0\n";
		else cout << L << "\n";
		return 0;
	}
	vector<int> id_gt[2];
	for(int k = 0; k < 2; k++) {
		id_gt[k].resize(N[k]);
		int a = 0;
		for(int i = 0; i < N[k]; i++) {
			while(a < N[1-k] && pos0[1-k][a] < pos0[k][i]) a++;
			if(k == 1) while(a < N[1-k] && pos0[1-k][a] <= pos0[k][i]) a++;
			id_gt[k][i] = a;
		}
	}
	vector<cat> cost(N[0]+N[1]+1, 0), add(N[0]+N[1]+1, 0);
	for(int i = 0; i < N[0]; i++) {
		// cost[d] += A[i]: A[i] > B[i+d]
		add[N[0]-i] += pos0[0][i];
		add[N[0]+id_gt[0][i]-i] -= pos0[0][i];
		// cost[d] -= A[i]: A[i] <= B[i+d]
		add[N[0]+id_gt[0][i]-i] -= pos0[0][i];
		add[N[0]+N[1]-i] += pos0[0][i];
	}
	for(int i = 0; i < N[1]; i++) {
		// cost[d] += B[i]: A[i-d] <= B[i]
		add[N[0]+i-id_gt[1][i]+1] += pos0[1][i];
		add[N[0]+i+1] -= pos0[1][i];
		// cost[d] -= B[i]: A[i-d] > B[i]
		add[N[0]+i-N[0]+1] -= pos0[1][i];
		add[N[0]+i-id_gt[1][i]+1] += pos0[1][i];
	}
	for(int i = 0; i < N[0]; i++) {
		add[N[0]+N[1]-i] += L-1-pos0[0][i];
		// add[N[0]+N[1]+1] -= L-1-pos0[0][i];
		add[0] += 1+pos0[0][i];
		add[N[0]-i] -= 1+pos0[0][i];
	}
	for(int i = 0; i < N[1]; i++) {
		add[N[0]+i+1] += 1+pos0[1][i];
		// add[N[0]+N[1]+1] -= 1+pos0[1][i];
		add[0] += L-1-pos0[1][i];
		add[i+1] -= L-1-pos0[1][i];
	}
	cat a = 0;
	for(int i = 0; i <= N[0]+N[1]; i++) {
		a += add[i];
		cost[i] += a;
	}
	int dif = (S[0][0] != S[1][0]) ^ (N[0]&1);
	cat ans = cost[dif];
	for(int i = dif; i <= N[0]+N[1]; i += 2) ans = min(ans, cost[i]);
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 384
#include<stdio.h>
int main(void){
    int S;
    scanf("%d",&S);
    int h,m,s;
    h=S/3600;
    S=S%3600;
    m=S/60;
    s=S%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 1804
#包除原理
#辺の保持をbit演算での保持へ変換するのが辛い
n = int(input())

TE = [[] for _ in range(n)]
TE2 = []
for i in range(n-1):
    ai,bi = map(int, input().split( ))
    ai -= 1
    bi -= 1
    TE[ai].append(bi)
    TE[bi].append(ai)
    TE2.append((ai,bi))
m  = int(input())
D =[]
for i in range(m):
    ai,bi = map(int ,input().split( ))
    ai -= 1
    bi-=1
    D.append((ai,bi))

bit = 1<<m


P =[0]*n
C = [[] for _ in range(n)]
from collections import deque
Q = deque()
Q.append(0)
V = [0]*n
V[0] = 1

while Q:
    v = Q.popleft()
    for u in TE[v]:
        if not V[u]:
            V[u] = 1
            Q.append(u)
            P[u] = v
            C[v].append(u)
def path(u,v):
    u_p = set()
    tmp1 = u
    while tmp1:
        u_p.add(tmp1)
        tmp1 = P[tmp1]
    u_p.add(tmp1)
    tmp2 = v

    while tmp2 not in u_p:
        tmp2 = P[tmp2]
    pth = 0##
    tmp3 = u
    tmp4 = v
    while tmp3!=tmp2:
        for t in range(n-1):
            if TE2[t] == (tmp3,P[tmp3]) or TE2[t]==(P[tmp3],tmp3):
                pth |= (1<<t)
        tmp3 = P[tmp3]

    while tmp4!= tmp2:
        for t in range(n-1):
            if TE2[t] == (tmp4,P[tmp4]) or TE2[t]==(P[tmp4],tmp4):
                pth |= (1<<t)
        tmp4 = P[tmp4]
    return pth

D2 = [path(D[i][0],D[i][1]) for i in range(m)]
#print(D2)
ans = 2**(n-1)
for i in range(1,bit):
    cnt = 0
    paths = 0
    for j in range(m):
        if (i>>j)&1:
            paths |= D2[j]
            cnt += 1
    cnt2 = 0
    for j in range(n-1):
        cnt2 += (paths>>j)&1
    ans += (-1)**cnt *2**(n-1-cnt2)
print(ans)


Measured memory_bytes: 43776
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    int n;
    cin >> n;
    bool y = false;
    rep(i, n){
        char c;
        cin >> c;
        if(c == 'Y')y = true;
    }
    if(y)cout << "Four";
    else cout << "Three";  
}

Measured memory_bytes: 256
S = input()
l = len(S)
OK = False
if S[0:7]=='keyence':
    OK = True
elif S[l-7:]=='keyence':
    OK = True
elif S[l-6:]=='eyence' and S[0]=='k':
    OK = True
elif S[l-5:]=='yence' and S[:2]=='ke':
    OK = True
elif S[l-4:]=='ence' and S[:3]=='key':
    OK = True
elif S[l-3:]=='nce' and S[:4]=='keye':
    OK = True
elif S[l-2:]=='ce' and S[:5]=='keyen':
    OK = True
elif S[l-1:]=='e' and S[:6]=='keyenc':
    OK = True
else:
    OK = False
print('YES' if OK else 'NO')


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

// #define multitest 1
#ifdef WIN32
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.first << ", " << p.second << ']';
	return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
	while (*name == ',' || *name == ' ')
		name++;
	std::cerr << name << " { ";
	for (const auto &v : arg)
		cerr << v << ' ';
	cerr << " }\n";
}
template <typename Arg1, typename... Args>
void PC(const char *names, Arg1 &&arg1, Args &&... args)
{
	while (*names == ',' || *names == ' ')
		names++;
	const char *comma = strchr(names, ',');
	std::cerr.write(names, comma - names) << " { ";
	for (const auto &v : arg1)
		cerr << v << ' ';
	cerr << " }\n";
	PC(comma, args...);
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
auto TimeStart = chrono::steady_clock::now();

const int nax = 2e5 + 10, mod = 1000000007;

void solve(int caseNo)
{
	int h, w;
	cin >> h >> w;
	vector<string> grid(h);
	for (auto &x : grid)
		cin >> x;
	for (int i = 0; i < h; i++)
	{
		cout << "#";
		if (i % 2 == 0)
		{
			for (int i = 1; i < (w - 1); i++)
				cout << "#";
			cout << ".\n";
		}
		else
		{
			for (int j = 1; j < (w - 1); j++)
				cout << grid[i][j];
			cout << ".\n";
		}
	}
	cout << '\n';
	for (int i = 0; i < h; i++)
	{
		cout << ".";
		if (i % 2 == 1)
		{
			for (int i = 1; i < w; i++)
				cout << "#";
			cout << "\n";
		}
		else
		{
			for (int j = 1; j < (w - 1); j++)
				cout << grid[i][j];
			cout << "#\n";
		}
	}
}

int main()
{
#ifndef WIN32
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	for (int i = 0; i < t; ++i)
		solve(i);
#ifdef TIME
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

int ans[114][514]={};
int h,w,n;

void draw(int cur,int c_){
    int x = cur / w;
    int y = cur - x * w;
    if(x%2) y = w-1-y;
    ans[x][y] = c_;
}

signed main(){
    scanf("%d%d%d",&h,&w,&n);
    int a[11451];
    REP(i,n) scanf("%d",&a[i]);

    int cur = 0;
    REP(i,n){
        REP(j,a[i]){
            draw(cur,i+1);
            cur++;
        }
    }

    REP(i,h){
        REP(j,w) printf("%d ",ans[i][j]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 512
open Printf
open Scanf

let id x = x

let n = scanf "%d\n" id
let str = scanf "%s\n" id

let rec loop left right n =
    if left >= right then n
    else if str.[left] = 'R' then loop (left + 1) right n
    else if str.[right] = 'W' then loop left (right - 1) n
    else loop (left + 1) (right - 1) (n + 1)

let () =
    printf "%d\n" (loop 0 (String.length str - 1) 0)


Measured memory_bytes: 4532
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n, K;
    cin >> n >> K;
    vector<int> bad(10, false);
    for (int i = 0; i < K; ++i) {
        int x;
        cin >> x;
        bad[x] = true;
    }

    int mn = 10;
    for (int k = 0; k < 10; ++k) {
        if (!bad[k]) {
            mn = k;
            break;
        }
    }

    string s = to_string(n);
    n = s.length();
    for (int i = 0; i < n; ++i) {
        int d = s[i] - '0';
        if (bad[d]) {
            while (i >= 0) {
                bool done = false;
                d = s[i] - '0';
                for (int j = d + 1; j < 10; ++j) {
                    if (!bad[j]) {
                        s[i] = (char) ('0' + j);
                        for (int k = i + 1; k < n; ++k) {
                            s[k] = (char)('0' + mn);
                        }
                        done = true;
                        break;
                    }
                }
                if (done) {
                    break;
                }
                --i;
            }

            if (i < 0) {
                for (int j = 1; j < 10; ++j) {
                    if (!bad[j]) {
                        s = string(1, (char)('0' + j));
                        break;
                    }
                }
                s += string(n, (char)('0' + mn));
            }

            break;
        }
    }


    cout << s << '\n';


    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    int alice = 0;
    int bob = 0;
    for (int i=0; i<n; i++) {
        if (i%2==0) alice += a.at(i);
        else bob += a.at(i);
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll t,f;
char c;
vector <char> mae,ushi;
int main(){
  ll q,a,b,ans=-1;
  string s;
  cin>>s;
  cin>>q;
  ll upside=1;
  rep(i,0,q){
    cin>>t;
    if(t==1)upside*=-1;
    else {
      cin>>f>>c;
      if(f==1){
        if(upside==1)mae.pb(c);
        else ushi.pb(c);
      }
      else{
        if(upside==1)ushi.pb(c);
        else mae.pb(c);
      }
    }
  }

  if(upside==-1){
    irep(i,ushi.size()-1,0)cout<<ushi[i];
    irep(j,s.length()-1,0)cout<<s[j];
    rep(k,0,mae.size())cout<<mae[k];
  }
  else {
    irep(i,mae.size()-1,0)cout<<mae[i];
    rep(j,0,s.length())cout<<s[j];
    rep(k,0,ushi.size())cout<<ushi[k];
  }
 
}

Measured memory_bytes: 1024
/*
 * Ref: http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf
 *
 * LCA (Lowest Common Ancestor), Doubling
 * O((N+Q)log N)
 */
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

int x[100005];
map<int, int> city_x_map; //  city, x_i

int r[18][100005]; // r[k][i]: hotel number, which we can reach from i-th hotel within 2^k days. (2^17 > 100005)

// assuming a <= b
ll calcDay(int a, int b) {
    ll day = 0;
    while (true) {
        if (a == b) { return day; }

        int k = 0;
        while(r[k][a] < b) {
            k++;
            //cout << "k " << k << ",a " << a << ", r[k][a] " << r[k][a] << endl;
        }
        // now r[k][a] >= b, update a and day
        if (k == 0) {
            return day+1LL;
        } else {
            a = r[k-1][a];
            day += (1LL << (k - 1));
        }
    }
}

int main(){
    //freopen("e.in", "r", stdin);
    int n;
    int L;
    int Q;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
        city_x_map.insert(make_pair(i+1, x[i]));
    }
    cin >> L;
    cin >> Q;

    sort(x, x+n);

    // Prepare r[k][i] using doubling
    for (int i = 0; i < n; ++i) {
        r[0][i] = (int)(upper_bound(x, x+n, x[i]+L) - x) - 1;
    }
    int maxK = 0;
    while (n >> maxK > 0) maxK++;
    for (int k = 0; k < maxK; ++k) {
        for (int i = 0; i < n; ++i) {
            r[k+1][i] = r[k][r[k][i]];
        }
    }

    // solve
    for (int j = 0; j < Q; ++j) {
        int a, b;     // original hotel number
        int axi, bxi; // hotel x coordinate
        cin >> a >> b;
        axi = city_x_map[a];
        bxi = city_x_map[b];

        if (axi > bxi) { swap(axi, bxi); }

        a = lower_bound(x, x+n, axi) - x;  // sorted hotel number
        b = lower_bound(x, x+n, bxi) - x;  // sorted hotel number

        //cout << a << " " << b << endl; // debug

        ll day = calcDay(a, b);

        cout << day << endl;
    }
    return 0;
}


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

int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<string, bool> M;
  while (n--) {
    string op, e;
    cin >> op >> e;
    if (op == "insert") {
      M[e] = true;
    } else if (op == "find") {
      if (M[e])
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}



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

typedef long long int ll;
typedef long int li;

const ll mod = 1000000007;
const ll inf = 1000000000000000000;

typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vli> vvli;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef map<ll, ll> mll;
typedef map<ll, string> mls;
typedef map<string, ll> msl;

#pragma GCC optimize ("-O3")
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define PI 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define all(v) v.begin(), v.end()
#define FOR(i, j, k, in) for(li i=j; i<k; i+=in)
#define RFOR(i, j, k, de) for(li i=j; i>=k; i-=de)
#define rep(i,j,k) FOR(i, j, k, 1)
#define rrep(i,j,k) RFOR(i, j, k, 1)
#define repc(v) for(auto it=v.begin(); it!=v.end(); it++)
#define T ll t; cin>>t; while(t--)

int main(){
  FAST

  ll n,m;
  cin>>n>>m;
  
  ll a,b;
  if(n==1)
    a=0;
  else{
    a=n*(n-1)/2;
  }
  
  if(m==1)
    b=0;
  else{
    b=m*(m-1)/2;
  }
  
  cout<<a+b;
  
  return 0;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define x first
#define y second
const int N = 100010;

int n;
ll c , x[N], v[N], suf[N], pre[N];

int main() {
	cin >> n >> c;
	for (int i = 1; i <= n; ++i) {
		cin >> x[i] >> v[i];
	}
	ll cur = 0, prev = c;
	for (int i = n ; i >= 1 ; --i) {
		cur += v[i] - abs(prev - x[i]);
		suf[i] = cur;
		prev = x[i];
	}
	for (int i = n ; i >= 1 ; --i) {
		suf[i] = max(suf[i + 1], suf[i]);
	}
	ll mx = suf[1];
	cur = 0;
	prev = 0;
	for (int i = 1 ; i <= n ; ++i) {
		cur += v[i] - abs(prev - x[i]);
		mx = max(mx, cur + max(0ll, suf[i + 1] - x[i]));
		prev = x[i];
	}
	cur = 0, prev = 0;
	for (int i = 1 ; i <= n ; ++i) {
		cur += v[i] - abs(prev - x[i]);
		pre[i] = cur;
		prev = x[i];
	}
	for (int i = 1 ; i <= n ; ++i) {
		pre[i] = max(pre[i - 1], pre[i]);
	}
	cur = 0;
	prev = c;
	for (int i = n ; i >= 1 ; --i) {
		cur += v[i] - abs(prev - x[i]);
		mx = max(mx, cur + max(0ll, pre[i - 1] - abs(c - x[i])));
		prev = x[i];
	}
	mx = max(mx, pre[n]);
	mx = max(mx, 0ll);
	cout << mx << endl;

	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mod 1e9+5
#define mx 200005
//#define inf 2e9
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
const int inf = 1e9+5;
//i  = current stair
int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    int dp[n];
    for(int i=0;i<n;i++)
        dp[i] = inf;
    dp[0] = 0;
    for(int i=0;i<n;i++)
    {
        for(int j= (i+1);j<=(i+2);j++)
        {
            if(j<n)
            {
                dp[j] = min(dp[j],(abs(h[j]-h[i]) + dp[i]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();int b=sc.nextInt();int c=sc.nextInt();int k=sc.nextInt();
        int tmp=0;
        while(b<=a){
                b*=2;
                tmp++;
            }
        while(c<=b){
                c*=2;
                tmp++;
            }
        if (tmp<=k)
            System.out.println("Yes");
        else
            System.out.println("No");



    }
    }


Measured memory_bytes: 26984
N, M = map( int, input().split())
A = ['']*N
B = ['']*M
for i in range(N):
    a = input()
    A[i] = a
for i in range(M):
    b = input()
    B[i] = b
k=N-M+1
ans = 'No'
for i in range(k):
    for j in range(k):
        now = 1
        for l in range(M):
            if not A[i+l][j:j+M] == B[l]:
                now = -1
                break
        if now == 1:
            ans = 'Yes'
            break
    if ans == 'Yes':
        break
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
using namespace std;
int main()
{
	string s;
	int i;
	bool b=0;
	cin>>s;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='C')
		b=1;
		if(s[i]=='F'&&b)
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <map>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){

map <string,int> score;

string s;

int n;
cin >> n;

for(int i = 0; i < n; i++){
cin >> s;
score[s] ++;
}

int m;
cin >> m;
for(int i = 0; i < m; i++){
cin >> s;
score[s] --;
}

int ans = 0;
for(auto itr = score.begin(); itr != score.end(); ++itr) {
ans = max(ans,itr -> second);
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define SIZE 100001

int main(){
  int n;
  scanf("%d", &n);

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

  while(1){
    int flag = 1;
    for(int i=1; i<n; i++){
      if(t[i-1]>t[i]){
	int tmp;
	tmp = t[i]; t[i] = t[i-1]; t[i-1] = tmp;
	tmp = x[i]; x[i] = x[i-1]; x[i-1] = tmp;
	tmp = y[i]; y[i] = y[i-1]; y[i-1] = tmp;
	flag = 0;
      }
    }
    if(flag) break;
  }
  
  for(int i=0; i<n; i++){
    int yoko = x[i-1] - x[i]; if(yoko<0) yoko=-yoko;
    int tate = y[i-1] - y[i]; if(tate<0) tate=-tate;
    int jikan = t[i] - t[i-1];
    if(i==0){
      yoko = x[i]; 
      tate = y[i]; 
      jikan = t[i];
    }
    //    printf("yoko+tate=%d, jikan=%d\n", yoko+tate, jikan);

    if(yoko+tate == jikan){
      continue;
    }
    else if(yoko+tate > jikan){
      printf("No\n");
      return 0;
    }
    else{
      if((jikan-yoko-tate)%2==1){
	printf("No\n");
	return 0;
      }
      else{
	continue;
      }
    }
  }

  printf("Yes\n");
  
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)

int main() {
  char c;cin>>c;
  string vowel = "aeiou";
  bool ans = false;
  rep(i,5) if(vowel[i]==c) ans=true;
  cout << (ans?"vowel":"consonant") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
int y[100010];
int p[100010];
pair<int,int> yi[100010];
int number[100010];
int cnt[100010];
int main(){ _;
  int n,m;cin>>n>>m;
  REP(i,m){
    cin>>p[i]>>y[i];
    yi[i]=make_pair(y[i],i);
  }
  sort(yi,yi+m);
  REP(i,m){
    //    cout<<yi[i].first<<endl;
    int index=yi[i].second;
    int pref=p[index];
    number[index]=++cnt[pref];
  }
  REP(i,m){
    cout<<setfill('0')<<setw(12)<<right<<(p[i]*1000000LL+number[i])<<endl;
  }
}


Measured memory_bytes: 3840
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  int b = 0, a = 0, ba = 0, ans = 0;
  while (n--) {
    string s; cin >> s;
    for (int i = 0; i < s.length(); ++i) {
      if (i < s.length() && s[i] == 'A') {
        if (i + 1 < s.length() && s[i + 1] == 'B') ++ans;
      }
    }
    if (s.front() == 'B') {
      if (s.back() == 'A') ++ba;
      else ++b;
    } else if (s.back() == 'A') {
      ++a;
    }
  }
  string tmp = "";
  if (a > 0) {
    tmp += 'A';
    --a;
  }
  REP(i, ba) tmp += "BA";
  if (b > 0) {
    tmp += 'B';
    --b;
  }
  ans += min(a, b);
  for (int i = 0; i < tmp.length(); ++i) {
    if (i < tmp.length() && tmp[i] == 'A') {
      if (i + 1 < tmp.length() && tmp[i + 1] == 'B') ++ans;
    }
  }
  cout << ans << '\n';
  return 0;
}


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

int main(){
	int n,k;
	cin>>n>>k;
	if(n%k)cout<<1<<endl;
	else cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
a = Array.new(4, 0)

10.times do
  a[3] = gets.chomp.to_i
  3.times do |i|
    if a[2-i] < a[3-i]
      a[2-i], a[3-i] = a[3-i], a[2-i]
    else
      break
    end
  end
end

print a[0], "\n", a[1], "\n", a[2], "\n"

Measured memory_bytes: 6092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 2000010
#define P 1000000007
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,a[N],s[N],id[N],nxt[N],p[N],b[N],f[N][2],m,ans;
int ksm(int a,int k)
{
	int s=1;
	for (;k;k>>=1,a=1ll*a*a%P) if (k&1) s=1ll*s*a%P;
	return s; 
}
void inc(int &x,int y){x+=y;if (x>=P) x-=P;}
int solve(int x)
{
	if (p[x]<=n)
	{
		id[m=1]=p[x];
		while (nxt[id[m]]<=n) id[m+1]=nxt[id[m]],m++;
	}
	else return 0;
	int t=0;
	for (int i=1;i<=m;i++)
	{
		b[++t]=-1;
		if (i<m) b[++t]=s[id[i+1]]-s[id[i]];
	}
	f[0][0]=1;
	for (int i=1;i<=t;i++)
	{
		f[i][0]=f[i][1]=0;
		if (b[i]==-1)
		{
			f[i][0]=f[i-1][0];
			f[i][1]=(f[i-1][1]+f[i-1][0])%P;
		}
		else
		{
			f[i][1]=f[i-1][1];
			f[i][0]=(f[i-1][0]+1ll*f[i-1][1]*b[i])%P;
		}
	}
	return f[t][1];
}
int solve2(int x)
{
	if (p[x]<=n)
	{
		id[m=1]=p[x];
		while (nxt[id[m]]<n) id[m+1]=nxt[id[m]],m++;
	}
	else return 0;
	int t=0;id[m+1]=n;
	for (int i=1;i<=m;i++)
	{
		b[++t]=-1;
		b[++t]=s[id[i+1]]-s[id[i]];
	}
	f[0][0]=1;
	for (int i=1;i<=t;i++)
	{
		f[i][0]=f[i][1]=0;
		if (b[i]==-1)
		{
			f[i][0]=f[i-1][0];
			f[i][1]=(f[i-1][1]+f[i-1][0])%P;
		}
		else
		{
			f[i][1]=f[i-1][1];
			f[i][0]=(f[i-1][0]+1ll*f[i-1][1]*b[i])%P;
		}
	}
	return f[t][0];
}
signed main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=a[i-1]^read();
	for (int i=1;i<=n;i++)
	{
		s[i]=s[i-1];
		if (a[i]==0) s[i]++;
	}
	for (int i=0;i<(1<<20);i++) p[i]=n+1;
	for (int i=n;i>=1;i--)
	{
		nxt[i]=p[a[i]];
		p[a[i]]=i;
	}
	if (a[n]==0)
	{
		ans=ksm(2,s[n]-1);
		for (int i=1;i<(1<<20);i++) inc(ans,solve(i));
	}
	else ans=solve2(a[n]);
	cout<<ans;
	return 0;
	//NOTICE LONG LONG!!!!!
}

Measured memory_bytes: 30976
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,a,b,temp;
    cin>>x>>a>>b;
    temp=a-b;
    if(temp>=0)
    {
        cout<<"delicious";
    }
    else
    {
        temp=abs(temp);
        temp=x-temp;
        if(temp>=0)
            cout<<"safe";
        else
            cout<<"dangerous";
    }
    return 0;
}


Measured memory_bytes: 3568
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A, B;
    cin >> A >> B;
    
    int ans = 0;
    
    ans = max(ans, A + A - 1);
    ans = max(ans, B + B - 1);
    ans = max(ans, A + B);
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define mod MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    int n; cin >> n;
    string s, t; cin >> s >> t;
    int cnt = 0;
    bool flag;
    for(int i = 1; i <= n; i++){
        flag = true;
        for(int j = 0; j < i; j++){
            if(s[n-i+j] != t[j]) flag = false;
        }
        if(flag) cnt = i;
    }
    cout << n*2 - cnt << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int m = 0;
  for (int t = n; t; t /= 10) m += t % 10;
  cout << (n % m ? "No" : "Yes") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> PP;

const ll MOD = 1000000007;

ll dp[2][304][304];

int main()
{
    int n, m;
    cin >> n >> m;
    PP p[304];
    for(int i = 0; i < m; i++){
        int l, r, x;
        cin >> l >> r >> x;
        p[i] = PP(P(r, l), x);
    }
    sort(p, p + m);
    int l = 0;
    dp[0][0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < i; j++){
            for(int k = 0; k < j; k++){
                dp[i % 2][j][k] = dp[(i + 1) % 2][j][k];
            }
        }
        for(int j_ = 0; j_ < i; j_++){
            for(int k = 0; k < j_; k++){
                dp[i % 2][i - 1][k] = (dp[i % 2][i - 1][k] + dp[(i + 1) % 2][j_][k]) % MOD;
            }
        }
        for(int k = 0; k < i; k++){
            for(int k_ = 0; k_ < k; k_++){
                dp[i % 2][i - 1][k] = (dp[i % 2][i - 1][k] + dp[(i + 1) % 2][k][k_]) % MOD;
            }
        }
        if(i != 1){
            dp[i % 2][i - 1][0] = (dp[i % 2][i - 1][0] + dp[(i + 1) % 2][0][0] * 2) % MOD;
            dp[i % 2][0][0] = dp[(i + 1) % 2][0][0];
        }
        else dp[i][0][0] = 3;
        while(p[l].first.first == i){
            if(p[l].second == 1){
                for(int j = 0; j <= i; j++){
                    for(int k = 0; k <= j; k++){
                        if(j >= p[l].first.second) dp[i % 2][j][k] = 0;
                    }
                }
            }
            else if(p[l].second == 2){
                for(int j = 0; j <= i; j++){
                    for(int k = 0; k <= j; k++){
                        if(j < p[l].first.second || k >= p[l].first.second) dp[i % 2][j][k] = 0;
                    }
                }
            }
            else{
                for(int j = 0; j <= i; j++){
                    for(int k = 0; k <= j; k++){
                        if(k < p[l].first.second){
                            dp[i % 2][j][k] = 0;
                        }
                    }
                }
            }
            l++;
        }
    }
    ll ans = 0;
    for(int j = 0; j <= n; j++){
        for(int k = 0; k <= j; k++) ans = (ans + dp[n % 2][j][k]) % MOD;
    }
    cout << ans << endl;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  int n;
  cin >> n;
  vector <double> p (n + 1);
  for (int i = 1; i <= n; i++) cin >> p[i];
  vector <vector <double> > dp (n + 1, vector <double> (n + 1, 0.0));
  dp[0][0] = 1.0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      if(j) dp[i][j] += dp[i - 1][j - 1] * p[i];
      dp[i][j] += dp[i - 1][j] * (1 - p[i]);
    }
  }
  double ans = 0.0;
  for (int i = 1; i <= n; i++) {
    if (i > n - i) ans += dp[n][i];
  }
  cout << setprecision(10) << fixed;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 70784
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)

for cx in range(0,101):
    for cy in range(0,101):
        x,y,h=xyh[0]
        H=h+abs(x-cx)+abs(y-cy)
        if H<0:
            continue

        for i in range(1,n):
            x,y,h=xyh[i]

            if h!=max(H-abs(x-cx)-abs(y-cy),0):
                break
        else:
            print('{} {} {}'.format(cx,cy,H))
            exit(0)

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

#define EPS 1e-7

typedef struct {
	char name[21];
	double efficiency;
} Rec;

int compare(const void *a, const void *b) {
	double ta = ((Rec *)a)->efficiency, tb = ((Rec *)b)->efficiency;

	if (fabs(ta - tb) < EPS)
		return strcmp(((Rec *)a)->name, ((Rec *)b)->name);
	else if (tb < ta)
		return -1;
	else
		return 1;
}

Rec rec[50];

int main(void) {
	int i;
	int n;

	while (scanf("%d", &n), n) {
		for (i = 0; i < n; i++) {
			double p, a, b, c, d, e, f, s, m;
			double income, t;

			scanf("%s %lf %lf %lf %lf %lf %lf %lf %lf %lf", rec[i].name, &p, &a, &b, &c, &d, &e, &f, &s, &m);
			income = f * m * s - p;
			t = a + b + c + (d + e) * m;

			rec[i].efficiency = income / t;
		}

		qsort(rec, n, sizeof(Rec), &compare);

		for (i = 0; i < n; i++)
			puts(rec[i].name);
		puts("#");
	}

	return 0;
}

Measured memory_bytes: 664
n=int(input())
a=list(map(int,input().split()))

hh=a[0]
hsum=0
for i in range(n):
    if a[i]<hh:
        dh=hh-a[i]
        hsum+=dh
    else:
        hh=a[i]
    
print(hsum)    
    

Measured memory_bytes: 32352
N = gets.chomp.to_i
A = gets.split(" ")
B = gets.split(" ")
C = gets.split(" ")
A.map!{|item| item.to_i}
B.map!{|item| item.to_i}
C.map!{|item| item.to_i}
sum  = 0
for i in 0..(N-1)
    sum += B[A[i]-1]
    if i > 0
        if A[i]-1 == A[i-1]
            sum += C[A[i-1]-1]
        end
    end
end
puts sum

Measured memory_bytes: 3836