akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

bool check(string a, char c){
	bool ans=false;
	
	for(int i=0; i<3; ++i){
		if(a[0+i]==c && a[3+i]==c && a[6+i]==c) ans=true;
	}
	
	for(int i=0; i<3; ++i){
		if(a[i*3]==c && a[i*3+1]==c && a[i*3+2]==c) ans=true;
	}
	
	if(a[0]==c && a[4]==c && a[8]==c) ans=true;
	if(a[2]==c && a[4]==c && a[6]==c) ans=true;
	
	return ans;
} 

int main(){
	string s;
	while(cin >> s){
		if(check(s, 'o'))
			printf("o\n");
		else if(check(s, 'x'))
			printf("x\n");
		else printf("d\n");
	}
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;
//最大公約数を求める
ll gcd(ll a, ll b) {
    return b != 0 ? gcd(b, a % b) : a;
}
//最小公倍数を求める
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
int main(){
  int n;cin>>n;
  int a;
  int ans = 0;
  fol(i,n){
    cin>>a;
    ans+=(a-1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long dur = a - b;
        for (int up = 0; up < n - 1; up++) {
            long max = d * up - c * (n - 1 - up);
            long min = c * up - d * (n - 1 - up);
            if (min <= dur && dur <= max) {
                System.out.println("YES");
                return;
            }
        }

        System.out.println("NO");
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] h = new int[n];
		for(int i = 0;i < n;i++) {
			h[i] = sc.nextInt();
		}
		int[][] ab = new int[m][2];
		int[] result = new int[n];
		for(int i = 0;i < n;i++) {
			result[i] = 0;
		}

		for(int i = 0;i < m;i++) {

			for(int j = 0;j < 2;j++) {
				ab[i][j] = sc.nextInt();
			}
			if(result[ab[i][0]-1] == 0 || result[ab[i][1]-1] == 0) {
				if(h[ab[i][0]-1] < h[ab[i][1]-1]) {
					result[ab[i][0]-1] = 1;
				}else if(h[ab[i][0]-1] == h[ab[i][1]-1]){
					result[ab[i][0]-1] = 1;
					result[ab[i][1]-1] = 1;
				}else {
					result[ab[i][1]-1] = 1;
				}
			}
		}

		int totalcount = 0;
		for(int i = 0;i < n;i++) {
			if(result[i] == 0) {
				totalcount++;
			}
		}

		System.out.println(totalcount);

	}

}


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

long long H, W;

int main() {
  cin >> H >> W;
  if (H == 1 or W == 1) cout << 1 << endl; 
  else {
    // 切り上げ
    long long ans = (H * W + 1) / 2;
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        long[] nm = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long n = nm[0];
        long m = nm[1];
        long ans = (1900 * m + 100 * (n - m)) * Convert.ToInt64(Math.Pow(2, m));

        Console.WriteLine(ans);
    }
}

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

int main() {
  int ans;
  string s;
  
  cin >> s;
  if (s[0] == '1') ans++;
  if (s[1] == '1') ans++;
  if (s[2] == '1') ans++;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;

class UnionFind {
public:
    vector <LL> par;
    vector <LL> siz;

    UnionFind(LL sz_): par(sz_), siz(sz_, 1LL) {
        for (LL i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(LL sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (LL i = 0; i < sz_; ++i) par[i] = i;
    }

    LL root(LL x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool unite(LL x, LL y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool same(LL x, LL y) {
        return root(x) == root(y);
    }

    LL size(LL x) {
        return siz[root(x)];
    }
};

int main(){
	int N, M;
	cin >> N >> M;
	UnionFind uf(N);
	rep(i,M){
		int A, B;
		cin >> A >> B;
		A--; B--;
		uf.unite(A,B);
	}
	LL ans=0;
	rep(i,N) ans=max(ans,uf.size(i));
	cout << ans << endl;

	return 0;
}

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

int n, m, k, ans=1e9;
string grid[11];

int main(){
	cin >> n >> m >> k;
	for (int i=0;i<n;i++) cin >> grid[i];
	for (int mask=0;mask<(1<<(n-1));mask++){
		vector<vector<int>>pref(n+1,vector<int>(m+1));
		int tmp=__builtin_popcount(mask);
		bool cek;
		for (int j=0;j<m;j++){
			cek=0;
			for (int i=0;i<n;i++){
				pref[i][j]=(grid[i][j]=='1');
				if (i>0 && ((mask&(1<<(i-1)))==0)) pref[i][j]+=pref[i-1][j];
				if (j>0) pref[i][j]+=pref[i][j-1];
				if (i>0 && ((mask&(1<<(i-1)))==0) && j>0) pref[i][j]-=pref[i-1][j-1];
				if (pref[i][j]>k) cek=1;
			}
			if (cek){
				tmp++;
				cek=0;
				for (int i=0;i<n;i++){
					pref[i][j]=(grid[i][j]=='1');
					if (i>0 && ((mask&(1<<(i-1)))==0)) pref[i][j]+=pref[i-1][j];
					if (pref[i][j]>k) cek=1;
				}
				if (cek) break;
			}
		}
		if (!cek) {
			ans=min(ans,tmp);
//			cout << mask << ":\n";
//			for (int i=0;i<n;i++){
//				for (int j=0;j<m;j++){
//					cout << pref[i][j] << " ";
//				}
//				cout << "\n";
//			}
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
    int N;
    cin >> N;
    string S[N];
    int P[N];
    for(int i = 0; i < N; i++) cin >> S[i] >> P[i];
    int swaped[N];
    for(int i = 0; i < N; i++) swaped[i] = 0;

    for(int i = 0; i < N; i++) {
        for(int j = 1; j < N; j++) {
            if( (S[i]==S[j] && P[i]<P[j]) || (S[i] > S[j])) {
                swaped[i]++;
            }
        }
    }
    int cnt = 0;
    for(int j = 0; j < N; j++) {
        for(int i = 0; i < N; i++) {
            if(swaped[i] == cnt) {
                cout << i+1 << endl;
            }
        }
        cnt++;
    }

    return 0;
}

Measured memory_bytes: 256
D, G = [int(_) for _ in input().split()]
PC = [[int(_) for _ in input().split()] for i in range(D)]
P = [p for p, c in PC]
C = [c for p, c in PC]

from heapq import *

h = []

heappush(h, (0, 0, (0,)*D))

result = 0

ef = {}

while h:
    t, score, pat = heappop(h)
    # print(t, score, pat)
    if score >= G:
        result = t
        break

    def add(i, pat, d):
        pat1 = list(pat)
        if pat1[i] +d <= P[i]:
            pat1[i] += d
            pat1 = tuple(pat1)
            if not pat1 in ef:
                t1 = t + d
                score1 = score + (i+1)*100*d
                if pat1[i] == P[i]:
                    score1 += C[i]
                ef[pat1] = t
                heappush(h, (t1, score1, pat1))

    for i in range(D-1, -1, -1):
        if pat[i] < P[i]:
            add(i, pat, 1)
            break

    for i in range(D):
        if pat[i] + 1 < P[i]:
            add(i, pat, P[i] - pat[i])

print(result)


Measured memory_bytes: 107736
num = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
sum = 0
 
for i in range(num):
	if i == 0:
		sum += b[a[i]-1]
	else:
		sum += b[a[i]-1]
		if (a[i]-1) == a[i-1]:
			sum += c[a[i-1]-1]
 
print(sum)

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

int main(){
	ll n, l, r;
	ll ans = 1001001001001;
	cin >> n;
	for(ll i = 1; i*i <= n; i++){
		if(n % i == 0){
			r = n/i;
			ans = min(ans, i+r-2);
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d %d", $N, $K, $Q);
$sum = array_pad(array(), $N, 0);
for ($i = 0; $i < $Q; $i++) {
    fscanf(STDIN, "%d", $A);
    $sum[$A - 1]++;
}
for ($i = 0; $i < $N; $i++) {
    echo $K - ($Q - $sum[$i]) > 0 ? "Yes\n" : "No\n";
}


Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define ref(i,n) for(int i=0;i<n;i++)
using namespace std;
string s,d;
int main()
{
    cin>>s>>d;
    if(s.size()==d.size()-1){
        ref(i,s.size()) if(s[i]!=d[i]) {
            cout<<"No";
            return 0;
        }
        cout<<"Yes";
    }
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

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

    int cnt=0;
    while(b-a>=0){
        b-=a;
        cnt++;
    }    
    cout <<min(cnt,c)<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define tracev(v)               for (auto& x: v) cerr << x << " "; cerr << '\n';
#define trace2v(v)              for (auto& x: v) cerr << x.fi << " - " << x.se << '\n'; cerr << '\n';
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long ll; 
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifndef ONLINE_JUDGE
    freopen("errlog", "w", stderr);
#endif
    int a, b, c; cin >> a >> b >> c;
    if (c >= a && c <= b) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int A, B, C;
  std::cin >> A >> B>> C;
  if ((A < C) && (C < B)) {
    std::cout << "Yes" << std::endl;
  } else if ((B < C) && (C < A)) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}

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

typedef pair<int,string> Pis ;
#define f first
#define s second

vector<Pis> VC ;

int main(){
	
	string str,Astr ;
	getline( cin , str ) ;
	str += ' ' ;
	
	bool f = false ;
	string tmp ;
	tmp.erase();
	for( int i=0 ; i < str.size() ; i++ ){
		if( str[i] != ' ' ) tmp += str[i] ;
		else {
			for( int j=0 ; j<VC.size() ; j++ ){
				if( VC[j].s == tmp ){
					VC[j].f++;
					f = true ;
					break    ;
				}
			}
			if( f ) f = false ;
			else {
				VC.push_back( Pis(1,tmp) ) ;
				if( Astr.size() < tmp.size() ) Astr = tmp ;
			}
			tmp.erase();
		}
	}
	
	sort( VC.begin() , VC.end() );
	
	cout << VC[VC.size()-1].s << " " ;
	cout << Astr << endl ;
	
	return 0;
}

Measured memory_bytes: 1192
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>	tree_set;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9 + 7;
const ll N=1e5 + 5;

int main()
{
    fast();
    string str;
    cin>>str;
    ll len = str.length();
    ll mn = LLONG_MAX;
    for(ll i=0;i<=len-3;i++)
    {
        ll num = (str[i]-'0')*100 + (str[i+1]-'0')*10 + str[i+2]-'0';
        mn = min(mn , abs(num-753));
    }
    cout<<mn;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def solve():
    N, M = map(int, input().split())
    uf = UnionFind(N+1)
    for i in range(M):
        a,b = map(int, input().split())
        uf.union(a,b)
    ans = 0
    for i in range(N):
        ans = max(ans, uf.size(i))
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 79856
n, maxw = map(int, input().split())

dp = [0 for _ in range(maxw+1)]
for i in range(n):
    v, c = map(int, input().split())
    for j in range(maxw, -1, -1):
        if j>=c:
            dp[j] = max(dp[j], dp[j-c]+v)
        else:
            break
print(dp[-1])

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

int c_makenum(int, int);

int n;
int A[30];

int main(){
  int p, q, i, j;
  int *B;
  
  scanf("%d", &n);
  for(i = 0 ; i < n ; i++){
    scanf("%d", &A[i]);
  }

  scanf("%d", &q);
  B = malloc(q * sizeof(int));
  for(i = 0 ; i < q ; i++){
    scanf("%d", &B[i]);
  }

  for(i = 0 ; i < q ; i++){
    if(c_makenum(0, B[i]) == 1)printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}

int c_makenum(int i, int key){
  int res;
  
  if(key == 0)return 1;
  if(i >= n)return 0;

  res = c_makenum(i + 1, key) || c_makenum(i + 1, key - A[i]);
  
  return res;
}



Measured memory_bytes: 2108
#include <iostream>

using namespace std;

int main()
{
    size_t perimeter;
    int n;
    cin >> perimeter >> n;
    size_t a[n];
    for (size_t i = 0; i < n; ++i) {
        cin >> a[i];
    }
    size_t d[n];
    for (size_t i = 0; i + 1 < n; ++i) {
        d[i] = a[i + 1] - a[i];
    }
    d[n - 1] = perimeter - (a[n - 1] - a[0]);
    
    size_t answ = 0;
    size_t max = 0;
    for(size_t i = 0; i < n; ++i) {
        if(d[i] > max) max = d[i];
        answ += d[i];    
    }
    cout << answ - max;
    return 0;
}

Measured memory_bytes: 3964
n, x = map(int, input().split())

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

a.sort()

ans = 0

for i in range(n-1):
    if x - a[i] >= 0:
        x = x - a[i]
        ans += 1

if x == a[n-1]:
    ans += 1

print(ans)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define For(start,end) for(int i = (int)start;i<(int)end;i++)
using Int = long long int;
int main(){
    int N,Y;
    cin>>N>>Y;
    bool finish=false;
    int a=0,b=0;
    for(;a<=N;a++)
    {
        for(b=0;b<=N-a;b++)
        {
            if( 10000*a+5000*b+1000*(N-a-b)==Y){
                finish=true;
                break;
            }
    
        }
        if(finish){
            break;
        }
    
    }
    if(!finish)
    {
        cout<<-1<<" "<<-1<<" "<<-1<<endl;
    }
    else
    {
        cout<<a<<" "<<b<<" "<<(N-a-b)<<endl;
    }
    
}

Measured memory_bytes: 3588
#include <iostream>
#include <map>

typedef long long ll;

int main(){
   int N;
   std::cin >> N;
   int A[N];
   std::map<int, int> mp;
   for(int i=0; i<N; ++i){
      std::cin >> A[i];
      mp[A[i]]++;
   }
   ll sum = 0;
   for(auto itr=mp.begin(); itr!=mp.end(); ++itr){
	 ll n = itr->second;
	 sum += n * (n-1)/2;
   }
   for(int k=0; k<N; ++k){
      ll n = mp[A[k]];
      std::cout << sum - n * (n-1)/2 + (n-1) * (n-2)/2 << std::endl;
   }
   return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double ok = 0;
  double ng = 90;
  const double pi = std::acos(-1);

  for(int q = 0;q < 60;q++) {
    double theta = (ok + ng) / 2 * 2 * pi / 360.0;
    double L = a * std::sin(theta);
    double R = b * std::cos(theta);
    double vol = 0;
    if(L < R) {
      double len = a * std::cos(theta) + L * std::tan(theta);
      vol = (len * (R - L) + len * L / 2) * a;
    }
    else {
      double len = b * std::sin(theta) + R / std::tan(theta);
      vol = (len * R) / 2 * a;
    }
    if(vol < x) {
      ng = (ok + ng) / 2;
    }
    else {
      ok = (ok + ng) / 2;
    }
  }
  cout << fixed << setprecision(10);
  cout << ok << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

int main(){
    double a,b,x;
    cin >> a >> b >> x;

    double s = x/a;
    double rad;

    if(s<=a*b/2){
        rad = atan((a*b*b)/(2.0*x));
    }else{
        rad = M_PI/2.0 - atan(a*a*a/(2.0*a*a*b-2.0*x));
    }

    printf("%.10f\n", rad * 180.0 / M_PI);
    return 0;
}

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

using namespace std;
using ll = int64_t;
using P = std::pair<int, int>;

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

int main() {
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> T(N);
    vector<ll> A(N);
    for(int i = 0; i < N; i++) {
        cin >> T[i];
    }

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

    ll cnt = 1LL;
    if(A[0] != T[N-1]) {
        cnt = 0;
    }
    
    if(N == 2) {
        // 1 5
        if(T[0] != T[1]) {
            // 5 2
            if(T[1] > A[1]) {
                cnt = 0LL;
            }
        }

        if(A[0] != A[1]) {
            if(A[0] > T[0]) {
                cnt = 0LL;
            }
        }
    }


    for(int i = 1; i < N - 1; i++) {
        if(T[i-1] != T[i]) {
            if(T[i] > A[i]) {
                cnt = 0LL;
            }
        } else {
            // 余白あり
            if(A[i] == A[i+1]) {
                cnt *= min(T[i], A[i]) - 1LL + 1LL;
                cnt %= MOD;
            }
        }

        if(A[i] != A[i+1]) {
            if(T[i] < A[i]) {
                cnt = 0LL;
            }
        }
    }

    cout << cnt % MOD << endl;
}


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

int main(){
    int64_t N, K, i, longest = 0, shortest = 0, time, limit, cost;
    cin >> N >> K;
    
    vector<int64_t> fighter(N), food(N), result(N);
    for(i = 0; i < N;i++){
        cin >> fighter[i];
        cost += fighter[i];
    }
    for(i = 0; i < N;i++){
        cin >> food[i];
    }
    sort(fighter.begin(), fighter.end());
    sort(food.begin(), food.end());
    reverse(food.begin(), food.end());
    for(i = 0; i < N; i++){
        result[i] = fighter[i] * food[i];
    }

    for(i = 0; i < N; i++){
        if(longest < result[i])longest = result[i];
    }
    while(longest != shortest){
        time = (longest + shortest) / 2;
        limit = K;
        for(i = 0; i < N; i++){
            if(result[i] > time){
                limit -= (result[i] - time - 1) / food[i] + 1;
            }
            if(limit < 0)break;
        }
        if(limit < 0){
            shortest = time + 1;
        }else{
            longest = time;
        }
    }
    cout << longest << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main() {
	int64_t n, k, q;
	cin >> n >> k >> q;
	vector<int> a(q);
	for (int i = 0; i < q; i++) {
		int x;
		cin >> x;
		a.at(i) = x - 1;
	}
	vector<int64_t> point(n, k - q);
	for (int i = 0; i < q; i++) {
		int who = a.at(i);
		point.at(who)++;
	}
	for (int i = 0; i < n; i++) {
		if (point.at(i) > 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

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

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    int a, b, c;
    cin >> a >> b >> c;
    if ((a <= c && c <= b) || (b < c && c <= a))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main(void)
{
    solve();
}


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

int main() {
    string s1;
    cin >> s1;
    string s2 = "CODEFESTIVAL2016";
    int cnt = 0;
    for(int i=0; i<16; i++) {
        if(s1[i] != s2[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]

def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]

def fetch_ints_inputs(times):
    return [fetch_int_input() for _ in range(times)]


cards = fetch_inputs(3)
cards = {
            "a": cards[0],
            "b": cards[1],
            "c": cards[2]
        }

turn = "a"

while True:
    if cards[turn]:
        tmp_turn = cards[turn][0]
        cards[turn] = cards[turn][1:]
        turn = tmp_turn
    else:
        winner = turn
        break

print(winner.upper())


Measured memory_bytes: 38448
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    long long n,ans=0;
    cin>>n;
    long long a[n];
    map <long long,long long> m1;
    for(long long i=0;i<n;i++){
        cin>>a[i];
    }
    //for(long long i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
    //for(long long i=0;i<n;i++) ans+=a[i];
    sort(a,a+n);
    for(long long i=0;i<n-1;i++){
        if(a[i]+a[i+1]<0){
            a[i]=-a[i];
            a[i+1]=-a[i+1];
        }
    }
    //for(long long i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
    for(long long i=0;i<n;i++) ans+=a[i];
    cout<<ans<<"\n";
    
    return 0;
}

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

int main() {
  rep(i,3) {
    char c;
    cin >> c;
    if (c == '1') cout << 9;
    else cout << 1;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3608
num = int(input())
index = list(map(int, input().split()))
point = list(map(int, input().split()))
add = list(map(int, input().split()))


total = 0
for i in range(num):
  total += point[index[i]-1]

for j in range(num-1):
  if index[j+1] == index[j]+ 1:
    total += add[index[j]-1]

print(total)

Measured memory_bytes: 38368
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define p(S) cout<<(S)<<endl
using namespace std;
const int inf=1e9;
 
int main(){
    int n;
    cin>>n;
    int dp[100010], effect[100010];
    REP(i,0,n) cin>>effect[i];
    REP(i,1,n) dp[i]=inf;
    queue<int> q;
    dp[0]=0;
    q.push(0);
    //bfs
    while(!q.empty()){
        int now=q.front();q.pop();
        REP(i,1,7){
            int next=now+i;
            if(next>n-1) break;
            while(dp[next]==inf){
                if(effect[next]==0) q.push(next);
                dp[next]=dp[now]+1;
                next+=effect[next];
            }
        }
        if(dp[n-1]<inf)  break;
    }
    p(dp[n-1]);
    return 0;
}

Measured memory_bytes: 3928
def next(s,x,y):
	ans = []
	if s[x][y+1] == '.':
		ans.append([x,y+1])
	if s[x][y-1] == '.':
		ans.append([x,y-1])
	if s[x+1][y] == '.':
		ans.append([x+1,y])
	if s[x-1][y] == '.':
		ans.append([x-1,y])
	return ans

h,w = map(int,input().split())
s = []
add = ['#' for i in range(w+2)]
s.append(add)
counter = 0
for i in range(h):
	sinput = str(input())
	stemp = []
	for i in range(w):
		stemp.append(sinput[i])
	for i in range(w):
		if stemp[i] == '.':
			counter += 1
	stemp.insert(0,'#')
	stemp.append('#')
	s.append(stemp)
s.append(add)

arrival = [[0 for i in range(w+1)] for k in range(h+1)]
q = [[1,1]]
arrival[1][1] = 1
while len(q) > 0:
	nextcell = next(s,q[0][0],q[0][1])
	for i in range(len(nextcell)):
		if arrival[nextcell[i][0]][nextcell[i][1]] == 0:
			q.append(nextcell[i])
			arrival[nextcell[i][0]][nextcell[i][1]] = arrival[q[0][0]][q[0][1]] + 1
	q.pop(0)

if arrival[h][w] == 0:
	print(-1)
else:
	print(counter - arrival[h][w])

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
int main(){
    double w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<fixed<<setprecision(6)<<(double)w*h/2.0<<" ";
    if(x==w/2.0&&y==h/2.0){
        cout<<1<<endl;
    }
    else{
        cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 3776
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
using namespace std;
int main(){
  int a,b,x;
  cin >> a >> b >> x;

  if( (a<=x) && (a+b >= x) ) printf("YES\n");
  else printf("NO\n");

  return 0;
  
}


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

#ifdef DEBUG
#include "../.inc/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

const int mod = 998244353;
struct P { int x, y; };

const int MAXN = 200010;
long long pow2[MAXN];
void init() {
    pow2[0] = 1;
    for (int i=1; i<MAXN; ++i) {
        pow2[i] = (pow2[i-1]*2) % mod;
    }
}

void compress(vector<int> &v) {
    vector<int> w(v);
    sort(w.begin(), w.end());
    for (int i=0; i<(int)v.size(); ++i) {
        v[i] = lower_bound(w.begin(), w.end(), v[i]) - w.begin();
    }
}

class BIT {
public:
    int n;
    vector<int> nodes;
    BIT(int n): n(n+1), nodes(n+1, 0) {}

    void add(int i, int v) {
        nodes[++i] += v;
        for (i+=i&(-i); i<=n; i+=i&(-i)) nodes[i] += v;
    }
    int sum(int i) {
        int res = nodes[++i];
        for (i-=i&(-i); i>0; i-=i&(-i)) res += nodes[i];
        return res;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");
    init();

    int n;
    cin >> n;

    vector<int> x(n), y(n);
    for (int i=0; i<n; ++i) {
        cin >> x[i] >> y[i];
    }
    compress(x);
    compress(y);

    vector<P> p;
    for (int i=0; i<n; ++i) {
        p.push_back((P){x[i], y[i]});
    }
    sort(p.begin(), p.end(), [](const P &a, const P &b){
        return a.x < b.x || (a.x == b.x && a.y < b.y);
    });

    vector<int> tl(n), bl(n);
    {
        BIT bit(2*n);
        for (int i=0; i<n; ++i) {
            bl[i] = bit.sum(p[i].y);
            tl[i] = i - bl[i];
            bit.add(p[i].y, 1);
        }
    }
    vector<int> tr(n), br(n);
    {
        BIT bit(2*n);
        for (int i=n-1; i>=0; --i) {
            br[i] = bit.sum(p[i].y);
            tr[i] = (n-1-i) - br[i];
            bit.add(p[i].y, 1);
        }
    }

    vector<vector<int>> pick = {
        {1,0,0,1}, {0,1,1,0}, {1,0,1,1}, {0,1,1,1}, {1,1,0,1}, {1,1,1,0}, {1,1,1,1}
    };

    long long ans = 0;
    for (int i=0; i<n; ++i) {
        for (int j=0; j<7; ++j) {
            if (pick[j][0] && tl[i] <= 0) continue;
            if (pick[j][1] && tr[i] <= 0) continue;
            if (pick[j][2] && bl[i] <= 0) continue;
            if (pick[j][3] && br[i] <= 0) continue;
            long long c = 1;
            c *= pick[j][0] ? pow2[tl[i]]-1 : 1; c %= mod;
            c *= pick[j][1] ? pow2[tr[i]]-1 : 1; c %= mod;
            c *= pick[j][2] ? pow2[bl[i]]-1 : 1; c %= mod;
            c *= pick[j][3] ? pow2[br[i]]-1 : 1; c %= mod;
            ans += c; ans %= mod;
        }
        ans += pow2[n-1]; ans %= mod;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9680
import sys

def value(w,n,P):

	tmp_w = 0
	k = 1

	for i in range(n):
		if tmp_w + w[i] <= P:
			tmp_w += w[i]
		else:
			tmp_w = w[i]
			k += 1
	return k


def test():

	inputs = list(map(int,sys.stdin.readline().split()))
	n = inputs[0]
	k = inputs[1]
	w = []

	max = 0
	sum = 0

	for i in range(n):

		w.append(int(sys.stdin.readline()))

		if w[i] > max:
			max = w[i]

		sum += w[i]

	while max != sum:

		mid = (max + sum) // 2

		if value(w,n,mid) > k:
			max = mid + 1
		else:
			sum = mid


	print(max)

if __name__ == "__main__":
	test()



Measured memory_bytes: 9556
# coding: utf-8
while 1:
    m,t,p,r=map(int,input().split())
    if m==0:
        break
    teamdata=[[0,0,i+1,set()] for i in range(t)]
    data=[]
    for i in range(r):
        a,b,c,d=map(int,input().split())
        if d==0:
            teamdata[b-1][0]+=1
            teamdata[b-1][1]+=a
            teamdata[b-1][3].add(c)
        data.append([a,b,c,d])
    for a,b,c,d in data:
        if d!=0 and (c in teamdata[b-1][3]):
            teamdata[b-1][1]+=20
    teamdata=sorted(teamdata, key=lambda x:(-x[0],x[1],-x[2]))
    for i in range(t):
        print(teamdata[i][2],end=('\n' if i==t-1 else ',' if teamdata[i][0]>teamdata[i+1][0] or teamdata[i][1]<teamdata[i+1][1] else '='))



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

//公約数
void div(long long a, vector<long long> &n) {
  n.push_back(1);
  for (long long i = 2; i <= sqrt(a); i++)
    if (a % i == 0) n.push_back(i);
  if (n.at(n.size() - 1) == sqrt(a))
    for (long long i = n.size() - 2; i >= 0; i--)
      n.push_back(a / n.at(i));
  else
    for (long long i = n.size() - 1; i >= 0; i--)
      n.push_back(a / n.at(i));
  return;
}

void comdiv(long long a, long long b, vector<long long> &n) {
  if (a > b) swap(a, b);
  vector<long long> m(0);
  div(a, m);
  for (long long i = 0; i < m.size(); i++)
    if (b % m.at(i) == 0) n.push_back(m.at(i));
  return;
}

//素数判定
long long p_np(long long n) {
  if (n == 1) return 0;
  for (long long i = sqrt(n); i >= 2; i--)
    if (n % i == 0) return 0;
  return 1;
}

int main() {
  long long a, b;
  cin >> a >> b;
  vector<long long> n(0), check(0);
  comdiv(a, b, n);
  for (long long i = 1; i < n.size(); i++) {
    for (long long j = 0; j < check.size(); j++)
      if (n.at(i) % check.at(j) == 0) continue;
    if (p_np(n.at(i)) == 1) check.push_back(n.at(i));
  }
  cout << check.size() + 1 << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> ivec;
const ll N = 1e9+7;

int main(){
    int n,w; cin >> n >> w;
    vector<P> vw(n);
    rep(i,n){
        int tv,tw;cin >> tv >> tw;
        vw[i] = P(tv,tw);
    }
    int dp[n+1][w+1] = {};
    // fill(dp[0],dp[0]+w,0);
    rep(i,n){
        rep(j,w+1){ 
            if(vw[i].second <= j) dp[i+1][j] = max(dp[i][j-vw[i].second]+vw[i].first,dp[i][j]);
            else dp[i+1][j] = dp[i][j];
            // cout << dp[i][j] << " ";
        }
        // cout << endl;
    }
    // rep(i,n+1){rep(j,w+1)cout << dp[i][j] << " "; cout << endl;}
    cout << dp[n][w] << endl;
    return 0;
}


Measured memory_bytes: 7036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double h1 = (double)30 * h + 0.5 * m;
  double m1 = (double)6 * m;
  double arc = abs(h1 - m1);
  if(arc>180){
    arc =360-arc;
  }
  double pi = 3.14159265358979;
  double rad = pi / (double)180 * arc;
  double c = cos(rad);
  double ans = sqrt(a * a + b * b - (double)2 * a * b * c);
  cout << fixed << setprecision(11) << ans << endl;
}

Measured memory_bytes: 4096
battle = list(map(int, input().split()))
a_HP = battle[0]
a_ATK = battle[1]
b_HP = battle[2]
b_ATK = battle[3]

while(b_HP>=0):
    b_HP -= a_ATK
    if b_HP <= 0:
        print("Yes")
        break
    a_HP -= b_ATK
    if a_HP <= 0:
        print("No")
        break

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> x(N);
  for (int i = 0; i < N; i++){
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  cout << (x.back() - x.front() + 1) / 2 << endl;
}


Measured memory_bytes: 3156
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

int main(){
  int A,B,C,X,Y;
  std::cin >> A >> B >> C >> X >> Y;

  int a=0,b=0,c=0;
  
  if((A+B)>(C*2)){
    if(X>Y){
      c = Y*2;
      X = X-Y;
      Y = 0;
      if(X*A<X*C*2){
	a = X;
      }else{
	c += X*2;
      }
    }else{
      c = X*2;
      Y = Y-X;
      X = 0;
      if(Y*B<Y*C*2){
	b = Y;
      }else{
	c += Y*2;
      }
    }
    //std::cout << a << b << c << std::endl;
  }else{
    a = X;
    b = Y;
  }

  std::cout << (a*A+b*B+c*C) << std::endl;
  return 0;
}
    


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os


def rect(w, h):
    row = '#' * w + '\n'
    print(row * h)

for s in sys.stdin:
    H, W = list(map(int, s.split()))
    if W == H == 0:
        break
    else:
        rect(W, H)

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

int main() {
 int N;
 
 cin >> N;
  bool flag = false;
  for(int i = 1; i < 10; i++) {
    for(int j = 1; j < 10; j++) {
      if(i * j == N) flag = true; 
    }
  }

  if(flag) cout << "Yes";
  else cout << "No";
 return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 入力1をnに入れる
		String s = sc.next();

		int n = s.length();

		for (int i = 0; i < 1 << n; i++) {
			StringBuilder sb = new StringBuilder(s);

			//ビット全探索で文字列Sに"+ - "を挿入していく
			for (int j = n - 2; j >= 0; j--) {
				if ((1 & i >> j) == 1) {
					sb.insert(j + 1, "+");
				} else {
					sb.insert(j + 1, "-");
				}
			}

			String str = sb.toString();
			int ans = Character.getNumericValue(str.charAt(0));
			//"+ - "入りの文字列をsplitして足し合わせる
			for (int j = 1; j < 2 * n - 2; j= j+2) {
				if (str.charAt(j) == '+') {
					ans += Character.getNumericValue(str.charAt(j+1));
				} else if (str.charAt(j) == '-') {
					ans -= Character.getNumericValue(str.charAt(j+1));
				}
			}

//			System.out.println("sb:" + sb);
//			System.out.println("ans:" + ans);
			if (ans == 7) {
				System.out.println(sb+"="+ans);
				break;
			}
		}
	}
}


Measured memory_bytes: 22484
n = int(input())
h = [int(i) for i in input().split()]
c = 0
ans = 0
for i in range(n-1):
    # print('start',i)
    # print(h[i],h[i+1])
    if h[i] >= h[i+1]:
        c += 1
        ans = max(c,ans)
    else:
        c = 0
    # print('end',ans)
print(ans)

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

int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int y, m, d;
    cin >> y >> m >> d;
    int days = 0;
    days += ((y - 1) - ((y - 1) / 3)) * 195;
    days += (y - 1) / 3 * 200;
    if(y % 3 == 0) {
      days += (m - 1) * 20;
    } else {
      days += ((m - 1) / 2) * 39;
      if((m - 1) % 2 != 0) days += 20;
    }
    days += d;
    cout << 196470 - days + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-7
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 998244353;
long double PI = acosl(-1);
const ll infl = 1e18+100;
const int inf = 2e9+100;
const int nmax = 2e5+2;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

vector<int>g[nmax];
int val[nmax];
int ans[nmax];
set<int>cur;


void dfs(int u, int p=0){
    int rimov=0, dhuk=0;

    auto it = cur.lower_bound(val[u]);
    if(it==cur.end()){
        cur.insert(val[u]);
        dhuk=1;
    }
    else if(*it!=val[u]){
        rimov = *it;
        cur.erase(*it);
        cur.insert(val[u]);
        dhuk = 1;
    }

    ans[u] = cur.size();

    for(int v : g[u]) if(v!=p){
        dfs(v, u);
    }

    if(dhuk) cur.erase(val[u]);
    if(rimov) cur.insert(rimov);
}

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

//    freopen("bajeces.txt", "r", stdin);
//    freopen("mara.txt", "w", stdout);

    int n;
    cin>>n;
    for(int i=1; i<=n; i++) cin>>val[i];
    for(int i=1; i<n; i++){
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    dfs(1);
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<"\n";
    }

}
/*

*/


Measured memory_bytes: 33340
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define F first
#define S second
#define pi pair <ll, ll>
#define pii pair <pi, pi>
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T = 1;
	//cin >> T;
	while(T--){	
		ll n, i;
		cin >> n;
		ll a[n];
		bool fg = false;
		for(i = 0; i < n; i++){
			cin >> a[i];
			if(a[i] == 0){
				fg = true;
			}
		}
		if(fg){
			cout << 0;
			return 0;
		}
		ll ans = 1, x;
		const ll y = 1e18;
		for(i = 0; i < n; i++){
			if(ans > y / a[i]){
				ans = -1;
				break;
			}
			ans *= a[i];
		}
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 4420
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2000000000
#define MOD 1000000007
#define N 200005
#define M 1000005
#define LOG 19
#define KOK 32000
#define EPS 0.000000001
using namespace std;
 
ll s(int I,int O,int J,int L) {

	if(I<0 || J<0 || L<0) return -1ll*inf*inf;

	return 1ll*I/2*2+J/2*2+L/2*2+O;

}

int main() {
 
	int I,O,T,J,L,S,Z;
 
	//freopen("input.txt","r",stdin);
 
	scanf("%d %d %d %d %d %d %d",&I,&O,&T,&J,&L,&S,&Z);

	printf("%lld",max(s(I-1,O,J-1,L-1)+3,s(I,O,J,L)));
	 
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

int main()
{
    int N;
    cin >> N;
    v<ll> T(N);
    for (int i = 0; i < N; i++)
    {
        cin >> T[i];
    }
    ll ans = T[0];

    for (int i = 0; i < N; i++)
    {
        ans = lcm(ans, T[i]);
    }

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

Measured memory_bytes: 3568
height = [0 for i in range(10)]
sort_height = [0 for i in range(10)]

#set
for i in range(10):
    height[i] = int(input())

#sort
for i in range(10):
    for j in range(10):
        if height[i] >= sort_height[j]:
            #?????????
            for k in range(9, j, -1):
                sort_height[k] = sort_height[k-1] 

            sort_height[j] = height[i]
            break
        
for i in range(3):
    print(sort_height[i])

Measured memory_bytes: 7744
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        sc.close();

        long power = 1;
        long mod = 1000000007L;

        for (int i = 1; i <= n; i++) {
            power = power * i % mod;
        }

        System.out.println(power);
    }
}

Measured memory_bytes: 21588
#include <vector>
#include <iostream>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

struct Seg {
    int l, r;
    Seg() {}
    Seg(int a, int b) : l(a), r(b) {}
    bool operator<(const Seg &s) const {
        return r < s.r;
    }
};

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

    std::vector<Seg> segs(M);
    for(int i=0; i<M; i++) {
        int l, r; cin >> l >> r;
        segs[i] = Seg(l, r);
    }
    std::sort(segs.begin(), segs.end());

    int prev = -1, ans = 0;
    for(int i=0; i<M; i++) {
        if(prev <= segs[i].l) {
            ans++;
            prev = segs[i].r;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
dish = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    ans -= dish[i][1]
def f(l):
    a, b = l
    return a+b
dish.sort(key = f)
cnt = 0
while dish:
    a, b = dish.pop()
    if cnt % 2 == 0:
        ans += a+b
        cnt += 1
    else:
        cnt += 1
print(ans)

Measured memory_bytes: 34216
N = gets.to_i
ans = 0

if N <= 111
    ans = 111
elsif N <= 222
    ans = 222
elsif N <= 333
    ans = 333
    elsif N <= 444
    ans = 444
    elsif N <= 555
    ans = 555
    elsif N <= 666
    ans = 666
    elsif N <= 777
    ans = 777
    elsif N <= 888
    ans = 888
    elsif N <= 999
    ans = 999
    end

puts ans


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

#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()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,m;
	cin >> n >>m;
	
	vector<ll> a(n),b(n), c(m),d(m);
	rep(i,n) cin >>a[i] >>b[i];
	rep(i,m) cin >>c[i] >>d[i];

	rep(i,n){
		int ans=1<<29, svj=-1;
		rep(j,m){
			ll w=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(ans > w){
				svj=j; ans = w;
			}
		}
		cout << svj+1 <<endl;
	}
	
	return 0;
}


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

int main(){
	int a, b;
	int x, y;	

	while(1){
		scanf("%d %d", &a, &b);
		if((a == 0) && (b == 0)){
			break;
		}
		else{
			for(y=0;y<a; y++){
				for(x=0;x<b;x++){
					if(y%2==0){
						if(x%2==0)
							printf("#");
						else
							printf(".");
					}
					else{
						if(x%2==1)
							printf("#");
						else
							printf(".");
					}	
				}
				printf("\n");
			}
			printf("\n");
		}

	}
	
	return 0;

}


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

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

    int n;
    cin >> n;
    vector< LL >v(n);
    for (LL &x : v) cin >> x;
    sort(v.rbegin(), v.rend());

    LL ans = v.front();
    n -= 2;
    for (int i = 1; i < v.size() && n > 0; i++) {
        ans += v[i];
        n--;
        if (n > 0) {
            ans += v[i];
            n--;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4784
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int validCapLetterCount= 0;

		if (S.charAt(0) != 'A' || Character.isUpperCase(S.charAt(1))
				|| Character.isUpperCase(S.charAt(S.length() - 1))) {
			System.out.println("WA");
			return;
		}

		for (int i = 2; i <= S.length()-2; i++) {
			if(Character.isUpperCase(S.charAt(i)) && S.charAt(i)=='C' && validCapLetterCount==0){
               validCapLetterCount++;
			}else if(Character.isUpperCase(S.charAt(i))){
				System.out.println("WA");
				return;
			}
		}
		
		if(validCapLetterCount==1){
			System.out.println("AC");
		}else{
			System.out.println("WA");
		}
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
long long int func(int n);
int main(){
  int n,m;
  cin>>n>>m;
  if(n==m||abs(n-m)==1){
    long long int ans=(func(n)*func(m))%1000000007;
    if(n==m){
      ans=(2*ans)%1000000007;
    }
    cout<<ans<<endl;
  }else{
    cout<<0<<endl;
  }
  return(0);
}

long long int func(int n){
  long long int x=1;
  for(int i=0;i<n-1;i++){
    x=(x*(n-i))%1000000007;
  }
  return x;
}


Measured memory_bytes: 256
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {

    let r = read_line().parse::<i32>().unwrap();
    let g = read_line().parse::<i32>().unwrap();
    println!("{}", 2*g - r);

}


Measured memory_bytes: 4352
S = input()
S = ''.join(list(reversed([c for c in S])))

while S:
    if S[:7] == 'remaerd':
        S = S[7:]
    elif S[:6] == 'resare':
        S = S[6:]
    elif S[:5] == 'maerd':
        S = S[5:]
    elif S[:5] == 'esare':
        S = S[5:]
    else:
        print('NO')
        exit()

print('YES')

Measured memory_bytes: 4724