akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;
double eps = 1e-11;

int main() {
    string S;
    cin >> S;
    int w;
    cin >> w;
    string ans = "";
    for (int i = 0; i < S.size(); i++) {
        if (i % w == 0) {
            ans += S[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
  string b;
  cin >> b;
  string ans = (b == "A") ? "T" : 
               (b == "T") ? "A" :
               (b == "C") ? "G" : "C";
  cout << ans << endl;
  return 0;
}

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

int n;
string s,t,ans;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>s>>t;
    for(int i=0;i<n;i++){
        ans+=s[i];
        ans+=t[i];
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k,ans=0;cin>>n>>k;
  if(k==0) ans+=n*n;
  else {
    for(ll b=k+1;b<=n;++b) {
      ll rem=n%b,div=(n-rem)/b;
      ans+=(b-k)*div;
      if(rem>=k) ans+=rem-k+1;
    }
  }
  print(ans);
  return 0;
}

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

int main()
{
	long long a, b, c, d; scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	long long ans = -1e18-10;
	ans = max(ans, a*c);
	ans = max(ans, a*d);
	ans = max(ans, b*c);
	ans = max(ans, b*d);
	printf("%lld", ans);
}


Measured memory_bytes: 3824
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

inline double add(double a, double b){
    return abs(a+b)<(1e-10)*(abs(a)+abs(b)) ? 0.0 : a+b;
}

struct vec{
    double x,y;
    vec operator-(vec b){
        return (vec){add(x,-b.x),add(y,-b.y)};
    }
    vec operator+(vec b){
        return (vec){add(x,b.x),add(y,b.y)};
    }
    vec operator*(double d){
        return (vec){x*d,y*d};
    }
    double dot(vec v){
        return add(x*v.x,y*v.y);
    }
    double cross(vec v){
        return add(x*v.y,-y*v.x);
    }
    double norm(){
        return sqrt(x*x+y*y);
    }
};

int ccw(vec& a, vec& b, vec& c){
    vec ab = b-a, ac = c-a;
    double o = ab.cross(ac);
    if(o>0) return 1; //CCW
    if(o<0) return -1; //CW
    if(ab.dot(ac)<0){
        return 2; //C-A-B
    }else{
        if(ab.dot(ab)<ac.dot(ac)){
            return -2; //A-B-C
        }else{
            return 0; //A-C-B
        }
    }
}

int isInterSection(vec& p0,vec& p1,vec& p2,vec& p3){//??????p[0]p[1]??¨p[2]p[3]
    switch(ccw(p0,p1,p2)*ccw(p0,p1,p3)){
        case -1:
        case -4:
            break;
        case 0:
            return ~(ccw(p0,p1,p2)|ccw(p0,p1,p3))?2:-1;
        default:
            return 0;
    }
    switch(ccw(p2,p3,p0)*ccw(p2,p3,p1)){
        case -1:
        case -4:
        case 0:
            break;
        default:
            return 0;
    }
    return 1;
}

vec interSection(vec& p0,vec& p1,vec& p2,vec& p3){
    double k = (p3-p2).cross(p2-p0)/(p3-p2).cross(p1-p0);
    return p0+(p1-p0)*k;
}

typedef vector<vec> polygon;

double area(polygon& g){
    double S=0;
    int n=g.size();
    for(int i=0;i<n;i++){
        S+=g[i].cross(g[(i+1)%n]);
    }
    S/=2;
    return S;
}

polygon cut(polygon& G, vec& p1, vec& p2){
    polygon g;
    int n=G.size();
    for(int i=0;i<n;i++){
        if((p2-p1).cross(G[i]-p1)>=0){//????????????????????´???
            g.push_back(G[i]);
        }
        if((p2-p1).cross(G[i]-p1) * (p2-p1).cross(G[(i+1)%n]-p1)<0){
            g.push_back(interSection(p1,p2,G[i],G[(i+1)%n]));
        }
    }
    return g;
}

int main(){
    int n;
    vec v,p1,p2;
    polygon G,g;
    for(cin >> n;n;n--){
        cin >> v.x >> v.y;
        G.push_back(v);
    }
    cout.precision(8);
    cout << fixed;
    for(cin >> n;n;n--){
        cin  >> p1.x >> p1.y >> p2.x >> p2.y;
        g=cut(G,p1,p2);
        cout << area(g) << endl;
    }
    return 0;
}

Measured memory_bytes: 3252
s = input()

t = int(len(s)/2)
ans_left = 'g' * (len(s)-t)
ans_right = 'p' * t
ans = ans_left + ans_right
ret = 0

for i in range(len(s)-t):
    if(s[i:i+1] == 'p'):
        ret -= 1

for i in range(len(s)-t, len(s)):
    if(s[i:i+1] == 'g'):
        ret += 1

print(ret)


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

long long N, M, a[100009][3], maxn = -(1LL << 60);

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
	}
	for (int i = 0; i < 8; i++) {
		vector<long long>vec;
		for (int j = 1; j <= N; j++) {
			long long S = 0;
			for (int k = 0; k < 3; k++) { if ((i / (1 << k)) % 2 == 0) S += a[j][k]; else S -= a[j][k]; }
			vec.push_back(S);
		}
		sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());
		long long ans = 0;
		for (int j = 0; j < M; j++) ans += vec[j];
		maxn = max(maxn, ans);
	}
	cout << maxn << endl;
	return 0;
}



Measured memory_bytes: 3200
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int m = a * b;
        int r = 2 * ( a + b );
        System.out.println( m + " " + r );
    }
}


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

typedef long long int ll;

ll gcd(ll a, ll b){
    if(a == 0) return b;
    return gcd(b%a, a);
}
ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}
ll lcm(vector<int> a){
    ll res = 1;
    for(auto v: a)
        res = lcm(res, v);
    return res;
}

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    
    cout << lcm(a) << endl;
    
    return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<math.h>

using namespace std;

int main(){
	int N;
    vector<int> v;
    cin>>N;
    int t;
    for (int i=0;i<N;i++){
        cin>>t;
        v.push_back(t);
    }

    sort(v.begin(),v.end());
    int cost=0;
    for(int i=0;i<N-1;i++){
        cost+=v[i];
    }
    cost+=(v[N-1]/2);
	cout<<cost<<endl;
	
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

ll f(ll a, ll b) {
  return b == 0 ? a : 2 * ((a - 1) / b) * b + f(b, a % b);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  ll N, X;
  cin >> N >> X;
  cout << f(N - X, X) + N << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main(){
    int i,t1=0,t2=0,t3=0,a[10];
    for (i=0;i<=9;i++)
    {
        scanf("%d",&a[i]);
        if (a[i]>=t1)
        {
            t3=t2;
            t2=t1;
            t1=a[i];
        }
        else if (a[i]>=t2)
        {
            t3=t2;
            t2=a[i];
        }
        else if (a[i]>=t3)
            t3=a[i];
    }
    printf("%d\n",t1);
    printf("%d\n",t2);
    printf("%d\n",t3);
return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)














int main(){
    string s;
    cin >> s;
    ll ans = 0, abc = 0, a = 0, p = 0;
    bool f = true;
    for(ll i = 0; i < s.size(); i++){
        if(f){
            if(s[i] == 'A'){
                a++;
            }
            else if(s[i] == 'B'){
                if(a > 0){
                    f = false;
                    a--;
                    p = 2;
                }
            }
            else{
                a = 0;
            }
        }
        else{
            if(p == 2){
                if(s[i] == 'C'){
                    abc++;
                    p = 0;
                }
                else{
                    if(abc > 0){
                        ans += abc * (abc + 1) / 2;
                        ans += a * abc;
                    }
                    a = 0;
                    if(s[i] == 'A') a = 1;
                    abc = 0;
                    f = true;
                }
            }
            else if(p == 1){
                if(s[i] == 'B'){
                    p = 2;
                }
                else{
                    if(abc > 0){
                        ans += abc * (abc + 1) / 2;
                        ans += a * abc;
                    }
                    if(s[i] == 'A'){
                        a = a + abc + 2;
                    }
                    else{
                        a = 0;
                    }
                    abc = 0;
                    f = true;
                }
            }
            else{
                if(s[i] == 'A'){
                    p = 1;
                }
                else{
                    if(abc > 0){
                        ans += abc * (abc + 1) / 2;
                        ans += a * abc;
                    }
                    if(s[i] == 'B'){
                        p = 2;
                        a = abc - 1 + a;
                    }
                    else{
                        f = true;
                        a = 0;
                    }
                    abc = 0;
                }
            }
        }
        // cerr << i << " " << a << " " << abc << " " << ans << endl;
    }
    if(abc > 0){
        ans += abc * (abc + 1) / 2;
        ans += a * abc;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int check[30];
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		check[s[i]-'a']++;
		if(check[s[i]-'a']>=2){
			cout<<"no"<<endl;
			return 0;
		}
	}
	cout<<"yes"<<endl;
	return 0;
}

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

int main() {
    int a, b, c; cin >> a >> b >> c;
    cout << (c - (a - b) >= 0 ? c - (a - b) : 0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
    int n;
    cin >> n;
    int as = 100;
    int ans = 0;
    while (as < n)
    {
        as += as / 100;
        ans++;
    }
    cout << ans << "\n";
}

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

int main() {
  
  string T;
  cin >> T;
  int P = 0, D = 0, X = 0;
  
  for (int i; i < T.size(); i++) 
  {
    
    if (T.at(i) == '?')
    {
      
      if (i == 0 || T.at(i - 1) == 'D')
      {
        
        if (i == T.size() - 1)
        {
          T.at(i) = 'D';
        }
         else if (T.at(i + 1) == 'D' || T.at(i + 1) == '?')
         {
           T.at(i) = 'P';
         }
         else
         {
           T.at(i) = 'D';
         }
        
      }
      
      else
      {
        T.at(i) = 'D';
      }
      
    }

    
  }
  
  cout << T << endl;
  
}

Measured memory_bytes: 3736
from itertools import accumulate

N,K = map(int, input().split())
As = [] 
for i in range(1,int(N**0.5)+1):
    As.append(i)
    if N//i != i:
        As.append(N//i)
As = sorted(As,reverse=False)
nums = []
for i in range(len(As)-1):
    nums.append(As[i+1]-As[i])
nums = [1] + nums
nums.reverse()
mod = 10**9 + 7
ans = 0
dp = [[0] * len(As) for i in range(K+1)]


dp[0][0] = 1
for i in range(K):
    # 1だと全通り分が成り立つし、Nだと1通り。
    # それぞれ種別にまとまっているので、それらをかける
    acc = list(accumulate(dp[i]))
    for j in range(len(As)):
        dp[i+1][len(As)-j-1] = acc[j]*nums[j]%mod
print(sum(dp[K])%mod)


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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	ll a, b, c, k; cin >> c >> b >> a >> k;
	if (k > b+c){
		cout << c-(k-b-c) << endl;
	}
	else
		cout << c-max(0LL, c-k) << endl;
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


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

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    for(int i = 0; i < n; i++) {
        cin >> x[i];
    }
    auto y = x;
    sort(x.begin(), x.end());
    int med = n/2;
    int ans1 = x[n/2];
    int ans2 = x[n/2 - 1];
    for(int i = 0; i < n; i++) {
        if(abs(ans1 - y[i]) < abs(ans2 - y[i])){
            cout << ans2 << endl;
        }
        else {
            cout << ans1 << endl;
        }
    }

    return 0;
}

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> adj(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  } 
  queue<int> q;
  q.push(0);
  vector<bool> vis(n);
  vector<int> res(n);
  vis[0] = true;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int node : adj[cur]) {
      if (!vis[node]) {
        res[node] = cur + 1;
        vis[node] = true;;
        q.push(node);
      }
    }
  }
  cout << "Yes\n";
  for (int i = 1; i < n; i++)
    cout << res[i] << "\n"[i == n - 1];
  return 0;
}

Measured memory_bytes: 10256
from collections import deque

k = int(input())
q = deque(range(1, 10))
for _ in range(k):
    x = q.popleft()
    r = x % 10
    if r != 0:
        q.append(10*x + (r - 1))
    q.append(10*x+r)
    if r != 9:
        q.append(10*x + (r + 1))
print(x)


Measured memory_bytes: 12404
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

int evalDir(int i, int j, int di, int dj, char c, const vs &v) {
  for (int s = 0;; s++) {
    i += di, j += dj;
    if (i < 0 || j < 0 || i >= 8 || j >= 8 || v[i][j] == '.') return 0;
    if (v[i][j] == c) return s;
  }
}

vi di = {0, 1, 1, 1, 0, -1, -1, -1}, dj = {-1, -1, 0, 1, 1, 1, 0, -1};

int eval(int i, int j, char c, const vs &v) {
  if (v[i][j] != '.') return 0;
  int s = 0;
  rep(k, 8) s += evalDir(i, j, di[k], dj[k], c, v);
  return s;
}

void update(int i, int j, char c, vs &v) {
  v[i][j] = c;
  rep(k, 8) {
    int t = evalDir(i, j, di[k], dj[k], c, v);
    if (t) {
      int ui = i, uj = j;
      while (t--) {
        ui += di[k], uj += dj[k];
        v[ui][uj] = c;
      }
    }
  }
}

void solve() {
  vs v(8);
  rep(i, 8) cin >> v[i];
  for (;;) {
    auto f = [&](char c) {
      int maxi = -INF, ti, tj;
      if (c == 'o') {
        rep(i, 8) rep(j, 8) {
          int e = eval(i, j, c, v);
          if (cmax(maxi, e)) {
            ti = i;
            tj = j;
          }
        }
      } else {
        for (int i = 7; i >= 0; i--) {
          for (int j = 7; j >= 0; j--) {
            int e = eval(i, j, c, v);
            if (cmax(maxi, e)) {
              ti = i;
              tj = j;
            }
          }
        }
      }
      if (maxi > 0) {
        update(ti, tj, c, v);
        return false;
      }
      return true;
    };
    bool a = f('o');
    bool b = f('x');
    if (a && b) break;
  }
  rep(i, 8) cout << v[i] << endl;
}

Measured memory_bytes: 3232
#include <stdio.h>
int main(void){
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a == b){
        printf("%d", c);
    }else if(a == c){
        printf("%d", b);
    }else{
        printf("%d", a);
    }
    
}


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

typedef pair<int, int> ii;

int A[200005];
int B[200005];

int main(){
    int N;
    scanf("%d", &N);

    for(int i = 0; i < N; i ++){
        scanf("%d", &A[i]);
    }

    for(int i = 0; i < N; i ++){
        scanf("%d", &B[i]);
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    for(int i = 0; i < N; i ++){
        pq.push(ii(B[i] + B[(i+2)%N], i));
    }

    long long cnt = 0;
    while(!pq.empty()){
        ii temp = pq.top(); pq.pop();

        int val = temp.first;
        int indx = temp.second;

        if(val != B[indx] + B[(indx+2)%N]){continue;}

        /*printf("Current B: ");
        for(int i = 0; i < N; i ++){
            printf("%d ", B[i]);
        }
        printf("\n");*/

        int sum = (B[(indx+2)%N]+B[indx]);
        int times = (B[(indx+1)%N]-A[(indx+1)%N])/sum;

        if(times == 0){continue;}

        B[(indx+1)%N] -= times*sum;

        cnt += times;

        pq.push(ii(B[(indx+N-1)%N]+B[(indx+1)%N], (indx+N-1)%N));
        pq.push(ii(B[(indx+1)%N]+B[(indx+3)%N], (indx+1)%N));
    }

    for(int i = 0; i < N; i ++){
        if(B[i] != A[i]){
            printf("-1");
            return 0;
        }
    }

    printf("%lld\n", cnt);
}


Measured memory_bytes: 4852
n,k = map(int,input().split())

s=list(input())

border = [0]

for i in range(1,n):
    if s[i-1] != s[i]:
        border.append(i)

border_count = len(border)

ans = 0

for i in range(border_count):
    if s[border[i]] == '0':
        block_1 = i+k*2
    else:
        block_1 = i+k*2+1
    #print(block_1, border)
    if block_1 < border_count:
        ans = max(ans, border[block_1]-border[i])
    else:
        ans = max(ans, n-border[i])
print(ans)


Measured memory_bytes: 83520
a, b = [int(i) for i in input().split()]
ans = ""
for i in range(1,41)[::-1]:
    if a == 0:
        ans += str(((b- b%(2**i))//2 + max(b%(2**i)- 2**(i-1)+ 1,0))%2)
    else:
        ans += str((((b- b%(2**i))//2 + max(b%(2**i)- 2**(i-1)+ 1,0)) - (((a-1)- (a-1)%(2**i))//2 + max((a-1)%(2**i)- 2**(i-1)+1,0)))%2)
print(int(ans,2))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 998244353;
const int INF = 2e18;

signed main() {
    int W, H;
    cin >> W >> H;
    vector<pair<int, bool>> cost;
    for(int i = 0; i < W + H; i++) {
        int temp;
        cin >> temp;
        cost.emplace_back(temp, i >= W);
    }
    sort(cost.begin(), cost.end());
    int h = H + 1, w = W + 1;
    int ans = 0;
    for (auto now : cost) {
        if (now.second) {
            ans += w * now.first;
            h--;
        } else {
            ans += h * now.first;
            w--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
 
typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
 
//const
#define MOD 1000000007 //10^9+7:合同式の法
 
//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
 
void showResult(ll diff_v, ll delta_t, ll diff_x) {
    if (diff_v * delta_t >= diff_x){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return;
}
 
void Main() {
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
 
    ll diff_v = v - w;
    if (diff_v >= 0L) {
        if (b - a > 0L) 
            showResult(diff_v, t, b - a);
        else {
            showResult(diff_v, t, a - b);
        }
    } else {
        cout << "NO" << endl;
    }
}
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
//#define s second
#define MOD (long long)1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define mkt make_tuple
#define nax (int)1e5+1
typedef long long ll;
typedef unsigned long long ull;
class solution{
public:
	void solve(){
		int a,b;
		cin>>a>>b;
		if(a> b){
			int i;
			fo(i,0,a){
				cout<<b;
			}
		}
		else{
			for(int i=0;i<b;i++){
				cout<<a;
			}
		}
	} 
};
 
int main()
{
    fast;
	ll i=0;
	solution s;
	s.solve();
 
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int n,WrongCount;
  string ans;
  
  cin >> n;
  vector<int> a(n);

  //vectorに全入力値を代入する
  rep(i,n) cin >> a[i];

  WrongCount = 0;
  rep(i,n) {
    if (a[i] != i+1) WrongCount++;
  }
  
  if (WrongCount == 0 || WrongCount == 2) {
    ans = "YES";
  }
  else  {
    ans = "NO";
  }
  cout << ans << endl;
}


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

class calc{
  string s;
  string::iterator it;

public:
  calc(const string&str){
    s = str;
    it = s.begin();
  }

  int fact(){
    if(*it == '('){
      ++it;
      int ret = exp();
      ++it;
      return ret;
    }
    else{
      int ret = 0;
      while('0' <= *it && *it <= '9'){
	ret *= 10;
	ret += *it - '0';
	++it;
      }
      return ret;
    }
  }

  int term(){
    int ret = fact();
    while(*it == '*' || *it == '/'){
      if(*it == '*'){
	++it;
	ret *= fact();
      }
      else if(*it == '/'){
	++it;
	ret /= fact();
      }
    }
    return ret;
  }
  
  int exp(){
    int ret = term();

    while(*it == '+' || *it == '-'){
      if(*it == '+'){
	++it;
	ret += term();
      }
      else if(*it == '-'){
	++it;
	ret -= term();
      }
    }
    return ret;
  }
};

int main(){
  string str;
  int n;

  cin >> n;
  while(n--){
    cin >> str;
    calc ans(str);
    cout << ans.exp() << endl;
  }

  return 0;
}

Measured memory_bytes: 1220
#include <cstdio>
typedef long long ll;
int N, A, num;
ll dp[51][2501] = { 1 }, ans = 0;

int main() {
  scanf("%d%d", &N, &A);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &num);
    for (int j = i; j > 0; --j) {
      for (int k = num; k <= 2500; ++k) {
        dp[j][k] += dp[j - 1][k - num];
      }
    }
  }
  for (int i = 1; i <= N; ++i) 
    ans += dp[i][A * i];
  printf("%lld", ans);
}

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


void solve(std::vector<long long> x){
    long long ans = 0;
    for(int i = 0; i < x.size(); ++i){
        if(x[i] != i+1) ans = i+1;
    }
    cout << ans << endl;
    return;
}

int main(){
    std::vector<long long> x(5);
    for(int i = 0 ; i < 5 ; i++){
        scanf("%lld",&x[i]);
    }
    solve(std::move(x));
    return 0;
}


Measured memory_bytes: 3664
#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>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

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

    int ans=0;
    for(int i=0; i<n; i++){
        int c; cin>>c;
        if(v[i] - c > 0) ans += v[i] - c;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

k,n = ip()
if n:
    x = ip()
    x = set(x)
    if k not in x:
        print(k)
    else:
        a = k-1
        while a in x:
            a -= 1
        b = k+1
        while b in x:
            b += 1
        if abs(a-k) < abs(b-k):
            print(a)
        elif abs(b-k) < abs(a-k):
            print(b)
        else:
            print(min(a,b))
else:
    print(k)






Measured memory_bytes: 61832
N,K = list(map(int,input().split()))
x = list(map(int,input().split()))

score = 10**10
for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    if r <= 0:
        score = min(score,-l)
    elif l >= 0:
        score = min(score,r)
    else:
        score = min(score,-2*l+r,-l+2*r)
print(score)

Measured memory_bytes: 14224
n = int(input())
hs = [int(elem) for elem in input().split()]

import numpy as np

diff_lst = np.array([1] + [h - hs[i-1] for i, h in enumerate(hs) if i > 0])
lst = np.where(diff_lst > 0)[0]

res = 0
for i, num in enumerate(lst):
    if i > 0:
        res = max(res, num - lst[i-1] - 1)
    else:
        res = max(res, num - 1)
    if i == len(lst) - 1:
        res = max(res, len(diff_lst) - 1 - num)
print(res)

Measured memory_bytes: 20768
#include <stdio.h>
#include <string.h>

int main()
{
  char str1[15], str2[15], trash1[15];
  int balls1, balls2;

  scanf("%s %s", str1, str2);
  scanf("%d %d", &balls1, &balls2);
  scanf("%s", trash1);

  (strcmp(trash1, str1) == 0) ? balls1-- : balls2--;
  printf("%d %d\n", balls1, balls2);

  return 0;
}

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

int main(){
  int n, m;
  int a, b;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  for (int i = 0; i < n; i++){
    cin >> h[i];
  }

  for (int i = 0; i < m; i++){
    cin >> a >> b;
    a--; b--;
    if (h[a] >= h[b]) ok[b] = false;
    if (h[a] <= h[b]) ok[a] = false;
  }

  int ans = 0;
  for (int i = 0; i < n; i++){
    if (ok[i]) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3688
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a,b=map(str,input().split())
print(int(a*int(b)) if int(a)<=int(b) else int(b*int(a)))

Measured memory_bytes: 77388
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) r.begin(),r.end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-9;
//int mod=1000000007;

int a,b,n;

int f(){
	int s=0; 
	a%=b;
	for(int i=0; i<n; i++){
		a*=10;
		s+=a/b;
		a%=b;
	}
	return s;
}

int main(){
	while(cin>>a>>b>>n){
		cout<<f()<<endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <tuple>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	int ans = max(0,c-a+b);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100;
const ll mod = 1000000007;
int dy[4]={-1,0,1,0},dx[4]={0,-1,0,1};
typedef pair<int,int> P;
#define fi first
#define se second
int main(){
int n,m;
   while(cin>>n>>m){
   if(n==0||m==0)return 0;
   vector<vector<char>> a(n,vector<char>(m));
   for(int i=0;i<n;i++)for(int j=0;j<m;j++)cin>>a.at(i).at(j);
   string s;
   cin>>s;
   P pos={0,0};
   int count=0;
   vector<vector<int>>b(n,vector<int>(m,0));
   for(int i=0;i<s.size();i++){
        vector<vector<int>>b(n,vector<int>(m,0));
       queue<P> q;
       q.push(pos);
       while(!q.empty()){
            P np=q.front();
            q.pop();
            if(a[np.fi][np.se]==s.at(i)){pos=np;break;}
            for(int i=0;i<4;i++){
               int ny=np.fi+dy[i];
               int nx=np.se+dx[i];
               if(ny<0||ny>=n||nx<0||nx>=m)continue;
               if(b[ny][nx]!=0)continue;
               b[ny][nx]=b[np.fi][np.se]+1;
               q.push(P(ny,nx));
         }
       }
       count+=b[pos.fi][pos.se];
   }
   count+=(int)s.size();
   cout<<count<<endl;
   }
}


Measured memory_bytes: 3236
import std.stdio, std.array, std.algorithm, std.conv, core.bitop, std.string;

void main(){
	int h, w;
		for(;scanf("%d%d ", &h, &w), h;){
		auto board = new int[][](h);
		foreach(ref line; board){
			line = array(map!(to!int)(readln.chomp.split));
		}

		auto vert = new int[](w);
		foreach(i; 0..h){
			foreach(j; 0..w){
				vert[j] |= board[i][j]<<i;
			}
		}

		int ans = 0;
		foreach(bit; 0..1<<h){
			ans = max(ans, reduce!((int a, int b){return a + max(popcnt(b^bit), h - popcnt(b^bit));})(0, vert));
		}

		writeln(ans);
	}
}

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

string s;



int main(){

	cin>>s;
	char ss=s[0];
	int cnt=0;
	for(int i=1;i<s.size();i++){
		if(s[i]!=ss){
			ss=s[i];
			cnt++;
		}
	}

	cout<<cnt<<endl;

}

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

def f(N, Z, W, A):
    A.insert(0, W)

    lastA = A[-1]
    sc = abs(lastA - A[-2])
    minOfX = sc
    maxOfY = sc
    scX = sc

    for i in range(N-1, 0, -1):
        sc = abs(lastA - A[i-1])

        scX = max(sc, maxOfY)
        scY = min(sc, minOfX)

        minOfX = min(minOfX, scX)
        maxOfY = max(maxOfY, scY)

    return scX
            

def test():
    assert f(3, 100, 100, [10, 1000, 100]) == 900
    assert f(3, 100, 1000, [10, 100, 100]) == 900
    assert f(5, 1, 1, [1, 1, 1, 1, 1]) == 0
    assert f(1, 1, 1, [1000000000]) == 999999999


def main():
    N,Z,W = map(int, input().split())
    A = list(map(int, input().split()))

    print(f(N,Z,W,A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	vi v(5);
	rep(i,0,5) cin>>v[i];
	int ans=MOD;
	do{
		ll cnt=0;
		int a=0;
		rep(i,0,5){
			a+=v[i];
			if(a%10!=0 && i!=4){
				a+=10-(a%10);
			}
		}
		chmin(ans,a);
	}while(next_permutation(all(v)));
	cout<<ans<<endl;
	
	return 0;
}

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

int a[2001];

int main() {
    a[0] = 1;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 2001; j >= 0; j--) {
            if (a[j] && j + k < 2001) {
                a[j + k] = 1;
            }
        }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int k;
        cin >> k;
        cout << (a[k] ? "yes" : "no") << endl;
    }
}


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

bool include(string s, string p){
    
    long sn = s.length();
    long pn = p.length();
    
    for(long i=0; i<sn; i++){
        bool match = true;
        for(long j=0; j<pn; j++){
            if( s[(i+j)%sn] != p[j] ){
                match = false;
                break;
            }
        }
        if(match){
            return true;
        }
    }
    
    return false;
    
}

int main() {
    
    string s;
    cin >> s;
    
    string p;
    cin >> p;
    
    if( include(s, p) ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
    
}



Measured memory_bytes: 3204
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

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

#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout << (x) << endl
#define watch2(x,y) cout << (x) << " " << (y) << endl
#define watch3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int mod = 1e9 + 7;
const int inf = 1e18;
const int N = 8005;

int i,n;
string s,t;

void solve(){
    cin>>s>>t;
    if(t.substr(0,sz(t)-1)==s)
        cout<<"Yes";
    else
        cout<<"No";
}

signed main(){
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
import java.util.*;
import java.util.Map.Entry;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Longest Increasing Sequence
// 2012/09/22
public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int n;
	long[] a;

	void run(){
		n=sc.nextInt();
		a=new long[n+1];
		for(int i=0; i<n; i++){
			a[i+1]=sc.nextInt();
		}
		a[0]=Long.MIN_VALUE;
		solve();
	}

	@SuppressWarnings("unchecked")
	void solve(){
		TreeMap<Long, Integer>[] dp=new TreeMap[n+1];
		HashMap<Long, Integer>[] cuts=new HashMap[n+1]; // if use TreeMap,
														// you'll receive TLE,
														// HAHAHA!!!
		for(int i=0; i<=n; i++){
			dp[i]=new TreeMap<Long, Integer>();
			cuts[i]=new HashMap<Long, Integer>();
		}
		dp[0].put(Long.MIN_VALUE, 0);

		for(int j=1; j<=n; j++){
			long sum=a[j];
			for(int i=j-1; i>=0; i--){
				// merge (i, j]
				Entry<Long, Integer> entry=dp[i].lowerEntry(sum);
				if(entry!=null){
					int value=cuts[j].containsKey(sum)?dp[j].get(sum):-1;
					if(entry.getValue()+1>value){
						dp[j].put(sum, entry.getValue()+1);
						cuts[j].put(sum, i);
					}
				}
				sum+=a[i];
			}
			// remove unnecessary entry from dp[j]
			int max=-1;
			ArrayList<Long> remove=new ArrayList<Long>();
			for(Entry<Long, Integer> entry : dp[j].entrySet()){
				long key=entry.getKey();
				int value=entry.getValue();
				if(value>max){
					max=value;
				}else{
					// unnecessary entry
					remove.add(key);
				}
			}
			for(long key : remove){
				dp[j].remove(key);
				cuts[j].remove(key);
			}
		}

		// restore "Longest Increasing Sequence"
		LinkedList<Integer> list=new LinkedList<Integer>();
		int cut;
		long sum;
		for(cut=n, sum=Long.MAX_VALUE; cut>=1;){
			list.addFirst(cut);
			sum=dp[cut].lowerKey(sum);
			cut=cuts[cut].get(sum);
		}
		list.removeLast();
		StringBuilder sb=new StringBuilder();
		sb.append(list.size()+1);
		sb.append('\n');
		for(int i : list){
			sb.append(i);
			sb.append(' ');
		}
		if(sb.charAt(sb.length()-1)==' '){
			sb.deleteCharAt(sb.length()-1);
		}
		println(sb.toString());
	}

	class Scanner{
		BufferedReader br;
		StringTokenizer st;

		Scanner(InputStream in){
			br=new BufferedReader(new InputStreamReader(in));
			eat("");
		}

		void eat(String s){
			st=new StringTokenizer(s);
		}

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

		boolean hasNext(){
			while(!st.hasMoreTokens()){
				String s=nextLine();
				if(s==null)
					return false;
				eat(s);
			}
			return true;
		}

		String next(){
			hasNext();
			return st.nextToken();
		}

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

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 80000
N,M = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(M)]

red = set([1])
n_ball = [1]*(N+1)

for x,y in XY:
  n_ball[x] -= 1
  n_ball[y] += 1
  if x in red:
    red.add(y)
    if n_ball[x]==0:
      red.remove(x)
print(len(red))

Measured memory_bytes: 34332
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; k < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

int main() {
  int N,M;
  cin >> N >> M;
  vi connects(M);
  rep(i,M) {
    int k;
    cin >> k;
    rep(j,k) {
      int x;
      cin >> x;
      connects[i] += 1 << (x-1);
    }
  }
  int p = 0;
  rep(i,M) {
    int x;
    cin >> x;
    p += x << i;
  }
  int ans = 0;
  for(int i = 0;i < (1 << N);i++) {
    int t = 0;
    rep(j,M) {
      int x = connects[j] & i;
      rep(k,N) {
        if(x >> k & 1) {
          t ^= 1 << j;
        }
      }
    }
    if(t == p) {
      ans++;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#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;
#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

void solve() {
    lli n, a;
    cin >> a;
    lli ans = a + a * a + a * a * a;
    cout << ans << endl;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

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

const int MN = 200010;

int N, H;
vector<int> adj[MN];
int vis[MN], chk[MN], ideg[MN], odeg[MN];
int x, y;

void dfs(int u) {
    vis[u] = 1;

    //cout << u <<  ' ' << ideg[u] << ' ' << odeg[u] << endl;

    if(N <= u) {
        if((u - N) % 2) {
            if(ideg[u] > odeg[u]) {
                printf("NO");
                exit(0);
            }
            x += odeg[u] - ideg[u];
        }
        else {
            if(odeg[u] > ideg[u]) {
                printf("NO");
                exit(0);
            }
            y += ideg[u] - odeg[u];
        }
    }

    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(!vis[v]) {
            dfs(v);
        }
    }
}

int main() {
    scanf("%d %d", &N, &H);

    for(int i = 0; i < N; i++) {
        int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d);

        chk[i] = 1;
        if(c) {
            adj[N + 2 * c].push_back(i);
            adj[i].push_back(N + 2 * c);
            ideg[i]++;
            odeg[N + 2 * c]++;
            chk[N + 2 * c] = 1;
        }
        else {
            adj[N + 2 * a + 1].push_back(i);
            adj[i].push_back(N + 2 * a + 1);
            ideg[i]++;
            odeg[N + 2 * a + 1]++;
            chk[N + 2 * a + 1] = 1;
        }

        if(d) {
            adj[i].push_back(N + 2 * d + 1);
            adj[N + 2 * d + 1].push_back(i);
            ideg[N + 2 * d + 1]++;
            odeg[i]++;
            chk[N + 2 * d + 1] = 1;
        }
        else {
            adj[i].push_back(N + 2 * b);
            adj[N + 2 * b].push_back(i);
            ideg[N + 2 * b]++;
            odeg[i]++;
            chk[N + 2 * b] = 1;
        }
    }

    for(int i = 0; i < N + 2 * H; i++) if(!vis[i] && chk[i]) {
        x = 0;
        y = 0;
        dfs(i);

        //cout << i << ' ' << x << ' ' << y << endl;

        if(!x || x != y) {
            printf("NO");
            return 0;
        }
    }
    printf("YES");
}


Measured memory_bytes: 11776
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int N, X, m[100];
    scanf("%d%d", &N, &X);
    for (int i = 0; i < N; i++) scanf("%d", &m[i]);

    int rest = X, num = N;
    for (int i = 0; i < N; i++) rest -= m[i]; sort(m, m + N);

    for (int i = 0; i < N; i++) {
        num += rest / m[i]; rest -= rest / m[i] * m[i];
        if (rest < m[i]) break;
    }
    printf("%d\n", num);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string s1,s2;
    cin >> s1 >> s2;
    int A,B;
    cin >> A >> B;
    string U;
    cin >> U;

    if(U == s1)
        cout << A - 1 << " " << B << endl;
    else
    {
        cout << A << " " << B - 1 << endl;
    }
    
    
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
long long M  = 1e9+7;
 
 
signed main(){
    fast;
    int n; cin >> n;
    vector <int> a(n);
    map <int,int> mp;
    int ans = 0;
    for(int i=0 ; i<n ; i++){
    	cin >> a[i];
    	mp[a[i]]++;
    }

  	for(auto x : mp){
  		int t  =x.s;
  		ans += (t*(t-1))/2;
  	}

  	for(int i=0 ; i<n ; i++){
  		int t = ans;
  		int x = mp[a[i]];
  		t -= x*(x-1)/2;
  		x--;
  		t += x*(x-1)/2;
  		cout << t << endl;
  	}
}

Measured memory_bytes: 11136