akhauriyash/Code-Regression huggingface dataset:
import Data.Maybe (fromJust)

main = interact $ unlines.map encode.lines

encode :: String -> String
encode = map (toChar.correctLength) . devide5 . concat . map toDigits

toDigits :: Char -> String
toDigits c = fromJust $ lookup c cdTable

devide5 :: String -> [String]
devide5 xs = if length xs > 5 then l : devide5 r
                              else [xs]
                              where (l,r) = splitAt 5 xs

toChar :: String -> Char
toChar str = fromJust $ lookup str dcTable

correctLength xs = if length xs == 0 then xs
                                     else xs ++ replicate (5 - length xs) '0'

cdTable = [ (' ' , "101")
          , ('\'', "000000")
          , (',' , "000011")
          , ('-' , "10010001")
          , ('.' , "010001")
          , ('?' , "000001")
          , ('A' , "100101")
          , ('B' , "10011010")
          , ('C' , "0101")
          , ('D' , "0001")
          , ('E' , "110")
          , ('F' , "01001")
          , ('G' , "10011011")
          , ('H' , "010000")
          , ('I' , "0111")
          , ('J' , "10011000")
          , ('K' , "0110")
          , ('L' , "00100")
          , ('M' , "10011001")
          , ('N' , "10011110")
          , ('O' , "00101")
          , ('P' , "111")
          , ('Q' , "10011111")
          , ('R' , "1000")
          , ('S' , "00110")
          , ('T' , "00111")
          , ('U' , "10011100")
          , ('V' , "10011101")
          , ('W' , "000010")
          , ('X' , "10010010")
          , ('Y' , "10010011")
          , ('Z' , "10010000")]

dcTable = [ ("00000",'A')
          , ("00001",'B')
          , ("00010",'C')
          , ("00011",'D')
          , ("00100",'E')
          , ("00101",'F')
          , ("00110",'G')
          , ("00111",'H')
          , ("01000",'I')
          , ("01001",'J')
          , ("01010",'K')
          , ("01011",'L')
          , ("01100",'M')
          , ("01101",'N')
          , ("01110",'O')
          , ("01111",'P')
          , ("10000",'Q')
          , ("10001",'R')
          , ("10010",'S')
          , ("10011",'T')
          , ("10100",'U')
          , ("10101",'V')
          , ("10110",'W')
          , ("10111",'X')
          , ("11000",'Y')
          , ("11001",'Z')
          , ("11010",' ')
          , ("11011",'.')
          , ("11100",',')
          , ("11101",'-')
          , ("11110",'\'')
          , ("11111",'?')]


Measured memory_bytes: 4256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    vector<ll> v(3);
    for (ll i = 0; i < 3; i++)
    {
        cin >> v[i];
    }
    sort(ALL(v));
    ll s = v[0] * v[1];
    cout << s * (v[2] - v[2] / 2 * 2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> s(N, 0);
  for (int i=1; i<N; i++){
    cin >> s.at(i);
  }
  vector<int> result(N, 0);
  for (int i=1; i<N; i++){
    result.at(s.at(i)-1) += 1;
  }
  for (int i=0; i<N; i++){
    cout << result.at(i) << endl;
  }
  return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
unsigned long long p[90],n;
int main(){
	p[0]=2;
	p[1]=1;
	scanf("%llu",&n);
	if(n<2){
		printf("%llu\n",p[n]);
		return 0;
	}
	for(register int i=2;i<=n;i++){
		p[i]=p[i-1]+p[i-2];
	}
	printf("%llu\n",p[n]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using std::setprecision;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::min;
using std::max;
using std::fill;
using std::max_element;
using std::min_element;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
//#define double long double

const long long MOD = 1e9 + 7;
const long long inf = 1e18;
const long long infsmart = 1e12;

long long n, k;
long long p1;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (a == 1)
            p1 = i;
    }
    ll ans = 1e9;
    for (int l = 0; l + k - 1 < n; l++)
    {
        if (l <= p1 && p1 <= l + k - 1)
        {
            //cout << l << " " << l + k - 1 << endl;
            //cout << (l + k - 2) / (k - 1) << " " << (n - l - 2) / (k - 1) << endl;
            ans = min(ans, (l + k - 2) / (k - 1) + 1 + (n - l - 2) / (k - 1));
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int main() {
  
  while ( true ) {
	int n, k;
	cin >> n >> k;
	if ( n == 0 && k == 0 ) break;

	vector<int> s( k ), sum( k );
	for ( int i = 0; i < k; i++ ) {
	  cin >> s[ i ];
	}
	
	for ( int i = 0; i < n; i++ ) {
	  for ( int j = 0; j < k; j++ ) {
		int val;
		cin >> val;
		sum[ j ] += val;
	  }
	}
	bool success = true;
	for ( int i = 0; success && i < k; i++ ) {
	  if ( s[ i ] < sum[ i ] ) {
		success = false;
	  }
	}
	if ( success ) {
	  cout << "Yes" << endl;
	} else {
	  cout << "No" << endl;
	}
  }  
}

Measured memory_bytes: 1188
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let a: Vec<_> = it.next().unwrap().bytes().rev().collect();
    let mut counts = vec![vec![0usize; 26]; a.len() + 1];
    for i in 0..a.len() {
        for c in 0..26 {
            counts[i + 1][c] = counts[i][c] + if a[i] == (b'a' + c as u8) { 1 } else { 0 };
        }
    }
    let mut cur = 1usize;
    for i in 0..a.len() {
        for c in 0..26 {
            if c != a[i] - b'a' {
                cur += counts[i][c as usize]
            }
        }
    }
    println!("{}", cur);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 55548
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

#define fst first
#define snd second

typedef long long llint;
typedef pair<int, int> pii;

const int MAXN = 2e5+10;

int n, A, B;
int a[MAXN];

bool check(int N, int K) {
  return K == N - 1 || 2 * K <= N;
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &a[i]);

  sort(a, a + n);

  for (int i = 0; i < n; ++i) {
    A += a[i] == a[0];
    B += a[i] == a[n - 1];
  }

  if (A == n && B == n) {
    if (check(n, a[0]))
      printf("Yes\n");
    else
      printf("No\n");
    return 0;
  }

  if (A + B != n) {
    printf("No\n");
    return 0;
  }

  if (a[0] >= A && a[0] + 1 == a[n - 1] && 2 * (a[0] - A + 1) <= B)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct frac {
  int c0, c1;
  frac(int c0 = 0, int c1 = 0) : c0(c0), c1(c1) {}
  bool operator < (const frac &d) const {
    return (ll) c0 * d.c1 < (ll) d.c0 * c1;
  }
  frac operator + (const frac &d) const {
    return frac(c0 + d.c0, c1 + d.c1);
  }
};
const int N = 200010;
frac r[N];
priority_queue<pair<frac, int>> q;
int n, par[N], f[N];
ll ans = 0;
int F(int x) {
  while (x != f[x]) x = f[x] = f[f[x]];
  return x;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &par[i]);
  }
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    if (x == 0) {
      r[i] = frac(1, 0);
    } else {
      r[i] = frac(0, 1);
    }
    if (i > 1) q.push(make_pair(r[i], i));
    f[i] = i;
  }
  while (!q.empty()) {
    int v = q.top().second;
    frac d = q.top().first;
    q.pop();
    if (v != F(v) || d.c0 != r[v].c0 || d.c1 != r[v].c1) continue;
    int u = F(par[v]);
    f[v] = u;
    ans += (ll) r[u].c1 * r[v].c0;
    r[u] = r[u] + r[v];
    if (u != 1) q.push(make_pair(r[u], u));
  }
  printf("%lld\n", ans);
}


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

int x,y;

struct grid{
  char g[11][11];
  int count;
};

void DFS(grid& gr,char firstcell,char changecolor,int posx,int posy){

  if(posx < 0 || posx >= x  || posy < 0 || posy >= y || gr.g[posx][posy] != firstcell){
  //if(gr.g[posx][posy] != firstcell){
    return;
  }

  gr.g[posx][posy] = changecolor;

  DFS(gr,firstcell,changecolor,posx+1,posy);
  DFS(gr,firstcell,changecolor,posx-1,posy);
  DFS(gr,firstcell,changecolor,posx,posy+1);
  DFS(gr,firstcell,changecolor,posx,posy-1);
}

int main(){

  while(1){

    cin >> x >> y;

    if(x==0 && y==0){
      break;
    }

    grid start;

    for(int i=0; i<y; i++){
      for(int j=0; j<x; j++){
        cin >> start.g[j][i];
      }
    }

    char firstcell = start.g[0][0];

    bool flag = true;

    for(int i=0; i<y; i++){
      for(int j=0; j<x; j++){
        if(start.g[j][i]!=firstcell){
          flag = false;
          break;
        }
      }
      if(!flag){
        break;
      }
    }
    if(flag){
      cout << 0 << endl;
      continue;
    }

    start.count = 0;

    queue<grid> q;

    q.push(start);

    while(1){

      grid BeforeGrid = q.front();
      q.pop();

      BeforeGrid.count++;

      grid tmp = BeforeGrid;

      firstcell  = tmp.g[0][0];

      if(firstcell != 'R'){
          DFS(tmp,firstcell,'R',0,0);

          flag = true;
          for(int i=0; i<y; i++){
            for(int j=0; j<x; j++){
              if(tmp.g[j][i]!='R'){
                flag = false;
                break;
              }
            }
            if(!flag){
              break;
            }
          }
          if(flag){
            cout << tmp.count << endl;
            break;
          }

          q.push(tmp);
          tmp = BeforeGrid;
      }

      if(firstcell != 'G'){
          DFS(tmp,firstcell,'G',0,0);

          flag = true;
          for(int i=0; i<y; i++){
            for(int j=0; j<x; j++){
              if(tmp.g[j][i]!='G'){
                flag = false;
                break;
              }
            }
            if(!flag){
              break;
            }
          }
          if(flag){
            cout << tmp.count << endl;
            break;
          }

          q.push(tmp);
          tmp = BeforeGrid;
      }

      if(firstcell != 'B'){
          DFS(tmp,firstcell,'B',0,0);

          flag = true;
          for(int i=0; i<y; i++){
            for(int j=0; j<x; j++){
              if(tmp.g[j][i]!='B'){
                flag = false;
                break;
              }
            }
            if(!flag){
              break;
            }
          }
          if(flag){
            cout << tmp.count << endl;
            break;
          }

          q.push(tmp);
      }

    }






  }


    return 0;
}

Measured memory_bytes: 18624
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	ll ans=0;
	while(a<=b)a*=2,ans++;
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
/*
 * atcoder/abc097_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

string S;
int K, N;
void solve() {
  cin >> S >> K;
  N = S.size();
  vector<string> subs;
  for (int len=1; len<=K; len++) {
    for (int l=0; l+len<=N; l++) {
      subs.push_back(S.substr(l, len));
    }
  }
  sort(subs.begin(), subs.end());
  unique(subs.begin(), subs.end());
  cout << subs[K-1] << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


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

kind = [i + 1 for i in range( N )]
taste = [i + L for i in range( N )]
taste_abs = [abs(i + L) for i in range( N )]

cnt =0

for i in taste:
    if i<0:
        cnt +=1
        
if cnt ==N:
    print(sum(taste) + min(taste_abs))
else:
    print(sum(taste) - min(taste_abs))

Measured memory_bytes: 3064
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int N;
	ll x;
	cin >> N >> x;
	vector<ll> a(N);
	REP(i, N) cin >> a[i];
	sort(a.begin(), a.end());
	int res = 0;
	ll sum = 0;
	while(res < N && sum + a[res] <= x) {
		sum += a[res];
		if (res == N - 1 && sum < x) break;
		res++;
	}
	cout << res << "\n";

	return 0;
}
		

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

int main(void){
   int x,a,b;
   cin>>x>>a>>b;
   int dist_1=abs(x-a);
   int dist_2=abs(x-b);
   if(dist_1<dist_2) cout<<"A"<<endl;
   else cout<<"B"<<endl;
   return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    if (a == b) {
        cout << 0 << endl;
        return 0;
    }
    ll sum = accumulate(all(a), 0LL);
    ll bmin = LONG_LONG_MAX;
    rep(i, n) {
        if (a[i] > b[i]) {
            bmin = min(bmin, b[i]);
        }
    }
    cout << (sum - bmin) << endl;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
//cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);

struct node{
    int key;
    node *parent,*left,*right;
};

node *root,*NIL;

void insert(int k){
    node *y=NIL;
    node *x=root;
    node *z;

    z=(node*)malloc(sizeof(node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;

    while(x!=NIL){
        y=x;
        if(z->key<x->key){
            x=x->left;
        }else{
            x=x->right;
        }
    }

    z->parent=y;

    if(y==NIL){
        root=z;
    }else{
        if(z->key<y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
}

node *find(node *u,int k){
    while(u!=NIL&&u->key!=k){
        if(k<u->key){
            u=u->left;
        }else{
            u=u->right;
        }
    }
    return u;

}

void preorder(node *u){
    if(u==NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

void inorder(node *u){
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

int main() {
    int n,x;
    string s;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin>>s;
        if(s=="insert"){
            scanf("%d",&x);
            insert(x);
        }else if(s=="find"){
            scanf("%d",&x);
            node *t=find(root,x);
            if(t!=NIL){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }else if(s=="print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}






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

int main() {
  double Ans = 0;  // 回答：
  int R; cin >> R;  // 半径

  // cout << Ans << setprecision(7);	// 計算前に桁数指定
  Ans = R * 2 * 3.1415926;

  cout << Ans << endl;
}


Measured memory_bytes: 3768
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	    while (true) {
		    String[] line = br.readLine().split(" ");

		    int n = Integer.parseInt(line[0]);
		    int x = Integer.parseInt(line[1]);

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

		    int resultCount = 0;
		    for (int i = 1; i <= n; i++) {
		    	for (int j = i + 1; j <= n; j++) {
		    		for (int k = j + 1; k <= n; k++) {

		    			if (i + j + k == x) {
		    				resultCount++;
		    			}
		    		}
		    	}
		    }
		    System.out.println(resultCount);
	    }
	}
}

Measured memory_bytes: 24968
def Main(S, T, A, B, U):
    if(U == S):
        return str(A-1) + " " + str(B)
    else:
        return str(A) + " " + str(B-1)

def main():
    S, T = list(map(str, input().split()))
    A, B = list(map(int, input().split()))
    U = str(input())
    print(Main(S, T, A, B, U))

if __name__ == '__main__':
    main()

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

using namespace std;

using i64 = int64_t;
const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){
    int h, n;
    cin >> h >> n;
    vector<bitset<8>> bs(h);
    for(int i = 0; i < n; ++i){
        int x, y;
        cin >> y >> x;
        bs[x].set(y);
        if(x)
            bs[x - 1].set(y + 4);
    }


    vector<pair<int, int>> mask_vec{
        make_pair(bitset<8>("00000000").to_ulong(), 0),
        make_pair(bitset<8>("11001100").to_ulong(), 1),
        make_pair(bitset<8>("01100110").to_ulong(), 1),
        make_pair(bitset<8>("00110011").to_ulong(), 1),
        make_pair(bitset<8>("11111111").to_ulong(), 2)
    };

    vector<vector<int>> dp(h, vector<int>(256, 0));
    for(int i = 0; i < h - 1; ++i){
        for(int j = 0; j < 256; ++j){
            if(j & bs[i].to_ulong())
                continue;
            for(auto& mask : mask_vec){
                if((j | bs[i].to_ulong()) & mask.first)
                    continue;
                int nex = (j | mask.first) >> 4;
                dp[i + 1][nex] = max(dp[i + 1][nex], dp[i][j] + mask.second);
            }
        }
    }
    int ans = 0;
    for(int j = 0; j < 256; ++j){
        if((j & bs.back().to_ulong()) == 0)
            ans = max(ans, dp.back()[j]);
    }
    cout << ans << endl;

}



Measured memory_bytes: 13356
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int conv_int(string s){
  int len = s.length();
  int res = 0;
  int last = -1;
  REP(i,len){
    if(s[i] == 'm'){
      if(last == -1) res += 1000;
      else res += last * 1000;
      last = -1;
    }else if(s[i] == 'c'){
      if(last == -1) res += 100;
      else res += last * 100;
      last = -1;
    }else if(s[i] == 'x'){
      if(last == -1) res += 10;
      else res += 10 * last;
      last = -1;
    }else if(s[i] == 'i'){
      if(last == -1) res += 1;
      else res += last;
      last = -1;
    }else{
      last = s[i] -'0';
    }
  }
  return res;
}

string conv_str(int n){
  string res = "";

  if(n >= 1000){
    int num = n / 1000;
    if(num > 1){
      res += to_string(num);
    }
    res += "m";
  }
  n %= 1000;
  if(n >= 100){
    int num = n / 100;
    if(num > 1){
      res += to_string(num);
    }
    res += "c";
  }
  n %= 100;
  if(n >= 10){
    int num = n / 10;
    if(num > 1){
      res += to_string(num);
    }
    res += "x";
  }
  n %= 10;
  if(n > 0){
    if(n > 1){
      res += to_string(n);
    }
    res += "i";
  }
  return res;
}

int main(){

  int n;
  cin >> n;
  REP(ii,n){
    string s1, s2;
    cin >> s1 >> s2;
    int num = conv_int(s1) + conv_int(s2);
    cout << conv_str(num) << endl;
  }
  return 0;
}




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

int main(){ 
  int a,b; 
  cin>>a>>b;
  if(a<=0&&b>=0||b<=0&&a>=0){ 
    cout<<"Zero"<<endl;
  }else if(a>0&&b>0){
    cout<<"Positive"<<endl;
  }else if((b-a)%2==1){
    cout<<"Positive"<<endl;
  }else{
    cout<<"Negative"<<endl;
  }
}

Measured memory_bytes: 256
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstdlib>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

typedef long long ll;

using namespace std;

int main(){
    string s;
    cin>>s;
    rp(i,0,s.size()) {
        if (i==4) cout<<" ";
        cout<<s[i];
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	int n;
	string s;
	int ret = 0;
	cin >> n >> s;
	for (int i = 0; i < n - 2; i++) {
		int ok = 1;
		for (int j = 0; j < 3; j++) {
			if (s[i + j] != 'A' + j) {
				ok = 0;
			}
		}
		ret += ok;
	}
	cout << ret << endl;

	return 0;
}


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

int main (){
  
  int A;
  
  int B;
  
  int C;
  
  cin >> A >> B >> C;
  
  if(A > C && B < C || A < C && B > C){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let K: usize = sc.cin();
    let h: Vec<i32> = (0..n).map(|_| sc.cin()).collect();
    let mut d: Vec<i32> = vec![1000000000; n];
    d[0] = 0;
    for j in 1..n {
        for k in 1..K+1 {
            if j >= k {
                d[j] = min(d[j], d[j-k] + (h[j] - h[j-k]).abs());
            }
        }
    }
    // trace!(&d);
    put!(d[n-1]);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int> > data;
vector<bool> used;
pair<int, int> nap[4] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
vector<int> one, two;
void dfs(int vertex, int col){
    used[vertex] = true;
    if (col==0) one.push_back(vertex);
    else two.push_back(vertex);
    for (int i=0; i < data[vertex].size(); i++){
        int to = data[vertex][i];
        if (used[to]) continue;
        dfs(to, 1-col);
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, d1, d2;
    cin >> n >> d1 >> d2;
    for (int i=0; i < 4*n*n; i++){
        vector<int> help;
        data.push_back(help);
        used.push_back(true);
    }
    vector<int> vert;
    for (int i=0; i < 2*n; i++) for (int j=0; j < 2*n; j++) vert.push_back(i*2*n + j);
    vector<pair<int, int> > del;
    for (int i=0; i <= d1; i++){
        int th = d1 - i*i;
        if (th < 0) continue;
        int num = sqrt(th);
        if (num*num==th) del.push_back(make_pair(i, num));
    }
    for (int i=0; i < vert.size(); i++) used[vert[i]] = false;
    vector<int> nv;
    for (int i=0; i < 2*n; i++){
        for (int j=0; j < 2*n; j++){
            int V = 2*n*i + j;
            for (int p=0; p < 4; p++){
                for (int x=0; x < del.size(); x++){
                    int ni = i + nap[p].first * del[x].first;
                    int nj = j + nap[p].second * del[x].second;
                    if (ni < 0 || ni >= 2*n || nj < 0 || nj >= 2*n) continue;
                    data[V].push_back(2*n*ni + nj);
                }
            }
        }
    }
    for (int i=0; i < vert.size(); i++){
        if (!used[vert[i]]){
            one.clear(), two.clear();
            dfs(vert[i], 0);
            if (one.size() < two.size()) swap(one, two);
            for (int j=0; j < one.size(); j++) nv.push_back(one[j]);
        }
    }
    del.clear();
    for (int i=0; i <= d2; i++){
        int th = d2 - i*i;
        if (th < 0) continue;
        int num = sqrt(th);
        if (num*num==th) del.push_back(make_pair(i, num));
    }
    vert = nv;
    for (int i=0; i < vert.size(); i++) used[vert[i]] = false;
    nv.clear();
    for (int i=0; i < 2*n; i++){
        for (int j=0; j < 2*n; j++){
            int V = 2*n*i + j;
            for (int p=0; p < 4; p++){
                for (int x=0; x < del.size(); x++){
                    int ni = i + nap[p].first * del[x].first;
                    int nj = j + nap[p].second * del[x].second;
                    if (ni < 0 || ni >= 2*n || nj < 0 || nj >= 2*n) continue;
                    data[V].push_back(2*n*ni + nj);
                }
            }
        }
    }
    for (int i=0; i < vert.size(); i++){
        if (!used[vert[i]]){
            one.clear(), two.clear();
            dfs(vert[i], 0);
            if (one.size() < two.size()) swap(one, two);
            for (int j=0; j < one.size(); j++) nv.push_back(one[j]);
        }
    }
    for (int i=0; i < n*n; i++){
        int I = nv[i] / (2*n), J = nv[i] % (2*n);
        cout << I << " " << J << endl;
    }
    return 0;
}


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

int main() {
	int n, j, key;
	cin >> n;
	int *a = new int[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++) {
		key = a[i];
		j = i - 1;
		while(( j >= 0) && (a[j] > key)) {
			a[j+1] = a[j];
			j--;
			a[j+1] = key;
		}
		for (int j = 0; j < n-1; j++)
			cout << a[j] << ' ';
		cout << a[n-1] << endl; 
	}
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <unordered_set>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}



int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}

int iabs(int i)
{
    if (i > 0) return i;
    else return -i;
}


int main()
{
    int H, W;
    cin >> H >> W;

    vec_t<int,2> A = make_vec<int,2>(H, W);
    vec_t<int,2> B = make_vec<int,2>(H, W);

    for (int h = 0; h < H; ++h)
        for (int w = 0; w < W; ++w)
            cin >> A[h][w];

    for (int h = 0; h < H; ++h)
        for (int w = 0; w < W; ++w)
            cin >> B[h][w];
   

    vec_t<bool,3> dp = make_vec<bool,3>(H, W, (H+W)*80, false);

    for (int h = 0; h < H; ++h)
    {
        for (int w = 0; w < W; ++w)
        {
            int d = diffabs(A[h][w], B[h][w]);
            if (h == 0 && w == 0)
            {
                dp[h][w][d] = true;
            }
            
            if (w > 0)
            {
                for (size_t i = 0; i < dp[h][w-1].size(); ++i)
                {
                    if (dp[h][w-1][i])
                    {
                        dp[h][w][i+d] = true;
                        dp[h][w][iabs(i-d)] = true;
                    }
                }
            }

            if (h > 0)
            {
                for (size_t i = 0; i < dp[h-1][w].size(); ++i)
                {
                    if (dp[h-1][w][i])
                    {
                        dp[h][w][i+d] = true;
                        dp[h][w][iabs(i-d)] = true;
                    }
                }
            }
        }
    }

    const auto &hw = dp[H-1][W-1];
    auto it = find_if(begin(hw), end(hw), [](auto b){ return b; });
    int ans = std::distance(begin(hw), it);
    cout << ans << endl;
}

Measured memory_bytes: 13932
S=input()
Q_num = int(input())
Q=[]
for _ in range(Q_num):
    Q.append(list(input().split()))
from collections import deque
sento = deque()
matsubi = deque()
mirror_num=0
for q in Q:
    t=q[0]
    if t=='1':
        mirror_num+=1
        continue

    f=int(q[1])
    c=q[2]
    # 反転が偶数回なら反転は無視できる
    if int(mirror_num%2)==0:
        if f==1:
            sento.appendleft(c)
            continue
        matsubi.append(c)
        continue

    if f==1:
        matsubi.append(c)
        continue
    sento.appendleft(c)
    continue

sento = ''.join(sento)
matsubi = ''.join(matsubi)
S_result = sento+S+matsubi
if mirror_num%2==1:
    S_result = S_result[::-1]
print(S_result)




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

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

  

  if (s[0] == s[1] && s[0] != s[2])
  {
    if (s[2] == s[3])
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
  else if (s[0] == s[2] && s[0] != s[1])
  {
    if (s[1] == s[3])
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
    }
  else if (s[0] == s[3] && s[0] != s[1])
  {
    if (s[1] == s[2])
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll T;
    cin >> T;
    rep(i, T){
        ll N;
        cin >> N;
        vector<ll> K(N), L(N), R(N);
        rep(j, N){
            cin >> K.at(j) >> L.at(j) >> R.at(j);
        }
        ll base = 0;
        rep(j, N){
          ll m = min(L.at(j), R.at(j));
          base += m;
          L.at(j) -= m;
          R.at(j) -= m;
        }
        map<ll, vector<ll>> left;
        map<ll, vector<ll>> right;
        ll c = 0;
        rep(j, N){
          if(R.at(j) == 0){
            left[K.at(j)].push_back(L.at(j));
            c++;
          }
          else{
            right[K.at(j)+1].push_back(R.at(j));
          }
        }
        ll ans = base;
        priority_queue<ll> app;
        rep2(k, c+1, N+1){
          rep(l, sz(left[k])){
            app.push(left[k].at(l));
          }
        }
        rep(j, c){
          rep(k, sz(left[c-j])){
            app.push(left[c-j].at(k));
          }
          if(!app.empty()){
            ans += app.top();
            app.pop();
          }
        }
        priority_queue<ll> app2;
        rep(k, c){
          rep(l, sz(right[k+1])){
            app2.push(right[k+1].at(l));
          }
        }
        rep2(j, c+1, N+1){
          rep(k, sz(right[j])){
            app2.push(right[j].at(k));
          }
          if(!app2.empty()){
            ans += app2.top();
            app2.pop();
          }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 44640
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e5;
const ll INF=1e18;
int N;
ll a[MAX_N*3];
ll sm[2][MAX_N+1];
int main(){
	cin>>N;
	REP(i,N*3){
		cin>>a[i];
	}
	priority_queue<ll,vector<ll>,greater<ll> > pque1;
	REP(i,N){
		sm[0][0]+=a[i];
		pque1.push(a[i]);
	}
	REP(i,N){
		sm[0][1+i]=sm[0][i];
		sm[0][1+i]+=a[N+i];
		pque1.push(a[N+i]);
		sm[0][1+i]-=pque1.top();
		pque1.pop();
	}
	priority_queue<ll> pque2;
	REP(i,N){
		sm[1][N]+=a[2*N+i];
		pque2.push(a[N*2+i]);
	}
	REP(i,N){
		sm[1][N-1-i]=sm[1][N-i];
		sm[1][N-1-i]+=a[2*N-i-1];
		pque2.push(a[N*2-i-1]);
		sm[1][N-1-i]-=pque2.top();
		pque2.pop();
	}
	ll ans=-INF;
	REP(i,N+1){
		ans=max(ans,sm[0][i]-sm[1][i]);
	}
	cout<<ans<<endl;
	return 0;
}


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

int main()
{
    ll n, i, sum=0;

    cin>>n;

    for(i=1; i<=n; i++)
    {
        if(i%3==0||i%5==0)continue;
        sum+=i;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3632
using System;

class Program {
  static void Main(string[] args) {
    string[] val = Console.ReadLine().Split();
    int a = int.Parse(val[0]);
    int b = int.Parse(val[1]);
    int c = int.Parse(val[2]);
    int d = int.Parse(val[3]);

    int start = Math.Max(a, c);
    int end = Math.Min(b, d);

    int ans = Math.Max(end - start, 0);

    Console.WriteLine(ans);
  }
}


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

int main(){
	int n;
	cin >> n;
	
	int appear[100002];
	for(int i = 0; i < 100002; i++)	appear[i] = 0;
	
	int a;
	for(int i = 0; i < n; i++){
		cin >> a;
		a++;
		appear[a-1]++;
		appear[a]++;
		appear[a+1]++; 
	}
	
	sort(appear, appear + 100002);
	
	cout << appear[100001] << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iomanip> 
using namespace std; 
#define rep(i,a,b)		for(long int i=a;i<=b;i++)
#define MOD 1e9+7

int ds(int n)
{
	int ans =0;
	while(n)
	{
		ans+=n%10;
		n/=10;
	}
	return ans;
}

int n,a,b,sum=0;
int main() 
{ 
	ios::sync_with_stdio(false);
    cin.tie(NULL);  
    
	cin>>n>>a>>b;
	rep(i,1,n)
	{
		if(ds(i)>=a and ds(i)<=b)
			sum+=i;
	}
	cout<<sum;
}
	

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

// cout << fixed << setprecision(12)

int main(){
  
  lint D; cin >> D;
  vi c(26); // contest 0-25
  for(lint i=0; i<26; i++) cin >> c[i];
  vvi s(D+1, vi(26)); // day 0-D
  for(lint d=1; d<=D; d++){
    for(lint j=0; j<26; j++){
      cin >> s[d][j];
    }
  }
  
  vi t(D+1); // day 0-D
  /*
  for(lint d=1; d<=D; d++){
    cin >> t[d];
    t[d]--;
  }
  */
  
  vi last(26,0);
  
  // lint ans = 0;
  
  // lint incr = 2;
  
  for(lint d=1; d<=D-1; d+=2){// 2days!!!!!
    vvi diff(26, vi(26));
    
    for(lint i=0; i<26; i++){ // if contest i (0-25)
      for(lint ii=0 ;ii<26; ii++){
        // ans += s[d][t[d]];
        lint plus = s[d][i];
    
        // last[t[d]] = d;
        lint oldlast = last[i];
        last[i] = d;
    
        lint minus = 0;
    
        for(lint j=0; j<26; j++){
          // ans -= c[j] * (d - last[j]);
          minus += c[j] * (d - last[j]);
        }
      
        // last[i] = oldlast;
        // diff[i] = plus - minus;
        
        ////////////////////
        
        // ans += s[d][t[d]];
        lint pluss = s[d+1][ii];
    
        // last[t[d]] = d;
        lint oldlastt = last[ii];
        last[ii] = d+1;
    
        lint minuss = 0;
    
        for(lint j=0; j<26; j++){
          // ans -= c[j] * (d - last[j]);
          minuss += c[j] * (d+1 - last[j]);
        }
      
        // last[i] = oldlast;
        // diff[i] = plus - minus;
        
        ////////////////////
        
        diff[i][ii] = plus + pluss - minus - minuss;
        last[i] = oldlast;
        last[ii] = oldlastt;
      }
    }
    
    vi soto (0);
    for(lint i=0; i<26; i++){
      for(lint ii=0; ii<26; ii++){
        soto.PB(diff[i][ii]);
      }
    }
    sort(ALL(soto));
    lint t = -1;
    lint tt = -1;
    for(lint i=0; i<26; i++){
      for(lint ii=0; ii<26; ii++){
        if(diff[i][ii] == soto[soto.size()-1]){
          t = i;
          tt = ii;
        }
      }
    }
    cout << t+1 << endl;
    cout << tt+1 << endl;
    last[t] = d;
    last[tt] = d+1;
    
  }
  
  // 364 days so far
  // last one day
  
  vi dif(26);
  for(lint i=0; i<26; i++){
    lint plu = s[D][i];
    // lint oldlas = last[i];
    last[i] = D;
    
    lint minu = 0;
    
    for(lint j=0; j<26; j++){
    minu += c[j] * (D - last[j]);
    }
    
    dif[i] = plu - minu;
  }
  
  vi sot(0);
    for(lint i=0; i<26; i++){
      sot.PB(dif[i]);
    }
    sort(ALL(sot));
    lint tl = -1;
    for(lint i=0; i<26; i++){
      if(dif[i] == sot[sot.size()-1]){
        tl = i;
      }
    }
  cout << tl+1 << endl;
}
 
  
  
  
  

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

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> maze(h);
  for(int i=0;i<h;i++) {
    cin >> maze[i];
  }
  vector<int> height;
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      if(maze[i][j]=='#') {
        height.push_back(i);
        break;
      }
    }
  }
  int temp=1;
  int theight=0;
  for(int i=0;i<height.size();i++) {
    vector<int> width;
    for(int j=0;j<w;j++) {
      if(maze[height[i]][j]=='#') {
        width.push_back(j);
      }
    }
    int twidth=0;
    string out;
    for(int j=0;j<width.size();j++) {
      int end=w;
      if(j<width.size()-1) {
        end=width[j+1];
      }
      for(int k=twidth;k<end;k++) {
        if(k!=0) {
          out+=' ';
        }
        out+=to_string(temp);
      }
      temp++;
      twidth=end;
    }
    int end=h;
    if(i<height.size()-1) {
      end=height[i+1];
    }
    for(int j=theight;j<end;j++) {
      cout << out << endl;
    }
    theight=end;
  }
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		ans++;
		for (int j = 0; j < i; j++) {
			if (h[i] < h[j]) {
				ans--;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
    int n;
    cin >> n;
    vector<ll> t(n);
    ll ans = 1;
    rep(i,n) {
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
// ps01.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>

using namespace std;

int main()
{	
  	int n;
    cin>>n;
  	cout<< (n*(n+1))/2;
    
    
}



Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAX=200020;
int a[MAX],chk[MAX],n,num[MAX],tmp[MAX];
vector<int> conn[MAX],seq,cycle;
int build(int x){
    vector<int> t;
    if(num[x]==0){
        for(int i=0;i<conn[x].size();i++) t.push_back(build(conn[x][i]));
        for(int i=0;i<t.size();i++) tmp[t[i]]=x;
        for(int i=1;;i++) {
            num[x]=i;
            if(tmp[i]!=x) break;
        }
    }
    return num[x];
}
int dfs(int x){
    if(chk[x]==0) {
        chk[x]=1;
        seq.push_back(x);
        return dfs(a[x]);
    }
    return x;
}
int main(){
    int t1=0,t2=0;
    vector<int> t;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),conn[a[i]].push_back(i);
    cycle.push_back(dfs(1));
    for(int i=seq.size()-1;seq[i]!=cycle[0];i--) cycle.push_back(seq[i]);
    for(int i=0;i<cycle.size();i++){
        for(int j=0;j<conn[cycle[i]].size();j++) if(conn[cycle[i]][j]!=cycle[(i+1)%cycle.size()]) build(conn[cycle[i]][j]);
    }

    for(int i=0;i<conn[cycle[0]].size();i++) t.push_back(num[conn[cycle[0]][i]]);
    for(int i=0;i<t.size();i++) tmp[t[i]]=cycle[0];
    for(int i=1;;i++) {
        if(tmp[i]!=cycle[0]){
            if(t1==0) t1=i;
            else if(t2==0) t2=i;
            else break;
        }
    }
    num[cycle[0]]=t1;
    for(int i=1;i<cycle.size();i++) build(cycle[i]);
    num[cycle[0]]=0;
    if(build(cycle[0])==t1){
        printf("POSSIBLE\n");
        return 0;
    }
    for(int i=0;i<cycle.size();i++) num[cycle[i]]=0;
    num[cycle[0]]=t2;
    for(int i=1;i<cycle.size();i++) build(cycle[i]);
    num[cycle[0]]=0;
    if(build(cycle[0])==t2){
        printf("POSSIBLE\n");
        return 0;
    }
    printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 30580
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    vector<long long> v(n);
    for(auto& i:v)cin>>i;
    
    long long curb=2, curs=2;
    for(int i=n-1; i>=0; i--){
        if(v[i]>curb){
            cout<<-1;
            return 0;
        }
        long long cursn=v[i]*(curs/v[i])+(curs%v[i]?v[i]:0);
        if(cursn>curb){
            cout<<-1;
            return 0;
        }
        long long curbn=v[i]*(curb/v[i])+v[i]-1;
        curb=curbn, curs=cursn;
    }
    cout<<curs<<" "<<curb;
    
    
    
    
   
    return 0;
}

Measured memory_bytes: 1024