akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <limits>
#include <algorithm>
using namespace std;

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

    int max_profit = numeric_limits<int>::min();
    int min_value = numeric_limits<int>::max();

    for (int x; cin >> x;) {
        int p = x - min_value;
        if (max_profit < p)
            max_profit = p;
        if (x < min_value)
            min_value = x;
    }

    cout << max_profit << endl;

    return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  vector<vector<ll>> weight(n, vector<ll>(n)), cost(n, vector<ll>(n));
  for (int i = 0; i < n; i++) {
    weight.at(i).at(i) = a.at(i);
  }
  
  for (int width = 2; width <= n; width++) {
    for (int l = 0; l + width <= n; l++) {
      int r = l + width - 1;
      weight.at(l).at(r) = weight.at(l).at(r - 1) + a.at(r);
      ll keep = 1e18;
      for (int mid = l + 1; mid <= r; mid++) {
        keep = min(keep, cost.at(l).at(mid - 1) + cost.at(mid).at(r) + weight.at(l).at(mid - 1) + weight.at(mid).at(r));
      }
      cost.at(l).at(r) = keep;
    }
  }
  
  cout << cost.at(0).at(n - 1) << '\n';
}

Measured memory_bytes: 2816
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int seconds = input.nextInt();
        int h = seconds / 3600;
        int remain = seconds % 3600;
        int m = remain / 60;
        int s = remain % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26308
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define iter2(c) for(auto it2=c.begin(); it2!=c.end(); it2++)
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define pmod(x,m) (((x)%(m)+m)%m)
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

bool check(int n, int m, int k)
{
    for (int i=0; i<=n; i++) {
        for (int j=0; j<=m; j++) {
            int black = i*j + (n-i)*(m-j);
            if (black == k) {
                return true;
            }
        }
    }
    return false;
}

int32_t main()
{
    #ifdef DEBUG
    freopen("B.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    int n,m,k;
    cin >> n >> m >> k;

    if (check(n,m,k))
        cout<<"Yes"<<endl;
    else 
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll x[100005]={0};
ll v[100005]={0};
ll sum1[100005]={0};
ll sum2[100005]={0};
ll shun[100005]={0};
ll ni[100005]={0};
int main()
{
    ll c;
    int n;
    scanf("%d%lld",&n,&c);
    for(int i=1;i<=n;i++){
    	scanf("%lld%lld",&x[i],&v[i]);
    	sum1[i]=sum1[i-1]+v[i];
    	shun[i]=max(shun[i-1],sum1[i]-x[i]);
	}
	ll maxn=shun[n];
	for(int i=n;i>0;i--){
		sum2[i]=sum2[i+1]+v[i];
		ni[i]=max(ni[i+1],sum2[i]-c+x[i]);
	}
	maxn=max(maxn,ni[1]);
	for(int i=1;i<=n;i++){
		maxn=max(maxn,sum1[i]-2*x[i]+ni[i+1]);
	}
	for(int i=1;i<=n;i++){
		maxn=max(maxn,sum2[i]-2*(c-x[i])+shun[i-1]);
	}
	printf("%lld\n",maxn);
	/*for(int i=1;i<=n;i++){
        cout<<shun[i]<<endl;
        cout<<ni[i]<<endl;
     }*/
    return 0;
}

Measured memory_bytes: 4992
program V1006;
 var
  a:array[0..200001] of longint;
  i,n:longint;
 begin
  readln(n);
  for i:=1 to n do
   read(a[i]);
  readln;
  i:=n;
  while i>=1 do
   begin
    if n=1 then writeln(a[i])
           else write(a[i],' ');
    dec(i,2);
   end;
  if n mod 2=1 then i:=2
               else i:=1;
  while i<=n do
   begin
    if i+2>n then writeln(a[i])
             else write(a[i],' ');
    inc(i,2);
   end;
 end.


Measured memory_bytes: 2816
import javax.swing.*;
import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {


    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public void execute(CustomReader in) throws IOException {
        final int N = in.readLineAsInt();
        int[] A = in.readLineAsIntArray();
        long ans = 0L;
        for (int i = 0; i < N; i++) {
            ans += A[i] - 1;
        }
        System.out.println(ans);
    }


    static class CustomReader extends BufferedReader {
        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int readLineAsInt() throws IOException {
            return Integer.parseInt(readLine());
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

        public char[][] readAsCharMatrix(int rows) throws IOException {
            char[][] matrix = new char[rows][];
            for (int i = 0; i < rows; i++) {
                matrix[i] = this.readLine().toCharArray();
            }
            return matrix;
        }

    }

}

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

int main(){
  int N,A,B,a=0,b=1;
  string S;
  cin>>N>>A>>B>>S;
  for(char c:S)
    if(c=='c')
      cout<<"No"<<endl;
    else if(c=='a')
      if(a<A+B){
        cout<<"Yes"<<endl;
        a++;
      }else
        cout<<"No"<<endl;
    else{
      if(a<A+B && b<=B){
        cout<<"Yes"<<endl;
        a++;
      }else
        cout<<"No"<<endl;
      b++;
    }
}

Measured memory_bytes: 896
#include<stdio.h>
int main(){
char a[21];
int i=0;
while(1){
scanf("%c",&a[i]);
if(a[i]=='\n'){
break;
}
else{
i++;
}
}
i=i-1;
for(;i>=0;i--){
printf("%c",a[i]);
}
printf("\n");
return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define MAXSIZE 60
using namespace std;
const int N = 1e3 + 5;
const ll mo = 1e10 +7;
const int M = 100+50;
const ll mod = 998244353;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b){
		int t=a;
		a=b;
		b=t;
	}
	if(c>a && b>c)
		cout<<"Yes\n";
	else
		cout<<"No\n";
    return 0;
}

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

#define ll          long long
#define ld          long double
#define pb          push_back
#define pii         pair<int,int> 
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F         first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cerr << #x << " is " << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)

using namespace std;

const int N=1e5+5;

vi ad[N];
bool vis[N];
int dp[N];
stack<int> st;

void topo(int x){
    vis[x]=true;

    for(auto y:ad[x]){
        if(vis[y]==false)
            topo(y);
    }

    st.push(x);
}

int dfs(int x){
    if(vis[x]==true)return dp[x];
    vis[x]=true;
    int val=0;

    for(auto y:ad[x]){

        val=max(val,dfs(y)+1);
    }
    dp[x]=val;
    return val;
}

void solve(){
    int n,m;
    cin>>n>>m;
    int u,v;


    rep(i,0,m){
        cin>>u>>v;
        ad[u].pb(v);
    }

    rep(i,1,n+1){
        if(vis[i]==false)
            topo(i);
    }

    mem(vis);

    while(st.empty()==false){
        u=st.top();
        st.pop();
        if(vis[u])continue;

        dfs(u);
    }

    int ans=0;
    for(int i=1;i<n+1;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans;
}



int main(){
    // #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
   

    int t=1,i=1;
    //cin>>t;
    

    while(t--){
       // cout<<"Case #"<<i++<<": ";
        solve();
    
    }

    return 0;
}

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

int main()
{

    int a,b;
    while(cin>>a>>b)
    {

        priority_queue<int> p;
        p.push(a),p.push(b);
        int ans=0;
        int num=p.top();
        ans+=num;
        p.pop();
        num--,p.push(num);
        num=p.top();
        ans+=num;
        p.pop();
        num--,p.push(num);
        cout<<ans<<"\n";
    }


}


Measured memory_bytes: 256
$n=<>;$mo=1e9+7;
%mem;
@str=("A","C","G","T");
sub check{
    my $s=shift;
    return 0 if ($s=~/(AGC|GAC|ACG|A.GC|AG.C)/);
    return 1;
}
sub dfs{
    my($cu,$l3)=@_;
    if (defined $mem{$cu}->{$l3}){
        return $mem{$cu}->{$l3};
    }
    return 1 if $cu==$n;
    my $ret=0;
    for my$c(@str){
        $ret = ($ret + &dfs($cu+1, substr($l3,1).$c)) % $mo if &check($l3.$c);
    }
    $mem{$cu}->{$l3}=$ret;
    return $ret;
}

print &dfs(0,"TTT")

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define int long long
#define REP(i,a,n) for(int i=a;i<(n);i++)
#define REP_sz(i,s) for(int i=0;i<s.size();i++)
#define RE return
#define FILL(a,b) memset(a,b,sizeof(a))
#define SO(a) sort(all(a))
#define pb push_back
#define sz(a) a.size()
#define V vector
#define ld long double
#define viit(a) vector<int>::iterator a
#define msit1(a) map<string,int>::iterator a
#define miit(a) map<int,int>::iterator a
#define msit2(a) map<int,string>::iterator a
#define IT iterator
#define FOR(i,a,n) for(int i=a;i<=(n);i++)
#define B(s) s.back()
#define all(a) a.begin(),a.end()
#define ER1(a) a.erase(a.begin())
#define ER0(a) a.erase(a.end())
#define pii pair<int,int>
#define pause system("PAUSE")
#define cls system("CLS")
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n,m;
	cin>>n>>m;
	V<int>a(n);
	REP(i,0,n)cin>>a[i];
	cout<<(n-m)/(m-1)+((n-m)%(m-1)? 2:1);
    return 0;
}


Measured memory_bytes: 3800
x=gets.to_i
a=0
while a**5<=x**2
    c=a**5-x
    if c<0
        t=(-c)**0.2
    else
        t=c**0.2
    end
    t=t.to_i
    t=-t if c<0
    (t-10..t+10).each{|b|
        if a**5-b**5==x
            puts "#{a} #{b}"
            exit
        end
    }
    a+=1
end


Measured memory_bytes: 14812
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=list(map(int,input().split()))
p=set(p)
res=[]
for i in range(x,-1,-1):
    if i not in p:
        res.append(i)
        break
for i in range(x+1,102):
    if i not in p:
        res.append(i)
if len(res)==1:
    print(res[0])
else:
    if x-res[0]>res[1]-x:
        print(res[1])
    else:
        print(res[0])

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

int main(){
	int n, m, k, cost;
	string item;

	while( cin >> n , n ){
		map<string,int> Table;
		for(int i=0 ; i<n ; ++i ){
			cin >> item >> cost;
			Table[ item ] = cost;
		}
		cin >> m;
		for(int i=0 ; i<m ; ++i ){
			vector<string> vc;
			cin >> item >> k;

			for(int j=0 ; j<k ; ++j ){
				string s;
				cin >> s;
				vc.push_back( s );
			}
			int sum = 0;
			for(int j=0 ; j<(int)vc.size() ; ++j ){
				sum += Table[ vc[j] ];
			}
			Table[ item ] = min( sum , Table[ item ] );
		}
		string obj;
		cin >> obj;
		cout << Table[ obj ] << endl;
	}
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long

int main()
{

    int a,b;
    while(~scanf("%d%d",&a,&b))
    {

        if(a>9||a<1||b>9||b<1)
            printf("-1\n");
        else
            printf("%d\n",a*b);
    }
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		Console.WriteLine((A-B) % 2 == 0 ? "Alice" : "Borys" );
	}
	int N,A,B;
	public Sol(){
		var d = ria();
		N = d[0]; A = d[1]; B = d[2];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

typedef pair<int,int> pii;
typedef pair<int,pii> piii;
piii extgcd(int a,int b){
  int x=1,y=0,x1=0,y1=1,t;
  while(b!=0){
    int q=a/b;
    t=x,x=x1,x1=t-q*x1;
    t=y,y=y1,y1=t-q*y1;
    t=b,b=a-q*b,a=t;
  }
  return a>0?piii(a,pii(x,y)):piii(-a,pii(-x,-y));
}

int main(void){

  int a,b;

  cin >> a >> b;

  piii res=extgcd(a,b);
  cout << res.second.first << " " << res.second.second << endl;

  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,c;cin >> n >> c;
	vector<vector<int>> d(c,vector<int>(c));
	rep(i,c) rep(j,c) cin >> d[i][j];
	vector<vector<int>> cnt(3,vector<int>(c));
	rep(i,n){
		rep(j,n){
			int a;cin >> a;
			a--;
			cnt[(i + j) % 3][a]++;
		}
	}
	int ans = 1000000000;
	rep(c1, c){
		rep(c2, c){
			rep(c3, c){
				if(c1 == c2 || c2 == c3 || c3 == c1) continue;
				int sum = 0;
				rep(i,c){
					sum += d[i][c1] * cnt[0][i];
					sum += d[i][c2] * cnt[1][i];
					sum += d[i][c3] * cnt[2][i];
				}
				ans = min(ans, sum);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define all(x) x.begin(), x.end()
#define sz(x) (int)(x.size())
#define pb push_back
#define mp make_pair
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define endl "\n"
#define int long long

using namespace std;

const int N = (int)(5e5) + 322;
const int inf = 99999999999;

vector <pair <char, int> > v;

string s;

int k;

signed main () {
    ios_base :: sync_with_stdio (false); cin.tie(0);
    int cnt = 0;
    cin >> s >> k;
    s += '@';
    for(int i = 0; i < sz(s) - 1; ++i) {
        cnt++;
        if (s[i] != s[i + 1]) {
            v.pb({s[i], cnt});
            cnt = 0;
        }
    }
    if (sz(v) == 1) {
        cout << v.front().second * k / 2;
        return 0;
    }
    int ans = 0;
    for(int i = 1; i < sz(v) - 1; ++i) {
        ans += v[i].second / 2;
    }
    ans *= k;
    if (v.front().first == v.back().first) {
        ans += (k - 1) * ((v.front().second + v.back().second) / 2);
    }else {
        ans += (k - 1) * ((v.front().second / 2 + v.back().second / 2));
    }
    ans += v.front().second / 2;
    ans += v.back().second / 2;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
-module('Main').
-export([main/1]).

main(_) ->
    {ok, [K]} = io:fread("", "~d"),
    {ok, [S]} = io:fread("", "~s"),
    LenOfS = length(S),
    case LenOfS > K  of
        true ->
            Sliced = string:slice(S, 0, K),
            NewS = unicode:characters_to_list([Sliced, "..."]),
            io:format("~s~n", [NewS]);
        false ->
            io:format("~s~n", [S])
    end,
    halt().





Measured memory_bytes: 21936
# -*- coding: utf-8 -*-

import sys
from heapq import heappush, heappop, heapify

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
A  = [-a for a in LIST()]

heapify(A)
for i in range(M):
    mx = -heappop(A)
    mx //= 2
    heappush(A, -mx)

print(-sum(A))


Measured memory_bytes: 15148
def input_li():
    return list(map(int, input().split()))

def input_int():
    return int(input())

N = input_int()
# dp[x][y] ... x日目にyを行った時の幸福度を格納する
dp = [[0] * 3 for _ in range(N)]
for i in range(N):
    a, b, c = input_li()
    if i == 0:
        dp[i][0] = a
        dp[i][1] = b
        dp[i][2] = c
    else:
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c
print(max(dp[-1]))


Measured memory_bytes: 86928
s = input()
divisor = 10 ** 9 + 7
dp = [[0] * 13 for _ in range(len(s) + 1)]
dp[0][0] = 1
for i in range(len(s)):
  if s[i] == '?':
    for j in range(10):
      for k in range(13):
        dp[i + 1][(k * 10 + j) % 13] += dp[i][k]
  else:
    t = int(s[i])
    for k in range(13):
      dp[i + 1][(k * 10 + t) % 13] += dp[i][k]
  for k in range(13):
    dp[i + 1][k] %= divisor
print(dp[len(s)][5])


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

int main(){
  long long cnt=0,n,d[5];
  cin >> n;
  int c[26]={};
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    c[s.at(0)-65]++;
  }
  d[0]=c[0];
  d[1]=c[2];
  d[2]=c[7];
  d[3]=c[12];
  d[4]=c[17];
  for(int i=0;i<5;i++){
    for(int j=i+1;j<5;j++){
      for(int k=j+1;k<5;k++){
        cnt += d[i]*d[j]*d[k];
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(){
  int n;
  int a[20],b[20],c[20];
  int sum = 0;
  scanf("%d",&n);
  for(int i = 0;i < n;i++){
    scanf("%d",a+i);
  }
  for(int i = 0;i < n;i++){
    scanf("%d",b+i);
  }
  for(int i = 0;i < n-1;i++){
    scanf("%d",c+i);
  }
  for(int i = 0;i < n-1;i++){
    sum += b[i];
    if(a[i] +1 == a[i+1]){sum += c[a[i]-1];}
  }
  sum += b[n-1];
  printf("%d\n",sum);
  return 0;
}

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

using namespace std;

int main()
{
    string str;
    int n;
    cin>>n>>str;
    for(int i = 0;i<str.size();i++)
    {
        cout<<(char)((str[i]-'A'+n)%('Z'-'A'+1)+'A');
    }
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()
slp = [LIST() for _ in range(n)]
m = INT()
w = [INT() for _ in range(m)]

dp = [0]*394

v = [0]*394
for s, l, p in slp:
	for x in range(s, l+1):
		v[x] = max(v[x], p)


for i in range(394):
	for j in range(i+1):
		dp[i] = max(dp[i], dp[i-j]+v[j])

ans = []
for i in w:
	if dp[i] == 0:
		print(-1)
		break
	else:
		ans.append(dp[i])
else:
	print(*ans, sep="\n")



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

using namespace std;

using ll = long long;

int main(){
    ll k, ans = 0; cin >> k;
    for(ll i = 1; i <= k; ++i){
       for(ll j = 1; j <= k; ++j){
            for(ll x = 1; x <= k; ++x){
                ans += __gcd(i, __gcd(j, x));
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3564
N, W = map(int, input().split())

VW = []
for _ in range(N):
    VW.append(list(map(int, input().split())))

dp = [0] * (W+1)

for v, w in VW:
    for i in range(W+1):
        if i >= w:
            dp[i] = max(dp[i], dp[i-w] + v)
print(dp[-1])


Measured memory_bytes: 5912
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PI;
using namespace std;
#define MAX  999999
int main(){
    vs s(10000);
    int  n; cin >> n;
    rep(i,n) cin >> s[i];
    int t; cin >> t; vs h(10000);
    rep(i,t) cin >> h[i];
    bool check = true; bool belong = false;
    rep(i,t){
        belong = false;
        rep(j,n){
        if(h[i] ==s[j]){
            belong = true;
            if(check){cout<< "Opened by " << h[i] << endl; check = false;}
            else {cout << "Closed by " << h[i] << endl; check = true;}
            break;
            }
        }
        if(!belong) cout << "Unknown " << h[i] << endl;
    }
}

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

string s;

signed main() {
    //cin.tie(0); ios::sync_with_stdio(false);
    cin >> s;
    int N = s.size();
    int ans = 0;
    
    rep(S, 1<<(N-1)) {
        int now = s[0]-'0';
        rep(i, N-1) {
            if ((S>>i)&1) {
                ans += now;
                now = s[i+1]-'0';
            }
            else now = 10*now+(s[i+1]-'0');
        }
        ans += now;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
-- if B / A >= C then C else B / A 

import Control.Applicative

solve :: Int -> Int -> Int -> Int
solve a b c = if b `div` a >= c then c else b `div` a

main :: IO ()
main = do
  [a, b, c] <- map read . words <$> getLine
  putStrLn $ show $ solve a b c


Measured memory_bytes: 508
using System;
    using System.Text;
    using System.Collections.Generic;
    using static System.Math;
    using System.Linq;
    using static System.Array;

    namespace ConsoleApp2
    {
        class Program
        {

            static void Main(string[] args)
            {
                var S = Console.ReadLine();
       
                Console.WriteLine(S == "ABC" ? "ARC":"ABC");

            }
        }
    }


Measured memory_bytes: 25816
import io.StdIn._
object Main extends App {
    val Array(h,w) = readLine.split(" ").map(_.toInt)
    
    val h_ceil = BigDecimal((h/2.0).ceil)
    val w_ceil = BigDecimal((w/2.0).ceil)
    val h_floor = BigDecimal((h/2.0).floor)
    val w_floor = BigDecimal((w/2.0).floor)

    if(h == 1 || w == 1) println(1)
    else {
        val output = w_ceil*h_ceil+h_floor*w_floor
        println(output.toLong)
    }
}

Measured memory_bytes: 25532
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  cout << (a + b * 5 + c * 10 + d * 50 + e * 100 + f * 500 >= 1000) << endl;
}

Measured memory_bytes: 1160
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N-i+1):
        if i*10000+j*5000+(N-i-j)*1000 == Y:
            print(i,j,N-i-j)
            exit(0)
print("-1 -1 -1")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

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

	    String S=gs();
	    int w=gi();

	    for (int i=0; i<S.length();i+=w) {
	    	String s=S.substring(i, i+1);
	    	System.out.print(s);
	    }
	    //System.out.println(T.replaceAll("?", "D"));
	}

	public static double f(double r, double n, double m, double i) {
		double a = 0;
		double b=0;
		if(0<i&&i<n) {
			a=Math.abs(r-((2*r/n)*i));
			a= Math.sqrt(Math.pow(r, 2) - Math.pow(a, 2));
		}
		if(0<i-m&&i-m<n) {
			b=Math.abs(r-(2*r*(i-m)/n));
			b=Math.sqrt(Math.pow(r, 2) - Math.pow(b, 2));
		}
		return 2* Math.max(a, b);
	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35988
#include <iostream>

using namespace std;

constexpr int MAX_N = 3000;

int main()
{
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int count = 0;
    for (auto r = 0u; r <= MAX_N / R; ++r)
    {
        auto rc = R * r;
        for (auto g = 0u; g <= (MAX_N - rc) / G; ++g)
        {
            auto rest = N - rc - G * g;
            if (rest / B <= MAX_N && rest % B == 0)
            {
                ++count;
            }
        }
    }
    cout << count;
}

Measured memory_bytes: 888
import scala.math._

object Main {
  val sc = new java.util.Scanner(System.in)
  def main(args: Array[String]) {
    while(true) {
      val a, b = sc.nextInt()
      if(a == 0 && b == 0) {
        return
      }

      val n = sc.nextInt()
      val dp = Array.ofDim[Long](a+1, b+1)
      for(i <- 1 to n) {
        val x, y = sc.nextInt()
        dp(x)(y) = -1
      }
      dp(1)(1) = 1
      for(i <- 1 to a; j <- 1 to b; if (i, j) != (1, 1)) {
        if(dp(i)(j) == -1) {
          dp(i)(j) = 0
        } else {
          dp(i)(j) = dp(i-1)(j) + dp(i)(j-1)
        }
      }
      println(dp(a)(b))
    }
  }
}

Measured memory_bytes: 45344
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}



class Ver{
public:
    map<ll, ll> children; // ver, distance
    ll idx;
    ll d;
    Ver(){};
    Ver(ll _idx){
        idx = _idx;
        children = map<ll, ll>();
        d = -1;
    }
    void addChildren(ll c, ll d){
        children.emplace(make_pair(c,d));
    }
    
    void calc(ll d_so_far, map<ll, Ver>& m){
        if(d > -1) return;
        this->d = d_so_far;
        FORMAP(it, this->children){
            m[it->ff].calc(this->d + children[it->ff], m);
        }
        return;
    }
};

map<ll, Ver> vex;

int main(){
    ll N; cin >> N;
    REP(i, N-1){
        ll a, b, c; cin >> a >> b >> c;
        if(vex.count(a) == 0){
            vex[a] = Ver(a);
        }
        if(vex.count(b) == 0)
        {
            vex[b] = Ver(b);
        }
        vex[a].addChildren(b, c);
        vex[b].addChildren(a, c);
    }
    ll Q, K; cin >> Q >> K;
    vex[K].calc(0, vex);
    
    REP(i, Q){
        ll x, y; cin >> x >> y;
        cout << vex[x].d + vex[y].d << endl;
    }
    return 0;
}


Measured memory_bytes: 29952
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read();
    let mut v: Vec<(i32, i32, i32)> = (0..n).map(|_| (read(), read(), read())).collect();
    v.insert(0, (0, 0, 0));
    let yes = v[..].windows(2).all(|w| {
        let (t, x, y) = w[0];
        let (nt, nx, ny) = w[1];
        let time = nt - t;
        let dist = (nx - x).abs() + (ny - y).abs();
        dist <= time && time % 2 == dist % 2
    });
    println!("{}", if yes { "Yes" } else { "No" });
}

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

using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 100000;

int n, f[N + 5];
vector<int> G[N + 5];

void dfs(int u, int fa = -1) {

    int c = 0;
    for(int i = 0; i < (int) G[u].size(); ++i) {
        int v = G[u][i];
        if(v == fa) continue;

        dfs(v, u);

        if(!f[v]) {
            ++ c;
        } else {
            f[u] += f[v];
        }
    }
    if(c) f[u] += c - 1;
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    
    read(n);
    for(int i = 1; i < n; ++i) {
        static int u, v;
        read(u), read(v);
        G[u].pb(v), G[v].pb(u);
    }

    for(int i = 0; i < n; ++i) if((int) G[i].size() >= 3) {
        dfs(i);
        printf("%d\n", f[i]);
        return 0;
    }
    printf("1\n");
    return 0;
}


Measured memory_bytes: 10368
// ctrl+shift+b
#include <bits/stdc++.h>

using namespace std;

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

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

#endif

void Main() {
    string S; cin >> S;
    ll ans = INF;
    rep(i, S.size() - 2){
        ll tmp = 100 * (S[i] - '0') + 10 * (S[i + 1] - '0') + (S[i + 2] - '0');
        tmp = abs(753 - tmp);
        if (tmp < ans){ans = tmp;}
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3548
fun main(arr:Array<String>) {
    val antennas = (1..5).map { readLine()!!.toInt() }
    val k = readLine()!!.toInt()
    if(antennas.last() - antennas[0] > k) {
        println(":(")
    } else {
        println("Yay!")
    }
}


Measured memory_bytes: 31772
while True:
    n=int(input())
    if n==0:
        break
    else:
        x=[0]*31
        x[0]=1
        x[1]=1
        x[2]=2
        for i in range(3,n+1):
            x[i]=x[i-3]+x[i-2]+x[i-1]
    print((x[n]//3650)+1)


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

int main(){
    int N; cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++) cin >> d[i];
    sort(d.begin(), d.end());
    cout << ((d[N/2])-(d[(N/2)-1]));
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t ll;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

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; }
void SWAP(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void SWAP(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

using namespace std;


class D {
	int n;
	vector<int> a;
public:
	D()
	{
		cin >> n;
		a.resize(n);
		REP(i, n)
			cin >> a[i];
	}

	void solve()
	{
		sort(ALL(a));

		int k{ a.back() };
		int target{ (k & 1) ? (k + 1) / 2 : k / 2 };
		int r{ a[0] };
		int diff{ INTMAX };

		REP(i, n)
		{
			int d{ abs(target - a[i]) };
			if (d < diff)
			{
				SWAP(diff, d);
				r = a[i];
			}
			else if (a[i] > target)
				break;
		}

		cout << k << " " << r << endl;

	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}


Measured memory_bytes: 640
#include<cstdio>
const int MAXN = 100;
int dp[3][MAXN + 5];
int max(int a,int b) {
	return a>b?a:b;
}
int main() {
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d",&dp[1][i]);
	for(int i=1;i<=N;i++)
		scanf("%d",&dp[2][i]);
	for(int i=1;i<=N;i++)
		dp[1][i] += dp[1][i-1];
	for(int i=1;i<=N;i++)
		dp[2][i] += max(dp[1][i], dp[2][i-1]);
	printf("%d",dp[2][N]);
}

Measured memory_bytes: 128
#include<vector>
#include<iostream>
#include<string>
#include<algorithm> 
using namespace std;
int main(){
	int n,d,x,k,ans=0;
	cin>>n>>d>>x;
	for(int i=1;i<=n;i++){
		cin>>k;
		ans+=(d-1)/k+1;
	}
	cout<<ans+x<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.Math;

class Main{

    public static void main(String[] args){

        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        scanner.close();
        int sum = 0;
        double tax1 = 0.08;
        double tax2 = 0.1;
        while(true){
            sum += 1;
            if(Math.floor(sum*tax1)==a && Math.floor(sum*tax2)==b){
                System.out.println(sum);
                return;
            }
            if(sum>a/tax1 && sum>b/tax2){
                System.out.println("-1");
                return;
            }
        }

    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1e9+5;
const int N=2e5+5;
const int mod=1e9+7;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int x;
	cin>>x;
	int init=400;
	int now=8;
	while(1){
		if(x>=init&&x<=init+199){
			return cout<<now,0;
		}
		--now;
		init+=200;
	}
	return 0;
}


Measured memory_bytes: 3660
N,M = map(int,input().split())
A = [[0]*M]*N
for i in range(N):
    A[i] = list(map(int,input().split()))
    del A[i][0]

I = [True]*(M)

for j in range(1,M+1):
    for ki in range(N):
        if not (j in A[ki]):
            I[j-1] = False

print(I.count(True))

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional> 

using namespace std;

#define mp make_pair
#define pb push_back
#define pf push_front
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int (i)=0;(i)<(n);++(i))
#define rep(i,st,ed) for(register int (i)=(st);(i)<=(ed);++(i))
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<typename T> inline T qmin(const T a,const T b) {return a<b?a:b;}
template<typename T> inline T qmax(const T a,const T b) {return a>b?a:b;}
template<typename T> inline void getmin(T &a,const T b) {if(a>b) a=b;}
template<typename T> inline void getmax(T &a,const T b) {if(a<b) a=b;}

inline void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=1e9+7;
const ll linf=1e17+7;
const int N=2e5+7;

int t[N];
int n,c,k;

int main(){
	scanf("%d%d%d",&n,&c,&k);
	for(int i=1;i<=n;++i) scanf("%d",t+i);
	sort(t+1,t+n+1);
	int ans=0;
	for(int i=1,j;i<=n;i=j){
		int cur=t[i]+k,times=c;
		for(j=i;times&&j<=n&&t[j]<=cur&&cur<=t[j]+k;--times,++j);
		++ans;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 764
possible_appearances = ->(dice) {
  table = 
     [[0, 1, 2, 3, 4, 5], [3, 1, 0, 5, 4, 2], [1, 5, 2, 3, 0, 4], [5, 1, 3, 2, 4, 0],
      [1, 2, 0, 5, 3, 4], [3, 5, 1, 4, 0, 2], [5, 4, 2, 3, 1, 0], [2, 1, 5, 0, 4, 3],
      [1, 0, 3, 2, 5, 4], [5, 2, 1, 4, 3, 0], [2, 4, 0, 5, 1, 3], [4, 5, 3, 2, 0, 1],
      [3, 4, 5, 0, 1, 2], [4, 0, 2, 3, 5, 1], [1, 3, 5, 0, 2, 4], [2, 0, 1, 4, 5, 3],
      [0, 4, 3, 2, 1, 5], [4, 2, 5, 0, 3, 1], [4, 3, 0, 5, 2, 1], [2, 5, 4, 1, 0, 3],
      [3, 0, 4, 1, 5, 2], [0, 3, 1, 4, 2, 5], [0, 2, 4, 1, 3, 5], [5, 3, 4, 1, 2, 0]]
  result = []
  table.each do |dice1|
    next_dice = Array.new(6, 0)
    dice1.each_with_index {|n, i| next_dice[n] = dice[i]}
    result << next_dice
  end
  result.uniq
}

appearances = possible_appearances.(gets.split.map(&:to_i))
gets.to_i.times do
  top, front = gets.split.map(&:to_i)
  appearances.each do |a|
    if a[0] == top and a[1] == front
      puts a[2]
      break
    end
  end
end



Measured memory_bytes: 8912
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,ans=0,count=0;
    cin >> n;
    ll a[n];
    bool color[9];
    fill(color,color+9,false);
    for (ll i=0;i<n;i++)cin >> a[i];
    for (ll i=0;i<n;i++){
        color[a[i]/400]=true;
        if (a[i]/400>=8){
            count++;
        }
    }
    for (ll i=0;i<8;i++){
        if (color[i])ans++;
    }
    if (ans!=0){
        cout << ans << " ";
    }else{
        cout << 1 << " ";
    }
    ans+=count;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    ll N, isThree=1;
    char S;
    in(N);
    rep(_, N){
        scanf("%c", &S);
        if(S=='Y') isThree = 0;
    }
    puts(isThree ? "Three":"Four");
    return 0;
}


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

int main() {
  int n, max;
  cin >> n >> max;
  vector<int> ames(n, 0);
  unsigned long long eat = 0;
  for(int i=0;i<n;i++) {
    int ame;
    cin >> ame;
    int tot;
    if (i == 0) {
      tot = ame;
    } else {
      tot = ame + ames[i-1];
    }
     
    if (tot > max) {
      int e = tot - max;
      eat += e;
      ame -= e;
    }
    // cout << eat << " ";
    ames[i] = ame;
  }

  cout << eat << endl;

  return 0;
}

Measured memory_bytes: 888
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

int solve(int N, int D) {
    if (N%2 == 0) {
        return 127*(N-1) + (127^D);
    } else {
        return 127*(N-1) + D;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
        int N, D;
        cin >> N >> D;
        cout << solve(N, D) << endl;
    }
    return 0;
}


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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using pint = pair<int, int>; 
using pll  = pair<ll, ll>;
using vint = vector<int>; 
using vll  = vector<ll>;
using vstr = vector<string>;

//　定数, 変数 *********************************************
const ll MOD=1e9+7;
const ll INF=1ll<<60;

ll X;

// *********************************************************
int main(){
    cin >>X;
    ll happy=0;
    while(X>=500){
        happy += 1000;
        X -= 500;
    }
    while(X>=5){
        happy += 5;
        X -= 5;
    }

    cout << happy << endl;
    return 0;
}

Measured memory_bytes: 3592