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

d = dict()
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

counts = 0
for k, v in d.items():
    counts += v*(v-1)//2

for k in range(0, N):
    ak = A[k]
    print(counts - d[ak] + 1)

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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  int c = (g * 10) + b;
  if (c % 4 == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x=0,n,a,b;
	int sum[200]={0},keta[200]={0};

	while(scanf("%d %d",&a,&b)!=EOF)
	{
		sum[x]=a+b;
		x++;
	}

	for(n=0;n<x;n++)
	{
		while(sum[n]!=0)
		{
			sum[n]=sum[n]/10;
			keta[n]++;
		}
		printf("%d\n",keta[n]);
	}

	return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
// #include <stdlib.h>
int main()
{
    int n, x, i = 1,  max = -1000000, min = 1000000;
    long sum = 0;
    scanf("%d", &n);
    do
    {
        scanf("%d", &x);
        if (x < min)
        {
            min = x;
        }
        if (x > max)
        {
            max = x;
        }
        sum = sum + x;
        i++;
        
    } while (i <= n);
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;

    map<int, int> m;
    for (int i = 2; i <= N; ++i) {
        int tmp = i;
        for (int j = 2; j * j <= i; ++j) {
            while (!(tmp % j)) {
                tmp /= j;
                m[j]++;
            }
        }
        if (tmp > 1)
            m[tmp]++;
    }

    ll ans = 1;
    for (auto i : m)
        (ans *= (i.second + 1)) %= MOD;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    double L;
    cin >> L;
    printf("%.10f\n",(L / 3) * (L / 3) * (L / 3));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

int main() {
    fastIO;
    int n, d, rta = 0;
    cin >> n >> d;
    d = d*2+1;
    rta = ceil(1.0*n/d);
    cout << rta << endl;
    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

ll imos[31][110000];

int main() {
    ll n, c;
    cin >> n >> c;
    memset(imos, 0, sizeof(imos));
    rep(i, 0, n) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--, c--;
        imos[c][a]++;
        imos[c][b]--;
    }
    rep(i, 0, c) rep(j, 1, 110000) imos[i][j] += imos[i][j-1];
    rep(i, 0, c) rep(j, 0, 110000) if(imos[i][j]) imos[i][j] = 1;

    ll ans = 0;
    rep(i, 0, 110000) {
        ll cnt = 0;
        rep(j, 0, c) cnt += imos[j][i];
        chmax(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 26880
import math

S = input().split(" ")
A = int(S[0])
B = int(S[1])

def calculate(a,b):
    theta = 1 - 1e-9

    s1 = a/0.08
    s2 = (a + theta)/0.08


    s3 = b/0.10
    s4 = (b + theta) / 0.10

    m1 = math.ceil(s1)
    m2 = math.floor(s2)

    m3 = math.ceil(s3)
    m4 = math.floor(s4)

    arr1 = [i for i in range(m1,m2+1)]
    arr2 = [i for i in range(m3,m4+1)]

    result = list(set(arr1).intersection(set(arr2)))


    if len(result) == 0:
        return -1
    else:
        return min(result)



result = calculate(A,B)
print(result)





Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x[5];
    cin>>x[0]>>x[1]>>x[2]>>x[3]>>x[4];
    for(int i=0;i<5;i++)
    {
        if(x[i]==0)
        {
            cout<<i+1;
            break;
        }
    }

   }


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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define PI 3.1415926535

int main(void)
{

    double r;
    cin >> r;

    double ans = r * 2.0 * PI;
    printf("%lf\n", ans);

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  int sum_length = 0;
  for (int i = 0; i < N; ++i) {
    cin >> L.at(i);
    sum_length += L.at(i);
  }

  int max_length = *max_element(L.begin(), L.end());
  sum_length -= max_length;

  cout << (max_length < sum_length ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool a[4];
int x;
int main()
{
	for(int i=1;i<=2;i++)
	{
		scanf("%d",&x);
		if(x==1)
			a[1]=true;
		if(x==2)
			a[2]=true;
		if(x==3)
			a[3]=true;
	}
	for(int i=1;i<=3;i++)
	{
		if(a[i]==false)
			printf("%d",i);
	}
	return 0;
}

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

using namespace std;

int a, b, c, size, d[3][1000], n, r;
int co[301], s[1000];

main(){
  while(cin >> a >> b >> c && (a|b|c)){
    cin >> n;
    fill(co, co+301, 2);
    size = a + b + c;
    for(int i=0;i<n;i++){
      cin >> a >> b >> c >> r;
      if(r){
        co[a] = co[b] = co[c] = 1;
        s[i] = true;
      }else{
        d[0][i] = a;
        d[1][i] = b;
        d[2][i] = c;
        s[i] = false;
      }
    }
    for(int i=0;i<n;i++){
      if(!s[i]){
        if(co[d[1][i]] == 1 && co[d[2][i]] == 1) co[d[0][i]] = 0;
        if(co[d[0][i]] == 1 && co[d[2][i]] == 1) co[d[1][i]] = 0;
        if(co[d[0][i]] == 1 && co[d[1][i]] == 1) co[d[2][i]] = 0;
      }
    }
    for(int i=1;i<=size;i++) cout << co[i] << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    int A,P;
    cin >> A>>P;
    
    P=P+(A*3);
    
    int ans=P/2;
    
    
    cout << ans << endl;
}


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

int main(){
  string S;
  cin >> S;
  string T=S;
  reverse(T.begin(),T.end());
  if(S!=T){
    cout << "No" << endl;
    return 0;
  }
  T=S.substr(0,(S.size()-1)/2);
  reverse(T.begin(),T.end());
  if(S.substr(0,(S.size()-1)/2)!=T){
    cout << "No" << endl;
    return 0;
  }
  S.erase(S.begin(),S.begin()+(S.size()+3)/2-1);
  T=S;
  reverse(T.begin(),T.end());
  if(S!=T){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "")
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

int main() {
    init_io();
    ll A, B;
    cin >> A >> B;
    ll ans = 0;
    ll half = (B - A + 1) / 2;
    if((B - A + 1) % 2 == 1) {
        if(A % 2 == 1 && (half + 1) % 2 == 1) ans = 1;
        if(A % 2 == 0 && half % 2 == 1) ans = 1;
    } else {
        if(half & 1) ans = 1;
    }
    for(ll i = 1; i < 60 && (1ll << i) <= B; i++) {
        ll cnt = 0;
        if(A & (1ll << i)) {
            ll tmp = A & ((1ll << i) - 1);
            cnt += (1ll << i) - tmp;
        }
        if(B & (1ll << i)) {
            ll tmp = B & ((1ll << i) - 1);
            cnt += tmp + 1;
        }
        ans += (cnt & 1 ? (1ll << i) : 0);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int h, w;
bool contain(int y, int x){
   return (0 <= y && y < h && 0 <= x && x < w);
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];
    rep(i, 0, h){
        rep(j, 0, w){
            if(s[i][j] == '#') continue;
            int cnt = 0;
            for(int k = i - 1; k <= i + 1; k++){
                for(int l = j - 1; l <= j + 1; l++){
                    if(!contain(k, l)) continue;
                    if(k == i && l == j) continue;
                    if(s[k][l] == '#') cnt++;
                }
            }
            s[i][j] = '0' + cnt;
        }
    } 
    rep(i, 0, h){
        cout << s[i] << endl;
    }
}

Measured memory_bytes: 256
from itertools import permutations


def solve(string):
    a = map(int, string.split())
    ans = min(sum([abs(_p0 - _p1) for _p0, _p1 in zip(p, p[1:])]) for p in permutations(a, 3))
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 3064
def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    H.append(0)
    H.insert(0, 0)
    N += 2

    inf = 10**12
    dp = [[inf] * (K+1) for _ in range(N)]
    dp[0][0] = 0
    for i in range(N):
        for k in range(K+1):
            for j in range(K-k+1):
                if i + j + 1 < N:
                    dp[i+j+1][k+j] = min(dp[i+j+1][k+j], dp[i][k] + max(0, H[i+j+1] - H[i]))
    print(min(dp[-1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 41840
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    string s;
    cin>>n>>s>>k;
    char c=s[k-1];
    REP(i,n){
        if(s[i]!=c) s[i]='*';
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
  public static void main(String[]$) {
    Scanner c=new Scanner(System.in);
    int n=c.nextInt();
    long s=0,a=0;
    Map<Long,Long> m=new HashMap<>();
    m.put(s,1l);
    while(n-->0){
      s+=c.nextLong();
      long k=m.containsKey(s)?m.get(s):0;
      m.put(s, k+1);
      a+=k;
    }
    System.out.print(a);
  }
}

Measured memory_bytes: 102472
n = int(input())
ans = ['' for _ in range(n)]

def dfs(i, mx):
    if i == n:
        print(''.join(ans))
        return
    for j in range(mx+1):
        ans[i] = chr(ord('a') + j)
        dfs(i+1, max(j+1, mx))

dfs(0, 0)

Measured memory_bytes: 4340
#include<stdio.h>
int ara[100001];
int main()
{
    int n,k,m,a,i;
    scanf("%d%d%d",&n,&k,&m);
    for(i=0;i<m;i++)
    {
        scanf("%d",&a);
        ara[a]++;
    }
    for(i=1;i<=n;i++)
    {
        if((k-(m-ara[i]))>0)
            printf("Yes\n");
        else
            printf("No\n");
    }
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
#define REPP(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)
#define PER(i,a) for(int i = (a) - 1; i >= 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair

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

const int maxn = 2e5 + 5;
int a[maxn], h[maxn];

int main() {
    int n;
    scanf("%d", &n);
    REP(i, n) scanf("%d", h + i);
    REP(i, n) scanf("%d", a + i);
    int base = 1, x;
    while (base <= n) {
		base *= 2;
	}
	vector<ll> tree(base * 2);
    REP(i, n) {
		x = h[i] + base;
		ll best = 0;
		while (x >= 1) {
			if (x & 1) {
				best = max(best, tree[x - 1]);
			}
			x /= 2;
		}
        best += a[i];
        x = h[i] + base;
        while (x >= 1) {
			tree[x] = max(tree[x], best);
			x /= 2;
		}
    }
    ll ans = *max_element(tree.begin() + base + 1, tree.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5888
import Control.Monad
import Control.Applicative
import Data.List

main = do
  xs <- map toInt . words <$> getContents
  mapM_ print $ solve xs

solve :: [Int] -> [Int]
solve = map area

toInt :: String -> Int
toInt s = read s

area :: Int -> Int
area d = d * (sum $ map (\x -> x * x) ls)
  where ls = [d, d+d .. 600 - d]

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    int N,Y;
    cin >> N >> Y;
    Y/=1000;
    int k;
    REP(j,N+1){
        REP(i,N+1){
            k=N-i-j;
            if(i*10+j*5+k==Y && k>=0 ){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <limits.h>
#include <iomanip>
#include <cassert>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i, v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL << 60;
const int INF = 1e9;
const long long MOD = 1000000007;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
typedef long long ll;
#define pint pair<int, int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll h;
    cin >> h;
    ll cnt = 0;
    while (h != 0)
    {
        cnt++;
        h /= 2;
    }

    ll ans = 1;
    ll num = 1;
    rep(i, cnt - 1)
    {
        num *= 2;
        ans += num;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M = map(int, input().split())
    A = [0] * M
    B = [0] * M

    for i in range(M):
        A[i], B[i] = map(int, input().split())

    iland = [0] * M
    uf = UnionFind(N)
    for i in range(M-1, -1, -1):
        a = A[i] - 1
        b = B[i] - 1

        if uf.same(a, b):
            iland[i] = 0
        else:
            iland[i] = uf.size(a) * uf.size(b)

        uf.union(a, b)

    ans = [0] * M
    ans[0] = iland[0]
    for i in range(1, M):
        ans[i] = ans[i-1] + iland[i]

    for i in range(M):
        print(ans[i])


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
typedef long double ld;

ll dp[405][405];
ll pre[405];
ll niz[405];

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
        pre[i] = pre[i-1] + niz[i];
    }
    for(int len=2; len<=n; len++){
        for(int l=1; l+len-1<=n; l++){
            int r = l+len-1;
            dp[l][r] = dp[l+1][r];
            for(int k=l; k<r; k++){
                dp[l][r] = min(dp[l][r], dp[l][k] + dp[k+1][r]);
            }
            dp[l][r] += pre[r]-pre[l-1];
        }
    }
    cout << dp[1][n];
    return 0;
}


Measured memory_bytes: 1536
from string import ascii_lowercase as alph

def gen_pattern(N, pre=""):
  for i in range(ord(max(pre or "\x60"))-0x5f):
    pattern = pre+alph[i]
    if len(pattern) == N:
      print(pattern)
    else:
      gen_pattern(N, pattern)

gen_pattern(int(input()))


Measured memory_bytes: 5016
#include<iostream>
#include<string>
using namespace std;
int main(void){
     int N,K;
     string S;
     cin>>N>>K>>S;
     if(S[K-1]=='A'){
         S[K-1]='a';
     }else if(S[K-1]=='B'){
         S[K-1]='b';
     }else if(S[K-1]=='C'){
         S[K-1]='c';
     }
     cout<<S<<endl;



    
    
   


return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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

  

  cin >> n >> m;
  if (m == 0) {
    rep(i, (1LL << n)) cout << i << " " << i << " ";
    cout << endl;
    return 0;
  }

  rep(i, 1LL << n) {
    if (i != m) tmp ^= i;
  }
  if (tmp != m || (1LL << n) < m) {
    cout << "-1" << endl;
    return 0;
  }
  rep(i, (1LL << n)) {
    if (i != m) cout << i << " ";
  }
  cout << m << " ";
  rrep(i, (1LL << n)) {
    if (i != m) cout << i << " ";
  }
  cout << m << endl;


  return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt(); //1行目の入力
		for(int i = 1; x != 0; i++){
			System.out.println("Case "+i+": "+x);
			x = sc.nextInt();
		}
	}
}


Measured memory_bytes: 41676
def lP(l: list) -> None:
    for i in range(len(l)-1):
        print(l[i], end = ' ')
    print(l[len(l)-1])

N = int(input())
l = list(map(int, input().split()))
sum = 0

for i in range(N):
    minI = i
    for j in range(i+1, N):
        if l[minI] > l[j]:
            minI = j
    if i != minI:
        l[i], l[minI] = l[minI], l[i]
        sum += 1
lP(l)
print(sum)


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

struct P{
	int id;
	int x;
	int y;
}p[100001];
struct edge{
	int from;
	int to;
	long long w;
};
vector<edge> v;
int s[100001];
int n;

bool cmp(edge a,edge b){
	return a.w < b.w;
}
bool cmpx(P p1,P p2){
	return p1.x < p2.x;
}
bool cmpy(P p1,P p2){
	return p1.y < p2.y;
}
int findr(int x){
	if(x!=s[x]){
		s[x] = findr(s[x]);
	}
	return s[x];
}

long long Kruskal(){
	long long ans = 0;
	int nume = 0;
	for(int i = 1;i<=n;i++) s[i] = i;
	sort(v.begin(),v.end(),cmp);
	int m = v.size();
	for(int i = 0;i < m;i++){
		int fx = findr(v[i].from);
		int fy = findr(v[i].to);
		if(fx!=fy){
			s[fx] = fy;
			ans+=v[i].w;
			nume++;
			if(nume==n-1) break;
		}
	}
	return ans;
}

int main(){
	long long x,y;
	
	cin >> n;
	for(int i = 1;i<=n;i++){
		cin >> p[i].x >> p[i].y;
		p[i].id = i;
	}
	edge e;
	sort(p+1,p+n+1,cmpx);
	for(int i = 2;i<=n;i++){
		e.from = p[i].id;
		e.to = p[i-1].id;
		e.w = min(abs(p[i].x-p[i-1].x),abs(p[i].y-p[i-1].y));
		v.push_back(e);
	}
	sort(p+1,p+n+1,cmpy);
	for(int i = 2;i<=n;i++){
		e.from = p[i].id;
		e.to = p[i-1].id;
		e.w = min(abs(p[i].x-p[i-1].x),abs(p[i].y-p[i-1].y));
		v.push_back(e);
	}
	long long ans = Kruskal();
	cout << ans;
}

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

using namespace std;

#define LL long long

const LL MOD = 1000000007;

int main() {
  LL N, K;
  cin >> N >> K;
  vector<int> div;
  for (int k=1; k*k<=N; k++) {
    div.push_back(k);
    int m = N / k;
    if (m != k) div.push_back(m);
  }
  sort(div.begin(), div.end());
  vector<LL> initial;
  int prev = 0;
  for (auto v : div) {
    initial.push_back(v-prev);
    prev = v;
  }
  vector<LL> curr = initial;
  vector<LL> next(curr.size(), 0);
  for (int k=0; k<K-1; k++) {
    LL t = 0;
    for (int i=0; i<(int)curr.size(); i++) {
      int j = (int)(curr.size()-i-1);
      t += curr[i] ;
      t %= MOD;
      next[j] = (initial[j] * t) % MOD;
    }
    swap(curr, next);
  }
  int res = 0;
  for (auto v : curr) {
    res = (res + v) % MOD;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++ i) {
        int x;
        cin >> x;
        a[x - 1] = i + 1;
    }
    for (int i = 0; i < n; ++ i) {
        cout << a[i] << " ";
    }
    
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vs vector<string>
#define vll vector<ll>
#define ii pair<int, int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back
#define FOR(i, x, n) for(int i=x; i<=n; ++i)
#define ROF(i, x, n) for(int i=x; i>=n; --i)
#define MOD 1000000007
#define F first
#define S second

int main() {

    ll a, b, c, d;
    sc("%lld %lld %lld %lld", &a, &b, &c, &d);

    ll ans = max(a*c, max(a*d, max(b*c, b*d)));

    printf("%lld\n", ans);
}



Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
  int result = 0;
  cin >> N;
  vector<int> L(N,0);
  for(int a = 0;a < N;a++)cin >> L[a];
  sort(L.begin(),L.end());
  for(int a = 0;a < N;a++){
    for(int b = a+1;b < N;b++){
      for(int c = b+1;c < N;c++){
        if(L[a] + L[b] > L[c]&&L[a] != L[b]&&L[b] != L[c]){
          result++;
         
        }
      }
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int main(){
    string s;cin>>s;
    if(s[2]==s[3] && s[4]==s[5])cout<<"Yes";
    else cout<<"No";
}



Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
   	int n=read();long long sum=0;
   	for(int i=1;i<=n;i++)if(i%3!=0 && i%5!=0)sum+=i;
   	printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 1604
# coding: utf-8
import sys
input = sys.stdin.readline

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

left = 0
right = 0
for gate in lst_gate:
    if gate < start:
        left += 1
    else:
        right += 1
print(min(left, right))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
const float PI = 3.14;


int main()
{
	
	int n;
	cin >> n;
	vector<int> a, num(n);

	for (int i = 0; i < n - 1; i++) {
		int in; cin >> in; a.push_back(in);
		num[in-1]++;
	}

	for (int i = 0; i < num.size(); i++) {
		cout << num[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 5024
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main() {
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 5268
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll MOD = (ll)1e9 + 7;
const double EPS = 1e-9;

ll fib[100100];

// Fibonacci数列を埋める
void precalc() {
    fib[0] = 1;
    fib[1] = 1;
    for(int i = 2; i < 100100; ++i) {
        fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;
    }
    return;
}




int main () {
    
    precalc();

    ll n,m; cin >>n>>m;
    vector<ll> a(m+2, -1); 
    for (int i = 1; i <= m; i++) {
        cin >> a[i];  
    }
    a[m+1] = n+1;

    vector<ll> da(m+1);

    for (int i = 0; i < m+1; i++) {
        if (i >= 1 && i+1 <= m && a[i] == a[i+1] - 1) {
            cout << 0 << endl;
            return 0;
        } 
        da[i] = a[i+1] - a[i] - 2;
    }

    ll res = 1;
    for (int i = 0; i < m+1; i++) {
        if (da[i] > 0) {
            res *= fib[da[i]];
            res %= MOD;
        } 
    }

    cout << res << endl;
    return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  string g;
  int y,m,d;
  while(cin>>g,g!="#"){
    cin>>y>>m>>d;
    if(y>31||(y==31&&m>=5)){
      cout<<'?'<<" "<<y-30<<" "<<m<<" "<<d<<endl;
    }else{
      cout<<g<<" "<<y<<" "<<m<<" "<<d<<endl;
    }
  }
}



Measured memory_bytes: 3184
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var a = Input().ToInt();
		
		int cnt = 0;
		for(int i = 0; i < n; i++)
		{
			if(i+1 == a[i] && i+1 < n)
			{
				var k = a[i+1];
				a[i+1] = a[i];
				a[i] = k;
				cnt++;
			}
			else if(i+1 == a[i])
			{
				cnt++;
				break;
			}
		}
		Console.WriteLine(cnt);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 18912
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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



dd dis(dd ax,dd ay,dd bx,dd by){
    return sqrt(powl(bx-ax,2.0)+powl(by-ay,2.0));
}
int main(){fastio
    dd pi=2*acos(0.0);
    //cout<<pi<<endl;
    dd a,b,h,m;cin>>a>>b>>h>>m;
    h=h+m/60;
    dd rs=h/12;
    dd rt=m/60;
    //cout<<rs<<endl;
    //cout<<rt<<endl;
    
    dd sx=a*cos(2*pi*rs);
    dd sy=a*sin(2*pi*rs);
    dd tx=b*cos(2*pi*rt);
    dd ty=b*sin(2*pi*rt);
    
    //cout<<sx<<" "<<sy<<" "<<tx<<" "<<ty<<endl;
    
    cout<<setprecision(20)<<dis(sx,sy,tx,ty)<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 4192
#include<stdio.h>
 
#define MAXLEN 20000
 
int garea,gareas[(MAXLEN/2)+1],gcnt,gend;
 
 
int getArea( char *inputs, int start, int end )
{
    int i;
    int ravine,water;
    
    gareas[gcnt]=ravine=water=0;
    for( i=start; i!=end; i++ ) {
        if( '\\'== *(inputs+i) ) {
           	water+=(ravine*2);
            ravine++;
            water++;
        } else if( 0 != ravine && '/' == *(inputs+i) ) {
        	ravine--;
        } else {
	     	water+=ravine;
        }       
    }
	gareas[gcnt]+=water;
    
    return gareas[gcnt];
}
  
int checkRavine( char *inputs, int start )
{
    int i;
    int ravine, minh, tmpi;
    
    ravine=0;
    tmpi=minh=MAXLEN;
    for( i=start; i<=gend && '\0'!=*(inputs+i); i++ ) {
        if( '\\'== *(inputs+i) ) {
            ravine++;
        } else if( 0 != ravine && '/' == *(inputs+i) ) {
            ravine--;
            if( ravine < minh ) {
        		minh=ravine;
        		tmpi=i;
            }
            if( 0 == ravine ) {
            	garea+=getArea( inputs, start, i+1 );
            	gcnt++;
			    gend=MAXLEN;           	
                return i-start;
            }
        }
    }
	gend=tmpi;
    return 0;
}
 
 
void getAreas( char *inputs )
{
    int i,next;
     
    next=0;
    for( i=0; '\0'!=inputs[i]; i++ ) {
        next=checkRavine( inputs, i );
        i+=next;
    }
 
    return;
}
 
int main( void ) 
{
    char inputs[MAXLEN+1];
    int i;
 
    scanf( "%s", inputs );
    garea=gcnt=0;
    gend=MAXLEN;
    getAreas( inputs );
     
    printf( "%d\n", garea );
    
    if( gcnt ) {
        printf( "%d ", gcnt );
        for( i=0; i<gcnt; i++ ) {
            printf( "%d", gareas[i] );
            if( i < gcnt-1 ) {
            	printf( " " );  
            }
        }
        printf( "\n" );
       
    } else {
        printf( "0\n" );
    }
     
    return 0;
}

Measured memory_bytes: 576
#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>

using namespace std;

char ch[200200];
int N;

int solve(){
	stack<int> st;
	for(int i = 0; i < N; ++i){
		if(st.empty()) st.push(i);
		else if(ch[st.top()] == 'S' && ch[i] == 'T') st.pop();
		else st.push(i);
	}
	return st.size();
}

void input(){
	scanf("%s", ch);
	N = strlen(ch);
}

int main(){
	input();
	int ans = solve();
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1280
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())

int main(void){
  int e;
  while(cin>>e,e){
    int ans = e;
    for(int z = 0; z*z*z<=e; z++){
      for(int y = 0; y*y+z*z*z<=e; y++){
        int x = e - y*y - z*z*z;
        ans = min(ans,x+y+z);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 868
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 2000
#define INF (1<<26)
typedef pair<int,int > P;
struct edge{int to,cap,cost,rev;};

int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back((edge){to,cap,cost,G[to].size()});
  G[to].push_back((edge){from,0,-cost,G[from].size()-1});
}

int min_cost_flow(int s,int t,int f){
  int res=0;
  fill(h,h+V,0);
  while(f>0){
    priority_queue< P , vector<P> , greater<P> > que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
      P p=que.top();que.pop();
      int v=p.second;
      if(dist[v]<p.first)continue;
      for(int i=0;i<(int)G[v].size();i++){
	edge &e=G[v][i];
	if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
	  dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
	  prevv[e.to]=v;
	  preve[e.to]=i;
	  que.push(P(dist[e.to],e.to));
	}
      }
    }
  
    if(dist[t]==INF){
      return -1;
    }
    for(int v=0;v<V;v++)h[v]+=dist[v];
    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d, G[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap-=d;
      G[v][e.rev].cap+=d;
    }
  }
  return res;
}

int n;
int t[200][200],u[200][200];
char a[200][200],b[200][200];

int main(){
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>t[i][j];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>u[i][j];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>a[i][j];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      b[i][j]='.';

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int sum=0;
      if(a[i][j]=='.'){
	sum+=t[i][j]*2;
	for(int k=0;k<n;k++){
	  if(a[i][k]=='o')sum+=u[i][k];
	  if(a[k][j]=='o')sum+=u[k][j];
	}
      }else{
	for(int k=0;k<n;k++){
	  if(k!=j&&a[i][k]=='o')sum+=u[i][k];
	  if(k!=i&&a[k][j]=='o')sum+=u[k][j];
	}	
      }
      add_edge(i,n+j,1,sum);
    }
  }
  for(int i=0;i<n;i++){
    add_edge(n+n,i,1,0);
    add_edge(n+i,n+n+1,1,0);
  }
  V=n+n+2;
  cout<<min_cost_flow(n+n,n+n+1,n)/2<<endl;


  
  for(int i=0;i<n;i++){
    for(int j=0;j<(int)G[i].size();j++){
      edge e=G[i][j];
      
      if(e.cap==0&&n<=e.to&&e.to<n+n){
	b[i][e.to-n]='o';
      }
    }
  }


  vector<P> ans;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(a[i][j]==b[i][j])continue;
      ans.push_back(P(i,j));
    }
  }
  
  cout<<ans.size()<<endl;
  for(int i=0;i<(int)ans.size();i++){
    P p=ans[i];
    if(a[p.first][p.second]=='.'){
      cout<<p.first+1<<" "<<p.second+1<<" write"<<endl;
    }else{
      cout<<p.first+1<<" "<<p.second+1<<" erase"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1980
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];

        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            a[i] = x;
            b[i] = x;
        }
        
        Arrays.sort(a);

        for (int i = 0; i < n; i++) {
            if (b[i] == a[n - 1]) {
                System.out.println(a[n - 2]);
            } else {
                System.out.println(a[n - 1]);
            }
        }

        sc.close();
    }    
}


Measured memory_bytes: 93764
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;

void solve(long long N, std::vector<long long> &a) {
	sort(a.begin(), a.end());
	bool ans = false;
	if (a.back() == a.front()) {
		ans = a.front() == N - 1 || a.front() * 2 <= N;
	} else if (a.front() + 1 == a.back()) {
		int b = count(a.begin(), a.end(), a.front());
		int c = count(a.begin(), a.end(), a.back());
		ans = b < a.back() && 2 * (a.back() - b) <= c;
	}
	cout << (ans ? "Yes" : "No") << endl;
}

int main() {
    long long N;
	scanf("%lld", &N);
	std::vector<long long> a(N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &a[i]); // a[i]--;
	}
	solve(N, a);
	return 0;
}


Measured memory_bytes: 4092
import fractions
#解説見ました。
def lcm(x,y):
    return (x * y) // fractions.gcd(x,y)
def wei(n,x,y):
    return n-(n//x + n//y - n//lcm(x,y))

A,B,C,D = [int(i) for i in input().split(" ")]
print(wei(B,C,D) - wei(A-1,C,D))
  

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

#define fi first
#define se second

const int N = 100100;
const long long mod = 1e9 + 9;

using namespace std;

int n;
int a[N];
int d[N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
                if(i - 1 > 0){
                        d[i] = d[i - 1] + abs(a[i] - a[i - 1]);
                }
                if(i - 2 > 0){
                        d[i] = min(d[i], d[i - 2] + abs(a[i] - a[i - 2]));
                }
        }
        cout << d[n] << "\n";
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define per(i,a,b) for(ll i=(b)-1;i>=(a);i--)
const ll maxn=2e5+5;
ll n,a,ans=0;
map<ll, ll> bst;
int main() {
    ios_base::sync_with_stdio(0);
    cin>>n;
    rep(i,1,n+1) {
        cin>>a;
        ans+=bst[i-a];
        bst[i+a]++;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 26276
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{
    int n;
    string s,t;
    cin >> n >> s >> t;
    string str = "";
    for (int i=0; i<n; ++i)
    {
        str += s[i];
        str += t[i];
    }

    cout << str << endl;

    return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
-- end of templete

f 0 = 0
f n = mod n 10 + f (div n 10)

main = do
    n <- getInt
    putStrLn $ cond "Yes" "No" $ (==0) $ mod n $ f n

Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()

using ll = long long;

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

	vector<int> a(N);
	vector<int> ball(N, 0);
	rep(i, N)
	{
		cin >> a[i];
	}
	
	ll ans = 0;
	for (int i = N - 1; i >= 0; i--)
	{
		int count = 0;

		for (int j = i * 2 + 1; j < N; j += (i + 1))
		{
			count += ball[j];
		}

		if (a[i] == 1)
		{
			if (count % 2 == 0)
			{
				ball[i] = 1;
				ans++;
			}
		}
		else
		{
			if (count % 2 == 1)
			{
				ball[i] = 1;
				ans++;
			}
		}
	}

	cout << ans << endl;
	vector<int> nums;
	rep(i, N)
	{
		if (ball[i] == 1)
		{
			nums.push_back(i + 1);
		}
	}
	
	rep(i, nums.size())
	{
		if (i > 0)
		{
			cout << " ";
		}

		cout << nums[i];
	}
	cout << endl;



	return 0;
}

Measured memory_bytes: 3064
import sys
A = input()
B = input()
if len(A) > len(B):
    print('GREATER')
    sys.exit()
elif len(A) < len(B):
    print('LESS')
    sys.exit()
elif A == B:
    print('EQUAL')
    sys.exit()

for i in range(len(A)):
    if A[i] == B[i]:
        i += 1
        continue
    elif A[i] > B[i]:
        print('GREATER')
        sys.exit()
    elif A[i] < B[i]:
        print('LESS')
        sys.exit()
print('EQUAL')

Measured memory_bytes: 61996