akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define MAX  2147483647
#define fi first
#define se second
#define mid (l+r>>1)
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define fodown(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
int n,m;
pair<int,int> num[200001];
struct node{
	int x,y;
}a[100001];
int read()
{
   int x=0,tmp=1;
   char ch=getchar();
   while(ch<'0' || ch>'9' ) { if(ch=='-') tmp=-1;ch=getchar();}
   while(ch>='0'&& ch<='9') { x = x * 10+ ch-'0';ch=getchar();}
   return x*tmp;
}
int cmp(node a,node b)
{
    return a.x<b.x;
}
int main()
{
  // freopen(" .in","r",stdin);
  // freopen(" .out","w",stdout);
  n=read();
  m=read();
  fo(i,1,m)
  {
  	 a[i].x=read();
  	 a[i].y=read();
  }
  sort(a+1,a+m+1,cmp);
  fo(i,1,n)
  num[i].fi=i,num[i].se=i;
  int y;
  for(int i=1;i<=m;i++){
  	    y= a[i].y;
        num[y].fi = num[y+1].fi = min(num[y].fi, num[y+1].fi);
        num[y].se = num[y+1].se = max(num[y].se, num[y+1].se);
  }
  fo(i,1,n-1)
  {
    printf("%d ",num[i].se-num[i].fi+1);	
  }
  cout<<num[n].se-num[n].fi+1<<endl;
   return 0;
}

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

const ll mod=1E9+7;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,m;
	cin>>n>>m;
	vector<ll> x,y;
	ll prevv;
	for(int i=0;i<n;++i){
		ll t;
		cin>>t;
		if(i) x.push_back(t-prevv);
		prevv=t;
	}
	for(int i=0;i<m;++i){
		ll t;
		cin>>t;
		if(i) y.push_back(t-prevv);
		prevv=t;
	}
	ll sumx=0,sumy=0;
	for(int i=0;i<n-1;++i){
		(x[i]=(i?x[i-1]:0)+(i+1LL)*x[i])%=mod;
		(sumx+=x[i])%=mod;
	}
	for(int i=0;i<m-1;++i){
		(y[i]=(i?y[i-1]:0)+(i+1LL)*y[i])%=mod;
		(sumy+=y[i])%=mod;
	}
	ll res=sumx*sumy%mod;
	cout<<res<<'\n';
}




Measured memory_bytes: 5556
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int A,B;R(A,B);
    if(A>=10||B>=10)W(-1);
    else W(A*B);
    return 0;
}


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

using namespace std;

# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;

# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n, a, b;
	cin >> n >> a >> b;

	if (a > b || (n == 1 && a != b))
		kill(0);
	cout << ((n - 1) * b + a) - ((n - 1) * a + b) + 1 << endl;

	return 0;
}


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

ll sub(ll a){
  if (a % 4 == 0) return a;
  else if (a % 4 == 1) return (a-1) ^ a;
  else if (a % 4 == 2) return (a-2) ^ (a-1) ^ a;
  else if (a % 4 == 3) return 0ll;
}

int main(){
  ll a, b; cin >> a >> b;
  cout << ( sub(max(0ll,--a)) ^ sub(b) ) << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a=0,c=0;
    int X,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;
    long long p[A],q[B],r[C],SUM;
    vector<int> ans;
    for(int i=0; i<A; i++){
        cin >> p[i];
    }
    for(int i=0; i<B; i++){
        cin >> q[i];
    }
    for(int i=0; i<C; i++){
        cin >> r[i];
    }
    sort(p,p+A,greater<>());
    sort(q,q+B,greater<>());
    sort(r,r+C,greater<>());
    for(int i=0; i<X; i++){
        ans.push_back(p[i]);
    }
    for(int i=0; i<Y; i++){
        ans.push_back(q[i]);
    }
    sort(ans.begin(),ans.end());
    while(1){
        if(a==X+Y || c==C) break;
        if(ans.at(a)<r[c]){
            ans.at(a)=r[c];
            a++;
            c++;
        }else{
            break;
        }
    }
    for(int i=0; i<X+Y; i++){
        SUM+=ans.at(i);
    }
    cout << SUM;
    return 0;
}

Measured memory_bytes: 3704
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

ll dp[100010][4];

int main() {
	string s;
	cin >> s;

	// 初期状態
	REP(i, 4) dp[0][i] = 0;
	dp[0][0] = 1;

	REP(i, s.size()) 
	{
		// 状態変化なし
		if (s[i] != '?') {
			REP(j, 4) dp[i + 1][j] = dp[i][j];
		}
		else {
			REP(j, 4) dp[i + 1][j] = 3*dp[i][j];
		}

		// 状態変化あり
		if (s[i] == 'A' || s[i] == '?') {
			dp[i + 1][1] += dp[i][0];
		}
		if (s[i] == 'B' || s[i] == '?') {
			dp[i + 1][2] += dp[i][1];
		}
		if (s[i] == 'C' || s[i] == '?') {
			dp[i + 1][3] += dp[i][2];
		}

		REP(j, 4) dp[i + 1][j] %= mod;
	}
	cout << dp[s.size()][3];
	system("pause");
	return 0;
}

Measured memory_bytes: 3832
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;


int main(){
	string s,t;
	cin>>s>>t;
	int a,b;
	cin>>a>>b;
	string u;
	cin>>u;
	if(s==u) cout<<a-1<<" "<<b;
	else if(u==t) cout<<a<<" "<<b-1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=2e3+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int n,k;
vector<int> e[MAXn];
int dep[MAXn];
void dfs(int x,int p,int d = 0){
    dep[x] = d;
    for (auto i:e[x]) {
        if (i == p) continue;
        dfs(i,x,d+1);
    }
}
int main(){
    IOS();
    cin >> n >> k;
    REP (i,n-1) {
        int u,v;
        cin >> u >> v;
        u--, v--;
        e[u].eb(v);
        e[v].eb(u);
    }

    int ans = n;
    if (k & 1) {
        REP (i,n) for (auto it:e[i]) {
            dfs(i,it), dfs(it,i);
            int cnt = 0;
            REP (j,n) if (dep[j] > (k-1)/2) cnt++;
            ans = min(ans,cnt);
        }
    }
    else {
        REP (i,n) {
            dfs(i,i);
            int cnt = 0;
            REP (j,n) if (dep[j] > k/2) cnt++;
            ans = min(ans,cnt);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3760
#include<cstdio>
int main(){
char a[1001];
int i,sum;
while(1){
    sum = 0;
scanf("%s",a);
if(a[0] == '0'){
    break;
}
for(i = 0;a[i] != '\0';i++){
    sum = sum + a[i] - '0';
}
printf("%d\n",sum);
}
return 0;
}


Measured memory_bytes: 2684
//01
#include<iostream>
#include<numeric>

using namespace std;

int main(){
  int N;
  cin>>N;
  int a[200][3];
  for(int i=0;i<N;i++){
    cin>>a[i][0]>>a[i][1]>>a[i][2];
  }
  for(int i=0;i<N;i++){
    int s=0;
    for(int j=0;j<3;j++){
      int k;
      for(k=0;k<N;k++){
	if(i==k)continue;
	if(a[i][j]==a[k][j])break;
      }
      if(k==N){
	s+=a[i][j];
      }
    }
    cout<<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		char s[] = sc.next().toCharArray();
		System.out.println(s[0] + "" + (s.length - 2) + "" + s[s.length - 1]);
	}
}


Measured memory_bytes: 22612
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <bitset>
#include <vector>
using namespace std;
int f(int n,int number) {
	if (number == 4)return(n + 3);
	if (number % 2==0)f(n + 1, number/2);
	else f(n + 1, number * 3 + 1);
}
int main()	
{
	int N,T;
	cin >>N>>T;
	int cost = 1001;
	int c, t;

	for (int i = 0; i < N; i++) {
		cin >> c; cin >> t;
		if (t <= T )cost=min(c,cost);
	}
	cost == 1001 ? cout << "TLE" << endl: cout <<cost<< endl;
}


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

#define int long long
int N, M;

signed main() {
  cin >> N >> M;
  int s = min(N, M/2);
  N -= s;
  M -= 2*s;
  if (N == 0 && M > 0) {
    s += M/4;
  }
  cout << s << "\n";
  return 0;
}


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

int dp[110][4][2];
signed main()
{
    string s;cin >> s;
    int K;
    cin >> K;
    int n = s.size();
    dp[0][0][0] = 1;
    rep(i,n)rep(j,4)rep(k,2){
        int d = s[i] - '0';
        rep(a,10){
            int ni = i+1,nj = j,nk = k;
            if(k == 0&& d < a)continue;
            if(j == 3 && a !=0)continue;
            if(j < 3 && a!=0)nj++;
            if(a < d)nk = 1;
            dp[ni][nj][nk] += dp[i][j][k];

            
        }

        
    }
    cout << dp[n][K][0] + dp[n][K][1] << endl;


    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	line := nextLine()

	cols := strings.Split(line, " ")

	nums := []int{}

	for _, s := range cols {
		n, _ := strconv.Atoi(s)
		nums = append(nums, n)
	}

	one := nums[0] * nums[1]
	two := nums[2]

	if one > two {
		fmt.Println(two)
	} else {
		fmt.Println(one)
	}

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,d;
    cin >> n >> d;
    double x[n][d];
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin >> x[i][j];
        }
    }
    int count=0;
    double tmp;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
        {
            tmp=0;
            if(i!=j){
                for(int k=0;k<d;k++){
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                }
                if(ceil(sqrt(tmp) == floor(sqrt(tmp))))count++;
            }
        }
    }
    cout << count/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    string ans = "ABC";
    if (n>999) ans = "ABD";
    
    

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


Measured memory_bytes: 256
class Dice:
    def __init__(self, one: int, two: int, three: int, four: int, five: int, six: int) -> None:
        self.__one = one
        self.__two = two
        self.__three = three
        self.__four = four
        self.__five = five
        self.__six = six

    def roll(self, direction) -> None:
        if direction == "N":
            tmp = self.__one
            self.__one = self.__two
            self.__two = self.__six
            self.__six = self.__five
            self.__five = tmp

        if direction == "E":
            tmp = self.__one
            self.__one = self.__four
            self.__four = self.__six
            self.__six = self.__three
            self.__three = tmp

        if direction == "S":
            tmp = self.__one
            self.__one = self.__five
            self.__five = self.__six
            self.__six = self.__two
            self.__two = tmp

        if direction == "W":
            tmp = self.__one
            self.__one = self.__three
            self.__three = self.__six
            self.__six = self.__four
            self.__four = tmp

    def set_top(self, top: int) -> None:
        if dice.top != top:
            for i in range(3):
                dice.roll("N")
                if (dice.top == top):
                    break
        if dice.top != top:
            for i in range(3):
                dice.roll("E")
                if (dice.top == top):
                    break

    def rotate(self) -> None:
        tmp = self.__two
        self.__two = self.__four
        self.__four = self.__five
        self.__five = self.__three
        self.__three = tmp

    @property
    def top(self) -> int:
        return self.__one

    @property
    def front(self) -> int:
        return self.__two

    @property
    def right(self) -> int:
        return self.__three


if __name__ == "__main__":
    one, two, three, four, five, six = map(int, input().split(' '))
    dice = Dice(one, two, three, four, five, six)
    q = int(input())
    for i in range(q):
        top, front = map(int, input().split(' '))
        dice.set_top(top)
        while dice.front != front:
            dice.rotate()
        print(dice.right)



Measured memory_bytes: 5608
n=int(input())
v=list(map(int,input().split()))
vodd=[v[i] for i in range(n) if i%2==1]
veven=[v[i] for i in range(n) if i%2==0]
vodd.sort()
veven.sort()
def matome(l):
    result=[]
    a=l[0]
    b=0
    for i in range(len(l)):
        if l[i]==a:
            b+=1
        else:
            result.append([a,b])
            b=1
            a=l[i]
    result.append([a,b])
    return result
odd=matome(vodd)
odd.sort(key=lambda x:-x[1])
even=matome(veven)
even.sort(key=lambda x:-x[1])

if len(odd)==1 and len(even)==1:
    if odd[0][0]==even[0][0]:
        print(n//2)
    else:
        print(0)
elif len(odd)==1:
    if odd[0][0]==even[0][0]:
        print(n-odd[0][1]-even[1][1])
    else:
        print(n-odd[0][1]-even[0][1])
elif len(even)==1:
    if odd[0][0]==even[0][0]:
        print(n-odd[1][1]-even[0][1])
    else:
        print(n-odd[0][1]-even[0][1])
else:


    if odd[0][0]==even[0][0]:
        if odd[1][1]>even[1][1]:
            print(n-odd[1][1]-even[0][1])
        else:
            print(n-odd[0][1]-even[1][1])

    else:
        print(n-odd[0][1]-even[0][1])

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

int n,a[500000],t[500000],tag,an;
long long ans = 1;

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        t[a[i]]++;
    }
    for(int i=1;i<n+5;i++){
        if(t[i]%2==1)tag=1;
    }
    if(tag==0){
        for(int i=1;i<n+5;i++){
            if(t[i]>0)ans *= 2, ans %= 1000000007;
        }
        cout<<ans<<endl;
    }else{
        cout<<0<<endl;
    }



}


Measured memory_bytes: 1024
x,k,d = map(int,input().split())

need = abs(x)//d

if x>0:
    if k>=need:
        x -= need*d
        k -= need
    else:
        x -= k*d
        k = 0
else:
    if k>=need:
        x += need*d
        k -= need
    else:
        x += k*d
        k = 0
    

while x>0 and k>0:
    x-=d
    k-=1

if k%2==0:
    print(abs(x))
else:
    print(x+d)


Measured memory_bytes: 9196
from collections import Counter


n = int(input())
A = list(map(int, input().split()))
c = Counter(A)
cc = c.most_common()
ans = 0
for i in range(len(cc)):
    n = cc[i][1]
    if n < 2:
        break
    ans += n * (n-1) // 2

for i in A:
    cnt = c[i]
    if cnt == 1:
        print(ans)
    else:
        ans_ = ans + (cnt-1)*(cnt-2) // 2 - cnt*(cnt-1)//2
        print(ans_)

Measured memory_bytes: 29240
#include <cstdio>
using namespace std;

struct Card {
  char suit;
  int num;
};

void swap(Card *a, Card *b) {
  Card tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

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

void quickSort(Card A[], int p, int r) {
  int q;
  if (p < r) {
    q = partition(A, p, r);
    quickSort(A, p, q - 1);
    quickSort(A, q + 1, r);
  }
}

void merge(Card A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  Card L[n1 + 1], R[n2 + 1];
  for (int i = 0; i < n1; i++) L[i] = A[left + i];
  for (int i = 0; i < n2; i++) R[i] = A[mid + i];
  L[n1].num = R[n2].num = 20000000;
  int i = 0;
  int j = 0;
  for (int k = left; k < right; k++) {
    if (L[i].num <= R[j].num) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(Card A[], int left, int right) {
  int mid;
  if (left + 1 < right) {
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int n;
  char s[10];
  Card card[100000], another[100000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s %d", s, &card[i].num);
    card[i].suit = s[0];
    another[i] = card[i];
  }
  quickSort(card, 0, n - 1);
  mergeSort(another, 0, n);
  bool flag = false;
  for (int i = 0; i < n; i++) {
    if (card[i].suit != another[i].suit) {
      flag = true;
      break;
    }
  }
  if (flag) {
    printf("Not stable\n");
  } else {
    printf("Stable\n");
  }
  for (int i = 0; i < n; i++) {
    printf("%c %d\n", card[i].suit, card[i].num);
  }
}


Measured memory_bytes: 5028
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner obj=new Scanner(System.in);
    long n=obj.nextLong();
    StringBuilder result = new StringBuilder();

        while(n>0){
            n--;
            result.insert(0, (char)('a' + n % 26));
            n /= 26;
        }

        System.out.println(result.toString());
  }
}

Measured memory_bytes: 35820
#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 INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    // read in integer 
    ll x, rem, curr;
    cin >> x;
    curr = (x/500)*1000;
    rem = x%500;
    cout << curr + (rem/5)*5 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
int main(){
	int i,c;
	while((c=getchar())!=EOF){
		if(islower(c)){
			c=toupper(c);
		}else if(isupper(c)){
			c=tolower(c);
		}
		putchar(c);
	}
	return 0;
}


Measured memory_bytes: 1756
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define endl            "\n"
#define forn(i,x,n)     for(int i=x; i<n; i++)
#define forit(it, m)    for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


void zeus()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int n;
int k;
double a[200001];

bool check(int x) {
    double ans = 0;
    forn(i, 0, n) {
        ans += ceil(a[i] / x) - 1;
    }
    return (ans <= k);
}
int32_t main() {

    zeus();

    cin >> n >> k;

    forn(i, 0, n) {
        cin >> a[i];
    }

    int low = 1;
    int high = 1e9 + 2;

    while (low < high) {
        int mid = (low + high) / 2;

        if (check(mid)) high = mid;
        else low = mid + 1;

    }

    cout << low << endl;


}

Measured memory_bytes: 5240
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		for(int i=0;i<n;i++) {
			int a=in.nextInt(),b=in.nextInt(),q=a%b;
			if(q==0)System.out.println(b);
			else System.out.println(q);
		}
	}

}



Measured memory_bytes: 26544
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np

N = int(input())
L = np.array([list(map(int, input().split())) for _ in range(2)])

count = 0
for i in range(N):
    count = max(count, np.sum(L[0][:i+1]) + np.sum(L[1][i:]))
print(count)


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

string s;
int n;
ll ans;
void solve(int x, ll cur, ll sum) {
    if (x == n) {
        ans += cur + sum;
        return;
    }
    int b = s[x] - '0';
    solve(x + 1, cur * 10 + b, sum);
    solve(x + 1, b, sum + cur);
}

int main() {
    cin >> s;
    n = s.length();
    solve(1, s[0] - '0', 0);
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(void){
    int n;
    cin>>n;
    n = n % 10;
    if(n == 3) cout<<"bon"<<endl;
    else if(n == 0 || n == 1 || n == 6 || n == 8){
        cout<<"pon"<<endl;
    }
    else{
        cout<<"hon"<<endl;
    }

    return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
int main(){
    int n,l;
    cin >> n >> l;
    string s[n];
    for(int i=0; i<n; i++){
        cin >> s[i];
    }
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            if(s[j] < s[i]){
                string wk;
                wk=s[j];
                s[j]=s[i];
                s[i]=wk;
            }
        }
    }

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

    cout << endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 1000050;
using namespace std;
typedef long long ll;
ll p[maxn];
int main()
{
	int n;
	cin>>n;
	int sum=0;
	for(int i=1;i<=n;i++){
		cin>>p[i];
		sum=sum^p[i];
	}
	for(int i=1;i<=n;i++){
		int ans=sum^p[i];
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 5100
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005



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

        int a,b,c,d;
        cin >> a >> b >> c >> d;
        int ans=a*b-(a*d+b*c-c*d);
        cout << ans << '\n';
        

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
//#define MOD 1000000007
const int INF = 1LL<<30;

int main() {
    ll n;
    cin>>n;
    string res="";
    while(n){
        n--;
        res+=(char)('a'+(n%26));
        n/=26;
    }
    reverse(all(res));
    
    cout<<res<<endl;
}

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

long long int arr[200005];

int main() {
	long long int k,n;
	
	cin>>k>>n;
	
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	
	long long int mx = 0;
	
	for(int i=1;i<n;i++){
		mx = max(mx, arr[i]-arr[i-1]);
	}
	
	mx = max(mx,k+arr[0]-arr[n-1]);
	
	cout<<k-mx<<endl;
	return 0;
}


Measured memory_bytes: 1792
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> A(N), B(N);
    int max_val = 0, cnt = 0;
    for(int i=0; i<N; i++) {
        cin >> A[i];
        B[i] = A[i];
        if(A[i] > max_val) {
            max_val = A[i];
            cnt = 1;
        }
        else if(A[i] == max_val) cnt++;
    }
    sort(B.rbegin(), B.rend());

    for(int i=0; i<N; i++) {
        if(A[i] != max_val or cnt >= 2) cout << max_val << endl;
        else cout << B[1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long[] A = new long[N];
    long sum = 1;
    
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextLong();
      if (A[i] == 0) {
        sum = 0;
        break;
      } else if (A[i] > (1000000000000000000L / sum)) {
        sum = -1;
      } else {
        sum *= A[i];
      }
    } 
      System.out.println(sum);
                 
      sc.close();
  }
}


Measured memory_bytes: 61756
dice=input().split()
for direction in input():
    if direction == "N":
        dice=[dice[i]for i in [1,5,2,3,0,4]]
    elif direction == "W":
        dice=[dice[i]for i in [2,1,5,0,4,3]] 
    elif direction == "E":
        dice=[dice[i]for i in [3,1,0,5,4,2]] 
    elif direction == "S":
        dice=[dice[i]for i in [4,0,2,3,5,1]]
    
print(dice[0])


Measured memory_bytes: 5568
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U>& p) {
  os << p.first << " " << p.second;
  return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream &os, const vector< T > &v) {
  rep(i, v.size())
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T>
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
#line 2 "d.cpp"

int main() {
  ll n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;

  vl ans(n-1);

  rep(i, n) {
    rep3(j, i+1, n) {
      ll d = min(j-i, 1+abs(x-i)+abs(y-j));
      ans[d-1]++;
    }
  }

  rep(i, n-1) {
    cout << ans[i] << el;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#define ll long long
#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
#define gcd(A,B) (__gcd(A,B))
#define lcm(A,B) A/(__gcd(A,B))*B
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define ld long double
#define mod 1000000007LL
#define all(x) x.begin(), x.end()
#define usecppio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

char str[101010];
int c = 0;
int vs = 0;
vector <char> v;
int main()
{
    scanf("%s",str);
    int len = strlen(str);
    for (int i = 0; i<len; i++)
    {
        v.PB(str[i]);
        vs++;
        if (vs>=2)
        {
            if (v[vs-1]!=v[vs-2])
            {
                v.pop_back();
                v.pop_back();
                vs -= 2;
                c+=2;
            }
        }
    }
    printf("%d",c);
}

Measured memory_bytes: 512
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (Long i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  map<Long, Long> M;
  vector<Long> v(n);
  fore(i, 0, n) cin >> v[i];
  fore(i, 0, n) {
    M[(i + 1) - v[i]]++;
  }
  Long ans = 0;
  fore(i, 0, n) {
    M[(i + 1) - v[i]]--;
    Long busco = v[i] + (i + 1);
    if (M.count(busco)) ans += M[busco];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 16328
#include <bits/stdc++.h>
    
using namespace std;
typedef long long ll;
    
int main()
{
    int N, X;
    cin >> N >> X;
    vector<int> donuts;
    int all = 0;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        donuts.push_back(tmp);
        all += tmp;
    }
    sort(donuts.begin(), donuts.end());
    X -= all;
    int count = X / donuts[0];
    cout << N + count;
    
    return 0;
}

Measured memory_bytes: 256
/*     *******************Bismillahir Rahmanir Rahim************************
                          MD. ASFAKUL GHANI!
                          *ProMAGFAT*!
 SECRET_warning :)->FAT   CSE-25!
                          JAHANGIRNAGAR UNIVERSITY!
                          Dhaka,Bangladesh!
*/

#include <bits/stdc++.h>
#include <set>
using namespace std;

#define           fasterIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define           Im int main()
#define           ll long long
#define           sc scanf
#define           pf printf
#define           rn0 return 0
#define           rn return
#define           f0(i,n) for(ll i=0;i<n;i++)
#define           f1(i,n) for(ll i=1;i<=n;i++)
#define           f2(i,n) for(ll i=n-1;i>=0;i--)
#define           pi 2*acos(0.0)
#define           modulo 1000003
#define           dd double
#define           PI 3.14159265358979
#define           pi 2*acos(0.0)
#define           p_b push_back
#define           ps push

/*
ll for_binarySearch(ll a,ll b,ll aa[],ll x){while(a<=b){ll mid=(a+b)/2;if(aa[mid]==x) return 1;else if(aa[mid] > x) b=mid-1;else a=mid+1;}return -1;}
ll for_gcd(ll a,ll b){if(a==0) return b;else return for_gcd(b%a,a);}
ll for_prime(ll x){for (ll i=2;i*i<=x;i++){if(x%i==0) return 0;}return 1;}
void for_swap(char *x,char *y){char temp;temp=*x;*x=*y;*y=temp;}
ll for_big_mod(ll b,ll p,ll m){if(p==0) return 1;else if(p%2==0){ll k=for_big_mod(b,p/2,m);return (k*k)%m;}else return ((b%m)*(for_big_mod(b,p-1,m)))%m;}
ll for_josephus(ll n,ll k){if(n==1) return 1;return (for_josephus(n-1,k)+k-1)%n+1;}
ll for_gcdExtended(ll a,ll b,ll *x,ll *y){if(a==0){*x=0;*y=1;return b;}ll x1,y1;ll gcd=for_gcdExtended(b%a,a,&x1,&y1);*x=y1-(b/a)*x1;*y=x1;return gcd;}
*/
/*
void debug1()
{
    cout << "***" << endl;
}

void debug11(ll n)
{
    cout << n << endl;
}
*/

Im
{
    /*#ifdef FAT
       freopen("input.txt","w",stdin);
    #endif // FAT*/

    fasterIO;

    ll m,n;
    cin>>m>>n;
    cout << (m*n) << " " << 2*(m+n) << endl;

   // main();

    rn0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
 
 
 
int main (){
    int N;
    cin>>N;
    vector<string> Vec(N);
    for(int i=0; i<N; i++){
        cin>>Vec.at(i);
        sort(Vec.at(i).begin(), Vec.at(i).end());
    }
    sort(Vec.begin(), Vec.end());
  	/*for(int i=0; i<3; i++){
      	cout<<Vec.at(i)<<" ";
    }*/
    long long Sum=0;
    long long Count=0;
    for(int i=0; i<N-1; i++){
        bool X=true;
        for(int j=0; j<10; j++){
            if(Vec.at(i).at(j)==Vec.at(i+1).at(j)){
                continue;
            }
            else{
                X=false;
                break;
            }
        }
        Sum+=Count;
        if(X){
            Count++;
        }
        else{
            Count=0;
        }
    }
    Sum+=Count;
    cout<<Sum<<endl;
}

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

int main() {
    int N ;
    cin >> N ;
    int a = N%10 ;
    if(a==2|| a== 4 || a==5 || a==7 || a==9) cout << "hon" ;
    else if(a==0 || a==1 || a== 6 || a==8) cout << "pon" ;
    else cout << "bon" ;
}

Measured memory_bytes: 3608
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll t[100001] = {};
ll x[100001] = {};
ll y[100001] = {};
int main() {
	int n; cin >> n;
	repe(i, 1, n)cin >> t[i] >> x[i] >> y[i];

	repe(i, 1, n) {
		ll diff_d = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
		ll diff_t = t[i] - t[i - 1];

		if (diff_d > diff_t || (diff_t - diff_d) & 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 2560
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
bool bad[15][15];
bool need[15][15];
int main(){
	cin >> n;
	rep(i,n){
		int a; cin >> a;
		rep(j,a){
			int x,y; cin >> x >> y; x--;
			if(y == 0) bad[i][x] = bad[x][i] = 1;
			else need[i][x] = 1;
		}
	}
	int ans=0;
	rep(i,(1<<n)){
		vector<int>vi;
		rep(j,n) if(((i>>j)&1)) vi.pb(j);
		rep(x,vi.size()) rep(y,vi.size()) if(bad[vi[x]][vi[y]]) goto fail;
		rep(x,vi.size()) rep(j,n){
		    if(need[vi[x]][j] && ((i>>j)&1) == 0)  goto fail;
		}
		ans = max(ans,__builtin_popcount(i)); fail:;
	}
	cout<<ans<<endl;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll mod = 1e9+7;
typedef pair<int,int> P;

int main(){
    int h,w;
    cin>>h>>w;
    int n;
    cin>>n;
    int a;
    P p[n];
    for(int i=0;i<n;i++){
        cin>>a;
        p[i].first=a;
        p[i].second=i+1;
    }
    int aa[h][w];
    memset(aa,0,sizeof(a));
    sort(p,p+n,greater<P>());
    int c=0;
    for(int i=0;i<h;i++){
        if(i%2==0){
            for(int j=0;j<w;j++){
                if(p[c].first==0)c++;
                aa[i][j] = p[c].second;
                p[c].first--;
            }
        }else{
            for(int j=w-1;j>=0;j--){
                if(p[c].first==0)c++;
                aa[i][j] = p[c].second;
                p[c].first--;
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<aa[i][j]<<' ';
       }
       cout<<endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

int main() {
  int n, a, b;
  cin >> n >> a>> b;
  vi r(3);
  rep(i, n) {
    int p;
    cin >> p;
    if(p <= a) r[0]++;
    else if(p <= b) r[1]++;
    else r[2]++;
  }
  cout << min(r[0], min(r[1], r[2])) << endl;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
#include<cstring>
#include <vector>
#include <algorithm>

int s[2] = {-1, 1};

int solve(int x, int n, int* arr)
{
  for (int i = 0; i < x +1; i++)
  {
    for (int j : s)
    {
      int a = x + j*i;
      bool found = false;
      for (int k = 0; k < n; k++)
      {
        if (arr[k] == a)
          found = true;
      }
      if (!found) return a;
    }
  }
  return -1;
}

int main()
{
  int x, n;
  cin >> x;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++)
  {
    cin >> arr[i];
  }
  int res = solve (x, n, arr);
  cout << res << endl;
}


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


int H,W;
bool F[52][52]; //障害物
bool D[52][52][52][52]; //探索済みかの判定用
int inc_tx[4] = {1,-1,0,0};
int inc_ty[4] = {0,0,1,-1};
int inc_kx[4] = {-1,1,0,0};
int inc_ky[4] = {0,0,-1,1};

class Point{
public:
  int tx; //タカユキの座標
  int ty;
  int kx; //カズユキの座標
  int ky;
  int d; //ターン回数
  void set(int a,int b,int c,int d){
    tx = a;
    ty = b;
    kx = c;
    ky = d;
  }
};

bool is_out_of_area(int y,int x) //座標が範囲内か確認する関数
{
  return x < 1 || x > W || y < 1 || y > H || F[y][x];
}

int main(){

  while(1){

    Point p,q;
    int tx,ty,kx,ky;
    queue<Point> qa;
    cin >> W >> H;
    if(W == 0 && H == 0)
    break;
    cin >> tx >> ty >> kx >> ky;
    memset(F,1,sizeof(F));
    for(int y=1;y<=H;y++){
      for(int x=1;x<=W;x++){
        cin >> F[y][x];
      }
    }
    memset(D,1,sizeof(D));
    p.set(tx,ty,kx,ky);
    D[ty][tx][ky][kx] = 0;
    p.d = 0;
    qa.push(p);
    while(1){
      if(qa.empty()){
        cout << "NA" <<endl;
        break;
      }
      p = qa.front();
      qa.pop();
      if(p.d >= 100){
        cout << "NA" << endl;
        break;
      }
      if(p.tx == p.kx && p.ty == p.ky){
        cout << p.d << endl;
        break;
      }
      for(int i=0;i<4;i++){
        q.tx = p.tx + inc_tx[i]; q.ty = p.ty + inc_ty[i];
        q.kx = p.kx + inc_kx[i]; q.ky = p.ky + inc_ky[i];

        if(is_out_of_area(q.ty ,q.tx) == 0 || is_out_of_area(q.ky ,q.kx) == 0){
          if(is_out_of_area(q.ty ,q.tx)){
            q.ty = p.ty; q.tx = p.tx;
          }
          if(is_out_of_area(q.ky ,q.kx)){
            q.ky = p.ky; q.kx = p.kx;
          }
          if(D[q.ty][q.tx][q.ky][q.kx]){
            q.d = p.d + 1;
            qa.push(q);
            D[q.ty][q.tx][q.ky][q.kx] = 0;
          }
        }

      }
    }

  }
  return 0;
}



Measured memory_bytes: 10388
// https://atcoder.jp/contests/agc033/tasks/agc033_a
// BFS

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define mp(i,j) make_pair(i,j)

typedef long long ll;

typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int H, W;
vector<pair<int, int>> start;
char Maze[1010][1010];
int min_path[1010][1010];

void Main()
{
    cin >> H >> W;
    memset(min_path, -1, sizeof(min_path));
    queue<P> q;
    rep(i,H) {
        rep(j,W) {
            cin >> Maze[i][j];
            if (Maze[i][j] == '#') {
                q.push(mp(i,j));
                min_path[i][j] = 0;
            }
        }
    }
    while (!q.empty()) {
		auto p = q.front(); q.pop();
        rep(i,4) {
			int ny = p.first + dy[i];
			int nx = p.second + dx[i];
			if (ny >= 0 && nx >= 0 && ny < H && nx < W && Maze[ny][nx] != '#' && min_path[ny][nx] == -1) {
                min_path[ny][nx] = min_path[p.first][p.second] + 1;
				q.push(mp(ny, nx));
            }
        }
	}
    int res = -1;
    rep(i,H) {
        rep(j,W) {
            res = max(res, min_path[i][j]);
        }
    }
    cout << res << endl;
}

int main()
{
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
}


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef pair<ll, ll> PLL;

ll N,M,R;
vector<ll> r;
ll d[222][222];

signed main() {
    cin>>N>>M>>R;
    r.resize(R);
    rep(i,0,R){
        cin>>r[i];
    }
    sort(begin(r),end(r));
    rep(i,1,N+1) rep(j,1,N+1) if (i!=j) d[i][j]=d[j][i]=1e18;
    rep(i,1,N+1) d[i][i]=0;
    rep(i,0,M){
        ll a,b,c;
        cin>>a>>b>>c;
        if (c > d[a][b])
            continue;
        d[a][b] = d[b][a] = c;
    }

    // ワーシャルフロイド
    rep(k,1,N+1)
        rep(i,1,N+1)
            rep(j,1,N+1)
                d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
    ll ans = 1e18;
    do {
        // cout<<"perm: ";
        // rep(i,0,R){
        //     cout<<r[i]<<" ";
        // }
        // cout<<endl;

        ll t = 0;
        rep(i,1,R){
            t += d[r[i-1]][r[i]];
        }
        ans = min(ans, t);
    } while(next_permutation(begin(r),end(r)));
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    string s; cin >> s;
    bool flag = 1;
    for (int i = 0; i < s.size() / 2; i++) {
        if (s[i] != s[ s.size() - i - 1]) {
            flag = 0; break;
        }
    }
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
const ll modl=1e9+7;
ll e10[1000006],e9[1000006],e8[1000006];
int main(){
	ll n;
	cin>>n;
	e10[0]=e9[0]=e8[0]=1;
	for(int i=1;i<=n;i++)
	{
		e10[i]=e10[i-1]*10%modl;
		e9[i]=e9[i-1]*9%modl;
		e8[i]=e8[i-1]*8%modl;
	}ll ans=0;
	for(ll j=2;j<=n;j++)
	{
		ans+=(e10[n-j]*(((e9[j-1]-e8[j-1])%modl+modl)%modl)%modl);
		ans%=modl;
	}
	cout<<ans*2%modl<<endl;
	return 0;
}


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

int main()
{   
    int n,d,i,ans;
    double x,y,dis;
    cin>>n>>d;

    for(i = 0; i < n; i++){
        cin>>x>>y;
        dis = sqrt((x*x)+(y*y));
        if (dis<=d){
            ans+=1;
        }
    }    
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3196
#include <iostream>

using namespace std;

int main(void){
  int K;
  int A, B;
  int num = 1;
  bool findFlag = false;
  cin >> K >> A >> B;
  while(K * num <= B){
    if(A <= K * num && K * num <= B){
      cout << "OK" << endl;
      findFlag = true;
      break;
    }
    num++;
  }
  if(!findFlag){
    cout << "NG" << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
import math
n,a,b,k = map(int, input().split())
un = 998244353
f = [0]*(n+1)
inv = [0] * (n+1)
f[0] = f[1] = 1

for i in range(2, n+1):
    f[i] = (f[i-1] * i ) % un

inv[n] = pow(f[n], un-2, un)
for i in range(n, 0, -1):
    inv[i-1] = (inv[i] * i) % un

#フェルマーの小定理の利用
def nCr(n,r):
    global f, inv
    return (f[n] * inv[r]) % un * inv[n-r] % un

total = 0
for i in range(n+1):
    if((k-a*i)%b==0):
        count_b = (k-a*i)//b
        if(count_b >= 0 and count_b <= n):
            total += nCr(n, i) * nCr(n, count_b)

print(str(total % un))


Measured memory_bytes: 26740