akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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<class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    vi dp(101010,INF);
    vi coin(1,1);
    rep(i,30){
        ll t=pow(6,i);
        if(t<=dp.size())coin.pb(t);
        else break;
    }
    rep(i,30){
        ll t=pow(9,i);
        if(t<=dp.size())coin.pb(t);
        else break;
    }
    Sort(coin);
    dp[0]=0;
    for(int i=0;i<dp.size();i++){
        for(int j=0;j<coin.size();j++){
            if(i+coin[j]<dp.size())chmin(dp[i+coin[j]],dp[i]+1);
            else break;
        }
    }
    int n;
    cin>>n;
    fin(dp[n]);
}




Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        loop: while(true){
            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();
            switch(op){
                case "+":
                    System.out.println(a + b);
                    break;
                case "-":
                    System.out.println(a - b);
                    break;
                case "*":
                    System.out.println(a * b);
                    break;
                case "/":
                    System.out.println(a / b);
                    break;
                default:
                    break loop;
            }
        }
    }

}

Measured memory_bytes: 26116
import java.io.*;
import java.util.*;

//solution classes here

public class Main {

    //main solution here

    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int n= sc.nextInt();
        int m=sc.nextInt();
        int[] a = new int[n];
        int sum=0;
        for(int i=0;i<n;i++) {
            a[i] = sc.nextInt();
            sum+=a[i];
        }
        Arrays.sort(a);
        int val=(sum+(4*m-1))/(4*m);
        int count=0;
        for(int i=0;i<n;i++) {
            if(a[i]>=val) {
                count++;
            }
        }

        if(count>=m)
            out.println("Yes");
        else
            out.println("No");




        out.flush();
        out.close();
    }

    //solution functions here


    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

/* *****************************************************************************************************************************
 * I'M NOT IN DANGER, I'M THE DANGER!!!
 * *****************************************************************************************************************************
 */

Measured memory_bytes: 22228
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using Graph = vector<vector<int>>;
using ll = long long;
using p = pair<int, int>;

int main()
{
    int x;
    cin >> x;
    if (x >= 30)
    {

        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3596
k = int(input())
a = [int(i) for i in input().split()]
l = r = 2
for i in reversed(a):
    if (l - 1) // i == r // i:
        print(-1)
        break
    l, r = (l + i - 1) // i * i, r // i * i + i - 1
else:
    print(l, r)


Measured memory_bytes: 14252
def dfs(i,f):
    #print(i,f,check)
    global min
    if i==d:
        if f >= g:
            ans = 0
            for j in range(d):
                if check[j]==1 :
                    ans += p[j]
            if ans<min:
                min=ans
                return
        else:
            l=0
            max=0
            for j in range(d):
                if check[j]==0:
                    l=j
                    max=100*(j+1)
            for j in range(p[l]):
                if j == p[l]-1:
                    return
                sum = f + max*(j+1)
                if sum >= g:
                    ans=0
                    for j1 in range(d):
                        if check[j1]==1 :
                            ans += p[j1]
                    ans += j+1
                    if ans<min:
                        min=ans
                        return
    else:
        check[i]=1
        dfs(i+1,f+s[i])
        check[i]=0
        dfs(i+1,f)

d,g=map(int,input().split())
p=[0]*d
c=[0]*d
s=[0]*d
check=[0]*d
min=1000
for i in range(d):
    p[i],c[i]=map(int,input().split())
    s[i]=100*(i+1)*p[i]+c[i]
dfs(0,0)
print(min)

Measured memory_bytes: 3064
function main()
  
  S = split(chomp(readline()), "")
  T = split(chomp(readline()), "")
  
  ans = 0
  
  for i in 1:3
    
    if S[i] == T[i]
      ans += 1
    end
    
  end
  
  println(ans)
  
end

main()

Measured memory_bytes: 111460
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	int sum = 0;
	int m = n;
	while (m)
	{
		sum += m % 10;
		m /= 10;
	}
	if (n % sum) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()

vvi matmul(vvi a, vvi b){
	int n=a.size();
	auto d=vvi(n,vi(n,0));
	rep(i,n)rep(j,n)rep(k,n) d[i][j]|=a[i][k]&b[k][j];
	return d;
}

vector<vvi> memo(101);
vvi matpow(vvi a,int p){
	if(memo[p].size()==0)
		memo[p]=(p&1)?matmul(matpow(a,p-1),a):matmul(matpow(a,p/2),matpow(a,p/2));
	return memo[p];
}

int main(){
	int n,m,a[3];
	while(cin>>n>>m>>a[0]>>a[1]>>a[2]){
		vvi z(n,vi(n,0)), e=z;
		rep(_,m){
			int p,q; cin>>p>>q;
			e[p-1][q-1]=1;
		}
		fill(all(memo),vvi());
		memo[1]=e;

		vector<vvi> d(3);
		rep(p,3) d[p]=matpow(e,a[p]);
		
		vi g(n,0), ng(n,0);
		g[n-1]=1;
		rep(t,1000){
			bool next=0;
			fill(all(ng),0);
			rep(i,n) if(!g[i]){
				bool ok=1,r;
				rep(p,3) [&]{r=0; rep(j,n) r|=(g[j]&d[p][i][j]); ok&=r;}();
				if(ok) ng[i]=next=1;
			}
			if(!next){
				cout<<"IMPOSSIBLE"<<endl;
				break;
			} else if(ng[0]){
				cout<<t+1<<endl;
				break;
			}
			rep(i,n)g[i]|=ng[i];
		}
	}
	return 0;
}



Measured memory_bytes: 3332
#include <iostream>
using namespace std;
int a, b, c, d;
int main() {
  cin >> a >> b >> c >> d;
  a += b;
  c += d;
  if (a > c) {
    cout << "Left" << endl;
    return 0;
  }
  if (a == c) {
    cout << "Balanced" << endl;
    return 0;
  }
  if (a < c) {
    cout << "Right" << endl;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int cnt[1010];

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    REP(i, 1, N) {
        int num = i;
        int j = 2;
        while(num > 1) {
            while(num % j == 0) {
                num /= j;
                cnt[j]++;
            }
            j++;
        }
    }
    int ans = 1;
    REP(i, 1, 1000) {
        ans = (ans * (cnt[i] + 1)) % mod;
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
    int sum = 0;
    int n;
    cin>>n;
    for(int i =1;i<=n;i++)
    {
        int a,b;
        cin>>a>>b;
        sum += b-a+1;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

ll x, y;

ll solve() {
    ll res = 1;
    while (2*x <= y) {
        res++;
        x *= 2;
    }
    return res;
}

void input() {
    cin >> x >> y;
}

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

    input();
    cout << solve() << endl;
}


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

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

    int N, X;
    cin >> N >> X;
    int cnt = 1, D = 0;  
    for (int i = 0; i < N; i++) {
        int L;
        cin >> L;
        D += L;
        if (D > X) break;
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
#define MAXN 2555
#define INF 0x3f3f3f3f
#define v first
#define b second
using namespace std;
const int N = 1000000;
bool prime[N];
int p[N],tot=0;
void init(){
    for(int i = 2; i < N; i ++) prime[i] = true;
    for(int i = 2; i < N; i++){
        if(prime[i]) p[tot ++] = i;
        for(int j = 0; j < tot && i * p[j] < N; j++){
            prime[i * p[j]] = false;
            if(i % p[j] == 0) break;
        }
    }
}

int main()
{
   init();
   int n;
   while(scanf("%d",&n)==1)
   {
      int sum=0;
      for(int i=0;i<tot;i++)
      {
         if(p[i]<=n)
            sum++;
         else break;
      }
      cout<<sum<<endl;
   }
   return 0;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

  int n = 1;
  for (int i = 0; i < a; ++i) {
    if (n < b)
      n *= 2;
    else
      n += b;
  }

  cout << n << endl;
}


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

a=[]
for i in range(1000000):
  if i==0:
    a.append(s)
  else:
    if a[i-1]%2==0:
      ans=int(a[i-1]/2)
    else:
      ans=int(3*a[i-1]+1)
    a.append(ans)
    
  if a[i] in a[:i-1]:
    print(i+1)
    break
  i=i+1

Measured memory_bytes: 3060
## coding: UTF-8

N = int(input())

AC = 0
WA = 0
TLE = 0
RE = 0

for i in range(N):
    S = input()
    if(S == 'AC'):
        AC += 1
    elif(S == 'WA'):
        WA += 1
    elif(S == 'TLE'):
        TLE += 1
    elif(S == 'RE'):
        RE += 1

print('AC x {}'.format(AC))
print('WA x {}'.format(WA))
print('TLE x {}'.format(TLE))
print('RE x {}'.format(RE))



Measured memory_bytes: 69984
/*
Author- Aasav Badera
Time- Sun Apr 12 17:44:46 2020
*/
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
// -------------------Standard Traversal Moves---------------------
// vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
// vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------

#define ll                 long long    
#define int                long long                        
#define pb                 push_back                                                     
#define mii                map<ll ,ll >
#define rep(i, a, b)       for(ll  i=a;i<b;i++)
#define dbg(args...)       { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define hell               1000000007
// #define hell               (ll)998244353
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define mp                 make_pair
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define inf                1e18L+1
#define endl               '\n' 
#define N                  200005
ll n, m, k, a[N];

bool vis[201][201][201];
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    ll tests = 1;
    // cin >> tests;
    while(tests--)
    {
        cin >> k;
        ll ans = 0;
        rep(i ,1, k+1)
        rep(j ,1, k+1)
        rep(c ,1 ,k+1)vis[i][j][k] = 0;
        rep(i ,1 ,k+1)
        {
        	rep(j , 1, k+1)
        	{
        		rep(l, 1, k+1){
        			if(!vis[i][j][l]){
        				vis[i][j][l] = 1;
        				// dbg(i, j ,l);
        				ans += __gcd(i, __gcd(j ,l));
        			}
        		}
        	}
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 11444
#include "bits/stdc++.h"
using namespace std;

int main() {
	int K,A,B;
	cin >> K >> A >> B;
	//vector<string> S(N);
	int s=0;
  	for(int i=A;i<=B;i++){
		  if(i%K==0){
			  s = 1;
			  break;
		  }
	  }

	  if(s==1){
		cout << "OK" << endl;
	  }
	  else cout << "NG" << endl;
}



Measured memory_bytes: 3624
use io::*;
use std::*;

fn solve(N: i64, A: i64, B: i64) {
    let ans = std::cmp::min(A*N, B);
    println!("{}", ans);
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut N: i64;
    N = scanner.next();
    let mut A: i64;
    A = scanner.next();
    let mut B: i64;
    B = scanner.next();
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(N, A, B)).unwrap().join().unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 8572
n = int(input())
a = [int(i) for i in input().split()]
x = [0]*(n+1)
m = 0
ans = []
for i in reversed(range(1,n+1)):
  tmp = 0
  for j in range(2*i,n+1,i):
    if x[j] == 1:
      tmp += 1
  if tmp % 2 != a[i-1]:
    x[i] = 1
    m += 1
    ans.append(i)
print(m)
for i in ans:
  print(i,end=" ") 
"""
#no ball
if all(i == 0 for i in x):
  print(0)
  exit()
#else
for i in range(1,n+1):
  if x[i] == 1:
    print(i,end=" ")
"""

Measured memory_bytes: 11996
N=int(input())
A=[]
B=[]
for i in range(N):
    a=int(input())
    A.append(a)
    B.append(a)
B.sort()
for i in range(N):
    if A[i]==B[N-1]:
        print(B[N-2])
    else:
        print(B[N-1])

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

//#define DBG

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll N;
vector<ll> A;


int main(){

    cin >> N;
    cin.ignore();
    ll sum = 0;
    for(int i = 0; i < N; i++){
        ll tmp;
        cin >> tmp;
        A.push_back(tmp);
         sum += tmp;
    }
    cin.ignore();

    ll ans = 0;
    for(int i = 0; i < N - 1; i++){
        sum -= A[i];
        ll msum = sum % MOD;
        ans += ((A[i] % MOD) * msum) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;

    #ifdef DBG
    ll naive_ans = 0;
    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            naive_ans += ((A[i] % MOD) * (A[j] % MOD)) % MOD;
            naive_ans %= MOD;
        }
    }
    if(ans == naive_ans) cout << "SUC" << endl;
    else {
        cout << "ERR naive = " << naive_ans << endl;
    }

    cout << 200000LL * 1000000000LL << endl;
    #endif
    return 0;

}

Measured memory_bytes: 5268
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
vector<int>t(200000,1);
vector<vector<int>>pas(200000);
void dfs(int v,int before){
    for(int i=0;i<pas[v].size();i++){
        int u=pas[v][i];
        if(u!=before){
            dfs(u,v);
            t[v]+=t[u];
        }
    }
    return;
}
int main(){
    int n;
    cin>>n;
    int a[n-1],b[n-1];
    for(int i=0;i<n-1;i++){
        cin>>a[i]>>b[i];
        pas[a[i]-1].push_back(b[i]-1);
        pas[b[i]-1].push_back(a[i]-1);
    }
    long long p[n+1];//2pow
    p[0]=1;
    for(int i=1;i<=n;i++)p[i]=(p[i-1]*2)%mod;
    dfs(0,-1);
    long long x=(p[n]-n*p[n-1]-1)%mod+mod,y=p[n];
    for(int i=1;i<n;i++){
        x+=(p[t[i]]-1)*(p[n-t[i]]-1);
        x%=mod;
    }
    while(x%2==0 && y%2==0)x/=2,y/=2;
    long long po=y;
    y=1;
    for(int i=mod-2;i>0;i/=2){
        if(i%2){
            y*=po;
            y%=mod;
        }
        po*=po;
        po%=mod;
    }
    cout<<(x*y)%mod<<endl;
    return 0;
}

Measured memory_bytes: 26908
use proconio::input;

fn main() {
    input! {
        n: usize,
        _: usize,
        mut s: [String; n],
    };
    s.sort();
    let mut ans = String::new();
    for s_i in s.iter() {
        ans += s_i;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <math.h>

int main(void)
{
	int x, h;
	
	while (scanf("%d %d", &x, &h), x && h){
		printf("%f\n", x * x + 2 * x * sqrt((double)x * x / 4 + h * h));
	}
	
	return (0);
}

Measured memory_bytes: 632
#include<cstdio>
#include<algorithm>
#include<utility>
using namespace std;
int main(){
  int n,a[100000],cnt=0;
  pair<int,int> b[100000];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    b[i]=make_pair(a[i],i);
  }
  sort(b,b+n);
  for(int i=0;i<n;i++)
    if(i%2!=b[i].second%2)
      cnt++;
  printf("%d\n",cnt/2);
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define pi acos(-1)
#define el << endl
#define yes cout << "YES" <<  endl
#define no cout << "NO" << endl
#define show(x) cout << x << endl
#define impossible cout<< "impossible" << endl
#define tc int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const ll maxn = 2e5+10;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);


	long double a,b,r;
	cin>>a>>b;


	r = a*b;

	ll x = r;
	show(x);

	return 0;
}
///Alhamdulillah
///Full : by me:)




Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
	if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

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

	ll n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++){
		ll op = n/i;
		ans += i*((op*(op+1))/2);
	}
	cout<<ans;

    return 0;
}


Measured memory_bytes: 3568
/*
Code By RyeCatcher
*/
#include <cstdio>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <cstdlib>
#define ri register int 
#define ll long long 
#define ull unsigned long long 
using namespace std;
template <class T>inline void read(T &x){
    x=0;int ne=0;char c;
    while(!isdigit(c=getchar()))ne=c=='-';
    x=c-48;
    while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
    x=ne?-x:x;return ;
}
const int maxn=1000005;
const int inf=0x7fffff;
int n;
ll a[maxn];
ll sum[maxn],mi=1e18,mx=-1e18,ans=1e18,tmp;
int main(){
    int x,y;
    read(n);
    sum[0]=0;
    for(ri i=1;i<=n;i++)read(a[i]),sum[i]=sum[i-1]+a[i];
    int l=1,r=3;
    for(ri k=2;k<=n-2;k++){
        while((abs((sum[k]-sum[l+1])-(sum[l+1]))<abs(sum[k]-sum[l]-sum[l]))&&l+1<k)l++;
        while((abs((sum[n]-sum[r+1])-(sum[r+1]-sum[k]))<abs((sum[n]-sum[r])-(sum[r]-sum[k])))&&r+1<n)r++;
        mi=1e18,mx=-1e18;
        tmp=sum[k]-sum[l];
		mi=min(mi,tmp),mx=max(mx,tmp);
        tmp=sum[l];
		mi=min(mi,tmp),mx=max(mx,tmp);
        tmp=sum[n]-sum[r];
		mi=min(mi,tmp),mx=max(mx,tmp);
        tmp=sum[r]-sum[k];
		mi=min(mi,tmp),mx=max(mx,tmp);
        ans=min(ans,mx-mi);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 5888
#include "vector"
#include "set"
#include "map"
#include "unordered_set"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define INF2 4611686018427387904
//#define MOD 1000000007
#define MOD 998244353
#define MAX_SIZE 1000000000

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { bool first = true; for (const auto& j: v) { if (!first) { os << " "; } first = false; os <<j; } os << "\n"; return os; }
template<typename T>
istream& operator>>(istream& is, vector<T>& v) { for (auto& elem : v) { is >> elem; } return is; }

vector<ll> f;
void set_f(int n) { f.resize(n+1); f[0] = 1; for (int i=1; i<= n; i++) { f[i] = (f[i-1] * i) % MOD;} }
ll nod(ll a, ll b) { if (b == 0) { return a; } else { return nod(b, a % b); } }
ll pw(ll x, ll n, ll m=MOD) { if (n == 0) { return 1;} if (n%2 == 0) { return pw((x*x) % m, n/2, m); } return (pw(x, n-1, m) * x) % m; }
ll dv(ll a, ll b) { return (a * pw(b, MOD - 2)) % MOD; }
ll c_n_k(int n, int k) { if (k > n) { return 0; } if (k < 0) { return 0; } return dv(dv(f[n], f[k]), f[n-k]); }

void solve() {
    string s;
    cin >> s;
    int n = s.size();

    for (int i=0; i<n; i++) {
        if (s[i] != s[n-1-i]) {
            cout << "No";
            return;
        }
    }

    int m = (n-1) / 2;
    for (int i=0; i<m; i++) {
        if (s[i] != s[m-1-i]) {
            cout << "No";
            return;
        }
    }

    m = (n+3) / 2 - 1;
    for (int i=m; i<n; i++) {
        if (s[i] != s[n-1-(i-m)]) {
            cout << "No";
            return;
        }
    }

    cout << "Yes";
}

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

    if (0) {
        int tests;
        cin >> tests;
        for (int t = 1; t <= tests; t++) {
            //cout << "Case #" << t << ": ";
            solve();
            //cout << "\n";
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}


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

int main() {
	string a[100];
	int b;
	cin >> b;
	for (int i = 0;i < b;i++)
		cin >> a[i];
	int c = 0;
	for (int i = 0;i < b;i++)
		if (a[i] == "Y")
			c = 1;
	if (c == 1)
		cout << "Four"<<endl;
	else cout << "Three" << endl;

	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int h,m,s,S;
    scanf("%d",&S);
    h=S/3600;
    m=S%3600/60;
    s=S%3600%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

const int NILL = -1;

typedef long int lint;

typedef struct node
{
  lint key;
  struct node* parent;
  struct node* left;
  struct node* right;
  
}TREE;

TREE* root = NULL;

void insert(TREE* t)
{
  TREE* x;
  TREE* y;

  y = NULL;
  x = root;

  while(x != NULL)
  {
    y = x;
    if(t->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  
  if(y == NULL) root = t;
  else if(t->key < y->key){
    y->left = t;
  }
  else{
    y->right = t;
  }
}

int find(lint key)
{
  TREE* p = root;
  
  while(p != NULL && p->key != key){
    if(p->key > key){
      p = p->left;
    }
    else{
      p = p->right;
    }
  }
  //p->keyだとsegmentation faultになるので注意
  if(p != NULL) return 1;
  else return 0;
}

void PreOrder(TREE* n)
{
  if(n == NULL) return;
  printf(" %ld",n->key);
  PreOrder(n->left);
  PreOrder(n->right);
}

void InOrder(TREE* n)
{
  if(n == NULL) return;
  InOrder(n->left);
  printf(" %ld",n->key);
  InOrder(n->right);
}

void print()
{
  InOrder(root);
  printf("\n");
  PreOrder(root);
  printf("\n");
}

int main()
{
  int m;
  int i;
  char order[20];
  lint key;
  
  scanf("%d",&m);

  for(i = 0; i < m;i++){
    scanf("%s",order);
    
    if(order[0] == 'i'){
      scanf("%ld", &key);

      //if(i == 0) root = tree;
      TREE* t = (TREE *)malloc(sizeof(TREE));
      t->right = t->left = NULL;

      t->key = key;
      insert(t);
    }
    else if(order[0] == 'f'){
      scanf("%ld",&key);
      
      if(find(key)) printf("yes\n");
      else printf("no\n");
    }
    else if(strcmp(order,"print") == 0){
      print();
    }
  }
  return 0;
}



Measured memory_bytes: 20488
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << endl;
}

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

#define int long long 

bool cmp(pair<int , int > a  , pair<int , int >  b )
{
	if(a.first < b.first) return true ; 
	if(a.first == b.first) 
	{
		if(a.second < b.second ) return true ; 
	}
	return false; 
}




int32_t main() 
{
	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w" , stdout);
	#endif
	

	int t=1;
	//cin >> t;
	while (t-- ) 
	{
		
		int x1 , y1 , x2 , y2 ; 
		cin >> x1 >> y1 >> x2 >> y2 ; 
		int ans = 0 ; 
		int temp1  , temp2 ; 
		// if(y1 > 0 and y2 > 0) ans = y1*y2;
		// else if(y1 < 0 and y2 < 0) ans = x1*x2 ; 
		// else if(y1 > 0 and y2 < 0) ans = y1*y2 ; 
		// if(y1 < 0)
		// {
		// 	if(x2 < 0 and y2 > 0)
		// 		ans =  x1*x2 ;
		// 	else if(x2 > 0)
		// 		ans = y1*x2 ;
				 
		// }

		temp1 = x1*x2 ;
		temp2 = x1*y2 ; 
		int temp3 = y1*y2;
		int temp4 = y1*x2 ;
		temp3 = max(temp3 , temp4);
		temp2 = max(temp1 , temp2);

		cout<<max(temp2 , temp3)<<endl ;
	}

}
	

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

int main(){
	int a,b;
	string op;
	cin >> a >> op >> b;
	while(op != "?") {
		if(op == "+"){
			cout << a+b << endl;
		} else if(op == "-"){
			cout << a-b << endl;
		} else if(op == "*"){
			cout << a*b << endl;
		} else if(op == "/"){
			cout << a/b << endl;
		}
		cin >> a >> op >> b;
	}
	return 0;
}


Measured memory_bytes: 3144
S = input()
ans = 'AC'

if S[0] != 'A':
  ans = 'WA'
if S[2:len(S)-1].count('C') != 1:
  ans = 'WA'

if sum(1 for c in S if c.isupper()) != 2:
  ans = 'WA'
print(ans)

Measured memory_bytes: 2940
#include<iostream>
#define ll long long



using namespace std;

ll dp[3001][3001] ={0};

ll P1(ll arr[],int i, int j)
{
  if(i>j)
    return 0;

  if(dp[i][j] != 0)
    return dp[i][j];

  ll op1 = arr[i] + min( /*arr[i+1] +*/ P1(arr,i+2,j), /*arr[j] +*/ P1(arr,i+1,j-1));
  ll op2 = arr[j] + min(/*arr[i] +*/ P1(arr,i+1,j-1), /*arr[j-1] +*/ P1(arr,i,j-2));

  return dp[i][j] = max(op1,op2);
}

int main()
{
  int n;
  cin>>n;
  ll arr[n];

  ll total_score = 0;

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

  ll final_X = P1(arr,0,n-1);
  ll final_Y = total_score - final_X;

  cout<<final_X - final_Y;
  
  return 0;
}

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

typedef std::pair<int, int> pair;
typedef long long LL;

const int N = 200005, mod = 1000000007;

int n;
pair point[N], interval[N];

int sum[N << 2], tag[N << 2];
void reduce(int &x) { x += x >> 31 & mod; }
void pushup(int x) {reduce(sum[x] = sum[x << 1] + sum[x << 1 | 1] - mod);}
void setmul(int x, int y = 2) {
	sum[x] = (LL) sum[x] * y % mod, tag[x] = (LL) tag[x] * y % mod;
}
void pushdown(int x) {
	if (tag[x] != 1) setmul(x << 1, tag[x]), setmul(x << 1 | 1, tag[x]), tag[x] = 1;
}
void multiply(int R, int o = 1, int l = 0, int r = n) {
	if (R <= l) return setmul(o);
	if (R > r) return;
	int mid = l + r >> 1; pushdown(o);
	multiply(R, o << 1, l, mid), multiply(R, o << 1 | 1, mid + 1, r);
	pushup(o);
}
void modify(int p, int v, int o = 1, int l = 0, int r = n) {
	if (l == r) return reduce(sum[o] += v - mod);
	int mid = l + r >> 1; pushdown(o);
	if (p <= mid) modify(p, v, o << 1, l, mid);
	else modify(p, v, o << 1 | 1, mid + 1, r);
	pushup(o);
}
int query(int L, int R, int o = 1, int l = 0, int r = n) {
	if (L <= l && R >= r) return sum[o];
	int mid = l + r >> 1, ret = 0; pushdown(o);
	if (L <= mid) reduce(ret += query(L, R, o << 1, l, mid) - mod);
	if (R > mid) reduce(ret += query(L, R, o << 1 | 1, mid + 1, r) - mod);
	return ret;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 0; i < n; ++i)
		std::cin >> point[i].second >> point[i].first;
	std::sort(point, point + n);
	static int s[N], top = 0;
	for (int i = 0; i < n; ++i) {
		if (!top || point[s[top - 1]].second < point[i].second) s[top++] = i;
		interval[i].first = *std::lower_bound(s, s + top, i, [&] (int x, int y) {return point[x].second < point[i].second;});
	}
	top = 0;
	for (int i = n - 1; ~i; --i) {
		if (!top || point[s[top - 1]].second > point[i].second) s[top++] = i;
		interval[i].second = *std::lower_bound(s, s + top, i, [&] (int x, int y) {return point[x].second > point[i].second;});
	}
	std::sort(interval, interval + n);
	for (int i = 1; i < n; ++i) assert(interval[i].second >= interval[i - 1].second);
	std::fill(tag, tag + (n + 1 << 2), 1), modify(0, 1);
	for (int i = 0; i < n; ++i) {
		int L, R; std::tie(L, R) = interval[i];
		multiply(R + 1), modify(R + 1, query(L, R));
	}
	std::cout << query(n, n) << '\n';
	return 0;
}

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

using namespace std;
#define int long long
#define x first
#define y second

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

mt19937 rand1(time(0));
int randlr(int l, int r) {
    return rand1() % (r - l + 1) + l;
}

vector<pii> g[100009];
int dist[100009];

const int inf = 1e17;

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

    int n, m;
    cin >> n >> m;

    while (m--) {
        int l, r, c;
        cin >> l >> r >> c;

        g[l - 1].push_back({r - 1, c});
    }

    for (int i = 1; i < n; i ++) {
        g[i].push_back({i - 1, 0});
        dist[i] = inf;
    }

    priority_queue<pii> q;
    q.push({0, 0});
    while (q.size()) {
        auto vp = q.top();
        q.pop();

        if (-vp.x != dist[vp.y]) continue;
        int v = vp.y;

        for (auto u : g[v]) {
            if (dist[u.x] > dist[v] + u.y) {
                dist[u.x] = dist[v] + u.y;
                q.push({-dist[u.x], u.x});
            }
        }
    }

    if (dist[n - 1] == inf) dist[n - 1] = -1;

    cout << dist[n - 1];

    return 0;
}




Measured memory_bytes: 9464
/*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/
#include <bits/stdc++.h>
using namespace std;

const int mx=1e5+5;
char str[mx];
int main ()
{
    int i,n,ans;

    scanf ("%s",str);
    ans=n=strlen(str);
    for (i=1;i<n;i++) {
        if (str[i]!=str[i-1]) ans=min(ans,max(i,n-i));
    }
    printf ("%d\n",ans);

    return 0;
}


Measured memory_bytes: 384
import fractions
a,b,c,d=map(int,input().split())
x=b//c
y=b//d
z=b//(c*d // fractions.gcd(c,d))
xx=(a-1)//c
yy=(a-1)//d
zz=(a-1)//(c*d // fractions.gcd(c,d))
if c==1 or d==1:
    print(0)
elif c==d:
    print(b-x-(a-1-xx))
elif a==b:
    if a%c==0 or a%d==0:
        print(0)
    else:
        print(1)
else:
    print(int(b-x-y+z-(a-1-xx-yy+zz)))

Measured memory_bytes: 5052
/**
 * C - X: Yet Another Die Game
 * https://atcoder.jp/contests/abc053/tasks/arc068_a
 **/
#include<iostream>

#define ll long long

using namespace std;

int main() {
    ll x; cin >> x;
    ll ans = 0;
    ll q = x/11;
    ll r = x%11;
    if(r==0) {
        ans += 2*q;
    } else if(r<7) {
        ans += 2*q+1;
    } else {
        ans = 2*q+2;
    }
    cout << ans << endl;
}

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

#define INF 1<<29

using namespace std;

//全くわからんかった

int main(void) {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int count = 0;
		for (int j = 1; j <= i; j++) {
			if (i % 2 == 0) {
				continue;
			}
			if (i%j == 0) {
				count++;
			}
			if (count == 8) {
				ans++;
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<ll> A;

ll cnt(int x) {
    // 幸福度がx以上上がるような握手が何回できるかを返す
    ll res = 0;
    int z = 0;
    for (ll a : A) {
        // 左手がa
        int remain = x - a;
        int y = A.end() - lower_bound(A.begin(), A.end(), remain);
        res += y;
    }
    return res;
}

int main() {
    // 幸福度を決めてM回以上になるかの二分探索
    ll N, M;
    cin >> N >> M;
    A = vector<ll> (N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    ll ok = 0; ll ng = 1e6;
    while (abs(ng - ok) > 1) {
        ll mid = (ok + ng) / 2;
        if (cnt(mid) >= M) ok = mid;
        else ng = mid;
    }
    ll ans = 0;
    ll x = cnt(ng);
    ans += (M-x) * ok;
    ll total = accumulate(A.begin(), A.end(), 0L);
    vector<ll> cum = A;
    for (int i = 1; i < N; i++) {
        cum[i] += cum[i-1];
    }
    for (ll a : A) {
        ll remain = max((ng - a), 0LL);
        ll y = A.end() - lower_bound(A.begin(), A.end(), remain);
        ans += a * y;
        ans += total - (y != N ? cum[N-y-1] : 0);
    }
    cout << ans << '\n';
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}

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

int main (){
  int ans =0, n, j=0;
  cin >> n;
  for (int i=0; i<n; ++i){
    int x;
    cin >> x;
    for (; x%2 == 0 && x != 0; ++j){
      //cout << x << ' ';
      x /= 2;
    }
    //cout << j << endl;
    if (i==0) ans=j;
    if (ans > j) ans = j;
    j = 0;
  }
  cout << ans << endl;
}

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

#define ll long long int

using namespace std;

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


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

void swap(long long *a,long long *b){
	long long temp = *a;
	*a = *b;
	*b = temp;
}

int partition(long long l,long long h,long long arr[]){
		long long index = l;
		long long temp = arr[h];
		for(long long i=l;i<h;i++){
			if(arr[i]>=temp){
				swap(&arr[index],&arr[i]);
				index++;
		}
	}
		swap(&arr[index],&arr[h]);
		return index;
			}



void quickSort(long long arr[],long long l,long long h){
	
	if(l<h){
		int index = partition(l,h,arr);
		quickSort(arr,l,index-1);
		quickSort(arr,index+1,h);
	}
}

//long long arr[1000000];

int main(){

	long long n; cin>> n;
	vector<int>arr(n);
	
	for(int i=0;i<n;i++)cin >> arr[i];

		sort(arr.begin(),arr.end(),greater<int>());
//for(int i=0;i<n;i++)printf("%lli ",arr[i]);


	long long comfort = arr[0];

	int temp = n-2;
	if(temp%2){
		
		for(int i=1;i<=(temp/2);i++)comfort += 2 * arr[i];
		comfort += arr[(temp/2) + 1];
	}
	else{
		for(int i=1;i<=(temp/2);i++)comfort += 2 * arr[i];
	}

	printf("%lli\n",comfort);




	return 0;
}

Measured memory_bytes: 4032
#include<iostream>
#include<algorithm>
using namespace std;
int N;
int T[15],F[15];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int a;cin>>a;
		for(int j=0;j<a;j++)
		{
			int x,y;cin>>x>>y;
			x--;
			if(y==0)F[i]|=1<<x;
			else T[i]|=1<<x;
		}
	}
	int ans=0;
	for(int i=0;i<1<<N;i++)
	{
		bool ok=true;
		for(int j=0;j<N;j++)
		{
			if(!(i>>j&1))continue;
			if(~i&T[j]||i&F[j])ok=false;
		}
		if(ok)ans=max(ans,__builtin_popcount(i));
	}
	cout<<ans<<endl;
}


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

int main(){
	int n;cin>>n;
	vector<int> p(n);
	int ans=0;
	for(int i=0;i<n;i++){
		cin>>p.at(i);
		if(i>=2){
			if((p.at(i-2)<p.at(i-1) and p.at(i-1)<p.at(i)) or (p.at(i-2)>p.at(i-1) and p.at(i-1)>p.at(i))){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Long a=sc.nextLong();
		Long b=sc.nextLong();
		Long c=sc.nextLong();

		List<Long> l1=new ArrayList<Long>();
		List<Long> l2=new ArrayList<Long>();
		List<Long> l3=new ArrayList<Long>();
		for(int i=0;i<a;i++)
			l1.add(sc.nextLong());
		for(int i=0;i<b;i++)
			l2.add(sc.nextLong());
		for(int i=0;i<c;i++)
			l3.add(sc.nextLong());

		TreeSet<Long> ts1=new TreeSet();
		TreeSet<Long> ts2=new TreeSet();
		ts1.addAll(l1);
		ts2.addAll(l2);
	
		
		solve(ts1,ts2,l3);
	}




	private static void solve(TreeSet<Long> ts1, TreeSet<Long> ts2, List<Long> l3) {
		// TODO Auto-generated method stub
		for(Long i:l3){

			 if (ts1.contains(i)&&ts2.contains(i)){
				System.out.println(0);
			}
			else if(ts1.contains(i)){
				Long a=ts2.lower(i);
				Long b=ts2.higher(i);
				if (a==null)
					System.out.println(Math.abs(b-i));
				if (b==null)
					System.out.println(Math.abs(a-i));
				System.out.println(Math.min(Math.abs(a-i), Math.abs(b-i)));
			}
			else if(ts2.contains(i)){
				Long a=ts1.lower(i);
				Long b=ts1.higher(i);
				if (a==null)
					System.out.println(Math.abs(b-i));
			 if (b==null)
					System.out.println(Math.abs(a-i));
				System.out.println(Math.min(Math.abs(a-i), Math.abs(b-i)));
			}
			Long a=ts1.lower(i);
			Long b=ts1.higher(i);
			Long c=ts2.lower(i);
			Long d=ts2.higher(i);

			if(a==null && c==null){
				System.out.println(Math.max(b, d)-i);
			}
			else if(b==null && d==null){
				System.out.println(i-Math.min(a, c));
			}
			else if(a==null && d==null){
				System.out.println(b-c+Math.min(b-i, i-c));
			}
			else if(b==null && c==null){
				System.out.println(d-a+Math.min(i-a, d-i));
			}
			else if(a==null){
				Long tmp1=Math.max(b, d)-i;
				Long tmp2=b-c+Math.min(b-i, i-c);
				System.out.println(Math.min(tmp1, tmp2));
			}
			else if(b==null){
				Long tmp1=i-Math.min(a, c);
				Long tmp2=d-a+Math.min(i-a, d-i);
				System.out.println(Math.min(tmp1, tmp2));
			}
			else if(c==null){
				Long tmp1=Math.max(b, d)-i;
				Long tmp2=d-a+Math.min(d-i, i-a);
				System.out.println(Math.min(tmp1, tmp2));
			}
			else if(d==null){
				Long tmp1=i-Math.min(a, c);
				Long tmp2=b-c+Math.min(b-i, i-c);
				System.out.println(Math.min(tmp1, tmp2));
			}

			else{
				Long tmp1 = b - c + Math.min(b - i, i - c);
				tmp1=Math.min(tmp1, d-a+Math.min(i-a, d-i));
				tmp1=Math.min(tmp1, i-Math.min(a, c));
				tmp1=Math.min(tmp1, Math.max(b, d)-i);

				System.out.println(tmp1);
			}
	
			
		}
	}




}


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

void solve(int M, int K) {
  if (K >= (1<<M)) {
    cout << -1 << endl;
    return;
  }
  vector<int> res;
  if (K == 0) {
    for (int i=0; i<(1<<M); i++) res.push_back(i);
    for (int i=0; i<(1<<M); i++) res.push_back((1<<M)-i-1);
  } else {
    int a = 0;
    for (int i=0; i< (1<<M); i++) {
      if (i==K) continue;
      res.push_back(i);
      a = a ^ i;
    }
    if (a != K) {
      cout << -1 << endl;
      return;
    }
    res.push_back(K);
    for (int i=0; i < (1<<M); i++) {
      int j = (1<<M)-i-1;
      if (j==K) continue;
      res.push_back(j);
    }
    res.push_back(K);
  }
  for (int i=0; i < 2*(1<<M); i++) {
    cout << res[i] << (i==(2*(1<<M)-1) ? '\n' : ' ');
  }
}

int main() {
  int M, K;
  cin >> M >> K;
  solve(M, K);
}


Measured memory_bytes: 2932
s = input()
n = len(s)
comp = {i+1: True if st == '1' else False for i, st in enumerate(s)}
comp[0] = False

# feasibility check
feasible = True
for i in range(n//2 + 1):
    if i == 1 and not (comp[i] and comp[n-i]):
        feasible = False
        break
    elif comp[i] ^ comp[n-i]:
        feasible = False
        break

if not feasible:
    print(-1)
else:
    edge = []
    parent = n
    for i in reversed(range(1, n)):
        edge.append((i, parent))
        if comp[i]:
            parent = i
    for u, v in edge:
        print(u, v)

Measured memory_bytes: 24252