akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, acc[333333];

  std::string s;
  
  std::cin >> N >> s;

  acc[0] = 0;

  for (int i = 0; i < N; i ++)
    acc[i + 1] = acc[i] + (s[i] == 'E' ? 1 : 0);

  int cm = INF;

  for (int i = 0; i < N; i ++) {
    int c = (i - (acc[i] - acc[0])) + (acc[N] - acc[i + 1]);

    cm = std::min(c, cm);
  }

  std::cout << cm << std::endl;
  
  return 0;
}


Measured memory_bytes: 1812
#include <iostream>
#include <stack>
#include <string>
#include <cstdlib> 
using namespace std;

int main(){
    string word;
    stack<int> S;
    while (cin >> word){
        if (word == "+"){
            int n = S.top();
            S.pop();
            int m = S.top();
            S.pop();
            S.push(n + m);
        }
        else if (word == "-"){
            int n = S.top();
            S.pop();
            int m = S.top();
            S.pop();
            S.push(m - n);
        }
        else if (word == "*"){
            int n = S.top();
            S.pop();
            int m = S.top();
            S.pop();
            S.push(m * n);
        }
        else if (word == "/"){
            int n = S.top();
            S.pop();
            int m = S.top();
            S.pop();
            S.push(m / n);
        }else{
            S.push(stoi(word));
        }
    }
    cout << S.top() << endl; 
}

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

#define ll     long long
#define fr     first
#define sec    second
#define rep(i,n)  for(i=0;i<n;i++)
#define vi     vector <int>
#define vc     vector <char>
#define vl     vector <ll>
#define vb     vector <bool>
#define pb     push_back
#define M      1000000007
#define ios    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open   freopen("input.txt","r",stdin);
#define close  freopen("output.txt","w",stdout);
#define M_PI   3.14159265358979323846
#define pp     pair<int,int>
#define nn 100003
#define MM 1000000000
#define MN 1000000000000000000

void solve()
{
    float d,t,s;
    cin>>d>>t>>s;
    if(d/s<=t)
        cout<<"Yes";
    else
        cout<<"No";
    return;
}

int main()
{
    ios;
    solve();
    return 0;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

uint_fast32_t scan(){
    uint_fast32_t a{};
    int c;
    while((c=getchar_unlocked()-'0')>=0) a=(a<<1u)+(a<<3u)+c;
    return a;
}

uint_fast64_t scan64(){
    uint_fast64_t a{};
    int c;
    while((c=getchar_unlocked()-'0')>=0) a=(a<<1u)+(a<<3u)+c;
    return a;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    ll k;
    n=scan();k=scan64();
    vector<int> a(n),f(n);
    for(auto&i:a) i=scan();
    for(auto&i:f) i=scan();
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    sort(f.begin(),f.end());
    ll l=-1,r=1e18,m;
    while(r-l>1){
        m=(l+r)>>1;
        ll s=0;
        fr(i,n) if(a[i]>m/f[i]) s+=a[i]-m/f[i];
        if(s>k) l=m;
        else r=m;
    }
    cout<<r<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	typedef pair<double, int> p;
	p a[9], b[9], c[9], d[20];
	for (int i = 0; i < 8; i++)cin >> a[i].second >> a[i].first;
	for (int i = 0; i < 8; i++)cin >> b[i].second >> b[i].first;
	for (int i = 0; i < 8; i++)cin >> c[i].second >> c[i].first;
	sort(a, a + 8); sort(b, b + 8); sort(c, c + 8);
	int k = 0;
	for (int i = 2; i < 4; i++) {
		d[k] = a[i]; k++;
		d[k] = b[i]; k++;
		d[k] = c[i]; k++;
	}
	sort(d, d + 6);
	cout << a[0].second << ' ' << a[0].first << endl;
	cout << a[1].second << ' ' << a[1].first << endl;
	cout << b[0].second << ' ' << b[0].first << endl;
	cout << b[1].second << ' ' << b[1].first << endl;
	cout << c[0].second << ' ' << c[0].first << endl;
	cout << c[1].second << ' ' << c[1].first << endl;
	cout << d[0].second << ' ' << d[0].first << endl;
	cout << d[1].second << ' ' << d[1].first << endl;
	char ch; cin >> ch;
}

Measured memory_bytes: 3128
package main

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

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

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

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

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	ans := 0
	c := map[pair]int{}

	for i := 0; i < n; i++ {
		a := int(scanFloat64()*1e9 + 0.5)

		c2, c5 := 0, 0
		for a%2 == 0 && c2 < 18 {
			a /= 2
			c2++
		}
		for a%5 == 0 && c5 < 18 {
			a /= 5
			c5++
		}
		for p, e := range c {
			if p.a+c2 >= 18 && p.b+c5 >= 18 {
				ans += e
			}
		}

		c[pair{c2, c5}]++
	}
	fmt.Fprintln(wr, ans)

}

type pair struct{ a, b int }


Measured memory_bytes: 5096
#include <stdio.h>

int A[500001];
int H;

void maxHeapify(int i){
  int l=2*i;
  int r=2*i+1;
  int temp,largest;

  if(l<=H && A[l]>A[i]){
    largest=l;
  }else{
    largest=i;
  }
  if(r<=H && A[r]>A[largest]){
    largest=r;
  }

  if(largest!=i){
    temp=A[i];
    A[i]=A[largest];
    A[largest]=temp;
    maxHeapify(largest);
  }
}

int main(){
  int i;

  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  for(i=H/2;i>=1;i--){
    maxHeapify(i);
  }

  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 3668
#include <stdio.h>

int main()
{
  int k, n, ans = 0;
  int tmp = 0;
  int a[1000000];
  int i;
  scanf("%d%d", &k, &n);
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  tmp = a[0] + k - a[n - 1];
  for(i = 0; i < n - 1; i++){
    if(a[i + 1] - a[i] > tmp){
      ans += tmp;
      tmp = a[i + 1] - a[i];
    }else{
      ans += a[i + 1] - a[i];
    }
  }
  if(a[n - 1] - a[n - 2] > tmp){
    ans = k - (a[n - 1] - a[n - 2]);
  }
  printf("%d\n", ans);
  
  return 0;
}

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

using namespace std;

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

	int N, X;
	cin >> N >> X;

	
	int ans = 0;

	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;
		ans = __gcd(ans, abs(X - x));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;

int main() {
    int n;
    cin >> n;
    vector<ll> v(n+1),sum(n+1,0);
    vector<vector<ll>> dp(n+1,vector<ll>(n+1));
    rep(i,n){
        cin >> v.at(i+1);
        sum[i+1]=sum[i]+v[i+1];
    }
    for (int i=1;i<n;i++){
        for (int j=1;j+i<=n;j++){
            dp[j][j+i]=INF;
            for(int k=j;k<j+i;k++){
                dp[j][j+i]=min(dp[j][j+i],dp[k+1][j+i]+dp[j][k]);
            }
            dp[j][j+i]+=sum[j+i]-sum[j-1];
        }
    }
    cout << dp[1][n] << endl;
}


Measured memory_bytes: 1536
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, q;
  cin >> n >> q;

  priority_queue<T, vT, greater<T>> pque;
  rep(i, n) {
    ll s, t, x;
    cin >> s >> t >> x;
    pque.emplace(x, x - t, x - s);
  }
  set<P> st;
  rep(i, q) {
    ll d;
    cin >> d;
    st.emplace(-d, i);
  }

  vll ans(q, -1);
  while (!st.empty() && !pque.empty()) {
    ll x, lf, rg;
    tie(x, lf, rg) = pque.top();
    pque.pop();
    auto itr = st.upper_bound(P(lf, INF));
    while (itr != st.end()) {
      ll a, id;
      tie(a, id) = *itr;
      if (a <= rg) {
        ans[id] = x;
        st.erase(itr++);
      } else
        break;
    }
  }
  rep(i, q) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 20972
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int map[3][3];
bool st[3][3];

bool check()
{
	for(int i=0;i<3;i++)
		if(st[i][0] && st[i][1] && st[i][2])
			return true;
	for(int i=0;i<3;i++)
		if(st[0][i] && st[1][i] && st[2][i])
			return true;
	if(st[0][0] && st[1][1] && st[2][2])
		return true;
	if(st[0][2] && st[1][1] && st[2][0])
		return true;
	return false;
}

int main()
{
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			cin>>map[i][j];
	int n;
	cin>>n;
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
			{
				if(a == map[i][j])
				{
					st[i][j] = true;
					ans++;
					break;
				}
			}
	}
	if(ans>=3)
	{
		if(check()) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	else
		cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 100005;

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

// hand built gcd function
int gcd (int x, int y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

int main() {

	FAST;

	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	l[0] = 0;
	for (int i = 1; i <= n; i ++) {
		l[i] = gcd(l[i - 1], a[i - 1]);
	}
	r[n + 1] = 0;
	for (int i = n; i >= 1; i --) {
		r[i] = gcd(r[i + 1], a[i + 1]);
	}
	for (int i = 1; i <= n; i ++) {
		m[i] = gcd(l[i], r[i]);
	}
	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		ans = max(ans, m[i]);
	}
	cout << ans << '\n';
	return 0;
}

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

#ifdef _DEBUG
    #include "/home/v-o_o-v/deb.h"
    #define deb(x...)cerr << "[" << #x << "] = [";_print(x);
#else
    #define deb(x...)
#endif

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
   
    string s, t;
    cin >> s >> t;
    sort(all(s));
    sort(rall(t));
    if(s < t)puts("Yes");
    else puts("No");
    return 0;
}
// Write Here


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define mod (1e9 + 7)
#define pb push_back
#define int long long 
using namespace std;
typedef pair<int,int> pii;

signed main(){
  long long  n,m;

  cin>>n>>m;

  long long res;
  res=n%2==1?n++:0;
  res^=m%2==0?m--:0;
  res^=((m-n+1)/2)%2==1?1:0;
  cout<<res<<endl;
  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
char c[300002];
int n;
int a[300002],b[300002];
int ans=300000;
int main(){
	scanf("%d%s",&n,c+1);
	for(int i=1;i<=n;i++){
		if(c[i]=='W') a[i]=b[i]=0;
		else a[i]=b[i]=1;
		a[i]+=a[i-1]; 
	}
	for(int i=n;i>=1;i--) b[i]+=b[i+1];
	for(int i=1;i<=n;i++){
		int el=a[i-1],wr=n-i-b[i+1];
		if(n-el-wr-1<ans) ans=n-el-wr-1;
		//printf("%d %d\n",el,wr);
	}
	printf("%d",ans);
	return 0;
} 

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

using namespace std;

#define ll long long

bool isprime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i*i<=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
long long lcm(long long a,long long b)
{
    long long p,r;
    p = a*b;
    r = __gcd(a, b);
    return p/r;
}
void solve()
{
   string s;
   int c=0;
   cin>>s;
   for(int i=1;i<s.length();i++)
   {
       if(s[i]==s[i-1])
       {
           c++;
           break;
       }
   }
   if(!c)
    cout<<"Good"<<endl;
   else
    cout<<"Bad"<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3676
local n=io.read("*n")
local a={}
a[1],a[n+2]=0,0
for i=2,n+1 do
    a[i]=io.read("*n")
end

local total=0
for i=1,n+1 do
    total=total+math.abs(a[i]-a[i+1])
end

for i=2,n+1 do
    local x=math.abs(a[i-1]-a[i+1])
    local y=math.abs(a[i-1]-a[i])
    local z=math.abs(a[i]-a[i+1])
    print(total+x-y-z)
end

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
vector<int> selectionSort(vector<int> v){
  int mi,n = 1;
  bool flag;
  for(int i = 0;i < v.size();i++){
    mi = i;
    flag = false;
    for(int j = i + 1;j < v.size();j++){
      if(v[mi] > v[j]){
        mi = j;
        flag = true;
      }
    }
    if(flag){
      swap(v[i],v[mi]);
      ans++;
    }
  }
  return v;
}

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i = 0;i < N;i++)cin >> v[i];
  v = selectionSort(v);
  for(int i = 0;i < v.size();i++){
    if(i != v.size() - 1)cout << v[i] << " ";
    else cout << v[i] << endl;
  }
  cout << ans << endl;
}


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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int H, W, D;
  cin >> H >> W >> D;
  vector<pair<int, int>> A(H * W + 1);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int tmp;
      cin >> tmp;
      A[tmp] = make_pair(i, j);
    }
  }
  vector<long> v(H * W + 1);
  for (int i = 1; i < H * W + 1; i++) {
    if (v[i] || i - D <= 0)
      continue;
    for (int j = 0; j < H * W + 1 - i; j += D) {
      v[i + j] = abs(A[i + j].first - A[i + j - D].first) +
                 abs(A[i + j].second - A[i + j - D].second);
    }
  }
  for (int i = 1; i < H * W + 1 - D; i++) {
    v[i + D] += v[i];
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int R, L;
    cin >> R >> L;
    cout << v[L] - v[R] << endl;
  }
}

Measured memory_bytes: 2560
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

long long gcd(int a, int b){
  if (a%b == 0){
    return(b);
  }
  else{
    return(gcd(b, a%b));
  }
}

int main(){    
  string S;
  cin >> S;
  int U = S.length();
  
  if('2'==S[U-1] || '4'==S[U-1] || '5'== S[U-1] || '7'== S[U-1] || '9'==S[U-1]){
    cout << "hon" << endl;
  }
  if('0'==S[U-1] || '1'==S[U-1] || '6'== S[U-1] || '8'== S[U-1]){
    cout << "pon" << endl;
  }
  if('3'==S[U-1]){
    cout << "bon" << endl;
  }
  

}
 


Measured memory_bytes: 3632
N, M = map(int, input().split())
E = []
for _ in range(M):
  a, b, c = map(int, input().split())
  E.append((a-1, b-1, -c))

INF = 10**20
V = [INF]*N
V[0] = 0
for _ in range(N):
  for a, b, c in E:
    d = V[a]+c
    if d < V[b]: V[b] = d

R = [False]*N
R[-1] = True
for _ in range(N):
  for a, b, c in E:
    R[a] |= R[b]

for a, b, c in E:
  if V[a]+c<V[b] and R[b]:
    print('inf')
    exit()
    
print(-V[-1])

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
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 digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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; }

int main(){
    ll A, B, C;
    cin >> A >> B >> C;
    if (A+B >= C) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

me = ""

ans = 0

for i in range(n):
    if t[i] == "r":
        if i < k:
            me += "p"
            ans += p
        elif me[i-k] != "p":
            me += "p"
            ans += p
        else:
            if t[i-k] == "p":
                me += "p"
                ans += p
            else:
                me += "r"

    elif t[i] == "s":
        if i < k:
            me += "r"
            ans += r
        elif me[i-k] != "r":
            me += "r"
            ans += r
        else:
            if t[i-k] == "r":
                me += "r"
                ans += r
            else:
                me += "s"

    else:
        if i < k:
            me += "s"
            ans += s
        elif me[i-k] != "s":
            me += "s"
            ans += s
        else:
            if t[i-k] == "s":
                me += "s"
                ans += s
            else:
                me += "p"

print(ans)

Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n >> k;
    vl A, ANS;
    rep(i, n) {
        cin >> x;
        A.push_back(x);
    }
    deque<ll> DQ;

    a = INF;
    rep(i, k) {
        while (!(DQ.empty() || DQ.back() <= A[i])) DQ.pop_back();
        DQ.push_back(A[i]);
    }
    ANS.push_back(DQ.front());

    rep(i, n - k) {
        if (DQ.front() == A[i]) DQ.pop_front();
        while (!(DQ.empty() || DQ.back() <= A[i + k])) DQ.pop_back();
        DQ.push_back(A[i + k]);
        ANS.push_back(DQ.front());
    }

    rep(i, n - k + 1) {
        cout << ANS[i];
        if (i != n - k) cout << " ";
        else cout<<endl;
    }
}



Measured memory_bytes: 25852
MOD = 10**9 + 7 

N = gets.to_i
S = gets.chomp

h = Hash.new(0)

S.chars{ |c|  h[c] += 1 }

ans = 1
h.each do |k, v|
  ans *= (v+1) 
  ans %= MOD
end

p ans-=1

Measured memory_bytes: 1916
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum_a = [0]
sum_b = [0]
for i in range(n):
    sum_a.append(a[i]+sum_a[i])
for i in range(m):
    sum_b.append(b[i]+sum_b[i])
ans = 0
j = m
for i in range(n+1):
    if sum_a[i] > k:
        break
    while sum_b[j] > k - sum_a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)


Measured memory_bytes: 47556
using System;
using System.Linq;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var (n, m, c, xs) = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            var bseq = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var ans = 0;

            for (var i = 0; i < n; ++i) {
                var aseq = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

                var correct = bseq.Zip(aseq, (b, a) => b * a).Sum() + c;
                if (correct > 0) ++ans;
            }
            Console.WriteLine(ans);
        }
    }

    public static class ArrayDeconstruct {
        public static void Deconstruct<T>(this T[] source, out T d1, out T d2, out T d3, out T[] rest) {
            const int maxLen = 3;
            var len = source.Length;

            d1 = default;
            d2 = default;
            d3 = default;

            if (len > 0) d1 = source[0];
            if (len > 1) d2 = source[1];
            if (len > 2) d3 = source[2];

            rest = source.Skip(maxLen).ToArray();
        }
    }
}


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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int D=365,A=26,K=20;

int d;
int c[A],s[D][A],last[A];

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

    cin>>d;
    for(int j=0;j<A;j++)
        cin>>c[j],
        last[j]=-1;
    for(int i=0;i<d;i++)
        for(int j=0;j<A;j++)
            cin>>s[i][j];
    for(int i=0;i<d;i++)
    {
        int best=0;
        for(int j=0;j<A;j++)
            if(s[i][j]+c[j]*(i-last[j])*min(K,d-i)>
               s[i][best]+c[best]*(i-last[best])*min(K,d-i))
                best=j;
        last[best]=i;
        cout<<best+1<<"\n";
    }
}


Measured memory_bytes: 3708
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String A = scan.next();
		String B = scan.next();
		String C = scan.next();

		char[] X = A.toCharArray();
		char[] Y = B.toCharArray();
		char[] Z = C.toCharArray();
		
		if(X[X.length-1]==Y[0]) {
			if(Y[Y.length-1]==Z[0]){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}else {
			System.out.println("NO");
		}
		
	}

}


Measured memory_bytes: 21844
#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,c,n;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&n);
	if (a<b) swap(a,b);
	if (b<c) swap(b,c);
	if (a<b) swap(a,b);
	printf("%d\n",a*(1<<n)+b+c);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

/*
 * ref. [Union-Find](https://www.slideshare.net/chokudai/union-find-49066733)
 * ref. [AtCoder ABC 157 - AtCoder Live](https://www.youtube.com/watch?v=TdR816rqc3s)
 */
class UnionFind {
    public:
        UnionFind(int n = 0): d(n, -1) {}

        // 0-index, [0, n) in other words
        // Time complexity: O(a(n)) (a = inverse Achkermann function)
        int find(int x) {
            if (d[x] < 0) return x;
            return d[x] = find(d[x]);
        }

        // Return false if x and y are alreday in the same group, otherwise return true.
        // 0-index, [0, n) in other words
        // Time complexity: O(a(n)) (a = inverse Achkermann function)
        bool unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) swap(x, y);
            d[x] += d[y];
            d[y] = x;
            return true;
        }

        // 0-index, [0, n) in other words
        // Time complexity: O(a(n)) (a = inverse Achkermann function)
        bool same(int x, int y) {
            return find(x) == find(y);
        }

        // 0-index, [0, n) in other words
        // Time complexity: O(1)
        int size(int x) {
            return -d[find(x)];
        }

    private:
        vector<int> d;
};


vector<pair<int, int>> roads;
vector<pair<int, int>> trains;

int main(void) {
    int N, K, L;
    cin >> N >> K >> L;

    UnionFind uf_for_roads(N);

    roads.resize(K);
    for (int i = 0; i < K; i++) {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        roads[i] = {p, q};
        uf_for_roads.unite(p, q);
    }

    UnionFind uf_for_trains(N);

    trains.resize(L);
    for (int i = 0; i < L; i++) {
        int r, s;
        cin >> r >> s;
        r--;
        s--;
        trains[i] = {r, s};
        uf_for_trains.unite(r, s);
    }

    map<pair<int, int>, int> acc;
    for (int i = 0; i < N; i++) {
        int x = uf_for_roads.find(i);
        int y = uf_for_trains.find(i);
        pair<int, int> p = {x, y};
        acc[p]++;
    }
    for (int i = 0; i < N; i++) {
        int x = uf_for_roads.find(i);
        int y = uf_for_trains.find(i);
        pair<int, int> p = {x, y};
        cout << acc[p] << endl;
    }

    return 0;
}


Measured memory_bytes: 15104
#include <iostream>
#include <vector>

int h;
int key[500010];


void MaxHeap(int i){
  int l = i*2;
  int r = i*2+1;
  int largest = l;
  if(l <= h && key[l] > key[i]){ largest = l; }
  else { largest = i; }
  if(r <= h && key[r] > key[largest]){ largest = r; }
  if(largest != i){
    std::swap(key[i], key[largest]);
    MaxHeap(largest);
  }
}

void buildMaxHeap(){
  for(int i=h/2; i>=1; i--){ MaxHeap(i); }
}

int main(){
  std::cin >> h;
  for(int i=1; i<h+1; i++){ std::cin >> key[i]; }

  buildMaxHeap();

  for(int i=1;i<h+1; i++){
    if( i!=h+1 ){ std::cout << " "; }
    std::cout << key[i];
  }
  std::cout << std::endl;
  return 0;
}



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

#define ll long long
#define ull unsigned long long
#define LL long long
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define sch(n) scanf(" %c", &n)
#define ss(n) scanf("%s", n)
#define pii pair <int, int>
#define pll pair <ll, ll>
#define plp pair <int, pll >
#define pb push_back
#define fr first
#define sc second
#define all(a)  a.begin(),a.end()
#define Unique(a)  sort(all(a)),a.erase(unique(all(a)),a.end())

#define inf (1LL<<50)
#define eps 1e-9

ll Set(ll n, ll pos)
{
    return n|(1LL<<pos);
}

bool Check(ll n, ll pos)
{
    return (bool) (n&(1LL<<pos));
}

ll dp[1050][1050];

char grid[1050][1050];

#define mod 1000000007

bool valid(ll i, ll j)
{
    if (i < 1)
        return false;
    if (j < 1)
        return false;
    if (grid[i][j] == '#')
        return false;
    return true;
}

int main ()
{
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    //  ios_base::sync_with_stdio(0); // no printf/scanf must be present
    ll cs, ts, i, j, k, x, y, z, q, m, n, cap;

    while(sl(n) != EOF)
    {
        sl(m);

        for (i = 1; i <= n; i++)
            ss(grid[i]+1);

        for (i = 1; i <= n; i++)
        for (j = 1; j <= m; j++)
        {
            if (i == 1 && j == 1)
            {
                dp[i][j] = 1;
                continue;
            }

            dp[i][j] = 0;
            if (valid(i-1,j))
                dp[i][j] = (dp[i][j]+dp[i-1][j])%mod;
            if (valid(i,j-1))
                dp[i][j] = (dp[i][j]+dp[i][j-1])%mod;

          //  cout << i << " " << j << " " << dp[i][j] << endl;
        }

        printf("%lld\n", dp[n][m]);
    }
    return 0;
}


Measured memory_bytes: 9472
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

const int MAX = 15001000;
bool IsPrime[MAX];
int MinFactor[MAX];
vector<int> preprocess(int n = MAX) {
    vector<int> res;
    for (int i = 0; i < n; ++i) IsPrime[i] = true, MinFactor[i] = -1;
    IsPrime[0] = false; IsPrime[1] = false; 
    MinFactor[0] = 0; MinFactor[1] = 1;
    for (int i = 2; i < n; ++i) {
        if (IsPrime[i]) {
            MinFactor[i] = i;
            res.push_back(i);
            for (int j = i*2; j < n; j += i) {
                IsPrime[j] = false;
                if (MinFactor[j] == -1) MinFactor[j] = i;
            }
        }
    }
    return res;
}

vector<pair<int,int> > prime_factor(int n) {
    vector<pair<int,int> > res;
    while (n != 1) {
        int prime = MinFactor[n];
        int exp = 0;
        while (MinFactor[n] == prime) {
            ++exp;
            n /= prime;
        }
        res.push_back(make_pair(prime, exp));
    }
    return res;
}


int main(int argc, char const *argv[]) {
    ll n; cin>>n;
    preprocess();

    ll ans = 0;
    for (ll i = 1; i <= n; ++i) {
        auto pf = prime_factor(i);
        ll tmp = 1;
        //cout << "i = " << i << '\n';
        for (auto &&e: pf) {
            tmp *= (e.second+1);
          //  cout << e.first << ' ' << e.second << '\n';
        }
        ans += tmp*i;
    }
    cout << ans << '\n';
    return 0;
}

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

#define N 101

int top,S[N];

int pop(){

  if(top == 0){
    fprintf(stderr,"アンダーフロー\n");
    exit(2);
  }

  return S[top--];

}

void push(int x){

  if(top == 100){
    fprintf(stderr,"オーバーフロー\n");
    exit(1);
  }

  S[++top] = x;

}


int main(){

  int n,a,b,status;

  char A[1000000];

  S[top] = NULL;

  while((status = scanf("%s",&A)) != EOF){
    
    if(A[0] == 42 || A[0] == 43 || A[0] == 45){
      
      switch(A[0]){
	
      case 42:
	b = pop();
	a = pop();
	push(a * b);
	break;

      case 43:
	b = pop();
	a = pop();
	push(a + b);
	break;

      case 45:
	b = pop();
	a = pop();
	push(a - b);
	break;
	
      }
      
    }
    
    else{
      push(atoi(A));
    }
    
  }

  printf("%d\n",S[top]);

  return 0;
}





Measured memory_bytes: 2076
#include <iostream>
#include <algorithm>
#define MAX 10
#define INF 9999999

using namespace std;

int v[MAX + 1];
int road[MAX + 1][MAX + 1];
bool visit[MAX + 1];
int n,mn,MN,Max;

int gettotalDistance(int now){ // ダイクストラ法

  fill( v , v + MAX + 1 , INF );
  fill( visit , visit + MAX + 1 , false );

  v[now] = 0;
  
  while(1){
    
    MN = INF;
    for( int i = 0 ; i <= Max ; i++ ){
      if( !visit[i] && v[i] < MN ){
	MN = v[i];
	mn = i;
      }
    }
    
    if( MN == INF ) break;
    visit[mn] = true;
    
    for( int i = 0 ; i <= Max ; i++ ){
      int t = road[mn][i] + v[mn];
      v[i] = min( v[i] , t );
    }
    
  }
  
  int total = 0;
  for( int i = 0 ; i <= Max ; i++ ) 
    total += v[i];
  
  return total;
}

int main(void){

  while( cin >> n , n ){

    for( int i = 0 ; i <= MAX ; i++ )
      for( int j = 0 ; j <= MAX ; j++ )
	road[i][j] = INF;

    int a,b,c; 
    Max = 0;
    for( int i = 0 ; i < n ; i++ ){
      cin >> a >> b >> c;
      road[a][b] = c;
      road[b][a] = c;
      Max = max( Max , max(a,b) );
    } 
    
    int ans = INF;
    int ansnum;
    for( int i = 0 ; i < Max ; i++ ){
      int ANS = gettotalDistance(i);
      if( ans > ANS ){
	ans = ANS;
	ansnum = i;
      }
    }
    cout << ansnum << " " << ans << endl;
    }
  return 0;
}

Measured memory_bytes: 1160
N = int(input())
abc = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

def dfs(s, count):
    if len(s) == N:
        print(s)
        return
    for i in range(count + 1):
        dfs(s+abc[i], count+1 if i == count else count)

dfs('', 0)

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

ll mod = 998244353;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}

vector<ll> fact;
vector<ll> invfact;

void set_fact(int n){
    fact.resize(n+1, 1);
    invfact.resize(n+1, 1);
    for (int i = 2; i <= n; i++) {
        fact[i] = fact[i-1] * i % mod;
    }
    invfact[n] = modinv(fact[n]);
    for (int i = n-1; i >= 2; i--) {
        invfact[i] = invfact[i+1] * (i+1) % mod;
    }
    return;
}

ll comb(int n, int k) {
    if (k > n || k < 0) return 0;
    if (k == n || k == 0) return 1;
    return fact[n] * invfact[n-k] % mod * invfact[k] % mod;
}

int main(){
    ll N;
    string S;
    cin >> S;
    N = S.size();
    vector<ll> blue(N+1, 0), red(N+1, 0);
    for (int i = 1; i <= N; i++) {
        blue[i] = blue[i-1] + (S[i-1] - '0');
        red[i] = 2*i - blue[i];
    }
    
    set_fact(2*N);
    
    vector<vector<ll>> dp(N+1, vector<ll>(N+1, 0));
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= i-1; j++) {
            if (blue[i] >= j+1) dp[i][j+1] = (dp[i][j+1]+dp[i-1][j])%mod;
            if (red[i] >= i-j) dp[i][j] = (dp[i][j] + dp[i-1][j])%mod;
        }
    }
    ll ans = 0;
    for (int i = 0; i <= N; i++) {
        if (i > blue[N] || N-i > red[N]) continue;
        ans = (ans + dp[N][i] * comb(N, blue[N]-i) %mod)%mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 31744
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

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

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)					// repeat
#define repr(i, begin, end) for (ll i = begin - 1; end <= i; i--)		// repeat reverse

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif

class DPB
{
public:
	DPB()
	{
		cin >> n >> k;
		h.resize(n);
		rep(i, 0, n)
			cin >> h[i];
	}
	void Run(void)
	{
		vector<vector<ll>> dp(n, vector<ll>(k, LLONG_MAX));
		dp[0][0] = 0;
		rep(i, 0, n)
		{
			rep(j, 0, k)
			{
				if (0 <= i - j - 1)
					dp[i][j] = dp[i - j - 1][0] + abs(h[i - j - 1] - h[i]);
			}

			sort(all(dp[i]));
		}

		cout << dp[n-1][0];
	}
private:
	ll n;
	ll k;
	vector<ll> h;
};

int main(void)
{
	DPB dpb;
	dpb.Run();

	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll A, B, M;
    cin >> A >> B >> M;
    vector<ll> a_items(A), b_items(B);
    ll min_a = INF;
    ll min_b = INF;
    rep(i, A) {
        ll a;
        cin >> a;
        a_items[i] = a;
        min_a = min(a, min_a);
    }
    rep(i, B) {
        ll b;
        cin >> b;
        b_items[i] = b;
        min_b = min(b, min_b);
    }
    ll ans = min_a + min_b;
    rep(i, M) {
        ll x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        ll tmp = a_items[x] + b_items[y] - c;
        ans = min(ans, tmp);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if(c>=a&&c<=b) 
cout<< "Yes"<<endl;
else 
cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int search(int A[],int n, int key){
    int i=0;
    A[n] = key; //番兵
    while(A[i] != key) i++;
    return i != n;
}

int main(){
    int i,n,A[10000+1],q,key,sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);

    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&key);
        if(search(A,n,key)) sum++;
    }
    printf("%d\n",sum);

    return 0;
}


Measured memory_bytes: 2076
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k, ans;
    cin >> n >> k;
    ans = 0;
    vll a(n+1, 0);//初期化忘れない
    vll flag(n+1, 0);//一度来たかのフラグ。
    FOR(i, 1, n){
        cin >> a[i];
    }

    ll loop = 1;
    while(flag[loop] == 0){//ループ地点を求める=1度来た地点に戻ったらループのスタート地点
        flag[loop] = 1;
        loop = a[loop];
    }

    ll i = 1;
    ll start = 0;
    while(i != loop){//ループ地点までの移動回数
        start++;
        i = a[i];
    }
    
    if(k < start){//ループ地点より前に終わる場合
        ll j = 1;
        while(k > 0){//残り移動回数
            k--;
            j = a[j];
        }
        cout << j <<"\n";
        return 0;
    }

    k -= start;
    ll loopNum = 1;
    i = loop;
    while(a[i] != loop){//ループの移動回数
        loopNum++;
        i = a[i];
    }

    k = k % loopNum;
    i = loop;
    while(k > 0){//残り移動回数
        k--;
        i = a[i];
    }

    ans = i;
    cout << ans <<"\n";
	return 0;
}

Measured memory_bytes: 6364
#include <stdio.h>

int getDirection(char);

int main(){
  int jewel[21][21],x,y;
  int N,M,i,j,distance,can;
  int nx,ny,dir;
  const int dx[4] = {-1,0,1,0};
  const int dy[4] = {0,1,0,-1};
  char direction;
  char in; /* inテ」ツ?ッテ、ツスツ凖・ツ按?」ツ?ェテヲツ板ケティツ。ツ古」ツつ津ィツェツュテ」ツ?ソティツセツシテ」ツつ?ァツ板ィテ」ツ??*/

  while(1){
    nx = ny = 10;
    scanf("%d",&N);
    if(N == 0){ break; }
    for(i = 0 ; i < 21 ; i++){
      for(j = 0 ; j < 21 ; j++){
        jewel[i][j] = -1;
      }
    }
    for(i = 0 ; i < N ; i++){
      scanf("%d%d",&x,&y);
      jewel[y][x] = i;
    }
    scanf("%d%c",&M,&in);
    for(i = 0 ; i < M ; i++){
      scanf("%c%d%c",&direction,&distance,&in);
      dir = getDirection(direction);
      for(j = 0 ; j < distance ; j++){
        nx += dx[dir];
        ny += dy[dir];
        if(jewel[ny][nx] != -1){
          jewel[ny][nx] = -1;
        }
      }
    }
    can = 1;
    for(i = 0 ; i < 21 ; i++){
      for(j = 0 ; j < 21 ; j++){
        if(jewel[i][j] != -1){
          can = 0;
        }
      }
    }
    if(can == 1){ printf("Yes\n"); }
    else{ printf("No\n"); }
  }
  return 0;
}

int getDirection(char ch){
  if(ch == 'W'){ return 0; }
  if(ch == 'N'){ return 1; }
  if(ch == 'E'){ return 2; }
  if(ch == 'S'){ return 3; }
}

Measured memory_bytes: 584
s = input()

flag = s == s[::-1]
n = len(s)
cond2 = s[:(n-1)//2]
flag &= cond2 == cond2[::-1]
cond3 = s[(n+3)//2-1:]
flag &= cond3 == cond3[::-1]

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
def check(S):
  for i in range(len(S)//2):
    if S[i] != S[-(i+1)]:
      print("No")
      exit(0)
  
S = input()
for i in range((len(S)-1)//2):
  if S[i] != S[-(i+1)]:
    print("No")
    exit(0)
    
check(S[:(len(S)-1)//2])
check(S[len(S)+3//2:])
print("Yes")

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <vector>

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

  std::vector<int> a(n);
  for (int i=0; i<n; ++i)
    scanf("%d", &a[i]);

  std::sort(a.begin(), a.end());

  if (n == 2)
    return !printf("%d %d\n", a[1], a[0]);

  int N=a.back();
  int j=std::lower_bound(a.begin(), a.end()-1, N/2)-a.begin();

  if (a[j] == N/2)
    return !printf("%d %d\n", N, a[j]);

  // if (j > 0)
  //   fprintf(stderr, "%d (%d) %d\n", a[j]-N/2, N/2, N/2-a[j-1]);

  if ((j > 0 && a[j]-(N+1)/2 > N/2-a[j-1]) || j == n-1)
    --j;

  printf("%d %d\n", N, a[j]);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
 
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////

void solve(){
  ini(H,W);
  vector<string> A(H),B(H);
  in(A); in(B);
  int cnt = 0;
  rep(i,H) rep(j,W) cnt += A[i][j] != B[i][j];
  out(cnt);
}


Measured memory_bytes: 11392
/**
 * @Author:      G_bg
 * @DateTime:    2019-08-10 20:09:37
 * @Description: 
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int mod = 1e9+7;
const int maxn = 1e5+10;
map<string,int> mp;
int main(int argc, const char *argv[]) {
    ios::sync_with_stdio(0);cin.tie(0);
    int n;cin >> n;
    for(int i = 0;i < n;i++){
        string str;cin >> str;
        sort(str.begin(),str.end());
        mp[str]++;
    }
    LL sum = 0;
    for(auto i = mp.begin(),j = mp.end();i != j;++i){
        sum += (i->second)*1LL*(i->second-1)/2;
    }
    cout << sum << endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 11264