akhauriyash/Code-Regression huggingface dataset:
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::thread;
use std::cmp::*;
fn exec() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let a: Vec<i64> = (0..n).map(|_| sc.ne()).collect();
    let mut z: Vec<_> = a.into_iter().zip(0..).collect();
    z.push((0, -1));
    z.sort();
    let mut ans = vec![0; n];
    let (mut mi, mut cnt, mut mx) = (n, 0, z[n].0);
    for (x, i) in z.into_iter().rev() {
        if x != mx {
            assert!(mi < n);
            ans[mi] += (mx - x) * cnt;
            mx = x;
        }
        cnt += 1;
        mi = min(mi, i as usize);
    }
    for x in ans {
        println!("{}", x);
    }
}

fn main() {
    const DEFAULT_STACK: usize = 16 * 1024 * 1024;
    let builder = thread::Builder::new();
    let th = builder.stack_size(DEFAULT_STACK);
    let handle = th.spawn(|| { exec(); }).unwrap();
    let _ = handle.join();
}

trait Monoid<T>: Clone {
    fn merge(&T, &T) -> T;
    fn ide() -> T;
}

// Range Minimum Query
type Int = i64;
impl Monoid<Int> for Int {
    fn merge(l: &Int, r: &Int) -> Int {
        std::cmp::min(*l, *r)
    }
    fn ide() -> Int {
        std::i32::MAX as Int
    }
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => return None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => {
                panic!("parse error, {:?}",
                       String::from_utf8(self.buf[l..r].to_owned()))
            }
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string ans;
	for(char i=0,a;i<9;++i){
		cin>>a;
		if(i%4==0)ans+=a;
	}
	cout<<ans<<"\n"s;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
    return u;
  }
  if(k<u->key){
    return treeSearch(u->left,k);
  }else{
    return treeSearch(u->right,k);
  }
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL){
    return treeMinimum(x->right);
  }
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  
  if(z->left==NIL || z->right==NIL){
    y=z;
  }else{
    y=treeSuccessor(z);
  }

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

  if(x!=NIL){
    x->parent=y->parent;
  }

  if(y->parent==NIL){
    root=x;
  }else if(y==y->parent->left){
    y->parent->left=x;
  }else{
    y->parent->right=x;
  }
  if(y!=z){
    z->key=y->key;
  }
  free(y);
}

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

  z = malloc(sizeof(struct 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;
  }
}

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

void find(int x){
  Node t;
  t = treeSearch(root, x);
  if ( t != NIL ) printf("yes\n");
  else printf("no\n");
}
  
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      find(x);
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20456
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a,b;
	while(cin>>a>>b,a!="0"||b!="0"){
		int hit=0,brow=0;
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
			if(i==j)continue;
			if(a[i]==b[j])brow++;
		}
	}
		for(int i=0;i<4;i++)if(a[i]==b[i])hit++;
		cout<<hit<<" "<<brow<<endl;
	}
	return 0;
}

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

using namespace std;



int main()
{
   int n;
   cin >> n;
   int lyginiai = 0, da5 = 0, da3 = 0;

   for (int i = 0; i < n; i++)
   {
       int c;
       cin >> c;
       if(c%2==0)
       {
           lyginiai++;
           if(c%5==0)da5++;
           else if(c%3==0)da3++;
       }

   }
   if(da3+da5 == lyginiai) cout << "APPROVED";
   else cout << "DENIED";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
constexpr int MOD = 1000000007;

void print(const std::vector<ll>& v)
{
  std::for_each(v.begin(), v.end(), [](ll x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

//#の次に.がこない
//.....#######という形
int main ()
{
    ll N;
    cin>>N;
    string S;
    cin>>S;
    vector<ll> b(N,0),w(N,0);
    REP(i,N){
        if(i>0){
            if (S[i] == '#'){
                b[i] = b[i-1]+1;
                w[i] = w[i-1];
            }else{
                b[i] = b[i-1];
                w[i] = w[i-1] + 1;
            }
        }else{
            if (S[i] == '#'){
                b[i] = 1;
                w[i] = 0;
            }else{
                b[i] = 0;
                w[i] = 1;
            }
        }
    }
   
    vector<ll> ans(N+1,0);
    ans[0] = w[N-1];
    REP(i,N){
    //i+1番目までwhite
    //左の#と右の.のかずを数える
        ans[i+1] = b[i] + w[N-1] - w[i];
    }

    cout<<*min_element(ALL(ans))<<endl;
}

Measured memory_bytes: 5252
/* 
 * Project: AISing programing Contest B - An Odd Problem
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/07/11
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
using namespace std;

int n;
int a[100];

void solve() {
    int cnt = 0;
    for (int i=0;i<n+1;i+=2) {
        if (a[i]&1)
            cnt++;
    }
    printf("%d\n",cnt);
}

int main() {

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

Measured memory_bytes: 3228
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int L[110];
signed main() {
    int N; cin >> N;
    L[0] = 2;
    L[1] = 1;
    repq(i,2,N) L[i] = L[i-1] + L[i-2];
    cout << L[N] << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    put(c/a*b);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;


int main() {
    ll n;
    cin >> n;
    vector<pair<pair<int, int>, int>>z(n);
    for (int i = 0; i < n; i++) {
        cin >> z[i].first.first >> z[i].first.second >> z[i].second;
    }
    vector<ll> ans(n + 1, 1000000000000000);
    for (ll i = 0; i < (1 << n); i++) {
        ll a = 0;
        vector<int> d;
        vector<int> ad;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                a++;
                d.push_back(j);
            }
            else ad.push_back(j);
        }
        ll zans = 100000000000;
        ll bbs = ad.size();
        vector<int> ds(30);
        ds[0] = 1;
        for (int i = 1; i < 30; i++) {
            ds[i] = ds[i - 1] * 2;
        }
        for (int j = 0; j < ds[a]; j++) {
            ll g = 0;
            vector<int> x(a + 1);
            vector<int> y(a + 1);
            for (int k = 0; k < a; k++) {
                if (j & ds[k]) {
                    x[k] = z[d[k]].first.first;

                }
                else y[k] = z[d[k]].first.second;
            }
            int xx = x.size();
            int yy = y.size();
            for (int ks = 0; ks < bbs; ks++)
            {
                int ku = ad[ks];
                int m = 1000000000;
                for (int l = 0; l < a + 1; ++l) {
                    m = min(m, abs(x[l] - z[ku].first.first));
                }
                for (int l = 0; l < a + 1; ++l) {
                    m = min(m, abs(y[l] - z[ku].first.second));
                }
                g += (ll)m * (ll)z[ku].second;
            }
            zans = min(g, zans);

        }
        ans[a] = min(ans[a], zans);
    }
    for (int i = 0; i < n + 1; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 3644
# abc138_a.py
# https://atcoder.jp/contests/abc138/tasks/abc138_a

# A - Red or Not /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 整数 aと、英小文字からなる文字列 sが入力されます。
# aが 3200 以上なら s と出力し、a が 3200未満なら red と出力するプログラムを書いてください。

# 制約
#     2800≤a<5000
#     sは長さ 1 以上 10以下の文字列である。
#     sの各文字は英小文字である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# a
# s

# 出力
# aが 3200 以上なら s と出力し、a が 3200未満なら red と出力せよ。

# 入力例 1
# 3200
# pink

# 出力例 1
# Copy

# pink

# a=3200は 3200 以上であるため s=pink と出力します。

# 入力例 2
# 3199
# pink

# 出力例 2
# red

# a=3199は 3200未満であるため red と出力します。

# 入力例 3
# 4049
# red

# 出力例 3
# red

# a=4049は 3200 以上であるため s= red と出力します。


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    s = lines[1]
    a = int(lines[0])
    # X, A = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(M):
    #     valueses.append(list(map(int, lines[i+1].split())))

    if a >= 3200:
        result = s
    else:
        result = 'red'

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3200', 'pink']
        lines_export = ['pink']
    if pattern == 2:
        lines_input = ['3199', 'pink']
        lines_export = ['red']
    if pattern == 3:
        lines_input = ['4049', 'red']
        lines_export = ['red']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9232
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  int a;
  cin>>a;
  double b=a/2;
  cout<<setprecision(13)<<1-b/a;
      
}

Measured memory_bytes: 256
#include<map>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int b,m,n;
  map<int,int,greater<int> > a;
  map<int,int,greater<int> >::iterator it;
  while(cin>>n>>m&&n+m){
    a.clear();
    for(i=0;i<n;i++){
      int d,p;
      cin>>d>>p;
      a[p]+=d;
    }
    b=0;
    for(it=a.begin();it!=a.end();it++){
      if((*it).second>m){
	b+=(*it).first*((*it).second-m);
	m=0;
      }else
	m-=(*it).second;
    }
    cout<<b<<endl;
  }
  return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat
vector<int> adj[100005];
bool visited[100005]={false};
ll dp[100005][2]={0};
//dp[i][0]-number of ways to paint black
//dp[i][1]-number of ways to paint white

void self_add(ll &a , ll b)
{
	a+=b;
	if(a>=mod)a-=mod;
}

void self_mul(ll &a , ll b)
{
	a*=b;
	a%=mod;
}
void dfs(ll start)
{
	visited[start]=true;	
	dp[start][0]=1;
	dp[start][1]=1;
	for(ll i:adj[start])
	{
		if(!visited[i])
		{
			dfs(i);
			self_mul(dp[start][0],dp[i][1]);
			ll tmp=0;
			self_add(tmp,dp[i][1]);
			self_add(tmp,dp[i][0]);
			self_mul(dp[start][1],tmp);
		}
	}
}

int main(int argc, char const *argv[])
{
	sync;
	ll n;
	cin>>n;
	rep(i,n-1)
	{
		ll a,b;
		cin>>a>>b;
		a--,b--;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	dfs(0);
	//rep(i,n)cout<<dp[i][0] sp dp[i][1]<<endl;
	cout<<(dp[0][0]+dp[0][1])%mod<<endl;
	return 0;
}


Measured memory_bytes: 11520
# coding: utf-8
# Your code here!

A, B, C, X = int(input()), int(input()), int(input()), int(input())
counter = 0

for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if 500 * i + 100 * j + 50 * k == X:
                counter += 1
print(counter)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
	int w, h, r, x, y, upperl, lowerl, rightl, leftl;
	bool includes = true;

	cin >> w >> h >> x >> y >> r;

	if (x <= 0 || x >= w) {
		includes = false;
	}
	if (y <= 0 || y >= h) {
		includes = false;
	}

	rightl = x + r;
	leftl = x - r;
	upperl = y + r;
	lowerl = y - r;

	if (rightl > w || leftl < 0 || upperl > h || lowerl < 0) {
		includes = false;
	}

	if (includes == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


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

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

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

    char T = '\0';
    int cnt = 0;
    REP(0, i, S.length()) {
        // cout << S[i] << endl;

        if (i == 0) {
            T = S[i];
        } else {
            if (S[i] != T) {
                T = S[i];
            } else {
                S[i] = T == '0' ? '1' : '0';
                T = S[i];
                cnt++;
            }
        }
    }

    // cout << S << endl;
    cout << cnt << endl;

    return 0;
}


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

int main() {
    int h,w,n;
    cin >> h >> w >> n;
    vector<vector<int>> a(w,vector<int>(h));
    vector<int> c(n+1);
    rep(i,n) cin >> c.at(i+1);
    int k=1,p=0;
    rep(i,h){
        if (i%2==0){
            for (int j=0;j<w;j++){
                a.at(j).at(i)=k;
                p++;
                if (p>=c.at(k)) {k++;p=0;}
            } 
        }
        if (i%2==1){
            for (int j=w-1;j>-1;j--){
                a.at(j).at(i)=k;
                p++;
                if (p>=c.at(k)) {k++;p=0;}
            } 
        }
    }
    rep(i,h){
        rep(j,w-1) cout << a.at(j).at(i) << " ";
        cout << a.at(w-1).at(i) << endl;
    }
}


Measured memory_bytes: 384
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <iomanip>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
	ll n;cin>>n;
	int arr[n],mx1=0,mx2=0,idx;
	loop(n,i,0){
		cin>>arr[i];
		if(arr[i]>mx1)idx=i,mx1=arr[i];
	}
	loop(n,i,0){
		if(i==idx)continue;
		mx2=max(mx2,arr[i]);
	}
	loop(n,i,0){
		if(i==idx)cout<<mx2<<endl;
		else cout<<mx1<<endl;
	}
	return 0;
}


Measured memory_bytes: 2432
/*
 * Contest156_A.cpp
 *
 *  Created on: 2020/02/22
 *      Author: black
 */

#include <iostream>

using namespace std;

int main(){
	int n, r;

	cin >> n >> r;

	if (n < 10){
		r = r + (100*(10-n));
	}
	cout << r;

	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct node
{
    int flag;
    int num;
} b[100009];
int main()
{
    int n,m,ans=0,ans1=0;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
        b[i].flag=0,b[i].num=0;
    for(int i=0; i<m; i++)
    {
        int x;
        char a[5];
        scanf("%d%s",&x,a);
        getchar();
        if(a[0]=='A')
            b[x].flag=1;
        else
        {
            if(b[x].flag==0)
                b[x].num++;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(b[i].flag==1)
        {
            ans++;
            ans1+=b[i].num;
        }
    }
    printf("%d %d",ans,ans1);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    map<int,bool>m;
    bool chk = true;
    for(int i=0;i<s.length();i++){
        int num = (int)(s[i]-'a');
        if(m[num]){
            chk=false;
        }else{
            m[num] = true;
        }
    }
    if(chk)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

    private static final Scanner SCANNER = new Scanner(System.in);

    static int readOneInt() {
        String line = SCANNER.nextLine();
        return Integer.parseInt(line);
    }

    public static void main(String[] args) {

//        int tc = Integer.parseInt(SCANNER.nextLine());
        int tc = 1;
        for (int i = 0; i < tc; ++i) {
            test(readOneInt());
        }
    }

    private static void test(int n) {
        int d = n % 10;
        if (d == 2 || d == 4 || d == 5 || d == 7 || d == 9) {
            System.out.println("hon");
        } else if (d == 0 || d == 1 || d == 6 || d == 8) {
            System.out.println("pon");
        } else if (d == 3) {
            System.out.println("bon");
        }
    }
}



Measured memory_bytes: 35784
/**
 * Created by hiramekun at 16:19 on 2019-09-17.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    string s;
    cin >> s;

    ll n = s.size();
    rep(i, n) {
        if (i % 2 == 0) {
            if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') continue;
            cout << "No" << '\n';
            return;
        } else {
            if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D') continue;
            cout << "No" << '\n';
            return;
        }
    }
    cout << "Yes" << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int check_num_pattern(int num, int sum)
{
    int i, j, k;
    int pattern;

    pattern = 0;
    for (i = 1; i <= num; i++)
    {
        for (j = i + 1; j <= num; j++)
        {
            for (k = j + 1; k <= num; k++)
            {
                if (i + j + k == sum)
                {
                    // printf("set: %d %d %d\n", i, j, k);
                    pattern++;
                }
            }
        }
    }
    return (pattern);
}

int main(void)
{
    int num[100], sum[100], dataset = 0;
    int i;
    
    for(i = 0;;i++)
    {
        scanf("%d %d", &num[i], &sum[i]);
        if (num[i] == 0 && sum[i] ==0)
            break;
        dataset++;
    }

    int result[dataset];
    for (i = 0; i < dataset; i++){
        result[i] = check_num_pattern(num[i], sum[i]);
    }

    for (i = 0; i < dataset; i++)
    {
        printf("%d\n", result[i]);
    }
    return (0);
}


Measured memory_bytes: 2048
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = float("inf")
k -= 1
for i in range(k, n):
    sub = abs(x[i] - x[i - k]) + min(abs(x[i]), abs(x[i - k]))
    ans = min(ans, sub)
    
print(ans)

Measured memory_bytes: 14392
n, k = map(int, input().split())
MOD = 10 ** 9 + 7


dist = [(n + 1, n + 1)]
r = n + 1
for i in range(2, n + 100):
    # [l, r)
    r = dist[-1][0]
    l = n // i + 1
    if r - l < 1:
        break
    dist.append((l, r))

while True:
    if r == 1:
        break
    dist.append((r - 1, r))
    r -= 1

dist = dist[::-1]
del dist[-1]


length = [r - l for l, r in dist]
dp = [[0] * len(dist) for i in range(k)]
for i in range(len(dist)):
    dp[0][i] = length[i]

for i in range(k - 1):
    ru = 0
    for j in range(len(dist)):
        ru += dp[i][j]
        ru %= MOD
        dp[i + 1][~j] += ru * length[~j]
        dp[i + 1][~j] %= MOD

print(sum(dp[-1]) % MOD)

Measured memory_bytes: 128792
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>

using namespace std;

bool achievable(int x, const vector<int>& len) {
    int offset = accumulate(len.begin(), len.end(), 0);

    if(x > offset || x < -offset) {
        return false;
    }

    vector<vector<int>> dp(2, vector<int>(2 * offset + 1));

    dp[0][offset] = 1;

    for(int i = 0; i < len.size(); ++i) {
        fill(dp[!(i & 1)].begin(), dp[!(i & 1)].end(), 0);
        for(int j = 0; j < 2 * offset + 1; j++) {
            if(dp[i & 1][j]) {
                if(j - len[i] >= 0) {
                    dp[!(i & 1)][j - len[i]] = 1;
                }

                if(j + len[i] < 2 * offset + 1) {
                    dp[!(i & 1)][j + len[i]] = 1;
                }
            }
        }
    }

    return dp[len.size() & 1][x + offset];
}

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

    int x, y;
    cin >> x >> y;

    vector<int> a[2];

    int n = s.size();
    
    int i;
    for(i = 0; i < n; i++){
        if(s[i] == 'F') {
            x--;
        } else {
            break;
        }
    }

    int len = 0;
    int axis = 0;

    for(; i < n; i++) {
        if(s[i] == 'T') {
            if(len > 0) {
                a[axis].push_back(len);
            }

            len = 0;
            axis = !axis;
        } else {
            len++;
        }
    }

    if(len > 0) {
        a[axis].push_back(len);
    }

    if(achievable(x, a[0]) && achievable(y, a[1])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 384
const main = (input) => {
  const lines = input.trim().split("\n");
  const [N, M] = lines[0].split(' ').map(str => parseInt(str));
  const checkList = lines.slice(1).map(line => {
    const [s, c] = line.split(' ');
    return [parseInt(s - 1), c];
  });
  const numList = Array(N).fill(0);

  // 全探索
  for (let i = 0; i < Math.pow(10, N); i++) {
    const strNum = i.toString();
    if (strNum.length == N && checkList.every(sc => strNum[sc[0]] === sc[1])) {
      console.log(strNum)
      process.exit(0);
    }
  }
  console.log(-1);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



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

using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);

//FILE *fi=freopen("1.inp","r",stdin);
//FILE *fo=freopen("1.out","w",stdout);
int n;
long long p;
string s;
long long d[100001];
long long ans;
int main()
{
    cin>>n>>p;
    cin>>s;
    s='.'+s;
    long long cur = 0;
    long long x = 1;
    long long cnt=0;
    if(p==5||p==2)
    {
        for(int i=n;i>=1;i--)
        {
            cnt+=((s[i]-'0')%p)==0;
            ans+=cnt;
        }
        cout<<ans;
        return 0;
    }
    d[0]=1LL;
    for(int i=n;i>=1;i--)
    {
        cur = (((s[i]-'0') * x % p) + cur) % p;
        x*=10;
        x%=p;
        ans+=d[cur];
        d[cur]++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
#define pi acos(-1)
const int N=100005;
const ll mod=1e9+9;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
int a,b,c,x,y;
int ans;
int main()
{
	a=read();b=read();c=read();x=read();y=read();
	if(c+c<a+b){
		int tmp=min(x,y),ans2=2*max(x,y)*c;
		ans=tmp*2*c;
		x-=tmp;y-=tmp;
		if(x)
			ans+=x*a;
		else if(y)
			ans+=y*b;
		ans=min(ans2,ans);
	}
	else
		ans=a*x+b*y;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>

typedef long long llong;
using namespace std;

int main() {
	int n;
	char taro[110];
	char hana[110];
	int score_t = 0;
	int score_h = 0;
	int cmp;

	scanf("%d", &n);


	for (int i = 0; i < n; i++) {
		scanf("%s", taro);
		getchar();
		scanf("%s", hana);
		cmp = strcmp(taro, hana);
		if (cmp > 0)score_t+=3;
		else if (cmp == 0) {
			score_h++; score_t++;
		}
		else if (cmp < 0)score_h+=3;
	}

	printf("%d %d\n", score_t, score_h);

	return 0;
}




Measured memory_bytes: 3196
#define DEBUG 0
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 7/27/2019, 8:48:44 PM
 * Powered by Visual Studio Code
 */
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using ll = long long;
class mint
{
public:
  static ll MOD;
  ll x;
  mint() : x(0) {}
  mint(ll x) : x(x % MOD) {}
  mint operator-() const { return x ? MOD - x : 0; }
  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= MOD)
    {
      x -= MOD;
    }
    return *this;
  }
  mint &operator-=(const mint &a) { return *this += -a; }
  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint &operator/=(const mint &a)
  {
    mint b{a};
    return *this *= b.power(MOD - 2);
  }
  mint operator+(const mint &a) const { return mint(*this) += a; }
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  bool operator<(const mint &a) const { return x < a.x; }
  bool operator==(const mint &a) const { return x == a.x; }
  const mint power(ll N)
  {
    if (N == 0)
    {
      return 1;
    }
    else if (N % 2 == 1)
    {
      return *this * power(N - 1);
    }
    else
    {
      mint half = power(N / 2);
      return half * half;
    }
  }
};
ll mint::MOD = 1e9 + 7;
istream &operator>>(istream &stream, mint &a) { return stream >> a.x; }
ostream &operator<<(ostream &stream, const mint &a) { return stream << a.x; }
class combination
{
public:
  vector<mint> inv, fact, factinv;
  static int MAX_SIZE;
  combination() : inv(MAX_SIZE), fact(MAX_SIZE), factinv(MAX_SIZE)
  {
    inv[1] = 1;
    for (auto i = 2; i < MAX_SIZE; i++)
    {
      inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
    }
    fact[0] = factinv[0] = 1;
    for (auto i = 1; i < MAX_SIZE; i++)
    {
      fact[i] = mint(i) * fact[i - 1];
      factinv[i] = inv[i] * factinv[i - 1];
    }
  }
  mint operator()(int n, int k)
  {
    if (n >= 0 && k >= 0 && n - k >= 0)
    {
      return fact[n] * factinv[k] * factinv[n - k];
    }
    return 0;
  }
};
int combination::MAX_SIZE = 3000010;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// constexpr double epsilon = 1e-10;
// constexpr ll infty = 1000000000000000LL;
// constexpr int dx[4] = {1, 0, -1, 0};
// constexpr int dy[4] = {0, 1, 0, -1};
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}
void No()
{
  cout << "No" << endl;
  exit(0);
}

int main()
{
  ll A, B;
  cin >> A >> B;
  ll K = (A + B) / 2;
  if (abs(A - K) == abs(K - B))
  {
    cout << K << endl;
  }
  else
  {
    cout << "IMPOSSIBLE" << endl;
  }
}

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


	int n, m; cin >> n >> m;

	vector <int> a(n);

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

	vector <int> b(m), c(m);

	for(int i = 0; i < m; i++){
		cin >> b[i] >> c[i];
	}

	map <int, int> mp;
	for(int i = 0; i < n; i++){
		mp[a[i]]++;
	}

	for(int i = 0; i < m; i++){
		mp[c[i]] += b[i];
	}

	int current = 0, sum = 0;

	auto it = mp.end();

	while(current != n){
		it = prev(it);

		int temp = min(it->second, n - current);

		current += temp;
		sum += temp * it->first;
	}



	cout << sum << endl;



	return 0;
}

Measured memory_bytes: 15104
def solve():
    N, W = map(int, input().split())
    weight = []
    value = []
    
    for i in range(N):
        w,v = map(int,input().split())
        weight.append(w)
        value.append(v)

    maxvalue = sum(value)
    dp = [[float('inf')]*(maxvalue+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0

    for i in range(N):
        for v in range(maxvalue+1):
            if v - value[i] < 0:
                dp[i+1][v] = min(dp[i+1][v], dp[i][v])
            else:
                dp[i+1][v] = min(dp[i+1][v], dp[i][v-value[i]]+weight[i])
                dp[i+1][v] = min(dp[i+1][v], dp[i][v])
    
    ans = 0
    for i in range(N+1):
        for j in range(maxvalue+1):
            if dp[i][j] <= W:
                ans = max(ans, j)
    
    print(ans)
            
if __name__ == '__main__':
    solve()

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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define pi 3.1415926536
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

ll a, b;
string s;

int ra[1000010], rb[1000010];
int main()
{
    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(2 * a - 1, 2 * b - 1)) << endl;
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

const int INF=1001001001;

string S;
int dp[222222][5];
signed main(){
	cin>>S;
	fill_n(*dp,222222*5,-INF);
	int N=S.size();
	for(int i=1;i<=4;i++)dp[i][i]=1;
	rep(i,N)rep(j,5){
		if(dp[i][j]==-INF)continue;
		for(int k=1;k<=5;k++){
			if(i+k>S.size())break;
			if(S.substr(i-j,j)==S.substr(i,k))continue;
			chmax(dp[i+k][k],dp[i][j]+1);
		}
	}
	int ans=-INF;
	rep(i,5)chmax(ans,dp[N][i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9220
# -*- coding: utf-8 -*-

### TESTCASE
test = ""
#test = \
"""
4 3
ans
3333
"""

"""
9 3
ans
333333333
"""
############
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
####### MAIN

a, b = map(int, input2().split())

print(sorted([str(a) * b, str(b) * a])[0])




Measured memory_bytes: 3060
import sys

sys.setrecursionlimit(10 ** 7)

row = list(map(int, input().split()))
N, K = row[0], row[1]

result = 0
for i in range(N):
    score = i + 1
    coin_toss_count = 0
    while score < K:
        coin_toss_count += 1
        score = score * 2
    result += (1 / N) * (0.5 ** coin_toss_count)

print(result)


Measured memory_bytes: 3188
while ( n = gets.to_i ) != 0
	l = r = p = false
	res = 0
	gets.split.each do | w |
		if w[0] == 'l'
			l ^= true
		elsif
			r ^= true
		end

		if l == r && l != p
			p ^= true
			res += 1
		end
	end
	puts res
end

Measured memory_bytes: 6096
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

using namespace std;

typedef long long ll;
const int mod = 1000000007;

ll num[100100];
ll dp[110][100100];
ll sdp[100100];

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

    int iter = 0;
    for (int i = 1; i <= n;) {
        int j = n / i;
        if (i <= j) num[iter++] = 1, i++;
        else num[iter++] = n/j - i + 1, i = n/j + 1;
    }

    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;

    for (int i = 0; i < k; i++) {
        memset(sdp, 0, sizeof(sdp));
        for (int j = 1; j <= iter; j++) {
            sdp[j] = sdp[j-1] + dp[i][j-1];
            sdp[j] %= mod;
        }
        for (int j = 0; j < iter; j++) {
            dp[i+1][j] = sdp[iter-j] * num[j];
            dp[i+1][j] %= mod;
        }
    }

    ll ans = 0;
    for (int j = 0; j < iter; j++) {
        ans += dp[k][j];
        ans %= mod;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 87552
#include <stdio.h>
#include <vector>
#include <string.h>

using namespace std;

struct DATA{
	int start;
	int end;
	int fileID;
	DATA(int start, int end, int fileID){
		this->start = start, this->end = end, this->fileID = fileID;
	}
};

vector<DATA> data;

void Write(int fileID, int file_length)
{
	int size = (int)data.size();
	for(int i = 0; i < size; i++){
		if(data[i].fileID == -1){
			if(file_length <= data[i].end - data[i].start + 1){
				data.insert(data.begin() + i, DATA(data[i].start, data[i].start + file_length - 1, fileID));
				data[i+1].start = data[i+1].start + file_length;
				return;
			}else{
				data[i].fileID = fileID;
				file_length -= data[i].end - data[i].start + 1;
			}
		}
	}
}

void Arrange()
{
	for(int i = 0; i < (int)data.size()-1; i++){
		if(data[i].fileID == -1){
			if(data[i+1].fileID == -1){
				data[i].end = data[i+1].end;
				data.erase(data.begin() + (i+1));
				i--;
			}
		}
	}
}

void Delete(int fileID)
{
	int size = (int)data.size();
	for(int i = 0; i < size; i++){
		if(data[i].fileID == fileID) data[i].fileID = -1;
	}
	Arrange();
}

void Reference(int pos)
{
	int size = (int)data.size();
	for(int i = 0; i < size; i++){
		if(data[i].end >= pos){
			printf("%d\n", data[i].fileID);
			return;
		}
	}
}

int main(void)
{
	int N;
	char com[5];
	int op1, op2;
	
	while(1){
		scanf("%d", &N);
		if(N == 0) break;
		data.clear();
		data.push_back( DATA(0, 1000000001, -1) );
		
		for(int i = 0; i < N; i++){
			
			scanf("%s", com);
			if(strcmp(com, "W") == 0){
				scanf("%d %d", &op1, &op2);
				Write(op1, op2);
			}else if(strcmp(com, "D") == 0){
				scanf("%d", &op1);
				Delete(op1);
			}else if(strcmp(com, "R") == 0){
				scanf("%d", &op1);
				Reference(op1);
			}
		}
		printf("\n");
	}
	return 0;
}
		

Measured memory_bytes: 2856
#include<stdio.h>

int main(void)
{
	int n,card[4][13] = {0};
	int i, j, d;
	char m;

	scanf("%d", &n);

	for(i=0;i<n;i++){
		scanf(" %c %d", &m, &d);

		if(m=='S')card[0][d-1]=1;
		else if(m=='H')card[1][d-1]=1;
		else if(m=='C')card[2][d-1]=1;
		else if(m=='D')card[3][d-1]=1;
	}

	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			if(card[i][j] == 0){
				switch(i){
					case 0: printf("S %d", j+1);
							break;
					case 1: printf("H %d", j+1);
							break;
					case 2: printf("C %d", j+1);
							break;
					case 3: printf("D %d", j+1);
							break;
				}	
				printf("\n");
			}
		}

	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin >> n;
   long long a[n];
   long long x = 0;
   for(int i=0;i<n;i++){ 
      cin >> a[i];
      x = x^a[i];
   }
   long long b[n];
   for(int i=0;i<n;i++){ 
      b[i] = x^a[i];
   }
   for(int i=0;i<n;i++){ 
      cout << b[i]<<" ";
   }
    
}


Measured memory_bytes: 6660
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<int> G[N];
int delv, delu;
int n, m, x, y, d[N], fa[N], dp[N], q[N];
void dfs(int x, int fx) {
    d[x] = d[fx] + 1;
    fa[x] = fx;
    dp[x] = d[x] % 2 ? 1 : -1;
    for (int y : G[x]) {
        if (y == fx) continue;
        if (d[y]) {
            delv = y;
            delu = x;
            continue;
        }
        dfs(y, x);
        dp[x] += dp[y];
    }
}
void SolveTree() {
    if (dp[1]) {
        puts("-1");
        return;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) ans += abs(dp[i]);
    printf("%d\n", ans);
}
void SolveOdd() {
    if (dp[1] % 2) {
        puts("-1");
        return;
    }
    int ans = 0, t = -dp[1] / 2;
    ans = abs(t);
    for (; delu; delu = fa[delu]) dp[delu] += t;
    for (; delv; delv = fa[delv]) dp[delv] += t;
    for (int i = 1; i <= n; i++) ans += abs(dp[i]);
    printf("%d\n", ans);
}
void SolveEven() {
    if (dp[1]) {
        puts("-1");
        return;
    }
    int ans, top = 0, mid;
    for (; delv != delu; delv = fa[delv]) {
        q[++top] = dp[delv];
        d[delv] = 0;
    }
    sort(q + 1, q + top + 1);
    mid = q[(top + 1) / 2];
    ans = abs(mid);
    for (int i = 1; i <= n; i++)
        if (d[i]) ans += abs(dp[i]);
    for (int i = 1; i <= top; i++) ans += abs(q[i] - mid);
    printf("%d\n", ans);
}
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        scanf("%d%d", &x, &y);
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs(1, 0);
    if (m == n - 1)
        SolveTree();
    else if ((d[delv] - d[delu]) % 2)
        SolveEven();
    else
        SolveOdd(); 
}

Measured memory_bytes: 13568
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
#include<list>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int N;
vector<pair<int, int>> V;
pair<llong, llong> U = make_pair(0,0);


int main() {
	cin >> N;
	int A[10010], B[10010];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < N; i++) {
		pair<int, int>p = make_pair(A[i], B[i]);
		V.push_back(p);
	}
	for (int i = 0; i < V.size(); i++) {
		if (V[i].first < V[i].second) {
			int a = V[i].second - V[i].first;
			
			U.first += a / 2;
			
		}
		else if (V[i].first == V[i].second) {

		}
		else {
			int a = V[i].first - V[i].second;
			U.second += a;
 		}
	}

	
	if (U.first >= U.second) cout << "Yes";
	else cout << "No";
	return 0;
	
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  string s;
  cin >> s;
  ll open = 0;
  ll close = 0;
  for(int i = 0;i < n;i++){
    if(s[i] == '(')open++;
    else{
      if(open > 0)open--;
      else close++;
    }
  }
  for(int i = 0;i < close;i++)s = '(' + s;
  for(int i = 0;i < open;i++)s = s + ')';
  cout << s << endl;
}

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

// #define int long long
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<pi>
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(t) int t;cin>>t;while(t--)solve()
#define ll long long

void solve(){
	
}

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,d;
	int c=0;
	cin>>n>>d;
	while(n--){
		int x,y;
		cin>>x>>y;
		ll ans = x*(ll)x + y*(ll)y;
		if (ans<=d*(ll)d)c++;
	}
	cout<<c;


}


Measured memory_bytes: 3668
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        for(int i=1; i<=10000; i++){
            int n = sc.nextInt();
            if(n==0)    break;
            System.out.println("Case " + i + ": " + n);
        }
    }
}



Measured memory_bytes: 41076
package main

import (
	"fmt"
)

func main() {
	var A, B, N int
	fmt.Scan(&A, &B, &N)

	if N < B {
		fmt.Println(A * N / B)
	} else {
		x := B - 1
		fmt.Println(A*x/B - A*(x/B))
	}
}

Measured memory_bytes: 1756