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

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] H = nextIntArray(sc, N);

		sc.close();

		String ans = "Yes";
		int max = 0;

		for (int i = 0; i < N; i++) {
			if (H[i] < max - 1) {
				ans = "No";
			}

			max = Math.max(H[i], max);

		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 50844
object Main extends App {

  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt()
  var A = sc.nextInt()
  var B = sc.nextInt()
  val S = sc.next().toList
  val results = S.map(i => {
    i match {
      case 'a' => {
        if (A + B > 0) {
          A -= 1
          "Yes"
        } else {
          "No"
        }
      }
      case 'b' => {
        if (A + B > 0 && B > 0) {
          B -= 1
          "Yes"
        } else {
          "No"
        }
      }
      case 'c' => "No"      
    }
  })
  results.foreach(println)
}

Measured memory_bytes: 62800
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long a[100];
int main()
{
    int n;
	scanf("%d",&n);
	a[0]=2;a[1]=1;
	for(int i=2;i<=n;i++)
	{
		a[i]=a[i-1]+a[i-2];
	}
	printf("%lld\n",a[n]);
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int ans=1;
  for (int i=1; i<n; i++) {
    if (s[i]!=s[i-1]) {
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {

	int h, w, p;
	cin >> h >> w;
	p = w + 2;

	string A, B;
	string S = "#";
	string content;

	for (int a = 0; a < p; a++) {

		A += S;
	}

	cout << A << endl;

	for (int b = 0; b < h; b++) {

		cin >> content;
		cout << S << content << S << endl;

	}

	for (int c = 0; c < p; c++) {

		B += S;
	}

	cout << B << endl;

}

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

int main(){
    int n,i,t=0,h=0;
    cin >> n;
    for(i=0;i<n;i++){
        string X,Y;
        cin >> X >> Y;
        if(X > Y)t+=3;
        else if(Y > X)h+=3;
        else {
            t++;
            h++;
        }
    }
    cout << t << " " << h << endl;
    return 0;
}


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

#define pb  push_back
#define mp  make_pair
#define ll  long long
#define itr iterator

typedef pair<ll,ll> pii;

const ll MAX=2e5+9;
const ll INF=1e12;

vector<int> vec[MAX];

deque<int> dq;

int N,M,X,Y,start,end_,os,oe,mark[MAX];

signed main()
{
	ios_base::sync_with_stdio(false);
 
 	start=-1;
 	cin>>N>>M;
 	for(int A=1;A<=M;A++)
 	{
 		cin>>X>>Y;
 		if(start==-1)
 			start=X,
 			end_=Y;
 		vec[X].pb(Y);
 		vec[Y].pb(X);
 	}
 	mark[start]=1;
 	mark[end_]=1;
 	dq.push_back(start);
 	dq.push_back(end_);
 	while(true)
 	{
 		os=start;
 		oe=end_;
 		for(auto A:vec[start])
 		{
 			if(!mark[A])
 			{
 				dq.push_front(A);
 				mark[A]=1;
 				start=A;
 				break;
 			}
 		}
 		for(auto A:vec[end_])
 		{
 			if(!mark[A])
 			{
 				dq.push_back(A);
 				mark[A]=1;
 				end_=A;
 				break;
 			}
 		}
 		if(start==os and end_==oe)
 			break;
 	}
 	cout<<dq.size()<<"\n";
 	while(!dq.empty())
 	{
 		cout<<dq.front()<<" ";
 		dq.pop_front();
 	}
	return 0;
}

Measured memory_bytes: 9444
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long
#define  vi               std::vector<int>
#define  pb               push_back
#define  MAX              100007
#define  End              return 0;
#define                   pi acos(-1)
map<int,int>mp;

int main () {
    int x,n;
    cin>>x>>n;
    int aa[n];
    for(int i=0; i<n; i++) cin>>aa[i],mp[aa[i]]++;
    int k=0;
    while(1){
        if(!mp[x]) return cout<<x<<endl,0;
        else{
            if(k%2==0){
                k++;
                x-=k;
            }
            else{
                k++;
                x+=k;
            }
        }
    }
    End
}
/* pray for me
Do before die
*/


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
main(){
  string s,t,u;
  int r=0;
  cin>>s;
  for(int i=0;i<s.size();++i){
    t=u;
    u=s[i];
    while(i<s.size()-1&&t==u)u+=s[++i];
    cerr<<"t,u:"<<t<<","<<u<<"\n";
    r++;
    if(i==s.size()-1&&t==u)r--;
  }
  cout<<r;
}

Measured memory_bytes: 640
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)

	cnt := map[int]int{}
	for i := 0; i < n; i++ {
		cnt[a[i]]++
	}

	ans := 0

	for i := 0; i < n; i++ {
		if a[i] != 1 && cnt[1] != 0 {
			continue
		}
		if cnt[a[i]] != 1 {
			continue
		}
		f := true
		for j := 2; j*j <= a[i]; j++ {
			if a[i]%j == 0 {
				if cnt[a[i]/j] != 0 {
					f = false
					break
				}
				if cnt[j] != 0 {
					f = false
					break
				}
			}
		}
		if f {
			ans++
		}
	}

	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 14956
#include<iostream>
using namespace std;
int n,m,s,x,map[55][55],visit[55],a,b;
int main()
{
	cin>>n>>m;
	for (int i=1;i<=m;i++)
	{
		cin>>a>>b;
		visit[a]++;
		visit[b]++;
		map[a][b]=map[b][a]=1;
	}
	bool falg=true;
	while(1)
	{
		falg=true;
		for (int i=1;i<=n;i++)
		{
			if (visit[i]==1)
			{
				s++;
				x=i;
				falg=false;
				visit[i]--;
				break;
			}
		}
		if (falg)
			break;
		for (int i=1;i<=n;i++)
		{
			if (map[x][i]==1)
			visit[i]--;
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>

int main(void)
{
    int64_t X = 0, Y = 0;
    int64_t answer;
    scanf("%ld %ld", &X, &Y);
    if (Y == 1 || X == Y || X % Y == 0) {
        answer = -1;
    } else {
        answer = X * (Y - 1);
    }
    printf("%ld\n", answer);
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

struct Node
{
    int id;
    int c = 0;
    bool used = false;
    vector<int> edges;
};

const int M_MAX = 200000;
Node nodes[100000];
int L[M_MAX];
int R[M_MAX];
int D[M_MAX];

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

    for(int i = 0; i < M; i++)
    {
        cin >> L[i] >> R[i] >> D[i];
        nodes[L[i]].id = L[i];
        nodes[L[i]].edges.push_back(i);
        nodes[R[i]].id = R[i];
        nodes[R[i]].edges.push_back(i);
    }

    for(int i = 0; i < N; i++)
    {
        if(nodes[i].used)
            continue;
        
        nodes[i].used = true;
        nodes[i].c = 0;
        stack<int> stack;
        stack.push(i);
        while(!stack.empty())
        {
            int j = stack.top();
            stack.pop();
            for(const auto edge: nodes[j].edges)
            {
                int l = L[edge];
                int r = R[edge];
                if(nodes[l].used && nodes[r].used)
                {
                    int d = nodes[r].c - nodes[l].c;
                    if(d != D[edge])
                    {
                        cout << "No" << endl;
                        return 0;
                    }
                }
                else
                {
                    if(nodes[l].used)
                    {
                        nodes[r].c = nodes[l].c + D[edge];
                        nodes[r].used = true;
                        stack.push(r);
                    }
                    else
                    {
                        nodes[l].c = nodes[r].c - D[edge];
                        nodes[l].used = true;
                        stack.push(l);
                    }
                }

            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 10880
#include<iostream>
#include<cstring>
#include<set>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=200010;
int n;
int tr[N];
int res[N];
struct node{
    int x;
    int y;
    int id;
    bool operator < (const node&W)const
    {
        if(x!=W.x)
        return x<W.x;
        return  y<W.y;
    }
}q[N];
int p[N];
int sz[N];
int find(int x)
{
    if(p[x]!=x)
        p[x]=find(p[x]);
    return p[x];
}
set<pair<int,int>>s;
set<pair<int,int>>S;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&q[i].x,&q[i].y),q[i].id=i,p[i]=i,sz[i]=1;
     sort(q+1,q+n+1);
   for(int i=1;i<=n;i++)
   {
            if(s.empty())
            s.insert({q[i].y,q[i].id});
        auto it=s.lower_bound({q[i].y,0});
        int b=q[i].id;
        b=find(b);
        bool flag=false;
        for(set<pair<int,int>>::iterator x=s.begin();x!=it;x++)
        {
            flag=true;
            int a=x->second;
           a=find(a);
            if(a!=b)
            {
                p[a]=b;
                sz[b]+=sz[a];
              //  break;
            }
        }
        if(!flag)
            s.insert({q[i].y,q[i].id});
   }
    for(int i=1;i<=n;i++)
        printf("%d\n",sz[find(i)]);
    return 0;
}

Measured memory_bytes: 12052
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
string s;
ll k;

int main(){
	IOS
	cin >> s >> k;
	ll cnt=0, sais=s.size();
	string ini;
	for(int i=0;i<sais;i++){
		if(s[i]=='1'){
			cnt++;
		}
		else{
			ini=s[i];
			break;
		}
	}
	if(cnt>=k){
		cout << 1 << '\n';
		return 0;
	}
	cout << ini << '\n';
}	



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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n, x, y;
	cin >> n >> x >> y;
	x--, y--;
	vector<int> res(n);
	rep (i, n) {
	  FOR (j, i + 1, n) {
		int dist = min(j - i, min(abs(x - i) + abs(y - j) + 1, abs(x - j) + abs(y - i) + 1));
		res[dist]++;
	  }
	}
	FOR(i, 1, n) cout << res[i] << endl;
    
    return 0;
}


Measured memory_bytes: 3636
n = int(input())
h = list(map(int, input().split()))

dp = [0]*n
dp[1] = abs(h[1] -h[0])

for i in range(2, n):
    dp[i] = min(dp[(i-2)] + abs(h[i] - h[i-2]) ,
                dp[(i-1)] + abs(h[i] - h[i-1]))

print(dp[n-1])


Measured memory_bytes: 52336
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var NMR = Sarray();
            var N = NMR[0];
            var M = NMR[1];
            R = NMR[2];
            ri = Sarray();
            for (var i = 0; i < R; ++i)
                --ri[i];
            var MAX = long.MaxValue / 2;
            csts = Enumerable.Range(0, (int)N).Select(_ => new long[N]).ToArray();
            for (var i = 0; i < N; ++i) for (var j = i + 1; j < N; ++j) csts[j][i] = csts[i][j] = MAX;
            for (var i = 0; i < M; ++i)
            {
                var abc = Sarray();
                var a = abc[0] - 1;
                var b = abc[1] - 1;
                var c = abc[2];
                csts[a][b] = csts[b][a] = c;
            }
            for (var k = 0; k < N; ++k) for (var i = 0; i < N; ++i) for (var j = 0; j < N; ++j) csts[i][j] = Min(csts[i][j], csts[i][k] + csts[k][j]);
            ans = MAX;

            for (var i = 0; i < R; ++i)
            {
                used = new bool[R];
                used[i] = true;
                dfs(i, 0, 0);
            }
            WriteLine(ans);
        }
        static bool[] used;
        static long ans;
        static long R;
        static long[] ri;
        static long[][] csts;
        static void dfs(long s, long num, long cst)
        {
            if (num == R - 1)
            {
                ans = Min(ans, cst);
                return;
            }
            for (var i = 0; i < R; ++i)
            {
                if (used[i]) continue;
                used[i] = true;
                dfs(i, num + 1, cst + csts[ri[s]][ri[i]]);
                used[i] = false;
            }
        }
    }
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 112345;
ll A[MAX_N];
ll S[MAX_N];

bool possible(ll N, ll M, ll V, ll P, int m) {
  if (m < P) return true;

  ll D = N-V;
  ll len = m - (P-1);
  if (len <= D) {
    if (A[P-1] - M <= A[m]) return true;
    else return false;
  }
  ll tot = S[m] - S[P-1];
  ll need = tot - len * A[m];
  if (need > D * M) return false;
  for (int i = P-1; i < m; i++) {
    if (A[i] - M > A[m])
      return false;
  }
  return true;
}

int main2() {
  int N = nextInt();
  ll M = nextLong();
  ll V = nextLong();
  ll P = nextLong();
  REP(i, N) A[i] = nextLong();
  sort(A, A+N);
  reverse(A, A+N);
  S[0] = 0;
  REP(i, N) S[i+1] = S[i] + A[i];

  // pv(A, A+N);
  // pv(S, S+N+1);

  // int a = 3;
  // int b = 5;
  // for (int i = a; i < b; i++) cout << A[i] << " "; cout << endl;
  // cout << S[b] - S[a] << endl;

  // for (int mid = 0; mid < N; mid++)
    // cout << (possible(N, M, V, P, mid) ? 1 : 0);
  // cout << endl;

  ll lo = -1;
  ll hi = N;
  while (hi - lo > 1) {
    ll mid = (hi + lo) / 2;
    if (possible(N, M, V, P, mid)) lo = mid; else hi = mid;
  }
  ll ans = lo + 1;
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(x) ((x) > 0 ? (x) : -(x))

int
main(int argc, char *argv[])
{
  long long a, b, c, x, y;
  scanf("%lld %lld %lld %lld %lld", &a, &b, &c, &x, &y);

  if(x < y){
    long long temp;
    temp = y;
    y = x; x = temp;
    temp = b;
    b = a; a = temp;
  }

  long long a1, a2, a3;
  a1 = a * x + b * y;
  a2 = 2 * c * y + a * (x - y);
  a3 = 2 * c * y + 2 * c * (x - y);
  printf("%lld\n", min(a1, min(a2, a3)));

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
const int MOD = 1000000009;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s[100005];
  map<string, int>cnt;
  ll ans = 0;

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

  for(int i = 0;i < n;i++){
    sort(ALL(s[i]));
    if(cnt[s[i]] >= 1){
      ans += cnt[s[i]];
    }
    cnt[s[i]]++;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 16640
#include<map>
#include<cstdio>
#include<vector>

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

using namespace std;

template<class T>
class FenwickTree{
	vector<T> a;
public:
	FenwickTree(int n):a(n){}
	T sum(int i,int j)const{
		if(i==0){
			T s=0;
			for(;j>=0;j=(j&(j+1))-1) s+=a[j];
			return s;
		}
		return sum(0,j)-sum(0,i-1);
	}
	void add(int i,T v){
		for(;i<a.size();i|=i+1) a[i]+=v;
	}
};

int calc1(int n,const FenwickTree<int> &ft){
	int lo=0,hi=n-1;
	while(lo<hi){
		int mi=(lo+hi)/2;
		if(ft.sum(0,mi)==0) lo=mi+1; else hi=mi;
	}
	return lo;
}

int calc2(int n,const FenwickTree<int> &ft,int x){
	int lo=0,hi=n-1;
	while(lo<hi){
		int mi=(lo+hi)/2;
		if(ft.sum(0,mi)<x) lo=mi+1; else hi=mi;
	}
	return lo;
}

int main(){
	for(int nq,lim;scanf("%d%d",&nq,&lim),nq;){
		int n=0,m=0;

		map<int,int> f;
		static int id[400000];

		FenwickTree<int> ft(nq);
		rep(_,nq){
			int q,x; scanf("%d%d",&q,&x);
			if(q==0){
				ft.add(m,1);
				f[x]=m;
				id[m]=x;
				m++;
				n++;
				if(n>lim){
					ft.add(calc1(nq,ft),-1);
					n--;
				}
			}
			else if(q==1){
				ft.add(calc2(nq,ft,x),-1);
				n--;
			}
			else if(q==2){
				printf("%d\n",id[calc2(nq,ft,x)]);
			}
			else{
				ft.add(f[x],-1);
				n--;
			}
		}
		puts("end");
	}

	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MAX = 50;
const int INF = INT_MAX / 2;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    for(int i=0; i<n; ++i)
        cin >> b[i];

    vector<vector<int> > dp(MAX+1, vector<int>(1<<n, INF));
    for(int i=0; i<n; ++i){
        if(i % 2 == 0)
            dp[a[i]][1<<i] = i;
        else
            dp[b[i]][1<<i] = i;
    }
    for(int i=0; i<(1<<n); ++i){
        bitset<32> bs(i);
        int pos = bs.count();
        for(int prev=1; prev<=MAX; ++prev){
            if(dp[prev][i] == INF)
                continue;

            int cnt = -1;
            for(int j=0; j<n; ++j){
                if(bs[j])
                    continue;
                ++ cnt;

                int curr = a[j];
                if((pos - j) % 2 != 0)
                    curr = b[j];
                if(curr < prev)
                    continue;

                bitset<32> bs2 = bs;
                bs2[j] = true;
                dp[curr][bs2.to_ulong()] = min(dp[curr][bs2.to_ulong()], dp[prev][i] + cnt);
            }
        }
    }

    int ans = INF;
    for(int i=1; i<=MAX; ++i)
        ans = min(ans, dp[i].back());
    if(ans < INF)
        cout << ans << endl;
    else
        cout << -1 << endl;

    return 0;
}


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

const ll INF = 1LL << 60;
const int MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

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

    int A[N][M], B[M];
    REP(i, M) cin >> B[i];
    REP(i, N) REP(j, M) cin >> A[i][j];

    int ans = 0;
    REP(i, N) {
        int sum = 0;
        REP(j, M) sum += A[i][j] * B[j];
        sum += C;
        if (sum > 0) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    double h,n;
    cin >> h >> n;
    vector <int> a(n);
    int sum= 0;
    REP (i,n) {
        cin >> a[i];
        sum += a[i];
    }
    /*if (sum>=h) cout << "Yes" << endl;
    else cout << "No" << endl;*/

    bool is_passed = true;
    if (sum <h ) is_passed = false;
    cout << (is_passed ? "Yes" : "No") << endl;

    return 0;

}

Measured memory_bytes: 640
#include <cstdio>
#include <map>

using namespace std;

int main() {
    int n, a;
    map<int, int> m;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a);
        m[a] = i;
    }
    for (auto i = m.begin(); i != m.end();) {
        printf("%d", i -> second);
        printf("%c", ++i == m.end() ? '\n' : ' ');
    }
    return 0;
}


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

int main() {
	int n, f, tmp = 0, count = 1;
	vector<int>mochi(100), kagami(100);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> mochi.at(i);
	}
	for (int i = 0; i < n; i++) {
		for (int i = 1; i < n; i++) {
			if (mochi.at(i) < mochi.at(i - 1) && tmp < mochi.at(i - i)) {
				tmp = mochi.at(i - 1);
			}
			else if (tmp < mochi.at(i)) {
				tmp = mochi.at(i);
				f = i;
			}
		}
		for (int s = 0; s < n; s++) {
			if (tmp == mochi.at(s)) {
				mochi.at(s) = 0;
			}
		}

		kagami.at(i) = tmp;
		tmp = 0;
	}
	//for (int i = 0; i < n; i++) {
		//cout << kagami.at(i) << endl;
	//}
	for (int i = 1; i < n; i++) {
		if (kagami.at(i - 1) > kagami.at(i) && kagami.at(i) != 0) {
			count++;
		}
	}
	cout << count<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
	char x[1200];
	while(1){
		cin>>x;
		if(x[0]=='0')break;
		int sum=0;
		for(int i=0;i<strlen(x);i++){
			sum+=(int)(x[i]-48);
		}
		cout<<sum<<endl;
	}
}
	

Measured memory_bytes: 3008
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	string s;
	cin>>n;
	cin>>s;
	vector<ll> cnte(n,0);
	vector<ll> cntw(n,0);
	REP(i,n) {
		if(i==0) {
			if(s[i]=='E') {
				cnte[i]=1;
				cntw[i]=0;
			}
			else {
				cnte[i]=0;
				cntw[i]=1;
			}
		} else {
			if(s[i]=='E') {
				cnte[i]=cnte[i-1]+1;
				cntw[i]=cntw[i-1];
			}
			else {
				cnte[i]=cnte[i-1];
				cntw[i]=cntw[i-1]+1;
			}
		}
	}
	ll ans=INF;
	REP(i,n) {
		ll buf=0;
		if(i==0) buf=cnte[n-1]-cnte[0];
		else if(i==n-1) buf=cntw[i-1];
		else buf=cntw[i-1]+(cnte[n-1]-cnte[i]);
		ans=min(ans,buf);
	}
	cout<<ans<<endl;
}


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

int main(){
  int A,B,m;
  cin >>A >>B >>m;
  vector<int> a(A), b(B);
  int amin = 1e8, bmin=1e8;
  rep(i,A) {
    cin >>a[i];
    amin = min(amin, a[i]);
  }
  rep(i,B) {
    cin >>b[i];
    bmin = min(bmin, b[i]);
  }
  int curMin = amin+bmin;
  rep(i,m){
    int x,y,c;
    cin >>x >>y >>c;
    int sum = a[x-1]+b[y-1]-c;
    curMin = min(curMin, sum);
  }
  cout << curMin << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;

int Sumdegi(int x, int y){
  int keta =0;
  while(x!=0){
    x /= y;
    keta++;
  }
  return keta;
}

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


  cout << Sumdegi(n,k); 
}

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

int main() 
{
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); cout.tie(NULL);
	string s;
	cin>>s;
	if(s == "AAA" | s == "BBB")
		cout<<"No\n";
	else
		cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    map<int,int> mp;
    for(int i=1; i<=n; ++i) {
        mp[i] = 0;
    }
    for(int i=1; i<n; ++i){
        int a;
        cin >> a;
        mp[a]++;
    }
    for(auto x: mp) {
        ct(x.second);
    }

}



Measured memory_bytes: 13036
#include <bits/stdc++.h>
using namespace std;
int main(void){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int h;
    for (int i=0; i<5; i++){
        cin >> h;
        if (h == 0){
            cout << i+1;
        }
    }
}

Measured memory_bytes: 3608
l = list(map(int, input().split()))
count = 0
while True:
  if l[0] == l[1] == l[2]:
    print(count)
    break
  
  l = sorted(l)

  if l[1] == l[2] and not l[0] == l[1]:
    l[0] += 2
  else:
    l[0] += 1
    l[1] += 1
  
  count += 1



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

int main()
{
  int H, W;

  while (true) {
    cin >> H >> W;

    if (H == 0 && W == 0) {
      break;
    }
    for (int i = 0; i < H; i ++) {
      // 高さが0か最大ならすべて＃で描く
      if (i==0 || i == H - 1) {
        for (int j = 0; j < W; j ++) {
          cout << "#";
        }
      } else {
        for (int j = 0; j < W; j ++) {
          if (j == 0 || j == W - 1) {
            cout << "#";
          } else {
            cout << ".";
          }
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int n;
  cin >> n;
  long long int b[n];
  for (int i=0;i<n;i++){
  	cin >> b[i];
  }
  long long int dp[n];
  dp[0]=0;
  dp[1]=abs(b[1]-b[0]);
  for (int i=2;i<n;i++){
  	dp[i]=min(dp[i-2]+abs(b[i]-b[i-2]),dp[i-1]+abs(b[i]-b[i-1]));
  }
  cout << dp[n-1] <<endl;
}

Measured memory_bytes: 1792
#include    <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define rep(i,a,b)  for(int i=a;i<b;++i)
#define fore(i,a)  for(__typeof(a.begin()) i=a.begin();i!=a.end();++i)
#define __unique(V) V.resize(unique(V.begin(),V.end())-V.begin())
#define cntbit(X)   __builtin_popcount(X)
#define fi  first
#define se  second
#define LL  long long
#define ii  pair<int,int>
#define iii pair<int,ii>
#define TASK "FOF"
using   namespace   std;
int n,m,a[1005][1005];
int F[1005][1005],G[1005][1005][2];
///--------------------------
void    readf(){
    cin>>n>>m;
    fo(i,1,m) fo(j,1,n){
        cin>>a[i][j];
        F[i][j]=F[i-1][j]+F[i][j-1]-F[i-1][j-1]+a[i][j];
    }
}
///--------------------------
int get(int X1,int Y1,int X2,int Y2){
    return (F[X2][Y2]-F[X1-1][Y2]-F[X2][Y1-1]+F[X1-1][Y1-1]);
}
///--------------------------
int dp(int i,int j,int id){
    if (G[i][j][id]!=-1) return G[i][j][id];
    int &rs=G[i][j][id];
    if (i==m || j==n) return (rs=0);
    rs=-1e9-1;
    if (id==0){
        if (i<m && j<n){
            rs=max(rs,get(i+1,j+1,i+1,n)-dp(i+1,j,1));
            rs=max(rs,-get(i+1,j+1,m,j+1)-dp(i,j+1,1));
        }
    }else{
        if (i<m && j<n){
            rs=max(rs,-get(i+1,j+1,i+1,n)-dp(i+1,j,0));
            rs=max(rs,get(i+1,j+1,m,j+1)-dp(i,j+1,0));
        }
    }
    return rs;
}
///--------------------------
void    solve(){
    memset(G,-1,sizeof(G));
    cout<<abs(dp(0,0,0))<<'\n';
}
///--------------------------
int     main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    readf();
    solve();
}







Measured memory_bytes: 19084
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int n, m;
	int[] a, b, c;

	void run(){
		n=sc.nextInt();
		m=sc.nextInt();
		a=new int[m];
		b=new int[m];
		c=new int[m];
		for(int i=0; i<m; i++){
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
			c[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		int[][] max=new int[n][n];
		for(int i=0; i<n; i++){
			fill(max[i], -INF);
		}
		for(int i=0; i<m; i++){
			max[a[i]][b[i]]=c[i];
		}
//		debug(max);
		for(int k=0; k<n; k++){
			for(int i=0; i<n; i++){
				for(int j=0; j<n; j++){
					max[i][j]=max(max[i][j], max[i][k]+max[k][j]);
				}
			}
//			debug(max);
		}
		println(max[0][n-1]+"");
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 25164
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int n,k;
ll ans;
int main()
{
	scanf("%d%d",&n,&k);
	if(k==0) {printf("%lld\n",(ll)n*n);return 0;}
	for(int i=k+1;i<=n;++i)
	{
		int A=n/i;
		ans+=A*(i-k);
		A=n-A*i;
		ans+=max(0,A-k+1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl

int main(){
    int X, A; cin>>X>>A;
    if(X<A){
        cout<<"0"<<endl;
    }else{
        cout<<"10"<<endl;
    }
}


Measured memory_bytes: 3628
#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 Rep(i, r) for (register int i = (0), i##end = (int)(r); 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

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 ("E.in", "r", stdin);
	freopen ("E.out", "w", stdout);
#endif
}

const int N = 1e5 + 1e3;

char S[N], T[N];

int totS[N][2], totT[N][2];

int main () {

	File();

	scanf ("%s", S + 1);
	scanf ("%s", T + 1);

	For (i, 1, strlen(S + 1)) Cpy(totS[i], totS[i - 1]), ++ totS[i][S[i] - 'A'];
	For (i, 1, strlen(T + 1)) Cpy(totT[i], totT[i - 1]), ++ totT[i][T[i] - 'A'];

	int q = read();
	while (q --) {
		int lS = read(), rS = read(), lT = read(), rT = read();
		int staS = (totS[rS][0] - totS[lS - 1][0]) - (totS[rS][1] - totS[lS - 1][1]),
			staT = (totT[rT][0] - totT[lT - 1][0]) - (totT[rT][1] - totT[lT - 1][1]);
		puts(!((staS - staT) % 3) ? "YES" : "NO");
	}

	return 0;

}

Measured memory_bytes: 2304
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,X=mi()
    L=list(mi())

    d = 0
    ans = 1
    for i in range(N):
        d = d + L[i]
        ans += d <= X

    print(ans)



if __name__ == "__main__":
    main()

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

using namespace std;

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

	vector<string> S;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		S.push_back(s);
	}

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

	for (int i = 0; i < N; i++) {
		cout << S[i];
	}
	cout << endl;
	
}






Measured memory_bytes: 3644
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

string makeTurnString(string S) {
    string L;
    L.push_back(S.at(S.size() - 1));
    for (int i = 0; i < S.size() - 1; i++) {
        L.push_back(S.at(i));
    }
    return L;
}

int main() {
    string S, T;
    cin >> S >> T;

    string ans = "No";
    rep(i, S.size()) {
        if (S == T) ans = "Yes";
        S = makeTurnString(S);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

struct clo {
	int amin;
	int amax;
	int value;
};

int main() {
	int D, N; cin >> D >> N;
	vector<int>ts;
	for (int i = 0; i < D; ++i) {
		int t; cin >> t; ts.emplace_back(t);
	}
	vector<clo>cs;
	for (int i = 0; i < N; ++i) {
		int a, b, c; cin >> a >> b >> c;
		cs.push_back(clo{ a,b,c });
	}
	vector<vector<int>>dp(D + 1, vector<int>(N,-1e9));
	for (int i = 0; i < N; ++i) {
		dp[0][i] = 0;
	}
	for (int d = 0; d < D; ++d) {
		const int hot = ts[d];
		for (int f = 0; f < N; ++f) {
			const int prevalue = cs[f].value;
			for (int c = 0; c < N; ++c) {
				if (cs[c].amin <= hot&&hot <= cs[c].amax) {
					const int nowvalue = d?cs[c].value:cs[f].value;
					dp[d + 1][c] = max(dp[d + 1][c], dp[d][f] + abs(prevalue - nowvalue));
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		ans = max(ans, dp[D][i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3224
#include <stdio.h>

int main(void) {
	int a, b, c;
	int cur, t;

	scanf("%d %d %d", &a, &b, &c);

	cur = t = 0;
	do {
		if (cur <= c + t * 60 && c + t * 60 <= cur + a) {
			printf("%d\n", c + t * 60);
			return 0;
		}

		cur += a + b;
		while (c + t * 60 < cur)
			t++;
	} while (cur % 60);

	puts("-1");
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 200000;
struct node{
	int pos,flag,v;
}a[maxn*2+50];
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	
	//00001234
	for(int i=0;i<=2*maxn;++i){
		a[i].v = 0;
		a[i].pos = 0;
		a[i].flag = 0;
	}
	for(int i=maxn,j=1;j<=n;++j){
		a[i+j].v = j;
		a[i+j].pos = i+j;
	}
	
	int chg,p=1;
	for(int i=0;i<m;++i,++p){
		scanf("%d",&chg);
		if(a[chg+maxn].flag==0){
			a[chg+maxn].flag=1;
			a[chg+maxn].pos = maxn - p;
			a[maxn-p].v = chg;
		}else{
			a[a[chg+maxn].pos].flag = 1;
			a[chg+maxn].pos = maxn - p;
			a[a[chg+maxn].pos].pos = maxn - p;
			a[maxn - p].v = chg;
		}
	}
	
	for(int i=0;i<=2*maxn;++i)
		if(a[i].v && (!a[i].flag))printf("%d\n",a[i].v);
	
	return 0;
}

Measured memory_bytes: 7908
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;

  int p = max(a,c);
  int q = min(b,d);

  cout << max(0,q-p) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
int main(void){
	int n, y,a,b,c;
	scanf("%d %d",&n,&y);
	y/=1000;
	a=max((y-n-4*min(y/5,n))/9,0);
	c=min((y-n)/9,min(y/10,n));
	for(;a<=c;a++){
		b=y-n-9*a;
		if(b%4==0&&0<=n-a-b/4){
			printf("%d %d %d",a,b/4,n-a-b/4);
			return 0;
		}
	}
	printf("-1 -1 -1");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 5001
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int main(){
	int t, a = 0, b = 0;
	for(int i = 0;i < 4;i++)scanf("%d", &t), a += t;
	for(int i = 0;i < 4;i++)scanf("%d", &t), b += t;
	printf("%d\n", max(a, b));
	return 0;
}

Measured memory_bytes: 3196
H, W = map(int,input().split())
s = []
black = 0
for i in range(H):
    tmp = list(input())
    s.append(tmp)
    for j in range(W):
        if tmp[j] == "#":
            black += 1
white = H*W - black


q = [(0,0,0)]
s[0][0] = "#"
while q:
    i, j, cnt = q.pop(0)
    for di, dj in [(1,0),(0,1),(-1,0),(0,-1)]:
        ni, nj = i+di, j+dj
        if ni == H-1 and nj == W-1:
            print(white-cnt-2)
            exit(0)
        elif 0 <= ni < H and 0 <= nj < W and s[ni][nj] == ".":
            s[ni][nj] = "#"
            q.append((ni,nj,cnt+1))
print(-1)

Measured memory_bytes: 3064
import itertools
import numpy as np

H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]

matrix = np.zeros((H, W))
for x in range(H):
    for y in range(W):
        if C[x][y] == '#':
            matrix[x, y] = 1

n_success = 0
for h in range(H + 1):
    for rows in itertools.combinations(range(H), h):
        for w in range(W + 1):
            for cols in itertools.combinations(range(W), w):
                X = matrix.copy()
                X[rows, :] = 0
                X[:, cols] = 0
                if X.sum() == K:
                    n_success += 1
print(n_success)

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

need = [None] * m
ans = 0

for i in range(m):
    s = list(map(int, input().split()))
    need[i] = s

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

for i in range(2 ** n):
    zentou = 1
    status = [0] * n

    for j in range(n):
        if ((i >> j) & 1):
            status[j] = 1

    for j in range(m):
        total = 0
        for t in range(1, len(need[j])):
            if status[need[j][t]-1] == 1:
                total += 1
        
        if total%2 != p[j]:
            zentou = 0

    if zentou == 1:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=1005;
int n;
ll cura,curb;

int main(){
	scanf("%d",&n);
	while(n--){
		ll a,b;
		scanf("%lld%lld",&a,&b);
		if(!cura)cura=a,curb=b;
		else{
			ll c=max((cura+a-1)/a,(curb+b-1)/b);
			cura=c*a;
			curb=c*b;
		}
	}
	printf("%lld",cura+curb);
	return 0;
}

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

int main(){
    long long N, K, sum=0, ans;
    cin >> N >> K;
    vector<pair<int, int>> ab(N);

    for(int i=0; i<N; i++){
	cin >> ab[i].first >> ab[i].second;
    }
    sort(ab.begin(), ab.end());

    for(int i=0; i<N; i++){
	sum += ab[i].second;
	if(K<=sum){
	    ans= ab[i].first;
	    break;
	}
    }
    cout << ans << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

int main() {
    long w, n, ans = -1e9;
    string s;
    cin >> n >> w;
    vector<long> ws(n), vs(n);
    vector<vector<long>> dp(n + 1, vector<long>(100001, 1e9 + 1));
    // dp[i][j] least weight of items for value j
    for (long i = 0; i < n; i++) {
        cin >> ws[i];
        cin >> vs[i];
    }
    // cout << "hogrider" << endl;
    dp[0][0] = 0;
    for (long i = 1; i <= n; i++) {
        for (long j = 0; j < 100001; j++) {
            if (j - vs[i - 1] < 0) {
                dp[i][j] = min(dp[i - 1][j], dp[i][j]);
                continue;
            }
            dp[i][j] = min({dp[i - 1][j], dp[i - 1][j - vs[i - 1]] + ws[i - 1]});
        }
    }
    // cout << "hogrider" << endl;
    for (long j = 0; j < 100001; j++) {
        if (w >= dp[n][j]) {
            ans = max(ans, j);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 80256
N = int(input())
P = [ 11, 31, 41, 61, 71,101,131,151,181,191,
     211,241,251,271,281,311,331,401,421,431,
     461,491,521,541,571,601,631,641,661,691,
     701,751,761,811,821,881,911,941,971,991,
     1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,
     1291,1301,1321,1361,1381]
P = list(map(str, P))
print(" ".join(P[:N]))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n;
    cin>>n;
    int a[n+2],i,b[n+2];
    for(i=0;i<n;i++)
        cin>>a[i];
        for(i=0;i<n;i++)
        b[i]=a[i];
    sort(a,a+n);
    for(i=0;i<n;i++) {
        if(b[i]<a[n-1])
        cout<<a[n-1]<<endl;
        else
            cout<<a[n-2]<<endl;

    }




    return 0;
}


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

#define scan(x) scanf("%d",&x)
#define scan2(x,y) scanf("%d%d",&x,&y)
#define scan3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define FASTER std::ios::sync_with_stdio(false)
#define DEBUG(x) cout<<#x<<" = "<<x<<endl

#define pb push_back
#define mk make_pair
#define vp vector<pair<ll,ll> >
#define se second
#define fi first
#define vi vector<ll>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define fab(i,a,b) for(ll i=a;i<=b;i++)
#define inp(n,a) for(ll i=0;i<n;i++){cin>>a[i];}
#define strToInt(x,z) istringstream y(x);y>>z  //(string,integer)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b / __gcd(a,b);
#define MOD 1000000007
#define pi 3.14159265
using namespace std;
long double a[100010], b[100010],n,p;

int main() 
{
	//FASTER;
	string a,b;
	cin >> a >> b;

	if(a.length() != b.length())
	{
		if(a.length() > b.length())
		{
			cout << "GREATER" <<endl;
		}else
		cout << "LESS" <<endl;

		return 0;
	}

	rep(i,a.length())
	{
		if(a[i]-'0' > b[i] - '0')
		{
			cout << "GREATER" << endl;
			return 0;
		}else if (a[i]-'0' < b[i] -'0')
		{
			/* code */
			cout << "LESS" <<endl;
			return 0;
		}
	}

	cout << "EQUAL" <<endl;


	return 0;
}		

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	X := sc.Next()

	l := 0
	for _, v := range X {
		l += int(v - '0')
		l %= 9
	}
	if l%9 == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 3104