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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

vector<bool> hours;

int calc_min_diff() {
    int ret = 24;
    rep(i, 24) {
        rep(j, 24) {
            if (i == j) continue;
            if (hours[i] && hours[j]) {
                int d1 = abs(i - j);
                int d2 = 24 - d1;
                chmin(ret, min(d1, d2));
            }
        }
    }
    return ret;
}

int main() {
    hours.resize(24);
    hours[0] = true;
    
    int N;
    cin >> N;
    vector<int> D(N);
    rep(i, N) cin >> D[i];
    vector<int> cnt(13, 0);
    rep(i, N) cnt[D[i]]++;

    if (cnt[0] || cnt[12] >= 2) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> one_cnt_hours;
    for (int i = 1; i < 12; i++) {
        if (cnt[i] == 1) one_cnt_hours.push_back(i);
        else if (cnt[i] == 2) hours[i] = hours[24 - i] = true;
        else if (cnt[i] > 2) {
            cout << 0 << endl;
            return 0;
        }
    }

    if (cnt[12]) hours[12] = true;

    if (one_cnt_hours.size() == 0) {
        cout << calc_min_diff() << endl;
        return 0;
    }

    int ans = 0;
    int m = one_cnt_hours.size();
    rep(bit, 1 << m) {
        rep(i, m) {
            int hour = one_cnt_hours[i];
            if (bit >> i & 1) {
                hours[hour] = true;
                hours[24 - hour] = false;
            } else {
                hours[hour] = false;
                hours[24 - hour] = true;
            }
        }
        chmax(ans, calc_min_diff());
    }
    cout << ans << endl;
}

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


int main(){ 
    int n,k,q;
    cin >> n >> k>>q;
    vector<int>a(q);
    for(int i=0;i<q;i++)cin >> a[i];
    vector<int>man(n);
    for(int i=0;i<q;i++)a[i]--;
    for(int i=0;i<n;i++)man[i] = k;
    for(int i=0;i<q;i++){
        man[a.at(i)] +=1;
    }
    for(int i=0;i<n;i++){
        man[i] -= q;
        if(man[i] <= 0)cout<<"No"<<endl;
        else cout << "Yes" << endl;
    }
    
}


Measured memory_bytes: 1408
main :: IO ()
main = do
  ls <- getContents
  let ls' = map (read :: String -> Int) (lines ls)
      ansL = solve ls'
  mapM_ putStrLn ansL
solve :: [Int] -> [String]
solve [] = []
solve (i:is) = ("3C" ++ (format (i `mod` 39))):(solve is)

format :: Int -> String
format 0 = "39"
format i = (replicate (2 - length s) '0') ++ s
  where s = show i

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define f first
#define sec second
#define pb push_back
#define pf push_front
#define po pop_back
#define fast ios_base::sync_with_stdio(false)
#define vi vector<ll>
#define vii vector< pair<ll,ll> >
#define pi pair<ll,ll>
#define map map<ll,ll>
#define set set<ll>
#define tostr to_string
#define toint stoi
#define gcd __gcd


int main()
{
    fast;
   ll a,b;cin>>a>>b;
   cout<<6-a-b<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;
#define PI (acos(-1))

int main()
{
  ll  A, B, K;
  cin >> A >> B >> K;

  if (K >= A + B)
  {
    cout << 0 << " " <<0;
  }
  else
  {
    if(K >= A){
      cout << 0 <<" " <<B-(K-A);
            
    }else{
      cout << A-K <<" "<<B ;
    }
  }
}


Measured memory_bytes: 3608
import sys

#fp = open("input.txt", "r")
fp = sys.stdin

while True:
    n = int(fp.readline()[:-1])
    if n == 0:
        break

    stella = [map(int, fp.readline()[:-1].split(" ")) for i in xrange(n)]

    m = int(fp.readline()[:-1])
    sky = [map(int, fp.readline()[:-1].split(" ")) for i in xrange(m)]

    trans_x = 0
    trans_y = 0
    for star in sky:
        trans_x = star[0] - stella[0][0]
        trans_y = star[1] - stella[0][1]
        flg = True
        for s in stella[1:]:
            if not [s[0] +trans_x, s[1]+trans_y] in sky:
                flg = False
                break
        if flg:
            break
    print trans_x,trans_y

Measured memory_bytes: 4500
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch WalkingTakahashi | diff WalkingTakahashi.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address WalkingTakahashi.cpp && ./a.out

/*

 8/15/2020

 5:08-

 */

LL X,K,D;

LL solve() {
  LL x=abs(X);
  LL a=x/D;
  //dump(x,a,K,D);
  if(a>K) return x-K*D;

  LL k=K-a;
  x=x-a*D;
  if(K==a) return x;
  LL y=x-D;
  //assert(y<0);
  y=abs(y);
  return k%2==0?x:y;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>X>>K>>D;
  cout<<solve()<<endl;

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A.at(i);
    if(A.at(0) != 0){
        cout << -1 << endl;
        return 0;
    }
    rep(i, N-1){
        if(A.at(i+1) - A.at(i) > 1){
            cout << -1 << endl;
            return 0;
        }
    }
    vector<ll> goal(N);
    rep(i, N){
        goal.at(i) = i - A.at(i);
    }
    ll ans = 0;
    ll p = N-1;
    while(true){
        ans += p - goal.at(p);
        if(goal.at(p) == 0){
            break;
        }
        while(goal.at(p-1) == goal.at(p)){
            p--;
        }
        p--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6336
import sys

sys.setrecursionlimit(1000000)

import bisect
import math
import collections
import heapq


def solve(N):
    i = 8
    n = 400
    while i > 0:
        if N < 200 + n + (200 * (8 - i)):
            return str(i)
        i -= 1


if __name__ == "__main__":

    N = int(input())
    print(solve(N))


Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
/*
	vec1.size();
	str1.length();
	vec1.pop_back;
*/
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef vector<pll> vplll;
#define rep(i,l,r) for (ll i = l; i < r; ++i)
#define reprev(i,l,r) for (ll i = r; i >= l; --i)
ll mod = 1e9+7;
ll expo_mod(ll x, ll y, ll p) 
{ 
	ll res = 1;
	x = x % p; 
	if (x == 0) 
		return 0; 
	while (y > 0) 
	{
		if (y%2==1) 
			res = (res*x) % p; 
		y = y>>1; // y = y/2 
		x = (x*x) % p; 
	} 
	return res; 
} 
ll gcd(ll a,ll b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k,cnt,curr;
	ll arr[200005];
	cin>>n>>k;
	ll ind[n+1];
	rep(i,1,n+1)
	{
		cin>>arr[i];
	}
	cnt=0;
	// curr=arr[1];
	// s1.insert(1);
	curr=1;
	set <ll> s1;
	while(s1.find(curr)==s1.end())
	{
		s1.insert(curr);
		ind[curr]=cnt;
		cnt++;

		curr=arr[curr];
	}
	ll cycle_len=cnt-ind[curr];
	// k-=ind[curr];
	if(k<=ind[curr])
	{
		curr=1;
		while(k--)
		{
			curr=arr[curr];
		}
		cout<<curr<<"\n";
	}
	else
	{
		k-=ind[curr];
		k%=cycle_len;
		while(k--)
		{
			curr=arr[curr];
		}
		cout<<curr<<"\n";
	}
	return 0;
}

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

class Program{
    static void Main(){
        int N = int.Parse(Console.ReadLine());
        string[] inputs = Console.ReadLine().Split(' ');
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = int.Parse(inputs[i]);
        }
        int avg = (int)Math.Round(a.Average(), MidpointRounding.AwayFromZero);
        int cost = 0;
        for(int i = 0; i < N; i++){
            if(a[i] != avg){
                cost += (int)Math.Pow((a[i] - avg), 2);
            }
        }
        Console.WriteLine(cost);
    }
}

Measured memory_bytes: 3032
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    vec a(4);
    int n;
    cin>>n;
    rep(i,4){
        a[i]=n%10;
        n/=10;
    }
    reverse(all(a));
    string s;
    for(int i=0;i<(1<<3);i++){
        int sum=0;
        sum+=a[0];
        string t;
        t+=to_string(a[0]);
        for(int j=0;j<3;j++){
            if(i>>j&1){
                sum+=a[j+1];
                t+='+';
                t+=to_string(a[j+1]);
            }else{
                sum-=a[j+1];
                t+='-';
                t+=to_string(a[j+1]);
            }
        }
        if(sum==7){
            s=t;
            break;
        }
    }
    s+="=7";
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast_io ios :: sync_with_stdio(false);
using namespace std;

int main() {
	fast_io;
	int n; cin >> n;
	int a[n];
	int cont = 0;
	for(int i = 0; i < n; i++) {
		cin>> a[i];
	}
	
	for(int i = 1; i < n - 1; i++) {
		if((a[i] < a[i-1] && a[i] > a[i+1]) || (a[i] > a[i-1] && a[i] < a[i+1])) {
			cont++;
		}
	}
	cout << cont;
	return 0;
}

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

int main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++) cin>>v[i];
  vector<int> odd(1e5+1,0),even(1e5+1,0);
  for(int i=0;i<n;i+=2) odd[v[i]]++;
  for(int i=1;i<n;i+=2) even[v[i]]++;
  int ido=(int)(max_element(odd.begin(),odd.end())-odd.begin());
  int ide=(int)(max_element(even.begin(),even.end())-even.begin());
  sort(odd.begin(),odd.end());
  sort(even.begin(),even.end());
  int ans;
  if(ido==ide){
    ans=max(odd.back()+*(even.end()-2),even.back()+*(odd.end()-2));
  }
  else{
    ans=odd.back()+even.back();
  }
  cout<<n-ans<<endl;
  return 0;
}
    


Measured memory_bytes: 1408
#include<iostream>

using namespace std;

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

    int ps = 0;
    int qs = 0;
    int n = 0;

    int p, q;
    char c;
    while(cin >> p >> c >> q){
        ps += p * q;
        qs += q;
        ++n;
    }

    int mq = qs / n;
    if((qs % n) * 2 >= n){
        ++mq;
    }

    cout << ps << endl << mq << endl;

    return 0;
}


Measured memory_bytes: 3056
N, K = map(int, input().split())
bitK = format(K, "b").zfill(41)
A = [int(a) for a in input().split()]
DP = [[0, 0] for _ in range(41)] #DP[i][0]は上位i bit目までKと一致、DP[i][1]はK以下
Ones = [0] * 41
for a in A:
    bita = format(a, "b").zfill(41)
    for i in range(41):
        Ones[i] += int(bita[i])

if bitK[0] == "1":
    DP[0][0] = (2 ** 40) * (N - Ones[0])
    DP[0][1] = (2 ** 40) * Ones[0]
else:
    DP[0][0] = (2 ** 40) * Ones[0]
    DP[0][1] = 0

for i in range(1, 41):
    oneNum = Ones[i]
    digit = 2**(40-i)
    if bitK[i] == "1":
        DP[i][0] = DP[i-1][0] + digit * (N - oneNum)
        DP[i][1] = DP[i-1][0] + digit*oneNum
        if DP[i-1][1] > 0:
            DP[i][1] = max(DP[i][1], DP[i-1][1] + digit*max(oneNum, N-oneNum))
    else:
        DP[i][0] = DP[i-1][0] + digit*oneNum
        if DP[i-1][1] > 0:
            DP[i][1] = DP[i-1][1] + digit*max(oneNum, N-oneNum)

print(max(DP[-1]))

Measured memory_bytes: 14620
import itertools


n, r = map(int, input().split())
# p = list(map(int, input().split()))
# s = input().split()
# S = [int(input()) for i in range(int(n))]
i =0


def Base_10_to_n(X, n):
    if (int(X / n)):
        return Base_10_to_n(int(X / n), n) + str(X % n)
    return str(X % n)


x2 = Base_10_to_n(n, r)
print(len(x2))  # "100011"が表示される．

# print(r+i)


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

using namespace std;

int main()
{
  int n,i,j,found=1;
  vector <int> v;
  cin >> n;

  for(i=1;i<=n;i++){
    cin >> j;
    v.push_back(j);
  }

  for(i=0;i<v.size();i++){
    if(v[i]%2==0 && !(v[i]%3==0) && !(v[i]%5==0)){
      found = 0;
      break;
    }
  }

  if(found) cout << "APPROVED";
  else cout << "DENIED";

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,c=0,a=10;
    cin>>n;
    if(n%2==1 || n<2)
    {
        cout<<0<<endl;
        return 0;
    }
     ll b=n/10;
    while(b>0)
    {
        c=c+b;
        a=a*5;
        b=n/a;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
int main(){
  int ans = 0;
  rep(i, 3){
    char s;
    cin >> s;
    if(s == '1') ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];
        long ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        for (int i = 0; i < n - k; i++) {
            ans += a[i];
        }
        System.out.println(ans);

    }
}


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}


inline int addmod(int x,int y)
{
    return (x%mod + y%mod)%mod;
}
inline int submod(int x,int y)
{
    return (x%mod - y%mod + mod)%mod;
}
inline int mulmod(int x,int y)
{
    return (x%mod *1LL* y%mod)%mod;
}

inline int nextSubMask(int i, int mask)
{
    return (i-1)&mask;   /// returns next  submask
}

template<typename T>
void we_r_done(T mssg)
{
    cout<<mssg;
    exit(0);
}


int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;

    int n,m;
    scn2(n,m);
    vector<int>v[n+2];
    for(int i=1; i<=m; i++){
        int a,b;
        scn2(a,b);
        v[a].pb(b);
        v[b].pb(a);
    }

    for(int i=1; i<=n; i++){
        sort(atoz(v[i]));
        if(v[i].size() && v[i][0] == 1 && v[i].back() == n) we_r_done("POSSIBLE");
    }
    cout<<"IMPOSSIBLE";
    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?
///sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b : x.a<y.a);});


Measured memory_bytes: 12016
INF = float('inf')

N, M, X = map(int, input().split())
Cs = []
Ass = []
for _ in range(N):
    C, *As = map(int, input().split())
    Cs.append(C)
    Ass.append(As)
#print('Ass:')
#for As in Ass:
#    print(As)

ans = INF
for S in range(1<<N):
    Bs = [0] * M
    cost = 0
    for i in range(N):
        if (S>>i)&1:
            cost += Cs[i]
            for j in range(M):
                Bs[j] += Ass[i][j]
        if min(Bs) >= X:
            ans = min(ans, cost)

if ans == INF:
    print(-1)
else:
    print(ans)


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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    int counter = 0;

    //検索
    for(int i = 0; i < S.size() ; ++i){
        if( S[i]   == 'A'
         && S[i+1] == 'B'
         && S[i+2] == 'C') counter++;
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 0;
		for(i = 1; i <= n; i = i * 2) {
		}
		i = i / 2;
		System.out.println(i);
	}
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

using Graph = vector<vector<Pii>>;
Graph g;
ll es[51][51];

void dfs(int v, int p, int u, ll edges) {
    es[u][v] = edges;
    for (const auto& to : g[v]) {
        if (to.first == p) continue;
        dfs(to.first, v, u, edges | (1LL << to.second));
    }
}

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

    int N;
    cin >> N;
    g.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }

    int M;
    cin >> M;
    Vi us(M), vs(M);
    for (int i = 0; i < M; i++) {
        cin >> us[i] >> vs[i];
        --us[i], --vs[i];
    }

    for (int i = 0; i < N; i++) {
        dfs(i, i, i, 0);
    }

    ll ans = (1LL << (N - 1));
    for (ll mask = 1; mask < (1LL << M); mask++) {
        ll edges = 0;
        for (int i = 0; i < M; i++) {
            if (mask & (1LL << i)) {
                edges |= es[us[i]][vs[i]];
            }
        }
        int e_num = __builtin_popcountll(edges);
        if (__builtin_popcountll(mask) & 1) {
            ans -= (1LL << (N - 1 - e_num));
        }
        else {
            ans += (1LL << (N - 1 - e_num));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

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

    set<int> ans;

    for(int i = a; i < a+x && i <= b; i++){
        ans.insert(i);
    }

    for(int i = b; i > b-x && i >= a; i--){
        ans.insert(i);
    }

    for(auto itr = ans.begin(); itr != ans.end(); itr++){
        cout << *itr << endl;
    }
}


Measured memory_bytes: 888
#include<iostream>
#include<iomanip>

using namespace std;

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  int n,a;
  cin>>n>>a;
  n%500<=a ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  bool ok = false;
  for (int i = n - m + 1; i >= 0; --i) {
    ok = true;
    for (int j = 0; j < m; ++j) {
      if (s[i + j] != '?' and s[i + j] != t[j]) {
        ok = false;
      }
    }
    if (ok) {
      for (int j = 0; j < m; ++j) {
        s[i + j] = t[j];
      }
      for (int j = 0; j < n; ++j) {
        if (s[j] == '?') { s[j] = 'a'; }
      }
      break;
    }
  }
  printf("%s\n", ok ? s.c_str() : "UNRESTORABLE");
  return 0;
}


Measured memory_bytes: 256
int main()
{
  char s[101];
  scanf("%s", s);
  for (int i = 0; s[i] != '\0'; i++)
  {
    if ((i % 2 == 0 && s[i] == 'L') || (i % 2 == 1 && s[i] == 'R'))
    {
      printf("No");
      return 0;
    }
  }
  printf("Yes");
}

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

int main() {
    int n;
    cin >> n;
    int x = n;
    int f = 0;
    
    while(x) {
        f += x % 10;
        x /= 10;
    }
    
    cout << (((n % f) == 0) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	LL X, Y, ans;
	cin >> X >> Y;
	ans = -1;

	if (X == Y) {
		ans = -1;
	}
	else if (Y == 1) {
		ans = -1;
	}
	else if (X > Y) {
		if (X%Y == 0) {
			ans = -1;
		}
		else {
			ans = X;
		}
	}
	else {
		//x<y
		ans = X;
	}
	if (ans > 1000000000000000000)ans = -1;

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li      int32_t
#define lli     long long
#define ulli unsigned long long

#define pn           printf("\n")
#define nl           cout<<'\n'
#define sf(N)        scanf("%lld",&N)
#define pf(N)        printf("%lld",N)
#define sf1(N1,N2)    scanf("%lld %lld",&N1,&N2)
#define pf1(N1,N2)    printf("%lld %lld",N1,N2)
#define sf2(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define pf2(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define sl          cout<<' '
#define ps          printf(" ")

#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))

#define pb      push_back
#define pob     pop_back
#define itr     iterator
#define sz()    size()
#define szof    sizeof
#define lb      lower_bound
#define ub      upper_bound
#define mp      make_pair
#define vlli    vector<lli>
#define plli    pair<lli,lli>
#define vplli   vector<plli >
#define F       first
#define S       second
#define Dup     erase(unique(V.begin(),V.end()),V.end())

#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define ALL(V)  V.begin(),V.end()

#define MX1     100000
#define MX2     1000000
#define mod     1000000007
#define Inf     1000000000000000
using namespace std;

lli Power(lli a,lli b)
{
    lli result=1;

    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }

        b=b>>1;
        a=(a*a)%mod;
    }

 return result;
}

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/
    
    lli N,M;
    cin>>N>>M;
    
    cout<<(N-1)*(M-1);
    
    
    
    




 return 0;
}


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

const int N=1e5+100;
typedef long long ll;
int a[N];
ll lcm(ll x,ll y)
{
    return x*y/__gcd(x,y);
}
int main()
{
   ios::sync_with_stdio(0);cin.tie(0);
   ll a,b,c,d;cin>>a>>b>>c>>d;
   ll cc=b/c-(a-1)/c;
   ll dd=b/d-(a-1)/d;
   ll cd=b/lcm(c,d)-(a-1)/lcm(c,d);
   ll ans=(b-a+1)-cc-dd+cd;
   cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int n; cin >> n;
	unordered_map<int, bool> mp; 
	bool f = true;
	rep(i, n){
		int a; cin >> a;
		if(mp[a]) f = false;
		mp[a] = true;
	}
	YES(f);
}

Measured memory_bytes: 8520
#include <bits/stdc++.h>
using namespace std;
bool ACGT(char ch) {
	if (ch == 'A' || ch == 'T' || ch == 'C' || ch == 'G') return true;
	else return false;
}
int main() {
	string S;
	cin >> S;
	vector<int>A(S.size(), 0);
	if (ACGT(S.at(0))) A.at(0) = 1; 
	for (int i = 1; i < S.size(); i++) {
		if (ACGT(S.at(i))) A.at(i) = A.at(i - 1) + 1;
		else A.at(i) = 0;
	}
	sort(A.begin(), A.end(), greater<int>());
	cout << A.at(0) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
        int a[10][10]={},n,d,i,j,k,l=0,p=0,ans;
        int s[10];
        scanf("%d%d",&n,&d);
        for(i=0;i<n;i++){
            for(j=0;j<d;j++){
                scanf("%d",&a[i][j]);
            }
        }
       for(i=0;i<n;i++){
            for(k=i+1;k<n;k++){
                ans=0;
                for(j=0;j<d;j++){
                    ans=ans+((a[i][j]-a[k][j])*(a[i][j]-a[k][j]));
                }
                s[p]=ans,p++;
            }
       }
       for(i=0;i<p;i++){
            ans=sqrt(s[i]);
            if(ans*ans==s[i]){
                l++;
            }
       }
       printf("%d",l);
       return 0;
}


Measured memory_bytes: 2152
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)((n>>m)&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)
ll gcd(ll p,ll q){for(ll t;q;)t=p%q,p=q,q=t;return p;}

ll a,b;
char s1[100010],s2[100010];
int main(){
	scanf("%lld%lld\n",&a,&b);
	scanf("%s%s",s1,s2);
	ll d=gcd(a,b);
	rep(i,0,d)if(s1[i*a/d]!=s2[i*b/d]){
		puts("-1");
		return 0;
	}
	printf("%lld\n",a*b/d);
	return 0;
}


Measured memory_bytes: 384
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
ant_list=[a,b,c,d,e]
ant_list.sort()
if (ant_list[-1]-ant_list[0])<=k:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();

			LinkedList<Long> list = new LinkedList<Long>();

			for (int i = 0; i < 3*n; i++) {
				list.add(in.nextLong());
			}
			Collections.sort(list);

			long cost = 0;
			for (int i = 0; i < n; i++) {
				list.removeFirst();
				list.removeLast();
				cost += list.removeLast();
			}
			System.out.println(cost);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


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

#define eb emplace_back
#define ld long double
#define ll long long

using namespace std;

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n, x, t;
	cin >> n >> x >> t;
	cout << t * ((n + x - 1) / x) << "\n";
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define ml cout<<"\n"
 
#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define in insert
#define ff first
#define ss second
#define mod 1000000007

#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	ios_base::sync_with_stdio(false);
     	cin.tie(NULL);
    	cout.tie(NULL);    
    // ll t;
    // cin>>t;
    // while(t--){
    	
        
    // }
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;
}

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

int main() {
  int n, c, k;
  cin >> n >> c >> k;

  vector<ll> t(n);
  rep (i, n) cin >> t[i];

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

  ll lt = t[0] + k;
  ll p = 1;
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (t[i] <= lt && p < c)
      p++;
    else {
      ans++;
      p = 1;
      lt = t[i] + k;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, m, a[N];
int lb[20][N], rb[20][N], cnt;
int fl[1058576], fr[1058576], mx, s[N];

void init() {
	lb[cnt][1] = 1;
	for(int i = 2; i <= n; i++) lb[cnt][i] = (a[i] - a[i - 1] > m) ? i : lb[cnt][i - 1];
	rb[cnt][n] = n;
	for(int i = n - 1; i; i--) rb[cnt][i] = (a[i + 1] - a[i] > m) ? i : rb[cnt][i + 1];
	lb[cnt][0] = 1, rb[cnt][n + 1] = n;
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(; m; m /= 2) init(), ++cnt; init();
	fr[0] = n + 1, mx = (1 << cnt) - 1;
	for(int i = 1; i <= mx; i++) {
		fr[i] = n;
		for(int j = 0; j < cnt; j++) if(i & (1 << j)) {
			fl[i] = max(fl[i], rb[j + 1][fl[i ^ (1 << j)] + 1]);
			fr[i] = min(fr[i], lb[j + 1][fr[i ^ (1 << j)] - 1]);
		}
	}
	for(int i = 0; i <= mx; i++) {
		int x = lb[0][fr[mx ^ i] - 1], y = rb[0][fl[i] + 1];
		if(x <= y) ++s[x], --s[y + 1];
	}
	for(int i = 1; i <= n; i++)
		s[i] += s[i - 1], puts(s[i] ? "Possible" : "Impossible");
	return 0;
}

Measured memory_bytes: 39168
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int n;cin>>n;
    int a[100010],b[100010];
    ll S_a[100010],S_b[100010];
    S_a[0]=S_b[0]=0;
    for(int i=1;i<=n;i++){
        int c;cin>>c;
        a[i]=b[i]=c;
    }
    ll ans_a=0,ans_b=0;
    for(int i=1;i<=n;i++){
        S_a[i]=S_a[i-1]+a[i];
        S_b[i]=S_b[i-1]+b[i];
        if(i%2==1){
            if(S_a[i]<=0){
                ans_a+=1-S_a[i];
                S_a[i]=1;
            }
            if(S_b[i]>=0){
                ans_b+=S_b[i]+1;
                S_b[i]=-1;
            }
        }
        else{
            if(S_a[i]>=0){
                ans_a+=S_a[i]+1;
                S_a[i]=-1;
            }
            if(S_b[i]<=0){
                ans_b+=1-S_b[i];
                S_b[i]=1;
            }
        }
    }
    cout<<min(ans_a,ans_b)<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long n,m;
long long a,x;
long long i,j;
vector <long long> p,t;
int main ()
{
	while(1)
	{
		cin >> n >> m;
		if(n==0 && m==0) break;
		p.clear();
		t.clear();
		p.push_back(0);
		for(i=0;i<n;i++)
		{
			cin >> a;
			p.push_back(a);
		}
		sort(p.begin(),p.end());
		for(i=0;i<=n;i++)
		{
			j=i;
			while(p[i]+p[j]<=m)
			{
				t.push_back(p[i]+p[j]);
				if(j==n) break;
				j++;
			}
		}
		sort(t.begin(),t.end());
		x=0;
		j=t.size()-1;
		//for(i=0;i<p.size();i++) cout << "PP" << p[i];
		//for(i=0;i<t.size();i++) cout << "TT" << t[i];
		for(i=0;i<=j;i++)
		{
			while(t[i]+t[j]>m) j--;
			if(x<t[i]+t[j])
			{
				x=t[i]+t[j];
				//cout <<"AA"<< t[i] << " " << t[j];
			}
		}
		cout << x << endl;
	}
}

Measured memory_bytes: 6988
N = int(input())
A = list(map(int, input().split()))
mn = len(list(filter(lambda x: x < 0, A)))
ans = [-A[i] if A[i] < 0 else A[i] for i in range(N)]
if mn % 2 == 0:
    print(sum(ans))
else:
    print(sum(ans)-min(ans)*2)


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

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

  int cnt = 0;
  if(s[0] == 'o') ++cnt;
  if(s[1] == 'o') ++cnt;
  if(s[2] == 'o') ++cnt;
  cout << 700 + 100*cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	for (int i=0; i<n; ++i){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	for (int i=0; i<n; ++i){
		cin >> b[i];
	}
	sort(b.begin(), b.end());
	for (int i=0; i<n; ++i){
		cin >> c[i];
	}
	sort(c.begin(), c.end());
	
	long long res = 0;
	vector <int> next_b(n, -1);
	for (int i=0, j=0; i<n; ++i){
		while (j < n && a[i] >= b[j]) ++j;
		if (j == n) break;
		next_b[i] = j;
	}
	vector <long long> next_c(n, -1);
	for (int i=0, j=0; i<n; ++i){
		while (j < n && b[i] >= c[j]) ++j;
		if (j == n) break;
		next_c[i] = n-j;
	}
	for (int i = n-1; i > 0; --i){
		if (next_c[i] == -1) continue;
		next_c[i-1] += next_c[i];
	}
	for (int i=0; i<n; ++i){
		if(next_b[i] == -1) break;
		if (next_c[next_b[i]] != -1)
			res += next_c[next_b[i]];
	}
	cout << res << endl;
}

Measured memory_bytes: 2560
#MLE注意！

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = input().rstrip()
    if '7' in n:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

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

int main()
{
    int N, M, C;
    cin >> N >> M >> C;
    int B[M + 1], A[N + 1][M + 1];
    for (int j = 1; j <= M; j++)
    {
        cin >> B[j];
    }
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= M; j++)
        {
            cin >> A[i][j];
        }
    }
    int count = 0;
    for (int i = 1; i <= N; i++)
    {
        int sum = C;
        for (int j = 1; j <= M; j++)
        {
            sum += A[i][j] * B[j];
        }
        if (sum > 0)
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
long long sum1;
double xx;
int a[1005];
long long ans;
int main()
{
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
		cin>>a[i];
		sum1+=a[i];
	}
	sort(a+1,a+1+n,cmp);
	xx=1.0*sum1/4/m;
	for(int i=1;i<=n;i++)
	{
		if(a[i]<xx)
		{
			break;
		}
		else
		{
			ans++;
		}
	}
	if(ans>=m)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var A [3]int
	for i := 0; i < 3; i++ {
		fmt.Scanf("%d", &A[i])
	}

	if sum := A[0] + A[1] + A[2]; sum >= 22 {
		fmt.Println("bust")
	} else {
		fmt.Println("win")
	}
}


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

#define ll long long
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define rfo(i,n,a) for(ll i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll t,n,i,j,x;
    cin>>x>>n;
    vector<ll> a;
    //a.resize(n);
    fo(i,0,n){
    cin>>j;
    a.pb(j);
    }
    if(!n){
        cout<<x<<endl;
        return 0;
    }
    sort(a.begin(),a.end());
    ll in=lower_bound(a.begin(),a.end(),x)-a.begin();
    if(a[in]!=x){
        cout<<x<<endl;
        return 0;
    }
    ll k=1,n1=1e9,n2=1e9;
    rfo(i,in-1,0){
    if(a[i]!=x-k){
        n1=x-k;
        break;;
    }
    k++;
    }
    k=1;
    fo(i,in+1,n){
    if(a[i]!=x+k){
        n2=x+k;
        break;
    }
        k++;
    }
    if(n1==1e9)
        n1=a[0]-1;
    if(n2==1e9)
        n2=a[n-1]+1;
    ll mn1=fabs(n1-x),mn2=fabs(n2-x);
    if(mn1==mn2){
        cout<<min(n1,n2)<<endl;
        return 0;
    }
    if(mn1<mn2)
        cout<<n1<<endl;
    else
        cout<<n2;

}


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

int main() {
	string w;
	cin >> w;
	int s = w.length();
	string kai = "Yes";
	if(s % 2 > 0)
	{
		kai = "No";
	}
	else
	{
		sort(w.begin(),w.end());
		for(int i = 0;i < s;i += 2)
		{
			if(w.at(i) != w.at(i+1))
			{
				kai = "No";
			}
		}
	}
    cout << kai << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

int main(){
	//mahakal();fast;

	ll n ;
	cin>>n ;
	ll arr[n];
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
	bool flag=0;
	for(ll i=0;i<n;i++){
		if(~arr[i]&1){
			if(arr[i]%3!=0 && arr[i]%5!=0){
				flag=1;
			}
		}
	}
	if(flag)cout<<"DENIED"<<endl;
	else cout<<"APPROVED"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF = 1001001001;

int e, x, y, z, m;
int main()
{

	while (1)
	{
		cin >> e;
		if (e == 0) break;
		m = INF;
		rep(z, 101)
		{
			rep(y,1001)
			{
				x = e - y*y - z*z*z;
				if (x >= 0)
				{
					m = min(m, x + y + z);
				}
			}
		}
		cout << m << endl;

	}
	return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <cmath>
#include <ctime>
#include <numeric>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define REP(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define MSG(a) cout << #a << " "  << a << endl;
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

const int MOD = 100000;

int main()
{
	//ifstream ifs("E:\\programing\\C C++\\2010-ho-data\\2010-ho-data\\2010-ho-t1-in6");
	int n, m;
	while(cin >> n >> m)
	{
		int index = 0, res = 0;
		vint town(n); town[0] = 0;

		REP(i, 1, n)
			cin >> town[i];

		partial_sum(town.begin(), town.end(), town.begin());

		rep(i, m)
		{
			int s;
			cin >> s;

			res += abs(town[index] - town[index + s]);
			index += s;
			res %= MOD;
		}

		cout << res << endl;
	}
}

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

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

// タプルの最初の要素から順番に比較　もしその要素が同じなら次の要素で比較
bool mycompare( const tuple<string,int,int> &lhs, const tuple<string,int,int> &rhs )
{
    if (get<0>(lhs) != get<0>(rhs)) return get<0>(lhs) < get<0>(rhs);
    if (get<1>(lhs) != get<1>(rhs)) return get<1>(lhs) > get<1>(rhs);
    return get<2>(lhs) < get<2>(rhs);
}

int main() {
  int N;
  cin >> N;
  vector<tuple<string,int,int>> vt(N);
  rep(i, N){
    string S;
    int P;
    cin >> S >> P;
    vt.at(i) = make_tuple(S, P, i+1);
  }
  sort(vt.begin(), vt.end(), mycompare);
  rep(i, N){
    cout << get<2>(vt.at(i)) << endl;
  }
}

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

int main(void)
{
    int n,i,j,num,ans=0;

    scanf("%d",&n);

    for ( i = 1; i <= n; i++)
    {
        if(i%2==1)
        {
            num=0;
            for(j=1;j<=i;j++)
            {
                if(i%j==0) num++;
            }
            if(num==8) ans++;
        }
    }

    printf("%d",ans);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#define int long long

signed compair(const void *a, const void *b){
	int sub = *(int *)a - *(int *)b;
	if(sub < 0){
		return -1;
	}
	else if(sub == 0){
		return 0;
	}
	else{
		return 1;
	}
}

int ABS(int a){
	return a >= 0 ? a : -a;
}

int min(int a, int b){
	return a <= b ? a : b;
}

signed main(){
	int N, i, m, ans = 0;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	qsort(A, N, sizeof(int), compair);
	if(N % 2 == 0){
		m = A[N / 2];
		for(i = 0; i < N; i++){
			ans += 2 * ABS(A[i] - m);
		}
		ans -= ABS(A[N / 2 - 1] - m) + ABS(A[N / 2] - m);
	}
	else{
		m = A[N / 2];
		for(i = 0; i < N; i++){
			ans += 2 * ABS(A[i] - m);
		}
		ans -= min(ABS(A[N / 2 - 1] - m), ABS(A[N / 2 + 1] - m));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1788