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

using namespace std;

#define int long long
// #define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()

template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<bool> VB;
typedef vector<double> VD;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 5e18;
// const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793238

signed main() {
    LCIN(N, M);
    VL A(N);
    PQ<ll> now;
    REP(i, N) { now.emplace(IN()); }
    while(M) {
        ll t = now.top();
        now.pop();
        now.emplace(t / 2);
        M--;
    }
    ll ans = 0;
    while(now.size()) {
        ans += now.top();
        now.pop();
    }
    cout << ans << "\n";
}


Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

struct Guy{
	int sc;
	int L;
	bool ok;
};

typedef long long ll;
int n;
Guy guys[101];

ll dp[2][1<<17];

int main(){
	while(cin>>n&&n!=0){
		for(int i=0;i<n;i++){
			int m;
			cin>>m>>guys[i].L;
			guys[i].sc=0;
			guys[i].ok=true;
			for(int j=0;j<m;j++){
				int s,e;
				cin>>s>>e;
				s-=6;
				e-=6;
				for(int k=s;k<e;k++){
					if(!((guys[i].sc>>k)&1))guys[i].sc|=(1<<k);
					else guys[i].ok=false;
				}
			}
		}
		for(int i=0;i<2;i++)for(int j=0;j<(1<<17);j++)dp[i][j]=0;
		for(int i=n-1;i>=0;i--){
			int cur=(i+1)%2;
			int nxt=(i)%2;
			for(int j=0;j<(1<<17);j++)dp[nxt][j]=0;
			for(int j=0;j<(1<<17);j++){
				dp[nxt][j]=dp[cur][j];
				if(guys[i].ok)if(!(j&guys[i].sc))dp[nxt][j]=max(dp[nxt][j],dp[cur][j|guys[i].sc]+guys[i].L);
			}
		}
		ll res=dp[0][0];
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 2916
// Problem : C - Lower
// Contest : AtCoder Beginner Contest 139
// URL : https://atcoder.jp/contests/abc139/tasks/abc139_c
// Memory Limit : 1024,000000 MB 
// Time Limit : 2000,000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cout.precision(16);
  cout << fixed;
  
  int n;
  cin >> n;
  
  vector<int> a(n);
  for (auto&& i : a)
    cin >> i;
    
  int cur = 1;
  int ans = 1;
  
  for (int i = 1; i < n; ++i) {
    if (a[i - 1] >= a[i]) {
      ++cur;
    } else {
      cur = 1;
    }
    
    ans = max(ans, cur);
  }
  
  cout << ans - 1;
}


Measured memory_bytes: 640
from functools import lru_cache


N, X = [int(elem) for elem in input().split()]


h_burger = [None] * (N + 1)
h_burger[0] = 1
for i in range(1, N + 1):
    h_burger[i] = 3 + 2 * h_burger[i - 1]

@lru_cache(None)
def num_patties(l, x):
    if x == 0:
        return 0
    elif l == 0:
        return 1
    else:
        if x <= h_burger[l - 1] + 1:
            return num_patties(l - 1, x - 1)
        elif x == h_burger[l - 1] + 2:
            return num_patties(l - 1, h_burger[l - 1]) + 1
        else:
            return num_patties(l - 1, h_burger[l - 1]) + 1 \
                 + num_patties(l - 1, x - h_burger[l - 1] - 2)


print(num_patties(N, X))


Measured memory_bytes: 3940
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順

signed main(){
  int ans[600000];
  string s;
  cin >> s;
  int now = 0;
  while(s[now]=='L') now ++;
  ans[0]= now;
  int kkk = 0;
  int now2 = now;
  int now3;
  while(now2<s.size()&&kkk==0){
    now2 = now;
    while(s[now2]=='R'){
      now2 ++;
      if(now2==s.size()){
        kkk = 1;
        break;
      }
    }
    now3 = now2;
    while(kkk==0&&s[now3]=='L'){
      now3 ++;
    }
    if(kkk==0){
      ans[now2] = (now2-now)/2 + (now3-now2+1)/2;
      ans[now2-1] =(now2-now+1)/2 + (now3-now2)/2;
    }
    else{
      ans[s.size()-1] = now2-now;
    }
    now = now3;
    now2 = now;
  }
  REP(i,s.size()){
    cout << ans[i] << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int tmpmin=1e9;
int main(int argc,char const* argv[])
{
  string s;
  string t;
  cin >> s >> t;
  for(int i=0;i<s.size();i++)
    {
      s+=s[0];
      s.erase(s.begin());
      if(s==t)
	{
	  cout << "Yes" << endl;
	  return 0;
	}
    }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define P pair<int,int>
#define prique priority_queue
int n,a,b;
int cnt=0,cntb=0;
string s;
signed main(){
    cin>>n>>a>>b>>s;
    int l=s.size();
    rep(i,l){
        if(s[i]=='b')cntb++;
        if(s[i]=='a'&&cnt<a+b){
            puts("Yes");
            cnt++;
        }
        else if(s[i]=='b'&&cnt<a+b&&cntb<=b){
            puts("Yes");
            cnt++;
        }
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

int main(){
    ll N; cin >> N;
    vector<ll> a(N), b(N, 0), c(500000);
    rep(i, N) cin >> a[i];
    rep(i, N) b[i] += a[i] + i;
    rep(i, N) if (b[i] < 500000) c[b[i]]++;
    ll ans = 0;
    rep(i, N){
        if (0 <= -a[i] + i) ans += c[-a[i] + i];
    }
    // debug(a);
    // debug(c);
    pt(ans);
}

Measured memory_bytes: 10368
import java.util.Scanner;


public class Main {


//	final int MOD = 1000000007;

	public static long ans = 0;

	public static void main(String[] args) {

//		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

//		long a = sc.nextLong();

		int n = sc.nextInt();
		int ac = 0;
		int wa = 0;
		int tle = 0;
		int re = 0;

		for(int i = 0; i < n; i++) {
			String string = sc.next();
			if(string.equals("AC")) {
				ac++;
			} else if(string.equals("WA")) {
				wa++;
			} else if(string.equals("TLE")) {
				tle++;
			} else if(string.equals("RE")) {
				re++;
			}
		}


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

		System.out.println("AC x " + ac);
		System.out.println("WA x " + wa);
		System.out.println("TLE x " + tle);
		System.out.println("RE x " + re);


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

//		if(f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

//		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 57792
#include<iostream>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
using namespace std;

int main(void) {
	int count = 0;
	string s;
	cin >> s;
	REP(i, s.size()-1) {
		FOR(t, i + 1, s.size()) {
			if (s[i] == s[t]) {
				count++;
			}
		}
	}
	if (count == 0) {
		cout << "yes" << endl;
	}
	else {
		cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
t,a=list(map(int, input().split()))
h=list(map(int, input().split()))

ans=[]
for i, name in enumerate(h):
    ans.append([i+1, abs((t-name*0.006)-a)])
ans.sort(key=lambda x: x[1])
print(ans[0][0])

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <limits>
#include <bitset>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    int N; cin >> N;
    int K; cin >> K;
    vector<int> A(N);
    
    rep(i, N) {
        cin >> A[i];
    }

    int ans = 0;

    rep(i, N) {
        rep(j, N - i-1) {
            if (A[i] > A[i + j + 1]) ans++;
        }
    }


    ans %= MOD;
    ans = ans * K;
    ans %= MOD;

    int ans2 = 0;

    rep(i, N) {
        rep(j, N) {
            if (A[i] > A[j]) ans2++;
        }
    }

    ans2 %= MOD;
    ans2 = ans2 * ((K * (K - 1) / 2) % MOD);
    ans2 %= MOD;

    ans += ans2;

    ans %= MOD;

    cout << ans << endl;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int r0, w0, c, r;
    while (cin >> r0 >> w0 >> c >> r && r0){
        int ans = (c * w0 - r0 + r - 1) / r;
        cout << max(0, ans) << endl;
    }
    return 0;
}

Measured memory_bytes: 2988
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  int n, cnt;
  double d, x, y;
  cin >> n >> d;
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    if (sqrt(x * x + y * y) <= d) cnt++;
  }
  cout << cnt << endl;
}

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

public class Main {

	int[] p;
	int[] rank;
	
	void submit() {
		int n = nextInt();
		int m = nextInt();
		int[] cost = new int[n];
		for (int i = 0; i < n; i++) {
			cost[i] = nextInt();
		}
		
		p = new int[n];
		rank = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = i;
		}
		
		while (m-- > 0) {
			int v = nextInt();
			int u = nextInt();
			v = get(v);
			u = get(u);
			if (v == u) {
				continue;
			}
			if (rank[v] < rank[u]) {
				int tmp = v;
				v = u;
				u = tmp;
			}
			p[u] = v;
			if (rank[v] == rank[u]) {
				rank[v]++;
			}
		}
		
		Integer[] order = new Integer[n];
		for (int i = 0; i < n; i++) {
			order[i] = i;
		}
		
		Arrays.sort(order, (x, y) -> Integer.compare(cost[x], cost[y]));
		
		HashSet<Integer> comps = new HashSet<>();
		for (int i = 0; i < n; i++) {
			if (get(i) == i) {
				comps.add(i);
			}
		}
		
		if (comps.size() == 1) {
			out.println(0);
			return;
		}
		
		int need = 2 * comps.size() - 2;
		
		long ans = 0;
		
		boolean[] used = new boolean[n];
		
		for (int v : order) {
			if (comps.contains(p[v])) {
				ans += cost[v];
				comps.remove(p[v]);
				used[v] = true;
				need--;
			}
		}
		
		if (need < 0) {
			out.println("Impossible");
			return;
		}
		
		for (int v : order) {
			if (!used[v] && need > 0) {
				ans += cost[v];
				need--;
			}
		}
		
		if (need > 0) {
			out.println("Impossible");
		} else {
			out.println(ans);
		}
	}
	
	int get(int v) {
		return p[v] == v ? v : (p[v] = get(p[v]));
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


Measured memory_bytes: 56516
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
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<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
//桁数のカウント
//pow(x,n) == x^n
//sum = accumulate(v.begin(),v.end(),0);
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}



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

ll h,n,sum;
cin >> h >> n;
vi v(n);
repll(i,n) cin>> v[i];

sum = accumulate(v.begin(),v.end(),0);
if(sum >= h) cout << "Yes" << endl;
else cout << "No" << endl;

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

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

int main(){
    int n;cin>>n;n*=2;
    string s;cin>>s;
    int half=n/2;
    map<pair<string,string>,int> left,right;
    rep(i,1<<half){
        string a,b;
        rep(j,half){
            if(i&(1<<j)){
                a+=s[j];
            }
            else{
                b+=s[j];
            }
        }
        left[make_pair(a,b)]++;
        //cout<<a<<" "<<b<<endl;
    }
    rep(i,1<<half){
        string a,b;
        rep(j,half){
            if(i&(1<<j)){
                a=s[j+half]+a;
            }
            else{
                b=s[j+half]+b;
            }
        }
        right[make_pair(a,b)]++;
        //cout<<a<<" "<<b<<endl;
    }
    ll ans=0;
    for(auto au:left){
        ans+=1ll*au.second*right[au.first];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 103424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define I(x) cin >> x;
#define D(x) cerr << (x) << " ";
#define BR cerr << "\n";
#define P(x) cout << (x) << endl;
#define FIX cout << fixed << setprecision(10);

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
ll A, B, C;

int main(void){
  char c;
  I(c);
  if ('A' <= c && c <= 'Z') c = 'A';
  else c = 'a';

  P(c);

}


Measured memory_bytes: 3628
n=int(raw_input())
a=map(int,raw_input().split())
#b=[abs(a[i]) for i in xrange(n-1)]
s=0
a.sort()
for i in xrange(n-1):
	if a[i]<0:
		if a[i+1]<=0 or (a[i+1]>0 and -a[i]>a[i+1]):
			a[i+1]*=-1
			a[i]*=-1
print sum(a)


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = unordered_set<int32_t>;
using setstr = unordered_set<string>;
using qint = queue<int32_t>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    cout << accumulate(ALL(a), 0) - a.size() << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
int Max(int &a,int b){return a=max(a,b);}
int Min(int &a,int b){return a=min(a,b);}
int n,A,B,stone[N];
 
signed main(){
  cin>>n>>A>>B;
  for(int i=0;i<n;i++) cin>>stone[i];
  sort(stone,stone+n);
 
  int ans = 0;
  if( A == B || stone[n-1]<=min(A,B)) for(int i=0;i<n;i++) ans ^= stone[i]%(A+1);
  else if( A > B ) ans = 1;
  else if(stone[n-1]-A > A || stone[n-2] > A || n == 1) ans = 0;
  else {
    int sum = 0;
    for(int i=0;i<n-1;i++) sum ^= stone[i];
    if(sum == 0) sum = A;
    int x = stone[n-1] - sum;
    ans = sum >= stone[n-1]-A && stone[n-1]-x <= A;
  }
  
  cout<<(ans? "Hanako":"Jiro")<<endl;
  return 0;
}

Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,r,c,i,j,k=0;
    cin>>r>>c;
    int ar[r][c];
    int cn[r*c][4];
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            cin>>ar[i][j];
        }
    }
     for(i=0;i<r;i++)
    {
        for(j=0;j<c-1;j++)
        {
            if(ar[i][j]%2!=0)
            {
                k++;
                ar[i][j+1]=ar[i][j+1]+1;
                ar[i][j]=ar[i][j]-1;
             cn[k-1][0]=i;
              cn[k-1][1]=j;
               cn[k-1][2]=i;
                cn[k-1][3]=j+1;
 
 
            }
        }
    }
    for(j=0;j<c;j++)
    {
        for(i=0;i<r-1;i++)
        {
            if(ar[i][j]%2!=0)
            {
                k++;
                ar[i+1][j]=ar[i+1][j]+1;
                ar[i][j]=ar[i][j]-1;
             cn[k-1][0]=i;
              cn[k-1][1]=j;
               cn[k-1][2]=i+1;
                cn[k-1][3]=j;
 
 
            }
        }
    }
    cout<<k<<endl;
    for(i=0;i<k;i++)
    {
        for(j=0;j<4;j++)
        {
            if(j!=3)cout<<cn[i][j]+1<<" ";
          else
            cout<<cn[i][j]+1<<endl;
        }
        //cout<<endl;
    }
 
 
}

Measured memory_bytes: 6564
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ABC117_A();
		ABC117_B();
	}

	private static void ABC117_A() {
		Scanner scanner = null;
		String numT = "";
		String numX = "";

		try {
			scanner = new Scanner(System.in);
			numT = scanner.next();
			numX = scanner.next();

			BigDecimal result = new BigDecimal(numT).divide(
					new BigDecimal(numX), 6, RoundingMode.HALF_UP);
			System.out.println(result.floatValue());

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private static void ABC117_B() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			int[] wkArray = new int[numN];
			for (int i = 0; i < numN; i++) {
				wkArray[i] = scanner.nextInt();
			}

			Arrays.sort(wkArray);

			int max = 0;
			int others = 0;
			for (int i = numN - 1; i >= 0; i--) {
				if (i == numN - 1) {
					max = wkArray[i];
				} else {
					others += wkArray[i];
				}

			}
			System.out.println(max < others ? "Yes" : "No");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

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

#define int long long int

void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
#define fioe() fileioe()
#else
#define fioe() 1
#endif
//!

int32_t main()
{
	GO
	//fioe();
	int n,m;
	cin>>m>>n;
	int arr[n+2];
	int sum = 0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		sum += arr[i];
	}
	if(sum > m)
		cout<<-1<<endl;
	else
		cout<<m-sum<<endl;

	return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll N;
  cin >> N;
  cout << (N-1)*N/2 << endl;
}

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

int main(){
    int w,a,b;
    cin >> w >> a >> b;
    int ans = 0;
    if(a+w <= b){
        ans = b - (a+w);
    }
    else if (b+w <= a){
        ans = a - (b+w);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld n,i,j,p,k,m;
    string c,s,t,a,b,x,y;cin>>s;i=0;
    n=s.size();
    while(i<n)
    {
        if((n-i)<5)
            break;
        a=s.substr(i,5);
        b=s.substr(i,6);
        c=s.substr(i,7);
        if(b=="eraser")
            {
                i=i+6;
                t=t+b;
            }
            else if(a=="erase")
            {
                i=i+5;
                t=t+a;
            }
        else
        {
               if(a=="dream"&&c=="dreamer")
               {
                x=s.substr(i+5,5);y=s.substr(i+5,6);
                if(x=="erase"||y=="eraser")
                    {
                       i=i+5;
                        t=t+a;
                    }
                else
                    {
                        i=i+7;
                        t=t+c;
                    }
               }
               else if(a=="dream")
               {
                t=t+a;i=i+5;
               }
               else
                break;
        }
        //cout<<t<<" ";
    }
    if(s==t)
        cout<<"YES";
    else
        cout<<"NO";

}

Measured memory_bytes: 904
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
using namespace std;
int input(){
  int x;
  cin>>x;
  return x;
}
int abss(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}
int gcd(int x, int y){
	if(x<y){
    return gcd(y,x);
  }
  if(y==0){
    return x;
  }
  return gcd(y,x%y);
}



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

  



  
  
  

  


}


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

signed main() {
  string N;
  cin >> N;

  int sum = 0;
  for (int i = 0; i < N.size(); i++) {
    sum += (int)(N[i] - '0');
  }

  if (sum % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3680
s = input().split("T")
gx,gy = map(int,input().split())
for i,e in enumerate(s):
    s[i] = len(e)
xs,ys = s[::2],s[1::2]
x = xs.pop(0) if len(xs)>0 else 0
y = 0
xs.sort(reverse=True)
ys.sort(reverse=True)
def c(p,g,lis):
    for e in lis:
        if p <= g:
            p += e
        else:
            p -= e
    return p == g
if c(x,gx,xs) and c(y,gy,ys):
    print("Yes")
else:
    print("No")

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


int main(){
    int r[200000],n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>r[i];
    }
    int maxv=-2000000000;
    int minv=r[0];
    for(int i=1;i<n;i++){
        maxv=max(maxv,r[i]-minv);
        minv=min(minv,r[i]);
    }
    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 3860
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();

    int A = a-x;
    int B = b-x;
    A = Math.abs(A);
    B = Math.abs(B);
      if(A>B){
    System.out.println("B");
      }else{
	System.out.println("A");
      }
}
}


Measured memory_bytes: 35584
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    ll N, T, S, E; cin >> N >> T >> S >> E; S--; E--;
    vector< vector<int> > G(N);
    map< pair<int, int>, ll > pr;
    for(int i=0; i+1<N; i++) {
        int u, v, w; cin >> u >> v >> w;
        u--; v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
        if(u > v) swap(u, v);
        pr[make_pair(u, v)] = w;
    }

    vector<ll> lim(N), anc(N), cnt(N);
    function<void(int, int)> dfs = [&](int cur, int par) {
        if(cur == E) anc[cur] = true;
        for(auto to : G[cur]) {
            if(to == par) continue;
            dfs(to, cur);
            anc[cur] |= anc[to];
        }
    };

    function<bool(int, int)> solve = [&](int cur, int par) {
        vector<int> ch;
        for(auto to : G[cur]) if(to != par) ch.emplace_back(to);
        sort(ch.begin(), ch.end(), [&](int x, int y) {
                if(anc[x]) return false;
                if(anc[y]) return true;

                pair<int, int> px = minmax({cur, x});
                pair<int, int> py = minmax({cur, y});
                ll tx = pr[px] - 1LL * T * (G[x].size() - 1);
                ll ty = pr[py] - 1LL * T * (G[y].size() - 1);
                return tx < ty;
            });

        bool res = true;
        for(auto to : ch) {
            pair<int, int> p = minmax({cur, to});
            ll hp1 = pr[p] - 1LL * T * (cnt[cur] + cnt[to]);
            // fprintf(stderr, "cur = %d, to = %d, hp1 = %lld\n", cur + 1, to + 1, hp1);
            if(hp1 <= 0) return false;
            cnt[to]++;
            res &= solve(to, cur);

            if(anc[to]) continue;
            ll hp2 = pr[p] - 1LL * T * (cnt[cur] + cnt[to]);
            // fprintf(stderr, "cur = %d, to = %d, hp2 = %lld\n", cur + 1, to + 1, hp2);
            if(hp2 <= 0) return false;
            cnt[cur]++;
        }
        return res;
    };

    dfs(S, -1);
    bool ans = solve(S, -1);
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 22076
#include <iostream>                                                                                                                                                          
using namespace std;                                                                                                                                                         
                                                                                                                                                                             
using int64 = long long;                                                                                                                                                     
                                                                                                                                                                             
constexpr int N = 50;                                                                                                                                                        
int64 height[N + 1];                                                                                                                                                         
int64 patty[N + 1];                                                                                                                                                          
                                                                                                                                                                             
void init() {                                                                                                                                                                
  height[0] = 1;                                                                                                                                                             
  patty[0] = 1;                                                                                                                                                              
  for (int64 l = 1; l <= N; ++l) {
    height[l] = 2 * height[l - 1] + 3;
    patty[l] = 2 * patty[l - 1] + 1;
  }
}

int64 solve(int64 n, int64 k) {
  int64 p = 0;
  if (k == height[n])
    return patty[n];

  if (k == 1)
    return 0;
  --k;
  if (k <= height[n - 1])
    return solve(n - 1, k);

  k -= height[n - 1];
  p += patty[n - 1];
  if (k == 1)
    return p + 1;

  --k;
  ++p;
  if (k <= height[n - 1])
    return p + solve(n - 1, k);
  p += patty[n - 1];
      
  return p;              
}                          

int main() {         
  int64 n, k;       
  init();    
  while (cin >> n >> k) {
    cout << solve(n, k) << "\n";
  }   
      
  return 0;              
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    s = input()
    t = input()
    i = -1

    for j in range(len(s) - len(t) + 1):
        if all(a == '?' or a == b for a, b in zip(s[j:], t)):
            i = j
    if i == -1:
        print('UNRESTORABLE')
    else:
        ans = s[:i] + t + s[i+len(t):]
        ans = ans.replace('?', 'a')
        print(ans)
    
if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int scnt[100010], tcnt[100010];
signed main(void)
{
  string s, t;
  cin >> s >> t;
  REP(i, s.size()) scnt[i] = s[i] - 'A' + 1;
  REP(i, t.size()) tcnt[i] = t[i] - 'A' + 1;
  FOR(i, 1, s.size()) scnt[i] += scnt[i-1];
  FOR(i, 1, t.size()) tcnt[i] += tcnt[i-1];
  int q;
  cin >> q;
  REP(i, q) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((scnt[b-1] - scnt[a-2])%3 == (tcnt[d-1] - tcnt[c-2])%3)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 2432
s,t=input(),input()
m,n=len(s),len(t)
c=[[0]*(n+1) for _ in range(m+1)]
fro=[['']*(n+1) for _ in range(m+1)]
for i in range(1,m+1):
    for j in range(1,n+1):
        if s[i-1]==t[j-1]:
            c[i][j]=c[i-1][j-1]+1
            fro[i][j]='upper_left'
        elif c[i-1][j]>=c[i][j-1]:
            c[i][j]=c[i-1][j]
            fro[i][j]='above'
        else:
            c[i][j]=c[i][j-1]
            fro[i][j]='left'
x=''
a,b=m,n
while a>0 and b>0:
    if fro[a][b]=='upper_left':
        x+=s[a-1]
        a-=1;b-=1
    elif fro[a][b]=='above':
        a-=1
    else:
        b-=1
print(x[::-1])

Measured memory_bytes: 175112
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;
#define all(c) c.begin(), c.end()
map<int, vector<pair<int, int>>> g;

void color(int node, int *c)
{
    for (auto itr = g[node].begin(); itr != g[node].end(); ++itr)
    {
        int v = itr->first;
        int l = itr->second;

        if (c[v] != -1)
            continue;
        if (l % 2 == 0)
            c[v] = c[node];
        else
            c[v] = !c[node];

        color(v, c);
    }
}

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

    int n, u, v, w;
    cin >> n;

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

    int c[n + 3];
    for (int i = 1; i <= n; ++i)
        c[i] = -1;
    c[1] = 0;

    color(1, c);

    for (int i = 1; i <= n; ++i)
        cout << c[i] << endl;

    return 0;
}

Measured memory_bytes: 14848
n,k,q = list(map(int,input().split()))
b = [k] * n
for i in range(q):
    a = int(input())
    b[a-1] += 1

for i in range(n):
    ans = b[i] - q
    if(ans <= 0):
        print("No")
    else:
        print("Yes")



Measured memory_bytes: 6596
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector<ll> inp(3);
vector<ll> l;
ll len;

ll dfs(ll i, ll a, ll b, ll c){

  if(i==len){
    if(a!=0 && b!=0 && c!=0) return abs(a-inp[0])+abs(b-inp[1])+abs(c-inp[2]);
    else return INF;
  }

  ll non_result=dfs(i+1,a,b,c);
  ll add10;
  add10=10;
  if(a==0) add10=0;
  ll a_result=dfs(i+1,a+l[i],b,c)+add10;
  add10=10;
  if(b==0) add10=0;
  ll b_result=dfs(i+1,a,b+l[i],c)+add10;
  add10=10;
  if(c==0) add10=0;
  ll c_result=dfs(i+1,a,b,c+l[i])+add10;

  ll _min_l=min( {non_result,a_result,b_result,c_result} );

  return _min_l;

}

int main(void){

  ll n,a,b,c;

  cin>>n>>a>>b>>c;


  inp[0]=a;
  inp[1]=b;
  inp[2]=c;

  len=n;

  rep(i,n){
    ll x;
    cin>>x;
    l.pb(x);
  }

  ll _min_l=dfs(0,0,0,0);

  cout << _min_l << endl;

  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;
struct UnionFind {
    public:
    vector<int> par;
    UnionFind(int n){
        par=vector<int>(n,-1);
    }
    int root(int x){
        if(par[x]<0)return x;
    return par[x]=root(par[x]);
    }
    bool issame(int x,int y){
        return root(x)==root(y);
    }
    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y)return false;
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};

signed main(){
    int N,M;cin>>N>>M;
    vector<pair<int,int>> p(M);
    REP(i,M){
        int a,b;cin>>a>>b;a--;b--;
        p[i]={a,b};
    }
    reverse(all(p));
    UnionFind uf(N);
    vector<int> ans(M);
    REP(i,M)ans[i]=N*(N-1)/2;
    REP(i,M-1){
        if(uf.issame(p[i].first,p[i].second))ans[i+1]=ans[i];
        else{
            int x=uf.size(p[i].first);
            int y=uf.size(p[i].second);
            ans[i+1]=ans[i]-x*y;
            uf.merge(p[i].first,p[i].second);
        }
    }
    reverse(all(ans));
    REP(i,M)cout<<ans[i]<<endl;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    char b;

    cin >> b;

    if(b=='A'){
        cout << 'T';
    }else if(b=='C'){
        cout << 'G';
    }else if(b=='G'){
        cout << 'C';
    }else{
        cout << 'A';
    }

    return 0;
}

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

#define rep(i, x, n) for(int i=(x);i<(n);i++)
#define reps(i, x, n) for(int i=(x);i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;
//八方向を見るのに使うと便利(楽)
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[n + 5];
  reps(i, 1, n){
    cin >> a[i];
  }
  int memo[n + 5];
  memo[n] = a[n];
  for(int i = n - 1;i > 0;i --){
    memo[i] = __gcd(a[i], memo[i + 1]);
  }
  int ans = memo[2], l = a[1];
  reps(i, 2, n - 1){
    //cout << l << " " << memo[i] << '\n';
    ans = max(ans, __gcd(l, memo[i + 1]));
    l = __gcd(l, a[i]);
  }
  cout << max(ans, l) << '\n';
  return 0;
}


Measured memory_bytes: 4408
def solve(n, q, t, u, v):
    parents = list(range(n+1))
    def root(x):
        if x != parents[x]:
            parents[x] = root(parents[x])
        return parents[x]
    res = []
    for i in range(q):
        a = root(u[i])
        b = root(v[i])
        if t[i] == 0:
            if a > b:
                a, b = b, a
            parents[b] = a
        else:
            res.append(int(a == b))
    return "\n".join(map(str, res))
 
n, q = map(int, input().split())
t, u, v = zip(*[map(int, input().split()) for i in range(q)])
print(solve(n, q, t, u, v))

Measured memory_bytes: 112664