akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    int n,m,c;
    cin>>n>>m>>c;
    int b[m];
    for(int i=0;i<m;i++)cin>>b[i];
    int count=0;
    while(n--){
        int sum=0;
        for(int i=0;i<m;i++){
            int x;
            cin>>x;
            sum+=x*b[i];
        }
        if(sum+c>0)count++;
    }
    cout<<count;
}


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

public class Main {
    public static void main(String[] args){
    	try {
	    	InputStreamReader isr = new InputStreamReader(System.in);
	    	BufferedReader br = new BufferedReader(isr);
	    	String x = br.readLine();
	    	int x_int = Integer.parseInt(x);
	    	int ans = 0;
	    	if(x_int >= 1 || x_int <= 100) {
	    		ans = x_int * x_int * x_int;
	    	}
	    	System.out.println(ans);

    	} catch (IOException e) {
    		System.out.println(e);
		}

    }
}



Measured memory_bytes: 24092
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  int cnt = 0;
  rep(i,sz(s)) {
    if(s[i] == '+') {
      cnt++;
    } else {
      cnt--;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
 
int N;
vector<pair<int, int> > v1, v2;
int calc(int k1, int k2){
    if(k1 < 0 || k2 < 0)
      return INT_MAX;
    return ceil(N*1.0/2*1.0) - v1[k1].second + N/2 - v2[k2].second;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  vector<int> v(N);
  for(int i=0; i<N; ++i) cin >> v[i];
  map<int, int> mp1, mp2;
  for(int i=0; i<N; i+=2){
    ++mp1[v[i]];
  }
  for(int i=1; i<N; i+=2){
    ++mp2[v[i]];
  }
  auto it = mp1.begin();
  while(it != mp1.end()){
    v1.push_back(make_pair(it->first, it->second));
    ++it;
  }
  it = mp2.begin();
  while(it != mp2.end()){
    v2.push_back(make_pair(it->first, it->second));
    ++it;
  }
  sort(all(v1), [&](const pair<int, int> &a, const pair<int, int > &b){
       return a.second > b.second;
      });
  sort(all(v2), [&](const pair<int, int> &a, const pair<int, int> &b){
       return a.second > b.second;
      });
  int k1 = 0, k2 = 0, res = 0, flag = 0;
  if(v1[k1].first == v2[k2].first){
    flag = 1;
    int p = k2;
    while(k2 < (int)v2.size() && (v1[k1].first == v2[k2].first))  ++k2;
    res = calc(k1, k2);
    while(k1 < (int)v1.size() && (v1[k1].first == v2[p].first)) ++k1;
    res = min(res, calc(k1, p));
  }
  if(!flag) res = calc(k1, k2);
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 6524
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int numOfGame = stdIn.nextInt();

        int taroScore = 0;
        int hanakoScore = 0;
        for(int i = 0; i < numOfGame; i++) {
            String taroHand = stdIn.next();
            String hanakoHand = stdIn.next();
            
            int result = taroHand.compareTo(hanakoHand);
            if(result > 0) {
                // taro win
                taroScore += 3;
            } else if(result < 0) {
                // hanako win
                hanakoScore += 3;
            } else {
                // draw
                taroScore++;
                hanakoScore++;
            }
        }
        System.out.println(taroScore + " " + hanakoScore);
    }
}

Measured memory_bytes: 29240
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main()
{
    string s;
    cin >> s;

    for(int i = 1; i < s.size(); i++){
        string t(s.begin(), s.end() -i);
        if(t.substr(0,t.size()/2) == t.substr(t.size()/2)){
            cout << t.size() << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

constexpr ll N = 1e2, W = 1e9, V = 1e3;
constexpr ll MW = N*W + 1;
ll dp[N+1][N*V + 1];

int main(){
  ll n, w; cin >> n >> w;
  ll ww[n], v[n];
  REP(i, n) cin >> ww[i] >> v[i];

  REP(i, N+1)REP(j, N*V + 1) dp[i][j] = MW;
  dp[0][0] = 0;

  REP(i, n)REP(j, N*V + 1){
    if(dp[i][j] == MW) continue;

    dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    if(dp[i][j] + ww[i] <= w)
      dp[i+1][j+v[i]] = min(dp[i+1][j+v[i]], dp[i][j] + ww[i]);
  }
  
  ll ans = 0;
  REP(i, N*V + 1){
    if(dp[n][i] != MW) ans = i;
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
#include <string>
#include <vector>
using namespace std::chrono;
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define ll long long

bool isPowerOfTwo (ll x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}  

bool SameSign(ll x, ll y)
{
    return (x >= 0) ^ (y < 0);
}

ll gcd(ll u, ll v )
{
    ll shift;
    if (u == 0) return v;
    if (v == 0) return u;
    shift = __builtin_ctz(u | v);
    u >>= __builtin_ctz(u);
    do {
        v >>= __builtin_ctz(v);
        if (u > v) {
            ll t = v;
            v = u;
            u = t;
        }  
        v = v - u;
    } while (v != 0);
    return u << shift;
}

ll lcm(ll u,ll v){
    return u*v/gcd(u,v);
}

int isPower(int A) {
    int i=2;
    int n;
    
    if(A==1){return true;}
        else{
            while(1){
                n=A;
                int count=0;
                while(n%i==0){
                    n=n/i;
                    count++;
                }
                if(n==1 && count>1){return true;}else if(n==1 && count<=1)return false;
                i++;
            }
        return false;
    }}
#define PI 3.14159265358979323846

//30 10 60 10 60 50
//dp[6]=dp[5]+10;
//dp[5]=dp[3]+0;
//dp[3]=dp[1]+30;
//dp[1]=0;

int dp[100050]={0};

int  main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,0,n)cin>>a[i];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    rep(i,2,n){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int m1 = 1;
    int m2 = n;
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        m1 = max(m1, l);
        m2 = min(m2, r);
    }
    int a = m2-m1+1;
    if(a < 0){
        a = 0;
    }
    cout << a << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#include <math.h>
#include <stdio.h>
#include <time.h>
#define mp make_pair
typedef long long ll;
using namespace std;
const int INF=20050226;
int num[INF];
int cnt[INF];
bool use[INF]={true};
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>num[i];
		cnt[num[i]%INF]++;
		use[num[i]%INF]=false;
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(use[num[i]%INF]==false)
		{
			use[num[i]%INF]=true;
			if(num[i]>cnt[num[i]%INF])
			{
				ans+=cnt[num[i]%INF];
			}
			else
			{
				ans+=cnt[num[i]%INF]-num[i];
			}
		}
	}
	cout<<ans;
	return 0;
}


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

const long long INF = 1e16;

long long go(int i, int v, vector<int>& weights, vector<int>& values, vector<vector<long long>>& dp) {
    if (v < 0) return INF;
    if (v == 0) return 0;
    if (i == weights.size()) return INF;
    long long& ans = dp[i][v];
    if (ans != -1) return ans;
    return ans = min(go(i + 1, v, weights, values, dp), weights[i] + go(i + 1, v - values[i], weights, values, dp));
}

void solve(int test) {
    int n, w;
    cin >> n >> w;
    vector<int> weights(n), values(n);
    for (int i = 0; i < n; i++) {
        cin >> weights[i] >> values[i];
    }
    long long sum_value = accumulate(values.begin(), values.end(), 0LL);
    vector<vector<long long>> dp(n, vector<long long>(sum_value + 1, -1));
    // dp[i][v] -> min. weight of items to achieve value exactly v using any subset of items [i...n-1]
    // dp[0][v] -> min. weight of items to achieve value exactly v using any subset of items [0...n-1]
    for (long long v = sum_value; v >= 0; v--) {
        go(0, v, weights, values, dp);
    }
    long long ans = 0;
    for (long long v = sum_value; v >= 0; v--) {
        if (dp[0][v] <= w) {
            ans = v;
            break;
        }
    }
    cout << ans << "\n";
}

int main(){
#ifdef VPAL
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    for (int test = 1; test <= t; test++) {
        solve(test);
    }
    return 0;
}

Measured memory_bytes: 79488
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long llong;
const llong mod = 1e9 + 7;
const int maxn = 300000 + 5;
llong c1[maxn];
llong c2[maxn];
llong inv[maxn];

void Prepare_inv()
{
    inv[1] = 1; //1 µÄÄæÔªÊÇ1
    for (llong i = 2; i < maxn; i++)
        {
            inv[i] = (mod - mod / i) * inv[mod % i] % mod;
            //printf("inv[%lld]=%lld\n", i, inv[i]);
        }
}

void C1(llong n, llong r)
{
    c1[r] = 1;
    for (llong i = r + 1; i <= n; i++)
        {
            c1[i] = c1[i - 1] * i % mod * inv[i - r] % mod;
            //printf("c1[%lld][%lld]=%lld\n", i, r, c1[i]);
        }
}

void C2(llong n, llong r)
{
    c2[r] = 1;
    for (llong i = r + 1; i <= n; i++)
        {
            c2[i] = c2[i - 1] * i % mod * inv[i - r] % mod;
            //printf("c2[%lld][%lld]=%lld\n", i, r, c2[i]);
        }
}

int main()
{
    Prepare_inv();

    llong h, w, a, b;
    while (scanf("%lld %lld %lld %lld", &h, &w, &a, &b) != EOF)
    {
        if (h <= a || w <= b)
        {
            puts("0");
            continue;
        }

        C1(h - a + b - 2, b - 1);
        C2(w - b + h - 2, w - b - 1);

        llong ans = 0;
        llong right = 0;
        llong left = 0;
        for (llong i = h - a + b - 2; i >= b - 1; i--)
        {
            left = c1[i];
            right = c2[h + w - 3 - i];
            ans = (ans + left * right % mod) % mod;
            //printf("i=%lld j=%lld %lld %lld %lld\n", i, h+w-3-i, left, right, ans);
        }

        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 6400
#include<cstdio>
#include<vector>
#include<iostream>
#include<cstdio>
using namespace std;
const int big=(1<<30);
int gcd(int a,int b){if(a<b){swap(a,b);}if(b==0){return a;}return gcd(a%b,b);}
int main(void){
	int n,ans=big,i,q,gen,j;
	vector<int> a;
	cin>>n;
	for(i=0;i<n;i++){
		scanf("%d",&q);
		a.push_back(q);
	}
	for(i=-100;i<101;i++){
		gen=0;
		for(j=0;j<n;j++){
			gen+=(a[j]-i)*(a[j]-i);
		}
		ans=min(ans,gen);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i,j,n,flag=0,d;
    char a[1000]={0};
  
    scanf("%d%*c",&n);
    for(j=0;j<n;j++){
        flag=0;
        for(i=0;;i++){
            scanf("%c", &a[i]);
            if(a[i]=='\n'){
                a[i]='\0';
                d=i;
                break;
            }
        }
 
        for(i=0;;i++){
      if(d<7) break;
      if(a[i+6]=='\0') break;
      if(a[i]=='H'){
    if(a[i+1]=='o'){
      if(a[i+2]=='s'){
        if(a[i+3]=='h'){
          if(a[i+4]=='i'){
        if(a[i+5]=='n'){
          if(a[i+6]=='o'){
            a[i+6]='a';
          }
        }
          }
        }
      }
    }}}
        //for(i=0;i<d;i++)
printf("%s\n",a);//puts("");
        //for(i=0;i<1000;i++)a[i]=0;
    }
    return 0;
}

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

n = 1
ans = 10**5

def calucurate(M):
    n = 0
    while M > 0:
        n += M%10
        M //= 10
    return n

while n < N:
    t = N - n
    m = calucurate(t) + calucurate(n)
    ans = min(ans,m)
    n += 1

print(ans)

Measured memory_bytes: 9140
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    vector<ll> lsum(n, 0), rsum(n, 0);
    lsum[0] = a[0];
    for(int i = 1; i < n; i++){
        lsum[i] = gcd(lsum[i - 1], a[i]);
        //cout << lsum[i] << endl;
    }
    rsum[n - 1] = a[n - 1];
    for(int i = n - 2; i >= 0; i--){
        rsum[i] = gcd(rsum[i + 1], a[i]);
        //cout << rsum[i] << endl;
    }

    // for(int i = 0; i < n; i++){
    //     cout << lsum[i] << " " << rsum[i] << endl;
    // }

    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(i == 0){
            ans = max(ans, rsum[i + 1]);
        } else if(i == n - 1){
            ans = max(ans, lsum[i - 1]);
        } else {
            ans = max(ans, gcd(lsum[i - 1], rsum[i + 1]));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip>
#include<map>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll t,n,m;
    while (cin >> t>>n>>m)
    {
        
        int flag=0;
        for(int i=n;i<=m;i++)
        {
            if(i%t==0)
            {
                flag=1;
                break;
            }
        }
        if(flag)cout<<"OK\n";
        else cout<<"NG\n";
    }
}

Measured memory_bytes: 3124
import java.util.Scanner


object Main {
  // a: 値段
  // b: 購入上限
  case class Store(a:Long, b:Int)

  def read() = {
    val sc = new Scanner(System.in)
    val N, M = sc.nextInt()
    val stores: IndexedSeq[Store] = for (i <- 0 until N) yield{
      val a,b = sc.nextInt()
      Store(a.toLong,b)
    }
    (N,M,stores)
  }
  def solve(n:Int, m:Int, stores:IndexedSeq[Store]):Long= {
    // ソートする
    val sortedStores = stores.sortBy(store=>store.a)// 値段でソート
    var numDrink = 0
    var sumPrice:Long = 0
    for (store <- sortedStores){
      if(numDrink + store.b >= m){
        val numBuy = m - numDrink
        sumPrice += numBuy * store.a
        return sumPrice
      }
      sumPrice += store.b * store.a
      numDrink += store.b
    }
    sumPrice
  }

  def main(args: Array[String]): Unit = {
    val (n,m,stores) = read()
    println(solve(n,m,stores))
  }
}

Measured memory_bytes: 72324
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()
ans = [0] * n

for i in range(n-1,0,-1):
    ans[a[i - 1] - 1] += 1

for i in range(n):
    print(ans[i])

Measured memory_bytes: 53804
//#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(uniqu7e(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const LL INF = 1e18;
const LL MOD = 1e9 + 7;

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

void END(){cout << "Yes" << endl; exit(0);}

int k = 1;
map<PII, int> ec;

void dfs(VVI& T, int now, int prev, int prev_c)
{
	int color = 1;
	REPx(x, T[now])
	{
		if (x == prev) continue;
		if (color == prev_c) color++;
		chmax(k, color);
		ec[{x, now}] = color;
		ec[{now, x}] = color++;
	}
	REPx(x, T[now])
	{
		if (x == prev) continue;
		int key = ec[{now, x}];
		dfs(T, x, now, key);
	}
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	VVI T(n, VI());
	VPII edge(n-1);
	REP(i, n-1)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		ec[{a, b}] = 0;
		ec[{b, a}] = 0;
		T[a].emplace_back(b);
		T[b].emplace_back(a);
		edge[i] = {a, b};
	}
	dfs(T, 0, -1, 0);
	cout << k << endl;
	REPx(x, edge) cout << ec[{x.first,x.second}] << endl;
		
	return 0;
}


Measured memory_bytes: 20480
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	string S;
	cin>>S;
	rep(i,S.size()-1){
		if(S[i]=='P'&&S[i+1]=='?'){
			S[i+1]='D';
		}
		else if(S[i]=='?'&&S[i+1]=='?'){
			S[i]='P';
			S[i+1]='D';
		}
		else if(S[i]=='?'&&S[i+1]=='D'){
			S[i]='P';
		}
		else if(S[i]=='?'&&S[i+1]=='P'){
			S[i]='D';
		}
	}
	if(S.back()=='?'){
		S.back()='D';
	}
	cout<<S<<endl;
}

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

int main(){
    string s;
    cin>>s;
    string ans="Yes";
    for(int i=0;i<s.size();i++){
        if((i%2==1&&s[i]=='R')
        ||(i%2==0&&s[i]=='L')){
            ans="No";
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 504
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

int main(void){
	int N, K;	cin >> N >> K;
	string s;	cin >> s;
	vector<int> cnts;
	int cnt = 1;
	///	1の個数、0の個数、1の個数、… 、0の個数、1の個数となるように配列cntsを作る
	///	入力sが、0で始まるor0で終わるようなら、最初or最後に1の個数が0として加えておく
	if (s[0] == '0')	{
		cnts.push_back(0);
	}
	rep(i,N)	{
		if (s[i] != s[i+1])	{
			cnts.push_back(cnt);
			cnt = 1;
		}else{
			cnt++;
		}
	}
	while(cnts.size() < 2+2*K)	{
		cnts.push_back(0);
	}
	if (s[s.size()-1] == '0')	{
		cnts.push_back(0);
	}

	///	2K+1個ずつ、'1の個数'から始まるように和を比較する(尺取法)
	int tmp = 0;
	rep(i,2*K+1)	{
		tmp += cnts[i];
	}
	int ans = tmp;
	reps(i,cnts.size()-2*K-2)	{
		i++;
		tmp -= cnts[i-2] + cnts[i-1];
		tmp += cnts[i+2*K-1] + cnts[i+2*K];
		ans = max(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1528
"use strict";

function f(x) {
  if (x % 2 === 0) {
    return x/2;
  } else {
    return x * 3 + 1;
  }
}

function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");

  let s = Number(inputs[0]);
  let set = {}

  let current = s;
  let count = 1;
  while(set[current] !== true) {
    set[current] = true;
    current = f(current);
    count++;
  }

  console.log(count);

}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 22080
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

LL comb(LL n, LL k){
  LL r=1;
  for(LL d=1; d<=k; d++){
    r*=n;
    n--;
    r/=d;
  }
  return r;
}

int main(){
  LL N, A, B;
  cin >> N >> A >> B;
  vector<double> v(N);
  rep(i,N) cin >> v[i];
  sort(v.begin(),v.end(),greater<double>());
  double sum=0;
  rep(i,A) sum+=v[i];
  double ans=sum/A;
  LL num=0, n=0;
  rep(i,N) if(v[i]==v[0]) n++;
  if(n>=A) for(LL k=A; k<=min(n,B); k++) num+=comb(n,k);
  else{
    n=0;
    rep(i,N) if(v[i]==v[A-1]) n++;
    LL k=0;
    rep(i,A) if(v[i]==v[A-1]) k++;
    num+=comb(n,k);
  }
  cout << fixed <<  setprecision(15) << ans << endl;
  cout << num << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}

static void CF2016GF_B_InscribedBicycle();

static void ABC085C_Otoshidama();

#if 1
int main()
{
	ABC085C_Otoshidama();
	fflush(stdout);
	return 0;
}
#endif

static void ABC085C_Otoshidama()
{
	int N, Y;
	get2int(N, Y);

	int yukichi = 10000;
	int ichiyou = 5000;
	int hideyo = 1000;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= (N - i); j++) {
			int sum = (yukichi * i) + (ichiyou * j) + (hideyo * (N - i - j));
			if (sum == Y) {
				printf("%d %d %d\n", i, j, N - i - j);
				return;
			}
		}
	}
	printf("-1 -1 -1\n");
}


Measured memory_bytes: 256
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
x,y = map(int,input().split())
if (x in a and y in a) or (x in b and y in b) or (x in c and y in c) :
    print('Yes')
else :
    print('No')

Measured memory_bytes: 3060
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;
    
    auto arr = readln.chomp.split.map!(to!int).array;
    
    if (arr[0] != 0) {
        writeln(0);
        return;
    }
    
    arr = arr.dropOne.array;
    
    arr.sort();
    
    if (arr[0] == 0) {
        writeln(0);
        return;
    }
    
    immutable int MD = 998244353;
    int ans = 1, prevk = 0, prevv = 1, curk = 1, curv = 0;
    foreach (e; arr) {
        if (e > curk) {
            if (e > curk + 1) {
                writeln(0);
                return;
            }
            
            prevk = curk;
            prevv = curv;
            
            curk = e;
            curv = 0;
        }
        
        ++curv;
        
        debug { [prevk, prevv, curk, curv].map!(to!string).join(" ").writeln; }
        
        ans = (ans.to!long * prevv) % MD;
    }
    
    ans.writeln;
}

Measured memory_bytes: 4476
#include<iostream>
#include<stdio.h>
#include<algorithm>

using namespace std;
using UL = unsigned int;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int main(){
	int H, W; cin >> H >> W;
	int A[25][25]; rep(y, H) rep(x, W) cin >> A[x][y];
	int ans = 1000000000;
	rep(x, W)rep(y, H){
		int tmp = 0;
		rep(xx, W) rep(yy, H){
			tmp += min(abs(xx - x), abs(yy - y)) * A[xx][yy];
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;

	return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename T> struct Sum2 {
	typedef vector<vector<T>> A;
	A s;
	int X, Y;
	
	Sum2() { X = Y = -1; }
	Sum2(A & p) { init(p); }
	void init(A & p) {
		X = p.size();
		Y = p[0].size();
		s = A(X + 1, vector<T>(Y + 1, 0));
		
		inc1(x, X) {
		inc1(y, Y) {
			s[x][y] = p[x - 1][y - 1];
		}
		}
		inc1(x, X) {
		inc1(y, Y) {
			s[x][y] += s[x - 1][y];
		}
		}
		inc1(x, X) {
		inc1(y, Y) {
			s[x][y] += s[x][y - 1];
		}
		}
	}
	T sum(int xl, int xh, int yl, int yh) { // [xl, xh) × [yl, yh)
		assert(inII(xl, 0, X));
		assert(inII(xh, 0, X));
		assert(inII(yl, 0, Y));
		assert(inII(yh, 0, Y));
		assert(xl <= xh);
		assert(yl <= yh);
		return s[xh][yh] - s[xh][yl] - s[xl][yh] + s[xl][yl];
	}
};

int n, k;
vector<vector<int>> p(2000, vector<int>(1000, 0));

int main() {
	cin >> n >> k;
	inc(i, n) {
		int x, y; string c;
		cin >> x >> y >> c;
		if(c == "B") { x += k; }
		int z = (x / k + y / k) % 2 * k;
		x %= k; x += z;
		y %= k;
		p[x][y]++;
	}
	
	Sum2<int> s(p);
	int ans = 0, l = k * 2;
	incII(x, 0, l) {
	incII(y, 0, k) {
		int e = max(0, x - k);
		int f = min(l, x + k);
		int v =
			s.sum(0, e, y, k) +
			s.sum(e, x, 0, y) +
			s.sum(x, f, y, k) +
			s.sum(f, l, 0, y)
		;
		setmax(ans, v);
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main(){
	// sengen
	int k;
	// nyuryoku
	cin >> k;
	queue<long long> que;
	// keisan
	for(int i=1;i<10;i++) que.push(i);
	for(int i=1;i<=k-1;i++){
		long long now = que.front();
		que.pop();
		for(int j = -1;j<=1;j++){
			long long add = now%10 + j;
			if(add >= 0 && add <= 9){
				que.push(now*10 + add);
			}
		}
	}
	// syutsuryoku
	cout << que.front() << endl;
}

Measured memory_bytes: 5080
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


#define all(c) ((c).begin()), ((c).end())
struct edge {
  int src, dst;
  int weight;
};
struct graph {
  int n;
  vector<edge> edges;
  graph(int n = 0) : n(n) { }
  void add_edge(int src, int dst, int weight) {
    n = max(n, max(src, dst)+1);
    edges.push_back({src, dst, weight});
  }
  vector<int> p; 
  int root(int i) { 
    return p[i] < 0 ? i : p[i] = root(p[i]); 
  }
  bool unite(int i, int j) {
    if ((i = root(i)) == (j = root(j))) return false;
    if (p[i] > p[j]) swap(i, j);
    p[i] += p[j]; p[j] = i;
    return true;
  }
  int kruskal() {
    p.assign(n, -1);
    sort(all(edges), [](edge x, edge y) {
        return x.weight < y.weight; 
    });
    int result = 0;
    for (auto e: edges) 
      if (unite(e.src, e.dst)) 
        result += e.weight;
    return result;
  }
};


int main(){
	int n; cin >> n;
	vector<P> xy(n), yx(n);
	for(int i = 0; i < n; ++i){
		int x, y;cin >>x >> y;
		xy[i] = {x, i};
		yx[i] = {y, i};
    }
    sort(xy.begin(), xy.end());
    sort(yx.begin(), yx.end());
    graph g;
    for(int i = 0; i < n-1; ++i){
    	g.add_edge(xy[i].second, xy[i+1].second, xy[i+1].first - xy[i].first );
        g.add_edge(xy[i+1].second, xy[i].second, xy[i+1].first - xy[i].first );
        g.add_edge(yx[i].second, yx[i+1].second, yx[i+1].first - yx[i].first );
        g.add_edge(yx[i+1].second, yx[i].second, yx[i+1].first - yx[i].first );
    }
    
    int ans = g.kruskal();
    cout << ans << endl;
    
    return 0;
}

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

static inline int min(int x, int y) {
  if (x < y) {
    return x;
  } else {
    return y;
  }
}

static inline int max(int x, int y) {
  if (x < y) {
    return y;
  } else {
    return x;
  }
}

int main() {
  int a, b, c, d;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  int x = min(b, d) - max(a, c);
  cout << ((x > 0) ? x : 0);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, w, ans = 0, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> s;
  cin >> t;
  rep(i, 0, s.size())
  {
    if (s[i] != t[i])
    {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

int main(){

	int n = nxt();
	vector<pair<int, int>> x(n);
	int nn = n * n;
	for (int i = 0; i < n; ++i) {
		x[i] = {nxt(), i};
	}
	sort(all(x));

	vector<int> zalupa;
	vector<int> trash;
	for (auto p : x) {
		for (int i = 0; i < p.second; ++i) {
			zalupa.push_back(p.second);
		}
		for (int i = 0; i < n - 1 - p.second; ++i) {
			trash.push_back(p.second);
		}
	}
	reverse(all(trash));

	vector<int> a(nn);
	int index = 0;
	int zi = 0;
	vector<int> last(n);
	for (int i = 0; i < n; ++i) {
		last[i] = i;
	}
	vector<char> used(n);
	for (int i = 0; i < nn; ++i) {
		if (index < n && x[index].first - 1 == i) {
			if (last[x[index].second]) {
				puts("No");
				return 0;
			}
			a[i] = x[index].second + 1;
			used[x[index].second] = 1;
			++index;
		} else {
			if (zi < (int)zalupa.size()) {
				last[zalupa[zi]] -= 1;
				a[i] = zalupa[zi] + 1;
				++zi;
			} else {
				if (!used[trash.back()]) {
					puts("No");
					return 0;
				}
				a[i] = trash.back() + 1;
				trash.pop_back();
			}
		}
	}

	printf("Yes\n");
	for (int i = 0; i < nn; ++i) {
		printf("%d ", a[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 3356
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn add357(lv: &Vec<i32>) -> Vec<i32> {
    return lv
        .iter()
        .flat_map(|&m| vec![m * 10 + 3, m * 10 + 5, m * 10 + 7])
        .collect();
}

fn is357(n: i32) -> bool {
    let mut m = n;
    let mut has3 = false;
    let mut has5 = false;
    let mut has7 = false;
    while m != 0 {
        match m % 10 {
            3 => has3 = true,
            5 => has5 = true,
            7 => has7 = true,
            _ => return false,
        }
        m /= 10;
    }
    return has3 && has5 && has7;
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i32 = read(&mut stdin_lock, &mut buf, b'\n');

    let mut lav = vec![];
    let mut lv = vec![0i32];
    for _ in 0..9 {
        lv = add357(&lv);
        lav.append(&mut lv.clone());
    }

    let ans = lav.iter().filter(|&&i| i <= n && is357(i)).count();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
V e,s;
int N,M;
V mul(const V &a, const V &b){
	V c(N*N);
	int i=0,j;
	for(;i<N;i++)for(j=0;j<N;j++)c[i*N+j]=(a[slice(i*N,N,1)]*b[slice(j,N,N)]).sum()%M;
	return c;
}
V exp(const V &a, const int n){
	if(!n)return e;
	if(n==1)return a;
	if(n%2==1)return mul(exp(a,n-1),a);
	V b=exp(a,n/2);
	return mul(b,b);
}

main(){
	int i,a,b,c,t;
	for(;scanf("%d%d%d%d%d%d",&N,&M,&a,&b,&c,&t),N;){
		s.resize(N);
		e=0;
		e.resize(N*N);
		V x(N*N);
		for(i=0;i<N;i++){
			scanf("%d",&s[i]);
			e[i*N+i]=1;
			if(i>0)x[i*N+i-1]=a;
			x[i*N+i]=b;
			if(i<N-1)x[i*N+i+1]=c;
		}
		const V r=exp(x,t);
		for(i=0;i<N;i++){
			printf(i<N-1?"%d ":"%d\n",(r[slice(i*N,N,1)]*s).sum()%M);
		}
	}
}

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

int main(){

  int n, ans = 1;
  cin >> n;

  int d[n];


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

  sort(d, d+n);

  for (int i = 0; i < n - 1; i++) {
    if(d[i] != d[i + 1]) {
      ans++;
    }
  }

  cout << ans << endl;




}


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

typedef long long ll;

const int  MOD = 1e9+7;

vector<vector<char>> field;
vector<vector<ll>> dp;

int main(){

    int H, W;
    cin>> H >> W;
    
    field.resize(H);
    dp.resize(H);

    for(int h=0; h<H; h++){
        field[h].resize(W);
        dp[h].resize(W, 0);
    }

    for(int h=0; h<H; h++){
        for(int w=0; w<W; w++){
  
            cin>>field[h][w];
        }
    }

    dp[0][0]=1;
    for(int h=0; h<H; h++){
        for(int w=0; w<W; w++){
            if(field[h][w]=='.'){
 
                if(w-1>=0 && field[h][w-1]=='.'){
            
                    dp[h][w] = max(dp[h][w], dp[h][w]+dp[h][w-1]);
                }
                if(h-1>=0 && field[h-1][w]=='.'){
                    dp[h][w] = max(dp[h][w], dp[h][w]+dp[h-1][w]);
                }
                dp[h][w]%=MOD;
            }else{
                continue;
            }
        }
    }
    /*
    for(int h=0; h<H; h++){
        for(int w=0; w<W; w++){
            cout<<dp[h][w]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
    */
    cout<<dp[H-1][W-1]<<endl;
    return 0;
}

Measured memory_bytes: 12432
N, K=list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = input()

score=0
for k in range(K):
    temp_t = T[k::K]
    if len(temp_t)==1:
        if temp_t=='r':
            score += P
        elif temp_t=='s':
            score += R
        else:
            score += S
    else:
        prev = 'x'
        prev_count = 0
        for itr in range(len(temp_t)):
            if temp_t[itr] != prev:
                prev = temp_t[itr]
                prev_count = 1
                if temp_t[itr]=='r':
                    score += P
                elif temp_t[itr]=='s':
                    score += R
                else:
                    score += S
            else:
                prev_count += 1
                if prev_count % 2 == 1:
                    if temp_t[itr]=='r':
                        score += P
                    elif temp_t[itr]=='s':
                        score += R
                    else:
                        score += S
print(score)


Measured memory_bytes: 3316
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int n, x, max;
	int a, b, c;
	int ans;

	while (1) {
		scanf("%d%d", &n, &x);
		if (n == 0 && x == 0) break;

		ans = 0;
		max = x; if (max > n) max = n;
		for (a = 1; a <= max; a++) {
			for (b = a + 1; b <= max; b++) {
				c = x - a - b;
				if (c > b && c <= n) ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2048
#include <iostream>
using namespace std;
typedef unsigned long long ull;

ull gcd(ull m, ull n) {
    ull r;
    if (m < n) swap(m,n);
    if (n == 0) return m;
    return gcd(n, m % n);
}

ull lcm(ull m, ull n) {
    return (m * n) / gcd(m, n);
}

main() {
    ull a,b;
    while(cin>>a) {
        cin>>b;
        cout << gcd(a,b) << " " << lcm(a,b) << endl;
    }
}

Measured memory_bytes: 1152
def f(ks, d):
    md = 10 ** 9 + 7
    dp = [0] * d
    just = 0

    for k in ks:
        ndp = [0] * d

        for di, dk in enumerate(dp):
            for ndi in range(di, di + 10):
                ndp[ndi % d] += dk

        for ndi in range(just, just + k):
            ndp[ndi % d] += 1

        ndp = [ndk % md for ndk in ndp]

        just = (just + k) % d
        dp = ndp

    print((dp[0] + (just == 0) - 1) % md)


ks = list(map(int, list(input())))
d = int(input())
f(ks, d)


Measured memory_bytes: 3188
#include<iostream>

using namespace std;

int main()
{
    long long int money;
    long long  int total  = 0;

    cin>> money;

    int tousand = 0;
    int five = 0;

    if(money / 500 > 0)
    {
        tousand = money / 500;
        money = money -  (money /500) * 500;
        total += tousand * 1000;

    }

    if(money / 5 > 0)
    {
        five = money / 5;
        total += five * 5;
    

    }

    cout<< total;
}

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

int main(){
    string s,t;
    cin>>s>>t;
    VV dp(s.size()+1,V(t.size()+1,0));
    rep(i,s.size()){
        rep(j,t.size()){
            if(s[i]==t[j]){
                dp[i+1][j+1]=dp[i][j]+1;
            }else {
                dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
    ll len=dp[s.size()][t.size()];
    ll i=s.size()-1;
    ll j=t.size()-1;
    string ans;
    while(len>0){
        if(s[i]==t[j]){
            ans.push_back(s[i]);
            i--;
            j--;
            len--;
        }else if(dp[i+1][j]==dp[i][j]){
            i--;
        }else{
            j--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout<<ans<<endl;
}


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

int main(){
  int N,K,ans;
  cin>>N>>K;
  vector<int> l(N);
  for(int i = 0; i<N;i++){
    cin>>l.at(i);
  }
  sort(l.begin(),l.end(),greater<int>());
  ans = 0;
  for(int i = 0; i<K;i++){
    ans+=l.at(i);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	final int LEN = 0;

	int a[];
	
	void doIt() {
		int n = sc.nextInt();
		long ans = 1;
		int num[] = new int[n + 1];
		num[0] = 3;
		a = new int[n + 1];
		for(int i = 1; i <= n; i++)
			a[i] = sc.nextInt() + 1;
		for(int i = 1; i <= n; i++) {
			ans = (ans * (num[a[i] - 1] - num[a[i]])) % MOD;
			num[a[i]] ++;
		}
		System.out.println(ans % MOD);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 60484
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
typedef pair<P,long double> Pi;
typedef pair <long double,int> Pd;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()

const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
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(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<ll> a(n);
for(int i=0;i<n;i++)cin>>a[i];
int left=0,right=2;
for(int i=0;i<n-1;i++)a[i+1]+=a[i];
ll ans=inf;
for(int i=1;i<n-2;i++){
   // ll lsum=a[i],rsum=a[i+1]-a[i];
   if(right==i)right++;
  ll bfol=abs(a[left]-(a[i]-a[left])),bfor=abs(a[right]-a[i]-(a[n-1]-a[right])); 
   while(left+1<i&&abs(a[left+1]-(a[i]-a[left+1]))<bfol){bfol=abs(a[left+1]-(a[i]-a[left+1]));left++;}
   while(right+1<n-1&&abs(a[right+1]-a[i]-(a[n-1]-a[right+1]))<bfor){bfor=abs(a[right+1]-a[i]-(a[n-1]-a[right+1]));right++;}
 ans=min(ans,abs(max({a[left],a[i]-a[left],a[right]-a[i],a[n-1]-a[right]})-min({a[left],a[i]-a[left],a[right]-a[i],a[n-1]-a[right]})));
}
cout<<ans<<endl;
}




Measured memory_bytes: 1792
#include<stdio.h>

int main(void)
{
	int price = 800;
	int count,N,x,y;
	
	scanf("%d",&N);
	x = N * price;
	count = (int)(N / 15);
	y = 200 * count;
	
	printf("%d\n",x-y);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <numeric>
#include <cmath>

using namespace std;

void solve()
{
	int N;
	cin >> N;

	int cnt = 1;
	for (int i = 1; i <= N; i++) {
		int num;
		cin >> num;
		if (cnt == num) {
			cnt++;
		}
	}

	if (cnt == 1) {
		cout << -1 << endl;
	}
	else {
		cout << N - cnt + 1 << endl;
	}
}

int main()
{
	solve();

	return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

const int Max = 1e6;

int main() {
	int n, x, L[Max], D[Max], cnt = 1;
	cin >> n >> x;
	D[1] = 0;
	for (int i = 1; i <= n; ++i)
		cin >> L[i];
	for (int i = 2; i <= n + 1; ++i){
		D[i] = D[i - 1] + L[i - 1];
		if (D[i] <= x)
			++cnt;
	}
	cout << cnt;
	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  ll x, a = 0, b = 0;
  cin >> x;
  for(int i = -1000; i <= 1000; i++){
    for(int j = -1000; j <= 1000; j++){
      if(pow(i,5)-pow(j,5) == x){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4060