akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define FOR(i,b,e) for (int i = (b); i <= (e); i++)
#define FORD(i,b,e) for (int i = (b); i >= (e); i--)
#define SIZE(c) ((int) (c).size())

#define pb push_back
#define st first
#define nd second

using namespace std;


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

typedef vector <int> VI;
typedef vector <ll> VL;
typedef vector <bool> VB;
typedef vector <pii> VP;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;

struct Turbo {
    int n, value = 0;

    vector <vector<int>> G;
    vector <int> mate;
    vector <bool> vis;

    Turbo(int n): n(n), G(n), mate(n, -1), vis(n, 0) {}

    void addEdge(int u, int v) {
        G[u].push_back(v);
        G[v].push_back(u);
    }

    bool findPath(int v) {
        if (vis[v]) return false;
        vis[v] = true;

        for (int u : G[v]) if (mate[u] == -1 || findPath(mate[u])) {
            mate[v] = u;
            mate[u] = v;
            return true;
        }

        return false;
    }

    pair <int,vector<int>> runMatching() {
        while (true) {
            bool found = false;
            fill(vis.begin(), vis.end(), false);

            for (int v = 0; v < n; v++) if (mate[v] == -1 && findPath(v)) {
                found = true;
                value++;
            }

            if (!found) break;
        }

        return {value, mate};
    }
};

void makeStepOne(int n, int m, VVI &tab) {
    VVI tabRes(n, VI(m, -1));

    vector <set<int>> inRow(n);
    FOR(i,0,n-1) FOR(j,0,m-1) {
        inRow[i].insert(tab[i][j]);
    }

    FOR(j,0,m-1) {
        Turbo matching(2 * n);

        FOR(i1,0,n-1) for (int val : inRow[i1]) {
            int i2 = (val - 1) / m;
            assert(i2 >= 0 && i2 < n);

            matching.addEdge(i1, n + i2);
        }

        int value; VI mate;
        tie(value, mate) = matching.runMatching();

        assert(value == n);

        FOR(i,0,n-1) {
            auto it = inRow[i].begin();
            while (it != inRow[i].end() && (*it - 1) / m != mate[i] - n) {
                it++;
            }

            assert(it != inRow[i].end());

            tabRes[i][j] = *it;
            inRow[i].erase(it);
        }
    }

    tab = tabRes;
}

void makeStepTwo(int n, int m, VVI &tab) {
    FOR(j,0,m-1) {
        VI values(n);
        FOR(i,0,n-1) {
            values[i] = tab[i][j];
        }

        sort(values.begin(), values.end());

        FOR(i,0,n-1) {
            tab[i][j] = values[i];
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    VVI tab(n, VI(m));
    FOR(i,0,n-1) FOR(j,0,m-1) {
        cin >> tab[i][j];
    }

    makeStepOne(n, m, tab);

    FOR(i,0,n-1) FOR(j,0,m-1) {
        cout << tab[i][j] << " \n"[j == m-1];
    }

    makeStepTwo(n, m, tab);

    FOR(i,0,n-1) FOR(j,0,m-1) {
        cout << tab[i][j] << " \n"[j == m-1];
    }

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    int point[210];
    point[1] = 300000, point[2] = 200000, point[3] = 100000;
    for(int i = 4; i < 206; ++i) point[i] = 0;
    int X, Y;
    cin >> X >> Y;
    int res = point[X] + point[Y];
    if(X == 1 && Y == 1) res += 400000;
    cout << res << endl;
    return 0;
}

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

struct Trump{
	string suit;
	string num;
};

void print(Trump trump[], long N){
    for (long i = 0; i < N; i++){
        cout << trump[i].suit << trump[i].num;
        if (i < N - 1) cout << " ";
    }
    cout << endl;
}

void BubbleSort(Trump trump[], long N){
	for (long i = 0; i < N; i++){
		for (long j = N - 1; j >= i && j > 0; j--){
			if (trump[j].num < trump[j - 1].num){
				swap(trump[j], trump[j - 1]);
			}
		}
	}
}

void SelectionSort(Trump trump[], long N){
	for (long i = 0; i < N; i++){
		long minj;
		minj = i;
		for (long j = i; j < N; j++){
			if (trump[j].num < trump[minj].num){
				minj = j;
			}
		}
		Trump tmp;
		tmp = trump[i];
		trump[i] = trump[minj];
		trump[minj] = tmp;
	}
}

bool isStable(Trump card1[], Trump card2[], long N){
    BubbleSort(card1, N);
    SelectionSort(card2, N);
	for (long i = 0; i < N; i++){
        if (card1[i].num == card2[i].num){
            if (card1[i].suit != card2[i].suit){
                return false;
            }
        }
	}
	return true;
}

int main(){
	long N;
	cin >> N;
    string c;
	Trump card1[36];
	Trump card2[36];
	for (long i = 0; i < N; i++){
		cin >> c;
        card1[i].suit = c[0];
        card1[i].num = c[1];
	}
	for (long i = 0; i < N; i++){
		card2[i] = card1[i];
	}
	BubbleSort(card1, N);
	SelectionSort(card2, N);
    print(card1, N);
	cout << "Stable" << endl;
    print(card2, N);
	if (isStable(card1, card2, N)) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int ans=0;

        if(n>=500)
        {
            int t=n;
            n=n%500;
            ans+=1000*(t-n)/500;
        }
        if(n>=5)
        {
            int t=n;
            n=n%5;
            ans+=5*(t-n)/5;
        }

    cout<<ans<<endl;
}


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

using namespace std;

typedef long long int ll;

const ll MOD = 1000000007;

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

  int M, D;
  cin >> M >> D;

  int ans = 0;
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= D; j++) {
      int d1 = j % 10;
      int d10 = j / 10;
      if (d1 >= 2 && d10 >= 2 && d1 * d10 == i) ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=103;
int k,sum,s1;
char s[N];
int f[N][5][2];
int main() {
	scanf("%s",s);
	int len=strlen(s);
	scanf("%d",&k);
	f[0][0][0]=1;
	f[0][1][0]=s[0]-'1';
	f[0][1][1]=1;
	for(int i=0;i<len;i++)
		for(int j=0;j<=k;j++) {
			f[i+1][j][0]+=f[i][j][0];//i+1  0
			f[i+1][j+1][0]+=f[i][j][0]*9;//i+1  1~9
			if(s[i+1]=='0') f[i+1][j][1]+=f[i][j][1]; //i+1  0
			else {
				f[i+1][j+1][1]+=f[i][j][1];//i+1  s[i+1]
				f[i+1][j+1][0]+=f[i][j][1]*(s[i+1]-'1');
				f[i+1][j][0]+=f[i][j][1];
			}
		}
	printf("%d\n",f[len-1][k][0]+f[len-1][k][1]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>	
#include <stdio.h>	
#include <bits/stdc++.h>	
#include <queue>	
using namespace std;	
#define N 100
	

int r,s,p;

int ope(char x){
    if (x=='r') return p;
    else if (x=='s') return r;
    else if (x=='p') return s;
    else return 0;
}

int main(){
    long n,k;
    
    cin>>n>>k;
    cin>>r>>s>>p;
    char data[n];
    for (int i=0; i<n; i++){
        cin>>data[i];
    }
    long long sum=0;
    for (int i=0; i<=k-1; i++){
        long p=i;
        while (p<=n-1){
            if (p<=k-1) sum+=ope(data[p]);
            else{
                if (data[p]==data[p-k]) data[p]='a';
                else sum+=ope(data[p]);
            }
            p+=k;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
using namespace std;

int main()
{
    int n, a[200], ans=0;
    cin >> n;
    for(int input=1; input<=n; input++){
        cin >> a[input];
        if(a[input]%2!=0 && input%2!=0){
            ans++;
        }
    }
    cout << ans << endl;  
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int a,b,c;
    scanf("%d %d %d",&a, &b, &c);
    
    if (a < b && b < c) {
        printf("Yes\n");
    }else{//else：ほか
        printf("No\n");
    }
    
    return 0;
}



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

int main(int argc, char **argv)
{
	ll n; cin >> n;
	if (n == 1)
		std::cout << "Hello World" << std::endl;
	else
	{
		ll a, b; cin >> a >> b;
		std::cout << a + b<< std::endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,m,cnt,ch[N][2],u[N],v[N],vis[N];
vector<int> vec[N];
queue<int> q;
char s[N];
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d",&u[i],&v[i]);
		ch[u[i]][s[v[i]]-'A']++;
		ch[v[i]][s[u[i]]-'A']++;
		vec[u[i]].push_back(v[i]);
		vec[v[i]].push_back(u[i]);
	} 
    for (int i=1;i<=n;i++) if (!ch[i][0]||!ch[i][1]) q.push(i),vis[i]=1;
    while (!q.empty())
    {
    	int now=q.front();q.pop();
    	for (int i=0;i<vec[now].size();i++)
    	  if (!vis[vec[now][i]])
    	    if (!--ch[vec[now][i]][s[now]-'A']) q.push(vec[now][i]),vis[vec[now][i]]=1;
	}
	for (int i=1;i<=n;i++) cnt+=(!vis[i]);
	puts(cnt?"Yes":"No");
	return 0;
}

Measured memory_bytes: 14720
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll arr[n];
    for(int i=0;i<n;++i)
    {
        cin >> arr[i];
        arr[i] -= (i+1);
    }

    sort(arr, arr + n);
    ll med = arr[n/2];
    ll ans = 0;

    for(int i=0;i<n;++i)
    {
        ans += abs(arr[i] - med);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;

int main(void)
{
	int H, W;
	cin >> H >> W;

	string* str = new string[H];
	for (int i = 0; i < H; ++i) {
		cin >> str[i];
	}

	int* a = new int[W];
	for (int i = 0; i < W + 2; ++i) {
		cout << "#";
	}
	cout << endl;

	for (int i = 0; i < H; ++i) {
		cout << "#" << str[i] << "#" << endl;
	}

	for (int i = 0; i < W + 2; ++i) {
		cout << "#";
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations as comb

A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
b = [int(input()) for _ in range(N)]

bingo = [[8, 1, 6], [3, 5, 7], [4, 9, 2]]
check = []

for i in range(N):
    for j in range(3):
        if b[i] == A1[j]:
            check.append(bingo[0][j])
            break
        elif b[i] == A2[j]:
            check.append(bingo[1][j])
            break
        elif b[i] == A3[j]:
            check.append(bingo[2][j])
            break

flag = False
for i in list(comb(check, 3)):
    if sum(i) == 15:
        flag = True
        break

print("Yes" if flag else "No")

Measured memory_bytes: 3064
#include "bits/stdc++.h"

struct RangeMinimumQuery {
    using type = int;
    static type id() { return INT_MAX; }
    static type op(const type &l, const type &r) { return std::min(l, r); }
};

struct RangeMaximumQuery {
    using type = int;
    static type id() { return -INT_MAX; }
    static type op(const type &l, const type &r) { return std::max(l, r); }
};

struct RangeSumQuery {
    using type = int;
    static type id() { return 0; }
    static type op(const type &l, const type &r) { return l + r; }
};

template <typename M>
class SegmentTree
{
    using T = typename M::type;
    int n;
    std::vector<T> node;

public:
    // v を基に初期化
    SegmentTree(const std::vector<T> &v)
    {
        // n は v.size() 以上の最小の2冪
        n = 1;
        while (n < int(v.size()))
            n *= 2;
        node.resize(2 * n, M::id());

        // i の子 -> 2*i+1, 2*i+2 , 親 -> (i-1)/2
        for (int i = 0; i < int(v.size()); i++)
            node[i + n] = v[i];
        for (int i = n - 1; i >= 0; i--)
            node[i] = M::op(node[2 * i], node[2 * i + 1]);
    }
    // Monoid::id 初期化
    SegmentTree(int _n)
    {
        n = 1;
        while (n < _n)
            n *= 2;
        node.resize(2 * n, M::id());
    }
    // x 番目を val に更新
    void update(int x, T val)
    {
        x += n;
        node[x] = val;
        while (x >>= 1)
        {
            node[x] = M::op(node[2 * x], node[2 * x + 1]);
        }
    }
    // v[x] を M::op(v[x], val) に更新
    void operation(int x, T val)
    {
        x += n;
        node[x] = M::op(node[x], val);
        while (x >>= 1)
        {
            node[x] = M::op(node[2 * x], node[2 * x + 1]);
        }
    }
    // [a, b) の op
    T query(int l, int r)
    {
        l += n;
        r += n;
        T retl = M::id(), retr = M::id();
        while (l < r)
        {
            if (l & 1)
                retl = M::op(retl, node[l++]);
            if (r & 1)
                retr = M::op(node[--r], retr);
            l >>= 1;
            r >>= 1;
        }
        return M::op(retl, retr);
    }
};

using namespace std;

void solve_dsl_2_a()
{ // range min
    int n, q;
    cin >> n >> q;
    SegmentTree<RangeMinimumQuery> st(n);
    while (q--)
    {
        int type;
        cin >> type;
        if (type == 0)
        {
            int index, x;
            cin >> index >> x;
            st.update(index, x);
        }
        else
        {
            int s, t;
            cin >> s >> t;
            t++;
            cout << st.query(s, t) << endl;
            ;
        }
    }
}

void solve_dsl_2_b()
{ // range sum
    int n, q;
    cin >> n >> q;
    SegmentTree<RangeSumQuery> st(n);
    while (q--)
    {
        int type;
        cin >> type;
        if (type == 0)
        {
            int index, x;
            cin >> index >> x;
            index--;
            st.operation(index, x);
        }
        else
        {
            int s, t;
            cin >> s >> t;
            s--;
            cout << st.query(s, t) << endl;
            ;
        }
    }
}

int main()
{
    solve_dsl_2_a();
}



Measured memory_bytes: 3896
(function(input) {
    inputs = input.split(' ').map(Number);
    var r = inputs[0];
    var a = (r * r * Math.PI).toFixed(5);
    var c = (2 * r * Math.PI).toFixed(5);
    console.log('%d %d', a, c);
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7648
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

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; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	FOR(i,1,N + 1) {
		int res = 0;
		for (int x = 1; x * x <= N; ++x) {
			for (int y = 1; y * y <= N; ++y) {
				int a = 1;
				int b = x + y;
				int c = x * x + y * y + x * y - i;
				if (b * b - 4 * a * c < 0) continue;
				double z1 = (-b + sqrt(b * b - 4 * a * c)) / 2 * a;
				double z2 = (-b - sqrt(b * b - 4 * a * c)) / 2 * a;
				if (floor(z1) == z1 && z1 >= 1) {
					++res;
				}
				if (floor(z2) == z2 && z2 >= 1) {
					++res;
				}
			}
		}
		cout << res << endl;
	}
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 3604
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define all(v) (v).begin(),v.end()
#define fi first
#define se second
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
map<char,int> mp;
int main(){
int n,m;
cin>>n>>m;
vector<bool> a(n,false);
a[0]=true;
vector<int> x(m),y(m);
for(int i=0;i<m;i++){cin>>x[i]>>y[i];x[i]--;y[i]--;}
vector<int> box(n,1);
for(int i=0;i<m;i++){
 box[x[i]]--;
 box[y[i]]++;
 if(a[x[i]])a[y[i]]=true;
 if(box[x[i]]==0)a[x[i]]=false;
}
int ans=0;
for(int i=0;i<n;i++)if(a[i])ans++;
cout<<ans<<endl;
}


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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n{0};
    cin>>n;

    ll arr[n];
    for(ll i=0;i<n;i++)
    	cin>>arr[i];

    ll money=1000;
    ll start{0};   //represents starting-index(first index) of the increasing subarrays  
    
    for(ll i=0;i<n-1;i++){
    	if(arr[i+1]>arr[i]){
        	continue;
    	}
        else{
            ll stocks=money/arr[start];
            money=(money%arr[start])+(stocks*arr[i]);
            start=i+1;
        }
    }
    if(start!=n-1){
        ll stocks=money/arr[start];
        money=(money%arr[start])+(stocks*arr[n-1]);
    }

    cout<<money<<endl;

	return 0;
}



Measured memory_bytes: 3624
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n) cin>>a[i];
  int sum=0;
  int i=0;
  int j=0;
  while(i<n-1){
    j=0;
    while(j+i+1<=n-1){
      sum+=a[i]*a[j+i+1];
      j++;
    }
    i++;
  }
  cout<<sum<<endl;
}


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int k = sc.NextInt();
        int[] a = sc.IntArray();

        int answer = 0;
        n -= 1;
        while (true)
        {
            n -= k - 1;
            answer++;
            if (n <= 0)
            {
                break;
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 18016
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int a, b, k;
    cin >> a >> b >> k;
    int g = __gcd(a, b);
    vector<int> ans;
    forn(i, 1, g+1) {
        if (g%i == 0) {
            ans.pb(i);
        }
    }
    cout << ans[SZ(ans)-k] << endl;
}


Measured memory_bytes: 3656
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <typename T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int H, W, N;
    cin >> H >> W >> N;
    vector<int> A(N);
    cin >> A;

    vector<vector<int>> ans(H, vector<int>(W));
    int cnt = 0;
    int i = 0;
    REP(h, H) {
        REP(w, W) {
            ans[h][w] = (i + 1);
            cnt++;
            if (cnt == A[i]) {
                cnt = 0;
                i++;
            }
        }
    }

    REP(h, H) {
        if (h % 2 == 1) { reverse(ALL(ans[h])); }
    }

    REP(h, H) {
        REP(w, W - 1) {
            cout << ans[h][w] << " ";
        }
        cout << ans[h][W - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int c;
	char a[3];
	char b[3];
	char str[9];
scanf("%s",a);
scanf("%s",b);
sprintf(str,"%s%s",a,b);
int d=atoi(str);
c=sqrt(d);
if(c*c==d){
	printf("Yes");
}else{
	printf("No");
}
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
  int a;
  cin >> a;
  vector<int>b(a);
  vector<int>c(a);
  int d = 0;
  int e = 0;
  rep(i,a){
    cin >> b[i];
  }
  rep(i,a){
    cin >> c[i];
  }
  rep(i,a){
    if(b[i]-c[i]>0){
      d+=b[i];
      e+=c[i];
    }
  }
  cout << d-e << endl;
 return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "bitset"

using namespace std;

//const long long int MOD = 998244353;
const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

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

	cin >> N;
	vector<int>v(N);
	vector<int>w(N);
	int box = 0;
	for (auto &i : v) {
		cin >> i;
		box ^= i;
	}
	v.push_back(box);
	box = 0;
	for (auto &i : w) {
		cin >> i;
		box ^= i;
	}
	w.push_back(box);
	if (v == w) {
		cout << 0 << endl;
		return 0;
	}
	auto vv = v;
	auto ww = w;
	sort(vv.begin(), vv.end());
	sort(ww.begin(), ww.end());
	if (vv != ww) {
		cout << -1 << endl;
		return 0;
	}
	vv.erase(unique(vv.begin(), vv.end()), vv.end());
	map<int, int>ms;
	for (int i = 0; i < vv.size(); i++)ms[vv[i]] = i;
	UnionFind uf(vv.size());
	vector<int>flag(vv.size());
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (v[i] != w[i]) {
			ans++;
			uf.Unite(ms[v[i]], ms[w[i]]);
			flag[ms[v[i]]] = 1;
			flag[ms[w[i]]] = 1;
		}
	}
	set<int>s;
	for (int i = 0; i < vv.size(); i++) {
		if(flag[i])s.insert(uf.Find(i));
	}
	ans += s.size();
	for (int i = 0; i < N; i++) {
		if (v.back() == w[i]&&w[i]!=v[i]) {
			ans--;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10096
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int array[] = new int[5];
        for(int i = 0;i<5;i++){
            array[i] = sc.nextInt();
        }
        int k = sc.nextInt();

        Arrays.sort(array);

        if((array[4]-array[0])<=k){
            System.out.println("Yay!");
        }else{
            System.out.println(":(");
        }
    }

}


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

int main(){
  int n, sum = 0, tmp = -99;
  cin >> n;
  int a[n];
  int b[n];
  int c[n-1];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  for(int i=0; i<n; i++){
    cin >> b[i];
  }
  for(int i=0; i<n-1; i++){
    cin >> c[i];
  }
  for(int i=0;i<n;i++){
    if(tmp + 1 == a[i]){
      sum += c[tmp-1];
    }
    sum += b[a[i]-1];
    tmp = a[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
dict = {}
ans = 0

for i in range(n):
  if a[i] not in dict:
    dict[a[i]] = 1
  else:
    dict[a[i]] += 1

l = sorted(dict.items())
l += [(-1,0),(-2,0)]

for j in range(len(l)-2):
  if l[j][0]+1 == l[j+1][0] and l[j][0]+2 == l[j+2][0]:
     ans = max(ans,l[j][1]+l[j+1][1]+l[j+2][1])
  elif l[j][0]+1 == l[j+1][0] and l[j][0]+2 != l[j+2][0]:
     ans = max(ans,l[j][1]+l[j+1][1])
  elif l[j][0]+1 != l[j+1][0] and l[j][0]+2 != l[j+2][0]:
     ans = max(ans,l[j][1])
   
  
print(ans)
  

Measured memory_bytes: 14836
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<stack>
#include<queue>

typedef long long i64;

using namespace std;

int main(){
    int N,K;
    cin>>N>>K;
    K--;
    int one = 1e9;
    int left = 0;
    int right = 0;
    vector<int> vec(N);
    for(int i=0;i<N;i++){
        cin>>vec[i];
        if(vec[i] == 1) one = i;
        if(one == 1e9) left++; 
        else right++;
    }
    right--;

    int ans = (left / K) + (right / K);
    if(left % K) ans++;
    if(right % K) ans++;

    int m = left % K;
    int k = K;

    left -= m;
    k -= m;
    right -=k;


    int ans2 = (left / K) + (right / K);
    if(left % K) ans2++;
    if(right % K) ans2++;
    ans2++;

    ans = min(ans,ans2);

    cout<<ans<<endl;

}

Measured memory_bytes: 640
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var s = (((tmp[0]-0)*(tmp[1]-0)) % 2)==0?"Even":"Odd";
	//出力
	console.log('%s',s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29488
#include <bits/stdc++.h>
#define ll long long
#define mk make_pair
#define hash hashh
using namespace std;

const int N = 3e5;
const int inf = 1e9;

int n, ans, a, b, h[N];

bool check(int x) {
	ll t = 0;
	for (int i = 1; i <= n; i++) {
		if ((ll)b * x >= h[i]) continue;
		t += (h[i] - (ll)b * x + (a - b - 1)) / (a - b);
		if (t > x) return 0;
	}
	if (t > x) return 0;
	return 1;
}

int main() {
	scanf("%d %d %d", &n, &a, &b);
	for (int i = 1; i <= n; i++) scanf("%d", h + i);
	int l = 1, r = 1e9;
	while (l < r) {
		int mid = l + r >> 1;
		if (check(mid)) r = mid;
		else l = mid;
		if (l + 1 == r) {
			if (check(l)) r--;
			else l++;
		}
	}
	cout << l;
} 

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

using namespace std;

int main(int argc, char const *argv[])
{
    vector<int> ns;
    int n = 0, count = 0;

    cin >> n;

    while(n--) {
        int t = 0;
        cin >> t;
        ns.push_back(t);
    }

    for (int i = 1; i < ns.size()-1; i++) {
        if (ns[i] < ns[i+1] && ns[i] > ns[i-1] || ns[i] > ns[i+1] && ns[i] < ns[i-1])
            count++;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

const string YES = "Yes";
const string NO = "No";

void solve(vector<vector<long long>> A, long long N, vector<long long> b) {
    string ans = NO;
    bool card[3][3] = {false};

    for (int i = 0; i < N; i++) {
        for (int ai = 0; ai < 3; ai++) {
            for (int aj = 0; aj < 3; aj++) {
                if (A[ai][aj] == b[i]) {
                    card[ai][aj] = true;
                }
            }
        }
    }

    // bingo check, row
    for (int i = 0; i < 3; i++) {
        bool is_bingo = card[i][0] && card[i][1] && card[i][2];
        if (is_bingo) ans = YES;
    }

    // bingo check, column
    for (int i = 0; i < 3; i++) {
        bool is_bingo = card[0][i] && card[1][i] && card[2][i];
        if (is_bingo) ans = YES;
    }

    // bingo check, left cross
    if (card[0][0] && card[1][1] && card[2][2]) ans = YES;

    // bingo check, right cross
    if (card[0][2] && card[1][1] && card[2][0]) ans = YES;

    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  vector<vector<long long>> A(3, vector<long long>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A[i][j];
    }
  }
  long long N;
  cin >> N;
  vector<long long> b(N);
  for (int i = 0; i < N; i++) {
    cin >> b[i];
  }
  solve(move(A), N, move(b));
  return 0;
}


Measured memory_bytes: 3632
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,a[20005],b[20005],p[20005];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",p+i),a[p[i]]=p[i]*(n+1)+i,b[i]=(n+1-i)*(n+1);
    for(int i=1;i<n;++i)printf("%d ",a[i]);
    printf("%d\n",a[n]);
    for(int i=1;i<n;++i)printf("%d ",b[i]);
    printf("%d\n",b[n]);
    //system("pause");
    return 0;
}


Measured memory_bytes: 896
import numpy as np
S = str(input())
moji1 = "0"
moji2 = "1"
while len(moji1) < len(S):
    if moji1[-1] == "0":
        moji1 += "1"
        moji2 += "0"
    else:
        moji1 += "0"
        moji2 += "1"

Sarr = np.array([int(i) for i in S])
arr1 = np.array(([int(i) for i in moji1]))
arr2 = np.array(([int(i) for i in moji2]))
S1 = np.count_nonzero(Sarr - arr1 != 0)
S2 = np.count_nonzero(Sarr - arr2 != 0)
print(min(S1, S2))

Measured memory_bytes: 16096
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int W = sc.nextInt();
        int[] v = new int[n];
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }
        long[][] dp = new long[n + 1][W + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= W; j++) {
                dp[i + 1][j] = dp[i][j];
                if (j - w[i] >= 0) {
                    dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
                }
            }
        }
        // System.out.println(Arrays.deepToString(dp));
        System.out.println(dp[n][W]);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}



Measured memory_bytes: 32884
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int a[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
			if (a[i] % 2 == 1) {
				System.out.println(0);
				return;
			}
		}

		int cnt = 0;
		out_of_loop: while (true) {
			for (int i = 0; i < n; i++) {
				if (a[i] % 2 == 0) {
					a[i] = a[i] / 2;
				} else {
					break out_of_loop;
				}
			}
			cnt++;
		}

		System.out.println(cnt);
	}
}


Measured memory_bytes: 21204
#include <iostream>

using namespace std;

int main() {
    int n;
    int a, b, c;

    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> a >> b >> c;
        a *= a;
        b *= b;
        c *= c;

        if (a + b == c | b + c == a | c + a == b) cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 3084
#include <stdio.h>

int main(void) {
  int toSort[3];
  scanf(" %d %d %d", toSort, toSort + 1, toSort + 2);
  if (toSort[0] > toSort[2]) {
    int holder = toSort[2];
    toSort[2] = toSort[0];
    toSort[0] = holder;
  }
  if (toSort[0] > toSort[1]) {
    int holder = toSort[1];
    toSort[1] = toSort[0];
    toSort[0] = holder;
  }
  if (toSort[1] > toSort[2]) {
    int holder = toSort[2];
    toSort[2] = toSort[1];
    toSort[1] = holder;
  }
  printf("%d %d %d\n", toSort[0], toSort[1], toSort[2]);
}



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

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main() {
  int N, M; cin >> N >> M;
  vector<vector<int>> tree(N, vector<int> (0));
  for(int i = 0; i < M; i++) {
    int a, b; cin >> a >> b; a--; b--;
    tree.at(a).push_back(b);
    tree.at(b).push_back(a);
  }
  vector<int> dp(N, 1000000), mark(N);
  dp[0] = 0;
  queue<int> que;
  que.push(0);
  while(!que.empty()) {
    int p = que.front();
    que.pop();
    for(int i = 0; i < tree.at(p).size(); i++) {
      int t = tree.at(p).at(i);
      if(chmin(dp[t], dp[p] + 1)) {
        que.push(t);
        mark.at(t) = p + 1;
      }
    }
  }
  cout << "Yes" << endl;
  for(int i = 1; i < N; i++) {
    cout << mark.at(i) << endl;
  }
}

Measured memory_bytes: 10572
unittest
{
	assert( [ "3 1 4" ].parse.expand.solve == 5 );
	assert( [ "5 2 9" ].parse.expand.solve == 10 );
	assert( [ "8 8 1" ].parse.expand.solve == 9 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abc = input.front.split.to!( long[] );
	return tuple( abc[ 0 ], abc[ 1 ], abc[ 2 ] );
}

auto solve( long a, long b, long c )
{
	// 毒クッキーと解毒クッキーを交互に食べる
	if( c - 1 <= b + a ) return c + b;							// 毒クッキーを食べきれるパターン
	else                 return c + b - ( c - 1 - b - a );		// 毒クッキーを食べきれないパターン
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(i, n) for(int i = n-1; i >= (int)0; i--)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int n;
    std::cin >> n;
    std::vector<ll> a(n);
    std::vector<ll> b(n);
    
    rep(i,n)std::cin >> a[i];
    rep(i,n)std::cin >> b[i];
    std::vector<bool> cona(n,0),conb(n,0),con(n,0);
    std::vector<ll> h(n);
    
    cona[0]=1;
    rep(i,n-1){
        if(a[i+1]!=a[i])cona[i+1]=1;
    }
    conb[n-1]=1;
    irep(i,n-1){
        if(b[i+1]!=b[i])conb[i]=1;
    }
    bool han=0;
    rep(i,n){
        
        if(cona[i]&&conb[i]&&a[i]!=b[i])han=1;
        if(cona[i]&&a[i]>b[i])han=1;
        if(conb[i]&&a[i]<b[i])han=1;
    }
    if(han){
        std::cout << 0 << std::endl;
        exit(0);
    }
    rep(i,n)if(conb[i]||cona[i])con[i]=1;
    ll ans=1ll;
    rep(i,n){
        if(!con[i]){
         //   std::cout << i << std::endl;
            ans*=min(a[i],b[i]);
            ans%=MOD;
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 2688
fun main() = Thread(null, ::abc171b, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc171b() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val pList = readLine()!!.split(' ').map { it.toInt() }

    val answer = pList.sorted().take(k).sum()

    println(answer)
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int n;
  cin >> n;
  vi a(n);
  int sum = 0;
  rep (i, n) {
    cin >> a[i];
    sum += a[i];
  }
  int mi = inf;
  int ans = -1;
  rep (i, n) {
    if (mi > abs(sum - n*a[i])) {
      ans = i;
      mi = abs(sum - n*a[i]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>
#include <typeinfo>
#include <memory>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define fs first
#define sc second


int main(){
    ll N, X;
    ll b[110000], l[110000], r[110000];
    vector<P> p;

    cin >> N >> X;
    ll su = 0;
    for(int i = 0; i < N; i++){
        cin >> b[i] >> l[i] >> r[i];
        p.emplace_back(P(r[i] * (X - b[i]) + l[i] * b[i], i));
        su += r[i] * (X - b[i]);
    }

    sort(p.begin(), p.end());
    ll sb[110000];
    sb[0] = su;
    for(int i = 1; i <= N; i++){
        sb[i] = sb[i-1] - p[i-1].fs;
    }

    ll sl = -1, sr = N * X;

    while(sr - sl > 1){
        ll m = (sl + sr) / 2;
        ll x = m % X;
        ll y = m / X;

        ll res = -1;
        if(x == 0){
            res = sb[N-y];
        }
        else{
            for (int i = 0; i < N; i++) {
                ll res_tmp = sb[N - y];
                ll index = p[i].sc;
                if(x > b[index]){
                    res_tmp += (x - b[index]) * r[index] + b[index] * l[index];
                }
                else{
                    res_tmp += x * l[index];
                }

                if(i >= N - y){
                    res_tmp -= p[i].fs;
                    res_tmp += p[N-y-1].fs;
                }
                res = max(res_tmp, res);
            }
        }
        if(res < 0){
            sl = m;
        }
        else{
            sr = m;
        }
    }

    cout << sr << endl;

    return 0;
}


Measured memory_bytes: 5492
from collections import defaultdict
import sys
import time

sys.setrecursionlimit(2000)
N, M, K = [int(i) for i in input().split(" ")]

t = time.time()
class UnionNode():
    def __init__(self, number):
        self.number = number
        self.volume = 1
        self.master = None

    @property
    def root(self):
        if self.master:
            self.master = self.master.root
            return self.master
        else:
            return self

    def unite(self, target):
        seroot = self.root
        taroot = target.root
        if seroot.number == taroot.number:
            pass
        else:
            #print(f"unite {target.rootnum}({target.root.volume}), {self.rootnum}({self.root.volume})")
            if seroot.volume > taroot.volume:
                seroot.volume += taroot.volume
                taroot.master = seroot
            else:
                taroot.volume += seroot.volume
                seroot.master = taroot

nodes = [UnionNode(i) for i in range(N)]

outlist = defaultdict(lambda :[])

for i in range(M):
    s = input()
    a, b = s.split(" ")
    a = int(a) - 1
    b = int(b) - 1
    nodes[a].unite(nodes[b])
    outlist[a].append(b)
    outlist[b].append(a)

for i in range(K):
    s = input()
    a, b = s.split(" ")
    a = int(a) - 1
    b = int(b) - 1
    outlist[a].append(b)
    outlist[b].append(a)

result = []
for i in range(N):
    rootnode = nodes[i].root
    ret = rootnode.volume - 1
    for out in outlist[i]:
        if nodes[out].root.number == rootnode.number:
            ret -=1
    result.append(ret)

#for i in range(100):
#    print(result[i])

print(" ".join([str(i) for i in result]))

#print(time.time() - t)

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

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

Measured memory_bytes: 256