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

using namespace std;

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

    int len = S.length();
    vector<int> pos;
    vector<int> cnt(len, 0);

    int p = S.find("RL");
    while(p != string::npos){
        pos.push_back(p);
        cnt[p] = 1; cnt[p+1] = 1;
        p = S.find("RL", p + 2);
    }

    int lb, rb;
    int s;
    for(int i=0; i<pos.size(); ++i){
        if(i == 0) lb = 0; else lb = pos[i-1] + 2;
        if(i == pos.size() - 1) rb = len - 1; else rb = pos[i+1] - 1;
        s = 0;
        for(int j=pos[i]-1; j>=lb; --j){
            if(S[j] == 'R'){
                ++s;
                cnt[pos[i]] += (s+1) % 2;
                cnt[pos[i]+1] += s % 2;
            }
            else break;
        }
        s = 0;
        for(int j=pos[i]+2; j<=rb; ++j){
            if(S[j] == 'L'){
                ++s;
                cnt[pos[i]] += s % 2;
                cnt[pos[i]+1] += (s+1) % 2;
            }
            else break;
        }
    }

    for(int i=0; i<len; ++i)
        cout << cnt[i] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 1280
const main = stdin => {
  const input = stdin.trim().split(' ')
  for (let i = 0; i < 5; i++) {
    if (input[i] === '0') {
      console.log(i + 1)
      return
    }
  }
}


// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 29504
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define ll long long
#define inf 20021225
#define mxn 200010
using namespace std;
ll a[mxn];int n;
map<ll,int> mp;
int main()
{
	int ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for(int i=n;i;i--)
	{
		ll j;
		for(j=(1ll<<33);j>a[i];j>>=1ll)
			if(mp[j-a[i]])	break;
		if(j>a[i])	ans++,mp[j-a[i]]--;
		else mp[a[i]]++;
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

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

llong dp[200001];
int pre_index[200001];

vector<int> P;

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> C(n);
    rep(i, n) cin >> C[i];

    int pre;
    vector<int> CC;
    rep(i, n) {
        if (i == 0) {
            CC.push_back(C[i]);
            pre = C[i];
        } else {
            if (C[i] != pre) {
                CC.push_back(C[i]);
                pre = C[i];
            }
        }
    }
    int k = CC.size();

    fill(pre_index, pre_index + 200001, -1);

    P.resize(k);
    rep(i, k) {
        P[i] = pre_index[CC[i] - 1];
        pre_index[CC[i] - 1] = i;
    }
    
    dp[0] = 1;
    for (int i = 0; i < k; ++i) {
        dp[i] += dp[i - 1];
        dp[i] %= mod;
        if (P[i] != -1) {
            dp[i] += dp[P[i]];
            dp[i] %= mod;
        }
    }

    cout << dp[k - 1] << endl;

    return 0;
}

Measured memory_bytes: 5108
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define INF 999999999
using namespace std;
int main() {
  std::string S;
  std::cin >>  S;
  if (S == "ABC") {
    std::cout << "ARC" << '\n';
  }
  else{
    std::cout << "ABC" << '\n';
  }
}


Measured memory_bytes: 3616
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int main(){
  int n, x;
  cin >> n >> x;

  if (n == 2){
    if (x == 2) cout << "Yes\n1 2 3\n";
    else cout << "No\n";
  }
  else {
    rep(i, x - 2, x){
      if (i <= 0) continue;
      if (i + 3 >= n * 2) continue;
      vector<int> a{i, i + 1, i + 2, i + 3};
      do {
        auto md = [&](vector<int> v){ sort(all(v)); return v[1]; };
        int s = md({a[0], a[1], a[2]});
        int t = md({a[1], a[2], a[3]});
        if (s == x && t == x){
          cout << "Yes\n";
          vector<int> b;
          rep(j, 1, i) b.push_back(j);
          rep(j, i + 4, n * 2) b.push_back(j);
          rep(j, n - 2) cout << b[j] << endl;
          rep(j, 4) cout << a[j] << endl;
          rep(j, n - 2, n * 2 - 5) cout << b[j] << endl;
          return 0;
        }
      } while (next_permutation(all(a)));
    }
    cout << "No\n";
  }
}


Measured memory_bytes: 2420
// best coder in the world do not mess with me!!
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i > (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
void generate(int per[],int t)
{
	
	for(int i=t-1;i>0;i--)
	{
		int k=rand()%i;
		swap(per[k],per[i]);
	}
}

    int main()
    {
    	
        int a,y;
    	
        cin>>a>>y;
    	
        vector<long long> x(a);
    	
        for(int i =0;i<a;i++)
    	
        	cin>>x[i];
    	
        sort(x.begin(),x.end());
    	
        int result = max(a-y,0);
    	
        long long result_2 = 0;
    	
        for(int i =0;i<result;i++)
    	
        {
    	
        	result_2+=x[i];
    	
        }
    	
        cout<<result_2<<endl;
    }



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

using namespace std;

using ll = long long;
const ll MOD = 1000000007;

ll power(ll b, int e) {
    ll ans = 1;
    while (e) {
        if (e & 1)
            ans = (ans * b) % MOD;
        e >>= 1;
        b = (b * b) % MOD;
    }
    return ans;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> counts(K + 1);
    ll s = 0;
    for (int i = K; i >= 1; i--) {
        counts[i] = power(K / i, N);
        for (int j = i + i; j <= K; j += i) {
            counts[i] = (counts[i] + MOD - counts[j]) % MOD;
        }
        s = (s + counts[i] * i) % MOD;
    }
    cout << s << endl;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using PLL = pair<ll, ll>;

int main(){
    int n; cin >> n;
    vector<ll> a(n);
    //vector<PLL> v(n);
    map<ll, int> sums, diffs;
    map<ll, int> daburi;
    rep(i,n) {
        cin >> a[i];
        ll sum = i + a[i];
        ll diff = i - a[i];
        sums[sum]++;
        if(sum == diff)daburi[sum]++;
        diffs[diff]++;
    }
    ll ans = 0;
    for(auto s : sums){
        ll val = s.first;
        ll cnt = s.second;
        ll r = diffs[val];
        r -= daburi[val];
        ans += cnt * r;
    }
    cout << ans << endl;
}

Measured memory_bytes: 50656
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = n;
        int sum = 0;
        for(int i=0; i<10; i++){
            sum += m%10;
            m = m/10;
        }
        if(n%sum==0){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23636
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;

int solve(){
    int n,k,x,ans=0;
    priority_queue<int,vector<int> > q;
    scanf("%d %d %d",&n,&k,&x);
    for(int i=0;i<n-1;i++){
        int d;
        scanf("%d",&d);
        int tmp=d;
        d-=x;
        x=tmp;
        ans+=d;
        q.push(d);
    }
    for(int i=0;i<k-1&&!q.empty();i++){
        ans-=q.top();
        q.pop();
    }
    return ans;
}

int main(){
    int t;
    scanf("%d",&t);
    for(int i=0;i<t;i++){
        printf("%d\n",solve());
    }
    return 0;
}

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

const int n=200000; //グラフの最大頂点数
vector<int> g[n];
int cost[n]={};

void flow(int v, int p, int c){
  cost[v]+=c;
  for(int i=0; i<g[v].size(); i++){
    if(g[v][i]==p) continue;
    flow(g[v][i], v, cost[v]);
  }
}

void add_edge(int u, int v){
  g[u].push_back(v);
  g[v].push_back(u);
}

int main()
{
  int N, Q;
  cin >> N >> Q;
  for(int i=0; i<N-1; i++){
    int u, v;
    cin >> u >> v;
    add_edge(u-1, v-1);
  }
  for(int i=0; i<Q; i++){
    int p, x;
    cin >> p >> x;
    cost[p-1]+=x;
  }
  flow(0, -1, 0);
  for(int i=0; i<N; i++){
    cout << cost[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 26624
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;

int n,l,r,a[200001],s[200001],c[400001];

int lowbit(int x){
	return x&(-x);
}

long long query(int x){
	int i;
	long long sum=0;
	for(i=x;i>=1;i-=lowbit(i))
		sum+=c[i];
	return sum;
}

void add(int x){
	for(int i=x;i<=2*(n+1);i+=lowbit(i))
		c[i]++;
}

bool check(int x){
	int i;
	long long sum=0;
	for(i=1;i<=2*(n+1);i++)
		c[i]=0;
	for(i=1;i<=n;i++)
		s[i]=s[i-1]+(a[i]>=x?1:-1);
	for(i=0;i<=n;i++){
		sum+=query(s[i]+n+1);
		add(s[i]+n+1);
	}
	return sum>=1ll*n*(n+1)/4;
}

int main(){
	int mid,i;
	cin >> n;
	for(i=1;i<=n;i++){
		cin >> a[i];
		r=max(r,a[i]);
	}
	while(l<=r){
		mid=(l+r)/2;
		if(check(mid))
			l=mid+1;
		else
			r=mid-1;
	}
	cout << r;
	return 0;
}

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

#define ll long long

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;

    if ((a*b) % 2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;

    return 0;
}



Measured memory_bytes: 256
N, K = map(int, input().strip().split(" "))
R, S, P = map(int, input().strip().split(" "))
T = list(input())

point = {
    "r": P,
    "s": R,
    "p": S
}

score = 0

for i in range(N):

    tmp = i - K
    if 0 <= tmp and T[i] == T[tmp]:
        score += 0
        T[i]=""

    else:
        score+= point[T[i]]
print(score)


Measured memory_bytes: 4084
#include<bits/stdc++.h>//本当は必要なヘッダファイルだけインクルードするべきです
using namespace std;//本当は個別にusingするか変数や関数ごとにstd::をつけるべきです
//本当は関数内に宣言し明示的に初期化するべきです
int N,cnt;
vector<int>A;
void selectionSort(){
  for(int i=0;i<N;i++){
    int min_j=i;
    for(int j=i+1;j<N;j++){
      if(A[j]<A[min_j]){
        min_j=j;
      }
    }
    if(A[i]>A[min_j]){
      swap(A[i],A[min_j]);
      cnt++;
    }
  }
}
int main(void){
  cin>>N;
  A.resize(N);
  for(int i=0;i<N;i++)cin>>A[i];
  selectionSort();
  for(int i=0;i<N;i++)cout<<A[i]<<(i==N-1?'\n':' ');
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3136
N,M = map(int, input().split())
zekken = []
for i in range(N):
    zekken.append(int(input()))
def sousa(zekken,k):
    for i in range(N-1):
        if (zekken[i]%k>zekken[i+1]%k):
            zekken[i],zekken[i+1] = zekken[i+1],zekken[i]
    return zekken
for k in range(1,M+1):
    zekken = sousa(zekken,k)
for i in range(N):
    print(zekken[i])


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "YES" : "NO") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

int main()
{
    int A,B;
    cin >> A >> B;
    if(A%3==0 || B%3==0 || (A+B)%3==0)
    {
        cout <<"Possible";
    }else
    {
        cout <<"Impossible";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;


const int N = (int)5e5 + 9; //constによって、書き換えられなくなる
int lf[N];
int rf[N];

void solve(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    ll n = s.size();

    ll x = 0;
    rep(i, 0, n){
        if(s[i] == '<') x++;
        else x = 0;
        lf[i+1] = x;
    }
    ll y = 0;
    for(int i = n-1; i >= 0; i--){
        if(s[i] == '>') y++;
        else y = 0;
        rf[i] = y;
    }

    ll ans = 0;
    Rep(i, 0, n) ans += max(lf[i], rf[i]);
    
    cout << ans << "\n";
}


int main() {
    solve();
}


Measured memory_bytes: 4764
using System;
public class AtCoder {
    
  static void Main(string[] args) {
  
    var result = false;
    var val = int.Parse(Console.ReadLine());
    if (val == 3 || val == 5 || val == 7) {
      
      result = true;
    }
    Console.WriteLine(result ? "YES" : "NO");
  }
}

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

// author: Seong Yong-ju ( @sei40kr )

#define DEBUG(x) cout << #x << ": " << x << endl

#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); --i)

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i =  (n) - 1; i >= 0; --i)

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

using namespace std;

int main() {
  int n;
  string s1, s2;
  cin >> n >> s1 >> s2;

  bool last_vert = false;
  long ans = 1;
  REP(i, n) {
    char c1 = s1[i], c2 = s2[i];
    bool vert = c1 == c2;

    ans *= i == 0 ? (vert ? 3 : 6) : (last_vert ? 2 : (vert ? 1 : 3));
    ans %= 1000000007;

    if (!vert) {
      ++i;
    }
    last_vert = vert;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long
int main()
{
    SPEED
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int sum = 0;

    int t1 = min(a, k);

    a -= t1;
    k -= t1;

    sum += t1;

    int t2 = min(b, k);
    k -= t2;

    int t3 = min(k, c);

    sum -= t3;

    cout << sum;
    return 0;
}

Measured memory_bytes: 3564
import numpy as np
 
a,b=(int(x) for x in input().split())
sum=0

 
if a>=b:
  sum+=a
  if a-1>=b:
  	sum+=a-1
  else:
    sum+=b
else:
  sum+=b
  if b-1>=a:
  	sum+=b-1
  else:
    sum+=a
    
print(sum)

Measured memory_bytes: 20152
#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;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int,int> mi;
typedef map<ll,ll> mll;
typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> umll;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)
#define fi first
#define se second
#define ins(x,y) insert({x,y}) 
#define pb(x) push_back(x)
#define cnt(x) count(x)

void solve() {

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int tc=1; //cin >> tc;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        int n;
        cin>>n;
        int arr[n];
        for (int i = 0; i < n; i++)
		{
				cin>>arr[i];
		}
		
			
        ll sum=0;
        
        for(int i=1;i<n;i++)
        {
			if(arr[i-1]>arr[i])
			{
				sum+=arr[i-1]-arr[i];
				arr[i]=arr[i-1];
			}
		}
		cout<<sum<<endl;
        solve();
    }
}


Measured memory_bytes: 4424
import math
n, m = map(int, input().split())
ans = int()
if n == m :
	ans = 2
elif abs(n-m) == 1:
	ans = 1
else :
	ans = 0

for i in range(1, n+1):
	ans *= i
	ans %= 1000000007

for i in range(1, m+1):
	ans *= i
	ans %= 1000000007

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

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

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clz(x) - 1;	}


//Variables Declaration


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	int a,b,c;
	cin >> n;
	a=n/100;
	b=(n/10)%10;
	c=n%10;
	if(a==7 || b==7 || c==7)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N);
  REP(i, N) cin >> A[i];
  sort(ALL(A), REV(ll));
  ll ans = A[0];
  FOR(i, 2, N) { ans += A[i / 2]; }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4780
#include <iostream>
#include <string>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

int main(){
	string s;
	cin>>s;
	rep(i,s.length()){
		if((i+1)%2==1){
			if(s[i]=='L'){
				cout << "No";
				return 0;
			}
		}else{
			if(s[i]=='R'){
				cout << "No";
				return 0;
			}
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

LL  memo[100]={0};

LL Lucas(LL );

int main(void){
  int N;
  memo[0]=2;
  memo[1]=1;
  cin>>N;
  cout<<Lucas(N)<<endl;
  return 0;
}

LL Lucas(LL n){
  LL x,y;
  if(n==0) return 2;
  if(n==1) return 1;

  if(memo[n]!=0) return memo[n];
  
  if(n>=2){
    x=Lucas(n-1);
    y=Lucas(n-2);
    memo[n]= x + y;
    //y=Lucas(n-2);
    
    return memo[n];
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, k, ans = 0;
	cin >> n >> k;

	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin >> h.at(i);
		if(h.at(i)>=k)
			ans++;
	}
	cout << ans << endl;
}

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

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

    int m=1000;
    for(int i=0;i<=s.size()-3;i++){
        string sub=s.substr(i,3);
        m=min(abs(atoi(sub.c_str())-753),m);
    }

    cout<<m<<endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define F first
#define S second
#define db(x) cerr << #x << ": " << x << "\n";

int N;
vector<ll> A;
bool calc[100010][5][5];
ll dp[100010][5][5];

/*
    state:
    0 -> only jumps from i to i+2
    1 -> one jump from i to i+3
    2 -> two jumps from i to i+3
    3 -> one jump from i to i+4
*/

ll f(int done, int state, int offset) {
    if(done == N/2)
        return 0LL;

    int ind = 0;
    if(state == 0) 
        ind = offset + done * 2;
    else if(state == 1) 
        ind = offset + (done-1) * 2 + 3;
    else if(state == 2)
        ind = offset + (done-2) * 2 + 6;
    else if(state == 3) 
        ind = offset + (done-1) * 2 + 4;
    
    if(ind >= N)
        return LLONG_MIN;
    
    if(calc[done][state][offset])
        return dp[done][state][offset];
    calc[done][state][offset] = true;

    ll res = 0;
    if(state == 0) 
        res = max({f(done+1, 0, offset), f(done+1, 1, offset), f(done+1, 3, offset)});
    else if(state == 1)
        res = max(f(done+1,1,offset), f(done+1,2,offset));
    else if(state == 2 || state == 3)
        res = f(done+1,state,offset);
    
    return dp[done][state][offset] = (res == LLONG_MIN ? LLONG_MIN : A[ind] + res);
}

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

    cin >> N;
    A.resize(N);
    for(ll & x : A) cin >> x;
    
    memset(calc, false, sizeof calc);

    ll res = LLONG_MIN;
    if(N%2)
        res = max({f(0,0,0),f(0,0,1),f(0,0,2)});
    else 
        res = max(f(0,0,0),f(0,0,1));
    
    cout << res << '\n';
}


Measured memory_bytes: 34580
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

signed main() {
  int N, x;
  cin >> N >> x;
  VI a(N);
  REP (i, N) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int acc = 0;
  REP (i, N) {
    acc += a[i];
    if (acc > x) {
      cout << i << endl; return 0;
    }
  }
  if (acc == x) {
    cout << N << endl;
  } else {
    cout << N - 1 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;



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

	int w, a, b;
	cin >> w >> a >> b;
	int ans;
	if (w > abs(a - b)) {
		ans = 0;
	}
	else {
		ans = abs(a - b) - w;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
def divisors(M):#Mの約数列 O(n^(0.5+e))
    import math
    d=[]
    i=1
    while math.sqrt(M)>=i:
        if M%i==0:
            d.append(i)
            if i**2!=M:
                d.append(M//i)
        i=i+1
    d.sort()
    return d

N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[a[i]^a[i-1] for i in range(0,N)]
B=[b[i]^b[i-1] for i in range(0,N)]
d=divisors(N)
perioda=N
for i in range(0,len(d)):
    test=[A[(j+d[i])%N] for j in range(0,N)]
    if test==A:
        perioda=min(perioda,d[i])

periodb=N
for i in range(0,len(d)):
    test=[B[(j+d[i])%N] for j in range(0,N)]
    if test==B:
        periodb=min(periodb,d[i])

if perioda==periodb:
    A=A[:perioda]
    B=B[:periodb]
    kouho=[]
    for i in range(0,len(B)):
        if A[i]==B[0]:
            kouho.append(i)
    ans=-1
    for i in range(0,len(kouho)):
        test=[A[(j+kouho[i])%perioda] for j in range(0,perioda)]
        if test==B:
            ans=kouho[i]
            break
    if ans!=-1:
        for i in range(0,N//perioda):
            print(ans+perioda*i,a[ans+perioda*i]^b[0])

Measured memory_bytes: 138624
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

INF = 10**9 + 1

def precompute(N, M, data):
    data = data.reshape(-1, 3)
    A, B, C = data[:N].T
    D, E, F = data[N:].T
    X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
    Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
    DX, DY = np.diff(X), np.diff(Y)
    A = np.searchsorted(X, A)
    B = np.searchsorted(X, B)
    D = np.searchsorted(X, D)
    C = np.searchsorted(Y, C)
    E = np.searchsorted(Y, E)
    F = np.searchsorted(Y, F)
    return A, B, C, D, E, F, X, Y, DX, DY

@njit
def set_ng(A, B, C, D, E, F, H, W):
    ng = np.zeros((H * W, 4), np.bool_)

    for i in range(len(A)):
        for x in range(A[i], B[i]):
            v = x * W + C[i]
            ng[v][1] = 1
            ng[v - 1][0] = 1

    for i in range(len(D)):
        for y in range(E[i], F[i]):
            v = D[i] * W + y
            ng[v][3] = 1
            ng[v - W][2] = 1
    return ng

@njit
def solve(A, B, C, D, E, F, X, Y, DX, DY):
    H, W = len(X), len(Y)
    N = H * W
    ng = set_ng(A, B, C, D, E, F, H, W)
    x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
    v0 = x0 * W + y0
    visited = np.zeros(N, np.bool_)
    visited[v0] = 1
    stack = np.empty(N, np.int32)
    p = 0
    ret = 0

    def area(x):
        x, y = divmod(x, W)
        return DX[x] * DY[y]

    def push(x):
        nonlocal p, ret
        stack[p] = x
        visited[x] = 1
        ret += area(x)
        p += 1

    def pop():
        nonlocal p
        p -= 1
        return stack[p]

    push(v0)
    move = (1, -1, W, -W)
    while p:
        v = pop()
        for i in range(4):
            if ng[v][i]:
                continue
            w = v + move[i]
            if visited[w]:
                continue
            x, y = divmod(w, W)
            if x == 0 or x == H - 1 or y == 0 or y == W - 1:
                return 0
            push(w)
    return ret

N, M = map(int, readline().split())
data = np.int64(read().split())

x = solve(*precompute(N, M, data))
if x == 0:
    print('INF')
else:
    print(x)

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

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 

double EPS=1e-9; 
int INF=1000000005; 
long long INFF=1000000000000000005ll; 
double PI=acos(-1); 
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 }; 
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 }; 
const ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n") 
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl 
#define OUT(x) cout << x << endl 
#define debug(...) fprintf(stderr, __VA_ARGS__) 
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a)) 
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a)) 
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a)) 
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a)) 
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a)) 
#define EACH(a, b) for (auto&(a) : (b)) 
#define REP(i, n) FOR(i, 0, n) 
#define REPN(i, n) FORN(i, 1, n) 
#define MAX(a, b) a=max(a, b) 
#define MIN(a, b) a=min(a, b) 
#define SQR(x) ((ll)(x) * (x)) 
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define SIZE(v) (int)v.size() 
#define SORT(v) sort(ALL(v)) 
#define REVERSE(v) reverse(ALL(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
#define TC(t) while (t--) 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)


void solve() {

}

int main()  
{ 
    FAST_INP;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
    #endif
    
    // int tc; cin >> tc;
    // TC(tc) solve();
    int n;
    cin >> n;
    vi l(n);
    READ(l);
    SORT(l);
    int ans=0;
    FOR(i,0,n){
        FOR(j,i+1,n){
            FOR(k,j+1,n){
                if((l[i]!=l[j]&&l[j]!=l[k])&&l[i]+l[j]>l[k]){
                    // cout << i << " " << j << " " << k << endl;
                    ans++;
                }
            }
        }
    }
    OUT(ans);
    return 0; 
} 

Measured memory_bytes: 3680
import java.util.Scanner;
public class Main {
public static void main(String[]args){
    Scanner sc =new Scanner(System.in);

    int n,q;
    int i,l,r,p,count;
    int [] A,m;
    n =sc.nextInt();
    A = new int[n];
    for(i=0;i<n;i++){
        A[i] = sc.nextInt();
    }
    q = sc.nextInt();
    m = new int[q];
    for(i=0;i<q;i++){
        m[i] = sc.nextInt();
    }
    count=0;
    for(i=0;i<q;++i){
        r=n/2;
        l=0;
        p=n;
        while(true){
            if(m[i]== A[r]){
                count++;
                break;
            }
            else if(l==p||p-l==1){
                break;
            }
            else if(m[i]>A[r]){
                l=r;
                r=p-(p-l)/2;
            }
            else{
                p=r;
                r=p-(p-l)/2;
            }
        }
    }
    System.out.println(count);
    }
}



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

const int MAXN = 101;
const int MAXD = 200001;
const int INF = 1<<28;
int N, A, S;
int HP[MAXN];
int aMP[MAXN], aDM[MAXN];
int sMP[MAXN], sDM[MAXN];
int aDP[MAXD], sDP[MAXD];

void calc(int n, int w[MAXN], int cost[MAXN], int dp[MAXD]) {
  fill(dp, dp+MAXD, INF);
  dp[0] = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = w[i]; j < MAXD; ++j) {
      dp[j] = min(dp[j], dp[j-w[i]] + cost[i]);
    }
  }
}

int main() {
  while(cin >> N && N) {
    for(int i = 0; i < N; ++i) cin >> HP[i];
    int M; cin >> M;
    A = S = 0;
    for(int i = 0; i < M; ++i) {
      string name, target;
      int mp, damage;
      cin >> name >> mp >> target >> damage;
      damage = min(damage, 100000);
      if(damage == 0) continue;
      if(target == "All") {
        aMP[A] = mp;
        aDM[A] = damage;
        ++A;
      } else {
        sMP[S] = mp;
        sDM[S] = damage;
        ++S;
      }
    }
    calc(A, aDM, aMP, aDP);
    calc(S, sDM, sMP, sDP);
    for(int i = MAXD-1; i-1 >= 0; --i)
      sDP[i-1] = min(sDP[i-1], sDP[i]);
    int res = INF;
    for(int i = 0; i < MAXD; ++i) {
      int sum = aDP[i];
      if(sum == INF) continue;
      for(int j = 0; j < N; ++j) {
        if(sDP[max(0, HP[j]-i)] == INF) {
          sum = INF;
          continue;
        }
        sum += sDP[max(0, HP[j]-i)];
      }
      res = min(res, sum);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 2780
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

int A, B;

int main() {
    cin >> A >> B;
    if (A == B) {
        cout << A + B << endl;
    } else {
        cout << 2 * max(A, B) - 1 << endl;
    }
}




Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


N, M, Q = 0, 0, 0
A, B, C, D = [0], [0], [0], [0]
ans = 0

def dfs(i, l):
    global ans, N, M, Q, A, B, C, D
    if i >= N:
        tmp = 0
        for j in range(Q):
            if l[B[j]] - l[A[j]] == C[j]:
                tmp += D[j]
        ans = max(ans, tmp)
        return

    for j in range(1, M + 1):
        if l:
            if j >= l[-1]:
                l.append(j)
                dfs(i + 1, l)
                l.pop()
        else:
            l.append(j)
            dfs(i + 1, l)
            l.pop()


def solve():
    global ans, N, M, Q, A, B, C, D
    N, M, Q = map(int, input().split())
    A, B, C, D = [0] * Q, [0] * Q, [0] * Q, [0] * Q
    for i in range(Q):
        A[i], B[i], C[i], D[i] = map(int, input().split())
        A[i] -= 1
        B[i] -= 1

    l = []
    dfs(0, l)
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 75648
mod = 10**9+7

f = [1]*(2*10**6+5)
f[0] = 1
for i in range(1,2*10**6+4):
    f[i] = f[i-1]*i%mod

def inv(i):
    return pow(f[i],mod-2,mod)

def g(x,y):
    return f[x+y]*inv(x)*inv(y)%mod

r1,c1,r2,c2 = map(int,input().split(" "))
ans = g(r2+1,c2+1)-g(r2+1,c1)-g(r1,c2+1)+g(r1,c1)
print(ans%mod)

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

long long n, k;
long long a[100];

const long long mod = 1e9 + 7;
long long dp[101][101][256][2];
long long po[101];

long long dfs(long long i = 0, long long j = 0, long long s = 0, bool f = false) 
{
	long long & ret = dp[i][j][s][f];

	if (ret != -1) return ret;
	ret = 0;
	if (s == k && !f) {
		ret += po[j];
	}

	if (i == n) return ret;

	ret += dfs(i + 1, j, s, s == k) % mod;
	ret	+= dfs(i + 1, j + 1, s ^ a[i]) % mod;

	ret %= mod;

	return ret;
}

signed main()
{
	memset(dp, -1, sizeof(dp));
	cin >> n >> k;
	for (long long i = 0; i < n; ++i) {
		 cin >> a[i];
	}

	po[0] = 1;
	for (long long i = 1; i <= 100; ++i) { 
		po[i] = (po[i - 1] * i) % mod;
	}

	cout << dfs() << endl;
}


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

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

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

    int ans = 0, active = 0;
    for(int i = 0; i < n; i++){
        if(active < h[i]){
            ans += h[i] - active;
        }
        active = h[i];
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
  long int n;
  set<long int>s;
  cin >> n;
  vector<long int>a(n);
  vector<long int>b(200000);
  rep(i,n){ 
    cin >> a[i];
    b[a[i]]++;
    s.insert(a[i]);
  }
  vector<long int>ans1(200000);
  vector<long int>ans2(200000);
  long int k = 0,total=0;
  for (auto value : s) {
  	ans1[value] = b[value]*(b[value]-1)/2;
    ans2[value] = (b[value]-2)*(b[value]-1)/2;
    total += ans1[value];
  }
  
 rep(p,n){
   long int ans = total;
   ans -= ans1[a[p]];
   ans += ans2[a[p]];
   cout << ans << endl;
 }


}

Measured memory_bytes: 13824
s = input()
al = [chr(i) for i in range(97, 97+26)]
l = list(s)
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) == 26:
    for i in range(24, -1, -1):
        for j in range(25, i, -1):
            if s[i] < s[j]:
                print(s[:i] + s[j])
                exit()
else:
    for i in al:
        if not i in s:
            print(s + i)
            exit()

Measured memory_bytes: 3064
use proconio::{input, marker::Usize1};

const M: u64 = 1000_000_007;

fn main() {
    input! {
        n: usize,
        xy: [(Usize1, Usize1); n - 1],
    }

    let mut t = vec![vec![]; n];
    for (x, y) in xy {
        t[x].push(y);
        t[y].push(x);
    }

    println!("{}", DP::new(n).calc(&t, 0, 0));
}

struct DP {
    dp: Vec<Option<(u64,u64)>>,
}

impl DP {
    fn new(n: usize) -> DP {
        DP {
            dp: vec![None; n],
        }
    }

    fn calc(&mut self, t: &Vec<Vec<usize>>, i: usize, p: usize) -> u64 {
        let v = if let Some(v) = self.dp[i] {
            v
        } else {
            let mut v = (1, 1);
            for &j in t[i].iter() {
                if j != p {
                    v.0 = v.0 * self.calc(t, j, i) % M;
                    v.1 = v.1 * self.dp[j].unwrap().0 % M;
                }
            }
            self.dp[i] = Some(v);
            v
        };
        (v.0 + v.1) % M
    }
}



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

int main()
{
    int a,b;
    cin>>a>>b;
    int count=a;
    int sockets = 1;
    if(b==1)
    {
        cout<<0<<endl;
        return 0;
    }
    if(a<b)
    {
        while(count<b)
        {
            count+=(a-1);
            sockets++;
        }
    }
    else
    {
        cout<<1<<endl;
        return 0;
    }  
    
    cout<<sockets<<endl;
    return 0;
}

Measured memory_bytes: 256
# 初期入力
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())) )
B = np.array(list(map(int, input().split())) )
C = np.array(list(map(int, input().split())) )

#
manzoku =sum(B)
for i in range(N-1):
    if A[i+1] -A[i] ==1: # Ai Ai+1と続くとCiが加算
        manzoku +=C[A[i]-1] #iは０～N-1
        
print(manzoku)

Measured memory_bytes: 12604
#include <iostream>

using namespace std;

int main() {
	int w,h;

	while (cin >> h >> w) {
		if (h == 0 && w == 0) {
			break;
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cout << '#' << flush;
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
def resolve():
    N, M, X = list(map(int, input().split()))
    C = []
    A = []
    for i in range(N):
        ins = list(map(int, input().split()))
        C.append(ins[0])
        A.append(ins[1:])
    minprice = float("inf")
    for bits in range(1<<N):
        comps = [0 for _ in range(M)]
        price = 0
        for odr in range(N):
            if (bits & (1<<odr)):
                price += C[odr]
                for i in range(M):
                    comps[i] += A[odr][i]
        for i in range(M):
            if comps[i] < X:
                break
        else:
            minprice = min(minprice, price)
    print(minprice if minprice < float("inf") else -1)


if '__main__' == __name__:
    resolve()

Measured memory_bytes: 9180
h, w = map(int, input().split())
a = [input() for i in range(h)]
b = [-1]*h*w; c = []; d = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == "#": b[i*w+j] = 0; c.append(i*w+j)
while len(c) < h*w:
    if c[d]//w != 0:
        if b[c[d]-w] == -1: b[c[d]-w] = b[c[d]]+1; c.append(c[d]-w)
    if c[d]%w != 0:
        if b[c[d]-1] == -1: b[c[d]-1] = b[c[d]]+1; c.append(c[d]-1)
    if c[d]%w != w-1:
        if b[c[d]+1] == -1: b[c[d]+1] = b[c[d]]+1; c.append(c[d]+1)
    if c[d]//w != h-1:
        if b[c[d]+w] == -1: b[c[d]+w] = b[c[d]]+1; c.append(c[d]+w)
    d += 1
print(max(b))

Measured memory_bytes: 157896
x = int(input())
import math
flag = False
for i in range(x):
    ans = x - i
    for j in range(2,x):
        b = round(math.pow(ans, 1/j), 10)
        if b % 1 == 0:
            flag = True
            break
        elif b < 1:
            break
    if flag:
        break
print(ans)

Measured memory_bytes: 3188
//https://www.codechef.com/problems/CHEFSUBA
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define max(x,y) (x)>(y)?(x):(y)
#define min(x,y) (x)>(y)?(y):(x)
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1<<28;
const int maxn=1000010;
const int maxm=110;
const int maxk=100010;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n;
int main()
{
    //freopen("in.txt","r",stdin);
    int a,b;
    while(~scanf("%d %d",&a,&b))
    {
        if(a==2||b==2)
            printf("No\n");
        else if((a==4||a==6||a==9||a==11)&&(b==4||b==6||b==9||b==11))
            printf("Yes\n");
        else if((a==1||a==3||a==5||a==7||a==8||a==10||a==12)&&(b==1||b==3||b==5||b==7||b==8||b==10||b==12))
            printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define isNum(a) (a>='0'&&a<='9')
#define SP putchar(' ')
#define EL putchar('\n')
#define N 25005
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
template<class T1>void read(T1 &r_e_a_d);
template<class T1>void write(T1 w_r_i_t_e);
string str;
string a[N];
int main(){
    int i,j,k,n,id=0;
    string now;
    cin>>str;
    n=str.size();
    read(k);
    for(i=0;i<n;i++){
        now.clear();
        for(j=1;j<=k&&i+j-1<n;j++){
            now+=str[i+j-1];
            a[++id]=now;
        }
    }
    sort(a+1,a+id+1);
    unique(a+1,a+id+1);
    cout<<a[k]<<endl;
    return 0;
}
template<class T1>void read(T1 &r_e_a_d){
    T1 k=0;
    char ch=getchar();
    int flag=1;
    while(!isNum(ch)){
        if(ch=='-'){
            flag=-1;
        }
        ch=getchar();
    }
    while(isNum(ch)){
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    r_e_a_d=flag*k;
}
template<class T1>void write(T1 w_r_i_t_e){
    if(w_r_i_t_e<0){
        putchar('-');
        write(-w_r_i_t_e);
    }else{
        if(w_r_i_t_e<10){
            putchar(w_r_i_t_e+'0');
        }else{
            write(w_r_i_t_e/10);
            putchar((w_r_i_t_e%10)+'0');
        }
    }
}


Measured memory_bytes: 1664
A, B, C = map(int, input().split())
r = 0
s = set()
s.add((A, B, C))
while A%2 == 0 and B%2 == 0 and C%2 == 0:
  r += 1
  A, B, C = (B//2+C//2, C//2+A//2, A//2+B//2)
  if (A, B, C) in s:
    print(-1)
    exit()
  s.add((A, B, C))
print(r)


Measured memory_bytes: 3064