akhauriyash/Code-Regression huggingface dataset:
n,k=gets.chomp.split(' ').map(&:to_i)
r,s,p=gets.chomp.split(' ').map(&:to_i)
t=gets.chomp.chars
results = []
n.times do |i|
    if i<k
        if t[i]=="r"
            results<<["p",p]
        elsif t[i]=="s"
            results<<["r",r]
        else
            results<<["s",s]
        end
    else
        if t[i]=="r"&&(results[i-k][0]!="p")
            results<<["p",p]
        elsif t[i]=="s"&&(results[i-k][0]!="r")
            results<<["r",r]
        elsif t[i]=="p"&&(results[i-k][0]!="s")
            results<<["s",s]
        elsif t[i]=="r"
            if t[i+k]!="s"
                results<<["r",0]
            else
                results<<["s",0]
            end
        elsif t[i]=="s"
            if t[i+k]=="p"
                results<<["p",0]
            else
                results<<["s",0]
            end
        else
            if t[i+k]=="s"
                results<<["p",0]
            else
                results<<["r",0]
            end
        end
    end
end
ans = results.inject(0){|sum,num|sum+=num[1]}
puts ans


Measured memory_bytes: 24188
S = list(input())
l = [chr(i) for i in range(65, 65+26)]

flag = True
count = 0
for i in range(len(S)):
    if i == 0:
        if S[i] != 'A':
            flag = False
            break
    if i == 1:
        if S[i] in l:
            flag = False
            break
    if 2 <= i <= len(S) - 2:
        if S[i] == 'C':
            count += 1
        elif S[i] in l:
            flag = False
            break
    if i == len(S) - 1:
        if S[i] in l:
            flag = False
            break
if not count == 1:
    flag = False

if flag:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 9104
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String line = in.nextLine();
        String[] Array = line.split(" ");
        int A = Integer.parseInt(Array[0]);
        int B = Integer.parseInt(Array[1]);
        System.out.println(A*B+" "+2*(A+B));
    }
}

Measured memory_bytes: 26148
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
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;

int main(){
  ll a, b;
  cin >> a >> b;
  if(a<=5){
    cout << 0 << endl;
  }
  else if(a>5&&a<=12){
    cout << b / 2 << endl;
  }
  else{
    cout << b << endl;
  }
}

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

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

    if(n%1000==0){
        cout<<"0"<<endl;
    }else{
        cout<<(n/1000+1)*1000-n<<endl;
    }
}

Measured memory_bytes: 3632
def partition(a,p,r):
    x = int(a[r][1])
    i = p - 1
    for j in range(p,r):
        if int(a[j][1]) <= x:
            i += 1
            a[i],a[j] = a[j],a[i]
    a[i+1],a[r] = a[r],a[i+1]
    return i + 1
def quicksort(a,p,r):
    if p < r:
        q = partition(a,p,r)
        quicksort(a,p,q-1)
        quicksort(a,q+1,r)
n = input()
a = [map(str, raw_input().split()) for i in range(n)]
b = a[:]
quicksort(a,0,n-1)
print "Stable" if a == sorted(b, key = lambda x: int(x[1])) else "Not stable"
for s,i in a: print s,i

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

int main(void){
    
    int n = 0;
    cin >> n;
    
    
    int a[n];
    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
    }
    
    for(int i = (n-1) ; i >= 0 ;){
        cout << a[i];
        i--;
        if(i < 0){
            cout << endl;
            break;
        }else{
            cout << ' ';
        }
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()


int main() {
	int n;
	cin >> n;
	vector<int>d(n);
	rep(i, n)cin >> d[i];
	sort(all(d));
	int cnt = 1;
	rep(i, n - 1) {
		if (d[i] == d[i + 1])continue;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}





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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int64> pii;
typedef vector<int> vi;

const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 100000 + 10;

int n;
vector<int> adj[maxn];

void dfs(int s, int p, int l,   vector<int> &deg,
                                vector<int> &tot){
    int d = (int)adj[s].size() - 1;
    if (p == -1) d++;

    tot[l]++;
    deg[l] = max(deg[l], d);

    for (auto u : adj[s]){
        if (u != p){
            dfs(u, s, l + 1, deg, tot);
        }
    }
}

pii calc(vector<int> &deg, vector<int> &tot, bool edge){
    while (!tot.back()){
        assert(deg.back() == 0);

        tot.pop_back();
        deg.pop_back();
    }

    assert(deg.back() == 0);

    int A = tot.size();
    int64 X = 1;

    for (int i = 0; i + 1 < (int)deg.size(); ++i)
        X *= deg[i];

    if (edge)
        X *= 2;

    return {A, X};
}

pii solve_edge(int u, int v){
    vector<int> deg(n), tot(n);

    dfs(u, v, 0, deg, tot);
    dfs(v, u, 0, deg, tot);

    return calc(deg, tot, true);
}

pii solve_node(int u){
    vector<int> deg(n);
    vector<int> tot(n);

    dfs(u, -1, 0, deg, tot);

    return calc(deg, tot, false);
}

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

    cin >> n;

    for (int i = 0; i + 1 < n; ++i){
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    pii ans(n, 0);

    for (int i = 1; i <= n; ++i){
        pii ncur = solve_node(i);
        ans = min(ans, ncur);

        for (auto u : adj[i]){
            pii ecur = solve_edge(i, u);
            ans = min(ans, ecur);
        }
    }

    cout << ans.first << " " << ans.second << endl;

    return 0;
}

Measured memory_bytes: 2560
r, c = map(int, input().split())

matrix = [list(map(int, input().split())) for _ in range(r)]

for i in range(r):
    matrix[i].append(sum(matrix[i]))

matrix.append(list(map(sum, zip(*matrix))))
# matrix.append([sum(i) for i in zip(*matrix)])

for row in matrix:
    print(' '.join(str(e) for e in row))



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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; }

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    int d = min({abs(a-b)+abs(b-c),abs(b-c)+abs(c-a),abs(c-a)+abs(a-b)});
    cout << d << endl;
    return 0;
}

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

#define int int_fast32_t

signed main()
{
        string S;
        string T;

        cin >> S >> T;
        
        for ( int i = 0; i < (int)S.size() - (int)T.size() + 1; i++ ) {
                if ( S.substr(i, T.size()) == T ) cout << i << endl;
        }

        return (0);
}


Measured memory_bytes: 3176
a = []
import heapq  # heapqライブラリのimport

heapq.heapify(a)  # リストを優先度付きキューへ

while True:
    cm = input()
    if cm=='end':
        break
    elif cm.split()[0]=='insert':
        heapq.heappush(a, int(cm.split()[1])*(-1)) 
    elif cm.split()[0]=='extract':
        print(heapq.heappop(a)*(-1))


Measured memory_bytes: 45308
a,b,k=map(int,input().split())
if 2*k>=b-a+1:
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+k):
    print(i)
  for j in range(b-k+1,b+1):
    print(j)

Measured memory_bytes: 3060
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

H, N = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))

ok =H <= sum(A)
if ok:
    print('Yes')
else:
    print('No')


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

//.define
// #define FILE_IN_OUT
#define RET(_x)                       return cout << (_x) << '\n', 0;
#define all(_obj)                     std::begin(_obj), std::end(_obj)
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define ceilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define has(_obj, _val)               ((_obj).find(_val) != (_obj).end())
#define sz(_obj)                      static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)                     std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                     {}
#endif
#define endl "\n"
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
int dp[2][3005];

int Add(int x, int y) {
    x += y;
    return x < MOD ? x : x - MOD;
}

int Sub(int x, int y) {
    x -= y;
    return x >= 0 ? x : x + MOD;
}

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n;
    string s;
    cin >> n >> s;
    int cur = 0;
    dp[0][0] = 1;
    for (int i = 0; i < sz(s); ++i) {
        int pre = cur;
        cur ^= 1;
        memset(dp[cur], 0, sizeof(dp[cur]));
        for (int j = 1; j <= i + 1; ++j) {
            dp[pre][j] = Add(dp[pre][j - 1], dp[pre][j]);
        }
        for (int x = 0; x <= i + 1; ++x) {
            if (s[i] == '>') {
                dp[cur][x] = Sub(dp[pre][i + 1], x ? dp[pre][x - 1] : 0);
            } else {
                dp[cur][x] = x ? dp[pre][x - 1] : 0;
            }
        }
    }
    int ans = 0;
    loop(n) {
        ans = Add(ans, dp[cur][i]);
    }
    cout << ans << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int a ,b;
  string op;
  cin>>a>>op>>b;
  if(op=="+")
    {
      cout<<a+b<<endl;
    }
  if(op=="-")
    {
      cout<<a-b<<endl;
    }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
char in[20];
int c[26];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%s",in);
		c[in[0]-'A']++;
	}
	int left=-1;
	int right=20000;
	while(left+1<right){
		int M=(left+right)/2;
		int tmp=0;
		for(int i=0;i<26;i++)tmp+=min(c[i],M);
		if(M*b>tmp)right=M;
		else left=M;
	}
	printf("%d\n",left);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-7
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int main() {
	speed;
	int n;
	cin >> n;
	vector<int>v(n + 2);
	vector<int>ans(n + 2, inf);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	ans[0] = 0;
	for (int i = 0; i < n; ++i)
		ans[i + 1] = min(ans[i + 1], ans[i] + abs(v[i] - v[i + 1])),
		ans[i + 2] = min(ans[i + 2], ans[i] + abs(v[i] - v[i + 2]));
	cout << ans[n - 1];
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    string s;int ans;
    cin >> s;
    vector<string> a={"SAT","FRI","THU","WED","TUE","MON","SUN"};
    for(int i = 0; i < 7; ++i) if(s== a.at(i)) ans = i + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
int a[110], n;
int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    int min_ans = 1e9, ans;
    for (int i = a[1]; i <= a[n]; ++i) {
        ans = 0;
        for (int j = 1; j <= n; ++j) {
            ans += (a[j] - i) * (a[j] - i);
        }
        min_ans = min(min_ans, ans);
    }
    cout << min_ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int K, X;
    int minimum = -1000000;
    int maximum = 1000000;
    cin >> K >> X;
    if(X-K+1> -1000000){
        minimum = X-K+1;
    }
    if(X+K-1< 1000000){
        maximum = X+K-1;
    }
    for(int i = minimum; i <= maximum; i++){
        cout << i << " ";
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;

ll calc(ll d) {
  ll ret=1ll;
  rep(i, N) {
    ret*=d;
    ret%=MOD;
  }
  return ret;
}

int main() {
  INCANT;
  cin >> N;
  // 全事象-(0が全く存在しない)-(9が全く存在しない)+(0と9が存在しない)
  ll ans = calc(10)-2*calc(9)+calc(8);
  while(ans<0) ans+=MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int sum(int m){
  return (m/1)%10+(m/10)%10+(m/100)%10+(m/1000)%10+(m/10000)%10;
}

int main() {
  int N,m;
  m=50;
  cin>>N;
  	for(int i=1;i<N;i++){
      m=min(m,sum(i)+sum(N-i));
    }
  cout<<m<<endl;
}

Measured memory_bytes: 256
A, B = list(map(int, input().split()))

if A==1:
	if A==B:
		print('Draw')
	else:
		print('Alice')
elif B==1:
	print('Bob')
else:
	if A==B:
		print('Draw')
	elif A>B:
		print('Alice')
	else:
		print('Bob')

Measured memory_bytes: 2940
// Author: Tyler Wang

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.precision(12);
  std::cerr.precision(12);
  std::mt19937 rng((std::uint_fast32_t)std::chrono::high_resolution_clock::now()
                       .time_since_epoch()
                       .count());
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }
  vector<long long> sum(1 << n);
  for (int mask = 0; mask < (1 << n); ++mask) {
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if ((mask & (1 << i)) && (mask & (1 << j))) {
          sum[mask] += a[i][j];
        }
      }
    }
  }
  vector<long long> dp(1 << n);
  for (int mask = 0; mask < (1 << n); ++mask) {
    for (int k = mask; k != 0; k = (k - 1) & mask) {
      dp[mask] = max(dp[mask], dp[mask ^ k] + sum[k]);
    }
  }
  cout << dp[(1 << n) - 1] << '\n';
  return 0;
}

Measured memory_bytes: 1280
n = input()
n = int(n)
lin = input().split()
# 要素の個数を求める
dic_s = {}
for c in lin:
  dic_s.setdefault(c, 0)
  dic_s[c] += 1
# ペアの総数
tot = 0
for key,value in dic_s.items():
  v = value
  tot += v * (v - 1) / 2
# print(int(tot))
# 指定位置のペアを除く
for c in lin:
  if tot > 0:
    v = dic_s[c]
    print(int(tot-(v-1)))
  else:
    print(0)

Measured memory_bytes: 26404
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator sl
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
set<LL>v;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    cin>>n;
    k=0;
    s=0;t=0;z=0;
    for(i=0;i<n;i++)
    {
      cin>>p>>q>>o;
      if( p-s<(abs(t-q)+abs(z-o)) || (p-s)%2!=(abs(t-q)+abs(z-o))%2)
      {
          k=1;
      }
      s=p;
      t=q;
      z=o;
    }
    if(k==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter
n, m, *ab = (int(x) for x in sys.stdin.read().split())

bridges = 0
still_exist = True
while still_exist:
    bef = len(ab)
    for vertex, edges_count in Counter(ab).items():
        if edges_count == 1:
            i = ab.index(vertex)
            if i % 2 == 0: del ab[i:i+2]
            else: del ab[i-1:i+1]
            bridges += 1
            break 
    aft = len(ab)
    if bef == aft: still_exist = False

print(bridges)

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

X,N=map(int,input().split())
P=list(map(int,input().split()))
A=[]
for a in range(0,102):
    if not a in P:
        A.append(a)

ans=0
for a in A:
    if abs(X-a) < abs(X-ans):
        ans=a

print(ans)


Measured memory_bytes: 9176
#include<iostream>  
#include<cmath>
#include<string>
#include<stack>
#include<queue> 
#include<algorithm>
#include<stdlib.h> 
#include<ctime>
using namespace std;
int main(){ 
	long long n,m;
	cin>>n>>m;
	if(n==1||m==1)
		cout<<1;
	else if(n%2==0||m%2==0){
		if(n%2==0)
			cout<<n/2*m;
		else
			cout<<m/2*n;
	}
		
	else
		cout<<n*m/2+1;
}




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

N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.append(X)
y.append(Y)
x_max =	max(x)
y_min =	min(y)

if y_min - x_max > 0:
    print("No War")
else:
    print("War")



Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var a=scan.nextLine()
    var b=scan.nextLine()
        var c= ""

    for(i in 0..a.length-1)
    {
        c+=b[i]
    }
    if(a==c)
        println("Yes")
    else
        println("No")
}


Measured memory_bytes: 36400
// https://atcoder.jp/contests/abc118/tasks/abc118_c

// http://ctylim.hatenablog.com/entry/2015/08/30/191553
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>


#define ALL(a) (a).begin(), (a).end()
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define MAXINDEX(c) distance((c).begin(), max_element((c).begin(), (c).end()))
#define MININDEX(c) distance((c).begin(), min_element((c).begin(), (c).end()))
#define DEBUG(x) std::cerr << #x << " = " << (x) << " (" << __FILE__ << "::" << __LINE__ << ")" << std::endl;
#define ERROR(s) std::cerr << "Error::" << __FILE__ << "::" << __LINE__ << "::" << __FUNCTION__ << "::" << (s) << std::endl;
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)


#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

int inputValue(){
  int a;
  std::cin >> a;
  return a;
}

void inputArray(int *p, int a){
    rep(i, a){
        std::cin >> p[i];
    }
}

void inputVector(std::vector<int> *p, int a){
  rep(i, a){
    int input;
    std::cin >> input;
    p->push_back(input);
  }
}

template <typename T>
void output(T a, int precision){
  if (precision > 0){
    std::cout << std::setprecision(precision) << a << "\n";
  }else{
    std::cout << a << "\n";
  }
}

using namespace std;

int gcd(int a,int b){
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}


int main(int argc ,char **argv){

  int N = inputValue();
  vector <int> v;
  inputVector(&v, N);

  // cout << gcd(5,13) << endl;
  int d = 0;
  EACH(k, v) {
    d = gcd(d, *k);
  }
  cout << d << endl;

	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

// https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }


  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> As(n);
  for (int i = 0; i < n; i++) {
      cin >> As[i];
  }
  int max_a = *max_element(As.begin(), As.end());

  SegmentTree< int > seg(max_a + 1, [](int a, int b) { return max(a, b); }, 0);
  for (auto a: As) {
    int ret = seg.query(max(a - k, 0), min(a + k + 1, max_a + 1));
    seg.update(a, ret + 1);
  }
  cout << seg.query(0, max_a + 1) << endl;

  return 0;
}

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

#define int long long
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*
ifstream ifs("in.txt");
ofstream ofs("out.txt");
#define cin ifs
#define cout ofs
//*/

// Union-Find木
const int MAX_N = 100000;

struct UF {
    int par[MAX_N];   // 親
    int rank[MAX_N];  // 木の深さ

    // n要素で初期化
    void init(int n) {
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    // 木の根を求める
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;

        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
    }

    // xとyが同じ集合に属するか否か
    bool same(int x, int y) { return find(x) == find(y); }
};
int N, M;
int p[110000];
int inv[110000];
int x[110000], y[110000];
UF uf;

signed main() {
    cin >> N >> M;
    uf.init(N + 10);
    for (int i = 1; i <= N; i++) {
        cin >> p[i];
        inv[p[i]] = i;
    }
    for (int i = 0; i < M; i++) {
        cin >> x[i] >> y[i];
        uf.unite(x[i], y[i]);
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (uf.same(i, p[i])) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

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

  ll ans = 0;
  vector<int> a[26];

  string s, t;
  cin >> s >> t;
  auto n = s.size();
  rep(i, 0, n - 1) {
    a[s[i] - 'a'].pb(i);
  }
  int prev = -2;
  ll count = 0;
  for (const auto & c: t) {
    auto & ac = a[c - 'a'];
    if (ac.empty()) {
      count = 0;
      prev = -2;
      break;
    }

    auto x = upper_bound(ac.begin(), ac.end(), prev);
    if (x == ac.end()) {
      ++count;
      prev = ac[0];
    } else {
      prev = *x;
    }
  }
  ans = n * count + prev + 1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;


int main() {
    ll H, W;
    cin >> H >> W;

    if (H == 1 || W == 1){
        cout << 1 << endl;
        return 0;
    }
    if (H * W % 2 == 1){
        cout << H * W / 2 + 1 << endl;
    }
    else {
        cout << H * W / 2 << endl;
    }
}


Measured memory_bytes: 256
D = 61
n,k = gets.split(" ").map(&:to_i)
a = gets.split(" ").map(&:to_i)
aaa = []
aaa.push(a)
vv = []
D.times do |j|
	vv = []
n.times do |i|
 vv << aaa[j][aaa[j][i]-1]
end
aaa << vv
end
ans = 1
e =  Math.log10(k.to_s(2).to_i).ceil
(e+1).times do |l|
if k[l] == 1
ans = aaa[l][ans-1]
end
end
p ans

Measured memory_bytes: 123752
#include<iostream>

int main()
{
	double height, max=0, min=0;

	bool flg=1;

	while(std::cin >> height)
	{
		if(flg)
		{
			max=height;

			min=height;

			flg=0;
		}

		if(height>max)
		{
			max = height;
		}

		if(height<min)
		{
			min = height;
		}
	}

	std::cout << max-min << '\n';
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

int f(int a, int b) {
  if (a > b) swap(a, b);
  return (b + a) / (a + 1);
}

vector<array<int, 3>> g(int a, int b) {
  if (a > b) swap(a, b);
  int k = f(a, b);
  int pb = b % k;
  int pa = a - b / k;
  int n = b / k;
  if (pb == 0) {
    pa++;
    pb = k;
    --n;
  }
  vector<array<int, 3>> res;
  while (pa > k) {
    int t = min(pa / k, pb);
    res.push_back({k, 1, t});
    pa -= k * t;
    pb -= t;
    if (pb == 0) {
      int t = max(0, pa - k) / k / k * k;
      if (t) res.push_back({k, 1, t});
      n -= t / k + 1;
      pa -= k * t;
      pa += 1 + t / k;
      pb = k;
/*      --n;
      pa += 1;
      pb += k;*/
      assert(n >= 0);
    }
  }
  res.push_back({pa, pb, 1});
  res.push_back({1, k, n});
  return res;
}

string calc(array<int, 3> x, int l, int r) {
  int t = x[0] + x[1];
  string s = "";
  for (int i = l - 1; i < r; ++i) {
    int j = i % t;
    if (j < x[0]) s += "A";
    else s += "B";
  }
  return s;
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int T;
  cin >> T;
  for (int test = 1; test <= T; ++test) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<array<int, 3>> res = g(a, b);
    if (a > b) {
      reverse(res.begin(), res.end());
      for (int i = 0; i < res.size(); ++i) {
        swap(res[i][0], res[i][1]);
      }
    }
    string ans;
    for (int i = 0; i < res.size() && d > 0; ++i) {
      auto x = res[i];
      int l = (x[0] + x[1]) * x[2];
      if (l < c) {
        c -= l;
        d -= l;
        continue;
      }
      ans += calc(x, c, min(d, l));
      c = 1;
      d -= l;
    }
    cout << ans << endl;
  }
  return 0;
}

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

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

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

  ll INF = pow(10,9);
  if(s==INF) INF--;
  
  rep(i,n){
    if(i<k) cout<<s<<" ";
    else cout<<INF<<" ";
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {

  int N; std::cin >> N;
  std::vector<std::pair<long long, long long>> W(N);
  for(int i=0; i<N; i++) std::cin >> W[i].first >> W[i].second;

  std::sort(W.begin(), W.end(), [](std::pair<ll,ll> a, std::pair<ll,ll> b) { return a.second < b.second; });

  long long cur = 0;
  for(int i=0; i<N; i++) {
    if ( cur + W[i].first <= W[i].second ) cur += W[i].first;
    else {
      std::cout << "No" << std::endl;
      return 0;
    }
  }
  std::cout << "Yes" << std::endl;

  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<math.h>
using namespace std;

int main(){
    double a,b,c,d=0,e=0;
    string s;
    cin>>s;
    if(s[0]=='A'){cout<<'T';}
    if(s[0]=='C'){cout<<'G';}
    if(s[0]=='T'){cout<<'A';}
    if(s[0]=='G'){cout<<'C';}
    return 0;
}


Measured memory_bytes: 3476
n, m = map(int, input().split())

ret = 0

if (n >= 3) and (m >= 3):
    ret += (n-2) * (m-2)

if (n == 1) and (m >= 3):
    ret += m - 2

if (m == 1) and (n >= 3):
    ret += n - 2

if (m == 1) and (n == 1):
    ret += 1

print(ret)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define inf 1000000000
using namespace std;

int m, s, g;
map<int, int> mp;
//ダイスの目
int dice[7] = {0};
//ワープ位置
int wp[305] = {0};
// iでjを出した時に行く場所のメモ(0で正、1で負)
int memo[305][7][2] = {0};
//ゴールに行くまでの最短手数と、そのときのダイスの目
pair<int, int> process[305];
// iに行くためにいる必要がある場所と、そのときに振る必要があるダイスの目のペア
vector<pair<int, int>> v[305];
// process埋め
queue<int> qu;
//ダイクストラ 辺の重み、現在の場所
priority_queue<pair<int, int>, vector<pair<int, int>>,
               greater<pair<int, int>>>
    pq;

int makerand();

int main() {
  srand((int)time(0));
  int i, j, x, now = 0, y;
  cin >> m;
  for(i = 0; i <= m; ++i) process[i].first = inf;

  for(i = 1; i <= 6; ++i) {
    cin >> dice[i];
    ++mp[dice[i]];
  }
  cin >> s >> g;
  for(i = 1; i <= m; ++i) cin >> wp[i];
  for(i = 1; i <= m; ++i)
    for(j = 1; j <= 6; ++j) {
      if(i + dice[j] <= m) {
        memo[i][j][0] = i + dice[j] + wp[i + dice[j]];
        v[memo[i][j][0]].push_back(make_pair(i, j));
      }
      if(i - dice[j] >= 1) {
        memo[i][j][1] = i - dice[j] + wp[i - dice[j]];
        v[memo[i][j][1]].push_back(make_pair(i, -j));
      }
    }
  qu.push(g);
  process[g].first = 0;
  /*while(qu.size() > 0) {
    x = qu.front();
    if(x == s) break;
    qu.pop();
    for(i = 0; i < v[x].size(); ++i)
      if(process[v[x][i].first].first >
         process[x].first + 1) {
        process[v[x][i].first].first = process[x].first
  + 1; qu.push(v[x][i].first);
        process[v[x][i].first].second = v[x][i].second;
      }
  }*/
  pq.push(make_pair(0, g));
  while(pq.size() > 0) {
    pair<int, int> np;
    np = pq.top();
    pq.pop();
    x = np.second;
    for(i = 0; i < v[x].size(); ++i) {
      y = process[x].first +
          60 / mp[dice[max(v[x][i].second,
                           -v[x][i].second)]];
      if(process[v[x][i].first].first > y) {
        process[v[x][i].first].first = y;
        process[v[x][i].first].second = v[x][i].second;
        pq.push(make_pair(process[v[x][i].first].first,
                          v[x][i].first));
      }
    }
  }
  now = s;
  /*for(i = 1; i <= m; ++i)
    cout << process[i].first << " " << process[i].second
         << endl;*/
  while(now != g) {
    cin >> x;
    // x = makerand();
    // cout << "x:" << x << " ";
    if(dice[max(process[now].second,
                -process[now].second)] == dice[x]) {
      if(process[now].second > 0) {
        cout << 1 << endl;
        now = memo[now][x][0];
      }
      else {
        cout << -1 << endl;
        now = memo[now][x][1];
      }
    }
    else {
      cout << 0 << endl;
    }
  }
  return 0;
}

int makerand(){

	return 1 + rand() % 6;
}


Measured memory_bytes: 3308
package main

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

func solve() {
	k := scanInt()
	sum := 0
	// for i := 0; i < k; i++ {
	// 	for j := 0; j < i; j++ {
	// 		sum += 6 * (i - j - 1) * (j + 1)
	// 		fmt.Println(6 * (j + 1) * (j + 1))
	// 	}
	// 	sum += i + 1
	// }
	for i := 1; i < k+1; i++ {
		for j := 1; j < k+1; j++ {
			for h := 1; h < k+1; h++ {
				sum += gcd(gcd(h, i), j)
			}
		}
	}
	fmt.Println(sum)
	return
}

var sc = bufio.NewScanner(os.Stdin)

func gcd(a int, b int) int {
	if b == 0 {
		return a

	}

	return gcd(b, a%b)
}
func read() string {
	sc.Scan()
	return sc.Text()
}
func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}
func pow(n int, m int) int {
	ans := 1
	for i := 0; i < m; i++ {
		ans *= n
	}
	return ans
}
func main() {
	sc.Split(bufio.ScanWords)
	solve()
}


Measured memory_bytes: 1780
#include <stdio.h>

void insertionSort(int*, int);

int main(){
  int i;
  int j;
  scanf("%d", &i);
  int A[i];
  for(j=0;j<i;j++){
    scanf("%d", &A[j]);
  }
  for(j=0;j<i;j++){
    printf("%d", A[j]);
    if(j!=i-1)printf(" ");
    
  }
  printf("\n");
  insertionSort(A,i);
  return 0;
}

void insertionSort(int *A,int N){

  int i,j,v;
  
  for(i=1;i<=N-1;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(j=0;j<N;j++){
    printf("%d", A[j]);
    if(j!=N-1)printf(" ");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2072
open Scanf;;
let s = scanf "%s\n" (fun x -> x);;
let len = String.length s;;
let palin_len = len/2;;
let diff = ref 0;;
for k=0 to palin_len-1 do
  let remote_index = len-1-k in
  if s.[k] != s.[remote_index] then begin
  (* Printf.printf "%d\n" k; *)
  diff := !diff + 1
  end;
done;;
Printf.printf "%d\n" !diff;;

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    REP(i,N)cin >> A[i] >> B[i];
    ll ans = 0;
    bool equal = 1;
    ll mn = mod;
    ll sum = 0;
    REP(i,N){
        if(A[i]!=B[i]){
            equal = 0;
            if(A[i] < B[i]){
                ans += B[i];
            }else{
                chmin(mn,B[i]);
            }
        }else{
            ans += B[i];
        }
        sum += B[i];
    }
    cout << (equal ? 0 : sum - mn) << "\n";
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
       public static void main(String[] args) {
             Scanner in = new Scanner(System.in);
             int a = in.nextInt();
             int b = in.nextInt();
             int c = in.nextInt();
         
            System.out.println(b - a == c - b ? "YES" : "NO");
       }
}

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

int main() {
    string s, t;
    int a,b;

    cin >> s >> t;
    cin >> a >> b;

    string u;
    cin >> u;

    if (u == s) {
        cout << (a-1) << " " << b << endl;
    } else {
        cout << a << " " << (b-1) << endl;
    }
}

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

using namespace std;
typedef long long ll; 


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

	if (N % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	int half = N / 2;
	for (int i = 0; i < half; i ++) {
		if (s[i] != s[i + half]) {
			cout << "No" << endl;
			return 0;
		}
	}

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

Measured memory_bytes: 888
N = int(input())
mod = 1000000000+7

import numpy as np
dp=np.zeros((N+1, 4, 4, 4), dtype=np.int64)

dp[0,3,3,3] = 1
for length in range(N):
    for c1 in range(4):
        for c2 in range(4):
            for c3 in range(4):
                if dp[length, c1, c2, c3]==0:
                    continue
                for a in range(4):
                    if a==2 and c1==1 and c2==0:
                        continue
                    if a==2 and c1==0 and c2==1:
                        continue
                    if a==1 and c1==2 and c2==0:
                        continue
                    if a==2 and c1==1 and c3==0:
                        continue
                    if a==2 and c2==1 and c3==0:
                        continue     
                    dp[length+1, a, c1, c2] += dp[length, c1, c2, c3] 
                    dp[length+1, a, c1, c2] %= mod
print(dp[N].sum()%mod)

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

typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
int main() {
	int R, G, B, N, sum, res = 0;
	cin >> R >> G >> B >> N;

	for (int i = 0; i <= N; i++)
	{
		for (int j = 0; j <= N; j++)
		{
			sum = N - (i*R) - (j*G);
			if (sum >= 0 && sum%B == 0) {
				res++;
			}
		}
	}
	cout << res << endl;
}


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

int main() {
	int w,h;
	int e1[100][100]={};
	int e2[100][100]={};
	int n1[100][100]={};
	int n2[100][100]={};
	while(1){
		cin >> w >> h;
		if(w==0){return 0;}
		for(int i=1;i<w;i++){
			e2[i][0]=1;
		}
		for(int j=1;j<h;j++){
			n2[0][j]=1;
			for(int i=1;i<w;i++){
				e1[i][j]=(n2[i-1][j])%100000;
				e2[i][j]=(e1[i-1][j]+e2[i-1][j])%100000;
				n1[i][j]=(e2[i][j-1])%100000;
				n2[i][j]=(n1[i][j-1]+n2[i][j-1])%100000;
			}
		}
		int s=(e1[w-1][h-1]+e2[w-1][h-1]+n1[w-1][h-1]+n2[w-1][h-1])%100000;
		cout <<  s << endl;
	}
}

Measured memory_bytes: 1324
using System;
using System.Linq;

class C
{
	static void Main() => Console.WriteLine(new int[int.Parse(Console.ReadLine())].Select((_, i) => new { x = int.Parse(Console.ReadLine()), i }).OrderBy(_ => _.x).Where((_, j) => _.i % 2 == 0 && j % 2 == 1).Count());
}


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

using namespace std;
using ll =long long;
using db = double;

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 che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める

int main()
{
	ll n ;
	cin >> n ;
	ll k ;
	cin >> k;
	vector<ll> x(n+1);
	bool zero = true;
	ll zero_index  = -1;
	rep(i,n+1){
		if(i==n&&zero_index==-1){
			zero_index=n; 
			x[zero_index] = 0;
			break;
		}
		ll a ; cin >> a ;
		if(a>=0&&zero == true){
			zero_index = i ;
			x[i++]   = 0 ; x[i] = a;
			zero = false;
		}else{
			x[i] = a;
		}
	}
	ll ans = INF;
	rep(i,k+1){
		ll tmp = 0 ;
		if(zero_index-i >= 0 && zero_index + k - i <= n ){
			ll  minus = x[zero_index] - x[zero_index - i];
			ll plu =  x[zero_index + ( k - i )] - x[zero_index];
			tmp = minus + plu ;

			tmp += min(minus,plu);
			//  負の側と正の側、小さい方を二倍すれば位い
			//che(tmp,"tmp");
			chmin(ans,tmp);
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end());
#define fill(a,x) memset(a,x,sizeof(a))
#define zero(a) fill(a,0)
#define minus(a) fill(a,-1)
#define dbg(x) cout << #x"=" << x << endl

const int INF=INT_MAX/3;
const int LIMIT=100;

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

int r,g;

int main(){
  cin>>r>>g;
  cout<<2*g-r<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define PI acos(-1)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << "\n";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 1e18 + 100;
int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	vi h(n);
	for(int i = 0;i < n;i++){
		cin >> h[i];
	}
	vi dp(n, inf);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]) + dp[0];
	for(int i = 2;i < n;i++){
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << "\n";
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            List<string> lstA = new List<string>();
            lstA.Add(sS[0]);
            lstA.Add(sS[1]);
            lstA.Add(sS[2]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            lstA.Sort();
            int iOut = int.Parse(lstA[2] + lstA[1]) + int.Parse(lstA[0]);

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13524
#include<stdio.h>

int main(){
    int N,M,i,A[11000];
    scanf("%d %d",&N,&M);
    for(i=0;i<M;i++)scanf("%d",&A[i]);
    for(i=0;i<M;i++)N-=A[i];
    if(N<0)printf("-1\n");
    if(N>=0)printf("%d\n",N);
}

Measured memory_bytes: 1688
/*
    Created by Tejas Chaudhari
    link:
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef double lf;
typedef bool bl;
typedef vector<ll> vl;
typedef vector<lf> vd;
typedef vector<bl> vb;
typedef string st;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define INF (LONG_LONG_MAX / 4)
#define SORT(x) sort(x.begin(), x.end())
#define Mod % 1000000007

void re_curse() {
    ll n;
    cin>>n;
    vl arr(4, 0);
    while (n--) {
        string a;
        cin>>a;
        if (a == "AC") {
            ++arr[0];
        } else if (a == "WA") {
            ++arr[1];
        } else if (a == "TLE") {
            ++arr[2];
        } else {
            ++arr[3];
        }
    }
    cout<<"AC x "<<arr[0]<<endl;
    cout<<"WA x "<<arr[1]<<endl;
    cout<<"TLE x "<<arr[2]<<endl;
    cout<<"RE x "<<arr[3]<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin>>t;
    for (int i = 1; i <= t; ++i) {
        re_curse();
    }
    return 0;
}


Measured memory_bytes: 3636
a,b,c,x,y=map(int,input().split())


moneys=[]
for i in range(0,max(x,y)*2+1,2):
    apizza=x-int(i/2)
    bpizza=y-int(i/2)
    if apizza<0:
        apizza=0
    if bpizza<0:
        bpizza=0
    money=apizza*a+bpizza*b+i*c
    moneys.append(money)

print(min(moneys))


Measured memory_bytes: 12916
Module Module2
    Sub main()
        Dim temp As String() = Console.ReadLine.Split(" "c)
        Dim A As Integer = Integer.Parse(temp(0))
        Dim B As Integer = Integer.Parse(temp(1))
        Dim C As Integer = Integer.Parse(temp(2))
        Dim ret As String = "No"

        If A = B AndAlso A <> C Then
            ret = "Yes"
        ElseIf A = C AndAlso A <> B Then
            ret = "Yes"
        ElseIf B = C AndAlso A <> B Then
            ret = "Yes"
        End If

        Console.WriteLine(ret)

    End Sub
End Module


Measured memory_bytes: 11092