akhauriyash/Code-Regression huggingface dataset:
/**
 * Created by hiramekun at 20:52 on 2019-08-24.
 */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}


template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;

    vvl level(n, vl(n));
    auto dfs = [&](auto &&f, ll l, ll r, ll lev) -> void {
        if (l + 1 == r) return;
        ll mid = (l + r) / 2;
        for (ll i = l; i < mid; ++i) {
            for (ll j = mid; j < r; ++j) {
                level[i][j] = lev;
            }
        }
        f(f, l, mid, lev + 1);
        f(f, mid, r, lev + 1);
    };
    dfs(dfs, 0, n, 1);
    for (ll i = 0; i < n - 1; ++i) {
        for (ll j = i + 1; j < n; ++j) {
            cout << level[i][j] << ' ';
        }
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


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

#define MOD_1000000007 (1000000007LL)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)

using std::cerr;
using std::cout;
using std::endl;
using std::make_pair;
using std::map;
using std::pair;
using std::priority_queue;
using std::set;
using std::string;
using std::vector;
typedef long long ll;

ll a, b, c;

void solve() {
  if(c-a-b<0) {
    cout << "No" << endl;
    return;
  }
  if((4*a*b)<(c-a-b)*(c-a-b)) {
    cout << "Yes" << endl;
    return;
  }
  cout << "No" << endl;
}

int main() {
  scanf("%lld %lld %lld", &a, &b, &c);
  solve();
  return 0;
}

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

#define MAX 2000001
#define VMAX 10000

int main(void)
{
  unsigned short *A, *B;
  
  int C[VMAX+1];
  int n, i, j;
  scanf("%d",&n);
  
  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  
  for(i=0;i<=VMAX;i++) C[i] = 0;
  
  for(i=0;i<n;i++) {
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }
  
  for(i=1;i<=VMAX;i++) C[i] = C[i] + C[i-1];
  
  for(j=1;j<=n;j++) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
  for(i=1;i<=n;i++) {
    if(i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 9560
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int H,W;
    cin>>H>>W;
    vector<string> c(H,"");
    REP(i,H)cin>>c[i];
    REP(i,H)REP(y,2)cout<<c[i]<<endl;
}

Measured memory_bytes: 256
from math import ceil


def main():
    n, h = map(int, input().split())
    attack = []
    for _ in range(n):
        a, b = map(int, input().split())
        attack.append([a, 1])
        attack.append([b, 0])
    answer = 0
    attack.sort(key=lambda x: x[0], reverse=True)
    for a, t in attack:
        if h <= 0:
            break
        if t:
            answer += ceil(h / a)
            h = 0
        else:
            answer += 1
            h -= a
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 32940
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int n,m;
vi a,b;
bool f(int s,int t){
	if(t==-1){
		if(s==-1)return true;
		return false;
	}
	if(s>n||s<0)return false;
	if(a[s]==b[t]&&f(s-1,t-1))return true;
	if((a[s]+1)%12==b[t]&&f(s-2,t-1))return true;
	if((a[s]+11)%12==b[t]&&f(s+1,t-1))return true;
	return false;
}
int main(){
	map<string,int>M;
	M["A"]=0;
	M["A#"]=1;
	M["B"]=2;
	M["C"]=3;
	M["C#"]=4;
	M["D"]=5;
	M["D#"]=6;
	M["E"]=7;
	M["F"]=8;
	M["F#"]=9;
	M["G"]=10;
	M["G#"]=11;
	int q;
	cin>>q;
	while(q--){
		cin>>n>>m;
		a=vi(n);
		b=vi(m);
		rep(i,n){
			string s;
			cin>>s;
			a[i]=M[s];
		}
		rep(i,m){
			string s;
			cin>>s;
			b[i]=M[s];
		}
		if(f(n-1,m-1)||n!=1&&f(n-2,m-1))cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

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

typedef long long ll;
const ll MOD = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= MOD;
	if(k%2 == 1){
		ret *= x;
		ret %= MOD;
	}
	return ret;
}

ll F[1002];
ll G[1002];
ll init(){
	F[0] = 1;
	G[0] = 1;
	for(int i = 0 ; i+1 < 1002 ; i ++){
		F[i+1] = F[i]*(i+1);
		F[i+1] %= MOD;
		G[i+1] = modpow(F[i+1],MOD-2);
	}
}

int main(){
	init();
	ll n,k;
	ll a[22];
	cin >> n >> k;
	for(int i = 1 ; i <= k ; i ++){
		cin >> a[i];
	}
	
	static ll dp[22][1002] = {};
	dp[0][0] = 1;
	for(int i = 1 ; i <= k ; i ++){
		for(int j = 0 ; j <= n ; j ++){
			for(int t = 0 ; t <= min(a[i],(ll)j) ; t ++){
				ll x = dp[i-1][j-t]*F[n-t]; x %= MOD;
				x *= G[a[i]-t]; x %= MOD;
				x *= G[t]; x %= MOD;
				dp[i][j] += x;
			}
			dp[i][j] %= MOD;
			//cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}
	ll ret = dp[k][n];
	ret *= F[n]; ret %= MOD;
	for(int i = 1 ; i <= k ; i ++){
		ret *= G[n-a[i]];
		ret %= MOD;
	}
	cout << ret << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
 	string s = "ABC";
 	string a = "ARC";
 	string ss;
 	cin>>ss;
 	if(s==ss){
 		cout<<a<<endl;
 	}else{
 		cout<<s<<endl;
 	}

}



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

int main() {
  int N, K;
  cin >> N >> K;
  
  int sum = 0;

  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    int A = x * 2;
    int B = (K - x) * 2;
    if (A < B) {
      sum += A;
    } else {
      sum += B;
    }
  }
  cout << sum << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    int d, x;
    cin >> d >> x;
    int cnt = 0;

    rep(i, n)
    {
        int a;
        cin >> a;
        for (int j = 0;; j++)
        {
            if (a * j + 1 > d)
                break;
            cnt++;
        }
    }
    OP(x + cnt);
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main(int argc, char* argv[]) {
	ll n, answer = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)
		{
			answer += i;
		}
	}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define mp make_pair

void print(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cout<<a[i]<<' ';
    cout<<endl;
}

void get(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cin>>a[i];
}

const ll p = 998244353;

int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    s = s%p;
    if (s<0) s+=p; 
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    
    string s;
    cin>>s;
    int n = s.length();
    vector<int> blue(2*n);
    vector<int> red(2*n);
    for (int i = 0; i<2*n; i++)
    {
        if (i!=0) blue[i] = blue[i-1];
        if (i<n)
        {
            if (s[i]=='1') blue[i]++;
            if (s[i]=='2') blue[i]+=2;
            red[i] = 2*(i+1) - blue[i];
        }
        else red[i] = red[i-1];
    }
    
    vector<vector<int>> cnt(2*n, vector<int>(2*n+1));
    if (blue[0]>0) cnt[0][1] = 1;
    if (blue[0]<2) cnt[0][0] = 1;
    for (int i = 1; i<2*n; i++)
    {
        for (int j = max(0, i+1-red[i]); j<=min(i+1, blue[i]); j++)
        {
            cnt[i][j] = cnt[i-1][j];
            if (j>0) cnt[i][j] = add(cnt[i][j], cnt[i-1][j-1]);
        }
    }
    
    //print(blue);
    //for (int i = 0; i<2*n; i++) print(cnt[i]);
    
    int total = 0;
    for (int i = 0; i<=2*n; i++) total = add(total, cnt[2*n-1][i]);
    cout<<total;
    
}

Measured memory_bytes: 62976
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<ll> dp;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

void solve()
{
    ll n,k;
    cin>>n>>k;
    ll dp[k+1];
    ll ans=0;
    repb(i,k,1)
    {
        ll v=k/i;
        ll val=power(v,n,mod);
        dp[i]=val;
        for(ll j=2*i;j<=k;j+=i)
        {
            dp[i]=(dp[i]-dp[j]+mod)%mod;
        }
        // cout<<dp[i]<<endl;
        ans=(ans+(i*dp[i])%mod)%mod;
    }
    cout<<ans<<endl;
}

int main()
{
    IOS;
    ll t;
    // cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
}     


Measured memory_bytes: 4384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a,b,c;
    vector<int> v;
    cin>>a>>b>>c;
    v.pb(a);
    v.pb(b);
    v.pb(c);
    sort(v.begin(),v.end());
    if(v[0]==5 && v[1]==5 && v[2]==7){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
p = 1
#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

#a,bの最小公倍数
def lcm(a, b):
	return a * b // gcd (a, b)
for i in range(n):
    a = int(input())
    p = lcm(a, p)
print(p)

Measured memory_bytes: 38384
import sys
import numpy as np
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n, m, c = rm()
b = np.array(rl())
cnt = 0
for _ in range(n):
  a = np.array(rl())
  if np.sum(a*b) > -c:
    cnt += 1
print(cnt)

Measured memory_bytes: 27300
#include <iostream>
#include <math.h>
using namespace std;

int main() {
int n,m;
while(cin>>n){
	m=0;
	int wa=2;
	for (int k=0;k<=10;k++){
		if(n%wa!=0){
			if(m!=0){
				cout<<" ";
			}
			cout<<wa/2;
			n=n-wa/2;
			m=m+1;
		}
	wa=wa*2;
}
cout<<endl;
}
	return 0;
}

Measured memory_bytes: 1160
/*-------property of the half blood prince-----*/

#include <bits/stdc++.h>
#include <dirent.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define MIN(X,Y) X<Y?X:Y
#define MAX(X,Y) X>Y?X:Y
#define ISNUM(a) ('0'<=(a) && (a)<='9')
#define ISCAP(a) ('A'<=(a) && (a)<='Z')
#define ISSML(a) ('a'<=(a) && (a)<='z')
#define ISALP(a) (ISCAP(a) || ISSML(a))
#define MXX 10000000000
#define MNN -MXX
#define ISVALID(X,Y,N,M) ((X)>=1 && (X)<=(N) && (Y)>=1 && (Y)<=(M))
#define LLI long long int
#define VI vector<int>
#define VLLI vector<long long int>
#define MII map<int,int>
#define SI set<int>
#define PB push_back
#define MSI map<string,int>
#define PII pair<int,int>
#define PLLI pair<LLI,LLI>
#define PDD pair<double,double>
#define FREP(i,I,N) for(int (i)=(int)(I);(i)<=(int)(N);(i)++)
#define eps 0.0000000001
#define RFREP(i,N,I) for(int (i)=(int)(N);(i)>=(int)(I);(i)--)
#define SORTV(VEC) sort(VEC.begin(),VEC.end())
#define SORTVCMP(VEC,cmp) sort(VEC.begin(),VEC.end(),cmp)
#define REVV(VEC) reverse(VEC.begin(),VEC.end())
#define INRANGED(val,l,r) (((l)<(val) || fabs((val)-(l))<eps) && ((val)<(r) || fabs((val)-(r))<eps))
#define INRANGEI(val,l,r) ((val)>=(l) && (val)<=(r))
#define MSET(a,b) memset(a,b,sizeof(a))
using namespace std;
using namespace __gnu_pbds;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction


//typedef tree < int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

vector<LLI>arr;

LLI gcd(LLI a, LLI b){
    if(a==0)return b;
    return gcd(b%a,a);
}

int main(){
    int n;
    LLI k;
    cin>>n>>k;
    LLI mxx = 0;
    FREP(i,1,n){
        LLI a;
        cin>>a;
        arr.PB(a);
        mxx = max(mxx,a);
    }
    LLI gg = arr[0];
    FREP(i,1,n-1){
        gg = gcd(gg,arr[i]);
    }
    if(k%gg==0 && k<=mxx){
        cout<<"POSSIBLE\n";
    }
    else{
        cout<<"IMPOSSIBLE\n";
    }
    return 0;
}


Measured memory_bytes: 1400
h,w,K = map(int,input().split())
c = [list(map(str, input().strip())) for i in range(h)]

count = 0
he = [0 for i in range(h)]
for i in range(2**h):
    we = [0 for i in range(w)]

    h_set = set(range(h))
    for j in range(h):
        if(he[j] == 0):
            h_set.discard(j)
    h_a = list(h_set)
    for j in range(h):
        if(he[h-j-1] == 0):
            he[h-j-1] = 1
            for k in range(h-j,h):
                he[k] = 0
            break

    for j in range(2**w):
        w_set = set(range(w))
        for k in range(w):
            if(we[k] == 0):
                w_set.discard(k)
        w_a = list(w_set)
        for k in range(w):
            if(we[w-k-1] == 0):
                we[w-k-1] = 1
                for m in range(w-k,w):
                    we[m] = 0
                break


        black = 0
        for x in h_a:
            for y in w_a:
                if(c[x][y] == '#'):
                    black += 1
        if(black == K):
            count += 1
 
        

print(count)

        




Measured memory_bytes: 9288
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n;
	cin>>n;
	vector<ll> v(n+1);
	for(ll i=1;i<=n;i++)	
		cin>>v[i];
	vector<ll> g1(n+1,0),g2(n+2,0);
	for(ll i=1;i<=n;i++)
	{
		g1[i]=__gcd(v[i],g1[i-1]);
	}
	for(ll i=n;i>=0;i--)
		g2[i]=__gcd(v[i],g2[i+1]);
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		ans=max(ans,__gcd(g2[i+1],g1[i-1]));
	}
	cout<<ans;
}

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

int main(){
  int K; cin >> K;
  string S; cin >> S;
  if (S.size() <= K){
    cout << S << endl;
  } else {
    for (int i=0; i<K; i++){
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
    
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  ll N;
  string S;
  cin >> N >> S;
  vector<char> alphabets;
  rep(i, 27) {
    char a = 'A';
    ll lla = a;
    lla += i;
    alphabets.pb(lla);
  }

  // A 65

  for (char t : S) {
    ll llt = (t - 65 + N % 26) % 26 + 65;
    char tt = llt;
    cout << tt;
  }
  ENDL;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;

int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	long long int  s[200][200];
	//cout << fixed << setprecision(10);

	long long int pl_num = 0, mi_num = 0;
	long long int n, m, res = 0,sa_x,sa_y, sum = 0,a[200000],pl[200000],mi[200000];

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] > 0) { pl[pl_num]=a[i],pl_num++; }
		else{ mi[mi_num] = a[i], mi_num++; }
	}
	if (pl_num == 0) {
		sort(mi, mi + n);

		long long int ma = 0, block = mi[n-1];
		for (int i = 0; i < n; i++) { ma += abs(a[i]); }
		cout << ma+2*mi[n-1] << endl;
		for (int i = 0; i < n-1; i++) {
			cout << block << " " << mi[i] << endl;
			block -= mi[i];
		}
	}
	else if (mi_num == 0) {

		sort(pl, pl+ n);
		long long int ma = 0, block = pl[0];
		for (int i = 0; i < n; i++) { ma += abs(a[i]); }
		cout << ma-2*pl[0] << endl;
		for (int i = 1; i < n-1; i++) {
			cout << block << " " << pl[i] << endl;
			block -= pl[i];
		}
		cout << pl[n-1] << " " << block << endl;
		block = pl[n-1] - block;
	}
	else if (pl_num <= mi_num) {
		long long int ma = 0, block = pl[0];
		for (int i = 0; i < n; i++) { ma += abs(a[i]); }
		cout << ma << endl;
		for (int i = 0; i < mi_num - pl_num + 1; i++) {
			cout << block << " " << mi[i] << endl;
			block -= mi[i];
		}
		for (int i = 1; i < pl_num; i++) {
			cout << mi[i + mi_num - pl_num] << " " << block << endl;
			block = mi[i + mi_num - pl_num] - block;
			cout << pl[i] << " " << block << endl;
			block = pl[i] - block;
		}
	}
	else {
		long long int ma = 0, block = mi[0];
		for (int i = 0; i < n; i++) { ma += abs(a[i]); }
		cout << ma << endl;
		for (int i = 0; i < pl_num - mi_num ; i++) {
			cout << block << " " << pl[i] << endl;
			block -= pl[i];
		}
		cout << pl[pl_num - mi_num] << " " << block<< endl;
		block = pl[pl_num - mi_num]-block;
		for (int i = 1; i < mi_num; i++) {
			
			cout << mi[i] << " " << block << endl;
			block = mi[i] - block;
			cout << pl[i - mi_num + pl_num] << " " << block << endl;
			block = pl[i - mi_num + pl_num] - block;
		}
	}
}


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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  if(a/k == b/k && a%k != 0 && b%k != 0){
      cout << "NG" << endl;
  }
  else
    cout << "OK" << endl;
}




Measured memory_bytes: 3584
#include<iostream>

using namespace std;

int main() {
	int N;
	int p[50];
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> p[i];
	}
	int count = 0;
	for (int i = 0;i < N;i++) {
		/*cout << i << endl;*/
		if (p[i] != i+1) {
			count++;
		}
	}
	/*cout << count << "#" << endl;*/
	if (count == 0 || count == 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N, K;
int a[3];
int h[100000];
string T;
int ans = 0;

int memo[100000][4];
int solve(int n, int b){
    if(n >= N) return 0;
    if(memo[n][b] != -1) return memo[n][b];
    int ret = 0;
    rep(i, 3){
        if(i == b) continue;
        int tmp = solve(n+K, i);
        if((i+1)%3 == h[n]) tmp += a[i];
        ret = max(ret, tmp);
    }
    return memo[n][b] = ret;
}

signed main(){
    cin >> N >> K >> a[0] >> a[1] >> a[2] >> T;
    rep(i, N){
        if(T[i] == 'r') h[i] = 0;
        if(T[i] == 's') h[i] = 1;
        if(T[i] == 'p') h[i] = 2;
    }
    memset(memo, -1, sizeof(memo));
    rep(i, K) ans += solve(i, 3);
    cout << ans << endl;
}

Measured memory_bytes: 8576
import java.util.Stack;
import java.util.Scanner;
import java.lang.Integer;

public class Main {

    // the method checks if it is an integer
    public static boolean isInteger(String value){
        boolean isInteger = false;
        try{
            Integer.parseInt(value);
            isInteger = true;
        }catch(NumberFormatException ex){
        }
        return isInteger;
    }

    // method to covert a string to operator
    public static int toOperator(String operator, int value1, int value2){
        int result=0;
        if(operator.equals("+")){
            result = value1+value2;
        }else if (operator.equals("-")){
            result = value2-value1;
        }
        else if(operator.equals("*")){
            result = value1*value2;
        }
        else if (operator.equals("/")){
            result = value1/value2;
        }
        return result;
    }

    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<Integer>();
        Scanner input1 = new Scanner(System.in);
        int value1;
        int value2;

        String element = input1.nextLine();
        String elements[] = element.split(" ");
        for (String e : elements) //(int i=0; i< elements.length)
        {
            if(isInteger(e)){
                stack.push(Integer.parseInt(e));
            }else{
                value1 = stack.pop();
                value2 = stack.pop();
                //System.out.println(value1+" "+value2);
                stack.push(toOperator(e,value1,value2));
        }

        }
        System.out.println(stack.pop());
    }}



Measured memory_bytes: 26152
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;
ll a, b, k;

int main(){
	IOS
	cin >> a >> b >> k;
	ll ab;
	ab=a-min(a, k);
	k-=min(a, k);
	b-=min(b, k);
	cout << ab << ' ' << b << '\n';
}


Measured memory_bytes: 3620
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <array>
#include <queue>
#include <set>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

ll digits(ll num)
{
    ll count = 0;
    while (num !=0)
    {
        num /= 10;
        count++;
    }
    return count;
}

ll f(ll A, ll B)
{
    return max(digits(A), digits(B));
}

int main()
{
    ll N;
    cin >> N;

    ll rootN = sqrt(N);
    
    ll ans = digits(N);
    for (ll A = 1; A <= rootN; A++)
    {
        if (N % A != 0)
            continue;
        
        ll B = N / A;
        ans = min(ans, f(A, B));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val result = (1 to N).forall{i =>
    val a = in.nextInt
    a % 2 == 1 || a % 3 == 0 || a % 5 == 0
  }
  println(if (result) "APPROVED" else "DENIED")
}

Measured memory_bytes: 27460
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7


def solve(f):
    n, s = f.read_int_list()
    x = [f.read_int_list() for _ in xrange(n)]

    ans = 0
    side = 0
    l = 0
    r = n-1
    while True:
        if x[l][0] > s:
            return ans + x[r][0] - s
        elif x[r][0] < s:
            return ans + s - x[l][0]
        else:
            if x[l][1] >= x[r][1]:
                x[l][1] += x[r][1]
                if side != 1:
                    ans += x[r][0] - x[l][0]
                side = 1
                r -= 1
            else:
                x[r][1] += x[l][1]
                if side != -1:
                    ans += x[r][0] - x[l][0]
                side = -1
                l += 1


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 19996
#include <iostream>
#include <bitset>
#include <map>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
using namespace std;

int A[200];
int N;

bool bit_Search(int i, int m){
    if(m == 0) return true;
    if(i >= N) return false;
    
    return bit_Search(i+1, m) || bit_Search(i+1, m - A[i]);
}



int main() {

    int Q;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int M;
        cin >> M;
        
        bool ans = bit_Search(0, M);
        
        if(ans) cout << "yes" << endl;
        else cout << "no" << endl;
        
    }
    
    return 0;
}




Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int k=sc.nextInt();		//円形の湖
		int n=sc.nextInt();		//n軒の家
		
		int[]a=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}

		int count=0;
		int ans=a[0]+(k-a[n-1]);
		for(int i=0;i<n-1;i++) {
			count=a[i+1]-a[i];
			if(count>ans) {
				ans=count;
			}
		}
		System.out.println(k-ans);
		sc.close();
	}

}

Measured memory_bytes: 50444
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using namespace std;

int main(){
  int n;
  int m = 1;
  int l = 0;
  cin >> n;
  FOR(i,1,n+1) m *= i;
  int x[n], y[n];
  float ans = 0;
  REP(i,n) cin >> x[i] >> y[i];

  REP(i,n){
    FOR(j,i+1,n){
      ans += sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
      l++;
    }
  }
  
  ans = ans*(n-1)/l;
  cout << setprecision(10) << ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll findGCD(ll arr[], ll n) 
{ 
    ll result = arr[0]; 
    for (ll i = 1; i < n; i++) 
    { 
        result = gcd(arr[i], result); 

        if(result == 1) 
        { 
        return 1; 
        } 
    } 
    return result; 
} 
int main() 
{ 
    ll n,s=0; cin>>n;
    for(int i=1;i<=n;i++)
    {for(int j=1;j<=n;j++)
    {for(int k=1;k<=n;k++)
    {
    ll arr[] = { i, j, k,}; 
    s+=findGCD(arr, 3);}}}
    cout<<s;
    return 0; 
} 


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define INF 1e9

void init()
{
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}

int main()
{
    init();
    int K;
    cin>>K;
    string s;
    cin>>s;
    if(s.size()>K){
        s.erase(K);
        s = s + "...";
    }
    cout<<s<<endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  vector<long> data(N * 3);
  for(int i = 0; i < N * 3; i++)cin >> data.at(i);
  sort(data.begin(), data.end());
  long ans = 0;
  for(int i = N; i < N * 3; i += 2){
    ans += data.at(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

#define ll long long
const int maxN = 100005;
const ll INF = 1000000000000000000LL;

class TaskB {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		string s, t;
		cin >> s >> t;
		int ans = 10000;
		for(int i = 0; i + t.size() <= s.size(); i++) {
			int c = 0;
			for(int j = 0; j < t.size(); j++) {
				if(s[i + j] != t[j] ) {
					c++;
				}
			}
			ans = min(ans, c);
		}
		cout << ans << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskB solver;
	solver.solve();
	return 0;
}


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


class UnionFindNode(object):
    """
    Union-Find構造
    ノードのグループ併合や、所属グループ判定を高速に処理する
    """

    def __init__(self, group_id, parent=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.size_ = 1
        self.rank_ = 1

    def __str__(self):
        template = "UnionFindNode(group_id: {}, \n\tparent: {}, size: {}, rank: {})"
        return template.format(self.group_id_, self.parent_, self.size_,
                               self.rank_)

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def get_size(self):
        root = self.root()
        return root.size_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()

        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                unite_root.parent_ = root
                root.rank_ = max(root.rank_, unite_root.rank_ + 1)
                root.size_ += unite_root.size_

            else:
                root.parent_ = unite_root
                unite_root.rank_ = max(root.rank_ + 1, unite_root.rank_)
                unite_root.size_ += root.size_


N, M = map(int, input().split())

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

node_list = [UnionFindNode(i) for i in range(N)]
for _ in range(M):
    x, y = map(int, input().split())
    node_list[x-1].unite(node_list[y-1])

ans = 0
for i, p in enumerate(p_array):
    if node_list[i].find() == node_list[p-1].find() or i == p-1:
        ans += 1

print(ans)


Measured memory_bytes: 75608
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  vector<int> arr{0, 0, 0};
  cin >> arr[0] >> arr[1] >> arr[2];
  sort(arr.begin(), arr.end());

  // 2 3 6
  int diff_max_mid = arr[2] - arr[1]; // 3
  arr[0] += diff_max_mid; //2+3 => 5
  int diff_max_min = arr[2] - arr[0]; //6-5=>1


  if(diff_max_min == 0)
  {
    cout << diff_max_mid << endl;
  }
  else if(diff_max_min%2 == 0)
  {
    cout << diff_max_mid + diff_max_min/2 << endl;
  }
  else
  {
    cout << diff_max_mid + diff_max_min/2 + 2 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
const DIV:usize = 1000000007;
const MOVES: [(i32, i32); 4] = [(1, 0), (0, 1), (-1, 0), (0, -1)];
use std::collections::BTreeSet;
fn main(){
    input!{
        n:usize,
        s:chars,
    }
    let mut sum_v = vec![0;n+1];
    for j in 1..n+1 {
        if s[j-1] == 'W'{
            sum_v[j] = sum_v[j-1] + 1;  
        } else {
            sum_v[j] = sum_v[j-1];
        }
    }
    let mut ans = usize::max_value();
    for j in 0..n{
        let count = sum_v[j]+n-(j+1) -(sum_v[n]-sum_v[j+1]);
        ans = min(count,ans);
    };
    println!("{}",ans);
}

Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll X;
  cin >> X;
  
  ll c1=0;
  ll c2=0;
  while(X >= 500){
    X -= 500;
    c1++;
  }
  while(X >= 5){
    X -= 5;
    c2++;
  }
  cout << c1*1000+c2*5 << endl;
}


Measured memory_bytes: 3580
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> h(n);
    for(auto &e : h) std::cin >> e;
    std::vector<std::priority_queue<int, std::vector<int>, std::less<>>> x(n);
    rep(i, m) {
        int a, b;
        std::cin >> a >> b;
        a--;
        b--;
        x[a].push(h[b]);
        x[b].push(h[a]);
    }
    int ans = 0;
    rep(i, n) {
        if(x[i].empty() or x[i].top() < h[i]) {
            ans++;
        }
    }
    std::cout << ans << std::endl;
}

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

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,t=0,ca,cb;
	cin>>n;
	vector<int>v(n),a(n),b(n);
	for(int i=0;i<n;i++)cin>>v.at(i);
	a=v;
	for(int i=0;i<n;i++)cin>>v.at(i);
	b=v;
	sort(v.begin(),v.end());
	do{
		t++;
		if(v==a){
			ca=t;
		}
		if(v==b){
			cb=t;
		}
	}while(next_permutation(v.begin(),v.end()));
	cout<<abs(ca-cb)<<endl;
}


Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\ALDS1_6_A-in9.txt"));

		int n = scan.nextInt();
		Tree t = new Tree(n);

		for (int i = 0; i < n; i++) {
			String s = scan.next();
			if (s.equals("insert"))
				t.insert(i, scan.nextInt());
			else if (s.equals("find"))
				t.find(scan.nextInt());
			else {
				t.printInorder();
				t.printPreorder();
			}
		}

		scan.close();
		System.exit(0);
	}
}

class Tree {

	private class Node {
		public Node(int _key) {
			key = _key;
		}

		int key;
		int Parent = -1;
		int LeftChild = -1;
		int RightChild = -1;
	}

	Node[] node;
	int root = -1;

	public Tree(int n) {
		node = new Node[n];
	}

	public void find(int key) {
		find(root, key);
	}

	private void find(int x, int key) {
		if (x == -1)
			System.out.println("no");
		else if (node[x].key == key)
			System.out.println("yes");
		else if (key < node[x].key)
			find(node[x].LeftChild, key);
		else
			find(node[x].RightChild, key);
	}

	public void printPreorder() {
		printPre(root);
		System.out.println();
	}

	private void printPre(int id) {
		if (id == -1)
			return;
		System.out.print(" " + node[id].key);
		printPre(node[id].LeftChild);
		printPre(node[id].RightChild);
	}

	public void printInorder() {
		printIn(root);
		System.out.println();
	}

	private void printIn(int id) {
		if (id == -1)
			return;
		printIn(node[id].LeftChild);
		System.out.print(" " + node[id].key);
		printIn(node[id].RightChild);
	}

	public void insert(int i, int key) {
		node[i] = new Node(key);
		insert(i);
	}

	private void insert(int z) {
		int y = -1;
		int x = root;
		while (x != -1) {
			y = x;
			if (node[z].key < node[x].key)
				x = node[x].LeftChild;
			else
				x = node[x].RightChild;
		}
		node[z].Parent = y;

		if (y == -1)
			root = z;
		else if (node[z].key < node[y].key)
			node[y].LeftChild = z;
		else
			node[y].RightChild = z;
	}
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
using ll = long long;
using Graph = vector<vector<int>>;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
 
const int MOD = 1000000007;
using mint = Fp<MOD>;

int main(){
    int N; cin>>N;
    vector<ll> A(N); rep(i,N)cin>>A.at(i);

    mint res = 0;
    mint two = 1;
    for(int i = 0; i < 60; i++){
        ll zero = 0, one = 0;
        for(int n = 0; n < N; n++){
            if(A.at(n)&(1LL<<i))one++;
            else zero++;
        }
        res += mint(zero*one)*two;
        two*=2;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 2560
N=int(input())
S=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            count=0
            for s in S:
                if count==0:
                    if s==str(i):
                        count+=1
                elif count==1:
                    if s==str(j):
                        count+=1
                elif count==2:
                    if s==str(k):
                        count+=1
                if count==3:
                    ans+=1
                    break
print(ans)

Measured memory_bytes: 74776
module Main where

import           Control.Monad
import           Control.Monad.State
import           Data.Array.IO
import           Data.List
import           Data.List.Split
import           Data.Ord
import qualified Data.Vector.Unboxed as V
import           Text.Printf

main :: IO ()
main = do
  n <- readLn
  ss <- replicateM n getLine :: IO [String]
  let cs = (sum . map count) ss
      both = (length . filter (\x -> head x == 'B' && last x == 'A')) ss
      as = (length . filter ((==) 'A' . last)) ss - both
      bs = (length . filter ((==) 'B' . head)) ss - both
  print $ cs + ans both as bs
  where
    count (a:b:xs)
      | a == 'A' && b == 'B' = 1 + count xs
      | b == 'A' = count (b:xs)
      | otherwise = count xs
    count _ = 0

    ans both as bs
      | as == 0 && bs == 0 = max (both - 1) 0
      | bs == 0 = both
      | as == 0 = both
      | otherwise = both + min as bs



Measured memory_bytes: 5500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s,t;
    cin>>s;
    t=s;
    reverse(begin(t),end(t));
    int ans=0;
    rep(i,s.size()) if(s[i]!=t[i]) ans++;
    cout<<ans/2<<endl;
}

Measured memory_bytes: 3584