akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

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

	vector<double> p(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i];

	}

	//sort(p.begin(), p.end(), std::greater<int>());
	//for (int i = 0; i < N; i++) cout << p[i] << " " << endl;
	//cout << endl;

	int sum = 0;
	int index = 0;
	for (int i = 0; i < K; i++) {
		sum += p[i];
	}
int  sum_tmp=sum;
	for (int i = K; i < N; i++) {
		sum_tmp = sum_tmp + p[i] - p[i - K];
		//cout << "i: " << i << " sum_tmp: " << sum_tmp << " sum: " << sum << endl;
		if (sum_tmp > sum) {
			index = i - K+1;
			sum = sum_tmp;

		}

	}


	double ans = 0;
	for (int i = index; i < index + K; i++) {
		ans += p[i] * (p[i] + 1) / 2 / p[i];
		//cout << p[i] << endl;
	}

	cout << fixed;//小数点を確実に8桁で表示するためのもの
	cout << setprecision(8) << ans << endl;

}



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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n, m;
	cin >> n >> m;
	if(abs(n - m) > 1) {
		cout << 0 << endl;
		return 0;
	}
	long long ans = 1;
	int mod = 1000000007;
	for(int i = 1; i <= n; i++) {
		ans = ans * i % mod;
	}
	for(int i = 1; i <= m; i++) {
		ans = ans * i % mod;
	}
	if(n == m) {
		cout << ans * 2 % mod << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;	
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
//int fac(int n){
//	for(int i = 1;i <= n;i++)
//}
//int comb(int n, int k){

//}
int main(){
	long long int k, s, ans = 0;
	cin >> k >> s;
//	if(s > k){
//		ans = ((s + 2) * (s + 1) / 2) - 3 * ((s - k + 1) * (s - k) / 2);
//	}else{
//		ans = (s + 2) * (s + 1) / 2;
//	}
	int z;
	for(int i = k;i >= 0;i--){
		for(int j = i;j >= 0;j--){
			z = (s - i - j);
			if(z >= 0){
				z = (s - i - j);
				if(j < z){
					break;
				}
				if(i == j && j == z){
					ans++;
				}else if((i == j) || (j == z) || (z == i)){
					ans += 3;
				}else{
					ans += 6;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using LL = long long;

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

    int N, D, A;
    cin >> N >> D >> A;

    vector< pair< LL, LL>> pro(N);
    for (int i = 0; i < N; i++) cin >> pro[i].first >> pro[i].second;

    LL add = 0;
    set< pair<LL, LL>> st;
    sort(begin(pro), end(pro));
    LL result = 0;

    for (int i = 0; i < N; i++) {
        LL health = pro[i].second;
        while (!st.empty() && st.begin()->first <= pro[i].first) {
            add -= st.begin()->second;
            st.erase(st.begin());
        }
        LL need = (health + A - 1) / A;
        need -= add;
        if (need > 0) {
            add += need;
            result += need;
            st.emplace(pro[i].first + 2 * D + 1, need);
        }
    }

    cout << result << endl;
}


Measured memory_bytes: 9600
n = int(input())
p = list(map(int, input().split()))
a = list(p)

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

  

for i in range(n):
  for j in range(n):
    a[i] = p[j]
    a[j] = p[i]
    if a == ans:
      print('YES')
      exit()
    else:
      a = list(p)
       
      
      
      
    
print('NO')

Measured memory_bytes: 3064
#include <cstdio>

int main()
{
  double max, min, input;
  scanf("%lf", &input);
  min = max = input;

  while (~scanf("%lf", &input)) {
    if (max < input)
      max = input;
    if (min > input)
      min = input;
  }
  printf("%.1f\n", max-min);
  return 0;
}

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

// Longest Increasing Subsequence
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D&lang=ja

// ビットで全探索 O(2^N)
int bits(vector<int> a) {
  int ans = 0;
  int n = a.size();
  rep(seq, 1 << n) {
    int len = __builtin_popcount(seq);
    vector<int> sub(len);
    int j = 0;
    rep(i, n) if (seq & 1 << i) sub[j++] = a[i];

    bool is = true;
    rep(i, len - 1) {
      if (sub[i] >= sub[i + 1]) {
        is = false;
        break;
      }
    }
    if (is) ans = max(ans, len);
  }
  return ans;
}

int dp[100001];

// O(N^2) まだ遅い
int dp1(vector<int> a) {
  int n = a.size();
  rep(i, n) {
    dp[i] = 1;
    rep(j, i) if (a[j] < a[i]) dp[i] = max(dp[i], dp[j] + 1);
  }
  int ans = 0;
  rep(i, n) ans = max(ans, dp[i]);
  return ans;
}

// O(NlogN)
int dp2(vector<int> a) {
  int n = a.size();
  fill(dp, dp + n, 1e+9);
  rep(i, n) { *lower_bound(dp, dp + n, a[i]) = a[i]; }
  return lower_bound(dp, dp + n, 1e+9) - dp;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  // int ans = bits(a);
  // int ans = dp1(a);
  int ans = dp2(a);

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


Measured memory_bytes: 3944
#include <stdio.h>

#define N 101

int check(int s,int d,int v);

int root[N][N]; /* rooter path */
int visited[N]; /* already visited flag */

int que[N][2];  /* queue for bfs {rooter id, num of rooter} */
int wp,rp;      /* write pointer, read pointer for queue */

int main(){
    int n,r,k,t;
    int p,s,d,v;
    int i,j;
    char c;
    int ans;

    /* init root */
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            root[i][j]=0;
        }
    }

    /* input */
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&r);
        scanf("%d",&k);
        for(j=0;j<k;j++){
            scanf("%d",&t);
            root[r][j] = t;
        }
    }


    scanf("%d",&p);
    for(i=0;i<p;i++){
        scanf("%d %d %d",&s,&d,&v);
        ans = check(s,d,v);
        printf(ans?"%d\n":"NA\n",ans);
    }
    return 0;
}
 
 
int check(int s,int d,int v){
    int i,ret,id,num,nextid;

    for(i=0;i<N;i++)visited[i]=0;

    /* init que */
    wp=0;
    rp=0;

    visited[s]=1;
    /* push que */
    que[wp][0]=s;
    que[wp][1]=1;
    wp++;

    while(rp<wp){
        /* pop que */
        id=que[rp][0];
        num=que[rp][1];
        rp++;

        if(id==d) return num; /* goal(return num of rooter) */
        if(num>=v) continue;/* TTL is too small */

        /* check next rooter */
        for(i=0;root[id][i];i++){
            nextid=root[id][i];

            if(visited[nextid]) continue; /* already visited */
            visited[nextid]=1;

            /* push que */
            que[wp][0]=nextid;
            que[wp][1]=num+1;
            wp++;
        }
    }

    return 0;/* can't alive */
}

Measured memory_bytes: 640
N,M = map(int,input().split())
A = list(map(int,input().split()))
 
dp = [-1 for i in range(N+10)]
l = [0,2,5,5,4,5,6,3,7,6]
dp[0] = 0
for i in range(N-1):
    for s in A:
        if dp[i] == -1 and i!=0:
            continue
        if dp[i + l[s]] < dp[i]*10+s:
            dp[i + l[s]] = dp[i]*10+s
print(dp[N])

Measured memory_bytes: 14668
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <fstream>

#define ll long long
#define ld long double

using namespace std;

ifstream fin("date.in");

int main() {
    int a, b, c, k;

    cin >> a >> b >> c >> k;

    int sum = 0;
    if (k > 0) {
        if (k - a >= 0) {
            k -= a;
            sum += a;
        }
        else {
            sum = a - (a - k);
            k = 0;
        }
    }

    if (k > 0)
        k -= b;

    if (k > 0) {
        if (k - c >= 0) {
            k -= c;
            sum -= c;
        } else {
            sum -= (c - (c - k));
        }
    }

    cout << sum;

    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    ll f = 0;
    ll count = 0;
    rep(i, 0, s.size()){
        if(f == 0){
            if(s[i] == 'K'){
                f++;
                count = 0;
            }else if(s[i] != 'A'){
                cout << "NO" << endl;
                return 0;
            }else{
                count++;
                if(count > 1){
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
        else if(f == 1){
            if(s[i] == 'I'){
                f++;
                count = 0;
            }else if(s[i] != 'A'){
                cout << "NO" << endl;
                return 0;
            }else{
                count++;
                if(count > 0){
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
        else if(f == 2){
            if(s[i] == 'H'){
                f++;
                count = 0;
            }else if(s[i] != 'A'){
                cout << "NO" << endl;
                return 0;
            }else{
                count++;
                if(count > 0){
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
        else if(f == 3){
            if(s[i] == 'B'){
                f++;
                count = 0;
            }else if(s[i] != 'A'){
                cout << "NO" << endl;
                return 0;
            }else{
                count++;
                if(count > 1){
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
        else if(f == 4){
            if(s[i] == 'R'){
                f++;
                count = 0;
            }else if(s[i] != 'A'){
                cout << "NO" << endl;
                return 0;
            }else{
                count++;
                if(count > 1){
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
        else if(f == 5){
            if(s[i] != 'A'){
                cout << "NO" << endl;
                return 0;
            }else{
                count++;
                if(count > 1){
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
    }

    if(f != 5){
        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		while (true) {

			String str = scan.next();

			if (str.equals("0")) {
				break;
			}

			// strArry????????????????????????????´?
			String[] strArry = str.split("");

			
			int x = 0;
			int sum = 0;
			for (int i = 0; i < strArry.length; i++) {
				//??´??°???????????????x?????£??\
				x = Integer.parseInt(strArry[i]);
				sum = sum + x;
			}
			
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 27252
#include <stdio.h>
int main(void)

{
    char N[99999];
    int i,a=0,b=0,o=0;

    scanf("%s",N);

    for(i=0;N[i]!='\0';i++)
       if(N[i] == '1') b++;
       else            o++;

    if(o>b) printf("%d\n",b*2);
    else    printf("%d\n",o*2);

    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,a[5];
    cin>>n;
    for(int i=0;i<5;i++) cin>>a[i];
    sort(a,a+5);
    ll mia=n/a[0]+1;
    if(n%a[0]==0) mia=n/a[0];
    cout<<mia+4<<endl;
}

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

int main(){
  int a,b,c; cin >> a >> b >> c;
  string ret="No";
  if(a==b&&b!=c) ret="Yes";
  else if(b==c&&c!=a) ret="Yes";
  else if(c==a&&a!=b) ret="Yes";
  cout << ret;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
void chmin(LL& a, LL b) {
	a = min(a, b);
}
//////////////
string f(int N) {
	string ans = "";
	while (N) {
		int ter = N % 10;
		ans = char('0' + ter) + ans;
		N /= 10;
	}
	for (int i = 6 - ans.size(); i > 0; --i) {
		ans = char('0') + ans;
	}
	return ans;
}
void solve() {
	int N, M;
	cin >> N >> M;
	vector<int> P(M), Y(M);
	vector<vector<int>> dat(M);
	for (int i = 0; i < M; ++i) {
		cin >> P[i] >> Y[i];
		dat[i] = {Y[i],P[i],i};
	}
	vector<int> C(N + 1, 0);
	vector<string> ans(M);
	sort(dat.begin(), dat.end());
	for (int i = 0; i < M; ++i) {
		ans[dat[i][2]] = f(dat[i][1]) + f(C[dat[i][1]] + 1);
		C[dat[i][1]]++;
	}
	for (int i = 0; i < M; ++i) {
		cout << ans[i] << endl;
	}
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


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

int main(){
  string S;
  cin>>S;
  int N=S.size();

  int left=0,right=N-1;
  int cnt=0;
  bool fl=true;
  while(left<right){
    char s=S[left],t=S[right];
    if(s==t){
      ++left;
      --right;
    }
    else if(s=='x'){
      ++left;
      ++cnt;
    }
    else if(t=='x'){
      --right;
      ++cnt;
    }
    else{
      fl=false;
      break;
    }
  }

  if(fl) cout<<cnt<<endl;
  else cout<<-1<<endl;
}

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

long long i, o, j, l, t;

signed main() {
	cin >> i >> o >> t >> j >> l;
	cout << o + max(i/2*2 + j/2*2 + l/2*2, (i&&j&&l ? (i-1)/2*2 + (j-1)/2*2 + (l-1)/2*2 + 3 : 0));
}

Measured memory_bytes: 256
import math

D, G = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(D)]

ans = 100000000
for bit in range(1 << D):
    s = 0
    ans_ = 0
    li = 0
    for i in range(D):
        if bit & (1 << i):
            s += (i+1) * 100 * pc[i][0] + pc[i][1] 
            ans_ += pc[i][0]
        else:
          li = i  
    if s < G:
        lv = 100 * (li + 1)
        need = int(math.ceil((G - s) / lv))
        if pc[li][0] < need:
            continue
        ans_ += need
    ans = min(ans, ans_)

print(int(ans))



Measured memory_bytes: 73904
#include<iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if((x-r>=0)&&(y-r>=0)&&(x+r<=W)&&(y+r<=H)){
        cout << "Yes" <<endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3116
# from math import gcd
def gcd(a,b):
    if b == 0:return a
    return gcd(b,a%b)

a,b,k = map(int,input().split())

g = gcd(a,b)

cnt = 0
for i in range(g,0,-1):
  if a%i == 0 and b%i == 0:
    # print('i is now ',i)
    cnt+=1
    if cnt == k:
      print(i)
      break


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long H = scan.nextLong();
		long W = scan.nextLong();

		if (H == 1 || W == 1) {
			System.out.println(1);
		} else if ((H * W) % 2 == 0) {
			System.out.println(H * W / 2);
		} else {
			System.out.println((H * W / 2) + 1);
		}
	}

}


Measured memory_bytes: 22612
<>;
undef $/;
my $s = <>;
my @w = split /\s+/, $s;
my %w = map { $_ => 1 } @w;
@w != keys %w and print 'No' and exit;
$s =~ /^(?:\w*(\w)\s+(?=\g{-1}))+\w+\s+$/ and print 'Yes' and exit;
print 'No';

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

using namespace std;
const int INF=1e9+5;
const int MOD=1e9+7;
typedef long long ll;

int main(){
	int n,k;
	cin>>n>>k;
	int a[k];
	int sum=0;
	for(int i=0;i<k;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>n)
		cout<<"-1\n";
	else
		cout<<n-sum<<endl;
	
}


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

int main() {
  int n;
  scanf("%d", &n);
  int a, ans = 0;
  for (int i=0; i<n; i++) {
    scanf("%d", &a);
    ans += a-1;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#define NUM 100000
#define MAX 2000000000

using namespace std;

struct Card {
    char suit;
    int value;
};

struct Card L[NUM / 2 + 2], R[NUM / 2 + 2];

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

void quickSort(struct Card A[], int N, int p, int r) {
    if (p < r) {
        int q = partition(A, p, r);
        quickSort(A, N, p, q - 1);
        quickSort(A, N, q + 1, r);
    }
}

void merge(struct Card A[], int N, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;

    for (int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    L[n1].value = R[n2].value = MAX;
    
    int j = 0;
    int k = 0;
    for (int i = left; i < right; i++) {
        if (L[j].value <= R[k].value) {
            A[i] = L[j++];
        } else {
            A[i] = R[k++];
        }
    }
}

void mergeSort(struct Card A[], int N, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, N, left, mid);
        mergeSort(A, N, mid, right);
        merge(A, N, left, mid, right);
    }
}

int main() {
    int N, v;
    char s[10];
    Card A[NUM], B[NUM];
    int stable = 1;

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> s >> v;
        A[i].suit = B[i].suit = s[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, N, 0, N);
    quickSort(B, N, 0, N - 1);

    for (int i = 0; i < N; i++) {
        if (A[i].suit != B[i].suit) stable = 0;
    }

    if (stable == 1) {
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }

    for (int i = 0; i < N; i++) {
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}


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

int main(){
  int h,w,n;
  cin >> h >> w >> n;
  int ret;
  if(h > w){
    ret = n/h;
    if(n%h != 0) ret++;
  }
  else{
    ret = n/w;
    if(n%w != 0) ret++;
  }
  cout << ret << endl;
  return 0;
}
		

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

class Square
{
private:
    pair <int, int> p1, p2, p3, p4;
    int x_1to2, y_1to2;
    int x_abs, y_abs;

    void setOtherTwoPoints()
    {
        if (x_1to2 >= 0 && y_1to2 >= 0) {
            p3.first = p2.first - y_abs;
            p3.second = p2.second + x_abs;
            p4.first = p1.first - y_abs;
            p4.second = p1.second + x_abs;
        } else if (x_1to2 < 0 && y_1to2 < 0) {
            p3.first = p2.first + y_abs;
            p3.second = p2.second - x_abs;
            p4.first = p1.first + y_abs;
            p4.second = p1.second - x_abs;
        } else if (x_1to2 < 0 && y_1to2 >= 0) {
            p3.first = p2.first - y_abs;
            p3.second = p2.second - x_abs;
            p4.first = p1.first - y_abs;
            p4.second = p1.second - x_abs;
        } else {
            p3.first = p2.first + y_abs;
            p3.second = p2.second + x_abs;
            p4.first = p1.first + y_abs;
            p4.second = p1.second + x_abs;
        }
    }
    
public:
    Square(int x1, int y1, int x2, int y2)
    {
        p1.first = x1; p1.second = y1;
        p2.first = x2; p2.second = y2;

        x_1to2 = x2 - x1;
        y_1to2 = y2 - y1;

        x_abs = abs(x_1to2);
        y_abs = abs(y_1to2);

        setOtherTwoPoints();
    }

    void printOtherTwoPoints()
    {
        cout << p3.first << " "
             << p3.second << " "
             << p4.first << " "
             << p4.second << endl;
    }
};


int main()
{
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    Square sqr(x1, y1, x2, y2);
    sqr.printOtherTwoPoints();
}


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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

int main(void){
    char n[10];
    int cnt = 0;
    int i;
    scanf("%s", n);
    for (i = 0; i < 4; i++){
        if (n[i] == n[i+1]){
            cnt++;
        }else{
            cnt = 0;
        }
        if (cnt == 2){
            printf("Yes\n");
            return 0;
        }
    }

    printf("No\n");


    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int volume = int.Parse(Console.ReadLine());

                if (volume == 0) break;

                int minPrice = int.MaxValue;

                for (int c = 0; c <= volume; c += 500)
                {
                    int rest = volume - c;

                    for (int b = 0; b <= rest; b += 300)
                    {
                        int a = rest - b;

                        if (a % 200 != 0) continue;

                        int na = a / 200;
                        int nb = b / 300;
                        int nc = c / 500;

                        int price = na * 380 + nb * 550 + nc * 850;

                        int ma = na / 5;
                        int mb = nb / 4;
                        int mc = nc / 3;

                        int discount = ma * 380 + mb * 330 + mc * 306;

                        price -= discount;

                        minPrice = Math.Min(minPrice, price);
                    }
                }
                Console.WriteLine(minPrice);
            }
        }
    }
}

Measured memory_bytes: 9172
#include <iostream>
using namespace std;
int gcd(int x, int y)
{
    if (x > y)
    {
        return gcd(x - y, y);
    }
    if (y > x)
    {
        return gcd(y - x, x);
    }
    if (x == y)
    {
        return x;
    }
}
int main()
{
    int x, y;
    cin >> x >> y;

    cout << gcd(x, y) << endl;
}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

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

	rep(i, s.size()) {
		cout << char('A' + (s[i] - 'A' - 3 + 26) % 26);
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1176
N, M = map(int, input().split())
ans = [0 for _ in range(N)]
if N == 1:
	ans[0] = 0
else:
	ans[0] = 1
f = 1
flg = [-1 for _ in range(M + 1000)]

for _ in range(M):
	s, c = map(int, input().split())
	if s == 1 and c == 0 and N != 1: 
		f = 0
	if flg[s] != -1 and flg[s] != c:
		f = 0
	else:
		flg[s] = c
		ans[s - 1] = c

if f:
	for a in ans:
		print(a, end = "")
else:
	print(-1)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
//#define endl cout << "\n"
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s;
    cin >> s;
    int l = (s.size())-1;
    if(s[l]=='3') cout << "bon" << endl;
    else if(s[l]=='0' || s[l] == '1' || s[l] == '6' || s[l] == '8') cout << "pon" << endl;
    else cout << "hon"  << endl;
    bye;
}



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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    string s; cin >> s;

    int ans = 0;
    for(int i = 0; i < s.length()-1; i++){
        if(s[i] != s[i+1])
            ans++;
    }

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

Measured memory_bytes: 3788
#include<iostream>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<cstring>
using namespace std;

int main(void) {
	bool prime[100001];
	prime[0] = prime[1] = 0;
	int i;
	for (i = 2; i <= 100000; i++) {
		prime[i] = 1;
	}
	int  j, k, m, Q, N;
	cin >> N;
	int a[100000] = {};
	for (i = 2; i <= 316; i++) {
		if (prime[i]) {
			for (j = 2 * i; j <= 100000; j += i) {
				prime[j] = false;
			}
		}
	}
	k = 0;
	for (i = 2; i < 55555; i++) {
		if (prime[i] && i % 5 == 1) {
			a[k] = i;
			k++;
		}
	}
	for (i = 0; i < N; i++) {
		cout << a[i] << endl;
	}


	return 0;
}








Measured memory_bytes: 768
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int a,b;cin>>a>>b;
	if(a <b){
		rep(i, b){
			cout << a;
		}
		cout << endl;
		return 0;
	}else{
		rep(i, a){
			cout << b;
		}
		cout << endl;
		return 0;
	}
	return 0;
}


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

#define GET_STDIN fgets(buf, 1024, stdin)
#define FOR(i, n, b) for(int i = 0; i < (n); i += (b))

using namespace std;

int main() {
  int k, s;
  char buf[1024];

  GET_STDIN;
  sscanf(buf, "%d %d", &k, &s);

  int sum = 0;
  FOR(x, k + 1, 1) {
    FOR(y, k + 1, 1) {
     if (s - x - y >= 0 && s - x - y <= k) {
       sum++;
     }
    }
  }

  cout << sum << endl;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    ll h,n; cin >> h >> n;
    vl da(n),mp(n);
    rep(i,n)cin>>da[i]>>mp[i];
    vvl dp(h+10,vl(n+1,L_INF)); // dp[体力][魔法の種類数]
    dp[0][0] = 0;
    //ll res = L_INF;
    rep(i,h+1){
        rep(j,n){
            chmin(dp[i][j+1],dp[i][j]); //jの魔法を使わないとき
            chmin(dp[min(i+da[j],h)][j+1],dp[i][j+1]+mp[j]);
        }
    }
    out(dp[h][n]);
}


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

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    if (v.empty()) {
        ostr << "{ }";
        return ostr;
    }
    ostr << "{" << v.front();
    for (auto itr = ++v.begin(); itr != v.end(); itr++) {
        ostr << ", " << *itr;
    }
    ostr << "}";
    return ostr;
}

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

int main(void){

  long long N, K;
  cin >> N >> K;

  long long h[N];
  for (int i=0; i<N; i++){cin >> h[i];}

  long long dp[N];
  const long long INF = 1LL << 60;
  for (int i=0; i<N; i++){dp[i] = INF;}
  dp[0] = 0;


  for (int i=1; i<N; ++i){
    for (int j=1; j<=K; ++j){
      if (i - j < 0) {;}
      else {
        chmin(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
      }
    }
  }


  cout << dp[N-1] << endl;


  return 0;
}



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

int dp[200][200][200];
int dfs(int n,int k,int s){
	if( n < 0 || k < 0 || s < 0 ) return 0;
	if( n == 0 && k == 0 && s == 0) return 1;
	if( dp[n][k][s] != -1 ) return dp[n][k][s];
	int ans = dfs(n-1,k-1,s-n) + dfs(n-1,k,s);
	return dp[n][k][s] = ans;
}
int main(){
	memset(dp,-1,sizeof(dp));
	int n,k,s;
	while(cin >> n >> k >> s && n){
		cout << dfs(n,k,s) << endl;
	}
	
	
}

Measured memory_bytes: 32416
# coding: utf-8
# Your code here!


N=int(input())
List=input()
AList=list(List)
#print(AList)
#print(sorted(List))
RCNT=AList.count("R")
BList=sorted(List)
#print(List[0])

#print(RCNT)

ANUM=0
BNUM=0
ans=0
i=0
while i<N:
    if AList[i]=="R":
        ANUM+=1
    if BList[i]=="R":
        BNUM+=1
        
    #print(BNUM,ANUM)
    if AList[i]!=BList[i]:
        ans+=1
    if BNUM==RCNT or ANUM==RCNT:
        print(ans)
        quit()
    
    i+=1
    
print(ans)













Measured memory_bytes: 12996
N = int(input())
A = list(map(int, input().split()))
 
ans = 1
 
if 0 in A:
    ans = 0
 
else:
    for i in range(len(A)):
        ans = ans * A[i]
        if ans > 10 ** 18:
            ans = '-1'
            break
print(ans)

Measured memory_bytes: 21636
n=int(input())
A =list(map(int,input().split()))
B =list(map(int,input().split()))
res = 0
ans = 0 
for i in range(n):
    if A[i]-B[i]>=0:
        ans += B[i]
        res = 0
    else:
        ans += A[i]
        res =abs (A[i]-B[i])
    if res != 0:
        if A[i+1]-res>0:
            ans += res
            A[i+1] = A[1+i]-res 
            res = 0
        else:
            ans += A[i+1]
            A[i+1] =0
            res =0

print(ans)  



Measured memory_bytes: 18476
#include<iostream>
using namespace std; //or std::cin et al.

int main() {
	int w,h,x,y,r;
	cin >> w >> h >> x >> y >> r;
	if (x - r < 0 || x + r > w) cout << "No" << endl;
	else if (y - r < 0 || y + r > h) cout << "No" << endl;
	else cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }

    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

const int mod = 1e9 + 7;
using modint = ModInt<mod>;

modint dp[30][(1<<21)+10];

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

    dp[0][0] = 1;
    for(int i=0; i<N; i++){
        for(int s=0; s<(1<<N); s++){
            if(dp[i][s] != 0) for(int j=0; j<N; j++){
                if(!(s&(1<<j)) && a[i][j]) dp[i+1][s|(1<<j)] += dp[i][s];
            }
        }
    }

    cout << dp[N][(1<<N)-1] << endl;

}

Measured memory_bytes: 246016
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    vector<int> a(n);
    rep(i,n) cin >> a[i];

    //ABC146Eと同様に累積和を取りたくなるような内容。
    vector<int> s(n+1); s[0] = 0;
    rep(i,n) s[i+1] = (s[i] + a[i]) %k;

    map<int,int> mp;
    ll ans = 0;

    //累積和配列の範囲がn+1なのでしっかり留意してアレンジすること
    rep(i,n+1){
        ans += mp[s[i]];
        mp[s[i]]++;
    }

    dunk(ans);
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	string s;
	cin>>s;
	int n=s.size();
	--n;
	while(n>0){
		if(s[n]=='r'){
			if(n>=6 && s.substr(n-6, 7)=="dreamer"){
				n-=7;
			}
			else if(n>=5 && s.substr(n-5, 6)=="eraser"){
				n-=6;
			}
			else{
				cout<<"NO"<<'\n';
				return 0;
			}
		}
		else if(s[n]=='e'){
			if(n>=4 && s.substr(n-4, 5)=="erase"){
				n-=5;
			}
			else{
				cout<<"NO"<<'\n';
				return 0;
			}
		}
		else if(s[n]=='m'){
			if(n>=4 && s.substr(n-4, 5)=="dream"){
				n-=5;
			}
			else{
				cout<<"NO"<<'\n';
				return 0;
			}
		}
	}
	cout<<"YES"<<'\n';
	return 0;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    
    string S = "";
    
    for (int i = 0; i < H; i++){
        string s;
        cin >> s;
        S += s;
    }
    
    for (int i = 0; i < H*W; i++){
        
        int times = 0;
        
        if (i-1 > -1 && i % W != 0){
            if (S.at(i-1) == '#'){
                times++;
            }
        }
        
        if (i+1 < S.size() && (i+1) % W != 0){
            if (S.at(i+1) == '#'){
                times++;
            }
        } 
        
        if (i-W > -1){
            if (S.at(i-W) == '#'){
                times++;
            }
        }
        
        if (i+W < S.size()){
            if (S.at(i+W) == '#'){
                times++;
            }
        }
        
        if (i-1-W > -1 && i % W != 0){
            if (S.at(i-1-W) == '#'){
                times++;
            }
        }
        
        if (i-1+W < S.size() && i % W !=0){
            if (S.at(i-1+W) == '#'){
                times++;
            }
        }
        
        if (i+1-W > -1 && (i+1) % W !=0){
            if (S.at(i+1-W) == '#'){
                times++;
            }
        }
        
        if (i+1+W < S.size() && (i+1) % W != 0){
            if (S.at(i+1+W) == '#'){
                times++;
            }
        }
        
        if (S.at(i) == '.'){
            

          if (times == 0){
              S.at(i) = '0';
          }
        
          if (times == 1){
              S.at(i) = '1';
          }

          if (times == 2){
              S.at(i) = '2'; 
          }
        
          if (times == 3){
              S.at(i) = '3';
          }
        
          if (times == 4){
              S.at(i) = '4';
          }
        
          if (times == 5){
              S.at(i) = '5';
          }
        
          if (times == 6){
              S.at(i) = '6';
          }
        
          if (times == 7){
              S.at(i) = '7';
          }
        
          if (times == 8){
              S.at(i) = '8';
          }
          
        }
    }
    
    for (int i = 0; i < H*W; i+=W){
        
        string s = "";
        
        for (int j = 0; j < W; j++){
            s += S.at(i+j); 
        }
        
        cout << s << endl;
    }
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, K, H[300], a[300];
ll DP[301][302][301], res = llmax;
vector<int>v;

int main() {
	cin >> N >> K;
	v.push_back(0);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
		v.push_back(H[i]);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < N; i++) {
		a[i] = lower_bound(v.begin(), v.end(), H[i]) - v.begin();
	}
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			for (int k = 0; k <= N; k++) {
				DP[i][j][k] = llmax / 2;
			}
		}
	}
	DP[0][0][0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= K; j++) {
			for (int k = 0; k <= N; k++) {
				DP[i + 1][j][a[i]] = min(DP[i + 1][j][a[i]], DP[i][j][k] + max(0, H[i] - v[k]));
				DP[i + 1][j + 1][k] = min(DP[i + 1][j + 1][k], DP[i][j][k]);
			}
		}
	}
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= N; j++) {
			res = min(res, DP[N][i][j]);
		}
	}
	cout << res << endl;
}

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

using namespace std;
int n, c;

int main() {
    scanf("%d %d", &n, &c);
    vector<int> w(n);
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &w[i], &v[i]);
    }

    // dp[i][j] := maximum total value of a subset of the first i items, with total size at most j
    vector<vector<long long>> dp(n + 1, vector<long long>(c + 1, 0));
    for (int j = 0; j <= n; ++j) {
        dp[0][j] = 0;
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= c; ++j) {
            if (j < w[i - 1]) dp[i][j] = dp[i - 1][j];
            else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
        }
    }
    printf("%lld\n", dp[n][c]);

    return 0;
}


Measured memory_bytes: 83260
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    ls = [0] * n
    ans = []

    for i in range(n)[::-1]:
        if (sum(ls[i::i+1]) % 2) != a[i]:
            ls[i] = 1
            ans.append(i+1)
    print(sum(ls))
    if ans:
        print(*ans[::-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 14904
use proconio::marker::*;
use proconio::*;
use std::cmp::max;

fn main() {
    input! {
        x: i64,
        k: i64,
        d: i64,
    };
    let x = x.abs();

    let ans;
    if x / d >= k {
        ans = x - d * k;
    } else {
        ans = if (x / d - k) % 2 == 0 {
            x % d
        } else {
            (x % d - d).abs()
        };
    }
    println!("{}", ans);
}


Measured memory_bytes: 2124
#include<stdio.h>
#include<string.h>
 
char X[1001],Y[1001];
 
int LCS_Length(void){
  int i,j;
  int m = strlen(X);
  int n = strlen(Y);
  int c[m+1][n+1];
 
  for(i=1 ; i<=m ; i++) c[i][0] = 0;
  for(j=0 ; j<=n ; j++) c[0][j] = 0;
   
  for(i=1 ; i<=m ; i++){
    for(j=1 ; j<=n ; j++){
      if(X[i-1] == Y[j-1]) c[i][j] = c[i-1][j-1] + 1;
      else if(c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j];
      else c[i][j] = c[i][j-1];
    }
  }
  return c[m][n]; 
}
 
main(){
  int i,n;
  scanf("%d",&n);
  for(i=0 ; i<n ; i++){
    scanf("%s%s",X,Y);
    printf("%d\n",LCS_Length());
  }
  return 0;
}

Measured memory_bytes: 6632
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    int alice = 0;
    int bob = 0;
    boolean alice_turn = true;
    for (int i = a.length - 1; i >= 0; i--) {
      if (alice_turn) {
        alice += a[i];
        alice_turn = false;
      } else {
        bob += a[i];
        alice_turn = true;
      }
    }
    System.out.println(alice - bob);
  }
}

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

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

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

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

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

const ll INF = 1e9+7;


vector<int>  edge[1000005];
map<int,int> memo[1000005];
int dfs(int n, int b){
	if( memo[n].count(b) ) return memo[n][b];
	if( b >= 0 && edge[n].size() == 1 ) return -1;
	int ret = 0, cnt = 0;
	for(auto t: edge[n]) if( t != b ){
		auto r = dfs(t, n);
		if( r < 0 ) cnt++;
		else ret += r;
	}
	//cout << "dfs: " << n << " " << ret << " " << cnt << endl;
	if( ret == 0 && cnt == 1 ) return memo[n][b] = -1;
	if( cnt > 0 ) ret += cnt-1;
	return memo[n][b] = ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	int N;

	cin >> N;
	rep(i,N-1){
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	int ans = INF;
	rep(i,N) if( i==0 || edge[i].size() != 1 ){
		int ret = 0, cnt = 0;
		for(auto t: edge[i]){
			auto r = dfs(t, i);
			if( r < 0 ) cnt++;
			else ret += r;
		}
		if( edge[i].size() <= 1 && ret > 0 && cnt == 0 ) ret++;
		if( ret == 0 && cnt == 1 ) ret = 1;
		else if( cnt > 1 ) ret += cnt-1;
		else if( ret > 0 && cnt == 1 ) ret += cnt;
		else if( cnt > 0 ) ret += cnt-1;
		//cout << i << "=" << ret << endl;
		chmin(ans, ret);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 93952
n, k = [int(i) for i in input().split()]
xx = [int(i) for i in input().split()]

cost = float("inf")
for i in range(n-k+1):
  j = i + k - 1
  cost = min(
    cost,
    abs(xx[i] - 0) + abs(xx[j] - xx[i]),
    abs(xx[j] - 0) + abs(xx[i] - xx[j])
  )
print(cost)

Measured memory_bytes: 62576
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
	int N, K; cin >> N >> K;
	int* a = new int[N];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	bitset<5000>* table = new bitset<5000>[N];
	for (int i = 0; i < N; i++) {
		table[i] = 0;
	}
	table[N - 1][0] = true;
	for (int i = N - 1; i >= 0; i--) {
		if (i < N - 1) { table[i] = table[i + 1]; }
		table[i] |= table[i] << a[i];
	}

	int ans = 0;
	bitset<5000> bset;
	bset[0] = true;
	for (int i = 0; i < N; i++) {
		bool found = false;
		if (i == 0) {
			for (int j = max(0, K - a[i]); j < K; j++) {
				if (table[i + 1][j] == true) { found = true; break; }
			}
		}
		else if (i == N - 1) {
			for (int j = max(0, K - a[i]); j < K; j++) {
				if (bset[j] == true) { found = true; break; }
			}
		}
		else {
			int x = max(0, K - a[i]);
			int y = K;
			int count = 0;
			for (int j = x; j < y; j++) {
				if (table[i + 1][j] == true) { count++; }
			}
			for (int j = 0; j < K; j++) {
				if (bset[j] == true && count > 0) { found = true; break; }
				x--; y--;
				if (x >= 0) { count += (table[i + 1][x] == true); }
				count -= (table[i + 1][y] == true);
			}
		}
		if (found == false) { ans++; }

		bset |= bset << a[i];
	}

	cout << ans << endl;

	return 0;
}

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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i;
    string str;
    cin>>n>>str;
    int cnt=0;
    for(i=0;i+2<n;i++)
    {
        if(str[i]=='A'&&str[i+1]=='B'&&str[i+2]=='C')
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256