akhauriyash/Code-Regression huggingface dataset:
/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//  cout <<  s.at(1)-'0'-49  <<endl;
int main() {
  int n,x;
  cin >> n >> x;
  vector<int>m(n);
  rep(i,n) cin >> m.at(i);
  int nokori = x;
  rep(i,n) nokori -= m.at(i);
  int count=0;
  int mi = 1000000;
  rep(i,n) mi = min(mi,m.at(i) );
  int a = nokori / mi;   
  cout << a + n <<endl;

}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int i,N,A,B,temp,sum,rem,store=0;
    scanf("%d%d%d",&N,&A,&B);
    for(i=1;i<=N;i++)
    {
        temp=i;
        sum=0;
        while(temp!=0)
        {
            rem=temp%10;
            sum+=rem;
            temp/=10;
        }
        if(sum>=A && sum<=B)
        {
            store+=i;
        }
    }
    printf("%d\n",store);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int bikkuri[8] = {1,1,2,6,24,120,720,5040};

long dic(vector<int> c){
	int l = c.size();
	vector<bool> used(l);
	for(int i=0;i<l;++i){
		used[i] = false;
	}
	long res = 1;
	for(int i=0;i<l;++i){
		int k = c[i];
		int counter = 0;
		for(int j=0;j<k-1;++j){
			if(!used[j])counter++;
		}
		res += counter * bikkuri[l-i-1];
		used[k-1] = true;
	}
	return res;
}

int main(){
	int n;
	cin >> n;
	vector<int> p,q;
	for(int i=0;i<n;++i){
		int k;
		cin >> k;
		p.push_back(k);
	}
	for(int i=0;i<n;++i){
		int k;
		cin >> k;
		q.push_back(k);
	}
	cout << abs(dic(p) - dic(q)) << endl;
}

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

#define int long long
#define ll long long
#define vll vector<int>
#define mset(a) memset(a,0,sizeof(a))
#define pb push_back
#define range(c) c.begin() , c.end()
#define forn(i,n) for(ll i=0; i<(int)n; ++i)
#define for1(i,n) for(ll i=1; i<(int)n; ++i)
#define endl '\n'
#define MOD 1000000007
#define pii pair<int,int>
#define test ll t;cin>>t;while(t--)
using namespace std;

vector<bool> sieve(ll n){
    vector<bool>prime(n+1,true);
    prime[0]=prime[1]=false;
    for(ll i=2; i<=n; ++i){
        if(prime[i]&&(i*i)<=n)
        for(ll j=i*i; j<=n; j+=i)prime[j]=false;
    }
    return prime;
}

ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

//////////////////////////////////////////////////////////////

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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

    int n,m;
    cin>>n>>m;
    int res = n*(n-1) + m*(m-1);
    cout<<res/2<<endl;    

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
void dividing_student(int a, int b, int c);
 
int main(void)
{
    while(1){
        int n;/*n????????????????????°*/
        scanf("%d", &n);    
        if(n == 0){
            break;
        }else{
            for( int i = 0; i < n; ++i){
                int pm ,pe, pj; /*???????????°????????±????????????????????°*/
                scanf("%d %d %d", &pm, &pe, &pj);
                dividing_student( pm, pe, pj);
            }
        }
    }
    return 0;
}
 
void dividing_student( int a, int b, int c)
{
    if( a >= 100|| b >= 100 || c >=100){
        printf("A\n");
    }else if( (a + b) / 2 >= 90){
        printf("A\n");
    }else if( (a + b + c) / 3 >= 80){
        printf("A\n");
    }else if( (a + b + c) / 3 >= 70){
        printf("B\n");
    }else if((a + b + c) / 3 >= 50 && (a >= 80 || b >= 80)){
        printf("B\n");
    }else{
        printf("C\n");
    }
}    

Measured memory_bytes: 2484
#include <stdio.h>

int main(void)
{
	int W,H,x,y,r;

	scanf("%d", &W);
	scanf("%d", &H);
	scanf("%d", &x);
	scanf("%d", &y);
	scanf("%d", &r);
	
	if(0<=x-r && W>=x+r && H>=y+r && 0<=y-r){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define r(i,n) for(int i=0; i<n; i++)
#define rr(i,n) for(int i=1; i<n; i++)
typedef long long ll;
int main(void){
  int n, t;
  int k;
  int ans=0;

  int cnt=0;
  cin >> n >> t;
  vector<int> a(n,0);
  r(i,n){
    cin >> a[i];
  }
  rr(i,n){
      ans += min(a[i]-a[i-1], t);
  }
  cout << ans+t << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define INF 2000000001

int** init( int n ) {
  /*
   * 初期値INFのn次正方行列を作成する
   */
  int i, j;
  int** a;

  a = (int**)malloc( sizeof( int* ) * n );
  for( i=0; i<n; i++ ) {
    a[i] = (int*)malloc( sizeof( int ) * n );
  }

  for( i=0; i<n; i++ ) {
    for( j=0; j<n; j ++ ) {
      a[i][j] = INF;
    }
  }

  return a;

}

void scanGraph( int** g, int n ) {
  int i;  
  int u, k, v;
  
  
  while( scanf( "%d%d", &u, &k ) != EOF ) {
    
    for( i=0; i<k; i++ ) {
      scanf( "%d", &v );
      scanf( "%d", &g[u][v] );
    }
    
  }
  
  return;
  
}


int* ssspForCost( int** g, int n ) {

  int i;
  int *dist, color[n];
  int minDist, minVert, newVert;

  dist = (int*)malloc( sizeof( int ) * n );

  for( i=0; i<n; i++ ) {
    dist[i] = INF;
    color[i] = 0;
  }

  dist[0] = 0;
  color[0] = 1;
  newVert = 0;

  while( 1 ) {

    for( i=0; i<n; i++ ) {
      if( dist[ newVert ] + g[ newVert ][ i ] < dist[i] && color[i] == 0 ) {
	dist[i] = dist[ newVert ] + g[ newVert ][ i ];
      }
    }

    minDist = INF;
    for( i=0; i<n; i++ ) {
      if( dist[i] < minDist && color[i] == 0 ) {
	minDist = dist[i];
	minVert = i;
      }
    }

    if( minDist == INF ) {
      break;
    }

    dist[ minVert ] = minDist;
    color[ minVert ] = 1;
    newVert = minVert;

  }

  return dist;

}   

void printDist( int* dist, int n ) {
  int i;

  for( i=0; i<n; i++ ) {
    printf( "%d %d\n", i, dist[i] );
  }

  return;

}

int main() {
  int n;
  int** g;
  int* dist;

  scanf( "%d", &n );
  g = init( n );

  scanGraph( g, n );

  dist = ssspForCost( g, n );

  printDist( dist , n );

  return 0;

}

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

int main(void)
{
  int n, max1, a[5001];
  
  while(cin >> n, n) {
    for(int i = 0 ; i < n ; i++) {
      cin >> a[i];
    }
    max1 = a[0];
    
    /* ツ全ツ探ツ催オ */
    for(int i = 0 ; i < n ; i++) {
      int sum = 0;

      for(int j = i ; j < n ; j++) {
	sum += a[j];
	max1 = max( max1, sum);
      }
    }
    cout << max1 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
n,a,b = map(int, input().split())
i = 1
sum = 0
while ( i <= n ):
    l = list(str(i))
    s = 0
    for x in l:
        s = s + int(x)
    if a <= s and s <= b:
        sum = sum + i
    i = i + 1
print(sum)

Measured memory_bytes: 3060
a, b, k = map(int, input().split())
listN=range(a,b+1)
index=0
if k>len(listN):
    for number in listN:
        print(number)
else:
    listForP=[]
    index1=0
    while index<k:
        print(listN[index])
        listForP.append(listN[index])
        index+=1
    index2=len(listN)-k
    while index2<len(listN):
        if listN[index2] not in listForP:
            print(listN[index2])
        index2+=1

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i= 0; i <(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main()
{
    int n;
    cin >>n;
    map<string,int> cnt;
        rep(i,n){
        string s;
        cin>>s;
        cnt[s]++;
    }
    cout << "AC x " << cnt["AC"]<<endl;
    cout << "WA x " << cnt["WA"]<<endl;
    cout << "TLE x " << cnt["TLE"]<<endl;
    cout << "RE x " << cnt["RE"]<<endl;
       return 0;
}

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

int min( int a, int b )
{
    return a < b ? a : b;
}

int main()
{
    int n, a, b, c, d;

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

    a = n % a == 0 ? n / a * b : ( n / a + 1 ) * b;
    c = n % c == 0 ? n / c * d : ( n / c + 1 ) * d;
    
    cout << min( a, c ) << endl;

    return 0;
}


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

int main() {
  string a;
  cin >> a;
  if ( a.at(5) == '1') { 
    cout << "TBD" << endl;
  }else if ( a.at(6) > '4'){
    cout  << "TBD" << endl;
  }else cout << "Heisei" << endl;
}

  

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

#define pb push_back
#define rep(i, a, n) for(int (i)=a; (i)<(n); (i)++)
#define FOR(i, n) rep(i, 0, n)
#define F(n) FOR(i, n)
#define FF(n) FOR(j, n)
#define repi(i, a, n) for(int (i)=a; (i)<=(n); (i)++)
#define FORI(i, n) repi(i, 1, n)
#define FI(n) FORI(i, n)
#define FFI(n) FORI(j, n)
#define IN(x) int x; cin>>(x);
#define SIN(x) string x; cin>>x;
#define INN(x, y) int x, y; cin>>(x)>>(y);
#define INFO(a) cout<<"info "<<a<<endl
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define vpii vector<pair<int, int> >
#define sortv(x) sort((x).begin(), (x).end())
#define sortvd(x) sort((x).begin(), (x).end(), greater<int>())
#define lboundv(x,v) lower_bound((x).begin(),(x).end(),(v))-(x).begin();
#define uboundv(x,v) upper_bound((x).begin(),(x).end(),(v))-(x).begin();
#define ite iterator
#define fi first
#define se second
#define mems(a, v) memset((a), (v), sizeof((a)))
#define lmid(l, r) ((l)+(r)-1)/2
#define rmid(l, r) ((l)+(r))/2+1
#define mp make_pair

typedef long long ll;
typedef long double LD;

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	INN(n, k);
	ll ans=1;
	while(ans<=k && n--) {
		ans<<=1;
	}
	if(n>0) while(n--) ans += k;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var q = int.Parse(line[2]);
        var a = new int[n, n];
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var wh = int.Parse(line[0]) - 1;
            var ww = int.Parse(line[1]) - 1;
            a[wh, ww]++;
        }
        var b = setArray(a);
        for (int i = 0; i < q; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var p = int.Parse(line[0]) - 1;
            var p2 = int.Parse(line[1]) - 1;
            Console.WriteLine(getAns(b, p, p2));
        }
    }
    public static int getAns(int[,] a, int p, int q)
    {
        var n = a.GetLength(0);
        var wa = Math.Max(p, q);
        var wb = Math.Min(p, q);
        var a1 = 0; var a2 = 0; var a3 = 0; var a4 = 0;
        a1 = a[wa, wa];
        if (wb - 1 >= 0) { a4 = a[wb - 1, wb - 1]; a2 = a[wa, wb - 1]; a3 = a[wb - 1, wa]; }
        return a1 - a2 - a3 + a4;
    }
    public static int[,] setArray(int[,] a)
    {
        var n = a.GetLength(0);
        var t = new int[n, n];
        for (int i = 0; i < n; i++)
        {
            t[i, 0] = a[i, 0];
            for (int j = 1; j < n; j++)
                t[i, j] = t[i, j - 1] + a[i, j];
        }
        var t2 = new int[n, n];
        for (int i = 0; i < n; i++)
        {
            t2[0, i] = t[0, i];
            for (int j = 1; j < n; j++)
                t2[j, i] = t2[j - 1, i] + t[j, i];
        }
        return t2;
    }
}


Measured memory_bytes: 20508
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string sa,sb,sc;
    cin >> sa >> sb>> sc;
    int a,b,c;
    a = b = c = 0;
    char card=sa[0]; 
    a++;
    while(true){
        if(card == 'a'){
            if(a == sa.length()){
                cout << "A" << endl;
                break;
            }
            card = sa[a];
            a++;
        }
        else if(card == 'b'){
            if(b == sb.length()){
                cout << "B" << endl;
                break;
            }
            card = sb[b];
            b++;
        }
        else if(card == 'c'){
            if(c == sc.length()){
                cout << "C" << endl;
                break;
            }
            card = sc[c];
            c++;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n;
  double con=0;
  int a[101];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
  scanf("%d",&a[i]);
  }
  for(int j=0;j<n;j++){
    con += (double)1/a[j];
  }
  double ans = 1/con;
  printf("%lf\n",ans);
  return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        //値の取得
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        
        long count = 0;
        long max = 0;   //最大平方数
        
        while (true){
            if (count * count > N){
                System.out.println(max);
                System.exit(0);
            } else {
                max = count * count;
            }
            ++count;
        }

    }
}

Measured memory_bytes: 35828
#include <iostream>
using namespace std;
int main(){
    int H,W;
    cin >> H >> W;
    while(H!=0 && W!=0){
        for(int i=1; i<=H; i++){
            if(i%2!=0){
                for(int j=1; j<=W; j++){
                    if(j&2!=0){
                        cout << '#';
                    }
                    else if(j%2==0){
                        cout << '.';
                    }
                }
            }
            else if(i%2==0){
                    for(int j=1; j<=W; j++){
                        if(j&2!=0){
                            cout << '.';
                        }
                        else if(j%2==0){
                            cout << '#';
                        }
                    }
            }
            cout << "\n";
        }
        cout << "\n";
        cin >> H >> W;
    }
    if(H==0 && W==0){
        return 0;
    }
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(arr,n)       for(int i=0;i<n;i++)cin>>arr[i]
#define output(arr,n)      for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define for_each(arr)      for(auto& it:arr)cout<<it<<" "
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x)
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
    //#ifndef ONLINE_JUDGE
   // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
   // #endif
    cin>>a>>b;
    vector<int>v(a);
    for(int i=0;i<a;i++)cin>>v[i];
    sort(v.begin(),v.end());
    if(b>=a){
            cout<<0<<endl;
            return 0;
    }
    for(int i=0;i<a-b;i++){
        ans+=v[i];
    }
    cout<<ans<<endl;




    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}




Measured memory_bytes: 1024
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    l,r,d = IL()
    c = 0
    for rep in range(l,r+1):
        if rep%d==0:
            c += 1

    print(c)
    return

if __name__=='__main__':
    Main()

Measured memory_bytes: 27144
#include <iostream>
#include <vector>
#include <cstdlib>
 
using namespace std;
 
int main()
{  
    int N, K;
    cin >> N >> K;
	int min = ((N-1) / (K-1));
  	if( (N-1) % (K-1) > 0)
      min++;

  	cout << min << endl;    
    return 0;
}

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

int main(){
    long long n, a, b;
    cin >> n >> a >> b;

    if(a > b || a != b && n == 1){
        cout << 0 << endl;
        return 0;
    }

    cout << ((n-1)*b+a)-((n-1)*a+b)+1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  rep(i, N) cin >> H[i];
  sort(H.begin(), H.end());
  cout << int(H.end() - lower_bound(H.begin(), H.end(), K)) << endl;
  return 0;
}



Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int N,Q;
string s;
char t[200000],d[200000];
int check[200000];

//右に落ちるか左に落ちるか落ちないか判定する
int jud(int n){
  int pos = n;
  for(int i=0;i<Q;i++){
    char now = s[pos];
    if(t[i] == now){
      if(d[i] == 'L') pos--;
      if(d[i] == 'R') pos++;
    }
    if(pos == -1){
      return -1;
    } else if(pos == N){
      return 1;
    }
  }
  return 0;
}

int bsl(int a, int b){
  //cout << "l " << a << b << endl;
  int p = (a + b) / 2;
  if(check[p] == 2) check[p] = jud(p);

  if(check[p] == -1 && p == N-1) return p;
  else if((check[p]==0 || check[p]==1) && p==0) return -1;
  else if(check[p] == -1 && (check[p+1] == 0 || check[p+1] == 1)) return p;
  else if((check[p] == 0 || check[p] == 1) && check[p-1] == -1) return p-1;
  else if(check[p] == -1){
    return bsl(p+1,b);
  }
  else if(check[p] == 1 || check[p] == 0){
    return bsl(a,p-1);
  }
}

int bsr(int a, int b){
  //cout << "r " << a << b << endl;
  int p = (a + b + 1) / 2;
  if(check[p] == 2) check[p] = jud(p);

  if(check[p] == 1 && p == 0) return p;
  else if((check[p]==-1 || check[p]==0) && p==N-1) return -1;
  else if(check[p] == 1 && (check[p-1] == 0 || check[p-1] == -1)) return p;
  else if((check[p] == 0 || check[p] == -1) && check[p+1] == 1) return p+1;
  else if(check[p] == 1){
    return bsr(a,p-1);
  }
  else if(check[p] == -1 || check[p] == 0){
    return bsr(p+1,b);
  }
}

int main(){
  cin >> N >> Q;
  cin >> s;
  for(int i=0;i<Q;i++) cin >> t[i] >> d[i];

  //左右に落ちる部分を見つける
  fill(check,check+200000,2);//2は未定
  //cout << bsl(0,N-1) << endl;
  //cout << bsr(0,N-1) << endl;
  check[0] = jud(0);
  check[N-1] = jud(N-1);
  int l = bsl(0,N-1);
  int r = bsr(0,N-1);
  int ans = N;
  if(l != -1){
    ans -= l + 1;
  }
  if(r != -1){
    ans -= N - r;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1796
#include<bits/stdc++.h>
using namespace std;
int a[9],b[9],n,x;
int main()
{
	for(int i=0;i<9;++i) scanf("%d",&a[i]);
	scanf("%d",&n);
	while(n--){
		scanf("%d",&x);
		for(int i=0;i<9;++i){
			if(x==a[i]){
				b[i]=1;
				break;
			}
		}
	}
	for(int i=0;i<3;++i){
		if(b[i]&&b[i+3]&&b[i+6]){
			printf("Yes");
			return 0;
		}
		if(b[3*i]&&b[3*i+1]&&b[3*i+2]){
			printf("Yes");
			return 0;
		}
	}
	if(b[0]&&b[4]&&b[8]){
		printf("Yes");
		return 0;
	}
	if(b[2]&&b[4]&&b[6]){
		printf("Yes");
		return 0;
	}
	printf("No");
	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)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

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

  string white, black;
  rep(i,100) {
    white.push_back('.');
    black.push_back('#');
  }

  vector<string> GW(50), GB(50);
  rep(i,50) {
    GW[i] = white;
    GB[i] = black;
  }
  
  rep(i,a-1) GB[i/50*2+1][i%50*2] = '.';
  rep(i,b-1) GW[i/50*2][i%50*2] = '#';

  cout << "100 100" << endl;
  rep(i,50) cout << GW[i] << endl;
  rep(i,50) cout << GB[i] << endl;
  return 0;
}


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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int ,int>> vec1(n);
  vector<pair<int ,int>> vec2(m);
  for (auto &v : vec1) {
    int a, b;
    cin >> a >> b;
    v = make_pair(a, b);
  }
  for (auto &v : vec2) {
    int c, d;
    cin >> c >> d;
    v = make_pair(c, d);
  }

  for (int i = 0; i < n; ++i) {
    int a = vec1[i].first;
    int b = vec1[i].second;
    int ans = -1;
    int vmin = 1e9;
    for (int j = m - 1; 0 <= j; --j) {
      int c = vec2[j].first;
      int d = vec2[j].second;
      int tmp = abs(a - c) + abs(b - d);
      if (tmp <= vmin) {
        ans = j;
        vmin = tmp;
      }
    }
    cout << ans + 1 << endl;
  }
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int s[100000];
int issquare(int x, int y){
    return s[x]*s[y];
}
int main(){
    for(int i = 0; i*i < 30000; i++)
        for(int j = 0; j *j < 30000; j++){
            s[i*i+j*j] = 1;
        }
    int t;
    cin >> t;
    while(t--){
        int a, b;
        cin >> a >> b;
        int x = a*a+b*b, prime = 0;
        for(int i = 2; !prime && i < x; i++){
            if(x % i == 0){
                if(issquare(x/i, i))
                    prime = 1;
            }
        }
        if(prime)
            puts("C");
        else
            puts("P");
    }
    return 0;
}

Measured memory_bytes: 1352
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	fmt.Println(k * beki(k-1, n-1))
}

func beki(a int, b int) (r int) {
	r = 1
	for i := 0; i < b; i++ {
		r = r * a
	}
	return
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
bool N[102][102];
int map[102][102],R,ga,gb,w,h,f=0;
void block(int ,int);
int main()
{
	int i,n,c,d,X=0,Y=0,x,y;
	cin>>w>>h;
	while(w!=0||h!=0){
		memset(map,0,sizeof(map));
		memset(N,false,sizeof(N));
		cin>>X>>Y;
		cin>>ga>>gb;
		cin>>n;
		for(i=0;i<n;i++){
			cin>>c>>d>>x>>y;
			if(d){
				map[y][x]=c;
				map[y+1][x]=c;
				map[y+2][x]=c;
				map[y+3][x]=c;
				map[y][x+1]=c;
				map[y+1][x+1]=c;
				map[y+2][x+1]=c;
				map[y+3][x+1]=c;

			}
			else{
				map[y][x]=c;
				map[y+1][x+1]=c;
				map[y+1][x+2]=c;
				map[y+1][x+3]=c;
				map[y+1][x]=c;
				map[y][x+1]=c;
				map[y][x+2]=c;
				map[y][x+3]=c;

			}
		}
		R=map[Y][X];
		if(R==map[gb][ga]&&R!=0){
			block(Y,X);
			if(f==1) cout<<"OK"<<endl;
		        else cout<<"NG"<<endl;
		}
		else cout<<"NG"<<endl;
		//for(i=0;i<h;i++){
			//for(j=0;j<w;j++){
			//	cout<<map[i][j];
			//}
				
	//		cout<<endl;
		//}
		f=0;
		cin>>w>>h;
	}
	return 0;
}
void block(int b,int a)
{
	//if(f==1) return 1;
	N[b][a]=true;
	if(ga==a&&gb==b) f=1;
		if(map[b][a+1]==R&&N[b][a+1]==false) block(b,a+1); //???
		if(map[b+1][a]==R&&N[b+1][a]==false) block(b+1,a); //???
		if(map[b][a-1]==R&&N[b][a-1]==false) block(b,a-1); //???
		if(map[b-1][a]==R&&N[b-1][a]==false) block(b-1,a); //???
}

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

using namespace std;

int main()

{


    int a,k,l=0;

    //scanf("%d ",&k);

    while(1)
    {
        scanf("%d",&a);
        if(a==0)
            break;
        else

        printf("Case %d: %d\n",++l,a);
    }



    return 0;
}



Measured memory_bytes: 3164
#include <iostream>

int main(void) {
    int outlet_total = 0;
    int cnt = 0;
    int A;
    int B;

    std::cin >> A >> B;

    while(1) {  
        outlet_total = (A - 1) * cnt + 1;
        if (outlet_total >= B) {
            break;
        }
        cnt++;
    }

    std::cout << cnt << std::endl;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
	string S,T;
	cin>>S;
	cin>>T;
	if(S.size()!=T.size()){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<S.size();i++){
		bool flag=true;
		for(int j=0;j<S.size();j++){
			if(S[j]!=T[(i+j)%S.size()]){
				flag=false;
				break;
			}
		}
		if(flag){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

using namespace std;
#define ll long long
const int MAXN = 2e5 + 1;
int mass[301][301];
int ans[301][301];
int summcolomn[301];
vector<int> res;

void solve() {
    string s;
    int n;
    cin>>n>>s;
    for(int i=0;i<s.size();i++){
        s[i]='A'+(s[i]-'A'+n)%26;
    }
    cout<<s;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class BStringswiththeSameLength
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var st = Console.ReadLine().Split(' ');
            var s = st[0].ToCharArray();
            var t = st[1].ToCharArray();

            string ans = "";
            for (int i = 0; i < n; i++)
            {
                ans += s[i].ToString() + t[i].ToString();
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define pb push_back
using namespace std;
int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b;
	cin>>a>>b;
	ul c=a*b;
	if(c%2==0)
		cout<<"Even";
	else
		cout<<"Odd";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>
#include <cstdio>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
//priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

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

llint a,b,c;

void solve(){
  cin >> a >> b;
  int d,r;
  double f;
  d=a/b;
  r=a%b;
  f=a/(double)b;
  printf("%d %d %f\n",d,r,f);
}

int main() {
  solve();
  return 0;
}



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

#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define rrep(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,n) rep(i,0,n)
#define RREP(i,n) rrep(i,n,0)

int main()
{
    int n;
    cin>>n;
    vector<pair<pair<string,int>,int>> all;
     REP(i,n)
   {
       string s;
       int p;
       cin>>s>>p;
       all.push_back(make_pair(make_pair(s,-p),i+1));
   }
    sort(all.begin(),all.end());
    REP(i,n)
    {
        cout<<all.at(i).second<<endl;
    }

}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
ll n,ans;
ll a[200001];
int main(){
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		a[i]-=i;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		ans+=abs(a[i]-a[n/2]);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1664
"""B - Can you solve this?"""
N,M,C=(int(i) for i in input().split())
B=[int(i) for i in input().split()]
result=0
for i in range(N):
    A=[int(i) for i in input().split()]
    comp=C
    for j in range(M):
        comp+=A[j]*B[j]
    if comp>0:
        result+=1
print(result)

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int sgn(int x) { return (x > 0) - (x < 0); }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int A,B,C,K;
    cin>>A>>B>>C>>K;
    int cnt=0;
    while(B<=A){B*=2,cnt++;}
    while(C<=B){C*=2,cnt++;}
    if(cnt<=K)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
int a[114514],b[114514];
signed main(){
	ic(m) ic(n)
	int wa=0,ac=0;
	rep(0,i,n){
		ic(p)
		sc(s)
		if(b[p]==114514)continue;
		if(s=="AC"){
			b[p]=114514;
			ac++;
			wa+=a[p];
		}
		else a[p]++;
	}
	cout<<ac<<" "<<wa<<endl;
}	

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int H,W,N;
int a[201][201];
int A[201][201];

inline int calc(int h,int w,int H,int W){
  return A[H][W]-A[H][w]-A[h][W]+A[h][w];
}

bool solve(int h,int w,int H,int W,int N,int M){
  if(calc(h,w,H,W)<M*N)return false;
  if(N==1)return true;
  for(int i=h+1;i<H;i++){
    if(calc(h,w,i,W)<M)continue;
    if(solve(i,w,H,W,N-1,M))return true;
    break;
  }
  for(int j=w+1;j<W;j++){
    if(calc(h,w,H,j)<M)continue;
    if(solve(h,j,H,W,N-1,M))return true;
    break;
  }
  for(int i=H-1;i>h;i--){
    if(calc(i,w,H,W)<M)continue;
    if(solve(h,w,i,W,N-1,M))return true;
    break;
  }
  for(int j=W-1;j>w;j--){
    if(calc(h,j,H,W)<M)continue;
    if(solve(h,w,H,j,N-1,M))return true;
    break;
  }
  return false;
}

bool check(int nv,int sv,int M){
  int ev=0,wv=0;
  while(calc(0,0,wv,nv)<M){
    wv++;
    if(wv>=H)return false;
  }
  while(calc(0,nv,ev,W)<M){
    ev++;
    if(ev>=H)return false;
  }
  if(sv<nv)ev=max(ev,wv);
  if(sv>nv)wv=max(ev,wv);
  if(calc(wv,0,H,sv)<M)return false;
  if(calc(ev,sv,H,W)<M)return false;
  return true;
}

bool check(int M){
  if(N==4)
    for(int nv=1;nv<W;nv++)
      for(int sv=1;sv<W;sv++)
        if(check(nv,sv,M))return true;
  return solve(0,0,H,W,N,M);
}

int compute(){
  int L=0,R=200000001,M;
  while(R-L>1){
    M=(L+R)/2;
    if(check(M))L=M;
    else R=M;
  }
  return L;
}

int main(){
  scanf("%d %d %d",&H,&W,&N);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      scanf("%d",&a[i][j]);
      A[i+1][j+1]=a[i][j]+A[i+1][j]+A[i][j+1]-A[i][j];
    }
  }
  int ans=compute();
  printf("%d\n",ans);
  return 0;
}

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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

int main(){
	setIO();
	string a, b; cin >> a >> b;
	int ct = 0;
	for (int i = 0; i < (int)a.size(); i++){
		if (a[i] != b[i]) ct++;
	}
	cout << ct << endl;
}

Measured memory_bytes: 3780
import itertools
def distance(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5
n = int(input())
a = [tuple(map(int,input().split())) for _ in range(n)]
l = []
for m in list(itertools.permutations(a)):
    d = 0
    for i in range(n-1):
        d += distance(m[i],m[i+1])
    l.append(d)
print(sum(l)/len(l))

Measured memory_bytes: 15816
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var X = sc.nextInt();
        long sum = 0;
        for (int i = 1; true; i++) {
            sum += i;
            if (X <= sum) {
                WriteLine(i);
                return;
            }
        }
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {

        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}

Measured memory_bytes: 11092
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                                              NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
//----------------------------------------------------------------------------------------------------------------------------------------------------

#define mod 1000000007
int main()
{
	fast;
	ll n,k;
    cin>>n>>k;
    ++n;
	ll sum = 0;
	vector<ll> prefix(n,0);
	vector<ll> suffix(n,0);
	for(int i=1;i<n;i++)
		prefix[i] = prefix[i-1] + i;
	suffix[n-1] = n-1;
	for(int i=n-2;i>=0;i--)
		suffix[i] = suffix[i+1] + i;
	for(int i=k;i<=n;i++)
    {
        //debug4(i-1,n-i,suffix[n-i],prefix[i-1])
        sum = (sum + suffix[n-i] - prefix[i-1] + 1) % mod;
    }
	cout<<sum;
 	return 0;
}


Measured memory_bytes: 6364
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	VI A(N);
	int ma = 0;
	REP(i, N) {
		cin >> A[i];
		chmax(ma, A[i]);
	}
	rSORT(A);
	int sum1[80] = { 0 };
	int sum0[80] = { 0 };
	int ans = 0;

	REP(j, N) {
		int a = A[j];
		int i = 0;
		while (i <= 60) {
			if (a % 2 == 0) {
				//cout << A[i] << " " << i <<" "<< (1 << i)*sum[i] << endl;
				ans += (((1LL << i)%mod)*sum1[i])%mod;
				ans %= mod;
				//cout << (1LL<<i)<<" "<<ans << " " << a << endl;
			}
			else {
				ans += (((1LL << i)%mod)*sum0[i])%mod;
				ans %= mod;
				//cout << ans << " " << a << endl;
			}
			if ((1LL << i) <= ma) {
				//cout << (1 << i) << endl;
				if (a % 2) {
					sum1[i]++;
				}
				else {
					sum0[i]++;
				}
			}

			a /= 2;
			i++;
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    const int K = 4;
    vector<vector<int>> dp(n+1, vector<int>(K + 1, -1));
    
    dp[0][0] = 0;
    rep(i, n) {
        for(int j = 0; j <= K; j++) {
            if(dp[i][j] == -1) {
                continue;
            }
            for(int k = 1; k <= K && i + k <= n; k++) {
                if( j != k || s.substr(i - j, j) != s.substr(i, k) ) {
                    dp[i + k][k] = max(dp[i + k][k], dp[i][j] + 1);
                }
            }
        }
    }

    int ans = 0;
    for(int j = 0; j <= K; j++) {
        ans = max(ans, dp[n][j]);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11396
#include<bits/stdc++.h>
using namespace std;
const int nmax=100005;
vector<vector<int>> g(nmax);
int f(int s){
  int res=g[s].size();
  vector<int> v;
  for(int i=0;i<g[s].size();i++){
    v.push_back(f(g[s][i]));
  }
  sort(v.begin(),v.end(),greater<int>());
  for(int i=0;i<g[s].size();i++){
    res=max(res,v[i]+i+1);
  }
  return res;
}
int main(){
  int n;cin >> n;
  for(int i=1;i<n;i++){
    int a;cin >> a;
    a--;
    g[a].push_back(i);
  }
  cout << f(0) << endl;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n;
  cin >> n;
  vector<LL> p(n);
  for(LL &x:p) cin >> x;
  vector<LL> cp(p.begin(),p.end());
  sort(cp.begin(),cp.end());
  LL dif = 0;
  REP(i,p.size()) if(p[i]!=cp[i]) ++dif;
  cout << (dif<=2?"YES":"NO") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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; }

string s, t;

int main(void){
	cin >> s >> t;
	vector<lli> cs(26), ct(26);
	for(auto si : s) cs[si-'a']++;
	for(auto ti : t) ct[ti-'a']++;
	sort(cs.begin(), cs.end());
	sort(ct.begin(), ct.end());
	rep(i, 26){
		if(cs[i] != ct[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3904
#include<bits/stdc++.h>
using namespace std;
#define w(t) int t;cin>>t;while(t--)
#define pb   push_back
#define mk   make_pair
typedef long long ll;
const ll mod=1e9+7;
int dp[3005][3005];

string getLCS(string &s,string &t,int len){
	string LCS;
	int i=0,j=0;
	while(len>0){
		if(s[i]==t[j]){
			LCS.push_back(s[i]);
			i++;
			j++;
			len--;
		}else{
			if(dp[i][j+1]>dp[i+1][j])j++;
			else
				i++;
		}
	}
	return LCS;
}


int lenLCS(string &s,string &t,int i,int j){
   
   if(i==s.size())return 0;
   else if(j==t.size())return 0;
   
   if(dp[i][j]!=-1)return dp[i][j];
   if(s[i]==t[j]){
   	  dp[i][j]=1+lenLCS(s,t,i+1,j+1);
   }else{
   	  dp[i][j]=max({lenLCS(s,t,i+1,j),lenLCS(s,t,i,j+1)});
   }
   return dp[i][j];
}

string solve(string s,string t){
   memset(dp,-1,sizeof dp);
   int len=lenLCS(s,t,0,0);
    return getLCS(s,t,len);
}

int main()
{

	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr); 
	cout.tie(nullptr);
    string s,t;
    cin>>s>>t;
    cout<<solve(s,t);
   
    return 0;
  
}

Measured memory_bytes: 36096
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string t = "MARCH";
    int n;
    cin >> n;
    map<char, ll>mp;
    while(n--)
    {
        string s;
        cin >> s;
        ++mp[s[0]];
    }
    ll ans = 0;
    for(int i = 0;i < t.size();++i)
        for(int j = i + 1;j < t.size();++j)
            for(int k = j + 1;k < t.size();++k)
                ans += mp[t[i]] * mp[t[j]] * mp[t[k]];
    cout << ans;
    return 0;
}


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

const int maxn=200005;
const int mod=998244353;
int n,diam,s,t,ans;
vector<int>edge[maxn];
int dep[maxn],par[maxn],dp[maxn][3][3],ndp[3][3];
bool leaf[maxn];
void Add(int &a,int b){
	a+=b;
	if(a>=mod)a-=mod;
}

void predfs(int x,int p,int d){
	par[x]=p;
	dep[x]=d;
	for(int i=0;i<int(edge[x].size());i++)
		if(edge[x][i]!=p)predfs(edge[x][i],x,d+1);
}
void dfs(int x,int p,int d){
	if(d==diam/2)leaf[x]=true;
	dp[x][0][0]=1;
	for(int i=0;i<int(edge[x].size());i++){
		int y=edge[x][i];
		if(y==p)continue;
		dfs(y,x,d+1);
		for(int a=0;a<3;a++)for(int b=0;b<3;b++)ndp[a][b]=0;
		for(int a=0;a<3;a++)for(int b=0;b<3;b++)if(dp[x][a][b])
			for(int c=0;c<3;c++)for(int d=0;d<3;d++)if(dp[y][c][d]){
				int cur=1LL*dp[x][a][b]*dp[y][c][d]%mod;
				if(leaf[y]){
					Add(ndp[min(2,a+1)][b],cur);
					Add(ndp[a][b],cur);
					Add(ndp[a][min(2,b+1)],cur);
				}
				else{
					Add(ndp[min(2,a+c)][b],cur);
					Add(ndp[a][b],cur);
					Add(ndp[a][min(2,b+d)],cur);
				}
			}
		for(int a=0;a<3;a++)for(int b=0;b<3;b++)dp[x][a][b]=ndp[a][b];
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	predfs(1,0,0);
	for(int i=1;i<=n;i++)if(!s||dep[i]>dep[s])s=i;
	predfs(s,0,0);
	for(int i=1;i<=n;i++)if(!t||dep[i]>dep[t])t=i;
	diam=dep[t];
	int u=t;
	for(int i=1;i<=diam/2;i++)u=par[u];
	if(diam%2==0){
		dfs(u,0,0);
		ans=dp[u][1][1];
	}
	else{
		int v=par[u];
		dfs(u,v,0);
		dfs(v,u,0);
		int ansu=(1LL*dp[u][0][1]+dp[u][1][1]+dp[u][2][1])%mod;
		int ansv=(1LL*dp[v][1][0]+dp[v][1][1]+dp[v][1][2])%mod;
		ans=2LL*ansu%mod*ansv%mod;
	}
	printf("%d\n",1LL*ans*(mod+1)/2%mod);
	return 0;
}

Measured memory_bytes: 28544
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef int64_t ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll mx = 0;
  for (auto& v : a) {
    if (v > 0) mx += v;
  }

  ll ans = 0;
  ll tmp1 = 0;  // 長さ k の区間で正の数だけ黒にした
  ll tmp2 = 0;  // 長さ k の区間で全部黒の場合
  rep(i, k) {
    if (a[i] > 0) tmp1 += a[i];
    tmp2 += a[i];
  }

  chmax(ans, mx - tmp1 + tmp2);
  chmax(ans, mx - tmp1);

  for (int i = k; i < n; i++) {
    if (a[i-k] > 0) tmp1 -= a[i-k];
    tmp2 -= a[i-k];

    if (a[i] > 0) tmp1 += a[i];
    tmp2 += a[i];

    chmax(ans, mx - tmp1 + tmp2);
    chmax(ans, mx - tmp1);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024