akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;	cin >> n;
  map<string,int> mp;
  long long ans = 0;
  for(int i = 0; i < n; i++){
  	string s;	cin >> s;
    sort(s.begin(),s.end());
    ans += mp[s];
    mp[s]++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 11136
import sys
def is_prime(x):
 if x<=1:return False
 i=2
 while i*i<=x:
  if x%i==0:return False
  i+=1
 return True
for e in sys.stdin:
 N=int(e)
 mx=mn=0
 for i in range(N-1,1,-1):
  if is_prime(i):mx=i;break
 for i in range(N+1,N*2):
  if is_prime(i):mn=i;break
 print(mx,mn)


Measured memory_bytes: 5592
// AOJ 0023
#include<iostream>
#include<cmath>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

const long double EPS = 1e-17;

long double sq(long double x) {
  return x * x;
}

long double abs(long double x) {
  return (x > 0 ? x : -x);
}
/*
bool eq(long double x, long double y) {
  return abs(x - y) < EPS;
}*/

long double dist(long double xa, long double ya, long double xb, long double yb) {
  return sq(xa - xb) + sq(ya - yb);
}

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    long double xa, ya, ra, xb, yb, rb;
    cin >> xa >> ya >> ra >> xb >> yb >> rb;

    long double d = sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb));
    
    if (ra - rb > d + EPS) {
      cout << 2 << endl;
    } else if (rb - ra > d + EPS) {
      cout << -2 << endl;
    } else if (d > ra + rb + EPS) {
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  }
}

Measured memory_bytes: 1232
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
# xy = sorted(xy, key=lambda x: x[0])
counter = Counter()
for i in range(N):
    for j in range(i+1, N):
        nxy = xy[i]
        pxy = xy[j]
        counter[(nxy[0]-pxy[0], nxy[1]-pxy[1])] += 1
        counter[(pxy[0]-nxy[0], pxy[1]-nxy[1])] += 1
# print(counter)
if N == 1:
    print(1)
else:
    print(N-counter.most_common(1)[0][1])


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cout<<(x)<<endl;

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    li a,b;

    cin>>a>>b;

    cout<<a*b;
}

int main()
{    
   

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

    li t=1;

    // cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
#define MAX 100000

int main(){
	int n,i;
	int ans=0;
	int a[MAX];
	int f[MAX]={0};
	
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	
	for(i = 1;i <= n;i++){
		if(f[i])continue;
		if(a[a[i]]==i){
			ans++;
			f[a[i]]++;
		}
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 896
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

/* MACROS SAMPAH */
#define Jehian using
#define Norman namespace
#define Saviero std
#define cepet {ios_base::sync_with_stdio(0);cin.tie(0);}

Jehian Norman Saviero;

/* MACROS FOR TYPE */
typedef long l;
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

/* MACROS FOR PRINT */
#define nl printf("\n")
#define sp printf(" ")

/* MACROS FOR FUNCTION AND METHOD */
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define eb emplace_back
#define RESET(x) memset((x), 0, sizeof(x))
#define SET(x,y) for(int _je = sizeof(x)/sizeof(x[0]); _je--;) x[_je] = y
#define SQR(x) (x)*(x)
#define CUBE(x) SQR(x)*(x)
#define ALL(x) (x).begin(), (x).end()
#define ALLSIZE(x,n) (x), (x)+(n)

/* MACROS FOR ATTRIBUTE */
#define fi first
#define se second

/* MACROS FOR SCAN */
#define scc(x) scanf("%c", &x)
#define scd(x) scanf("%Lf", &x)
#define scf(x) scanf("%f", &x)
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scld(x) scanf("%Lf", &x)
#define scui(x) sci(x)
#define scul(x) scl(x)
#define scull(x) scll(x)

string A;
int main(){
	cin >> A;
	bool hehe = true;
	for (auto& it : A){
		hehe = hehe && it == '9';
	}
	if (hehe){
		cout << 9 * A.size() << endl;
	} else {
		ll sum = 0;
		for (ll i = 0; i < A.size(); ++i){
			sum += A[i]-'0';
		}
		ll idx = -1;
		ll res[2];
		RESET(res);
		for (ll i = 0; i < A.size(); ++i){
			if (A[i] != '9'){
				idx = i;
				break;
			} else {
				res[0] += 9;
				res[1] += 9;
			}
		}
		if (idx > 0){
			--res[0];
			res[0] += 9*(A.size()-idx);
		}
		res[1] = A[idx]-1-'0';
		res[1] += 9*(A.size()-idx-1);
		cerr << res[0] << " " << res[1] << endl;
		cout << max(max(res[0],res[1]),sum) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <cstdlib>

using namespace std;
typedef long long ll;

bool calc(string s, int i, string ans, int sum, string &ans2){
  string plus;
  plus += '+';
  plus += s[i+1];
  string minus;
  minus += '-';
  minus += s[i+1];
  /*cout << plus + " " + minus + " " << i <<  " " + ans + " " << sum <<endl;*/

  if(i == 3){
    if(sum == 7){
      ans2 = ans;
      return true;
    }
    else{
      return false;
    }
  }

  //+
  if(calc(s, i+1, ans += plus , sum + (int)(s[i+1] - '0'), ans2)){
    return true;
  }
  ans.pop_back();
  ans.pop_back();
  //-
  if(calc(s, i+1, ans += minus, sum - (int)(s[i+1] - '0'), ans2)){
    return true;
  }
  return false;
}

string conv(string s, int i, string &ans, int sum){
  string ans2;
  if(calc(s, i, ans, sum, ans2)){
    return ans2 += "=7";
  }
}



int main(){
  string S;
  cin >> S;
  string ans;
  ans += S[0];
  char aaa = S[0];
  int sum;
  sum = (int)(aaa - '0');
  cout << conv(S, 0, ans, sum) <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int h,w;
    int nn[10][10];
    int d[10][10];
    int cnt[10]={};
    cin >> h>> w;
    rep(i,10)rep(j,10)cin >> nn[i][j];
    rep(i,h)rep(j,w){
        int tmp;
        cin >> tmp;
        if(tmp>=0){
            cnt[tmp]++;
        }
    }
    rep(i,10)rep(j,10){
        d[i][j]=nn[i][j];
    }
    rep(k,10)rep(i,10)rep(j,10){
        d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
    }
    int res=0;
    DEBUG{
        cout << d[2][1] << " " << d[1][2] << endl;
    }
    rep(i,10)res+=cnt[i]*d[i][1];
    cout << res << endl;



    return 0;
}


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

namespace AtCoder.Abc
{
    class A_167_Registration
    {
        // https://atcoder.jp/contests/abc167/tasks/abc167_a
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力 S
            string S = Console.ReadLine();
            // 文字列の入力 T
            string T = Console.ReadLine();

            S += T[T.Length - 1];

            if (S == T)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25840
S = input()

list = list(S)
#print(list)

ref = []
ref.append(list[0])
count = 0
for i in range(len(list)-1):
    if int(ref[i]) == int(list[i+1]):#つぎの　値が同値ならカウント
        count += 1
        if int(list[i+1]) == 1:
            ref.append(0) # refの次の参照値を反転して作成
        else:
            ref.append(1) # refの次の参照値を反転して作成
    else:
        ref.append(list[i+1]) # refの次の参照値を作成

print(count)


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using namespace std;

int main()
{
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    if (x == 0 && y == 0 || x == 0 && y == h || x == w && y == h || x == w && y == 0) {
        long double ans = w * h / 2.0;
        cout << ans << " ";
        cout << 0 << endl;
        return 0;
    }
    if (x == 0 || y == 0 || x == w || y == h) {
        long double ans = w * h / 2.0;
        cout << ans << " ";
        cout << 0 << endl;
        return 0;
    }
    ll b = min(x * h, (w-x) * h);
    ll d = min(y * w, (h-y) * w);
    long double res = w * h / 2.0;
    cout << res << " ";
    if (b == d) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
    ll n,i;
    cin>>n;
    ll arr[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    ll a[n+1];
    for(i=1;i<=n;i++)
    {
        a[arr[i]]=i;
    }

    for(i=1;i<=n;i++)
    {
        cout<<a[i]<<" ";
    }
}


Measured memory_bytes: 2432
// header {{{
// header {{{
#include <bits/stdc++.h>
using namespace std;
 
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
 
#define ASSERT(expr...) assert((expr))
 
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
 
using f32 = float;
using f64 = double;
// }}}
 
constexpr i64 INF = 1'010'000'000'000'000'017LL;
 
constexpr i64 MOD = 1'000'000'007LL;
 
constexpr f64 EPS = 1e-12;
 
constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

 
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define ll long long int
#define VI vector <int>
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
 
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
 
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
 
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}
 
// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
 
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}
 
//--------------------------------------------------------------------
 
bool isOK(int mid, double key){
 
    if((double)mid*mid > key) {
             return true;
     } else {
              return false;
     }
}

 int binary_search(double key) {
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2000000000;
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}





void solve() {
int N,M;
cin >> N >> M;
cout << N*(N-1)/2 + M*(M-1)/2;
}
 
signed main() {
 
    solve();
 
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long sum = Long.MAX_VALUE;
		
		for (long i = 1; i <= a; i++) {
			if(a%i == 0) {
				if (i > a/i) break;
				//System.out.println(i +" "+  a/i);
				if(sum > i + a/i) sum = i + a/i - 2;
				if(isPrime(a/i))break;
			}
		}
		 
		System.out.println(sum);
	
	}
	
	public static boolean isPrime(long n) {
		if (n < 2) {
	        return false;
	    }
	    if (n % 2 == 0) {
	        return (n == 2);
	    }

	    for (long i = 3; i * i <= n; i += 2) {    //奇数のみ [O(√n[/2])で可]
	        if (n % i == 0) {
	            return false;
	        }
	    }
	    return true;
	}

}

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

int main() {
  int a,b;
  cin >> a >> b;
  int ans = a+b;
  if(ans < 24) cout << ans << endl;
  else cout << ans-24 << endl;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;


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

    int m, nmin, nmax;
    while (cin >> m >> nmin >> nmax, m) {
        V a(m);
        rep(i, m) cin >> a[i];

        int ans = -1;
        int ma_gap = -1;
        rep(i, m) {
            if (nmin <= i + 1 && i + 1 <= nmax) {
                int now_gap = a[i] - a[i + 1];
                if (now_gap >= ma_gap) {
                    ans = i + 1;
                    ma_gap = now_gap;
                }
            }
        }

        cout << ans << endl;
    }
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 100'000
i64 N;
bool is_prime[MAX_N * 10];

void solve() {
    fill(is_prime, is_prime + MAX_N * 10, true);
    for (i64 i = 2; i < MAX_N * 10; i++) {
        if (!is_prime[i]) continue;
        for (i64 j = 2 * i; j < MAX_N * 10; j += i) is_prime[j] = false;
    }

    for (i64 n = N; n < MAX_N * 10; n++) {
        if (is_prime[n]) {
            cout << n << endl;
            return;
        }
    }
}

int main() {
    cin >> N;

    solve();

    return 0;
}

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

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

int main()
{
	int w, h;
	while( cin >> w >> h && ( w || h ) ){
		int* map = new int[ ( w + 2 ) * ( h + 2 ) ]();
		int xs, ys, xg, yg;
		cin >> xs >> ys;
		cin >> xg >> yg;
		int n;
		cin >> n;
		for( int i = 0; i < n; ++i ){
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			for( int j = 0; j < 2; ++j ){
				if( d == 0 ) x += ( 2 * j );
				else y += ( 2 * j );
				for( int k = y; k < y + 2; ++k ){
					for( int m = x; m < x + 2; ++m ){
						map[ k * ( w + 2 ) + m ] = c;
					}
				}
			}
		}
		bool ans = false;
		int cs, cg;
		cs = map[ ys * ( w + 2 ) + xs ];
		cg = map[ yg * ( w + 2 ) + xg ];
		if( !( cs == 0 || cg == 0 || cs != cg ) ){
			queue< pair< int, int > > q;
			q.push( make_pair( xs, ys ) );
			while( !q.empty() ){
				int x = q.front().first;
				int y = q.front().second;
				q.pop();
				if( x == xg && y == yg ){
					ans = true;
					break;
				}
				map[ y * ( w + 2 ) + x ] = 0;
				for( int i = 0; i < 4; ++i ){
					int nx = x + dx[ i ];
					int ny = y + dy[ i ];
					if( map[ ny * ( w + 2 ) + nx ] == cs ){
						q.push( make_pair( nx, ny ) );
					}
				}
			}
		}
		cout << ( ans ? "OK" : "NG" ) << endl;
		delete[] map;
	}
	return 0;
}

Measured memory_bytes: 1320
n = int(input())
a = list(map(int,input().split()))
if abs(max(a))>=abs(min(a)):
  p = a.index(max(a))
  print(2*n-1)
  for i in range(n):
    print(p+1,i+1)
  for i in range(1,n):
    print(i,i+1)
else:
  p = a.index(min(a))
  print(2*n-1)
  for i in range(n):
    print(p+1,i+1)
  for i in range(n,1,-1):
    print(i,i-1)

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

typedef string::const_iterator ParseState;

class ParseError {
};

int expression(ParseState &begin);

int term(ParseState &begin);

int factor(ParseState &begin);

int number(ParseState &begin);

int expression(ParseState &begin) {
    int res = term(begin);
    while (true) {
        if (*begin != '+') break;
        begin++;
        res += term(begin);
    }
    return res;
}

int term(ParseState &begin) {
    int res = number(begin);
    while (true) {
        if (*begin != '*') break;
        begin++;
        res *= number(begin);
    }
    return res;
}

int factor(ParseState &begin) {

}

int number(ParseState &begin) {
    int ret = 0;
    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}

int expression2(ParseState &begin) {
    int res = number(begin);
    while (true) {
        if (*begin == '+') {
            begin++;
            res += (*begin - '0');
            begin++;
            continue;
        } else if (*begin == '*') {
            begin++;
            res *= (*begin - '0');
            begin++;
            continue;
        }
        break;
    }
    return res;
}

int main() {

    //  while (true) {

    string s;
    cin >> s;

    int N;
    cin >> N;

    auto state1 = s.cbegin();
    auto state2 = s.cbegin();

    int res1 = expression(state1);
    int res2 = expression2(state2);

    //cout << res1 << res2 << endl;

    if (res1 == res2 && res1 == N) {
        cout << "U" << endl;
    } else if (res1 == N && res2 != N) {
        cout << "M" << endl;
    } else if (res1 != N && res2 == N) {
        cout << "L" << endl;
    } else {
        cout << "I" << endl;
    }

    //  }

    return 0;
}





























Measured memory_bytes: 3224
#include<iostream>
using namespace std;
	long long N,M;
	long long T[100010];
	long long P;
	struct p{
		long long x,y;
	}He[100010];
	int main(){
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>T[i];
	}
	cin>>M;
	for(int i=1;i<=M;i++){
		cin>>He[i].x>>He[i].y;
	}
	for(int i=1;i<=M;i++){
		long long sum=0;
		for(int j=1;j<He[i].x;j++){
			sum=sum+T[j];
		}
		sum=sum+He[i].y;
	 for(int j=He[i].x+1;j<=N;j++){
	 	sum=sum+T[j];
	 }
	cout<<sum<<endl;
}
}

Measured memory_bytes: 256
S = input()
B = S.count('B')
W = S.count('W')
es = 'W' * W + 'B'* B
bf = es.find('B')
blst = [0] * B
for i in range(B):
    blst[i] = bf + i
slst = [0] * B
bindex = 0
for i in range(len(S)):
    if S[i] == 'B':
        slst[bindex] = i
        bindex += 1

ans = 0
for i in range(B):
    ans += blst[i] - slst[i]

print(ans)

Measured memory_bytes: 19172
// AOJ ALDS1_5_A Exhaustive Search
// 2018.4.30 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char f[2002];
short que[2002]; int top, end;

int main()
{
	int n, a, q;
	int stop, x;
	
	n = in(), que[0] = 0, end = 1;
	while (n--) {
		stop = end;
		a = in();
		for (top = 0; top < stop; top++) {
			x = que[top] + a;
			if (f[x]) continue;
			f[x] = 1, que[end++] = x;
		}
	}

	q = in();
	while (q--) {
		puts(f[in()]? "yes": "no");
	}
	return 0;
}


Measured memory_bytes: 2100
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.Vector;



public class Main{

	public static class pair implements Comparable<pair> {
		int id;
		int ans;
 
		pair(int x, int y) {
 
			id = x;
			ans = y;
 
		}
 
		public pair() {
 
		}
 
		public int compareTo(pair o) {
			// TODO Auto-generated method stub
 
			return this.id - o.id;
		}
	}
 
//	static int mod = (int) 998244353.;
	static ArrayList<Integer> gr[];
	static int[] ar;
	static Scanner sc = new Scanner(System.in);
	static int pri[] = new int[(int) 1e6 + 5];
	static StringBuilder out = new StringBuilder();
 
	//static long dp[];
 
	public static void main(String[] args) throws IOException {
		int t =1;// sc.nextInt();
		
		while (t-- > 0) {

			int n=sc.nextInt();
			int k=sc.nextInt();
			gr=new ArrayList[n+1];
			for(int i=0;i<=n;i++) {
				gr[i]=new ArrayList<Integer>();
			}
			
			for(int i=0;i<k;i++) {
				int di=sc.nextInt();
				for(int j=0;j<di;j++) {
					int in=sc.nextInt();
					gr[in].add(i);
				}
			}
			int cnt=0;
			for(int i=1;i<=n;i++) {
				if(gr[i].size()==0)cnt++;
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 50016
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ln "\n"
#define pb push_back
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define vll vector<ll>
#define vpll vector<pll>
#define vvll vector<vector<ll>>
#define sll stack<ll>
#define qll queue<ll>
#define mp make_pair
#define f first
#define s second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define Test ll t;cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define init(x,n,v) for(ll i=0;i<=n;i++) x[i]=v;
#define all(x) x.begin(),x.end()
ll MOD = 1e9+7 , MAX = 1e18 , k=1e9;
int main() 
{
	fast_io;
	ll r;
	double ans;
	cin>>r;
	ans = (44*r*1.0)/7;
	cout<<fixed<<setprecision(10)<<ans;
	return 0;
}

Measured memory_bytes: 3804
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define _ << " " <<
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	int cnt = 0;
	for (char i : s) {
		if (i == 'o') cnt++;
	}
	puts(cnt + 15 - s.length() >= 8 ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Data.List

f :: [(Int, Bool)] -> Int
f xs = sum ys
  where
    (_, ys) = mapAccumL g 0 xs
    g !acc (k, True)
        | acc + k > 0  = (acc + k, 0)
        | otherwise    = (1, abs $ k - (1 - acc))
    g !acc (k, False)
        | acc + k < 0  = (acc + k, 0)
        | otherwise    = (-1, abs $ k - (-1 - acc))

main :: IO ()
main = do
    getLine
    as <- fmap read . words <$> getLine :: IO [Int]
    let bs = zip as (cycle [True, False])
    let cs = zip as (cycle [False, True])
    print $ min (f bs) (f cs)

Measured memory_bytes: 54652
# -*- coding: utf-8 -*-

import sys
from heapq import heappush, heappop

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

# ダイクストラ(頂点数, 隣接リスト(0-indexed), 始点)
def dijkstra(N: int, nodes: list, src: int) -> list:
    # 頂点[ある始点からの最短距離]
    # (経路自体を知りたい時はここに前の頂点も持たせる)
    res = [float('inf')] * N
    # スタート位置
    que = [(0, src)]
    res[src] = 0
    # キューが空になるまで
    while len(que) != 0:
        # srcからの距離, 現在のノード
        dist, cur = heappop(que)
        # 出発ノードcurの到着ノードでループ
        for nxt, cost in nodes[cur]:
            # 今回の経路のが短い時
            if res[cur] + cost < res[nxt]:
                res[nxt] = res[cur] + cost
                # 現在の移動距離をキューの優先度として、早い方から先に処理するようにする
                heappush(que, (res[nxt], nxt))
    # ノードsrcからの最短距離リストを返却
    return res

N=INT()
nodes=[[] for i in range(N)]
for i in range(N):
    l=LIST()
    u=l[0]
    k=l[1]
    l=l[2:]
    for j in range(0, k*2, 2):
        nodes[u].append((l[j], l[j+1]))

ans=dijkstra(N, nodes, 0)
for i in range(N):
    print(i, ans[i])



Measured memory_bytes: 69008
if __name__ == '__main__':
    N = int(input())
    S = input()

    # S = "WWWWWEEE"
    # N = len(S)

    min_total_turns = N

    left_turns = [0 for _ in range(N)]
    for i in range(N - 1):
        left_turns[i + 1] = left_turns[i]
        if S[i] == "W":
            left_turns[i + 1] += 1

    right_turns = [0 for _ in range(N)]
    for i in range(N - 1, -1, -1):
        if i != 0:
            right_turns[i - 1] = right_turns[i]
            if S[i] == "E":
                right_turns[i - 1] += 1

        min_total_turns = min(min_total_turns, left_turns[i] + right_turns[i])

    # print(left_turns)
    # print(right_turns)
    print(min_total_turns)


Measured memory_bytes: 17872
h,w=map(int,input().split())
m=[[None for j in range(w)] for i in range(h)]
c=[[-1 for j in range(w)] for i in range(h)]
for i in range(h):
    s=input()
    for j in range(w):
        if s[j]==".":
            m[i][j]=0
        else:
            m[i][j]=1

for i in range(h):
    j=0
    start=-1
    while(j<w):
        if start==-1:
            if m[i][j]==0:
                start=j
                count=1
        else:
            if m[i][j]==1:
                for k in range(start,j):
                    c[i][k]+=count
                start=-1
            else:
                count+=1
        j+=1
    if start!=-1:
        for k in range(start,w):
            c[i][k]+=count
for j in range(w):
    i=0
    start=-1
    while(i<h):
        if start==-1:
            if m[i][j]==0:
                start=i
                count=1
        else:
            if m[i][j]==1:
                for k in range(start,i):
                    c[k][j]+=count
                start=-1
            else:
                count+=1
        i+=1
    if start!=-1:
        for k in range(start,h):
            c[k][j]+=count
result=0
for i in range(h):
    for j in range(w):
        result=max(result,c[i][j])
print(result)

Measured memory_bytes: 117852
import java.io.IOException;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = a / 500;
        int c = (a % 500) / 5;
        System.out.println(1000 * b + 5 * c);
    }
}

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

const int N = 1000+9;
const int MOD = 1000000007;

int n,tot,pri[N],cnt[N]; 

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

int main() {
	int n = read(), vout = 1;
	for (int i=2,tag=1;i<=n;i++,tag=1) {
		for (int j=2;j<i;j++) {
			if (i % j == 0) {
				tag = 0;
				break;
			}
		}
		if (tag) pri[++tot] = i;
	}
	for (int i=1,w;i<=n;++i) {
		for (int j=1;j<=tot;j++) {
			for (w=i;w%pri[j]==0;cnt[j]++) w /= pri[j];
		}
	}
	for (int i=1;i<=tot;i++)
		vout = vout * (cnt[i] + 1LL) % MOD;
	printf("%d\n",vout);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	if(y==0) return x;
	return gcd(y,x%y);	
}

ll lcm(ll x, ll y) {
	ll z=gcd(x,y);
	return x/z*y;
}

int main()
{
	int n;
	string u;
	double ans=0,x;
	cin >> n;
	rep(i,n){
		cin >> x >> u;
		ans+=(u=="JPY"?x:x*380000.0);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def judge(A):
    B = [0] * len(A)
    for i, a in enumerate(A):
        b = 0
        while a % 2 == 0:
            b += 1
            a //= 2
        B[i] = b
    if len(set(B)) == 1:
        return True
    else:
        return False


N, M = map(int, input().split())
A = [int(i) // 2 for i in input().split()]
A = list(set(A))
m = A[0]

if judge(A):
    for a in A[1:]:
        m = lcm(m, a)

    M //= m
    ans = (M + 1) // 2
else:
    ans = 0
print(ans)


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

struct edge {
    ll to,cost;
};

/*
const int COM_MAX = 6000500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/
int main(){
    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++){
        cin >> a[i];
        a[i]--;
    }
    int cnt = 0, ans = 0;
    for (int i = 0; i < N; i++){
        if (a[i] == cnt){
            cnt++;
        }
    }
    if (cnt == 0){
        cout << -1 << endl;
        return 0;
    }
    cout << N-cnt << endl;
}

Measured memory_bytes: 1024
N,A,B = map(int,input().split())
H = []
for _ in range(N):
    H.append(int(input()))
H = sorted(H)
def check(x):
    cnt = 0
    for h in H:
        if h > x * B:
            tmp = (h - x*B) // (A-B)
            #切り上げ
            if tmp * (A-B) != h - x*B: tmp += 1
            cnt += tmp
    if cnt <= x:
        return True
    else:
        return False
# (l,r]
def bisect(l,r):
    if r - l == 1: return r
    mid = (l+r) // 2
    if check(mid):
        return bisect(l,mid)
    else:
        return bisect(mid,r)
    
print(bisect(0,10**31))


Measured memory_bytes: 8284
#include<iostream>
#include<algorithm>
using namespace std;
int N,L[2000];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>L[i];
	sort(L,L+N);
	long ans=0;
	for(int i=0;i<N;i++)
	{
		int id=i;
		for(int j=i+1;j<N;j++)
		{
			while(id<N&&L[id]<L[i]+L[j])id++;
			ans+=id-j-1;
		}
	}
	cout<<ans<<endl;
}


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

using namespace std;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    vector<int> t(n);
    vector<int> x(n);
    vector<int> y(n);

    P p(0,0);
    int now = 0;
    for (int i=0; i<n; i++) cin >> t[i] >> x[i] >> y[i];

    bool ans = true;
    for (int i=0; i<n; i++) {
        int rest = t[i] - now;
        int dist = abs(p.first - x[i]) + abs(p.second - y[i]);
        if (rest < dist) {
            ans = false;
            break;
        }

        if (rest%2 != dist%2) {
            ans = false;
            break;
        }

        now = t[i];
        p = P(x[i],y[i]);
    }

    cout << (ans? "Yes" : "No") << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, m;
    cin >> n >> m;
    ll mod = 1e9 + 7;
    ll ans = 1;
    if (abs(n-m) > 1) {
        cout << 0 << endl;
        return 0;
    } else if (abs(n-m) == 1) {
        for(int i = 1; i <= n; i++) {
            ans *= i;
            ans %= mod;
        }
        for(int i = 1; i <= m; i++) {
            ans *= i;
            ans %= mod;
        }
    } else {
        for(int i = 1; i <= n; i++) {
            ans *= i;
            ans %= mod;
        }
        ans *= ans;
        ans *= 2;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N = getN()
A = getList()

pair = True
semi = True
# not divisible
# 全部互いに素かどうか
judge = [0] * (10 ** 6 + 1)

now = A[0]
for i in A[1:]:
    now = math.gcd(now, i)
if now > 1:
    semi = False

for i in A:
    judge[i] += 1

for i in range(2, 10 ** 6 + 1):
    cnt = 0
    for j in range(i, 10 ** 6 + 1, i):
        cnt += judge[j]
    if cnt > 1:
        pair = False
        break

if pair and semi:
    print('pairwise coprime')
elif semi:
    print('setwise coprime')
else:
    print('not coprime')

Measured memory_bytes: 228584
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
t = [[] for _ in range(n + 1)]
for i in ab:
    t[i[1]].append(i[0])
flag = False
for j in t[n]:
    if 1 in t[j]:
        flag = True
        break
print("POSSIBLE") if flag else print("IMPOSSIBLE")

Measured memory_bytes: 63408
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = getInt(sc);

		List<Integer> a = new ArrayList<>();
		a.add(s);
		for (int i = 0;; i++) {
			int fn = function(a.get(i));
			if (a.contains(fn)) {
				System.out.println(a.size() + 1);
				break;
			} else {
				a.add(fn);
			}
		}

	}

	private static int function(int n) {

		if (n % 2 == 0) {
			return n / 2;
		} else {
			return n * 3 + 1;
		}
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


Measured memory_bytes: 21844
object Main extends App{
    val Array(n, m, q) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val LR = new Array[(Int, Int)](m)
    val PQ = new Array[(Int, Int)](q)

    val MM = Array.ofDim[Long](n+1, n+1)

    for(i<-0 until m){
    	val Array(t1, t2) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    	LR(i) = (t1, t2)
    }

    for(i<-0 until q){
    	val Array(t1, t2) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    	PQ(i) = (t1, t2)
    }

    LR.map{ case(l,r) => MM(l)(r) += 1 }

    //MM.foreach(a => println(a.mkString(" ")))

    for(i <- 1 to n; j <- 1 to n){
    	MM(i)(j) += MM(i-1)(j) + MM(i)(j-1) - MM(i-1)(j-1)
    }

    val ans = PQ.map{ case(p,q) => 
		MM(q)(q) - MM(p-1)(q) - MM(q)(p-1) + MM(p-1)(p-1)		
	}

	for(x <- ans){
		println(x)
	}

}

Measured memory_bytes: 120580
#include <stdio.h>

int main(void){
    int n; scanf("%d", &n);
    long long int S = 0, T = 0;
    while(n--){
        long long c; int d; scanf("%d%lld", &d, &c);
        S += c * d; T += c;
    }
    if(S % 9 == 0) {S /= 9; S--;}
    else S /= 9;
    printf("%lld\n", T + S - 1);
    return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
#include <math.h>
#include <numeric>
#include <stack>
#include <map>
using namespace std;
#define DEBUG 0
#define lli long long int

const lli N_MAX = 200001;
lli N;
lli X[N_MAX], A[N_MAX];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i];
		A[i] = X[i];
	}
	sort(A, A + N);

	lli med_l = A[N / 2];
	lli med_s = A[(N / 2) - 1];

	for (int i = 0; i < N; i++) {
		if (X[i] < med_l) cout << med_l << endl;
		else cout << med_s << endl;
	}
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
    cin >> s;
    int n = s.size();
    s = '.' + s;
    bool exist = true;
    if(s[1]=='0' || s[n]=='1')exist = false;

    for(int i=1;i<n;i++){
        if(s[i]!=s[n-i])exist = false;
    }
    if(!exist){
		cout << -1 << endl;
		return 0;
	}
    s[n] = '1';
    queue<int> ones;
    for(int i=1;i<=n;i++){
        if(s[i]=='1')ones.push(i);
    }
    for(int i=1;i<n;i++){
        if(i==ones.front()){
            ones.pop();
        }
        cout << i << " " << ones.front() << endl;
    }
}

Measured memory_bytes: 1900
n, y = map(int, input().split())

for i in range(y//10000 + 1):
    for j in range(y//5000 + 1):
        if 10000*i + 5000*j + 1000*(n - i - j) == y:
            if n - i - j >= 0:
                print(i, j, n - i - j)
                exit()

print(-1, -1, -1)

Measured memory_bytes: 40880
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define ins insert
#define fi first
#define se second
#define okay ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define llmax 2e18
#define PI 3.14159265
int d[10000001];
using namespace std;
int main() {
	okay;
//	int t;
//	cin>>t;
//	while(t--)
	{
		ll n;
		cin>>n;
		for (ll i = 1; i <= n; i++) { 
        for (ll j = 1; j * i <= n; j++) 
            d[i * j]++; 
    	} 
		ll ans=0;
		for(ll i=1;i<=n;i++)
		ans+=(i*d[i]);
		cout<<ans;
	}
}

Measured memory_bytes: 42696
#include <tuple>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <limits>
#include <string>
#include <cmath>


template<class... Ts> using tuple_t = std::tuple<Ts...>;
template<class T, class U> using map_t = std::map<T, U>;
template<class T, class U> using pair_t = std::pair<T, U>;
template<class T> using vector_t = std::vector<T>;
template<class T> using set_t = std::set<T>;

uint64_t digit(uint64_t num, uint64_t base = 10)
{
	uint64_t i = 0;
	while(num)
	{
		++i;
		num /= base;
	}
	return i;
}

uint64_t digit_sum(uint64_t num, uint64_t base = 10)
{
	uint64_t i = 0;
	while(num)
	{
		i += num % base;
		num /= base;
	}
	return i;
}

int min(vector_t<int> nums)
{
	int min_ = std::numeric_limits<int>::max();
	for(auto& i :nums)
		if(min_ > i)
			min_ = i;
	return min_;
}
int max(vector_t<int> nums)
{
	int max_ = std::numeric_limits<int>::min();
	for(auto& i :nums)
		if(max_ < i)
			max_ = i;
	return max_;
}
int first_min(vector_t<int> nums, int start = 0)
{
	int min_ = min(nums);
	for(int i = start; i < nums.size(); ++i)
		if(nums[i] == min_)
			return i;
	return 0;
}

int main()
{
	uint64_t n,m,d;
	std::cin>>n>>m>>d;
	double b = d==0?(n-d):(n-d)*2;
	double div=n;
	std::printf("%.10lf\n",b*(m-1)/div/div);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = String.valueOf(n);
		char[] ch = s.toCharArray();
		if ((ch[0] == ch[1] && ch[0] == ch[2]) || (ch[1] == ch[2] && ch[1] == ch[3])) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
//atcoder 146 c
int main()
{
  int n,m,ans;
  cin >> n >> m;
  vector<int> A(m);
  for(int& e:A)cin >>e;
  ans = n - accumulate(A.begin(),A.end(),0);
  if(ans<0)ans=-1;
 cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define SORT(x) sort(all(x))
#define RSORT(x) sort(all(x),greater<ll>())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define sprint(X) printf("%f\n", (X)) // 小数点の出力
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
#define case(X) cout << "Case #" << (X) + 1 << ":" << "\n"
static const int INF = 1e+9+7;

int main(){

  ll r;
  cin >> r;
  print(r * r);

 return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int H, W;
int main(){

	for (;;){
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int a = 0; a < H; a++){
			
			for (int b = 0; b < W; b++){
				if ((a + b) % 2 == 0)cout << '#';
				if ((a + b) % 2 == 1)cout << '.';
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3100
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
#define ll long long
const int maxn = 1000 + 5;
string s1,s2,s3;
int main()
{
    cin>>s1>>s2>>s3;
    if(s1[s1.length()-1]==s2[0]&&s2[s2.length()-1]==s3[0])
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  ll nummax = A[0], res = 0; // 最大値を保持しておく
  for (int i=1; i<N; i++) {
    if (nummax>A[i]) res += nummax-A[i];
    else nummax = A[i];
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4832