akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};
struct Card L[MAX/2 +2],R[MAX/2+2];

void marge(struct Card *A,int n,int l,int m,int r){
  int i,j,k;
  int n1=m-l;
  int n2=r-m;
  for(i=0;i<n1;i++) L[i]=A[l+i];
  for(i=0;i<n2;i++) R[i]=A[m+i];
  L[n1].value=R[n2].value=SENTINEL;
  i=j=0;
  for(k=l;k<r;k++){
    if(L[i].value<=R[j].value){
      A[k]=L[i++];
    }else{
      A[k]=R[j++];
    }
  }
}

void margeSort(struct Card *A,int n,int l,int r){
  int m;
  if(l+1<r){
  m=(l+r)/ 2;
  margeSort(A,n,l,m);
  margeSort(A,n,m,r);
  marge(A,n,l,m,r);
}
}

int partition(struct Card *A,int n,int p,int r){
  int i,j;
  struct Card t,x;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;

  return i+1;
}

void quickSort(struct Point *A,int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main(){
  int  n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable =1;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].suit=B[i].suit=S[0];
    A[i].value=B[i].value=v;
  }

  margeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit != B[i].suit) stable=0;
  }
  if(stable==1) printf("Stable\n");
  else if(stable==0) printf("Not stable\n" );
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].suit,B[i].value );
  }

  return 0;
}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int a,b,x;
  cin >> a >> b >> x;
  if(x <= a + b && x >= a) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}

const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;


int main() {
  int n;
  scanf("%d",&n);
  vi a(n);
  rep(i,n) scanf("%d",&a[i]);
  sort(rng(a)); reverse(rng(a));
  int x = n-1;
  rep(i,n) if (i) {
    if (a[i] <= i) {
      if (a[i] == i) {
        int s = (a[i-1]-i)%2==1;
        int j = i;
        while (j < n && a[i] == a[j]) ++j;
        int t = (j-i)%2 == 1;
        if (s || t) puts("First");
        else puts("Second");
        return 0;
      }
      x = i-1;
      break;
    }
  }
  if (((a[x]+x+1)-(x*2))%2 == 0) puts("Second");
  else puts("First");
  return 0;
}










Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int m,int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(m,n / 2);
	x *= x;
	if (n % 2 == 1)x *= m;
	return x;
}
ll max(ll a, ll b) {
	if (a < b)return b;
	else return a;
}
struct edge { int to, cost; };


int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t);
	Yes(s<t)
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define ll long long
#define re return
#define mp map<int,int>
#define N 200005
#define pql priority_queue<ll>
using namespace std;
int a[N];
int main() {
	int n;
	ll ans=0;
	cin>>n;
	rep(i,1,n) cin>>a[i];
	sort(a+1,a+n+1);
	rep(i,1,n-1) {
		if(a[i]<0&&a[i+1]<0){
			a[i]*=-1;
			a[i+1]*=-1;
		}
		else if(a[i]<0&&a[i+1]<a[i]*-1){
			a[i]*=-1;
			a[i+1]*=-1;
		}
	}
	rep(i,1,n) ans+=a[i];
	cout<<ans;
	re 0;
}


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

int main(){
    int64_t N;
    cin >> N;
    int64_t ans = 0;
    for(int64_t i=0; i<N; i++) ans += (i+1)*(N-i);
    for(int i=0; i<N-1; i++){
        int64_t a, b;
        cin >> a >> b;
        a--; b--;
        if(a > b) swap(a, b);
        ans -= (a+1)*(N-b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int up[360];

int main()
{
	int x; scanf ("%d", &x);

	int d = 0;
	for (int k = 1;; k++){
		up[d]++;
		d = (d + x) % 360;
		for (int i = 1; i < 360; i++)if (360 % i == 0){
			for (int j = 0; j < i; j++){
				int mn = up[j];
				for (int l = j; l < 360; l += i) if (mn > up[l]) mn = up[l];
				for (int l = j; l < 360; l += i) up[l] -= mn;
			}
		}
		int cnt = 0;
		for (int i = 0; i < 360; i++) cnt += up[i];
		if (cnt == 0){
			printf ("%d\n", k);
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1728
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill((T*)array, (T*)(array+N), val);
}
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


class BCountABC {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        string s;
        in >> n >> s;
        int cnt = 0;
        rep(i, s.length()-2){
            string t = "";
            t += s[i];
            t += s[i+1];
            t += s[i+2];
            if(t == "ABC") cnt++;
        }
        out << cnt << endl;
	}
};


int main() {
	BCountABC solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
def inpl():
    return list(map(int, input().split()))


N = int(input())
W = inpl()
sumW = sum(W)

ans = sumW
tmp_sum = 0
for i, w in enumerate(W):
    tmp_sum += w
    ans = min(ans, abs(sumW - 2 * tmp_sum))

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <numeric>
#define rep(i,s,n) for (int i = s; i < n; ++i)
#define drep(i,s,n) for (int i = n; i >= s; --i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
using namespace std;
typedef long long ll;

int gcd(int a, int b)
{
   if (a%b == 0) return(b);
   else          return(gcd(b, a%b));
}
int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
void printvv(vector<vector<auto>> vv, int n)
{
  cout << '[' << endl;
  rep(q, 0, n)
  {
    cout << '[';
    rep(p, 0, n)
    {
      cout << vv.at(q).at(p) << ',';
    }
    cout << ']' << endl;
  }
  cout << ']' << endl;
}


//------------------------------------------------------------
int main() {
  int N, dt=0, dist=0;
  bool bl=true;

  cin >> N;

  vector<vector<int>> v(N, vector<int>(3));
  rep(i,0,N) cin >> v.at(i).at(0) >> v.at(i).at(1) >> v.at(i).at(2);

  if (N==1)
  {
    dt   = v.at(0).at(0);
    dist = abs(v.at(0).at(1)) + abs(v.at(0).at(2));
    if(dt<dist || dt%2!=dist%2) bl=false;
    if(bl)cout << "Yes" << endl;
    else  cout << "No" << endl;
    return 0;
  }

  rep(i,1,N)
  {
    dt = v.at(i).at(0) - v.at(i-1).at(0);
    dist = abs(v.at(i).at(1)-v.at(i-1).at(1)) + abs(v.at(i).at(2)-v.at(i-1).at(2));

    if(dt<dist || dt%2!=dist%2)
    {
      bl=false;
      break;
    }
  }

  if(bl)cout << "Yes" << endl;
  else  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 5760
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break

    for i in range(H):
        for j in range(W):
            if (j-i) % 2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print("")
    print("")



Measured memory_bytes: 7012
N = int(input())
H = list(map(int,input().split()))
f = True
for i in range(1,N):
    if H[i] == H[i-1]-1:
        H[i] += 1
    if H[i] < H[i-1]:
        f = False
        break

if f:
    print('Yes')
else:
    print('No')

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

int main() {
	string a;
	cin >> a;
	int A = a[0] - '0';
	int B = a[1] - '0';
	int C = a[2] - '0';
	int D = a[3] - '0';
	if(A + B + C + D == 7){
		cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
	}
	else if(A - B + C + D == 7){
		cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
	}
	else if(A + B - C + D == 7){
		cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
	}
	else if(A + B + C - D == 7){
		cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
	}
	else if(A - B - C + D == 7){
		cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
	}
	else if(A + B - C - D == 7){
		cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
	}
	else if(A - B + C- D == 7){
		cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
	}
	else{
		cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
	}
	return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s;
    cin >> s;
    if(s=="RRR")
        cout << 3;
    else if(s=="RRS" || s=="SRR")
        cout << 2;
    else if(s=="SSS")
        cout << 0;
    else
        cout << 1;
}


Measured memory_bytes: 3624
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	a := iSScan(n)
	m := make(map[int]int)
	for _, v := range a {
		m[v]++
	}
	ans := 0
	for k, v := range m {
		if k > v {
			ans += v
		} else if k < v {
			ans += v - k
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 9844
#include<iostream>

using namespace std;

string s;

int main(){
  cin >> s;
  int start = 0,end = s.length()-1;

  int ans = 0;
  while(start < end){
    if(s[start] == '('){
      if(s[end] != ')') ans++;
    }else if(s[start] == ')'){
      if(s[end] != '(') ans++;
    }else{
      if(s[start] != s[end]) ans++;
    }
    start++;
    end--;
  }

  if(start == end){
    if(s[start] == '(' || s[start] == ')') ans++;
  }
  cout << ans << endl;
  return 0;
}

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

struct process{
    string name;
    int time;
};
const int MAX=100010;
int head=0;
int tail=0;

process dequeue(process *p);
void enqueue(process *p, process s);


int main(){
    process p[MAX];
    process a,b;
    int n,q,i;
    char str[11];
    int sum=0;
    cin>>n>>q;
    for(i=0;i<n;i++){
        scanf("%s", str);
        p[i].name=str;
        scanf("%d", &(p[i].time));
        /*cin>>a.name>>a.time;*/
        /*enqueue(p, a);*/
    }
    tail=n;

    while(head!=tail){
        a=dequeue(p);
        b.name = a.name;
        b.time = a.time - q;
        if(b.time<=0){
            sum += a.time;
            printf("%s %d\n", a.name.c_str(), sum);
            /*cout<<a.name<<' '<<sum<<endl;*/
        }
        else{
            sum += q;
            enqueue(p, b);
        }
    }
}

void enqueue(process *p, process s){
    if(head==(tail+1)%MAX) ;
    else{
        p[tail]=s;
        if(tail==MAX-1) tail=0;
        else tail++;
    }
}

process dequeue(process *p){
    process s;
    if(head==tail) ;
    else{
        s=p[head];
        if(head==MAX-1) head=0;
        else head++;
        return s;
    }
}


Measured memory_bytes: 7096
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

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

	vector<double> x(N);
	vector<string> u(N);

	for (int i = 0; i < N; i++) {
		cin >> x[i] >> u[i];

	}
	
	double s = 0;

	for (int i = 0; i < N; i++) {
		if (u[i] == "JPY") {
			s += x[i];
		}
		else {
			s += x[i] * 380000;
		}
	}
	cout << s << endl;

}

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

struct Oct {
    int c[8];
    bool operator<(const Oct &rhs) const {
        for (int j=0;j<8;++j) {
            if (c[j]<rhs.c[j]) return true;
            else if (c[j]>rhs.c[j]) return false;
        }
        return false;
    }
};

string color[8];
int col[8];
map<string,int> mp;

Oct x_rot(Oct ot)
{
    Oct rt;
    rt.c[0]=ot.c[3];
    rt.c[1]=ot.c[2];
    rt.c[2]=ot.c[6];
    rt.c[3]=ot.c[7];
    rt.c[4]=ot.c[0];
    rt.c[5]=ot.c[1];
    rt.c[6]=ot.c[5];
    rt.c[7]=ot.c[4];
    return rt;
}

Oct y_rot(Oct ot)
{
    Oct rt;
    rt.c[0]=ot.c[4];
    rt.c[1]=ot.c[0];
    rt.c[2]=ot.c[3];
    rt.c[3]=ot.c[7];
    rt.c[4]=ot.c[5];
    rt.c[5]=ot.c[1];
    rt.c[6]=ot.c[2];
    rt.c[7]=ot.c[6];
    return rt;
}

Oct z_rot(Oct ot)
{
    Oct rt;
    rt.c[0]=ot.c[3];
    rt.c[1]=ot.c[0];
    rt.c[2]=ot.c[1];
    rt.c[3]=ot.c[2];
    rt.c[4]=ot.c[7];
    rt.c[5]=ot.c[4];
    rt.c[6]=ot.c[5];
    rt.c[7]=ot.c[6];
    return rt;
}

Oct gOct;
Oct sortOct[64];
set<Oct> ans;

void calc(int depth, int pos) {
    if (depth == 8) {
        Oct temp = gOct;
        for (int x = 0; x < 4; x++) {
            for (int y = 0; y < 4; y++) {
                for (int z = 0; z < 4; z++) {
                    sortOct[x + y * 4 + z * 16] = temp;
                    temp = z_rot(temp);
                }
                temp = y_rot(temp);
            }
            temp = x_rot(temp);
        }
        sort(sortOct, sortOct + 64);
        ans.insert(sortOct[0]);
        return;
    }
    for (int i = 0; i < 8; i++) {
        if ((pos >> i) & 1) { continue; }
        gOct.c[depth] = col[i];
        calc(depth + 1, pos | (1 << i));
    }
}


int main()
{
while (true) {
ans.clear();mp.clear();
    for (int j=0;j<8;++j)
        if (!(cin >> color[j])) { return 0; }
    for (int j=0;j<8;++j) {
        if (mp.find(color[j])!=mp.end())
            col[j]=mp[color[j]];
        else {
            col[j]=mp.size();
            mp[color[j]]=col[j];
        }
    }

    calc(0,0);
    cout << ans.size() << endl;
}
    return 0;
}

Measured memory_bytes: 1016
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define exists(s,x) (s).find(x)!=(s).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define fi first
#define se second
typedef long long ll;
const ll INF = 1LL<<60;
ll MOD = 1000000007;
 
inline ll add(ll x, ll y) {return (x+y)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll sub(ll x, ll y) {
    ll res = x - y;
    if(res < 0) res += MOD;
    return res;
}
inline ll modpow(ll x, ll y) {
    ll res = 1;
    while(y) {
        if(y&1) res = mul(res,x);
        y >>= 1;
        x = mul(x,x);
    }
    return res;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, P; cin >> N >> P; MOD = P;
    string s; cin >> s;
    if(P == 2 || P == 5) {
        ll ans = 0;
        REP(i,N) if((ll)(s[i]-'0')%P == 0) ans += (ll)i+1;
        cout << ans << endl;
        return 0;
    }
    vector<ll> v(N,0);
    for(int i = N-1; i>=0; --i) {
        ll num = s[i] - '0';
        num %= P;
        if(i==N-1) v[i] = num;
        else {
            v[i] = add(v[i+1],mul(num,modpow(10%P,N-1-i)));
        }
    }
    map<ll,ll> mp;
    for(auto x:v) mp[x]++;
    ll ans = 0;
    for(auto p:mp) {
        ll num = p.se;
        ans += num * (num-1) / 2;
    }
    ans += mp[0];
    // for(auto x:v) cout << x << " "; cout << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2580
#include<bits/stdc++.h>
using namespace std;
void solve()
{
	int n,m,i;
	cin>>n>>m;
	if(n&1)
		for(i=1;i<=m;i++)
			cout<<i<<" "<<n-i<<endl;
	else
		for(i=0;i<m;i++)
			if(i<(m+1)/2)	cout<<i+1<<" "<<n-i<<endl;
			else			cout<<i+1<<" "<<n-i-1<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	while(t--)	solve();
	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
int main(void){
	int a = 0, b = 0;
	int d = 0, r = 0;
	double f = 0.0;

	scanf("%d %d", &a, &b);
	d = a / b;
	r = a % b;
	f = 1.0 * a / b;

	printf("%d %d %.8lf", d, r, f);
}

Measured memory_bytes: 2716
h,w = map(int,input().split())
C = []
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(h):
    C.append(list(map(str,input().split())))
for i in range(h):
    if "snuke" in C[i]:
        j = C[i].index("snuke")
        print(alpha[j]+str(i+1))
        break


Measured memory_bytes: 3060
H,W,K = map(int,input().split())
S = [list(map(int,input())) for _ in [0]*H]

ans = H*W
S2 = [[0]*(W+1) for _ in [0]*(H+1)]
for i in range(H):
    for j in range(W):
        S2[i+1][j+1] = S2[i][j+1] + S[i][j]
for i in range(1,H+1):
    for j in range(W):
        S2[i][j+1] += S2[i][j]

for i in range(1<<(H-1)):
    check = [0]+[j+1 for j in range(H-1) if i>>j&1]+[H]
    cnt = len(check)-2
    l = 0
    r = 1
    while r<=W:
        for j,k in zip(check[:-1],check[1:]):
            if S2[j][l] + S2[k][r] - S2[j][r] - S2[k][l] > K:
                if r==l+1:
                    cnt += H*W
                    r = W+1
                    break
                cnt += 1
                l = r-1
                r = r
                break
        else:
            r += 1
    ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 44864
D = int(input())
C = list(map(int, input().split()))
S = [tuple(map(int, input().split())) for _ in range(D)]
Z = 26

last = [-1] * Z
ans = 0
T = []
for d in range(D):
    maxScore = -float('inf')
    cand = 0
    for i in range(26):
        tmp = last[i]
        last[i] = d
        up = S[d][i]
        down = sum(C[j] * (d - last[j]) for j in range(Z))
        score = up - down
        if maxScore < score:
            cand = i
            maxScore = score
        last[i] = tmp
    last[cand] = d
    T.append(cand + 1)
print(*T, sep='\n')


Measured memory_bytes: 74700
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    
    long long a, b, c;
    
    cin >> a >> b >> c;
    
    if(a + b >= c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
    
}


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

int main() {
    int N, K;
    cin >> N >> K;
    set<int> st;
    for (int i = 0; i < K; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            st.insert(a);
        }
    }
    cout << N - (int)st.size() << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int b = y2 - y1;
  int a = x2 - x1;
  int x3 = x2 - b;
  int x4 = x3 -a;
  int y3 = y2 +a;
  int y4 = y3 -b;
  printf("%d %d %d %d",x3,y3,x4,y4);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
int x1,x2,x3,x4,x5;
cin >> x1 >> x2 >> x3 >> x4 >> x5;
if(x1 == 0)
cout << 1 << endl;
else if (x2 == 0)
cout << 2 << endl;
else if (x3 == 0)
cout << 3 << endl;
else if (x4 == 0)
cout << 4 << endl;
else if (x5 == 0)
cout << 5 << endl;
    

    
}

Measured memory_bytes: 3616
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
       int n=s.nextInt(),k=s.nextInt();
       boolean[][] dp=new boolean[k+1][n+1];
       int[] arr=new int[n+1];
       for(int i=1;i<=n;i++){arr[i]=s.nextInt();}
       for(int i=1;i<=k;i++){
       	for(int j=1;j<=n;j++){
       		dp[i][j]=i<arr[j]?dp[i][j-1]:(dp[i][j-1]||!dp[i-arr[j]][n]);
       	}
       }
       if(dp[k][n]){out.write("First\n");}
       else{out.write("Second\n");}
        
        out.flush();
  }
}


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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;

template<class T,class U>
using umap = unordered_map<T,U>;

template<class T>
using uset = unordered_set<T>;

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

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


int main(){
  #define int ll
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);

  priority_queue<pair<int, int>> pq;

  bitset<200000> bs = 0;
  int finished = 0;
  
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }

  for(int i = 0; i < n; ++i){
    cin >> b[i];
    pq.push({b[i], i});
    if(a[i] == b[i]){
      bs[i] = 1;
      finished++;
    }
    if(a[i] > b[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  int cnt = 0;
  while(!pq.empty()){
    if(finished == n){
      cout << cnt << endl;
      return 0;
    }
    while(!pq.empty() && bs[pq.top().second] == 1){
      pq.pop();
    }
    if(pq.empty()){
      cout << cnt << endl;
      return 0;
    }
    int val, pos;
    tie(val, pos) = pq.top();
    pq.pop();
    int r = pos + 1, l = pos - 1;
    if(l < 0) l += n;
    if(r >= n) r -= n;

    int mns = b[r] + b[l];
    int div = (b[pos] - a[pos]) / mns;
    if(div == 0){
      cout << -1 << endl;
      return 0;
    }
    cnt = (cnt + div);
    b[pos] -= div*mns;
    
    if(b[pos] < a[pos]){
      cout << -1 << endl;
      return 0;
    } else if(b[pos] == a[pos]){
      bs[pos] = 1;
      finished++;
    } else {
      pq.push({b[pos], pos});
    }
    
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 9584
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;

int main()
{
    string s;
    cin >> s;
    if(s.size()<=3) cout << "ABC" << endl;
    else cout << "ABD" << endl;
    return 0;
} 


Measured memory_bytes: 256
/*input
3
-1 0
0 3
2 -1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#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())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=1005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=80000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

vector<ll> v;
ll x[maxn],y[maxn];

string ans[maxn];

int main()
{
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>x[i]>>y[i];

	ll cur=1;
	while(SZ(v)<35) v.pb(cur),cur<<=1;

	REP(i,n) if((x[0]%2+y[0]%2+10)%2!=(x[i]%2+y[i]%2+10)%2){
		cout<<"-1\n";
		return 0;
	}

	if((x[0]+y[0])%2){
		cout<<SZ(v)<<'\n';
		REP(i,SZ(v)) cout<<v[i]<<" \n"[i==SZ(v)-1];
	}
	else{
		cout<<SZ(v)+1<<'\n';
		cout<<1<<' ';
		REP(i,SZ(v)) cout<<v[i]<<" \n"[i==SZ(v)-1];
	}

	if((x[0]+y[0])%2==0){
		REP(i,n) ans[i].pb('R'),x[i]--;
	}

	REP(i,n){
		REP(j,SZ(v)-1){
			if(x[i]%2){
				if((x[i]+y[i]-1)/2%2){
					ans[i].pb('R');
					x[i]--;
				}
				else ans[i].pb('L'),x[i]++;
			}
			else{
				if((x[i]+y[i]-1)/2%2){
					y[i]--;
					ans[i].pb('U');
				}
				else ans[i].pb('D'),y[i]++;
			}
			x[i]>>=1;
			y[i]>>=1;
		}
		if(x[i]==1) ans[i].pb('R');
		else if(x[i]==-1) ans[i].pb('L');
		else if(y[i]==1) ans[i].pb('U');
		else ans[i].pb('D');
	}
	REP(i,n) cout<<ans[i]<<'\n';

	return 0;
}


Measured memory_bytes: 512
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
  
    int n, k;
    cin>>n>>k;

    vi v(n);
    for(int &x:v) cin>>x;
        sort(all(v));

    int ans = MAX;
    for(int i=0;i<n-k +1;i++){
        ans = min(ans, v[i+k-1] - v[i]);
    }

    cout<<ans;
} 

Measured memory_bytes: 1024
import bisect,math
def main():
    n,h = map(int,input().split())
    array = []
    m=0
    for _ in range(n):
        a,b = map(int,input().split())
        array.append(b)
        if m < a:
            m=a
    array.append(m)
    array = sorted(array)
    array = array[bisect.bisect(array,m)-1:]
    cnt = 0
    while h>0:
        if len(array)>1:
            h -= array.pop(-1)
            cnt += 1
        else:
            a = array[0]
            cnt += math.ceil(h/a)
            print(cnt)
            return
    print(cnt)
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 8300
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <cstdlib>

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
 
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9

using namespace std;
typedef long long ll;

int main(){
	int n, x[102], y[102], cx, cy, x1=-1, y1=-1;
	ll h[102], h1=-1, height;
	
	cin >> n;
	REP(i,n){
		cin >> x[i] >> y[i] >> h[i];
		if (h[i]!=0 && x1<0){
			x1 = x[i]; y1 = y[i]; h1 = h[i];
		}
	}
	
	for (cx=0; cx<=100; cx++){
		for (cy=0; cy<=100; cy++){
			height = h1 + abs(x1-cx) + abs(y1-cy);
			bool ok = true;
			REP(i,n){
				if (h[i]>0){
					if (h[i]!=height-abs(x[i]-cx)-abs(y[i]-cy)){
						ok = false;
						break;
					}
				}else{
					if (height-abs(x[i]-cx)-abs(y[i]-cy)>0){
						ok = false;
						break;
					}
				}
			}
			if (ok){
				printf("%d %d %lld\n", cx, cy, height);
				return 0;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
data = [1 for i in range(n)]

for j in range(m):
  a, b = map(int, input().split())
  if h[a-1] <= h[b-1]:
    data[a-1] = 0
  if h[a-1] >= h[b-1]:
    data[b-1] = 0

result = 0

for i in data:
  if i == 1:
    result += 1

print(result)

Measured memory_bytes: 20112
import java.util.Scanner;

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

    int count = 0;
    int time = 0;

    while (n > count) {
      time += t;
      count += x;
    }

    System.out.println(time);
  }
}

Measured memory_bytes: 26996
#include<stdio.h>
int main(void){
	int a,b,c,d,a1,b1,c1,d1,an,bn;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	scanf("%d%d%d%d",&a1,&b1,&c1,&d1);
	an=a+b+c+d;
	bn=a1+b1+c1+d1;
	if(an>=bn){printf("%d\n",an);}
	else{printf("%d\n",bn);}
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int n, m;
vector<int> lis[100100];
int vis[100100];
int col[100100];

int tc = 1;
void dfs(int here, int p) {
    vis[here] = tc++;
    for (int &there : lis[here]) {
        if (!vis[there]) {
            dfs(there,here);
        }
        else if (there!=p&&vis[there]<vis[here]) {
            printf("%d %d\n",here+1,there+1);
            col[here] ^= 1;
        }
    }
    if (~p) {
        if (col[here]) {
            printf("%d %d\n",here+1,p+1);
        }
        else {
            printf("%d %d\n",p+1,here+1);
            col[p]^=1;
        }
    }
}

int main() {
    scanf("%d%d",&n,&m);
    for (int i=0;i<m;i++) {
        int a, b;
        scanf("%d%d",&a,&b);
        a--; b--;
        lis[a].push_back(b);
        lis[b].push_back(a);
    }
    if (m%2) puts("-1");
    else {
        dfs(0,-1);
    }

    return 0;
}


Measured memory_bytes: 13952
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

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

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

#define ALL(set) (set).begin(), (set).end()

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	int s;
	cin >> s;
	map<int, bool> visited;
	int answer = 1;
	while(!visited.count(s))
	{
		visited[s] = true;
		s % 2 ? (s *= 3) += 1 : s /= 2;
		++answer;
	}
	cout << answer << '\n';
}

Measured memory_bytes: 3660
import scala.collection.mutable.ListBuffer
import scala.io.StdIn

object Main extends App {

  var text = StdIn.readLine()
  val n = StdIn.readLine().toInt
  val buff = ListBuffer.empty[String]
  
  def divide(target: String, s: Int, e: Int): Array[String] = {
    Array(target.take(s), target.slice(s, e), target.takeRight(target.length - e))
  }
  
  (0 until n).foreach { _ =>
    val cmd = StdIn.readLine().split(' ')
    
    val a = cmd(1).toInt
    val b = cmd(2).toInt + 1
    
    val divs = divide(text, a, b)
    //println(divs.toList)
    text = cmd(0) match{
      case "replace" => divs(0) + cmd(3) + divs(2)
      case "reverse" => divs(0) + divs(1).reverse + divs(2)
      case _ => {
        buff +=  divs(1)
        text
      }
    }
  }
  
  buff.foreach(println)
  
}



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

#define ull unsigned long long

const int MaxN(200003);
const int Mod(1e9 + 7);

int c[MaxN], w[MaxN], Mn[MaxN];
int tmp[MaxN], tot, res, cres;
int fac[MaxN], rfac[MaxN];
vector<int> G[MaxN];
bool Vis[MaxN];

int fexp(int x, int k)
{
	int res = 1;
	for(; k; k >>= 1, x = (ull) x * x % Mod)
		if(k & 1) res = (ull) res * x % Mod;
	return res;
}

inline int mymin(int x, int y)
{
	return w[x] < w[y] ? x : y;
}

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

void dfs(int u)
{
	Vis[u] = true, tmp[++tot] = c[u];
	for(auto v : G[u]) if(!Vis[v]) dfs(v);
}

int main()
{
	int n, X, Y;
	scanf("%d%d%d", &n, &X, &Y);
	w[0] = Mod;
	for(int i = 1; i <= n; i++)
	{
		scanf("%d%d", &c[i], &w[i]);
		Mn[c[i]] = mymin(Mn[c[i]], i);
	}
	for(int i = 1; i <= n; i++)
		if(w[Mn[i]] < w[res]) cres = res, res = Mn[i];
		else if(w[Mn[i]] < w[cres]) cres = Mn[i];
	for(int i = 1; i <= n; i++)
	{
		if(Mn[c[i]] != i && w[Mn[c[i]]] + w[i] <= X) add(Mn[c[i]], i);
		else if(c[res] != c[i] && w[res] + w[i] <= Y) add(res, i);
		else if(cres && w[cres] + w[i] <= Y) add(cres, i);
	}
	for(int i = fac[0] = 1; i <= n; i++)
		fac[i] = (ull) fac[i - 1] * i % Mod;
	rfac[n] = fexp(fac[n], Mod - 2);
	for(int i = n; i; i--)
		rfac[i - 1] = (ull) rfac[i] * i % Mod;
	int ans = 1;
	for(int i = 1; i <= n; i++)
		if(!Vis[i])
		{
			tot = 0, dfs(i);
			ans = (ull) ans * fac[tot] % Mod;
			sort(tmp + 1, tmp + 1 + tot);
			for(int j = 1, k; j <= tot; j = k)
			{
				for(k = j; k <= tot && tmp[k] == tmp[j]; k++);
				ans = (ull) ans * rfac[k - j] % Mod;
			}
		}
	printf("%d\n", ans);
	return 0;
}


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

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  //詰める動作を最後にすると考えると捨てる動作と同一視できる。左から取る回数　右から取る回数を全探索し、余ったK回捨てる動作を行う。以上をシュミレーション 
  int N,K;cin>>N>>K;
  deque<int> inq;
  for (int i = 0; i < N; i++)
  {
    int X;cin>>X;
    inq.push_back(X); 
  }
  int res = -1*INF;
  for (int a = 0; a <= min(N,K); a++)
  {
    for (int b = 0; a + b <=min(N,K); b++)
    {
      auto q = inq;
      priority_queue<int, vector<int>, greater<int> > pq;
      int d = max(0LL,K - a - b);
            
      int s = 0;
      for (int i = 0; i < a; i++)
      {
        pq.push(q.front());
        s += q.front();
        q.pop_front();
      }

      for (int i = 0; i < b; i++)
      {
        pq.push(q.back());
        s+=q.back();
        q.pop_back();
      }
      
      chmax(res,s);
      
      for (int i = 0; i < d; i++)
      {
        if(pq.empty())break;
        s -=pq.top();
        chmax(res,s);
        pq.pop();  
      }

      
      
    }
    
  }
  cout<<res<<endl;
  

  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 3624
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var INI = int.MaxValue / 2;
            (int N, int M) = Slice2<int>();
            var dp = new long[N, N];
            for (var i = 0; i < N; ++i)
                for (var j = 0; j < N; ++j)
                    if (i != j) dp[i, j] = INI;
            for (var i = 0; i < M; ++i)
            {
                (int a, int b, int c) = Slice3<int>();
                --a; --b;
                dp[a, b] = c;
                dp[b, a] = c;
            }
            var ori = new long[N, N];
            for (var i = 0; i < N; ++i)
                for (var j = 0; j < N; ++j)
                    ori[i, j] = dp[i, j];
            for (var k = 0; k < N; ++k)
                for (var i = 0; i < N; ++i)
                    for (var j = 0; j < N; ++j)
                        if (dp[i, k] + dp[k, j] < dp[i, j]) dp[i, j] = dp[i, k] + dp[k, j];
            var ans = 0L;
            for (var i = 0; i < N; ++i)
                for (var j = i + 1; j < N; ++j)
                    if (INI != ori[i, j] && dp[i, j] < ori[i, j]) ++ans;
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 27492
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    int N;
    cin >> N;
    vector<int> v;
    int c = 0;
    int zero = 0;
    int mi = 0;
    REP(i, N) {
        int t;
        cin >> t;
        if(t < 0)
            mi++;
        if(t == 0) {
            zero++;
        } else {
            v.push_back(abs(t));
        }
    }
    SORT(v);
    LLI sum = 0;
    for(auto f : v) {
        sum += f;
    }
    if(mi % 2 && zero == 0 && 0 < v.size()) {
        sum -= v[0] * 2;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<string>
#include<cctype>

using namespace std;

bool check(string str) {
	if (str[0] != 'A') {
		return false;
	}

	int c_index = str.find("C");
	if (c_index < 2 || str.length() - 2 < c_index) {
		return false;
	}

	int count_A = 0;
	int count_C = 0;
	for (int i = 0; i < str.length(); i++) {
		char s = str[i];

		if (s == 'A') {
			if (count_A == 0) {
				count_A++;
				continue;
			}
			else {
				return false;
			}
		}
		else if (s == 'C') {
			if (count_C == 0) {
				count_C++;
				continue;
			}
			else {
				return false;
			}
		}

		if (!islower(s)) {
			return false;
		}
	}

	return true;
}

int main() {
	string str;

	cin >> str;

	if (check(str)) {
		cout << "AC" << endl;
	}
	else {
		cout << "WA" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();

			long []A = new long[N];

			for(int i = 0;i<N;i++)A[i] = scan.nextLong();

			/*
			int count = 0;
			for(int i = 0;i<N-1;i++) {
				int max = A[i];
				for(int j = i+1;j<N;j++) {
					max = Math.max(A[j], max);
				}

				if(max==A[i])count++;
			}

			if(count==N-1) {
				System.out.println(N);
				return;
			}*/

			long goukei = 1000;

			long motteru = 0;

			for(int i = 0;i<N-1;i++) {


				if(motteru==0) {
					if(A[i]<A[i+1]) {
						motteru=goukei/A[i];
						goukei-=motteru*A[i];
					}
				}else {
					if(A[i]>A[i+1]) {
						goukei+=motteru*A[i];
						motteru=0;
					}
				}

				if(i==N-2) {
					if(motteru==0)continue;
					else {
						goukei+=motteru*A[i+1];
						continue;
					}
				}






			}

			System.out.println(goukei);




		}


	}



}


Measured memory_bytes: 35716
#include <iostream>
#include <string>

using namespace std;

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

	int i;
	string s[n];
	for(i=0; i<n; i++)
	{
		cin >> s[i];
		if(s[i] == "Y")
		{
			cout << "Four" << endl;
			break;
		}
	}

	if(i == n) cout << "Three" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  string l = "qwertasdfgzxcvb", r = "yuiophjklnm", s;
  while (cin >> s && s != "#") {
    string condi = (l.find(s[0]) != string::npos) ? l : r;
    int count = 0;
    for (int i = 1; i < s.size(); ++i) {
      if (condi.find(s[i]) == string::npos) {
        count++;
        condi = (l.find(s[i]) != string::npos) ? l : r;
      }
    }
    cout << count << endl;
  }
  return 0;
}



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

#define ALL(a) a.begin(), a.end()

int n;
vector<int> a, b, c;

void solve() {
  int i;
  ll ans = 0, small, large;

  sort(ALL(a));
  sort(ALL(c));

  for (i = 0; i < n; i++) {
    auto itr_a = lower_bound(ALL(a), b[i]);
    auto itr_c = upper_bound(ALL(c), b[i]);

    small = itr_a - a.begin();
    large = c.end() - itr_c;

    ans += small * large;
  }

  cout << ans << '\n';

  return;
}

int main() {
  int i;

  cin >> n;

  a.resize(n);
  b.resize(n);
  c.resize(n);

  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (i = 0; i < n; i++) {
    cin >> b[i];
  }

  for (i = 0; i < n; i++) {
    cin >> c[i];
  }

  solve();

  return 0;
}

Measured memory_bytes: 1536