akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <stdio.h>
#include<string>
using namespace std;
string s,t; int j, i;
int main() {
	while (cin>>s)
	{
		j = 0; i = 0;
		for (size_t k = 0; k < s.size()-2; k++)
		{
			t = s.substr(k, 3);
			if (t == "JOI")j++;
			else if (t == "IOI")i++;
		}
		cout << j << endl << i << endl;
	}
	return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(void){
 int sx,sy,tx,ty;
 cin >> sx >> sy >> tx >> ty;

 const int dx=tx-sx,dy=ty-sy;

 // Path 1
 cout << string(dy,'U') << string(dx,'R');

 // Path 2
 cout << string(dy,'D') << string(dx,'L');

 // Path 3
 cout << 'L' << string(dy+1,'U') << string(dx+1,'R') << 'D';

 // Path 4
 cout << 'R' << string(dy+1,'D') << string(dx+1,'L') << 'U';

 // EndLine
 cout << endl;
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){
    int a, b, c, d;
    
    cin>>a>>b>>c>>d;
    
    const int lower = max(a,c);
    const int upper = min(b,d);
    


    cout << max(0,upper-lower) << endl;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
template<typename T>
struct BIT{
    int n;
    vector<T> dat;
    BIT(){}
    BIT(int N) : n(N + 1), dat(n, T()){}
    BIT(const vector<T> & a) : n((int) a.size() + 1), dat(n, T()){
        for(int i = 0; i < n - 1; i++){
            add(i, a[i]);
        }
    }
    //0-index
    void add(int i, T x){
        i++;
        while(i < n){
            dat[i] += x;
            i += i & - i;
        }
    }
    //0-index [0,i]
    T sum(int i){
        i++;
        T res = 0;
        while(i){
            res += dat[i];
            i -= i & - i;
        }
        return res;
    }
    //min index i s.t. a[0] + ... + a[i] >= x
    //if there is no i, return n
    //assume a[k] >= 0
    //TODO:verify
    int lower_bound(T x){
        int res = 0;
        int h = 31 - __builtin_clz(n);
        for(int i = h; i >= 0; i--){
            if(res + (1 << i) < n and dat[res + (1 << i)] < x){
                x -= dat[res + (1 << i)];
                res += 1 << i;
            }
        }
        return res;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int>a(n+1);
    rep(i,n){
        int x;
        cin >> x;
        a[x] = i + 1;
    }
    BIT<int> bit(n + 2);
    bit.add(0, 1);
    bit.add(n+1,1);
    ll ans = 0;
    bit.add(a[n],1);
    rep(_,n){
        if(!_)continue;
        const int id = a[n-_];
        const int num = n - _;
        int sum = bit.sum(id);
        int l = bit.lower_bound(sum);
        int l2 = bit.lower_bound(sum - 1);
        int r = bit.lower_bound(sum + 1);
        int r2 = bit.lower_bound(sum + 2);
        if(id > 1 and l >= 1)ans += (long long) num * (l - l2) *  (r - id);
        if(id < n and r <= n)ans += (long long) num * (r2 - r) * (id - l);
        bit.add(id, 1);
    }
    cout << ans << endl;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

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

    rep(i,n){
        int a;
        cin>>a;
        h-=a;
    }

    if(h>0){
        cout<<"No"<<endl;
    }

    else {
        cout<<"Yes"<<endl;
    }

}


Measured memory_bytes: 256
N = int(input())

alp = "abcdefghijklmnopqrstuvwxyz"

ans =  [ ["",0] ]


for i in range(N):

    nex = []

    for s,i in ans:

        for j in range(i+1):

            nex.append([s+alp[j] , max(i,j+1)])

    ans = nex
    #print (ans)

ans.sort()

for s,i in ans:
    print (s)




Measured memory_bytes: 25716
n = int(input())
a = list(map(int, input().split()))
a_ = list(reversed(a))

import fractions
l = [a[0]]
r = [a_[0]]
for i in range(n):
    l.append(fractions.gcd(l[-1], a[i]))
    r.append(fractions.gcd(r[-1], a_[i]))
#print(l)
#print(r)

s = [0]*n
for i in range(n):
    if i == 0:
        s[i] = r[n-1]
    elif i == n-1:
        s[i] = l[n-1]
    else:
        s[i] = fractions.gcd(l[i], r[n-(i+1)])
#print(s)
print(max(s))

Measured memory_bytes: 96480
/* Strategy
For example, "abcdefgh", h1 = 3, h2 = 2, h3 = 4.

initial "abcdefgh" = STR
h1 = 3  "defghabc" = STR.split(3, 8) + STR.split(0, 3)
h2 = 2  "fghabcde" = STR.split(5, 8) + STR.split(0, 5)
h3 = 4  "bcdefgha" = STR.split(1, 8) + STR.split(0, 1)
*/

//const config = { stdin: 'tmp', newline: '\r\n' }; // win
const config = { stdin: '/dev/stdin', newline: '\n' }; // linux

body = require('fs').readFileSync(config.stdin, 'ascii').split('\-')[0];
dataset = body.match(/[a-zA-Z]+[^a-zA-Z]+/g);
res = dataset.map(function (dataset) {
	var line, str, len, offset;
	line = dataset.trim().split(config.newline);
	str = line.shift();
	line.shift();
	len = str.length;
	offset = line.map(Number).reduce(add, 0) % len;
	return str.slice(offset, len) + str.slice(0, offset);
});

console.log(res.join('\n'));

function add(x, y) { return x + y; }

Measured memory_bytes: 15584
def mincost(n, A):
    dp = [0] * n
    dp[1] = abs(A[1] - A[0])
    for i in range(2, n):
        dp[i] = float('inf')
        for j in range(i - 2, i):
            dp[i] = min(dp[i], dp[j] + abs(A[j] - A[i]))
    return dp[n - 1]


if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().split()))
    res = mincost(n, A)
    print(res)


Measured memory_bytes: 13980
N = int(input())
F = [list(map(int, input().split())) for n in range(N)]
P = [list(map(int, input().split())) for n in range(N)]

ans = -10**9

for bit in range(1 << 10):
  if bit == 0:
    continue

  total = 0

  for n in range(N):
    count = 0

    for i in range(10):
      if bit & (1 << i):
        count += F[n][i]
    total += P[n][count]

  if total > ans:
    ans = total

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
using namespace std;
#define MOD          1000000007
#define PI           3.14159265358979
#define rep(i, n)    for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v)   for (auto i : v)
#define all(x)       (x).begin(), (x).end()
#define rall(x)      (x).rbegin(), (x).rend()
#define pb(x)       push_back(x)
#define mp(x, y)     make_pair((x), (y))
#define fi           first
#define se           second
#define setp(x)      setprecision(x)
#define mset(m, v)   memset(m, v, sizeof(m))
#define int          long long
//static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
static const int INF =        0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef long long             ll;
typedef vector<int>           vi;
typedef vector<double>        vd;
typedef vector<long long>     vll;
typedef vector<string>        vs;
typedef vector<bool>          vb;
typedef pair<int, int>        pii;
typedef pair<long, long>      pll;
typedef vector<pii>           vpii;
typedef vector<pll>           vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

signed main() { 
        int n, k;
        cin >> n >> k;
        vi a(n);
        rep(i, n) cin >> a[i];
        vi l(n, 0);
        vi r(n, 0);
        vi m(n, 0);
        l[0] = (a[0] > 0 ? a[0] : 0);
        r[n - 1] = (a[n - 1] > 0 ? a[n - 1] : 0);
        for (int i = 0; i < k; i ++) m[0] += a[i];
        for (int i = 1; i <= n - k - 1; i ++) l[i] = l[i - 1] + (a[i] > 0 ? a[i] : 0);
        for (int i = n - 2; i >= k; i --) r[i] = r[i + 1] + (a[i] > 0 ? a[i] : 0);
        for (int i = 1; i <= n - k; i ++) m[i] = m[i - 1] - a[i - 1] + a[i + k - 1];
        int ans = -INF;
        if (n == k) {
                ans = (m[0] > 0 ? m[0] : 0);
        } else {
                amax(ans, (m[0] > 0 ? m[0] : 0) + r[k]);
                for (int i = 0; i <= n - k - 2; i ++ ) amax(ans, l[i] + (m[i + 1] > 0 ? m[i + 1] : 0) + r[k + i + 1]);
                amax(ans, l[n - k - 1] + (m[n - k] > 0 ? m[n - k] : 0));
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,n,sum=0;
    cin>>n;
    long long int  a[n+2];
    for(i=0; i<n; i++)
    {
        cin>>a[i];

    }
    sort(a,a+n);
    sum=a[n-1]/2;
    for(i=0; i+1<n; i++)
    {
        sum=sum+a[i];
    }
cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
#include <fstream>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e9 
typedef long long ll;
typedef long double ld;
int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    vector<ll> v={a*c,b*c,a*d,b*d};
    cout<<MAX(v)<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int a,b;cin>>a>>b;
  string s;cin>>s;

  rep(i,0,s.size()){
    if(i<a||a<i){
      if(s[i]<'0'||'9'<s[i]){out("No");return 0;}
    }else if(i==a){
      if(s[i]!='-'){out("No");return 0;}
    }
  }

  out("Yes");

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		ArrayList<Integer> ans = new ArrayList<>();
		while (list.size() > 0) {
			boolean flag = false;
			for (int i = 0; i < list.size(); i++) {
				int x = list.get(list.size() - 1 - i);
				if (x == list.size() - i) {
					flag = true;
					ans.add(x);
					list.remove(list.size() - 1 - i);
					break;
				}
			}
			if (!flag) {
				System.out.println(-1);
				return;
			}
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < ans.size(); i++) {
			sb.append(ans.get(ans.size() - 1 - i)).append("\n");
		}
		System.out.print(sb);
	}
}


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

using namespace std;

inline int read()
{
    int ret=0,flag=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')flag=-1;c=getchar();}
    while(c>='0'&&c<='9')ret=ret*10+(c^'0'),c=getchar();
    return flag*ret;
}

int n;

int main()
{
    n=read();
    for(int i=1;i<=n;i++)
    {
        int x=read();
        if(!(x&1)&&x%3&&x%5)
        {
            printf("DENIED");
            return 0;
        }
    }
    printf("APPROVED");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();
    long ans = 0;
    if (a > b) {
      ans = 0;
    } else if (n == 1 && a != b) {
      ans = 0;
    } else if (n == 1){
      ans = 1;
    } else {
      ans += (n-2) * (b - a) + 1;
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 35400
#include <iostream>
#include <vector>
#include <algorithm>

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

  size_t N, W, weight, value, V = 100001;
  std::cin >> N >> W;

  std::vector<std::vector<size_t>> dp(2);
  dp[0] = std::vector<size_t>(V, W+1);
  dp[1] = std::vector<size_t>(V, W+1);
  dp[0][0] = 0;

  unsigned ans = 0;

  for (unsigned i = 0; i < N; ++i)
  {
    std::cin >> weight >> value;
    for (unsigned j = 0; j < V; ++j)
    { 
      if (j >= value)
      { 
        dp[1][j] = std::min(dp[0][j], dp[0][j-value] + weight);
      }
      else
      { 
        dp[1][j] = dp[0][j];
      }
      if (dp[1][j] <= W)
      { 
        ans = std::max(ans, j);
      }
    }
    dp[0].swap(dp[1]);
  }
  std::cout << ans;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define int long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define MAXN 200100
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);

}

int32_t main(){
	fastio;
	int x;
    cin>>x;
    int r = 0;
    r+=(x/500)*1000;
    x = x%500;
    r+=(x/5)*5;
    cout<<r<<endl;
	// Math -> gcd it all
	//did you check N=1? Did you mix up N,M?
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    boolean flg = true;
    for(int i=0; i<s.length(); i++){
      if(i%2==0){
        if(s.charAt(i)=='L') {
          flg = false;
          break;
        }
      }
      if(i%2!=0){
        if(s.charAt(i)=='R') {
          flg = false;
          break;
        }
      }
    }
    System.out.println(flg==false?"No":"Yes");
  }
}

Measured memory_bytes: 21332
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <utility>

using ll = long long;
using namespace std;

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

  ll ans = 0;
  ll sec = 0;

  // i=0
  cin >> sec;
  ans += T;

  for (ll i = 1; i < N; i++) {
    ll now;
    cin >> now;
    if (T < now - sec) {
      ans += T;
    } else {
      ans += now - sec;
    }

    sec = now;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <string>


using namespace std;
using ll = long long;
using ull = unsigned long long;


#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

auto sumdig(ll num) {
	ll dig, sum;
	sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}

auto mdist(pair<int, int> a, pair<int, int> b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
int main() {

	int a, b, c;
	cin >> a >> b >> c;
	int n = 1;
	int first = -1;
	int ta;
	while (true) {
		ta = a * n;

		if (ta % b == c) {
			cout << "YES" << endl;
			break;
		}

 		if (n == 1) {
			first = ta % b;
		}
		else {
			if (first == ta % b) {
				cout << "NO" << endl;
				break;
			}
		}


		n += 1;
	}


	return 0;
}



Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt2() (int, int) {
	return nextInt(), nextInt()
}

func nextInt3() (int, int, int) {
	return nextInt(), nextInt(), nextInt()
}

func nextInt4() (int, int, int, int) {
	return nextInt(), nextInt(), nextInt(), nextInt()
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

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

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a := nextInts(n)

	ans := 0
	for i := range a {
		if i%2 == 0 && a[i]%2 == 1 {
			ans++
		}
	}
	puts(ans)
}


Measured memory_bytes: 1780
#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

class Node
{
public:
    Node() {
        this->_val = 0;
        this->_parent = -1;
        this->_left = -1;
        this->_right = -1;
    }
    Node(int val) {
        this->_val = val;
        this->_parent = -1;
        this->_left = -1;
        this->_right = -1;
    };
    ~Node(){
        ;
    };

    const int& val() const { return this->_val; }
    int& val() { return this->_val; }

    const int& parent() const { return this->_parent; }
    int& parent() { return this->_parent; }

    const int& left() const { return this->_left; }
    int& left() { return this->_left; }

    const int& right() const { return this->_right; }
    int& right() { return this->_right; }

private:
    int _val;
    int _parent;
    int _left;
    int _right;
};

std::vector<Node> nodelist(500000);
const int rootid = 0;
int counter = 0;

void insert(int newval)
{
    if (counter == 0) {
        nodelist[rootid].val() = newval;
        return;
    }

    int y; // ?????¨??°????????????????????????
    int x = rootid; // ?????¨??°??????????????????
    while (x != -1) {
        y = x;
        if (newval < nodelist[x].val()) {
            x = nodelist[x].left(); // ?????????????§????
        } else {
            x = nodelist[x].right();
        }
    }
    nodelist[counter].parent() = y;
    nodelist[counter].val() = newval;

    if (newval < nodelist[y].val()) {
        nodelist[y].left() = counter; // ?????????????????????
    } else {
        nodelist[y].right() = counter; // ?????????????????????
    }
}

void inorder(int id)
{
    if (nodelist[id].left() != -1) {
        inorder(nodelist[id].left());
    }
    cout << " " << nodelist[id].val();
    if (nodelist[id].right() != -1) {
        inorder(nodelist[id].right());
    }
}

void preorder(int id)
{
    cout << " " << nodelist[id].val();
    if (nodelist[id].left() != -1) {
        preorder(nodelist[id].left());
    }
    if (nodelist[id].right() != -1) {
        preorder(nodelist[id].right());
    }
}

int main()
{
    int n;
    cin >> n;
    std::string op;
    int k;
    for (int i = 0; i < n; i++) {
        cin >> op;
        if (op == "insert") {
            cin >> k;
            insert(k);
            counter++;
        } else if (op == "print") {
            // cout << "Inorder:" << endl;
            inorder(rootid);
            cout << endl;
            // cout << "Preorder:" << endl;
            preorder(rootid);
            cout << endl;
        }
    }

    // debug
    // for (int i = 0; i < counter; i++) {
    //     cout << "id = " << i << endl
    //          << "val = " << nodelist[i].val() << endl
    //          << "parent = " << nodelist[i].parent() << endl
    //          << "left = " << nodelist[i].left() << endl
    //          << "right = " << nodelist[i].right() << endl
    //          << endl;
    // }

    return 0;
}

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

int main() {
  int X;
  cin >> X;
  int a, b;
  for(int i = -1000; i < 1000; i++) {
    for(int j = -1000; j < 1000; j++) {
      if(pow(i,5)-pow(j,5)==X || pow(i,5)-pow(j,5)==-X) {
        a = i;
        b = j;
        break;
      }
    }
  }
  if(pow(a,5)-pow(b,5)==X)  cout << a << " " << b << endl;
  else cout << b << " " << a << endl;
}


Measured memory_bytes: 4060
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<fstream>
#include<sstream>
#include<queue>
#include<iterator>
using namespace std;

vector<int> g[100000];
vector<int> path;
int cnt[100000],mid,n;
void dfs(int x,int pre){
	path.push_back(x);
	if(x==n-1){
		mid=path[(path.size()+1)/2];
	}
	cnt[x]=1;
	for(int i=0;i<g[x].size();i++){
		if(g[x][i]!=pre){
			dfs(g[x][i],x);
			cnt[x]+=cnt[g[x][i]];
		}
	}
	path.pop_back();
}


int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0,-1);
	if(cnt[mid]>=n-cnt[mid])cout<<"Snuke\n";
	else cout<<"Fennec\n";
	
	
	
	

  return 0;
}


Measured memory_bytes: 11256
#include <stdio.h>

char S[200200];

int main()
{
	scanf ("%s", S);
	long long ans = 0, cnt = 0;
	for (int i = 0; S[i]; i++){
		if (S[i] == 'A') cnt++;
		else if (S[i] == 'B' && S[i + 1] == 'C'){
			ans += cnt; i++;
		}
		else{
			cnt = 0;
		}
	}
	printf ("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int N = intArray[0];
            int M = intArray[1];
            int[] A = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            double sum = A.Sum();
            int cnt = 0;
            double border = sum / (4d * (double)M);
            for (int i = 0; i < N; i++)
            {
                if ((double)A[i] >= border)
                {
                    cnt++;
                }
            }
            if (cnt >= M)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 28244
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sort(v) sort(v.begin(),v.end())
#define pb push_back
int main()
{
ll a,b,c,d,e=0,f=0,k=0,i,j,p,q,s=1,g=0;
    
cin>>a>>c;
    ll kk=1e9+7;
    vector<ll>v,x,vv;
  for(i=0;i<a;i++)
  {
  cin>>b;
   if(b>=0)v.pb(b);
   else x.pb(b);
  }
 sort(x);sort(v);
 if(x.size()%2==1){e=x[x.size()-1];x.pop_back();g=1;}
i=0;j=v.size()-1;
if(x.size()+v.size()>=c&&(v.size()>0||c%2==0))
{
  if(c%2==1){c--;s*=v[j]%kk;j--;s%=kk;}
  while(c)
  {
  if(i+1<=x.size()&&j-1>=0&&c>1)
  {
  p=v[j]*v[j-1];
  q=x[i]*x[i+1];
  if(p>q){s*=p%kk;j-=2;s%=kk;}
  else {s*=q%kk;i+=2;s%=kk;}c-=2;
  }
  else if(i+1<=x.size()&&c>1)
   {q=x[i]*x[i+1];
    s*=q%kk;i+=2;c-=2;s%=kk;
   }
  else if(j-1>=0&&c>1)
    {p=v[j]*v[j-1];
     s*=p%kk;j-=2;c-=2;s%=kk;
    }
  
     
  }
}
else
{s=1;
        if(g==1)
    x.pb(e);
   sort(x);j=x.size()-1;i=0;
while(c)
{
           //cout<<j<<endl;
  if(i<v.size()&&j>=0)
   {
    if(v[i]<x[j]*(-1)){s*=v[i];i++;}
    else {s*=x[j];j--;}c--;
   }
   else if(i<v.size())
   {s*=v[i];c--;i++;
   }
else {s*=x[j];j--;c--;}
   if(s<0){
   ll cc=(-1*s)%kk;
      s=kk-cc;}
    else s=s%kk;

}


}
if(s<0){
   ll cc=(-1*s)%kk;//cout<<cc<<endl;
      s=kk-cc;}
    else s=s%kk;
    
cout<<s<<endl;
 }

Measured memory_bytes: 5524
import sys

c_dict = {
'a':0, 'b':0, 'c':0, 'd':0, 'e':0, 'f':0, 'g':0,
'h':0, 'i':0, 'j':0, 'k':0, 'l':0, 'm':0, 'n':0,
'o':0, 'p':0, 'q':0, 'r':0, 's':0, 't':0, 'u':0,
'v':0, 'w':0, 'x':0, 'y':0, 'z':0
}

while True:
    a = sys.stdin.readline()
    if not a:
        break
    else:
        str = a.lower() #すべての文字を小文字に変換
        for i in str: #strの中身を一文字ずつiに入れる
            if i in c_dict: #c_dictにiが含まれているかどうか，含まれる→True，含まれない→False
                c_dict[i] = c_dict[i] + 1 #print(c_dict[i]) >>> 値
            """ #もし，辞書に無い文字を追加したければ，これでできる（appendしなくていいの利点）
            else:
                c_dict[i] = 1
            """

for i in c_dict:
    print(i,':',c_dict[i])



Measured memory_bytes: 5588
x = input().split()
a = int(x[0])
b = int(x[1])
c = int(x[2])

if a <= b <= c:
    print(a,b,c)
elif a <= c <= b:
    print(a,c,b)
elif b <= a <= c:
    print(b,a,c)
elif b <= c <= a:
    print(b,c,a)
elif c <= a <= b:
    print( c,a,b)
else:
    print(c,b,a)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  long long b = 0, ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') b++;
    else ans += b;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
int main(){
	map<string, set<pair<int,int> > > lo;
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		string p; int v;
		cin >> p >> v;
		lo[p].insert({-v, i});
	}
	for(auto it : lo){
		for(auto ic : it.second){
			cout << ic.second + 1 << endl;
	
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF (2147483647)
#define MOD (int)(1e9 + 7) 

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    double ans = 0;
    double s;
    cin >> s;
    int res = (s/3);
    double min = res * res * res;
    if((int)s%3 == 0) {
        ans = min;
    }
    else {
        for(int i = 0; i <= 1000; ++i) {
            for(int j = 0; j <= 1000; ++j) {
                double ii = (double)i/(double)1000;
                double jj = (double)j/(double)1000;
                double kk = s - (res+ii) - (res+jj);
                ans = max(ans, (res+ii)*(res+jj)*kk);
            }
        }
    }
    cout << fixed << setprecision(12) << ans << '\n';
    return 0;
}

Measured memory_bytes: 3772
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a[200010],ans[200010];
    pll b[200010];
    cin>>n;
    rep(i,n){
        cin>>a[i];
        b[i]=pll(a[i],i);
    }
    sort(b,b+n);
    rep(i,n){
        if(i<n/2){
            ans[b[i].second]=b[n/2].first;
        } else{
            ans[b[i].second]=b[n/2-1].first;
        }
    }
    rep(i,n){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 8448
import math

def finding(n):
    nn = math.floor(math.sqrt(n))
    if nn*nn == n:
        return nn, nn
    else:
        for i in range(nn, 0, -1):
            if n % i == 0:
                return i, n//i


n = int(input())
nn1, nn2 = finding(n)
print(nn1+nn2-2)


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    int n;
    cin >> n;
    vi h(n);
    rep(i, n) cin >> h[i];
    vi dp(n + 1, INF);
    dp[0] = 0;

    rep(i, n + 1) {
        if (i - 1 >= 0) dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i - 2 >= 0) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));

        // debug(i);
        // debug(dp[i]);
    }

    out(dp[n - 1]);
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args)
    {
        //変数
        int count=0;
        boolean sw=false;
        int max=Integer.MIN_VALUE;
        int min=Integer.MAX_VALUE;
        int answer=0;
        int tmp=0;
        List<Integer> list1=new ArrayList<>();
        int array1[]=new int[5];
        //入力
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        for(int i=0;i<N;i++)
        {
            list1.add(sc.nextInt());
        }
        //処理
        for(int i=0;i<list1.size();i++)
        {
            tmp=list1.get(i);
            //System.out.println(tmp);
            for (int j=i-1;j>=0;j--)
            {
                //System.out.println(j);
                if(tmp<list1.get(j))
                {
                    break;
                }else
                {
                    if(j==0)
                    {
                        count++;
                    }
                }
            }
            if(i==0)
            {
                count++;
            }
            //System.out.println(i);
        }
        answer=count;
        /*
        Collections.sort(a);
        System.out.println(Arrays.toString(a.toArray()));
        //System.out.println(Arrays.toString(X));
		//System.out.println(Arrays.deepToString(a));
        */
        System.out.println(answer);
    }
}

Measured memory_bytes: 21712
#include <iostream>

using namespace std;

int main(void){
  string N;
  cin >> N;

  if(N[0] == '9')
    cout << "Yes" << endl;
  else if(N[1] =='9')
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll A[3], ans=0;
	ll K;

	rep(i,3) cin >> A[i];
	cin >> K;

	if( K % 2 ){
		ans = A[1] - A[0];
	}else{
		ans = A[0] - A[1];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int k,ans;
	
	scanf("%d",&k);
	
	if(k%2==0){
		ans=(k/2)*(k/2);
	}else{
		ans=(k+1)/2*(k/2);
	}
	
	printf("%d",ans);
	
	return 0;
}

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;



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

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

	vector<int> a(m);
	vector<int> b(m);
	vector<vector<int>> c;
	rep (i, 0, m) {
		cin >> a[i] >> b[i];
		vector<int> tmp(b[i]);
		rep (j, 0, b[i])
			cin >> tmp[j];
		c.push_back(tmp);
	}

	vector<vector<int>> dp(2000, vector<int>(5000, INF));
	dp[0][0] = 0;

	for (int i = 0; i < m; i++) {
		int open_id = 0;
		for (int j = 0; j < b[i]; j++)
			open_id |= (1 << (c[i][j] - 1));

		dp[i + 1] = dp[i];
		for (int j = 0; j < (1 << n); j++) {
			dp[i + 1][j | open_id] = min({dp[i + 1][j | open_id], dp[i][j | open_id], dp[i][j] + a[i]}); // dp[i][0]は常にゼロ
		}
	}

	if (dp[m][(1 << n) - 1] == INF)
		cout << -1 << endl;
	else
		cout << dp[m][(1 << n) - 1] << endl;

	return 0;
}


Measured memory_bytes: 39552
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 1000001;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const int mod =  1e9+7;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   ll n;
   cin>>n;
   vector<pair<ll,ll> > v;
   rep(i,0,n)
   {
   	ll a,b;
   	cin>>a>>b;
   	v.push_back({b,a});
   }
   sort(v.begin(),v.end());
   ll x=0;
   rep(i,0,n)
   {
   	if(x+v[i].se<=v[i].fi)
   	{
   		x+=v[i].se;
	   }
	   else{

	   cout<<"No";
	   return 0;}
   }
   cout<<"Yes";
}

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

const int MAXN = 20;
int m, n;
int bit[MAXN];
bool dp[1<<MAXN];
int path[1<<MAXN];

int main() {
  cin >> m;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    bit[x] |= 1<<y;
  }
  dp[1<<1] = true;
  path[1<<1] = 1;
  for(int i = 0; i < (1<<m); ++i) {
    if(!dp[i]) continue;
    for(int j = 0; j < m; ++j) {
      if(i&(1<<j)) continue;
      if(bit[j] & ~i) continue;
      dp[i|(1<<j)] = true;
      path[i|(1<<j)] = j;
    }
  }
  int b = (1<<m)-1;
  while(b) {
    int p = path[b];
    cout << p+1 << endl;
    b &= ~(1<<p);
  }
  return 0;
}

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


Measured memory_bytes: 2104
#include<iostream>
using namespace std;
int main(){
	long n;
	cin >> n;
	long ans=0;
	for(long i=1;i<n;i++){
		if((n-i)%i==0 && n/((n-i)/i)==n%((n-i)/i)) ans+=(n-i)/i;
		else if((n-i)/i<i) break;
	}
	cout << ans << endl;
}


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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int X;
  cin >> X;

  vector<bool> prime(1e6,true);
  prime.at(0)=false;
  prime.at(1)=false;
  rep(i,1e6){
    if(!prime.at(i))  continue;
    for(int j=i+i;j<1e6;j+=i) prime.at(j)=false;
  }
  REP(i,X,1e6){
    if(prime.at(i)){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
#define rep(i,n) for(i=0 ; i < (n); ++i)
#define rrep(i,n) for(i  1; i <= (n); ++i)
#define drep(i,n) for(i  (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//./a.exe

bool isPrime(int x){
    int i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
  int s,i;
  cin >> s;
  rep(i,1000000){
  if(s==1 || s==2 || s==4 ){
      s = i+4;
      break;
  }
  else if(s==8){
      s = i+5;
      break;

  }
  else if(s%2==0){
      s = s/2;
  }
  else if(s%2 ==1){
      s = s*3 + 1;
  }
  }
  cout << s << endl;


//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,k,ans;
    cin>>a>>b>>c>>k;
    ans=min(a,k);
    k-=ans;
    k-=b;
    if(k>0){ans-=k;}
    cout<<ans;
    return 0;}

Measured memory_bytes: 3620
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input().replace('r', 'a').replace('s', 'b').replace('p', 's').replace(
    'b', 'r').replace('a', 'p')
ans = t.count('r') * r + t.count('s') * s + t.count('p') * p
for i in range(k):
    while i + k < n:
        if t[i] == t[i + k] == 'r':
            ans -= r
            i += k * 2
        elif t[i] == t[i + k] == 's':
            ans -= s
            i += k * 2
        elif t[i] == t[i + k] == 'p':
            ans -= p
            i += k * 2
        else:
            i += k
print(ans)


Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

const int N=405;

int n,h,a,b,c,d,in[N],out[N],f[N];
bool ok[N],vis[N];

int get(int x) {return f[x]?f[x]=get(f[x]):x;}

void merge(int x,int y) {
	x=get(x);y=get(y);
	if (x==y) return;
	f[y]=x;
}

int main() {
	scanf("%d%d",&n,&h);
	fo(i,1,n) {
		scanf("%d%d%d%d",&a,&b,&c,&d);
		int l=c?-c:a;l+=h;
		int r=d?d:-b;r+=h;
		in[r]++;out[l]++;
		vis[l]=vis[r]=1;
		merge(l,r);
	}
	fo(i,h+1,h*2) if (in[i]>out[i]) {puts("NO");return 0;}
	fo(i,0,h-1) if (in[i]<out[i]) {puts("NO");return 0;}
	fo(i,0,h*2) ok[get(i)]|=(in[i]!=out[i]);
	fo(i,0,h*2) if (vis[i]&&get(i)==i&&!ok[i]) {puts("NO");return 0;}
	puts("YES");
	return 0;
}

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

using namespace std;

#define ll long long 
#define Fastest ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

int main()
{
	int a[100005], n; 
	
	cin >> n;
	
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	
	if(n%2)
	{
		cout << 0 << endl;
		return 0;
	}
	
	sort(a+1, a+n+1);
	
	int mid = n/2;
	
	int f = a[mid];
	int l = a[mid+1];
	
	if(f == l) cout << 0 << endl;
	else
	{
		cout << l-f << endl;
	}
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int lim[] = {5, 3, 3, 3, 3, 3, 4, 3, 4};
string inpchar[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

signed main() {
    int n; cin >> n;
    rep(i,0,n) {
        string s, ans; cin >> s;
        int inp = -1, mo = -1;
        rep(j,0,s.length()) {
            if(s[j] == '0') {
                if(inp != -1) {
                    ans += inpchar[inp][mo];
                    mo = -1;
                    inp = -1;
                }
            }
            else {
                inp = s[j] - '1';
                mo = (mo + 1) % lim[inp];
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3144
str = gets.chomp
gets

ARGF.each do |line|
  command, a, b, c = line.chomp.split
  a = a.to_i
  b = b.to_i

  case command
  when "print"
    puts str[a..b]
  when "replace"
    str[a..b] = c
  when "reverse"
    aa = str.slice(0...a)
    bb = str.slice(a..b)
    bb.reverse!
    cc = str.slice((b+1)..(str.length - 1))
    str = aa + bb + cc
  end
end

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

using ll = long long;
ll N;
string S;
int P;

ll solve() {
    if (P == 2 || P == 5) {
        ll res = 0;
        for (int i = 0; i < N; i++) if ((S[N - i - 1] - '0') % P == 0) res += N-i;
        return res;
    }

    vector<ll> val(P, 0);
    ll tenfactor = 1;
    ll cur = 0;
    val[cur]++;

    for (int i = 0; i < N; i++) {
        cur = (cur + (S[N-i-1] - '0') * tenfactor) % P;
        tenfactor = (tenfactor * 10) % P;
        val[cur]++;
    }

    ll res = 0;
    for (int p = 0; p < P; ++p) res += val[p] * (val[p] - 1) / 2;

    return res;
}

int main() {
    cin >> N >> P >> S;
    cout << solve() << endl;
}

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

int main(){

	int a,b;

	cin>>a>>b;

	if(a>b)
		cout<<"a > b"<<endl;
	
	else if(a==b)
		cout<<"a == b"<<endl;
	
	else
		cout<<"a < b"<<endl;
	

	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a>>b>>c>>d;
  int i;
  for(i=0;i<1000;i++){
    c=c-b;
    if(c<=0){
      cout << "Yes";
      break;
    }
    a=a-d;
    if(a<=0){
      cout << "No";
      break;
    }
  }
}
  

Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define EACH( it, c ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	while ( true )
	{
		int n;
		cin >> n;

		if ( !n )
		{
			break;
		}

		VI times( n );
		FOR( t, times )
		{
			cin >> t;
		}
		sort( ALL( times ) );

		LL res = 0, total = 0;
		REP( i, 0, times.size() )
		{
			res += total;
			total += times[i];
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1248
town_num = int(input())

monster_num = list(map(int,input().split()))

hero_power = list(map(int,input().split()))

counter = 0
left_num = 0
for i,(one,two) in enumerate(zip(monster_num,hero_power)):
    counter += min(two+left_num,one)
    left_num = min(max(0,two+left_num-one),two)
counter += min(monster_num[-1],left_num)

print(counter)


Measured memory_bytes: 19116
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  long long N,M,a,b,ans=0;
  cin>>N>>M;
  vector <pair<long long, long long> > p(N);
  for(int i=0;i<N;i++){
    cin>>a>>b;
    p[i]=make_pair(a,b);
  }
  sort(p.begin(),p.end());
  long long sum=0;
  for(int i=0;i<N;i++){
    if(p[i].second+sum>=M){
      ans+=(M-sum)*p[i].first;
      break;
    }else{
      ans+=p[i].first*p[i].second;
      sum+=p[i].second;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792