akhauriyash/Code-Regression huggingface dataset:
n, k = gets.split.map(&:to_i)
l = Array.new(10){ Array.new }
n.times do
  p, q = gets.split.map(&:to_i)
  l[q-1] << p
end
l.each{|arr| arr.sort!.reverse! }
dp = Array.new(2){ Array.new(n, 0) }
10.times do |i|
  (0..k).each do |j|
    dp[i%2][j] = [dp[i%2][j], dp[i%2^1][j]].max
    s = 0
    l[i].size.times do |m|
      break if j + m + 1 > k
      s += l[i][m]
      dp[i%2][j+m+1] = [dp[i%2][j+m+1], dp[i%2^1][j] + s + m*(m+1)].max
    end
  end
end
p dp[1][k]

Measured memory_bytes: 8816
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll A, V, B, W, T;
    cin >> A >> V >> B >> W >> T;

    if ((V - W) * T >= abs(A - B)) {
        print("YES");
    } else {
        print("NO");
    }
    
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a;
    vector<P> v;
    For(i, 1, n) {
        cin >> a;
        v.pb({a, i});
    }
    sort(all(v));
    rep (i, n - 1) { cout << v[i].second << " "; }
    cout << v[n - 1].second << endl;

    return 0;
}


Measured memory_bytes: 2544
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
//ll lin(){ll x;scanf("%d",&x);return x;}
int main(){
    string s;
    cin>>s;
    char tmp1= s.at(0);
    char tmp2='0';
    int id=1;
    int ans1=1;
  //  cout<<s[0]<<" ";
    while(id<s.length()){
        if(tmp1==s[id]&tmp2=='0'){
            if(id<s.length()-1){
                tmp1=s[id];
                tmp2=s[id+1];
                id++;
            }else{
                ans1--;
            }
          //  cout<<tmp1<<tmp2<<" ";
        }else{
            tmp1=s[id];
            tmp2='0';
       //     cout<<tmp1<<" ";
        }
        id++;
        ans1++;
    }
   // cout<<endl<<ans1<<endl;
    
    tmp1= s.at(0);
    tmp2=s[1];
    id=2;
    int ans2=1;
    //cout<<s[0]<<s[1]<<" ";
    while(id<s.length()){
        if(tmp1==s[id]&tmp2=='0'){
            if(id<s.length()-1){
                tmp2=s[id+1];
                id++;
            }
            else{
                ans2--;
            }
         //   cout<<tmp1<<tmp2<<" ";
        }else{
            tmp1=s[id];
            tmp2='0';
            //cout<<tmp1<<" ";
        }
        id++;
        ans2++;
    }
    //cout<<endl<<ans2<<endl;
    cout<<max(ans1,ans2)<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c;
    cin >> a >> b >> c;

    if (a <= c && c <= b)
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256
// ダイス１
#include <stdio.h>

int main(void){
  int dai[7], dai2[7];
  int i, j=0;
  char direc[101];

  scanf("%d %d %d %d %d %d", &dai[0], &dai[1], &dai[2], &dai[3], &dai[4], &dai[5]);
  for(i=0;i<7;i++)
    dai2[i] = dai[i];

  scanf("%s", direc);

  while(direc[j]!='\0'){
    if(direc[j] == 'S'){
      dai2[0] = dai[4];
      dai2[1] = dai[0];
      dai2[4] = dai[5];
      dai2[5] = dai[1];
    }
    if(direc[j] == 'E'){
      dai2[0] = dai[3];
      dai2[2] = dai[0];
      dai2[3] = dai[5];
      dai2[5] = dai[2];
    }
    if(direc[j] == 'N'){
      dai2[0] = dai[1];
      dai2[1] = dai[5];
      dai2[4] = dai[0];
      dai2[5] = dai[4];
    }
    if(direc[j] == 'W'){
      dai2[0] = dai[2];
      dai2[2] = dai[5];
      dai2[3] = dai[0];
      dai2[5] = dai[3];
    }
    for(i=0;i<7;i++)
      dai[i] = dai2[i];
    j++;
  }
  printf("%d\n", dai[0]);
  return 0;

}



Measured memory_bytes: 2036
#include<cstdio>
int A,B,n;
int num[5],tot;
long long ans;
bool plus()
{
	num[0]++;
	tot++;
	for(int i=0;i<=4;++i)
		if(num[i]==10)
		{
			num[i+1]++;
			num[i]=0;
			tot-=9;
		}
	if(tot>=A&&tot<=B)
		return 1;
	return 0;
}
int main()
{
	scanf("%d%d%d",&n,&A,&B);
	for(int i=1;i<=n;++i)
	{
		if(plus())
			ans+=(long long)i;
	}
	printf("%d\n",ans);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define int long long 

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

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

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

  string t = "AKIHABARA";

  int i = 0;
  rep(j, t.size()){
    if(i < s.size() and t[j] == s[i]) i++;
    else if(t[j] == 'A') ;
    else{
      cout << "NO" << endl;
      return 0;
    }
  }

  if(i != s.size()){
    cout << "NO" << endl;
    return 0;
  }

  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <vector>
#include <fstream>
#include <math.h>
using namespace std;

int main()
{
    int N;
    cin>>N;
    int ans=1;
    for (ans = 1; ans * (ans + 1) / 2 < N; ans++);
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(void){
  int n;
  int Acard[10000], Bcard[10000];

  while(1){
    int playerA = 0, playerB = 0;
    std::cin >> n;
    if(n == 0)  return 0;

    for(int i=0; i < n ; i++){
      std::cin >> Acard[i]; std::cin >> Bcard[i];
    }

    for(int i=0; i < n; i++){
      if(Acard[i] == Bcard[i]){
        playerA += Acard[i];  playerB += Bcard[i];
      }else if(Acard[i] > Bcard[i]){
        playerA += Acard[i] + Bcard[i];
      }else{
        playerB += Acard[i] + Bcard[i];
      }
    }

    std::cout << playerA << " " << playerB << std::endl;
  }
}

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

int main()
{
  char c[3][3];
  for(int i = 0;i < 3;i++){
    for(int j = 0;j < 3;j++){
      cin >> c[i][j];
    }
  }
  cout << c[0][0] << c[1][1] << c[2][2] << endl;

  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long L;
L n,sum=0,idx;
char res[20];
void encode(char st[]){
    L l=strlen(st);
    for(L i=0;i<l;i++){
        if(st[i]=='m'){
            if(i>0){
                if(st[i-1]>='2'&&st[i-1]<='9'){
                    L d=st[i-1]-'0';
                    sum+=(1000*d);
                    st[i-1]='f';
                }
                else sum+=1000;
                st[i]='f';
            }
            else{
                sum+=1000;st[i]='f';
            }
        }
        else if(st[i]=='c'){
            if(i>0){
                if(st[i-1]>='2'&&st[i-1]<='9'){
                    L d=st[i-1]-'0';
                    sum+=(100*d);
                    st[i-1]='f';
                }
                else sum+=100;
                st[i]='f';
            }
            else{
                sum+=100;st[i]='f';
            }
        }
        else if(st[i]=='x'){
            if(i>0){
                if(st[i-1]>='2'&&st[i-1]<='9'){
                    L d=st[i-1]-'0';
                    sum+=(10*d);
                    st[i-1]='f';
                }
                else sum+=10;
                st[i]='f';
            }
            else{
                sum+=10;st[i]='f';
            }
        }
        else if(st[i]=='i'){
            if(i>0){
                if(st[i-1]>='2'&&st[i-1]<='9'){
                    L d=st[i-1]-'0';
                    sum+=(1*d);
                    st[i-1]='f';
                }
                else sum+=1;
                st[i]='f';
            }
            else{
                sum+=1;
                st[i]='f';
            }
        }
    }
}
void decode(){
    L d=sum/1000;
    if(d){
        if(d>1){
            res[idx++]=d+'0';
            res[idx++]='m';
        }
        else{
            res[idx++]='m';
        }
    }
    sum%=1000;
    d=sum/100;
    if(d){
        if(d>1){
            res[idx++]=d+'0';
            res[idx++]='c';
        }
        else{
            res[idx++]='c';
        }
    }
    sum%=100;
    d=sum/10;
    if(d){
        if(d>1){
            res[idx++]=d+'0';
            res[idx++]='x';
        }
        else{
            res[idx++]='x';
        }
    }
    sum%=10;
    d=sum/1;
    if(d){
        if(d>1){
            res[idx++]=d+'0';
            res[idx++]='i';
        }
        else{
            res[idx++]='i';
        }
    }
    res[idx]='\0';
}
int main(){
    scanf("%lld",&n);
    char st[20],stt[20];
    while(n--){sum=idx=0;
        scanf("%s",st);scanf("%s",stt);
        encode(st);
        encode(stt);
        decode();
        cout<<res<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3168
//package atcoder.beginner_172;

import java.io.*;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main (String[] args) throws Exception {

        String s = "1 4 1000000000\n" +
                "2 1000000000\n" +
                "999999999 1 1 1";

//        br = new BufferedReader(new StringReader(s));
        br = new BufferedReader(new InputStreamReader(System.in));
        bw = new BufferedWriter(new OutputStreamWriter(System.out));

        rl(); int N=nin(), M=nin(); long K=nlo();
        rl(); long A[]=new long[N]; A[0] = nlo(); for (int i=1; i<N; ++i) A[i]=A[i-1]+nlo();
        rl(); long B[]=new long[M]; B[0] = nlo(); for (int i=1; i<M; ++i) B[i]=B[i-1]+nlo();

        int c=Arrays.binarySearch(B, K);
        if (c<0) c=-c-1; else ++c;
        for (int i=0; i<N && A[i]<=K; ++i) {
            if (K-A[i]>=0) {
                int j=Arrays.binarySearch(B, (K-A[i]));
                if (j<0) j=-j-2;
                c=Math.max(c, i+j+2);
            }
        }

        bw.write(Integer.toString(c));
        bw.newLine();
        bw.flush();

    }

    static BufferedReader br;
    static BufferedWriter bw;
    static StringTokenizer st;
    static void rl() throws Exception{
        st = new StringTokenizer(br.readLine());
    }
    static long nlo(){
        return Long.parseLong(st.nextToken());
    }
    static int nin(){
        return Integer.parseInt(st.nextToken());
    }
    /*private static void te(){
      }*/
    static double ndo(){
        return Double.parseDouble(st.nextToken());
    }
    static char[] nca(){
        return st.nextToken().toCharArray();
    }
    static String nstr(){
        return st.nextToken();
    }
}

Measured memory_bytes: 60432
#include <bits/stdc++.h>
using namespace std;
 
string to_string(string s) {
 return '"' + s + '"';
}

string to_string(const char* ch) {
 return to_string((string)ch);
}

string to_string(char ch) {
 return (string)"'" + ch + (string)"'";
}

string to_string(bool b) {
 return (b ? "true" : "false");
}

template<class A, class B>
string to_string(pair<A, B> p) {
 return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template<class A>
string to_string(A a) {
 string res = "{";
 bool first = true;
 for(const auto& x: a) {
  if(first == false) res += ", ";
  first = false;
  res += to_string(x);
 }
 res += "}";
 return res;
}

void debug() {cerr << "]\n";}

template<class H, class... T>
void debug(H head, T... tail) {
 cerr << to_string(head) << " ";
 debug(tail...);
}

#ifdef LOCAL
 #define debug(...) cerr << "[" << #__VA_ARGS__ << " ] = ["; debug(__VA_ARGS__);
#else 
 #define debug(...) 
#endif

typedef long long ll;

vector<ll> subset_sum;

int main() 
{
 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
 cout.tie(nullptr);
 int n;
 cin >> n;
 int w;
 cin >> w;
 vector<pair<ll, ll>> a(n);
 int t_sum = 0;
 for(auto& i: a) cin >> i.first >> i.second, t_sum += i.second;
 subset_sum.assign(t_sum+1, 1e9);
 subset_sum[0] = 0;
 //for(auto& i: a) {
  //subset_sum[i.second] = min(subset_sum[i.second], i.first);
 //}
 for(int i = 0; i < n; i++) {
  for(int j = t_sum; j >= a[i].second; j--) {
   subset_sum[j] = min(subset_sum[j], subset_sum[j - a[i].second] + a[i].first);
  }
 }
 debug(subset_sum);
 int ans = 0;
 for(int i = t_sum; i >= 1; i--) {
  if(subset_sum[i] <= w) {
   ans = i;
   break;
  }
 }
 cout << ans << '\n';
 return 0;
}


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int a,b,c,d;

int main()
{
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if ((abs(a-c)<=d) || (abs(a-b)<=d && abs(b-c)<=d)) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
long long f(long long b,long long x){return x<b?x:f(b,x/b)+x%b;}
long long g(){
	long long n,s,b=2,r=-1,z;
	scanf("%lld%lld",&n,&s);
	if(n<s)return -1;
	if(n==s)return n+1;
	for(;b*b<=n;b++)if(f(b,n)==s)return b;
	for(b=1;b*b<=n&&b<=s;b++)if((n-s)%b==0&&f(z=(n-s)/b+1,n)==s)r=z;
	return r;
}
int main(){printf("%lld\n",g());}

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a == "5" && b == "7" && c == "5") {
    cout << "YES" << endl;
  }
  else if (a == "5" && c == "7" && b == "5") {
    cout << "YES" << endl;
  }
  else if (b == "5" && a == "7" && c == "5") {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


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

int main()
{
	int i, j, H, W, D, A[301][301], Q, L[100001], R[100001];
	scanf("%d %d %d", &H, &W, &D);
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) scanf("%d", &(A[i][j]));
	}
	scanf("%d", &Q);
	for (i = 1; i <= Q; i++) scanf("%d %d", &(L[i]), &(R[i]));
	
	int pos[90001][2];
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			pos[A[i][j]][0] = i;
			pos[A[i][j]][1] = j;
		}
	}
	
	int k = (H * W + D - 1) / D, **dist = (int**)malloc(sizeof(int*) * (D + 1));
	for (i = 1; i <= D; i++) {
		dist[i] = (int*)malloc(sizeof(int) * k);
		dist[i][0] = 0;
		for (j = 1; j < k && i + j * D <= H * W; j++) dist[i][j] = dist[i][j-1] + abs(pos[i+j*D][0] - pos[i+(j-1)*D][0]) + abs(pos[i+j*D][1] - pos[i+(j-1)*D][1]);
	}
	
	for (i = 1; i <= Q; i++) printf("%d\n", dist[(R[i]-1)%D+1][(R[i]-1)/D] - dist[(L[i]-1)%D+1][(L[i]-1)/D]);
	fflush(stdout);
	return 0;
}

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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pinin=pair<int ,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

string yes="Yes",no="No";

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

}


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

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] line;
      MyList list = new MyList();

      for(int i=0; i<n; i++) {
        line = br.readLine().split(" ");
        switch( line[0] ) {
          case "insert" :
            list.insertFirst( Integer.parseInt(line[1]) );
            break;
          case "delete" :
            list.delete( Integer.parseInt(line[1]) );
            break;
          case "deleteFirst" :
            list.deleteFirst();
            break;
          case "deleteLast" :
            list.deleteLast();
            break;
          default :
            System.out.println("n:" + i + " is failed.");
        }
      }

      System.out.println ( list.getAllElements() );
    }
  }
}

class Node {
  Node next,prev;
  int key;

  public Node(int key) {
    this.key = key;
  }
}

class MyList {
  Node nil;
  Node current;
  int size;

  public MyList() {
    nil = new Node(0);
    nil.next = nil.prev = nil;
    size = 0;
  }

  public String getAllElements() {
    StringBuilder buf = new StringBuilder(size*5);

    if(size > 0){
      current = nil.next;
      for(int i=0; i<size; i++){
        buf.append(current.key).append(" ");
        current = current.next;
      }
    }
    buf.setLength(buf.length()-1);

    return buf.toString();
  }
  public void insertFirst(int x) {
    if(size == 0) {
      current = new Node(x);
      nil.next = current;
      nil.prev = current;
      current.prev = nil;
      current.next = nil;
      size++;
    }
    else {
      Node add = new Node(x);
      
      current.prev.next = add;
      add.prev = current.prev;

      add.next = current;
      current.prev = add;

      current = add;
      size++;
    }
  }
  public void deleteFirst() {
    nil.next = current.next;
    current.next.prev = current.prev;

    current = current.next;
    size--;
  }
  public void deleteLast() {
    current = nil.prev;

    nil.prev = current.prev;
    current.prev.next = current.next;

    current = nil.next;
    size--;
  }
  public void delete(int x) {
    Node target = findFirst(x);

    if(target == nil) current = current.next;
    else {
      current.prev.next = target.next;
      current.next.prev = target.prev;
      current = nil.next;
      size--;
    }
  }
  private Node findFirst(int x) {
    while(current != nil) {
      if(current.key == x) break;
      current = current.next;
    }

    return current;
  }
}


Measured memory_bytes: 189968
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n; cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 > 0 && i % 5 > 0) sum += i;
  }
  outl(sum);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 3196
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define INF 999999999
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long unsigned int ll;
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; }

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


int main()
{
	int n;
	int ans = 0;
	string s;
	cin >> n;
	cin >> s;

	for (int i = 0; i < n-2;i++) {
		if (s[i] == 'A') {
			if (s[i+1] == 'B') {
				if (s[i+2] == 'C') {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

int main()
{

    int r, c;
    cin >> r >> c;

    vector<vector<int>> T(r+1, vector<int>(c+1, 0));

    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> T.at(i).at(j);
        }
    }

    int s = 0;
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            int v = T.at(i).at(j);
            T.at(i).at(c) += v;
            T.at(r).at(j) += v;
            s += v;
            cout << v << " ";
        }
        cout << T.at(i).at(c) << endl;
    }
    for(int i = 0; i < c; i++){
        cout << T.at(r).at(i) << " ";
    }
    cout << s << endl;

}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll t;
  cin >> t;
  while(t--) {
    ll n;
    cin >> n;
    priority_queue<ll,vec,greater<ll>> q;
    ll ans=0;
    mat a(n),b(n+1);
    for(ll i=0;i<n;i++) {
      ll k,l,r;
      cin >> k >> l >> r;
      k--;
      ans+=min(l,r);
      if(l-r>0) {
        a[k].push_back(l-r);
      }
      else if(l-r<0) {
        b[k+1].push_back(r-l);
      }
    }
    for(ll i=0;i<n;i++) {
      for(ll v:a[i]) {
        q.push(v);
      }
      while(q.size()>i+1) q.pop();
    }
    while(q.size()) {
      ans+=q.top();
      q.pop();
    }
    for(ll i=n-1;i;i--) {
      for(ll v:b[i]) {
        q.push(v);
      }
      while(q.size()>n-i) q.pop();
    }
    while(q.size()) {
      ans+=q.top();
      q.pop();
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 18312
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <string>

using namespace std;

int main(){
    int A,B;
    int ret;
    scanf("%d %d", &A, &B);
    if (A < 6){
        ret = 0;
    }else if(A < 13){
        ret = B/2;
    }else{
        ret = B;
    }
    printf("%d\r\n", ret);
    fflush(stdout);
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

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

  if (S[2] == S[3] && S[4] == S[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    ll a[n][3];
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < 3;j++)
        {
            cin >> a[i][j];
        }
    }
    ll dp[n][3] = {a[0][0],a[0][1],a[0][2]};
    for(int i = 1;i < n;i++)
    {
        for(int j = 0;j < 3;j++)
        {
            for(int k = 0;k < 3;k++)
            {
                if(j == k)
                {
                    continue;
                }
                dp[i][k] = max(dp[i][k],dp[i - 1][j] + a[i][k]);
            }
        }
    }
    ll ans = 0;
    for(int i = 0;i < 3;i++)
    {
        if(dp[n - 1][i] > ans)
        {
            ans = dp[n - 1][i];
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		char c[] = str.toCharArray();
		int n = c.length;
		boolean f = false;
		for (int i = 0; i < n; i++)
		{
			if (c[i] == '?') {
				c[i] = 'D';
			}
		}
		sc.close();
		System.out.println(c);
	}
}


Measured memory_bytes: 32588
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define INF 11111111111111111
#define MOD 1000000007
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;

ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

//-------------------------------------------------------------------------------

#define MAX 10000

int main(void) {
  string s1, s2;

  cin >> n;
  cin >> s1 >> s2;

  if (s1[0] == s1[1]) {
	ans = 6;
	temp = 2;
	flag = false;
  }
  else {
	ans = 3;
	temp = 1;
	flag = true;
  }

  ll len = s1.length();
  s1 += "0";

  FOR(i, temp, len) {
	if (s1[i] == s1[i + 1]) {
	  flag ? ans *= 2 : ans *= 3;
	  flag = false;
	  i++;
	}
	else {
	  if (flag) ans *= 2;
	  flag = true;
	}
	ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)

class SegTree:
    def __init__(self, N, ele):
        self.num = 2**(N-1).bit_length()
        self.el = ele
        self.data = [ele]*(2*self.num)

    def calc(self, x, y):
        return max(x, y)

    def update(self, idx, x):
        idx += (self.num - 1)
        self.data[idx] = x
        while idx > 0:
            idx = (idx-1)//2
            self.data[idx] = self.calc(self.data[2*idx+1], self.data[2*idx+2])

    def query(self, l, r):
        L = l + self.num
        R = r + self.num
        res = self.el
        while L < R:
            if L & 1:
                res  = self.calc(res, self.data[L-1])
                L += 1
            if R & 1:
                R -= 1
                res = self.calc(res, self.data[R-1])
            L >>= 1
            R >>= 1
        return res
    
    def get(self, idx):
        idx += (self.num - 1)
        return self.data[idx]

n, k = map(int, input().split())
A = [int(input()) for _ in range(n)]
seg = SegTree(330000, 0)
max_a = 300010
for a in A:
    l = max(0, a-k)
    r = min(max_a, a+k+1)
    now = seg.query(l, r)
    seg.update(a, now+1)

print(seg.query(0, max_a))


Measured memory_bytes: 106640
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  string S;
  cin >> S;
  S.at(5) = ' ';
  S.at(13) = ' ';
  cout << S << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline int compare(const int*a,const int*b){return *a-*b;}
static inline int desc(const int*a,const int*b){return *b-*a;}
static inline long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
int main(void)
{
  int N=IN(),x,p=0,m=0,z=0,sign=0,A[200000];
  long K=IN(),count=0,l=-2e18,r=-l,mid;
  while(N--){x=IN();if(x>0)A[m+p++]=x;else if(x<0)A[p+m++]=x;else z++;}
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;
  qsort(A,m+p,sizeof(int),(int(*)(const void*,const void*))compare);
  qsort(A,m,sizeof(int),(int(*)(const void*,const void*))desc);
  rep(i,m)A[i]*=-1;
  if(K<=1l*m*p)r=1l;else l=-1l;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;
      rep(i,plus){while(1l*A[m+i]*A[m+plus]>mid){plus--;}if(i>=plus){break;}count+=1l*plus-i;}
      rep(i,minus){while(1l*A[i]*A[minus]>mid){minus--;}if(i>=minus){break;}count+=1l*minus-i;}
    }
    else{mid*=-1l;sign=1;int low=0;rep(i,m){while(1l*A[m+low]*A[m-1-i]<mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K){if(sign)r=-mid-1l;else r=mid-1l;}else{if(sign)l=-mid+1l;else l=mid+1l;}
  }
  return OUT(l),0;
}

Measured memory_bytes: 2800
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<utility>
#include<string>
#include<string.h>
#include<queue>
#include<stack>
#include<math.h>
#include<array>
#include<algorithm>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int judge(int num, int* d){
    int flag=1;
    while(num>0){
        int val = num%10;
        REP(i,10)if(val==d[i])flag=0;
        num/=10;
    }
    return flag;
}

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int d[11] ={};
    REP(i,11)d[i]=-1;
    REP(i,k)scanf("%d",&d[i]);
    while(1==1){
        if(judge(n, d))break;
        n++;
    }
    printf("%d\n",n);
    return 0;
}

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

int main() {
  int N, sum;
  cin >> N;
  sum = 50;
  
  for (int i = 0;i < N;i++){
    int x, n = 0;
    cin >> x;
    while (x % 2 == 0){
      x = x / 2;
      n++;
    }
    if (n < sum){
      sum = n;
    }
  }
  cout << sum << endl;
}
    

Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int D;
    cin >>D;
    if(D==25)cout<<"Christmas";
    else if(D==24)cout<<"Christmas Eve";
    else if(D==23)cout<<"Christmas Eve Eve";
    else if(D==22)cout<<"Christmas Eve Eve Eve";
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it,c) for(__typeof((c).begin())it=(c).begin(); it!=(c).end();++it)
#define RFOR(it,c) for(__typeof((c).rbegin())it=(c).rbegin(); it!=(c).rend();++it)
#define exist(c, v) (find((c).begin(), (c).end(), (v)) != (c).end())

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

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

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
	return os;
}

struct state {
	int v, cnt, d;
	state(int v, int c, int d):v(v), cnt(c), d(d){}
	bool operator>(const state& s) const {
		return d > s.d;
	}
};

struct edge {
	int to, cost;
	edge(int t, int c):to(t), cost(c){}
};

int ans;
vector<vector<edge> > es;
vector<int> dist;

void dijkstra(int s, int t, int limit) {
	ans = INT_MAX;
	priority_queue<state, vector<state>, greater<state> > que;
	vector<vector<int> > dist(es.size(), vector<int>(es.size() + 1, INT_MAX));
	que.push(state(s, 0, 0));
	dist[s][0] = 0;
	
	while(!que.empty()) {
		const state s = que.top();
		que.pop();
		if(dist[s.v][s.cnt] < s.d || s.cnt >= (int)es.size())
			continue;

		if(s.d > limit)
			return;

		if(s.v == t)
			chmin(ans, s.cnt);

		for(int i = 0; i < es[s.v].size(); ++i) {
			const edge& e = es[s.v][i];
			if(dist[e.to][s.cnt + 1] > s.d) {
				dist[e.to][s.cnt + 1] = s.d;
				que.push(state(e.to, s.cnt + 1, s.d));
			}

			const int next_dist = dist[s.v][s.cnt] + e.cost;

			if(dist[e.to][s.cnt] > next_dist) {
				dist[e.to][s.cnt] = next_dist;
				que.push(state(e.to, s.cnt, next_dist));
			}
		}
	}
}


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

	for(int n, m, c; cin >> n >> m >> c, n;) {
		es.clear();
		es.resize(n);
		for(int i = 0; i < m; ++i) {
			int f, t, d;
			cin >> f >> t >> d;
			--f;
			--t;
			es[f].push_back(edge(t, d));
		}

		dijkstra(0, n - 1, c);
		cout << ans << endl;		
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1516
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	l,r,d=MI()

	ans=(r-l)//d

	a=l+ans*d

	if r//d*d==-(-a//d)*d:
		ans+=1

	print(ans)










if __name__ == "__main__":
	main()


Measured memory_bytes: 61996
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<cstdlib>
using namespace std ;

#define MAXN 1007

int n ;
int a[ MAXN ][ MAXN ] ;

int pos[ MAXN ] ;
int f[ MAXN ] ;

bool h[ MAXN ] ;

queue < int > q ;

void input ( ) {
    scanf ( "%d" , &n ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        for ( int j = 1 ; j < n ; ++ j ) {
            scanf ( "%d" , &a[ i ][ j ] ) ;
        }
    }
}

void solve ( ) {
    for ( int i = 1 ; i <= n ; ++ i ) {
        q.push ( i ) ;
        pos[ i ] = 1 ;
        f[ i ] = 0 ;
    }
    int ans = 0 ;
    while ( q.empty ( ) == false ) {
        int x = q.front ( ) ;
        q.pop ( ) ;
        int other = a[ x ][ pos[ x ] ] ;
        if ( h[ other ] == true && a[ other ][ pos[ other ] ] == x ) {
            h[ other ] = false ;
            ++ pos[ other ] , ++ pos[ x ] ;
            int aux = max ( f[ other ] , f[ x ] ) + 1 ;
            ans = max ( ans , aux ) ;
            f[ other ] = f[ x ] = aux ;
            if ( pos[ other ] < n ) {
                q.push ( other ) ;
            }
            if ( pos[ x ] < n ) {
                q.push ( x ) ;
            }
        }
        else {
            h[ x ] = true ;
        }
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        if ( pos[ i ] < n ) { printf ( "-1\n" ) ; return ; }
    }
    printf ( "%d\n" , ans ) ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

bool use[1000][1000][1000];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x, y, z, k; cin>>x>>y>>z>>k;
	vll a(x), b(y), c(z);
	rep(i, x) cin>>a[i];
	rep(i, y) cin>>b[i];
	rep(i, z) cin>>c[i];
	sort(rall(a));
	sort(rall(b));
	sort(rall(c));

	priority_queue<tuple<ll, int, int, int> > que;
	que.push(make_tuple(a[0]+b[0]+c[0], 0, 0, 0));
	while(k--){
		tuple<ll, int, int, int> T = que.top(); que.pop();
		ll p = get<0>(T);
		int sx = get<1>(T);
		int sy = get<2>(T);
		int sz = get<3>(T);
		if (use[sx][sy][sz]){k++; continue;}
		use[sx][sy][sz] = true;
		cout << p << "\n";
		if (sx+1<=x-1)
			que.push(make_tuple(a[sx+1]+b[sy]+c[sz], sx+1, sy, sz));
		if (sy+1<=y-1)
			que.push(make_tuple(a[sx]+b[sy+1]+c[sz], sx, sy+1, sz));
		if (sz+1<=z-1)
			que.push(make_tuple(a[sx]+b[sy]+c[sz+1], sx, sy, sz+1));
	}
	return 0;
}

Measured memory_bytes: 973312
#include <bits/stdc++.h> 
using namespace std;
int A,B,C,X;
int ans = 0; 
int main(void){
	scanf("%d %d %d %d",&A,&B,&C,&X);
	for(register int i = 0;i <= A;i ++){
		for(register int j = 0;j <= B;j ++){
			for(register int k = 0;k <= C;k ++){
				if(i * 500 + j * 100 + k * 50 == X){
					ans++;
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<pair<int,int>, int> dp;

int solve(vector<vector<int>> &A, int day, int last)
{
	if(day == A.size())
		return 0;


	if(dp.find({day, last}) != dp.end())
		return dp[{day, last}];


	int ans = 0;

	for(int i = 0;i<3;i++)
	{
		if(last != i)
		{
			ans = max(ans, solve(A, day+1, i)+ A[day][i]);
		}
	}

	return dp[{day, last}] = ans;
}



int main()
{
	int n;
	cin>>n;
	vector<vector<int>> A(n, vector<int> (3, 0));
	dp.clear();
	for(int i = 0;i<n;i++)
	{
		cin>>A[i][0]>>A[i][1]>>A[i][2];
	}


	cout<<solve(A, 0, -1)<<endl;
}

Measured memory_bytes: 36992
#include<cstdio>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>

using namespace std;
#define N 4
#define N2 16

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r','u','l','d'};
int MDT[N2][N2];

struct Puzzle {
    int f[N2], space, MD;
    int cost;

    bool operator < (const Puzzle &p) const{
        for(int i=0; i<N2; i++){
            if(f[i]==p.f[i]) continue;
            return f[i] < p.f[i];
        }
        return false;
    }
};

struct State{
    Puzzle puzzle;
    int estimated;
    bool operator < (const State &s) const{
        return estimated > s.estimated;
    }
};

int getAllMD(Puzzle pz){
    int sum=0;
    for(int i=0; i<N2; i++){
        if(pz.f[i] == N2) continue;
        sum += MDT[i][pz.f[i]-1];
    }
    return sum;
}

int astar(Puzzle s){
    priority_queue<State> PQ;
    s.MD = getAllMD(s);
    s.cost = 0;
    map<Puzzle, bool> V;
    Puzzle u, v;
    State initial;
    initial.puzzle = s;
    initial.estimated = getAllMD(s);
    PQ.push(initial);

    while(!PQ.empty()){
        State st = PQ.top(); PQ.pop();
        u = st.puzzle;

        if(u.MD == 0) return u.cost;
        V[u] = true;

        int sx = u.space / N;
        int sy = u.space % N;

        for(int r=0; r<4; r++){
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if(tx<0 || ty<0 || tx>=N || ty>=N) continue;
            v = u;

            v.MD -= MDT[tx * N + ty][v.f[tx * N + ty] - 1];
            v.MD += MDT[sx * N + sy][v.f[tx * N + ty] - 1];

            swap(v.f[sx * N + sy], v.f[tx * N + ty]);
            v.space = tx * N + ty;
            if(!V[v]){
                v.cost++;
                State news;
                news.puzzle = v;
                news.estimated = v.cost + v.MD;
                PQ.push(news);
            }
        }
    }
    return -1;
}

int main(){
    for(int i=0; i<N2; i++){
        for(int j=0;j<N2;j++){
            MDT[i][j] = abs(i/N-j/N) + abs(i%N-j%N);
        }
    }
    Puzzle in;

    for(int i=0;i<N2;i++){
        cin >> in.f[i];
        if(in.f[i]==0){
            in.f[i] = N2;
            in.space = i;
        }
    }
    cout << astar(in) << endl;

    return 0;

}




Measured memory_bytes: 257548
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    string S;
    cin >> S;

    S.replace(4, 1, "");
    S.replace(6, 1, "");
    int n = stoi(S);
    if (n <= 20190430) cout << "Heisei" << endl;
    else cout << "TBD" << endl;

    return 0;
}


Measured memory_bytes: 256
list=[]
n=int(input())
b=[]
for _ in range(n):
    list.append(input())
for i in range(n-1):
    if list[i][-1]!=list[i+1][0]:
        b.append(0)
    elif len(list)!=len(set(list)):
        b.append(0)
if b.count(0)==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

int N,M,A[300][300];
int open[300],play[300];

int ok(int k){
    fill(open,open+M,1);
    REP(t,M){
        // printf("t=%d\n",t);
        fill(play,play+M,0);
        REP(i,N){
            REP(j,M)
                if(open[A[i][j]]){
                    play[A[i][j]]++;
                    break;
                }
        }
        int f=true,s=0;
        REP(i,M){
            if(k<play[i]){
                open[i]=0;
                f=false;
            }
            s+=play[i];
        }
        if(s==N&&f)
            return true;
    }
    return false;
}

int main(void){
    cin>>N>>M;
    REP(i,N)
        REP(j,M){
            cin>>A[i][j];
            A[i][j]--;
        }
    int mink=0,maxk=IMAX/2;
    while(maxk-mink>1){
        int midk=(mink+maxk)/2;
        // printf("maxk=%d mink=%d\n",maxk,mink);
        if(ok(midk))
            maxk=midk;
        else
            mink=midk;
    }
    if(ok(mink))
        cout<<mink<<endl;
    else
        cout<<maxk<<endl;
     return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int n,r;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin>>n>>r;

    if (n>=10){
        cout<<r;
    }
    else cout<<100*(10-n)+r;





    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		
		long ans = 1;
		long num = (long)(1E9 + 7);
		for(int i = 1;i <= N;++i) {
			ans = ans * i;
			if(ans > num)
				ans = ans % num;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#include<iostream>

double simulate(int year, int rate, int type){
	if(type == 1){//単利
		return 1 + 1.0 * year * rate / 100;
	}else{//複利
		double res = 1;
		for(int i=year;i--;){
			res *= (1 + 1.0 * rate / 100);
		}
		return res;
	}
}

int main(){
	int n, y, max_atm;
	double max_ir;
	while(std::cin >> n >> y, n){
		max_atm = 0;
		max_ir = 0;
		for(;n--;){
			int b, r, t;
			std::cin >> b >> r >> t;
			double ir = simulate(y, r, t);
			if(ir > max_ir){
				max_ir = ir;
				max_atm = b;
			}
		}
		std::cout << max_atm << std::endl;
	}
}

Measured memory_bytes: 1160
// ITP1_1_B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

using namespace std;

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

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します



Measured memory_bytes: 3080