akhauriyash/Code-Regression huggingface dataset:
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

const inf = int(2e18)

func main() {
	sc.Split(bufio.ScanWords)

	N, K := getInt(), getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	sort.Ints(a)

	L := -inf
	R := inf
	for L+1 != R {
		M := (L + R) / 2
		cnt := 0
		for i := 0; i < N; i++ {
			if a[i] < 0 {
				l := i
				r := N
				for l+1 != r {
					m := (l + r) / 2
					if a[i]*a[m] <= M {
						r = m
					} else {
						l = m
					}
				}
				cnt += N - r
			} else {
				l := i
				r := N
				for l+1 != r {
					m := (l + r) / 2
					if a[i]*a[m] <= M {
						l = m
					} else {
						r = m
					}
				}
				cnt += l - i
			}
		}
		if cnt < K {
			L = M
		} else {
			R = M
		}
	}
	out(R)
}


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string w = ReadString();
            bool ans = w.GroupBy(c => c).All(g => g.Count() % 2 == 0);
            Console.WriteLine(ans ? "Yes" : "No");
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 13396
from collections import deque


def isPalindrome(s):
    L = len(s)
    rst = True
    if L:
        for i in range(L // 2):
            if s[i] != s[L - 1 - i]:
                rst = False
                break
    return rst


N = int(input())
S = []
for _ in range(N):
    s, c = input().split()
    S.append((s, int(c)))

path = [dict() for _ in range(2)]
q = deque()
S.sort(key=lambda x: x[1])
for s, c in S:
    if s not in path[0] or path[0][s] > c:
        path[0][s] = c
        q.append((0, s, c))

ans = float('inf')
isPossible = False
while q:
    side, s0, c0 = q.popleft()
    if isPalindrome(s0):
        ans = min(ans, c0)
        isPossible |= True
    else:
        for s1, c1 in S:
            if side == 0:
                l = s0
                r = s1
            else:
                l = s1
                r = s0

            if len(l) > len(r):
                for i in range(len(r)):
                    if l[i] != r[-1 - i]:
                        break
                else:
                    ns = l[len(r):]
                    nc = c0 + c1
                    nside = 0
                    if (ns not in path[nside]) or path[nside][ns] > nc:
                        path[nside][ns] = nc
                        q.append((nside, ns, nc))
            elif len(l) < len(r):
                for i in range(len(l)):
                    if l[i] != r[-1 - i]:
                        break
                else:
                    ns = r[:-len(l)]
                    nc = c0 + c1
                    nside = 1
                    if (ns not in path[nside]) or path[nside][ns] > nc:
                        path[nside][ns] = nc
                        q.append((nside, ns, nc))
            else:
                for i in range(len(l)):
                    if l[i] != r[-1 - i]:
                        break
                else:
                    ns = ''
                    nc = c0 + c1
                    nside = 0
                    if (ns not in path[nside]) or path[nside][ns] > nc:
                        path[nside][ns] = nc
                        q.append((nside, ns, nc))
if isPossible:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 74560
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;

int main(void){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<3;i++){
        if(s[i]=='1'){
             ans++;
             }
    }
             cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl
#define all(v) v.begin(), v.end()
#define rsort(v) sort(v.rbegin(), v.rend())


const ll mod = 1e9+7;
struct mint {
  ll x;
  mint(ll x=0) : x((x%mod+mod)%mod) {}
  mint &operator+=(const mint &p) { if((x += p.x) >= mod) x -= mod; return *this; }
  mint &operator-=(const mint &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
  mint &operator*=(const mint &p) { x = x * p.x % mod; return *this; }
  mint &operator/=(const mint &p) { *this *= p.inverse(); return *this; }
  mint operator-() const { return mint(-x); }
  mint operator+(const mint &p) const { return mint(*this) += p; }
  mint operator-(const mint &p) const { return mint(*this) -= p; }
  mint operator*(const mint &p) const { return mint(*this) *= p; }
  mint operator/(const mint &p) const { return mint(*this) /= p; }
  bool operator==(const mint &p) const { return x == p.x; }
  bool operator!=(const mint &p) const { return x != p.x; }
  mint inverse() const {
    ll a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return mint(u);
  }
  mint pow(ll n) const {
    mint ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const mint &p) { return os << p.x; }
  friend istream &operator>>(istream &is, mint &a) {
    ll t;
    is >> t;
    a = mint(t);
    return (is);
  }
};


int main() {
  int N;
  cin >> N;
  map<pair<ll,ll>, pair<ll,ll>> m;
  ll zero = 0;
  mint ans = 1, two = 2;
  rep(i,N) {
    ll a, b;
    cin >> a >> b;
    if (a==0 && b==0) {
      zero++;
      continue;
    }
    if (a<0) {
      a = -a;
      b = -b;
    }
    if (a==0) {
      m[{0,1}].first++;
    } else if (b==0) {
      m[{0,1}].second++;
    } else {
      ll g = __gcd(abs(a), abs(b));
      a /= g; b /= g;
      if (b<0)
        m[{-b,a}].second++;
      else
        m[{a,b}].first++;
    }
  }
  for (auto &e: m) {
    ll c1 = e.second.first, c2 = e.second.second;
    ans *= two.pow(c1) + two.pow(c2) - 1;
  }
  ans += zero - 1;
  print(ans);
  return 0;
}

Measured memory_bytes: 19104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef	long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef pair<ll, pll> plll;
typedef vector<pair<int, pii>> viii;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define tc int tt;cin>>tt;while(tt--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fio ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#define RED "\033[31m"
#define GREEN "\033[32m"
#define RESET "\033[0m"
#define sleep for (int i = 1, a;i < 100000000;i++, a = a * a)
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map;

int main() {
	fio;
	int n;
	cin >> n;
	vl a(n);
	for (int i = 0;i < n;i++)
		cin >> a[i];
	ll ans = 0;
	for (int i = 1;i < n;i++)
		if (a[i] < a[i - 1]) {
			ans += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	cout << ans << '\n';
}


Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    string b;
    cin >> b;
    string ans;
    
    if (b == "A")ans = "T";
    else if (b == "C")ans = "G";
    else if (b == "G")ans = "C";
    else if (b == "T")ans = "A";
        
    cout << ans << endl;
    
    
 
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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 <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, c; cin >> n >> c;
    vector<vector<int> > d(c, vector<int>(c));
    rep (i, c) rep (j, c) cin >> d[i][j];
    map<int, int> m[3];
    rep (i, n) {
        rep (j, n) {
            int a; cin >> a; a--;
            m[(i + j) % 3][a]++;
        }
    }
    ll ans = 1e18;
    rep (i, c) {
        rep (j, c) {
            rep (k, c) {
                if (i == j || j == k || k == i) continue;
                ll tmp = 0;
                rep (l, c) tmp += m[0][l] * d[l][i];
                rep (l, c) tmp += m[1][l] * d[l][j];
                rep (l, c) tmp += m[2][l] * d[l][k];
                chmin(ans, tmp);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n;
	cin>>n;
	ll a[n+1],b[n+1],c[n+1];
	for (ll i=1;i<=n;i++)
		cin>>a[i]>>b[i]>>c[i];
	ll dp1[n+1];
	ll dp2[n+1];
	ll dp3[n+1];
	dp1[0]=0;
	dp2[0]=0;
	dp3[0]=0;
	dp1[1]=a[1];
	dp2[1]=b[1];
	dp3[1]=c[1];
	//cout<<max(dp1[1],max(dp2[1],dp3[1]))<<endl;
	for (ll i=2;i<=n;i++)
	{
		dp1[i]=max(dp2[i-1]+a[i],dp3[i-1]+a[i]);
		dp2[i]=max(dp1[i-1]+b[i],dp3[i-1]+b[i]);
		dp3[i]=max(dp2[i-1]+c[i],dp1[i-1]+c[i]);
		//cout<<max(dp1[i],max(dp2[i],dp3[i]))<<endl;
	}
	cout<<max(dp1[n],max(dp2[n],dp3[n]));
}

Measured memory_bytes: 4992
#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<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
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;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

   int a,b;
   char op;
 while(1){
   cin >>a>>op>>b;
   if(op=='?')break;
   if(op=='+'){
     cout<<a+b<<endl;
   }
   else if(op=='-'){
     cout<<a-b<<endl;

   }
   else if(op=='*'){
     cout<<a*b<<endl;
   }
   else if(op=='/' && b!=0){
     cout<<a/b<<endl;
   }

 }
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {
    sws;

    int n;
    cin >> n;
    vi v(n);

    fo(i, n) {
        cin >> v[i];
    }

    sort(all(v));

    // fo(i, n) {
    //     cout << v[i] << " ";
    // }
    // cout << endl;

    cout << (v[n / 2] - v[n / 2 - 1]) << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

char res[15];
string s;
int siz;

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> s;
    FOR(i,0,s.length()-1)
        if (s[i] == 'B') {
            if (siz) siz--;
        }
        else res[++siz] = s[i];
    FOR(i,1,siz) cout << res[i];
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
const ll mod = 1e9+7;

ll power(ll a,ll b) {
    ll res = 1;
    while(b) {
        if(b&1) {
            res = (res*a)%mod;
        }
        a = (a*a)%mod;
        b >>= 1;
    }
    return res;
}

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

bool isPalin(string s) {
    int n = s.length();
    int l = 0;
    int r = n-1;
    while(l < r) {
        if(s[l] != s[r]) {
            return false;
        }
        l++;
        r--;
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.length();
    if(n%2 == 0) {
        cout << "No" << endl;
    } else {
        bool a = isPalin(s);
        bool b = isPalin(s.substr(0,(n-1)/2));
        bool c = isPalin(s.substr((n+3)/2-1,(n-1)/2));
        if(a && b && c) puts("Yes");
        else puts("No");
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
c = 1000
s = 0
l = len(A)
for i, a in enumerate(A):
    if i < l - 1:
        if a == A[i+1]:
            continue
        elif a < A[i+1]:
            if c >= a:
                ss = c // a
                s += ss
                c -= ss * a
        else:
            if s > 0:
                c += s * a
                s = 0
    else:
        if s > 0:
            c += s * a
            s = 0
print(c)

Measured memory_bytes: 61856
def calc(L):
    stack=[]
    for l in L:
        try:
            l=float(l)
            stack.append(l)
        except:
            b=stack.pop(-1)
            a=stack.pop(-1)
            if l=="+":
                stack.append(a+b)
            elif l=="-":
                stack.append(a-b)
            elif l=="*":
                stack.append(a*b)
            else:
                stack.append(a/b)
    return stack[0]



while True:
    try:
        s=input()
        print(calc(s.split(" ")))
    except EOFError:
        break



Measured memory_bytes: 5580
class Vertex
  class << self
    def register(index, weights)
      @vertexes ||= {}
      @vertexes[index] = new(index, weights)
    end

    def find(index)
      @vertexes[index]
    end

    def each
      @vertexes.each { |_, v| yield v }
    end
  end

  attr_reader :index
  attr_accessor :parent

  def initialize(index, weights)
    @index = index
    @index_cost_map = weights.map.with_index { |e, i| e == -1 ? nil : [i, e] }.compact!.to_h
    @selected = false
  end

  def neighbors
    @neighbors ||= @index_cost_map.keys.map { |i| self.class.find(i) }
  end

  def neighbor?(other)
    @index_cost_map.key?(other.index)
  end

  def cost(other)
    @index_cost_map[other.index]
  end

  def selected?
    @selected
  end

  def select!
    @selected = true
  end
end

class Prim
  class << self
    def solve
      min_costs = Hash.new { |h, k| h[k] = Float::INFINITY }
      min_costs[0] = 0

      loop do
        min_cost = Float::INFINITY
        selected_vertex = nil
        Vertex.each do |v|
          if !v.selected? && min_costs[v.index] < min_cost
            selected_vertex = v
            min_cost = min_costs[v.index]
          end
        end

        break if selected_vertex.nil?

        selected_vertex.select!

        Vertex.each do |v|
          next if v.selected? || !selected_vertex.neighbor?(v)

          if selected_vertex.cost(v) < min_costs[v.index]
            min_costs[v.index] = selected_vertex.cost(v)
            v.parent = selected_vertex
          end
        end

      end

      sum = 0
      Vertex.each { |v| sum += v.parent.cost(v) if v.parent }
      sum
    end
  end
end

n = gets.to_i
n.times do |i|
  Vertex.register(i, gets.strip.split.map(&:to_i))
end

puts Prim.solve



Measured memory_bytes: 7332
def main():
    N = int(input())
    T = [int(x) for x in input().split()]
    M = int(input())
    PX = [[int(x) for x in input().split()] for _ in range(M)]
    for P, X in PX:
        t = T[:]
        t[P - 1] = X
        print(sum(t))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int MAX = 300000;
int main(){
  vector<bool> prime(MAX + 1, true);
  prime[1] = false;
  for (int i = 0; i * 7 <= MAX; i++){
    int x = i * 7 + 1;
    if (x <= MAX){
      if (prime[x]){
        for (int j = x * 2; j <= MAX; j += x){
          prime[j] = false;
        }
      }
    }
    int y = i * 7 + 6;
    if (y <= MAX){
      if (prime[y]){
        for (int j = y * 2; j <= MAX; j += y){
          prime[j] = false;
        }
      }
    }
  }
  while (1){
    int N;
    cin >> N;
    if (N == 1){
      break;
    }
    cout << N << ":";
    for (int i = 0; i * 7 <= MAX; i++){
      int x = i * 7 + 1;
      if (x <= MAX){
        if (prime[x]){
          if (N % x == 0){
            cout << ' ' << x;
          }
        }
      }
      int y = i * 7 + 6;
      if (y <= MAX){
        if (prime[y]){
          if (N % y == 0){
            cout << ' ' << y;
          }
        }
      }
    }
    cout << endl;
  }
}


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

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

  vector<int> d(N);
  rep(i,N) cin >> d[i];
  sort(d.begin(),d.end());

  if(N % 2 != 0){
    cout << 0 << endl;
  } else if(d[N/2] == d[N/2 - 1]){
    cout << 0 << endl;
  } else {
    cout << d[N/2] - d[N/2 - 1] << endl;
  }
}

Measured memory_bytes: 640
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int n,W;
    cin>>n>>W;
    vector<ll>dp(W+1,0);
    for(int i=0;i<n;i++){
        int w;
        cin>>w;
        ll v;
        cin>>v;
        for(int weight=W-w;weight>=0;weight--){
            dp[weight+w]=max(dp[weight+w], dp[weight]+v);
        }
    }
    ll mx=0;
    for(int i=0;i<=W;i++){
        mx = max(dp[i],mx);
    }
    cout<<mx<<"\n";
}


Measured memory_bytes: 1024
x = int(input())
a=b=c=0

for i in range(1,5):
    if i==1:
        d=x%10
    elif i==2:
        c=x%10
    elif i==3:
        b=x%10
    else:
        a=x%10

    x/=10
    x = int(x)


#apply 8 combinations

if a+b+c+d == 7:
    print(str(a) + "+" + str(b) + "+" + str(c) + "+" + str(d) + "=" + "7")
elif a+b+c-d == 7:
    print(str(a) + "+" + str(b) + "+" + str(c) + "-" + str(d) + "=" + "7")
elif a+b-c+d == 7:
    print(str(a) + "+" + str(b) + "-" + str(c) + "+" + str(d) + "=" + "7")
elif a+b-c-d == 7:
    print(str(a) + "+" + str(b) + "-" + str(c) + "-" + str(d) + "=" + "7")
elif a-b-c-d == 7:
    print(str(a) + "-" + str(b) + "-" + str(c) + "-" + str(d) + "=" + "7")
elif a-b-c+d == 7:
    print(str(a) + "-" + str(b) + "-" + str(c) + "+" + str(d) + "=" + "7")
elif a-b+c-d == 7:
    print(str(a) + "-" + str(b) + "+" + str(c) + "-" + str(d) + "=" + "7")
elif a-b+c+d == 7:
    print(str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=" + "7")


Measured memory_bytes: 3192
H, W = [int(i) for i in input().split()]
S = [input() for _ in range(H)]

L = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] != "#":
            L[i][j] = 1 if j == 0 else 1 + L[i][j - 1]
    for j in range(W - 1, -1, -1):
        if S[i][j] != "#":
            R[i][j] = 1 if j == W - 1 else 1 + R[i][j + 1]

for j in range(W):
    for i in range(H):
        if S[i][j] != "#":
            U[i][j] = 1 if i == 0 else 1 + U[i - 1][j]
    for i in range(H - 1, -1, -1):
        if S[i][j] != "#":
            D[i][j] = 1 if i == H - 1 else 1 + D[i + 1][j]

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
print(ans)


Measured memory_bytes: 184452
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
    buf := make([]byte, 0, 1000000)
    for {
        l, p, e := rdr.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    return string(buf)
}


func nextLine() string {
    sc.Scan()
    return sc.Text()
}


func main(){
	var a, b int
	fmt.Scan(&a)
	fmt.Scan(&b)

	if a<b {
		for i:=0; i<b;i++{
			fmt.Print(a)
		}
	}else {
		for i:=0; i<a;i++{
			fmt.Print(b)
		}
	}
	fmt.Println("")
}


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

int N,A[100010];

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)scanf("%d",A + i);

    int ans = 1000;
    for(int i = 0; i < N; i++)
    {
        int cnt = 0;
        while(A[i] != 0 && A[i] % 2 == 0)
        {
            A[i] /= 2;
            cnt++;
        }
        ans = min(ans,cnt);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int x[5];
    for(int i=0;i<5;i++){
        cin>>x[i];
    }
    for(int j=0;j<5;j++){
        if(x[j]==0){
            cout<<j+1;
        }
    }

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill fill_n
#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define comp(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define infile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi;
typedef vector<ll> vli;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvli;
const int M = 1e9+7;
const int N = 2e5;
ll po(int,int);


void solve(){
   int n;
   ll d;
   cin>>n>>d;
   ll x,y;
   int ans=0;
   FOR(i,0,n){
       cin>>x>>y;
       if(x*x +y*y <= d*d) ans++;
   }
   cout<<ans<<"\n";

}





int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int t=1;
    //cin>>t;
    FOR(i,1,t+1){
        //cout<<"Case #"<<i<<": "; 
        solve();
    }
    
	return 0;
	
	
}


ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;

int main()
{
  string s,ans; cin >> s;
  
  int count=0;
  while(count < s.size()){
  	count++;
  }
  count -= 2;
  ans = to_string(count);
  cout << s.at(0) << ans << s.at(s.size()-1) << endl;
}

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

int main()
{
    int n, x;
    cin >> n >> x;
    int l[n];
    for(int i = 0; i < n; ++i) {
        scanf("%d", &l[i]);
    }

    int d[n + 1];
    int count = 0;
    d[0] = 0;
    /*
    for(int j = 1; j < n; ++j) {
        d[j] = d[j-1] + l[j-1];
        if(d[j] <= x) {
            count++;
        }else{
            break;
        }
    }
*/
    for(int j = 1; j < n + 1; ++j) {
        d[j] = d[j-1] + l[j-1];
    }

    for(int j = 0; j < n + 1; ++j) {
        if(d[j] > x) {
            count = j;
            break;
        }
    }
    if(count==0) count = n+1;
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
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; }
const int INF = INT_MAX;
const int MOD = 1000000007;

struct edge {
    int to;
    int weight;
};

vector<vector<edge>> graph;
vi color;

void dfs(int v, int now_color){
    color[v] = now_color;
    for (auto e : graph[v]) {
        int mod = e.weight % 2;
        if (color[e.to] == -1) {
            if (mod == 0) dfs(e.to, now_color);
            else dfs(e.to, 1-now_color);
        }
    }
}

int main() {
    int N;
    cin >> N;
    graph.resize(N);
    rep(i, N-1) {
        int u, v, w;
        cin >> u >> v >> w;
        edge e1 = {v-1, w};
        edge e2 = {u-1, w};
        graph[u-1].push_back(e1);
        graph[v-1].push_back(e2);
    }

    color = vi(N, -1);
    dfs(0, 0);

    rep(i, N) {
        cout << color[i] << endl;
    }
}

Measured memory_bytes: 8192
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<=b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair< int, int>
#define vpii vector<pii>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   
    int t=1;
    //cin>>t;
    while(t--){
    	int n,m;
    	cin>>n>>m;
    	string s;
    	vector<string>a;
    	Fr(i,0,n-1){
    		cin>>s;
    		a.pb(s);
    	}
    	vvi dp(n,vi(m,0));
    	dp[0][0]=1;
    	Fr(i,0,n-1){
    		Fr(j,0,m-1){
    			if(i==0||j==0){
    				if(a[i][j]=='#'){
    					dp[i][j]=0;
    				}
    				else{
    					dp[i][j]=dp[max(0,i-1)][max(0,j-1)];
    				}
    			}
    			else{
    				if(a[i][j]=='.'){
    					dp[i][j]=dp[i-1][j]+dp[i][j-1];
    				}
    			}
    			dp[i][j]=dp[i][j]%mod;
    		}
    	}
    	cout<<dp[n-1][m-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 9216
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#include "atcoder/all"
#else
#define NDEBUG
#include <atcoder/all>
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

//   X    Y
pair<int, int> pos[200'005];
int ord_x[200'005];
int ans[200'005];

struct Group {
    int l, r;
    int min, max;
};

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

    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        pos[i] = {x, y};
        ord_x[x] = i;
    }
    sort(pos, pos + n);

    auto top = n;
    auto group = vector<Group>();
    group.push_back({});

    for (int i = 0; i < n; ++i) {
        auto [x, y] = pos[i];
        assert(x == i);

        auto&& g = group.back();
        if (g.l == g.r) { // empty
            g.l = x;
            g.r = x + 1;
            g.min = y;
            g.max = y;
        } else {
            g.r = x + 1;
            g.min = min(g.min, y);
            g.max = max(g.max, y);
        }

        auto xcnt = g.r - g.l;
        auto ycnt = top - g.min;
        if (xcnt == ycnt && g.max + 1 == top) {
            top = g.min;
            group.push_back({});
        }
    }
    if (group.back().l == group.back().r) { // empty
        group.pop_back();
    }

    for (auto&& g : group) {
        for (auto x = g.l; x < g.r; ++x) {
            ans[ord_x[x]] = (g.r - g.l);
        }
    }

    for (int i = 0; i < n; ++i) {
        cout << ans[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 6872
#include <iostream>
#include <complex>
#include <cmath>
#define X real()
#define Y imag()
#define F first
#define S second
#define ML make_pair
#define EPS 1e-10
#define PI acos(-1)
using namespace std;
typedef long double  D;
typedef complex<double> P;
typedef complex<double> V;
typedef pair<P,P> L;


// 内積 (Inner Product) : a・b = |a||b|cosθ 1
D IP(V a, V b) {
	return (a.real() * b.real() + a.imag() * b.imag());
}

// 外積 (Exterior Product) : |a×b| = |a||b|sinθ 2
D EP(V a, V b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}

//交点判定
bool ISC(L l1,L l2){
	V v1,v2;
	v1=l1.S-l1.F;
	v2=l2.S-l2.F;
	if(abs(EP(v1,v2))<EPS)
		return false;
	else
		return true;
}

//　交点の座標
P IS(L l1,L l2){
	P p1,p2,p3,p4;
	p1=l1.F,p2=l1.S,p3=l2.F,p4=l2.S;
	D tmp=(EP(p4-p3,p3-p1)/EP(p4-p3,p2-p1));
	V v1=(tmp,tmp);
	return p1+(p2-p1)*v1;
}
int main(void){
	int n;
	cin >>n;
	for(int j=0;j<n;j++){
		P point[4],tmp1,tmp2;
		for(int i=0;i<3;i++)
			cin >> point[i].X >> point[i].Y;
		L l1,l2;
		tmp1=((point[0]+point[1])/P(2.0,0));
		D angle,r=1.0;
		angle=arg(point[1]-point[0]);
		angle+=PI/2.0;
		tmp2=polar(r,angle);
		l1=ML(tmp1,tmp1+tmp2);

		tmp1=(point[0]+point[2])/P(2.0,0);
		angle=arg(point[2]-point[0]);
		angle+=PI/2.0;
		tmp2=polar(r,angle);
		l2=ML(tmp1,tmp1+tmp2);

		point[3]=IS(l1,l2);
		cout.precision(3);
		cout << fixed << point[3].X << ' '<< point[3].Y << ' '<< abs(point[3]-point[0]) << endl;
	}
	return 0;
}

Measured memory_bytes: 1368
H,W,K = map(int,input().split())
cake = [list(input()) for _ in range(H)]
cnt = 1

ans = [[0]*W for _ in range(H)]

for h in range(H):
    for w in range(W):
        if cake[h][w] == "#":
            ans[h][w] = cnt
            cnt += 1

for h in range(H):
    for w in range(1,W):
        if ans[h][w] == 0:
            ans[h][w] = ans[h][w-1]

for h in range(H):
    for w in range(W-2,-1,-1):
        if ans[h][w] == 0:
            ans[h][w] = ans[h][w+1]

for h in range(1,H):
    for w in range(W):
        if ans[h][w] == 0:
            ans[h][w] = ans[h-1][w]

for h in range(H-2,-1,-1):
    for w in range(W):
        if ans[h][w] == 0:
            ans[h][w] = ans[h+1][w]

for h in range(H):
    print(*ans[h])


Measured memory_bytes: 52188
h, w = map(int, input().split())
n = int(input())
list_a = list(map(int, input().split()))
result = []

row = []
for i in range(n):
  temp_a = list_a[i]
  for _ in range(temp_a):
    row.append(i+1)
    if len(row) == w:
      if len(result) % 2 != 0:
        row = row[::-1]
      result.append(row)
      row = []

for one_row in result:
  temp_str = ""
  for one_num in one_row:
    temp_str += str(one_num) + " "
  print(temp_str[:-1])

Measured memory_bytes: 3572
#include <stdio.h>

int main()
{
	int a[10];
	int b, c, tmp;
	for(b=0;b<10;b++) {
		scanf("%d", &a[b]);
	}
	for(b=0;b<=9;b++) {
		for(c=9;c>b;c--) {
			if(a[c]>a[c-1]) {
				tmp = a[c];
				a[c] = a[c-1];
				a[c-1] = tmp;
			}
		}
	}
	for(b=0;b<3;b++) {
		printf("%d\n", a[b]);
	}
	return (0);
}



Measured memory_bytes: 2052
mod=10**9+7
N,K=list(map(int,input().split()))
if (N+K)%3==0 and N*2>=K and K*2>=N:
   A=max(N,K)-min(N,K)
   low=(min(N,K)-A)//3
   all_pt=low*2+A
else:
   print(0)
   exit()
up,down=1,1
for i in range(low):
   up=up*(all_pt-i)%mod
   down=down*(i+1)%mod
base=pow(down,mod-2,mod)
print(up*base%mod)

Measured memory_bytes: 8996
n,m=map(int,input().split())
a=[[] for i in range(n)]
for i in range(m):
    x,y=map(int,input().split())
    a[x-1].append(y-1)
    a[y-1].append(x-1)

import itertools
p=itertools.permutations(range(1,n))
p=list(p)

def check(x,y):
    if y in a[x]:
        return True
    else:
        return False
ans=0
for route in p:
    flag=True
    for i in range(n-1):
        if i==0:
            if check(0,route[i])==True:
                pass
            else:
                flag=False
        else:
            if check(route[i-1],route[i])==True:
                pass
            else:
                flag=False
    if flag==True:
        ans+=1
print(ans)


Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	char X, Y;
	cin >> X >> Y;

	if (X < Y) {
		cout << '<' << endl;
	}
	else if (X > Y) {
		cout << '>' << endl;
	}
	else {
		cout << '=' << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n= sc.nextInt();
    int AC= 0;
    int WA= 0;
    int TLE= 0;
    int RE= 0;
    for(int i = 0; i<n;i++){
      String a= sc.next();
      if(a.equals("AC")){
        AC++;
      }
      if(a.equals("WA")){
        WA++;
      }
      if(a.equals("TLE")){
        TLE++;
      }
      if(a.equals("RE")){
        RE++;
      }
      
    }
    System.out.println("AC x " +AC);
    System.out.println("WA x " +WA);
    System.out.println("TLE x " +TLE);
    System.out.println("RE x " +RE);
  }
}



Measured memory_bytes: 58356
#include <stdio.h>

int main(void)
{
	int sec;
	int h;
	int m;
	int s;

	scanf("%d", &sec);

	if(sec<0 ||  sec>86400)
	{
		return 1;
	}

	s = sec % 60;
	sec /= 60;
	m = sec % 60;
	sec /= 60;
	h = sec % 60;


	printf("%d:%d:%d\n", h, m, s);


	return 0;
}

Measured memory_bytes: 592
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};



//--------------8---------------->> coding space <<-----------------8-------------//
class UnionFind {
private:
	Vec< int > data;
	int num_of_g;
	
public:
	UnionFind(int n) : data(n, -1), num_of_g(n) {}
	
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		
		if (x == y) return 0;
		
		if (data[y] < data[x]) swap(x, y);
		data[x] += data[y]; data[y] = x;
		--num_of_g;
		
		return 1;
	}
	
	bool sameSet(int x, int y) { return root(x) == root(y); }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
	int getNumOfG() { return num_of_g; }
};

int H, W;
string a[111];

int getID(int x, int y) { return y * W + x; }

void yes() { puts("Yes"); exit(0); }
void no() { puts("No"); exit(0); }

void solve() {
	UnionFind uf(H * W);
	for_(y,0,H) for_(x,0,W) {
		if (x < W-x-1) uf.unionSet(getID(x, y), getID(W-x-1, y));
		if (y < H-y-1) uf.unionSet(getID(x, y), getID(x, H-y-1));
	}
	
	map< int, int > grp;
	for_(y,0,H) for_(x,0,W) grp[uf.root(getID(x,y))]++;
	
	Vec< int > nums;
	for (auto p : grp) {
		nums.push_back(p.second);
		//cerr << p.first << " " << p.second << endl;
	}
	sort(allof(nums), greater< int >());
	
	map< char, int > crp;
	for_(y,0,H) for_(x,0,W) crp[a[y][x]]++;
	
	priority_queue< int > que;
	for (auto p : crp) que.push(p.second);
	
	for (int x : nums) {
		if (que.top() < x) no();
		int v = que.top(); que.pop();
		if (v-x > 0) que.push(v-x);
	}
	
	if (que.empty()) yes();
	no();
}

int main() {
	cin >> H >> W;
	for_(y,0,H) cin >> a[y];
	solve();
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
    
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    int n;
    cin >> n;
    int v[n], a[n];
    REP(i, n){
        cin >> v[i];
        a[i] = v[i];
    }
    
    int sum = 0;
    sort(a, a+n);
    map<int, int> m;
    REP(i, n){
        m[a[i]] = i%2;
    }
    REP(i, n){
        if(m[v[i]] != i%2){
            sum++;
        }
    }
    
    cout << sum/2 << endl;
}

Measured memory_bytes: 5760
n=int(input())
a=list(map(int, input().split()))

from collections import Counter
c=Counter(a)
avr=sum(a)//n
c[avr]=0
if sum(a)%n!=0:
	c[-(-sum(a)//n)]=0
ans = abs(max(a)-min(a))**n
for key in c:
	res=0
	for aa in a:
		res+=(aa-key)**2
	ans=min(ans,res)
print(ans)

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s;cin>>s;

  ll b=0;
  ll res=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='B'){
      b++;
    }else{
      res += b;
    }
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	int n, m; cin >> n >> m;
	vector<int> a(m);
	rep(i, m) cin >> a[i];
	int sum = 0;
	rep(i, m) sum += a[i];
	int ans = n - sum;
	if (ans >= 0) dunk(ans);
	else dunk(-1);
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, m, ans = 0;
    cin >> n >> m;
    vector<ll> a(n), sum(n);
    rep(i, n){
        cin >> a[i];
        a[i] %= m;
    }
    sum[0] = a[0];
    REP(i, n-1)sum[i] = (sum[i-1] + a[i]) % m;
    map<ll, ll> mp;
    mp[0]++;
    rep(i, n){
        ans += mp[sum[i]];
        mp[sum[i]]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5760
N = int(input())
for h in range(1, 3501):
    for n in range(h, 3501):
        bunbo = 4 * h * n - N * n - N * h
        if bunbo > 0 and N * h * n % bunbo == 0:
            print("{} {} {}".format(h, n, N * h * n // bunbo))
            exit()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);
#define endl "\n"
#define MAXN ((int)2e5+123)
#define MOD ((int)1e9+7)
#define ll long long
#define INF INT_MAX
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define si set<int>
#define pb push_back
#define SZ(v) int(v.size())
#define ms(v,x) memset(v,x,sizeof v)
#define fore(i,m,n) for(int i=m;i<n;i++)
#define forn(i,n) fore(i,0,n)
#define foreach(i,v) for(auto i: v)
#define all(v) v.begin(), v.end()

template<typename T> T gcd(T a, T b) {return b? gcd(b,a%b): a;}
template<typename T> T lcm(T a, T b) {return a*b/gcd(a,b);}


using namespace std;

int n,t,m,a,b;
int cont;
int main(){_
    cin >> n >> m;
    vi v(n+1), good(n+1,1); good[0] = 0;

    fore(i,1,n+1) cin >> v[i];
    while(m--){
       cin >> a >> b; 
       
       if(v[a] == v[b]) good[b] = 0, good[a] = 0;
       else if(v[a] < v[b]) good[a] = 0;
       else good[b] = 0;
    }

    forn(i,n+1) if(good[i]) cont++;
    cout << cont << endl;
    return 0;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, a, b;
    cin >> x >> a >> b;
    int n;
    cin >> n;
    while(n--) {
        string s;
        cin >> s;
        if(s == "nobiro") x += a;
        if(s == "tidime") x += b;
        if(s == "karero") x = 0;
        chmax(x, 0);
    }
    cout << x << endl;
    return 0;
}



Measured memory_bytes: 3224