akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] ar = new long[n];

        for (int i = 0; i < ar.length; i++) {
            ar[i] = scan.nextLong();
        }


        boolean flag = true;
        for (int i = ar.length - 2; i >= 0; i--) {
            if (ar[i + 1] < ar[i] && ar[i] - ar[i + 1] > 1) {
                flag = false;
                break;
            }else if(ar[i + 1] < ar[i] && ar[i] - ar[i + 1] == 1){
                ar[i]--;
            }
        }

        System.out.println(flag ? "Yes" : "No");
    }
}


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

using namespace std;

using ll = long long;

bool Solve() {
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 1; i < 1000; ++i)
        if (a * i % b == c) return true;
    return false;
}

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

    if (Solve()) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;

int main(){
    string S, T; cin >> S >> T;
    ll ans = INF;
    for(int i = 0; i <= S.size() - T.size(); i++){
        ll cnt = 0;
        for(int j = 0; j < T.size(); j++){
            if(S[i+j] != T[j]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Grid {
    Grid(int h, int w) : h(h), w(w), st(w + 1), v(h * st, -1) {}
    void bfs() {
        queue<int> q;

        char a[1001];
        for (int i = 0; i < h; i++) {
            cin >> a;
            for (int j = 0; j < w; j++) {
                if (a[j] == '#') {
                    q.push(st * i + j);
                    v[st * i + j] = 0;
                }
            }
        }

        int r = 0;
        while (!q.empty()) {
            int k = q.front(); q.pop();
            for (auto d : { -st, -1, 1, st }) {
                int l = k + d;
                int i = l / st;
                int j = l % st;
                if (l < 0 || i == h || j == w) continue;
                if (v[l] < 0) {
                    q.push(l);
                    r = v[l] = v[k] + 1;
                }
            }
        }
        cout << r << endl;
    }
    int h, w, st;
    vector<int> v;
};

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

    int h, w;
    cin >> h >> w;

    Grid g(h, w);
    g.bfs();

    return 0;
}

Measured memory_bytes: 8320
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <utility>


#define MOD 1000000007

using ll = long long int;
using namespace std;

vector<vector<ll>> adj(100005);

ll N, K;

ll solve(ll node, ll from) {
  ll sum = 1;
  ll nchoice = (from == -1 ? K - 1 : K - 2);

  for (ll c : adj[node]) {
    if (from == c) continue;
    sum = sum * solve(c, node) % MOD;
    sum = sum * nchoice % MOD;
    nchoice -= 1;  
  }

  return sum;
}

int main() {
  cin >> N >> K;
  
  for (int i = 0; i < N - 1; i++) {
    ll a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  cout << (K * solve(1, -1)) % MOD << endl;

  return 0;
}

Measured memory_bytes: 10368
N = int(input())
A = list(map(int,input().split()))

def f(x):
  cnt = 0
  tmp = 0
  for a in A:
    tmp += a
    #print(tmp, x)
    if(tmp*x >= 0):
      cnt += abs(tmp)+1
      tmp = -x
    x *= -1
    #print(tmp, x)
  return cnt

print(min(f(1), f(-1)))  

Measured memory_bytes: 14332
/// Zhamshitov
/// Rinat
/// Rahatovich
/// 8 "A";
///
#include <bits/stdc++.h>

using namespace std;


int main()

{
    int n, m, a[1009], mx = -9, mn = 999999;
    cin >> n;
    for( int i = 0 ; i < n; i++ )
        cin >> a[i], mx = max(a[i], mx), mn = min(mn, a[i]);
    cout << mx - mn;
}



Measured memory_bytes: 256
N, P = map(int, input().split())

def factorization(n):
    arr, temp = [], n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

fac = list(reversed(factorization(P)))
ans = 1

for sosuu, cnt in fac:
    cnt //= N
    if cnt>0:
        ans *= (sosuu**cnt)

print(ans)

Measured memory_bytes: 3064
class CompleteBinaryTree:
    def __init__(self, nodes):
        self.size = len(nodes)
        self.nodes = [None] + nodes
        
    
    def print_nodes(self):
        for i in range(1,self.size + 1):
            if i == 1:
                print('node {0}: key = {1}, left key = {2}, right key = {3}, '.format(i, self.nodes[i], self.nodes[2*i], self.nodes[2*i+1]))
            elif 2*i < self.size:
                print('node {0}: key = {1}, parent key = {2}, left key = {3}, right key = {4}, '.format(i, self.nodes[i], self.nodes[i//2], self.nodes[2*i], self.nodes[2*i+1]))
            elif 2*i == self.size:             
                print('node {0}: key = {1}, parent key = {2}, left key = {3}, '.format(i, self.nodes[i], self.nodes[i//2], self.nodes[2*i]))
            else:
                print('node {0}: key = {1}, parent key = {2}, '.format(i, self.nodes[i], self.nodes[i//2]))


    def _find_left(self, i):
        if 2*i <= self.size:
            return self.nodes[2*i]
        else:
            return -9999999999


    def _find_right(self, i):
        if 2*i+1 <= self.size:
            return self.nodes[2*i+1]
        else:
            return -9999999999


    def maxHeapify(self, i):
        n, l, r = self.nodes[i], self._find_left(i), self._find_right(i)
        if max(n, l, r) == l:
            self.nodes[i], self.nodes[2*i] = self.nodes[2*i], self.nodes[i]
            self.maxHeapify(2*i)
        elif max(n, l, r) == r:
            self.nodes[i], self.nodes[2*i+1] = self.nodes[2*i+1], self.nodes[i]
            self.maxHeapify(2*i+1)
            
    
    def buildMaxHeap(self):
        for i in range(self.size//2,0,-1):
            self.maxHeapify(i)


if __name__ == '__main__':
    n = int(input())
    nodes = list(map(int, input().rstrip().split()))
    cbt = CompleteBinaryTree(nodes)
    cbt.buildMaxHeap()
    print(' ' + ' '.join(map(str,cbt.nodes[1:])))


Measured memory_bytes: 68096
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    int n;
    cin >> n;
    vector<LL> a(n), b(n);
    vector<pair<LL, int>> c(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        c[i].first = a[i] + b[i];
        c[i].second = i;
    }
    sort(c.begin(), c.end(), greater<pair<LL, int>>());

    LL diff = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            diff += a[c[i].second];
        } else {
            diff -= b[c[i].second];
        }
    }
    cout << diff << endl;
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<vector<pair<int,int>>> A(N);
  for(int i=0;i<N-1;i++){
    int u,v,w;
    cin>>u>>v>>w;
    A[u-1].push_back({v-1,w});
    A[v-1].push_back({u-1,w});
  }
  vector<int> B(N,-1);
  B[0]=0;
  queue<int> C;
  C.push(0);
  while(!C.empty()){
    int I=C.front();
    C.pop();
    for(pair<int,int> p:A[I])
      if(B[p.first]==-1){
        B[p.first]=B[I]+p.second;
        C.push(p.first);
      }
  }
  for(int i:B)
    cout<<i%2<<endl;
}

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

int main(void){
    long long n,k,ans,m;
    scanf("%lld%lld",&n,&k);
    ans = n;
    if (n/k > 100000){
        m = n/k;
        n -= m*k;
    }
    for (long long i=0;i<=1001000;i++){
        n -= k;
        if (n < 0){
            n *= -1;
        }
        if (ans > n){
            ans = n;
        }
    }
    printf("%lld",ans);
}

Measured memory_bytes: 128
// https://atcoder.jp/contests/abc153/submissions/9756127
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	hs := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&hs[i])
	}

	if n <= k {
		fmt.Print(0)
		return
	}

	sort.Sort(sort.Reverse(sort.IntSlice(hs)))

	var hs2 []int
	if k == 0 {
		hs2 = hs
	} else {
		hs2 = hs[k:]
	}

	cal := 0
	for _, h := range hs2 {
		cal = cal + h
	}

	fmt.Print(cal)
}


Measured memory_bytes: 5504
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String T = sc.next();
        String P = sc.next();
        for(int i = 0 ; i <= T.length() - P.length() ; i++){
            for(int j = 0 ; j < P.length() ; j++){
                if(!(T.charAt(i+j) == P.charAt(j)))
                    break;
                if(j == P.length()-1)
                    System.out.println(i);
            }
        }
    }
}


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

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll sum = 0;

  vector<ll> v(n);

  for (int i = 0; i < n; i++)
    cin >> v[i];

  sort(v.begin(), v.end());
  ll ans = 0;

  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ll sm = v[i] + v[j];

      ll ind = lower_bound(v.begin(), v.begin() + i, sm) - v.begin();
      ll ind2 = upper_bound(v.begin(), v.begin() + i, v[j] - v[i]) - v.begin();
      // cout << i << " " << j << " -- > " << ind << " " << ind2 << endl;
      ans += max(0ll, ind - ind2);
    }
  }

  cout << ans << endl;
  return 0;
}

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



int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
 
    int A, B, K;
    cin >> A >> B >> K;
 
    if(B - A + 1 > K * 2) {
        for(int i = 0; i < K; i++) {
            cout << A + i << endl;
        }
        for(int i = K - 1; i >= 0; i--) {
            cout << B - i << endl;
        }
    } else {
        for(int i = A; i <= B; i++) {
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int sort(const long *a, const long *b){
return *a-*b;
}
int main(){
int n,m;
  scanf("%d%d",&n,&m);
  long ab[n][2];
  for(int i=0;i<n;i++){
	scanf("%ld%ld",&ab[i][0],&ab[i][1]);
  }//0:金額 1:本数
  qsort(ab,n,sizeof(long)*2,sort);
 int sum=0;//本数累計
  long long money=0;
  for(int i=0;i<n;i++){
	if(ab[i][1]+sum<m){
      money+=ab[i][0]*ab[i][1];//金額の加算(まとめて)
                       sum+=ab[i][1];//本数の加算
    }
   else {//途中で条件を満たす場合 //
     for(int j=0;j<ab[i][1];j++){//
	money+=ab[i][0];
       sum++;
       if(sum==m){printf("%lld",money);
                  return 0;
                 }//
     }//for
   }//else
    }
    
    return 0;
  }

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

const int mod = 998244353  ;

#define ft first
#define sd second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )


int main(){
 ios_base::sync_with_stdio(0);
        ll n;
        cin >> n;
        while(n--){
            ll i;
            cin >> i;
            if(i&1){
                    cout << "first";
            return 0;}
        }
        cout << "second";

    return 0;
}


Measured memory_bytes: 256
import sys
n = int(input())
h = list(map(int, input().split()))
h.reverse()
g = h[0]
for i in range(len(h)):
    if g - h[i] >= 0:
        g = h[i]
    elif g - h[i] == -1:
        g = h[i] - 1
    else:
        print("No")
        sys.exit()
print("Yes")


Measured memory_bytes: 15020
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

public class Cell
{
    public int X { get; set; }
    public int Y { get; set; }
    public string CellType { get; set; }
    public int Step { get; set; }

    public static Cell[] GetCells(char[] row, int y)
    {
        var cells = Enumerable.Range(0, row.Length).Select(x => new Cell
        {
            X = x + 1,
            Y = y,
            CellType = Convert.ToString(row[x]),
            Step = -1,
        });
        return cells.ToArray();
    }

}


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var n = Read();
        var input = Reads();
        var t = input[0];
        var a = input[1];
        input = Reads();
        var d = new double[n];
        for(int i = 0; i < n; i++)
        {
            d[i] = Math.Abs(a-(t - input[i] * 0.006));
        }
        long min=0;
        for(int i = 0; i < n; i++)
        {
            if (d.Min() == d[i])
            {
                min = i;
            }
        }
        Console.WriteLine(min + 1);

        Console.Out.Flush();
    }
}

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

#define int long long
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*
ifstream ifs("in.txt");
ofstream ofs("out.txt");
#define cin ifs
#define cout ofs
//*/

int a, b, c, d;
signed main() {
    cin >> a >> b >> c >> d;
    if ((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
# cnt = 0
# rem = 0
# for i in range(25):
#     if i*(i-1)//2 >= k:
#         cnt = i+1
#         rem = i*(i-1)//2 - k
#         break

ansl = []
for i in range(n-1):
    ansl.append((1,i+2))

com = (n-1)*(n-2)//2
rem = com - k
if rem < 0:
    print(-1)
    exit()

cu = 2
cv = 3
for i in range(rem):
    if cv > n:
        cu += 1
        cv = cu+1
    ansl.append((cu,cv))
    cv += 1

print(len(ansl))
for u,v in ansl:
    print(u,v)

# print(cnt)
# print(rem)

Measured memory_bytes: 74448
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 long long int H;
  cin>>H;
  long long int count=0 ,a=1;
   while(H>=1){
      H=H/2;
    count=count+a;
      a=a*2;
    }
 cout<<count;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>
#include<cassert>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで




using namespace std;
int n,m,k;
int a;//各距離の数
int b;
int extgcd(int a, int b, int &x, int &y) {
    int g = a;
    x = 1;
    y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}

int mod_fact(int n,int p,int& e){
  e = 0;
  if(n==0) return 1;
  int res = mod_fact(n/p,p,e);
  e += n/p;
  if(n/p%2 != 0){
    int t = 1;
    for(int i=1;i<=n;i++){
      t *= i;
      t %= p;
    }
    return res*(p-t)%p;
  }
  int t2=1;
  for(int i=1;i<=n;i++){
    t2 *= i;
    t2 %= p;
  }
  return res * t2%p;
}

int mod_inverse(int a,int m){
  int x,y;
  extgcd(a,m,x,y);
  return (m+x%m) %m;
}

int mod_comb(int n,int k,int p){
  if(n<0||k<0||n<k) return 0;
  int e1,e2,e3;
  int a1 = mod_fact(n,p,e1),a2 = mod_fact(k,p,e2),a3 = mod_fact(n-k,p,e3);
  if(e1>e2+e3) return 0;
  return a1 * mod_inverse(a2*a3%p,p)%p;
}


signed main(){
  cin >> n >> m >> k;
  if(m<n) swap(n,m);
  FOR(i,n){
    FOR(j,m){
      FOR(l,n){
        a += (2*abs(l-i)+(m-j))*(m-j+1)/2;
        a %= MOD;
        a += (2*abs(l-i)+(j-1))*(j)/2;
        a %= MOD;
        a += (MOD-abs(l-i));
        a %= MOD;
      }
    }
  }
  a *=500000004;
  a %= MOD;
  b = mod_comb(n*m-2,k-2,MOD);
  b %= MOD;
  cout << a*b%MOD << endl;
  return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    class V
    {
        public long p;
        public long m;
    }

    public static void Main()
    {
        long N, M;
        string[] strs = Console.ReadLine().Split(' ');
        N = long.Parse(strs[0]);
        M = long.Parse(strs[1]);
        List<V> L = new List<V>() { Capacity = (int)N };
        for(int i = 0; i < N; i++)
        {
            strs = Console.ReadLine().Split(' ');
            V tmp = new V();
            tmp.p = long.Parse(strs[0]);
            tmp.m = long.Parse(strs[1]);
            L.Add(tmp);
        }
        L.Sort((x, y) => (int)(x.p - y.p));

        long price = 0;
        for(int i = 0; i < N;)
        {
            long c = Math.Min(L[i].m, M);
            price += c * L[i].p;
            L[i].m -= c;
            M -= c;
            if (M <= 0)
                break;
            if (L[i].m == 0)
                i++;
        }
        Console.WriteLine(price);
    }
}

Measured memory_bytes: 22852
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

int main(){
  int i,j;
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b==c) cout<<"No"<<endl;
  else if(a==b||b==c||c==a) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}
  


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

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

const int MAXN = 1010;
const int INF = 1000000010;

int n, m, k;

int dp[MAXN];

char v[MAXN][MAXN];

vector< int > sumBlocks;

void buildBlocks(int mask)
{
	sumBlocks.push_back( 0 );

	int sz = __builtin_popcount( mask );

	for(int i = 0 ; i < sz ; i++)
		sumBlocks.push_back( 0 );
}

bool isValid()
{
	for(int i = 0 ; i < sumBlocks.size() ; i++)
		if( sumBlocks[i] > k ) return false;

	return true;
}

void change(int i, int val, int mask)
{
	int ind = 0;

	for(int k = 1 ; k <= n ; k++)
	{
		sumBlocks[ind] += (v[k][i] - '0')*val;
		if( mask & (1 << (k - 1) ) ) ind++;
	}
}

int main()
{
	scanf("%d %d %d",&n,&m,&k);

	for(int i = 1 ; i <= n ; i++)
		for(int j = 1 ; j <= m ; j++)
			scanf(" %c",&v[i][j]);

	int ans = INF;

	for(int mask = 0 ; mask < (1 << (n - 1)) ; mask++)
	{
		int L = 1;

		sumBlocks.clear();
		buildBlocks( mask );

		dp[0] = -1;
		dp[m] = INF;

		for(int i = 1 ; i <= m ; i++)
		{
			change( i , 1 , mask );

			while( L <= i && !isValid() )
				change( L++ , -1 , mask );

			if( L > i ) break;

			dp[i] = dp[L - 1] + 1;
		}

		ans = min( ans , dp[m] + __builtin_popcount( mask ));
	}

	printf("%d\n",ans);
}	

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std ;

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	string s;
	
	cin >> s;

	int pos = -1;
	ll count = 0;
	int i = 0;
	int len = s.size();
	/*
	while ((s[i] == 'W') && (i < len))
	{
		i++;
	}

	if (i == len)
	{
		cout << 0 << endl;
		return 0;
	}

	pos = i - 1;

	for (; i < s.size(); i++)
	{
		if (s[i] == 'W')
		{
			count += i - pos - 1;
			pos = pos + 1;
		}
	}
	*/
	std::vector<int> v;
	for (int i = 0; i < len; i++)
	{
		if (s[i] == 'W')
		{
			v.pb(i);
		}
	}

	for (int i = 0; i < v.size(); i++)
	{
		count += v[i] - i;
	}
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 1680
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
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() {
ll ans = 0;
	int N,K; cin >> N >> K;
	ll A[N+2];  //h_i
	ll dp[N+2]; //たどり着くまでのコストの最小
	rep(i,N){cin >> A[i];}
	rep(i,N)
	{
		if(i == 0){dp[0] = 0; continue;}
		ll a = MOD * MOD;
			rep(j,K)
			{
				if( i-(j+1) < 0){continue;}
			ll b = abs(A[i] - A [i-(j+1)]) + dp[i-(j+1)];
			a = min(a,b);
			}
		dp[i] = a;
	}
	ans = dp[N-1];

	cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.*;
import java.util.stream.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		int left = 0;
		long sum = 0, xor = 0;
		for (int right = 0; right < n; right++) {
			while((xor ^ a[right]) != (xor + a[right])) {
				xor ^= a[left++];
			}
			xor ^= a[right];
			sum += right - left + 1;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 89540
#include <iostream>
#include <string>
#include <set> 
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;

int main(){
int N; int ans=50000000;
string s;
cin>>N>>s;

int dp[400000];int left[400000];int right[400000];
right[0]=0;left[0]=0;
for(int i=1;i<N;i++){
    if(s[i]=='W')  continue;
    else right[0]++; 
}
//cout<<right[0]<<endl;
dp[0]=left[0]+right[0];
ans=dp[0];
for(int i=1;i<=N-1;i++){
    if(s[i-1]=='W') left[i] = left[i-1]+1;
    else left[i]=left[i-1];
    if(s[i]=='E') right[i] = right[i-1]-1;
    else right[i]=right[i-1];
    ans = min(ans,left[i]+right[i]);
   // if(ans==1) cout<<i<<endl;
   //cout<<ans<<endl;
}
/*dp[N-1]=0;
for(int i=0;i<N-1;i++){
    if(s[i]=='E') continue;
    else dp[N-1]++;
} */

cout<<ans<<endl;
return 0;
}




Measured memory_bytes: 3716
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
using namespace std;

typedef long long ll;
int modulo = 1000000007; // 10^9 + 7


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

	if (N % 2 == 0) {
		for (int i = N - 1; i >= 1; i = i - 2) cout << a[i] << " ";
		for (int i = 0; i <= N - 2; i = i + 2) cout << a[i] << " ";
	}
	else {
		for (int i = N - 1; i >= 0; i = i - 2) cout << a[i] << " ";
		for (int i = 1; i <= N - 2; i = i + 2) cout << a[i] << " ";
	}

	return 0;
}

Measured memory_bytes: 2944
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))
ans = "No"

if (A1[0] in b) and (A2[0] in b) and (A3[0] in b):
    ans = "Yes"
if (A1[1] in b) and (A2[1] in b) and (A3[1] in b):
    ans = "Yes"
if (A1[2] in b) and (A2[2] in b) and (A3[2] in b):
    ans = "Yes"
if (A1[0] in b) and (A2[1] in b) and (A3[2] in b):
    ans = "Yes"
if (A1[2] in b) and (A2[1] in b) and (A3[0] in b):
    ans = "Yes"
if (A1[0] in b) and (A1[1] in b) and (A1[2] in b):
    ans = "Yes"
if (A2[0] in b) and (A2[1] in b) and (A2[2] in b):
    ans = "Yes"
if (A3[0] in b) and (A3[1] in b) and (A3[2] in b):
    ans = "Yes"

print(ans)

Measured memory_bytes: 3064
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

use std::io::Write;

fn run() {
    input! {
        n: usize,
        k: u32,
        a: [u32; n],
    }
    let mut valid = vec![true; 1 << n];
    for i in 0..(1 << n) {
        let mut sum = 0;
        for j in 0..n {
            if (i >> j) & 1 == 1 {
                sum += a[j];
            }
        }
        if sum == k {
            valid[i] = false;
        }
    }
    for i in 1..(1 << n) {
        for j in 0..n {
            if (i >> j) & 1 == 1 {
                valid[i] &= valid[i ^ (1 << j)];
            }
        }
    }
    let mut ans = n;
    for i in 0..(1 << n) {
        if valid[i] {
            ans = std::cmp::min(ans, n - i.count_ones() as usize);
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
using ll = long long;
using pll = std::pair<ll,ll>;
const ll INF = (ll)1e18L;
const int NMAX = 404;
pll dp[NMAX][NMAX];
int main() {
    int n; std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        dp[i][i] = pll(0,a[i]);
    }
    for (int len = 2; len <= n; len++) {
        for (int i = 0, j = len - 1; j < n; i++,j++) {
            dp[i][j] = pll(INF,INF);
            for (int mid = i+1; mid <= j; mid++) {
                pll lt = dp[i][mid-1];
                pll rt = dp[mid][j];
                pll curr(lt.first + rt.first + lt.second + rt.second, lt.second + rt.second);
                dp[i][j] = std::min(dp[i][j], curr);
            }
        }
    }
    std::cout << dp[0][n-1].first << std::endl;
    return 0;
}

Measured memory_bytes: 2560
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main(){
  int a;
  cin >> a;
  cout << 3 * a * a << endl;
}

Measured memory_bytes: 256
A123 = list(map(int, input().split()))
ans = 1000

for i, a in enumerate(A123):
    for j, b in enumerate(A123):
        for k, c in enumerate(A123):
            if i != j and j != k and k != i:
                tmp = abs(b - a) + abs(c - b)
                if tmp < ans:
                    ans = tmp

print(ans)

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

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007
#define D 6410

ll dp[81][81][13000];

int main(){
  clr(dp,0);
  ll h,w;
  cin>>h>>w;
  vector<vector<ll> > vr(h,vector<ll>());
  vector<vector<ll> > vb(h,vector<ll>());
  rep(y,0,h){
    rep(x,0,w){
      ll a;
      cin>>a;
      vr[y].pb(a);
    }
  }
  rep(y,0,h){
    rep(x,0,w){
      ll a;
      cin>>a;
      vb[y].pb(a);
    }
  }
  dp[0][0][vr[0][0]-vb[0][0]+D] = 1;
  dp[0][0][vb[0][0]-vr[0][0]+D] = 1;
  rep(y,0,h){
    rep(x,0,w){
      if(y==0&&x==0)continue;
      ll r = vr[y][x];
      ll b = vb[y][x];
      rep(i,0,13000){
        if(y>0){
          if(dp[y-1][x][i]!=0){
            dp[y][x][i+r-b] = 1;
            dp[y][x][i+b-r] = 1;
          }
        }
        if(x>0){
          if(dp[y][x-1][i]!=0){
            dp[y][x][i+r-b] = 1;
            dp[y][x][i+b-r] = 1;
          }          
        }
      }
    }
  }
  ll mn = 1000000000;
  rep(i,0,13000){
    if(dp[h-1][w-1][i]==1){
      mn = min(mn,abs(i-D));
    }
  }
  cout << mn << endl;
  return 0;
}

Measured memory_bytes: 666880
#include<bits/stdc++.h>
#define int long long
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(int i=0;i<n;i++)
#define double long double
#define mod 998244353
#define F first
#define S second
#define pb push_back

using namespace std;



signed main()
{
	fast;
	int test=1;
	// cin>>test;
	for(int index=1;index<=test;index++)
	{	
		string s,t;
		cin>>s>>t;
		int len1=s.length();
		int len2=t.length();

		bool ans=0;
		for(int i=0;i<26;i++)
		{
			char temp='a'+i;
			if((s+temp)==t)
			{
				ans=1;
				break;
			}
		}
		
		if(ans==1) cout<<"Yes"<<endl;
		else
		{
			cout<<"No"<<endl;
		}
		
    }
}

Measured memory_bytes: 3616
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
if sum(A) < sum(B):
    print(-1)
    quit()
C = []
c = 0
for i in range(N):
    if A[i] < B[i]:
        c += B[i] - A[i]
    else:
        C.append(A[i] - B[i])
C.sort()
while c > 0:
    x = C.pop()
    c -= x
print(N-len(C))

Measured memory_bytes: 18292
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int x,a,b; cin >> x >> a >> b;
    if(abs(x-a)<abs(x-b)) out('A');
    if(abs(x-a)>abs(x-b)) out('B');

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main(){
  string s;
  cin >> s;
  if(s[0]=='9'||s[1]=='9'){
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 256
import sys
from bisect import bisect_right

def input(): return sys.stdin.readline().rstrip()

n, a, b, c, d = (int(x) for x in input().split())
A = [(a, a)]
for i in range(1, n):
    tmp = []
    for l, r in A:
        tmp.append((l + c, r + d))
        tmp.append((l - d, r - c))
    tmp.sort()
    index = bisect_right(tmp, (b, b))
    A = []
    for j in range(index - 2, index + 3):
        if 0 <= j < len(tmp):
            A.append(tmp[j])

ans = "NO"
for l, r in A:
    if l <= b <= r:
        ans = "YES"

print(ans)


Measured memory_bytes: 74172
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include<bitset>

using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par; 
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i; 
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d,e, H, W,L;
long long A[200005] = {};
long long B[200005] = {};
long long C[200005] = {};
long long D[200005] = {};
long long E[200005] = {};
bool f, ff;
string S;
set <long long>sll;
pl bufpl;
vector <long long>vl;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


bool fs[2005][2005] = {};

int main() {


	cin >>a>>b;
	
	f = false;
	if (a % 2 == 0 || b % 2 == 0) {
		f = true;
	}

	if (f) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}
	
	
	return 0;

}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#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 all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int MOD = (int)1e9+7;

int main(void) {
	//freopen("in.txt", "r", stdin);
	int n, m;
	cin >> n >> m;
	vector<pair<int, int> > v;
	rep(i,0,m) {
		int a, b;
		cin >> a >> b;
		v.pb(mp(a,-b));
	}
	sort(all(v));
	int ret = 1;
	int l = 0;
	int r = n;
	rep(i,0,m) {
		int a = v[i].F;
		int b = -v[i].S;
		int nl = max(l, a);
		int nr = min(r, b);
		if(nl >= nr) {
			ret++;
			l = a;
			r = b;
		} else {
			l = nl;
			r = nr;
		}
	}
	cout << ret << '\n';
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <iomanip>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c;
    cin >> a >> b >> c;
    VL diff = VL({
        a * b * (c % 2), 
        b * c * (a % 2),
        c * a * (b % 2)
    });
    cout << *min_element(ALL(diff)) << endl;
    return 0;
}


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

int main(){                                                                                 
  std::stack<int> st;                                                                       
  int input;                                                                                
  while(std::cin >> input ){                                                                
    if(input == 0){                                                                         
      std::cout << st.top() << std::endl;                                                   
      st.pop();                                                                             
    }                                                                                       
    else{                                                                                   
      st.push(input);                                                                       
    }                                                                                       
  }                                                                                         
  return 0;                                                                                 
}

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

int main() {
	// your code goes here
	long long n,k,i,r,s,p;
	cin>>n>>k>>r>>s>>p;
	string str;
	cin>>str;
	string play;
	long long score=0;
	for(i=0;i<k && i<n;i++)
	{
		if(i==k)
			break;
		if(str[i]=='r')
			play+='p',score+=p;
		else if(str[i]=='p')
			play+='s',score+=s;
		else
			play+='r',score+=r;
	}
	for(i=k;i<n;i++)
	{
		if(str[i]=='r' && play[i-k]!='p')
			play+='p',score+=p;
		else if(str[i]=='p' && play[i-k]!='s')
			play+='s',score+=s;
		else if(str[i]=='s' && play[i-k]!='r')
			play+='r',score+=r;
		else
			play+='x';
	}
	//cout<<play<<endl;
	cout<<score<<endl;

}

Measured memory_bytes: 640
import sys
import collections

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    AB = []
    V = [[] for _ in range(N + 1)]
    for _ in range(M):
        a, b = [int(x) for x in input().split()]
        AB.append([a, b])
        V[a].append(b)
        V[b].append(a)


    ans = 0
    for a, b in AB:
        visited = set()

        q = collections.deque()
        q.append(1)
        visited.add(1)

        while q:
            c = q.pop()
            for i in V[c]:
                if i in visited:
                    continue
                if (a == i and b == c) or (a == c and b == i):
                    continue
                else:
                    q.append(i)
                    visited.add(i)

        if len(visited) != N:
            ans += 1

    print(ans)









if __name__ == '__main__':
    main()



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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
	return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
	return a / gcd(a, b) * b;
}

string IntToString(int number)
{
	stringstream ss;
	ss << number;
	return ss.str();
}

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

int main()
{
    vi v[10];
    int b, c;
    rep(i, 3) {
	ci >> b >> c;
	v[b].pb(c);
	v[c].pb(b);
    }

    int c1 = 0, c2 = 0;
    for(int i = 1; i < 5; i++) {
	if(v[i].size() == 1) c1++;
	if(v[i].size() == 2) c2++;
    }
    
    if(c1 == 2 && c2 == 2) co << "YES" << en;
    else co << "NO" << en;
    
    return 0;
}









Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=105;
const int INF=1e9+1;
int n;
int a[N];
int main()
{
	scanf("%d",&n);
    int x;
    scanf("%d",&x);
	int ans=0;
    for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
        if(i<n){
            if(a[i]>x)
				break;
            x-=a[i];
            ans++;
        }
        else{
            if(a[i]==x)
				ans++;
        }
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 128
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if x==500*i+100*j+50*k:
        ans+=1
print(ans)
      



Measured memory_bytes: 67364
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  st s;
  cin >> s;
  ll k=s.size();
  ll ans=k;
  rep(i,k-1){
    if(s[i]!=s[i+1]){
      ans=min(ans,max(i+1,k-i-1));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3712
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int num1 = scan.nextInt();
        int K = scan.nextInt();

        int array[] = new int[num1];
        int dp[] = new int[num1];
        Arrays.fill(dp, 1000000000); 
        
        for(int i=0; i<num1; i++){
            int num2 = scan.nextInt();
            array[i] = num2;
        }
        
        dp[0] = 0;
        
        for(int i=1; i<num1; i++){
            for(int j = 1; j<K+1; j++){
                if(i-j > -1){
                    if(dp[i] > dp[i-j] + Math.abs(array[i] - array[i-j])){
                        dp[i] = dp[i-j] + Math.abs(array[i] - array[i-j]);
                    }
                }
            }
        }
        
        System.out.println(dp[num1 -1]);
    }
}

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

const int N_MAX = 300;
double dp[N_MAX+1][N_MAX+1][N_MAX+1];
int N;

double rec(int i, int j, int k){
  if(dp[i][j][k] >= 0) return dp[i][j][k];
  if(i == 0 && j == 0 && k == 0) return 0.0;
  
  double res = 0.0;
  if(i > 0) res += rec(i-1, j, k) * i;
  if(j > 0) res += rec(i+1, j-1, k) * j;
  if(k > 0) res += rec(i, j+1, k-1) * k;
  res += N;
  res /= i + j + k;
  return dp[i][j][k] = res;
}

int main() {
  cin >> N;
  
  int one = 0, two = 0, three = 0;
  for(int i = 0; i < N; i++){
    int a; cin >> a;
    if(a == 1) one++;
    if(a == 2) two++;
    if(a == 3) three++;
  }
  
  memset(dp, -1, sizeof(dp));
  
  cout << fixed << setprecision(10) << rec(one, two, three) << endl;
}

Measured memory_bytes: 213376
#include<stdio.h>
int main(){
    int n,m,i,a,b;
    scanf("%d%d",&n,&m);
    char s[5]={};
    while(m--){
        scanf("%d%d",&a,&b);
        if(a==1&&b==0&&n-1) goto END;
        if(s[a-1]&&s[a-1]-b-'0') goto END;
        s[a-1]=b+'0';
    }
    if(s[0]==0) s[0]=n-1?'1':'0';
    for(i=0;i<n;i++)
        if(!s[i])
            s[i]='0';
    printf("%s\n",s);
    return 0;
    END: ;
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
 
int main (void) {
    int N, K, Q;
    cin >> N >> K >> Q;
 
    vector<int> P(N, K);
    for (int i=0;i<Q; i++) {
        int a;
        cin >> a;
        P[a-1]++;
    }
    for (int i=0;i<N;i++) {
        if (P[i]-Q >0){
            cout << "Yes" << endl;
        }else {
            cout << "No" << endl;
        }
    }
 
    return 0;
}


Measured memory_bytes: 1024
#include <cfloat>
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	double W, H, x, y;
	cin >> W >> H >> x >> y;
	cout << W * H / 2.0 << " ";
	if (abs(W / 2.0 - x) < DBL_EPSILON && abs(H / 2.0 - y) < DBL_EPSILON)	cout << 1 << endl;
	else																	cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 256