akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
long long gcd(long long a, long long b) { return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b) { return a/gcd(a,b)*b;}

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

int dp[105][4][2];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int K;
  cin >> K;
  dp[0][0][0] = 1;
  rep(i,n)rep(j,4)rep(k,2) {
    int nd = s[i]-'0';
    rep(d,10) {
      int ni = i+1, nj = j, nk = k;
      if (d != 0) nj++;
      if (nj > K) continue;
      if (k == 0) {
        if (d > nd) continue;
        if (d < nd) nk = 1;
      }
      dp[ni][nj][nk] += dp[i][j][k];
    }
  }
  int ans = dp[n][K][0] + dp[n][K][1];
  cout << ans << endl;
  return 0;



  // string s;
  // cin >> s;
  // int k;
  // cin >> k;
  // int dp[s.size()][k + 1][2];
  // rep(i, s.size() + 1) rep(j, k + 1) rep(h, 2) dp[i][j][h] = 0;
  // dp[0][0][0] = 1;

  // for (int i = 0; i < s.size(); i++) {
  //   int x = s[i] - '0';
  //   int ni = i + 1;

  //   rep (j, k + 1) {
  //     rep (a, 10) {
  //       int nj = j;
  //       if (a != 0) nj = j + 1;
  //       if (nj > k) continue;

  //       rep (h, 2) {
  //         int nk = 0;
  //         if ((x == a && h == 1) || (x == a && i == 0)) nk = 1;
  //         else if ((h == 1 && a > x) || (i == 0 && a > x)) break;
  //         dp[ni][nj][nk] += dp[i][j][h];
  //       }
  //     }
  //   }
  // }

  // int ans = dp[s.size()][k][0] + dp[s.size()][k][1];
  // cout << ans << endl;
  // return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

//For DP
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//Union-Find tree
struct UnionFind{
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N;  i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る : root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { //xとyの木を併合
        int rx = root(x); //xの木の根をrx
        int ry = root(y); //yの木の根をyx
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)ときはそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時 : xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int main(){
    int a[3];
    rep(i,3) cin >> a[i]; 
    int judge[2] = {0};
    rep(i,3){
        if(a[i] == 5) judge[0] += 1;
        if(a[i] == 7) judge[1] += 1;
    }
    if(judge[0] == 2 && judge[1] == 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


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

int main() {
    string s;
    cin>>s;
    for(int i=0; i<s.size(); i++) {
        if(s[i] == '?') {
            s[i] = 'D';
        }
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3752
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int lcm(int i, int j){
    return i/__gcd(i, j)*j;
}

int main() {
    int n;
    while(cin >> n, n){
        vector<int> L(n), R(n), S(n), T(n);
        vector<vector<int>> G(n);
        vector<int> dp(n), indeg(n);
        for (int i = 0; i < n; ++i) {
            int p, q, r, b;
            scanf("%d %d %d %d", &p, &q, &r, &b);
            r--; b--;
            L[i] = p, R[i] = q, S[i] = r, T[i] = b;
            if(r < 0 && b < 0){
                dp[i] = (p+q)/__gcd(p, q);
            } else {
                if(r >= 0) G[i].emplace_back(r), indeg[r]++;
                if(b >= 0) G[i].emplace_back(b), indeg[b]++;
            }
        }
        deque<int> Q;
        stack<int> s;
        int cnt = 0;
        int x = min_element(indeg.begin(),indeg.end()) - indeg.begin();
        vector<int> visited(n, 0), num(n);
        s.emplace(x);
        while(!s.empty()){
            int a = s.top(); s.pop();
            visited[a]++;
            num[a] = cnt++;
            if(!dp[a]) Q.emplace_front(a);
            for (auto &&i : G[a]) {
                if(!visited[i]) s.emplace(i);
            }
        }
        while(!Q.empty()){
            int i = Q.front(); Q.pop_front();
            if(S[i] < 0){
                int j = T[i];
                dp[i] = lcm(dp[j]*R[i], L[i])/L[i]+ lcm(dp[j]*R[i], L[i])/R[i];
            }else if(T[i] < 0){
                int j = S[i];
                dp[i] = lcm(dp[j]*L[i], R[i])/L[i]+ lcm(dp[j]*L[i], R[i])/R[i];
            }else {
                dp[i] = lcm(dp[S[i]]*L[i], dp[T[i]]*R[i])/L[i]+lcm(dp[S[i]]*L[i], dp[T[i]]*R[i])/R[i];
            }
        }
        cout << dp[x] << "\n";
    }

    return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	queue <long long> bfs;
	for (long long i=1;i<10;i++)
		bfs.push(i);
	while (!bfs.empty())
	{
		long long now=bfs.front();
		bfs.pop();
		a--;
		if (!a)
		{
			cout<<now<<endl;
			return 0;
		}
		if (now%10==9)
		{
			bfs.push(now*10+now%10-1);
			bfs.push(now*10+now%10);
		}
		else if (now%10==0)
		{
			
			bfs.push(now*10+now%10);
			bfs.push(now*10+now%10+1);
		}
		else
		{
			bfs.push(now*10+now%10-1);
			bfs.push(now*10+now%10);
			bfs.push(now*10+now%10+1);
		}
	}
	return 0;
}


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

int main() {
	int64_t x;
	cin >> x;
	int64_t year = 0;
	int64_t tmp = 100;
	while(1) {
		year++;
		tmp = tmp * 1.01;
		if(tmp >= x) {
			break;
		}
	}
	cout << year << endl;
}

Measured memory_bytes: 3636
# coding: utf-8
N,M=map(int,input().split())
H=list(map(int,input().split()))
G=[[] for i in range(N)]

for i in range(M):
    A,B=map(int,input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)

ans=0
for i in range(N):
    flg=True
    for j in range(len(G[i])):
        if H[i]<=H[G[i][j]]:
            flg=False
    
    if flg:
        ans+=1

print(ans)
 

Measured memory_bytes: 29384
#include <stdio.h>
#include <algorithm>
#include <vector>
int n,m,p[100003],y[100003];std::vector<int> a[100003];
main(){
    scanf("%d%d",&n,&m);for(int i=1;i<=m;i++) scanf("%d%d",&p[i],&y[i]),a[p[i]].push_back(y[i]);
    for(int i=1;i<=n;i++) std::sort(a[i].begin(),a[i].end());
    for(int i=1;i<=m;i++) printf("%012lld\n",p[i]*1000000ll+(std::lower_bound(a[p[i]].begin(),a[p[i]].end(),y[i])-a[p[i]].begin()+1));
    return 0;
}

Measured memory_bytes: 9332
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
static const int n=1000;

int lcs(string x,string y){
  int c[n+1][n+1];
  int m=x.size();
  int n=y.size();
  int maxl=0;
  x=' '+x;
  y=' '+y;
  for(int i=1;i<=m;i++)c[i][0]=0;
  for(int i=1;i<=n;i++)c[0][i]=0;

  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(x[i]==y[j]){
	c[i][j]=c[i-1][j-1]+1;
      }else {
	c[i][j]=max(c[i-1][j],c[i][j-1]);
      }
      maxl=max(maxl,c[i][j]);
    }
  }
  /*  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      cout<<c[i][j]<<" ";
    }
    cout<<endl;
    }///////////*/
  return c[m][n];
}

int main(){
  string s1,s2;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s1>>s2;
    cout<<lcs(s1,s2)<<endl;
  }
  return 0;
}

Measured memory_bytes: 5128
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,d;
  vector<int> c;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b;
    if(b==0) cin>>d,c.push_back(d);
    if(b==1) cin>>d,cout<<c[d]<<"\n";
    if(b==2) c.pop_back();
  }
}



Measured memory_bytes: 3932
N=int(input())
S=input()

x=0
l=[0]

for i in range(N):
    if S[i] is "I":
        x+=1
        l.append(x)
    if S[i] is 'D':
        x-=1
        l.append(x)
        
        
out=max(l)
print(out)
    

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
 
int main () {
  int n;cin>>n;
  int c =n%10;

  if(c ==3){
    cout<<"bon"<<endl;
  }else if(c==0 ||c ==1 ||c ==6 ||c ==8){
    cout<<"pon"<<endl;
  }else{
    cout<<"hon"<<endl;
  }
return 0;
}

Measured memory_bytes: 3636
package main

import (
	"fmt"
)

func main(){
	var a string
	fmt.Scan(&a)
	set := make(map[uint8]struct{})
	for i := 0; i< len(a); i++{
		set[a[i]] = struct{}{}
	}
	if len(set) == len(a){
		fmt.Println("yes")
	}else{
		fmt.Println("no")
	}
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer toks = new StringTokenizer(in.readLine());
		long a = Integer.parseInt(toks.nextToken());
		long b = Integer.parseInt(toks.nextToken());
		if(a<=0 && b>=0){
			System.out.println("Zero");
		}else if(a>0 && b>0){
			System.out.println("Positive");
		}else if(a<0 && b<0){
			if((Math.abs(b)-Math.abs(a))%2==0){
				System.out.println("Negative");
			}else{
				System.out.println("Positive");
			}
		}
//		out.println(res==0?"Zero":res>0?"Positive":"Negative");

		out.close();
	}
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b;
    cin>>a>>b;
    ll cnt=0;
    for(ll i=a;i<=b;i++)
    {
        ll aa=i/10000;
        ll bb=(i/1000)%10;
        //ll cc=(i/100)%10;
        ll cc=(i/10)%10;
        ll dd=i%10;
        if(aa==dd && bb==cc)
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;



}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define NIL -1
typedef long long ll;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


mint f(int n) {
    if (n==0) return 1;
    mint x = f(n/2);
    x *= x;
    if(n%2 == 1) x *= 2;
    return x;
}

mint choose(int n, int a) {
    mint x = 1, y = 1;
    rep(i,a) {
        x *= n-i;
        y *= i+1;
    }
    return x / y;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    mint ans = f(n);
    ans -= 1;
    ans -= choose(n,a);
    ans -= choose(n,b);
    cout << ans.x << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	double x1,y1,x2,y2;
	scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
	
	double dx=x2-x1;
	double dy=y2-y1;
	double a=dx*dx+dy*dy;
	
	printf("%f\n",sqrt(a));
	return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>

using namespace std;

typedef tuple<int, int, int> T;
typedef pair<long, T> P;

set<T> s;

int main(){
    int X, Y, Z, K;
    long A[100000], B[100000], C[100000];
    cin >> X >> Y >> Z >> K;
    for(int i = 0; i < X; i++){
        cin >> A[i];
    }
    for(int i = 0; i < Y; i++){
        cin >> B[i];
    }
    for(int i = 0; i < Z; i++){
        cin >> C[i];
    }
    sort(A, A+X, greater<long>());
    sort(B, B+X, greater<long>());
    sort(C, C+Z, greater<long>());
    
    int cnt = 1;
    priority_queue<P> que;
    que.push(P(A[0]+B[0]+C[0], T(0, 0, 0)));
    s.insert(T(0, 0, 0));
    while(cnt <= K){
        P top = que.top();
        que.pop();
        cout << top.first << endl;
        cnt++;
        //cout << 'H' << endl;
        T t = top.second;
        long a = get<0>(t);
        long b = get<1>(t);
        long c = get<2>(t);
        //cout << a << ' ' << b << ' ' << c << endl;
        if(a+1 < X && s.count(T(a+1, b, c)) == 0){
            long tmp = A[a+1]+B[b]+C[c];
            que.push(P(tmp, T(a+1, b, c)));
            s.insert(T(a+1, b, c));
        }
        if(b+1 < Y && s.count(T(a, b+1, c)) == 0){
            long tmp = A[a]+B[b+1]+C[c];
            que.push(P(tmp, T(a, b+1, c)));
            s.insert(T(a, b+1, c));
        }
        if(c+1 < Z && s.count(T(a, b, c+1)) == 0){
            long tmp = A[a]+B[b]+C[c+1];
            que.push(P(tmp, T(a, b, c+1)));
            s.insert(T(a, b, c+1));
        }
    }
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long  ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n; cin >> n;
    vl a(n);
    rep(i,n)cin>>a[i];
    rep(i,n)if(a[i] % 2){
        out("first");
        return 0;
    }
    out("second");
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC003WannaGoBackHome
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();

            bool n = false;
            bool w = false;
            bool s = false;
            bool e = false;

            foreach(var c in S)
            {
                switch(c)
                {
                    case 'N':
                        n = true;
                        break;
                    case 'W':
                        w = true;
                        break;
                    case 'S':
                        s = true;
                        break;
                    case 'E':
                        e = true;
                        break;
                }
            }

            if(!n && s)
            {
                Console.WriteLine("No");
                return;
            }
            if(n&&!s)
            {
                Console.WriteLine("No");
                return;
            }
            if(!w && e)
            {
                Console.WriteLine("No");
                return;
            }
            if (w && !e)
            {
                Console.WriteLine("No");
                return;
            }
            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13140
N = int(input())

a = list(map(int, input().split()))

sum_alice = 0
sum_bob = 0
a = sorted(a, reverse=True)

for i in range(len(a)):
    if i % 2 == 0:
        sum_alice += a[i]
    else:
        sum_bob += a[i]

print(sum_alice - sum_bob)


Measured memory_bytes: 3060
N, W = list(map(int, input().split()))
vw = []
dp = [[0 for j in range(W+1)] for i in range(N+1)]

for i in range(N):
    vw_i = list(map(int, input().split()))
    vw.append((vw_i[0], vw_i[1]))

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

print(dp[N][W])



Measured memory_bytes: 42472
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 30
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int MOD = 1000000007;

int H,W,len;
char mp[50][50];
int dist[50][50];

int main(){
    std::ios_base::sync_with_stdio(false);

    cin >> H >> W;
    int white_cnt = 0;

    REP(i,H){
        REP(j,W){
            char c; cin >> c;
            mp[i][j] = c;
            if(c=='.'){
                white_cnt++;
            }
            dist[i][j] = -1;
        }
    }

    len = -1;

    typedef pair<int, int> P;
    queue<P> q;

    q.push(P(0, 0));


    while(!q.empty()){
        P p = q.front(); q.pop();
        int x=p.first; int y=p.second;
        for(int k=0; k<4; ++k){
            int ny=y+dy[k]; int nx=x+dx[k];
            if(ny<0||ny>=H||nx<0||nx>=W) continue;
            if(mp[ny][nx] =='#' || dist[ny][nx] != -1) continue;
            dist[ny][nx] = dist[y][x]+1;
            q.push(P(nx,ny));
        }
    }

    if(dist[H-1][W-1]==-1){
        cout << -1 << endl;
    } else {
        cout << white_cnt-dist[H-1][W-1]-2 << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  string s;
  cin >> s;
  ll k=s.size();
  vvl dp(k+1,vl(13));
  dp[0][0]=1;
  rep(i,12){
    dp[0][i+1]=0;
  }
  ll a=1;
  rep(i,k){
    rep(j,13){
      if(s[k-i-1]=='?'){
        rep(l,10){
          dp[i+1][(j+a*l)%13]+=dp[i][j];
          dp[i+1][(j+a*l)%13]%=MOD;
        }
      }
      else{
        ll x=a*(s[k-i-1]-'0')%13;
        dp[i+1][(j+x)%13]+=dp[i][j];
        dp[i+1][(j+x)%13]%=MOD;
      }
    }
    a*=10;
    a%=13;
  }
  cout << dp[k][5] << endl;
}

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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

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

inline int read() {
    int x(0), sgn(1); char ch(getchar());
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("C.in", "r", stdin);
	freopen ("C.out", "w", stdout);
#endif
}

const int N = 1e5 + 1e3;

string str;

int main () {

	File();

	cin >> str;
	
	puts(regex_match(str, regex("^(dream|dreamer|erase|eraser)*$")) ? "YES" : "NO");

	return 0;

}


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

void _126() {
    string s;
    cin >> s;
    int first = atoi(s.substr(0, 2).c_str());
    int second = atoi(s.substr(2, 2).c_str());

    if (first > 0 && first <= 12 && second > 0 && second <= 12)
        cout << "AMBIGUOUS" << endl;
    else if (first > 0 && first <= 12)
        cout << "MMYY" << endl;
    else if (second > 0 && second <= 12)
        cout << "YYMM" << endl;
    else
        cout << "NA" << endl;
}

void _127() {
    int r, d, x;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; ++i) {
        x = r * x - d;
        cout << x << endl;
    }
}

int main()
{
    _127();
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, ans=0, tmp=0;
    cin >> N;	
    vector<int> h(N);
    for(int i=0; i<N; i++){
	cin >> h[i];
    }

    for(int i=0; i<N-1; i++){

	if(h[i] >=h[i+1])
	    tmp++;
	else{
	    tmp=0;
	}
	ans = max(ans, tmp);
    }
    cout << ans << endl;

}



Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int[] c = new int[n];
        int[][] a = new int[n][m];
        for(int i = 0; i < n; i++){
            c[i] = Integer.parseInt(sc.next());
            for(int j = 0; j < m; j++){
                a[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < 1<<n; i++){
            int[] b = new int[m];
            int cost = 0;
            for(int j = 0; j < n; j++){
                if((i>>j & 1) != 0){
                    for(int k = 0; k < m; k++){
                        b[k] += a[j][k];
                    }
                    cost += c[j];
                }
            }
            boolean flag = true;
            for(int j = 0; j < m; j++){
                if(b[j] < x) flag = false;
            }
            if(flag){
                min = Math.min(cost, min);
            }
        }
        if(min != Integer.MAX_VALUE){
            System.out.println(min);
        }else{
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 37088
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int V = sc.nextInt();
        int E = sc.nextInt();
        int[][] g = new int[V][V];
        for (int i = 0; i < E; i++) {
            int u = sc.nextInt();
            int v = sc.nextInt();
            int c = sc.nextInt();
            g[u][v] = c;
        }
        MaxFlow mf = new MaxFlow(g);
        System.out.println(mf.calc(0, V - 1));
    }

    static class MaxFlow {

        int[][] g;
        int[][] res;

        MaxFlow(int[][] g) {
            this.g = g;
            this.res = new int[g.length][];
            for (int i = 0; i < g.length; ++i) {
                this.res[i] = g[i].clone();
            }
        }

        int calc(int src, int sink) {
            int result = 0;
            int[] prev = new int[g.length];
            while (true) {
                Arrays.fill(prev, -1);
                boolean[] visited = new boolean[g.length];
                Queue<Integer> q = new LinkedList<>();
                q.add(src);
                visited[src] = true;
                OUT: while (!q.isEmpty()) {
                    int cur = q.poll();
                    for (int i = 0; i < g.length; ++i) {
                        if (!visited[i] && res[cur][i] > 0) {
                            prev[i] = cur;
                            visited[i] = true;
                            if (i == sink) {
                                break OUT;
                            }
                            q.add(i);
                        }
                    }
                }
                if (!visited[sink]) {
                    break;
                }
                int pos = sink;
                int pathCap = Integer.MAX_VALUE;
                while (pos != src) {
                    int p = prev[pos];
                    pathCap = Math.min(pathCap, res[p][pos]);
                    pos = p;
                }
                pos = sink;
                while (pos != src) {
                    int p = prev[pos];
                    res[p][pos] -= pathCap;
                    res[pos][p] += pathCap;
                    pos = p;
                }
                result += pathCap;
            }
            return result;
        }
    }
}



Measured memory_bytes: 34776
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long 
#define trace(x) cerr<<#x<<" : "<<x<<endl;

int main() 
{ 
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL); 
ll n; 
cin>>n; 
ll a[n+1],c[n+1]={0}; 
for (int i = 1; i<=n; ++i)
{
    cin>>a[i];
}
c[1]=0; 
c[2]=abs(a[2]-a[1]); 
for (int i = 3; i<=n; ++i)
{
    c[i]=min((c[i-1]+(abs(a[i]-a[i-1]))),(c[i-2]+abs(a[i]-a[i-2])));
}
cout<<c[n];
return 0;
}

Measured memory_bytes: 1792
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(i):
    print(i,flush=True)
    s = ins()
    a[i] = h[s]
    if h[s]==1:
        exit()

h = {'Vacant':1, 'Male':2, 'Female':3}
n = inn()
a = [0]*(n+1)
foo(0)
a[n] = a[0]
p = 0
q = n
cnt = 1
while q>p+1:
    r = (p+q)//2
    foo(r)
    cnt += 1
    if cnt >= 20:
        exit()
    if a[r]==a[p] and (r-p)%2==1 or a[r]!=a[p] and (r-p)%2==0:
        q = r
    else:
        p = r
        #ddprint(a)
    #ddprint(f"p {p} q {q}")
print("err")


Measured memory_bytes: 4424
class ABC140C:

    def __init__(self):
        self.nNum = int(input())
        self.bList = list(map(int, input().split()))

    def solve(self):
        aList = [0] * self.nNum
        aList[0] = self.bList[0]
        for i in range(self.nNum - 1):
            if self.bList[i] < aList[i]:
                aList[i] = self.bList[i]
            aList[i + 1] = self.bList[i]

        print(sum(aList))


if __name__ == '__main__':
    ABC140C().solve()


Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<vector<int>> vec(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> vec.at(i).at(j);
        }
    }
    
    int N;
    cin >> N;
    
    vector<int> num(N);
    for (int i = 0; i < N; i++) {
        cin >> num.at(i);
    }

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < N; k++) {
                if ( vec.at(i).at(j) == num.at(k) ) {
                    vec.at(i).at(j) = 0;
                }    
            }
        }
    }

    // cout << vec.at(0).at(0) << endl;
    // cout << vec.at(0).at(1) << endl;
    // cout << vec.at(0).at(2) << endl;

    bool ans = false;

    if( vec.at(0).at(0) == 0 && vec.at(0).at(1) == 0 && vec.at(0).at(2) == 0 ) {
        ans = true;
    }

    if( vec.at(1).at(0) == 0 && vec.at(1).at(1) == 0 && vec.at(1).at(2) == 0 ) {
        ans = true;
    }

    if( vec.at(2).at(0) == 0 && vec.at(2).at(1) == 0 && vec.at(2).at(2) == 0 ) {
        ans = true;
    }

    

    if( vec.at(0).at(0) == 0 && vec.at(1).at(0) == 0 && vec.at(2).at(0) == 0 ) {
        ans = true;
    }

    if( vec.at(0).at(1) == 0 && vec.at(1).at(1) == 0 && vec.at(2).at(1) == 0 ) {
        ans = true;
    }

    if( vec.at(0).at(2) == 0 && vec.at(1).at(2) == 0 && vec.at(2).at(2) == 0 ) {
        ans = true;
    }

    
    if( vec.at(0).at(0) == 0 && vec.at(1).at(1) == 0 && vec.at(2).at(2) == 0 ) {
        ans = true;
    }

    if( vec.at(0).at(2) == 0 && vec.at(1).at(1) == 0 && vec.at(2).at(0) == 0 ) {
        ans = true;
    }

    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
use std::io;

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split(' ')
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

fn main() {
    let (n, _l) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    let mut vec = Vec::new();

    for _ in 0..n {
        vec.push(read_one::<String>());
    }

    vec.sort();
    let ans = vec.into_iter()
        .fold(String::from(""), |a, b| a + &b);

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

Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int Array[100001];
int numnum[100002];

signed main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> Array[i];
	}
	for (int i = 0; i < N; i++) {
		numnum[Array[i]]++;
	}

	int ans = 0;
	int evenCou = 0;
	for (int i = 1; i <= 100000; i++) {
		if (numnum[i] >= 3 && numnum[i] % 2 == 1) {
			//奇数だったらnumnum[i]/2回操作しておわり
			ans += (numnum[i] / 2);
		}
		else if(numnum[i]>=2){
			//偶数だったらnumnum[i]/2-1回の操作は確定、ラスト1回はもう一つの2個の解消と同時にできる
			ans += numnum[i] / 2 - 1;
			evenCou++;
		}
	}
	if (evenCou % 2 == 0) {
		ans += evenCou / 2;
	}
	else {
		ans += evenCou / 2 + 1;
	}
	cout << N-ans*2 << "\n";

	return 0;
}

Measured memory_bytes: 1792
// 1~Nについてループ.
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,k; cin >> n >> k;
  double P=0.0;
  for(int i=1;i<=n;++i){
    int c = i;
    double p=1.0/n; // 少なくとも片方は浮動小数点にすること
    while(c<=k-1){
      c = c*2;
      p = p/2.0;
    }
    P += p;
  }
  printf("%.20f",P);
  return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;



int main() {

    int num;
    cin>>num;

    if(num == 1){
        cout<<0<<endl;
        return 0;
    }

    vector<int> res(num);

    for(auto& v : res)
        cin>>v;

    sort(res.begin(), res.end());

    int mi = *min_element(res.begin(), res.end());
    int ma = *max_element(res.begin(),res.end());
    if(mi == ma){
        cout<<0<<endl;
        return 0;
    }

    cout<<res.back()-res[0]<<endl;


    return 0;
}


Measured memory_bytes: 256
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def message_queue():
        # write your code here
        # tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
        task_num, task_time = map(int, input().split())
        _input = sys.stdin.readlines()
        
        task_deque = deque(map(lambda x: dict(name=x.split()[0], time=int(x.split()[-1])), _input))
        total_time = 0

        while task_deque:
            item = task_deque.popleft()
            if item['time'] <= task_time:
                total_time += item['time']
                print(item['name'], total_time)
            else:
                item['time'] -= task_time
                total_time += task_time
                task_deque.append(item)


if __name__ == '__main__':
    solution = Solution()
    solution.message_queue()

Measured memory_bytes: 29924
N, M = map(int, input().split())
AB = []

for i in range(N):
    AB.append(list(map(int, input().split())))
AB = sorted(AB, reverse=False)

num = 0
ans = 0
for i in AB:
    if num+i[1] < M:
        num += i[1]
        ans += i[0]*i[1]
    else:
        ans = ans + (M-num)*i[0]
        print(ans)
        break


Measured memory_bytes: 28656
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int n, D, cnt = 0;
    cin>>n>>D;
    for(int i = 0; i < n; i++){
        int x, y;
        cin>>x>>y;
        int d = ceil((ld)sqrt(x*x+y*y));
        if(d<=D)cnt++;
    }   
    cout<<cnt;
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3640
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

int H, W, m[55][55], dx[] = {1,1,0,-1,-1,-1,0,1}, dy[] = {0,1,1,1,0,-1,-1,-1};
bool flag[55][55];

void dfs(int y, int x) {
	for (int k = 0; k < 8; k++) {
		int nx = x + dx[k] , ny = y + dy[k];
		if (0<=ny && ny<H && 0<=nx && nx<W) {
			if (flag[ny][nx] && m[ny][nx]==1) {
				flag[ny][nx] = false;
				dfs(ny, nx);
			}
		}
	}
}

int main() {
	
	while (1) {

		cin >> W >> H;
		if (W==0 && H==0) break;
	
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> m[i][j];
				flag[i][j] = true;
			}
		}

		int cnt = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (m[i][j] == 1 && flag[i][j]) cnt++;
				flag[i][j] = false;
				if(m[i][j]==1) dfs(i, j);
			}
		}

		cout << cnt<<endl;

	}
	return 0;
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
int main()
{	
	int n;
	cin>>n;
	long long a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	int flag=0;
	for(int i=0;i<n-1;i++)
		if(a[i]==a[i+1])
			{flag=1;break;}
	if(!flag)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

Measured memory_bytes: 1792
from collections import Counter
from operator import mul
from functools import reduce


def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


N = int(input())
lst_s = ["".join(sorted(input())) for _ in range(N)]

cnt_s = Counter(lst_s)

ans = 0
for v in cnt_s.values():
    if v == 1:
        continue
    else:
        ans += cmb(v, 2)
print(ans)


Measured memory_bytes: 20028
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N;
    cin >> N;
    VL a(N);
    REP(i, N) cin >> a[i];
    SORT(a);
    deque<LL> dq;
    FOR(i, 1, N) dq.emplace_back(a[i]);
    LL left = a[0], right = a[0];
    bool f = false;
    LL ans = 0;
    REP(i, N - 1) {
        LL left_val = dq.front();
        LL right_val = dq.back();
        LL left_lval = llabs(left - left_val);
        LL left_rval = llabs(right - left_val);
        LL right_lval = llabs(left - right_val);
        LL right_rval = llabs(right - right_val);
        if (max(left_lval, left_rval) < max(right_lval, right_rval)) {
            dq.pop_back();
            if (right_lval < right_rval) {
                ans += right_rval;
                right = right_val;
            } else {
                ans += right_lval;
                left = right_val;
            }
        } else {
            dq.pop_front();
            if (left_lval < left_rval) {
                ans += left_rval;
                right = left_val;
            } else {
                ans += left_lval;
                left = left_val;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
import Control.Applicative
import Control.Monad

main = do
    n <- readLn
    input <- replicateM n $ (\(a:b:_) -> (a,b) ) . map read . words <$> getLine
    print $ (\(a,b) -> a + b) $ foldl1 solve input where
        solve :: (Int, Int) -> (Int, Int) -> (Int, Int)
        solve (a,b) (c,d) = let
            latio = (1+) $ max ((a-1) `div` c) ((b-1) `div` d)
            in (latio * c, latio * d)


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

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


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

using namespace std;

int main(void)
{
    string S;
    int i, n, judge=1;

    cin >> S;

    n = S.size();

    for(i=0; i<n; i++){
        if(i%2==0){ //奇数番目
            if(S[i]!='R' && S[i]!='U' && S[i]!='D'){
                judge = 0;
            }
        }

        else{
            if(S[i]!='L' && S[i]!='U' && S[i]!='D'){
                judge = 0;
            }
        }
    }

    if(judge == 1){
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#define ll long long
using namespace std;
const ll N = 1e6 + 5;
int main(){
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	ll ans = 0;
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; j++){
			for(int k = 0; k <= c; k++){
				ll yy = 500LL * i + 100LL * j + 50LL * k;
				if(yy == x){
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int v, e;
vector<pair<int, int> > adj[110], revadj[110];
int capacity[1010], cost[1010], flowingthrough[1010], dis[110], pre[110], preedge[110], endofedge[1010];
void bellmanford()
{
	fill_n(dis, v, 1e9);
	dis[0] = 0;
	for (int f = 0; f < v; f++)
	{
		for (int i = 0; i < v; i++)
		{
			for (auto e : adj[i])
			{
				if (flowingthrough[e.second] != capacity[e.second])
				{
					if (dis[e.first] > dis[i] + cost[e.second])
					{
						dis[e.first] = dis[i] + cost[e.second];
						pre[e.first] = i;
						preedge[e.first] = e.second;
					}
				}
			}
			for (auto e : revadj[i])
			{
				if (flowingthrough[e.second])
				{
					if (dis[e.first] > dis[i] - cost[e.second])
					{
						dis[e.first] = dis[i] - cost[e.second];
						pre[e.first] = i;
						preedge[e.first] = e.second;
					}
				}
			}
		}
	}
}
pair<int, int> mincostmaxflow()
{
	int ans = 0;
	int totalcost = 0;
	while (1)
	{
		bellmanford();
		if (dis[v-1] == 1e9) break;
		ans++;
		// Augment path
		int a = v-1;
		while (a)
		{
		//	printf("%d ", a);
			int e = preedge[a];
			if (endofedge[e] == a) flowingthrough[e]++, totalcost += cost[e];
			else flowingthrough[e]--, totalcost -= cost[e];
			a = pre[a];
		}
		//printf("%d\n", a);
	}
	return { ans, totalcost };
}
int f;
int main()
{
	scanf("%d%d%d", &v, &e, &f);
	for (int i = 0; i < e; i++)
	{
		int a, b;
		scanf("%d%d%d%d", &a, &b, &capacity[i], &cost[i]);
		assert(a != b);
		endofedge[i] = b;
		adj[a].emplace_back(b, i);
		revadj[b].emplace_back(a, i);
	}
	adj[v-1].emplace_back(v, e);
	cost[e] = 0;
	endofedge[e] = v;
	capacity[e] = f;
	v++;
	auto ans = mincostmaxflow();
//	printf("%d %d\n", ans.first, ans.second);
	if (ans.first != f) printf("-1\n");
	else printf("%d\n", ans.second);
}


Measured memory_bytes: 3224
/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>

typedef long long ll ;

#define pll pair<ll , ll >
#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back

using namespace std;
const int maxn = 1000*100+5 ;
const ll inf = 9223372036854775807 ;


int main()
{
	migmig ;
	int a  , b ; 
	cin>>a >> b ; 
	cout<<max(a-b , max(a+b , a*b)) ; 
}
//////
////////
///////////




Measured memory_bytes: 256
k,a,b = map(int,input().split())

ans=1
cnt=0
if a>=b-1:
    print(ans+k)
    exit(0)

cnt += (a-ans)
ans += (a-ans)


#まとめてa枚をb枚に交換
n = (k-cnt)//2
ans-= a * n
ans+= b * n
cnt+= 2 * n

#残り回数でビスケットをわる
ans += k-cnt

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>

using namespace std;
int N;
int h[110];
void dfs(int left, int right) {
    int cnt=0;
    while(true){
        cnt++;
        for(int i=left;i<right;i++){
            cout<<"cnt="<<cnt<<endl;
            if(h[i]>0){
                h[i]--;
            }else{
                dfs(0, i-1);
                dfs(i+1, N);
            }
            printf("h[%d]=%d\n",i,h[i]);
        }
        //ans++;
        bool ok=true;
        for(int i = 0; i < N; i++) {
            //printf("h[%d]=%d\n",i,h[i]);
            if(h[i]>0)ok=false;
        }
        if(ok)break;
        //cout<<"cnt="<<cnt<<endl;
    }
}
int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    int ans=0, active=0;
    for(int i = 0; i < N; i++) {
        if(active >= h[i]){
            active = h[i];
        } else {
            ans += h[i]-active;
            active = h[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
fun main(arg: Array<String>) {

    val n = readLine()!!.toInt()

    val p = Array(n) { i ->
        readLine()!!.split(" ").map { it.toInt() }.let { intArrayOf(i, it[0], it[1]) }
    }

    val edge = ArrayList<IntArray>()

    p.sortBy { it[1] }
    for (i in 0..n - 2) {
        val d = Math.abs(p[i][1] - p[i + 1][1])
        edge.add(intArrayOf(p[i][0], p[i + 1][0], d))
    }

    p.sortBy { it[2] }
    for (i in 0..n - 2) {
        val d = Math.abs(p[i][2] - p[i + 1][2])
        edge.add(intArrayOf(p[i][0], p[i + 1][0], d))
    }

    edge.sortBy { it[2] }

    val uf = UnionFind(n)
    var ret = 0L

    edge.forEach {
        if (!uf.same(it[0], it[1])) {
            uf.union(it[0], it[1])
            ret += it[2]
        }
    }
    println(ret)
}

class UnionFind(size: Int) {
    val par = IntArray(size) { -1 }

    fun same(x: Int, y: Int) = root(x) == root(y)

    fun union(x: Int, y: Int) {
        val rx = root(x)
        val ry = root(y)
        if (rx == ry) return
        par[rx] += par[ry]
        par[ry] = x
    }

    fun root(x: Int): Int {
        if (par[x] < 0) return x
        par[x] = root(par[x])
        return par[x]
    }
}


Measured memory_bytes: 78804
def pows(a, n, mod):
    # [a**0, a**1, ..., a**n] % mod
    ret = [1] * (n + 1)
    for i in range(1, n + 1):
        ret[i] = ret[i - 1] * a % mod
    return ret


def ext_euc(a, b):
    if b == 0:
        return 1, 0, a
    y, x, v = ext_euc(b, a % b)
    y -= (a // b) * x
    return x, y, v


def mod_inv(a, mod):
    x, _, _ = ext_euc(a, mod)
    return x % mod


def main():
    MOD = 10**9 + 7
    K = int(input())
    S = input()
    N = len(S)
    ans = 0
    pw25 = pows(25, K, MOD)
    pw26 = pows(26, K, MOD)
    comb = 1  # (k+N-1)_C_k
    for k in range(K + 1):
        ans += pw25[k] * comb * pw26[K - k]
        ans %= MOD
        comb *= k + N
        comb *= mod_inv(k + 1, MOD)
        comb %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 92388
#include<iostream>

using namespace std;

int main()
{
  int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int k;
  cin >> k;
  
  cout << a[k-1] <<endl;
  
  return 0;
}

Measured memory_bytes: 888