akhauriyash/Code-Regression huggingface dataset:
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
signed main()
{
	int x;
	cin>>x;
	for(int i=-120;i<=120;i++)
	{
		for(int j=-120;j<=120;j++)
		{
			if(pow(i,5)-pow(j,5)==x)
			{
				cout<<i<<" "<<j<<endl;
				return 0;
			}
//			cout<<i<<" "<<j<<endl;
		}
	}
}












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

const int maxn = 2e5;
int n, ans[maxn + 3], m[maxn + 3];
vector<int> G[maxn + 3];
map<pair<int, int>, int> M;

int Q(int u, int x, int p) {
	if (M.count(make_pair(u, x))) {
		return M[make_pair(u, x)];
	}
	int &ret = M[make_pair(u, x)] = 0;
	for (int i = 0, v; i < G[u].size(); i++) {
		v = G[u][i];
		if (v == p || v > x) continue;
		ret += Q(v, x, u) + 1;
	}
	return ret;
}

void dfs(int u, int p = 0) {
	if (u != 1) {
		ans[u] = ans[p];
		if (u > m[p]) {
			ans[u] += Q(u, m[u], p) + 1;
		} else {
			ans[u] += Q(u, m[u], p) - Q(u, m[p], p);
		}
	}
	for (int i = 0, v; i < G[u].size(); i++) {
		v = G[u][i];
		if (v == p) continue;
		m[v] = max(u, m[u]);
		dfs(v, u);
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1, u, v; i < n; i++) {
		scanf("%d %d", &u, &v);
		G[u].push_back(v), G[v].push_back(u);
	}
	dfs(1);
	for (int i = 2; i <= n; i++) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}
	return 0;
}


Measured memory_bytes: 51584
S = input()
S = list(S)
li = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

for s in S:
    if s in li:
        li.remove(s)

if len(li) == 0:
    li = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    max = 26
    m = []
    for i in range(2,len(S)+1):
        m.append(li.index(S[-i+1]))
        if li.index(S[-i]) < li.index(S[-i+1]):
            m = [x for x in m if x > li.index(S[-i])]
            S[-i] = li[min(m)]
            S = S[:-i+1]
            for s in S:
                print(s,end='')
            exit()
    print(-1)
else:
    S += li[0]
    for s in S:
        print(s,end='')


Measured memory_bytes: 3064
def solve(a,b,c,x,y):
  l = []
  for i in range(10**6):
    s = a*max(x-i,0)+b*max(y-i,0)+c*i*2
    l.append(s)
  return min(l)

        

A,B,C,X,Y = map(int,input().split())
print(solve(A,B,C,X,Y))


Measured memory_bytes: 49716
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int n;

int main(){
    cin >> n;
    string tmp = "No";
    for(int i = 1; i < 10; ++i){
        if(n % i == 0 && n / i <= 9){
            tmp = "Yes";
            break;
        }
    }
    cout << tmp << endl;
    return 0;
}


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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int r; cin >> r;
  cout << r * 2 * 3.14159265358 << endl;
}


Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	int N,i,temp,ans=0;
	cin>>N;
	vector<int> p;
	for(i=0;i<N;i++){
		cin>>temp;
		p.push_back(temp);
	}
	sort(p.begin(),p.end());
	for(i=0;i<N-1;i++){
		ans+=p.at(i);
	}
	ans+=p.at(i)/2;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!(n: usize, mut a: [i64; n], b: [i64; n]);
    for i in 0..n {
        a[i] -= b[i];
    }
    if a.iter().sum::<i64>() <= 0 {
        println!("-1");
        std::process::exit(0);
    }
    a.sort();
    let l = (0..n).find(|&l| 0 <= a[l]).unwrap_or(n);
    let mut r = n;
    let mut pos = 0;
    let neg = -a[0..l].iter().sum::<i64>();
    while pos < neg {
        r -= 1;
        pos += a[r];
    }
    println!("{}", l + (n - r));
}


Measured memory_bytes: 5912
#include <stdio.h>
#include <iostream>
#include <climits>
#include <map>
#include <cmath>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <vector>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <utility>
#include <queue>

/* Raiyan Noory Rady,CSE'17,RUET
Email:raiyannooryrady@gmail.com
Smile->Desire->Unity->Effort->Struggle->Success->Again smile :)
*/

#define ll long long int
#define pb  push_back
#define mod  1000000007
#define inf  1000000000000000000
#define pi  acos(-1.0)
#define maxn  1000009
#define sorted(s)  sort(s.begin(),s.end())
#define sortarr(a) sort(a,a+n)
#define slc(n) scanf("%I64d", &n)
#define sl(n)  scanf("%lld", &n)
#define sf(n)  scanf("%lf", &n)
#define si(n)  scanf("%d", &n)
#define sch(n)  scanf(" %c", &n)
#define ss(n)  scanf("%s", n)
#define pf printf
#define pb  push_back
#define fr first
#define sc second
#define all(a)  a.begin(),a.end()
#define forl(n) for(i=0;i<n;i++)
/*STL library functions

sort(first_iterator, last_iterator) � To sort the given vector.

reverse(first_iterator, last_iterator) � To reverse a vector.

*max_element (first_iterator, last_iterator) � To find the maximum element of a vector.

*min_element (first_iterator, last_iterator) � To find the minimum element of a vector.

accumulate(first_iterator, last_iterator, initial value of sum) � Does the summation of vector elements

count(first_iterator, last_iterator,x) � To count the occurrences of x in vector.

find(first_iterator, last_iterator, x) � Points to last address of vector ((name_of_vector).end())
 if element is not present in vector.

binary_search(first_iterator, last_iterator, x) � Tests whether x exists in sorted vector or not.

lower_bound(first_iterator, last_iterator, x) � returns an iterator pointing to the first element in the range [first,last)
which has a value not less than �x�.

upper_bound(first_iterator, last_iterator, x) � returns an iterator pointing to the first element in the range [first,last)
 which has a value greater than �x�.

arr.erase(position to be deleted) � This erases selected element in vector and shifts and resizes the vector elements accordingly.

arr.erase(unique(arr.begin(),arr.end()),arr.end()) � This erases the duplicate occurrences in sorted vector in a single line.

distance(first_iterator,desired_position) � It returns the distance of desired position from the first iterator.
This function is very useful while finding the index.
*/

using namespace std;

int main()
{

     ll n,i;
     cin>>n;
     double a[n+5],sum=0.0;
     for(i=0;i<n;i++)
     {
         cin>>a[i];
         sum+=(1.0/a[i]);
     }
     printf("%.12lf\n",1/sum);


    return 0;
}






Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(void){
  int a[3][6];
  for(int i=0;i<3;i++)
    for(int j=0;j<6;j++)
      cin>>a[i][j];
  for(int i=0;i<3;i++)
    for(int j=2;0<=j;j--){
      a[i][j+3]-=a[i][j];
      if(a[i][j+3]<0){a[i][j+2]-=1;a[i][j+3]+=60;}
    }
  
  for(int i=0;i<3;i++){
    for(int j=0;j<2;j++)
      cout<<a[i][j+3]<<" ";
    cout<<a[i][5]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if(a<=8 && b<=8) puts("Yay!");
	else puts(":(");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#ifndef LOCAL_RUN
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("fast-math")
    #pragma GCC target("avx2,tune=native")
#endif*/
#define X first
#define Y second
using namespace std;

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

const int N = 2e5 + 228;

ll dp[N], arr[N];

int main()
{
    #ifdef LOCAL_RUN
        freopen("input.txt", "r", stdin);
    //#else
        //freopen("tickets.in", "r", stdin);
        //freopen("tickets.out", "w", stdout);
    #endif
	ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    arr[0] = arr[1];
    for (int i = 2; i <= n; i++) {
        dp[i] = min(dp[i-1] + abs(arr[i-1] - arr[i]), dp[i-2] + abs(arr[i-2] - arr[i]));
        dp[i-1] = min(dp[i-1], dp[i] + abs(arr[i] - arr[i-1]));
    }
    cout << dp[n];

    return 0;
}

// 272472LF


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

const int MAX_N = 1e5 + 5, MOD = 1e9 + 7;
int n;
bool dp[MAX_N];
string s;

int main() {
    cin >> s;
   	for (int i = 1; i <= s.size(); i++) {
   		if (i < 5) {
   			dp[i] = false;
   			continue;
   		}

   		if (i == 5) {
   			if (s[0] == 'd' && s[1] == 'r' && s[2] == 'e' && s[3] == 'a' && s[4] == 'm')
   				dp[i] = true;
   			if (s[0] == 'e' && s[1] == 'r' && s[2] == 'a' && s[3] == 's' && s[4] == 'e')
   				dp[i] = true;
   			continue;
   		}

   		if (i == 6) {
   			if (s[0] == 'e' && s[1] == 'r' && s[2] == 'a' && s[3] == 's' && s[4] == 'e' && s[5] == 'r')
   				dp[i] = true;
   			continue;
   		}

   		if (i == 7) {
   			if (s[0] == 'd' && s[1] == 'r' && s[2] == 'e' && s[3] == 'a' && s[4] == 'm' && s[5] == 'e' && s[6] == 'r')
   				dp[i] = true;
   			continue;
   		}

   		if (s[i - 1] == 'm') {
   			if (s[i - 5] == 'd' && s[i - 4] == 'r' && s[i - 3] == 'e' && s[i - 2] == 'a' && s[i - 1] == 'm')
   				dp[i] = dp[i - 5];

   			continue;
   		}


   		if (s[i - 1] == 'e') {
   			if (s[i - 5] == 'e' && s[i - 4] == 'r' && s[i - 3] == 'a' && s[i - 2] == 's' && s[i - 1] == 'e')
   				dp[i] = dp[i - 5];

   			continue;
   		}

   		if (s[i - 1] != 'r')
   			continue;

   		if (s[i - 3] == 'm') {
   			if (s[i - 7] == 'd' && s[i - 6] == 'r' && s[i - 5] == 'e' && s[i - 4] == 'a' && s[i - 3] == 'm' && s[i - 2] == 'e' && s[i - 1] == 'r')
   				dp[i] = dp[i - 7];

   			continue;
   		}
   		if (s[i - 3] == 's') {
   			if (s[i - 6] == 'e' && s[i - 5] == 'r' && s[i - 4] == 'a' && s[i - 3] == 's' && s[i - 2] == 'e' && s[i - 1] == 'r')
   				dp[i] = dp[i - 6];

   			continue;
   		}
   	}

   	cout << (dp[s.size()]? "YES": "NO");
    return 0;
}

Measured memory_bytes: 512
fun main(args: Array<String>) {
    var (n, m)= readLine()!!.split(' ').map { it.toInt() }
    var a=readLine()!!.split(' ').map { it.toInt() }
    var sum=a.sum()
    var count=0
    a.map {
        if(it.toFloat()>=sum.toFloat()/(4*m).toFloat()){
            count++
        } }
    if (count<m){
        println("No")
    }else{
        println("Yes")
    }
}

Measured memory_bytes: 38248
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  string s,s_out;
  cin >> s;
  int x[4];
  for (int i = 0; i<4; i++){
    x[i] = (int)s[i] - (int)'0';
  }
  
  int sum;
  for (int i = 0; i < (1 << 4); i++){
  	sum = x[0];
    s_out = s[0];
    for (int j = 0; j < 3; j++){
      if ((i >> j) & 1){
        sum += x[j+1];
        s_out = s_out + '+' + s[j+1];
      } else {
        sum -= x[j+1];
        s_out = s_out + '-' + s[j+1];
      }
    }
    
    if (sum == 7){
      break;
    }
  }
  s_out = s_out + '=' + '7';
  cout << s_out << endl;
  
}

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


#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;

vector<int> a;


int main(void){
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    ll ans = 0;
    
    if(a + b > 2 * c){
        ll m = min(x, y);
        ans += c * m * 2;
        x-=m;y-=m;
    }

    if(a > c + c){
        ans += c * x * 2;
        x = 0;
    }

    if(b > c + c){
        ans += c * y * 2;
        y = 0;
    }

    cout << ans + x*a + y*b << endl;

    return 0;
}



Measured memory_bytes: 256
n=int(input())
s=list(input())
ans=0
for i in range(n):
    cnt=0
    a=list(set(s[:i:]))
    b=list(set(s[i::]))
    for j in range(len(a)):
        if a[j] in b:
            cnt+=1
    ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 3060
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()

    if s[2] == s[3]:
        if s[4] == s[5]:
            print('Yes')
            sys.exit()

    print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
N,M = list(map(int, input().split()))
A = set(list(map(int, input().split())))
B = set(list(map(int, input().split())))

mod = 10**9+7

a = 0
b = 0
ans = 1

for i in range(N*M,0,-1):
  #print(i,a,b,ans)
  if i in A and i in B:
    ans = ans
    a += 1
    b += 1
  elif i in A: # i not in B
    ans *= b
    ans %= mod
    a+=1
  elif i in B:
    ans *= a
    ans %= mod
    b+=1
  else:
    if a*b - (N*M - i) <= 0:
      print(0)
      break
    else:
      ans *= a*b - (N*M - i)
      ans %= mod
      
else:
  print(ans)
    
    
  


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

int count(vector<string> A) {
    int cnt = 0;
    rep(i, A.size()) {
        rep(j, A[i].size()) {
            if(A[i][j]=='r') ++cnt;
        }
    }
    return cnt;
}


int main() {
    int H, W, K;
    cin >> H >> W >> K;
    string row;
    vector<string> A;
    rep(i, H) {
        cin >> row;
        A.push_back(row);
    }
    int ans = 0;
    rep(h, 1<<H) {
        rep(w, 1<<W) {
            int cnt = 0;
            rep(i, H) {
                rep(j, W) {
                    if(h>>i&1 || w>>j&1) continue;
                    if(A[i][j] == '#') ++cnt;
                }
            }
        if(cnt==K) ++ans;
        }
    }

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

Measured memory_bytes: 3568
N=int(input())
S=["".join(sorted(input())) for n in range(N)]
d={}
for s in S:
    if s not in d:
        d[s]=1
    else:
        d[s]+=1
c=0
for k in d:
    n=d[k]
    c+=(n*(n-1))//2
print(c)


Measured memory_bytes: 19400
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << 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...);
	}
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 1e6 + 5;

ll sm[MAXN];

void sieve()
{
	for(int i=2;i<MAXN;i++)
	{
		if(sm[i]) continue;
		for(int j=i;j<MAXN;j+=i) sm[j] = i;
	}
}

int main()
{
	FAST_IO;

	sieve();
	ll n, ans = 0;
	cin >> n;
	for(int i=1;i<n;i++)
	{
		ll temp = i, res = 1;
		while(temp > 1)
		{
			ll y = sm[temp], cnt = 0;
			while(temp % y == 0)
			{
				temp /= y;
				cnt += 1;
			}
			res *= (cnt + 1);
		}
		ans += res;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11460
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  
  int N, a, b, M, x[11], y[11], z[11], K;
  
  cin >> N >> a >> b >> M;
  for(int j = 1; j <= M; j++){
    cin >> x[j] >> y[j] >> z[j];
  }
  cin >> K;
  for(int j = M; j > 0; j--) {
    if(x[j] == 0){
      if(y[j] == K);
      else if(z[j] == K) swap(y[j], z[j]);
      else continue;
      K = z[j];
    }
    else {
      if(y[j] == K)
      K = z[j];
    }
  }
  cout << a + b * (K - 1) << endl;
  
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
using namespace std;
using ll = long long;
int main()
{
    ll n;
    cin >> n;
    ll ans[n] = {0};
    for (ll i = 1; i < n; i++)
    {
        ll p;
        cin >>p ;
        ans[p - 1]++;

    }
    for (ll i = 0; i < n;i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 5184
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  vector<int>num(N,0);
  for(int i=0;i<N;i++){
    cin >> num[i];
  }
  
  sort(num.begin(),num.end());
  
  cout << num[N / 2] - num[N / 2 - 1] << endl;
  
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main() {
    ll n;
    cin >> n;
    VL x(n), y(n);
    rep(i, 0, n) cin >> x[i] >> y[i];
    VVL f(4, VL(n));
    rep(i, 0, n) f[0][i] = x[i] + y[i];
    rep(i, 0, n) f[1][i] = x[i] - y[i];
    ll mx = 0;
    ll mx1 = *max_element(ALL(f[0]));
    ll mn1 = *min_element(ALL(f[0]));
    ll mx2 = *max_element(ALL(f[1]));
    ll mn2 = *min_element(ALL(f[1]));
    mx = max(mx, mx1 - mn1);
    mx = max(mx, mn1 - mx1);
    mx = max(mx, mx2 - mn2);
    mx = max(mx, mn2 - mx2);
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 14340
import java.io.*;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
int[][] num;
while((line=br.readLine())!=null){
num=new int[10][10];
for(int i=0;i<10;i++){
num[9][i]=(int)(line.charAt(i)-'0');
}
for(int i=8;i>=0;i--){
for(int j=0;j<=i;j++){
num[i][j]=(num[i+1][j]+num[i+1][j+1])%10;
}
}
System.out.println(num[0][0]);
}
}
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

// 素数判定
// から派生して、最初の約数を返す
int isPrime(ll a)
{
    if (a == 1) return 1;
    for (ll i = 2; i * i <= a; i++)
	{
        if(a % i == 0) return i;
    }
    return -1;
}

void solve()
{
	ll n;
	cin >> n;

	ll first_prime = isPrime(n);
	if (first_prime <= 0)
	{
		cout << 1;
		return;
	}
	if (first_prime == 1)
	{
		cout << 0;
		return;
	}

	map<ll, ll> mp;

	int ans = 0;
	for (int i = first_prime; i <= n; i = isPrime(n)) 
	{
		if (i == 1)
		{
			break;
		}
		if (i == -1)
		{
			mp[n]++;
			break;
		}
		while (n % i == 0)
		{
			// cout << i << " ";
			mp[i]++;
			n /= i;
		}
	}

	for(auto& m : mp)
	{
		// cout << m.first << " : " << m.second << endl;
		int i = 1;
		while(m.second >= i)
		{
			m.second -= i;
			++i;
			++ans;
		}
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3656
from collections import Counter

M = 998244353
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
r = 0
if (a[0], c[0]) == (0, 1):
    r = i = 1
    while c[i]:
        r = r * pow(c[i - 1], c[i], M) % M
        n -= c[i]
        i += 1
print((r, 0)[n > 1])


Measured memory_bytes: 19928
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	vector<string> A(n), B(n);
	for (auto& a : A) cin >> a;
	for (auto& b : B) cin >> b;
	int ans = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			if (A[i][j] != B[i][j]) ans++;
	cout << ans << endl;

	return 0;
}


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

int main()
{
	char ch;
    cin>>ch;
    if(ch>='A'&&ch<='Z')
    {
        cout<<'A';
    }
    else
    {
        cout<<'a';
    }
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
int main(){
  ll N;
  cin>>N;
  ll a=N%10;
  if(a==2||a==4||a==5||a==7||a==9){cout<<"hon"<<endl;}
  else if(a==3){cout<<"bon"<<endl;}
  else{cout<<"pon"<<endl;}
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    int a,b; cin >> a >> b;

    cout << max(0, a-2*b) << endl;

    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#define int long long
using namespace std;

typedef pair<int, int> Pii;

void readline(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readline(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}

signed main(){

    int N;

    cin >> N;

    int ans = 1000000000;

    for(int i = 0; i <= N; i++){
        int tmp = 0;
        int six = i;
        int nine = N - i;

        while(six > 0){
            tmp += six % 6;
            six /= 6;
        }
        while(nine > 0){
            tmp += nine % 9;
            nine /= 9;
        }

        if(tmp < ans) ans = tmp;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列以外を出力する
    void write(){

    }
    template<typename First, typename... Rest>
    void write(First first, Rest... rest){
        cout << first << " ";
        write(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    int N, M;
    io.read(N, M);
    vector<int> K(N);
    vector<vector<int>> A(N);
    for(int i = 0; i < N; i++){
        io.read(K[i]);
        A[i].resize(K[i]);
        for(int j = 0; j < K[i]; j++){
            io.read(A[i][j]);
        }
    }
    map<int, int> mp;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < K[i]; j++){
            mp[A[i][j]]++;
        }
    }
    int ans = 0;
    for(auto i = mp.begin(); i != mp.end(); i++){
        if(i->second == N) ans++;
    }
    io.write(ans);
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for _ in range(M)])

AB = sorted(AB, reverse=False, key=lambda x: x[1])

last_b = AB[0][1] - 1  # 最初に潰す橋
cnt = 1  # 上で一つ壊してるので+1
for a, b in AB:
    if a <= last_b:
        continue
    else:
        last_b = b - 1
        cnt += 1
print(cnt)


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

//手前から特定の文字列で切れるところまで切り、残った文字列のsizeを返す
bool cutstr(string S, vector<string> W){
  int cursol = 0;
  while(cursol < S.size()){
    if(S.substr(cursol, 5) == W.at(0) || S.substr(cursol, 5) == W.at(2)){
      cursol += 5;
    }
    else if(S.substr(cursol, 6) == W.at(3)){
      cursol += 6;
    }
    else if(S.substr(cursol, 7) == W.at(1)){
      cursol += 7;
    }
    else return false;
  }
  if(cursol == S.size()) return true;
  return false;
}

int main(){
  string S;
  cin >> S;
  vector<string> W = {"dream", "dreamer", "erase", "eraser"};
  reverse(S.begin(), S.end());
  for(int i = 0; i < 4; i++){
    reverse(W.at(i).begin(), W.at(i).end());
  }
  if(cutstr(S, W)) cout << "YES" << endl;
  else cout << "NO" << endl;

}

Measured memory_bytes: 512
H,W=map(int,input().split())
S=[]
for _ in range(H):
    s=input()
    s=[a for a in s]
    S.append(s)
visited=[[-1 for _ in range(W)] for _ in range(H)]
visited[0][0]=1
stack=[[0,0]]
answer=0
S[0][0]='.'
while len(stack)>0:
    h,w=stack.pop()
    number=0
    for x,y in ([0,1],[0,-1],[1,0],[-1,0]):
        new_w=w+x
        new_h=h+y
        if new_w<0 or new_w>=W or new_h<0 or new_h>=H:
            continue
        elif visited[new_h][new_w]==-1 and S[new_h][new_w]=='#':
            number+=1
            visited[new_h][new_w]=1
            S[new_h][new_w]='.'
            stack.append([new_h,new_w])
            if x==-1 and y==0:
                answer=1
                break
            elif x==0 and y==-1:
                answer=1
                break
        if number>1:
            answer=1
            break
if answer==0:
    print('Possible')
else:
    print('Impossible')


Measured memory_bytes: 62336
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  for(int i=2;i<=10000;i++){
    if((a*i)%b==c){
      cout<<"YES"<<endl;
      break;
    }
    else if(i==10000){
      cout<<"NO"<<endl;
    }
    
  }
    
  return 0;
}


Measured memory_bytes: 256
/******************************************
* NICK : nikhilsinghh59 *
******************************************/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"

#define PB push_back
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
const int M = 1e9+7;

ll pp(ll a) {
    return (a*a*a*a*a);
}

int main()
{   
   
    ll x;
    cin >> x;
    //cout << x << endl;
    //cout << pp(2);

    for(ll i=-1000 ; i<=1000 ; i++) {
        for(ll j=-1000 ; j<=1000 ; j++) {
            //cout << p(i) << endl;
            if((pp(i) - pp(j)) == x) {
                //cout << " jj";
                cout << i << " " << j;
                return 0;
            }
        }
    }

    // for(ll i=0;i<1000;i++){
    //     ll a = v[i].second;
    //     if(mp.find(a - x)!=mp.end()) {
    //         cout << i << " " << mp[a-x];
    //         return 0;
    //     }
    //     if(mp.find(x-a)!=mp.end()) {
    //         cout << i << " " << mp[x-a];
    //         return 0;
    //     }
    //     if(mp.find(x + a)!=mp.end()) {
    //         cout << -1*i << " " << -1*mp[x+a];
    //         return 0;
    //     }

    // }

    // cout << "NOT FOUND" << endl;


    return 0;
}

Measured memory_bytes: 3640
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,
        l:[i64;n],
    }
    let mut ans = 0i64;
    for i in 0..n {
        for j in i + 1..n {
            if l[i] == l[j] {
                continue;
            }
            for k in j + 1..n {
                if l[i] == l[k] || l[j] == l[k] {
                    continue;
                }
                let mut v = vec![l[i], l[j], l[k]];
                v.sort();
                if v[2] < v[0] + v[1] {
                    ans += 1i64;
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2184
def rot(s):
    x=""
    for c in s:
        tmp = ord(c)-ord("a")
        if "a"<=c<="z":
            x += chr((tmp+1) % 26 + ord("a"))
        else:
            x += c
    return x
    
def check(s):
    for word in s.split():
        if word=="the" or word=="this" or word=="that":
            return True
    else: return False

while True:
    try:
        s = raw_input()
        f = False
        for i in range(26):
            if check(s):break
            else: s=rot(s)
        print s
    except:
        break

Measured memory_bytes: 4236
#include <stdio.h>
int main(){
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(A!=B&&A!=C){
    printf("%d",A);
  } else if(B!=A&&B!=C){
    printf("%d",B);
  } else if(C!=A&&C!=B){
    printf("%d",C);
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long dp[3005][3005];
const long long inf=100000000000000000;
int main()
{
int n;
cin>>n;
vector<long long >arr(n);
for(int i=0;i<n;i++)
{
    cin>>arr[i];
}
for(int i=0;i<n;i++)
{
    dp[i][i]=arr[i];
}
for(int l=1;l<=n-1;l++)
{

    for(int i=0;i<=n-l;i++)
    {
        long long mx=-inf;
        mx=max(mx,arr[i]-dp[i+1][i+l]);
        mx=max(mx,arr[i+l]-dp[i][i+l-1]);
        dp[i][i+l]=mx;
        //cout<<setw(10)<<dp[i][i+l]<<" ";
    }
}
cout<<dp[0][n-1]<<endl;

return 0;
}


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

#define NMAX 200000
#define INF 2000000000

#define MOD 1000000007

using namespace std;

int nodes;
int queries;
vector<int> tree[NMAX];
int values[NMAX];
int nodeValues[NMAX];
bool viz[NMAX];

void DFS(int node, int value)
{
    nodeValues[node] = value;
    viz[node] = 1;
    for(int i = 0; i < tree[node].size(); i++)
    {
        if(!viz[tree[node][i]])
        {
            DFS(tree[node][i], value + values[tree[node][i]]);
        }
    }
}

int main()
{
    cin >> nodes >> queries;
    int a, b, x, p;
    for(int i = 0; i < nodes - 1; i++)
    {
        cin >> a >> b;
        a--;
        b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    for(int i = 0; i < queries; i++)
    {
        cin >> p >> x;
        p--;
        values[p] += x;
    }

    DFS(0, values[0]);

    for(int i = 0; i < nodes; i++)
    {
        cout << nodeValues[i] << ' ';
    }

    return 0;
}


Measured memory_bytes: 24192
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

namespace std {
template <> struct hash<pair<int, int>> {
  size_t operator()(const pair<int, int> &p) const {
    constexpr static unsigned s = CHAR_BIT * sizeof(size_t) / 2;
    return (size_t)p.first << s | p.second;
  }
};
}

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(void) {}
  Edge(int src, int dst) : src(src), dst(dst) {}
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void edges_to_graph(Graph &graph, const Edges &edges, const int vertices, const bool directed = true) {
  graph.clear(), graph.resize(vertices);
  for (const auto &e : edges) graph[e.src].emplace_back(e);
  if (!directed) for (const auto &e : edges) graph[e.dst].emplace_back(Edge(e.dst, e.src, e.weight));
}

void dfs(Graph &g, int v, int p, int prev_col, unordered_map<pair<int, int>, int> &cmap) {
  int col = 0;
  for (const auto &e : g[v]) {
    if (e.dst == p) continue;
    ++col;
    if (col == prev_col) ++col;
    cmap[{ v, e.dst }] = col;
    dfs(g, e.dst, v, col, cmap);
  }
}

void bfs(Graph &g, unordered_map<pair<int, int>, int> &cmap) {
  queue<tuple<int, int, int>> que;
  que.push(make_tuple(0, -1, 0));
  while (!que.empty()) {
    int v = get<0>(que.front()), p = get<1>(que.front()), pc = get<2>(que.front());
    que.pop();
    int col = 1;
    for (const auto &e : g[v]) {
      if (e.dst == p) continue;
      if (col == pc) ++col;
      cmap[{ v, e.dst }] = col;
      que.push(make_tuple(e.dst, v, col));
      ++col;
    }
  }
}

Graph graph;
int main(void) {
  int n;
  cin >> n;
  Edges edges(n - 1);
  rep (i, n - 1) {
    int a, b;
    cin >> a >> b;
    edges[i] = {--a, --b, 0};
  }
  edges_to_graph(graph, edges, n, false);
  int maxi = 0;
  rep (i, n) maxi = max(maxi, (int)graph[i].size());
  unordered_map<pair<int, int>, int> cmap;
  // dfs(graph, 0, -1, 0, cmap);
  bfs(graph, cmap);
  cout << maxi << "\n";
  rep (i, n - 1) cout << cmap[{ edges[i].src, edges[i].dst }] << "\n";
  return 0;
}

Measured memory_bytes: 13988
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        String result = s.replace("?", "D");

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 40980
n = int(input())
s = list(map(int,input().split()))
sum = 0
s.insert(0, 0)
s.insert(n+1, 0)
for i in range(n+1):
    sum += abs((s[i])-(s[i+1]))
for j in range(1,n+1):
    print(sum - abs(s[j-1]-s[j]) - abs(s[j]-s[j+1]) +abs(s[j-1]-s[j+1]))

Measured memory_bytes: 14040
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;


const long long MAX = 10000000000;

void dfs(vector<long long> &nums, long long curr) {
    if (curr > MAX) {
        return;
    }

    nums.push_back(curr);

    long long lastDigit = curr % 10;
    if (lastDigit > 0) dfs(nums, 10 * curr + (lastDigit - 1));
    dfs(nums, 10 * curr + lastDigit);
    if (lastDigit < 9) dfs(nums, 10 * curr + (lastDigit + 1));
}

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

    vector<long long> nums;
    for (long long i = 1; i <= 9; i++) {
        dfs(nums, i);
    }
    sort(nums.begin(), nums.end());

    cout << nums[K - 1] << endl;
    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define int long long
using namespace std;

char str[10];
int ans,n;

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

signed main()
{
	n=read();
	ans=n/500*1000;
	n%=500;
	ans+=n/5*5;
	printf("%lld\n",ans);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 100005;
const int M = 200005;

int f[M], s[N], t[N], c[N], tot[M];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, C;
	cin>>n>>C;
	for(int i = 1; i <= n; i++){
		cin>>s[i]>>t[i]>>c[i];
	}
	memset(tot, 0, sizeof(tot));
	for(int i = 1; i <= C; i++){
		memset(f, 0, sizeof(f));
		for(int j = 1; j <= n; j++){
			if(c[j] == i){
				f[2*s[j] - 1]++;
				f[2*t[j] + 1]--;
			}
		}
		for(int j = 1; j < M; j++){
			f[j] += f[j - 1];
		}
		for(int j = 1; j < M; j++){
			if(f[j])tot[j]++;
		}
	}
	int ans = 0;
	for(int i = 1; i < M; i++){
		ans = max(ans, tot[i]);
	}
	cout<<ans<<'\n';

	return 0;
}

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()

ll gcd(ll a, ll b);

ll sum(int n);

void go(){
   int a;
   string s;
   cin>>a>>s;
   if(a>=3200) cout << s;
   else cout << "red";
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll gcd(ll a, ll b){     
   if(b == 0) return a;
   
   return gcd(b, a % b);
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
require 'prime'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n,a,b=gsmi

div=n/(a+b)
mod=n%(a+b)

puts div*a+min(mod,a)

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

#define int long long

using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int n,a[300030],dp[300030];

signed main(){
    cin>>n;
    n*=3;
    rep(i,0,n)cin>>a[i];
    priority_queue<int,vector<int>,greater<int>> que;
    int sum=0;
    rep(i,0,n){
        que.push(a[i]);
        sum+=a[i];
        if(que.size()>n/3){
            sum-=que.top();
            que.pop();
        }
        dp[i]=sum;
    }
    priority_queue<int> que2;
    sum=0;
    for(int i=n-1;i>=0;i--){
        que2.push(a[i]);
        sum+=a[i];
        if(que2.size()>n/3){
            sum-=que2.top();
            que2.pop();
        }
        if(i>=1)dp[i-1]-=sum;
    }
    int ret=dp[n/3-1];
    for(int i=n/3-1;i+n/3<n;i++)ret=max(ret,dp[i]);
    cout<<ret<<endl;
    return 0;
    
    
    
}

Measured memory_bytes: 7284
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort()
cs = [0] * (N + 1)
for i in range(N):
  cs[i + 1] = cs[i] + a[i]
def check(x):
  t = cs[x + 1]
  for i in range(x + 1, N):
    if a[i] <= 2 * t:
      t += a[i]
    else: return False
  return True
ok = N - 1
ng = -1
m = 0
while ok - ng > 1:
  m = (ok + ng) // 2
  if check(m):
    ok = m
  else:
    ng = m
print(N - ok)

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int n, k;
    cin >> n >> k;
    int d[200];
    int a;
    int cnt[200] = {0};
    rep(i,k){
        cin >> d[i];
        rep(j,d[i]) {
            cin >> a;
            a--;
            cnt[a] = 1;
            }
    }
    int rslt = 0;
    rep(i,n){
        if(cnt[i] == 0) rslt += 1;
    }
    cout << rslt << endl;
    return 0;
}


Measured memory_bytes: 3640
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[]
for _ in range(M):
    x,y,c=map(int,input().split())
    xyc.append([x,y,c])
mi=min(a)+min(b)
for i in range(M):
    e=xyc[i][0]-1
    f=xyc[i][1]-1
    g=xyc[i][2]
    h=a[e]+b[f]-g
    mi =min(mi,h)
print(mi)


Measured memory_bytes: 79596
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 40, MAXM = 1005;
char s1[MAXN], s2[MAXM];
long long state[MAXM];
bool bulb[MAXM];
char ans[MAXM];
int main() {
    int n, m, q;
    while(cin >> n >> m >> q && (n || m || q)) {
        long long mask = (1LL << n) - 1;
        for(int i = 0; i < m; i ++) {
            state[i] = mask;
            bulb[i] = 0;
        }
        for(int i = 0; i < q; i ++) {
            scanf("%s %s", s1, s2);
            long long changed = 0, notchanged = 0;
            for(int j = 0; j < n; j ++) {
                changed = changed * 2 + (s1[j] == '1');
            }
            notchanged = mask ^ changed;
            for(int j = 0; j < m; j ++) {
                if(s2[j] - '0' == bulb[j]) {
                    state[j] &= notchanged;
                } else {
                    state[j] &= changed;
                }
                bulb[j] = s2[j] - '0';
            }
        }
//        for(int i = 0; i < m; i ++) {
//            cout << state[i] << endl;
//        }
        for(int i = 0; i < m; i ++) {
            int cnt = 0, res = -1;
            for(int j = 0; j < n; j ++) {
                if(state[i] >> (n - j - 1) & 1) {
                    res = j;
                    cnt ++;
                }
            }
            assert(cnt > 0);
            if(cnt == 1) {
                if(res < 10) {
                    ans[i] = res + '0';
                } else {
                    ans[i] = res - 10 + 'A';
                }
            } else {
                ans[i] = '?';
            }
        }
        ans[m] = 0;
        printf("%s\n", ans);
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<pll> vll;
typedef vector<vl> vvl;

#define fori(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define sz(a) (int)(a).size()
#define fi first
#define se second

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

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

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);

    int n, x, t;
    cin >> n >> x >> t;

    for (int i = 1;; i++)
    {
        if (i * x >= n)
        {
            cout << i * t << endl;
            return 0;
        }
    }

    time_taken();
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(){
  int a,b,c,t;
  scanf("%d%d%d",&a,&b,&c);
  if(a>b){t=a;a=b;b=t;}if(a>c){t=a;a=c;c=t;}
  printf("%d",(b>c?b:c)-a);
}


Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
int pr[30002],n,i,vis[30002];
int main(){
	
	vector <int> v;
	int sum=0;
	cin>>n;
	if(n==3){
		cout<<"2 5 63"<<endl;
		return 0;
	}
	for(i=30000;i>=2;i=i-2){
		if(n>2){
			v.push_back(i);
			vis[i]=1;
			n--;
			sum+=i;
			if(i==8 && n%2==0 && sum%3==0)
			break;
			if(i==6 && n%2==0 && sum%3==0)
			break;
			if(i==4 && n%2==0 && sum%3==0)
			break;
		}
		else
		break;
	}
	int j=3;
	while(n){
		if(sum%j==0 && vis[j]==0){
			for(i=j;i<30000 && n!=0 ;i=i+j)
				if(vis[i]==0 && i%2==1){
					v.push_back(i);
					vis[i]=1;
					n--;
					sum+=i;
				}
		}
		j=j+2;
	}
	for(i=0;i<v.size();i++)
		cout<<v[i]<<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <atcoder/segtree>
#include <iostream>
#include <vector>

using namespace std;

int op(int a, int b) { return max(a, b); }
int default_data() { return 0; }
using SegTree = atcoder::segtree<int, op, default_data>;

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

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

    // dp[i] = the max length of B where B[-1] = i
    const int M = 300000 + 10;
    auto dp = SegTree(M);
    dp.set(A[0], 1);
    for (int i = 1; i < N; i++) {
        auto lb = max(A[i] - K, 0);
        auto ub = min(A[i] + K + 1, M);
        dp.set(A[i], dp.prod(lb, ub) + 1);
    }
    cout << dp.prod(0, M) << endl;

    return 0;
}

Measured memory_bytes: 9796
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramB
    {
        static void Main(string[] args)
        {
            var list = new List<int>() { int.Parse(Console.ReadLine()) };
            var result = 1;

            while (true)
            {
                result++;
                var r = func(list.Last());
                if (list.Contains(r))
                {
                    break;
                }
                list.Add(r);
            }

            Console.WriteLine(result);
        }

        static int func(int n)
        {
            if ((n & 1) == 0)
            {
                return n / 2;
            }
            else
            {
                return 3 * n + 1;
            }
        }
    }
}


Measured memory_bytes: 28152