akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int kosu=sc.nextInt();

		int kisu=0;
		int niba=0;
		int four=0;

		int tmp=0;
		for(int i=0; i<kosu; i++) {
			tmp=sc.nextInt();
			if(tmp%2==1) {
				kisu++;
			}
			else if(tmp%2==0 && tmp%4==2) {
				niba++;
			}
			else if(tmp%4==0) {
				four++;
			}
		}
		int score=kosu-niba;

		if((score-four)<=four) {
			System.out.println("Yes");
		}
		else if((score-four-1)==four && niba==0) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

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



// Main Code
int main()
{
	int q;
	cin>>q;
	ll cnt = 0;
	priority_queue<ll> pqmax;
	priority_queue<ll, vector<ll>, greater<ll>> pqmin;
	double med = 0.0;
	ll ans = 0;
	ll lsum = 0, rsum = 0;
	while(q--)
	{
		int z;
		cin>>z;
		if(z == 1)
		{
			ll u, v;
			cin>>u>>v;
			cnt += v;
			if(pqmax.empty())
			{
				pqmax.push(u);
				lsum += u;
				med = (double) u;
				ans = u;
			}
			else
			{
				if(pqmax.size() > pqmin.size())
				{
					if(u < med)
					{
						pqmin.push(pqmax.top());
						lsum -= pqmax.top();
						rsum += pqmax.top();
						pqmax.pop();
						pqmax.push(u);
						lsum += u;

					}
					else
					{
						pqmin.push(u);
						rsum += u;
					}
					med = (pqmax.top() + pqmin.top()) / 2.0;
					ans = pqmax.top();
				}
				else if(pqmin.size() > pqmax.size())
				{
					if(u > med)
					{
						pqmax.push(pqmin.top());
						rsum -= pqmin.top();
						lsum += pqmin.top();
						pqmin.pop();
						pqmin.push(u);
						rsum += u;
					}
					else
					{
						pqmax.push(u);
						lsum += u;
					}
					med = (pqmax.top() + pqmin.top()) / 2.0;
					ans = pqmax.top();
				}
				else
				{
					if(u < med)
					{
						pqmax.push(u);
						lsum += u;
						med = (double) pqmax.top();
						ans = pqmax.top();
					}
					else
					{
						pqmin.push(u);
						rsum += u;
						med = (double) pqmin.top();
						ans = pqmin.top();
					}
				}
			}
		}
		else
		{
			ll rst = pqmax.size()*ans - lsum + rsum - pqmin.size()*ans;
			//cout<<lsum<<" "<<rsum<<" "<<pqmax.size()<<" "<<pqmin.size()<<pqmax.top()<<" "<<pqmin.top()<<endl;
			cout<<ans<<" "<<rst+cnt<<endl;
		}
	}
}


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

int main() {
  string s;
  cin >> s;
  int y = 700;
  if (s[0] == 'o') {
    y = y + 100;
  }
  if (s[1] == 'o') {
    y = y + 100;
  }
  if (s[2] == 'o') {
    y = y + 100;
  }
  cout << y << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int a;
    cin>>a;
    string s;
    cin>>s;
    if(a>=3200){
        cout<<s<<endl;
    }else{
        cout<<"red"<<endl;
    }
}

Measured memory_bytes: 3480
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w,d;
    cin>>h>>w>>d;
    int F[310][310];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)cin>>F[i][j];
    }
    pair<int,int> a[d5];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            a[F[i][j]]=make_pair(i,j);
        }
    }
    int cost[d5];
    for(int i=0;i<d5;i++)cost[i]=0;
    for(int i=1;i<d5;i++){
        if(i-d<0)continue;
        cost[i]+=cost[i-d]+abs(a[i].first-a[i-d].first)+abs(a[i].second-a[i-d].second);
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;
        cout<<cost[r]-cost[l]<<endl;
    }
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  string s;
  cin >> s;
  int n=s.size();
  int ans=0;
  rep(i, n){
    ans+=(int)(s[i]-'0');
  }
  if(ans%9==0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3716
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <limits>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <numeric>
//#include <tuple>

constexpr long long mod = static_cast<long long>(1e9 + 7);

void dfs(int i, const std::vector<std::vector<int>>& edges, std::vector<bool>& isVisit, std::vector<int>& nodes) {
    isVisit[i] = true;
    nodes.push_back(i);
    for(auto v: edges[i]) {
        if(!isVisit[v]) dfs(v, edges, isVisit, nodes);
    }
}

int main() {
    int N, M;
    std::cin >> N >> M;
    std::vector<int> weights(N);
    for(auto& val: weights)
        std::cin >> val;

    std::vector<std::vector<int>> edges(N);
    while(M--) {
        int u, v;
        std::cin >> u >>v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }

    std::vector<std::vector<int>> trees;
    std::vector<bool> isVisit(N, false);
    for(int i = 0; i < N; ++i) {
        if(!isVisit[i]) {
            std::vector<int> ans;
            dfs(i, edges, isVisit, ans);
            trees.push_back(std::move(ans));
        }
    }

    std::sort(begin(trees), end(trees), [](auto& x, auto& y){return x.size() > y.size();});

    std::priority_queue<int, std::vector<int>, std::greater<int>> que;
    for(auto val: trees[0])
        que.push(weights[val]);

    long long ans = 0;
    for(int i = 1; i < trees.size(); ++i) {
        auto& tree = trees[i];
        if(que.empty()) {
            ans = -1;
            break;
        }
        std::sort(begin(tree), end(tree), [&weights = weights](int x, int y){return weights[x] < weights[y];});
        int v = que.top();
        que.pop();
        ans += (v + weights[tree.front()]);
        for(int j = 1; j < tree.size(); ++j)
            que.push(weights[tree[j]]);
    }

    if(ans < 0) std::cout << "Impossible" << std::endl;
    else std::cout << ans << std::endl;

    return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    ll N, M;
    cin >> N >> M;
    pair<ll, ll> X[100000];
    for (int i = 0; i < N; i++) {
        ll A, B;
        cin >> A >> B;
        X[i] = make_pair(A, B);
    }
    sort(X, X + N);
    ll ans = 0, k = 0;
    for (int i = 0; k != M; i++) {
        ll a = min(M - k, X[i].second);
        ans += a * X[i].first;
        k += a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
# AOJ DSL_2_A "Range Minimum Query"
# SegmantTreeの実装

# 初期化最大値
INF = (1 << 31) - 1

class SegmentTree:
    def __init__(self, N):
        self.N = 2**(N-1).bit_length()
        self.data = [[INF, -1] for _ in range(2*self.N-1)]

    # k番目の値(0-indexed)をaに変更
    def update(self, k, a):
        self.data[k+self.N-1] = [a, k]
        k += self.N - 1
        while k > 0:
            k = (k-1)//2
            if self.data[2*k+1][0] < self.data[2*k+2][0]:
                self.data[k] = self.data[2*k+1][:]
            else:
                self.data[k] = self.data[2*k+2][:]

    # [l, r)の最小値取得
    # kがNodeの番号、対応する区間が[a, b)
    def query_min(self, l, r):
        L = l + self.N
        R = r + self.N
        s = [INF, -1]
        while L < R:
            if R & 1:
                R -= 1
                if s[0] > self.data[R-1][0]:
                    s = self.data[R-1]
            if L & 1:
                if s[0] > self.data[L-1][0]:
                    s = self.data[L-1]
                L += 1
            L >>= 1; R >>= 1
        return s


import sys
input = sys.stdin.readline
from bisect import bisect_left

N = int(input())
X = list(map(int, input().split()))
sortedX = sorted(X)

decided = [-1]*(N**2+1)
for i, x in enumerate(X):
    decided[x] = i+1

marge = SegmentTree(N+1)
remains = [0]*(N+1)
alreadyUsed = [None]*(N+1)
for i, x in enumerate(X):
    i += 1
    alreadyused = bisect_left(sortedX, x)
    if i != 1:
        marge.update(i, x-alreadyused-i)
    alreadyUsed[i] = alreadyused
    remains[i] = i-1

def solve():
    offset = 0
    for n in range(1,N**2+1):
        if decided[n] != -1:
            decided_num = decided[n]
            if remains[decided_num] > 0:
                return False, None
            remain = N-decided_num
            if remain < 0:
                return False, None
            if remain == 0:
                marge.update(decided_num, INF)
                remains[decided_num] = 0
            else:
                marge_now = (N**2-n)-(N-alreadyUsed[decided_num]-1)-remain+offset
                marge.update(decided_num, marge_now)
                remains[decided_num] = remain
        else:
            marge_now, num = marge.query_min(0, N+1)
            if marge_now-offset < 0 or marge_now == INF:
                return False, None
            remains[num] -= 1
            if remains[num] == 0:
                marge.update(num, INF)
            else:
                marge.update(num, marge_now+1)
            decided[n] = num
            offset += 1
    return True, decided[1:]

if __name__ == "__main__":
    ok, ans = solve()
    if ok:
        print("Yes")
        print(*ans)
    else:
        print("No")


Measured memory_bytes: 66520
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Cards[] = new int[N];
        for (int i = 0; i <= N - 1; i++) {
            Cards[i] = sc.nextInt();
        }
        int alice = 0;
        int bob = 0;
        int j;
        while (true) {
            j = calc(Cards);
            alice += Cards[j];
            Cards[j] = 0;
            j = calc(Cards);
            bob += Cards[j];
            Cards[j] = 0;
            j = calc(Cards);
            if (Cards[j] == 0) {
                break;
            }
        }
        System.out.println(alice - bob);
        sc.close();

    }

    public static int calc(int num[]) {
        int max = 0;
        int listNumber = 0;
        for (int i = 0; i <= num.length - 1; i++) {
            if (num[i] >= max) {
                max = num[i];
                listNumber = i;
            }
        }
        return listNumber;
    }

}

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

int main() {
  long int N, sum=0;cin >> N;
  vector<int> vec(N);
  vec.at(0) = 1;
  for (int i=1;i<N;i++) vec.at(i) = vec.at(i-1) + 1;
  for (int i=0;i<N;i++) {
    //if (vec.at(i)%15 == 0) continue;
    if (vec.at(i) % 3 == 0) vec.at(i) = 0;
    else if (vec.at(i) % 5 == 0) vec.at(i) = 0;
    else continue;
  }
  for (int i=0;i<N;i++) sum += vec.at(i);
  cout << sum << endl;
}


Measured memory_bytes: 7216
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <map>

using namespace std;






int main()
{
    int a,b,c;scanf("%d%d%d",&a,&b,&c);
    if (a+b+c>=22)
        printf("bust");
    else
        printf("win");



}









Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define modd 998244353
#define umap unordered_map<ll,ll>

ll a[101];

ll fun(ll n,ll k){
  ll dp[n+2][k+2];

  for(int j=0;j<=k;j++)     //base case
    dp[0][j]=(j>a[0]?0:1);

  for(int i=1;i<n;i++)     // distributing among other children also
    for(int j=0;j<=k;j++)
      if(j==0)dp[i][j]=dp[i-1][j];   // if no candies left
      else dp[i][j]=(dp[i][j-1]%mod+dp[i-1][j]%mod-(j-a[i]-1>=0?dp[i-1][j-a[i]-1]:0)%mod +mod)%mod;


    return dp[n-1][k];


}

int32_t main() 
{ 
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    ll n,k;
    cin>>n>>k;
   
    fori(0,n)cin>>a[i];
 
    
    cout<<fun(n,k)<<"\n";





    
  
    
    
 
return 0;
}    

Measured memory_bytes: 81676
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define SIZE 100005

using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
long long int MOD = 1000000007;

int main()
{
	string str;
	cin>>str;
	int n=str.size();
	int ans=n/2;
	for(char x='a';x<='z';x++){
		string newstr=x+str+x;
		int ma=0;
		int cnt=0;
		for(int i=0;i<newstr.size();i++){
			if(newstr[i]==x){
				ma=max(ma,cnt);
				cnt=0;
			}else{
				cnt++;
			}
		}
		ans=min(ma,ans);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n;
struct suit{
    char t;
    int num;
};
suit a[100000];
suit b[100000];
int cmp(suit x,suit y){
    return x.num<y.num;
}
int Partition(int p,int r){
    int i=p-1,j;
    suit temp;
    for(int j=p;j<r;j++){
        if( a[j].num <=a[r].num){
            i++;
            temp=a[j];
            a[j]=a[i];
            a[i]=temp;
            //swap(a[i],a[j]);
        }
    }
    temp=a[r];
    a[r]=a[i+1];
    a[i+1]=temp;

    return i+1;
}
int QuickSort(int p,int r){
     if(p<r){
        int v=Partition(p,r);
        QuickSort(p,v-1);
        QuickSort(v+1,r);
    }
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin >> a[i].t>>a[i].num;
        b[i]=a[i];
    }
    QuickSort(0,n-1);
    stable_sort(b,b+n,cmp);
    int judge=1;
    for(int i=0;i<n;i++){
        if(a[i].num!=b[i].num||a[i].t!=b[i].t){
            judge=0;
            break;
        }
    }
    if(judge==0)
        cout<<"Not stable"<<endl;
    else
        cout<<"Stable"<<endl;
    for(int i=0;i<n;i++)
        cout<<a[i].t<<" "<<a[i].num<<endl;
    return 0;
}



Measured memory_bytes: 4736
from collections import defaultdict

n = int(input())

def get_primes(lim):
    table = [True] * (lim+1)
    table[0:2] = False, False
    for i in range(2, int(lim**0.5)+1):
        if not table[i]: continue
        for j in range(i*2, lim+1, i):
            table[j] = False
    return [i for i in range(lim+1) if table[i]]

def factorize(x, primes):
    res = []
    for p in primes:
        if p ** 2 > x: break
        cnt = 0
        while not x % p:
            x //= p
            cnt += 1
        if cnt: res.append((p, cnt))
    if x > 1: res.append((x, 1))
    return res

p = get_primes(100)
ff = defaultdict(int)

for i in range(2, n+1):
    for x, num in factorize(i, p):
        ff[x] += num

ans = 0

for i in range(len(p)):
    if 74 <= ff[p[i]]: ans += 1
    for j in range(len(p)):
        if i == j: continue
        if 4 <= ff[p[i]] and 14 <= ff[p[j]]: ans += 1
        if 2 <= ff[p[i]] and 24 <= ff[p[j]]: ans += 1
        for k in range(j, len(p)):
            if j == k or i == k: continue
            if 2 <= ff[p[i]] and 4 <= ff[p[j]] and 4 <= ff[p[k]]:
                ans += 1

print(ans)


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

int main()
{
	int n; cin >> n;
	vector<int> a( n, 0 );
	REP( i, n ) cin >> a[i];
	int sum = accumulate( ALL( a ), 0 );

	bitset<4000010> set;
	set.set(0);
	REP( i, n ) set |= set << a[i];
	
	int cnt = 0;
	int l = ( sum + 1 ) / 2;
	REP( i, 4000010 )
	if( i >= l && set[i] )
	{
		cout << i << endl;
		break;
	}

	return 0;
}

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

int main(){
	set<string> user;
	bool open=false;
	string name;
	int n,m;
	cin>>n;
	while(n--){
		cin>>name;
		user.insert(name);
	}
	cin>>m;
	while(m--){
		cin>>name;
		if(user.find(name)!=user.end()){
			if(open)cout<<"Closed by ";
			else cout<<"Opened by ";
			cout<<name<<endl;
			open=!open;
		}else{
			cout<<"Unknown "<<name<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
using namespace std;
const int inf=1e9+10;
const int mod=1e9+7;
const int maxn=1e5+10;
string s,t,u;
int a,b;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>s>>t>>a>>b>>u;
	if(u==s) a--;
	if(u==t) b--;
	cout<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int a ; cin >>a ; 
  int sum = 0 ; 
   int  mx = 20000 ; 
  int *arr = new int [a]; 
  for (int i= 0  ; i< a ;i++)
  cin >> arr[i] ; 
  
  for ( int i = 0 ; i < a ; i++)
  for ( int j = i+1 ; j < a ; j++)
  sum += arr[i]*arr[j] ;//3
                        //3 1 2
  
 cout<<sum ; 
    return 0;
}

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

int main(){
    int ans = 0;
    int N;

    std::cin >> N;
    vector<int> tako(N);

    for(int i = 0; i < N; i++){
        std::cin >> tako[i];
    }

    for(int i = 0; i < N-1; i++){
        for(int j = i+1; j < N; j++){
            ans = ans + tako[i]*tako[j];
        }
    }

    std::cout << ans;


}

Measured memory_bytes: 3584
# -*- coding: utf-8 -*-
"""
B - Contest with Drinks Easy
https://atcoder.jp/contests/abc050/tasks/abc050_b

"""
import sys


def solve(N, T, M, drinks):
    total = sum(T)
    ans = []
    for p, x in drinks:
        ans.append(total + x - T[p-1])
    return ans


def main(args):
    N = int(input())
    T = [int(t) for t in input().split()]
    M = int(input())
    drinks = [[int(i) for i in input().split()] for _ in range(M)]
    ans = solve(N, T, M, drinks)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 3064
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
ll i,j,k;
ll n,m;
ll ma,mb;
ll dp[405][405];
ll a[45],b[45],c[45];
ll ans=0;

int main(){
	
	cin>>n>>ma>>mb;
	for(i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	for(i=0;i<402;i++){
		for(j=0;j<402;j++){
			dp[i][j]=INF;
		}
	}
	dp[0][0]=0;
	for(i=0;i<n;i++){
		for(j=402;j>=0;j--){
			for(k=402;k>=0;k--){
				if(j<a[i] || k<b[i]){
				}else{
					dp[j][k]=min(dp[j][k],dp[j-a[i]][k-b[i]]+c[i]);
				}
			}
		}
	}
	ll ans=INF;
	for(i=1;i<450;i++){
		if(ma*i>=400 || mb*i>=400)break;
		ans=min(ans,dp[ma*i][mb*i]);
	}
	if(ans==INF){
		cout<<-1<<endl;
	}else{
		cout<<ans<<endl;
	}

	return 0;
}


Measured memory_bytes: 6272
s = input()
K = int(input())

ans = []

for index, i in enumerate(s):
  ans.append(i)

  count = 1
  now = i
  for indexs, k in enumerate(s):
    if indexs <= index:
      continue
      
    if count >= 5:
      break

    now += k
    ans.append(now)
    count += 1

ans = list(set(ans))
ans.sort()
print(ans[K-1])

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

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

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

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

// value
int N;
int A[100010];

void solve() {

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int ans[3][2];
	ans[0][0] = A[1];
	ans[0][1] = A[0];
	ans[1][0] = A[0];
	ans[2][0] = gcd(A[0], A[1]);
	for (int i = 2; i < N; i++) {
		ans[0][0] = max(gcd(ans[0][0], A[i]), gcd(ans[0][1], A[i]));
		ans[0][1] = gcd(ans[1][0], A[i]);
		ans[1][0] = ans[2][0];
		ans[2][0] = gcd(ans[2][0], A[i]);
	}

	cout << max(ans[1][0], max(ans[0][0], ans[0][1])) << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    string s;
    cin >> s;
    int y = stoi(s.substr(0,4));
    int m = stoi(s.substr(5,2));
    int d = stoi(s.substr(8,2));

    if(y>2019 || (y==2019 && m>4)) cout << "TBD" << endl;
    else cout << "Heisei" << endl;

    return 0;
    
}

Measured memory_bytes: 256
# coding: utf-8

data = {}
while i = gets do
  i = i.chomp
  next if i.empty?
  cnt = data[i]
  cnt = 0 if cnt == nil
  data[i] = cnt += 1
end

result = data.sort {|(k1, v1), (k2, v2)| v2 <=> v1}

max = 0
array = []
result.each do |key, value|
  if max.to_i > value.to_i then
    break
  else
    max = value
  end
  array << key.to_i
end

array.sort!{|a, b| (a <=> b)}
array.each do |a|
  puts a
end

Measured memory_bytes: 6088
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;

int main(){
  int H, W; cin >> H >> W;
  char s[H][W];
  rep(i, H)
    rep(j, W)
    cin >> s[i][j];
  //ここまで入力

  //(i, j)から各方向に照らせるのが何マスか
  int left[H][W],  right[H][W];
  int lower[H][W], upper[H][W];
  
  //leftの計算
  rep(i, H){
    rep(j, W){
      //壁ならば次のマスを見る
      if(s[i][j] == '#'){
	//照らせるマスは0
	left[i][j] = 0;
	continue;
      }
      //一番左のマスが照らせる範囲は1マス
      if(j == 0)
	left[i][j] = 1;
      //一つ左のマスより，一マス多く照らせる
      else
	left[i][j] = left[i][j-1] + 1;  
    }
  }

  //rightの処理．leftと同様
  rep(i, H){
    for(int j=W-1; j>=0; j--){
      if(s[i][j] == '#'){
	right[i][j] = 0;
	continue;
      }
      if(j == W-1)
	right[i][j] = 1;
      else
	right[i][j] = right[i][j+1] + 1;
    }
  }

  //lowerの処理．leftと同様
  for(int i=H-1; i>=0; i--){
    rep(j, W){
      if(s[i][j] == '#'){
	lower[i][j] = 0;
	continue;
      }
      if(i == H-1)
	lower[i][j] = 1;
      else
	lower[i][j] = lower[i+1][j] + 1;
    }
  }

  //upperの処理．leftと同様
  rep(i, H){
    rep(j, W){
      if(s[i][j] == '#'){
	upper[i][j] = 0;
	continue;
      }
      if(i == 0)
	upper[i][j] = 1;
      else
	upper[i][j] = upper[i-1][j] + 1;
    }
  }

  int sum;
  int max = 0;
  rep(i, H){
    rep(j, W){
      //4方向足すが，(i, j)マスを三重でカウントしているため-3する
      sum = left[i][j] + right[i][j] + lower[i][j] + upper[i][j] - 3;
      //maxの更新
      if(sum > max)
	max = sum;
    }
  }
  
  cout << max << endl;

  return 0;
}


Measured memory_bytes: 66688
#include "bits/stdc++.h"
using namespace std ;


int a[3000] ;
int p[3000] ;
int L[3000] ;
int main(){
	int n , l ;
	cin >> n ;
	for( int i = 0 ; i < n ; i++ ){
		cin >> l ;
		L[i] = l ;
		a[l]++ ; 
	}
	for( int i = 1 ; i < 3000 ; i++ ){
		p[i] = p[i-1] + a[i ] ;
	}
	long long count = 0 ;
	for( int i = 0 ; i < n ; i++ ){
		for( int j = i+1 ; j < n ; j++ ){
			int a = L[i] ;
			int b = L[j] ;
			int m  = abs(a-b) ;
			int M = a+b ;
			int ans = p[M-1] - p[m] ;
			if( m < a && a < M ) ans-- ;
			if( m < b && b < M) ans-- ;
			// cout << a << " " << b << " " <<m   << " " <<M << " " << p[M-1] - p[m] << endl ;
			count += ( max(0,ans) );
		}
	}
	cout << count / 3 << endl ;



	return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
const int MAX_V=1e5+1;
vector<int> G[MAX_V];
int dis[2][MAX_V];
int used[2][MAX_V];
int c[2]={1,1};
void add_edge(int from, int to){
  G[from].pb(to);
  G[to].pb(from);
}
void distance(int s,int p, int d){
  rep(i,G[s].size()){
    int point = G[s][i];
    if(!used[p][point]){
      used[p][point]=1;
      dis[p][point]=d+1;
      distance(point, p, d+1);
    }
  }  
}

void search(int s, int p, int kinshi,int N){
  
  //  if(s!=kinshi){
  rep(i,G[s].size()){
    int point = G[s][i];
    if(!used[p][point] && point != kinshi){
      if(p==0 && point==N-1){
	continue;
      }
      else{
      used[p][point]=1;
      c[p]++;
      search(point,p,kinshi,N);
      }
    }
  }
  //  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int a,b;
  rep(i,N-1){
    cin >> a >> b;
    a--;
    b--;
    add_edge(a,b);
  }
  memset(used[0],0,sizeof(used[0]));
  memset(used[1],0,sizeof(used[1]));
  dis[1][N-1]=0;
  dis[0][0]=0;
  used[1][N-1]=1;
  used[0][0]=1;
  distance(N-1, 1, 0);
  distance(0, 0, 0);
  int l=INT_MAX;
  int index;
  rep(i,N){
    //    cout << i<<" : F Dis " << dis[0][i] << " S Dis " << dis[1][i] << endl;
    if(dis[0][i] == dis[1][i]){
      if(l > dis[0][i]){
	l = dis[0][i];
	index =i;
      }
    }

    if(dis[0][i]+1 == dis[1][i]){
      if(l > dis[0][i]){
        l = dis[0][i];
      	index =i;
      }
    }
  }
  //  cout << "kinshi " << index << endl;
  if(index!=0) c[0]=2;
  memset(used[0],0,sizeof(used[0]));
  memset(used[1],0,sizeof(used[1]));
  used[0][0]=1;
  used[1][N-1]=1;
  //  search(0, 0, index,N);
  search(N-1,1,index,N);
  c[0]=N-c[1];
  //  cout << "first pc : " << c[0] << " second pc : "<< c[1] << endl;
  if(c[0] <= c[1]){
    cout << "Snuke" << endl;
  }
  else{
    cout << "Fennec" << endl;
  }
  
  return 0;
    

}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int LOG=61;

ll A, B, u, v, x, y, t, a, b, ans, bit;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>A>>B;
	if (A==B) kill(1)
	for (int i=59; ~i; i--){
		bit=i;
		if ((A^B)&(1ll<<i)) break ;
		if (A&(1ll<<i)){
			A^=(1ll<<i);
			B^=(1ll<<i);
		}
	}
//	debug(bit)
	ans=(1ll<<bit)-A;
	ll tmp=(B^(1ll<<bit))+1;
	while (tmp&(tmp-1)) tmp+=(tmp&-tmp);
	if (tmp>=A) ans+=(1ll<<bit);
	else{
		ans+=tmp;
		ans+=(1ll<<bit)-A;
	}
	cout<<ans<<"\n";
	
	return 0;
}


Measured memory_bytes: 3656
H,W,K = map(int, input().split())
L=[]
for i in range(H):
    L.append(list(input()))
HH = 2**H
WW = 2**W

C=0

for i in range(HH):
    for i2 in range(WW):
        c=0
        hh = str(format(i,"b").zfill(H))
        ww = str(format(i2,"b").zfill(W))
        for h in range(H):
            for w in range(W):
                if hh[h]=="0" and ww[w]=="0":
                    if L[h][w]=="#":
                        c+=1
        if c==K:
            C+=1
print(C)

Measured memory_bytes: 9248
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

int power(int x, int n){
	int res = 1;
	
	while(n){
		if(n&1) res *= x;
		
		x *= x;
		
		n >>= 1;
		
		res %= MOD;
		
		x %= MOD;
	}
	
	return res;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	const int NUM = 20;
	const int MAX = (1<<NUM);
	
	int N;
	int ans = 0;
	
	vector<int> con(MAX);
	
	cin>>N;
	
	for(int i = 0; i < N; i++){
		int a;
		
		cin>>a;
		
		con[a]++;
	}
	
	for(int i = 0; i < NUM; i++){
		for(int j = 0; j < MAX; j++){
			if(~j & (1 << i)) {
				con[j] += con[j ^ (1 << i)];
				con[j] %= MOD;
			}
		}
	}
	
	for(int i = 0; i < MAX; i++){
		con[i] = power(2, con[i]);
		con[i] = (con[i] - 1 + MOD)%MOD;
	}
	
	for(int i = 0; i < MAX; i++){
		
		if(__builtin_popcount(i) % 2 == 0) ans += con[i];
		else ans -= con[i];
		
		ans = (ans + MOD) % MOD;
	}
	
	cout<<ans<<endl;
	
	return 0;
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  int L, R;
  cin >> L >> R;

  if(R-L >= 2019){
    cout << 0 << endl;
  }
  else{
    ll ans = 2019;
    for(ll j = L+1; j <=R; j++){
      for(ll i = L; i < j; i++){
        ans = min(ans, i*j%(ll)2019);
      }
    }
    cout << ans << endl;
  }

  return 0;
}


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

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  
  if((b-a) <= 0){
    cout << "delicious" << endl;
   }else if(b-a <= x){
    cout << "safe" << endl;
  }else{
    cout << "dangerous" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <ctime>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int unt;
typedef double db;
typedef pair <int, int> pii;
typedef vector <int> vi;

#define Fi first
#define Se second
#define pb push_back
#define mp make_pair
#define rep(x, a, b) for(int x = (a); x <= (b); ++ x)
#define per(x, a, b) for(int x = (a); x >= (b); -- x)
#define rop(x, a, b) for(int x = (a); x < (b); ++ x)
#define por(x, a, b) for(int x = (a); x > (b); -- x)
#define forE(x, a) for(int x = head[a]; x; x = nxt[x])

#ifdef DEBUG
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define debug(x)
#endif

const db eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int Minf = 0x7f7f7f7f;
const LL INF = 0x3f3f3f3f3f3f3f3fll;
const LL MINF = 0x7f7f7f7f7f7f7f7fll;

int main() {
	LL n; cin >> n;
	LL ans = n - 1;
	for(LL i = 1; i * i <= n; ++ i) {
		if(n % i == 0) ans = min(ans, i - 1 + n / i - 1);
	}
	printf("%lld\n", ans);
}


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

typedef string::iterator IT;

typedef struct{
    int mode;
    string src;
    string dest;
} firewall;

typedef struct{
    int legal;
    string src;
    string dest;
    string mes;
} packet;

bool id(string key, string trg){
    IT itk = key.begin();
    IT itt = trg.begin();
    for(; itk != key.end(); (itk++, itt++)){
        if( *itk == '?' ) continue;
        if( *itk != *itt ) return false;
    }
    return true;
}

int convert(string key){
    return key == "permit";
}

int main(){
    int n, m;
    while( cin >> n >> m, n || m ){
        firewall fw[n];
        packet pck[m];
        int count = 0;
        string a, b, c;
        for(int i = 0; i < n; i++){
            cin >> a >> b >> c;
            fw[i].mode = convert(a);
            fw[i].src = b;
            fw[i].dest = c;
        }
        for(int i = 0; i < m; i++){
            cin >> a >> b >> c;
            pck[i].legal = 0;
            pck[i].src = a;
            pck[i].dest = b;
            pck[i].mes = c;
        }
        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                if( id( fw[j].src, pck[i].src ) &&
                    id( fw[j].dest, pck[i].dest ) ){
                    pck[i].legal = fw[j].mode;
                }
            }
            count += pck[i].legal;
        }
        cout << count << endl;
        for(int i = 0; i < m; i++){
            if( pck[i].legal ){
                cout << pck[i].src << ' ' << pck[i].dest
                     << ' ' << pck[i].mes << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1464
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;

int main() {
    int n, x;
    cin >> n >> x;
    int l[n], d[n + 1];
    d[0] = 0;
    for (int i = 0; i < n; i++) {
        cin >> l[i];
        d[i + 1] = d[i] + l[i];
    }

    int cnt = 0;
    for (int i = 0; i < n + 1; i++) {
        if (d[i] <= x) cnt++;
    }

    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
import bisect
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)
ans = 0
for a in range(0,n-2):
  for b in range(a+1,n-1):
    max_c = bisect.bisect_left(l,l[a] + l[b])
    ans += max_c-b-1
print(ans)
      
      
      

Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

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

	int n;
	cin >> n;

	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}

	int ans = 0;
	rep(i, n) {
		if (a[a[i]] == i) {
			ans++;
		}
	}
	cout << ans / 2 << endl;

	return 0;
}








Measured memory_bytes: 1152
n, k = map(int, input().split())
list_A = list(map(int, input().split()))
list_MAP = []
set_MAP = set()
x = 1
while True:
    list_MAP.append(x)
    set_MAP.add(x)
    x = list_A[x-1]
    if x in set_MAP:
        break


q = len(list_MAP) - list_MAP.index(x)
p = k - list_MAP.index(x)

if p < 0:
    print(list_MAP[k])
else:
    list_MAP = list_MAP[list_MAP.index(x):]
    print(list_MAP[p % q])

Measured memory_bytes: 32528
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    sa = sum(a)
    t = 0
    mt = 10 ** 20
    for v in a:
        t += v
        mt = min(mt, abs(sa - t - t))
    print(mt)


if __name__ == '__main__':
    solve()


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

int top, S[1000];

void push(int x){
    S[++top] = x;
}

int pop(){
    top--;
    return S[top+1];
}

int main(){
    int a, b;
    top = 0;
    char s[100];
    
    while(scanf("%s", s) != EOF){
        if(s[0] =='+'){
            a = pop();
            b = pop();
            push(a + b);
        } else if(s[0] =='-'){
            b = pop();
            a = pop();
            push(a - b);
        } else if(s[0] == '*'){
            a = pop();
            b = pop();
            push(a * b);
        } else {
            push(atoi(s));
        }
    }
    
    printf("%d\n", pop());
    
}


Measured memory_bytes: 3192
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
se_ = Counter(A)
key = se_.keys()
 
 
all = 0
for i in key:
    all += se_[i]*(se_[i]-1)//2
    
 
for i in A:
    final=0
    final = all -se_[i]+1
    print(final)

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

int main(){
  int N;
  cin >> N;
  int64_t L0, L1, L2, Ln;
  L0 = 2;
  L1 = 1;
  L2 = 0;
  Ln = 1;
  for(int i = 0; i < N - 1; i++){
    Ln = L1 + L0;
    L2 = L0;
    L0 = L1;
    L1 = L0 + L2;
  }
  cout << Ln << endl;
}

Measured memory_bytes: 3636
/*
    Author: Shivam Shukla
    Title : DP_N_Modified.cpp
    Date : 03/09/2020   >> 13:15:37
*/

#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
#define INF(x) numeric_limits<x>::max()
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow_mod(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 
unordered_map<ll, unordered_map<ll, ll>> dp; 
ll solve(vl& a, vl& pre, int i, int j) {
    if (i >= j)
        return 0;

    if (dp.count(i) && dp[i].count(j))
        return dp[i][j];

    ll mn = INF(ll);
    rep(k, i, j) {
        mn = min(mn, solve(a, pre, i, k) + solve(a, pre, k + 1, j) + pre[j] - ((i) ? pre[i - 1] : 0));    
    }    

    dp[i][j] = mn;
    return mn;
} 

int32_t main(int argc,char** argv){
    fastio();
    auto tstart= clock();
 
    #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      freopen("error.txt","w",stderr);
    #endif   

    int n; cin >> n; 
    vl a(n), pre(n); repa(i, n) cin >> a[i];

    pre[0] = a[0];
    rep(i, 1, n)  
        pre[i] = pre[i - 1] + a[i];

    cout << solve(a, pre, 0, n - 1) << endl;


    cerr << setprecision(2) << fixed<<"Time elapsed: " << (double)(clock() - tstart)/CLOCKS_PER_SEC << endl; 
    return 0; 
}

Measured memory_bytes: 7184
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class Main {

    static int n;
    static int[] data;
    static BufferedReader br;
    static BufferedWriter bw;

    public static void main(String args[]) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        bw = new BufferedWriter(new OutputStreamWriter(System.out));
        n = Integer.parseInt(br.readLine());
        String[] st = br.readLine().split(" ");
        data = new int[n];
        for (int i = 0; i < n; i++) {
            data[i] = Integer.parseInt(st[i]);
        }

        for (int i = 1; i < n; i++) {
            printData();
            int key = data[i];
            int j = i - 1;
            while (j >= 0 && data[j] > key) {
                data[j + 1] = data[j];
                j--;
            }
            data[j + 1] = key;
        }
        printData();
        bw.flush();
    }

    static void printData() throws IOException {
        bw.append("" + data[0]);
        for (int j = 1; j < n; j++) {
            bw.append(" " + data[j]);
        }
        bw.newLine();
    }

}


Measured memory_bytes: 26592
#include <bits/stdc++.h>
#define INF 1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define arr array
#define _min(a) *min_element(a.begin(), a.end());
#define _max(a) *max_element(a.begin(), a.end());
#define _sort(x) sort(x.begin(), x.end())
#define _rsort(x) sort(x.rbegin(), x.rend())
#define _reverse(x) reverse(x.begin(), x.end())
#define _debug(x) cout << #x << " = " << x << endl;
#define debug(x, y) cout << #x " = " << x << " " << #y << " = " << y << endl;
#define _lower_bound(a, x) lower_bound(a.begin(), a.end(), x) - a.begin()
#define _upper_bound(a, x) upper_bound(a.begin(), a.end(), x) - a.begin()
typedef long long ll;
using namespace std;

void solve() {	
	int n; cin >> n;
	vector<int> a(n), dp(n, 0);
	for (auto &u : a) cin >> u;
	dp[1] = abs(a[1] - a[0]);
	for (int i = 2; i < n; ++i) {
		dp[i] = min(abs(a[i] - a[i - 1]) + dp[i - 1], abs(a[i] - a[i - 2]) + dp[i - 2]);
	}
	// for (auto &u : dp) cout << u << " "; cout << endl;
	cout << dp[n - 1] << endl;
}   

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

    // int t; cin >> t;
    // while(t--) 
        solve();
}

Measured memory_bytes: 3968
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    cnt = 0
    for x in range(N-2):
        if S[x:x+3] == "ABC": cnt += 1
    print(cnt)
    return


# 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():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define gnr(i,l,r) for(int i=int(r); i>=int(l); i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Int n,m,_,x,y,q;
string s,sb;
bool ok;
char ch;

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

  cin>>s>>x; n=s.size();
  ok=true;
  rep(i,n-1){
    ok&=(s[i]==s[i+1]);
  }
  if(ok){pri1(n*x/2); return 0;}
  if(s[0]!=s[n-1]){
    int sm=1; Int ans=0;
    rer(i,1,n){
      if(s[i]==s[i-1])sm++;
      else{
        ans+=x*(sm/2); sm=1;
      }
    }
    ans+=x*(sm/2);
    END
  }else{
    int sm=1; Int ans=0;
    rer(i,1,n){
      if(s[i]==s[i-1])sm++;
      else{
        ans+=x*(sm/2); sm=1;
      }
    }
    ans+=x*(sm/2);
    int ma=1,usi=1;
    rep(i,n-1){
      if(s[i+1]==s[i])ma++;
      else break;
    }
    gnr(i,1,n-1){
      if(s[i-1]==s[i])usi++;
      else break;
    }
    if((ma%2)&&(usi%2))ans+=x-1;
    END
  }
}

Measured memory_bytes: 256