akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define double ld
#define faster ios_base::sync_with_stdio(false);
typedef pair<int,int> pii;
///------------------------------------------------------------------------
const int inf=1e18;
const int mod=1e9+7;
ifstream in("input.txt");
ofstream out("output.txt");
struct item
{
    int c,w;
    item(){c=0;w=0;}
};
vector<vector<int> > dp;
signed main()
{
    int n;
    cin>>n;
    int w;
    cin>>w;
    vector<item> vec(n);
    for(int i=0;i<n;i++)
        cin>>vec[i].w>>vec[i].c;
    dp.resize(n+1,vector<int>(200000,inf));
    int sz=200000;
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<sz;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j-vec[i-1].c>=0)
                dp[i][j]=min(dp[i][j],dp[i-1][j-vec[i-1].c]+vec[i-1].w);
//            cerr<<"dp["<<i<<"]["<<j<<"]= ";
//            if(dp[i][j]==-inf)
//                cerr<<"inf";
//            else
//                cerr<<dp[i][j];
//            cerr<<"\n";
        }
    }
    int maxi=0;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<sz;j++)
        {
            if(dp[i][j]<=w)
                maxi=max(maxi,j);
        }
    }
    cout<<maxi;
    return 0;
}
























Measured memory_bytes: 159744
import sys
from collections import deque
input = sys.stdin.readline


def main():
    h, w = map(int, input().split())
    ch, cw = map(int, input().split())
    dh, dw = map(int, input().split())
    
    ch += 1
    cw += 1
    dh += 1
    dw += 1
    
    
    s = ["#"*(w+4)]
    s.append("#"*(w+4))
    for i in range(h):
        s.append("##" + input()[:-1] + "##")
    s.append("#"*(w+4))
    s.append("#"*(w+4))
    
    
    ans = [[-1]*(w+4) for _ in range(h+4)]
    for i in range(h+4):
        for j in range(w+4):
            if s[i][j] == "#":
                ans[i][j] = -2
    ans[ch][cw] = 0
    
    move = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    move2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), \
             (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2), \
             (0, -2), (0, -1), (0, 0), (0, 1), (0, 2), \
             (1, -2), (1, -1), (1, 0), (1, 1), (1, 2), \
             (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]
        
    not_yet = deque([(ch, cw)])
    one_time = deque([])
    
    while len(not_yet) > 0:
        x, y = not_yet.popleft()
        one_time.append((x, y))
        for (p, q) in move:
            v1, v2 = x+p, y+q
            if ans[v1][v2] == -1:
                not_yet.append((v1, v2))
                ans[v1][v2] = ans[x][y]
                
        if len(not_yet) == 0:
            while len(one_time) > 0:
                x2, y2 = one_time.popleft()
                for (v1, v2) in move2:
                    i, j = x2+v1, y2+v2
                    if ans[i][j] == -1:
                        ans[i][j] = ans[x2][y2]+1
                        not_yet.append((i, j))
          
    print(ans[dh][dw])
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 93084
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}
bool b[200003];
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n , k;
	cin >> n >> k;
	vector<int> a(n + 1) , c;
	for (int i = 1 ; i <= n ; i++) cin >> a[i];
	int cc = 1;
	while (!b[cc]) {
		b[cc] = 1;
		cc = a[cc];
		k--;
		if (k == 0) {
			cout << cc << endl;
			return 0;
		}
	}
	int ccc = cc;
	do {
		c.push_back(cc);
		cc = a[cc];
	} while (cc != ccc);
	cout << c[k % c.size()] << endl;



	return 0;
}



Measured memory_bytes: 5932
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define AZ 'z'-'a'+1

typedef struct t{
    struct t *parent;
    int score;
}Tree;

Tree* make(int count){
    Tree *t=(Tree*)malloc(sizeof(Tree));
    t->score = count;
    t->parent = NULL;
    return t;
}

int depth(Tree *t,int c){
    if(t==NULL){
        if(c==0){c=1;}
        return c;
    }
    return depth(t->parent,c+1);
}

int main(void){
    char s[100001];
    int count[AZ][2];
    int n,nn,len,i,j,f;
    int min1,num1,min2,num2,sum;
    Tree *ts,**t,*p,*exc;
    scanf("%s",s);
    len = strlen(s);
    n=0;
    for(i=0;i<len;i++){
        f=0;
        for(j=0;j<n;j++){
            if(count[j][0]==s[i]){
                count[j][1]++;
                f=1;
                break;
            }
        }
        if(f==0){
            count[n][0]=s[i];
            count[n][1]=1;
            n++;
        }
    }
    nn=n;
    ts = (Tree*)malloc(sizeof(Tree)*n);t = (Tree**)malloc(sizeof(Tree*)*n);
    for(i=0;i<n;i++){
        ts[i].score=count[i][1];
        ts[i].parent=NULL;
        t[i] = &ts[i];
    }
    while(nn>1){
        min1 = t[0]->score;num1=0;
        min2 = t[1]->score;num2=1;
        if(min1>min2){
            i=min1;min1=min2;min2=i;
            i=num1;num1=num2;num2=i;
        }
        for(i=2;i<nn;i++){
            if(min1>t[i]->score){
                min2=min1;num2=num1;
                min1=t[i]->score;num1=i;
            }else if(min2>t[i]->score){
                min2=t[i]->score;num2=i;
            }
        }
        p = make(t[num1]->score+t[num2]->score);
        t[num1]->parent=p;t[num2]->parent=p;
        if(num1==nn-1){
            if(num2!=nn-2){
                exc=t[num2];t[num2]=t[nn-2];t[nn-2]=exc;
            }
        }else if(num1==nn-2){
            if(num2!=nn-1){
                exc=t[num2];t[num2]=t[nn-1];t[nn-1]=exc;
            }
        }else if(num2==nn-1){
            exc=t[num1];t[num1]=t[nn-2];t[nn-2]=exc;
        }else if(num2==nn-2){
            exc=t[num1];t[num1]=t[nn-1];t[nn-1]=exc;
        }else{
            exc=t[num1];t[num1]=t[nn-1];t[nn-1]=exc;
            exc=t[num2];t[num2]=t[nn-2];t[nn-2]=exc;
        }
        nn--;
        t[nn-1]=p;
    }
    sum=0;
    for(i=0;i<n;i++){
        sum+=depth(ts[i].parent,0)*ts[i].score;
    }
    printf("%d\n",sum);
}


Measured memory_bytes: 2108
import copy
n=int(input())
numl=list(map(int,input().split()))	
chk=sorted(numl)

flag=True
if chk==numl :
  flag=True
else :
  flag=False

for i in range(n) :
  #print(i)
  for j in range(n):
    #print(j)
    temp=copy.deepcopy(numl)
    temp[i]=numl[j]
    temp[j]=numl[i]
    #print(temp)
    if temp==chk :
      flag=True
      break

if flag==True:
  print("YES")
else :
  print("NO")
  







Measured memory_bytes: 3444
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());

			var factorDic = new Dictionary<int, long>();

			for(int i = 2; i <= n; i++)
			{
				var value = i;
				var max = (i + 1) / 2;
				for(int j = 2; j <= max; j++)
				{
					while (value > 1)
					{
						if (value % j == 0)
						{
							if (factorDic.ContainsKey(j))
							{
								factorDic[j]++;
							}
							else
							{
								factorDic.Add(j, 1);
							}

							value /= j;
						}
						else
						{
							break;
						}
					}
				}

				if(value != 1)
				{
					factorDic.Add(value, 1);
				}
			}

			long mod = 1;
			foreach(var value in factorDic.Values)
			{
				mod = mod * (value + 1) % 1000000007;
			}

			Console.WriteLine(mod);
		}
	}
}


Measured memory_bytes: 13152
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll xmin[3], xmax[3], ymin[3], ymax[3]; //decrese, stay, increase
char D[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, 3) {
		xmin[i] = linf;
		ymin[i] = linf;
		xmax[i] = -linf;
		ymax[i] = -linf;
	}
	rep(i, 0, N) {
		ll x, y; char d;
		cin >> x >> y >> d;
		x *= 2;
		y *= 2;
		if(d == 'U') {
			MIN(xmin[1], x);
			MAX(xmax[1], x);
			MIN(ymin[0], y);
			MAX(ymax[2], y);
		}
		else if(d == 'D') {
			MIN(xmin[1], x);
			MAX(xmax[1], x);
			MIN(ymin[2], y);
			MAX(ymax[0], y);
		}
		else if(d == 'R') {
			MIN(xmin[0], x);
			MAX(xmax[2], x);
			MIN(ymin[1], y);
			MAX(ymax[1], y);
		}
		else if(d == 'L') {
			MIN(xmin[2], x);
			MAX(xmax[0], x);
			MIN(ymin[1], y);
			MAX(ymax[1], y);
		}
	}
	ll res = linf;
	rep(i, 0, 400000000) {
		ll txmin = min(min(xmin[0] + i, xmin[1]), xmin[2] - i);
		ll txmax = max(max(xmax[0] - i, xmax[1]), xmax[2] + i);
		ll tymin = min(min(ymin[0] + i, ymin[1]), ymin[2] - i);
		ll tymax = max(max(ymax[0] - i, ymax[1]), ymax[2] + i);
		MIN(res, (txmax - txmin) * (tymax - tymin));
	}
	cout << res / 4.0 << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

#define Flash ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define F first
#define S second
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define ll long long
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const long long MXN = 1e5 + 1;
const long long MNN = 1 * 1e4 + 1;
const long long MOD = 1e8;
const long long INF = 1e18;
const long long OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n, mn = 11111111;

string tostring(int n){
    string t = "";
    while(n != 0){
        t += (n % 10) + '0';
        n /= 10;
    }
    return t;
}

int main(){
    cin >> n;
    for(int i = 1; i <= n / 2; i ++){
        int sum = 0, sum1 = 0;
        string x = tostring(i), y = tostring(n - i);
        for(int j = 0; j < tostring(i).size(); j ++){
            sum += tostring(i)[j] - '0';
        }
        for(int j = 0; j < tostring(n - i).size(); j ++){
            sum1 += tostring(n - i)[j] - '0';
        }
        mn = min(mn, sum + sum1);
    }
    cout << mn;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	ll n;
	cin >> n;
	for(int i=1;i<=n;i++){
		if(i*(i+1)==n*2){
			int ans[1000][1000],cnt=1;
			for(int j=0;j<i;j++){
				for(int k=j;k<i;k++){
					ans[j][k]=cnt;
					ans[k][j]=cnt;
					cnt++;
				}
			}
			int c=1;
			FOR(j,i){
				ans[i][j]=c;
				c+=i-j;
			}
			cout << "Yes" << endl;
			cout << i+1 << endl;
			FOR(j,i+1){
				cout << i << " ";
				FOR(k,i){
					cout << ans[j][k] << " ";
				}
				cout << endl;
			}
			return 0;
		}
	}
	cout << "No" << endl;
}

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

int main(){
	int n;
	cin >> n;
	bool flag = false;
	for (int i = 0; i < n; ++i)
	{
		int a;
		cin >> a;
		if(a%2==1)flag=true;
	}
	if (flag)
		cout << "first" << endl;
	else
		cout << "second" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    string w;
    cin >> w;
    for (char c = 'a'; c <= 'z'; ++c) {
        int count = 0;
        for (const char d : w) {
            if (d == c) {
                ++count;
            }
        }
        if (count % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(10)





void solve() {

	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << " ";
	if(a + b > n) {
		cout << a + b - n << "\n";
	}
	else {
		cout << 0 << "\n";
	}
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	solve();

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <limits>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define print_double(val,a) cout << fixed << setprecision(a) << val << endl;
ll mod = 1e9 + 7;
int alpha[26];
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (abs(a - b) > pow(10, 18)) { cout << "Unfair" << endl; return 0; }
	if (k % 2 == 1) { cout << b - a<<endl; }
	else cout << a - b << endl;

	return 0;
}

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

struct Bamboo {
  int mp;
  int da;
  int db;
  int dc;
};

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

  vector<Bamboo> bamboo;
  for (int i = 0; i < (1 << n); ++i) {
    int length = 0;
    int mp = -10;
    for (int j = 0; j < n; ++j) {
      if ((i >> j) & 1) {
        length += l[j];
        mp += 10;
      }
    }
    mp = max(mp, 0);
    int da = abs(a - length);
    int db = abs(b - length);
    int dc = abs(c - length);
    bamboo.emplace_back(Bamboo {mp, da, db, dc});
  }

  const int m = 1 << n;
  int ret = 1000000000;
  for (int ia = 1; ia < m; ++ia) {
    for (int ib = 1; ib < m; ++ib) {
      if (ia & ib)
        continue;
      for (int ic = 1; ic < m; ++ic) {
        if ((ia & ic) || (ib & ic))
          continue;
        int cost = bamboo[ia].da + bamboo[ia].mp +
          bamboo[ib].db + bamboo[ib].mp +
          bamboo[ic].dc + bamboo[ic].mp;
        ret = min(ret, cost);
      }
    }
  }
  cout << ret << "\n";

  return 0;
}


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

using namespace std;

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


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

struct Query {int l, r, x;};

using I = long long;
const I MOD = 1e9 + 7;

I dp[301][301][301];

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<Query>> Q(N+1);
  for(auto i=0; i<M; ++i) {
    Query q;
    cin >> q.l >> q.r >> q.x;
    Q[q.r].emplace_back(q);
  }

  auto ok = [&](vector<int> v) {
    sort(begin(v), end(v));
    for(auto q: Q[v.back()]) {
      if(q.x==1) if(!(v[1]<q.l))               return false;
      if(q.x==2) if(!(v[0]<q.l && q.l<=v[1]))  return false;
      if(q.x==3) if(!(q.l<=v[0]))              return false;
    }
    return true;
  };

  dp[0][0][0] = 1;
  for(auto r=0; r<N; ++r) for(auto g=0; g<N; ++g) for(auto b=0; b<N; ++b) if(dp[r][g][b]) {
    if(!ok({r, g, b})) dp[r][g][b] = 0;
    auto k = max({r, g, b}) + 1;
    (dp[k][g][b] += dp[r][g][b]) %= MOD;
    (dp[r][k][b] += dp[r][g][b]) %= MOD;
    (dp[r][g][k] += dp[r][g][b]) %= MOD;
  }

  I res = 0;
  for(auto i=0; i<N; ++i) for(auto j=0; j<N; ++j) if(ok({N, i, j})) (res += dp[N][i][j] + dp[i][N][j] + dp[i][j][N]) %= MOD;
  cout << res << endl;
}


Measured memory_bytes: 213376
s = input()

a = int(s[0:2])
b = int(s[2:4])

if a >= 1 and a <=12:
    if b>=1 and b<=12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if b>=1 and b<=12:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int MAXN=2e5+5;
ll a[MAXN],b[MAXN];
int n;
ll k;
bool check(ll mid){
	ll ret=0;
	for (int i=1;i<=n;i++){
		ll tmp=mid/b[i];
		if (a[i]>tmp) tmp=a[i]-tmp;
		else tmp=0;
		ret+=tmp;
	}
	return ret<=k;
}
bool cmp(ll a,ll b){ return a>b; }
int main(){
	scanf("%d%lld",&n,&k);
	ll mx=0;
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for (int i=1;i<=n;i++) scanf("%lld",&b[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+n+1,cmp);
	ll l=-1,r=1e12,mid;
	while (l+1<r){
		mid=(l+r)>>1;
		if (check(mid)) r=mid;
		else l=mid;
	}
	while (r>=1&&check(r-1)) r--;
	printf("%lld\n",r);
	return 0;
}


Measured memory_bytes: 3328
import sys
input=sys.stdin.readline  #危険！基本オフにしろ！

def BELLMANFORD(point,d,n):
    cost       = [-float("inf")for node in range(n+1)]
    preference = [None         for node in range(n+1)]      #最適路のこと 
    cost[point]= 0
    for i in range(n-1):                                  #経路の長さは最大n-1であるため
        for now,lis in d.items():
            for nex,c in lis:
                if cost[nex]<cost[now]+c:
                    cost[nex]=cost[now]+c
                    preference[nex]=now
 
    negative=[0]*n                                        #負閉路の長さは最大nであるため
    
    for i in range(n):                  #閉路判定
        for now,lis in d.items():
            for nex,c in lis:
                if negative[now-1]==1:
                    negative[nex-1]=1
                if cost[nex]<cost[now]+c:
                    cost[nex]=cost[now]+c
                    preference[nex]=now
                    negative[now-1]=1
 
    return cost,negative


def main():
    n,m=map(int,input().split())
    
    d={}
    for s in range(m):
        a,b,c=map(int,input().split())
        if a in d:
            d[a].append((b,c))
        else:
            d[a]=[(b,c)]
    
    x,y=(BELLMANFORD(1,d,n))
    
    if y[n-1]>0:
        print("inf")
    else:
        print(x[n])


if __name__ == '__main__':
    main()


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

int main() {
	int A , B;
	cin >> A >> B;
	int ans = A+B;
	if(ans < A - B){
		ans = A - B;
	}
	if(ans < A * B){
		ans = A*B;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int x;cin >> x;
   int ans = 1;
   for(int i=2;i<=x;i++){
      for(int j=2;j<=x;j++){
         if(pow(i,j)<=x){
            ans = max((int)pow(i,j),ans);
         }
         else break;
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())

cntW = 0
for s in S:
    if s == '.':
        cntW += 1

cntB = 0
MIN = 10 ** 5
for i in range(N+1):
    MIN = min(cntW+cntB,MIN)
    if i < N:
        if S[i] == '#':
            cntB += 1
        else:
            cntW -= 1

print(MIN)

Measured memory_bytes: 4840
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string S;

void solve(){
    int n = S.size();
    int cnt = 0;
    for(int i=0; i<(n+1)/2; i++){
        if(S[2*i] == '1') cnt++;
    }
    for(int i=0; i<n/2; i++){
        if(S[2*i+1] == '0') cnt++;
    }
    cout << (cnt < (n-cnt) ? cnt : (n-cnt)) << endl;
}

int main(){
    cin >> S;
    solve();
    return 0;
}


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

// ll extended_gcd(ll a, ll b, ll &x, ll &y)
// {
//     if(a==0)
//     {
//         x = 0;
//         y = 1;
//         return b;
//     }
    
//     ll x1,y1;
//     ll g = extended_gcd(b%a, a, x1, y1);
    
//     x = y1-(b/a)*x1;
//     y = x1;
//     return g;
// }

// ll powe(ll x,ll n) {
//   if(x==0) return 0;
//   if(n==0) return 1;
//   ll val = powe(x,n/2);
//   if(n%2) return (((val*val)%N)*x)%N;
//   return (val*val)%N;
// }

// ll comb(ll n, ll k) { 
//     if(k==0) return 1;
//     if(k==n) return 1;
//     return (((mods[n]*invmods[n-k])%N)*invmods[k])%N;
// }

// ll cofac(vector<vector<ll> > &adj) {
//   ll tot = 1, idx;
//   ll res = 1;

//   for(ll i=1;i<adj.size();i++) {
//     idx = i;

//     while(idx<adj.size() && !adj[idx][i])
//       idx++;

//     if(idx==adj.size())
//       return 0;

//     if(idx!=i) {
//       swap(adj[i],adj[idx]);
//       if((idx-i)%2)
//         res = -res;
//     }

//     vector<ll> temp(adj[i].begin(),adj[i].end());

//     ll val = temp[i];
//     for(ll j=i+1;j<adj.size();j++) {
//       ll ids[b] = adj[j][i];

//       for(ll k=i+1;k<adj.size();k++) {
//         adj[j][k] = ((val*adj[j][k])%N - (ids[b]*temp[k])%N + 2*N)%N;
//       }

//       tot = (tot*val)%N;
//     } 
//   }

//   for(ll i=1;i<adj.size();i++)
//     res = (res * adj[i][i])%N;
  
//   ll x,y;
//   extended_gcd(tot,N,x,y);
//   // cout<<(res*x)%N<<endl;
//   return (2*N+(res*x)%N)%N;
// }




int main() {

  ll n,k;
  cin>>n>>k;

  vector<ll> A(n,0), temp;
  for(ll i=0;i<n;i++)
    cin>>A[i];

  temp = A;
  sort(temp.begin(),temp.end());

  ll sum = 0;
  ll prev = 0;

  for(ll i=1;i<n;i++) {
    if(temp[i]==temp[i-1]) {
      sum = (sum+prev)%N;
    }
    else {
      prev = i;
      sum = (sum+prev)%N;
    }
  } 
  sum = (sum*((((k-1)*k)/2)%N))%N;

  ll c = 0;
  for(int i=0;i<n;i++) {
    for(int j=i+1;j<n;j++)
      if(A[j]<A[i])
        c = (c+1)%N;
  }

  sum = (sum + (c*k)%N)%N;

  cout<<sum<<endl;




  return 0;
} 


Measured memory_bytes: 256
def solve():
  K, A, B = map(int, input().split())
  if B - A <= 2: return K + 1 # 交換による利益なし
  if K - 1 < A: return K + 1  # 交換できる回数なし

  # ビスケットをAまで貯めれば、それ以降は継続した売り買いが可能
  # 売り買いの2回の操作で得られるのは、(B - A)分の利益
  # 残り操作回数が奇数だった場合、ビスケットを1枚増やす操作に割り当てる
  K -= A - 1
  N = K // 2
  mod = K % 2
  return A + (B - A) * N + mod

print(solve())


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

int main() {
    int N, A_i, k, i;

    cin >> N;
    set<int> B;

    for(i=0; i<N; i++) {
        cin >> A_i;
        B.insert(A_i);
    }

    k = B.size();

    if(k%2 == 1) {
        cout << k << endl;
    }
    else {
        cout << k-1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
long long mpow(int x){
  long long i = 1;
  for (int j = 0; j < x; j++) i=(i*2);
  return i%mod;
}
int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<long long> m(61);
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 61; j++){
      m[j]+=A[i]%2;
      A[i]/=2;
    }
  }
  long long res;
  for (int i = 0; i < 61; i++){
    res += (m[i] * (N - m[i]))%mod * mpow(i);
    res %= mod;
  }
  cout << res%mod;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h> 
using namespace std;
int main()
{
	long long n,i,j,ans1=0,ans2=0;
	cin>>n;
	long long a[n+2],b[n+2];
	for (i=1;i<=n;i++)
	{
		cin>>a[i];
		b[i]=a[i];
	}
	/*for (i=1;i<=n;i++)
	{
		ans1=max(ans1,a[i]);
		if (a[i]!=ans1)
		   ans2=max(ans2,a[i]);
    }*/
    sort(b+1,b+n+1);
    ans1=b[n];
    ans2=b[n-1];
	for (i=1;i<=n;i++)
	{
		if (a[i]!=ans1)
		   cout<<ans1<<endl;
		else
		   cout<<ans2<<endl;
	}
	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

bool isIn(int r, int c) { return 0 <= r and r < 8 and 0 <= c and c < 8; }

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> pos(n);
  REP(i, n) {
    int r, c;
    cin >> r >> c;
    pos[i] = make_pair(r, c);
  }

  vi row(8, 0);
  vi col(8, 0);
  REP(i, 8) {
    row[i] = i;
    col[i] = i;
  }

  vector<vector<bool>> grid(8, vector<bool>(8));

  while (next_permutation(ALL(row))) {
    while (next_permutation(ALL(col))) {
      REP(i, 8) {
        REP(j, 8) { grid[i][j] = false; }
      }
      REP(i, 8) { grid[row[i]][col[i]] = true; }

      bool flag = true;
      REP(i, 8) {
        REP(r, 8) {
          if (r == row[i])
            continue;
          int diff = r - row[i];
          if ((isIn(r, col[i] + diff) and grid[r][col[i] + diff]) or
              (isIn(r, col[i] - diff) and grid[r][col[i] - diff])) {
            flag = false;
            break;
          }
        }
        REP(j, n) {
          if (!grid[pos[j].first][pos[j].second]) {
            flag = false;
            break;
          }
        }
      }

      if (flag) {
        REP(i, 8) {
          REP(j, 8) { cout << (grid[i][j] ? 'Q' : '.'); }
          cout << '\n';
        }
        return 0;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 3108
#include <algorithm>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N;
  while (cin >> N) {
    vector<string> W(N);
    for (int i = 0; i < N; i++) cin >> W[i];
    bool ok = true;
    for (int i = 1; i < N; i++) {
      ok &= W[i - 1].back() == W[i].front();
    }
    ok &= set<string>(W.begin(), W.end()).size() == N;
    cout << (ok ? "Yes" : "No") << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
string ans="";
void dfs(int pos,int v,string s,string op){
    if(pos==4){
        if(v==7)ans=op+"=7";
        return;
    }
    dfs(pos+1,v+(s[pos]-'0'),s,op+"+"+s[pos]);
    dfs(pos+1,v-(s[pos]-'0'),s,op+"-"+s[pos]);
}
int main(){
    string s;
    cin>>s;
    string op="";
    dfs(1,s[0]-'0',s,op+s[0]);
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  if(a + b == 15) cout << "+" << endl;
  else if(a * b == 15) cout << "*" << endl;
  else cout << "x" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "Local_Debug.h"
using namespace std;
#define Endl endl
#define debug(x) cout << #x << " = " << (x) << endl
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 5;
ll n;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0), cout.setf(ios::fixed), cout.precision(10);
	while (cin >> n)
		cout << double((n + 1) / 2) / double(n) << endl;
}
/*
4
5
1
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
using namespace std;
int main()
{
//fastio;
char a[3];
cin>>a[0]>>a[1]>>a[2];
if(a[0]=='1')
cout<<9;
else if(a[0]=='9')
cout<<1;
else
cout<<a[0];
if(a[1]=='1')
cout<<9;
else if(a[1]=='9')
cout<<1;
else
cout<<a[1];
if(a[2]=='1')
cout<<9;
else if(a[2]=='9')
cout<<1;
else
cout<<a[2];
}


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

using namespace std;

int main(){
	int N; cin >> N;
	int A[N];
	for(int i = 0; i < N; ++i) cin >> A[i];
	for(int i = 0; i < N; ++i){
		int x = A[i];
		int cnt = 0;
		while(1){
			if(x%2 == 0){
				x /= 2;
				cnt++;
			}else{
				A[i] = cnt;
				break;
			}
		}
	}
	cout << *min_element(A, A + N) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n;
	cin>>n;
	while(n--){
		string s="";
		rep(i,8){
			string q="";
			char c;cin>>c;
			int t;
			if(isalpha(c))t=c-'a'+10;
			else t=c-'0';
			rep(j,4){
				q=(char)(t%2+'0')+q;
				t/=2;
			}
			s+=q;
		}
		int out=0;
		int t=1;
		for(int i=24;i>0;i--){
			out+=t*(s[i]-'0');
			t*=2;
		}
		if(s[0]=='1')cout<<"-";
		cout<<out<<".";
//		
		t=10000000; 
		out=0;
		for(int i=25;i<32;i++){
			t/=2;
			out+=t*(s[i]-'0');
		}
		if(out==0)cout<<0<<endl;
		else{
			int t=7;
			while(t>1&&out%10==0){out/=10;t--;}
			//cout<<out<<endl;
			printf("%0*d\n",t,out);
		}

	}
}

Measured memory_bytes: 1252
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
0
)");
#define cin input
#endif

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

	set<int> v6{1, 6, 6*6, 6*6*6, 6*6*6*6, 6*6*6*6*6, 6*6*6*6*6*6};
	set<int> v9{9, 9*9, 9*9*9, 9*9*9*9, 9*9*9*9*9};

	int r = 99999;
	for (int i = 0; i <= n; i += 9)
	{
		int j = n - i;
		int k = i;
		int c = 0;
		while (j)
		{
			j -= *--v6.upper_bound(j);
			++c;
		}
		while (k)
		{
			k -= *--v9.upper_bound(k);
			++c;
		}
		r = min(r, c);
	}

	cout << r << endl;

	return 0;
}


Measured memory_bytes: 256
A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
i=gets.chomp.to_i

puts A[i-1]

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

int main(){
    int k,s;
    cin >> k >> s;
    int count = 0;
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            if(0 <= s-i-j && s-i-j <= k){
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

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

using ll = long long int;

int q;
ll a, b;

ll ans;

int main(void) {
  // Here your code !
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
    ll c = -1;
    scanf("%lld %lld", &a, &b);

    if (a > b) swap(a, b);

    // find max c where c ^ 2 < a * b
    for (int base = ceil(sqrt(a * b)); base >= 0; --base) {
      if ((ll)base * (ll)base < a * b) {
        c = (ll)base; break;
      }
    }

    if (a == b || a + 1 == b) {
      ans = 2 * a - 2;
    }
    else if (c * (c + 1) >= a * b) {
      ans = 2 * c - 2;
    }
    else {
      ans = 2 * c - 1;
    }
    printf("%lld\n", ans);
  }

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    char str[1000];
    int i, f, score, len;
     
    while (gets(str) != NULL){
        if (str[0] == '0'){
            break;
        }
         
        score = 0;
        i = 0;
		f = 0;
         
        len = strlen(str);
         
        while (i < len){
            if (str[i] == '1' && (str[i + 1] >= '0' && str[i + 1] <= '3')){
                score += 10;
                i += 3;
            }
            else if (str[i] == '1'){
                score += 1;
				f = 1;
                i += 2;
            }
            else if (str[i] >= '2' && str[i] <= '9'){
                score += (str[i] - '0');
                i += 2;
            }
        }
        if (score > 21){
        	printf("0\n");
        }
		else if (f && score + 10 <= 21){
			printf("%d\n", score + 10);
		}
		else {
			printf("%d\n", score);
		}
    }
     
    return (0);
}

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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll S;
    cin >> S;
    ll x1 = 0, y1 = 0;
    ll x2 = 1e9, y2 = 1;
    ll x3, y3;
    if (S==1e18) x3 = 0, y3 = 1e9;
    else {
        y3 = S / (int)1e9 + 1;
        x3 = 1e9 - S % (int)1e9;
    }
    cout << x1 << " " << y1 << " ";
    cout << x2 << " " << y2 << " ";
    cout << x3 << " " << y3 << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int n,c=0;
  cin >> n;
  vector<int> f(101);
  for(int i=0;i<n;i++){
    int d;
    cin >> d;
    f.at(d) = 1;
  }
  for(int i=0;i<101;i++){
    c += f.at(i);
  }
  cout << c;
}

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

int main(){
 	int A,B,C,D;
  	cin>>A>>B>>C>>D;
  	if(A+B>C+D)
      cout<<"Left"<<endl;
  	else if(A+B==C+D)
      cout<<"Balanced"<<endl;
  	else
      cout<<"Right"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef long long int ll;

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

typedef long long int ll;

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

int sim(int pos){
	for(int i=0;i<q;i++){
		if (t[i]==s[pos]){
			pos += (d[i]=='R') ? 1 : -1;
		}
		if (pos < 0) return -1;
		if (pos >= n) return 1;
	}
	return 0;
}

int main(void){
	cin >> n >> q;
	cin >> s;
	for(int i=0;i<q;i++) cin >> t[i] >> d[i];

	// 何番目まで左に落ちるか
	int lo = -1, hi = n, mid1, mid2;
	while(lo+1<hi){
		// cerr << lo << " " << hi << endl;
		mid1 = (lo + hi) / 2;
		if (sim(mid1) == -1){
			lo = mid1;
		}else{
			hi = mid1;
		}
	}
	int left = lo;
	// 何番目まで右に落ちないか
	lo = -1, hi = n;
	while(lo+1<hi){
		// cerr << lo << ":" << hi << endl;
		mid2 = (lo + hi) / 2;
		if (sim(mid2) == 1){
			hi = mid2;
		}else{
			lo = mid2;
		}
	}
	int right = lo;
	// cerr << left << " and " << right << endl;
	cout << right - left << endl;
	


    return 0;
}


Measured memory_bytes: 1028
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		String[] substr = str.split(" ", 0);


		String s = substr[0];
		int n = Integer.parseInt(substr[0]);
		int k = Integer.parseInt(substr[1]);
		int i = 1;
		int target = k;
		while (true) {

			if (n < target) {
				break;
			}
			target = target * k;
			i++;

		}
		scan.close();
		System.out.println(i);
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vt<i64> a(n);
  rep(i, 0, n) cin >> a[i];

  vt<i64> tmp;
  rep(i, 1, 33) {
    tmp.push_back(1ll << i);
  }
  map<i64, int> mp;
  rep(i, 0, n) mp[-a[i]]++;

  int ans = 0;
  for(auto &it : mp) {
    i64 num = -it.first;
    for(int i = tmp.size() - 1; i >= 0; --i) {
      if(!mp.count(-(tmp[i] - num))) continue;

      if(tmp[i] - num == num) {
        ans += it.second / 2;
        it.second %= 2;
      }
      else {
        int cnt = min(it.second, mp[-(tmp[i] - num)]);
        ans += cnt;
        it.second -= cnt;
        mp[-(tmp[i] - num)] -= cnt;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

ll cnt[10][10]; // cnt[a][b] := 先頭がaで末尾がbの数の個数
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    int N;
    cin >> N;
    for(int i=1;i<=N;i++){
        int head = to_string(i)[0] - '0';
        int end  = i%10;
        cnt[head][end]++;
    }
    ll ans = 0;
    for(int i=1;i<=9;i++)for(int j=1;j<=9;j++){
        ans += cnt[i][j] * cnt[j][i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right

N = int(input())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort()
C.sort()
ans = sum([bisect_left(A, b) * (N - bisect_right(C, b)) for b in B])
print(ans)


Measured memory_bytes: 23092
fun main(args: Array<String>) {
    val (a, b, k) = readLine()!!.split(" ").map(String::toInt)
    if (b - a < 2 * k) {
        for (i in a..b) println(i)
    } else {
        for (i in 0 until k) {
            println(a + i)
        }
        for (i in 0 until k) {
            println(b - k + i + 1)
        }
    }
}

Measured memory_bytes: 37872
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

typedef long long ll;
//vector<int>


using namespace std;

int main() {
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    sort(a.begin(),a.end());
    ll MIN=1000000007;
    int ans=0;
    if (ll(a.at(n-1))%2==0){
        for(int i=0;i<n-1;i++){
            if(MIN>=abs(a.at(n-1)/2-a.at(i))){
                MIN=abs(a.at(n-1)/2-a.at(i));
                ans=a.at(i);
            }
        }
    }
    if (ll(a.at(n-1))%2==1){
        for(int i=0;i<n-1;i++){
            if(MIN>=min(abs(a.at(n-1)/2-a.at(i)), abs(a.at(n-1)/2+1-a.at(i)))){
                MIN=min(abs(a.at(n-1)/2-a.at(i)), abs(a.at(n-1)/2+1-a.at(i)));
                ans=a.at(i);
            }
        }
    }

    cout<<a.at(n-1)<<" "<<ans<<endl;


	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define out(x) cout << (x) << endl;
#define outs(x) for(auto i : x) cout << i << " ";
ll gcd(ll a,ll b){while(b){ll tmp = a % b;a = b;b = tmp;}return a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}

int main() {
  str n;cin >> n;
  if(n[0] == n[2]) puts("Yes");
  else puts("No");
  return 0;
}

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

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


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    cin>>n;
    cout<<(n+1)/2<<endl;
    
    return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int n, t;
  cin >> n >> t;

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

  int mn_a = 1 << 30;
  vector<int> df;
  for (int i = 0; i < n; i++) {
    mn_a = min(mn_a, a[i]);
    df.push_back(a[i] - mn_a);
  }
  sort(df.begin(), df.end());
  cout << upper_bound(df.begin(), df.end(), df.back()) - lower_bound(df.begin(), df.end(), df.back()) << endl;

  return 0;
}

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

int main(){
	int N;
	int T[100];
	int M;
	int P[100];
	int X[100];

	cin >> N;
	for(int i=0;i<N;i++)
		cin >> T[i];

	cin >> M;
	for(int i=0;i<M;i++)
		cin >> P[i] >> X[i];
	
	int sum;
	for(int i=0;i<M;i++){
		sum = 0;
		for(int j=0;j<N;j++){
			 if((P[i]-1) != j)
				 sum+=T[j];
			 else sum+=X[i];
		}
		cout << sum << endl;
	}
	return 0;
}



Measured memory_bytes: 256
dataset = []
while True:
    x, y = map(int, input().split())
    if (x < 0 and x > 10000) and (y < 0 and y > 10000):
        break
    elif (x is 0) and (y is 0): 
        break

    listed = []
    listed.append(x)
    listed.append(y)
    dataset.append(listed)
    if len(dataset) >= 3000:
        break

for i in dataset:
    if i[0] > i[1]:
        print("{0} {1}".format(str(i[1]), str(i[0])))
    elif i[0] < i[1]:
        print("{0} {1}".format(str(i[0]), str(i[1])))
    else:
        print("{0} {1}".format(str(i[0]), str(i[1])))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, L; cin >> n >> L;
    vector<int> a(n); cin >> a;
    int pos = -1;
    REP(i, n-1) {
        if (a[i] + a[i+1] >= L) {
            pos = i;
        }
    }
    if (pos < 0) {
        cout << "Impossible" << endl;
    }
    else {
        cout << "Possible" << endl;
        FOR(i, 0, pos) {
            cout << i+1 << endl;
        }
        RFOR(i, pos, n-1) {
            cout << i+1 << endl;
        }
    }
}


Measured memory_bytes: 1280
#include<stdio.h>
int main(){
    int n,i;
    scanf("%d",&n);
    int a[n+1],b[n+1],c[n+1];
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(i=1;i<n;i++)
        scanf("%d",&c[i]);
    int ans=b[a[1]];
    for(i=1;i<n;i++){
        if(a[i+1]==1+a[i])
            ans+=c[a[i]];
        ans+=b[a[i+1]];
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};

int main(){
  double a;
  cin >> a;
  cout << fixed << setprecision(15);
  double b=100;
  int i=0;
  while(b<a){
    b=floor(b*1.01);
    i++;
  }
  cout << i;
}

Measured memory_bytes: 3724
A, B, C, D = map(int, input().split())
MOD = 998244353

dp = [[0] * (D + 2) for _ in range(C + 2)]
dp[A][B] = 1

for h in range(A, C + 1):
    for w in range(B, D + 1):
        d = dp[h][w] % MOD
        dp[h + 1][w] += d * w
        dp[h][w + 1] += d * h
        dp[h + 1][w + 1] -= d * w * h % MOD
print(dp[C][D] % MOD)


Measured memory_bytes: 136932
from collections import defaultdict
from itertools import combinations

N = int(input())
Ns = defaultdict(int)
for _ in range(N):
    n = input()
    if n[0] in 'MARCH':
        Ns[n[0]] += 1

if len(Ns.keys()) < 3:
    print(0)
    quit()

ans = 0
for c in combinations(Ns.keys(), 3):
    ans += Ns[c[0]] * Ns[c[1]] * Ns[c[2]]
print(ans)

Measured memory_bytes: 3316