akhauriyash/Code-Regression huggingface dataset:
M,N = map(int,input().split())

ans = 1
modulo = 10**9+7
if N==M:
    for i in range(N):
        ans *= (i+1)
        ans %= modulo
        ans *= (i+1)
        ans %= modulo
    ans *= 2
    ans %= modulo
else:
    A,B = max(M,N),min(N,M)
    if A-B==1:
        for i in range(N):
            ans *= (i+1)
            ans %= modulo
        for i in range(M):
            ans *= (i+1)
            ans %= modulo
    else:
        ans = 0

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()

using namespace std;

int n, a, b;
int ans[1 << 17];
int full;

int bit(int mask) {
	rep(i, 0, n - 1)
		if ((mask >> i) & 1) return i;
	return -1;
}

void solve(int l, int r, int x, int y, int f) {
	if (l + 1 == r) {
		ans[l] = x;
		ans[r] = y;
		return;
	}
	int b = bit((x ^ y));
	int X = x;
	int Y = y;
	if ((x >> b) & 1) X ^= (1 << b);
	if ((y >> b) & 1) Y ^= (1 << b);
	assert(__builtin_popcount(X) % 2 == __builtin_popcount(Y) % 2);
	int m = (l + r) / 2;
	int q = -1;
	f ^= (1 << b);
	rep(i, 0, n - 1)
		if (!((f >> i) & 1)) {
			q = i;
			break;
		}
	int z = (X ^ (1 << q));
	solve(l, m, X, z, f);
	solve(m + 1, r, z, Y, f);
	if ((x >> b) & 1) rep(i, l, m) ans[i] ^= (1 << b);
	if ((y >> b) & 1) rep(i, m + 1, r) ans[i] ^= (1 << b);
}

int main() {
	scanf ("%d%d%d", &n, &a, &b);
	full = (1 << n) - 1;
	if (__builtin_popcount(a) % 2 == __builtin_popcount(b) % 2) return printf ("NO\n"), 0;
	printf ("YES\n");
	solve(0, full, a, b, 0);
	rep(i, 0, full) printf ("%d ", ans[i]);
	
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>  
#include <cstdio>  
#include <stack>  
#include <vector>  
#include <algorithm>  
using namespace std;  
  
int main(){  
  stack<int> S1;  
  stack<pair<int, int> > S2;  
  char ch;  
  int sum = 0;  
  for(int i = 1;cin >> ch; i++){  
    if(ch == '\\')S1.push(i);  
    else if(ch == '/' && S1.size() > 0){  
      int j = S1.top();S1.pop();  
      sum += i - j;  
      int a = i - j;  
      while(S2.size() > 0 && S2.top().first > j){  
        a += S2.top().second;S2.pop();  
      }  
      S2.push(make_pair(j, a));  
    }  
  }  
  vector<int> ans;  
  while(S2.size() > 0){ans.push_back(S2.top().second);S2.pop();}  
  reverse(ans.begin(),ans.end());  
  cout<< sum << endl;  
  cout<< ans.size();  
  for( int i = 0; i < ans.size(); i++){  
    cout<< " ";  
    cout<< ans[i];  
  }  
  cout << endl;  
  return 0;  
}  

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

int main() {
  char a,b;
  cin>>a>>b;
  if(a==b) cout<<"="<<endl;
  else if(a>b) cout<<'>'<<endl;
  else cout<<'<'<<endl;
  return 0;
}


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

using namespace std;
vector<int> H;


int f(int l, int r) {
    if (l > r) return 0;

    int lowest = l;
    for (int i = l; i <= r; i++) {
        if (H[i] < H[lowest]) lowest = i;
    }

    int dec = H[lowest];
    for (int i = l; i <= r; i++) {
        H[i] -= dec;
    }

    return f(l, lowest - 1) + f(lowest + 1, r) + dec;
}

int main() {
    int n; cin >> n;
    H.resize(n);

    for (int i = 0; i < n; i++) cin >> H[i];

    cout << f(0, H.size() - 1) << endl;
    return 0;    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int dp[100][100];
bool solve(int x,int y)
{

	if(x==0 && y==0)
	{
		return true;

	}


	if(x<=0)
	{
		return false;
	}

	if(dp[x][y]!=-1)
		return dp[x][y];

	int ans=solve(x-1,y-2)||solve(x-1,y-4);
	dp[x][y]=ans;
	return ans;
}

int main()
{

	fastio;
		
	int x,y;
	cin>>x>>y;
	memset(dp,-1,sizeof(dp));
	if(solve(x,y))
	{
		cout<<"Yes";
	}
	else
		cout<<"No";
	return 0;
}







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

int main(){
  int n; cin>>n;
  vector<vector<int>> d(n,vector<int>(2));
  for(int i=0;i<n;i++){
    for(int j=0;j<2;j++)
      cin>>d[i][j];
  }
  bool x=false;
  for(int i=0;i<n-2;i++){
    if(d[i][0]==d[i][1]){
      if(d[i+1][0]==d[i+1][1])
        if(d[i+2][0]==d[i+2][1])
          x=true;
    }
  }
  
  if(x)
    cout<<"Yes"<<endl;
  else 
    cout<<"No"<<endl;
}

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

using namespace std;

#define EPS 1e-12

int main()
{
    int n, k, x;

    cin >> n >> k;

    vector <double> a(n+1, 0.0);
    vector <double> b(n+1, 0.0);

    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        a[i] = (1.0 + x) / 2.0;
        b[i] += b[i-1] + a[i];
    }

    // for (int i = 1; i <= n; i++)
    //     cout << a[i] << " ";
    // cout << "\n";

    // for (int i = 1; i <= n; i++)
    //     cout << b[i] << " ";
    // cout << "\n";

    double ans = 0.0;

    for (int i = 1; i <= n-k+1; i++)
    {
        double s = b[i+k-1] - b[i-1];

        if (s - ans > EPS)
        {
            ans = s;
        }
    }

    cout << fixed << setprecision(12) << ans << "\n";

    return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        char[] S = scanner.next().toCharArray();
        for (int i=0; i< S.length; i++) {
            if (i%2==0) {
                if (S[i] == 'L') {
                    System.out.println("No");
                    return;
                }
            }else {
                if (S[i] == 'R') {
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }

}

Measured memory_bytes: 21844
N = int(input())

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

B=[0]*N
B[0] = A[0]
saitei = float("inf")
for i in range(N-1):
    saitei = min(abs(B[i]-(a-B[i])), saitei)
    B[i+1] += (A[i+1] + B[i])
    
print(saitei)

Measured memory_bytes: 24832
use std::collections::{HashMap};
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)*}
    };
}

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")
    };
}
fn main() {
    input!(
    n: usize,
    a: [usize; n],
    );
    let o_a = a.clone();
    let mut a = a;
    a.sort();
    let a_len = a.len() - 1;
    let mut counts = vec![1_usize];
    let mut hash = vec![a[0_usize]];
    let mut n = 0;
    let mut sum = 0;
    for (i, v) in a.clone().into_iter().enumerate() {
        if i == a_len { break; }
        let k = a[i+1];
        if v == k {
            counts[n] += 1;
        } else {
            counts.push(1);
            hash.push(a[i + 1]);
            n += 1;
        }
    }
    let mut hashmap = HashMap::new();
    let tmp_c = counts.clone().into_iter();
    for (k, v) in hash.into_iter().zip(tmp_c){
        hashmap.insert(k, v);
    }
    for w in counts {
        sum += w * (w - 1) / 2;
    }
    for i in o_a {
        let num = hashmap[&i];
        println!("{}", sum - (num - 1));
    }
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll A[405], sum[405], DP[405][405];
bool visited[405][405];

ll Solve(int L, int R){
  if (visited[L][R]) return DP[L][R];
  visited[L][R] = true;
  if (L == R) return 0;
  ll ans = 1e18;
  for (int i = L; i + 1 <= R; i++){
    ans = min(ans, Solve(L, i) + Solve(i + 1, R));
  }
  return DP[L][R] = ans + sum[R] - sum[L-1];
}

int main(){
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    sum[i] = sum[i-1] + A[i];
  }
  cout << Solve(1, N) << endl;

  return 0;
}


Measured memory_bytes: 4976
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int n,r,k = 0;
  cin >> n >> r;
  if (n >= 10){
    cout << r << '\n';
  }
  k = 100 * (10 - n);
  if (n < 10){
    cout << r + k << '\n';
  }
  return 0;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	vector <int> odds, evens;
	for (int i = 0; i < m; ++i)
	{
		int x;
		cin>>x;
		if(x%2)
			odds.push_back(x);
		else
			evens.push_back(x);
	}
	if(odds.size() > 2)
		cout<<"Impossible\n";
	else
	{
		vector <int> A, ans;
		if(odds.size() >= 1)
			A.push_back(odds[0]);
		for (int i = 0; i < evens.size(); ++i)
		{
			A.push_back(evens[i]);
		}
		if(odds.size() >= 2)
			A.push_back(odds[1]);
		if(A.size() == 1)
		{
			ans.push_back(A[0]-1);
			ans.push_back(1);
		}
		else
		{
			for (int i = 0; i < A.size(); ++i)
			{
				if(i == 0)
					ans.push_back(A[i] - 1);
				else if(i == A.size() - 1)
					ans.push_back(A[i] + 1);
				else
					ans.push_back(A[i]);
			}
		}
		vector <int> fans;
		for (int i = 0; i < ans.size(); ++i)
		{
			if(ans[i])
				fans.push_back(ans[i]);
		}
		for (int i = 0; i < A.size(); ++i)
		{
			cout<<A[i]<<" ";
		}
		cout<<"\n"<<fans.size()<<"\n";
		for (int i = 0; i < fans.size(); ++i)
		{
			cout<<fans[i]<<" ";
		}
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input(''))
def e(x,y):
    z=1
    if x<y:
        z=x
        x=y
        y=z

    while x!=0 and y!=0 and z!=0 and x!=y:
        z=x%y
        x=y
        y=z
    return x

el=[]
for a in range(n):
    kara=[]
    for b in range(n):
        kara.append(e(a+1,b+1))
    
    el.append(kara)

s=0
for a in range(n):
    for b in range(n):
        u=el[a][b]
        for c in range(n):
            v=el[b][c]
            w=el[u-1][v-1]
            s=s+w

print(s)

Measured memory_bytes: 9368
#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 N, X, Y, V;
typedef pair<int, int> P;
struct edge
{
    int to, cost;
};

vector<edge> G[2020];
int d[2020];

void dijkstra(int s)
{
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V + 1, inf);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;

        for (int i = 0; i < G[v].size(); i++)
        {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int ans[2020];

int main()
{
    cin >> N >> X >> Y;
    V = N;
    repe(i, 1, N - 1)
    {
        G[i].push_back(edge{i + 1, 1});
        G[i + 1].push_back(edge{i, 1});
    }
    G[X].push_back(edge{Y, 1});
    G[Y].push_back(edge{X, 1});

    for (int i = 1; i <= N - 1; i++)
    {
        dijkstra(i);
        for (int j = i + 1; j <= N; j++)
        {
            ans[d[j]]++;
        }
    }

    for (int i = 1; i <= N - 1; i++)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 384
s=int(input())
a=s//100
b=s%100

if a*b:
  if a<=12:
    if b<=12:
      print('AMBIGUOUS')
    else:
      print('MMYY')
  else:
    if b<=12:
      print('YYMM')
    else:
      print('NA')
else:
  if a:
    if a<=12:
      print('MMYY')
    else:
      print('NA')
  elif b:
    if b<=12:
      print('YYMM')
    else:
      print('NA')
  else:
    print('NA')

Measured memory_bytes: 38256
#include<stdio.h>
int main(void){
    int n,m;
    char s[55][55];
    int i,j,k,c;
    int row,ans=2500,count;

    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++) scanf("%s",s[i]);


    for(i=1;i<=n-2;i++){
	for(j=1;i+j<=n-1;j++){
	    row=0;count=0;

	    for(k=0;k<i;k++){
		for(c=0;c<m;c++){
		    if(s[row][c]!='W') count++;
		}
		row++;
	    }
	    for(k=0;k<j;k++){
                for(c=0;c<m;c++){
                    if(s[row][c]!='B') count++;
                }
                row++;
            }
	    for(k=0;k<n-i-j;k++){
                for(c=0;c<m;c++){
                    if(s[row][c]!='R') count++;
                }
                row++;
            }

	    if(count<ans) ans=count;
	}
    }

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 600
// 問題の URL を書いておく
// https://atcoder.jp/contests/abc065/tasks/arc076_b

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <numeric>
#include <cmath>
using namespace std;

//#define ENABLE_PRINT

template<typename T>
T Input()
{
    T v;
    cin >> v;
    return v;
}

template<typename T>
vector<T> InputVector(int n)
{
    vector<T> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

template<typename T>
void InputArray(T* begin, int n)
{
    for(int i = 0; i < n; ++i)
    {
        cin >> begin[i];
    }
}

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

struct Vertex
{
    int id;
    int x;
    int y;
    int parent;
    int root(vector<Vertex>& vs)
    {
        if(parent == -1)
        {
            return id;
        }
        auto r = vs[parent].root(vs);
        parent = r;
        return r;
    }
};

struct Edge
{
    int s;
    int t;
    int d;
};

int main(int, const char**)
{
    int n;
    cin >> n;
    vector<Vertex> vs(n);
    vector<int> xs(n), ys(n);
    rep(i, n)
    {
        int x, y;
        cin >> x >> y;
        vs[i] = {i, x, y, -1};
        xs[i] = i;
        ys[i] = i;
    }

    sort(xs.begin(), xs.end(), [&vs](const auto& a, const auto& b){
        return vs[a].x < vs[b].x;
    });
    sort(ys.begin(), ys.end(), [&vs](const auto& a, const auto& b){
        return vs[a].y < vs[b].y;
    });
    vector<Edge> es(n * 2);
    es.resize(0);
    rep(i, n - 1)
    {
        es.push_back({xs[i], xs[i + 1], abs(vs[xs[i]].x - vs[xs[i + 1]].x)});
        es.push_back({ys[i], ys[i + 1], abs(vs[ys[i]].y - vs[ys[i + 1]].y)});
    }

    sort(es.begin(), es.end(), [](const auto& a, const auto& b){
        return a.d < b.d;
    });

    int64_t cost = 0;
    for(auto& e : es)
    {
        auto& s = vs[e.s];
        auto& t = vs[e.t];
        auto d = e.d;
        if(s.root(vs) == t.root(vs))
        {
            continue;
        }
        cost += d;
        vs[t.root(vs)].parent = e.s;
    }

    cout << cost << endl;
    return 0;
}


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

int main(){
  int n, k; cin >> n >> k;
  long long ans = 0;
  vector<long long> h(n);
  
  for(int i = 0; i < n; i++) cin >> h[i];
  
  sort(h.begin(), h.end());
  
  for(int i = 0; i < n-k; i++) ans += h[i];
  
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int a[114514];
int dif[114514];

int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	if (a[n - 1] < k)puts("IMPOSSIBLE");
	else {
		for (int i = 0; i < n - 1; i++)dif[i] = a[i + 1] - a[i];

		sort(dif, dif + n - 1);
		int mindif = dif[0];
		if (mindif == 0) {
			for (int i = 0; i < n - 1; i++) {
				if (dif[i] != 0) {
					mindif = dif[i];
					break;
				}
			}
		}
		for (int i = 0; i < n; i++) { if (a[i] - mindif != 0)mindif = min(mindif, abs(a[i] - mindif)); }
		if (mindif == 0) {
			for (int i = 0; i < n; i++) {
				if (a[i] == k) {
					puts("POSSIBLE");
					return 0;
				}
			}
			puts("IMPOSSIBLE");
		}
		else if (k%mindif == 0)puts("POSSIBLE");
		else puts("IMPOSSIBLE");
	}
	
}

Measured memory_bytes: 1024
T=0

def wa(a):
    s=0
    A = list(str(a))
    for i in range(len(A)):
        s += int(A[i])
    return s

N,A,B = map(int, input().split())

for i in range(1, N+1):
    if(i<10 and A<=i and i<=B):
        T+=i
    elif(i>=10 and A<=wa(i) and wa(i)<=B):
        T+=i

print(T)

Measured memory_bytes: 3060
import collections
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))
c = collections.Counter(a)

total = 0
for count in c.values():
    total +=  count*(count-1)//2

d = defaultdict(list)

for number in c.keys():
    count = c[number]
    d[number] = total - (count-1)

for i in a:
    print(d[i])



Measured memory_bytes: 32372
#ifdef __unix__
#include <bits/stdc++.h>
#else
#include <iostream>
#include <algorithm>
#include <math.h>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <bitset>
#endif

#define fastIO ios_base::sync_with_stdio(0), cin.tie(NULL)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define mkp make_pair
/*#define NUMTOSTR(x)  (unsigned char)((x) + 48);*/
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long  ull;
using namespace std;

int main(){
	fastIO;
	int n, lim;
	cin >> n >> lim;
	int ans = 0;
	while (n--)
	{
		int temp;
		cin >> temp;
		if (temp >= lim) ans++;
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b);
#define chmin(a, b) (a)=min(a, b);
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/



int main(void) {
  ll i, j, k;
  
  ll N, K;
  cin >> N >> K;
  ll a[MAX], b[MAX];
  
  for(i=0; i<N; i++) cin >> a[i] >> b[i];
  
  ll ans=0;
  for(i=0; i<N; i++) if((K|a[i])==K) ans+=b[i];
  
  for(i=0; i<=30; i++) {
    if(!(K>>i&1)) continue;
    ll S=(K>>(i+1))<<(i+1) | ((1<<i)-1);
    ll t=0;
    for(j=0; j<N; j++) if((S|a[j])==S) t+=b[j];
    chmax(ans, t);
  }
  
  pt(ans);
  
}





Measured memory_bytes: 1792
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CAverageLength {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    vector<double> x, y;
    set<double> s;
    int N;

    double dfs(int v, int d, double cur) {
        if (d == N - 1) {
            return cur;
        }

        s.insert(v);
        double res = 0;
        REP(i, N) {
            if (s.count(i)) continue;
            double tmp = sqrt((x[v] - x[i]) * (x[v] - x[i]) + (y[v] - y[i]) * (y[v] - y[i]));
            res += dfs(i, d + 1, cur + tmp);
        }
        s.erase(v);
        return res;
    }

    void solve(std::istream& cin, std::ostream& cout) {
        cin >> N;
        x = vector<double>(N);
        y = vector<double>(N);
        REP(i, N) cin >> x[i] >> y[i];

        double sum = 0;
        REP(i, N) {
            sum += dfs(i, 0, 0);
        }

        int m = 1;
        FOR(i, 1, N) m *= i;
        fcout << sum / (double) m << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CAverageLength solver;
    solver.solve(in, out);
    return 0;
}


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

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

	int ret = 0;
	for (int i = 1; i < n - 1; ++i) {
		if (p[i - 1] <= p[i]) {
			if (p[i] < p[i + 1]) {
				++ret;
			}
		}
		else { // p[i] < p[i - 1]
			if (p[i + 1] <= p[i]) {
				++ret;
			}
		}
	}
	
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define max 100000

int partition(int A[],int p,int r){
  int x,i,j,m;
  
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      m=A[i];
      A[i]=A[j];
      A[j]=m;
    }
  }
  m=A[i+1];
  A[i+1]=A[r];
  A[r]=m;
  
  return i+1;
}


int main(){
  int n,i,p,q,r;
  int A[max];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  p=0;
  r=n-1;
  q=partition(A,p,r);

  for(i=0;i<n-1;i++){
    if(i==q) printf("[%d] ",A[i]);
    else printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);

  return 0;
}



Measured memory_bytes: 2112
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        sc.close();

        System.out.print(Double.valueOf(w) * Double.valueOf(h) / 2.0);
//        if (w / 2 == x && w % 2 == 0 && h / 2 == y && h % 2 == 0) {
        if (w == x * 2 && h == y * 2) {
            System.out.println(" 1");
        } else {
            System.out.println(" 0");
        }
    }

}


Measured memory_bytes: 21332
#include <stdio.h>

typedef struct {
    double x;
    double y;
} vector;

vector vector_sub(vector a, vector b){
    vector ret;
    ret.x = a.x - b.x;
    ret.y = a.y - b.y;
    return ret;
}

double vector_product(vector a, vector b){
    return a.x * b.y - a.y * b.x;
}

int main(void){
    vector t1,t2,t3,tp;
    vector v12,v23,v31,v1p,v2p,v3p;
    double z1,z2,z3;

    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&t1.x,&t1.y,&t2.x,&t2.y,&t3.x,&t3.y,&tp.x,&tp.y)>=8){
        /* 辺と頂点→Pをベクトル化 */
        v12 = vector_sub(t2,t1);
        v23 = vector_sub(t3,t2);
        v31 = vector_sub(t1,t3);
        v1p = vector_sub(tp,t1);
        v2p = vector_sub(tp,t2);
        v3p = vector_sub(tp,t3);
        
        /* ベクトル外積が全て向きが同じなら内部にある */
        z1 = vector_product(v12, v2p);
        z2 = vector_product(v23, v3p);
        z3 = vector_product(v31, v1p);
        
        printf( ( ((z1>0)&&(z2>0)&&(z3>0)) || ((z1<0)&&(z2<0)&&(z3<0)) ) ? "YES\n":"NO\n" );
    }
    return 0;
}

Measured memory_bytes: 616
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
#define PI = 3.14159265358979323846
/*------------------------------------------------------------------------------*/

int count_DFS(const vector<vector<int>>& G, int index, int cnt, VI& used, int num){
  int ans = 0;

  used[index] = 1;

  cnt++;
  if(cnt == num){
    ans++;
  } else {
    REP(i, 1, (int)G[index].size()+1){
      if(G[index][i] == 1 && !used[i]){
        ans += count_DFS(G, i, cnt, used, num);
      }
    }
  }
  used[index] = 0;

  return ans;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N+1, vector<int>(N+1,0));

  REP(i, 0, M){
    int a, b;
    cin >> a >> b;
    G[a][b] = 1;
    G[b][a] = 1;
  }

  VI used(N+1, 0);
  cout << count_DFS(G, 1, 0, used, N) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
  
  	long long n;
    cin>>n;
    long long a[n];
    long long sum=0;
    for(long long i=0;i<n;i++){
      cin>>a[i];
      if(a[i]<a[i-1] && i!=0){
        sum=sum+(a[i-1]-a[i]);
        a[i]=a[i-1];
      }
    }
      cout<<sum;
  	return 0;
  
}

Measured memory_bytes: 5160
#include<stdio.h>
int main(void){
	int card[3];
	while(scanf("%d%d%d",&card[0],&card[1],&card[2])!=EOF){
		if((card[0]+card[1]+(55-card[0]-card[1]-card[2])/7)<=20)
			printf("YES\n");
		else
		printf("NO\n");
	}
	return 0; 
}

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

int main(){
  int N;
  ll W;
  cin >> N >> W;
  pair<ll,int> p[N];
  for(int i=0;i<N;i++) cin >> p[i].first >> p[i].second;
  ll w1 = p[0].first;

  sort(p,p+N);

  vector<int> val[4];
  for(int i=N-1;i>=0;i--){
    int ind = p[i].first - w1;
    val[ind].push_back(p[i].second);
  }

  /*for(int i=0;i<4;i++){
    for(int j=0;j<val[i].size();j++){
      cout << val[i][j] ;
    }
    cout << endl;
  }*/

  //累積和
  ll sum[4][101];
  fill(sum[0],sum[4],0LL);
  for(int i=0;i<4;i++){
    for(int j=1;j<=(int)val[i].size();j++){
      sum[i][j] = sum[i][j-1] + val[i][j-1];
    }
  }

  /*for(int i=0;i<4;i++){
    for(int j=0;j<=(int)val[i].size();j++){
      cout << sum[i][j] ;
    }
    cout << endl;
  }*/

  ll ans = 0LL;
  for(int i=0 ; i<=(int)val[0].size() ; i++){
    for(int j=0 ; j<=(int)val[1].size() ; j++){
      for(int k=0 ; k<=(int)val[2].size() ; k++){
        if(i*w1 + j*(w1+1) + k*(w1+2) <= W){
          int l = (W-((i+j+k)*w1 + j + 2*k)) / (w1 + 3);
          ll res = sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l];
          ans = max(ans, res);
        }
      }
    }
  }

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


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n;
  cin >> n;
  vector<tuple<int, int>> ts;
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    ts.push_back(make_tuple(i + 1, c));
  }
  sort(ts.begin(), ts.end(), [](const auto& t1, const auto& t2) {
    return get<1>(t1) < get<1>(t2);
  });
  for (const auto& t : ts) {
    cout << get<0>(t) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1780
import bisect
import sys
input=sys.stdin.readline
n,d,a=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()

data0=[0]*(n+1)
data1=[0]*(n+1)

def _add(data,k,x):
  while k<=n:
    data[k]+=x
    k+=k&-k

def add(l,r,x):
  _add(data0,l,-x*(l-1))
  _add(data0,r,x*(r-1))
  _add(data1,l,x)
  _add(data1,r,-x)

def _get(data,k):
  s=0
  while k:
    s+=data[k]
    k-=k&-k
  return s

def query(l,r):
  return _get(data1,r-1)*(r-1)+_get(data0,r-1)-_get(data1,l-1)*(l-1)-_get(data0,l-1)

x=[]
for i in range(n):
  x.append(l[i][0])
  add(i+1,i+2,l[i][1])

Right=[]
for i in range(n):
  Right.append(bisect.bisect_right(x,x[i]+2*d))

p=0
ans=0
while p<n:
  Q=query(p+1,p+2)
  add(p+1,Right[p]+1,-((Q+a-1)//a)*a)
  ans+=(Q+a-1)//a
  p=min(p+1,n-1)
  while query(p+1,p+2)<=0:
    p+=1
    if p==n:
      break
print(ans)

Measured memory_bytes: 111836
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	X = float("inf")
	s = sum(A)
	c = 0
	for i in range(N):
		c += A[i]
		X = min(X, abs(s - 2 * c))
	print(X)
	


if __name__ == '__main__':
	main()

Measured memory_bytes: 23640
import sys
input = sys.stdin.readline
from itertools import *
from collections import *

INF = float('inf')


def main():
    N = int(input())
    total_odd = 0
    for i in range(1, N + 1):
        if not i % 2 == 0:
            total_odd += 1
    print(total_odd / N)


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int x, k;
  cin >> k >> x;
  if(k * 500 >= x) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  } 
  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int main()
{
	fast;
	int a,b,c;
	cin>>a>>b>>c;
	if (b-a==c-b)
	   cout<<"YES"<<endl;
	else
	   cout<<"NO"<<endl;
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

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

  return 0;
}


Measured memory_bytes: 256
N = int(raw_input())
res = []
base = N
x = 1
if base == 0:
    print(0)
else:
    while True:
        if base == 0:
            break
        if base % (2 ** x) != 0:
            res.append(1)
            base -= (-2) ** (x-1)
        else:
            res.append(0)
        x += 1
    print(''.join([str(i) for i in reversed(res)]))



Measured memory_bytes: 2820
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

int h, w;
string s[51];
int d[51][51];
int dy[4] = {-1, 0, 1, 0};
int dx[4] = { 0, 1, 0, -1};
bool contain(int y, int x){
   return (0 <= y && y < h && 0 <= x && x < w);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w;
    int cnt = 0;
    rep(i, 0, h) cin >> s[i];
    rep(i, 0, h) rep(j, 0, w) d[i][j] = INF;
    rep(i, 0, h) rep(j, 0, w) if(s[i][j] == '#') cnt++;
    queue<P> q;
    q.push({0, 0});
    d[0][0] = 1;
    while(!q.empty()){
        P p = q.front(); q.pop();
        if(p.first == h - 1 && p.second == w - 1){
            break;
        }
        rep(i, 0, 4){
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if(!contain(ny, nx) || d[ny][nx] != INF || s[ny][nx] == '#') continue;
            q.push({ny, nx});
            d[ny][nx] = d[p.first][p.second] + 1;
        }   
    }
    int ans = h * w - cnt - d[h - 1][w - 1];
    if(d[h - 1][w - 1] == INF) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const ll inf = 4e18 +123;
//const int inf = 1e9 + 123;
const ll MAX = 1e6;

ll a,b,c,d;
map<ll,ll> m;
ll dfs(ll n)
{
	if(m.find(n)!=m.end())
		return m.find(n)->second;
	ll ret = inf;
	if(d<=(inf/n))
		ret = d*n;
	ret = min(ret, dfs(n/5) + (n%5)*d+c);
	ret = min(ret, dfs(n/3) + (n%3)*d+b);
	ret = min(ret, dfs(n/2) + (n%2)*d+a);

	if(n%5!=0)
	ret = min(ret, dfs(n/5+1) + (5-n%5)*d+c);
	if(n%3!=0)
	ret = min(ret, dfs(n/3+1) + (3-n%3)*d+b);
	if(n%2!=0)
	ret = min(ret, dfs(n/2+1) + (2-n%2)*d+a);
	m.insert({n, ret});
	return ret;
}
void solve()
{
	ll n;
	cin >> n >> a >> b >> c >> d;
	m.clear();
	m.insert({0, 0});
	m.insert({1, d});
	cout << dfs(n) << endl;
}
int main()
{    
//	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
	int t;
	cin >> t;
	while(t--)
	solve();
}

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

int main(){
  int N;
  cin >> N;
  
  int count = 0;
  for(int i = 1; i <= N; i++){
    int c = 0;
    
    int j = i;
    while(j>0){
      j/=10;
      c+=1;
    }
    if(c % 2 != 0){
      count += 1;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    string t = read!string;

    int len = 0;
    int s = 0;
    foreach (c; t) {
        switch (c) {
        case 'S':
            s++;
            break;
        case 'T':
            if (s > 0) s--;
            else {
                // ペアになれなかった T はそのまま残る(後ろの文字とペアになることはない)
                len++;
            }
            break;
        default:
            break;
        }
    }
    writeln(len + s);
}



Measured memory_bytes: 2684
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<tuple<string, int, int>> table(N);
  for(int i = 0; i < N; i++){
  string a;
  int b, c;
    cin >> a >> b;
    b *= -1;
    c = i + 1;
    table.at(i) = make_tuple(a, b, c);
  }
  sort(table.begin(), table.end());//町についてのsortが完了
  
  for(int i = 0; i < N; i++){
    string a;
    int b, c;
    tie(a, b, c) = table.at(i);
    cout << c << endl;
  }
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<deque>
#include<bitset>
#include<cmath>
#include<map>
#include<iomanip>
using namespace std;
using ll = long long int;
const ll mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a; i < b; i++)

int main() {
	
	vector<int> a(9);
	rep(i, 0, 9) cin >> a[i];

	ll n;
	cin >> n;

	vector<int> b(n);
	vector<int> c(101, 0);
	rep(i, 0, n) {
		cin >> b[i];
		c[b[i]] = 1;
	}
	
	vector<int> d(9, 0);
	rep(i, 0, 9) {
		if (c[a[i]] == 1) {
			d[i] = 1;
		}
	}

	string s = "Yes";
	if (d[0] == 1 && d[4] == 1 && d[8] == 1) {
		cout << s << endl;
		return 0;
	}
	if (d[2] == 1 && d[4] == 1 && d[6] == 1) {
		cout << s << endl;
		return 0;
	}
	rep(i, 0, 3) {
		if (d[i] == 1 && d[i + 3] == 1 && d[i + 6] == 1) {
			cout << s << endl;
			return 0;
		}
	}
	for (int i = 0; i < 9; i += 3) {
		if (d[i] == 1 && d[i + 1] == 1 && d[i + 2] == 1) {
			cout << s << endl;
			return 0;
		}
	}

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

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int a, b;
        cin >> a >> b;
        Int ans = max<Int>(0, a - 2 * b);
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long ul;
const static ul LIMIT = 100000007;

ul p[1001] = {1};
int main() {
  short r, c, a1, a2, b1, b2;
  cin >> r >> c >> a1 >> a2 >> b1 >> b2;
  short w = min(abs(b1 - a1), r - abs(b1 - a1));
  short h = min(abs(b2 - a2), c - abs(b2 - a2));
  short n = w + h;
  ul left, tmp;
  int i, j;
  for (i = 1; i <= n; i++) {
    left = 0;
    for (j = 0; j <= i; j++) {
      tmp = p[j];
      p[j] = (p[j] + left) % LIMIT;
      left = tmp;
    }
  }
  cout << (p[w] * (w * 2 == r ? 2 : 1) * (h * 2 == c ? 2 : 1)) % LIMIT << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {
    long long n;
	long long max = 0;

	cin >> n;

	for (long long i = 1; i <= n; i++) {
		if (i * i <= n) {
			max = i * i;
		}
	}
	
	cout << max << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cmath>

#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)
using namespace std;
class P{
public:
	int n;
	string s;
	int index;
	bool operator<(P x){
		return n < x.n;
	}
};

int main(){
	int n;string str;
	P A[36],B[36];
	cin >> n;
	REP(i,n){
		cin >> str;
		A[i].s=str;
		A[i].n=str[1];
		A[i].index=i;
		B[i] = A[i];
	}
	REP(i,n){
		for(int j=n-1;j>i;j--){
			if(A[j] < A[j-1]) swap(A[j],A[j-1]);
		}
	}
	REP(i,n){
		int minj=i;
		for(int j=i+1;j<n;j++){
			if(B[j] < B[minj])minj=j;
		}
		swap(B[i],B[minj]);
	}
	bool a=true,b=true;
	REP(i,n-1){
		if(A[i].n==A[i+1].n && A[i].index > A[i+1].index) a=false;
		if(B[i].n==A[i+1].n && B[i].index > B[i+1].index) b=false;
	}
	cout << A[0].s;
	REP(i,n-1){
		cout << " " << A[i+1].s;
	}
	cout << endl << (a?"Stable":"Not Stable") << endl;
	cout << B[0].s;
	REP(i,n-1){
		cout << " " << B[i+1].s;
	}
	cout << endl << (b?"Stable":"Not stable") << endl;
	return 0;
}



Measured memory_bytes: 3188
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

int main() {
    ll A, B;
    cin >> A >> B;

    if (A <= 8 && B <= 8)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>

int main()
{
    char a;
    std::cin >> a;
    if ('a' <= a && a <= 'z') {
        std::cout << "a";
    } else {
        std::cout << "A";
    }
    return 0;
}


Measured memory_bytes: 3032
#include<bits/stdc++.h>
using namespace std;
int main(){
  int f=0;
  string a;
  cin>>a;
  for(int i=0;i<a.size()-1;i++){
    if(a[i]=='A'&&a[i+1]=='C')f=1;
  }
  if(f)cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long[] number = new long[n+1];
        number[0] = 2;
        number[1] = 1;
        for (int i=2;i<=n;i++){
            number[i] = number[i-1] + number[i-2];
        }
        System.out.println(number[n]);

    }

}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
#include <bitset>
#include<math.h>
#include<list>
using namespace std;
typedef long long ll;
int main() {
	int n;
	double ans;
	cin >> n;
	if (n % 2==0) {
		ans = 0.5;
	}
	else {
		ans = ((n + 1) / 2) / (double)n;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#include <vector>
using namespace std;
#define rep(i,n) for(ll i = 0; i < n; ++i)
#define Rep(i,n) for(ll i = 0; i <= n; ++i)
#define yes "yes"
#define Yes "Yes"
#define no "no"
#define No "No"

namespace mydef
{
  void say(string some){
    cout << some << "\n";
  }
} // namespace mydef
using namespace mydef;
typedef long long ll;
const int INF = 1001001001;

//ここからいじる

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int K; 
  string S;
  cin >> K >> S;
  if(S.size() > K){
    rep(i, K){
      cout << S[i];
    }
    cout << "..." << "\n";
  }
  else
  {
    cout << S;
  }
  
  

  return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>

int main()
{
	int a;
	int b;
	int c;
	int t;
	scanf("%d %d %d", &a, &b, &c);

	if(a > b)
	{
		t = a;
		a = b;
		b = t;	
	}

	if(a > c)
	{
		t = a;
		a = c;
		c = t;	
	}

	if(b > c)
	{
		t = b;
		b = c;
		c = t;	
	}

	printf("%d %d %d\n", a, b, c);
	return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ln '\n';
int lim=1e6;
int inf=1e9+7;
int n;
vector<vector<vector<ll> > > dp;
vector<ll> a;vector<vector<ll> > sum;

ll solve(int i,int j,int k){
    if(i>j){
        return 0;
    }
    if(dp[i][j][k]!=-1){
        return dp[i][j][k];
    }else{
        if(i==j){
            dp[i][j][k]=a[i];
            return a[i];
        }
        ll tmp1=solve(i+1,j,!k);ll tmp2=solve(i,j-1,!k);
        ll ans1=(a[i]+sum[i+1][j]-tmp1);
        ll ans2=(a[j]+sum[i][j-1]-tmp2);
        ll ans=max(ans1,ans2);
        dp[i][j][k]=ans;
        return ans;
    }
}

int main()
{   
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    dp.resize(n,vector<vector<ll> >(n,vector<ll>(2,-1)));
    a.resize(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sum.resize(n,vector<ll>(n,0));
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            if(j>0){
                sum[i][j]=sum[i][j-1]+a[j];    
            }else{
                sum[i][j]=a[j];
            }
        }
    }
    ll ans=solve(0,n-1,0);
    ans=2*ans-sum[0][n-1];
    cout<<ans<<ln;
}

Measured memory_bytes: 563328
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			boolean bl = false;
			int cnt = 0;
			for (int i = 0; i < n; i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				if (a == b) {
					cnt++;
				} else {
					cnt = 0;
				}
				if (cnt >= 3) {
					bl = true;
				}
			}
			System.out.println(bl ? "Yes" : "No");
		}
	}
}

Measured memory_bytes: 35968
n = int(input())
d = list(map(int,input().split()))

count = 0

if n % 2 == 0:
    d.sort()
    tmp = n  // 2

    if d[tmp-1] == d[tmp]:
        print(0)

    else:
        print(d[tmp]-d[tmp-1])

else:
    print(0)

Measured memory_bytes: 14396
from collections import Counter
import sys

N = int(input())
A = sorted(list(map(int, input().split())))
sum_ = sum(A)
cntA = dict(Counter(A))

Q = int(input())
map_values = {val: val for val in set(A)}
for _ in range(Q):
    B, C = map(int, sys.stdin.readline().split())
    sum_ += (C-B) * cntA.get(B, 0)

    if C in cntA:
        cntA[C] += cntA.get(B, 0)
    else:
        cntA[C] = cntA.get(B, 0)
    cntA[B] = 0
    print(sum_)


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

#define pb push_back
#define ll long long int
#define mpi map<int, int>
#define vi vector<int>
#define si set<int>
#define pii pair<int, int>
#define vpi vector<pii>
#define vs vector<string>
#define pri priority_queue<int>
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define For(i, n) for (int i = 0; i < n; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, x, y) for (int i = x; i <= y; i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

double tick()
{
    static clock_t oldt, newt = clock();
    double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
    oldt = newt;
    return diff;
}

int main()
{
    string s;
    int k;
    cin >> k;
    cin >> s;
    if (s.length() > k)
        cout << s.substr(0, k) + "..." << endl;
    else
        cout << s << endl;

    cerr << "execution time is: " << tick() << "\n";
}


Measured memory_bytes: 3824