akhauriyash/Code-Regression huggingface dataset:
package main
 
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)
 
var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, "\n"))
}
func Output() {
  _ = writer.Flush()
}
 
func Max(x, y int) int {
  if x < y { return y }
  return x
}
func Mod(n, p int) int {
  if n < 0 {
    n += (-n / p + 1) * p
  }
  return n % p
}

func main() {
  NK := NextIntVec()
  _, K := NK[0], NK[1]
  A := NextIntVec()
  cnt := 0
  P := make(map[int][]int)
  P[0] = []int{0}
  p := 0
  for i, a := range A {
    p = (p + a - 1) % K
    _, ok := P[p]
    if ok {
      P[p] = append(P[p], i + 1)
    } else {
      P[p] = []int{i + 1}
    }
  }
  for _, p := range P {
    s, t := 0, 0
    for t < len(p) {
      for p[t] - p[s] < K {
        t++
        if t == len(p) { break }
      }
      if t == len(p) {
        cnt += (t - s) * (t - s - 1) / 2
        break
      }
      for K <= p[t] - p[s] {
        cnt += t - s - 1
        s++
      }
    }
  }
  Write(cnt)
  Output()
}

Measured memory_bytes: 26624
//  LINK ZADATKA: http://agc019.contest.atcoder.jp/tasks/agc019_b

#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <fstream>
#include <cstring>
#include <string>
#include <climits>

using namespace std;

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define INF 999999999
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define _gcd __gcd
#define eps 1e-9

string s;
ll sol, smanji, max_comb;
map<char, ll> mapa;
int main(){

	cin >> s;
	
	REP(i, s.size()) mapa[s[i]]++; 
	
	for(map<char,ll>::iterator it = mapa.begin(); it != mapa.end(); it++){
		//printf("%c %lld\n", it -> first, it -> second);
		ll temp_broj = it -> second - 1;
		sol += ((temp_broj)*(temp_broj+1))/2;
	}
	
	//cout << sol << endl;
	max_comb = ((s.size()-1) * s.size()) / 2;
	
	//printf("%lld %lld\n", smanji, max_comb);
	
	printf("%lld\n", max_comb - sol + 1);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
int dp[55][55][3000];
string alph("abcdefghijklmnopqrstuvwxyz");


signed main(){
    int a,b;cin>>a>>b;
    string s=to_string(b);
    rep(i,0,s.size()){
        a*=10;
    }
    int c=a+b;
    rep(i,0,5000){
        if(i*i==c){
           cout<<"Yes"<<endl;
        return 0; 
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cmath>
using namespace std;
int main(void){
    
    double r;
    cin >> r;
    
    double mawari = 2.0 * r * acos(-1);
    double menseki = r * r * acos(-1);
    
    cout << setprecision(15) << menseki << " " << mawari << endl;
    
    
}



Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main(){

	lli N, x;
	cin>>N;
	vector<lli> A;
	for (int i = 0; i < N; ++i)
	{
		cin>>x;
		A.push_back(x);
	}

	lli total_stool_height = 0;
	lli prev = A[0];
	for (int i = 1; i < N; ++i)
	{
		if(A[i]-prev >=0)
		{	prev = A[i];
			continue;
		}
		else{
			total_stool_height += prev-A[i];
		}
	}
	cout<<total_stool_height;
	return 0;
}

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

using namespace std;

int main(){
  int n;
  cin>>n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  int n1=n-1;
  //  vector<int> ans(n-2);
  int sum=0;
  for(int i=1;i<n1;i++){
    //    ans[i]=0;
    if(p[i]<p[i-1] && p[i]>p[i+1]) sum++;
    else if(p[i]>p[i-1] & p[i]<p[i+1]) sum++;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
s = [0] * 5
for i in range(n):
    l = input()
    l = l[0]
    if l == 'M':
        s[0] += 1
    elif l == 'A':
        s[1] += 1
    elif l == 'R':
        s[2] += 1
    elif l == 'C':
        s[3] += 1
    elif l == 'H':
        s[4] += 1
    else:
        pass
ans = 0
a = [[0,1,2],[0,1,3],[0,1,4],[0,2,3],[0,2,4],[0,3,4],[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
for i in range(10):
    ans += s[a[i][0]] * s[a[i][1]] * s[a[i][2]]
print(ans)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;
 
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  c=max(a,c);
  d=min(b,d);
  int ans = d-c;
  if(ans<0){ans=0;}

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


Measured memory_bytes: 256
S = input()

strong = True
N = len(S)

for i in range(int((N-1)/2)):
    if S[i] != S[-i-1]:
        strong = False

tmp = S[:int((N-1)/2)]
for i in range(int(len(tmp)-1/2)):
    if tmp[i] != tmp[-i-1]:
        strong = False


tmp = S[int((N+3)/2)-1:]
for i in range(int(len(tmp)-1/2)):
    if tmp[i] != tmp[-i-1]:
        strong = False

if strong:
    print("Yes")
else:
    print("No")

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

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 200011

int n, i, x, y, C;
vector<int> list[maxN];
char tp[maxN];

int down[maxN], up[maxN], dist[maxN], high[maxN], low[maxN], cnt[maxN];
vector< pair<int, int> > aux;
vector<int> loc;
ll ans;

void dfs(int node, int root) {
    down[node] = 0;

    for (auto to : list[node]) {
        if (to == root) continue;
        dfs(to, node);
        down[node] = max(down[node], down[to] + 1);
    }
}

void dfs2(int node, int root) {
    aux.clear();
    loc.clear();

    for (auto e : list[node])
        if (e != root)
        loc.pb(down[e] + 1);
    loc.pb(up[node]);

    if(loc.size() == 1) loc.pb(0);
    sort(loc.begin(), loc.end());
    high[node] = min(loc.back() - 1, loc[loc.size() - 2] + 1);



    dist[node] = max(down[node], up[node]);

    for (auto to : list[node]) {
        if (to == root) continue;
        aux.pb(mp(down[to], to));
    }

    if (aux.empty()) return;
    if (aux.size() == 1) {
        up[aux[0].second] = up[node] + 1;
        dfs2(aux[0].second, node);
        return;
    }

    sort(aux.begin(), aux.end());
    reverse(aux.begin(), aux.end());

    up[aux[0].second] = max(up[node] + 1, aux[1].first + 2);
    for (int i = 1; i < aux.size(); i++)
        up[aux[i].second] = max(up[node] + 1, aux[0].first + 2);

    for (auto e : list[node])
        if (e != root)
            dfs2(e, node);
}

void solve(int node, int root) {
    down[node] = 0;
    cnt[node] = tp[node] - '0';

    low[node] = 1 << 30;
    if (tp[node] == '1')
        low[node] = 0;

    for (auto to : list[node]) {
        if (to == root) continue;
        solve(to, node);
        down[node] = max(down[node], down[to] + 1);
        cnt[node] += cnt[to];

        if (cnt[to])
            low[node] = min(low[node], down[to] + 1);
    }

    if (low[node] <= high[node])
        ans += 1LL * (high[node] - low[node] + 1);
}

int main()
{
   // freopen("test.in","r",stdin);

    scanf("%d", &n);
    for (i = 1; i < n; i++) {
        scanf("%d%d", &x, &y);
        list[x].pb(y);
        list[y].pb(x);
    }

    scanf("\n%s", tp + 1);
    dfs(1, 0);
    dfs2(1, 0);

    C = min_element(dist + 1, dist + n + 1) - dist;
    solve(C, 0);

    if (cnt[C] == 0) {
        printf("0");
        return 0;
    }

    printf("%lld", ans + 1);

    return 0;
}


Measured memory_bytes: 30336
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "Good" : "Bad")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(string, s);
  	CoutYN(s[0] != s[1] && s[1] != s[2] && s[2] != s[3]);
}


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

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


Measured memory_bytes: 3084
function main(input) {
   input = input.trim();
  const a = input.split(" ").map(Number);
 console.log(a[1]-a[2]>=0 ?"delicious"
		    :a[2]-a[1]>a[0] ?"dangerous"
		    :"safe");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 30560
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    x = []
    for i in range(n):
        a, b = list(map(str, str(input().rstrip('\n')).split()))
        x.append([a, -int(b), i+1])
    x.sort()
    for i in range(n):
        print(x[i][2])


if __name__ == '__main__':
    slove()


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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1e6 + 20;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL MOD)
{
    if(n < 0) a = fp(a, MOD - 2, MOD), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % MOD) if(n & 1) res = res * a % MOD; return res;
}

void work()
{
    LL n, m;
    cin >>n >>m;
    cout <<(n * (n - 1) / 2) + (m * (m - 1) / 2) <<endl;
}


int main(int argc, char **argv)
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
//    pre();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
import collections

N = input()
M = [input()for i in range(int(N))]
X = collections.Counter(M)
max(X.items(), key=lambda x:x[1])[0]
i = max(X.values())
Y = [k for k, v in X.items() if v == i]
b = len(Y)
Z = sorted(Y,key =str.lower)
for i, v in enumerate(Z):
    if i > b:
        break
    else:
        print(Z[i])

Measured memory_bytes: 47724
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
	int x = 0, p = 1; char c = getchar();	
	while (c <= 32) c = getchar();
	if (c == 45) p = -p, c = getchar();
	while (c > 32) x = x * 10 + c - 48, c = getchar();
	return x * p;
}
using namespace std;
//ruogu_alter
const int N = 1e5 + 5;
char s[N];
int n, pre[N], nxt[N][3], dp[N];
//
inline void add(int &x, int y) {
	x += y; if (x >= MOD) x -= MOD;
}
bool is1() {
	for (int i = 2; i <= n; i++) if (s[i] == s[i - 1]) return false;
	return true;
}
int main() {
	scanf("%s", s + 1); n = strlen(s + 1);
	if (is1()) return !printf("%d\n", 1);
	for (int i = 1; i <= n; i++) {
		pre[i] = (pre[i - 1] + s[i] - 'a' + 1) % 3;
	}
	rep(i, 3) nxt[n][i] = n + 1;
	for (int i = n - 1; i >= 0; i--) {
		rep(j, 3) nxt[i][j] = nxt[i + 1][j];
		nxt[i][pre[i + 1]] = i + 1;
	}
	dp[0] = 1;
	rep(i, n) {
		int x = pre[i];
		rep(j, 3) if(j) add(dp[nxt[i][(j + x) % 3]], dp[i]);
	}
	int res = 0;
	for (int i = 1; i <= n; i++) if (pre[i] == pre[n]) {
		add(res, dp[i]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
using namespace std;
int partition(int A[], int p, int r){
	int x=A[r];
	int i=p-1;
	for(int j=p; j<r; j++){
		if(A[j]<=x){
			i++;
			int memo=A[j];
			A[j]=A[i];
			A[i]=memo;
		}
	}
	int memo=A[i+1];
	A[i+1]=A[r];
	A[r]=memo;
	return i+1;
}
int main(){
	int n;
	cin>>n;
	int A[n];
	for(int i=0; i<n; i++)
		cin>>A[i];
	int r=partition(A, 0, n-1);
	for(int i=0; i<n-1; i++){
		if(i==r){
			cout<<"["<<A[i]<<"]"<<" ";
		}
		else
			cout<<A[i]<<" ";
	}
	cout<<A[n-1]<<endl;
}


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

int main(void){
    string w[3] = {"Sunny", "Cloudy", "Rainy"};
    string s;
    cin >> s;

    if(s == w[0]) cout << w[1] << endl;
    else if(s == w[1]) cout << w[2] << endl;
    else if(s == w[2]) cout << w[0] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void){
    int h,w,ans=0;cin >> h >> w;
    int grid[505][505];
    vector<int> out;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cin >> grid[i][j];
        }
    }
    for(int i=1; i<=h; i++){
        for(int j=1; j<w; j++){
            if(grid[i][j]%2==1){
                out.push_back(i);
                out.push_back(j);
                out.push_back(i);
                out.push_back(j+1);
                grid[i][j]--;grid[i][j+1]++;
            }
        }
        if(i!=h && grid[i][w]%2==1){
            out.push_back(i);
            out.push_back(w);
            out.push_back(i+1);
            out.push_back(w);
            grid[i][w]--;grid[i+1][w]++;
        }
    }
    cout << out.size()/4 << endl;
    for(int i=1; i<=out.size(); i++){
        if(i%4!=0)cout << out[i-1] << " ";
        else cout << out[i-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 5232
import java.util.*;

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

	class R implements Comparable<R>{
		int n;
		String s;
		int p;
		R(int n, String s, int p){
			this.n=n;
			this.s=s;
			this.p=p;
		}
		@Override
		public int compareTo(R arg0) {
			if(this.s.equals(arg0.s)) {
				return Integer.compare(arg0.p, this.p);
			}else {
				return this.s.compareTo(arg0.s);
			}
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		ArrayList<R> l = new ArrayList<>();
		for(int i=0; i<N; i++) {
			String s = sc.next();
			int p = sc.nextInt();
			R r = new R(i+1, s, p);
			l.add(r);
		}
		Collections.sort(l);
		for(R r : l) {
			System.out.println(r.n);
		}
		sc.close();
	}


}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){  
  int n;
  cin >> n;
  deque<int> ans;
  if(n%2==0){
    rep(i,n){ int x; cin >> x; if(i%2==0){ ans.emplace_back(x); } else { ans.emplace_front(x); } }
  } else {
    rep(i,n){ int x; cin >> x; if(i%2==1){ ans.emplace_back(x); } else { ans.emplace_front(x); } }
  }
  for(auto nx:ans){
    cout << nx << " ";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 2944
import java.util.Scanner;


public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int l = 0;
    int r = s.length()-1;
    int ans = 0;
    while(l<r) {
      if(s.charAt(l)!=s.charAt(r)) ans++;
      l++;
      r--;
    }
    System.out.println(ans);
  }

}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    int ans = 0;
    rep(i,n+1) for(int j = 0; j+i <= n; j++){
        if(i+j > k) continue;
        priority_queue<int,vector<int>,greater<int>> pq;
        if(i+j == 0) continue;
        rep(l,i) pq.push(v[l]);
        rep(l,j) pq.push(v[n-1-l]);
        rep(l,k-i-j) if(!pq.empty() && pq.top() < 0) pq.pop();
        int tmp = 0;
        while(!pq.empty()){
            tmp += pq.top();
            pq.pop();
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int maxn=100000+100;
int p[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",p+i);
    int st=0;
    int ans=0;
    for(int i=1;i<n;i++){
        if(p[i]==i){
            swap(p[i],p[i+1]);
            ans++;
        }
    }
    for(int i=n;i>1;i--){
        if(p[i]==i){
            swap(p[i],p[i-1]);
            ans++;
        }
    }
    //for(int i=0;i<n;i++)
        //cout<<p[i+1]<<" ";
        printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include<iostream>

using namespace::std;
int main(){
    int N,i,score=0;
    cin>>N;
    int A[N],B[N],C[N-1];
    for(i=0;i<N;i++)
    cin>>A[i];
     for(i=0;i<N;i++)
    cin>>B[i];
     for(i=0;i<N-1;i++)
    cin>>C[i];
    for(i=0;i<N;i++){
    score+=B[A[i]-1];

    if(i<N-1&&A[i]+1==A[i+1]){
        score+=C[A[i]-1];
    }
      
    }
    cout<<score;
    return 0;
}

Measured memory_bytes: 256
//Author: pranta
//Date: 2020-Aug-03
//Problem: D_Alter_Altar
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
void solve()
{
    int n,cnt=0;
    string s;
    cin>>n>>s;
    int forward=0,backward=n-1;
    while(forward<backward){
        if(s[forward]=='W' and s[backward]=='R'){
            cnt++;
            forward++;
            backward--;
        }
        else{
            if(s[forward]=='R') forward++;
            if(s[backward]=='W') backward--;
        }
    }
    cout<<cnt<<endl;
}
int main()
{
    fast;
    int t;
    solve();
}

Measured memory_bytes: 3748
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * プログラミングコンテスト<br>
 * 0147:Fukushimaken
 *
 * @author t690593
 *
 */
public class Main {

	/** 最大グループ数 */
	static final int MAX_GROUP_NUKMBER = 100;

	/** 客の到着間隔 */
	static final int TIME_INTERVAL = 5;

	/** 座席 */
	static int[] sheets = new int[17];

	/** 各グループの待ち時間 */
	static int[] waitTimes = new int[100];

	/** インプット */
	static List<Integer> inputs = new ArrayList<Integer>();

	/** インプットの最大グループ番号 */
	static int maxGroupNumber;

	/**
	 * メイン
	 *
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNextInt()) {
			int inputNum = scanner.nextInt();
			if (maxGroupNumber < inputNum) {
				maxGroupNumber = inputNum;
			}
			inputs.add(inputNum);
		}

		// 先頭のグループ番号
		int frontGroup = 0;
		// 最後尾のグループ番号
		int endGroup = 0;
		// 経過時間：分単位
		int time = 0;

		while (true) {
			// 5分間隔でお店に客がくる（最後尾は最大グループ数より大きくならない）
			if (time % TIME_INTERVAL == 0 && endGroup < MAX_GROUP_NUKMBER) {
				endGroup++;
			}

			for (int i = frontGroup; i < endGroup; i++) {
				int ninzu = i % 5 == 1 ? 5 : 2;
				int startPos = getOpendSheetsPosition(ninzu);
				if (startPos >= 0) {
					// 座れる場合
					secureSheets(startPos, calcMealtime(i), ninzu);
					waitTimes[i] = time - i * 5;
					frontGroup++;
				} else {
					// 座れない場合
					break;
				}

			}

			// 入力されたグループ番号の最大番号が席に座るか、全てのグループが席に座ったら終了
			if (frontGroup == MAX_GROUP_NUKMBER || frontGroup > maxGroupNumber) {
				break;
			}

			// 座席の食事時間を時間経過とともに減らす
			for (int i = 0; i < sheets.length; i++) {
				if (sheets[i] > 0) {
					sheets[i] = sheets[i] - 1;
				}
			}

			time++;
		}

		for (int input : inputs) {
			System.out.println(waitTimes[input]);
		}
	}

	/**
	 * 空いている席の最初の席番号を返却する<br>
	 * 席が空いていない場合、-1を返却する
	 *
	 * @param peopleNum
	 *            グループの人数
	 * @return 空いている席の最初の席番号
	 */
	private static int getOpendSheetsPosition(int peopleNum) {
		int startPos = -1;
		int openedSheetNum = 0;
		for (int i = 0; i < sheets.length; i++) {
			if (sheets[i] == 0) {
				if (startPos == -1) {
					startPos = i;
				}
				openedSheetNum++;
			} else {
				startPos = -1;
				openedSheetNum = 0;
			}

			if (openedSheetNum == peopleNum) {
				return startPos;
			}
		}
		return -1;
	}

	/**
	 * 対象グループの食事時間を計算する
	 *
	 * @param targetGroup
	 *            対象グループ番号
	 * @return 食事間
	 */
	private static int calcMealtime(int targetGroup) {
		return 17 * (targetGroup % 2) + 3 * (targetGroup % 3) + 19;
	}

	/**
	 * 座席を確保する
	 *
	 * @param startPos
	 *            席確保する最初の席番号
	 * @param mealtime
	 *            確保する時間（食事時間）
	 * @param peopleNum
	 *            グループ人数
	 */
	private static void secureSheets(int startPos, int mealtime, int peopleNum) {
		for (int i = 0; i < peopleNum; i++) {
			sheets[i + startPos] = mealtime;
		}
	}
}

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

#define rp(i,t) for(int i=0;i<(t);i++)
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rsp(i,s,t) for(int i=(s);i<(t);i++)
#define rrp(i,t,s) for(int i=(t);i>=(s);i--)
#define rcp(i,s,b,d) for(int i=(s);b;d)
#define mst(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define N 200002

#define Dp puts("")
#define Dw printf
#define Ds printf("#")

typedef long long ll;
char ch,last;
ll n,a[N],sf[N],sb[N],ans;

inline void read(ll &x){x=ch=0;do{last=ch;ch=getchar();}while(ch<'0'||'9'<ch);do{x=x*10+ch-'0';ch=getchar();}while('0'<=ch&&ch<='9');if(last=='-')x=-x;}

int main(void)
{
	read(n);
	rep(i,1,n)read(a[i]),sf[i]=sf[i-1]+a[i];
	rrp(i,n,1)sb[i]=sb[i+1]+a[i];
	ans=abs(sf[1]-sb[2]);
	rsp(i,2,n)ans=min(ans,abs(sf[i]-sb[i+1]));
	printf("%lld",ans);
	return 0;
}


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

int main(){//main_program
  int N,K;
  cin >> N >> K;
  vector<int> P(N);
  int sum = 0;
  
  for(int i = 0; i < N;i++){
    cin >> P.at(i);
  }
  
  sort(P.begin(), P.end());
  for(int i = 0; i < K;i++){
    sum += P.at(i);
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 3556
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 310;
LL dp[SIZE][SIZE];
int H[SIZE];
template <class T>
void maa(T& x,T y){
    if(x<y)x=y;
}
template <class T>
void mii(T& x,T y){
    if(x>y)x=y;
}
int main(){
    int N,K;
    R(N,K);
    if(N==K){
        W(0);
        return 0;
    }
    FOR(i,1,N){
        R(H[i]);
    }
    FOR(i,1,N)FOR(j,0,N)dp[i][j]=1e18;
    FOR(i,1,N){
        dp[i][i-1]=H[i];
        REPP(j,1,i)FOR(k,0,min(K,j-1)){
            mii(dp[i][k+(i-j-1)],dp[j][k]+max(0,H[i]-H[j]));
        }
    }
    LL an=1e18;
    FOR(i,N-K,N){
        FOR(j,0,K-(N-i))mii(an,dp[i][j]);
    }
    W(an);
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int N, M, Q;
  int *rails;
  int i, j, k;
  int L, R;
  int p, q;
  int ans;
  
  // 整数の入力
  scanf("%d %d %d", &N, &M, &Q);N++;
  
  rails = (int *)malloc(sizeof(int) * N * N);
  for(i = 0; i < N * N; i++){
    rails[i] = 0;
  }
  for(i = 0; i < M; i++){
    scanf("%d %d", &L, &R);
    for(j = 0; j <= R - L; j++){
      rails[(L - 1) * N + j] = rails[(L - 1) * N + j] + 1;
    }
  }
//  for(i = 0; i < N * N; i++){printf("rails(%d, %d) = %d\n", i / N, i % N, rails[i]);}
  // 出力
  for(i = 0; i < Q; i++){
    ans = 0;
    scanf("%d %d", &p, &q);
    for(j = p; j <= q; j++){
      ans = ans + (rails[(j - 1) * N] - rails[(j - 1) * N + (q - j + 1)]);//printf("%d, %d checked ans = %d\n", j-1, (q - j + 1), ans);
    }
    printf("%d\n", ans);
  }
  
  return 0;
}




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

#define ll long long
#define tc(t) int t;cin >> t; while(t--)
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);


void solve() {
    ll k, n;
    cin >> k >> n;
    ll a[n+1] = {};
    for(int i = 1; i<=n; i++) cin >> a[i];
    ll diff = k - (a[n] - a[1]);
    for(int i = 1; i<=n-1; i++) {
        ll curr = a[i+1] - a[i];
        diff = max(diff, curr);
    }
    ll ans = k - diff;
    cout << ans << '\n';
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1792
import sys
import bisect
input = sys.stdin.readline

N = int(input())
L = [int(v) for v in input().split()]

def gcd(a, b):
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    return gcd(b, a % b)

p = L[0]
for v in range(N - 1):
    p = gcd(L[v + 1], p)
    
print(p)

Measured memory_bytes: 14252
using System;
using System.Collections.Generic;
using System.Linq;

public class Prog
{
    public static void Main()
    {
        //var input = Console.ReadLine().Split();
        //int[] X = Array.ConvertAll(input, int.Parse);
        var input = Console.ReadLine().Split();
        int N = int.Parse(input[0]);
        int K = int.Parse(input[1]);
        double rate = 0.0;
        if(N >= K)
        {
            for(int i = 1; i < K; i++)
            {
                int j = 0;
                int x = i;
                while(x < K)
                {
                    x *= 2;
                    j++;
                }
                rate += Math.Pow(1.0/2.0,j) / (double)N;
            }
            rate += (double)(N - K + 1) / (double)N;
        }
        else
        {
            for(int i = 1; i <= N; i++)
            {
                int j = 0;
                int x = i;
                while (x < K)
                {
                    x *= 2;
                    j++;
                }
                rate += Math.Pow(1.0 / 2.0, j) / (double)N;
            }
        }
        Console.WriteLine(rate);
    }
}

//Array.ConvertAll(int.Parse)

Measured memory_bytes: 11092
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

s = list(ns())
f = s[0]
del s[0]
l = s[-1]
del s[-1]
print(f + str(len(s)) + l)


Measured memory_bytes: 3060
import numpy as np
h, w, k = map(int, input().strip().split())
cs = [list(input().strip()) for _ in range(h)]
grid = np.zeros((h, w), dtype=np.int)
for i, row in enumerate(cs):
    for j, cell in enumerate(row):
        if cell == '#':
            grid[i, j] = 1


def count_black(grid, bits_row, bits_col):
    mask = np.ones((h, w), dtype=np.int)
    for i in range(h):
        bit = bits_row >> i & 1
        if bit:
            mask[i] = 0
    for j in range(w):
        bit = bits_col >> j & 1
        if bit:
            mask[:, j] = 0

    return np.sum(grid * mask)

count = 0
for b_row in range(2 ** h):
    for b_col in range(2 ** w):
        c = count_black(grid, b_row, b_col)
        if c == k:
            count += 1

print(count)


Measured memory_bytes: 27244
#include<stdio.h>
#include<stdbool.h>

#define MAX 100001

typedef struct {
  int id, time;
} State;

State queue[MAX];
int head, tail;

void push(int id,int tm) {
  queue[tail].id = id, queue[tail].time = tm;
  tail = ((tail+1==MAX)?0:tail+1);
}

State pop() {
  State v = queue[head];
  head = ((head+1==MAX)?0:head+1);
  return v;
}

inline bool empty() { return (tail - head) == 0; }

int n, q;
char P[MAX][200];

void exec() {
  int total_time = 0;
  while( !empty() ) {
    if( queue[head].time > q ) {
      queue[head].time -= q;
      State tmp = pop();
      push(tmp.id,tmp.time);
      total_time += q;
    } else {
      total_time += queue[head].time;
      printf("%s %d\n",P[queue[head].id],total_time);
      pop();
    }
  }
}

int main() {
  int i, T;
  scanf("%d %d",&n,&q);
  for(i=0;i<n;++i) {
    scanf(" %s %d",&P[i][0],&T);
    push(i,T);
  }
  exec();
  return 0;
}

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

int main() {
    int x, y;
    cin >> x >> y;

    if (x % y == 0) {
        cout << -1 << endl;
    }
    else {
        int i = 1;
        while(1) {
            if (i % x == 0 && i % y != 0) {
                cout << i << endl;
                break;
            }
            i *= x;
        }
    }
}


Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn calc (v: usize, g: &Vec<Vec<usize>>, dp: &mut Vec<i32>) -> i32 {
    if dp[v] >= 0 {
        return dp[v];
    }
    let mut d = 0;
    for &u in &g[v] {
        let t = calc (u, g, dp) + 1;
        d = std::cmp::max (d, t);
    }
    dp[v] = d;
    d
}

fn run() {
    input! {
        n: usize,
        m: usize,
        e: [(usize, usize); m],
    }
    let mut g = vec![vec![]; n + 1];
    for (x, y) in e {
        g[x].push (y);
    }
    for i in 1..(n + 1) {
        g[0].push (i);
    }
    let mut dp = vec![-1; n + 1];
    let ans = calc (0, &g, &mut dp) - 1;
    println! ("{}", ans);
}

fn main() {
    run();
}


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

using namespace std;


int main(int argc, char const* argv[])
{
	int n;
	int start,end;
	vector<int> answer;

	cin >> n;

	for( int i = 0;i < n;i++ ){
		cin >> start >> end;
		answer.clear();

		if( start < end ){
			for( int j = start;j <= end;j++ ) answer.push_back( j );
		} else {
			if( start <= 5 ){
				for( int j = start;j >= end;j-- ) answer.push_back( j );
			} else if( end > 5 ) {
				for( int j = start;j < 10;j++ ) answer.push_back( j );
				for( int j = 5;j >= 0;j-- ) answer.push_back( j );
				for( int j = 1;j <= end;j++ ) answer.push_back( j );
			} else {
				for( int j = start;j < 10;j++ ) answer.push_back( j );
				for( int j = 5;j >= end;j-- ) answer.push_back( j );
			}
		}

		for( unsigned int i = 0;i < answer.size();i++ ) cout << ( ( i == 0 ) ? "" : " " ) << answer[i];
		cout << endl;
	}


	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A =scan.nextInt() ;
		int B = scan.nextInt();
		int C = 3;
		
		if(A*B*C%2 == 0){
			System.out.println("No");
		}
		else {
			System.out.println("Yes");
		}
		scan.close();
	}
}

Measured memory_bytes: 25044
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var R, G, B, N int

func main() {
	sc.Split(bufio.ScanWords)

	R, G, B, N = nextInt(), nextInt(), nextInt(), nextInt()
	ans := 0
	for r := 0; r <= N/R; r++ {
		for g := 0; g <= (N-R*r)/G; g++ {
			if (N-R*r-G*g)%B == 0 {
				//fmt.Println(r, g)
				ans++
			}
		}
	}
	fmt.Println(ans)
}


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

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define fdr(i,a,b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
///////////////////////

int const K = 26;
int cnt[K];
string s;
long long ans;

void solve(){
	cin >> s;
	ans = sz(s) * 1LL * (1 + sz(s)) / 2 + 1;
	fr(i, 0, sz(s)) ++cnt[s[i]-'a'];
	fr(i, 0, sz(s)){
		ans -= cnt[s[i]-'a'];
		--cnt[s[i]-'a'];
	}
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();



	return 0;
}

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

int main(void){
    int n, m;
    std::cin >> n >> m;

    if(n >= m){
        int ans = 0;
        std::cout << ans << std::endl;
        return 0;
    }

    //n < m;

    std::vector<int> x(m);
    for(int i = 0; i < m; i++){
        std::cin >> x.at(i);
    }

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

    
    std::vector<int> gap(m-1);
    for(int i = 0; i < m-1; i++){
        gap.at(i) = x.at(i+1) - x.at(i);
    }

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

    long long ans = 0;

    for(int i = 0; i < m - n; i++){
        ans += gap.at(i);
    }

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

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	scanner := NewScanner()
	n := scanner.NextInt()
	k := uint64(scanner.NextInt64())
	as := make([]uint64, n)
	for i := 0; i < n; i++ {
		as[i] = uint64(scanner.NextInt64())
	}
	fmt.Println(Max(63, k, as))
}

func Max(digitNum uint, k uint64, as []uint64) uint64 {
	mask := uint64(1) << digitNum
	countOne, power := CountOne(digitNum, as), mask
	n := uint64(len(as))
	if k&mask == 0 {
		x := countOne * power
		if digitNum > 0 {
			x += Max(digitNum-1, k, as)
		}
		return x
	}

	// topDigit == 0
	x := countOne * power
	for i := uint(0); i < digitNum; i++ {
		count := CountOne(i, as)
		if n/2 >= count {
			x += (n - count) * (uint64(1) << i)
		} else {
			x += count * (uint64(1) << i)
		}
	}
	// topDigit == 1
	y := (n - countOne) * power
	if digitNum > 0 {
		y += Max(digitNum-1, k, as)
	}
	if x > y {
		return x
	} else {
		return y
	}
}

func CountOne(digitNum uint, as []uint64) uint64 {
	ans := uint64(0)
	mask := uint64(1) << digitNum
	for _, a := range as {
		if a&mask > 0 {
			ans++
		}
	}
	return ans
}

type Scanner struct {
	scanner *bufio.Scanner
}

func NewScanner() *Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &Scanner{s}
}

func (s *Scanner) NextWord() string {
	if !s.scanner.Scan() {
		log.Fatal("failed to find the next word")
	}
	return s.scanner.Text()
}

func (s *Scanner) NextInt() int {
	str := s.NextWord()
	i, err := strconv.Atoi(str)
	if err != nil {
		log.Fatalf("failed to parse %s to int", str)
	}
	return i
}

func (s *Scanner) NextInt64() int64 {
	str := s.NextWord()
	i, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		log.Fatalf("failed to parse %s to int64", str)
	}
	return i
}


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

using namespace std;
typedef long long ll;

const int N = int(1e8) + 7;

void init(){

}

void solve(){
    int a;
    scanf("%d", &a);
    printf("%d\n", a*a*3);
}

const bool mtc = false;

int main(){
    int t;
    if(mtc){
        scanf("%d", &t);
        while(t--) solve();
    }
    else solve();
}



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

int main (){
    char S[10];
    for (int i = 0; i < 10; i++){
        cin >> S[i];
    }
    if (S[6] - '0' >= 5){
        cout << "TBD" << endl;
    } else if (S[5] - '0' == 1) {
        cout << "TBD" << endl;
    } else {
        cout << "Heisei" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d]) ** 2
        if int(dist ** 0.5) ** 2 == dist:
            ans += 1

print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int mypow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> six(7), nine(7);
	for (int i = 0; i <= 6; i++) {
		six[i] = mypow(6, i);
		nine[i] = mypow(9, i);
	}
	vector<int> dp(N + 1, INF);
	dp[0] = 0;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= 6; j++) {
			if (i >= six[j]) dp[i] = min(dp[i], dp[i - six[j]] + 1);
			if (i >= nine[j]) dp[i] = min(dp[i], dp[i - nine[j]] + 1);
		}
	}

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

	return 0;
}

Measured memory_bytes: 640
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>

using namespace std;



int main(){
	string s;
	cin>>s;
	bool used[26];
	for(int i=0;i<26;i++){
		used[i]=false;
	}
	for(int i=0;i<s.length();i++){
		used[s.at(i)-'a']=true;
	}
	if(s.length()<=25){
		int min_index=0;
		for(int i=0;i<26;i++){
			if(used[i]==false){
				min_index=i;
				break;
			}
		}
		cout<<s<<(char)(min_index+'a')<<endl;
	}else{
		int last_index=24;
		bool used_in[26];
		for(int i=0;i<26;i++){
			used_in[i]=false;
		}
		used_in[s[25]-'a']=true;

		while(true){
			used_in[s[last_index]-'a']=true;
			if(s[last_index]>s[last_index+1]){
				last_index--;
				if(last_index==-1){
					break;
				}
			}else{
				break;
			}
		}
		if(last_index==-1){
			cout<<-1<<endl;
		}else{
			for(int i=0;i<last_index;i++){
				cout<<s[i];

			}
			for(int i=s[last_index]-'a'+1;i<=25;i++){
				if(used_in[i]){
					cout<<(char)(i+'a')<<endl;
					break;
				}
			}
		}

	}

	return 0;
}



Measured memory_bytes: 256
INF = -float('inf')
 
def bellmanford(n,e,r):
  costs = [INF]*n
  costs[r] = 0
  for i in range(n):
    for u,v,c in e:
      if costs[u]+c > costs[v] and costs[u]!=INF:
        costs[v] = costs[u]+c
        if i==n-1 and v==n-1:
          return 'inf'
  return costs[n-1]
 
n,m = map(int, input().split())
edge = []
for i in range(m):
  a,b,t = map(int, input().split())
  edge.append((a-1,b-1,t))
 
print(bellmanford(n,edge,0))

Measured memory_bytes: 74804
// Kenus the Ancient Greek
// * frank_c1
// * 2017 / 11 / 08

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int maxw = 87;
const int mo = (int)(1e9) + 7;
LL f[maxw + 10];
vector<pair<LL, LL> > g[maxw + 5];

void gen() {
	f[0] = f[1] = 1;
	for (int i = 2; i <= maxw + 3; ++i) f[i] = f[i - 1] + f[i - 2];
	g[0].push_back(make_pair(1, 1));
	for (int i = 0; i < maxw; ++i) {
		for (int j = 0; j < (int)g[i].size(); ++j) {
			LL y = g[i][j].first, x = g[i][j].second + y;
			while (x <= f[i] + f[i + 3]) {
				g[i + 1].push_back(make_pair(x, y)); x += y;
			}
		}
	}
}

LL calc(LL n, LL m, int p) {
	LL ret = 0;
	for (int j = 0; j < (int)g[p - 1].size(); ++j) {
		LL x = g[p - 1][j].first, y = g[p - 1][j].second;
		if (x <= m) (ret += (n - y) / x) %= mo;
	} return ret;
}

void solve() {
	LL n, m; 
	scanf("%lld%lld", &n, &m);
	if (n < m) swap(n, m);
	if (n == 2 && m == 2) {
		printf("1 4\n"); return;
	}
	if (m == 1) {
		printf("1 %d\n", n % mo); return;
	}
	int p = 2, res= 0;
	for (; n >= f[p + 1] && m >= f[p]; ++p); --p;
	printf("%d ", p); res = calc(n, m, p); 
	if (f[p + 1] <= m) res += calc(m, m, p);
	printf("%d\n", res % mo);
}

int main() {
	gen();
	int T; 
	scanf("%d", &T);
	while (T--) solve(); 
	return 0;
}

Measured memory_bytes: 4096