akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
vector<vector<char>> masu, temp;
int h, w, n;

bool check() {
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w;j++) {
			if (temp[i][j] != '.')return false;
		}
	}
	return true;
}

void fall() {
	for (int i = h - 1; i > 0;i--) {
		for (int j = w - 1; j >= 0; j--) {
			if (temp[i][j] != '.') continue;
			for (int k = i - 1; k >= 0;k--) {
				if (temp[k][j] == '.')continue;
				temp[i][j] = temp[k][j];
				temp[k][j] = '.';
				break;
			}
		}
	}
}

bool erase() {
	vector<vector<int>> f(h, vector<int>(w, 0));

	for (int i = 0; i < h;i++) {
		for (int j = 0; j < w;j++) {
			if (temp[i][j] == '.') continue;
			int Count = 0;
			for (int k = j;k < w;k++) {
				if (temp[i][j] == temp[i][k]) Count++;
				else break;
			}
			if (Count >= n) {
				for (int k = j;k < w;k++) {
					if (temp[i][j] == temp[i][k]) f[i][k] = 1;
					else break;
				}
			}
			Count = 0;
			for (int k = i;k < h;k++) {
				if (temp[i][j] == temp[k][j]) Count++;
				else break;
			}
			if (Count >= n) {
				for (int k = i;k < h;k++) {
					if (temp[i][j] == temp[k][j]) f[k][j] = 1;
					else break;
				}
			}
		}
	}
	bool ret = false;
	for (int i = 0; i < h;i++) {
		for (int j = 0; j < w;j++) {
			if (f[i][j] == 1) {
				temp[i][j] = '.';
				if (!ret) ret = true;
			}
		}
	}
	return ret;
}

bool solve() {
	fall();
	while (true) {
		if (!erase())break;
		fall();
	}
	return check();
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	cin >> h >> w >> n;
	masu.resize(h, vector<char>(w));
	for (int i = 0; i < h;i++) for (int j = 0; j < w;j++) cin >> masu[i][j];

	for (int i = 0; i < h;i++) {
		for (int j = 0; j < w - 1;j++) {
			if (masu[i][j] == masu[i][j + 1]) continue;
			temp = masu;
			swap(temp[i][j], temp[i][j + 1]);

			if (solve()) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 3180
def main
  n = gets.to_i
  tasks = []
  n.times {tasks << gets.split.map(&:to_i)}
  tasks.sort! {|a, b| a[1] <=> b[1]}
  t = 0
  flag = true
  tasks.each do |a, b|
    t += a
    flag = false if b < t
  end

  if flag
    puts "Yes"
  else
    puts "No"
  end
end

main if $0 == __FILE__


Measured memory_bytes: 18556
#include <stdio.h>
int main(){
   char a[12],b[12],c[12];scanf("%s%s%s",a,b,c);
   if((a[strlen(a)-1]==b[0])&&(b[strlen(b)-1]==c[0]))printf("YES");
   else printf("NO");
   //printf("%c %c %c %c",a[strlen(a)-1],b[0],b[strlen(b)-1],c[0]);
   return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

const int N = 1e2+5;

int a[N];

int main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    sort(a, a+n);

    int ans = 0;
    for(int i = 0; i<n; i++){
        for(int j = i+1; j<n; j++){
            for(int k = j+1; k<n; k++){
                if(a[i] + a[j] > a[k] && ((a[i] != a[j]) && (a[i] != a[k]) && (a[j] != a[k]))){
                    ans++;
                }
            }
        }
    }

    cout <<ans <<endl;

    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

/*** chmax, chmin ***/
// a < b ならば a を b で更新
// 更新されたら true を返す
template <typename T>
bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
// a > b ならば a を b で更新
// 更新されたら true を返す
template <typename T>
bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
/*** chmax, chmin ここまで ***/

void Main()
{
    int n;
    cin >> n;
  	vector<string> s(n);
  	rep(i,n) cin >> s[i];
    
  	sort(all(s));
  	map<string, int> mp;
  
    rep(i,n){
	  	mp[s[i]]++;
    }

  	int mx = 0;
  	for (auto p:mp){
    	chmax(mx, p.second);
    }
  	
	for (auto p:mp){
    	if(p.second == mx) {
			cout << p.first << endl;
        }
    }
	return;
}

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


Measured memory_bytes: 25472
H1, M1, H2, M2, K = map(int, input().rstrip().split())
minutes = M2 - M1
hours = 0
if minutes < 0:
    minutes += 60
    hours -= 1
hours += H2 - H1
minutes += hours * 60
answer = minutes - K
if answer < 0:
    answer = 0
print(answer)


Measured memory_bytes: 9172
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] a_str = in.readLine().split(" ");
    int[] a = new int[3];
    a[0] = Integer.parseInt(a_str[0]);
    a[1] = Integer.parseInt(a_str[1]);
    a[2] = Integer.parseInt(a_str[2]);
    int min = Math.min(Math.min(a[0],a[1]),a[2]);
    int sum = a[0] + a[1] + a[2];
    int max = Math.max(Math.max(a[0],a[1]),a[2]);
    System.out.println(max-(sum-min-max) + (sum-min-max)-min);
  }
}

Measured memory_bytes: 23124
// 2011/02/17 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n, m;
		cin >> n >> m;
		if(n==0&&m==0)
			break;

		int p[1000];		// ツ姪ャツ催伉づ個値ツ段
		for(int i=0; i<n; i++)
			cin >> p[i];

		// ツソツーツトツ（ツ降ツ渉）
		for(int i=0; i<n-1; i++)
			for(int j=i+1; j<n; j++)
				if(p[i]<p[j]){
					int tmp = p[i];
					p[i] = p[j];
					p[j] = tmp;
				}

		// mツ古つつィツつォツづ可鳴ウツ猟ソツづづ按づゥ
		for(int i=m-1; i<n; i+=m)
			p[i] = 0;

		// ツ債計
		int sum = 0;
		for(int i=0; i<n; i++)
			sum += p[i];

		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,K;
  cin >> A >> B >> C >> K;
  for(int i=0; i<K; i++){
  if(A>B && A>C){
    A *= 2;
  }
   else if(B>A && B>C){
     B *= 2;
   }
    else{
      C *= 2;
    }
  }
  cout << A+B+C << endl;  
}


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

using ll = long long;
using namespace std;

int main() {
    ll K;cin >> K;
    int n = 50;
    vector<ll> v(n);
    for(int i = 0;i < n;i++){
        v[i] = i;
    }
    for(int i = 0;i < n;i++){
        v[i] += K / n;
    }
    for(int i = 0;i < K % n;i++){

        v[i] += n;
        for(int j = 0;j < n;j++){
            if(i != j)v[j]--;
        }
    }
    cout<<n<<endl;
    for(int i = 0;i < n;i++){
        cout<<v[i]<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 3592
import itertools
import collections

n, m = map(int, input().split(" "))
t = [ [-1] * m for i in range(n) ]

NG='#'
OK='.'

ok_list = []
for i in range(n):
    for j,s in enumerate(input()):
        t[i][j] = s
        if s == OK:
            ok_list.append( (i, j ) )


def depth(t, src):
    q = collections.deque()
    deadlist = { src: 0 }
    q.append( (src[0], src[1], 0) )

    while len(q) != 0:
        x, y, cost = q.popleft()
        for _x, _y in [(x+1, y), (x-1,y), (x,y+1),(x,y-1)]:
            if ((_x,_y) not in deadlist ) and \
                ( 0 <= _x < n) and (0 <= _y < m) and t[_x][_y] == OK:
                deadlist[(_x, _y)] = cost+1
                q.append((_x, _y, cost+1))

    return max(deadlist.values())


ans = 0
for src in ok_list:
    tmp = depth(t, src)
    if ans < tmp:
        ans = tmp
print(ans)

Measured memory_bytes: 44780
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll dp[100005][105]={0};
ll pd[100005][105]={0};
int main(){
	ll n,m;cin>>n>>m;
	ll a[n+1];
	for(ll i=1;i<=n;i++)cin>>a[i];
	for(ll i=1;i<=n;i++)dp[0][i]=1;
	for(ll i=0;i<=n;i++)pd[0][i]=1;
	for(ll i=0;i<=m;i++)pd[i][0]=1;
	for(ll i=1;i<=m;i++){
		for(ll j=1;j<=n;j++){
			if(i-a[j]>=1)
			dp[i][j]=(pd[i][j-1]-pd[i-a[j]-1][j-1]+hell)%hell;
			else dp[i][j]=pd[i][j-1]%hell;
			pd[i][j]=(dp[i][j]+pd[i-1][j])%hell;
		}
	}
/*	for(ll i=1;i<=m;i++){
		for(ll j=1;j<=n;j++){
			cout<<dp[i][j]<<" ";
		}cout<<endl;
	}
	for(ll i=1;i<=m;i++){
		for(ll j=1;j<=n;j++){
			cout<<pd[i][j]<<" ";
		}cout<<endl;
	}
	*/
	cout<<dp[m][n];	
}

Measured memory_bytes: 164352
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var a = new int[n];
        var b = new int[n];
        var c = new int[n];
        for (int i = 0; i < n; i++)
        {
            var abc = Console.ReadLine().Split();
            a[i] = int.Parse(abc[0]);
            b[i] = int.Parse(abc[1]);
            c[i] = int.Parse(abc[2]);
        }

        var dp = new int[n + 1, 3];
        for (int i = 0; i < n; i++)
        {
            dp[i + 1, 0] = a[i] + Math.Max(dp[i, 1], dp[i, 2]);
            dp[i + 1, 1] = b[i] + Math.Max(dp[i, 0], dp[i, 2]);
            dp[i + 1, 2] = c[i] + Math.Max(dp[i, 0], dp[i, 1]);
        }

        var ans = Math.Max(Math.Max(
            dp[n, 0],
            dp[n, 1]),
            dp[n, 2]);

        Console.WriteLine(ans);
    }
}


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

int main() {
    int N;
    cin >> N;
    long long ans = 1;
    int mod = 1000000007;
    for (int i = 1; i <= N; i++) {
        ans %= mod;
        ans *= i;
    }
    ans %= mod;
    cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    int ans = 1;
    for (int i = 2; i < n; i++){
        int a = i * i;
        while (a <= n){
            ans = max(a, ans);
            a *= i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

int main() {
    int n, m, mx = 1e5 + 1;
    cin >> n >> m;
    vector<int> x(mx, 0);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        x[a]++;
    }

    int is[m] = {}, pr[m] = {};
    for (int i = 0; i < mx; i++) {
        pr[i % m] += 2 * (x[i] / 2);
        is[i % m] += x[i] % 2;
    }
    for (int i = 0; i < m; i++) cerr << pr[i] _ is[i] << endl;

    int ans = 0;
    for (int i = 1; 2 * i < m; i++) {
        int k = min(is[i], is[m - i]);
        ans += k;
        is[i] -= k;  is[m - i] -= k;
    }
    ans += (is[0] + pr[0]) / 2;
    if (m % 2 == 0) {
        ans += (is[m / 2] + pr[m / 2]) / 2;
    }

    for (int i = 1; 2 * i < m; i++) {
        if (is[i] == 0) {
            int k = is[m - i];
            ans += min(k, pr[i]);
            pr[i] -= min(k, pr[i]);
            ans += (pr[i] + pr[m - i]) / 2;
        }
        else {
            int k = is[i];
            ans += min(k, pr[m - i]);
            pr[i] -= min(k, pr[m - i]);
            ans += (pr[i] + pr[m - i]) / 2;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,p;
int a[103];
LL dp[50+3][2];
int main(){
	scanf("%d%d",&n,&p);
	for (int i=1;i<=n;i++) {
		scanf("%d",a+i);
		a[i]&=1;
	}
	dp[0][0]=1;
	for (int i=1;i<=n;i++){
		for (int j=0;j<=1;j++){
			dp[i][j]=0;
			for (int k=0;k<i;k++){
				dp[i][j]+=dp[k][j^a[i]];
			}
		}
	}
	LL ans=0;
	for (int i=0;i<=n;i++) ans+=dp[i][p];
	cout << ans << endl;
	return 0;
}


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

using namespace std;

using Int = long long;
using P = pair<int, int>;

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-9;

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  int hole = 1;
  for (int i = 0; i < 20; ++i) {
    if (hole >= B) break;
    hole += A - 1;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  char c;
  cin >> c;
  
  if ( c =='a'||c =='i'||c =='u'||c =='e'||c =='o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

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

  int A[500001],n;

void maxHeapify(int i){
  int l,r,largest,tmp;
 l=i*2;
  r=i*2+1;
  if(l<=n && A[l]>A[i])largest=l;
  else largest=i;

  if(r<=n && A[r]>A[largest])largest=r;
  if(largest!=i){tmp=A[i],A[i]=A[largest],A[largest]=tmp; maxHeapify(largest);}
}

void buildMaxHeap(){
  for(int i=n/2;i>=1;i--)maxHeapify(i);
}

int main(){
  cin>>n;
  for(int i=1;i<=n;i++)cin>>A[i];
  buildMaxHeap();
  for(int i=1;i<=n;i++)cout<<" "<<A[i];
  cout<<endl;

  return 0;
}

Measured memory_bytes: 3108
N=int(input())
a=list(map(int,input().strip().split()))

i=0
j=1
exe=False
for n in range(N):
    if a[n]!=j:
        i+=1
            
    else:
        exe=True
        j+=1

if exe==False:
    print(-1)
else:
    print(i)

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

typedef long long ll;

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans = 0;
    for(int i = 1; i < N-1; i++){
        int tmpans = 0;
        string s1,s2;
        s1 = S.substr(0, i);
        s2 = S.substr(i, N-i); 
        map<char, bool> m1,m2;
        for(auto c: s1){
            m1[c] = true;
        }
        for(auto c: s2){
            m2[c] = true;
        }
        for(auto x: m1){
            if(m2.count(x.first) != 0){
                tmpans++;
            }
        }
        if(tmpans > ans){
            ans = tmpans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	ll A, B, C, K;
	cin >> A >> B >> C >> K;

	ll ans = 0;
	ans += min(A, K);
	K -= min(A, K);
	K -= min(B, K);
	ans -= min(C, K);

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;

ll num[200010]={0};

int main(void){
    ll n;
    cin>>n;
    vector<ll>a(n+1),b(n+1),c;
    for(ll i=0;i<n;i++)cin>>a[i+1];
    for(ll i=n;i>=1;i--){
        if(num[i]%2==0){
            if(a[i]==0)b[i]=0;
            else{
                b[i]=1;
                for(ll j=1;j<=(ll)sqrt(i);j++){
                    if(i%j==0){
                        num[j]++;
                        if(j==i/j)continue;
                        num[i/j]++;
                    }
                }
            }
        }
        else{
            if(a[i]==1)b[i]=0;
            else{
                b[i]=1;
                for(ll j=1;j<=(ll)sqrt(i);j++){
                    if(i%j==0){
                        num[j]++;
                        if(j==i/j)continue;
                        num[i/j]++;
                    }
                }
            }
        }
    }
    for(ll i=1;i<=n;i++){
        if(b[i])c.push_back(i);
    }
    if((ll)c.size()==0){
        cout<<0<<endl;
        return 0;
    }
    cout<<(ll)c.size()<<endl;
    for(ll i=0;i<(ll)c.size();i++){
        if(i==(ll)c.size()-1)cout<<c[i]<<endl;
        else cout<<c[i]<<" ";
    }
    return 0;
}

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

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

using ll = long long int;
using ld = long double;
using pii = pair<int,int>;

#define REP(i,m,n) for(ll i = m; i < (ll)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
 
using vi=vc<int>;

const ll mod=1e9+7;
const ll INF = 1e18;

int main(){
  int n;cin >>n;
  int k;cin >>k;
  ll h[101000];
  REP(i,1,n+1) cin >> h[i];
  ll dp[101000];
  rep(i,100500) dp[i]=INF;
  dp[1]=0;
  
  rep(i,n){
    REP(j,1,k+1){
      chmin(dp[i+j],dp[i]+labs(h[i]-h[i+j]));}
  }
  cout << dp[n];
}

  

Measured memory_bytes: 1792
/*
Princess's Marriage
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2019&lang=jp
20:10
*/

#include<iostream>
#include<algorithm>
#include<vector>

using std::cout;
using std::cin;
using std::vector;
using std::pair;
using std::sort;
using std::min;

#define INF 999999999;


long long int N, M;
vector<pair<int, int>> DaP; //(Dn, Pn)
long long int ans;

int main(void){
	cin.tie(0);
	std::ios::sync_with_stdio(false);
	do{
		cin >> N >> M;
		if(N == 0 && M == 0)break;
		for(int i = 0; i < N; i++){
			pair<int, int> inn;
			cin >> inn.first >> inn.second;
			ans += inn.first * inn.second;
			DaP.push_back(inn);
		}
		sort(DaP.begin(), DaP.end(), [](pair<int, int> a, pair<int, int> b){return a.second > b.second;});
		int i = 0;
		while(M > 0){
			long long int minus = min(M, (long long int)DaP[i].first);
			ans -= DaP[i].second * minus;
			M -= minus;
			i++;
			if(i == DaP.size()) break;
		}
		cout << ans << "\n";
		ans = 0;
		DaP.clear();

	} while(true);


	return 0;
}




Measured memory_bytes: 3232
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)

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

#define MAX 250000
bool prime[MAX];

void erat()
{
	fill(prime, prime+MAX, true);
	prime[0] = false;
	prime[1] = false;
	for (int i = 2; i < MAX; i++)
		for (int j = 2*i; j < MAX; j += i)
			prime[j] = false;
}

int main(void)
{
	int n;
	erat();
	while (cin >> n, n) {
		int cnt = 0;
		REPI(i, n+1, 2*n) if (prime[i]) cnt++;
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define F(i,a,b) for(int i= (int)(a); i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define what_is(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
const int N = 1e6+7 ;

int main(){fast ;
	int n , m , k ;
	cin >> n >> m >> k ;
	int x = n , y = m ;
	int cnt[101] = {0} ;
	FI(i,1,x)
		if(n%i == 0)
			cnt[i]++ ;
	FI(i,1,y)
		if(m%i == 0)
			cnt[i]++ ;
	int tmp = 0 ;
	int res = 0 ;
		for(int i = 100 ; i >= 0 ; i--){
			if(cnt[i] == 2)
				tmp++ ;
			if(tmp == k){
				res = i ;
				break ;
			}
		}
		cout << res << endl ;
}




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

int main() {
  int N, X, T, k, l;
  cin >> N >> X >> T;
  
  k = N / X;
  l = N % X;
  
  if (l == 0)
    cout << k * T << endl; 
  
  if (l != 0)
    cout << k * T + T << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

char t[200010];
char d[200010];
int n, q;
string s;

int sim(int idx){
    rep(i, q){
        if (s[idx] == t[i]){
            if (d[i] == 'R') idx++;
            else idx--;
        }
        if (idx == n+1) return n+1;
        else if (idx == 0) return 0;
    }
    return idx;
}

ll binary_search1() {
    ll ng = -1;
    ll ok = n+1;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (sim(mid) == n+1) ok = mid;
        else ng = mid;
    }
    return ok;
}

ll binary_search2() {
    ll ng = n+1;
    ll ok = -1;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (sim(mid) == 0) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
    cin >> n >> q;
    cin >> s;
    rep(i, q) cin >> t[i] >> d[i];
    s = '?' + s;
    s = s + '?';

    cout << binary_search1() - binary_search2() - 1 << endl;

    return 0;
}


Measured memory_bytes: 4328
#include<iostream>
using namespace std;
int main(){
    int a,b,c,t;
    cin>>a>>b>>c;
    if(a>b){
        t=a;
        a=b;
        b=t;
    }
    if(b>c){
        t=b;
        b=c;
        c=t;
    }
    if(a>b){
        t=a;
        a=b;
        b=t;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
    
    return 0;
}


Measured memory_bytes: 3048
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
using namespace std;

class DisjointSet {/*{{{*/
  private:
    vector<int> parent;

    int root(int x)
    {
      if (parent[x] < 0) {
        return x;
      } else {
        return parent[x] = root(parent[x]);
      }
    }

  public:
    DisjointSet(int n) : parent(n, -1) {}

    bool unite(int x, int y)
    {
      x = root(x);
      y = root(y);
      if (x != y) {
        if (parent[x] > parent[y]) {
          swap(x, y);
        }
        parent[x] += parent[y];
        parent[y] = x;
        return true;
      } else {
        return false;
      }
    }

    bool find(int x, int y)
    {
      return root(x) == root(y);
    }

    int size(int n)
    {
      return -parent[root(n)];
    }
};/*}}}*/

struct edge {
  int u, v, w;
  bool operator<(const edge& e) const
  {
    return w < e.w;
  }
};

int solve(int N, const vector<edge>& edges)
{
  int ans = numeric_limits<int>::max();
  for (vector<edge>::const_iterator it(edges.begin()); it != edges.end(); ++it) {
    DisjointSet s(N);
    s.unite(it->u, it->v);
    int w = 0;
    for (vector<edge>::const_iterator jt(it+1); s.size(0) < N; ++jt) {
      if (jt == edges.end()) {
        goto FAIL;
      }
      if (s.unite(jt->u, jt->v)) {
        w = max(w, jt->w - it->w);
      }
    }
    ans = min(ans, w);
FAIL:
    ;
  }
  return ans == numeric_limits<int>::max() ? -1 : ans;
}

int main()
{
  int n, m;
  while (cin >> n >> m && n != 0) {
    vector<edge> edges(m);
    for (int i = 0; i < m; i++) {
      cin >> edges[i].u >> edges[i].v >> edges[i].w;
      --edges[i].u; --edges[i].v;
    }
    sort(edges.begin(), edges.end());
    cout << solve(n, edges) << endl;
  }
  return 0;
}

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;



int main()
{
	
	int n;
	cin >>n;
	vector<ll> a(n), b;
	rep(i,n) cin >>a[i];
	b=a;
	ll sm=0;
	repr(i,56,0){
		ll p = (1LL<<i);
		for(;;){
			auto mi = max_element(all(b));
			if(*mi < p * n) break;
			sm += p;
			*mi -= p * n + p;
			rep(j,n) b[j] += p;
		}
		
	}
	//for(auto x :b) printf("%lld, ",x); puts("");
	cout << sm << endl;
	return 0;
}


Measured memory_bytes: 256
N,M,K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
AA = [0]
BB = [0]
r = 0
for i in A:
    r += i
    AA.append(r)
r = 0
for i in B:
    r += i
    BB.append(r)
ans = 0
a = N
b = 0
while AA[a]+BB[b] > K:
    a -= 1
ans = a+b

while a >= 0:
    while b < M:
        if AA[a]+BB[b+1] <= K:
            b += 1
        else:
            break
    if ans < a+b:
        ans = a+b
    if b == M:
        break
    a -= 1
print(ans)



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

int main(void){
	int m, n;
	
	while(cin >> m >> n, m+n){
		vector<int> v (7368791);
		int now = m, cnt = 0;
		while(1){
			v[now] = true;
			for(int i = 2; i*now <= 7368791; ++i){
				v[now*i] = true;
			}
			while(v[now]) now++;
			cnt++;
			if(cnt == n)break;
		}
		cout << now << endl;
	}
	return 0;
}


Measured memory_bytes: 31868
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    int HEIGHT;
    int WIDTH;

    private void solve() {
        Scanner sc = new Scanner(System.in);
        HEIGHT = sc.nextInt();
        WIDTH = sc.nextInt();

        char[][] masu = new char[HEIGHT][WIDTH];
        for (int i = 0; i < HEIGHT; i++) {
            String S = sc.next();
            char[] S_Array = S.toCharArray();
            int j = 0;
            for (char ch : S_Array) {
                masu[i][j] = ch;
                j++;
            }
        }
        int ans = 0;
        int[][] left  = getLeft(masu);
        int[][] right = getRight(masu);
        int[][] down  = getDown(masu);
        int[][] up    = getUp(masu);
        for (int i = 0; i < HEIGHT; i++) {
            for (int j = 0; j < WIDTH; j++) {
                int tmp = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3;
                ans = Math.max(ans, tmp);
            }
        }
        System.out.print(ans);
    }

    private int[][] getLeft(char[][] masu) {
        int[][] left = new int[HEIGHT][WIDTH];
        for (int i = 0; i < HEIGHT; i++) {
            for (int j = 0; j < WIDTH; j++) {
                if (masu[i][j] == '#') {
                    left[i][j] = 0;
                }
                else if (j == 0) {
                    left[i][j] = 1;
                }
                else {
                    left[i][j] = left[i][j - 1] + 1;
                }
            }
        }
        return left;
    }

    private int[][] getRight(char[][] masu) {
        int[][] right = new int[HEIGHT][WIDTH];
        for (int i = 0; i < HEIGHT; i++) {
            for (int j = WIDTH - 1; j >= 0; j--) {
                if (masu[i][j] == '#') {
                    right[i][j] = 0;
                }
                else if (j == WIDTH - 1) {
                    right[i][j] = 1;
                }
                else {
                    right[i][j] = right[i][j + 1] + 1;
                }
            }
        }
        return right;
    }

    private int[][] getUp(char[][] masu) {
        int[][] up = new int[HEIGHT][WIDTH];
        for (int j = 0; j < WIDTH; j++ ) {
            for (int i = HEIGHT - 1; i >= 0 ; i--) {
                if (masu[i][j] == '#') {
                    up[i][j] = 0;
                }
                else if (i == HEIGHT - 1) {
                    up[i][j] = 1;
                }
                else {
                    up[i][j] = up[i + 1][j] + 1;
                }
            }
        }
        return up;
    }
    private int[][] getDown(char[][] masu) {
        int[][] down = new int[HEIGHT][WIDTH];
        for (int j = 0; j < WIDTH; j++ ) {
            for (int i = 0; i < HEIGHT; i++) {
                if (masu[i][j] == '#') {
                    down[i][j] = 0;
                }
                else if (i == 0) {
                    down[i][j] = 1;
                }
                else {
                    down[i][j] = down[i - 1][j] + 1;
                }
            }
        }
        return down;
    }

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

}


Measured memory_bytes: 143752
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
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 MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

class PrimeFactor {
private:
    map<uint64_t , uint> factor_result;
    const uint64_t data;

public:
    PrimeFactor(uint64_t data) : data(data) {
        uint64_t calc_base = data;
        for (uint64_t index = 2; index * index <= calc_base; index++) {
            while (calc_base % index == 0) {
                factor_result[index]++;
                calc_base /= index;
            }
        }
        if (calc_base != 1) factor_result[calc_base]++;
    }

    map<uint64_t, uint> &query() { return factor_result; }
};

int main() {
    ll N;
    cin >> N;
    PrimeFactor info(N);
    ll ans = 0;
    for (auto now : info.query()) {
        ll times = 1;
        while (now.second >= times * (times + 1) / 2) times++;
        ans += times - 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()0
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!
vector<int> primes;
bool isPrime[maxx+1];

void sieve(){
    primes.clear();
    memset(isPrime,true,sizeof(isPrime));
    isPrime[0]=isPrime[1]=false;
    for(int i=2;i*i<=maxx;i++){
        if(isPrime[i]){
            for(int j=i*i;j<maxx;j+=i){
                isPrime[j]=false;
            }
        }
    }
    primes.push_back(2);
    for(int i=3;i<maxx;i+=2){
        if(isPrime[i]){
            primes.push_back(i);
        }
    }
}

// bool isPrime(int n){
//     if(n==2){return 1;}
//     if(n%2==0){return 0;}
//     if(n<2){return 0;}
//     for(int i=3;i*i<=n;i+=2){
//         if(n%i==0){
//             return false;
//         }
//     }
//     return 1;
// }
int nextPrime(int n){
    sieve();
    return *upper_bound(all(primes),n-1);
}
void solve(){
    int n;
    cin>>n;
    cout<<nextPrime(n);
}

 
int main() {
    faster;
    int t=1;
    // cin>>t;
    
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 4832
__asm__ ( "                        \n\
        .comm   b,1,1              \n\
.L0:                               \n\
        .string \"%c\"             \n\
        .globl  main               \n\
main:                              \n\
        pushq   %rbp               \n\
        leaq    b(%rip), %rsi      \n\
        leaq    .L0(%rip), %rdi    \n\
        call    __isoc99_scanf@PLT \n\
        movzbl  b(%rip), %eax      \n\
        movsbl  %al, %eax          \n\
        cmpl    $65, %eax          \n\
        je      .LA                \n\
        cmpl    $67, %eax          \n\
        je      .LC                \n\
        cmpl    $71, %eax          \n\
        je      .LG                \n\
        cmpl    $84, %eax          \n\
        je      .LT                \n\
        jmp     .LEND              \n\
.LA:                               \n\
        movl    $84, %edi          \n\
        call    putchar@PLT        \n\
        jmp     .LEND              \n\
.LC:                               \n\
        movl    $71, %edi          \n\
        call    putchar@PLT        \n\
        jmp     .LEND              \n\
.LG:                               \n\
        movl    $67, %edi          \n\
        call    putchar@PLT        \n\
        jmp     .LEND              \n\
.LT:                               \n\
        movl    $65, %edi          \n\
        call    putchar@PLT        \n\
.LEND:                             \n\
        movl    $0, %eax           \n\
        popq    %rbp               \n\
        ret                        \n\
" );


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

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var sch = new List<int>[30];
            for (int i = 0; i < 30; i++) sch[i] = new List<int>();
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var t = int.Parse(line[0]);
                for (int j = 1; j <= t; j++)
                {
                    var w = int.Parse(line[j]) - 1;
                    sch[w].Add(i);
                }
            }
            Console.WriteLine(getAns(sch, setMap(n)));
        }
    }
    public static long[] setMap(int n)
    {
        var ret = new long[n];
        for (int i = 0; i < n; i++)
        {
            var w = "1" + new string('0', i);
            ret[i] = Convert.ToInt64(w, 2);
        }
        return ret;
    }
    public static int getAns(List<int>[] sch, long[] map)
    {
        var n = map.Length;
        var w = Convert.ToInt64(new string('1', n), 2);

        for (int i = 0; i < 30; i++)
        {
            var ret = 0L;
            foreach (var x in sch[i])
                ret = ret | map[x];
            if (ret == w) return i + 1;
            foreach (var x in sch[i]) map[x] = ret;
        }
        return -1;
    }
}



Measured memory_bytes: 9712
use std::collections::HashMap;

use proconio::input;

fn primes() -> impl Iterator<Item = i64> {
    let mut multiples = HashMap::with_capacity(10000);
    let iter = (3..).step_by(2).filter_map(move |i| {
        let (prime_or_none, factor) = match multiples.remove(&i) {
            Some(f) => (None, f),
            None => (Some(i), i * 2),
        };

        (1..)
            .map(|j| i + j * factor)
            .skip_while(|m| multiples.contains_key(m))
            .next()
            .map(|m| multiples.insert(m, factor));

        prime_or_none // filter_map()は次の素数が見つかるまでリトライする。
    });
    // 最初に2を返してから、他の素数を返す。
    Box::new((2..).take(1).chain(iter))
}


fn main() {
    input!{
        mut n: i64,
    };
    let end = (n as f64).sqrt().ceil() as i64;
    let mut p = HashMap::new();
    for i in primes() {
        if i > end {
            break;
        }
        while n % i == 0 {
            *p.entry(i).or_insert(0) += 1;
            n /= i;
        }
        if n == 1 {
            break;
        }
    }
    if n != 1 {
        *p.entry(n).or_insert(0) += 1;
    }
    let mut ans = 0;
    for &m in p.values() {
        let mut m = m;
        for i in 1.. {
            m -= i;
            if m >= 0 {
                ans += 1;
            } else {
                break;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5788
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) (v).begin(), (v).end()
const char newl = '\n';

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

  ll n;
  cin >> n;
  
  vl a(n);
  rep(i, n) cin >> a[i];
  sort(all(a), greater<ll>());
  
  vl sides;
  rep(i, n) if(a[i]==a[i+1]) {
      sides.push_back(a[i]);
      i++;
  }
  
  cout << (sides.size()>=2 ? sides[0] * sides[1] : 0LL) << newl;
  return 0;
}


Measured memory_bytes: 4560
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

using namespace std;

const double g=10.0,eps=1e-7;
const int N=1000+10,maxn=60000+10,inf=0x3f3f3f;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    ll ans1=1,ans2=-1;
    for(ll i=0;i<=40;i++)
    {
        for(ll j=0;j<=40;j++)
        {
            for(ll k=0;k<=1500;k++)
            {
                for(ll l=0;l<=1500;l++)
                {
                    if((i*a+j*b)*100+k*c+l*d>f)break;
                    if((i*a+j*b)*e<k*c+l*d)break;
                    ll te1=(i*a+j*b)*100+k*c+l*d;
                    ll te2=k*c+l*d;
                    if(te1*ans2<te2*ans1)
                    {
                        ans1=(i*a+j*b)*100+k*c+l*d;
                        ans2=k*c+l*d;
                    }
                }
            }
        }
    }
    cout<<ans1<<" "<<ans2<<endl;
    return 0;
}
/********************

********************/


Measured memory_bytes: 256
#include <iostream>

int dfs(int node, int N, bool *graph[], bool *visited)
{
    // 全て訪問済みかどうか
    bool all_visited = true;
    // 一つでも未訪問があれば false
    for(int i = 0; i < N; i++)
    {
        if(visited[i] == false)
        {
            all_visited = false;
        }
    }

    // 全て訪問出来たらパスの数を+1
    if(all_visited == true)
    {
        return 1;
    }

    // 0か1を返す
    int result = 0;
    for(int i = 0; i < N; i++)
    {
        // 辺がないなら次へ
        if(graph[node][i] == false) continue;
        // 訪問済みなら次へ
        if(visited[i] == true) continue;

        // それ以外なら訪問する
        visited[i] = true;
        // そのノードを訪問して再帰的にdfsを呼び出し
        result += dfs(i, N, graph, visited);

        // このノードを訪問しないパスへ
        visited[i] = false;
    }

    return result;
}

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

    // 隣接行列
    bool graph[N][N];

    // 隣接行列を初期化
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            graph[i][j] = false;
        }
    }

    // 入力
    for(int i = 0; i < M; i++)
    {
        int a, b;
        std::cin >> a >> b;
        graph[a-1][b-1] = true;
        graph[b-1][a-1] = true;
    }

    // 関数に渡すために隣接行列を変換
    bool *g[N];
    for(int i = 0; i < N; i++)
    {
        g[i] = graph[i];
    }

    // 訪問したかどうか記録する配列
    bool visited[N];
    for(int i = 0; i < N; i++)
    {
        visited[i] = false;
    }

    // visited[0]から開始：ノード１
    // dfs() を再帰的に呼び出して有効なルートをカウント
    visited[0] = true;
    std::cout << dfs(0, N, g, visited) << std::endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Reads();
            var maxmoji = "";
            var max = 0;

            var maxhindo = "";
            var hindo = 0;

            for (int i = 0; i < S.Length; i++)
            {
                if (S[i].Length > max)
                {
                    maxmoji = S[i];
                    max = S[i].Length;
                }
                var count = 0;
                for (int j = 0; j < S.Length; j++)
                {
                    if (S[i] == S[j])
                    {
                        count++;
                    }
                }
                if (hindo < count)
                {
                    hindo = count;
                    maxhindo = S[i];
                }
            }
            Write(maxhindo + " ");
            WriteLine(maxmoji);
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



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

using namespace std;
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	
	int a,b,c,d;
	cin >>a >>b >>c >>d;
	cout << min(a,b)+min(c,d) <<"\n";
	return 0;
	
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; ll P; string S; cin >> N >> P >> S;
    if (P==2||P==5){
        ll ans=0;
        for (int i=0;i<N;++i){
            if ((S[i]-'0')%P==0) ans+=i+1;
        }
        cout << ans << '\n';
        return 0;
    }
    vector<ll> po(N+1,1),rui(N+1,0);
    for (int i=0;i<N;++i) po[i+1]=po[i]*10%P;
    for (int i=0;i<N;++i) rui[i+1]=(rui[i]+(ll)(S[i]-'0')%P*po[N-1-i]%P)%P;
    vector<vector<int>> back(P);
    ll now=0;
    back[0].emplace_back(N);
    for (int i=N-1;i>=0;--i){
        now=(now+(ll)(S[i]-'0')%P*po[N-1-i]%P)%P;
        back[now].emplace_back(i);
    }
    for (int i=0;i<P;++i) reverse(back[i].begin(),back[i].end());
    ll sum=rui[N],ans=0;
    for (int i=0;i<N;++i){
        ll need=(sum+P-rui[i])%P;
        ans+=back[need].end()-upper_bound(back[need].begin(),back[need].end(),i);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 5396
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int i = sc.nextInt();
		
		int ans = (N + 1 - i);
   		System.out.println(ans);
		
   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int N = cin.nextInt();
		int Y = cin.nextInt();
		cin.close();

		for (int x=0; x<=N; x++) {
			for (int y=0; y<=N-x; y++) {
				int total = 10000*x + 5000*y + (N-x-y)*1000;
				if (total == Y) {
					System.out.println(x+" "+y+" "+(N-x-y));
					System.exit(0);
				}
			}
		}
		
		System.out.println("-1 -1 -1");
	}

}

Measured memory_bytes: 22724
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    cout<<fixed<<setprecision(12);
    ll n,w;
    cin>>n>>w;
    vector<pair<double,pll>> P(n);
    for(int i=0;i<n;i++){cin>>P[i].S.F>>P[i].S.S; P[i].F=(double)P[i].S.F/(double)P[i].S.S;}
    sort(P.begin(),P.end(),greater<pair<double,pll>>());
    double ans=0;
    int i=0;
    while(w>0 && i<n){
        ans+=(double)P[i].S.F/(double)P[i].S.S*min(w,P[i].S.S);
        w-=min(w,P[i].S.S);
        i++;
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}



Measured memory_bytes: 5204
#include<cstdio>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(void) {
	int N;
	scanf("%d", &N);
	long long A[200100];
	long long sum = 0;
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
		sum += A[i];
	}
	long long divisor = 1000000007;
	for (int i = 0; i < N - 1; i++) {
		sum -= A[i];
		ans += (A[i] * (sum % divisor)) % divisor;
		ans %= divisor;
	}
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;
using Graph = vector<vector<int>>;
int main(){
    int n;
    cin>>n;
    int a=n%1000;
    if(a==0){
        a=1000;
    }
    cout<<1000-a<<endl;


    
}

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

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

    int K;
    cin >> K;

    string S;
    S.size() < N;
    cin >> S;

    if(S.at(K-1)=='A'){
        S.at(K-1)='a';
    }
     if(S.at(K-1)=='B'){
        S.at(K-1)='b';
    } 
    if(S.at(K-1)=='C'){
        S.at(K-1)='c';
    }

    cout << S << endl;

    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
#define rep2(i,a,b) for (int i = (int)(a); i < (int)(b); ++i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr ll INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
const int MAXD = 200010;

ll compare(vector<vector<int>> &A,vector<vector<int>> &B,int sz = MAXD * 2) {
    int ans = INF;
    rep(i,sz) {
        sort(B[i].begin(),B[i].end());
        for (int a:A[i]) {
            int idx = lower_bound(B[i].begin(),B[i].end(),a + 1) - B[i].begin();
            if (idx >= (int)B[i].size()) continue;
            ans = min(ans,B[i][idx] - a);
        }
    }
    return ans;
}

int main() {
    int N; cin >> N;
    vector<vector<int>> XU(MAXD),XD(MAXD),YR(MAXD),YL(MAXD),mR(2*MAXD),mD(2*MAXD),mU(2*MAXD),mL(2*MAXD),aR(2*MAXD),aU(2*MAXD),aD(2*MAXD),aL(2*MAXD);
    rep(i,N) {
        int x,y; char s; 
        cin >> x >> y >> s;
        if (s == 'U') {
            XU[x].push_back(y);
            mU[y - x + MAXD].push_back(x);
            aU[y + x].push_back(x);
        } else if (s == 'R'){
            YR[y].push_back(x);
            mR[y - x + MAXD].push_back(x);
            aR[y + x].push_back(x);
        } else if (s == 'D') {
            XD[x].push_back(y);
            mD[y - x + MAXD].push_back(x);
            aD[y + x].push_back(x);
        } else {
            YL[y].push_back(x);
            mL[y - x + MAXD].push_back(x);
            aL[y + x].push_back(x);
        }
    }
    ll ans = INF;
    ans = min(ans,compare(XU,XD,MAXD)*5LL);
    ans = min(ans,compare(YR,YL,MAXD)*5LL);
    ans = min(ans,compare(mR,mD)*10LL);
    ans = min(ans,compare(mU,mL)*10LL);
    ans = min(ans,compare(aR,aU)*10LL);
    ans = min(ans,compare(aD,aL)*10LL);
    if (ans == INF) cout << "SAFE" << '\n';
    else cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 115524