akhauriyash/Code-Regression huggingface dataset:
import javax.swing.*;
import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {


    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public void execute(CustomReader in) throws IOException {
        final int N = in.readLineAsInt();
        System.out.println(baseMinus2String(N));
    }

    private String baseMinus2String(int N) {
        int n = Math.abs(N);
        boolean carry = false;
        String baseMinus2 = "";
        int mask = 1;
        int number = 0;
        for (int keta = 0; keta <= 32; keta++) {
            if ((n & mask) > 0) {
                if (carry) {
                    baseMinus2 = "0" + baseMinus2;
                } else {
                    baseMinus2 = "1" + baseMinus2;
                    number += (1 << keta) * ((keta % 2 == 0) ? 1 : -1);
                    if ((N >= 0 && keta % 2 == 1) || (N < 0 && keta % 2 == 0)) {
                        carry = true;
                    }
                }
            } else {
                if (carry) {
                    carry = false;
                    baseMinus2 = "1" + baseMinus2;
                    number += (1 << keta) * ((keta % 2 == 0) ? 1 : -1);
                    if ((N >= 0 && keta % 2 == 1) || (N < 0 && keta % 2 == 0)) {
                        carry = true;
                    }
                } else {
                    baseMinus2 = "0" + baseMinus2;
                }
            }
            if (number == N) {
                break;
            }
            mask = mask << 1;
        }

        return baseMinus2;
    }


    static class CustomReader extends BufferedReader {
        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int readLineAsInt() throws IOException {
            return Integer.parseInt(readLine());
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

        public char[][] readAsCharMatrix(int rows) throws IOException {
            char[][] matrix = new char[rows][];
            for (int i = 0; i < rows; i++) {
                matrix[i] = this.readLine().toCharArray();
            }
            return matrix;
        }

    }

}

Measured memory_bytes: 21204
function Main(inputs) {
	const inputlines = inputs.split("\n");
 	const firstvalues = inputlines[0].split(" ");
  	let prices = inputlines[1].split(" ").map(x => parseInt(x, 10));
  
  	prices.sort((a,b)　=> a - b);
  	
  	let total = 0;
  	for(let i = 0; i < firstvalues[1]; i++){
      total += prices[i];
    }
  
  	console.log(total);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29580
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var q = n;
  if(n < 3)return 0;
  var ans = 0;
  var set = new Set();
  set.add(1);
  for(var i = 2; i*i <= n; i++){
    while(n%i === 0){
      var set2 = new Set()
      for(var j of set){
        set2.add(j);
        set2.add(j*i);
      }
      set = set2;
      n /= i;
    }
  }
  if(n > 1){
    var set2 = new Set()
    for(var j of set){
      set2.add(j);
      set2.add(j*n);
    }
    set = set2;
  }
  for(var j of set){
    j--;
    if(Math.floor(q/j) === q%j)ans += j;
  }
  return ans;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  puts(a>b&&a>c ? "A" : (b>c ? "B" : "C"));
  return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int n,i,a,c,p;
long long r;
int main() {
  scanf("%d",&n);
  for (i=0; i<n; i++) {
    scanf("%d",&a);
    c=min(a,p);
    r+=c;
    a-=c;
    r+=a/2;
    p=a%2;
  }
  printf("%lld\n",r);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int date[12][31];
	int d;
	int i, j;
	int day;
	
	day = 5;
	for (i = 0; i < 12; i++){
		switch (i + 1){
		  case 1:
			d = 31;
			break;
			
		  case 3:
		  	d = 31;
			break;
			
		  case 5:
		  	d = 31;
			break;
			
		  case 7:
		  	d = 31;
			break;
			
		  case 8:
		  	d = 31;
			break;
			
		  case 10:
		  	d = 31;
			break;
			
		  case 12:
		  	d = 31;
			break;
			
		  case 4:
		  	d = 30;
			break;
			
		  case 6:
		  	d = 30;
			break;
			
		  case 9:
		  	d = 30;
			break;
			
		  case 11:
		  	d = 30;
			break;
		  case 2:
		  	d = 29;
			break;
			
		}
		for (j = 0; j < d; j++){
			date[i][j] = day;
			day++;
			if (day > 7){
				day = 1;
			}
		}
	}
	while (scanf("%d %d", &i, &j),  i != 0 && j != 0){
		switch (date[i - 1][j - 1]){
		  case 1:
		  	printf("Sunday\n");
			break;
			
		  case 2:
		  	printf("Monday\n");
			break;
			
		  case 3:
		  	printf("Tuesday\n");
			break;
			
		  case 4:
		  	printf("Wednesday\n");
			break;
			
		  case 5:
			printf("Thursday\n");
			break;
			
		  case 6:
		  	printf("Friday\n");
			break;
			
		  case 7:
		  	printf("Saturday\n");
			break;
		}
	}
	
	return (0);
}

Measured memory_bytes: 580
while True :
    m, f, r = map(int, input().split())
    m, f <= 50
    r <= 100
    s = m + f
    if m == -1 and f == -1 and r == -1 :
        break
    if m == -1 or f == -1 :
        print("F")
    elif 80 <= s :
        print("A")
    elif 65 <= s < 80 :
        print("B")
    elif 50 <= s < 65 :
        print("C")
    elif 30 <= s < 50 :
        if 50 <= r :
            print("C")
        else :
            print("D")
    else :
        print("F")


Measured memory_bytes: 5596
use std::io::Read;
use std::cmp::min;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let m: usize = it.next().unwrap().parse().unwrap();
    let inf = 1_000_000;
    let mut dp = vec![inf; 1 << n];
    for _ in 0..m {
        let a: u32 = it.next().unwrap().parse().unwrap();
        let b: usize = it.next().unwrap().parse().unwrap();
        let mut bit = 0;
        for _ in 0..b {
            let c = it.next().unwrap().parse::<usize>().unwrap() - 1;
            bit |= 1 << c;
        }
        dp[bit] = min(dp[bit], a);
        let mut i = (bit - 1) & bit;
        while i > 0 {
            dp[i] = min(dp[i], a);
            i = (i - 1) & bit;
        }
    }
    dp[0] = 0;
    for i in 1..(1 << n) {
        let mut j = (i - 1) & i;
        while j > 0 {
            dp[i] = min(dp[i], dp[j] + dp[i ^ j]);
            j = (j - 1) & i;
        }
    }
    if dp[(1 << n) - 1] >= inf {
        println!("-1");
    } else {
        println!("{}", dp[(1 << n) - 1]);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>

#define EQUAL 1
#define NOT_EQ 0

int main(){
    char S[20],T[20];
    int i, flag= EQUAL;

    scanf("%s", S);
    scanf("%s", T);

    auto T_len = strlen(T);
    auto S_len = strlen(S);

    if(T_len == S_len+1 && strncmp(T,S,S_len)==0){
        printf("Yes");
    }else{
        printf("No");
    }
}

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

struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};

typedef struct node *Node;
#define NIL NULL

Node root;

Node find(Node u,int k){
  while(u != NIL && k != u->key){
    if(k < u->key)u = u->l;
    else u = u->r;
  }
  return u;
}

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->r = NIL;
  z->l = NIL;

   while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->l;
      
    }else{
      x = x->r;
    }
  }
  z->p = y;
  if(y == NIL){
    root = z;
  }else{
    if(z ->key < y->key){
      y->l = z;
      
    }else{
      y->r = z;
    }
  }
}
    
void inorder(Node u){
    if(u == NIL){
  return;
}
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}

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

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);
      Node t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
      
    }
  }
  return 0;
}



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

int main() {
	int n,a_max;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	map<int,int> mp;
	
	for(int i=0;i<n;i++) {
		mp[a[i]]++;
	}
	
	int ans=0;
	for(auto x : mp) {
		int n = x.first;
		int m = x.second;
		if(m < n) ans += m;
		else ans += m-n;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5120
#include <iostream>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int n, i, j, num=0, flag=0;
  cin >> n;
  int a[n];
  for(i=0; i<n; i++)
    cin >> a[i];
  sort(a, a+n);
  num++;
  for(i=1; i<n; i++){
    if(a[i]!=a[i-1]){
      flag=0;
      num++;
    }
    if(a[i]==a[i-1]){
      if(flag==0){
	num--;
	flag=1;
      }
      else{
	num++;
	flag=0;
      }
    }
  }
  cout << num;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
// #define int long long
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

// auto mod int
const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint (ll x = 0) : x ((x % mod + mod) % mod) {}
    mint operator-() const { return mint (-x); }
    mint &operator+= (const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-= (const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*= (const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+ (const mint a) const { return mint (*this) += a; }
    mint operator- (const mint a) const { return mint (*this) -= a; }
    mint operator* (const mint a) const { return mint (*this) *= a; }
    mint pow (ll t) const {
        if (!t) return 1;
        mint a = pow (t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const { return pow (mod - 2); }
    mint &operator/= (const mint a) { return *this *= a.inv(); }
    mint operator/ (const mint a) const { return mint (*this) /= a; }
};
istream &operator>> (istream &is, const mint &a) { return is >> a.x; }
ostream &operator<< (ostream &os, const mint &a) { return os << a.x; }

// combination mod prime
struct combination {
    vector<mint> fact, ifact;
    combination (int n) : fact (n + 1), ifact (n + 1) {
        assert (n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    mint operator() (int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
    mint p (int n, int k) { return fact[n] * ifact[n - k]; }
} c (300000);

signed main() {
    int n, m, k;
    cin >> n >> m >> k;
    mint ans = 0;
    mint sum = 1;
    per (i, 0, n) {
        if (i <= k) ans += c (n - 1, i) * m * sum;
        sum *= (m - 1);
        // cout << ans << "\n";
    }
    cout << ans << "\n";
}


Measured memory_bytes: 7744
n=int(input())
arr=[int(i) for i in input().strip().split(" ")]
t=int(input())
dic={}
sum_array=0
for i in arr:
    dic[i]=dic.get(i,0)+1
    sum_array+=i
    

for _ in range(t):
    a,b=[int(i) for i in input().split(" ")]
    if a not in dic:
        print(sum_array)
        continue
    if b in dic:
        dic[b]+=dic[a]
    else:
        dic[b]=dic[a]
    
    sum_array+=dic[a]*(b-a)
    print(sum_array)
    dic[a]=0

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

using namespace std;
 
int main() {

int A, B, C, X;
cin >> A >> B >> C >> X;

int count = 0;

    for (int a = 0; a < A + 1; a++)
    {
        for (int b = 0; b < B + 1; b++)
        {
            for (int c = 0; c < C + 1; c++)
            {
                int total = 500 * a + 100 * b + 50 * c;
                
                if (total == X)
                {
                    count++;
                }
                
            }
            
        }
        
    }

cout << count << endl;

}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const inf = 1 << 60

func solve() {
	n, k := getInt(), getInt()
	xs := getIntSlice(n)

	l, r := 0, k-1
	ans := inf
	for r < n {
		distL := abs(min(xs[l], 0))
		distR := abs(max(xs[r], 0))

		ans = min(ans, distL*2+distR)
		ans = min(ans, distR*2+distL)

		l++
		r++
	}

	fmt.Fprintln(wr, ans)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// -----------------------------------------

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 2944
//#include <atcoder/fenwicktree>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 2e5 + 100, INF = 1e9 * 1e9 + 10;

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

ll binpow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
	}
	return res;
}

ll dsu[SIZE], sz[SIZE];
ll n;

ll find(int v) {
	if (dsu[v] == v) return v;
	else return dsu[v] = find(dsu[v]);
}

void uni(int v, int u) {
	u = find(u);
	v = find(v);

	if (u != v) {
		dsu[u] = v;
		sz[v] += sz[u];
	}
}

int main() {
	fastInp;

	cin >> n;

	vector<ll> ans;
	vector<tuple<ll, ll, ll>> vec;

	for (int i = 0; i < n; i++) {
		dsu[i] = i;
		sz[i] = 1;
		ll x, y;
		cin >> x >> y;
		vec.push_back({ x, y, i });
	}

	sort(vec.begin(), vec.end());

	vector<pair<ll, ll>> cur_s;
	for (int i = 0; i < n; i++) {
		while (!cur_s.empty()) {
			if (cur_s.back().first < get<1>(vec[i])) {
				uni(cur_s.back().second, get<2>(vec[i]));
				cur_s.pop_back();
			}
			else {
				break;
			}
		}

		cur_s.push_back({ get<1>(vec[i]), get<2>(vec[i]) });
	}

	cur_s.clear();

	for (int i = n - 1; i >= 0; i--) {
		while (!cur_s.empty()) {
			if (cur_s.back().first > get<1>(vec[i])) {
				uni(cur_s.back().second, get<2>(vec[i]));
				cur_s.pop_back();
			}
			else {
				break;
			}
		}

		cur_s.push_back({ get<1>(vec[i]), get<2>(vec[i]) });
	}

	set<pair<ll, ll>> s;

	for (int i = 0; i < n; i++) {
		if (s.empty()) {
			pair<ll, ll> v = { get<1>(vec[i]), get<2>(vec[i]) };
			s.insert(v);
			continue;
		}
		pair<ll, ll> mn = { INF, INF };
		while (!s.empty()) {
			if ((*(s.begin())).first < get<1>(vec[i])) {
				uni((*(s.begin())).second, get<2>(vec[i]));
				mn = min(mn, *(s.begin()));
				s.erase(s.begin());
			}
			else {
				break;
			}
		}

		if (mn.first == INF) {
			s.insert({ get<1>(vec[i]), get<2>(vec[i]) });
		}
		else {
			s.insert(mn);
		}
	}
	
	for (int i = 0; i < n; i++) {
		cout << sz[find(i)] << "\n";
	}

	return 0;
}

Measured memory_bytes: 22088
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <map>
using namespace std;
map<int, int>ma;
int n, ai[100010], sum[100010], num;
bool vis[100010];
int main()
{
	int i, j;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &ai[i]);
		if (ma.count(ai[i]) != 0) sum[ma[ai[i]]]++;
		else
		{
			ma[ai[i]] = ++num;
			sum[num]++;
		}
	}
	int ans = 0;
	for (i = 1; i <= n; i++)
	{
		int now = ma[ai[i]];
		if (vis[now] == 1) continue;
		if (ai[i] > sum[now])
		{
			ans += sum[now];
		}
		else ans += sum[now] - ai[i];
		vis[now] = 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 5632
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <map>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)
#define copy(x,t) memcpy(x,t,sizeof(x))
#define fi first
#define se second

typedef long long LL;
typedef std:: pair <LL,LL> pair;
const int MOD1=1000000007;
const int MOD2=1000000009;
const int N=200005;

std:: map <pair,bool> map;

char str[N],last[N];

int main(void) {
	int n,lastlen; scanf("%d",&n);
	rep(i,1,n) {
		scanf("%s",str+1);
		int len=strlen(str+1);
		pair now(pair(0,0));
		rep(i,1,len) {
			now.fi=(now.fi*37LL%MOD1+str[i])%MOD1;
			now.se=(now.se*29LL%MOD2+str[i])%MOD2;
		}
		if (map[now]) {
			puts("No"); return 0;
		}
		map[now]=true;
		if (i!=1) {
			if (str[1]!=last[lastlen]) {
				puts("No"); return 0;
			}
		}
		copy(last,str); lastlen=len;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 384
def f(n, s, t):
    for i in range(2, n):
        if (t[i-2] == t[i-1] and s[i-1] == 'o') or (t[i-2] != t[i-1] and s[i-1] == 'x'):
            t += 'S'
        else:
            t += 'W'
    for i in range(0, 2):
        if (t[(i+n-2)%n] == t[(i+n-1)%n] and s[(i+n-1)%n] == 'o') or (t[(i+n-2)%n] != t[(i+n-1)%n] and s[(i+n-1)%n] == 'x'):
            if t[i] != 'S': return ":("
        else:
            if t[i] != 'W': return ":("
    return t
n = int(input())
s = input()
u = ["SS", "SW", "WS", "WW"]
for i in range(4):
    t = f(n, s, u[i])
    if t != ":(":
        print(t)
        exit(0)
print(-1)



Measured memory_bytes: 3444
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
void File(){
	freopen("1.in","r",stdin);
	freopen("2.out","w",stdout);
}
#define REP(i,a,b) for(register int i=a;i<=b;++i)
#define DREP(i,a,b) for(register int i=a;i>=b;--i)
#define MREP(i,x) for(register int i=beg[x];i;i=E[i].last)
#define ll long long
int n;
int main(){
//	File();
	scanf("%d",&n);
	REP(i,1,n){
		ll a,b;
		scanf("%lld%lld",&a,&b);
		ll dd=sqrt(a*b),ans=dd*2-1;
		if(dd*dd==a*b){
			if(a==b)ans--;
			else ans-=2;
		}
		else if(dd*(dd+1)>=a*b)ans--;
		cout<<ans<<endl;
	}	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	int m = 1 << n;
	vector<int> a(m);
	for (int i = 0; i < m; ++i) scanf("%d", &a[i]);
	sort(a.begin(), a.end(), greater<int>());
	vector<multiset<int>> bags(n + 1);
	bags[n].insert(INT_MAX);
	for (int i = 0; i < m; ++i) {
		bool found = false;
		for (int j = n; j >= 0; --j) {
			if (!bags[j].empty() && *bags[j].rbegin() > a[i]) {
				bags[j].erase(prev(bags[j].end()));
				for (int k = 0; k < j; ++k) bags[k].insert(a[i]);
				found = true;
				break;
			}
		}
		if (!found) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
}


Measured memory_bytes: 7424
#include<bits/stdc++.h>
#define INFTY 10000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};

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

    int l = n.size();
    int dp0[105][4],dp1[105][4];
    dp0[1][1] = max(0,(n[0]-'0')-1);
    dp0[1][0] = 1;
    dp1[1][0] = 0;
    dp1[1][1] = 1;
    rep(i,2){dp1[1][i+2] = 0;dp0[1][i+2]=0;}
    for (int i = 2; i <= l; i++)
    {
        dp0[i][0] = 1;dp1[i][0] = 0;
        for (int j = 1; j < 4; j++)
        {
            dp0[i][j] = dp0[i-1][j-1]*9+dp0[i-1][j]+dp1[i-1][j-1]*max(0,((n[i-1]-'0')-1))+dp1[i-1][j];
            if(n[i-1]=='0'){dp1[i][j] = dp1[i-1][j];dp0[i][j] -=dp1[i-1][j];}
            else dp1[i][j] = dp1[i-1][j-1];    
        }
    }
    
    cout<<dp0[l][k]+dp1[l][k]<<endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int D = sc.nextInt();
   int N = sc.nextInt();

   int a ;
   if(N == 100) a = 101; 
   else a = N;
   
   if(D==0) System.out.println(a);
   else if(D==1) System.out.println(a*100);
   else if(D==2) System.out.println(a*10000);
 }
}

Measured memory_bytes: 25172
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readContents 4 >>= printRes . solve
    where
        printRes = mapM_ print

solve :: [[Int]] -> [Int]
solve [[_, _, _, k], as, bs, cs] = take k $ sortBy (flip compare) [a + bc | a <- as, bc <- bcs]
    where
        bcs = take k $ sortBy (flip compare) [b + c | b <- bs, c <- cs]


readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

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

typedef long long int ll;
ll large = 1000000000;
int main()
{
	ll s;
	cin >> s;

	ll x1 = 1e9;
	if(s > large)
	{
		if(s%x1 == 0)
			cout << x1 << " 0 0 " << s/x1 << " 0 0\n";
		else
			cout << x1 << " 0 " << s%x1 << " " << 1 + s/x1 << " " << "0 1\n";

		// ll sum = x1*(s/x1) + s%x1;
		// cout << sum << "\n";
	}
	else
	{
		cout << s  << " 0 0 1 0 0\n";
	}
}

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

int main() {
    int N; cin >> N;
    string s; cin >> s;
    string t;
    for (int i = 0; i < N; i++)
    {
        if(s[i]=='(') t += '(';
        else if(t[t.size()-1]=='('){
            t.erase(t.size()-1);
        } else {
            t += ')';
        }
    }
    //cout << t << endl;
    int pre, pos; pre = pos = 0;
    for (int i = 0; i < t.size(); i++)
    {
        if(t[i]=='(') pre++;
        else pos++;
    }
    string ma = string(pos, '(');
    string at = string(pre, ')');

    cout << ma + s + at << endl;
        
}

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

int main() {
  string s;
  cin >> s;
  string ans;
  int ni = s.size()-1;
  if (s[ni] == '3') ans = "bon";
  else if (s[ni] == '0' || s[ni] == '1' || s[ni] == '6' || s[ni] == '8') {
    ans = "pon";
  } else ans = "hon";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(non_snake_case)]
fn main() {
    input![X: usize, A: usize];
    println!("{}", if X < A { 0 } else { 10 });
}


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

#define INF (INT32_MAX)
#define MAX 5

int a[MAX];
int k;
int d[5*5*5*5*5];

int main() {
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

	int k = 0;
	do {
		d[k] = 0;
		for( int i = 0; i < 5; i++ ) {
			d[k] += a[i];
			if( i < 5 - 1 ) {
				if( d[k] % 10 ) {
					d[k] = (d[k] / 10 + 1) * 10;
				}
			}
		}
		k++;
	} while( next_permutation( a, a + 5 ) );
	sort( d, d + k );
	int ans = d[0];

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
int A,B,c;
scanf("%d %d",&A,&B);
if(A+B>A-B){
	c=A+B;
    }
else{
	c=A-B;
    }
if(A*B>c){
	c=A*B;
    }
printf("%d",c);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
typedef long long ll;
using namespace std;

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

int main()
{
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<int> left(N+1,0);
    vector<int> right(N+1,0);
    for(int i = 0; i < N; i++)left[i+1] = GCD(left[i],A[i]);
    for(int i = N - 1; i >= 0; i--) right[i] =GCD(right[i+1],A[i]);

    int res = 0;
    for(int i = 0; i < N; i++)
    {
        int l = left[i];
        int r = right[i+1];

        res = max(res,GCD(l,r));
    }
    cout << res << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
	int A,B,C;
	scanf("%d %d %d", &A, &B, &C);
	if (A==B) {
	printf("%d\n",C);
	} else {
		if (A==C) {
		printf("%d\n",B);
		} else {
		printf("%d\n",A);
		}
	}
}

Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
S=int(input())
ans=0
for i in range(1,S+1):
  #iこの数列
  if S<3*i:
    break
  a=S-(2*i)
  ans+=cmb(a-1,i-1,mod)
print(ans%mod)

Measured memory_bytes: 10296
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)
 
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout << min(a + b + 1, c) + b << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char x[101][101];
int n,m,s; 
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++) cin>>x[i][j];
    for(int i=1;i<=n;i++)
	{
        for(int j=1;j<=m;j++)
        {
            s=0;
            if(x[i][j]=='#') cout<<'#';
            else         
            {
                if(x[i-1][j]=='#') s++; 
				if(x[i+1][j]=='#') s++; 
				if(x[i][j+1]=='#') s++; 
				if(x[i][j-1]=='#') s++; 
                if(x[i-1][j-1]=='#') s++; 
                if(x[i-1][j+1]=='#') s++;
                if(x[i+1][j-1]=='#') s++;
				if(x[i+1][j+1]=='#') s++; 
                cout<<s;
            }
        }
        cout<<endl;
    }   
    return 0;     
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func intMin(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func intMax(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := scanInt(), scanInt()

	left, right := 1, N
	for i := 0; i < M; i++ {
		L, R := scanInt(), scanInt()
		left = intMax(left, L)
		right = intMin(right, R)
	}

	fmt.Println(intMax(right-left+1, 0))
}


Measured memory_bytes: 1792
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];
    auto ps = readln.split.to!(int[]);

    auto cs = new int[](N);
    foreach (i; 0..N-1) {
        if (ps[i+1] < ps[i]) {
            cs[i+1] -= 1;
            cs[max(0, i-K+2)] += 1;
        }
    }
    foreach (i; 1..N) cs[i] += cs[i-1];

    auto rbt = new RedBlackTree!int(ps[0..K]);
    int r;
    bool not_change;
    if (cs[0] == 0) {
        not_change = true;
    } else {
        r = 1;
    }
    foreach (i; 0..N-K) {
        if (ps[i] != rbt.front || ps[i+K] < rbt.back) {
            if (cs[i+1] == 0) {
                not_change = true;
            } else {
                ++r;
            }
        }
        rbt.removeKey(ps[i]);
        rbt.insert(ps[i+K]);
    }
    writeln(r + (not_change ? 1 : 0));
}


Measured memory_bytes: 18340
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int pm(int a,int n=mod-2){
	if(n==0)return 1;
	if(n==1)return a;
	int x=pm(a,n/2);
	x=(x*x)%mod;
	if(n%2)x=(x*a)%mod;
	return x;
}
int32_t main(){
	if(fopen("input.txt", "r"))
		freopen("input.txt", "r", stdin),
		freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,sum=0;
	cin >> n;
	int a[n],v[n]={0},f=1;
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int i=1;i<n;i++)
		v[i]=(v[i-1]+pm(i))%mod,
		f=(f*i)%mod;
	for(int i=1;i<n;i++)
		sum=(sum+(v[i]*(a[i]-a[i-1]))%mod)%mod;
	cout << (f*sum)%mod;
}


Measured memory_bytes: 1792
n = int(input())

if 400 <= n <= 599:
  ans=8
elif 600 <=n <=799:
  ans=7
elif 800 <=n <=999:
  ans=6
elif 1000 <=n <=1199:
  ans=5
elif 1200 <=n <=1399:
  ans=4
elif 1400 <=n <=1599:
  ans=3
elif 1600 <=n <=1799:
  ans=2
elif 1800 <=n <=1999:
  ans=1

  
print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N, X;
  cin >> N >> X;
  int m[1100];
  for(int i = 0; i < N; i++)
  {
    cin >> m[i];
  }
  
  //それぞれ１つずつ作ったときの残りの粉の量
  int powder_first = 0;
  for(int i = 0; i < N; i++)
  {
     powder_first += m[i];
  }
  int powder = X - powder_first;
  
  //一番粉消費が少ないやつ
  int mn = m[0];
  for(int i = 0; i < N; i++)
  {
     if(m[i] < mn) mn = m[i];
  }
  
  //何個作れるか
  int ans = powder/mn + N;
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  if (N==2) cout << -1 << endl;
  else if (N==3) {
    cout << "aa." << endl;
    cout << "..b" << endl;
    cout << "..b" << endl;
  }
  else {
    rep(i,N/4-1) {
      rep(j,i*4) cout << "."; cout << "aacd"; rep(j,N-(i+1)*4) cout << "."; cout << endl;
      rep(j,i*4) cout << "."; cout << "bbcd"; rep(j,N-(i+1)*4) cout << "."; cout << endl;
      rep(j,i*4) cout << "."; cout << "cdaa"; rep(j,N-(i+1)*4) cout << "."; cout << endl;
      rep(j,i*4) cout << "."; cout << "cdbb"; rep(j,N-(i+1)*4) cout << "."; cout << endl;
    }
    if (N%4==0) {
      rep(j,N-4) cout << "."; cout << "aacd"; cout << endl;
      rep(j,N-4) cout << "."; cout << "bbcd"; cout << endl;
      rep(j,N-4) cout << "."; cout << "cdaa"; cout << endl;
      rep(j,N-4) cout << "."; cout << "cdbb"; cout << endl;
    }
    else if (N%4==1) {
      rep(j,N-5) cout << "."; cout << "aabbc"; cout << endl;
      rep(j,N-5) cout << "."; cout << "hii.c"; cout << endl;
      rep(j,N-5) cout << "."; cout << "h..jd"; cout << endl;
      rep(j,N-5) cout << "."; cout << "g..jd"; cout << endl;
      rep(j,N-5) cout << "."; cout << "gffee"; cout << endl;
    }
    else if (N%4==2) {
      rep(j,N-6) cout << "."; cout << "aa..cd"; cout << endl;
      rep(j,N-6) cout << "."; cout << "bb..cd"; cout << endl;
      rep(j,N-6) cout << "."; cout << "cdaa.."; cout << endl;
      rep(j,N-6) cout << "."; cout << "cdbb.."; cout << endl;
      rep(j,N-6) cout << "."; cout << "..cdaa"; cout << endl;
      rep(j,N-6) cout << "."; cout << "..cdbb"; cout << endl;
    }
    else if (N%4==3) {
      rep(j,N-7) cout << "."; cout << "aabbcc."; cout << endl;
      rep(j,N-7) cout << "."; cout << "g..i..d"; cout << endl;
      rep(j,N-7) cout << "."; cout << "g..i..d"; cout << endl;
      rep(j,N-7) cout << "."; cout << ".hh.jje"; cout << endl;
      rep(j,N-7) cout << "."; cout << "k..m..e"; cout << endl;
      rep(j,N-7) cout << "."; cout << "k..m..f"; cout << endl;
      rep(j,N-7) cout << "."; cout << ".ll.nnf"; cout << endl;
    }
  }
  return 0;
}

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

using namespace std;

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

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int n, m;
vector<int> g[112345];
bool done[112345];

int main() {
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	deque<int> deq;
	deq.push_back(0);
	deq.push_back(g[0][0]);
	
	done[0] = done[g[0][0]] = true;
	
	while (true) {
		bool end = true;
		
		REP(t, 2) {
			int u;
			if (t == 0) u = deq.back();
			else u = deq.front();
			
			REP(i, g[u].size()) {
				int v = g[u][i];
				if (!done[v]) {
					if (t == 0) deq.push_back(v);
					else deq.push_front(v);
					done[v] = true;
					end = false;
					break;
				}
			}
		}
		
		if (end) break;
	}
	
	cout << deq.size() << endl;
	while (!deq.empty()) {
		printf("%d%c", deq.front() + 1, deq.size() == 1 ? '\n' : ' ');
		deq.pop_front();
	}
	
	return 0;
}


Measured memory_bytes: 7040
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N = int(input())
G = [[] for _ in range(N+1)]
for _ in range(N-1):
    A, B = map(int, input().split())
    G[A].append(B)
    G[B].append(A)
K = int(input())
num = [-1] * (N+1)
for _ in range(K):
    V, P = map(int, input().split())
    num[V] = P

# check parity
stack = [1]
depth = [-1] * (N+1)
depth[1] = 0
while stack:
    v = stack.pop()
    for c in G[v]:
        if depth[c] == -1:
            depth[c] = depth[v] + 1
            stack.append(c)
parity = [set(), set()]
for i in range(1, N+1):
    if num[i] != -1:
        parity[depth[i] % 2].add(num[i] % 2)
if len(parity[0]) == 2 or len(parity[1]) == 2:
    print('No')
    exit()

INF = 10**9
lb = [-INF] * (N+1)
ub = [INF] * (N+1)

def dfs1(v, p):
    for c in G[v]:
        if c == p:
            continue
        dfs1(c, v)
        lb[v] = max(lb[v], lb[c] - 1)
        ub[v] = min(ub[v], ub[c] + 1)
    if num[v] != -1:
        lb[v] = ub[v] = num[v]

dfs1(1, 0)

def dfs2(v, p):
    if lb[v] > ub[v]:
        print('No')
        exit()
    for c in G[v]:
        if c == p:
            continue
    for c in G[v]:
        if c == p:
            continue
        lb[c] = max(lb[c], lb[v] - 1)
        ub[c] = min(ub[c], ub[v] + 1)
        if lb[c] <= num[v] - 1:
            num[c] = num[v] - 1
        else:
            num[c] = num[v] + 1
        dfs2(c, v)

num[1] = lb[1]
dfs2(1, 0)
print('Yes')
print(*num[1:], sep='\n')

Measured memory_bytes: 211664
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

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

int main() {
	int N, W; cin >> N >> W;
	vector<long long>w(N), v(N);
	for (int i = 0; i < N; i++)cin >> w[i] >> v[i];
	vector<vector<long long>> dp(N+1, vector<long long>(W + 1, 0));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < W; j++) {
			chmax(dp[i + 1][j], dp[i][j]);
			if (j + w[i] > W)continue;
			chmax(dp[i + 1][j+w[i]], dp[i][j] + v[i]);
		}
	}
	long long ans = 0;
	for (int i = 0; i <= W; i++) chmax(ans, dp[N][i]);
	cout << ans << endl;
}





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

using namespace std;

typedef long long ll;
const int N = 200001;
const int MOD = 1e9 + 7;
int arr[N];
int dp[N];
int lst[N];
signed main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  for(int i = 0;i < n;i++)
    cin >> arr[i];
  dp[n] = 1;
  memset(lst, -1, sizeof(lst));
  for(int i = n - 1;i >= 0;i--){
    if(lst[arr[i]] == -1){
      dp[i] = dp[i + 1];
    }else{
      dp[i] = dp[lst[arr[i]]];
      if(arr[i + 1] != arr[i])
        dp[i] += dp[i + 1];
      dp[i] %= MOD;
    }
    lst[arr[i]] = i;
  }

  cout << dp[0];
  return 0;
}


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

using namespace std;

int main() {
  int N;
  string S, T;
  cin >> N >> S >> T;

  string result;
  for (int i = 0; i < N; i++) {
    result += S[i];
    result += T[i];
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int x,y,r,w,h,a,b;
    cin>>w>>h>>x>>y>>r;
    if((x-r)<0||(y-r)<0){
        cout<<"No"<<endl;
        return 0;
    }
    if((x+r)<=w&&(y+r)<=h){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}



Measured memory_bytes: 3092
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    //    ifstream in("input.txt");
    //    cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    int sum = -n;
    rep(i, n)
    {
        cin >> a[i];
        sum += a[i];
    }
    
    cout << sum << endl;
    
    return 0;
}

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

int N;
int A[210];  

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];

    int res = 0;

    while (true) {
        bool exist_odd = false; 
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;  
        }

        if (exist_odd) break;  

        
        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res;  
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int a,b,c,ans;
  scanf("%d%d%d",&a,&b,&c);
  ans=a+b;
  if(a+c<ans)
  {
    ans=a+c;
  }
  if(b+c<ans){
    ans=b+c;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
int main(void){
  int i,n,r,p,c;
  int m[50],tmp[50];

  while(1){
    scanf("%d%d",&n,&r);
    if(!n && !r) break;

    for(i=0;i<n;i++){
      m[i] = n-i;
    }

    while(r--){
      scanf("%d%d",&p,&c);
      for(i=0;i<p-1;i++){
        tmp[i+c] = m[i];
      }
      for(;i<p+c-1;i++){
        tmp[i-p+1] = m[i];
      }
      for(;i<n;i++){
        tmp[i] = m[i];
      }
      for(i=0;i<n;i++){
        m[i] = tmp[i];
      }
    }
    printf("%d\n",m[0]);
  }

  return 0;
}

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

int main() 
{  
    int i,j,a[200001],p,n;
    vector<int>adj[200001];
    cin>>n;
    for(i=2;i<=n;i++)
    {
        cin>>p;
        adj[p].push_back(i);
    }
    for(i=1;i<=n;i++)
        cout<<adj[i].size()<<endl;
    
	
} 


Measured memory_bytes: 14536
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

const int MAX = 1000;
const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX + 1];

int solve() {
    int ans = 0;
    bool V[MAX];

    for (int i = 0; i < n; ++i) {
        B[i] = A[i];
        V[i] = false;
    }
    sort(B, B + n);

    for (int i = 0; i < n; ++i) {
        T[B[i]] = i;
    }

    for (int i = 0; i < n; ++i) {
        if (V[i]) {
            continue;
        }

        int cur = i;
        int S = 0;
        int m = VMAX;
        int an = 0;
        while (true) {
            V[cur] = true;
            an++;
            int v = A[cur];
            m = min(m, v);
            S += v;
            cur = T[v];
            if (V[cur]) {
                break;
            }
        }

        ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
    }

    return ans;
}

int main() {
    cin >> n;
    s = VMAX;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
        s = min(s, A[i]);
    }

    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3176
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
	int a,b;
	cin >> a;
	cin >> b;
	int cnt = 0;
	int ans = 1;
	int add_num = a-1;

	while(ans<b){
		ans += add_num;
		cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
from math import pi, ceil, floor
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
from bisect import bisect_left, bisect_right, insort_left, insort_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    n = int(input())
    if n == 1:
        print("Hello World")
    else:
        a = int(input())
        b = int(input())
        print(a + b)

if __name__ == '__main__':
    main()

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

int N;
int A[100010];
int ans = 0;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)scanf("%d",A + i);
    for(int i = 0; i < N; i++)
    {
        if(A[i] == i + 1)
        {
            ans++;
            i++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  using ll = long long;
  ll X;
  cin >> X;
  int ans = 0;
  ll m = 100;
  while (m < X)++ans, m += m / 100;
  cout << ans << endl;
}


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

int main(){
    string o,e,p="";
    cin>>o>>e;
    for(int i=0;i<o.size();i++){
        p+=o[i];
        if(i<e.size()) p+=e[i];
    }
    cout<<p<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();
		
		long[][] a = new long[n][m];
		long[][] b = new long[m][l];
		long[][] c = new long[n][l];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		
		for(int i = 0; i < m; i++) {
			for(int j = 0; j < l; j++) {
				b[i][j] = sc.nextInt();
			}
		}
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				for(int k = 0; k < l; k++) {
					c[i][k] += a[i][j] * b[j][k];
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < l; j++) {
				if(j< l-1) System.out.print(c[i][j] + " ");
				else System.out.println(c[i][j]);
			}
		}
	}
}



Measured memory_bytes: 53700