akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>

using namespace std;

#define N 2<<30;

int main(){

  int n;


  while(cin >> n){
    if(n == 0) break;
    vector<int> V;
    int status;
    int in;
    int sum = 0;
    for(int i = 0; i < n; i++){
      cin >> in;
      if(i == 0){
	if(in < 0){
	  status = -1;
	  V.push_back(in);
	}
	else if(in >= 0)status = 1;

      } else {

	if(in < 0 && status > 0){
	  status = -1;
	  V.push_back(sum);
	  sum = 0;
	  V.push_back(in);
	  continue;
	}else if(in < 0 && status < 0){
	  V.push_back(in);
	  continue;
	}else if(in >= 0 && status < 0){
	  status = 1;
	  V.push_back(sum);
	  sum = 0;
	}
      }
      sum += in;
    }
    if(sum >= 0) V.push_back(sum);

    int max = -1*N;
    
    for(int i = 0; i < V.size(); i++){
      sum = 0;
      for(int j = i; j < V.size(); j++){
	sum += V[j];
	if(max < sum) max = sum;
      }
    }
    
    cout << max << endl;
  }
  return 0;
}

Measured memory_bytes: 0
//verma_ankit484

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

using namespace std;
unordered_map<ll, ll> parent, size;

void make_set(int v) {
    parent[v] = v;
    size[v] = 1;
}
int find_set(int v) {
    if (v == parent[v])
        return v;
    return find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
    }
}


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifdef AV
  freopen("int.txt", "r", stdin);
  #endif
  ll n, m;
  cin >> n >> m;
  for(ll i = 1; i <= n; i++) {
    make_set(i);
  }
  for(ll i = 0; i < m; i++) {
    ll x, y, z;
    cin >> x >> y >> z;
    union_sets(x, y);
  }
  set<ll> st;
  for(ll i = 1; i <= n; i++) {
    st.insert(find_set(i));
  }
  cout << st.size() << '\n';
  return 0;
}


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

#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define debug(x) cerr << #x << " = " << x << endl;
#define SET(c, v) memset(c, v, sizeof c)
#define pi 3.14159265358979323846264338
#define all(S) (S).begin(), (S).end()
#define INF 0x3f3f3f3f
#define mod 1000000007
#define pf push_front
#define pb push_back
#define mk make_pair
#define MAX 100000
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef unsigned long long int ull;
int v[MAX], pd[MAX], N, K;

int solve(int i) {
	int &ans = pd[i];
	if(i == N-1) return 0;
	if(i >= N) return 1 << 30;
	if(ans != -1) return ans;
	ans = 1 << 30;
	REP(j, i+1, i+K) ans = min(ans, solve(j) + abs(v[i] - v[j]));
	return ans;
}

int main(int argc, char** argv) {
	scanf("%d%d", &N, &K);
	rep(i, 0, N) scanf("%d", &v[i]);
	memset(pd, -1, sizeof pd);
	printf("%d\n", solve(0));
	return 0;
}


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

namespace ConsoleApp14
{
    class Class8
    {
        static void Main()
        {
            var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var H = HW[0];
            var W = HW[1];

            string[] R = new string[2 * H];
            for(int i = 0; i < H; i++)
            {
                string read = Console.ReadLine();
                R[2 * i] = read;
                R[2 * i + 1] = read;
            }
            foreach(string s in R)
            {
                Console.WriteLine(s);
            }
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MOD = 1e9+7;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//C++17以上
template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main() {
    int n;cin >> n;
    int cnt = 0;
    for(int i=1;i<=n;i++){
        string s = to_string(i);
        if(s.size()%2==1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		if (n == 0) {
			out(1);
		} else {
			out(0);
		}

	}

	/*
	 * 以下メソッド集
	 */

	public static int[] kousokusoinnsuubunkaihairetsu(int a) {
		int[] d = new int[a];
		for (int i = 0; i < a; i++) {
			d[i] = i;
		}
		for (int i = 2; i * i < a; i++) {
			for (int j = i * i; j < a; j += i) {
				if (d[j] == j)
					d[j] = i;
			}

		}

		return d;
	}

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
}

class XY {

	int h;
	int w;
	int d;

	XY(int h, int w, int d) {
		this.h = h;
		this.w = w;
		this.d = d;
	}
}

class NE {

	int n;
	int e;

	NE(int n, int e) {
		this.n = n;
		this.e = e;
	}
}

Measured memory_bytes: 35680
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
const ll INF = 1234567812345678;

int main() {
    int n;
    cin >> n;
    ll s[n];
    ll a[n];
    rep(i,n){
        cin >> s[i];
        a[i] = 1;
    }

    // 2500以下の素数
    vector<ll> p;
    srep(i,2,2500){
        int flag = 0;
        srep(j,2,100){
            if(i == j)continue;
            if(i % j == 0){
                flag = 1;
                break;
            }
        }
        if(flag == 0)p.push_back(i);
    }

    int m = p.size();
    rep(i,n){
        int j = 0;
        while(j<m){
            if(s[i] % p[j] == 0){
                int cnt = 0;
                while(s[i] % p[j] == 0){
                    cnt++;
                    s[i] /= p[j];
                }
                a[i] *= pow(p[j], cnt%3);
            }
            j++;
        }
        a[i] *= s[i];
    }

    sort(a,a+n);

    vector<ll> b,c;
    ll d[100001];
    rep(i,100001){
        ll ii = i;
        d[i] = ii * ii;
    }

    ll x = a[0];
    int cnt = 1;
    srep(i,1,n){
        if(a[i] != a[i-1]){
            b.push_back(x);
            c.push_back(cnt);
            x = a[i];
            cnt = 1;
        }else{
            cnt++;
        }
    }
    b.push_back(x);
    c.push_back(cnt);

    int ans = 0;

    rep(i,b.size()){
        //cout << b[i] << ' ' << c[i] << endl;
        if(b[i] == 1){
            ans++;
            c[i] = -1;
        }else if(c[i] != -1){
            ll b_ = b[i];
            ll y = 1;
            int j = 0;
            while(j<m){
                if(b_ % p[j] == 0){
                    cnt = 0;
                    while(b_ % p[j] == 0){
                        cnt++;
                        b_ /= p[j];
                    }
                    y *= pow(p[j], 3 - (cnt%3));
                }
                j++;
            }
            if(b_ != 1){
                if(b_ <= 100100){
                    y *= b_ * b_;
                }else{
                    auto it = lower_bound(d, d+100001, b_);
                    int index = it - d;
                    if(b_ != d[index]){
                        y = INF;
                    }else{
                        y *= index;
                    }
                }
            }
            auto it = lower_bound(b.begin(), b.end(), y);
            int index = it - b.begin();
            if(b[index] == y){
                ans += max(c[i], c[index]);
                c[i] = -1;
                c[index] = -1;
            }else{
                ans += c[i];
                c[i] = -1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 4424
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	
	final long MOD =  (long)(1e9+7);
	void solve() {
		int N = sc.nextInt();
		int[] a = new int [N];
		for (int i = 0; i < N; i++) a[i] = sc.nextInt();
		long ans = min(f(a, 1), f(a, -1));
		out.println(ans);
	}
	long f(int[] a, int s) {
		long res = 0;
		long sum = 0;
		for (int i = 0; i < a.length; i++) {
			sum += a[i];
			if (Long.signum(sum) == s) {
				//
			} else {
				sum -= a[i];
				long x = s - sum;
				res += Math.abs(a[i] - x);
				sum += x;
			}
			s *= -1;
		}
		return res;
	}
	
	
	static void tr(Object... os) { System.err.println(deepToString(os)); }
	static void tr(int[][] as) { for (int[] a : as) tr(a); }

	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

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

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 36792
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  l=LI()

  ll=[[] for _ in range(n)]

  for _ in range(m):
    a,b=LI()
    a-=1
    b-=1
    ll[a].append(b)
    ll[b].append(a)

  ans=0
  for i,h in enumerate(l):
    mx=-inf
    f=True
    for x in ll[i]:
      mx=max(mx,l[x])
      if h<=mx:
        f=False
        break
    if f:
      ans+=1

  return ans

# main()
print(main())


Measured memory_bytes: 93968
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int s;
	cin>>s;
	int b=s%100,a=s/100;
	//
	if((a==0||a>=13) && (b==0||b>=13)){
		cout<<"NA\n";
	}else if(a<=12 && (b>=13 ||b==0)){
		cout<<"MMYY\n";
	}else if( (a>=13||a==0) && b<=12){
		cout<<"YYMM\n";
	}else{
		cout<<"AMBIGUOUS\n";
	}
	return 0;
}



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

main(){
	while(true){
		int n;
		cin>>n;
		
		if(n<=0){
			break;
		}
		
		int maxV=-1, maxP=0;
		for(int i=0; i<n; ++i){
			//患者の番号、一回目に歩いた距離、二回目に歩いた距離
			int p, d1, d2;
			cin>>p>>d1>>d2;
			
			if(maxV < d1+d2){
				maxV = d1 + d2;
				maxP = p;
			}
		}
		
		printf("%d %d\n",maxP,maxV);
	}
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
    FI();
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k<=a) cout << k << endl;
    else if(k<=a+b) cout << a << endl;
    else cout << 2*a + b - k << endl;
    return 0;
}



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

int main(void){
    int S,h,m,s;
    cin >> S;
    h=S/3600;
    m=(S%3600)/60;
    s=(S%3600)%60;
    cout <<h;
    cout <<":";
    cout <<m;
    cout <<":";
    cout <<s;
    
    cout <<endl;
    
    
}



Measured memory_bytes: 3096
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int d = sc.nextInt();

		double ans = (double)(n - d) * (m - 1) / n / n;

		if (d != 0) {
			ans *= 2;
		}

		pr.printf("%.7f\n", ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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


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

int dfs(vector<vector<int>>&field, int x, int y,int rest) {
	int ans = 0;
	for (int way = 0; way < 4; ++way) {
		int nowx(x), nowy(y);
		while (1) {
			int nextx = nowx + dx[way];
			int nexty = nowy + dy[way];
			if (field[nexty][nextx] ==-1000) {
				break;
			}
			else if (field[nexty][nextx] <= 0) {
				nowx = nextx;
				nowy = nexty;
				continue;
			}
			else if (field[nexty][nextx] == 1000) {
				if (rest) {
					nowx = nextx;
					nowy = nexty;
					continue;
				}
				else {
					ans++;
					break;
				}
			}
			else {
				field[nexty][nextx] = -field[nexty][nextx];
				ans += dfs(field, nextx, nexty, rest - 1);
				field[nexty][nextx] = -field[nexty][nextx];
				break;
			}
		}
	}
	return ans;
}

int main() {
	while (1) {
		int W, H; cin >> W >> H;
		if (!W)break;
		vector<vector<int>>field(H + 2, vector<int>(W + 2, -1000));
		int num = 1;
		int sx, sy;
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				int n; cin >> n;
				if (n == 0)field[i + 1][j + 1] = 0;
				else if (n == 1)field[i + 1][j + 1] = num++;
				else {
					field[i + 1][j + 1] = 1000;
					sx = j + 1; sy = i + 1;
				}
			}
		}
		int ans = dfs(field, sx, sy, num - 1);
		cout << ans << endl;

	}
	
	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    map<int,int> even,odd;
    REP(i,n) {
        int v; cin >> v;
        if (i % 2 == 0) even[v]++;
        else odd[v]++;
    }
    int e1 = -1, e2 = -1, o1 = -1, o2 =-1;
    int ec1 = 0, ec2 = 0, oc1 = 0, oc2 =0;

    for (auto p:even) {
        if (p.second > ec1) {
            ec2 = ec1;
            ec1 = p.second;
            e2 = e1;
            e1 = p.first;
        } else if (p.second > ec2){
            ec2 = p.second;
            e2 = p.first;
        }
    }
    for (auto p:odd) {
        if (p.second > oc1) {
            oc2 = oc1;
            oc1 = p.second;
            o2 = o1;
            o1 = p.first;
        } else if (p.second > oc2){
            oc2 = p.second;
            o2 = p.first;
        }
    }
     
    int ans = 0;
    if (e1 != o1) {
        ans = n - ec1 - oc1;
    } else {
        ans = n - max(ec1+oc2,ec2+oc1);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;

int fast(){
	int res=0,fl=1;
	char c=getchar();
	while(c<48||c>57){
		if(c=='-')fl=-1;
		c=getchar();
	}while(c>=48&&c<=57)res=res*10+c-48,c=getchar();
	return res*fl;
}

void write(int x){
	if(x>9)write(x/10);
	putchar(x%10+48);
}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int num[n+1],cor[n+1];
	memset(num,0,sizeof(num));
	memset(cor,0,sizeof(cor));
	for(int i=1;i<=m;i++){
		int p;char s[5];
		scanf("%d %s",&p,s);
		if(s[0]=='A')cor[p]=1;
			else if(cor[p]==0)num[p]+=1;
	}int ans=0,pen=0;
	for(int i=1;i<=n;i++)
		if(cor[i]==1)ans+=1,pen+=num[i];
	printf("%d %d",ans,pen);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <queue>
#include <algorithm>
#include <set>
#include <vector>
#include <string>

using namespace std; using ll=long long; const int INF=1e9; using P=pair<ll,ll>;

int main() {
  int a,b,c,d; cin>>a>>b>>c>>d;
  int i=0;
  while(a>0&&c>0) {
    if (i%2==0) {
      c-=b;
    } else {
      a-=d;
    }
    i++;
  }
  //cout<<a<<" "<<c<<endl;
  if (a<=0) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 3624
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

#ifdef SHIK
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif

template<typename T>
void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( long long &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }

void R() {}
template<typename T, typename... U>
void R( T& head, U&... tail ) {
    _R(head);
    R(tail...);
}

template<typename T>
void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
template<typename T>
void _W( const vector<T> &x ) {
    for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
        if ( i!=x.cbegin() ) putchar(' ');
        _W(*i);
    }
}

void W() {}
template<typename T, typename... U>
void W( const T& head, const U&... tail ) {
    _W(head);
    putchar(sizeof...(tail)?' ':'\n');
    W(tail...);
}

#ifdef SHIK
#define FILEIO(...)
#else
#define FILEIO(name) do {\
    freopen(name ".in","r",stdin); \
    freopen(name ".out","w",stdout); \
} while (0)
#endif

// }}}

int main() {
    int n;
    R(n);
    LL x=1,y=1;
    while ( n-- ) {
        LL a,b;
        R(a,b);
        LL r=max((x+a-1)/a,(y+b-1)/b);
        x=a*r;
        y=b*r;
        dump(a,b,x,y);
    }
    W(x+y);
    return 0;
}


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

int mask;

template<class T> struct Parser {
    typedef string::const_iterator State;

    T solve(const string &S) {
        State begin = S.begin();
        return equation(begin);
    }

    // <equation> ::= <formula> "=" <formula>
    T equation(State &begin) {
        T left = formula(begin);
        begin++;    // skip '='
        T right = formula(begin);
        return left == right;
    }

    // <formula> ::= <boolean> |
    // "-" <formula> |
    // "(" <formula> "*" <formula> ")" |
    // "(" <formula> "+" <formula> ")" |
    // "(" <formula> "->" <formula> ")"
    T formula(State &begin) {
        if (*begin == '(') {
            begin++;                    // skip '('
            T left = formula(begin);
            char op = *begin;
            begin++;                    // skip '*' or '+' or '-'
            if (op == '-') begin++;     // skip '>'
            T right = formula(begin);
            begin++;                    // skip ')'
            T ret = deduce(left, op, right);
            return ret;
        } else if (*begin == '-') {
            begin++;    // skip '-'
            return !formula(begin);
        } else {
            return boolean(begin);
        }
    }

    T deduce(T x, char op, T y) {
        if (op == '*') {
            return x and y;
        } else if (op == '+') {
            return x or y;
        } else {    // "->"
            return !x or y;
        }
    }

    // <boolean> ::= "T" | "F" |
    // "a" | "b" | "c" | "d" | "e" | "f" |
    // "g" | "h" | "i" | "j" | "k" |
    T boolean(State &begin) {
        T ret;
        if (*begin == 'T') ret = 1;
        else if (*begin == 'F') ret = 0;
        else ret = (mask >> (*begin - 'a')) & 1;
        begin++;
        return ret;
    }
};

void solve(string S) {
    // 恒等式とは，式に現れる変数がどのような値であっても成立する等式のことである．
    Parser<bool> ps;
    for (mask = 0; mask < (1 << 11); mask++) {
        if (!ps.solve(S)) {
            cout << "NO" << endl;
            return ;
        }
    }
    cout << "YES" << endl;
}

int main() {
    string S;
    while (cin >> S && S != "#") {
        solve(S);
    }
    return 0;
}


Measured memory_bytes: 3240
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt, pi
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

S = input()
S = S.replace('BC', 'P')
N = len(S)

str_l = []
str_0 = ''
for i in range(N):
    if S[i] == "A" or S[i] == "P":
        str_0 += S[i]
    else:
        if str_0 != '':
            str_l.append(str_0)
            str_0 = ''
if str_0 != '':
    str_l.append(str_0)

ans = 0
for st in str_l:
    opt = []
    for i in range(len(st)):
        if st[i] == 'A':
            opt.append(0)
        else:
            opt.append(1)

    imos = copy.deepcopy(opt)
    for i in range(len(st) - 1):
        imos[-i - 2] += imos[-i - 1]

    for i in range(len(st)):
        if opt[i] == 0:
            ans += imos[i]
print(ans)

Measured memory_bytes: 17280
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


int main(void) {
    int i,j;
    int n;
    cin >> n;
    cout << "Christmas";
    rep(i,25-n)cout << " Eve";
    cout << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int a=0;
int main()
{
	int n,k;cin>>n>>k;
	string s;cin>>s;int len=s.length();
	for(int i=1;i<len;i++)
	{
		if(s[i]=='L'&&s[i-1]=='L') a++;
	}
	for(int i=len-2;i>=0;i--)
	{
		if(s[i]=='R'&&s[i+1]=='R') a++;
	}
	cout<<min(n-1,a+2*k)<<endl;
 } 

Measured memory_bytes: 512
import bisect
n=int(input())
a=list(map(int,input().split()))
s=[a[i]+i for i in range(n)]
di=[i-a[i] for i in range(n)]
di.sort()
ans=0
for i in range(n):
    ans+=bisect.bisect_right(di,s[i])-bisect.bisect_left(di,s[i])
print(ans)

Measured memory_bytes: 33780
from collections import defaultdict
from fractions import gcd
n=int(input())
def prime_factor(n):
    i = 2
    table = defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            table[i]+=1
        i += 1
    if n > 1:
        table[n]+=1
    return table
table=prime_factor(n)
d=list(table.keys())
ans=n
for i in d:
    ans*=(1-1/i)
print(int(ans))



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

int main()
{
  int n,a,d,mat[10][10];
  cin>>n>>d;
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>mat[i][j];
    }
  }  
  int ans = 0;
  for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        int df = 0;
         for(int k=0;k<d;k++){
           df += (mat[i][k]-mat[j][k])*(mat[i][k]-mat[j][k]);
         } 
        if(((int)sqrt(df))*((int)sqrt(df)) == df){
          ans++;
        }
      }
  }
cout<<ans;
return 0;
}



Measured memory_bytes: 256
S = gets.chomp.split('')
s_uniq  = S.uniq
k = gets.to_i

if s_uniq.size == 1 or k == 1
  puts S[0]
  exit
end  

if s_uniq[0] == "1"
  unless S[k-1].nil?
    if S[0..k-1].uniq == ["1"]
      puts s_uniq[0]
    else
      puts s_uniq[1]
    end
  else
    puts s_uniq[1]
  end
else
  puts s_uniq[0]
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    cout.precision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    return 0;
}
const int N = 1e5+5;
int a[N];
int n, m;
typedef complex<double> C;
typedef vector<int> vi;	
typedef vector<double> vd;
void fft(vector<C>& a) {
	int n = sz(a), L = 31 - __builtin_clz(n);
	static vector<complex<long double>> R(2, 1);
	static vector<C> rt(2, 1);  // (^ 10% faster if double)
	for (static int k = 2; k < n; k *= 2) {
		R.resize(n); rt.resize(n);
		auto x = polar(1.0L, M_PIl / k); // M_PI, lower-case L
		rep(i,k,2*k) rt[i] = R[i] = i&1 ? R[i/2] * x : R[i/2];
	}
	vi rev(n);
	rep(i,0,n) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
	rep(i,0,n) if (i < rev[i]) swap(a[i], a[rev[i]]);
	for (int k = 1; k < n; k *= 2)
		for (int i = 0; i < n; i += 2 * k) rep(j,0,k) {
			// C z = rt[j+k] * a[i+j+k]; // (25% faster if hand-rolled)  /// include-line
			auto x = (double *)&rt[j+k], y = (double *)&a[i+j+k];        /// exclude-line
			C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]);           /// exclude-line
			a[i + j + k] = a[i + j] - z;
			a[i + j] += z;
		}
}
vd conv(const vd& a, const vd& b) {
	if (a.empty() || b.empty()) return {};
	vd res(sz(a) + sz(b) - 1);
	int L = 32 - __builtin_clz(sz(res)), n = 1 << L;
	vector<C> in(n), out(n);
	copy(all(a), begin(in));
	rep(i,0,sz(b)) in[i].imag(b[i]);
	fft(in);
	trav(x, in) x *= x;
	rep(i,0,n) out[i] = in[-i & (n - 1)] - conj(in[i]);
	fft(out);
	rep(i,0,sz(res)) res[i] = imag(out[i]) / (4 * n);
	return res;
}
vector<double> poly((int) 1e5+1, 0);
void solve() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		cin >> a[i], poly[a[i]]++;
	auto poly2 = poly;
	poly = conv(poly, poly2);
	int ans = 0;
	for (int i = (int) 2e5; i >= 0; --i) {
		int use = min(m, (int) round(poly[i]));
		m -= use;
		ans += use * i;
	}
	cout << ans;
}


Measured memory_bytes: 26876
#include <iostream>
#include <vector>

using ll = long long;
#define rep(i,n) for(int i = 0;i < (n);++i)
constexpr int mod {1000000007};
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

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

int main() {
  ll n, a, b;
  std::cin >> n >> a >> b;
  mint answer(2);
  answer = answer.pow(n);
  //std::cout << answer.x << '\n';
  answer -= 1;
  mint minus(1);
  mint x=1, y=1;
  for (ll i = 0;i < a;++i) {
    x *= n-i;
    y *= i+1;
  }
  answer -= x/y;
  x = 1, y = 1;
  for (ll i = 0;i < b;++i) {
    x *= n-i;
    y *= i+1;
  }
  answer -= x/y;
  std::cout << answer.x << '\n';
}


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

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <map>

using namespace std;

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

#define anyfill(n,s) setw(n) << setfill(s)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define pb push_back
#define MAX 1000000000
#define MOD 1000000007

int main(){
  int n;cin>>n;
  string s[n];
  int a = 0;
  int b = 0;
  int ko = 0;
  int hai=0;
  for(int i = 0; n > i; i++){
    cin >> s[i];
    if(s[i][0] == 'B' && s[i][s[i].size()-1] == 'A'){
      hai++;
    }else if(s[i][0] == 'B'){
      b++;
    }else if(s[i][s[i].size()-1] == 'A'){
      a++;
    }
  }
  if(hai != 0){
    ko += hai-1;
    if(a != 0 && b != 0){
      ko+= min(a,b)+1;
    }else if(a != 0 || b != 0){
      ko++;
    }
  }else{
    ko+= min(a,b);
  }
  for(int i = 0; n > i; i++){
    for(int j = 1; s[i].size() > j; j++){
      if(s[i][j-1] == 'A' && s[i][j] == 'B')ko++;
    }
  }
  cout << ko << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
const ll KEY = 998244353;
using namespace std;

int main(){
  int N,K;
  string s;
  cin >> N >> s >> K;
  char key = s[K-1];
  rep(i,N){
    if(s[i]!=key) s[i] = '*';
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		int n,c;
		cin>>n;
		int v[30];
		for (int i = 1; i < n+1; ++i)
		{
			cin>>v[i];
		}
		int ans=0;
		for (int i = 1; i < n+1; ++i)
		{
			cin>>c;
			ans+=(v[i]-c>0?v[i]-c:0);
		}
		cout<<ans;
		return 0;
	}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){ 
int count=0;
int res=0;
string s;
cin>>s;
for(char c:s){
if(c=='S')
  count++;
else if(c=='T')
  count--;
if(count<0){
  res++;
  count=0;
}
}
 cout<<2*res<<endl;
}


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

int64_t N, A[300000], ans, MOD = 1e9 + 7;

int main() {
    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, 60) {
        int64_t c0 = 0, c1 = 0, bit = (1L << i);
        rep(j, N) {
            if (A[j] & bit) c1++;
            else c0++;
        }
        ans += bit % MOD * c0 % MOD * c1;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String[] weather = {"Sunny", "Cloudy", "Rainy"};
    int i=0;
    if(s.equals("Sunny")) i=1;
    if(s.equals("Cloudy")) i=2;
    if(s.equals("Rainy")) i=0;
    System.out.println(weather[i]);
  }
}

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

using namespace std;
const int maxn=100005;
int h[maxn],mem;
struct
{
    int v,next;
}e[maxn];
void add(int u,int v)
{
    e[mem].v=v;
    e[mem].next=h[u];
    h[u]=mem++;
}
int n,k;
int ans=0;
int dfs(int u,int fa)
{
    int deep=0;
    for(int i=h[u];i+1;i=e[i].next)
    {
        int v=e[i].v;
        deep=max(deep,1+dfs(v,u));
    }
    if(deep==k-1){
        if(fa==1) return 0;
        else {
            ans++;return -1;
        }
    }
    return deep;
}
int main()
{
    scanf("%d%d",&n,&k);
    memset(h,-1,sizeof(h));mem=0;
    int x;
    scanf("%d",&x);
    if(x!=1) ans++;
    for(int i=2;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        add(x,i);
    }
    for(int i=h[1];i+1;i=e[i].next)
    {
        int v=e[i].v;
        dfs(v,1);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 6144
#include<stdio.h>
int main(void) {
	char s[5];
	int c[4] = {0,0,0,0};
	scanf("%s", s);
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			if (s[i] == s[j] && i!=j) {
				c[i]++;
			}
		}
	}
	if (c[0] == 1 && c[1] == 1 && c[2] == 1 && c[3] == 1) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}









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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  int q;
  cin >> q;
  while(q--) {
    int b, e;
    cin >> b >> e;
    reverse(a.begin()+b, a.begin()+e);
  }
  for(int i = 0; i < n; ++i) cout << a[i] << " \n"[i==n-1];
  return 0;
}



Measured memory_bytes: 3056
A=[0]*9
for i in range(3):
    A[i*3:i*3+3]=input().split()
for i in range(int(input())):
    b=input()
    for j in range(9):
        if A[j]==b:
            A[j]="0"
s="012345678036147258048246"
a=f=0
for i in range(24):
    a+=int(A[int(s[i])])
    if i%3==2:
        if a==0:
            f+=1
        a=0
if f>0:
    print("Yes")
else:
    print("No")

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();
      int[] arr = new int[n];
      int min = Integer.MAX_VALUE;
      int max = Integer.MIN_VALUE;
      int minIdx = 0, maxIdx = 0;

      for(int i = 0; i < n; i++) {
        arr[i] = sc.nextInt();
        if(arr[i] < min) {
          min = arr[i];
          minIdx = i;
        }
        if(arr[i] > max) {
          max = arr[i];
          maxIdx = i;
        }
      }
	  System.out.println(2*n-1);
      if(min < 0 && Math.abs(min) > Math.abs(max)) { // neg
        for(int i = 0; i < n; i++) {
          arr[i] += min;
          System.out.println((minIdx+1) + " " + (i+1));
        }
        for(int i = n-1; i >= 1; i--) {
          arr[i-1] += arr[i];
          System.out.println((i+1) + " " + i);
        }
      } else {
        for(int i = 0; i < n; i++) {
          arr[i] += max;
          System.out.println((maxIdx+1) + " " + (i+1));
        }
        for(int i = 1; i < n; i++) {
          arr[i] += arr[i-1];
          System.out.println(i + " " + (i+1));
        }
      }
  }
}


Measured memory_bytes: 21844
n,m,r=map(int,input().split())
r=list(map(int,input().split()))
r=[t-1 for t in r]
abc=[list(map(int,input().split())) for _ in range(m)]
d=[[2**30 for _ in range(n)] for _ in range(n)]
for t in abc:
    d[t[0]-1][t[1]-1]=t[2]
    d[t[1]-1][t[0]-1]=t[2]
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
from itertools import permutations
res=[]
for t in permutations(r):
    ans=0
    for i in range(1,len(r)):
        ans+=d[t[i-1]][t[i]]
    res.append(ans)
print(min(res))

Measured memory_bytes: 51288
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;

signed main(){
  int N, K; cin >> N >> K;
  vector<P> vec;
  for(int i = 0; i < N; i++){
    int a, b; cin >> a >> b; vec.push_back(P(a, b));
  }
  sort(vec.begin(), vec.end());
  int sum = 0;
  int i = 0;
  while(sum < K && i < N){
    sum += vec[i].second;
    i++;
  }
  cout << vec[i - 1].first << endl;
}

Measured memory_bytes: 2420
#include "bits/stdc++.h"
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    fastio;
    string s;
    cin>>s;
    int sum=0;
    vector<int>cnt(2019);
    cnt[0]++;
    ll ans=0,p=1;
    for(int i=s.size()-1;i>=0;--i){
        sum += (s[i]-'0')*p;
        sum %= 2019;
        ans += cnt[sum];
        ++cnt[sum];
        p*=10;
        p%=2019;
    }
    cout<<ans;
}


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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int main(){
  int n,m;
  int sum=0;
  cin>>n>>m;
  int h[n+1];
  int v[n+1];
  memset(v,-1,sizeof(v));
  for(int i=1;i<=n;i++){
    int tmp;
    cin>>tmp;
    h[i]=tmp;
  }
  REP(i,m){
    int a,b;
    cin>>a>>b;
    if(h[a]<h[b]){
      v[a]=0;
    }else if(h[a]>h[b]){
      v[b]=0;
    }else{
      v[a]=0;
      v[b]=0;
    }

  }
  REP(i,n){
    if(v[i+1]==-1){
      sum++;
    }
    //cout<<v[i+1]<<endl;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 4404
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int cmp(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}

void run(void){
  int n,c,k;
  scanf("%d%d%d",&n,&c,&k);
  int *t=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++) scanf("%d",t+i);
  qsort(t,n,sizeof(int),cmp);
  int cnt=0;
  for(i=0;i<n;i++){
    int j=i;
    while(j<n && j-i<c && t[j]-t[i]<=k) j++;
    cnt++;
    i=j-1;
  }
  printf("%d\n",cnt);
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<string>
#include<stdio.h>
#include<cmath>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    int num[10] = {0,2,5,5,4,5,6,3,7,6};
    
    int n, m; cin >> n >> m;
    vector<int> a;
    rep(i, m) { int x; cin >> x; a.push_back(x); }
    sort(all(a), greater<int>());

    int dp[10005];
    dp[0] = 0;
    repn(i, n){
        dp[i] = -1;
        rep(j, m){
            if(i - num[a[j]] >= 0 && dp[i - num[a[j]]] >= 0){
                dp[i] = max(dp[i], dp[i - num[a[j]]] + 1);
            }
        }
    }

    string ans = "";
    int d = dp[n];
    rep(i, d){
        rep(j, m){
            if(n - num[a[j]] >= 0 && dp[n - num[a[j]]] == dp[n] - 1){
                ans = ans + to_string(a[j]);
                n -= num[a[j]];
                break;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 632
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1000000;
int cost[101][101],ttime[101][101];
int main(){
	int n,m;
	while(cin >> n >> m,n || m){
		int a,b,icost,itime,c,r;
		for(int i = 0;i <= m;++i){
			for(int j = 0;j <= m;++j){
				if(i == j) {
					cost[i][i] = 0;
					ttime[i][i] = 0;
				}
				else {
					cost[i][j] = INF;
					ttime[i][j] = INF;
				}
			}
		}
		for(int i = 0;i < n;++i){
			cin >> a >> b >> icost >> itime;
			cost[a][b] = cost[b][a] = icost;
			ttime[a][b] = ttime[b][a] = itime;
		}
		for(int k = 0;k <= m;++k){
			for(int i = 0;i <= m;++i){
				for(int j = 0;j <= m;++j){
					ttime[i][j] = min(ttime[i][j],ttime[i][k] + ttime[k][j]);
					cost[i][j] = min(cost[i][j],cost[i][k] + cost[k][j]);
				}
			}
		}
		cin >> c;
		for(int i = 0;i < c;++i){
			cin >> a >> b >> r;
			if(r == 1) cout << ttime[a][b] << endl;
			else cout << cost[a][b] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 948
#include<bits/stdc++.h>
using namespace std;
int main(){
	int h,w;cin>>h>>w;
	string s[h+2];

	string t="";
	for(int i=0;i<w+2;i++){
		t+='x';
	}
	s[0]=t;
	s[h+1]=t;
	for(int i=1;i<=h;i++){
		cin>>s[i];
		s[i]+='x';
		s[i]='x'+s[i];
		// cout<<s[i]<<endl;
	}

	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){

			if(s[i][j]!='.')continue;
			int cnt = 0;
			//check upper 3
			if( s[i-1][j-1]=='#' )cnt++;
			if( s[i-1][j+1]=='#' )cnt++;
			if( s[i-1][j]=='#' )cnt++;

			//check lower 3
			if( s[i+1][j-1]=='#' )cnt++;
			if( s[i+1][j+1]=='#' )cnt++;
			if( s[i+1][j]=='#' )cnt++;

			//check l,r
			if( s[i][j-1]=='#' )cnt++;
			if( s[i][j+1]=='#' )cnt++;

			s[i][j]=cnt+'0';
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cout<<s[i][j];
		}
		cout<<endl;
	}


}

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

int main() {
  int N,M,C;
  cin >> N >> M >> C;
  
  vector<vector<int>> BA(N+1,vector<int>(M));
  for ( int i = 0 ; i < N+1 ; i++ ){
  	for ( int j = 0 ; j < M ; j++){
    	cin >> BA.at(i).at(j);
    }
  }
  
  int cnt = 0 ;
  for ( int i = 1 ; i < N+1 ; i++ ){
    int sum = C ;
  	for ( int j = 0 ; j < M ; j++ ){
    	sum += BA.at(i).at(j) * BA.at(0).at(j);
    }  
    if ( sum > 0 )cnt++;
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256