akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ARC062_C
{
    class Program
    {
        static long N;
        static long T, A, t, a;
        static void Main(string[] args)
        {
            N = scan[0];
            var q = scan;
            T = q[0]; A = q[1];

            for (long i = 1; i < N; i++)
            {
                q = scan;
                t = q[0]; a = q[1];

                if(t - T >= 0 && a -A >= 0)
                {
                    T = t; A = a; continue;
                }

                long tx = (T % t == 0 || T / t == 0) ? T / t : T / t + 1;
                long ax = (A % a == 0 || A / a == 0) ? A / a : A / a + 1;

                long max = Math.Max(tx, ax);

                T = t * max;
                A = a * max;

                //Console.WriteLine(T+" "+A);
            }

            WriteLine(T + A);
        }

        static long[] scan { get { return Array.ConvertAll(ReadLine().Split(), long.Parse); } }
    }
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	auto dp = makeVector(N+1, 64, 0ll);

	dp[0][63] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 64; j++) {
			int a = j>>4;
			int b = (j>>2)&3;
			int c = j&3;
			//A
			(dp[i+1][((j<<2)&63)] += dp[i][j]) %= mod;
			//G
			if (b != 0 || c != 2) (dp[i+1][((j<<2)&63) | 1] += dp[i][j]) %= mod;
			//C
			if ((a != 0 || b != 1) && (a != 0 || c != 1) && (b != 0 || c != 1) && (b != 1 || c != 0)) {
				(dp[i+1][((j<<2)&63) | 2] += dp[i][j]) %= mod;
			}
			//T
			(dp[i+1][((j<<2)&63) | 3] += dp[i][j]) %= mod;
		}
	}
	
	ll sum = 0;
	for (int i = 0; i < 64; i++) {
		(sum += dp[N][i]) %= mod;
	}
	cout << sum << el;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3644
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>

#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)

using namespace std;

const ll sz=100005;
const ll szz=1000006;

int main()
{
    Ryuga;
    
    string s;
    cin>>s;
    if(s[1]=='R')
        cout<<"ABC";
    else
        cout<<"ARC";
    
}//Goodbye...

Measured memory_bytes: 3652
#!/usr/bin/env python3


def max_sum_strength(n, xs):
    ys = sorted(xs, reverse=True)
    res = sum(ys[i] for i in range(1, 2 * n, 2))
    return res


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    res = max_sum_strength(n, xs)
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 37084
#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() {
  int n;
  cin >> n;
  vector<int> a(n);
  int s=0;
  rep(i,n){
    int b;
    cin >> b;
    s^=b;
    a[i]=b;
  }
  rep(i,n){
    int res=s^a[i];
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 4052
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
using namespace std;
#define _LIBCPP_DEBUG 0
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> vec(n);
  REP(i,n) cin >> vec[i];
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int alice = 0, bob = 0;
  REP(i,n) {
    if(i%2 == 0) alice += vec[i];
    if(i%2 == 1) bob   += vec[i];
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int dy[] = {0, 0, 1, -1};
    int dx[] = {1, -1, 0, 0};

    for(;;){
        vector<string> s(14);
        s[0] = s[13] = string(14, '0');
        for(int i=0; i<12; ++i){
            if(!(cin >> s[i+1]))
                return 0;
            s[i+1] = '0' + s[i+1] + '0';
        }

        vector<vector<bool> > check(14, vector<bool>(14, false));
        int ret = 0;
        for(int i=1; i<=12; ++i){
            for(int j=1; j<=12; ++j){
                if(s[i][j] == '0' || check[i][j])
                    continue;
                ++ ret;
                queue<pair<int, int> > q;
                q.push(make_pair(i, j));
                check[i][j] = true;
                while(!q.empty()){
                    int y0 = q.front().first;
                    int x0 = q.front().second;
                    q.pop();
                    for(int k=0; k<4; ++k){
                        int y = y0 + dy[k];
                        int x = x0 + dx[k];
                        if(s[y][x] == '1' && !check[y][x]){
                            q.push(make_pair(y, x));
                            check[y][x] = true;
                        }
                    }
                }
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
/*"You can do anything you set your mind to,man" - Eminem*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define llpow(a,b) (ll)(pow(a,b)+0.5)
#define l_b(a,val) min((int)a.size()-1, (int)(lower_bound(a.begin(),a.end(),val)-a.begin()))
#define f first
#define s second
#define INF 9223372036854775807
const  int mod = 1000000007;
void add(ll& a, ll b){a+=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
void mul(ll& a, ll b){a*=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
ll binexpomodulo(ll x, ll y){ll res =1;x%=mod;if(!x)return 0;while(y){if(y&1){mul(res, x);}mul(x,x);y>>=1;}return res;}
ll nCrInOr(ll n, ll r){ll res = 1;if(r>n-r)r = n-r;ll rin = 1;for(ll i = 1; i <=r ; i++)rin = (rin*i)%mod;rin = binexpomodulo(rin,mod-2);for(ll i = 1; i <= r; i++)res = (res*(n-i+1))%mod;res = (res*rin)%mod;return res;}
int msb(ll n){int ans;for(int i = 0 ; i < 64;  i++)if(n&(1LL<<i))ans = i+1;return ans;}
void strrev(string& s){int n = (s.size());for(int i = 0 ; i < n/2; i++)swap(s[i],s[n-1-i]);}
int main()
{
	int n; cin>>n;
	ll a[n];
	for(int i = 0 ; i < n ;i++){
		cin>>a[i];
	}
	ll dp[n] = {INF};
	dp[0] = 0;
	dp[1] = abs(a[1]-a[0]);
	for(int i = 2; i < n; i++)
		dp[i] = min(abs(a[i]- a[i-1])+ dp[i-1], abs(a[i]- a[i-2]) + dp[i-2]);
	cout<<dp[n-1]<<endl;
  	return 0;
}

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

int nMatch[10] = {0,2,5,5,4,5,6,3,7,6};

int main(){
    int N, M;
    vector<int> A;
    cin >> N >> M;
    A = vector<int>(M,0);
    for(int i=0; i<M; i++) cin >> A[i];
    sort(A.begin(), A.end());

    vector<int> dp(N+1,-1);
    dp[0] = 0;
    for(int i=0; i<=N; i++){
        if(dp[i] == -1) continue;
        for(int j=0; j<M; j++){
            int nxt = i + nMatch[A[j]];
            if(nxt>N) continue;
            dp[nxt] = max(dp[nxt], dp[i]+1);
        }
    }
    int nDigit = dp[N];
    string ans = "";
    while(nDigit>0){
        for(int i=M-1; i>=0; i--){ 
            if(N-nMatch[A[i]]>=0 && dp[N-nMatch[A[i]]] == nDigit-1){
                ans += to_string(A[i]);
                N-=nMatch[A[i]];
                break;
            }
        }
        nDigit--;
    }
    cout << ans << endl;
}


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

int main(){
  char a,b,c,d;
  cin>>a>>b>>c>>d;
  if((a=='0' && b>='1' && b<='9')||(a=='1' && b>='0' && b<='2')){
    if((c=='0' && d>='1' && d<='9')||(c=='1' && d>='0' &&d<='2'))
    cout<<"AMBIGUOUS";
    else
    cout<<"MMYY";
  }
  else if((c=='0' && d>='1' && d<='9')||(c=='1' && d>='0' &&d<='2'))
  cout<<"YYMM";
  else
  cout<<"NA";
  return 0;
}

Measured memory_bytes: 3580
N = int(input())
T,A = map(int,input().split())
lis = list(map(int,input().split()))
tmperature = [T-_*0.006 for _ in lis]
ans_lis = [abs(A-_) for _ in tmperature]

print(ans_lis.index(min(ans_lis)) + 1)


Measured memory_bytes: 3060
//Bokann ga bokka--nn!!
//JOI 2007 yo-6
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int d[105][105];
int n,k;
void wf()
{
	for(int k=1;k<=n;k++)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
}
void wf2(int a,int b)
{
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			d[i][j]=min(d[i][j],min(d[i][a]+d[a][b]+d[b][j],d[i][b]+d[b][a]+d[a][j]));
		}
	}
}
int main(){

	while(1)
	{
		cin>> n >> k;
		if(!n) return 0;
		for(int i=0;i<105;i++)
		{	for(int j=0;j<105;j++)
			{
				if(i==j) d[i][j]=0;
				else d[i][j]=1e8;
			}
		}
		wf();
		for(int i=0;i<k;i++)
		{
			int t; cin >> t;
			if(t==0)
			{
				int x,y; cin >> x >> y;
				
				cout << (d[x][y]==1e8?-1:d[x][y]) << endl;
			}
			else
			
			{
				int x,y,z;
				cin >> x >> y >> z;
				if(d[x][y]>z)
				{
					d[x][y]=z;
					wf2(x,y);
				}
				if(d[y][x]>z)
				{
					d[y][x]=z;
					wf2(y,x);
				}
			}
		}
	}
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
int main(){
  char x[60];
  int N, K;
  cin>>N>>K;
  for(int i = 0;i<N;i++){
    cin>>x[i];
    if(x[K-1] == 'A'){
      x[K-1] = 'a';
    }
     if(x[K-1] == 'B'){
      x[K-1] = 'b';
    }
     if(x[K-1] == 'C'){
      x[K-1] = 'c';
    }
  }
  for(int i = 0;i<N;i++){
  cout << x[i];
  }
}
  
  

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {
	ll N, lim[5];
	scanf("%lld", &N);
	for (int i = 0; i < 5; i++) {
		scanf("%lld", &lim[i]);
	}

	ll Min = 11111111111111111;
	for (int i = 0; i < 5; i++) {
		if (Min > lim[i]) {
			Min = lim[i];
		}

	}

	ll ans;
	if (N%Min == 0) {
		ans = N / Min + 4;
	}
	else {
		ans = N / Min + 1 +4;
	}
	
	printf("%lld", ans );




}






Measured memory_bytes: 128
#include<iostream>
#include<array>
#include<algorithm>
int main()
{
	std::array<int, 8>num_sorted;
	int n;
	std::cin >> n;
	for (int i = 0; i < n; i++)
	{
		int num;
		std::cin >> num;
		for (int j = 0; j < 8; j++)
		{
			num_sorted[j] = num % 10;
			num /= 10;
		}
		std::sort(num_sorted.begin(), num_sorted.end());
		std::cout <<
			num_sorted[7] * 9999999 +
			num_sorted[6] * 999990 +
			num_sorted[5] * 99900 +
			num_sorted[4] * 9000 -
			num_sorted[3] * 9000 -
			num_sorted[2] * 99900 -
			num_sorted[1] * 999990 -
			num_sorted[0] * 9999999
			<< std::endl;
	}
	return 0;
}


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

int main(){

  int door[257];
  string id[257];
  string name;
  int n, m;
  int flag = 1; // flag == 1 locked

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> id[i];
  }
  cin >> m;
  for(int i = 0; i < m; i++){
    cin >> name;
    for(int j = 0; j < n; j++){
      if(id[j] == name){
        if(flag == 1){
          flag = 0;
          cout << "Opened by " << name << endl;
          break;
        }else{
          flag = 1;
          cout << "Closed by " << name << endl;
          break;
        }
      }
      if(j == n-1) cout << "Unknown " << name << endl;
    }
  }
  return 0;
}


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

typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//



int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	string s;
	cin >> s;
	int len = s.size();
	if(len < 26){
		int vis[26] = {};
		for(int i = 0 ; i < len ; ++i)
			vis[s[i]-'a']++;
		for(int i = 0 ; i < 26 ; ++i)
			if(!vis[i])
				return cout << s << char(i+'a') << "\n" , 0;
	}
	else{
		string temp = "";
		for(int i = 25 ; i >= 0 ; --i)
			temp += char(i + 'a');
		if(s == temp)
			cout << "-1\n";
		else{
			set < char > st;
			for(int i = 25 ; i >= 0 ; --i){
				st.insert(s[i]);
				if(s[i-1] < s[i]){ // abc
					char add = *st.upper_bound(s[i-1]);
					cout << s.substr(0 , i-1) << add << "\n";
					break;
				}
			}
		}
	}
	
	
    return 0;
}




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

long long fac(int num) {
	long long ans = 1;
	for (long long i = 2; i <= num; i++) {
		ans = (ans * i) % 1000000007LL;
	}
	return ans;
}

int main() {
	int x, y;
	cin >> x >> y;
	if (abs(x - y) > 1) {
		cout << 0;
	} else {
		cout << (2 * fac(x) * fac(y) / (1 + abs(x - y)) % 1000000007LL);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;





int a[40001], b[40000];
signed main(){
  while(1){
    int n;
    scanf("%lld", &n);
    if(n == 0)break;
    rep(i,n)scanf("%lld", &a[i]);
    rep(i,n)scanf("%lld", &b[i]);
    sort(a, a+n, greater<int>());
    sort(b, b+n, greater<int>());
    int cnt = 0, lose = 0, ans = 0;
    rep(i,n-1){
      if(a[i] <= b[cnt]){lose++;cnt++;}
      if((i+1)-lose >= (i+1)/2+1){
        printf("%lld\n", i+1);ans = 1;
        break;
      }
    }
    if(!ans)printf("NA\n");
  }
	return 0;
}











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

using namespace std;

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

    sort(v, v+N);

    for(int i = 1; i < N; i++){
        v[i] = ((v[i-1]+v[i])/2);
    }

    printf("%.12lf\n", v[N-1]);


    return 0;
}

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

using namespace std;

using lint = long long;
using ldouble = long double;

string rec(int A, int L) {
    if (L <= 0) {
        assert(A == 0);
        return "";
    }

    int D;
    for (D = 0; D * (D + 1) / 2 < A; ++D) {}

    string ret;
    for (int i = 0; i < L - D; ++i) ret += "()";
    return ret + ')' + rec(A - D, D - 1) + '(';
}

int main() {
    int A;
    cin >> A;
    int D;
    for (D = 1; D * (D + 1) / 2 < A; ++D) {}
    cout << ')' + rec(A - D, D - 1) + '(' << endl;
    return 0;
}



Measured memory_bytes: 8868
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    switch(n%10){
        case 3:
            cout<<"bon"<<endl;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout<<"pon"<<endl;
            break;
        default:
            cout<<"hon"<<endl;
            break;
    }
}


Measured memory_bytes: 3680
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());

		long ans = IntStream.rangeClosed(1, N).filter(s -> String.valueOf(s).length() % 2 != 0).count();

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 31188
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
using namespace std;


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

  int h = s/3600;
  s %= 3600;
  int m = s/60;
  s %= 60;
  cout << h << ":" << m << ":" << s << endl;

  return 0;
}








// EOF

Measured memory_bytes: 3076
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

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

const int s = 8;

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

bool check(vi v) {
    vector<vector<bool>> filled(s, vector<bool>(s, false));
    REP(y, s) filled[y][v[y]] = true;
    REP(y, s) {
        REP(i, 4) {
            int ix = v[y]+dx[i], iy = y+dy[i];
            while (INRANGE(ix, 0, s-1) and INRANGE(iy, 0, s-1)) {
                if (filled[iy][ix]) return false;
                ix += +dx[i]; iy += dy[i];
            }
        }
    }

    return true;
 }

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

    int n;
    cin >> n;

    vi v(8, 0);
    vi input;
    REP(_, n) {
        int x, y;
        cin >> y >> x;
        v[y] = x;
        input.emplace_back(y);
    }

    vi idx(8);
    iota(ALL(idx), 0);
    do {
        bool ng = false;
        for (int i : input) if (idx[i] != v[i]) ng = true;
        if (ng) continue;

        if (check(idx)) {
            REP(i, s) {
                string ans = "........";
                ans[idx[i]] = 'Q';
                cout << ans << endl;
            }

            // for (int i : input) {
            //     cout << i << "::  "; 
            //     cout << "idx[i]: " << idx[i] << " v[i]: " << v[i] << endl;
            // }

            break;
        }
    } while (next_permutation(ALL(idx)));

    return 0;
}



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

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, LN = 17, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int N, K;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    cin >> N >> K;
    int ret = K;
    for (int i = 1; i < N; i++) ret *= (K - 1);
    cout << ret << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;


int main(void)
{
    int n,k,r,s,p; 
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    
    int cnt = 0;
    for ( int i=0; i < (int)t.length(); ++i)
    {
        if ( t[i] == 'r' )
        {
            if ( i >= k && t[i-k] == 'r') t[i] = 'a';
            else cnt += p;
        }
        else if ( t[i] == 's' )
        {
            if ( i >= k && t[i-k] == 's') t[i] = 'a';
            else cnt += r;
        }
        else
        {
            if ( i >= k && t[i-k] == 'p') t[i] = 'a';
            else cnt += s;
        }
    }
    
    
    cout << cnt;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio> 
#include <string>
#include <cmath>
using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	a = a + b; c = c + d;
	if (a > c) cout << "Left\n";
	else if (a == c) cout << "Balanced\n";
	else cout << "Right\n";
	
	return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b = LI()
    if (a-b)%2 == 0:
        print((a+b)//2)
    else:
        print("IMPOSSIBLE")
    return

#B
def B():
    n = I()

    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 39408
A = int(input())
B = int(input())
ans = 0
if A == 1:
    if B == 2:
        ans = 3
    elif B == 3:
        ans = 2

elif A == 2:
    if B == 1:
        ans = 3
    elif B == 3:
        ans = 1

elif A == 3:
    if B == 1:
        ans = 2
    elif B == 2:
        ans = 1

print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main () {
	int n,k,ans=1;
	scanf ("%d%d",&n,&k);
	while (n--) ans+=min(ans,k);
	printf ("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
#define MOD 998244353 //1000000007

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

    // solution comes here
    ll N, x;
    cin >> N >> x;
    vl a(N);
    rep(i, N) cin >> a[i];

    ll ans=0;
    if(a[0]>x) {
        ans += a[0] - x;
        a[0] = x;
    }
    rep(i, N-1) {
        if(a[i] + a[i+1] > x){
            ans += a[i] + a[i+1] - x;
            a[i+1] -= a[i] + a[i+1] - x;
        } 
    }
    cout << ans << nl;
}

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

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;



int main()
{
    int n;
    cin >> n;
    int a[n];
    ll cnt[n];
    for(int i = 0; i < n; i++){
         cin >> a[i];
         cnt[i] = 0;
    }
    ll x[n];
    ll y[n];
    for(int i = 0; i < n; i++){
        cnt[a[i]-1]++;
        x[i] = 0; y[i] = 0;
    }
    ll sum = 0;
    for(int i = 0; i < n; i++){
        if(cnt[i] > 0) x[i] = (cnt[i] * (cnt[i]-1))/2;
        sum += x[i];
    }
    for(int i = 0; i < n; i++){
        if(cnt[i] > 1) y[i] = ((cnt[i]-1) * (cnt[i]-2))/2;
    }
    for(int i = 0; i < n; i++){
      cout << sum - x[a[i]-1] + y[a[i]-1] << endl;
    }

} 

Measured memory_bytes: 8064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define pai 3.141592653589793238462643383279

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

ll f(ll N){
    ll ng = 1e9, ok = 0;
    while(abs(ok-ng)>1){
        ll mid = (ng+ok)/2;
        if(mid*(mid+1)/2>N){
            ng = mid;
        }
        else ok = mid;
    }
    return ok;
}

int main(){
    ll N; cin >> N;
    auto p = prime_factorize(N); ll ans=0;
    for(auto k: p){
        int s = k.second;
        ans+=f(s);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
import sys

mod = 10 ** 9 + 7

def get_nums(n):
    res = [0 for _ in range(n)]
    for i in range(n):
        res[i] = int(input())
    return res


def get_numbers():
    return map(int, input().split())


n, m = get_numbers()
a = set(get_nums(m))

dp = [0 for _ in range(n + 1)]
dp[0] = 1
if 1 not in a:
    dp[1] = 1

for i in range(2, n + 1):
    if i not in a:
        dp[i] = dp[i - 1] + dp[i - 2]
        dp[i] %= mod

print(dp[-1])


Measured memory_bytes: 54940
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<time.h>
#include<cstdlib>
typedef long long ll;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mm(a) memset(a,0,sizeof(a))
#define lr rt<<1
#define rr rt<<1|1
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0);
#define inf 0x3f3f3f3f
#define eqs 1e-8
#define lb(x) (x&(-x))
#define ch(a) (int(a-'0'))
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef pair<int,int> pii;
const double pi=acos(-1);
const int maxn=1010;
//const ll Mod=1000000007;
const ll Mod=998244353;
using namespace std;


ll p[maxn],inv[maxn];
//inv[0]=inv[1]=1;
//inv[i]=1LL*(Mod-Mod/i)*inv[Mod%i]%Mod;          //这个是单个数的逆元 不是阶乘的逆元！！
//S(n,m)=S(n,m−1)+C(​​n m​​),S(n,m)=2S(n−1,m)−C(​​n−1 m​​)
ll ksm(ll x,ll y)
{
    ll res=1;
    while(y)
    {
        if(y&1)
        {
            res=res*x%Mod;
        }
        x=x*x%Mod;
        y/=2;
    }
    return res%Mod;
}
 
ll C(int n,int m)
{
    return p[n]*inv[m]%Mod*inv[n-m]%Mod;
}
int main()
{
    sync;
    p[0]=inv[0]=1;
    for(int i=1;i<=maxn-2;i++)
    {
        p[i]=p[i-1]*i%Mod;
//        inv[i]=ksm(p[i],Mod-2);
    }
    inv[maxn-2]=ksm(p[maxn-2],Mod-2);     //阶乘的逆元
    for(int i=maxn-3;i>=0;i--)
        inv[i]=inv[i+1]*(i+1)%Mod;
    
    ll s=0;
    ll n,m;
    cin>>n>>m;
    if(n>=2)
    {
        s+=1ll*C(n,2);
    }
    
    if(m>=2)
    {
        s+=1ll*C(m,2);
    }
    
    cout<<s<<endl;
    return 0;
}


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

using namespace std;
int main(int argc, const char * argv[]) {
    
    int H, W;
    cin >> H >> W ;
    int h, w;
    cin >> h >> w;

    cout << (H-h)*(W-w) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int64_t dp[10000010];

int main() {
	int n; cin >> n;
	for(int i = 1; i <= n; ++i) {
		for(int j = i; j <= n; j += i) {
			dp[j]++;
		}
	}
	int64_t ans = 0;
	for(int64_t i = 1; i <= n; ++i) {
		ans += i * dp[i];
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 81744
from collections import deque

S = deque(list(input()))
Q = int(input())
rvs = False

for q in range(Q):
    query = list(input().split())
    if len(query) > 1:
        if query[1] == "1":
            if rvs:
                S.append(query[2])
            else:
                S.appendleft(query[2])
        elif query[1] == "2":
            if rvs:
                S.appendleft(query[2])
            else:
                S.append(query[2])
    else:
        rvs = not (rvs)

if rvs:
    S.reverse()

print("".join(S))


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n; cin >> n;
    map<ll,ll> mp;
    rep(i,n){
        int a;cin>>a;
        mp[a]++;
    }
    if((n & 1) && mp[0] != 1){
        out(0);
        return 0;
    }
    for(auto m:mp){
        if(m.second != 2 && m.first != 0){
            out(0);
            return 0;
        }
    }
    ll m = mp.size();
    if(n & 1)m--;
    ll res = 1;
    rep(i,m){
        res *= 2;
        res %= MOD;
    }
    out(res);
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

const int MOD = 1000000007;

long long mod_inv(long long a, long long m) {
    long long b = m, x = 1, y = 0, t;
    while (b > 0) {
        t = a / b;
        swap(a -= t * b, b);
        swap(x -= t * y, y);
    }
    x %= m;
    if (x < 0) x += m;
    return x;
}

long long nCk_naive(int n, int k) {
    long long res = 1;
    while (k) {
        int N = n % MOD;
        int K = k % MOD;
        if (N < K) return 0;
        for (int i = 0; i < K; ++i) {
            res = res * (N - i) % MOD;
        }
        long long imul = 1;
        for (int i = 0; i < K; ++i) {
            imul = imul * (i + 1) % MOD;
        }
        res = res * mod_inv(imul, MOD) % MOD;
        n /= MOD;
        k /= MOD;
    }
    return res;
}

long long mod_pow(long long a, long long n, long long m) {
    a = (a % m + m) % m;
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
}

void _main() {
    int n, a, b;
    cin >> n >> a >> b;
    int ans = (mod_pow(2, n, MOD) + MOD - 1) % MOD;
    (ans += MOD - nCk_naive(n, a)) %= MOD;
    (ans += MOD - nCk_naive(n, b)) %= MOD;
    cout << ans << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("in.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("out.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ls = make_divisors(N)
rst = 0
for i in range(len(ls)) : 
    k = ls[i]
    m = (N / ls[i] - 1) 
    if k < m : rst += m
print(int(rst))

Measured memory_bytes: 3272
from math import sqrt

N = int(input())

n = int(sqrt(N)) + 10
def f(A, B):
    a = len(str(A))
    b = len(str(B))
    return max(a, b)


ans = 10 ** 10
for i in range(1, n):
    if (N//i) * i == N:
        ans = min(ans, f(i, N//i))

print (ans)

Measured memory_bytes: 3188
#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!{
        N: usize,
        T: usize,
        cts:[(usize,usize); N],
    }
    let mut ans = std::usize::MAX;
    let mut flag = false;
    for (c, t) in cts {
        if t <= T {
            ans = std::cmp::min(ans, c);
            flag = true;
        }
    }

    println!(
        "{}",
        if flag {
            ans.to_string()
        } else {
            "TLE".to_owned()
        }
    );
}

Measured memory_bytes: 4352
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	for(int i=1;i<=9;i++)for(int j=1;j<=9;j++){
		if(i*j==a){
			printf("Yes\n");return 0;
		}
	}
	printf("No\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a(0), b(0);
  
  cin >> a;
  
  b += a % 10;
  a /= 10;
  b += a % 10;
  a /= 10;
  b += a % 10;
  
  cout << b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  long long x;
  cin >> N >> x;
  vector<long long>A(N);
  for (int i = 0; i < N; i ++) cin >> A[i];
  long long ans = 0;
  for (int i = 1; i < N; i ++) {
    long long kj = A[i - 1] + A[i] - x;
    if (kj <= 0) continue;
    ans += kj;
    A[i] = max(0ll, A[i] - kj);
    //cout << ans << endl;
  }
  cout << ans << endl;
}



Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int INF = (int)10e9;
int dp[3][100005];

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

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

    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for(int i = 1; i < N; i++) {
        dp[0][i] = a[i] + max(dp[1][i-1], dp[2][i-1]);
        dp[1][i] = b[i] + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = c[i] + max(dp[0][i-1], dp[1][i-1]);
    }
    cout << max({dp[0][N-1], dp[1][N-1], dp[2][N-1]}) <<endl;

    return 0;
}

Measured memory_bytes: 2560
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <numeric>
#include <queue>
#include <vector>

using namespace std;

bool compare_F(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) {
    return a.first < b.first;
  } else {
    return a.second > b.second;
  }
}

bool compare_S(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second > b.second;
  } else {
    return a.first > b.first;
  }
}

template <typename T>
void ArrayInput(vector<T> &A) {
  for (auto itr = A.begin(); itr != A.end(); ++itr) {
    cin >> *itr;
  }
}
template <typename T>
void ArrayPut(vector<T> &A) {
  for (auto itr = A.begin(); itr != A.end(); ++itr) {
    cout << *itr << " ";
  }
  cout << endl;
}

using Graph = vector<vector<uint32_t>>;
vector<bool> seen;
vector<uint32_t> dis, A_dis, T_dis;

void dfs(Graph &G, uint32_t v) {
  seen[v] = true;

  for (auto itr = G[v].begin(); itr != G[v].end(); ++itr) {
    if (seen[*itr]) continue;
    dis[*itr] = dis[v] + 1;
    dfs(G, *itr);
  }
}

int main() {
  uint32_t N, u, v;
  cin >> N >> u >> v;
  Graph G(N);
  for (uint32_t i = 0; i < (N - 1); ++i) {
    uint32_t a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }

  seen.assign(N, false);
  dis.assign(N, 0);
  dfs(G, u - 1);
  T_dis = dis;
  dis.assign(N, 0);
  seen.assign(N, false);
  A_dis.assign(N, 0);
  dfs(G, v - 1);
  A_dis = dis;

  priority_queue<uint32_t> Que;
  vector<uint32_t> Cand;

  for (uint32_t i = 0; i < N; ++i) {
    if (A_dis[i] > T_dis[i]) Que.push(A_dis[i] - 1);
  }
  cout << Que.top();
  return 0;
}


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

int main(){
  int k; cin >> k;
  if(k%2==0) cout << (k/2)*(k/2);
  else cout << (k+1)/2*(k-1)/2;
}


Measured memory_bytes: 256
i = gets.to_i
h = gets.split.map(&:to_i)

list =[]

h.each do |t|
	list << t
end


count = 0
huf = []
for x in 0..(i - 3) do 
	
	huf << list[x]
	huf << list[x + 1]
	huf << list[x + 2]
	huf = huf.sort
	if list[x + 1] == huf[1]
		count += 1
	end
	huf.clear
end

puts count





Measured memory_bytes: 1788
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <complex>
#include <cmath>
using namespace std;

int h,w;
vector<string> s;
vector<vector<int>> b;

bool dfs(int x, int y){
    int xx = x-1,yy=y;
    if(xx>=0&&xx<h&&yy>=0&&yy<w){
        if(s[x][y]!=s[xx][yy]){
            if(b[xx][yy]==-1){
                b[xx][yy] = b[x][y];
                dfs(xx,yy);
            }
        }
    }
    xx = x+1;
    yy = y;
    if(xx>=0&&xx<h&&yy>=0&&yy<w){
        if(s[x][y]!=s[xx][yy]){
            if(b[xx][yy]==-1){
                b[xx][yy] = b[x][y];
                dfs(xx,yy);
            }
        }
    }
    xx = x;
    yy = y+1;
    if(xx>=0&&xx<h&&yy>=0&&yy<w){
        if(s[x][y]!=s[xx][yy]){
            if(b[xx][yy]==-1){
                b[xx][yy] = b[x][y];
                dfs(xx,yy);
            }
        }
    }
    xx = x;
    yy = y-1;
    if(xx>=0&&xx<h&&yy>=0&&yy<w){
        if(s[x][y]!=s[xx][yy]){
            if(b[xx][yy]==-1){
                b[xx][yy] = b[x][y];
                dfs(xx,yy);
            }
        }
    }
    return true;
}

int main(int argc, char const *argv[]) {
    cin>>h>>w;
    s = vector<string>(h);
    for(int i=0;i<h;++i)cin>>s[i];
    b = vector<vector<int>>(h,vector<int>(w,-1));
    int k=0;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            if(b[i][j]==-1){
                b[i][j]=k;
                dfs(i,j);
                k++;
            }
        }
    }
    map<long long,long long> bs,ws;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            if(s[i][j]=='.'){
                bs[b[i][j]]++;
            }
            else{
                ws[b[i][j]]++;
            }
        }
    }
    long long res = 0;
    for(int i=0;i<=k;++i){
        res += bs[i]*ws[i];
    }
    cout<<res<<endl;
    return 0;
}

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

int main()
{

	int n;
	cin >> n;
	vector<vector<int>> g(n+1);

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

	vector<int> dist(n+1);
	for (int i=1;i<=n;++i)
	{
		dist[i]=-1;
	}
	queue<int> q;

	q.push(1);
	dist[1]=0;
	while (q.empty()==false)
	{
		int node=q.front();
		q.pop();

		for (int i=0;i<g[node].size();++i)
		{
			int nn=g[node][i];
			if (dist[nn]<0)
			{
				dist[nn]=dist[node]+1;
				q.push(nn);
			}
		}
	}

	for (int i=1;i<=n;++i)
	{
		cout << i << " " << dist[i] << endl;
	}
}






Measured memory_bytes: 3168