akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	string str;
	for(;getline(cin,str);){
		int len=str.size();
		int i,c;
		for(c=1;c<=26;c++){
			for(i=0;i<len;i++){
				if('a'<=str[i]&&str[i]<='z'){
					str[i]++;
					if(str[i]>'z')str[i]='a';
				}
			}
			//cout<<str<<endl;
			if(str.find("the")!=string::npos||str.find("this")!=string::npos||str.find("that")!=string::npos){
				cout<<str<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979

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 (b<a) { a=b; return 1; } return 0; }


bool my_cp(pair<int, int> a, pair<int, int> b){
  return (double)b.first / (double)(b.second+1) < (double)a.first / (double)(a.second+1);
}


ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}

int N;

void dfs(string s, char m, int N){
  size_t len = s.length();
  if(len == N){
    cout << s << endl;
  }else{
    for(char c = 'a'; c <= m; c++){
      dfs(s + c, ((c == m)? (m + 1) : m), N);
    }
  }
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}





// substr(start, len)

int main(){

  long double R;
  cin >> R;

  long double ans = 2*pi*R;

  


  
  cout << setprecision(8) << ans << endl;  // For double
  // CHECK if it's possible to overflow!!
}

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

int main(){
  int k,y,a;
  string n;
  cin>>k>>y;
  if(k==0){
    if(y<1912){a=y-1867; n="M";}
    if(y<1926 && y>1911){a=y-1911; n="T";}
    if(y>1925 && y<1989){a=y-1925; n="S";}
    if(y>1988){a=y-1988; n="H";}
    cout<<n<<a<<endl;
  }

  if(k!=0){
    if(k==1){a=y+1867;}
    if(k==2){a=y+1911;}
    if(k==3){a=y+1925;}
    if(k==4){a=y+1988;}
    cout<<a<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3128
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s1 string
	fmt.Scan(&s1)
	n, _ := strconv.Atoi(s1)
	var s2 string
	fmt.Scan(&s2)
	q, _ := strconv.Atoi(s2)

	var str string
	fmt.Scan(&str)

	ac := make([]int, n)
	count := 0
	ac[0] = 0
	for i := 0; i < n-1; i++ {
		if (str[i] == 'A') && (str[i+1] == 'C') {
			count++
		}
		ac[i+1] = count
	}

	for i := 0; i < q; i++ {
		var sl, sr string
		fmt.Scan(&sl)
		fmt.Scan(&sr)
		l, _ := strconv.Atoi(sl)
		r, _ := strconv.Atoi(sr)
		v := ac[r-1] - ac[l-1]
		fmt.Println(v)
	}
}

Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using namespace std;



int main(){
    int A,B,X;
    cin >> A >> B >> X;

    if(X >= A and A+B >= X){
        puts("YES");
        return 0;
    }else{
        puts("NO");
        return 0;

    }

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

void print() {
    cout << endl;
}

// template <class Head, class... Tail>
// void print(Head&& head, Tail&&... tail) {
//     cout << head;
//     if (sizeof...(tail) != 0) cout << " ";
//     print(forward<Tail>(tail)...);
// }

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i,k-1)cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    cout << p.first << " " << p.second << "\n";
}

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;cin >> s >> t;
    ll ns, nt;
    ns = s.size();
    nt = t.size();
    debug(ns);debug(nt);
    vector<vector<ll>> dp(ns+1, vector<ll>(nt+1));

    rep(i,ns)rep(j,nt){
        if(s[i] == t[j]){
            chmax(dp[i+1][j+1], dp[i][j] + 1);
        }
        chmax(dp[i+1][j+1], max(dp[i+1][j], dp[i][j+1]));
    }
    // print(dp);

    string ans;
    ll x = ns, y = nt;
    ll temp = dp[ns][nt];
    while(temp){
        debug(x);debug(y);
        if(dp[x][y] == dp[x-1][y]){
            x--;
            continue;
        }
        if(dp[x][y] == dp[x][y-1]){
            y--;
            continue;
        }
        ans += s[x-1];
        temp--;
        x--;y--;
    }
    reverse(all(ans));
    cout << ans << endl;
}

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

ans = 0
for n in range(3, N+1, 2):

    count = 1
    for i in range(3, n+1, 2):
        if n % i == 0:
            count += 1
        if n == 1:
            break
    if count == 8:
        ans += 1

print(ans)


Measured memory_bytes: 9180
#include<iostream>
#include<utility>
#include<string>
using namespace std;
int main(){
    int N;
    cin >> N;
    string a[36], b[36];
    for(int i=0 ; i<N ; i++){
      cin >> a[i];
      b[i] = a[i];
    }
    for(int i=0 ; i<N ; i++){
      for(int j=N-1 ; j>i ; j--){
          if (a[j][1]<a[j-1][1]) swap(a[j], a[j-1]);
      }
    }
    for(int i=0 ; i<N-1 ; i++) cout << a[i] << " ";
    cout << a[N-1] << endl;
    cout << "Stable" << endl;
    for(int i=0 ; i<N ; i++){
        int minj = i;
      for(int j=i ; j<N ; j++){
        if (b[j][1]<b[minj][1]) minj = j;
      }
      swap(b[minj], b[i]);
    }
    for(int i=0 ; i<N-1 ; i++) cout << b[i] << " ";
    cout << b[N-1] << endl;
    for(int i=0 ; i<N ; i++){
        if(a[i]==b[i]) continue;
        else{
          cout << "Not stable" << endl;
          return 0;
        }
    }
    cout << "Stable" << endl;
}


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

int main(){

int N, i;
cin >> N;
int V[N], C[N];
for(i=0; i<N; i++){
    cin >> V[i];
}
for(i=0; i<N; i++){
  cin >> C[i];
}
int ans = 0;
for(i=0; i<N; i++){
  if(V[i]-C[i]>0){
    ans += (V[i]-C[i]);
  }
}
cout << ans << endl;
return 0;
}

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

using namespace std;

const int FACES = 6;
const int NUM_SWAPS = 3;

int swap_i[4][NUM_SWAPS][2] = {
	{{0, 1}, {1, 5}, {4, 5}},
	{{0, 3}, {2, 3}, {3, 5}},
	{{0, 4}, {1, 4}, {4, 5}},
	{{0, 2}, {2, 5}, {3, 5}},
};

int move_to_id(char move) {
	if (move == 'N') return 0;
	if (move == 'E') return 1;
	if (move == 'S') return 2;
	return 3;
}

int main() {
	vector<int> faces(FACES);
	for (auto &face: faces) {
		cin >> face;
	}
	cin.ignore();

	string moves;
	cin >> moves;
	for (auto move: moves) {
		auto move_id = move_to_id(move);
		for (int i = 0; i < NUM_SWAPS; ++i) {
			swap(faces[swap_i[move_id][i][0]], faces[swap_i[move_id][i][1]]);
		}
	}

	cout << faces[0] << endl;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct UnionFind {
    UnionFind() {}
    UnionFind(int n) {
        resize(n);
    }
    
    void resize(int n) {
        par.resize(n, -1);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
    
private:
    vector<int> par;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    ll ans = LONG_LONG_MAX;
    rep(bit, 1 << (h - 1)) {
        UnionFind uf(h);
        rep(i, h - 1) {
            ll v = ((bit & (1 << i)) != 0) ? 1 : 0;
            uf.merge(i, i + v);
        }
        vector<ll> sum(h, 0);
        set<ll> grp;
        rep(i, h) grp.insert(uf.root(i));
        ll cut = sz(grp) - 1;
        rep(i, w) {
            vector<ll> tmp(h, 0);
            rep(j, h) {
                tmp[uf.root(j)] += (s[j][i] == '1') ? 1 : 0;
            }
            bool f = false, ng = false;
            rep(j, h) {
                if (tmp[j] > k) ng = true;
                if ((sum[j] + tmp[j]) > k) f = true;
            }
            if (ng) {
                cut = LONG_LONG_MAX;
                break;
            }
            if (f) {
                rep(j, h) sum[j] = tmp[j];
                cut++;
            }
            else {
                rep(j, h) sum[j] += tmp[j];
            }
        }
        ans = min(ans, cut);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N;
    cin >> N;
    vec<lint> A_list(N);
    range(i, 0, N) cin >> A_list.at(i);
    double denominator = 0;
    for (const auto& A : A_list) {
        denominator += 1. / A;
    }
    cout << 1. / denominator << "\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String S = sc.next();

		    if(S.charAt(2) == S.charAt(3) && S.charAt(4) == S.charAt(5) ) {
		      System.out.println("Yes");
		    } else {
		      System.out.println("No");
		    }
	}
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

ll dp[111][111111];

int main(){
	
	ll n,w;cin >> n >> w;
	vector<pair<ll,ll>> v(n);
	REP(i,n)cin >> v[i].FI >> v[i].SE;
	
	REP(i,n){
		REP(j,w+1){
			dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
			if(j+v[i].FI <= w)dp[i+1][j+v[i].FI] = max(dp[i+1][j+v[i].FI],dp[i][j] + v[i].SE);
		}
	}
		
	cout << dp[n][w] << endl;
	
	
	return 0;
}


Measured memory_bytes: 87296
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        int ans = 0;
        if (a + b > 23) ans = a + b - 24;
        else ans = a + b;
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long ll;

int		str_cmp(const void *s1, const void *s2)
{
	return strcmp(*(char **)s1, *(char **)s2);
}

int main()
{
	int N;
	scanf("%d", &N);
	char str[N][11];
	int p[N];
	char **sort;
	sort = (char**)malloc(sizeof(char*) * N);
	int i = 0;
	int len;
	while (i < N)
	{
		scanf("%s", str[i]);
		scanf("%d", &p[i]);
		len = strlen(str[i]);
		sort[i] = (char*)malloc(sizeof(char) * (len + 1));
		strcpy(sort[i], str[i]);
		i++;
	}
	qsort(sort, N, sizeof *sort, str_cmp);
	i = 0;
	int n;
	int j,k;
	int max = -1;
	int index;
	while (i < N)
	{
		n = 0;
		j = 0;
		while (j < N)
		{
			if (strcmp(sort[i], str[j]) == 0)
			{
				k = 0;
				max = -1;
				while (k < N)
				{
					if (strcmp(str[j], str[k]) == 0)
					{
						if (p[k] > max)
						{
							max = p[k];
							index = k;
						}
					}
					k++;
				}
			}
			j++;
		}
		printf("%d\n", index + 1);
		p[index] = -1;
		i++;
	}
	return (0);
}


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

int Lcs(string X, string Y) {
  vector< vector<int> > dp(X.size() + 1, vector<int>(Y.size() + 1));
  X = ' ' + X, Y = ' ' + Y;
  for (int i = 1; i <= X.size() - 1; ++i) {
    for (int j = 1; j <= Y.size() - 1; ++j) {
      if (X[i] == Y[j])
        dp[i][j] = dp[i - 1][j - 1] + 1;
      else
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    }
  }
  return dp[X.size() - 1][Y.size() - 1];
}

int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    string X, Y;
    cin >> X >> Y;
    cout << Lcs(X, Y) << endl;
  }
}


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

int main() {
  int i, j;
  int x = 0;
  int k = 0;
  string s;
  cin >> i;
  for(j=0;j<i;j++){
	cin >> s[j];
  }
  for(j=0;j<i;j++){
	if(s[j]=='P'){
      k++;
    } 
  }
	if(k>0) x+=1;   
  k = 0;
  for(j=0;j<i;j++){
	if(s[j]=='G'){
      k++;
    } 
  }
	if(k>0) x+=1; 
  k = 0;
  for(j=0;j<i;j++){
	if(s[j]=='W'){
      k++;
    } 
  }
	if(k>0) x+=1;
  k = 0;
  for(j=0;j<i;j++){
	if(s[j]=='Y'){
      k++;
    } 
  }
	if(k>0) x+=1;    
  k = 0;
  if(x == 4) cout << "Four";
  if(x == 3) cout << "Three";
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Node{
    Node prev;
    Node next;
    int value;
    public Node(Node p,Node n,int v){
        prev=p;
        next=n;
        value=v;
    }
}
class DoublyLinkedList{
    Node n;
    public DoublyLinkedList(){
        this.n=new Node(null,null,0);
        this.n.next=this.n;
        this.n.prev=this.n;
    }
    public void insert(int v){
        Node node=new Node(this.n,this.n.next,v);
        this.n.next.prev=node;
        this.n.next=node;
        if(node.next==n)
            n.prev=node;
    }
    public void delete(int v){
        Node search=n.next;
        boolean done=false;
        while(!done && search!=n){
            if(search.value==v){
                search.prev.next=search.next;
                search.next.prev=search.prev;
                done=true;
            }
            else
                search=search.next;
        }
    }
    public void deleteFirst(){
        n.next.next.prev=n;
        n.next=n.next.next;
    }
    public void deleteLast(){
        n.prev.prev.next=n;
        n.prev=n.prev.prev;
    }
    public void printlist(){
        PrintWriter out = new PrintWriter(System.out);
        Node output=n.next;
        while(output.next!=n){
         out.print(output.value+" ");
            output=output.next;
        }
        out.print(output.value);
        out.println();
        out.flush();
    }
}
public class Main {
    public static void main(String[] args){
        DoublyLinkedList dll=new DoublyLinkedList();
        Scanner scanner=new Scanner(System.in);
        int n=Integer.parseInt(scanner.next());
        String[] commands={"insert","delete","deleteFirst","deleteLast"};
        String command;
        int value;
        for(int i=0;i<n;i++){
            command=scanner.next();
            if(command.equals(commands[0])){
                value=Integer.parseInt(scanner.next());
                dll.insert(value);
            }
            else if(command.equals(commands[1])){
                value=Integer.parseInt(scanner.next());
                dll.delete(value);
            }
            else if(command.equals(commands[2])){
                dll.deleteFirst();
            }
            else if(command.equals(commands[3])){
                dll.deleteLast();
            }
        }
        dll.printlist();
    }
}



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

const int MOD = 1e+9 + 7;


int main()
{
    long long N;
    cin >> N;

    // dp[i][j]: a と b の i bit 目以上が決定していて
    //           その段階で (v >> i) = (N >> i) - j となる通り数
    long long dp[61][3] = {};  // 10^{18} < 2^{60} より最大値は 60
    dp[60][0] = 1;
    for( int i = 59; i >=0; --i ){
        if( N & (1LL << i) ){
            dp[i][0] = dp[i+1][0];
            dp[i][1] = dp[i+1][0] + dp[i+1][1];
            dp[i][2] = 2*dp[i+1][1] + 3*dp[i+1][2];
        }else{
            dp[i][0] = dp[i+1][0] + dp[i+1][1];
            dp[i][1] = dp[i+1][1];
            dp[i][2] = dp[i+1][1] + 3*dp[i+1][2];
        }
        for( int j = 0; j < 3; ++j ) dp[i][j] %= MOD;
    }

    int ans = 0;
    for( int j = 0; j < 3; ++j ){
        ans += dp[0][j];
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader

fun main() {
    val br = System.`in`.bufferedReader()
    val n = br.readInt()
    val sieve = IntArray(n + 1) { -1 }
    var sum = 1L
    for (x in 2..n) {
        if (sieve[x] == -1) {
            sieve[x] = x
            if (x < 3163) {
                var y = x * x
                while (y <= n) {
                    sieve[y] = x
                    y += x
                }
            }
        }
        var numFactors = 1L
        var num = x
        while (sieve[num] != -1) {
            val p = sieve[num]
            var ct = 0
            while (num % p == 0) {
                num /= p
                ct++
            }
            numFactors *= (ct + 1)
        }
        sum += x * numFactors
    }
    print(sum)
}

private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val NL_INT = '\n'.toInt()

private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }

    while (read <= SPACE_INT && read != -1 && read != NL_INT) {
        mark(1)
        read = read()
    }
    if (read > SPACE_INT) {
        reset()
    }
    return if (neg) -ret else ret
}

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

using namespace std;

const int N = 1e5 + 7;

int a[N];
int dp[N];

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

	int n;

	cin >> n;

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

	dp[n-1] = 0;
	dp[n-2] = abs(a[n-2] - a[n-1]);

	for(int i = n-3; i >= 0; i--){
		dp[i] = min(dp[i+1] + abs(a[i] - a[i+1]), dp[i+2] + abs(a[i] - a[i+2]));
	}

	cout << dp[0] << "\n";

	return 0;
}

Measured memory_bytes: 1024
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define rall(x) x.rbegin() , x.rend()
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <ll , ll>;
void in(ll &x);
// const ll N = ;
#define singleCase
// #define multipleCase
ll n;

ll modular(ll x , ll m) {
   return ((x % m) + m) % m;
}

void work() {
   in(n);
   vector <ll> v(n);
   ll sum = 0;
   for (ll i = 0 ; i < n ; i++) {
      in(v[i]);
      sum += v[i];
   }
   bool pos = sum % ((n * (n + 1)) / 2) == 0;
   ll opt = sum / ((n * (n + 1)) / 2);
   ll tota = 0, totb = 0;
   for (ll i = 0 ; i < n ; i++) {
      ll cur = v[(i + 1) % n] - v[i];
      if ((opt - cur) % n != 0) pos = false;
      ll a = (opt - cur) / n;
      ll b = opt - a;
      if (a < 0 || b < 0) pos = false;
      tota += a, totb += b;
   }
   if (tota != opt || totb != (n - 1) * opt) pos = false;
   puts(pos ? "YES" : "NO");
   return;
}

int main() {
   #ifdef multipleCase
      ll nQ; in(nQ);
      while (nQ--)
         work();
   #endif
   #ifdef singleCase
      work();
   #endif
   return 0;
}

void in(ll &x) {
	bool neg = false;
	register ll c;
	x = 0;
	c = getchar();
	if(c == '-') {
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	  x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


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

int main(){
    int n;
    cin>>n;
    string line;
    cin>>line;
    int counte=0,countw=0;
    for(int i=0;i<n;i++){
        if(line[i]=='E'){
            counte++;
        }
    }
    int mindif=300006;
    for(int i=0;i<n;i++){
        int ans=counte+countw;
        if(line[i]=='E'){
            ans--;
        }
        if(ans<mindif){
            mindif=ans;
        }
        if(line[i]=='E'){
            counte--;
        }
        if(line[i]=='W'){
            countw++;
        }
    }
    cout<<mindif;
    return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

constexpr double concentration(double a,double b){
  return (b==0.0?0:100.0*b/(a+b));
}
constexpr double func(double a,double e){
  return a*e/(100-e);
}

main(){
  double a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  a*=100.0;
  b*=100.0;
  vector<double> x,y;
  for(double i=0.0;i*a<=f;++i)
    for(double j=0.0;j*b+i*a<=f;++j)
      x.emplace_back(a*i+b*j);
  for(double i=0.0;i*c<=f;++i)
    for(double j=0.0;j*d+i*c<=f;++j)
      y.emplace_back(c*i+d*j);
  // e = 100*b/(a+b)
  // (a+b)e = 100*b
  // ae+be = 100b
  // ae = 100b-be
  // ae = b(100-e)
  // ae/(100-e) = b
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());

  double ansx = 0.0;
  double ansy = 0.0;
  double ansc = 0.0;
  for(auto const& water:x){
    for(auto const& sugar:y){
      if(water+sugar>f)break;
      double conce = concentration(water,sugar);
      if(water/100.0*e<sugar)break;
      if(chmax(ansc,conce)){
        ansx = water;
        ansy = sugar;
      }
    }
  }
  cout<<(ansx+ansy==0?(a<f?a:b):(ansx+ansy))<<" "<<ansy<<endl;
}

void _main(){

  double a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  a*=100.0;
  b*=100.0;

  double ans1=0.0,ans2=0.0,tmp=0.0;
  for(double i=0.0;i*a<=f;++i){
    for(double j=0.0;i*a+j*b<=f;++j){
      for(double k=0.0;i*a+j*b+k*c<=f;++k){
        for(double l=0.0;i*a+j*b+k*c+l*d<=f;++l){
          if(i==0&&j==0)break;
          double g = concentration(a*i+b*j,c*k+d*l);
          if(g>e)break;
          if(a*i+b*j<c*k+d*l)break;
          if(chmax(tmp,g)){
            ans1=a*i+b*j+c*k+d*l;
            ans2=c*k+d*l;
          }
        }
      }
    }
  }
  cout<<(ans1)<<" "<<(ans2)<<endl;

}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 110;
const int MAX_K = 100100;
const int MOD = 1e9+7;
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);
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto& e : a) cin >> e;
    
    ModInt<MOD> dp[MAX_N][MAX_K];
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        ModInt<MOD> sum[MAX_K];
        for (int j = 0; j <= k; j++) {
            sum[j+1] = sum[j]+dp[i][j];
        }
        for (int j = 0; j <= k; j++) {
            dp[i+1][j] = sum[j+1]-sum[max(0, j-a[i])];
        }
    }
    
    cout << dp[n][k] << endl;
    return 0;
}

Measured memory_bytes: 43648
m=10**9+7
s=list(input())
n=len(s)
s.reverse()
dp=[[0]*13 for _ in range(n)]
if s[0]=="?":
    for i in range(10):
        dp[0][i]+=1
else:
    dp[0][int(s[0])]=1
x=1
for i in range(1,n):
    x=(x*10)%13
    for j in range(13):
        if s[i]=="?":
            if dp[i-1][j]!=0:
                for k in range(10):
                    dp[i][(j+k*x)%13]+=dp[i-1][j]
                    dp[i][j]%=m
        else:
            if dp[i-1][j]!=0:
                dp[i][(j+int(s[i])*x)%13]+=dp[i-1][j]
                dp[i][j]%=m
print(dp[n-1][5]%m)

Measured memory_bytes: 64888
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string.h>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int n, ma, mb;
int a[40], b[40], c[40];

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

int dp[41][401][401];


int main(void) {
	cin >> n >> ma >> mb;
	int max_c = 1000000;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i = 0; i <= 40; i++) {
		for (int j = 0; j <= 400; j++) {
			for (int k = 0; k <= 400; k++) {
				dp[i][j][k] = max_c + 1;
			}
		}
	}
	dp[0][0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 400; j++) {
			for (int k = 0; k <= 400; k++) {
				if (dp[i][j][k] == max_c + 1) {
					continue;
				}
				//iを選ばない
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
				//iを選ぶ
				dp[i + 1][j + a[i]][k + b[i]] = 
					min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
			}
		}
	}
	int ans = max_c + 1;
	for (int i = 1; i <= 400; i++) {
		for (int j = 1; j <= 400; j++) {
			if (i * mb == j * ma) {
				ans = min(ans, dp[n][i][j]);
			}
		}
	}
	if (ans == max_c + 1) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 25984
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>

using namespace std;
int factorial(int x){
    if(x<=1)return 1;
    return factorial(x-1)*x;
}
int main(){
    int n;
    cin>>n;
    vector<int>p(n),q(n);
    for(int i=0;i<n;i++)cin>>p[i];
    for(int i=0;i<n;i++)cin>>q[i];
     vector<int>a(n);
    for(int i=0;i<n;i++)a[i]=i+1;
    map<vector<int>,int>mp;
    do{
        mp[a]=mp.size();
    }while(next_permutation(a.begin(),a.end()));
    int ans=abs(mp[p]-mp[q]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18

using namespace std;

ll binomialCoeff(ll n,ll k);
ll power(ll x,ll y);

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

int mod(int a,int b)
{
    if(a>b)
        return a-b;
    return b-a;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int n,k;
    cin >> n >>k;
    ll dp[N];
    int h[n+1];
    for(int i=1;i<=n;i++)
        cin >> h[i];
    for(int i=1;i<=n;i++)
        dp[i] = inf;
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j<=0)
                break;
            dp[i] = min(dp[i] , dp[i-j] + mod(h[i],h[i-j]) );
        }
    }
    cout << dp[n];
}

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}


Measured memory_bytes: 1408
#include<stdio.h>

struct Card{
  char mark;
  char value;
};

void bubble(struct Card A[], int n){
  int i, j;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    for ( j = n-1; j >= i+1; j-- ){
      if ( A[j].value < A[j-1].value ){
	t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int n){
  int i, j, mini;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    mini = i;
    for ( j = i; j < n; j++ ){
      if ( A[j].value < A[mini].value ) mini = j;
    }
    t = A[i]; A[i] = A[mini]; A[mini] = t;
  }
}

int isStable(struct Card C1[], struct Card C2[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( C1[i].mark != C2[i].mark) return 0;
  }
  return 1;
}  

void print(struct Card A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i ) printf(" ");
    printf("%c%c", A[i].mark, A[i].value);
  }
  printf("\n");
}


int main(){
  struct Card C1[101], C2[101];
  int n, i;
  char ch;

  scanf("%d\n", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c ", &C1[i].mark, &C1[i].value);
  }

  for ( i = 0; i < n; i++ ) C2[i] = C1[i];

  bubble(C1, n);
  selection(C2, n);

  print(C1, n);
  printf("Stable\n");
  print(C2, n);
  if ( isStable(C1, C2, n) ){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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;}
ll mod= 1e9 + 7;



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

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {

int h,w;
while(1)
{
cin>>h>>w;
if(h==0&&w==0)break;
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
if(i==0||i==h-1||j==0||j==w-1)cout<<"#";
else cout<<".";
}
cout<<endl;
}
cout<<endl;
}
}



Measured memory_bytes: 3100
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int INF = 1 << 20;
int n,m;
int cost[111][111];
bool used[111];
int d[111];
int main(void)
{
  while(1){
    cin >> n >> m;
    if(!n && !m) break;

    for(int i = 1; i <= n; i++){
      fill(cost[i], cost[i] + n + 1, INF);
    }

    for(int i = 0; i < m; i++){
      int f;
      cin >> f;
      if(f){
	int a,b,c;
	cin  >> a >> b >> c;
	cost[a][b] = cost[b][a] = min(cost[a][b],c);
      }else{
	int a,b;
	cin >> a >> b;
	memset(used,false,sizeof(used));
	fill(d,d + n + 1, INF);
	d[a] = 0;

	while(1){
	  int v = 0;
	  for(int j = 1; j <= n; j++){
	    if(used[j]) continue;
	    if(!v || d[j] < d[v]) v = j;
	  }
	  if(!v) break;
	  used[v] = true;
	  for(int j = 1; j <= n; j++){
	    d[j] = min(d[j],d[v] + cost[v][j]);
	  }
	}

	cout << ((d[b] == INF)?-1:d[b]) << endl;
      }
    }
  }
}

Measured memory_bytes: 1208
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 h, w;
  scanf ("%" SCNi32 "%" SCNi32, &h, &w);
  char *a = (char *) calloc (h * w + 1, sizeof (char));
  for (i32 i = 0; i < h; ++i) {
    scanf ("%s", a + i * w);
  }
  char *r = (char *) calloc (h * w, sizeof (char));
  char *b = (char *) calloc (h * w, sizeof (char));
  for (i32 j = 0; j < w; ++j) {
    r[j] = '#';
    b[j] = '.';
    r[(h - 1) * w + j] = '.';
    b[(h - 1) * w + j] = '#';
  }
  for (i32 i = 1; i < h - 1; ++i) {
    int c = '#';
    for (i32 j = 0; j < w; j ++, c ^= '#' ^ '.') {
      r[i * w + j] = c;
      b[i * w + j] = c ^ '#' ^ '.';
    }
  }
  for (i32 i = 0; i < h * w; ++i) {
    if (a[i] == '#') {
      r[i] = b[i] = '#';
    }
  }
  for (i32 i = 0; i < h; ++i) {
    for (i32 j = 0; j < w; ++j) {
      putchar (r[i * w + j]);
    }
    putchar ('\n');
  }
  puts ("");
  for (i32 i = 0; i < h; ++i) {
    for (i32 j = 0; j < w; ++j) {
      putchar (b[i * w + j]);
    }
    putchar ('\n');
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 1408
X = int(input())

if X%7 == 4:
    print("mon")
elif X%7 == 5:
    print("tue")
elif X%7 == 6:
    print("wed")
elif X%7 == 0:
    print("thu")
elif X%7 == 1:
    print("fri")
elif X%7 == 2:
    print("sat")
elif X%7 == 3:
    print("sun")


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

int main()
{
    long n,i,j,k;
    cin>>n;
    long A[3][n+1];
    A[0][0]=A[1][0]=A[2][0]=0;
    for(i=1;i<=n;i++)
        cin>>A[0][i]>>A[1][i]>>A[2][i];

    long long dp[3][n+1];
    memset(dp,0,sizeof(dp));
    for(i=1;i<=n;i++)
    {
        dp[0][i]=max(dp[1][i-1],dp[2][i-1])+A[0][i];
        dp[1][i]=max(dp[0][i-1],dp[2][i-1])+A[1][i];
        dp[2][i]=max(dp[0][i-1],dp[1][i-1])+A[2][i];
    }
    cout<<max(dp[0][n],max(dp[1][n],dp[2][n]))<<endl;
}

Measured memory_bytes: 4992
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n + k + 2];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        // dp[i] ... 足場iに辿りつくまでに支払うこすとの最小値
        long[] dp = new long[n + k + 2];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 1; j <= k; j++) {
                dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(arr[i + j] - arr[i]));
            }
        }
//        debug(dp);
        System.out.println(dp[n - 1]);

    }


    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 54252
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
using ull = uint_fast64_t;
using ld = long double;
#define rep(i, n) for (ull i = 0; i < n; ++i)
#define rep1(i, n) for (ull i = 1; i < n; ++i)
ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }
template <typename T> void vecout(const T &v) {
  for (auto it = v.begin(); it != v.end();
       ++it, cout << (it != v.end() ? " " : "\n")) {
    cout << *it;
  }
}

void solve() {
  // main coding
  ll n,w; cin>>n>>w;
  vector<ll> W(n+1),V(n+1);
  rep1(i,n+1) cin>>W[i]>>V[i];

  vector<vector<ll>> dp(n+1,vector<ll>(w+1,0));
  for(ll i=1;i<=n;++i) for(ll c=0;c<=w;++c) {
    if(c-W[i]>=0) dp[i][c]=max(dp[i-1][c],dp[i-1][c-W[i]]+V[i]);
    else dp[i][c]=dp[i-1][c];
  }
  cout<<dp[n][w]<<endl;
}

int main() {
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 80256
#include"bits/stdc++.h"
using namespace std;

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

    int count = 0;
    for (int i = 0; i < N-2; i++) {
        if (S.substr(i, 3) == "ABC") {
            count++;
            i += 2;
        }
    }

    cout << count << endl;
    
    return 0;
}

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

int main(){
	int a,b,c,cnt=0;
	cin >> a >> b >> c;
	for(int i=a;i<=b;i++){
		if(c%i == 0){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}


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

using namespace std;

const int vy[] = {0, 1, 0, -1}, vx[] = {1, 0, -1, 0};
const string temp = "RDLU";

const int mask = (1 << 18) - 1;

int H, W, P, sx, sy;
string S[50], V[10];

int solve()
{

  queue< tuple< int, int, int, int > > que;
  int min_cost[50][50][10][10];
  memset(min_cost, -1, sizeof(min_cost));
  que.emplace(sx, sy, 0, 0);
  min_cost[sx][sy][0][0] = 0;

  while(!que.empty()) {
    int x, y, a, b;
    tie(x, y, a, b) = que.front();
    que.pop();
    string pat = V[a].substr(0, b);
    bool f = true;
    for(int i = 0; i < P; i++) f &= pat.find(V[i]) == string::npos;
    if(!f) continue;
    if(S[y][x] == 'G') return (min_cost[x][y][a][b]);
    for(int i = 0; i < 4; i++) {
      int nx = x + vx[i], ny = y + vy[i];
      if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
      if(S[ny][nx] == '#') continue;
      string nextpat = pat + string(1, temp[i]);
      bool match = false;
      for(int j = 0; j < nextpat.size(); j++) {
        string st = nextpat.substr(j);
        for(int k = 0; k < P; k++) {
          if(V[k].find(st) == 0) {
            if(min_cost[nx][ny][k][st.size()] == -1) {
              que.emplace(nx, ny, k, st.size());
              min_cost[nx][ny][k][st.size()] = min_cost[x][y][a][b] + 1;
            }
            match = true;
            break;
          }
        }
        if(match) break;
      }
      if(!match && min_cost[nx][ny][0][0] == -1) {
        que.emplace(nx, ny, 0, 0);
        min_cost[nx][ny][0][0] = min_cost[x][y][a][b] + 1;
      }
    }
  }
  return (-1);
}

int main()
{

  while(cin >> H >> W, H) {
    for(int i = 0; i < H; i++) {
      cin >> S[i];
      for(int j = 0; j < W; j++) {
        if(S[i][j] == 'S') sx = j, sy = i;
      }
    }
    cin >> P;
    for(int i = 0; i < P; i++) {
      cin >> V[i];
    }
    cout << solve() << endl;
  }
}

Measured memory_bytes: 4256
#include <stdio.h>
int main(){
  int n,ans=0;
  scanf("%d",&n);
  if	 ( n >= 64 ){ ans=64; }
  else if( n >= 32 ){ ans=32; }
  else if( n >= 16 ){ ans=16; }
  else if( n >=  8 ){ ans= 8; }
  else if( n >=  4 ){ ans= 4; }
  else if( n >=  2 ){ ans= 2; }
  else				{ ans= 1; }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 1724
#include<cstdio>
#include<algorithm>
using namespace std;
int n,i,j,k,a[105],seq[105];
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
	{
		for(j=n-i+1;j>0;j--)
		{
			if(a[j]==j)
			{
				seq[i]=j;
				for(k=j;k<=n-i;k++)a[k]=a[k+1];
				goto tag;
			}
		}
		printf("-1\n");
		return 0;
		tag:;
	}
	for(i=n;i>0;i--)printf("%d\n",seq[i]);
	return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var a =  IntArray(n)
    for (i in 0 until n) {
        a[i] = readLine()!!.toInt()
    }
    val max = a.max()!!
    val second = a.sorted()[n - 2]
    a.forEach {
        (if (it == max) second else max ).let { println(it) }
    }

}

Measured memory_bytes: 53164
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll a;
  string s;
  cin >> a >> s;
  if(a>=3200) pr(s);
  else pr("red");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <iostream>
#define INF 1000000
using namespace std;

int N, W;
int _dp[110][10010];
int v[110];
int w[110];

int dp(int num,int weight){
	if(_dp[num][weight]) return _dp[num][weight];
	if(num == 0 || weight == 0){
		return 0;
	}
	int max = dp(num-1,weight);
	if(weight >= w[num-1]){
		int t = dp(num-1,weight-w[num-1])+v[num-1];
		if(max < t) max = t;
	}
	_dp[num][weight] = max;
	return max;
}

int main(void){
	cin >> N >> W;
	
	for(int i=0; i<N; i++) cin >> v[i] >> w[i];
	
	cout << dp(N,W) << endl;
	
	return 0;
}


Measured memory_bytes: 6844
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif
#define sz(a) (int)a.size()
#define found(m,x) ((m).find(x)!=(m).end())
#define uset unordered_set
#define umap unordered_map
#define a(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<(int)n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<=(int)n:i>=(int)n;k<n?i++:i--)
#define input(v,n) fo(i,n)cin>>v[i]
using vi = vector<int>;
using vpi = vector<pair<int,int>>;
using pi = pair<int,int>;

const int nax = 1e5+7;
const int mod = 1e9+7; //1e9+2667 :: 0xcf : inf, 0xc0 -inf
const int inf = numeric_limits<int> :: max() - (int)9e6;
// ===================== MANASH =================== //

int n;

void test() {

    int m;
    cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2;
}

signed main() {

    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    #ifdef LOCAL
    freopen("input.txt","r",stdin);
    #endif

    int T = 1;
    //cin >> T;
    while(T--) {
        test();
        cout << "\n";
    }
    return 0;

}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n,m=0;
	int a[15];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%2==0) m++;
	}
	cout<<pow(3,n)-pow(2,m)<<endl;
}


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

std::vector<int> vec;

int n,tmp;

int main(){

    std::cin>>n;

    for(int i=0;i<n;i++){
        std::cin>>tmp;
        vec.push_back(tmp);
    }

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

    std::cout<<vec[n/2]-vec[n/2-1]<<std::endl;
    
    return 0;
}

Measured memory_bytes: 892
#include<iostream>
using namespace std;
int main()
{
for(;;){
int n,ans=0;
cin >> n;
if(n==0)return 0;
n=1000-n;
while(n>=500){
n-=500;
ans++;
}
while(n>=100){
n-=100;
ans++;
}
while(n>=50){
n-=50;
ans++;
}
while(n>=10){
n-=10;
ans++;
}
while(n>=5){
n-=5;
ans++;
}
while(n>=1){
n-=1;
ans++;
}
cout<< ans << "\n";
}
}

Measured memory_bytes: 1160