akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
				
int32_t main() {
	fast_cin();  
	string s; cin >> s;
	for (char &c : s) {
		c -= '0';
	}
	int n = s.size();
	auto check = [&](int k) {
		int pref[n + 1] = {0};
		int cur = 0;
		for (int i = 0; i < n; ++i) {
			cur ^= pref[i];
			if ((cur ^ s[i]) != 0) {
				if (i + k <= n) {
					pref[i + k] ^= 1;
					cur ^= 1;
				} else {
					return (i - 1 >= k - 1);
				}
			}
		}
		return true;
	};	
	int l = 0, r = n + 1;
	while (r > l + 1) {
		int mid = l + r >> 1;
		if (check(mid)) {
			l = mid;
		} else {
			r = mid;
		}
	}
	cout << l << endl;
	return 0;
}


Measured memory_bytes: 1232
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    private static final int INF = (int)1e9 + 7;

    int N;
    ArrayList<Integer> numbers;
    int[] dp;

    private void solve() {
        N = nextInt();

        numbers = new ArrayList<>();
        numbers.add(1);
        for(int i = 1;i < 10;i++) {
            int six = 1;
            int nine = 1;
            for(int j = 0;j < i;j++) {
                six *= 6;
                nine *= 9;
            }

            numbers.add(six);
            numbers.add(nine);
        }
        dp = new int[N + 1];
        Arrays.fill(dp, N);
        dp[N] = 0;
        for(int i = N;i >= 0;i--) {
            for(int n : numbers) {
                if (i >= n) {
                    dp[i - n] = Math.min(dp[i - n], dp[i] + 1);
                }
            }
        }
        out.println(dp[0]);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

int main(){
  string s;
  cin >> s;
  int a=s.size();
  int b=a/2;
  int count=0;
  
  for(int i=0;i<b;i++){
    if(s.at(i)!=s.at(a-i-1)){
      count++;
    }
    else{
      continue;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int cnt[30];

int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    cnt[s[i]-'a']++;
  }
  for(int i=0;i<26;i++){
    if(cnt[i]%2==1){
      cout<<"No"<<endl;
      return(0);
    }
  } 
  cout<<"Yes"<<endl;
  return(0);
}


Measured memory_bytes: 256
import itertools

n,m,x=map(int,input().split())
c=[0]*n
a=[[0]*m for i in range(n)]
for i in range(n):
    l=list(map(int,input().split()))
    c[i]=l[0]
    a[i]=l[1:len(l)]
    
cmin=10**7
yn2=""
for i in itertools.product([0,1], repeat=n):
    csum=0
    yn=""
    asum=[0]*m
    for ii in range(len(i)):
        if i[ii]==1:
            for j in range(m):
                asum[j]+=a[ii][j]
            csum+=c[ii]
    for j in range(m):        
        if asum[j]<x:
            yn="no"
            break
    if yn!="no":
#        print(csum,cmin)
        cmin=min(cmin,csum)
        yn2="yes"

if yn2=="yes":
    print(cmin)                
else:
    print(-1)

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

lint dp[101][100001] = {0};

int main(){
    int N, W;
    cin >> N >> W;
    vector<int> w(N);
    vector<lint> v(N);
    rep(i, N){
        cin >> w[i] >> v[i];
    }
    REP(i, 1, N + 1){
        rep(j, W + 1){
            if(j >= w[i - 1]){
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
            }else{
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 78336
#include<iostream>
using namespace std;
int I,flg;
int t[10][10],u[10][10];
int ans[10][10];
void check();
void dfs(int);
void compute(int,int);
int main(){
  cin>>I;
  while(I--){
    flg=0;
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	cin>>t[i][j];
	u[i][j]=t[i][j];
	ans[i][j]=0;
      }
    }
    dfs(0);
  }
  return 0;
}


void dfs(int x){
  if(flg)return;
  if(x==10){
    check();
  }else{
    ans[0][x]=0;
    dfs(x+1);
    if(flg)return;
    ans[0][x]=1;
    dfs(x+1);
  }
}


void check(){
  if(flg)return;
  for(int i=0;i<10;i++)for(int j=0;j<10;j++)t[i][j]=u[i][j];

  for(int i=0;i<10;i++)if(ans[0][i]==1)compute(0,i);
  
  for(int i=1;i<10;i++){
    for(int j=0;j<10;j++){
      ans[i][j]=0;
      if(t[i-1][j]==1){
	ans[i][j]=1;
	compute(i,j);
      }
    }
  }
  /*
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      if(j)cout<<' ';
      cout<<t[i][j];
    }
    cout<<endl;
  }
  */
  int cnt=0;
  for(int i=0;i<10;i++)cnt+=t[9][i];
  if(cnt==0){
    flg=1;
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	if(j)cout<<' ';
	cout<<ans[i][j];
      }
      cout<<endl;
    }
  }
}

void compute(int y,int x){
  t[y][x]=(t[y][x]*-1)+1;
  if(y>0)t[y-1][x]=(t[y-1][x]*-1)+1;
  if(x>0)t[y][x-1]=(t[y][x-1]*-1)+1;
  if(y<9)t[y+1][x]=(t[y+1][x]*-1)+1;
  if(x<9)t[y][x+1]=(t[y][x+1]*-1)+1;
}

Measured memory_bytes: 1156
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__



void solve(void){
  
  int N;
  cin >> N;
  
  vector<int> A(N+2); // 1-indexed
  vector<int> B(N+1); // 1-indexed
  
  ll sumT=0;
  
  REP2(i,1,N+2){
    cin >> A[i];
  }
  REP2(i,1,N+1){
    cin >> B[i];
    if(A[i]<=B[i]){
      sumT +=A[i];
      B[i] -=A[i];
      A[i]=0;
      if(A[i+1]<=B[i]){
        sumT += A[i+1];
        B[i] -=A[i+1];
        A[i+1]=0;
      }
      else
      {
        sumT += B[i];
        A[i+1] -=B[i];
        B[i] =0;
      }
    }
    else
    {
      sumT += B[i];
      A[i] -=B[i];
      B[i] = 0;
    }
  }
  
  
  cout << sumT << endl;

  
  return;
   
}

#define TESTCASES 1

int main(int argc, const char * argv[]) {


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

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include<algorithm>
using namespace std;

int main()
{
    std::ios::sync_with_stdio(false);
    int a,b;
    while (cin>>a>>b) {
        cout<<a*b+1-a-b<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
int n;
map<int, int> m;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  ll ans = 0;
  FOR(i, 0, n){
    int a;
    cin >> a;
    ans += m[i-a];
    m[i+a]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 20672
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int, int> P;

bool isCross(P p1, P p2) {
  if (p1.second >= p2.first) return true;
  return false;
}

P marge(P p1, P p2) {
  return P(min(p1.first, p2.first), p2.second);
}

int main() {
  int N, M, r, t, n, m, s, q, ts, te, mq;
  while (1) {
    scanf("%d%d", &N, &M);
    if (N == 0) break;
    scanf("%d", &r);
    vector<P> stu[10000]; // login time, logout time
    int pc[1000]; // login time
    for (int i = 0; i < r; i++) {
      scanf("%d%d%d%d", &t, &n, &m, &s);
      n--; m--;
      if (s) pc[n] = t;
      else {
        P p = P(pc[n], t);
        int num = stu[m].size() - 1;
        if (num >= 0 && isCross(stu[m][num], p)) {
          stu[m][num] = marge(stu[m][num], p);
          p = stu[m][num];
          num--;
          while (num >= 0 && isCross(stu[m][num], p)) {
            stu[m][num] = marge(stu[m][num], p);
            stu[m].erase(stu[m].end() - 1);
            num--;
          }
        } else stu[m].push_back(p);
      }
    }
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
      scanf("%d%d%d", &ts, &te, &mq);
      mq--;
      vector<P>::iterator it1 = lower_bound(stu[mq].begin(), stu[mq].end(), P(ts, ts));
      vector<P>::iterator it2 = upper_bound(stu[mq].begin(), stu[mq].end(), P(te, te));
      if (it2 == stu[mq].begin()) printf("0\n");
      else {
        int sum = 0;
        if (it1 != stu[mq].begin() && (*(it1 - 1)).second > ts) {
          if ((*(it1 - 1)).second > te) sum += te - ts;
          else sum += (*(it1 - 1)).second - ts;
        }
        if (it1 == it2) { printf("%d\n", sum); continue; }
        it2--;
        for (; it1 != it2; it1++) sum += (*it1).second - (*it1).first;
        if ((*it2).second > te) sum += te - (*it2).first;
        else sum += (*it2).second - (*it2).first;
        printf("%d\n", sum);
      }
    }
  }
}



Measured memory_bytes: 2868
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
	string s;
	cin >> s;
	char c = s.back();
	string ans;
	if (c == '2' || c == '4' || c == '5' || c == '7' || c == '9')ans = "hon";
	else if (c == '3')ans = "bon";
	else ans = "pon";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstring>
#define SIZE 101
using namespace std;

int main()
{
    int n, chack = 0;
    cin>>n;
    cin>>ws;
    string str;
    getline(cin, str);
    for(int i = 0; str[i]!='\0'; i++)
    {
        if(str[i] == 'Y')
        {
            chack++;
            break;
        }
    }
    if(!chack)
        cout<<"Three"<<endl;
    else
        cout<<"Four"<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] dp = new long[n][21];
        dp[0][sc.nextInt()] = 1;
        for (int i = 1; i < n - 1; i++) {
            int x = sc.nextInt();
            for (int j = 0; j + x <= 20; j++) {
                dp[i][j + x] += dp[i - 1][j];
            }
            for (int j = 20; j - x >= 0; j--) {
                dp[i][j - x] += dp[i - 1][j];
            }
        }
        int ans = sc.nextInt();
        System.out.println(dp[n - 2][ans]);
    }
}



Measured memory_bytes: 26472
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int res = 0;
        int[] A = new int[n];
        int k = sc.nextInt();
        for(int i = 0; i < k; i++) {
            int d = sc.nextInt();
            for(int j = 0; j < d; j++) {
                A[sc.nextInt() - 1]++;
            }
        }
        for(int a : A) {
            if(a == 0) res++;
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 46264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,m;cin>>n>>m;
    int p_ary[m];
    string s_ary[m];
    rep(i,m) cin >> p_ary[i] >> s_ary[i];
    rep(i,m) p_ary[i]--;
    int penalty[n];
    rep(i,n) penalty[i] = -1;
    int sum_pena = 0;
    int sum_ac = 0;

    rep(i,m)
    {
        if (penalty[p_ary[i]]==0)
        {
            continue;
        }
        else if (s_ary[i]=="AC")
        {
            sum_pena += max(0,penalty[p_ary[i]]);
            penalty[p_ary[i]] = 0;
            sum_ac++;
        }
        else if (s_ary[i] == "WA")
        {
            penalty[p_ary[i]] = max(1, penalty[p_ary[i]]+1);
        }
    }
    cout << sum_ac << " " << sum_pena << endl;
    
}




Measured memory_bytes: 6528
class SegmentTree:
  def __init__(self, n, op, e):
    self.n = n
    self.op = op
    self.e = e
    self.size = 2 ** ((n - 1).bit_length())
    self.node = [self.e] * (2 * self.size)
 
  def build(self, array):
    for i in range(self.n):
      self.node[self.size + i] = array[i]
    for i in range(self.size - 1, 0, -1):
      self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
 
  def update(self, i, val):
    i += self.size
    self.node[i] = val
    while i > 1:
      i >>= 1
      self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
 
  def get(self, l, r):
    l, r = l + self.size, r + self.size
    res_l, res_r = self.e, self.e
    while l < r:
      if l & 1:
        res_l = self.op(res_l, self.node[l])
        l += 1
      if r & 1:
        r -= 1
        res_r = self.op(self.node[r], res_r) 
      l, r = l >> 1, r >> 1
    return self.op(res_l, res_r)
  
N,K = map(int, input().split())
A = list(int(input()) for _ in range(N))

max_len = max(A) + 2
ST = SegmentTree(max_len,max,0)
for a in A:
  a += 1
  l = max(1,a-K)
  r = min(max_len,a+K)
  ST.update(a,ST.get(l,r+1)+1)
print(ST.get(1,max_len))

Measured memory_bytes: 127472
#include<bits/stdc++.h>
 using namespace std;
 
 // #define  int           long long
 #define pb                push_back
 #define ppb               pop_back
 #define pf                push_front
 #define ppf               pop_front
 #define all(x)            (x).begin(),(x).end()
 #define uniq(v)           (v).erase(unique(all(v)),(v).end())
 #define sz(x)             (int)((x).size())
 #define fr                first
 #define sc                second
 #define pint              pair<int,int>
 #define rep(i,a,b)        for(int i=a;i<b;i++)
 #define mem1(a)           memset(a,-1,sizeof(a))
 #define mem0(a)           memset(a,0,sizeof(a))
 #define ppc               __builtin_popcount
 #define ppcll             __builtin_popcountll
 #define vint			   vector<int>
 #define vpint			   vector<pair<int,int>>
 #define mp                make_pair


 void reader() 
 { 
 #ifndef ONLINE_JUDGE 
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout); 
 #endif
 }
 
 void fastIO() {ios_base::sync_with_stdio(false); cin.tie(NULL);}
 
 
 
 void solve()
 {
 
 int n;
 cin>>n;
 int x,y;
 int flag=1;
 int ctr=0;
 while(cin>>x>>y)
 {
 	if(x==y)
 		ctr++;
 	else
 		ctr=0;
 	if(ctr==3)
 	{
 		flag=0;
 		break;
 	}
 }
 if(flag)
 	cout<<"No";
 else
 	cout<<"Yes";
 
 cout<<"\n";
 }
 
 
 
 signed main()
 {
 	reader(); fastIO();
 	long long t=1;
 	//cin>>t;
 	while(t--) solve();
 	return 0;
 }

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>

#include <map>
 
using namespace std;
typedef long long ll;



ll ans,mx,sum,mn=1e8;
int main(){
	ll h,a;
	cin>>h>>a;
	if(h%a!=0) cout<<(h/a)+1;
	else cout<<h/a;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a=sc.nextInt();
		int m=n%500;
		if(a>=m){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

ll a[100005],b[100005];

int main()
{
	ios::sync_with_stdio(false);
	int n;
	ll ans=0,k,t,w;
	cin>>n;
	for(int i=0;i<=n;i++)
	cin>>a[i];
	for(int i=n;i>=0;i--)
	b[i]=b[i+1]+a[i];
	for(int i=0;i<=n;i++)
	{
		if(i==0) w=1;
		else w<<=1;
		w=min(w,b[i]);
		ans+=w;
		w-=a[i];
		if(w<0)
		{
			cout<<"-1"; return 0;
		}
	}
	cout<<ans;
	return 0;
}




Measured memory_bytes: 5216
def main():
    x, n = map(int, input().split(' '))
    p = list(map(int,input().split()))

    ax, px = x, x
    for i in range(100):
        ax = x + i
        px = x - i
        if px not in p:
            print(px)
            exit(0)
        if ax not in p:
            print(ax)
            exit(0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

vector<ll> A, S;
ll N, M;

ll get_count(ll mid) {
    ll cnt = 0;
    for (ll i = 0; i < N; i++) {
        auto p = [&](ll x) { return A[i] + x >= mid; };
        ll j = partition_point(A.begin(), A.end(), p) - A.begin();
        cnt += j;
    }
    return cnt;
}

ll binary_search(ll ok, ll ng) {
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (get_count(mid) >= M) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}

int main() {
    cin >> N >> M;
    A.resize(N), S.resize(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    for (int i = 0; i < N; i++) {
        S[i] = i ? S[i - 1] + A[i] : A[i];
    }

    int k = binary_search(-1, 1e8);

    ll ans = 0;
    for (int i = N - 1; i >= 0; i--) {
        auto p = [&](int x) { return A[i] + x >= k; };
        ll j = partition_point(A.begin(), A.end(), p) - A.begin();
        ans += j ? S[j - 1] + A[i] * j : 0;
    }
    ans -= (get_count(k) - M) * k;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int):
    if A*B%2==0:
        print(NO)
    else:
        print(YES)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;
typedef vector <int> low;

int main() {
	int a[3][3];

	for (int i = 0; i < 3; i++) {
		for (int  j = 0; j < 3; j++) {
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	vector <int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}

	bool find = false;
	for (int i = 0; i < n; i++) {
		for (int  j = 0; j < 3; j++) {
//			if (find == true) {
//				;
//			} else {
				for (int k = 0; k < 3; k++) {
					if (b[i] == a[j][k]) {
						a[j][k] = 0;
//						find = true;
						break;
					}
				}
//			}
		}
	}
//	cout << "----" << endl;
//	for (int i = 0; i < 3; i++) {
//		for (int j = 0; j < 3; j++) {
//			cout << a[i][j] << " ";
//		}
//		cout << endl;
//	}
//	cout << "----" << endl;


	for (int i = 0; i < 3; i++) {
		if (a[i][0] == 0) {
			bool bingo = true;
			for (int j = 0; j < 3; j++) {
				if (a[i][j] != 0) {
					bingo = false;
					break;
				}
			}
			if (bingo == true)  {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	for (int i = 0; i < 3; i++) {
		if (a[0][i] == 0) {
			bool bingo = true;
			for (int j = 0; j < 3; j++) {
				if (a[j][i] != 0) {
					bingo = false;
					break;
				}
			}
			if (bingo == true)  {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	if (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	if (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

typedef pair<int,int> pii;

int main() {
  int N, Q, M;
  pii cnt[101];
  while (true) {
    scanf("%d %d", &N, &Q);
    if (N == 0 && Q == 0) break;
    for (int i=0;i<100;i++) cnt[i] = pii(0, i);
    for (int i=0;i<N;i++) {
      scanf("%d", &M);
      for (int j=0;j<M;j++) {
        int Date;
        scanf("%d", &Date);
        cnt[Date].first--;
      }
    }
    sort(cnt, cnt+100);
    printf("%d\n", (-cnt[0].first < Q ? 0 : cnt[0].second));
  }
  return 0;
}

Measured memory_bytes: 2588
from collections import defaultdict
s = input()
dd = defaultdict(list)
for i, c in enumerate(s):
    dd[c].append(i)


def solve(ls):
    for x, y in zip(ls, ls[1:]):
        if y-x <= 2:
            return True, (x+1, y+1)
    return False, None


for k, v in dd.items():
    is_yes, ans = solve(v)
    if is_yes:
        print(*ans)
        break
else:
    print(-1, -1)


Measured memory_bytes: 13680
n = int(input())
s = input()
t = input()
prev = -1
i = 0
ans = 1
mod = pow(10,9)+7
while i != n:
    if s[i] == t[i]:
        if prev == -1:
            ans *= 3
        elif prev == 0:
            ans *= 2
        prev = 0
        i += 1
    else:
        if prev == -1:
            ans *= 6
        elif prev == 0:
            ans *= 2
        else:
            ans *= 3
        prev = 1
        i += 2
    ans %= mod
print(ans)

Measured memory_bytes: 9008
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        String s = kbd.next();
        String[] temp = s.split("");
        int cou = 0;
        int nokori = 15 - temp.length;
        for (int i = 0; i < temp.length; i++) {
            if (temp[i].equals("o")) {
                cou++;
            }
        }

        if (cou >= 8 || cou + nokori >= 8) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21844
n = int(input())
a = list(map(int, input().split()))

ans = 1
up = None

for x, y in zip(a, a[1:]):
    if x < y:
        if up is None:
            up = True
        elif not up:
            ans += 1
            up = None
    elif x > y:
        if up is None:
            up = False
        elif up:
            ans += 1
            up = None
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>

#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <random>
#include <complex>
#include <utility>
#include <tuple>
#include <memory>

#include <array>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <csignal>
#include <cstdint>
#include <cstddef>

#ifdef ONLINE_JUDGE
#define NDEBUG
#endif
#include <cassert>
#include <stdexcept>
#include <exception>

// << pair
template <typename T1, typename T2>
std::ostream&operator<<(std::ostream&os,const std::pair<T1,T2>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
// << container
template <typename C>
std::ostream&_debug_go(std::ostream&os,const C&v) {bool first=true;os<<"[";for(auto i:v){if(!first)os<<", ";os<<i;first=false;}return os<<"]";}
// << {vector, set, map} delegating to _debug_go
template<typename T> std::ostream&operator<<(std::ostream&os,const std::vector<T>&v){return _debug_go(os, v);}
template<typename T,size_t N> std::ostream&operator<<(std::ostream&os,const std::array<T,N>&v){return _debug_go(os, v);}
template<typename T> std::ostream&operator<<(std::ostream&os,const std::set<T>&v){return _debug_go(os, v);}
template<typename T1, typename T2> std::ostream&operator<<(std::ostream&os,const std::map<T1,T2>&v){return _debug_go(os, v);}
struct Debugger{template<typename T>Debugger&operator,(const T&v){std::cerr<<v<<" "; return *this;}} dbg;
#ifndef NDEBUG
#define debug(args...) do {dbg,args; cerr << "\n";} while(0)
#else
#define debug(args...)
#endif

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ITER(i, s, e) for (auto i((s)); i != (e); ++i)
#define IT(i, c) ITER(i, (c).begin(), (c).end())

using namespace std;

using ui = uint32_t;
using ll = int64_t;
using ull = uint64_t;
template <typename T = int> using Pt = complex<T>;

template <typename T>
T cross(const Pt<T>& a, const Pt<T>& b) { return a.real() * b.imag() - a.imag() * b.real(); }

template <typename T>
bool cmpPt(const Pt<T>& a, const Pt<T>& b) {
    return a.real() < b.real() || (a.real() == b.real() && a.imag() < b.imag());
}
// END TEMPLATE


ll solve(const string& S, const string& T) {
    int N = S.size();
    vector<array<int, 26>> X(N+1);
    X[N].fill(-1);
    for (int i = N-1; i >= 0; --i) {
        X[i] = X[i+1];
        X[i][S[i]-'a'] = i;
    }
    //REP(i, N+1) debug(X[i]);
    int n = 0, i = 0;
    for (char c : T) {
        if (X[0][c-'a'] == -1) return -1;
        i = X[i][c-'a'];
        if (i == -1) {
            ++n;
            i = X[0][c-'a'];
        }
        ++i;
        if (i == N) {
            ++n;
            i = 0;
        }
        //debug(c, i, n);
    }
    return 1LL*N*n + i;
}


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

    string S, T; cin >> S >> T;
    cout << solve(S, T) << '\n';

    return 0;
}


Measured memory_bytes: 10704
from collections import deque
import queue
N,M = list(map(int,input().split()))
linked_list ={i:[] for i in range(1,N+1)}
A_list = []
B_list = []
depths = [-1 for _ in range(N)]
depths[0] = 0
for m in range(M):

    A, B = list(map(int,input().split()))
    linked_list[A].append(B)
    linked_list[B].append(A)

    # A_list.append(A)
    # B_list.append(B)
node = []
simbols =[]
q = deque()
q.append(1)
while len(q) >0:
    node_no  = q.popleft()
    for i in linked_list[node_no]:
        if depths[i-1] != -1:
            continue

        q.append(i)
        depths[i-1]=node_no

        # print(f"node_no is {node_no} target is {i}")
        # print(depths)

if -1 in  depths:
    print("No")
else:
    print("Yes")
    for i in depths[1:]:
        print(i)

mod = 998244353
INF = 1 << 29
lINF = 1 << 35


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


# def main():
#     n, m = readInt()
#     # インデックスを部屋番号として、各部屋から繋がっている部屋の番号をリストに持つ
#     graph = [[] for i in range(n)]
#     for i in range(m):
#         x, y = readInt()
#         graph[x - 1].append(y - 1)
#         graph[y - 1].append(x - 1)
#     # 各部屋に設定する番号を記録する
#     v = [-1 for i in range(n)]
#     # 部屋1は -1 以外にしておく
#     v[0] = [0]
#     # queueを作成し部屋1（インデックスは0）を入れる
#     q = queue.Queue()
#     q.put(0)
#     while not q.empty():
#         # queueの先頭（今いる部屋の番号）を取り出す
#         x = q.get()
#         # 今いる部屋と繋がっている部屋を順に探索する
#         for y in graph[x]:
#             # -1ではない場合は既に探索済みなのでスキップする
#             if v[y] != (-1):
#                 continue
#             # あとで探索する為にqueueに入れておく
#             q.put(y)
#             print(f"node_no is {x} target is {y}")
#             v[y] = x
#             print(v)
#     print("Yes")
#     for i in range(1, n):
#         print(v[i] + 1)
#     return
#
#
# if __name__ == '__main__':
#     main()



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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n; cin >> n;
    ll k; cin >> k;
    int q; cin >> q;
    vector<ll> ans(n + 1, k);
    REP(i,  q) { 
        int a; cin >> a;
        ans[a] += 1;
    }
    FOR(i, 1, n + 1) {
        if (ans[i] - q <= 0) cout <<  "No" << endl;
        else cout << "Yes" << endl;
    }

}


Measured memory_bytes: 1408
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

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

    int c1 = 0;
    int c0 = 0;
    int n = s.length();

    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') c1++;
        else c0++;
    }

    cout << min(c0, c1) * 2 << endl;
    return 0;
}


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

#define N 401
using namespace std;

int n;
long long a[N];
long long dp[N][N];
long long prefix[N];

long long sum(int i, int j)
{
	return prefix[j] - prefix[i - 1];
}

long long solve2(int i, int j)
{
	if (i >= j)
		return 0;
	if (dp[i][j] != -1)
		return dp[i][j];
	long long ans = LLONG_MAX;
	for (int k = i; k < j; k++)
	{
		ans = min(ans, solve2(i, k) + solve2(k + 1, j) + sum(i, j));
	}
	return dp[i][j] = ans;
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	prefix[0] = 0;
	for (int i = 1; i <= n; i++)
		prefix[i] = a[i] + prefix[i - 1];
	memset(dp, -1, sizeof(dp));
	cout << solve2(1, n) << endl;
	return 0;
}



Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using CHY72;

namespace CHY72{
    
    public class PointXY<T>where T:IComparable {
        public T X , Y;
        public bool Flag = false;
        public PointXY(T _X,T _Y) {
            X = _X; Y = _Y;
        }
        public static bool operator ==(PointXY<T> P1, PointXY<T> P2) {
            return (P1.X.CompareTo( P2.X) == 0 && P1.Y.CompareTo (P2.Y) == 0);
        }
        public static bool operator !=(PointXY<T> P1, PointXY<T> P2) {return !(P1 ==P2);}
        public override int GetHashCode() {return X.GetHashCode() ^ Y.GetHashCode();}
        public override bool Equals(object obj) {
            if (obj == null || this.GetType() != obj.GetType()) {return false;}
            return (this == (PointXY<T>)obj);
        }         

    }
    
}    

public class Program {
    static bool ReadLine_1(ref int num1, bool Fin0 = true) {
        string str = Console.ReadLine();
        num1 = int.Parse(str);
        return (Fin0 && num1 == 0);
    }
    static int  ReadLine_1() {
        return  int.Parse(Console.ReadLine());
    }
    static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true) {
        string str = Console.ReadLine();
        num1 = int.Parse(str.Split(Spliter)[0]);
        num2 = int.Parse(str.Split(Spliter)[1]);
        return (Fin0 && num1 == 0);
    }
    static int[] ReadLine72(char Spliter = ' ') {
        return Console.ReadLine().Split(Spliter).Select(s => int.Parse(s)).ToArray();
    }

    const int DefaultMax = 727272;



    static void Main(string[] args) {
        while (true) {
            int n = ReadLine_1();
            if (n == 0) return;
            string[] Steps = Console.ReadLine().Split(' ');
            int output = 0;
            for (int i = 0; i < n - 1; i++) {
                if (   (Steps[i] == "ru" && Steps[i + 1] == "lu")
                    || (Steps[i] == "lu" && Steps[i + 1] == "ru")
                    || (Steps[i] == "rd" && Steps[i + 1] == "ld")
                    || (Steps[i] == "ld" && Steps[i + 1] == "rd")
                    
                    
                    )output++;
            }
            Console.WriteLine(output);

        }
    }
}

Measured memory_bytes: 5904
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int main(void) {
    string s, ans;
    cin >> s;
    int i;
    REP (i,s.size()) {
        if (s[i] == 'B') {
            if (ans.size() > 0)
                ans.pop_back();
        }
        else
            ans.push_back(s[i]);
    }
    cout << ans << endl;
    return 0;
}


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

int cnt(int x) {
	int res = 0;
	for (int i = 1; i <= x; i++) {
		if (x % i == 0) res++;
	}
	return res;
}

int main() {
	int n; cin >> n;
	int res = 0;
	for (int i = 1; i <= n; i += 2) {
		if (cnt(i) == 8) res++;
	}
	cout << res << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 105;
ll ans, sum, n, m, w, v, a, b, c, d;
ll va[N], vb[N], vc[N], vd[N];
ll pa[N], pb[N], pc[N], pd[N];

// w, 1, 2, 3
int main() {
    cin >> n >> m;
    cin >> w >> v;
    ll w0 = w, w1 = w + 1, w2 = w + 2, w3 = w + 3;
    va[a++] = v;
    for (int i = 1; i < n; ++i) {
        cin >> w >> v;
        if (w == w0)
            va[a++] = v;
        else if (w == w1)
            vb[b++] = v;
        else if (w == w2)
            vc[c++] = v;
        else
            vd[d++] = v;
    }
    sort(va, va + N, greater<ll>());
    sort(vb, vb + N, greater<ll>());
    sort(vc, vc + N, greater<ll>());
    sort(vd, vd + N, greater<ll>());
    for (int i = 0; i < a; ++i) {
        pa[i + 1] = pa[i] + va[i];
    }
    for (int i = 0; i < b; ++i) {
        pb[i + 1] = pb[i] + vb[i];
    }
    for (int i = 0; i < c; ++i) {
        pc[i + 1] = pc[i] + vc[i];
    }
    for (int i = 0; i < d; ++i) {
        pd[i + 1] = pd[i] + vd[i];
    }
    for (int h = 0; h <= a; ++h) {
        for (int i = 0; i <= b; ++i) {
            for (int j = 0; j <= c; ++j) {
                for (int k = 0; k <= d; ++k) {
                    if (w0 * h + w1 * i + w2 * j + w3 * k <= m) {
                        ans = max(ans, pa[h] + pb[i] + pc[j] + pd[k]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#define M 1046527
#define NIL -1
#define L 14

char H[M][L];

int getChar(char ch){
  if(ch == 'A'){
    return 1;
  }
  else if(ch == 'C'){
    return 2;
  }
  else if(ch == 'G'){
    return 3;
  }
  else if(ch == 'T'){
    return 4;
  }
}

long long getKey(char str[]){
  long long sum = 0,p = 1,i;

  for(i = 0;i < strlen(str);i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }

  return sum;
}

int h1(int key){
  return key % M;
}

int h2(int key){
  return 1 + (key % (M - 1));
}

int find(char str[]){
  long long key,i,h;

  key = getKey(str);

  for(i = 0; ;i++){
    h = (h1(key) + i * h2(key)) % M;

    if(strcmp(H[h],str) == 0){
      return 1;
    }
    else if(strlen(H[h]) == 0){
      return 0;
    }
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;

  key = getKey(str);

  for(i = 0; ;i++){
    h = (h1(key) + i * h2(key)) % M;
    
    if(strcmp(H[h],str) == 0){
      return 1;
    }
    else if(strlen(H[h]) == 0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i,n,h;
  char str[L],com[9];

  for(i = 0;i < M;i++){
    H[i][0] = '\0';
  }
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%s %s",com,str);

    if(com[0] == 'i'){
      if(insert(str) == 1){

      }
    }
    else{
      if(find(str) == 1){
	printf("yes\n");
      }
      else{
	printf("no\n");
      }
    }
  }

  return 0;
}



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

using namespace std;

int main()
{
  int n; cin >> n;
  int mn = 300000, cnt = 0;
  for (int i = 0; i < n; ++i) {
    int p; cin >> p;
    if (p < mn) {mn = p; ++cnt;}
  }
  cout << cnt << endl;
}

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

int dh[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dw[8] = {0, 1, -1, 0, 1, -1, 1, -1};

int main() {
	int H,W;
	cin >> H >> W;
	vector<string> S(H);
	vector<vector<int>> c(H, vector<int>(W,0));

	rep(i,H)
		cin >> S.at(i);

	rep(i,H)
		rep(j,W)
			if(S.at(i).at(j) == '#')
				rep(k,8) {
					int nh=i+dh[k], nw=j+dw[k];
					if(nh>=H || nw>=W || nh<0 || nw<0 || S.at(nh).at(nw)=='#')
						continue;
					++c.at(nh).at(nw);
				}

	rep(i,H) {
		rep(j,W)
			if(S.at(i).at(j) == '.')
				cout << c.at(i).at(j);
			else
				cout << '#';
		cout << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define de(x) cerr<<#x<<"="<<x<<endl;

ll a[100001];
int ca[1000];
ll n,k;

int main(void){
    //001
    //110
    //011
    //100
    cin>>n>>k;
    rep(i,n)cin>>a[i];
    ll d=2;
    ll c=0;
    while(d<=k){
        d*=2;
        c++;
    }
    d/=2;
    rep(i,c+1){
        rep(j,n){
            //de(a[j])
            //de(i)
            //int temp=a[j]>>(c-i);
            //de(temp);
            if(a[j]>>(c-i) & 1)ca[i]++;
            else ca[i]--;
        }
    }
    ll x=0;
    rep(i,c+1){
        ll prev=x;
        if(ca[i]<0 && x+pow(2,c-i)<=k)x+=pow(2,c-i);
        //cout<<ca[i]<<endl;
    }
    //cout<<x<<endl;
    ll ans=0;
    rep(i,n)ans+=x^a[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string S;
	std::cin >> S;
	int result = 0;
	for (auto ch : S) {
		if (ch == '1')
			++result;
	}
	std::cout << result << "\n";
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define vpli vector<pair<long long, int>>
#define deb(x) cout <<"deb "<<#x<<" "<< x << endl;
#define all(x) x.begin(), x.end()
ll MOD = 1e9 + 7;
const int INF = 2e9 + 10;
void solve()
{
    string s;
    cin>>s;
    for(char &x : s) x = 'x';
    cout<<s;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3648
#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 all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)

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

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int main() {
  string s;
  cin >> s;
  vector<int> a(4,0);
  rep(i,4) a.at(i) = s.at(i) - '0';

  int res;
  rep(i,1<<3) {
    res = a.at(0);
    rep(j,3) {
      if(i>>j&1) res+=a.at(j+1);
      else res -= a.at(j+1);
    }
    if(res == 7) {
      string t=to_string(a.at(0));
      rep(j,3) {
        if(i>>j&1) t=t+"+"+to_string(a.at(j+1));
        else t=t+"-"+to_string(a.at(j+1));
      }
      t+="=7";
      cout << t << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000007;
const int mod=1000000007;
const int max_n=100000;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}
vi parent(max_n);
vi depth(max_n,0);
int root(int i){if(parent[i]==i)return i;return root(parent[i]);}
void heigou(int x,int y){
  x=root(x);y=root(y);
  if(x==y)return;
  if(depth[x]<depth[y])parent[x]=y;
  else if(depth[x]>depth[y])parent[y]=x;
  else{parent[y]=x;depth[x]++;}
}
int main(){
  int n,m,ans=0;cin>>n>>m;
  vi v;
  rep(i,parent.size())parent[i]=i;
  rep(i,m){
    int a,b,c;cin>>a>>b>>c;
    heigou(a-1,b-1);
  }
  rep(i,n){
    v.push_back(root(i));
  }
  sort(v.begin(),v.end());
  rep(i,n-1){
    if(v[i]!=v[i+1])ans++;
  }
  cout<<ans+1<<endl;
}

Measured memory_bytes: 2936
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

const int maxn=1e5+5;

int n,L,T,a[maxn],w[maxn],b[maxn];

int main()
{
	scanf("%d %d %d",&n,&L,&T);
	fo(i,1,n) scanf("%d %d",&a[i],&w[i]), w[i]=(w[i]==2) ?-1 :1;
	
	int tag=1;
	fo(i,1,n)
	{
		b[i]=(a[i]+T*w[i])%L;
		b[i]=(b[i]+L)%L;
		if (w[i]==1)
		{
			int t=T-(L-a[i]-1);
			if (t>0) tag+=(t%L==0) ?t/L :t/L+1 ;
			tag%=n;
		} else
		{
			int t=T-a[i];
			if (t>0) tag-=(t%L==0) ?t/L :t/L+1 ;
			tag%=n;
		}
	}
	
	sort(b+1,b+1+n);
	tag=(tag+n)%n;
	if (tag==0) tag=n;
	fo(i,1,n)
	{
		printf("%d\n",b[tag]);
		tag=(tag==n) ?1 :tag+1;
	}
}

Measured memory_bytes: 2304
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
const int SIZEN = 200010;
LL pw[SIZEN];
LL C[SIZEN];
int N;
int main(){
    scanf("%d",&N);
    pw[0] = 1;
    for(int i = 1;i <= N;i++)pw[i] = pw[i-1] * 2 % mod;
    for(int i = 1;i <= N;i++)scanf("%lld",&C[i]);
    sort(C+1,C+1+N);
    LL ans = 0;
    for(int i = 1;i <= N;i++){
        ans = (ans + C[i] * pw[i-1] % mod * pw[N]%mod * ( (N-i)  * pw[max(N-i-1,0)]%mod + pw[N-i] ) % mod ) % mod;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4852
from collections import deque
def main():
    n = int(input())
    a = [0] + list(map(int, input().split()))
    b = deque(maxlen=n+1)
    for i in range(1,n+1):
        if (i % 2 == 0 and n % 2 == 0 ) or (i % 2 != 0 and n % 2 != 0 ):
            b.appendleft(a[i])
        else:
            b.append(a[i])

    print(*b)

main()

Measured memory_bytes: 25536
H,W = map(int, input().split())

#迷路の初期化
a = [[-1] * (W+2) for i in range(H+2)]
for i in range(1,H+1):
    s = input()
    for j in range(1,W+1):
        if s[j-1] == ".":
            a[i][j] = 0
        elif s[j-1] == "#":
            a[i][j] = -1
        else:
            print("ERROR")

#dpの初期化
dp_sum = [[0] * (W+2) for i in range(H+2)]
#step
steplst =  [[] for i in range((H+W)+2)]
#stepdxy = [[1,0],[-1,0],[0,1],[0,-1]]
stepdxy = [[1,0],[0,1]]

def do_step(n):
    stepok = 0
    if n == 1:
        x,y = 1,1
        a[x][y] = -9
        for dx,dy in stepdxy:
            if a[x+dx][y+dy] == 0 or a[x+dx][y+dy] == n:
                dp_sum[x+dx][y+dy] += 1
                a[x+dx][y+dy] = n
                steplst[n].append([x+dx,y+dy])
                stepok = 1
    else:
        for x,y in steplst[n-1]:
            for dx,dy in stepdxy:
                if a[x+dx][y+dy] == 0:
                    dp_sum[x+dx][y+dy] += dp_sum[x][y]
                    a[x+dx][y+dy] = n
                    steplst[n].append([x+dx,y+dy])
                    stepok = 1
                elif a[x+dx][y+dy] == n:
                    dp_sum[x+dx][y+dy] += dp_sum[x][y]
    return stepok

stepn = 1
while do_step(stepn) == 1:
    #for i in range(len(dp_sum)):
    #    print(dp_sum[i],a[i])
    stepn += 1

print(dp_sum[H][W] % (10**9+7))

Measured memory_bytes: 306940