akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<cstring>
#define MAXN 200010
using namespace std;
char s[MAXN];
int ans,n;
int main()
{
	scanf("%d%s",&n,s+1);
	int l=1,r=n;
	while(l<r)
	{
		if(s[l]=='W'&&s[r]=='R'){ans++;l++;r--;}
		else if(s[l]=='R'&&s[r]=='W') l++;
		else if(s[l]=='W'&&s[r]=='W') r--;
		else if(s[l]=='R'&&s[r]=='R') l++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3368
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

constexpr ll inf = 1e+15;
int n;
vector<int> a;
ll dp[2][3005][3005];

ll memo_rec(int Turn = 0, int Left = 0, int Right = n){
    if(dp[Turn][Left][Right] != -inf)   return dp[Turn][Left][Right];
    if(Right - Left == 1)   return dp[Turn][Left][Right] = a[Left] * (Turn ? -1 : 1);

    ll res = 0;
    if(Turn == 0){
        ll foo = memo_rec(Turn ^ 1, Left + 1, Right) + a[Left];
        ll bar = memo_rec(Turn ^ 1, Left, Right - 1) + a[Right - 1];
        res = max(foo, bar);
    }
    else{   // Turn == 1
        ll foo = memo_rec(Turn ^ 1, Left + 1, Right) - a[Left];
        ll bar = memo_rec(Turn ^ 1, Left, Right - 1) - a[Right - 1];
        res = min(foo, bar);
    }

    return dp[Turn][Left][Right] = res;
}

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

    cin >> n;
    a.resize(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];

    for(int i = 0; i < 2; ++i){
        for(int j = 0; j < n; ++j){
            for(int k = j + 1; k <= n; ++k){
                dp[i][j][k] = -inf;
            }
        }
    }
    cout << memo_rec() << endl;
}

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

int main(){
    long long int A, B, C, K; cin >> A >> B >> C >> K;
    if(K % 2 == 0) {
        cout << A - B;
    } else {
        cout << B - A;
    }
    return 0;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG

#include"bits/stdc++.h"
using namespace std;

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(int i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(int i=0;i<(ll)(n+1);i++)
#define AToB(i,a,b) for(int i=a;i<(ll)(b+1);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//bitsearch
#define BITSEARCH(bit, n) for (int bit = 0; bit < (1<<n); ++bit)
#define isOne(bit, i) bit & (1<<i)


//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back


#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

//pair
#define fir first
#define sec second

//types
#define ll long long
#define vec vector
#define cord2d pair<int,int>
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(long long a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(char a){ cout << a << endl; }
void print(double a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T = int>
void print(vec<T> v){ cout << v << endl; }

template <class T = int>
void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}}

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 10000007;

//maths
int factorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; }
int gcd(int a, int b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

////////////////////

void Main() {
    //code here
    int n = gi, k = gi;
    vec<int> nums = gim(n);
    vec<int> dp {0};
    AToB(i, 1, n-1) {
        int minV = INT_MAX;
        //print(minV);
        OneToN(dif,min(i, k)) {
            if (dif == 1) minV = abs(nums[i]-nums[i-dif]) + dp[i-dif];
            minV = min(minV, abs(nums[i]-nums[i-dif]) + dp[i-dif]);
        }
        dp.add(minV);
    }
    print(dp[n-1]);
}

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


Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

#define int long long

#if defined(__GNUC__)
#define itn __int32_t
#elif defined(_WIN32)
#define itn __int32
#endif

#define REP(i, n) for(itn (i) = 0; (i) < (n); (i)++)
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); (i)++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x))
#define RSORT(x, T) sort(ALL(x), greater<(T)>())
#define REVERCE(x) reverce(ALL(x))

itn main() {
	ios::sync_with_stdio(false);

	int n, m;

	cin >> n >> m;

	vector<int> box(n, 100000000);

	struct key {
		itn plice;
		itn kindValue;
		itn kind;
	};

	vector<key> keys(m);
	int kind_part;

	for (int i = 0; i < keys.size(); i++) {
		cin >> keys[i].plice >> keys[i].kindValue;
		for (int j = 0; j < keys[i].kindValue; j++) {
			cin >> kind_part;
			keys[i].kind |= 1 << (kind_part - 1);
		}
	}

	vector<vector<itn>> dp(m + 1);

	REP(i, dp.size()) {
		dp[i].resize(pow(2, n), pow(2, 30));
	}

	dp[0][0] = 0;

	REP2(i, 1, dp.size()) {
		REP(j, dp[i].size())dp[i][j] = dp[i - 1][j];
		REP(j, dp[i].size()) {
			dp[i][j | keys[i - 1].kind] = min(dp[i - 1][j] + keys[i - 1].plice, dp[i][j | keys[i - 1].kind]);
		}
	}

	if (dp[m][pow(2, n) - 1] == pow(2, 30)) {
		cout << -1;
	}
	else {
		cout << dp[m][pow(2, n) - 1];
	}

	return 0;
}

Measured memory_bytes: 16384
package main

import (
	"fmt"
)

func main() {

	var h, w int
	fmt.Scanf("%d %d", &h, &w)

	maze := make([][]bool, h)
	for i := 0; i < h; i++ {
		line := make([]bool, w)
		var s string
		fmt.Scanf("%s", &s)
		for j, c := range s {
			if c == '.' {
				line[j] = true
			}
		}
		maze[i] = line
	}

	max := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if !maze[i][j] {
				continue
			}
			_, _, d := farthest(maze, i, j)
			if d > max {
				max = d
			}
		}
	}

	fmt.Printf("%d\n", max)
}

type point struct {
	i int
	j int
}

type node struct {
	point point
	dist  int
}

func farthest(maze [][]bool, oi, oj int) (int, int, int) {

	mi, mj, md := oi, oj, 0

	origin := point{i: oi, j: oj}
	queue := []node{node{point: origin, dist: 0}}
	visited := map[point]struct{}{}

	for len(queue) > 0 {
		n := queue[0]
		queue = queue[1:]

		if _, ok := visited[n.point]; ok {
			continue
		}

		visited[n.point] = struct{}{}
		i, j, dist := n.point.i, n.point.j, n.dist

		if dist > md {
			mi, mj, md = i, j, dist
		}

		if i > 0 && maze[i-1][j] {
			queue = append(queue, node{point: point{i: i - 1, j: j}, dist: dist + 1})
		}
		if i < len(maze)-1 && maze[i+1][j] {
			queue = append(queue, node{point: point{i: i + 1, j: j}, dist: dist + 1})
		}
		if j > 0 && maze[i][j-1] {
			queue = append(queue, node{point: point{i: i, j: j - 1}, dist: dist + 1})
		}
		if j < len(maze[i])-1 && maze[i][j+1] {
			queue = append(queue, node{point: point{i: i, j: j + 1}, dist: dist + 1})
		}

	}

	return mi, mj, md
}


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

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

    ll n;
    cin >> n;
    ll base = 2;
    string res ="";

    if(!n){
        puts("0");
        return 0;
    }

    while(n){
        if(n%base) res = "1" + res;
        else res = "0" + res;
        n = (n-abs(n%base)) / -2;
    }
    cout << res << endl;
    return 0;
}

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

int main(){
  int n;
  double x[1000], ab[1000];
  double p1=0, p2=0, p3=0, pinf=0;
  cin >> n;
  for(int i=0; i<n; i++) cin >> x[i];
  for(int i=0; i<n; i++){
    cin >> ab[i];
    ab[i] = fabs(ab[i] - x[i]);
    p1 += ab[i];
    p2 += pow(ab[i], 2);
    p3 += pow(ab[i], 3);
    if(ab[i] > pinf) pinf= ab[i];
  }
  p2 = sqrt(p2);
  p3 = pow(p3, 1.0/3.0);
  printf("%f\n%f\n%f\n%f\n", p1, p2, p3, pinf);
  return 0;
}



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

map <string, int> s;
int n;
string a;
vector<string>v;

int main()
{
	cin >> n;
	for(int i=0; i<n; i++)
	{
		cin >> a;
		if(s.find(a) != s.end())
		{
			auto it = s.find(a);
			s[it->first]++; 
		}
		else
		s.insert(make_pair(a,0));
	}

	int maxi = -1;
	for(auto it = s.begin(); it != s.end(); ++it)
	{
		if((it->second) > maxi)
			maxi = it->second;

		//cout << maxi << '\n';
	}

	for(auto it = s.begin(); it != s.end(); ++it)
	{
		if(it->second == maxi)
			v.push_back(it->first);
	}

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

	for(int i=0; i<v.size(); i++)
		cout << v[i] << '\n';

	
}

Measured memory_bytes: 27252
a = int(input())

guidebook = {}
for i in range(a):
    li = list(input().split())
    if li[0] in guidebook:
        guidebook[li[0]][i+1] = int(li[1])
    else:
        guidebook[li[0]] = {i + 1: int(li[1])}

shop_sorted = sorted(guidebook.items(), key=lambda x: x[0])

for rural in shop_sorted:
    # print(rural[1])
    score_sorted = sorted(rural[1].items(), key=lambda x: x[1], reverse=True)
    # print(score_sorted)
    for i in score_sorted:
        print(i[0])


Measured memory_bytes: 38384
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) &= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
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); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int H, W;
  cin >> H >> W;
  int cont = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char tmp;
      cin >> tmp;
      if (tmp == '#') cont++;
    }
  }

  if (cont == H + W - 1) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    REP(i,h) cin >> s[i];
    VVI ans(h, VI(w, -1));
    int p = -1, cnt = 0;
    REP(i,h){
        VI x;
        REP(j,w){
            if (s[i][j] == '#') x.push_back(j);
        }
        if (x.empty()) continue;
        int d = 0;
        for (int y : x){
            FOR(j,d,y) ans[i][j] = cnt;
            cnt++;
            d = y + 1;
        }
        FOR(j,x.back(),w-2) ans[i][j+1] = ans[i][j];
        FORR(ii,i-1,p+1) REP(j,w) ans[ii][j] = ans[ii + 1][j];
        p = i;
    }
    FOR(ii,p+1,h-1) REP(j,w) ans[ii][j] = ans[ii - 1][j];
    REP(i,h){
        REP(j,w) printf("%d ", ans[i][j] + 1);
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;


/*void printvec(vector<int> v) {
	int a = v.size();
	for (int i = 0; i < a; i++) {
		printf("%d ", v[i]);
	}
	printf("\n");
}*/


int main(){
	int N,min=10000000,count=0;
	cin >> N;
	vector<int> P(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> P[i];
		if (P[i] <= min) {
			count++;
			min = P[i];
		}
	}
	cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

const int N=3000+19;
const int p=1e9+7;

int C[N][N];
int A[N],S[N],F[N][N];
int n,m,l,r,res;
char s[N];

void Upd(int &x,int y){
	x=(x+y)%p;
}

int main(){
	For(i,0,N){
		C[i][0]=1;
		For(j,1,i+1) C[i][j]=(C[i-1][j-1]+C[i-1][j])%p;
	}
	n=IN(),m=IN();
	scanf("%s",s+1);
	For(i,1,n+1) S[i]=S[i-1]+(s[i]=='1');
	For(i,1,n+1) A[i]=i;
	For(i,1,m+1){
		l=IN(),r=IN();
		A[l]=max(A[l],r);
	}
	For(i,1,n+1) A[i]=max(A[i],A[i-1]);
	F[1][S[A[1]]]=1;
	For(i,1,n){
		For(j,0,n+1)
			if (F[i][j]){
				if (j<A[i]-i+1) Upd(F[i+1][j+S[A[i+1]]-S[A[i]]],F[i][j]);
				if (j>0) Upd(F[i+1][j-1+S[A[i+1]]-S[A[i]]],F[i][j]);
			}
	}
	printf("%d\n",(F[n][0]+F[n][1])%p);
}

Measured memory_bytes: 40448
#include<iostream>
using namespace std;
int gcd(int a,int b){
  if(a<b)return gcd(b,a);
  else if(a%b)return gcd(b,a%b);
  else return b;
}
int main(){
  int n;
  cin>>n;
  int a;
  cin>>a;
  int x=a;
  for(int i=0; i<n-1; i++){
    cin>>a;
    x=gcd(a,x);
  }
  cout<<x<<endl;

}


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

bool operators[4] = {};
int a, b, c, d;
string s;

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

void dfs(int i, int sum, bool o[4]) {
    // 合計が7ならoperatorsにコピー
    if(i == 4) {
        if(sum == 7) {
            for (int c = 0; c < 4; c++) {
                operators[c] = o[c];
            }
        }
    } else {
        bool a1[4];
        for (int c = 0; c < 4; c++) {
            a1[c] = o[c];
        }
        a1[i] = false;
        dfs(i+1, sum-ctoi(s[i]), a1);

        bool a2[4];
        for (int c = 0; c < 4; c++) {
            a2[c] = o[c];
        }
        a2[i] = true;
        dfs(i+1, sum+ctoi(s[i]), a2);
    }
}

int main() {
    cin >> s;

    bool b[4] = {};

    dfs(1, ctoi(s[0]), b);

    cout << s[0];
    for(int i = 1; i < 4; i++) {
        if(operators[i]) cout << '+';
        else cout << '-';
        cout << s[i];
    }
    cout << "=7";
}


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

class Program
{
    static void Main(string[] args) {
#if DEBUG
        System.Diagnostics.Debug.WriteLine("-----TextFile1");
        System.Diagnostics.Debug.WriteLine(process("../TextFile1.txt"));
        System.Diagnostics.Debug.WriteLine("-----TextFile2");
        System.Diagnostics.Debug.WriteLine(process("../TextFile2.txt"));
        System.Diagnostics.Debug.WriteLine("-----TextFile3");
        System.Diagnostics.Debug.WriteLine(process("../TextFile3.txt"));
#endif

#if !DEBUG
        String ret = process(new System.IO.StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static string process(string filePath) {
        using (var input = new System.IO.StreamReader(filePath)) {
            if(input.EndOfStream) return "NO PROC";
            return process(input);
        }
    }

    static string process(System.IO.TextReader input) {
        int n     = int.Parse(input.ReadLine());
        int r = 800 * n - 200 * (n / 15);
        return "" + r;
    }
    
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    cout << min(A,B) + min(C,D) << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N+1);
  int h_max = 0;
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
    h_max = max(h_max,vec.at(i));
  }
  int cnt = 0;
  for(int i=0; i<h_max; i++){
    for(int j=0; j<N; j++){
      if(vec.at(j) > 0 && vec.at(j+1) <= 0){
        cnt++;
      }
      vec.at(j)--;
    }
  }
  cout << cnt << endl;
}

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

int main(){
    long long N,K;
    cin >> N >> K;

    //if(N<K/2){
      //  cout << 0 <<endl;
        //return 0;
    //}
    long long n = 0;
    //int k = N;
    /*while(k >= K){
        k -= K;        
        n++;
    }*/
    n = N / K;
    long long m =0;
    long long ans = 0;
    if(K%2 == 1){
        ans = n*n*n;
    }else{
        m = N /(K/2) - N/K;
        ans = m*m*m;
/*        if(N >= K*n + K/2){
            ans = (n+1)*(n+1)*(n+1);
        }else{
            ans = n*n*n;
        }*/
        ans += n*n*n;//n==0 -> ans=1
    }
    cout << ans << endl;

}
/*
a+b = kx
b+c = ky
c+a = kz
2(a+b+c)= k(x+y+z)
*/


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

#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
 
using namespace std;

int32_t main(){
    int n;
    string s, t;
    cin >> n;
    cin >> s >> t;

    int cnt=0;
    REP(i, n){
        if(s[i]==t[0]){
            string st1="", st2="";
            FOR(j, i, n){
                st1+=s[j];
            }
            REP(j, n-i){
                st2+=t[j];
            }

            if(st1==st2){
                cnt=max(cnt, (int)st1.length());
            }
        }
    }

    cout << (int)s.length()*2-cnt << endl;
}

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

using namespace std;


int main()
{
	// 入力
	long N;
	cin >> N;
	
	string answer = "";
	
	while (N != 0)
	{
		// Nを2で割った余りを計算する
		// nには0、-1が入る
		long n = N % 2;
		
		// Nが負の場合の対策
		if (n < 0)
		{
			n += 2;
		}
		
		answer += (char)('0' + n);
		
		// Nから余りを取り除いて-2で割る
		N = (N - n) / (-2);
	}
	
	// 1桁目から文字列を追加しているので、文字列を反転します。
	reverse(answer.begin(), answer.end());
	
	// N = 0の場合の例外対応
	if (answer == "")
	{
		answer = "0";
	}
	
	// 出力
	cout << answer << endl;
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	long long ans{};
	int mx{};
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		mx = max(mx, x);
		if (i) ans += mx - x;
	}
	cout << ans;
}

Measured memory_bytes: 3696
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;

#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;

const int d5 = 200100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin>>n>>s;
    int dp[d5];
    fill(dp,dp+d5,0);
    int cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]=='#'){
            cnt++;
        }
        dp[i]=cnt;
    }
    int dw[d5];
    fill(dw,dw+d5,0);
    cnt=0;
    for(int i=n-1;i>=0;i--){
        if(s[i]=='.'){
            cnt++;
        }
        dw[i]=cnt;
    }
    /* for(int i=0;i<10;i++){
        cout<<dp[i]<<' ';
    }
    cout<<endl;
    for(int i=0;i<10;i++){
        cout<<dw[i]<<' ';
    }
    cout<<endl; */
    int res=min(cnt,n-cnt);
    for(int i=1;i<n;i++){
        res=min(res,dp[i-1]+dw[i]);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 2196
using System;

class Atcoder50
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int c = int.Parse(input[2]);

        if (c - a >= 0 && b - c >= 0)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}

Measured memory_bytes: 11092
use std::cmp::min;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();

    let mut count1 = 0;
    for (i, c) in s.chars().enumerate() {
        if i % 2 == 0 && c == '0' {
            count1 += 1;
        }
        if i % 2 == 1 && c == '1' {
            count1 += 1;
        }
    }

    let mut count2 = 0;
    for (i, c) in s.chars().enumerate() {
        if i % 2 == 0 && c == '1' {
            count2 += 1;
        }
        if i % 2 == 1 && c == '0' {
            count2 += 1;
        }
    }

    println!("{}", min(count1, count2));
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
s=input()
a=int(s[:2])
b=int(s[2:])

if 1<=a and a<=12:
  if 1<=b and b<=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 1<=b and b<=12:
    print("YYMM")
  else:
    print("NA")


Measured memory_bytes: 2940
# 解説AC
def solve():
    n=int(input())
    a=list(map(int,input().split()))
    s=input()
    basis=[]
    for i in range(n-1,-1,-1):
      	# 基底を求める
        for e in basis:
            a[i]=min(a[i],a[i]^e)
        if a[i]:
            if s[i]=="0":
                basis.append(a[i])
            else:
                print(1)
                return
    print(0)

t=int(input())
for _ in range(t):
    solve()

Measured memory_bytes: 8984
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

cnt = 0
for i in b:
	x = bisect.bisect_left(a,i)
	y = bisect.bisect_right(c,i)
	cnt += x*(n-y)
print (cnt)

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

using namespace std;

#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define F first
#define S second
#define pb push_back

typedef long long ll;
typedef pair <int, int> pii;
typedef long double ld;
typedef vector <ll> vi;

const int N = 2e6 + 1;
const ll INF = 1e18 + 9;
const int B = 1e9 + 7;

int n;
int a[N];

int main() {
    #ifdef black
    freopen("in", "r", stdin);
    #endif // black
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    int e = 0, o = 0;
    forn(i, 1, n) {
        cin >> a[i];
        if (a[i] % 2 == 0) ++e;
        else ++o;
    }
    if (n == 1 || o % 2 == 0)
        cout << "YES\n";
    else
        cout << "NO\n";

    return 0;
}


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

int main() {
  string a, b;
  cin >> a >> b;
  
  int pass = 0;
  if(a.size() > b.size()){
    cout << "GREATER" << endl;
    pass++;
  }
  else if(a.size() < b.size()){
    cout << "LESS" << endl;
    pass++;
  }
  
  if(pass == 0){
    int i = 0, check = 0;
    while(i < a.size()){
      if(a.at(i) > b.at(i)){
        check = 1;
        break;
      }
      else if(a.at(i) < b.at(i)){
        check = -1;
        break;
      }
      i++;
    }
  
  if(check == 1) cout << "GREATER" << endl;
  else if(check == -1) cout << "LESS" << endl;
  else cout << "EQUAL" << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>  // assert(x>=10), 部分点問題
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <set>

#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
#define SORT(v,n) sort(v,v+n)
#define VSORT(v) sort(all(x))
#define FILL(v, value) (v+(sizeof(v) / sizeof *(v)), value);
#define inf 999999999
#define dbg(x) cout<<#x<<":"<<x<<endl;
#define pb(a) push_back((a))
#define mp(a) make_pair((a))
#define pi 2*acos(0.0)
#define in scanf
#define out printf
#define fi first
#define se second

// --
#define bit(n) (1LL<<(n)) // 左bitシフト
// --

using namespace std;

typedef long long llong;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<llong, pll> plp;

const int MOD=1000000007;
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};  // 右下左上


int main(int argc, char**argv){

  long n, c, k;
  cin >> n >> c >> k;
  vector<int> t;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    t.push_back(tmp);
  }
  t.push_back(inf);
  sort(all(t));
  // rep(i, n){
    // cout << i << ':';
    // cout << t[i] << endl;
  // }

  int ans = 0;
  int rider = 0;
  int pri_bus_time = 0;
  int first_time = 0;
  bool gone = true;
  rep(i, n){
    if (gone) {
      first_time = t[i];
      gone = false;
    }
    rider++;;
    // dbg(rider);
    if (rider >= c || t[i+1] - first_time > k){
      // bus go
      // cout << "go";
      // dbg(rider);
      ans++;
      rider = 0;
      gone = true;
    }
    if (i == n-1 && gone == false) ans++;
  }

  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 892
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        A: [u64; N],
        B: [u64; N],
    }
    let mut ans = 0;
    for i in 0..N{
        let mut total = 0;
        for j in 0..i+1{
            total += A[j];
        }
        for j in i..N{
            total += B[j]
        }
        ans = max(ans,total);
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using Int = signed;
using ll = long long;
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  Int n,m;
  cin>>n>>m;

  m++;
  vector<Int> a(m),b(m);
  for(Int i=0;i<m;i++) cin>>a[i];
  for(Int i=1;i<m;i++) cin>>b[i];

  vector<ll> hs;
  function<void(Int, Int)> predfs=[&](Int l,Int r){
    Int x=lower_bound(a.begin(),a.end(),r)-a.begin();
    if(a[x-1]<=l&&r<=a[x]) return;
    
    hs.emplace_back(((ll)l<<31)|r);
    Int m=(l+r)>>1;
    predfs(l,m);
    predfs(m,r);
  };

  predfs(0,(1<<n));
  sort(hs.begin(),hs.end());
  hs.erase(unique(hs.begin(),hs.end()),hs.end());
  map<ll, Int> idx;
  for(Int i=0;i<(Int)hs.size();i++) idx[hs[i]]=i;
  //cout<<hs.size()<<endl;
  
  vector<vector<Int> > dp(n+1,vector<Int>(hs.size(),-1));
  
  function<Int(Int, Int, Int, Int)> dfs=[&](Int l,Int r,Int d,Int k)->Int{
    //cout<<l<<" "<<r<<" "<<d<<" "<<k<<endl;
    Int x=lower_bound(a.begin(),a.end(),r)-a.begin();
    if(a[x-1]<=l&&r<=a[x]){
      Int v=b[x],tmp=0;
      tmp+=(k==v);
      tmp+=(r-l)>>(n-v+1);
      return tmp;
    }

    if(~dp[k][idx[((ll)l<<31)|r]]) return dp[k][idx[((ll)l<<31)|r]];
    Int &res=(dp[k][idx[((ll)l<<31)|r]]=0);
    
    Int m=(l+r)>>1;
    res=max(res,dfs(l,m,d+1,d)+dfs(m,r,d+1,k));
    res=max(res,dfs(l,m,d+1,k)+dfs(m,r,d+1,d));
    return res;
  };
  
  cout<<(1<<n)-dfs(0,1<<n,1,0)<<endl;
  return 0;
}




Measured memory_bytes: 33268
/**
 *    author:  FromDihPout
 *    created: 2020-09-11
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    priority_queue<int> price;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        price.push(x);
    }
    
    for (int i = 0; i < m; i++) {
        int p = price.top();
        price.pop();
        p /= 2;
        price.push(p);
    }
    
    long long ans = 0;
    while (!price.empty()) {
        ans += price.top();
        price.pop();
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int n;
  cin >> n;
  
  vector<int> v(n);
  
  for(int i = 0; i < n; i++){
    cin >> v.at(i);
  }
  
  int j, k = 0;
  
  while(j < n - 1){
    if((v.at(j) > v.at(j + 1)) || ((j > 0) && (v.at(j) >= v.at(j + 1)) && (v.at(j - 1) < v.at(j)))){
      v.at(j)--;
    }
    j++;
  }
  
  while(k < n - 1){
    if(v.at(k) <= v.at(k + 1)){
      k++;
    }
    else{
      break;
    }
  }
  
  if(k == n - 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
  

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

using namespace std; 

#define N 100000

long long a[N]; 

int main() {

	long long sum = 0, minimum = 1e18; 

	int negCount = 0; 

	int n; 

	cin >> n; 

	for(int i = 1; i <= n; i++) {

		cin >> a[i]; 

		sum += abs(a[i]); 

		if(a[i] < 0) {
			negCount++; 
		}
		minimum = min(minimum, abs(a[i])); 

	}

	if(negCount%2 != 0) {
		sum -= 2*minimum; 
	}

	cout << sum << endl; 


	return 0; 
}

Measured memory_bytes: 1024
//There was and will only be one Chester
//RIP legend
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    int even=0,odd=0,four=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]%2==1)
            odd++;
        else if(a[i]%2==0)
        {
            if(a[i]%4==0)
                four++;
            else
                even++;
        }
    }
    if(even==0)
    {
        if(odd<=four+1)
            cout<<"Yes";
        else
            cout<<"No";

    }
    else if(even>0)
    {
        if(odd<=four)
            cout<<"Yes";
        else
            cout<<"No";
    }

}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
static const int MAX_H = 100;
static const int MAX_W = 100;
void dfs(int H, int W, int y, int x, char ch, char field[][MAX_W]){
  field[y][x] = '.';
  int dx[] = {1, 0, -1, 0};
  int dy[] = {0, -1, 0, 1};
  for(int i = 0; i < 4; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
    if(field[ny][nx] == ch) dfs(H, W, ny, nx, ch, field);
  }
  return ;
}
int main(){
  for(;;){
    int H, W;
    char field[MAX_H][MAX_W];
    cin >> H >> W;
    if(H == 0 && W == 0) break;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	cin >> field[i][j];
      }
    }
    int cnt = 0;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	if(field[i][j] != '.'){
	  dfs(H, W, i, j, field[i][j], field);
	  cnt++;
	}
      }
    }
    cout << cnt << endl;
  }
  return 0;
}



Measured memory_bytes: 4236
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int H = scan.nextInt();
        int W = scan.nextInt();
        while (H != 0 || W != 0) {
            for (int x = 1; x <= H; x++) {
                for (int y = 1; y <= W; y++) {
                    if (x % 2 == 1 && y % 2 == 0 || x % 2 == 0 && y % 2 == 1) {
                        System.out.print(".");

                    } else {
                        System.out.print("#");
                    }
                }
                System.out.println("");
            }
            System.out.println("");

            H = scan.nextInt();
            W = scan.nextInt();

        }
    }
}



Measured memory_bytes: 35076
let pn = 1000000007

let pow x n =
  let rec doit x n acc =
    if n = 0 then acc
    else if n mod 2 = 0 then doit (x * x) (n / 2) acc
    else doit (x * x) (n / 2) (acc * x) in
  doit x n 1

let fold_left f init s n =
  let rec doit i acc =
    if i = n then acc
    else doit (i + 1) (f acc s.[i]) in
  doit 0 init

let () =
  let p = read_line () in
  let t = read_line () in
  let n = String.length p in
  let m = String.length t in
  let h = Array.make (n + 1) 0 in
  let hash x c = x * pn + Char.code c mod pn in
  String.iteri (fun i c -> h.(i+1) <- hash h.(i) c) p;
  let v = fold_left hash 0 t m in
  let x = pow pn m in
  for i = 0 to n - m do
    if h.(i+m) - h.(i)*x = v then Printf.printf "%d\n" i;
  done

Measured memory_bytes: 14380
import java.util.Scanner;

public class Main {

	static void printArray(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);

			if (i != a.length - 1) {
				System.out.print(" ");
			}
		}
		System.out.println();
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] A = new int[n];

		for (int i = 0; i < n; i++) {
			A[i] = scan.nextInt();
		}

		printArray(A);
		for (int i = 1; i < n; i++) {
			int key = A[i];
			int j;
			for (j = i - 1; j >= 0 && A[j] > key; j--) {
				A[j+1] = A[j];
			}
			A[j+1] = key;
			printArray(A);
		}

		scan.close();
	}

}

Measured memory_bytes: 25976
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << a * b / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(cin>>n,n){
    bool b[21][21] = {{0}};
    int m;
    REP(i,n){
      int x,y; cin>>x>>y;
      b[y][x] = true;
    }
    int x,y;
    x = 10; y = 10;
    if(b[y][x]){
      b[y][x] = false;
      n--;
    }
    cin >> m;
    REP(i,m){
      char c;
      int  w;
      cin>>c>>w;
      REP(j,w){
        if(c == 'N'){
          y++;
        }else if(c == 'E'){
          x++;
        }else if(c == 'W'){
          x--;
        }else if(c == 'S'){
          y--;
        }
        if(b[y][x]){
          b[y][x] = false;
          n--;
        }
      }
    }
    if(n==0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
#define INFLL        1e18
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
using ull=unsigned long long;
template<typename T>using pqg=priority_queue<T,vector<T>,greater<T>>;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

void yakusu(ll n,vector<ll>&y)
{
    for(ll i=1;i*i<=n;++i){
        if(n%i==0){
            y.push_back(i);
            if(i!=n/i)y.push_back(n/i);
        }
    }
}
int main()
{
    ll n=in(),k=in(),sum=0;
    vector<ll>a(n);
    REP(i,n)sum+=a[i]=in();

    vector<ll>y;
    y.reserve(sqrt(sum)*2);
    yakusu(sum,y);
    sort(ALL(y));

    ll ans=0;
    vector<ll>ar(n);
    REPR(i,y.size()){
        ll rsum=0;
        REP(j,n)rsum+=ar[j]=a[j]%y[i];
        ll statue=rsum/y[i];
        sort(ALL(ar),greater<ll>());
        ll cnt=0;
        for(ll j=statue;j<n;++j)cnt+=ar[j];
        if(cnt<=k)ans=max(ans,y[i]);
    }
    cout<<ans<<endl;
}


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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

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

  int K;
  cin >> K;

  int reminder = 0;

  EACH(i,1,K) {
    reminder = (reminder * 10 + 7) % K;
    if (reminder == 0) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}

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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)
using namespace std;
typedef unsigned char byte;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<llong, llong> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

using namespace std;


int main(){
    int n, l;
    cin >> n >> l;
    map<string, int> strs;

    FOR(i, 0, n) {
        string str;
        cin >> str;
        strs[str];
        strs[str]++;
    }

    FOR_ITER(i, strs) {
        FOR(j, 0, i->se) {
            cout << i->fi;
        }
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  sc.Scan()
  a, e := strconv.Atoi(sc.Text())
  if e != nil {
    panic(e)
  }
  sc.Scan()
  b, e := strconv.Atoi(sc.Text())
  if e != nil {
    panic(e)
  }
  sc.Scan()
  t, e := strconv.Atoi(sc.Text())
  if e != nil {
    panic(e)
  }


  fmt.Println(t / a * b)
}


Measured memory_bytes: 640
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		int n=sc.nextInt();
		sc.useDelimiter("(\\s)+|[:]");
		for(int i=0; i<n; i++){
			double h=sc.nextInt()*30;
			double m=sc.nextInt()*6;
			h+=m/12;
			double d=Math.abs(h-m);
			d=Math.min(d, 360-d);
			if(d+EPS<30){
				println("alert");
			}else if(d+EPS>=90&&d<=180+EPS){
				println("safe");
			}else{
				println("warning");
			}
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
def myAnswer(A:int,B:int,C:int) -> int:
   for i in range(1,B+1):
      if(A*i % B == C):
         return "YES"
   else:
      return "NO"

def modelAnswer():
   return
def main():
   A,B,C = map(int,input().split())
   print(myAnswer(A,B,C))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1000000007;
int factor[1000];
main(){
    int N;
    ll ans = 1;
    cin >> N;
    for(int i = 2;i <= N;i++){
        int num = i;
        rep:
        for(int j = 2;j < 1000;j++){
            if(num % j == 0){
                factor[j]++;
                num /= j;
                goto rep;
            }
        }
    }
    for(int i = 0;i < 1000;i++){
        ans = (ans*(factor[i]+1)) % MOD; 
    }
    cout << ans << endl;
}

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

typedef long long ll;

struct Edge{
    int to, cost;
    Edge() {}
    Edge(int t, int c) : to(t), cost(c) {}
};

#define INF 1ll<<60

int main(){
    int v, e, r;
    scanf("%d %d %d", &v, &e, &r);
    
    vector<vector<Edge>> path(v);

    int s, t, d;
    for(int i = 0; i < e; i++){
        scanf("%d %d %d", &s, &t, &d);
        path[s].push_back(Edge(t,d));
    }

    ll dist[v];
    for(int i = 0; i < v; i++)  dist[i] = INF;
    dist[r] = 0;

    priority_queue<pair<ll,int>> pq;
    for(int i = 0; i < v; i++)  pq.push({-dist[i], i});

    while(!pq.empty()){
        pair<ll,int> now = pq.top(); pq.pop();
        ll cost = -now.first;
        int pos = now.second;
        if(dist[pos] < cost)    continue;

        for(Edge e : path[pos]){
            if(cost + e.cost < dist[e.to]){
                dist[e.to] = cost + e.cost;
                pq.push({-dist[e.to], e.to});
            }
        }
    }

    for(int i = 0; i < v; i++){
        if(dist[i] != INF)  printf("%d\n", dist[i]);
        else                printf("INF\n");
    }

    return 0;
}


Measured memory_bytes: 16500
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    set<string> s;
    string a; cin >> a;
    s.insert(a);
    for(int i = 0; i < n - 1; ++i) {
        string x; cin >> x;
        s.insert(x);
        if(a[a.size() - 1] != x[0]) {
            cout << "No"; return 0;
        }
        a = x;
    }cout << (s.size() == n ? "Yes" : "No");
}


Measured memory_bytes: 256
n = gets.to_i
dic = []
n.times do |i|
  s,p = gets.chomp.split(" ")
  dic.push([s,p,i+1])
end
dic.sort_by!{|x| [x[0],-x[1].to_i] }
n.times do |i|
  puts dic[i][2]
end


Measured memory_bytes: 14228
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int ans = n * n - a;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256