akhauriyash/Code-Regression huggingface dataset:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    kabu = 0
    money = 1000
    for i in range(N-1):
        if A[i] < A[i+1]:
            kabu += money//A[i]
            money -= A[i]*(money//A[i])
        elif A[i] > A[i+1]:
            money += kabu*A[i]
            kabu = 0
    if kabu != 0:
        money += kabu*A[-1]
    print(money)
resolve()

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

int main(){
    int n,a[100002];
    cin >> n;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }
    int sum=1;
    for(int j=1;j<=n;j++){
        sum = a[sum];
        if(sum ==2){
            cout << j << endl;
            return 0;
        }
        
    }
    cout  << "-1" << endl;
    return 0;
    
}


Measured memory_bytes: 640
N, M = map(int, input().split())
H = list(map(int, input().split()))
groups = [[] for _ in range(N)]
for i in range(N):
    groups[i].append(H[i])

for _ in range(M):
    a, b = map(int, input().split())
    groups[a - 1].append(H[b - 1])
    groups[b - 1].append(H[a - 1])

ans = 0
for i in range(N):
    g = groups[i]
    g.sort(reverse=True)
    if len(g) == 1:
        ans += 1
        continue
    if g[0] != g[1] and g[0] == H[i]:
        ans += 1
print(ans)



Measured memory_bytes: 94396
import Data.List

main = do
  input <- group . sort . map (rate . (read :: String -> Int)) . words . last . lines <$> getContents
  let isFree = (head . last $ input) == 8
      rank = if isFree
                then (flip (-) 1) . length $ input
                else length input
      free = if isFree
                then length . last $ input
                else 0
  putStr . (++" ") . show $ if rank > 0
                               then rank
                               else 1
  putStrLn . show $ if isFree
                       then rank + free
                       else rank

rate :: Int -> Int
rate x
  | x < 3200  = div x 400
  | otherwise = 8


Measured memory_bytes: 1020
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
ll INF = 9999999999999999;

int N;
ll h[100010];
ll dp[100010];

ll rec(int i){
    
    if(dp[i] < INF) return dp[i];
    
    if(i == 0) return 0;
    
    ll res = INF;
    res = min(res, rec(i-1) + abs(h[i] - h[i-1]));
    if (i > 1) res = min(res, rec(i-2) + abs(h[i] - h[i-2]));
    
    return dp[i] = res;
}

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;
}
ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}
 
int main(void){
    int N,K; cin >> N >> K;
    vector<int> h(N+1000, 0); for(int i = 0; i < N; i++) cin >> h[i];
    vector<int> dp(N+1000,INF);
    
    dp[0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 1; j <= K; j++){
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
        }
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;
 
ll N, M;
vector<ll> v;
 
ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    return gcd(b, a%b);
}
 
 
int main() {
    cin >> N >> M;
    for (ll i = 0; i < N; ++i) {
        ll a; cin >> a; v.push_back(a>>1);
        if (a&1LL) { cout << "0" << endl; return 0; }
    }
    ll lcm = v[0];
    for (int i = 1; i < N; ++i) {
        lcm = (lcm * v[i]) / gcd(lcm, v[i]);
        if (lcm > M) { cout << "0" << endl; return 0; }
    }
  	for (num : v) {
      if (((lcm/num)&1) == 0) { cout << 0 << endl; return 0; }
    }
 
    ll ans = 0;
    for (ll i = lcm; i <= M; i += (lcm<<1)) ++ans;
 
    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll N; cin >> N;
    map<ll, ll> input_numbers;
    vector<ll> v(N);
    for (int i = 0; i < N; ++i) {
        cin >> v[i];
        if (!input_numbers.count(v[i])) {
            input_numbers[v[i]] = 0;
        }
        input_numbers[v[i]]++;
    }
    map<ll, ll> already_seen;
    sort(v.begin(), v.end());

    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ll num = v[i];
        // cout << "looking at " << num << endl;
        // for (auto j : already_seen) {
        //     cout << j.first << " ";
        // }
        // cout << endl;
        bool ok = true;
        // 重複があればダメ
        if (input_numbers[num] > 1) ok = false;
        // 約数がすでに出現していない
        else {
            for (ll j = 1; j * j <= num; j++) {
                if (num % j == 0) {
                    // cout << "約数 " << j << endl;
                    if (already_seen.count(j) || already_seen.count(num / j)) {
                        ok = false;
                        break;
                    }
                }
            }
        }

        if (ok) ans++;
        already_seen[num] = 1;
        // cout << ok << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 29840
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <map>
#include <set>
#define LL long long
#define mp make_pair

using namespace std;

const int maxn=200010;
const int oo=1000000000;
const int modulo=961748941;

string s;
int n;
int cnt[26];

void input(){
	cin >> s;
	n = s.size();
}	

void init(){
}

void solve(){
	LL best = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 26; j++)
			if (s[i] - 'a' != j) best += cnt[j];
		cnt[s[i] - 'a']++;	
	}
	cout << best + 1;
}

void output(){
//	cout << gethr(1, 2) << ' ' << gethl(1, 2);
}

int main(){
// 	freopen("test.inp", "r", stdin);
//	freopen("test.out", "w", stdout);
	std::ios::sync_with_stdio(false);
	input();
	init();
	solve();
	output();

	return(0);
}


Measured memory_bytes: 720
import java.util.*;
public class Main{


	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);

		long s  =sc.nextLong();
		long w  =sc.nextLong();
		long c  =sc.nextLong();
		long d  =sc.nextLong();
	  int i  =-1; 
		while(true) {
i++;
			if(i%2==0) {
				c-=w;
				if(c<=0) {
					System.out.println(" Yes");
break;
				}
				
			}else {
				s-=d;
				if(s<=0) {
				System.out.println("No");
				break;}
			}
			
		
		}
	}

}


Measured memory_bytes: 35676
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <bitset>

using namespace std;
using BIT = bitset<30>;

const int max_time = 1e5;

int main() {
	int N, C;
	cin >> N >> C;

	vector<BIT> records(max_time + 1, 0);

	int s, t, c;
	for (int i = 0; i < N; i++) {
		cin >> s >> t >> c;
		for (int i = s; i <= t; i++) {
			records[i].set(c - 1);
		}
	}

	int ans = 0;
	for (int i = 0; i <= max_time; i++) {
		int x = records[i].count();
		ans = max(ans, x);
	}

	cout << ans << endl;

	// for (int i = 0; i <= 100; i++) {
	// 	printf("%3d: %s %2d\n", i, records[i].to_string().substr(25).c_str(), (int)records[i].count());
	// }
	return 0;
}


Measured memory_bytes: 1024
n=int(input())
l=list(map(int,input().split()))
fin=True
if n>1 and l[0] == l[1]:l[0] += -1
for i in range(1,n):
  if n==1:break
  prev=l[i-1]
  now=l[i]
  if i == n-1:
    if prev>now:
      fin=False
    break
  else:
    next_=l[i+1]
  if prev < now and now >= next_:
    l[i] += -1
  elif prev>now:
    fin=False
    break
if fin==True:print("Yes")
else:print("No")

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ll long long
using namespace std;
const int nmax=201234;

int n,nw,nw2,nx=1,nx2=1;
ll k,res,a[2][51][51],b[2][51];

void ksm(ll k)
{
    ll c;
    while(k)
    {
        if(k&1)
        {
            for(int i=1; i<=n; ++i)
            {
                    c=0;
                    for(int k=1; k<=n; ++k)
                    {
                        c+=b[nw2][k]*a[nx][k][i];
                        c%=MOD;
                    }
                    b[nx2][i]=c;
            }
            swap(nw2,nx2);
        }
        k>>=1;
        swap(nw,nx);
        for(int i=1; i<=n; ++i)
        {
            for(int j=1; j<=n; ++j)
            {
                c=0;
                for(int k=1; k<=n; ++k)
                {
                    c+=a[nw][i][k]*a[nw][k][j];
                    c%=MOD;
                }
                a[nx][i][j]=c;
            }
        }
    }
}

int main()
{
    scanf("%d %lld",&n,&k);
    for(int i=1; i<=n; ++i)
    {
        for(int j=1; j<=n; ++j)
            scanf("%lld",&a[nx][i][j]);
        b[nw2][i]=1;
    }
    ksm(k);
    for(int i=1; i<=n; ++i)
            res=(res+b[nw2][i])%MOD;
    printf("%lld",res);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int n;
    cin >> n ;
    char a[n][110];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(strcmp(a[i],a[j])==0){
                cout << "No";
                return 0;
            }
        }
    }
    int sasa;
    for(int i=0;i<n-1;i++){
        for(int j=0;a[i][j]!=0;j++){
            sasa=j;
        }
        if(a[i][sasa]!=a[i+1][0]){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

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


  int main() {
  string x,y,z; //大会名。xはAtCoder、zはContestで固定
  cin >>x >>y >>z; //入力受付
  char a,b,c ; //一文字目

  a=x.at(0);
  b=y.at(0);
  c=z.at(0);

cout <<a <<b <<c <<endl;


}


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

typedef long long int ll;

int main()
{
    ll n;
    string s;
    cin >> n >> s;

    ll ans = 0;
    for(ll i = 0;i < n - 1;i++){
        if(s[i] != s[i + 1]){
            ans++;
        }
    }

    ans++;

    cout << ans;

    return 0;
}

Measured memory_bytes: 512
import scala.io.Source

object Main extends App {
  var set = (1 to 10000).filter(x => isPrimeNumber(x)).toSet
  val in = Source.stdin.getLines
  for (line <- in) {
    val n = line.toInt
    val count = (1 to n)
      .filter(x => set.contains(x))
      .filter(x => set.contains(n + 1 - x))
      .size

    println(count)
  }

  def isPrimeNumber(value: Int): Boolean = {
    if (value < 2) false
    else if (value == 2) true
    else if (value % 2 == 0) false
    else {
      val sqrt = Math.sqrt(value).toInt
      for (i <- 3 to sqrt by 2) {
        if (value % i == 0) {
          return false
        }
      }

      true
    }
  }
}



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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {
		var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long S = inputArray[0];
			long W = inputArray[1];


			//答えの出力
			var ans = W >= S ? "unsafe":"safe";
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 28088
import math
N = int(input())
L=list(map(int,input().split()))

s=sum(L)

s1=s//len(L)
s2=math.ceil(s/len(L))

a=0
b=0
for i in L:
    a+=(s1-i)**2
    b+=(s2-i)**2

print(min(a,b))

Measured memory_bytes: 3064
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] dp = new long[N+1];
		int[] last = new int[200001];
		dp[0] = 1;
		for(int i = 1; i <= N; i++) {
			int c = sc.nextInt();
			dp[i] = dp[i-1];
			if(last[c] != 0 && last[c] < i - 1)
				dp[i] += dp[last[c]];
			last[c] = i;
			dp[i] %= 1_000_000_007;
		}
		System.out.println(dp[N]);
	}

}

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

bool compare_by_greater_y(pair<ll,ll>a, pair<ll,ll>b){
    if(a.second!=b.second) return a.second>b.second;
    else return a.first>b.first;
}

int main(){
  int n,m;cin>>n>>m;
  vector<ll> a(n,0);
  vector<pair<ll,ll>> p(m);
  REP(i,n) cin>>a.at(i);
  REP(i,m){
    ll a,b;cin>>a>>b;
    p.at(i)=make_pair(a,b);
  }
  sort(a.begin(),a.end());
  sort(p.begin(),p.end(),compare_by_greater_y);  

  int j=0;
  ll ans=0;
  REP(i,n){
    bool f=true;
    while(j<m){
      if(p.at(j).first>0&&p.at(j).second>a.at(i)){
        ans+=p.at(j).second;
        p.at(j).first--;
        f=false;
        break;
      }else j++;
    }
    if(f) ans+=a.at(i);
  }

  cout<<ans;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF 1e9

int main(){
    int n,m;
    cin>>n>>m;
    
    int a[1000],b[1000],c[1000],dist[100][100];
    
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--,b[i]--;
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j) dist[i][j]=0;
            else dist[i][j]=INF;
        }
    }
    
    for(int i=0;i<m;i++){
        dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
        dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
    }
    
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    
    int ans=m;
    for(int i=0;i<m;i++){
        bool shortest=false;
        for(int j=0;j<n;j++){
            if(dist[j][a[i]]+c[i]==dist[j][b[i]]) shortest=true;
        }
        if(shortest) ans--;
    }
    cout<<ans<<endl;
}

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

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

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1 ? 1'000'000'007 : 998'244'353;
using m64 = modint<MOD>;
constexpr m64 operator"" _m(unsigned long long n) { return m64(n); }

i64 h, w;
vector<string> a;
vector<vector<optional<m64>>> dp;

m64 dfs(i64 y, i64 x) {
    if (y < 0 || y >= h || x < 0 || x >= w) return 0;
    if (a[y][x] == '#') return 0;
    if (y == h - 1 && x == w - 1) return 1;
    if (dp[y][x]) return dp[y][x].value();
    return dp[y][x].emplace(dfs(y + 1, x) + dfs(y, x + 1));
}

void solve() {
    cin >> h >> w;
    a.resize(h);
    for (auto& e : a) cin >> e;
    dp.resize(h, vector<optional<m64>>(w));
    cout << dfs(0, 0) << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 20000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))

const ll N = 2e5+5;
ll a[N];

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

	ll n;cin>>n;
	forn(i,n)cin>>a[i];
	forn(i,n)a[i]-=i+1;
	sort(a,a+n);
	ll m= n/2;
	ll ans=0;
	forn(i,n)ans+=abs(a[i]-a[m]);
	cout<<ans<<endl;
}


Measured memory_bytes: 5192
#include <iostream>

using namespace std;

int main(void) {

        int totalnum, goalx, goaly, matatabinum;
        int route[17][17][2];
        //  ??§?¨?x,??§?¨?y,????????????,??????????????°
        int a, b, c, d;
        cin >> totalnum;



        for(int n=0; n < totalnum; n++) {
                cin >> goalx >> goaly;
                cin >> matatabinum;

                //?????????
                for(int aa=0; aa <= goalx; aa++) {
                        for(int bb=0; bb <= goaly; bb++) {
                                if(aa==0&&bb==0) {
                                        route[aa][bb][0] = 0;
                                        route[aa][bb][1] = 1;
                                }else{
                                        route[aa][bb][0] = 0;
                                        route[aa][bb][1] = 0;
                                }
                        }
                }

                //??????????????????????????¢?????????
                for(int n=0; n < matatabinum; n++) {
                        cin >> a >> b >> c >> d; //x, y, x+1, y+1
                        if(a==c+1) route[c][d][0] += 1; //???????????????
                        if(a==c-1) route[a][b][0] += 1; //???????????????
                        if(b==d+1) route[c][d][0] += 2; //???????????????
                        if(b==d-1) route[a][b][0] += 2; //???????????????
                }

                //????????°????¨????
                for(int i=0; i <= goalx; i++) {
                        for(int j=0; j <= goaly; j++) {
                                //???????????????
                                if(route[i][j][0]==0) {
                                        route[i+1][j][1] += route[i][j][1];
                                        route[i][j+1][1] += route[i][j][1];
                                }
                                //???????????????
                                else if(route[i][j][0]==1) route[i][j+1][1] += route[i][j][1];
                                //???????????????
                                else if(route[i][j][0]==2) route[i+1][j][1] += route[i][j][1];
                        }
                }
                if(route[goalx][goaly][1]==0) {
                        cout << "Miserable Hokusai!" << endl;
                }else{
                        cout << route[goalx][goaly][1] << endl;
                }
        }

        return 0;

}

Measured memory_bytes: 3000
def main():
    N = int(input())
    A = list(map(int, input().split()))
    if N == 0 and A[0] == 1:
        print(1)
        return
    if A[0] != 0:
        print(-1)
        return
    piyo = 1
    work = [1]
    for a in A[1:]:
        piyo *= 2
        work.append(piyo)
        piyo -= a
    result = 0
    piyo = 0
    i = N
    for a in A[::-1]:
        piyo += a
        if a > work[i]:
            print(-1)
            return
        piyo = min(piyo, work[i])
        result += piyo
        i -= 1
    print(result)
main()

Measured memory_bytes: 675384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int n;
	cin>>n;
	int a[n],b[n],c[n],sum=0;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=1;i<=n;++i)
		cin>>b[i];
	for(int i=1;i<=n-1;++i)
		cin>>c[i];
	for(int i=1;i<=n;++i){
		sum+=b[a[i]];
		if(a[i-1]+1==a[i] && i>1){
			sum+=c[a[i-1]];
		}
	}
	cout<<sum<<endl;
		
	return 0;
}

Measured memory_bytes: 384
/*
AUTHOR: Aman Raj
LANG: C++
*/

using namespace std;

typedef   long long ll;
#include <bits/stdc++.h>


//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define all(a) a.begin(),a.end()
#define mod 998244353
#define inf 1e18
//#define mod 3
#define flush fflush(stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<ll, ll, hash<ll> > ht;

// find_by_order()  // order_of_key
typedef tree<
    int,
    null_type,
    less<long long int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;






ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c=c%mod;if(b%2==1) c*=a;c=c%mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }



 struct less_then_greater {
    template<typename T, typename U>
    bool operator()(T const& lhs, U const& rhs) const {
        if (lhs.first < rhs.first) return true;
        if (rhs.first < lhs.first) return false;
        return lhs.second > rhs.second;
    }
};
 /*std::priority_queue<std::pair<int, int>,
                    std::vector<std::pair<int, int>>,
                    less_then_greater
                   > pq;*/


ll n,m;
 vector<vector<ll> > v;
  vector<ll> vpar;
  int main()
{    fast;
   cin>>n>>m;
    v.resize(n);
    vpar.resize(n,-1);
     vector<ll> vans(n,-1);
      bool ok=true;
      for(ll i=0;i<m;i++)
      {
          ll a,b;cin>>a>>b;a--;b--;
          v[a].push_back(b);
          v[b].push_back(a);
      }
      vector<ll> pq;
      pq.push_back(0);
       vector<ll> visited(n);
   visited[0]=1;
         vpar[0]=-1;

       while(pq.size()>0)
       {

            vector<ll> v2;
            for(auto y:pq)
            {

             for(auto x:v[y])
             {
                 if(visited[x])continue;

                 vpar[x]=y;
                  visited[x]=1;
                   v2.push_back(x);
             }
            }
            pq.clear();pq=v2;

       }
       //for(auto x:vpar)cout<<x<<" ";cout<<endl;
       for(ll i=1;i<n;i++){if(vpar[i]==-1)ok=false;else vans[i]=vpar[i];}
     if(!ok)cout<<"No"<<endl;
     else { cout<<"Yes"<<endl;


     for(ll i=1;i<n;i++)cout<<vans[i]+1<<endl;}


        return 0;
}


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

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

  vector<int> vec(N);

  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

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

  int A = 0, B = 0;

  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      A += vec.at(i);
    }
    else {
      B += vec.at(i);
    }
  }

  cout << A - B << endl;
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    //what do i want to do
    //just go to adjacent stuff with 0 cost and transfer line for 1 cost
    //it's not that difficult...
    map<pair<int,int>,vector<int> > adj; //<p,c>,q
    vector<int> clist[m+5];
    for (int i=0; i<m; i++){
        int p,q,c;
        cin >> p >> q >> c;
        adj[make_pair(p,c)].push_back(q);
        adj[make_pair(q,c)].push_back(p);
        clist[p].push_back(c);
        clist[q].push_back(c);
    }
    map<pair<int,int>,int> dis;
    map<pair<int,int>,int> vis;
    int vil[n+5]; memset(vil,0,sizeof(vil));
    deque<pair<int,int> > q;
    for (auto kk : adj){
        if (kk.first.first == 1){ dis[kk.first]=1; q.push_back(kk.first);}
    }
    int iter=0;
    while(!q.empty()){
        pair<int,int> vc = q.front();
        int v=vc.first, c=vc.second; q.pop_front();
        if(vis.find(vc)!=vis.end()) continue;
        vis[vc]=1;
        if (vil[v]) goto ahc;
        vil[v]=1;
        for(int i : clist[v]){
            pair<int,int> np = make_pair(v,i);
            if (dis.find(np)==dis.end()) dis[np]=dis[vc]+1;
            else dis[np]=min(dis[np],dis[vc]+1);
            q.push_back(np);
            //cout<<'a'<<endl;
        }//O(NM) edges
        ahc: ;
        for (int i : adj[vc]){
            pair<int,int> np = make_pair(i,c);
            if (dis.find(np)==dis.end()) dis[np]=dis[vc];
            else dis[np]=min(dis[np],dis[vc]);
            q.push_front(np);
            //cout<<'b'<<endl;
        }
        //cout<<vc.first<<' '<<vc.second<<endl;
    }
    int an=1e9;
    for (auto tk : dis){
        if(tk.first.first==n) an = min(an,tk.second);
    }
    if(an==1e9)cout<<-1;
    else cout<<an;
}

Measured memory_bytes: 102912
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int N, M, k, val, sum = 0, ans;
    int p[100];

    scanf("%d", &N);
    for(int i = 0; i < N; i++){
        scanf("%d", &p[i]);
        sum += p[i];
    }

    scanf("%d", &M);
    for(int i = 0; i < M; i++){
        scanf("%d", &k);
        scanf("%d", &val);

        ans = sum + val - p[k - 1];
        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 1724
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), a[] = new int[n], b[] = new int[n], c[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		int dp[][] = new int[n + 1][3];
		dp[0][0] = a[0];
		dp[0][1] = b[0];
		dp[0][2] = c[0];
		for (int i = 1; i < n; i++) {
			dp[i][0] = Integer.max(dp[i - 1][1] + a[i], (dp[i - 1][2] + a[i]));
			dp[i][1] = Integer.max(dp[i - 1][0] + b[i], (dp[i - 1][2] + b[i]));
			dp[i][2] = Integer.max(dp[i - 1][0] + c[i], (dp[i - 1][1] + c[i]));
		}
		sc.close();
		System.out.println(Integer.max(Integer.max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]));
	}
}


Measured memory_bytes: 61724
#include<stdio.h>

int main(){
  int a,b;
  scanf("%d %d",&a,&b);

  if(a+b==3){
    printf("3\n");
  }
  else if(a+b==4){
    printf("2\n");
  }
  else{
    printf("1\n");
  }
  
  return 0;
  
}


Measured memory_bytes: 128
import numpy as np
N, M, X  = map(int, input().split())
A = []
for i in range(N):
  A.append(list(map(int, input().split())))
A = np.array(A)
bit_base = 2#bit_base^nの全探査になる. 

def Base_10_to_n(X, n):#10進数をbit_base進数に変換
  X_dumy = X
  out = ''
  while X_dumy>0:
    out = str(X_dumy%n)+out
    X_dumy = int(X_dumy/n)
  return out
Inf = 10**9
def main():
  ans = Inf
  for i in range(bit_base**N):
    s = Base_10_to_n(i, bit_base)
    s = s.zfill(N)
    p_alg = np.zeros(M+1)
    for num, j in enumerate(s):
      if j == '1':
        p_alg += A[num]
    if all(p_alg[1:] >= X):
      ans = min(ans, p_alg[0])
  if ans == Inf:
    print(-1)
  else:
    print(int(ans))
if __name__ == "__main__":
  main()
        

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

using namespace std;

int main() {
	double a,b,x;
    cin >> a >> b >> x;
    double answer;
    const double PI = 3.14159265358979323846;

    if (x == a * a * b) {
        answer = 0;
    } else {
        if(a * a * b / 2.0 <= x) {
            answer = atan(2 * (a * a * b - x) / (a * a * a)) * 180.0 / PI;
        } else {
            answer = (PI / 2 - atan(2 * x / (a * b * b))) * 180.0 / PI;
        }
    }

    cout << fixed << setprecision(10) << answer << endl;
	return 0;
}

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


int main(){
	int N; 
	cin >> N; 
	int A = 0, B = 0, C = 0; 
	for(int i = 0; i < N; i++){
		int a; 
		cin >> a; 
		if(a % 2 == 1){A ++;}
		else if(a % 4 == 2){B ++;}
		else{C ++;}
	}
	int D = A + min(B, 1); 
	if(C >= D - 1){cout << "Yes" << endl;}
	else{cout << "No" << endl;}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<ll> h(n);
  REP(i, n) cin >> h[i];
  int ans = 0;
  REP(i, n) {
    bool f = true;
    for (int j = 0; j < i; j++) {
      if (h[j] > h[i]) f = false;
    }
    if (f) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
#include<stdbool.h>
#include<stdlib.h>

int people[2][2];

char str[1000];

int main(void) {

	fgets(str, sizeof(str), stdin);

	sscanf(str, "%d %d %d %d", &people[0][0], &people[0][1], &people[1][0], &people[1][1]);

	bool win = false;

	while (true)
	{
		for (int p = 0; p < 2; p++) {

			people[1 - p][0] -= people[p][1];

			if (people[1 - p][0] <= 0) {

				if (p == 0) {
				
					printf("%s\n", "Yes");
				
					return 0;

				}
				else
				{
					printf("%s\n", "No");

					return 0;

				}

			}

		}



	}

}

Measured memory_bytes: 1688
H,N = map(int, input().split())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())

dp = [0]*(H+max(A)+1)
dp[0] = 0
for i in range(1, H+max(A)+1):
    for j in range(N):
        t = max(0,i-A[j])
        if dp[i]==0:
            dp[i] = dp[t] + B[j]
        else:
            dp[i] = min(dp[i], dp[t]+B[j])

ans = dp[H]
for i in range(H, H+max(A)+1):
    ans = min(ans, dp[i])
print(ans)


Measured memory_bytes: 43228
#include <cstdio>
int n,m,a[1005],sum=0,cnt=0;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	for(int i=1;i<=n;++i)if(a[i]*4*m>=sum) cnt++;
	if(cnt>=m) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
int main(){
    int q,h,s,d;
    cin>>q>>h>>s>>d;
    int64_t n;
    cin>>n;
    vector<pair<int64_t,int>> a(4);
    a[0]=make_pair(8*q,8);
    a[1]=make_pair(4*h,4);
    a[2]=make_pair(2*s,2);
    a[3]=make_pair(d,1);//これが一番小さかった時だけ警戒
    all(a);
    int64_t ans=0;
    if(a[0].second!=1){
        ans = n*a[0].first/2;
    }
    else{
        ans += (n/2)*2 * a[0].first/2;
        n = n - (n/2)*2;
        ans += n*a[1].first/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans[ohara],a[ohara],b[ohara],c[ohara],d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll q;
ll p;
V g[ohara];
bool vi[ohara];

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

void dfs(ll now,ll sco){
    if(vi[now])return;
    vi[now]=true;
    ans[now]=sco;
    rep(i,Size(g[now])){
        dfs(g[now][i],sco+c[g[now][i]]);
    }
}

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

    cin>>n>>q;
    rep(i,n-1){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }
    rep(i,q){
        cin>>p>>x;
        p--;
        c[p]+=x;
    }
    dfs(0LL,c[0]);
    rep(i,n){
        if(i==n-1)Cout(ans[i]);
        else cout<<ans[i]<<" ";
    }
    return 0;
}


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

int P, Q, A, N;

int dfs(int p, int q, int n, int t) {
	if (P * q < Q * p) return 0;
	if (P * q == Q * p) return 1;
	if (N == n) return 0;
	
	int res = 0;
	for (int i = t; q * i <= A; i++) {
		res += dfs(p * i + q, q * i, n + 1, i);
	}
	return res;
}


int main() {
	while(cin >> P >> Q >> A >> N, P or Q or A or N) {
		cout << dfs(0,1,0,1) << endl;
	}
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    vector<vector<char>> C(2, vector<char>(3));
    for(int i = 0; i < 2; i++) for(int j = 0; j < 3; j++) cin >> C[i][j];
    if(C[0][0] == C[1][2] && C[0][1] == C[1][1] && C[0][2] == C[1][0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
  
  int N, M;
  cin >> N >> M;
  
  vector<int> num(N);
  
  for (int i = 0 ; i < M ; i++){
    int a,b;
    cin >> a >> b;
    
    num.at(a-1)++;
    num.at(b-1)++;
    
  }
  
  for (int j = 0 ; j < N ; j++)
    cout << num.at(j) << endl;
}


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

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  long double H = PI*(h*60.0+m)/360.0;
  long double M = PI*m/30.0;
  if(M>H) swap(H,M);
  long double ans = sqrt(a*a+b*b-2.0*a*b*cos(H-M));
  cout << fixed << setprecision(10);
  cout << ans << endl;
}


Measured memory_bytes: 4164
#N枚のカードを大きい順に並べたリストを作成し、0,2,4,...番目をAliceが、1,3,5,...番目をBobが取ると考え、これらの総和の差を出力する
N = int(input())
a = list(map(int, input().split()))
b = sorted(a)[::-1]
Alice = 0
Bob = 0
for i in range(len(b)):
	if i % 2 == 0:
		Alice = Alice + b[i]
	else:
		Bob = Bob + b[i]
print(Alice - Bob)


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

using namespace std;
using ll = long long int;

int main(){
    int K;
    cin>>K;
    
    //vector<string> S={"1","2","3","4","5","6","7","8","9","01","11","21","12","22","32"};
    vector<string>S={"1"};
    S.resize(K);
    for(int i=1;i<K;i++){
        S[i]=S[i-1];
        bool ok=false;
        for(int j=0;j<S[i].size();j++){
            if(S[i][j]<=S[i][j+1] && S[i][j]!='9'){
                S[i][j]+=1;
                for(int k=j-1;k>=0;k--){
                    if(S[i][k+1]-1>'0') S[i][k]=S[i][k+1]-1;
                    else S[i][k]='0';
                }
                ok=true;
                break;
            }
        }
        if(!ok){
            if(S[i][S[i].size()-1]=='9'){
                for(int j=0;j<S[i].size();j++) S[i][j]='0';
                S[i].push_back('1');
            }
            else{
                S[i][S[i].size()-1]+=1;
                for(int k=S[i].size()-1-1;k>=0;k--){
                    if(S[i][k+1]-1>'0') S[i][k]=S[i][k+1]-1;
                    else S[i][k]='0';
                }
            }
        }
    }
    
    reverse(S[K-1].begin(),S[K-1].end());
    cout<<S[K-1]<<endl;
    
    return 0;
}




Measured memory_bytes: 5760
using System;
using System.Collections.Generic;

namespace ConsoleApp4
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var works = new List<Work>(n); 
			for (int i = 0; i < n; i++)
			{
				var input = Console.ReadLine().Split(' ');
				works.Add(new Work(UInt32.Parse(input[0]), UInt32.Parse(input[1])));
			}
			works.Sort((x, y) => { return (int)(x.mB - y.mB); });

			UInt32 now = 0;
			for (int i = 0; i < n; i++)
			{
				now += works[i].mA;
				if (works[i].mB < now)
				{
					Console.WriteLine("No");
					return;
				}
			}
			Console.WriteLine("Yes");
		}

		public struct Work
		{
			public UInt32 mA;
			public UInt32 mB;

			public Work(UInt32 a, UInt32 b)
			{
				mA = a;
				mB = b;
			}
		}
	}
}


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

int main(){
    int N;
    cin>>N;
    int a[N+2];
    a[0]=0;
    a[1]=0;
    int count=0;
    for(int i=2;i<N+2;i++){
        cin>>a[i];
        if(a[i]==a[i-1]){
            count++;
            a[i]=0;
        }
    }
    cout<<count<<endl;
    return 0;
}


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

dp = [int(i) for i in range(N+1)]
B6 = [6**i for i in range(1,7)]
B9 = [9**i for i in range(1,6)]
L = B6 + B9
L = sorted(list(set(L)))

for i in L:
    for j in range(1, N+1):
        if j - i >= 0:
            dp[j] = min(dp[j], dp[j-i] + 1)
print(dp[N])


Measured memory_bytes: 7064
from functools import reduce
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def xor(a, b):
    return a ^ b


def solve(a, b):
    return reduce(xor, range(a, b+1))


def f(a):
    """
    xor [0,a]
    """
    ans = 0
    l = []
    d = 2
    while (a+1)//d > 0:
        t = (a+1)//d*(d//2)+max((a+1) % d-d//2, 0)
        ans += (t % 2)*(d//2)
        l.append(t % 2)
        d *= 2
    ans += (((a+1)-d) % 2)*(d//2)
    l.append(((a+1)-d) % 2)
    return l


def solve2(a, b):
    rb = f(b)
    ra = f(a-1)
    for i in range(len(ra)):
        rb[i] ^= ra[i]
    ans = "".join(map(str, reversed(rb)))
    print(int(ans, 2))


A, B = map(int, input().split())
if A == 0 and B == 0:
    print(0)
else:
    solve2(A, B)


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

using namespace std;

long computeByOperator(long a,long b,char operatorInput) {
	long result = 0;
	if (operatorInput =='+') {
		result = a + b;
	}
	if (operatorInput =='-') {
		result = a - b;
	}
	if (operatorInput =='*') {
		result = a * b;
	}
	return result;
}


int main() {
	long numList[200];
	int index = 0;
	string input;

	while (cin>>input) {
		//cin >> input;
		//cout << input;
		if (!isdigit(input[0])) {
			numList[index-2] =computeByOperator(numList[index-2],numList[index-1],input[0]);
			//cout << numList[index - 2] << endl;
			index -= 1;
		}
		else {
			long temp = stol(input,nullptr,10);
			numList[index] = temp;
			index++;
		}
	}
	cin.get();
	cout << numList[0] << endl;

	return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#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++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int h, n, a, sum = 0;
    cin >> h >> n;
    REP(i, n){
        cin >> a;
        sum += a;
        if(sum >= h){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);

int x;
    if(a<b)
    x=a;
    else
    x=b;
int y;
    if(c<d)
    y=c;
    else
    y=d;
int ans=x+y;
printf("%d\n",ans);


  return 0;
}

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

long long f(long long b,long long n){
  if(n<b) return n;
  return f(b,n/b)+n%b;
}

int main(){
  long long n,s;
  cin >> n >> s;
  long long b=2;
  int flag=0;
  if(n==s){
    b=n+1;
    flag=1;
  }
  else{
    while(b<=sqrt(n)){
      if(f(b,n)==s){
        flag=1;
        break;
      }
      b++;
    }
  }
  
  long long p=1,c=100000000000;
  while(flag!=1 && p<sqrt(n) && 1<=((n-s)/p)){
    if(f(((n-s)/p)+1,n)==s ){
      c=min(c,((n-s)/p)+1);
      b=c;
      flag=2;
    }
    p++;
  }
  
  if(flag) cout << b << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
int H,W;
int t[20][20];
ll u[20][20],ans;

bool inField(int x){
  if(1<=x&&x<=W)return true;
  return false;
}

int main(){
  while(cin>>W>>H){
    if(H==0&&W==0)break;
    for(int i=0;i<20;i++)for(int j=0;j<20;j++)u[i][j]=0;
    for(int i=1;i<=H;i++)for(int j=1;j<=W;j++)cin>>t[i][j];

    for(int i=0;i<20;i++)u[1][i]=(t[1][i]==1?0:1);

    for(int i=1;i<H;i++){
      for(int j=1;j<=W;j++){
	if(t[i][j]==1)u[i][j]=0;
	if(u[i][j]==0)continue;
	if(t[i][j]==2){
	  u[i+2][j]+=u[i][j];
	  continue;
	}
	for(int k=-1;k<=1;k++){
	  if(!inField(j+k))continue;
	  if(t[i+1][j+k]==0){
	    u[i+1][j+k]+=u[i][j];
	  }else if(t[i+1][j+k]==2&&k==0){
	    u[i+1][j+k]+=u[i][j];
	  }
	}
      }//j
    }//i
    ans=0;
    for(int i=H;i<20;i++){
      for(int j=1;j<=W;j++){
	if(t[i][j]==1)continue;
	ans+=u[i][j];
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner input = new Scanner(System.in);
        int[] s = new int[111];
        int r = input.nextInt();
        int c = input.nextInt();
        int t, sum;
        for(int i = 0; i < r; i++)
        {
            sum = 0;
            for(int k = 0; k < c; k++)
            {
                t = input.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            }
            s[c] += sum;
            System.out.println(sum);
        }
        for(int i = 0; i < c; i++)
            System.out.print(s[i] + " ");
        System.out.println(s[c]);
    }
}

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

using namespace std;

int d;
long g;
int p[10];
int c[10];

int res = 10000;

int main(int argc, char const *argv[])
{
    cin >> d >> g;
    for(int i=0; i<d; i++){
        cin >> p[i] >> c[i];
    }

    int max_i = pow(2, d);
    for(int i=0; i<max_i; i++){
        long sum = 0;
        int cnt = 0;
        int rest = -1;
        for(int j=0; j<d; j++){
            if((i>>j)&1){
                sum += 100*(j+1)*p[j] + c[j];
                cnt += p[j];
            }else{
                rest = j;
            }
        }
        if(sum>=g) res = min(res, cnt);
        else if(rest!=-1){
            int need = (g-sum)/(100*(rest+1));
            if((g-sum)%(100*(rest+1))>0) need++;
            if(need<p[rest]) res = min(res, cnt+need);
        }
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
//Combination
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[2000010],finv[2000010],inv[2000010];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,2000010){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=invmod(i,mod);
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    c++;d++;
    combinit();
    ll ans=0;
    ans+=comb(a+b,b);
    ans%=inf;
    ans+=comb(c+d,d);
    ans%=inf;
    ans-=comb(a+d,d);
    ans%=inf;
    ans-=comb(b+c,c);
    ans%=inf;
    if(ans<0)ans+=inf;
    cout<<ans<<endl;
}

Measured memory_bytes: 47104
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int[] a = new int[3];
        int count = 0;
        for(int i = 0; i < s.Length; i++)
        {
            a[i] = int.Parse(s[i]);
            if (a[i] == 5) count++;
        }

        if (count == 2) Console.WriteLine("YES");
        else Console.WriteLine("NO");

    }

}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long N,A,B,x;
  cin>>N>>A>>B;
  x = N / (A + B) * A;
  if(N%(A+B)>A)
    x+=A;
  else
    x+=N%(A+B);
  cout<<x<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N, L;
  cin >> N >> L;
  vector<string> a(N);
  string ans = "";
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  
  sort(a.begin(),a.end());
  
  for(int i = 0; i < N; i++){
    ans += a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256