akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#ifndef LIB_REPEAT_HPP
#define LIB_REPEAT_HPP
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#define repeat_from(i,m,n) for (int i = (m); i < (n); ++i)
#define repeat_one(i,n) for (int i = 1; i <= (n); ++i)
#define repeat_rev(i,n) for (int i = (n)-1; 0 <= i; --i)
#define foreach(it, cont) for (decltype(cont.begin()) it = cont.begin(); it != cont.end(); ++it)
#endif
using namespace std;
struct point { int x, y; };
bool operator < (const point & a, const point & b) { return a.x != b.x ? a.x < b.x : a.y < b.y; }
const point directions[] = { { 0, 1 }, { 0, -1 }, { -1, 0 }, { 1, 0 } };
point operator + (const point & a, const point & b) { return (point) { a.x + b.x, a.y + b.y }; }
struct cell { int x, y, cost; };
bool operator < (const cell & a, const cell & b) { return not (a.cost < b.cost); } // reversed
int main() {
    ios_base::sync_with_stdio(false);
    while (true) {
        int W, H; cin >> W >> H; cin.ignore();
        if (W == 0 and H == 0) break;
        vector<string> m(2*H-1);
        repeat (h,2*H-1) {
            getline(cin, m[h]);
            if (m[h].length() < 2*W-1) m[h] += ' ';
        }
        priority_queue<cell> que; que.push((cell) { 0, 0, 1 });
        set<point> used;
        int result = 0;
        while (not que.empty()) {
            const cell c = que.top(); que.pop();
            if (c.x == W-1 and c.y == H-1) {
                result = c.cost;
                break;
            }
            if (used.count((point) { c.x, c.y })) continue;
            used.insert((point) { c.x, c.y });
            repeat (d,4) {
                const point e = (point) { c.x, c.y } + directions[d];
                if (0 <= e.x and e.x < W and 0 <= e.y and e.y < H) {
                    if (m[c.y+e.y][c.x+e.x] == '0' and not used.count(e)) {
                        que.push((cell) { e.x, e.y, c.cost+1 });
                    }
                }
            }
        }
        cout << result << endl;
    }
    return 0;
}

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

int main(){
    int A,B,C,X;
    cin >> A >> B >> C >> X;
    int res=0;
    
    for (int i = 0; i < A+1; i++)
    {
        for (int j = 0; j < B+1; j++)
        {
            for (int k = 0; k < C+1; k++)
            {
                if(((500*i)+(100*j)+(50*k))==X) res++;
            }           
        }      
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;

typedef struct {
    int parent;
    int left_child;
    int right_child;
    int num_children;
    int depth;
    int height;
    string type;
} Node;

int calcDepthHeight( int id, int depth );
void print( int id );

#define MAX_N (30)
#define NIL (-1)
Node node[MAX_N];
int n;
int root_id;

int main()
{

    scanf("%d", &n);

    // ?????????
    for ( int i = 0; i < n; i++ ) {
	node[i].parent = NIL;
	node[i].type = "internal node";
	node[i].height = NIL;
    }
    
    for ( int i = 0; i < n; i++ ) {
	int id, left, right;
	int num_children = 0;
	scanf("%d %d %d", &id, &left, &right);

	node[id].left_child = left;
	node[id].right_child = right;
	if ( left != NIL ) {
	    node[left].parent = id;
	    num_children++;
	}
	if ( right != NIL ) {
	    node[right].parent = id;
	    num_children++;
	}
	node[id].num_children = num_children;
	if ( num_children == 0 ) { // ???
	    node[id].type = "leaf";
	    node[id].height = 0;
	}
    }

    // ????????¢???
    for ( int i = 0; i < n; i++ ) {
	if ( node[i].parent == NIL ) {
	    root_id = i;
	    node[i].type = "root";
	    break;
	}
    }

    calcDepthHeight( root_id, 0 );

    for ( int i = 0; i < n; i++ ) {
	print( i );
    }

    return 0;
}


int calcDepthHeight( int id, int depth )
{
    node[id].depth = depth;
    if ( node[id].height != NIL ) {
	return node[id].height;
    }
    else {			// ??????height????±????????????????
	int height = 0;
	if ( node[id].left_child != NIL ) {
	    height = max( height, 1 + calcDepthHeight( node[id].left_child, depth + 1 ) );
	}
	if ( node[id].right_child != NIL ) {
	    height = max( height, 1 + calcDepthHeight( node[id].right_child, depth + 1 ) );
	}
	node[id].height = height;

	return height;
    }
}


void print( int id )
{
    printf("node %d: ", id);
    printf("parent = %d, ", node[id].parent);
    if ( node[ node[id].parent ].num_children > 1 ) {
	if ( node[node[id].parent].left_child == id ) {
	    printf("sibling = %d, ", node[node[id].parent].right_child);
	}
	else {
	    printf("sibling = %d, ", node[node[id].parent].left_child);
	}
    }
    else {
	printf("sibling = -1, ");
    }
    printf("degree = %d, ", node[id].num_children);
    printf("depth = %d, ", node[id].depth);
    printf("height = %d, ", node[id].height);
    printf("%s\n", node[id].type.c_str());
}

Measured memory_bytes: 1072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> t(n);
	vector<int> x(n);
	vector<int> y(n);
	rep(i,n) cin >> t.at(i) >> x.at(i) >> y.at(i);
	int curx=0,cury=0,curt=0,X,Y;
	rep(i,n){
		X=abs(curx-x.at(i));
		Y=abs(cury-y.at(i));
		if(X+Y>t.at(i)-curt || (t.at(i)-curt)%2!=(X+Y)%2){
			cout << "No" << endl;
			return 0;
		}
		curx=x.at(i);
		cury=y.at(i);
		curt=t.at(i);
	}
	cout << "Yes" << endl;
}

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

int N,prime[10010],k,f;

int main(){
  for(int i=1;i<=10000;i++){
    prime[i]=0;
  }///初期化
  prime[2]=1;
  for(int i=3;i<=10000;i++){
    f=2;
    while(i % f != 0){f++;};
    if(f==i){prime[i]=1;}
  };///素数判定
  while(scanf("%d",&N)==1){
    k=0;
    for(int i=1;i<=N;i++)
      {
	if(prime[i]==1&&prime[N-i+1]==1){
	  k++;}
      };
    printf("%d\n",k);
  }

}

Measured memory_bytes: 1224
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  dl R;
  ci(R);
  sp(10);
  co(R * 6.28318530717958623200);
}

Measured memory_bytes: 3780
import math
from itertools import accumulate

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n,m = map(int,input().split())

A = list(map(int,input().split()))


accum_A = [0] + A
accum_A = list(accumulate(accum_A))

mod_dic = {}

for i in accum_A:
    mod = i%m
    
    if mod in mod_dic.keys():
        mod_dic[mod] += 1
    else:
        mod_dic[mod] = 1

ans = 0
    
for i in mod_dic.values():
    if i >= 2:
        ans += combinations_count(i,2)
    
print(ans)



Measured memory_bytes: 17740
S=input()
if (S[0]==S[1] and S[2]==S[3]) or (S[0]==S[2] and S[1]==S[3]) or (S[0]==S[3] and S[1]==S[2]):
    if S[0]==S[1]==S[2]==S[3]:
        print('No')
    else:
        print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n-1)

	for i := range a {
		a[i] = nextInt() - 1
	}
	for i := range b {
		b[i] = nextInt()
	}
	for i := range c {
		c[i] = nextInt()
	}
	ans := 0
	for i := range a {
		debugf("a: %d:%d, %d\n", a[i], b[a[i]], ans)
		ans += b[a[i]]
		if i > 0 && a[i-1]+1 == a[i] {
			debugf("b: %d:%d, %d\n", a[i-1], c[a[i-1]], ans)
			ans += c[a[i-1]]
		}
	}

	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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

__attribute__ ((constructor))
void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

int main(){
    int k, t;
    cin >> k >> t;
    int max_ = 0;
    rep(i,t){
        int x;
        cin >> x;
        chmax(max_, x);
    }
    if(max_ <= (k+1)/2){
        cout << 0 << endl;
    }else{
        cout << max(max_ - 1 - (k - max_),0) << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    ll a, b;
    cin >> n >> a >> b;
    a -= b;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    int l = 0, r = 1e9;
    while (l + 1 < r) {
        int m = (l + r) / 2;
        ll k = 0;
        for (int i = 0; i < n; ++i) {
            k += max((h[i] - b * m + a - 1) / a, 0LL);
        }
        if (k > m) {
            l = m;
        } else {
            r = m;
        }
    }
    cout << r;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int x;
    long long int ans=0;
    cin >> x;
    
    ans += x/500 * 1000;
    x %= 500;
    ans += x/5 * 5;
    x %= 5;

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]){
		
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			
			int h = Integer.parseInt(sc.next());
			int w = Integer.parseInt(sc.next());
			
			if(h == 0 && w == 0){
				break;
			}
			
			for(int i = 0; i< h ;i++){
				
				for(int j = 0; j<w; j++){
					
					System.out.print("#");
				}
				
				System.out.println("");
			}
			
			System.out.println("");
			
		}
		
		
		sc.close();
		
	}

}



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

set<pair<int, int>> S;
int cntH[300001];
int cntW[300001];

int32_t main()
{
    int h, w, m;
    cin >> h >> w >> m;
    for (int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        S.insert(make_pair(a, b));
        ++cntH[a];
        ++cntW[b];
    }
    vector<pair<int, int>> more;
    vector<int> Hs, Ws;
    int maxH = 0, maxW = 0;
    for (int i = 1; i <= h; ++i)
    {
        maxH = max(maxH, cntH[i]);
    }
    for (int i = 1; i <= w; ++i)
    {
        maxW = max(maxW, cntW[i]);
    }
    for (int i = 1; i <= h; ++i)
    {
        if (cntH[i] == maxH)
            Hs.emplace_back(i);
    }
    for (int i = 1; i <= w; ++i)
    {
        if (cntW[i] == maxW)
            Ws.emplace_back(i);
    }
    bool fnd = 0;
    for (int i = 0; i < Hs.size() && !fnd; ++i)
    {
        for (int j = 0; j < Ws.size() && !fnd; ++j)
        {
            if (S.find(make_pair(Hs[i], Ws[j])) == S.end())
                fnd = 1;
        }
    }
    if (fnd)
        cout << maxH + maxW << '\n';
    else
        cout << maxH + maxW - 1 << '\n';
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<ll> Vec;
typedef vector<vector<ll>> Mat;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD =  1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,d;
    cin>>n>>d;
    Mat mat(n);
    rep(i,n){
        Vec w(d);
        rep(j,d){
            cin>>w[j];
        }
        mat[i]=w;
    }

//    dbg(mat);
    ll ans = 0;
    rep(i,n){
        REP(j,i+1,n){
            ll x=0;
            rep(k,d){
                 x += (mat[i][k]-mat[j][k])* (mat[i][k]-mat[j][k]);
            }
            double db = sqrt(x);
            double chk = db - (int) db;
            if(chk<=0.000000001&& chk >= -0.000000001){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    cin >> n;
    vector<int> ans(n + 1, 0);
    for (int i = 2; i <= n; i++) {
        int ai;
        cin >> ai;
        ans[ai] += 1;
    }
    for (int i = 1; i <= n; i++)  cout << ans[i] << endl;
}


Measured memory_bytes: 4000
from collections import Counter,defaultdict
n,m=map(int,input().split())
X=tuple(map(int,input().split()))
C=Counter(X)
Pairs=defaultdict(int)
Modcnt=defaultdict(int)
for k,v in C.items():
    Pairs[k%m]+=v//2
    Modcnt[k%m]+=v
ans=0
for i in range(m//2+1):
    if i==0 or i==m-i:
        ans+=Modcnt[i]//2
    else:
        if Modcnt[i]>=Modcnt[m-i]:
            k,l=i,m-i
        else:
            k,l=m-i,i
        a,b=Modcnt[k],Modcnt[l]
        ans+=b
        a-=b
        ans+=min(Pairs[k],a//2)
print(ans)

Measured memory_bytes: 84968
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;cin>>n;
	vector<int> v(n);
	int avg = 0;
	for(int i = 0; i < n; i++) {
		cin>>v[i];
		avg += v[i];
	}
	avg /= n;
	int avg2 = avg + 1;
	int ans = 0;
	int ans2 = 0;
	for(int i = 0; i < n; i++) {
		ans += ((v[i] - avg) * (v[i] - avg));
		ans2 += ((v[i] - avg2) * (v[i] - avg2));
	}
	cout << min(ans,ans2) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define X first
#define Y second
#define fw(i, start, end) for (ll i = start; i < end; ++i)
#define fe(i, start, end) for (ll i = start; i <= end; ++i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define endl "\n"
int main()
{
    FASTIO
    ll n;
    cin>>n;
    ll t=n%10;
    if(t==2||t==4||t==5||t==7||t==9)
    cout<<"hon"<<endl;
    if(t==0||t==1||t==6||t==8)
    cout<<"pon"<<endl;
    
    if(t==3)
    cout<<"bon"<<endl;
    

    return 0;
}

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
  string S ;
  cin >> S ;
  int ans=0;
  int N = S.size() ;
  vector<int> A(N) ;
  rep(i,N)  A.at(i) = ctoi( S.at(i) );
  rep(i,N)  ans += A.at(i) ;
  int B = stoi(S) ;
  if( B%ans == 0 ) cout <<  "Yes" << endl;
  else cout << "No" << endl ;
}


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

#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define allr(v) v.rbegin(),v.rend() 
//#define endl '\n'  
typedef  long long ll; 
typedef  unsigned long long ull; 
typedef vector< ll > edge; 
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <ll, vector<ll>, greater<ll> > min_heap;
const ll mod=1000000007;
const ll inf=1e15;
const ll N=2e5+10;

int main()
{
  boost;
  ll r,d,x;
  cin>>r>>d>>x;
  for(ll i=0;i<10;i++)
  {
  	x=r*x-d;
  	cout<<x<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int gcd(int a, int b)
{
    if (b == 0)
        return a;

    return gcd(b, a % b);
}

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

int N, X;
int x[101010];
int diff[101010];

int main()
{
    cin >> N >> X;
    rep(i, 0, N)
    {
        cin >> x[i];
    }
    x[N] = X;
    sort(x, x + N + 1);
    rep(i, 0, N)
    {
        diff[i] = x[i + 1] - x[i];
    }
    int D = gcd(diff[0], diff[1]);
    rep(i, 2, N)
    {
        D = gcd(D, diff[i]);
    }
    cout << D << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int X, Y, S;
int tax(int a, int b) {
	return a*(100+b)/100;
}
int max(int m,int s) {
	if (m >s) return m;
	else return s;
}
int solve() {
	int ma = 0;
	for (int i = 1; i < S;i++) {
		for (int j = 1; j < S;j++) {
			if (tax(i,X)+tax(j,X) == S ) {
				ma = max( ma, tax(i,Y)+tax(j,Y) );
				//cout << i << " " << j << " " << tax(i,Y) << " " << tax(j,Y) << endl;
			}
		}
	}
	return ma;
}
int main(){
	while (cin >> X >> Y >> S && X > 0 ) {
		cout << solve() << endl;
	}
}

Measured memory_bytes: 1160
def main():
    S = input()
    a = ["1" if i % 2 == 0 else "0" for i in range(len(S))]
    b = ["0" if i % 2 == 0 else "1" for i in range(len(S))]
    if comparison(S, a) <= comparison(S, b):
        print(comparison(S, a))
    else:
        print(comparison(S, b))


def comparison(S, n):
    count = 0
    for i in range(len(S)):
        if not n[i] == S[i]:
            count += 1
    return count


if __name__ == "__main__":
    main()


Measured memory_bytes: 4724
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    import bisect
    mod=10**9+7
    N,K=MI()
    A=LI()
    pos=[]
    zero=[]
    nega=[]
    for i in range(N):
        if A[i]>0:
            pos.append(A[i])
        elif A[i]==0:
            zero.append(A[i])
        else:
            nega.append(A[i]*-1)
            
    np=len(pos)
    nz=len(zero)
    nn=len(nega)
    
    pos.sort()
    zero.sort()
    nega.sort()
    
    inf=10**18 + 1
    
    #全部正で考える
    
    if K<=np * nn:
        # 答えが負になるパターン
        # 正の数で考えるので大きい方からK番目を考える
        # 二分探索*2
        # X以上になるものが，初めてK個以上になったタイミングが答え
        
        def ch(x):
            cnt=0
            for p in pos:
                t=(x+p-1)//p
                num=bisect.bisect_left(nega,t)
                cnt+=nn-num
            return cnt>=K
                
        
        ok=0
        ng=inf
        while ng-ok>1:
            x=(ok+ng)//2
            if ch(x):
                ok=x
            else:
                ng=x
        
        print(ok*-1)
        
    elif K<= np*nn + nz*(N-nz) + (nz*(nz-1))//2:
        print(0)
        
    else:
        # 答えが正になるパターン
        # 大きい方からK2= (N*(N-1))//2 - K番目を考える
        # 二分探索*2
        # X以上になるものが，初めてK2個以上になったタイミングが答え
        K2=(N*(N-1))//2 - K + 1
        # print(K2)
        
        def ch(x):
            cnt=0
            for p in pos:
                t=(x+p-1)//p
                num=bisect.bisect_left(pos,t)
                rem=np-num
                if t<=p:
                    rem-=1
                cnt+=rem
                
            for ne in nega:
                t=(x+ne-1)//ne
                num=bisect.bisect_left(nega,t)
                rem=nn-num
                if t<=ne:
                    rem-=1
                cnt+=rem
                
            cnt=cnt//2
            # print(x,cnt)
            return cnt>=K2
                
        
        ok=0
        ng=inf
        while ng-ok>1:
            x=(ok+ng)//2
            if ch(x):
                ok=x
            else:
                ng=x
        
        print(ok)
        
        
        

main()


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int d = a - b;
    if((c - d) <= 0) cout << 0 << endl;
    else cout << c - d << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int a, b;
        cin >> a >> b;
        if(a == 0 && b == 0)
            return 0;
        b -= a;

        vector<int> ret(3);
        ret[2] = b / 1000;
        b %= 1000;
        ret[1] = b / 500;
        b %= 500;
        ret[0] = b / 100;

        cout << ret[0] << ' ' << ret[1] << ' ' << ret[2] << endl;
    }
}

Measured memory_bytes: 0
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
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; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    in(N);

    vll L(N);
    inN(L, N);

    sort(all(L));

    int count = 0;

    rep(i, N)
    {
        reps(j, i + 1, N)
        {
            reps(k, j + 1, N)
            {
                if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) continue;

                if (L[k] < L[i] + L[j]) count++;
            }
        }
    }

    outl(count);

    return 0;
}

Measured memory_bytes: 3652
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ostream &operator<<(ostream &dest, __int128_t value)
{
    ostream::sentry s(dest);
    if (s)
    {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[128];
        char *d = std::end(buffer);
        do
        {
            --d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (value < 0)
        {
            --d;
            *d = '-';
        }
        int len = end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len)
        {
            dest.setstate(ios_base::badbit);
        }
    }
    return dest;
}

__int128 parse(string &s)
{
    __int128 ret = 0;
    for (int i = 0; i < s.length(); i++)
        if ('0' <= s[i] && s[i] <= '9')
            ret = 10 * ret + s[i] - '0';
    return ret;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, ss, sss;
    cin >> s >> ss >> sss;
    __int128 x = parse(s);
    __int128 k = parse(ss);
    __int128 d = parse(sss);
    if (x < 0)
    {
        x = -x;
    }
    if (x > d * k)
    {
        x = x - d * k;
        cout<<x<<"\n";
    }
    else
    {
        __int128 ans = x % d;
        __int128 count = x / d;
        //cout<<ans<<" "<<count<<"\n";
        if ((k - count) % 2 == 0)
            cout << ans << "\n";
        else
            cout << d - ans << "\n";
    }
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		if ((A * B) % 2 == 0) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 21844
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

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

int main()
{
    int N;
    int temp;
    bool flag = false;
    int counter_c = 0,counter_r = 0;
    
    vector<vector<int> >  array(3,vector<int>(3,0));
    vector<vector<bool> > is_OK(3,vector<bool>(3,false));
    for(int i = 0;i < 3;i++){
        for(int j = 0; j < 3;j++){
            cin >> array[i][j] ;
        }
    }
    cin >> N;
    
    for(int i = 0;i < N;i++){
        cin >> temp;
        for(int i = 0;i < 3;i++){
            for(int j = 0; j < 3;j++){
                if(temp == array[i][j]) is_OK[i][j] = true;
            }
        }
    }
    
    
    
    for(int i = 0;i < 3;i++){
        counter_r = 0;
        counter_c = 0;
        for(int j = 0; j < 3;j++){
            if(is_OK[i][j]) counter_r++;
            if(is_OK[j][i]) counter_c++;
        }
        if(counter_r == 3 || counter_c == 3) {
            cout << "Yes" << endl;
            flag = true;
            break;
        }
    }
    if(!flag){
        if(is_OK[0][0] &&is_OK[1][1] && is_OK[2][2]){
            cout << "Yes" << endl;
            flag = true;
        } 
    else if(is_OK[0][2] &&is_OK[1][1] && is_OK[2][0]){
            cout << "Yes" << endl;
            flag = true;
        }    
    }
     
    
    
    if(!flag) cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M,X,Y;
    cin>>N>>M>>X>>Y;
    
    int a=X,b=Y;
    rep(i,N){
        int x;cin>>x;
        chmax(a,x);
    }
    rep(i,M){
        int x;cin>>x;
        chmin(b,x);
    }
    
    if(a<b){
        cout1("No War")
    }else{
        cout1("War")
    }
}

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

using namespace std;

struct rest {
    string s;
    int p, i;
};

bool cr(rest a, rest b) {
    if (a.s != b.s) {
        return a.s < b.s;
    }
    return a.p > b.p;
}

int main() {
    int n;
    cin >> n;
    rest r[n];
    for (int i = 0; i < n; i++) {
        cin >> r[i].s >> r[i].p;
        r[i].i = i + 1;
    }
    sort(r, r+n, cr);

    for (int i = 0; i < n; i++) {
        cout << r[i].i << endl;
    }

    return 0;
}


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

int main(){
int A,B,C;
cin>>A>>B>>C;
if(A-B>0){
 if(B<C&&C<A){
 cout<<"Yes\n";
}
 else {
cout<<"No\n";
}
}

else{
 if(A<C&&C<B){
 cout<<"Yes\n";
}
 else{
 cout<<"No\n";
}
}

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

template<typename T> //最大公約数
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T> //最小公倍数
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

struct BinaryIndexedTree {
	vector<int> data;
	void init(int _sz){
		data.assign(_sz+1, 0);
	}
	
	int Sum(int k)
	{
		int sum = 0;
		for(; k > 0; k -= k & -k) {
			sum += data[k];
		}
		return sum;
	}
	void Add(int k, int x)
	{
		for(; k < data.size(); k += k & -k){
			data[k] += x;
		}
	}
};

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

	vector<BinaryIndexedTree> bit(26);
	for (int i = 0; i < 26; i++){
		bit[i].init(N+1);
	}

	for (int i = 0; i < s.size(); i++){
		bit[s[i] - 'a'].Add(i+1, 1);
	}

	vector<int> ans(0);
	for (int i = 0; i < Q; i++){
		int c; cin >> c;
		if (c == 1){
			int index; char c; cin >> index >> c;
			bit[s[index-1]-'a'].Add(index, -1);
			bit[c-'a'].Add(index, 1);
			s[index-1] = c;
		} else if (c == 2){
			int l, r; cin >> l >> r;
			int res = 0;
			for (int j = 0; j < 26; j++){
				if (bit[j].Sum(r) - bit[j].Sum(l-1) > 0){
					res++;
				} 
			}
			ans.push_back(res);
		}
	}
	for (int i = 0; i < ans.size(); i++){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 51844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e7+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;

int main(){
	cin >> s;
	int ans = 0;
	REP(i, s.size() - 1){
		if (s[i] != s[i + 1])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1020
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

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

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
#define MOD 1000000007
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main() { 
  string s,t;cin>>s>>t;
  cout << t << s << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int H, W;

    scanf("%d%d", &H, &W);

    char s[H][W+1];

    for(int i = 0; i < H; i++){
        scanf("%s", s[i]);
    }

    char t[H+2][W+3];

    for(int i = 0; i < W + 2; i++){
        t[0][i] = '.';
        t[H+1][i] = '.';
    }

    for(int i = 1; i <= H; i++){
        t[i][0] = '.';
        for(int j = 1; j <= W; j++){
            t[i][j] = s[i-1][j-1];
        }
        t[i][W+1] = '.';
    }

    int f = 0;

    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            if(t[i][j] == '#' && t[i-1][j] == '.' && t[i][j-1] == '.' && t[i][j+1] == '.' && t[i+1][j] == '.'){
                f = 1;
                break;
            }
        }
    }

    if(f == 1){
        printf("No\n");
    }else{
        printf("Yes\n");
    }

    return 0;
}

Measured memory_bytes: 1608
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

template <class T>
T add(T x, T y) {
	return x + y;
}

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p % i == 0)
			return false;
	}
	return true;
}

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

	int x;
	cin >> x;

	while (1) {
		if (IsPrime(x)) {
			break;
		}
		x++;
	}

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
//{{{
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

using PII = pair<int, int>;
using TI3 = tuple<int, int, int>;
using LL = long long;
using ULL = unsigned long long;
using MAT = array<array<LL, 2>, 2>;

template<class T> constexpr inline T begin(const T&) {return 0;}
template<class T> constexpr inline T end(const T& x) {return max(T(0), x);}

#define SZ(x) int((x).size())
#define PB push_back
#define EB emplace_back
#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define CHECK(a,b) static_assert(std::is_same<decltype(a), decltype(b)>::value, "REP diff types");

#define REPPP(i,s,c,t) for(i; ((s) and (c)) or (putchar("\n "[c]) and (c)); (t))
#define REPP2(i,n) REPPP(auto i=begin(n),i==begin(n),i!=end(n),++i)
#define REPP3(i,m,n) CHECK(m,n) REPPP(auto i=(m),i==(m),i<(n),++i)
#define REPP4(i,m,n,s) CHECK(m,n) REPPP(auto i=(m),i==(m),((s)>0 and i<(n)) or ((s)<0 and i>(n)),i+=(s))
#define REPP(...) GET_MACRO(__VA_ARGS__, REPP4, REPP3, REPP2)(__VA_ARGS__)

#define REP2(i,n) for(auto i=begin(n);i!=end(n);++i)
#define REP3(i,m,n) CHECK(m,n) for(auto i=(m);i<(n);++i)
#define REP4(i,m,n,s) CHECK(m,n) for(auto i=(m);((s)>0 and i<(n)) or ((s)<0 and i>(n));i+=(s))
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)

template<class T> void _read(T &x) {cin >> x;}
void _read(size_t &x) {scanf("%zu", &x);}
void _read(int &x) {scanf("%d", &x);}
void _read(LL &x) {scanf("%lld", &x);}
void _read(ULL &x) {scanf("%llu", &x);}
void _read(double &x) {scanf("%lf", &x);}
void _read(char &x) {scanf(" %c", &x);}
void _read(char *x) {scanf("%s", x);}
void read() {}
template<class T, class... U>
void read(T& head, U&... tail) {
    _read(head);
    read(tail...);
}

template<class T> void _print(const T &x) {cout << x;}
void _print(const size_t &x) {printf("%zu", x);}
void _print(const int &x) {printf("%d", x);}
void _print(const LL &x) {printf("%lld", x);}
void _print(const ULL &x) {printf("%llu", x);}
void _print(const double &x) {printf("%.16lf", x);}
void _print(const char &x) {putchar(x);}
void _print(const char *x) {printf("%s", x);}
void _print(const string &x) {printf("%s", x.c_str());}
template<class T> void _print(const vector<T> &x) {
    for(auto i = x.begin(); i != x.end(); _print(*i++)) {
        if (i != x.cbegin()) putchar(' ');
    }
}
void print() {putchar('\n');}
template<class T, class... U> void print(const T& head, const U&... tail) {
    _print(head);
    if(sizeof...(tail)) putchar(' ');
    print(tail...);
}

//}}}
const int MOD = 1000000007;

#define LLINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f

#define MAX_N 300005

int A[MAX_N];

int main()
{
    int N;
    read(N);
    REP(i, N) {
        read(A[i]);
    }
    int cnt[3] = {0, 0, 0};
    LL ans = 1;
    REP(i, N) {
        int c = -1;
        int k = 0;
        REP(j, 3) {
            if(A[i] == cnt[j]) {
                ++k;
                c = j;
            }
        }
        cnt[c] += 1;
        ans = (ans * k) % MOD;
    }
    print(ans);
    return 0;
}


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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int N = nextInt();
		long[] A = nextLongs();

		long ans = 0;
		for(int i=0;i<=60;i++){
			long n=0;
			long p=0;
			for(int k=0;k<N;k++){
				if((A[k]>>i&1)==1){
					p++;
				}else{
					n++;
				}
			}
			ans+=(1L<<i)%MOD*((p*n)%MOD)%MOD;
		}
		System.out.println(ans%MOD);
	}



	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 92296
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n+1];
    TreeSet<Integer> ts = new TreeSet<>();
    for(int i=1;i<=n;i++)a[sc.nextInt()]=i;
    long ans = 0;
    ts.add(0);
    ts.add(n+1);
    for(int i=1;i<=n;i++){
      ts.add(a[i]);
      ans+=(long)i*(ts.higher(a[i])-a[i])*(a[i]-ts.lower(a[i]));
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 95668
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define test int t; cin >> t; while(t--)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve() {
	int n;
	cin >> n;
	string s;
	map<string, int> mp;
	rep(i, 0, n - 1) {
		cin >> s;
		sort(all(s));
		mp[s]++;
	}
	int ans = 0;
	for (auto x : mp) {
		if (x.S > 1) {
			ans += x.S * (x.S - 1) / 2;
		}
	}
	cout << ans;
}

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

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

#define TEST 0

	if (TEST) {
		test;
		solve();
	} else {
		solve();
	}

	return 0;
}

Measured memory_bytes: 11312
// g++ -std=c++17 e.cpp -o a.out && ./a.out < in
#include <iostream>
#include <algorithm>
#include <functional>
#include <math.h>
#include <string>
#include <map>
#include <queue>
#define ll long long
#define IOS cin.sync_with_stdio(false);cin.tie(nullptr);
#define endl "\n"
#define pb push_back
#define rep(t, n) for (int t=0;t<(n);++t)
const ll NN = 1e5+5;
using namespace std;

int main() {
    // freopen("out", "w", stdout);
    IOS;
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    priority_queue<int> pq;
    
    ll aa[a], bb[b], cc[c];
    rep(t, a) cin >> aa[t];
    rep(t, b) cin >> bb[t];
    rep(t, c) cin >> cc[t];

    sort(aa, aa+a, greater<int>());
    sort(bb, bb+b, greater<int>());
    sort(cc, cc+c, greater<int>());

    rep(t, c) pq.push(cc[t]);

    rep(t, x) pq.push(aa[t]);
    rep(t, y) pq.push(bb[t]);

    ll sm = 0;
    rep(t, x+y) {
        sm += pq.top();
        pq.pop();
    }
    cout << sm;

}



Measured memory_bytes: 4852
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int main(){
	int n,count,max;
	char s[110];
	cin >> n;
	int check[110];
	cin >> s;

	count = 0;
	max = 0;

	for (int i = 0; i < n-1; i++) { //区切るいち
		count = 0;

		for (int l = 0; l < n; l++) { //初期か
			check[l] = 0;
		}

		for (int j = 0; j <= i; j++) { //チェックする方
			if (check[j] == 1) continue;

			for (int k = 1; k < n; k++) {//チェックされる側
				if (s[j] == s[k]) {

					if (k <= i) {
						check[k] = 1;
					}
					else if (k > i) {
						count++;
						break;
					}

				}
			}
		}

		if (count > max) max = count;
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256