akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
T intceil(T a, T b) {
    return (a + (b - 1)) / b;
}

signed main() {
    INIT;
    cin >> N >> X >> Y;
    cout << intceil(N, X) * Y << endl;
}

Measured memory_bytes: 3648
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto N = RD!long;
	auto M = RD!long;

	writeln((N == 1 ? 1 : max(0, N-2)) * (M == 1 ? 1 : max(0, M-2)));
	stdout.flush();
}

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

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

  bool bucket[26];
  for (int i = 0; i < 26; i++) {
    bucket[i] = false;
  }

  for (int i = 0; S[i]; i++) {
    bucket[S[i] - 'a'] = true;
  }

  for (int i = 0; i < 26; i++) {
    if(!bucket[i]) {
      cout << (char)(i + 'a') << endl;
      return 0;
    }
  }
  
  cout << "None" << endl;
}


Measured memory_bytes: 512
N=int(input())
H=list(map(int,input().split()))+[0]
ans=0
MIN=MAX=0
for i in range(N):
    if H[i]>H[i+1]:
        ans+=H[i]-MIN
        MIN=H[i+1]
    if i==N-1:
        print(ans)
        exit()

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
	int A, B;
		scanf("%d %d", &A, &B);
		
	if (A==2 && B==1 || A==1 && B==2) {
		printf("3");
	}
	else if (A==3 && B==1 || A==1 && B==3) {
		printf("2");
	}
	else if (A==3 && B==2 || A==2 && B==3) {
		printf("1");
	}	

	return 0;
}


Measured memory_bytes: 1664
#include <queue>
#include <string>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  priority_queue<int> Q;
  while (true) {
    int num;
    char oper[1000];
    scanf("%s", oper);
    if (oper[2]=='d') break;
    else if (oper[0]=='i') {
      scanf("%d", &num);
      Q.push(num);
    }
    else if (oper[1]=='x') {
      int ex = Q.top();
      Q.pop();
      cout << ex << endl;
    }
  }
}

Measured memory_bytes: 6200
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  string s;
  cin>>s;
  int cnt[100001] = {};
  int cur = 0;
  ll ans = 0;
  REP(i, s.size()){
    if(s[i] == '(') cur++;
    else cur--;
    ans += cnt[cur];
    cnt[cur]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1796
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,t,ans = 1;
    cin >> n;
    rep(i,n){
        cin >> t;
        ans = ans/gcd(ans,t)*t;
    }
    PRINT(ans);
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    vi H(N); REP(i, N) cin >> H[i];
    int ans = 0, m = -INF;
    REP(i, N)
    {
        if(m <= H[i]) ans++;
        m = max(m, H[i]);
    }
    cout << ans << endl;
} 
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, K;
int M;
std::vector<int> G[210];

std::string ask(int v){
    std::cout << v << std::endl;

    std::string res;
    std::cin >> res;

    return res;
}

void gen(int s, int n){
    if(n <= 1){
        return;
    }

    int n1 = n / 2, n2 = n - n1;
    for(int i=1;i<n1;++i){
        M += 1;
        G[s].emplace_back(s + i);
    }

    gen(s + 1, n1 - 1);
    gen(s + n1, n2);
}

void solve(int s, int n){
    if(n == 1){
        ask(s);
        return;
    }

    int n1 = n / 2, n2 = n - n1;
    std::string res = ask(s);
    
    if(res == "Yes"){
        return;
    }else if(res == "Near"){
        solve(s + 1, n1 - 1);
    }else{
        solve(s + n1, n2);
    }
}

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

    std::cin >> N >> K;

    gen(1, N);

    std::cout << M << std::endl;

    for(int i=1;i<=N;++i){
        for(int j : G[i]){
            std::cout << i << " " << j << std::endl;
        }
    }

    for(int t=0;t<K;++t){
        solve(1, N);   
    }
}



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

ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  return b;
}

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i,n) cin >> a[i];
  
  int num = 1;
  rep(i, n) {
    if (num == a[i]) {
      num++;
    }
  }
  
  int ans = -1;
  if (num != 1) ans = (n-num+1);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){

int x;
scanf("%d",&x);
if(x%7==1){
printf("fri\n");
}
else if(x%7==2){
printf("sat\n");
}
else if(x%7==3){
printf("sun\n");
}
else if(x%7==4){
printf("mon\n");
}
else if(x%7==5){
printf("tue\n");
}
else if(x%7==6){
printf("wed\n");
}
else{
printf("thu\n");
}
return 0;
}


Measured memory_bytes: 2104
<?php

$NM = explode( ' ', trim( fgets( STDIN ) ) );
$A = explode( ' ', trim( fgets( STDIN ) ) );

foreach ( $NM as $key => $value ) {
  $NM[$key] = intval($value);
}

foreach ( $A as $key => $value ) {
  $A[$key] = intval($value);
}

$sum = 0;

foreach ( $A as $value ) {
  $sum += $value;
}

$select = 0;

$vote = $sum / (4 * $NM[1]);
//$vote = round($vote);

rsort($A);

for ( $i = 0; $i < $NM[1]; $i++ ) {
  if ( $A[$i] < $vote ) {
    echo 'No';
    return;
  }
}

echo 'Yes';

?>

Measured memory_bytes: 4604
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int A, B;
	
	cin>>A>>B;
	
	cout<<max(0ll, A - B*2)<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
l,r=map(int, input().split())
m=2019
m=int(m)
pot = m

if l//m != r//m:
    print(0)
else:
    for i in range(l,r):
        for j in range(i+1,r+1):
            pot = min(pot, (i*j)%m)

    print(pot)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
mt19937 _mt(chrono::steady_clock::now().time_since_epoch().count());
ll getrnd(ll l,ll r){return uniform_int_distribution<ll>(l,r-1)(_mt);}
#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll t,ans=1;
	cin>>n;
	rep(i,n){
		cin>>t;
		ans=t/gcd(ans,t)*ans;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef long long int lli;

int main(){
    int flag1;
    lli N, *H, max, min, tmp, i;
    scanf("%lld", &N);
    H = (lli *)malloc(sizeof(lli)*N);
    for(i=0; i<N; i++)
    {
        scanf("%lld", &H[i]);
    }
    if(i==0)
    {
        fprintf(stdout,"Yes\n");
        free(H);
        return 0;
    }
    flag1 = 0;
    for(i=0; i<N-1; i++)
    {
        tmp = H[i+1]-H[i];
        if(tmp>=1)
        {
            flag1 = 0;
            continue;
        }else if(tmp==0)continue;
        else if(tmp == -1)
        {
            if(flag1 == 1)
            {
              flag1 = 2;
              break;              
            }
            flag1 = 1;
        }else{
            flag1 = 2;
            break;
        }
    }    
    if(flag1 == 2)fprintf(stdout,"No\n");
    else fprintf(stdout,"Yes\n");
    free(H);
}

Measured memory_bytes: 896
def i1str():
    return input()


def istrs(n=None):
    if n is None:
        return input().split()
    a = []
    for _ in range(n):
        a.append(istrs())
    return a


def i1num():
    return int(input())


def inums(n=None):
    if n is None:
        return list(map(int, input().split()))
    a = []
    for _ in range(n):
        a.append(inums())
    return a


def ostrs(l, sp=" "):
    print(sp.join(l))


def onums(l, sp=" "):
    print(sp.join(map(str, l)))


def solve(n):
    s = set()
    for _ in range(n):
        s.add(input())
    return len(s)


if __name__ == "__main__":
    n = i1num()
    print(solve(n))


Measured memory_bytes: 31208
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll N;
  cin >> N;

  vector<ll> factors;
  for (ll k = 2; k <= N; ++k) {
    ll n = k;

    // Calculate prime factors.
    ll i = 2;
    while (i * i <= n) {
      while ((n % i) == 0) {
        factors.push_back(i);
        n /= i;
        // For Debug
      }
      ++i;
    }
    if (n > 1) {
      factors.push_back(n);
    }
  }
  map<ll, ll> mp;
  for (auto x : factors) {
    ++mp[x];
  }

  // For Debug
  // for (auto x : mp) {
  //   cout << x.first << ": " << x.second << endl;
  // }

  // Here, we calculate the count of 74, 24, 14, 4, 2
  // (75) -> 1C1 = 1
  // (25, 3) -> 3C1 * (15-1)C1 = 42
  // (15, 5) -> 4C1 * (9-1)C1 = 32
  // (5, 5, 3) -> 9C2 * (15-2)C1 = 468
  ll c74 = 0;
  ll c24 = 0;
  ll c14 = 0;
  ll c4 = 0;
  ll c2 = 0;
  for (auto x : mp) {
    if (x.second >= 74) { ++c74; }
    if (x.second >= 24) { ++c24; }
    if (x.second >= 14) { ++c14; }
    if (x.second >= 4)  { ++c4; }
    if (x.second >= 2)  { ++c2; }
  }

  ll ans = 0;
  ans += c74;
  ans += c24 * max(0LL, (c2-1));
  ans += c14 * max(0LL, (c4-1));
  ans += c4 * max(0LL, c4-1) / 2 * max(0LL, c2-2);

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,x;
	cin>>n>>x;
	ll arr[n];
	//ll ps[n-1];
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];

	}
	ll c=0;
	//for(ll i=0;i<n-1;i++)
	//	ps[i]=arr[i]+arr[i+1];
	//ll min =2000000009;
	for(ll i=0;i<n-1;i++)
	{
		if(arr[i]+arr[i+1]>x)
		{
			c += arr[i]+arr[i+1]-x;
			arr[i+1]-=arr[i]+arr[i+1]-x;
			if(arr[i+1]<0)
				arr[i+1]=0;	
		}	
	}
	cout<<c<<"\n";

}

Measured memory_bytes: 4404
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
int num(vector< int > &A, vector< int > &D, int m) {
	int ret = 0;
	rep(i, A.size()) {
		ret += D.end() - lower_bound(D.begin(), D.end(), m - A[i]);
	}
	return ret;
}
signed main() {
	int X, Y, Z;
	cin >> X >> Y >> Z;
	cin >> K;
	vector< int > A(X), B(Y), C(Z);
	rep(i, X) cin >> A[i];
	rep(i, Y) cin >> B[i];
	rep(i, Z) cin >> C[i];
	vector< int > D(Y * Z);
	rep(i, Y) rep(j, Z) {
		D[i * Z + j] = B[i] + C[j];
	}
	sort(D.begin(), D.end());
	//vector< int > ans(K);
	int l = 0, r = LINF / 2;
	while (r - l > 1) {
		int m = (l + r) / 2;
		if (num(A, D, m) >= K) {
			l = m;
		} else {
			r = m;
		}
	}
	vector< int > ans;
	rep(i, X) {
		auto it = lower_bound(D.begin(), D.end(), r - A[i]);
		for (; it != D.end(); it++) {
			ans.push_back(A[i] + *it);
		}
	}
	while (ans.size() < K)
		ans.push_back(l);
	sort(ans.rbegin(), ans.rend());
	rep(i, K) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 8192
def solve(l):
    buf = []
    lb = len(bin(l)) - 3
    for i in range(lb):
        buf.append((i + 1, i + 2, 0))
        buf.append((i + 1, i + 2, 1 << i))
    ofs = 1 << lb
    for i, c in enumerate(bin(l)[3:]):
        if c == '1':
            buf.append((lb - i, lb + 1, ofs))
            ofs += 1 << (lb - i - 1)
    return lb + 1, buf


l = int(input())
n, buf = solve(l)
print(n, len(buf))
print('\n'.join(' '.join(map(str, e)) for e in buf))


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

 int K,A,B;
int pre(){
  cin >> K >> A >> B;
     for(int i=A;i<=B;i++){
        if(i%K==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


int main ()
{
  pre();
  return 0;
}

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

long long gcd(long long a,long long b){
	if(a>b){
		swap(a,b);
	}
	while(true){
		if(b%a==0){
			return a;
		}else{
			b=b%a;
			swap(a,b);
		}
	}
}

int main() {
	long long n,m,i,j,k,ans,cur,res,mod=1000000007;
	string s,t;
	cin >> n >> m;
	ans=n*m/gcd(n,m);
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
//in the name of god
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int)1e5+20
#define INF 1e9+20
#define pb push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int,int> pii;
const int delta=(int)1e9+7;
int n,a,ans1=1,ans2=1;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a; ans1*=3;
		if(a&1) ans2*=1;
		else ans2*=2;
	}
	ans1-=ans2;
	cout<<ans1;
	return cout<<endl,0;
}

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

using namespace std;

typedef long long ll;

int main(){
int N; cin >> N;
 multiset<int> M;
  for(int i = 0; i < N; i++){
    int a; cin >> a;
    auto c = M.lower_bound(a);
    if( c != M.begin()){ c--;
      M.erase(c); } M.insert(a);
}

cout << (int)M.size() << endl; return 0;}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std; 
  
int main(){
	int aux,sum,j,k,i;
	int ar[5];
	int* max;

	scanf("%d%d%d%d",&ar[0],&ar[1],&ar[2],&k);

	max=max_element(ar,ar+3);

	sum=*max<<k;

	j=max-ar;

	for(i=0;i<3;i++)
		if(i!=j)
			sum+=ar[i];

	printf("%d\n",sum);

	return 0;

}

Measured memory_bytes: 384
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;
const int INF = 1000100100;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int mod = 1000000007;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
  // 構造体の変数は public 変数であるためアクセス可能
  ll x; // typedef long long ll;

  // コンストラクタ
  mint(ll x=0):x((x%mod+mod)%mod){}

  // 単項演算子：符号やインクリメントなどを表すものなど
  // -（マイナス）演算子との区別は引数によって行う
  mint operator-() const { return mint(-x);}

  // 複合代入演算子のオーバーロード
  // *1 戻り値の型は必ず自分自身のクラスで参照を返す
  // *2 return文には「*this」を指定する
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }

  // 算術演算子のオーバーロード
  // 引数の型に & をつけることで参照を利用して受け取ることができる（コピーする必要がないため処理が高速化される）
  mint operator+(const mint a) const {  // メンバ変数の書き換えを防ぐために引数定義のあとに const をつけている
    mint res(*this);    // コピーコンストラクタ（コンパイラが自動で生成）
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // 素数の逆元計算にのみ有効
  mint inv() const { return pow(mod-2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

const int MAX = 1000100;
mint fac[MAX], finv[MAX], inv[MAX];
// 先にこれを行うことで O(1) で nCk を求められる
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i=2; i<MAX; i++){
        fac[i] = fac[i-1]*i;
        finv[i] = finv[i-1]/i;
    }
}

mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n-k];
    // cout << COM(n,k).x << endl;
}

int main()
{
    int n; cin >> n;
    mint res = mint(10).pow(n) - mint(9).pow(n) - mint(9).pow(n) + mint(8).pow(n);
    cout << res.x << endl;
}

Measured memory_bytes: 27044
import sys
sys.setrecursionlimit(10**7)
n,k = map(int,input().split())
li = [[] for _ in range(n+1)]
mod = 10**9+7
ans = k
perm = [1]*(n)# 組み合わせ(k-2)P(要素)

for i in range(n-1):
    a,b = map(int,input().split())
    li[a].append(b)
    li[b].append(a)
    perm[i+1] = (perm[i]*(k-2-i))%mod

def dfs(now,before):
    point = 1
    if now == 1:
        ret = 1
        ko = len(li[1])
        for i in range(ko):
            ret *= k-1-i
            ret %= mod
    else:
        ko = len(li[now])-1
        ret= perm[ko]%mod
    
    for i in li[now]:
        if i==before:
            continue
        ret = ret*dfs(i,now)%mod
    return ret

ans *= dfs(1,0)

print(ans%mod)

Measured memory_bytes: 88144
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;
typedef vector<vi> vvi;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000

void solve() {
    ll n;
    cin >> n;
    ll t = 0;
    for (ll i = 1 ; i <= n ; i++) {
        t += (i*(i+1))/2;
    }
    
    rep(i, n - 1) {
        ll a, b;
        cin >> a >> b;
        if (a > b) {
            swap(a, b);
        }
        t -= a * (n - b + 1);
    }
    cout << t << endl;
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

int main() {
    //querySolve();
    solve();

}


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

// one-based numbering
struct UnionFind {
    vector<int> data;
    // i: (data[i] < 0) -> group size, (data[i] > 0) -> parent;
    UnionFind(int n) {
        data.resize(n+1, -1);
    }
    int find(int x) {
        if(data[x] < 0) return x;
        else return data[x] = find(data[x]);
    }
    int size(int x) {
        return -data[find(x)];
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<int> v[m];
    for (int i = 0; i < n; i++) {
        int k; cin >> k;
        while (k--) {
            int l; cin >> l;
            v[--l].emplace_back(i+1);
        }
    }
    UnionFind uf(n+1);
    for (int i = 0; i < m; i++) {
        for (auto &p: v[i]) {
            uf.unite(p, v[i].front());
        }
    }
    if (uf.size(1) == n) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}

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

#define mp make_pair
#define pb push_back
#define f first
#define s second 
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define forn(i, x, y) for(int i = x; i <= y; i++)
#define forev(i, y, x) for(int i = y; i >= x; i--)

using namespace std;

const int maxn = (int)3e5 + 100;
const int mod = (int)1e9 + 7;
const int P = (int)1e6 + 7;
const int inf = (int)1e9 + 7;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef long double ld;

int n, m, used[maxn], deg[maxn];
vi g[maxn];
map<pii, int> was;
void dfs(int v, int p){
  used[v] = 1;
  for(auto to : g[v]){
    if(to != p){
      if(!used[to])
        dfs(to, v);
      else{
        if(was[mp(v, to)]) continue;
        was[mp(v, to)] = was[mp(to, v)] = 1;
        cout << v << " " << to << endl;
        deg[v] ^= 1;
      }
    }
  }
  if(p == -1){
    assert(!deg[v]);
    exit(0);
  }
  if(deg[v])
    deg[v] ^= 1, cout << v << " " << p << endl;
  else
    deg[p] ^= 1, cout << p << " " << v << endl;
}
int main () {
  cin >> n >> m;
  if(m & 1){
    cout << -1;
    return 0;
  }
  forn(i, 1, m){
    int u, v;
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(1, -1);
}

Measured memory_bytes: 27136
#include <bits/stdc++.h>
#define ll long long int
//#define m 1000000007
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp>     //required
// using namespace __gnu_pbds;              //required
// using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// ordered_set<int> s;
// ordered_set<int>::iterator itr;
// /* or:
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// ordered_set s;
// This works in C++98 but the above version only works in C++11
// */
// //char str[10000000];
void swap(ll *xp, ll *yp)
{
    ll temp = *xp;
    *xp = *yp;
    *yp = temp;
}
int main()
{
    ll arr[5];
    ll index;
    for (int i = 0; i < 5; i++)
    {
        cin >> arr[i];
        if (arr[i] == 0)
            index = i + 1;
    }
    cout << index << "\n";
    return 0;
}

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

int main() {
    int n;
    vector<int> s(100);
    cin >> n;
    for(int i=0;i<n;i++) cin >> s[i];
    int c = accumulate(s.begin(), s.end(),0);
    int ans=0;
    if(c%10 != 0) {
        cout << c << endl;
        return 0;
    }
    for(int i=0;i<n;i++) {
        if((c-s[i])%10 == 0) continue;
        ans = max(ans, c-s[i]);
    }
    cout << ans << endl;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    string s;
    cin >> s;
    string ans = "Yes";
    rep(i,s.size()){
        if(s[i]=='-' && i!=a){
            ans="No";
        }
        if(s[a]!='-'){
            ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
from collections import defaultdict
from collections import deque
from collections import Counter
import math
import itertools

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()

zoro = 0

data = [readInts() for i in range(n)]

for d1,d2 in data:
	if d1==d2:
		zoro+=1
	else:
		zoro = 0
	if zoro==3:
		break

if zoro==3:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 9464
#!/usr/bin/env python3
import sys
from collections import deque

def solve(N: int, Q: int, a: "List[int]", b: "List[int]", p: "List[int]", x: "List[int]"):
    matrix = [[] for _ in range(N+1)]
    counter = [0]*(N+1)
    for i in range(N-1):
        matrix[a[i]].append(b[i])
        matrix[b[i]].append(a[i])

    for q in range(Q):
        counter[p[q]]+=x[q]

    queue = deque()
    queue.append(1)

    checkflag = [False]*(N+1)
    while queue:
        root = queue.pop()
        checkflag[root]=True
        for node in matrix[root]:
            if checkflag[node] == False:
                queue.append(node)
                counter[node]+=counter[root]

    print(*counter[1:])




        
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    p = [int()] * (Q)  # type: "List[int]"
    x = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        p[i] = int(next(tokens))
        x[i] = int(next(tokens))
    solve(N, Q, a, b, p, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 74616
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { string a, b, c;
  cin >> a >> b >> c;
  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
    puts("YES");
  }else{
    puts("NO");
  }
}

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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


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

  cout << 6-a-b << endl;

  return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  179_B
//
//  Created by Parsa Alimohammadi on 6/31/1399 AP.
//  Copyright © 1399 Parsa Alimohammadi. All rights reserved.
//

#define ll long long
#define ldu long double
#define pb push_back
#define pop pop_back()
#define du double
// --------------------------------------------------------------
/*
 #define paii pair<int , int>
 #define pasi pair<string,int>
 #define F first
 #define S second
 */
// --------------------------------------------------------------
#define input_txt freopen("input.txt" , "r" , stdin);
#define output_txt freopen("output.txt" , "w" , stdout);
#define Shield  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug cout << "REAlY!! ";
// #define ashar cout << fixed << setprecision(tedad ashaar) << adadet ke bayad double bashe << endl;

#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
// #include<bits/stdc++.h>

using namespace std;

const int maxn = 1e6 * 1 + 2;
int n;
bool ans = false;

int main()
{
    Shield
    cin >> n;
    for (int d1,d2,g=0; n>0; n--)
    {
        cin >> d1 >> d2;
        if(d1==d2)
            g++;
        else
            g =0 ;
        if (g==3)
            ans= true;
    }
    
    ans == true ? cout << "Yes" : cout << "No";
    return 0;
}



Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    
    ll n;
    cin >> n;
    if(n%2 == 0){
        cout << 0.5 << endl;
    }else{
        cout << static_cast<long double>(n/2+1)/n << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define G(x, i) get<i>(x)
#define BITL(x, i) ((x) << (i))
#define BITR(x, i) ((x) >> (i))

using namespace std;

typedef tuple<int, int> i2;
typedef tuple<int, int, int> i3;
typedef tuple<int, int, int, int> i4;
typedef vector<int> vi;
typedef vector<i2> vi2;
typedef vector<i3> vi3;
typedef vector<vi> v2i;
typedef long long ll;
typedef tuple<ll, ll> l2;
typedef tuple<ll, ll> l3;
typedef vector<ll> vl;
typedef vector<l2> vl2;

int main() {
  string s;
  cin >> s;
  int a = 0, b = 0;
  for (char c : s)
    if (c == 'A')
      ++a;
    else
      ++b;
  if (a && b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int main() {
	int g;
	int num[]={1,2,4,8,16,32,64,128,256,512};
	stack<int> ans;
	while(cin>>g){
		for(int i=9;i>=0;i--){
			if(g>=num[i]){
				g-=num[i];
				ans.push(num[i]);
			}
		}for(int i=ans.size();i>0;i--){
			cout<<ans.top();
			ans.pop();
			if(i!=1)cout<<" ";
		}cout<<endl;
	}
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  int n;
  cin >> n;
  vector<LL> value(1<<18), weight(1<<18);
  FOR(i,1,n+1) cin >> value[i] >> weight[i];
  vector<vector<pair<LL, LL>>> hanzen(1<<11); // weight, value
  hanzen[0].emplace_back(0,0);
  FOR(bits,1,1<<11) {
    for(pair<LL,LL> p:hanzen[bits/2]) {
      pair<LL,LL> added = make_pair(p.first+weight[bits], p.second+value[bits]);
      hanzen[bits].push_back(p);
      hanzen[bits].push_back(added);
    }
    vector<pair<LL,LL>> tmp(hanzen[bits].begin(),hanzen[bits].end());
    sort(tmp.begin(),tmp.end());
    hanzen[bits].clear();
    hanzen[bits].emplace_back(0,0);
    for(pair<LL,LL> p:tmp) {
      if(hanzen[bits].back().second < p.second) hanzen[bits].push_back(p);
    }
  }
  int q;
  cin >> q;
  while(q--) {
    LL v, l;
    cin >> v >> l;
    vector<pair<LL,LL>> comb;
    comb.emplace_back(0,0);
    while(v>=(1<<11)) {
      vector<pair<LL,LL>> tmp(comb.begin(), comb.end());
      for(pair<LL,LL> p:tmp) {
        pair<LL,LL> added = make_pair(p.first+weight[v], p.second+value[v]);
        comb.push_back(added);
      }
      v/=2;
    }
    LL answer = 0;
    for(pair<LL,LL> p: comb) {
      LL cw,cv;
      tie(cw,cv) = p;
      if(cw>l) continue;
      auto ite = lower_bound(hanzen[v].begin(),hanzen[v].end(), make_pair(l-cw+1,0ll));
      --ite;
      answer=max(answer, cv+ite->second);
    }
    cout << answer << endl;
  }

  return 0;
}


Measured memory_bytes: 51104
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
B=[A[i] for i in range(N)]
cnt=0

for i in range(N):
    if A[i]<0:
        cnt+=1
        B[i]=-B[i]

if cnt%2==0:
    ans=sum(B)
else:
    ans=sum(B)-2*min(B)

print(ans)



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

int cal(int a,int b,int c,int d,int i1,int i2,int i3){
  int ans=0;
  if(i1==0)ans=a+b;
  else ans=a-b;
  if(i2==0)ans+=c;
  else ans-=c;
  if(i3==0)ans+=d;
  else ans-=d;
  return ans;
}

int main(){
  int s;
  int num[4]={};
  int flag=0;
  cin >> s;


  for (int i = 3; i >= 0; i--) {
    num[i]=s%10;
    s/=10;
  }

  int i[3];
  for (i[0] = 0; i[0] <= 1; i[0]++) {
    for (i[1] = 0; i[1] <= 1; i[1]++) {
      for (i[2] = 0; i[2] <= 1; i[2]++) {
        if(cal(num[0],num[1],num[2],num[3],i[0],i[1],i[2])==7){flag=1;break;}
      }
      if(flag==1)break;
    }
    if(flag==1)break;
  }

  for (int i2 = 0; i2 < 4; i2++) {
    std::cout << num[i2];
    if(i2!=3){
      if(i[i2]==0)std::cout << "+";
      else std::cout << "-";
    }
  }
  std::cout << "=7" << '\n';

return 0;
}


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

#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
const ll INF = 1LL << 60;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
};
ll modpow(ll m, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        ll t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void printInBase(int x, int y) {
    if (x < y) {
        cout << x;
        return;
    }
    int rem = x % y;
    printInBase(x / y, y);
    cout << rem;
}
map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}

int main() {
    int n;
    cin >> n;
    cout << n << ":";
    primeFactors(n);
    for (auto x : cnt) {
        REP(i, x.second) { cout << " " << x.first; }
    }
    cout << endl;
}


Measured memory_bytes: 3092
h,w = map(int, input().split())
s = [input() for i in range(h)]

visited = [[0]*w for i in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        black = 0
        white = 0
        stack = [[i,j]]
        while stack:
            a,b = stack.pop()
            if visited[a][b]!=1:
                visited[a][b]+=1
                if s[a][b]=='#':
                    black+=1
                else:
                    white+=1
                for x,y in [[1,0],[-1,0],[0,1],[0,-1]]:
                    c = a+y
                    d = b+x
                    if 0<=c<h and 0<=d<w:
                        if s[a][b]!=s[c][d]:
                            stack.append([c,d])
        ans += black*white
print(ans)




Measured memory_bytes: 105180
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
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; }
using namespace std;

//ABC135
signed main(void){

    int a, b; cin >> a >>b;
    if((b-a)%2==0)cout << (a+b)/2 << endl;
    else cout << "IMPOSSIBLE" << endl;

}

Measured memory_bytes: 764
import sys

class BIT:
    #1-indexed
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.p = 2**(n.bit_length() - 1)
        self.dep = n.bit_length()
    
    def get(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
    
    def bl(self, v):
        if v <= 0:
            return -1
        s = 0
        k = self.p
        for _ in range(self.dep):
            if s + k <= self.size and self.tree[s+k] < v:
                s += k
                v -= self.tree[s+k]
            k //= 2
        return s + 1

def compress(L):
    L2 = list(set(L))
    L2.sort()
    C = {v : k for k, v in enumerate(L2, 1)}
    return L2, C

N = int(input())
mod = 998244353
ans = N*pow(2, N-1, mod)%mod

points = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
points.sort()
_, PY = map(list, zip(*points))
_, Ci = compress(PY)
PY = [Ci[p] for p in PY]
T1 = BIT(N)
T2 = BIT(N)

for i in range(1, N+1):
    T2.add(i, 1)

for i in range(N):
    y = PY[i]
    c = T1.get(y)
    d = T2.get(y)-1 - c
    a = i - c
    b = N-1 - a - c - d
    T1.add(y, 1)
    a2 = pow(2, a, mod)
    b2 = pow(2, b, mod)
    c2 = pow(2, c, mod)
    d2 = pow(2, d, mod)
    ans += (a2-1)*b2*c2*(d2-1) + a2*(b2-1)*(c2-1)*d2 - (a2-1)*(b2-1)*(c2-1)*(d2-1)
    ans %= mod
print(ans)

Measured memory_bytes: 120828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+30;
const ll inf=1e18;
ll ans,a[maxn],s,sum[maxn];
int n;
int main(){
    cin >> n;
    for (int i=0;i<=n;i++) cin >> a[i];
    for (int i=n;i>=0;i--) sum[i]=sum[i+1]+a[i];
    s=1;
    for (int i=0;i<=n;i++){
        ans+=min(sum[i],s);
        s-=a[i];
        if (s<0){puts("-1");return 0;}
        s=min(s*2,inf);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5164
#include <bits/stdc++.h>
	using namespace std;
	#define IOS ios::sync_with_stdio(false), cin.tie(0)
	#define REP(i, n) for (int i = 0; i < n; i++)
	#define FOR(i, a, b) for (int i = a; i < b; i++)
	#define ALL(x) (x).begin(), (x).end()
	#define dump(x) cout << (x) << endl
	#define LMAX 9223372036854775807LL
	#define LMIN -9223372036854775807LL

	using ll = long long;
	template<typename T>
	using vec = vector<T>;
	using P = pair<ll, ll>;

	template <typename A, size_t N, typename T>
	void Fill(A (&array)[N], const T &val)
	{
		fill((T *)array, (T *)(array + N), val);
	}

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

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

	int main(){
		IOS;
		int n,m;
		cin >> n >> m;
		vec<vec<P>> p(n + 1);
		vector<string> ans(m);
		REP(i,m){
			int a,b;
			cin >> a >> b;
			p[a].push_back(P(b,i));
			ans[i] = to_string(a);
			while(ans[i].size() < 6)ans[i] = "0" + ans[i];
		}
		REP(i,n + 1){
			if(p[i].empty())continue;
			sort(ALL(p[i]));
			REP(j,p[i].size()){
				string tmp = to_string(j + 1);
				while(tmp.size() < 6){
					tmp = "0" + tmp;
				}
				ans[p[i][j].second] = ans[p[i][j].second] + tmp;
			}
		}
		REP(i,m)dump(ans[i]);
	}

Measured memory_bytes: 12416
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<cstdlib>
#include<algorithm>

using namespace std;

long long knapsack(int N,vector<pair<int,int> > v){
  vector<long long> dp(N+1);
  for(auto e:v){
    for(int i=e.first;i<dp.size();i++){
      dp[i]=max(dp[i],dp[i-e.first]+e.second);
    }
  }
  return dp.back();
}

int main(){
  int N,M,W,T;
  cin>>N>>M>>W>>T;
  map<string,int> V,P;
  for(int i=0;i<M;i++){
    string S;
    int v,p;
    cin>>S>>v>>p;
    V[S]=v;
    P[S]=p;
  }
  int L[7],X[7],Y[7];
  map<string,int> Q[7];
  for(int i=0;i<N;i++){
    cin>>L[i]>>X[i]>>Y[i];
    for(int j=0;j<L[i];j++){
      string R;
      int q;
      cin>>R>>q;
      Q[i][R]=q;
    }
  }
  vector<pair<int,int> > r;
  for(int i=1;i<1<<N;i++){
    vector<int> v;
    vector<pair<int,int> > vi;
    for(int j=0;j<N;j++){
      if(i>>j&1){
	v.push_back(j);
	for(auto e:Q[j]){
	  if(e.second<P[e.first]){
	    vi.emplace_back(V[e.first],P[e.first]-e.second);
	  }
	}
      }
    }
    int m=1<<29;
    do{
      int s=0;
      int x=0,y=0;
      for(auto e:v){
	s+=abs(X[e]-x)+abs(Y[e]-y);
	x=X[e];
	y=Y[e];
      }
      m=min(m,s+abs(x)+abs(y));
    }while(next_permutation(begin(v),end(v)));
    r.emplace_back(m,knapsack(W,vi));
  }
  cout<<knapsack(T,r)<<endl;
}

Measured memory_bytes: 1324