akhauriyash/Code-Regression huggingface dataset:
//20/01/2020
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b push_back
#define m_p make_pair

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};
vector<ll>v;
ll ans=0;
map<ll,ll>mp;

ll f(ll x){
    if(mp[x]>=1) return mp[x];
    if(x==1){
        return mp[x]=1;;
    }
    if(x>1){
        ll p=f(x/2);
        ll q=f(x/2);
        return mp[x]=(p+q+1);
    }

}

int main(){
    _fastio
    ll H;
    cin>>H;
    ll p=f(H);
    cout<<mp[H]<<endl;

    return 0;
}


Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS

main = do
  [a,b] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ maximum [a+b,a-b,a*b]


Measured memory_bytes: 380
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<long double, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << #i <<" "<<i<< std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;


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

  ll n,m;
  std::cin>>n>>m;

  std::vector<ll> s(n),t(m);
  rep(i,0,n)std::cin>>s[i];
  rep(i,0,m)std::cin>>t[i];

  std::vector<std::vector<ll>> sum(n+1,std::vector<ll>(m+1,0));

  rep(i,0,m+1)sum[0][i]=1;
  rep(i,0,n+1)sum[i][0]=1;

  rep(i,1,n+1){
    ll temp=0;
    rep(j,1,m+1){
      if(s[i-1]==t[j-1])temp=(temp+sum[i-1][j-1])%MOD;
      sum[i][j]=(sum[i-1][j]+temp)%MOD;
    }
  }

  std::cout<<sum[n][m];

  return 0;
}





Measured memory_bytes: 31616
#include<iostream>
using namespace std;
int main()
{
    long N,sum=0;
    cin >> N;
    long A[N+1],B[N];
	for (int i = 0; i < N+1; i++)
	{
        cin >> A[i]; 
	}
	for (int i = 0; i < N; i++)
	{
        cin >> B[i];
	}
	for (int i = 0; i < N; i++)
	{
        long mons_sum = A[i] + A[i+1];
		long min_val = min(mons_sum, B[i]);
        sum += min_val;
        if ((A[i]<B[i])){
          A[i+1] = mons_sum - B[i];
          if(A[i+1]<0){
            A[i+1] = 0;
          }
        }
	}
    cout << sum;
  return 0;
}

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

#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v) for_each((v).begin(), (v).end(), [](int& a) { cout << a << " "; }); cout << endl;

const int INF = INT_MAX;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

using PII = pair<int, int>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

LL N;
V<LL> v;


int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cin >> N;
    LL x;
    REP(i, 5) {
        cin >> x;
        v.push_back(x);
    }

    LL m = *std::min_element(ALL(v));

    cout << ((N + m - 1)/ m) + 4 << "\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<vector<int>> v;

    REP(i,n) {
        vector<int> v2(n-1);
        REP(j,n-1) {
            cin >> v2[j];
            v2[j]--;
        }
        v.emplace_back(v2);
    }

    int ans = 0;
    vector<int> cnt(n,0);
    set<pair<int,int>> q;
    
    auto next = [&](int i) {
        if (cnt[i] == n-1) return;
        int j = v[i][cnt[i]];
        //cerr << i << " " << j << endl;
        if (cnt[j] == n-1) return;
        if (v[j][cnt[j]] == i) {
            if (i > j) swap(i,j);
            q.emplace(make_pair(i,j));
        }
    };

    REP(i,n) {
        next(i);
    }

    while (!q.empty())
    {
        ans++;
        set<pair<int,int>> q2;
        swap(q,q2);
        for(auto x : q2) {
            cnt[x.first]++;
            cnt[x.second]++;
        }
        for(auto x : q2) {
            next(x.first);
            next(x.second);
        }

    }
    
    REP(i,n) if (cnt[i] != n-1) ans = -1;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4352
def getIntList(inp):
	return [int(_) for _ in inp]


from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs

def main(inputs):
	x=int(inputs[0][0])
	n=x//500
	x-=n*500
	n1=x//5
	print(n*1000+n1*5)


if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int p;
  int n;
  int count;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> p;
    if(p!=i+1){
      count += 1;
    }
  }
  if (count <= 2){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b;
  int ans;
  scanf("%d %d", &a,&b);
  ans=a+b;
  if(a-b>=ans){
    ans=a-b;
  }
  else{}
  if(a*b>=ans){
    ans=a*b;
  }
  else{}
  printf("%d",ans);
  return 0;
}

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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

ll  f[3005][3005];

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

    string s;   cin >> s;   s = "#" + s;
    string t;   cin >> t;   t = "#" + t;

    for(int i = 1 ; i < sz(s) ; ++i)
    for(int j = 1 ; j < sz(t) ; ++j)    {
        if (s[i] != t[j])   f[i][j] = max(f[i][j - 1],f[i - 1][j]);
        if (s[i] == t[j])   f[i][j] = f[i - 1][j - 1] + 1;
    }

    int x = sz(s) - 1;
    int y = sz(t) - 1;

    string ans = "";

    while (x && y)  {
        if (s[x] != t[y])   {
            if (f[x][y] == f[x - 1][y])
                --x;
            else
                --y;
        }
        else    {
            ans += s[x];
            --x;
            --y;
        }
    }
    reverse(all(ans));

    cout << ans << endl;
}

Measured memory_bytes: 70656
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

def lcm(a,b):
    return (a*b)//gcd(a,b)
n=int(input())
t=[]
for i in range(n):
    tmp=int(input())
    if tmp in t:
        continue
    t.append(tmp)

ans=1
for i in t:
    ans=lcm(ans,i)
print(ans)

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

int a, b, c;
int main() {
    
    cin >> a >> b >> c;
    int sum = a + b + c;
    if (sum == 17) {
        if (a == 5 || a == 7) {
            if (b == 5 || b==7) { 
                if (c == 5 || c == 7) {
                    cout << "YES" << endl;
                }
                else
                    cout << "NO" << endl;
            }
            else
                cout << "NO" << endl;
        }
        else
            cout << "NO" << endl;
    }
    else
        cout << "NO" << endl;

}

Measured memory_bytes: 256
use std::io::Read;
use std::io::Write;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let k: usize = it.next().unwrap().parse().unwrap();
    let c: usize = it.next().unwrap().parse().unwrap();
    let s: Vec<char> = it.next().unwrap().chars().collect();
    let mut dp = vec![0; n + c + 1];
    for (i, x) in s.iter().enumerate().rev() {
        dp[i] = dp[i + 1];
        if *x == 'o' {
            dp[i] = std::cmp::max(dp[i], dp[i + 1 + c] + 1);
        }
    }
    if dp[0] > k {
        return;
    }
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut i = 0;
    while i < n {
        while i < n && s[i] == 'x' {
            i += 1;
        }
        if dp[i] > dp[i + 1] {
            writeln!(out, "{}", i + 1).ok();
        }
        i += c + 1;
    }
}

fn main() {
    run();
}


Measured memory_bytes: 7548
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int dp[n+1];dp[0]=0;
    int tmp,p6,p9,ans;
    for(int i=1;i<=n;i++)
    {
        ans=dp[i-1]+1;
        p6=1;p9=1;
        while((int(pow(6.0,double(p6))))<=i)
        {
            tmp=pow(6,p6);
            ans=min(dp[i-tmp]+1,ans);
            p6++;
        }
        while((int(pow(9.0,double(p9))))<=i)
        {
            
            tmp=pow(9,p9);
            ans=min(dp[i-tmp]+1,ans);
            p9++;
        }
        dp[i]=ans;
    }
    cout<<dp[n]<<endl;
    return 0;
}

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

int main(){
    string str,order,p;
    cin >> str;
    int q,a,b;
    cin >> q;
    for(int i=0;i<q;++i){
        cin >> order >> a >> b;
        if(order == "print") {
            cout << str.substr(a,b-a+1) << endl;
        }
        if(order == "reverse") {
            string rev = str.substr(a,b-a+1);
            reverse(rev.begin(), rev.end());
            str = str.substr(0,a) + rev + str.substr(b+1);
        }
        if(order == "replace"){
            cin >> p;
            str.replace(a,b-a+1,p);
        }
    }
    return 0;
}



Measured memory_bytes: 3176
mod=10**9+7
n=input()
d=int(input())
l=len(n)
dp=[[[0]*d for _ in range(2)] for _ in range(l+1)]
dp[0][0][0]=1
for i in range(l):
  for j in range(10):
    for k in range(d):
      if j==int(n[i]):
        dp[i+1][0][(k+j)%d]+=dp[i][0][k]
        dp[i+1][1][(k+j)%d]+=dp[i][1][k]
      elif j<int(n[i]):
        dp[i+1][1][(k+j)%d]+=dp[i][0][k]+dp[i][1][k]
      elif j>int(n[i]):
        dp[i+1][1][(k+j)%d]+=dp[i][1][k]
      dp[i+1][0][k]%=mod
      dp[i+1][1][k]%=mod
print((dp[-1][0][0]+dp[-1][1][0]-1)%mod)

Measured memory_bytes: 92540
from collections import deque
N, M = map(int, input().split())
ls = [[] for _ in range(N)]
for _ in range(M):
  A, B = map(int, input().split())
  ls[A-1].append(B-1)
  ls[B-1].append(A-1)
visited = [False]*N
tmp = 0
counter = 0
isl = 0
while True:
  isl += 1
  found = deque()
  for city in ls[tmp]:
    found.append(city)
  visited[tmp] = True
  while len(found) != 0:
    tmp = found.pop()
    if not visited[tmp]:
      for city_ in ls[tmp]:
        found.append(city_)
      visited[tmp] = True
  while visited[counter]:
    counter += 1
    if counter > N-1:
      break
  tmp = counter
  if tmp > N-1:
    break
print(isl-1)
  

Measured memory_bytes: 82092
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
  
using namespace std;

#define pi 3.141592653589793

int result[20001][256];

int main()
{
	int n, m;
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		for(int i = 0; i < n + 1; i++){
			for(int j = 0; j < 256; j++){
				result[i][j] = 1000000000;
			}
		}
		result[0][128] = 0;
		int c[17], x[20001];
		for(int i = 1; i < m + 1; i++){
			cin >> c[i];
		}
		for(int i = 1; i < n + 1; i++){
			cin >> x[i];
		}
		for(int i = 1; i < n + 1; i++){
			for(int j = 0; j < 256; j++){
				for(int k = 1; k < m + 1; k++){
					int nexty = j + c[k];
					if(nexty < 0) nexty = 0;
					else if(nexty > 255) nexty = 255;
					result[i][nexty] = min(result[i][nexty], result[i - 1][j] + ((x[i] - nexty) * (x[i] - nexty)));
				}
			}
		}
		int ans = 1000000000;
		for(int i = 0; i < 256; i++) ans = min(ans, result[n][i]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 21236
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  for (int i = 0; i < M; i++){
    cin >> L.at(i) >> R.at(i);
  }
  int maxL = 1;
  int minR = N;
  for (int i = 0; i < M; i++){
    maxL = max(maxL, L.at(i));
    minR = min(minR, R.at(i));
  }
  int ans = 0;
  for (int i = 1; i <= N; i++){
    if (maxL <= i && i <= minR){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
"use strict";
    
const main = arg => {
    const S  = arg.split("\n")[0].split("");
    const alphabets = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "u", "v", "w", "x", "y", "z"];
    
    for(let i in alphabets) {
        if(S.indexOf(alphabets[i]) == -1) {
            console.log(alphabets[i]);
            return;
        }
    }
    
    console.log("None");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 8268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t

int main(){
    ll n;
    cin>>n;
    bool aman=false;
    while(n>0){
       if(n%10==7){
           aman=true;
       }
       n=n/10;
    }
    if(aman){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
     
#define int long long
#define hell 998244353  
#define endl "\n"
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX_SIZE 1000000000000000


int32_t main()
{   
    io

    int n;
    cin>>n;

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

    int dp[n];
    dp[0]=1;
    int max_possible=1;

    for(int i=1;i<n;i++)
    {
        if(a[i]<=a[i-1]){
            dp[i]=dp[i-1]+1;
            max_possible = max(max_possible, dp[i]);
        }
        else{
            dp[i]=1;
            max_possible = max(max_possible, dp[i]);
        }
    }

    cout<<max_possible-1;

    
return 0;
}   

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
using namespace std;

const int N = 305, mod = 1e9 + 7;
const int inf = 1e9;

void solve(int p){
    char a;
    cin >> a;
    if(a > 'Z'){
        cout << 'a' << endl;
    }
    else{
        cout << 'A' << endl;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);//cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t,p;
    t=1;
    //cin>>t;
    for(p=1;p<=t;p++){
        solve(p);
    }
    return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;

int main()
{
    int h, w;
    cin >> h >> w;
    ll p[100002], q[100002];
    P r[200002];
    for(int i = 0; i < h; i++){
        cin >> p[i];
        r[i] = P(p[i], 0);
    }
    for(int i = 0; i < w; i++){
        cin >> q[i];
        r[i + h] = P(q[i], 1);
    }
    sort(r, r + h + w);
    int x = 0, y = 0;
    ll ans = 0;
    for(int i = 0; i < h + w; i++){
        if(r[i].second == 0){
            ans += r[i].first * (w - y + 1);
            x++;
        }
        else{
            ans += r[i].first * (h - x + 1);
            y++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc[1000];
char ca,cb,cc,cd[1000][1000];
vector<ll> va,vb,vc;

int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>sc[i];
    sort(sc,sc+n);
    for(int i=0;i<n;i++){
        C sc[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int INFTY = (1 << 21);

int main() {
    int n;
    cin >> n;
    int p[n + 1], m[n + 1][n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> p[i - 1] >> p[n];
        m[i][i] = 0;
    }

    for (int l = 2; l <= n; l++) {
        for (int i = 1; i <= n - l + 1; i++) {
            int j = i + l - 1;
            m[i][j] = INFTY;
            for (int k = i; k <= j - 1; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }

    cout << m[1][n] << endl;

    return 0;
}


Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        System.out.println( solve(S) );
    }

    private static String solve(String S) {
        String s = reverse(S);
        String t1 = reverse("dream");
        String t2 = reverse("dreamer");
        String t3 = reverse("erase");
        String t4 = reverse("eraser");
        int i = 0;

        while(true) {
            i = nextIndexOf(s, i, t1, t2, t3, t4);
            if( i == -1 ) return "NO";
            if( i == s.length() ) return "YES";
        }
    }

    private static String reverse(String s) {
        char[] rev = new char[s.length()];
        for (int i = 0, j = s.length() -1; i < s.length(); i++, j--) {
            rev[j] = s.charAt(i);
        }
        return new String(rev);
    }

    private static int nextIndexOf(String s, int i, String... ts) {
        for (String t : ts) {
            if( s.startsWith(t, i) ) {
                return i + t.length();
            }
        }
        return -1;
    }
}

Measured memory_bytes: 26540
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    string n;
    cin >> n;

    if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3])) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

	int N;
	cin >> N;
	int A[N][10];
	int P[N][11];
	rep(i,N){
		rep(j,10){
			cin >> A[i][j];
		}
	}
	rep(i,N){
		rep(j,11){
			cin >> P[i][j];
		}
	}
	int ans = -INF;
	for(int bit = 1;bit < (1<<10); ++bit){
		int sum = 0;
		rep(i,N){
			int count = 0;
			rep(j,10){
				if(bit & (A[i][j]<<j) ){
					count++;
				}
			}
			sum += P[i][count];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2151

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;

typedef pair<int, int> state; // 頂点、残金
typedef pair<state, int> pass; // 状態、悪党
typedef tuple<int, int, int> cand; // -1 * cost, point, money

vector<pass> V[110][110];

int main() {
  int N, M, L;
  while(cin >> N >> M >> L && N) {
    N--;
    // 初期化
    for (auto i=0; i<110; i++) {
      for (auto j=0; j<110; j++) {
	V[i][j].clear();
      }
    }
    // 入力受け取り
    int AA[10000], BB[10000], DD[10000], EE[10000];
    for (auto i=0; i<M; i++) {
      cin >> AA[i] >> BB[i] >> DD[i] >> EE[i];
      AA[i]--;
      BB[i]--;
    }
    // 隣接リスト作成
    for (auto i=0; i<M; i++) {
      for (auto j=0; j<=L; j++) {
	V[AA[i]][j].push_back(make_pair(make_pair(BB[i], j), EE[i]));
	V[BB[i]][j].push_back(make_pair(make_pair(AA[i], j), EE[i]));
	int t = j - DD[i];
	if (t >= 0) {
	  V[AA[i]][j].push_back(make_pair(make_pair(BB[i], t), 0));
	  V[BB[i]][j].push_back(make_pair(make_pair(AA[i], t), 0));
	}
      }
    }
    // Dijkstra法
    priority_queue<cand> Q;
    Q.push(make_tuple(0, 0, L));
    bool visited[110][110];
    fill(&visited[0][0], &visited[0][0]+110*110, false);
    int ans = 0;
    while (!Q.empty()) {
      int np = get<1>(Q.top());
      int nl = get<2>(Q.top());
      int nc = -1 * get<0>(Q.top());
      Q.pop();
      if (!visited[np][nl]) {
	visited[np][nl] = true;
	// cerr << "visiting " << np << " at " << nl << endl;
	if (np == N) {
	  ans = nc;
	  break;
	}
	for (auto i=0; i<V[np][nl].size(); i++) {
	  int dp = V[np][nl][i].first.first;
	  int dl = V[np][nl][i].first.second;
	  int dc = V[np][nl][i].second;
	  if (!visited[dp][dl]) {
	    Q.push(make_tuple(-1* (dc+nc), dp, dl));
	  }
	}
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 11020
N = int(input())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[1])
flag = 0
cur = 0
for i in range(N):
    a,b = A[i]
    cur += a
    if cur>b:
        flag = 1
        break
if flag==1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 89752
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main(){
		new AOJ0257().doIt();
	}
	
	class AOJ0257{
		void doIt(){
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("1 0 0", "Close");map.put("0 1 0", "Close");map.put("1 1 0", "Open");map.put("0 0 1", "Open");
			map.put("0 0 0", "Close");
			while(in.hasNext()){
				System.out.println(map.get(in.nextLine()));
			}
		}
	}
	
}

Measured memory_bytes: 17144
#include<stdio.h>

int main(){

  int mount[11];
  int i,j,k,key;
  for(i=1;i<=10;i++){
    scanf("%d",&mount[i]);
  }

 for(j=1;j<=10;j++){
    key=mount[j];
    i=j-1;
    while(i>0 && mount[i]<key){
      mount[i+1]=mount[i];
      i--;
    }
    mount[i+1]=key;

 }
 /*print*/
 for(k=1;k<=3;k++){
   printf("%d\n",mount[k]);
 }
 return 0;
}

Measured memory_bytes: 0
N, M = map(int, input().split())
if N == 1 or M == 1:
  if N == M: print(1); exit()
  elif N == 2 or M == 2: print(0); exit()
  else: print(max(N, M) - 2); exit()
elif N == 2 or M == 2: print(0); exit()
else: print((N-2)*(M-2))

Measured memory_bytes: 61940
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int X, Y;
	cin >> X >> Y;
	if(abs(X-Y) <= 1) cout << "Brown" << endl;
	else cout << "Alice" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
    cin >> n;
    int ans = 0;
    int mx = 0;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if (x >= mx)
        {
            ans++;
            mx = max(x, mx);
        }
    }
    cout << ans << endl;
}

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

int main(){
  char a[3];
  for(int i=0;i<3;i++){
    cin >>a[i];
    if(a[i] =='1'){
      a[i] = '9';
    }else{
      a[i] = '1';
    }
  }
  cout << a << endl;





}

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

typedef long long ll;
using namespace std;


int main(void) {
   ll N;
   cin>>N;
   ll A[N];
   rep(i,N) cin>>A[i];
   ll Ans[N];

   ll sum = 0;
   rep(i,N) {
      sum += (i%2)?(-A[i]):A[i];
   }
   Ans[0] = sum;
   for (int i = 1; i < N;i++) {
      Ans[i] = 2 * A[i-1] - Ans[i-1]; 
   }
   rep(i,N) cout<<Ans[i]<<" ";
   cout<<endl;




   return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include<string.h>
using namespace std;
string s;
int main(){
	cin>>s;
	for(int i=0;i<s.length()-1;i++){
		if(s[i]=='A'&&s[i+1]=='C'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,m,ans=0;
  cin >> n >> m;
  long long a[n+1]={};
  map<long long, int> mp;
  for(int i=1;i<=n;i++){
    cin >> a[i];
    a[i]+=a[i-1];
    a[i]%=m;
    mp[a[i]]++;
  }
  ans+=mp[0];
  for(int i=1;i<=n;i++){
    mp[a[i]]--;
    ans+=mp[a[i]];
  }
  cout << ans << endl;
  return 0;
}

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

const int MOD = 1000000007;

bool is_prime(lint n) {
    for (lint i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    lint A, B;
    cin >> A >> B;
    vector<lint> div;

    lint m = min(A, B);
    lint ma = max(A, B);
    for (lint i = 1; i * i <= m; i++) {
        lldiv_t mpi = lldiv(m, i);
        lldiv_t mapi = lldiv(ma, i);
        if (mpi.rem == 0) {
            if (mapi.rem == 0) {
                div.push_back(i);
            }
            lint q = m / i;
            if (i == q) continue;
            lldiv_t mapq = lldiv(ma, q);
            if (mapq.rem == 0) {
                div.push_back(q);
            }
        }
    }

    int res = 0;
    for (auto&& i : div) {
        if (is_prime(i)) ++res;
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
class M{
public:
  int x;
  int y;
  int h;
};
bool ch(M a,M b){
  return a.h>b.h;
}
int abs(int a){
  if(a<0)return -a;
  else return a;
}
int main(){
  int n;cin>>n;
  vector<M> m(n);
  int cx,cy,ans_h,h;
  rep(i,n){
    cin>>m[i].x>>m[i].y>>m[i].h;
  }
  sort(m.begin(),m.end(),ch);
  int tag;
  for(int x=0;x<=100;x++){
    for(int y=0;y<=100;y++){
      h=m[0].h+abs(x-m[0].x)+abs(y-m[0].y);
      tag=0;
      rep(i,n){
	int tmp_h=m[i].h+abs(x-m[i].x)+abs(y-m[i].y);
	if(tmp_h>h&&m[i].h!=0)break;
	if(tmp_h<h)break;
	tag++;
      }
      if(tag==n){
	cx=x;
	cy=y;
	ans_h=h;
      }
    }
  }
  cout<<cx<<" "<<cy<<" "<<ans_h<<endl;
  //  rep(i,n)cout<<m[i].h<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, w, b, a[MAXN], s[MAXN];
bool check(int mid) {
	int Min = 0;
	for (int i = 2; i <= n; i += 2)
		if (s[i - 1] - Min >= mid) chkmin(Min, s[i]);
	return s[n] - Min >= mid;
}
int main() {
	read(n);
	for (int i = 1; i <= n; i++) {
		read(a[i]);
		if (i & 1) b += a[i], s[i] = s[i - 1] + a[i];
		else w += a[i], s[i] = s[i - 1] - a[i];
	}
	if (n % 2 == 0) {
		printf("%d %d\n", max(w, b), min(w, b));
		return 0;
	}
	int l = -w - b, r = w + b;
	while (l < r) {
		int mid = (l + r + 2 * w + 2 * b + 1) / 2 - w - b;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	printf("%d %d\n", w + l, b - l);
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;

int main(){
	queue<int> leave;
	stack<int> waiting;
	int n;
	while(scanf("%d",&n)==1){
		if(n==0){
			leave.push(waiting.top());
			waiting.pop();
		}else{
			waiting.push(n);
		}
	}
	while(!leave.empty()){
		cout<<leave.front()<<endl;
		leave.pop();
	}
	return 0;
}

Measured memory_bytes: 1212
a,b,k=gets.split.map(&:to_i)

if (b-a)<k
    a.upto(b) do |i|
        puts i
    end
    return
end

a.upto(a+k-1) do |i|
    if 
    puts i
    end
end

if (a+k-1)<(b-k+1)
    (b-k+1).upto(b) do |i|
        puts i
    end
else
    (a+k).upto(b) do |i|
        puts i
    end
end


Measured memory_bytes: 14412
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		
		Set<String> s  = new HashSet<>();
		for(int i=0;i<N;i++) {
			s.add(sc.next());
		}
		
		sc.close();

		out.println(s.size());
	}

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

	@SuppressWarnings("unused")
	private String join(String delimiter, int[] a) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < a.length; i++) {
			sb.append(a[i]);
			sb.append(delimiter);
		}
		return sb.substring(0, Math.max(sb.length() - delimiter.length(), 0));
	}

	@SuppressWarnings("unused")
	private String join(String delimiter, long[] a) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < a.length; i++) {
			sb.append(a[i]);
			sb.append(delimiter);
		}
		return sb.substring(0, Math.max(sb.length() - delimiter.length(), 0));
	}

	@SuppressWarnings("unused")
	private int max(int[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		int candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate > arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private long max(long[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		long candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate > arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private int min(int[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		int candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate < arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private long min(long[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		long candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate < arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private long[] nextLongArray(Scanner sc, int n) {
		long[] result = new long[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextLong();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 67240
import sys
from collections import deque

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
a = LI()
a = sorted(a)

d = a

x = 0
y = 0
flag = 0
while len(d) != 0:
    if flag == 0:
        x += d.pop()
        flag = 1
    elif flag == 1:
        y += d.pop()
        flag = 0
print(x-y)

Measured memory_bytes: 38384
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };


signed main() {
	int n;
	vector<pair<string, pair<int,int>>>list;
	

	cin >> n;

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		int num;
		cin >> num;

		list.push_back(make_pair(s, make_pair(-num, i + 1)));
	}

	sort(list.begin(), list.end());

	for (int i = 0; i < n; i++) {
		cout << list[i].second.second << endl;
	}





	getchar();
	getchar();
	return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int h,w; cin >> h >> w;
    vec<vll> minimum_magic(10, vll(10));
    rep(i,10) rep(j,10) cin >> minimum_magic[i][j];

    rep(k,10)rep(i,10)rep(j,10) {
        if(minimum_magic[i][k] == infll || minimum_magic[k][j] == infll) continue;
        chmin(minimum_magic[i][j], minimum_magic[i][k] + minimum_magic[k][j]);
    }

    ll ans = 0;
    rep(i,h) rep(j,w) {
        int p; cin >> p;
        if(!~p) continue;
        ans += minimum_magic[p][1];
    }

    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
import itertools, collections
N = int(input())
ans = collections.defaultdict(int)
for x, y, z in itertools.product(range(1, 101), repeat=3):
    n = x**2 + y**2 + z**2 + x * y + y * z + z * x
    ans[n] += 1
print('\n'.join(str(ans[i]) for i in range(1, N + 1)))


Measured memory_bytes: 12356
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n;
    cin>>n;
    vii x(n);
    for (int i = 0; i < n; ++i) {
        cin>>x[i].first>>x[i].second;
    }
    for(int i = 1 ; i < n; i++){
        int r = 1;
        if(x[i].first < x[i-1].first){
            r = max(r , x[i-1].first / x[i].first + (x[i-1].first % x[i].first == 0 ? 0 : 1));
        }
        if(x[i].second < x[i-1].second){
            r = max(r , x[i-1].second / x[i].second + (x[i-1].second % x[i].second == 0 ? 0 : 1));
        }
        x[i].first *= r ;
        x[i].second *= r;
    }
    cout<<x[n-1].first + x[n-1].second<<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++) cin >> d[i];

    int sum = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (i == j) continue;
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}


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

int main(){

  int N, ans=0;
  int j=1;
  long A[100001];
  long B[100001];
  long C[100001];

  cin >> N;
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  for(int i=0; i<N; i++){
    cin >> B[i];
    C[i] = A[i] - B[i];
  }
  sort(C, C+N);

  for(int i=0; i<N; i++){
    if(C[i]>=0) break;
    if(C[N-j]<0){
      cout << "-1" << endl;
      return 0;
    }
    if(abs(C[N-j]) > abs(C[i])){
      C[N-j]+=C[i];
      ans++;
    }else{
      C[i]+=C[N-j];
      C[N-j]=0;
      j++;
      i--;
      ans++;
    }
  }
  if(ans) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
import java.io.*;
import java.util.*;
import static java.lang.System.*;

public class Main {
	static FastScanner sc = new FastScanner(System.in);
	public static void main(String[] args) {
		int rectangle = 0;
		int diamond = 0;
		int a,b,c;
		String[] s = new String[3];
		while (sc.hasNext()) {
			s = sc.next().split(",");
			a = Integer.parseInt(s[0]);
			b = Integer.parseInt(s[1]);
			c = Integer.parseInt(s[2]);
			if (c*c == (a*a)+(b*b)) {rectangle++;}
			else if (a==b) {diamond++;}
		}
		out.println(rectangle+"\n"+diamond);
	}
}



class FastScanner implements Closeable {
	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	public FastScanner(InputStream in) {this.in = in;}
	private boolean hasNextByte() {
		if (ptr < buflen) {return true;}
		else{
			ptr = 0;
			try {buflen = in.read(buffer);}
			catch (IOException e) {e.printStackTrace();}
			if (buflen <= 0) {return false;}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {throw new NumberFormatException();}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){return minus ? -n : n;}
			else{throw new NumberFormatException();}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
	public void close() {
		try {in.close();}
		catch (IOException e) {}
	}
}


Measured memory_bytes: 24136
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main()
{
    vector<vector<string> > s(2, vector<string>(8, string(8, '.')));
    rep(i, 8) cin >> s[0][i];
    rep(k, 3) {
        cout << 90 * (k + 1) << endl;
        rep(i, 8) rep(j, 8) s[(k+1)%2][i][j] = s[k%2][7-j][i];
        rep(i, 8) cout << s[(k+1)%2][i] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import collections
n = int(input())
a = list(map(int, input().split()))
q = int(input())
dic = collections.Counter(a)
sum_list = [x * y for (x, y) in dic.items()]
sum = sum(sum_list)
for i in range(q):
    b, c = map(int, input().split())
    if b in dic and c not in dic:
        sum -= (b - c) * dic[b]
        print(sum)
        dic[c] = dic[b]
        del dic[b]
    elif b in dic and c in dic:
        sum -= (b - c) * dic[b]
        print(sum)
        dic[c] += dic[b]
        del dic[b]
    else:
        print(sum)


Measured memory_bytes: 21796
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int n,m,q;
int a[51][4];
int ans = 0;

void rec(int selectindex, vector<int> A) {
    int asize = A.size();
    if(asize==n) {
        int anstemp = 0;
        rep(i, q) {
            int t = A[a[i][1]-1] - A[a[i][0]-1];
            if(t==a[i][2]) {
                anstemp += a[i][3];
            }
        }
        ans = max(ans, anstemp);
        return;
    }

    FOR(i, selectindex, m) {
        vector<int> t = A;
        t.push_back(i+1);
        rec(i, t);
    }

    return;
}

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

    rep(i, q) {
        cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
    }

    vector<int> temp;
    rec(0, temp);

    print(ans);
    return 0;
}


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

int main(){
    string str;

    getline(cin,str);

    for(int i=0;i<(int)str.size();i++){
        if(islower(str[i])){
            str[i]=toupper(str[i]);
        }else if(isupper(str[i])){
            str[i]=tolower(str[i]);
        }

    }
    cout<<str<<endl;

}


Measured memory_bytes: 3112
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include <string.h>
int dp[105][3]={0};
int plan[105][3];
using namespace std;
int main(){
	int N,K;
	cin>>N>>K;
	int a,b;
	for(int i=0;i<105;i++){
		for(int j=0;j<3;j++){
			plan[i][j]=1;
		}
	}
	for(int i=0;i<K;i++){
		cin>>a>>b;
		b--;
		b=(b+1)%3;
		plan[a][b]=0;
		b=(b+1)%3;
		plan[a][b]=0;		
	}
	
	for(int i=1;i<=N;i++){
		if(i==1){
			dp[i][0]=plan[i][0];
			dp[i][1]=plan[i][1];
			dp[i][2]=plan[i][2];
		}else if(i==2){
			for(int k=0;k<3;k++){
				dp[i][k]=(dp[i-1][0]+dp[i-1][1]+dp[i-1][2])%10000;
			}
		}else{
			dp[i][0]=(dp[i-1][1]+dp[i-1][2]+plan[i-1][0]*(dp[i-2][1]+dp[i-2][2]))%10000;
			dp[i][1]=(dp[i-1][0]+dp[i-1][2]+plan[i-1][1]*(dp[i-2][0]+dp[i-2][2]))%10000;
			dp[i][2]=(dp[i-1][0]+dp[i-1][1]+plan[i-1][2]*(dp[i-2][0]+dp[i-2][1]))%10000;
		}
		
		for(int j=0;j<3;j++){
			dp[i][j]*=plan[i][j];
		}
		
	}
	/*for(int i=1;i<=N;i++){
		cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
	}*/
	
	cout<<(dp[N][0]+dp[N][1]+dp[N][2])%10000<<endl;
	
	
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    bool flag = true;
    bool isOne = false;
    bitset<100000> bit;
    bit.reset();
    for (int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i){
        if(a[i] % 2 != 0){
            bit[i] = 1;
        }
    }
    if(bit.none()){
        flag = false;
    }
    else {
        flag = true;
    }
    string ans;
    ans = flag ? "first" : "second";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	var a = parseInt(input[0], 10);
	//出力
	console.log(a*a);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500