akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a*c %mod;}a=a*a %mod;b>>=1;}return c;}
vi calc(ll x){vi res; while(x>0){res.eb(x%10);x/=10;}reverse(all(res)); return res;}

void solve() {
  ll n;
  cin>>n;
  vi t(n);
  rep(i,n) cin>>t[i];
  ll ans=1;
  rep(i,n) ans=LCM(ans,t[i]);
  out(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 256
#include<stdio.h>

long min(long x, long y){
  if(x<y) return x;
  else return y;
}

int main(){
  long a,b,c,x,y,sum=0;
  scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&x,&y);
  if(a+b>2*c){
    sum+=2*c*min(x,y);
    if(x>y){
      if(a<2*c) sum+=a*(x-y);
      else sum+=2*c*(x-y);
    }
    else{
      if(b<2*c) sum+=b*(y-x);
      else sum+=2*c*(y-x);
    }
  }
  else sum+=a*x+b*y;
  printf("%ld\n",sum);
}

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

enum {
    B10 = 10000, B5 = 5000, B1 = 1000
};

inline int maxNumber(long yen, int bill){
    return int(yen / bill);
}

inline bool isCorrect(int x10, int x5, int x1, int n, long y){
    bool isPositive = ((x10 >= 0) && (x5 >= 0) && (x1 >=0));
    bool isCorrectN = (n == x10 + x5 + x1);
    bool isCorrectY = (y - B10*x10 - B5*x5 - B1*x1 == 0);

    return isPositive && isCorrectN && isCorrectY;
}

void fastAns(int& x10, int& x5, int& x1, int n, long y){
    x10 = min(n, maxNumber(y, B10));
    for(; x10 >= 0; x10--){
        int det = B1 - B5;
        x5 = ( (n - x10)*B1 - (y - B10*x10)) / det;
        x1 = (-(n - x10)*B5 + (y - B10*x10)) / det;
        //cout << "DEBUG: "<< x10 << " " << x5 << " " << x1 << endl; 
        if(isCorrect(x10, x5, x1, n, y)) return;
    }
}

void simplyAns(int& x10, int& x5, int& x1, int n, long y){
    for(x10 = 0; x10 <= n; x10++){
        for(x5 = 0; x5 <= n - x10; x5++){
            x1 = n - x5 - x10;
            if(isCorrect(x10, x5, x1, n, y)) return;
        }
    }
}

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

    int x10 = -1, x5 = -1, x1 = -1;
    fastAns(x10, x5, x1, n, y);

    if(isCorrect(x10, x5, x1, n, y)){
        cout << x10 << " " << x5 << " " << x1 << endl; 
    } else {
        cout << "-1 -1 -1" << endl;
    }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    char c; cin>>c;
    if('a'<=c && c<='z') cout<<"a"<<endl;
    if('A'<=c && c<='Z') cout<<"A"<<endl;
}

Measured memory_bytes: 3620
#include <stdio.h>

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


Measured memory_bytes: 2064
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = ll;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

template<typename T>
string join(vector<T>& vec, string sep = " "){
    stringstream ss;
    for(int i = 0; i < vec.size(); i++){
        ss << vec[i] << (i + 1 == vec.size() ? "" : sep);
    }
    return ss.str();
}

bool is_march(char x){
    string march = "MARCH";
    return any_of(begin(march), end(march), [x](char y){return x == y;});
}

Int solve(int n, const vector<string>& ss){
    map<char, Int> counter;
    for(const auto& s : ss){
        char h = s[0];
        if(is_march(h)){
            counter[h]++;
        }
    }

    string march = "MARCH";
    Int res = 0;
    for(int i = 0; i < 5; i++){
        for(int j = 0; j < 5; j++){
            for(int k = 0; k < 5; k++){
                if(i == j || j == k || k == i){
                    continue;
                }
                char x = march[i];
                char y = march[j];
                char z = march[k];
                res += counter[x] * counter[y] * counter[z];
            }
        }
    }
    
    return res / 6;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<string> ss(n);
    cin >> ss;

    cout << solve(n, ss) << endl;

    return 0;
}


Measured memory_bytes: 5760
n,m =map(int,input().split())
s_li = []
k_li = []
for i in range(m):
  inp = list(map(int,input().split()))
  k_li.append(inp[0])
  s_li.append(inp[1:])
p_li = list(map(int,input().split()))
cnt = 0 
for bit in range(1<<n): #n桁のbitを用意しオンオフを管理する
  ok = True
  for i in range(m):#m個の電球それぞれについてスイッチがいくつオンになってるか調べる
    con = 0 #最初はオンになっているスイッチは0
    for j in s_li[i]:
      #i個目の電球に繋がっているki個のスイッチのオンオフを調べたい
      if ((bit >> j-1) & 1) == 1:
        #i個目の電球に繋がっているj個目のスイッチのオンオフを用意しておいたbitと照らし合わせて確認
        con += 1
    if con%2 != p_li[i]:
      ok = False
  if ok == True:
    cnt += 1
print(cnt)

Measured memory_bytes: 3064
n, k = map(int, input().split())

p = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

loop_max = []
loop_len = []
S = []
ans = []

for i in range(len(p)):
    now = i
    temp_len = 0
    temp_s = 0
    temp_l = []
    while True:
        now = p[now] - 1
        temp_len += 1
        temp_s += c[now]
        temp_l.append(temp_s)

        # 最初に戻ってきたら
        if now == i:
            break

    loop_len.append(temp_len)
    loop_max.append(temp_l)
    S.append(temp_s)

for i in range(len(S)):
    mod = k % loop_len[i] if k % loop_len[i] != 0 else loop_len[i]
    if S[i] > 0:
        if max(loop_max[i][:mod]) > 0:
            ans.append(((k-1)//loop_len[i])*S[i] + max(loop_max[i][:mod]))
        else:
            ans.append(((k - 1) // loop_len[i]) * S[i])
    else:
        ans.append(max(loop_max[i]))

print(max(ans))


Measured memory_bytes: 286456
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

struct Process
{
    Process()
    {}

    Process(char* name, int time)
    {
        sscanf(name, "%s", this->name);
        this->time = time;
    }

    Process(const Process& p)
    {
        Process((char*)p.name, p.time);
    }

    ~Process() {}

    char name[10];
    s64 time;
};

template <typename T>
class myQueue
{
public:
    myQueue(int n)
    : data(new T[n + 1]), N(n + 1), head(0), tail(0)
    {}

    ~myQueue() { delete[] data; }

    void enqueue(const T& x)
    {
        data[tail % N] = x;
        tail = (tail + 1) % N;
    }

    T& dequeue()
    {
        T& temp = data[head];
        head = (head + 1) % N;
        return temp;
    }

    bool full()
    {
        return head == (tail + 1) % N;
    }

    bool empty()
    {
        return head == tail;
    }

private:
    T* data;
    int N;
    int head;
    int tail;
};

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

    s64 t = 0;
    int n;
    int q;
    cin >> n >> q;
    myQueue<Process> queue(n);

    rep (i, n)
    {
        Process temp;
        cin >> temp.name >> temp.time;
        queue.enqueue(temp);
    }

    while (!queue.empty())
    {
        Process& temp = queue.dequeue();
        s64 tempt;
        tempt = MIN(temp.time, q);
        temp.time -= tempt;
        t += tempt;
        if (temp.time)
        {
            queue.enqueue(temp);
        }
        else
        {
            cout << temp.name << " " << t << "\n";
        }
    }

    return 0;
}



Measured memory_bytes: 4184
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define int          long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define pi           pair<int,int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define FIO         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int parent[200001];
int s[200001];
int find_set(int v)
{
   if(v==parent[v])
    return v;
   return(parent[v]=find_set(parent[v]));
}
void union_set(int a,int b)
{
    a=find_set(a);
    b=find_set(b);
    if(a!=b)
    {
        if(s[a]<s[b])
        {
            swap(a,b);
        }
        parent[b]=a;
        s[a]+=s[b];
    }
}
void solve()
{
     int n,q;
     cin>>n>>q;
     rep(i,0,n)
     {
        parent[i]=i;
        s[i]=1;
     }
     while(q--)
     {
        int x,a,b;
        cin>>x>>a>>b;
        if(x==0)
        {
            union_set(a,b);
        }
        else
        {
            if(find_set(a)==find_set(b))
            {
                cout<<1<<endl;
            }
            else
            {
                cout<<0<<endl;
            }
        }
     }

}

signed main()
{
        FIO
       
        
        int t=1;
        //cin>>t;
        while(t--)
        solve();
        cerr<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;

        return 0;
}

Measured memory_bytes: 6812
from math import log10
from itertools import product

N = int(input())
keta = int(log10(N)) + 1

if keta < 3:
    print(0)
    exit()

count = 0
# keta 桁の 753 数と N を比較
for k in range(3, keta+1):
    for pair in product([3, 5, 7], repeat=k):
        if len(set(pair)) < 3:
            continue
        tmp = 0
        for i, p in enumerate(pair):
            tmp += p * (10**(k-i-1))
        if N >= tmp:
            count += 1

print(count)

Measured memory_bytes: 3064
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    String s= sc.next();
    if(s.length()==6)
    {
      if(s.charAt(2)==s.charAt(3))
      {
        if(s.charAt(4)==s.charAt(5))
        {
          System.out.println("Yes");
        }
        else
          System.out.println("No");
      }
      else
         System.out.println("No");
    }
     else
         System.out.println("No");
  }
}
     
        
          

Measured memory_bytes: 21972
# ABC087C

n = int(input())
a0 = list(map(int, input().split()))
a1 = list(map(int, input().split()))
Max = 0
for k in range(len(a0)):
    s = sum(a0[:k+1]) + sum(a1[k:])
    Max = max(Max, s)
print(Max)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
const lint MOD = 1e9+7;
const lint INF = 1e18;
lint N;
vector<vector<lint> > a;
vector<lint> memo;

lint solve(lint bit){
	if(memo[bit] != -1) return memo[bit];
	if(bit == 0) return memo[bit] = 1;
	lint counter = __builtin_popcount(bit), ans = 0;
	for(lint i = 0; i < N; i++){
		if((bit & (1 << i)) && a[counter - 1][i]){
			ans += solve(bit - (1 << i));
			ans %= MOD;
		}
	}
	return memo[bit] = ans;
}

signed main(){
	cin >> N;
	a.resize(N, vector<lint> (N));
	memo.resize((1 << N), -1);
	for(lint i = 0; i < N; i++){
		for(lint j = 0; j < N; j++) cin >> a[i][j];
	}
	cout << solve((1 << N) - 1) << endl;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int N;
	cin >> N;
	
	int countDifference = 0;
	for(int i = 0; i < N; i++){
		int tmp;
		cin >> tmp;
		if(tmp != (i + 1)) countDifference++;
	}
	
	if(countDifference <= 2){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	
	return 0;
}

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

using ll=long long;
using namespace std;

#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}

const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int a, b;cin >> a >> b;
    
    cout << a/b << " " << a%b << " ";
    cout << fixed << setprecision(10) << double(a)/double(b) << endl;
}


Measured memory_bytes: 3244
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		//B
		String S = sc.next();
		String T = sc.next();
		boolean flag = false;
		for(int i = 0; i < S.length();i++){
			if(S.equals(T)){
				flag = true;
				break;
			}
			S = S.substring(1,S.length())+S.substring(0,1);
		}
		if(flag)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='darwin':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N, W = MAP()
v = [0] * N
w = [0] * N
for i in range(N):
	v[i], w[i] = MAP()

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(0, N):
	# print(i, v[i], w[i])
	for sum_w in range(W+1):
		if sum_w>=w[i]:
			dp[i+1][sum_w] = max(dp[i][sum_w], dp[i][sum_w-w[i]]+v[i])
		else:
			dp[i+1][sum_w] = dp[i][sum_w]

# print(dp)
print(dp[N][W])


Measured memory_bytes: 25944
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
signed main(){
    int n;cin>>n;
    int x;cin>>x;
    if(x==1 || x==2*n-1)return puts("No")*0;
    cout<<"Yes"<<endl;
    map<int,int>mp;
    if(n==2){
        cout<<1<<'\n'<<2<<'\n'<<3<<'\n';
        return 0;
    }else if(x==2){
        mp[x+1]=mp[x]=mp[x-1]=mp[x+2]=1;
    }else{
        mp[x+1]=mp[x]=mp[x-1]=mp[x-2]=1;
    }
    vi iijissougaomoitukanai;
    rep(i,2*n-1)if(mp[i+1]!=1)iijissougaomoitukanai.push_back(i+1);
    int l=0;
    for(int i=1;i<=2*n-1;i++){
        if((2*n-1)/2==i){
            if(x==2)cout<<x+1<<'\n'<<x<<'\n'<<x-1<<'\n'<<x+2<<endl;
            else cout<<x-1<<'\n'<<x<<'\n'<<x+1<<'\n'<<x-2<<endl;
            i+=3;
        }
        else cout<<iijissougaomoitukanai[l++]<<endl;
    }
}


Measured memory_bytes: 15600
#include <iostream>
using namespace std;
int main() {
	int A , B , Ans;
	char op;
	
	cin >> A >> op >> B;
	
	if (op == '+')
	Ans = A + B;
	
	if (op == '-')
	Ans = A - B;
	
	cout << Ans << endl;
}

Measured memory_bytes: 3600
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

class Main {

	public static void main(String[] args) {

		Scanner sc = null;
		Map<Integer, Integer> map = new TreeMap<Integer, Integer>();
		try {
			sc = new Scanner(System.in);
			while (sc.hasNextInt()) {
				int num = sc.nextInt();

				if (!map.containsKey(num)) {
					map.put(num, 0);
				}
				map.put(num, map.get(num) + 1);
			}
			List<Integer> list =new ArrayList<Integer>();
			int value = 0;
			for(Map.Entry<Integer, Integer> entry: map.entrySet()){
				if(value<entry.getValue()){
					value=entry.getValue();
					list.removeAll(list);
					list.add(entry.getKey());
				}
				else if(value==entry.getValue()){
					list.add(entry.getKey());
				}
			}
			for(int x:list){
				System.out.println(x);
			}

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 20192
X,N=list(map(int,input().split()))
p=list(map(int,input().split()))
dist=1000
ans=1000
for i in range(0,150):
    low=X-i
    high=X+i
    if p.count(low)==0:
        print(low)
        exit()
    elif p.count(high)==0:
        print(high)
        exit()

Measured memory_bytes: 9188
import sys
def main():
    # a^5-b^5=xのx(x:自然数, a,b:整数)
    x = int(input())

    flag = 0
    for a in range(-118, 120, 1):
        for b in range(-119, 119, 1):
            if pow(a,5)-pow(b,5)==x:
                flag = 1
                break
        if flag==1: break

    print(str(a)+" "+str(b))

main()


Measured memory_bytes: 9120
s = int(input())

a = s % 100
b = (s-a) / 100

if a >= 1 and a <= 12:
    if b >= 1 and b <= 12:
        print('AMBIGUOUS')
    else:
        print('YYMM')
else:
    if b >= 1 and b <= 12:
        print('MMYY')
    else:
        print('NA')

Measured memory_bytes: 9024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 
int main() {
	ll n;
	cin>>n;
	map<ll,ll>a;
	ll ch[200010];
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		ch[i]=now;
		a[now]++;
	//	ma=max(ma,now);
	}
	auto itr=a.end();
	itr--;
	ll ma=itr->first;
	ll val=itr->second;
	itr--;
	for(ll i=0;i<n;i++){
		if(val>=2){
			cout << ma<<endl;
		}
		else{
			if(ch[i]==ma){
				cout << itr->first<<endl;
			}
			else{
				cout << ma<<endl;
			}
		}
	}
	// your code goes here
	return 0;
}

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


//defines...
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define in insert
#define pi 2*acos(0.0)1
#define srt(s) sort(s.begin(),s.end())
#define rsrt(s) sort(s.rbegin(),s.rend())
#define all(x) x.begin(),x.end()

const ll mod=1e9+7;
const ll MX=2e5+5;

//code goes from here...



int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);
#endif

    boost
    //---------------------------------
    int n;
    cin >> n;
    vector <ll> v(n);
    for(auto &i : v) cin >> i;
    rsrt(v);
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        if(i%2) sum+=v[i];
        else sum -=v[i];
    }
    cout << abs(sum) << endl;
    
    //---------------------------------
    
    return 0;
}


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


int main(){
    int L,R,d; cin>>L>>R>>d;
    
    int ans=0;
    for(int i=L; i<=R; i++){
        if(i%d==0){
            ans++;
        }
    }
    
    cout << ans <<endl;
}


Measured memory_bytes: 3628
import os

import itertools
import sys
from math import gcd

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

K = int(sys.stdin.buffer.readline())

# memo = [[0] * 201 for _ in range(201)]
# for a, b in itertools.product(range(201), repeat=2):
#     memo[a][b] = gcd(gcd(a, b), c)

s = 0
for a, b, c in itertools.product(range(1, K + 1), repeat=3):
    s += gcd(gcd(a, b), c)
print(s)



Measured memory_bytes: 67828
#include <iostream>
#include <cmath>

int main() {
  int lt = 0; int lx = 0; int ly = 0;
  int ct = 0; int cx = 0; int cy = 0;

  int n;
  std::cin >> n;

  bool traverable = true;
  for( int i = 0; i < n; ++i ) {
    lt = ct; lx = cx; ly = cy;
    std::cin >> ct >> cx >> cy;

    const int dt = ct - lt;
    const int dx = std::abs(cx - lx);
    const int dy = std::abs(cy - ly);

    const bool enough_time = (dx + dy) <= dt;
    const bool just_time = ((dx + dy) % 2) == (dt % 2);

    if( !enough_time || !just_time ) {
      traverable = false;
      break;
    }
  }

  if( traverable ) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define int long long
#define sync ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 2 * 1e5 + 7;
const int inf = 1e17 + 7;
const int MOD = 1e9 + 7;

signed main() {
    sync;
    int n;
    cin >> n;
    int a, b;
    cin >> a >> b;
    if (b < a) swap(a, b);
    if ((b - a) % 2 == 0) cout << (b - a) / 2 << '\n';
    else
    cout << min(n - b, a - 1) + 1 + (b - a - 1) / 2 << '\n';
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
signed main(){
    int x,n,p[105];
    scanf("%d %d",&x,&n);
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&p[i]);
    }
    int flag[105]={};
    int ans=0;
    for(i=0;i<n;i++){
        flag[p[i]]=1;
    }
    for(i=1;i<=101;i++){
        if(flag[i]==0){
            int abs1,abs2;
            abs1=x-ans;
            abs2=x-i;
            if(abs1<0){
                abs1=abs1*-1;
            }
            if(abs2<0){
                abs2=abs2*-1;
            }
            if(abs1>abs2){
                ans=i;
            }
        }
    }
    printf("%d\n",ans);
    return(0);    
}

Measured memory_bytes: 1732
n = int(input())
a = []
for _ in range(n):
    a.append([list(map(int,input().split())) for __ in range(int(input()))])
l = []
for i in range(2**n):
    flag2 = 0
    for j in range(n):
        if i >> j & 1 == 1:
            flag1 = 0
            for k in a[j]:
                if i >> (k[0]-1) & 1 != k[1]:
                    flag1 = 1
                    flag2 += 1
                    break
            if flag1 : break
        
    if flag2 == 0 :l.append(list(bin(i)).count('1'))
print(max(l))

Measured memory_bytes: 9220
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  REP(i,N) cin >> A[i];
  int sum = 0;
  REP(i,N) sum += A[i];
  sort(ALL(A), greater<int>());
  if(A[M-1]* 4 * M >= sum) cout << "Yes";
  else cout << "No";
  
  return 0;
}

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

using namespace std;

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i)
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i)

#define DEBUG(...) fprintf(stderr , __VA_ARGS__)

template<typename T>inline int chkmin(T &x , const T &y){ return x > y ? x = y , 1 : 0; }
template<typename T>inline int chkmax(T &x , const T &y){ return x < y ? x = y , 1 : 0; }

template<typename T>inline T read(T &f)
{
	f = 0 ; int x = 1 ; char c = getchar();
	while(!isdigit(c)) x = c == '-' ? -1 : 1 , c = getchar();
	while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
	return f *= x;
}

using int64 = long long;
using uint64 = unsigned long long;

int main()
{
	int a ;
	read(a);
	cout << a * a * a << endl;
	return 0;
}

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

#define all(x) (x).begin(), (x).end()

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);
    
    int N;
    cin >> N;

    int odd = 0;
    for (int i = 0; i < N; i++) {
        int val;
        cin >> val;
        if (val & 1) odd++;
    }

    cout << (odd & 1 ? "NO" : "YES") << endl;
    return 0;
}



Measured memory_bytes: 256
package main

import "fmt"

const M = 1000000007

func main() {
	var n int
	fmt.Scan(&n)

	fmt.Println(solve(n))
}

func solve(n int) int64 {
	dp := make([][]int64, n+1)

	for i := 0; i <= n; i++ {
		dp[i] = make([]int64, 4)
	}

	for i := 0; i < 4; i++ {
		dp[0][0] = 1
	}

	for i := 1; i <= n; i++ {
		// put 0
		dp[i][1] = (dp[i][1] + dp[i-1][0] + dp[i-1][1]) % M
		dp[i][3] = (dp[i][3] + dp[i-1][3] + dp[i-1][2]) % M

		// put 9
		dp[i][2] = (dp[i][2] + dp[i-1][2] + dp[i-1][0]) % M
		dp[i][3] = (dp[i][3] + dp[i-1][3] + dp[i-1][1]) % M

		for j := 1; j < 9; j++ {
			for k := 0; k < 4; k++ {
				dp[i][k] = (dp[i][k] + dp[i-1][k]) % M
			}
		}
	}

	return dp[n][3]
}


Measured memory_bytes: 59192
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
-- import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
import Debug.Trace

solve :: Int -> Int -> [Int] -> Int
solve n a xs = sum [reduce V.! i VU.! (i*a) | i <- [1..n]]
  where

  reduce = foldl update initTbl xs

  initTbl = V.fromListN (n+1) (v1 : repeat v2)
    where v1 = VU.fromListN (a*n + 1) (1 : repeat 0)
          v2 = VU.fromListN (a*n + 1) (repeat 0)

  update :: V.Vector (VU.Vector Int) -> Int -> V.Vector (VU.Vector Int)
  update tbl x = V.fromListN (n+1) [upd i | i <- [0..n]]
    where upd :: Int -> VU.Vector Int
          upd 0 = tbl V.! 0
          upd i = upd0 (tbl V.! (i-1)) (tbl V.! i)
          upd0 :: VU.Vector Int -> VU.Vector Int -> VU.Vector Int
          upd0 v1 v2 = VU.zipWith (+) ((VU.replicate x 0) VU.++ v1) v2

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n,bs_a]:remLines1 = remLines0
      n = readBInt bs_n
      a = readBInt bs_a
      line2:remLines2 = remLines1
      xs = map readBInt line2
  in solve n a xs

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 52220
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
cmin = 10**6
for i in range(N):
    t = T-H[i]*0.006
    if abs(A-t)<cmin:
        cmin = abs(A-t)
        ind = i+1
print(ind)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define pp pair<ll,ll>
#define inf 1e9
using namespace std;
const int N=200005;

ll arr[N],pre[N];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    
    for(int i=1;i<=n;i++)
    cin>>arr[i];
    
    for(int i=1;i<=n;i++)
    pre[i]=arr[i]+pre[i-1];
  
    ll ans=N*inf;
    for(int i=1;i<n;i++)
    ans=min(ans,abs(2*pre[i]-pre[n]));
    
    cout<<ans<<"\n";
 
    return 0;
} 

Measured memory_bytes: 3328
#!/usr/bin/env python3
import math

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, K = map(int, input().split())
    A = [int(i) for i in input().split()]

    dv = []
    for _ in range(60):
        l = [0] * N
        dv.append(l)
    
    for n in range(N):
        dv[0][n] = A[n] - 1
    
    for k in range(1, 60):
        for n in range(N):
            dv[k][n] = dv[k - 1][dv[k - 1][n]]
    
    a = []
    for i in range(60):
        if K>>i & 1:
            a.append(i)

    now = 0
    for i in a:
        now = dv[i][now]
    print(now + 1)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 175160
package main

import (
	"fmt"
)

func main() {
	var n, a, b, c, d int
	fmt.Scan(&n, &a, &b, &c, &d)

	for i := 0; i < n; i++ {
		j := n - i - 1
		l := a + i*c - j*d
		r := a + i*d - j*c
		if l <= b && b <= r {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}


Measured memory_bytes: 1772
H, W = map(int, input().split())
grid = [input() for _ in range(H)]
checked = [[False]*W for _ in range(H)]


def solve(arr, count):
    next_arr = set()
    count += 1
    for a in arr:
        y, x = a[0], a[1]
        checked[y][x] = True
        if y == H-1 and x == W-1:
            return count
        if y < H-1:
            if not checked[y+1][x] and grid[y+1][x] == '.':
                next_arr.add((y+1, x))
        if 0 < y:
            if not checked[y-1][x] and grid[y-1][x] == '.':
                next_arr.add((y-1, x))
        if x < W-1:
            if not checked[y][x+1] and grid[y][x+1] == '.':
                next_arr.add((y, x+1))
        if 0 < x:
            if not checked[y][x-1] and grid[y][x-1] == '.':
                next_arr.add((y, x-1))
    if len(next_arr) == 0:
        return -1
    return solve(next_arr, count)


min_steps = solve([(0, 0)], 0)
if min_steps == -1:
    print(-1)
else:
    w_c = 0
    for i in grid:
        w_c += i.count('.')
    print(w_c - min_steps)


Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int INF=999999999;
const int MOD=1000000007;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll n, d[5];
const char march[] = {'M', 'A', 'R', 'C', 'H'};

int main() {
    cin >> n;
    for (int i = 0; i < 5; i++) d[i] = 0LL;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < 5; j++) {
            if (s[0] == march[j]) d[j]++;
        }
    }
    ll ans = 0LL;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += d[i] * d[j] * d[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

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

// LRUD
int dy[] = {0, 0, -1, 1};
int dx[] = {-1, 1, 0, 0};
int rev[] = {1, 0, 3, 2};
int H, W, N;
int sr, sc;
bool isOut(int d, vector<int>& sv, vector<int>& tv)
{
  int y = sr, x = sc;
  REP(i, sv.size()) {
    if (sv[i] == d) {
      x += dx[d];
      y += dy[d];
    }
    if (x < 0 || x >= W || y < 0 || y >= H) return true;
    if (tv[i] == rev[d]) {
      int nx = x + dx[rev[d]];
      int ny = y + dy[rev[d]];
      if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
      x = nx;
      y = ny;
    }
  }
  return false;
}

int main()
{
  cin >> H >> W >> N;
  cin >> sr >> sc;
  sr--; sc--;
  vector<int> sv, tv;
  REP(i, N) {
    char c; cin >> c;
    if (c == 'L') sv.PB(0);
    if (c == 'R') sv.PB(1);
    if (c == 'U') sv.PB(2);
    if (c == 'D') sv.PB(3);
  }
  REP(i, N) {
    char c; cin >> c;
    if (c == 'L') tv.PB(0);
    if (c == 'R') tv.PB(1);
    if (c == 'U') tv.PB(2);
    if (c == 'D') tv.PB(3);
  }
  REP(i, 4) {
    if (isOut(i, sv, tv)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;

using namespace std;

//Binary exponent
ll Bin_pow(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        {
            res=res*a;
        }
        a=a*a;
        b>>=1;
    }
    return res;
}

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

//LCM
ll lcm(ll a,ll b)
{
	return (a*b)/gcd(a,b);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll a;
	cin>>a;
	
	cout<<a*(1+a+(a*a))<<"\n";
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n), p(n), q(n);
    rep(i, n) v[i] = i + 1;
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];

    int a, b, cnt = 0, ans = 0;
    do
    {
        if (v == p)
            a = cnt;
        if (v == q)
            b = cnt;
        cnt++;
    } while (next_permutation(all(v)));
    ans = abs(a - b);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 998244353
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int ope[1140];
int price[1140];
int dp[1140][5000];
signed main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int a,b;
		cin>>a>>b;
		price[i] = a;
		for(int j=0;j<b;j++){
			int x;
			cin>>x;
			x--;
			ope[i] += (1<<x);
		}
	}
	int ma = (1<<n)-1;
	for(int i=0;i<=m;i++){
		for(int j=0;j<=ma;j++){
			dp[i][j] = LINF;
		}
	}
	dp[0][0] = 0;
	for(int i=1;i<=m;i++){
		for(int j=0;j<=ma;j++){
			dp[i][j] = min(dp[i][j],dp[i-1][j]);
			dp[i][ j | ope[i] ] = min( dp[i][ j | ope[i] ], dp[i-1][j]+price[i] );
		}
	}
	if(dp[m][ma] == LINF) dp[m][ma] = -1;
	cout<<dp[m][ma]<<endl;
	return 0;
}

Measured memory_bytes: 41088
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
signed main()
{
    IOS
    int a,b; cin>>a>>b;
    if(a==b){
        cout<<1;
        return 0;
    }
    if((a+b)%2){
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    cout<<(a+b)/2<<endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
#include <fstream>   // ifstream, ofstream
#include <sstream>   // istringstream
using namespace std;
using ll = long long;
const int mod = 1000000007;
 
ll gcd(ll a, ll b){return b ? gcd(b,a%b) : a;};//最大公約数
ll lcm(ll a, ll b){return a*b/gcd(a,b);};//最小公倍数
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
typedef pair<string,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
//ll a[100000];
//ll dom[100001];
 
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  vector<char> s;
  ll p=n%(a+b);
  ll q=n/(a+b);
  if(a==0){
    cout<<"0";
    return 0;
  }
  ll ans;
  if(n<=a){
    cout<<n;
    return 0;
  }
  if(p>0){
    if(n%(a+b)<a){
    	ans=a*q+(n%(a+b));
    }else{
      ans=a*q+a;
    }
  }else{
    ans=a*q;
  }
  cout<<ans;
  return 0;
}

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

const int N = 10005;

int main()
{
	int N,X;
	cin >> N >> X;
	int L[N];
	int temp = 0;
	rep(i,N)
	{
		cin >> L[i];
	}

	rep(i,N)
	{
		temp += L[i];
		if (temp > X)
		{
			cout << i+1 << endl;
			return 0;
		}
	}

	cout << N+1 << endl;

	return 0;
}

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

int main() {
	int n,m;
  	cin>>n>>m;
  	vector<int> a(m+1,0);
  	int k,temp;
  	for(int i=0;i<n;i++){
    	cin>>k;
      	for(int j=0;j<k;j++){
          	cin>>temp;
        	a[temp]++;
        }
    }
  	int cnt=0;
  	for(int i=1;i<m+1;i++){
    	if(a[i]==n){
        	cnt++;
        }
    }
  cout<<cnt<<endl;
}



Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll r,g,b,n ;
	cin >> r >> g >> b >> n ;
	ll ans = 0 ;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			ans += (i*r+j*g<=n&&(n-i*r-j*g)%b==0) ;
		}
	}
	cout << ans << endl ;
}


Measured memory_bytes: 3636
from bisect import bisect, bisect_left
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

N, K = inpl()
V = inpl()
ans = 0
for a in range(min(K+1, N+1)):
    for b in range(min(K-a, N-a)+1):
        U = V[:a] + V[N-b:]
        U = sorted(U)
        l = bisect_left(U, 0)
        k = K - a - b
        if k <= l:
            ans = max(ans, sum(U[k:]))
        else:
            ans = max(ans, sum(U[l:]))

print(ans)

Measured memory_bytes: 42352
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll unsigned long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 1000000100000000000
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define st size_t
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=1005;
const int NN=1000001;
const ll md=998244353;



int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    str s;
    cin >> s;
    str ans="Yes";
    str a=s;
    reverse(a.begin(),a.end());
    if (a!=s)ans="No";
    a="";
    for (int i=0;i<s.size()/2;i++){
        a+=s[i];
    }
    s=a;
    reverse(a.begin(),a.end());
    if (a!=s)ans="No";
    cout << ans << E;
    r0;
}


Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let s: String = read();

    let ans = if a >= 3200 { s } else { "red".to_string() };

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int main(void)
{
	string n;
	int s;

	while (true){
		getline(cin, n);
		if (n == "0") break;
		s = 0;
		for (int i=0; i<n.size(); i++){
			s += (n.at(i)-'0');
		}
		cout << s <<endl;
	}
	return 0;
}

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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	if(s[0]!='A'){
		cout<<"WA"<<'\n';
		return 0;
	}
	int ok=0;
	int tmp;
	FOR(i, 2, s.size()-1){
		if(s[i]=='C'){
			++ok;
			tmp=i;
		}
	}
	if(ok==1){
		FOR(i, 1, s.size()){
			if(i!=tmp && s[i]-'a'<0 || s[i]-'a'>26){
					cout<<"WA"<<'\n';
					return 0;
			}
		}
		cout<<"AC"<<'\n';
	}else{
		cout<<"WA"<<'\n';
	}
	return 0;
}


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;
    vector<int> d(n);
    rep(i,n) cin >> d.at(i);
    vector<int> num(101);
    int ans = 0;
    rep(i,n) num.at(d.at(i))++;
    rep(i,101){
        if(num.at(i) > 0 ) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
n,x = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
tmp = 0
tmp2 = 0
if a[0] > x:
    ans += a[0] - x
    tmp = x
else:
    tmp = a[0]
for i in range(1,n):
    if a[i] + tmp > x:
        tmp2 = a[i] + tmp - x
        ans += tmp2
        a[i] -= tmp2
        tmp = a[i]
    else:
        tmp = a[i]
print(ans)

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    int ans = 0;
    bool used[MAX];
    rep(i, N) used[i] = false;
    rep(i, N) {
        if (i - K < 0) {
            if (T[i] == 'r') {
                ans += P;
                used[i] = true;
            } else if (T[i] == 's') {
                ans += R;
                used[i] = true;
            } else {
                ans += S;
                used[i] = true;
            }
        } else {
            if (T[i - K] != T[i]) {
                if (T[i] == 'r') {
                   ans += P;
                   used[i] = true;
                } else if (T[i] == 's') {
                    ans += R;
                    used[i] = true;
                } else {
                    ans += S;
                    used[i] = true;
                }
            } else {
                if (!used[i - K]) {
                    if (T[i] == 'r') {
                        ans += P;
                        used[i] = true;
                    } else if (T[i] == 's') {
                        ans += R;
                        used[i] = true;
                    } else {
                        ans += S;
                        used[i] = true;
                    }
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  $a = explode(" ", trim(fgets(STDIN)));
  
  $ans = array_fill(0, $n, 0);
  for($i=0; $i<$n-1;$i++){
    $ans[$a[$i]-1]++;
  }

  for($i=0; $i<$n; $i++){
    echo $ans[$i].PHP_EOL;
  }

Measured memory_bytes: 35916
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#define rep( i, a, n ) for( int i = a; i < n; i++ )
#define per( i, a, n ) for( int i = n - 1; i >= a; i-- )
#define mem( f, x ) memset( f, x, sizeof( f ) )
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define e 2.71828
using namespace std;
const int N = 105;
const int M = 1e6+5;
const int MAX = 5;
const ll inv = 500000004;
const double g = 9.80;
const double PI = acos( -1.0 );
int n;
ll sum;
ll a[N];
 
int main(){
    while( scanf( "%d %lld", &n, &sum ) != EOF ){
        rep( i, 1, n + 1 ) scanf( "%lld", a + i );
        sort( a + 1, a + n + 1 );
        bool flag = 0;
        int ans = 0;
        rep( i, 1, n ){
            if( sum - a[i] < 0 )
                break;
            sum -= a[i];
            ans++;
        }
        if( sum == a[n] ) ans++;
        printf( "%d\n", ans );
    }
    return 0;
}

Measured memory_bytes: 256
import sys
n = int(input())
d,x = map(int, sys.stdin.readline().split())

a = [int(input()) for _ in range(n)]

sum = 0
for i in a:
    count = 0
    choco = 1
    while choco <= d:
        choco += i
        count += 1
    sum += count

print(x + sum)



Measured memory_bytes: 3060
N = int(input())
H = list(map(int, input().split()))

dp = [float('inf')] * N

for n in range(N):
  if ( n == 0):
    dp[n] = 0
    continue
  cost1 = dp[n - 1] + abs(H[n] - H[n - 1])
  min_cost = dp[n]
  if (min_cost > cost1):
    min_cost = cost1
  
  if (n >= 2):
    cost2 = dp[n - 2] + abs(H[n] - H[n - 2])
    if (min_cost > cost2):
      min_cost = cost2
  
  dp[n] = min_cost

print(dp[-1])


Measured memory_bytes: 13980