akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  int n;cin >> n;
  vector<int> a(100001);
  vector<int> b(100001);
  rep(i,n){
    int t;cin >> t;
    if(i%2==0)a[t]++;
    else b[t]++;
  }
  int aM=0;
  int bM=0;
  int aa,bb;
  rep(i,100001){
    aM=max(aM,a[i]);
    bM=max(bM,b[i]);
    if(aM==a[i])aa=i;
    if(bM==b[i])bb=i;
  }
  if(aa!=bb){
    cout << n-aM-bM << endl;
    return 0;
  }
  
  int am=0;int bm=0;
  if(aa==bb){
    rep(i,100001){
      if(i!=aa)am=max(a[i],am);
      if(i!=bb)bm=max(b[i],bm);
    }
  }
  cout << min(n-am-bM,n-aM-bm) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
 
using namespace std;

void solve(){

	return;
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);


	long long int n,m,cont=0;
	
	cin >> n >> m;
	vector<int>v(n);
	for(int i=0;i<n;i++)
		cin >> v[i];

	sort(all(v));
	reverse(all(v));

	for(int i=m;i<n;i++){
		cont+=v[i];
	}	

	cout << cont << endl;
	return 0;
}

Measured memory_bytes: 1024
//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define nl cout<<"\n";
#define chk(x) cout<<#x<<" : "<<x, nl
#define ll long long int
#define u unsigned
#define vi vector<int>
#define vvi vector<vi>
#define pr pair<ll, ll>
#define vii vector<pair<int, int>>
#define vll vector<pr>
#define vl vector<ll>
#define m(a,b) map<a, b>
#define ci m(char, ll)
#define ii m(ll, ll)
#define mid(a,b) ((a+b)/2)
#define pb push_back
#define LCM(a,b) ((a*b)/__gcd(x,y))
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

class triplet{
    ll f, s, t;};

vl in(ll n){vl v;ll x;
    f(i,n)
    cin>>x, v.pb(x);
    return v;}
void out(vl v){
    fl(i,v)cout<<i;
}
void out(vl v, char ch){
    fl(i,v)
    cout<<i<<ch;
}

void solve(){
    ll N;
    cin>>N;
    cout<<N*(N-1)/2;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
   return 0;
}

Measured memory_bytes: 3608
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, K;
    cin >> N >> K;

    struct Sushi {
        ll t, d;
    };
    vector<Sushi> sushis(N);
    for (ll i = 0; i < N; i++) {
        cin >> sushis[i].t >> sushis[i].d;
        sushis[i].t--;
    }

    sort(sushis.begin(), sushis.end(), [&](Sushi& lhs, Sushi& rhs) {
        return lhs.d > rhs.d;
    });

    ll temp = 0, size = 0;
    vector<ll> s(N, 0);
    for (ll i = 0; i < K; i++) {
        temp += sushis[i].d;
        if (s[sushis[i].t]++ == 0) {
            size++;
        }
    }

    ll ans = temp + size * size;
    ll left = K - 1, right = K;
    while (true) {
        while (0 <= left && s[sushis[left].t] == 1) {
            left--;
        }
        while (right < N && s[sushis[right].t] > 0) {
            right++;
        }
        if (0 > left || right >= N) {
            break;
        }
        temp += sushis[right].d - sushis[left].d;
        size++;
        ans = max(ans, temp + size * size);
        s[sushis[right++].t]++;
        s[sushis[left--].t]--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2688
#include <cstdio>
int main()
{
    int n, s;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        printf("Case %d:\n", i+1);
        scanf("%d", &s);
        for (int j = 0; j < 10; ++j) {
            s = ((s * s) / 100) % 10000;
            printf("%d\n", s);
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){	
  string s; cin>>s;
  if(s=="ABC")
    cout<<"ARC\n";
  else
    cout<<"ABC\n";
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


Measured memory_bytes: 3616
import sys

# import math
# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    d = []
    for i in range(n):
        s, p = input().split()
        d.append((s, int(p), i + 1))

    tmp = sorted(d, key=lambda x: x[1], reverse=True)
    tmp1 = sorted(tmp, key=lambda x: x[0])

    for t in tmp1:
        print(t[2])


if __name__ == '__main__':
    main()


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

int n;

int main() {
    cin >> n;

    long ans = 0;
    for(int i = 1; i <= n; i++) {
        int len = to_string(i).size();
        ans += (len % 2 == 1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
    string str, order, content, str_m;
    int cnt, a, b;
    cin >> str >> cnt;
    for (int i=0; i<cnt; i++){
        cin >> order >> a >> b;
        if (order == "replace"){
            cin >> content;
            str = str.replace(a, b-a+1, content);
        } else if (order == "reverse" && a != b){
            str_m = "";
            for (int j=0; j<str.size(); j++){
                if (a<=j && j<=b) str_m += str[b+a-j];
                else str_m += str[j];
            }
            str = str_m;
        } else if (order == "reverse" && a == b){
            continue;
        } else {
            for (int j=0; j<=(b-a); j++){
                if (j == b-a) cout << str[j+a] << endl;
                else cout << str[j+a];
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  
  int N;
  int sum=0;
  cin >> N;
  vector<int>A(N);
  rep(i,N)cin >> A.at(i);
  rep(i,N-1){
    for(int j=1+i;j<N;j++){
      sum += A.at(i)*A.at(j);
    }
  }
  cout<<sum<<endl;

}

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

def calc(x):
    count = 0
    while x > 0:
        count += x % 10
        x = x // 10
    return count

cnt = 0
for i in range(1, n+1):
    result = calc(i)
    if a <= result and result <= b:
        cnt += i
print (cnt)


Measured memory_bytes: 2940
#define inf 9223372036854775807
#define ll long long
#define pii pair<ll,ll>
#define m_p  make_pair
#define ull unsigned long long
#define spd  ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
const ll N = 2e5 + 5;
ll arr[N];
const ll M = 1e9+7;
int main()
{
    spd

    ll n,i,j,k,sum=0,ans=0,var=0;

    cin>>n;

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

    for(i=0;i<n;i++)
    {
        sum+=arr[i];

        sum%=M;
    }

    for(i=0;i<n-1;i++)
    {
        sum-=arr[i];

        if(sum<0)sum+=M;

        ans+=((arr[i]%M)*(sum%M))%M;
        ans%=M;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 5176
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
using namespace std;
int max(int a,int b){
    return (a > b)?a:b;
}
int min(int a,int b){
    return (a < b)?a:b;
}
int main()
{
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    int cost[30];
    cost[0] = C*max(X,Y)*2;
    cost[1] = C*min(X,Y)*2+(max(X,Y)-min(X,Y))*((X>Y)?A:B);
    cost[2] = A*X+B*Y;
    sort(&cost[0],&cost[3]);
    cout << cost[0];
    return 0;
}

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

static const int MAX = 100000;

int n;

int partition(int A[], int p, int r) {
	int x = A[r-1];
	int i = p - 1;
	int tmp;
	for (int j = p; j < r-1; j++) {
		if (A[j] <= x) {
			i += 1;
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	tmp = A[i + 1];
	A[i + 1] = A[r-1];
	A[r-1] = tmp;
	return i + 1;
}

int main() {
	cin >> n;
	int A[MAX];
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	int g = partition(A, 0, n);
	for (int i = 0; i < n; i++) {
		if (i > 0) {
			cout << " ";
		}
		if (i == g) {
			cout << "[" << A[i] << "]";
		}
		else {
			cout << A[i];
		}
	}
	cout << endl;
}


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

random_device randev;
mt19937 rng(randev());

int h,w;
string a[12];
bool b[12][12],dp[1<<12];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>h>>w;
    for(int i=0;i<h;i++)cin>>a[i];
    for(int T=0;T<1<<17;T++){
        memset(b,1,sizeof(b));
        for(int i=0;i<w;i++)for(int j=i;j<w;j++)
            for(int k=0;k<h;k++)b[i][j]&=a[k][i]==a[h-1-k][j];
        memset(dp,0,sizeof(dp));
        dp[0]=1;
        for(int s=0;s<1<<w;s++)if(dp[s]){
            for(int i=0;i<w;i++)for(int j=i+1;j<w;j++){
                dp[s|1<<i|1<<j]|=!(s>>i&1)&&!(s>>j&1)&&b[i][j];
            }
        }
        if(w&1){
            for(int i=0;i<w;i++)if(dp[((1<<w)-1)^(1<<i)]&&b[i][i]){
                cout<<"YES\n";
                return 0;
            }
        }else{
            if(dp[(1<<w)-1]){
                cout<<"YES\n";
                return 0;
            }
        }
        shuffle(a,a+h,rng);
    }
    cout<<"NO\n";

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,ans=1;
    cin>>n;
    while(n){
        n/=2;
        ans*=2;
    }
    cout<<ans-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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

    int array[100];
    for (int i=0;i<len;i++) {
        scanf("%d", &array[i]);
    }

    int tmp, count=0;
    for (int i=0;i<len;i++) {
        int minj = i;
        for (int j=i;j<len;j++) {
            if (array[j] < array[minj]) {
                minj = j;
            }
        }
        if (i != minj) {
            tmp = array[i];
            array[i] = array[minj];
            array[minj] = tmp;
            count++;
        } 

    }

    for (int i=0;i<len;i++) {
        if (i != len-1) {
            printf("%d ", array[i]);
        } else {
            printf("%d\n", array[i]);
        }
    }
    printf("%d\n", count);

    return 0;
}


Measured memory_bytes: 2748
package main

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

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	// writer  = bufio.NewWriterSize(os.Stdout, 1000000)
)

func main() {
	scanner.Split(bufio.ScanWords)
	// scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	// defer writer.Flush()
	n, k := scanInt(), scanInt()
	h := scanInts(n)

	min := func(x, y int) int {
		if x < y {
			return x
		}
		return y
	}

	dp := make([]int, n)
	for i := 1; i < n; i++ {
		dp[i] = math.MaxInt64
	}

	for i := 0; i < n; i++ {
		for j := 1; j <= k; j++ {
			if (i + j) >= n {
				break
			}
			t1, t2 := dp[i+j], dp[i]+abs(h[i]-h[i+j])
			dp[i+j] = min(t1, t2)
		}
	}

	fmt.Println(dp[n-1])
}

func scanInt() int {
	i, _ := strconv.Atoi(scanString())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanString(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanString() string {
	scanner.Scan()
	return scanner.Text()
}

func scanStrings(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanString()
	}
	return s
}

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

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

// greatest common divisor(最大公約数)
func gcd(a, b int) int {
	for {
		mod := a % b
		if mod == 0 {
			return b
		}
		a, b = b, mod
	}
}

// latest common multiple(最小公倍数)
func lcm(a, b int) int {
	return (a / gcd(a, b)) * b
}

func fact(n int) int {
	ret := 1
	for i := 1; i <= n; i++ {
		ret *= i
	}
	return ret
}

func perm(n, r int) int {
	ret := 1
	for i := 0; i < r; i++ {
		ret *= n
		n--
	}
	return ret
}

func isPrimeNum(n int) bool {

	if n <= 1 {
		return false
	}

	l := int(math.Sqrt(float64(n)) + 1.)
	for i := 2; i < l; i++ {
		if n%i == 0 {
			return false
		}
	}

	return true
}


Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <set>
#include <cmath>
#include <math.h>

using namespace std;
        
int main(){
    int n;
    cin>>n;
    int k;
    cin>>k;
    int ans=1;
    for(int i=0;i<n;i++){
        if(ans*2>=ans+k){
            ans+=k;
        }else{
            ans*=2;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
data = list(map(int,input().split())) #行列の型
matlix = [list(map(int,input().split()))for i in range(data[0])]
#print(matlix)
vector =[]
for j in range(data[1]):
    vector.append(int(input()))
#print(vector)
#answer=[]
for k in range(0,data[0]):
    num=0
    
    for l in range(0,data[1]):
        num += matlix[k][l]*vector[l]
    print(num)


Measured memory_bytes: 6024
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
int main(){
   int T;
   cin>>T;
   for(int i=0;i<T;i++){
       long long N,M,A,B;
       cin>>N>>M>>A>>B;
       cout<<floor_sum(N,M,A,B)<<endl;
   }
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n; cin >> n;
  vector<int> p(n); REP(i, n) cin >> p[i];

  int cnt = 0;
  REP(i, n - 1) {
    if(i == 0) continue;
    if((p[i - 1] < p[i] && p[i] < p[i + 1]) ||
      (p[i - 1] > p[i] && p[i] > p[i + 1])) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

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

  int x, n;
  cin >> x >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  vector<bool> ans(200, false);
  for (int i = 0; i < n; i++) ans[p[i]] = true;

  int m = x, M = x;
  while (1) {
    if (!ans[m]) break;
    m--;
  }
  while (1) {
    if (!ans[M]) break;
    M++;
  }

  if (x-m == M-x) {
    cout << m << endl;
    return 0;
  }
  if (x-m < M-x) {
    cout << m << endl;
    return 0;
  }
  cout << M << endl;
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A, B;
  cin >> A >> B;

  int i;
  int ans = 0;
  
  for (i = A; i <= B; i++){
    string num = to_string(i);
    if(num[0] == num[4] && num[1] == num[3]){
      ans += 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
function Main(input) {
	input = input.split("\n");
	var tmp = input[1].split(" ");
	var n = parseInt(input[0], 10);
	var ns = new Array(n);
	var min = 100000000;
	for(var k=0; k<=100; k++){
    	var sum = 0;
    	for(var i=0; i<n; i++){
    		ns[i] = parseInt(tmp[i], 10);
        	sum += Math.pow(ns[i] - k, 2);
        }
      if(min > sum){
        min = sum;
      }
    }
	console.log(min);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
a,b,c,x,y=map(int,input().split())
ans=0
if a+b>c*2:
    z=min(x,y)
    ans+=z*c*2
    x-=z
    y-=z

if a>c*2:
    ans+=x*c*2
    y=max(0,y-x)
    x=0
if b>c*2:
    ans+=y*c*2
    x=max(0,x-y)
    y=0
ans+=a*x
ans+=b*y
print(ans)

    


Measured memory_bytes: 61948
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	if (C - (A - B)<0) {
		cout << "0" << endl;
	}
	else { 
		cout << C - (A - B) << endl;  
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <map>

int main(){
	int n;
	std::cin >> n;
	std::map<int, int> mp;
	for(int i=0; i < n; i++){
		int a;
		std::cin >> a;
		auto itr = mp.find(a);
		if(itr != mp.end()){
			itr->second = 0;
			mp.erase(itr);
		}
		else{
			mp[a] = 1;
		}
	}
	int c = 0;
	for(auto x : mp){
		c += x.second;
	}
	std::cout << c;
	return 0;
}

Measured memory_bytes: 4864
#define CPP17
#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#ifdef CPP17
#include <variant>
#endif

// Yay!!
#define endl codeforces

// macros for iterator
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)

// alias
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;

// variadic min/max
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }

// variadic chmin/chmax
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

// multi demension array
template <typename T, std::size_t Head, std::size_t... Tail> struct multi_dim_array { using type = std::array<typename multi_dim_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dim_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t... Args> using mdarray = typename multi_dim_array<T, Args...>::type;

#ifdef CPP17
// fill container
template <typename T, typename F, typename... Args> 
void fill_seq(T &t, F f, Args... args) { if constexpr (std::is_invocable<F, Args...>::value) { t = f(args...); } else { for (ssize_t i = 0; i < t.size(); i++) fill_seq(t[i], f, args..., i); } }
#endif

// make multi dimension vector
template <typename T> vec<T> make_v(ssize_t sz) { return vec<T>(sz); }
template <typename T, typename... Tail> auto make_v(ssize_t hs, Tail&&... ts) { auto v = std::move(make_v<T>(std::forward<Tail>(ts)...)); return vec<decltype(v)>(hs, v); }

// init
namespace init__ { 
struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; 
}


bool solve() {
    ll a, v, b, w, t;
    std::cin >> a >> v >> b >> w >> t;
    std::swap(a, b);
    std::swap(v, w);
    ll dist = std::abs(a - b);
    if (w <= v) return false;
    return dist <= std::abs(v - w) * t;
}

int main() {
    std::cout << (solve() ? "YES" : "NO") << "\n";
    return 0;
}


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

int main() {

  int N;
  cin >> N;

  int sum = 0;

  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    sum += r - l + 1;
  }

  cout << sum << endl;

}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  i64 N, M;
  cin >> N >> M;
  i64 ans = 0;
  ans += min(N, M / 2);
  M -= 2 * ans;
  ans += M / 4;
  cout << ans << '\n';
}


Measured memory_bytes: 256
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def solve():
    N, M = map(int, input().split())
    n = Base_10_to_n(N, M)
    return len(n)

print(solve())

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

#define ll long long
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf (int)(1e18)
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(p) p.begin(), p.end()
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define sz(x) (int)x.size()
#define PI 3.14159265
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void run()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void solution()
{
    int d, t, s;
    cin >> d >> t >> s;
    if (d > s * t)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    return;
}
int32_t main()
{
    run();
    solution();
    return 0;
}

Measured memory_bytes: 3556
N,M=map(int,input().split())
C=[[0,0] for i in range(N)]

for i in range(M):
  p,S=input().split()
  x=int(p)-1
  if C[x][0]==0:
    if S=="WA":
      C[x][1]+=1
    else:
      C[x][0]=1

print(sum([C[i][0] for i in range(N)]),sum([C[i][1] for i in range(N) if C[i][0]==1]))


Measured memory_bytes: 14168
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
int main()
{
    int H,A;
    cin >> H >> A;
    cout << ceil(H/(float)A) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(n / 2);
	x %= mod;
	x *= x;
	x %= mod;
	if (n % 2 == 1)x *= 10;
	x %= mod;
	return x;
}


int main(){
	int n,k;
	cin >> n>>k;
	hei(int) dp(n+1,INF),a(n);
	rep(i, 0, n)cin >> a[i];
	dp[0] = 0;
	rep(i, 1, n) {
		if (k >= i) {
			rep(j, 0, i)dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
		}
		else {
			rep(j, i - k, i)dp[i] = min(dp[i], dp[j] + abs(a[j] - a[i]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 200010, M = 2 * N;
const double eps = 1e-6;

int n, a[N];
LL l[N], r[N];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) l[i] = l[i - 1] + a[i];
    for(int i = n; i >= 1; i--) r[i] = r[i + 1] + a[i];

    LL res = 1e18;
    for(int i = 1; i <= n; i++)
    {
        if(i > 1) res = min(res, abs(l[i] - a[i] - r[i]));
        if(i < n) res = min(res, abs(l[i] - r[i] + a[i]));
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4096
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    int A[] = new int[1000001];
    for(int i=1; ; i++){
      if(A[s] != 0){
        System.out.println(i);
        return;
      }
      A[s] = i;
      if(s%2==0) s/=2;
      else s=s*3+1;
    }
  }
}

Measured memory_bytes: 25812
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int M;
vector<pii> ini;


struct RangeTree {
  using Pair = pii;
  using vp = vector<Pair>;

  int SZ;
  vector<vp> speedup;
  vector<vp> seg;
  
  // ini = {(x_1, y_1), ... , (x_m, y_m)}
  // at least {x_i} should be compressed to {0..N-1}
  RangeTree(int N, vp &ini) {
    SZ = 1;
    while (SZ < N) SZ <<= 1;
    speedup.resize(SZ);
    seg.resize(SZ*2);

    for (auto &p : ini) {
      seg[p.X+SZ-1].eb(Pair(p.Y, p.X));
    }

    rep(i, SZ) {
      sort(all(seg[i+SZ-1]));
    }

    rrep(i, SZ-1) {
      vp &sp = speedup[i];
      vp &sg = seg[i];
      vp &lch = seg[i*2+1];
      vp &rch = seg[i*2+2];

      sg.resize(lch.size() + rch.size());
      sp.resize(lch.size() + rch.size());
      merge(all(lch), all(rch), sg.begin());
      int a1 = 0, a2 = 0;
      rep(k, sg.size()) {
        while (a1 < lch.size() && lch[a1].X < sg[k].X) a1++;
        sp[k].X = a1;
        while (a2 < rch.size() && rch[a2].X < sg[k].X) a2++;
        sp[k].Y = a2;
      }
      sp.pb(Pair(lch.size(), rch.size()));
    }
  }

  int _query(int wishl, int wishr, int k, int ly, int ry, int watchl, int watchr) {
    if (wishr <= watchl || watchr <= wishl) return 0;
    if (wishl <= watchl && watchr <= wishr) {
      // [ly, ry)
      return ry - ly;
    }
  
    int mid = (watchl+watchr)/2;
    int p, q;
    int lval, rval;
    p = speedup[k][ly].X;
    q = speedup[k][ry].X;
    lval = _query(wishl, wishr, k*2+1, p, q, watchl, mid);
    p = speedup[k][ly].Y;
    q = speedup[k][ry].Y;
    rval = _query(wishl, wishr, k*2+2, p, q, mid, watchr);
    return lval + rval;
  }

  int query(int dx, int ux, int dy, int uy) {
    if (ux <= dx || uy <= dy) return 0;
    int ly = lower_bound(all(seg[0]), Pair(dy, -1)) - seg[0].begin();
    int ry = lower_bound(all(seg[0]), Pair(uy, -1)) - seg[0].begin();
    return _query(dx, ux, 0, ly, ry, 0, SZ);
  }
};

int main() {
  scanf("%d%d", &N, &M);
  rep(i, N) {
    int l, r;
    scanf("%d%d", &l, &r);
    r++;
    ini.eb(pii(l, r));
  }

  RangeTree rt(M+3, ini);
  reps(d, 1, M+1) {
    int ans = 0;
    for (int i=0; i<=M; i+=d) {
      ans += rt.query(i-d+1, i+1, i+1, M+2);
    }
    printf("%d\n", ans);
  }
}


Measured memory_bytes: 123460
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 2000000000000000000LL
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;


int main() {
	int N, C, K;
	cin >> N >> C >> K;
	vi T(N);
	rep(i, N) {
		cin >> T[i];
	}
	sort(T.begin(), T.end());
	int ans = 0;
	reprev(i, N) {
		ans++;
		int time = T[i];
		//cout << time << endl;
		int num = 1;
		while (i >= 0 && num <= C && time - T[i] <= K) {
			i--;
			num++;
		}
		i++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
fun main(args: Array<String>) {
    readLine()!!.toCharArray().fold("") { acc, elm ->
        when (elm) {
            '0', '1' -> acc.plus(elm)
            else -> if (acc.isNotEmpty()) {
                acc.dropLast(1)
            } else {
                acc
            }
        }
    }.let(::println)
}



Measured memory_bytes: 31768
#include <iostream>
#include <numeric>
using namespace std;
int main() {
	int N, M, X;
	int A[101] = { 0 };

	cin >> N >> M >> X;

	for (int i = 1; i <= M; i++)
	{
		int tmp;
		cin >> tmp;
		A[tmp] = 1;
	}

	int ans1 = accumulate(A, A + X, 0);
	int ans2 = accumulate(A + X, A + N, 0);

	cout << ((ans1 > ans2) ? ans2 : ans1) << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  vector<int> as(N);
  F0R(i, N) {
    cin >> as[i];
  }
  int l = 0, r = K;

  F0R(i, N - K) {
    cout << (as[r] > as[l] ? "Yes" : "No") << newl;
    l++;
    r++;
  }
}
#endif


Measured memory_bytes: 3968
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>a(N);
	vector<bool>c(N, true);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	int i = 0, count = 1;
	while (a[i] != 2) {
		if (!c[i]) {
			cout << "-1";
			return 0;
		}
		c[i] = false;
		i = a[i] - 1;
		count++;
	}
	cout << count;
	return 0;
}

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

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

const int MAXN = 6000*6000;

ll n, a1, a2, b1, b2, c1, c2;
ll ans;

ll dp[MAXN+10];

void solve()
{
    ll i, j;
    for(j=0; j<=n; j++) dp[j]=j;
    dp[0]=0;
    for(j=0; j<=n; j++)
    {
        if(a1<=j) dp[j]=max(dp[j], dp[j-a1]+a2);
        if(b1<=j) dp[j]=max(dp[j], dp[j-b1]+b2);
        if(c1<=j) dp[j]=max(dp[j], dp[j-c1]+c2);
    }
    ans=0;
    for(i=0; i<=n; i++) ans=max(ans, dp[i]);
}

int main()
{
    ll i, j, k;
    scanf("%lld%lld%lld%lld%lld%lld%lld", &n, &a1, &b1, &c1, &a2, &b2, &c2);

    solve();
    n=ans; swap(a1, a2); swap(b1, b2); swap(c1, c2);
    solve();

    printf("%lld", ans);
}


Measured memory_bytes: 196864
#include<bits/stdc++.h>
using namespace std;
int main(){
  int r,D,x;
  cin>>r>>D>>x;
  vector<int>X(11);
  X.at(0)=x;
  for(int i=0;i<10;i++){
    X.at(i+1)=r*X.at(i)-D;
  }
  for(int i=1;i<11;i++){
    cout<<X.at(i)<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int X, N; cin >> X >> N;
    vector<bool> flag(10000, false);
    for (int i = 0; i < N; ++i) {
        int a = 0;
        cin >> a;
        flag[a] = true;
    }
    int ans = 0, down = X - 1, now = X, up = X + 1;
    while(true) {
        if (flag[X] == true) {
            if (flag[down] == false) {
                ans = down;
                break;
            }
            else if (flag[up] == false) {
                ans = up;
                break;
            }
            else {
                down--; up++;
            }
        }
        else {
            ans = X;
            break;
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3720
N, Y=map(int, input().split())
max_100 = Y//10000
max_50 = Y//5000
max_10 = Y//1000
p=[[-1,-1,-1]]
flag = False
for x in range (max_100+1):
    for y in range(N-x+1):
        if 10000*x+5000*y+1000*(N-x-y)==Y:
                p.append([x,y,N-x-y])
                flag = True
                break
    if flag:
        break
print(p[-1][0], p[-1][1], p[-1][2])

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

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

int main() {
	ll n, ans = 0;
	cin >> n;
	vector<ll> a(n + 1), b(n);
	rep(i, n + 1) cin >> a.at(i);
	rep(i, n) cin >> b.at(i);
	rep(i, n) {
		if (a.at(i) >= b.at(i)) {
			ans += b.at(i);
		}
		else if (a.at(i) + a.at(i + 1) <= b.at(i)) {
			ans += a.at(i) + a.at(i + 1);
			a.at(i + 1) = 0;
		}
		else {
			ans += b.at(i);
			a.at(i + 1) -= b.at(i) - a.at(i);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
n=int(input())
xl=[list(map(int,input().split())) for i in range(n)]
xl=[i+[i[0]-i[1],i[0]+i[1]] for i in xl] # [point,arm,left,right]
xl.sort(key=lambda x: x[3])
i=0
ans=n
while i<len(xl)-1:
  if xl[i][-1]>xl[i+1][2]:
    del xl[i+1]
    ans-=1
  else:
    i+=1
print(ans)


Measured memory_bytes: 42316
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int H = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        int N = Integer.parseInt(sc.next());

        int base = 0;
        int target = 0;
        if (H > W) {
            base = H;
            target = W;
        } else {
            target = H;
            base = W;
        }
        int count = 0;
        for (int i = 1; i <= target; i++) {
            count++;
            N = N - base;
            if (N <= 0) {
                break;
            }
        }

        System.out.println(count);
    }
}



Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
char yo(char s){return (s == 'S' ? 'W' : 'S');}
int main(){
	int n;
	string s;
	cin >> n >> s;
	string a[] = {"SS", "SW", "WS", "WW"};
	for(int i = 0; i < 4; ++i){
		string po = a[i];
		for(int j = 1; j < n; ++j){
			if(po[j] == 'S'){
				if(s[j] == 'o') po += po[j - 1];
				else po += yo(po[j - 1]);
			}else{
				if(s[j] != 'o') po += po[j - 1];
				else po += yo(po[j - 1]);
			}
		}
		if(po[0] != po[n]) continue;
		if(s[0] == 'o'){
			if((po[0] == 'S' && po[1] == po[n - 1]) || (po[0] == 'W' && po[1] != po[n - 1])){
				cout << po.substr(0, n) << endl;
				return 0;
			}
		}else{
			if((po[0] == 'W' && po[1] == po[n - 1]) || (po[0] == 'S' && po[1] != po[n - 1])){
				cout << po.substr(0, n) << endl;
				return 0;
			}
		}

	}
	cout << "-1\n";
	return 0;
}

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

int n, k;
int arr[100001];
int dp[100001];
int solve(int cur){
    if(dp[cur] != -1) return dp[cur];
    if(cur == 1) return dp[cur] = 0;
    int mina = 1e9;

    for(int x=1;x<=k;x++){
        if(cur - x >= 1){
            int temp = abs(arr[cur] - arr[cur - x]) + solve(cur-x);
            mina = min(mina, temp);
        }
    }
    return dp[cur] = mina;
}
int main(){
    memset(dp, -1, sizeof dp);
    cin>>n>>k;
    for(int x=1;x<=n;x++)
        cin>>arr[x];


    cout<<solve(n);

}


Measured memory_bytes: 10604
//PrintTest.cpp
#include<iostream>
using namespace std;

int main()
{
    int i, x;
    for ( i = 0; i < 10000; i++)
    {
        cin>>x;
        if (x != 0)
        {
            cout<<"Case "<<i+1<<": "<<x<<endl;
        }
        else
        {
            break;
        }
    }
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    vector<ll> num(190),odd;
    for(ll i = 1;i < 190;i++){
        num[i] = i * (i + 1) * (i + 2) / 6;
        if(i * (i + 1) * (i + 2) / 6 % 2 == 1)odd.push_back(i * (i + 1) * (i + 2) / 6);
    }
    vector<ll> memo(1000005,INF),od(1000005,INF);
    memo[0] = 0;
    rep(i,1000002){
        rep(j,189){
            if(num[j] + i <= 1000001){
                memo[num[j] + i] = min(memo[num[j] + i],memo[i] + 1);
            }
            else break;
        }
    }
    od[0] = 0;
    rep(i,1000002){
        rep(j,odd.size()){
            if(odd[j] + i <= 1000001){
                od[odd[j] + i] = min(od[odd[j] + i],od[i] + 1);
            }
            else break;
        }
    }
    while(true){
        cin >> N;
        if(N == 0)break;
        cout << memo[N] <<" "<< od[N] << "\n";
    }
}


Measured memory_bytes: 18280
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

s = input()
cnt = [0]*4
for i in range(len(s)):
    if s[i] == "N":
        cnt[0] = 1
    elif s[i] == "W":
        cnt[1] = 1
    elif s[i] == "E":
        cnt[2] =1
    else:
        cnt[3] =1

if cnt[0]^cnt[3] == 1 or cnt[1]^cnt[2] == 1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 12496
import numpy as np
import sys
buf = sys.stdin.buffer

H, W = map(int, buf.readline().split())
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = np.where(np.array(list(map(list, buf.read().decode('utf-8').split()))).reshape(H, W) == '.', 1, 0)
grid_v = grid.T

right = np.maximum.accumulate(np.where(grid < 1, np.arange(W + 2), 0), axis=1)
left = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid < 1, np.arange(W + 2), 10 ** 10)).copy(), axis=1))
down = np.maximum.accumulate(np.where(grid_v < 1, np.arange(H + 2), 0), axis=1).T
up = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid_v < 1, np.arange(H + 2), 10 ** 10)).copy(), axis=1)).T

print(np.max((left - right) + (up - down)) - 3)

Measured memory_bytes: 247328
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,T; cin >> N >> T;
    vector<int> A(T+1);
    rep(i,N) {
        int l,r; cin >> l >> r;
        A[l]++;
        A[r]--;
    }
    rep(i,T) A[i+1] += A[i];

    cout << *max_element(all(A)) << endl;
}



Measured memory_bytes: 3372
#include "bits/stdc++.h"
using namespace std;

#define ul unsigned long int
#define ull unsigned long long
#define li long long int


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

  int a[100][100],b[100],c;
  for (int i=0;i<n;i++) {
    for (int j=0;j<m;j++) {
      cin>>a[i][j];
    }
  }
  for (int i=0;i<m;i++) {
    cin>>b[i];
  }
  
  for (int i=0;i<n;i++) {
    c=0;
    for (int j=0;j<m;j++) {
      c+=a[i][j] * b[j];
    }
    cout << c <<endl;
  }

  return 0;
}



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

#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second

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

using namespace std;


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

   ll n, x; cin>>n>>x;
   vector<ll> cities;
   while(n--){
      ll city; cin >> city;
      cities.pb(city);
   }
   
   //sort(cities.begin(), cities.end());
   ll c = *min_element(cities.begin(), cities.end());
   ll ans = abs(c-x);
   for(int i = 0; i < cities.size(); i++){
      ans = gcd(ans, abs(x-cities[i]));
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		if(A + B >= C) {
			System.out.println(B + C);
		} else {
			System.out.println(A + 1 + B + B);
		}
		
	}
}


Measured memory_bytes: 21844
import itertools

h, w, k = [int(x) for x in input().split()]
C = [input() for _ in range(h)]

answer = 0

for hreps in range(h + 1):
    for hchosen in itertools.combinations(range(h), hreps):
        for wreps in range(w + 1):
            for wchosen in itertools.combinations(range(w), wreps):
                count = 0
                for y in hchosen:
                    for x in wchosen:
                        if C[y][x] == '#':
                            count += 1
                if count == k:
                    answer += 1

print(answer)


Measured memory_bytes: 9200