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

queue<pair<int, pair<int, int>>> q; //first int distance, second int current node location

int g[1000][1000];
int dist[1000][1000];

//vector<int> g[200005];

vector<char> input[1000];

int dr[4] = {1, -1, 0, 0};
int dc[4] = {0, 0, 1, -1};

int main()
{

    int h, w;

    int count = 0;

    cin >> h >> w;

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            char inp;
            cin >> inp;
            if (inp == '.')
            {
                g[j][i] = 0;
            }
            else
            {
                g[j][i] = 1;
                q.push(make_pair(0, make_pair(j, i)));
            }
        }
    }

    //changes all elements of array into 0/-1
    memset(dist, -1, sizeof(dist)); // works only for 0 or -1

    while (!q.empty())
    {
        int d = q.front().first, x = q.front().second.first, y = q.front().second.second;

        q.pop();

        if (dist[x][y] != -1)
        {
            continue;
        }

        g[x][y] = 1;

        dist[x][y] = d;

        for (int i = 0; i < 4; i++)
        {
            if (x + dr[i] < w && x + dr[i] >= 0 && y + dc[i] < h && y + dc[i] >= 0)
            {
                q.push(make_pair(d + 1, make_pair(x + dr[i], y + dc[i])));
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (dist[j][i] > ans)
            {
                ans = dist[j][i];
            }
            // cout << dist[j][i];
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 56392
#include<stdio.h>
int main(){
	int a;
	while(scanf("%d",&a),a){
		int val=0;
		for(int i=0;i<12;i++){
			int b,c;
			scanf("%d%d",&b,&c);
			a-=(b-c);
			if(a<=0&&val==0){
				val=i+1;
			}
		}
		if(val==0)printf("NA\n");
		else printf("%d\n",val);
	}
}

Measured memory_bytes: 0
#include<stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	double value[n+1];
	for(int i=1; i<=n; i++){
		scanf("%lf", &value[i]);
	}
	
	double min;
	int minn;
	for(int i=1; i<=n; i++){
		min=value[i], minn=i;
		for(int j=i+1; j<=n; j++){
			if(min > value[j]){
				min = value[j];
				minn= j;
			}
		}
		value[minn] = value[i];
		value[i] = min;
	}
	
	double final=0;
	final += (value[1]+value[2])/2;
	for(int i=3; i<=n; i++){
		final = (final+value[i])/2;
	}
	printf("%lf", final);
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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



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

    ((a*b)%2 == 0)? P("Even") : P("Odd");
	
	return  0;
}

Measured memory_bytes: 256
import java.math.*;
import java.util.*;
public class Main {
    public static void main(String args[])
    {
        Scanner input = new Scanner(System.in);
        String s1 = input.nextLine();
        String s2 = input.nextLine();
        if(s1.equals(s2.substring(0,s2.length()-1))==true)
            System.out.print("Yes");
        else{
            System.out.print("No");
        }
    }
   
}

Measured memory_bytes: 35736
from collections import deque
def dfs(N):
    stack=deque(["3","5","7"])
    cnt=0
    while stack:
        cand=stack.pop()
        if all(cand.count(c)>0 for c in "357"):
            cnt+=1
        for c in "357":
            if int(cand+c)<=N:
                stack.append(cand+c)
    return cnt
if __name__=="__main__":
    N=int(input())
    print(dfs(N))

Measured memory_bytes: 3444
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <list>
#include <cmath>
#include <stack>
#include <queue>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int main()
{
	int n, k;
	cin >> n >> k;
	int count = 0;
	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		if (tmp >= k)
		{
			count++;
		}
	}
	cout << count;
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

// これはAC。いちおう解説動画見る
int main() {
    int n;
    cin >> n;
    int a[26] = {0};
    for(int i = 0; i < 26; i++) {
        a[i] = 1e6;
    }

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < 26; j++) {
            a[j] = min(a[j], (int)count(s.begin(), s.end(), j+'a'));
        }
    }

    string ans;
    for (int i = 0; i < 26; i++) {
        ans += string(a[i], i+'a');
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

#include <iostream>
#include <string>

using namespace std;

int N;

double x[15];
string u[15];
double e = 380000;

int main(){
	cin >> N;
	double ans = 0;
	for(int i = 0; i < N; i++){
		cin >> x[i] >> u[i];
		if(u[i] == "JPY"){
			ans += x[i];
		}else{
			ans += x[i]*e;
		}
	}
	printf("%.11f\n",ans);
	return 0;
}


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

int main() {
    int N;
    string S;

    cin >> N >> S;

    if(N%2 == 0){
        for(int i=0; i<N/2; i++){
            if(S.at(i) != S.at(i+(N/2))) {
                cout << "No" << endl;
                return 0;
            } 
        }

        cout << "Yes" << endl;
        return 0;
    }
    else{
        cout << "No" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector<vector<int>> da(500, vector<int>(500,0));
int n;

int bfs(int s, int used[500][500]){
  used[s/n][s%n]=0;
  queue<P> q;
  q.push({s/n,s%n});
  int res = inf;
  while(!q.empty()){
    auto p = q.front(); q.pop();
    rep(i,4){
      int nx = p.F+dx[i];
      int ny = p.S+dy[i];
      if(nx<0 || n<=nx || ny<0 || n<=ny){ res = min(res, used[p.F][p.S]); if(res==0){return 0;} continue;}
      if(used[nx][ny]<=used[p.F][p.S] + (da[nx][ny]==1?1:0)){ continue; }
      used[nx][ny] = used[p.F][p.S] + (da[nx][ny]==1?1:0);
      q.push({nx,ny});
    }
  }
  return res;
}

int main(){
  cin >> n;
  vector<int> p(n*n);
  rep(i,n*n){
    cin >> p[i]; p[i]--;
  }
  ll ans= 0;

  vector<vector<int>> g(n, vector<int>(n,1));
  vector<vector<int>> a(n, vector<int>(n));
  rep(i,n)rep(j,n){
    a[i][j] = min(min(i,j),min(n-1-i,n-1-j))+1;
  }
  auto update = [&](int x, int y){
    queue<P> q;
    q.push({x,y});
    while(!q.empty()){
      auto p = q.front(); q.pop();
      rep(i,4){
        int nx = p.F+dx[i];
        int ny = p.S+dy[i];
        if(nx<0 || n<=nx || ny<0 || n<=ny){ continue; }
        if(a[nx][ny] <= a[p.F][p.S]+g[p.F][p.S] ){ continue; }
        a[nx][ny] = a[p.F][p.S]+g[p.F][p.S];
        q.push({nx,ny});
      }
    }
  };

  rep(i,n*n){
    ans += a[p[i]/n][p[i]%n] - 1;
    g[p[i]/n][p[i]%n] = 0;
    update(p[i]/n, p[i]%n);
  }
  cout << ans << endl;
  return 0;  
}

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

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)


void func(std::string S){
    string t(S.size(),'x');
    cout << t << endl;
}

int main(){
    // cout << fixed << setprecision(5);

    std::string S;
    std::cin >> S;
    func(S);
    return 0;
}


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

int main() {
	int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());

    int cnt=0,sum=0;
    for(int i=0;i<n;i++){
        if(sum+a[i]<k){
            sum+=a[i];
            cnt++;
        }
        else cnt=0;
    }

    cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int cnt = 0;
void PrintArray(int a[], int n)
{
    for (int i = 0; i < n; i++){
        if (i != 0){
            printf(" ");
        }
        printf("%d", a[i]);
    }
    printf("\n");
}

void merge(int a[], int left, int right)
{
    if (left < right) {

    int middle = (left + right) / 2;
    if (left + 1 < right){
        merge(a, left, middle);
        merge(a, middle + 1, right);
    }
    

    int b[right - left + 1];
    
    int i = left;
    int j = middle + 1;
    int k;
    int state;
    
    for (k = 0; k <= right - left; k++){
        if (a[i] <= a[j]){
            b[k] = a[i++];
            cnt++;     
        }else {
            b[k] = a[j++];
            cnt++;
        }
        
        
        if (i > middle){
            state = 1;
            k++;
            break;
        }
        if (j > right){
            state = 0;
            k++;
            break;
        }      
    }

    for (; k <= right - left; k++){
        b[k] = state ? a[j++] : a[i++];
        cnt++;
    }    
    
    for (i = left; i <= right; i++){
        a[i] = b[i - left];
    }
    }

}

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

    int a[n];

    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }

    merge(a, 0, n - 1);
    PrintArray(a, n);
    printf("%d\n", cnt);
}



Measured memory_bytes: 6520
/**
 *    author:  morato
 *    created: 06.09.2020 23:17:23
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if (s == "MON") {
    cout << 6 << '\n';
  }
  if (s == "TUE") {
    cout << 5 << '\n';
  }
  if (s == "WED") {
    cout << 4 << '\n';
  }
  if (s == "THU") {
    cout << 3 << '\n';
  }
  if (s == "FRI") {
    cout << 2 << '\n';
  }
  if (s == "SAT") {
    cout << 1 << '\n';
  }
  if (s == "SUN") {
    cout << 7 << '\n';
  }
  return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>
static int h, w, n, a, i, j, xss[100][100], dx = 1, dy, x, y;
void print(void) {
    int x, y;
    for (y = 0; y < h; ++y) {
        for (x = 0; x < w; ++x) {
            if (x) putchar(' ');
            printf("%d", xss[y][x]);
        }
        putchar('\n');
    }
}
void put(int i) {
    xss[y][x] = i;
    x += dx;
    if (x <= -1 || x >= w) {
        x -= dx;
        ++y;
        dx = -dx;
    }
}
int main(void) {
    scanf("%d%d%d", &h, &w, &n);
    for (i = 1; i <= n; ++i) {
        scanf("%d", &a);
        for (j = 1; j <= a; ++j) put(i);
    }
    print();
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
using namespace std;

int main()
{
    string c;
    cin >> c;
    for(int i = 0;i< c.size();i++)

      cout << "x" ;
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;
struct aa {
	int now;
	long long int time;
	int from;
};
class Compare {
public:
	//aaが昇順に並ぶ
	bool operator()(const aa&l, const aa&r) {
		return l.time> r.time;
	}
};
int main() {
	int N; cin >> N;
	vector<vector<long long int>>costs(N,vector<long long int>(N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			int a; cin >> a;
			costs[i][j] = a;
		}
	}
	long long int sum = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			sum += min(costs[i][j], costs[j][i]);
		}
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

#ifdef KACTL
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
#endif
#define all(x) begin(x), end(x)

using ll = int64_t;
using ld = long double;
using pii = pair<int32_t, int32_t>;
using vi = vector<int32_t>;

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

    int n;
    ll k;
    cin >> n >> k;
    constexpr int LOGN = 61;
    array<vi, LOGN> st;
    st[0].resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> st[0][i];
        --st[0][i];
    }
    for (int j = 1; j < LOGN; ++j) {
        st[j].resize(n);
        for (int i = 0; i < n; ++i) {
            st[j][i] = st[j - 1][st[j - 1][i]];
        }
    }

    int u = 0;
    for (int j = 0; j < LOGN; ++j) {
        if ((1LL << j) & k) {
            u = st[j][u];
        }
    }

    cout << u + 1 << '\n';

    return 0;
}


Measured memory_bytes: 50984
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            return Array().Select(int.Parse).ToArray();
        }
        public long[] LongArray()
        {
            return Array().Select(long.Parse).ToArray();
        }
    }
    struct SS
    {
        public int X, Y;
        public SS(int x, int y)
        {
            X = x;
            Y = y;
        }
    }

    class Program
    {
        private int N;
        private string[] S;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            S = new string[N];
            for (int i = 0; i < N; i++)
            {
                S[i] = sc.Next();
            }
        }

        public void Solve()
        {
            Scan();
            var cnt = new int[5];
            foreach (var s in S)
            {
                switch (s[0])
                {
                    case 'M':
                        cnt[0]++;
                        break;
                    case 'A':
                        cnt[1]++;
                        break;
                    case 'R':
                        cnt[2]++;
                        break;
                    case 'C':
                        cnt[3]++;
                        break;
                    case 'H':
                        cnt[4]++;
                        break;
                }
            }
            long ans = 0;
            for (int i = 0; i < 3; i++)
            {
                for(int j=i+1;j<4;j++)
                {
                    for(int k=j+1;k<5;k++)
                    {
                        ans += (long)cnt[i] * cnt[j] * cnt[k];
                    }
                }
            }
            Console.WriteLine(ans);
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, count;
  cin >> N;
  count = 0;
  
  for (int i = 0; i < N; i++) {
    char S;
    cin >> S;    
    if (S == 'Y')
      count++;
  }
  if (count == 0)
    cout << "Three" << endl;
  else
    cout << "Four" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    ll H;
    cin >> H;

    ll res = H, pos = 0;;
    while(res != 0){
        res = floor(res/2);
        pos++;
    }
    ll ans = pow(2, pos) - 1;
    cout << ans << endl;
}

Measured memory_bytes: 3996
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	ll N, M;
	cin>>N>>M;
	vector<queue<ll> > rn(N);
	REP(i, M) {
		ll a, b;
		cin>>a>>b;
		--a;
		--b;
		rn[a].push(b);
		rn[b].push(a);
	}
	deque<ll> dq;
	set<ll> used;
	REP(i, N) {
		if(rn[i].size()) {
			dq.push_front(i);
			used.insert(i);
			dq.push_back(rn[i].front());
			used.insert(rn[i].front());
			rn[i].pop();
			break;
		}
	}
	while(rn[dq.front()].size()) {
		if(used.count(rn[dq.front()].front()) == 0) {
			used.insert(rn[dq.front()].front());
			dq.push_front(rn[dq.front()].front());
		} else rn[dq.front()].pop();
	}
	while(rn[dq.back()].size()) {
		if(used.count(rn[dq.back()].front()) == 0) {
			used.insert(rn[dq.back()].front());
			dq.push_back(rn[dq.back()].front());
		} else rn[dq.back()].pop();
	}
	cout<<dq.size()<<endl;
	REP(i, dq.size()) {
		if(i != dq.size() - 1) cout<<dq[i] + 1<<" ";
		else cout<<dq[i] + 1<<endl;
	}
}


Measured memory_bytes: 73472
using System;
using System.Collections.Generic;
using System.Linq;

namespace contest_Csharp
{
    class Program
    {
        static void Main(string[] args)
        {
            long N,M;
            var prop = Console.ReadLine().Split(' ')
                .Select(x => long.Parse(x)).ToList();
            N = prop[0];
            M = prop[1];
            var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();

            long s=A.Sum();
            var number = A.Where(x => x * 4 * M >= s).Count();
            string ans = (number >= M) ? "Yes" : "No";
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
typedef long long int ll;
#define vaibhavv06               \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(0);
#define endl '\n'
#define int long long
#define MM(a,b) memset(a,b,sizeof(a))
const ll MOD = 1000000007;
using namespace std;
 
int32_t main(){
    vaibhavv06;
	int n; cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
    int dp[n][3]={0};
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(int i=1;i<n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
        // cout<<max(dp[i][0],max(dp[i][1],dp[i][2]))<<endl;

    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 201;
const int64_t INF = 10000000000;
vector<vector<int64_t>> Cost(MAXN, vector<int64_t>(MAXN, INF));

int main()
{
  int64_t N, M, R, a, b, c;
  cin >> N >> M >> R;
  vector<int64_t> A(R);
  for (int i = 0; i < R; i++)
    cin >> A.at(i);
  for (int i = 0; i < M; i++)
  {
    cin >> a >> b >> c;
    Cost.at(a).at(b) = c;
    Cost.at(b).at(a) = c;
  }
  for (int i = 1; i <= N; i++)
    Cost.at(i).at(i) = 0;
  for (int k = 1; k <= N; k++)
  {
    for (int i = 1; i <= N; i++)
    {
      for (int j = 1; j <= N; j++)
      {
        if (Cost.at(i).at(j) > Cost.at(i).at(k) + Cost.at(k).at(j))
          Cost.at(i).at(j) = Cost.at(i).at(k) + Cost.at(k).at(j);
      }
    }
  }
  sort(A.begin(), A.end());
  int64_t ans = INF;
  do
  {
    int64_t s = 0;
    for (int i = 1; i < R; i++)
    {
      s += Cost.at(A.at(i - 1)).at(A.at(i));
    }
    if (s < ans)
      ans = s;
  } while (next_permutation(A.begin(), A.end()));
  cout << ans << endl;
}

Measured memory_bytes: 512
package main

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

type tops [][]int

func (t tops) Len() int {
	return len(t)
}

func (t tops) Less(i, j int) bool {
	return t[i][1] < t[j][1]
}

func (t tops) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}

type UnionFind struct {
	par []int
}

func newUnionFind(n int) *UnionFind {
	u := &UnionFind{}
	u.par = make([]int, n)
	for i := range u.par {
		u.par[i] = -1
	}
	return u
}

func (u UnionFind) root(x int) int {
	if u.par[x] < 0 {
		return x
	}
	return u.root(u.par[x])
}

func (u UnionFind) unite(x, y int) {
	xr := u.root(x)
	yr := u.root(y)
	if xr == yr {
		return
	}
	u.par[yr] += u.par[xr]
	u.par[xr] = yr
}

func (u UnionFind) same(x, y int) bool {
	return u.root(x) == u.root(y)
}

func (u UnionFind) size(x int) int {
	return -u.par[u.root(x)]
}

type Node struct {
	n        int
	children []*Node
}

func main() {
	var n int
	fmt.Scan(&n)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	u := newUnionFind(n)
	tMap := make(map[int][]int)
	for i := 1; i <= n-1; i++ {
		scanner.Scan()
		a, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		if _, ok := tMap[a]; !ok {
			tMap[a] = []int{}
		}
		u.unite(a-1, b-1)
		tMap[a] = append(tMap[a], b)
		if _, ok := tMap[b]; !ok {
			tMap[b] = []int{}
		}
		tMap[b] = append(tMap[b], a)
	}

	c := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		c[i], _ = strconv.Atoi(scanner.Text())
	}
	sort.Ints(c)

	root := u.root(0) + 1
	r := &Node{
		n: root,
	}
	parents := map[int]bool{root: true}
	var build func(n *Node, parents map[int]bool)
	build = func(node *Node, parents map[int]bool) {
		if _, ok := tMap[node.n]; !ok {
			return
		}

		parents[node.n] = true
		for _, child := range tMap[node.n] {
			if !parents[child] {
				c := &Node{n: child}
				node.children = append(node.children, c)
				build(c, parents)
			}
		}
	}
	build(r, parents)

	var order []int
	q := []*Node{r}
	for len(q) > 0 {
		order = append(order, q[0].n-1)
		q = append(q, q[0].children...)
		q = q[1:]
	}

	ts := make([]int, n)
	for i := 0; i < n; i++ {
		ts[order[i]] = c[n-1-i]
	}

	var sum int
	for k, v := range tMap {
		for i := 0; i < len(v); i++ {
			if k < v[i] {
				if ts[k-1] < ts[v[i]-1] {
					sum += ts[k-1]
				} else {
					sum += ts[v[i]-1]
				}
			}
		}
	}
	fmt.Println(sum)

	for i := 0; i < n; i++ {
		fmt.Print(ts[i])
		if i != n-1 {
			fmt.Print(" ")
		}
	}
	fmt.Println("")
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

struct Query {
    char c, d;
};

std::istream &operator>>(std::istream &in, Query &o) {
    cin >> o.c >> o.d;
    return in;
}


#define _GLIBCXX_DEBUG

#include <iostream>
#include <vector>

using namespace std;

#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()
typedef int Weight;

struct Edge {
    int src, dst;
    Weight weight;

    Edge(int src, int dst, Weight weight) :
            src(src), dst(dst), weight(weight) {}
};

bool operator<(const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
           e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;
typedef pair<Weight, int> Result;

Result visit(int p, int v, const Graph &g) {
    Result r(0, v);
    FOR(e, g[v]) if (e->dst != p) {
            Result t = visit(v, e->dst, g);
            t.first += e->weight;
            if (r.first < t.first) r = t;
        }
    return r;
}

Weight diameter(const Graph &g) {
    Result r = visit(-1, 0, g);
    Result t = visit(-1, r.second, g);
    return t.first; // (r.second, t.second) is farthest pair
}

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

    Graph graph(n);

    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(Edge(a, b, 1));
        graph[b].push_back(Edge(b, a, 1));
    }

    int p = diameter(graph);

    string ans = p % 3 == 1 ? "Second" : "First";
    cout << ans << endl;
}

Measured memory_bytes: 29952
# from pprint import pprint
# import math
import collections

# n = int(input())
n, m = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = [None] * m
c = [None] * m
for i in range(m):
    _b, _c = map(int, input().split(' '))
    b[i] = _b
    c[i] = _c

cnt = collections.Counter(a)

# カウンターのみ更新
for j in range(m):
    cnt.update({c[j]: b[j]})

a_tup = cnt.items()

# カウンターの結果を逆順にして合計n個になるまで取り出して加算
res = 0
num_cnt = 0
for _ in sorted(a_tup, reverse=True):
    res += _[0] * _[1]
    num_cnt += _[1]

    # n個を超えたらその分減らす
    if num_cnt >= n:
        res -= _[0] * (num_cnt - n)
        break

print(res)


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


int main() {
    int n,h;
    cin >> n >> h;
    vector<int> a(n),b(n);
    for (int i=0;i<n;i++) cin >> a[i] >> b[i];
    sort(a.begin(),a.end(),greater<int>());
    sort(b.begin(),b.end(),greater<int>());
    int ans=0,k=0;
    while (h>0) {
        if (b[k]>a[0] && k<n) {
            h-=b[k];
            k++;
            ans++;
        } else {
            if (h%a[0]==0) ans+=h/a[0];
            else ans+=h/a[0]+1;
            break;
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>

int binarysearch(int *A,int key,int n){
  int left=0,right=n,mid;
  while(left<right){
    mid = (right+left)/2;
    
    if(key==A[mid]){
      return 1;
    }else if(key<A[mid]){
      right = mid;
    }else if(key>A[mid]){
      left = mid+1;
    }
  }
  return 0;
}

int main() {
  int A[100000];
  
  int n;
  scanf("%d",&n);
  
  
  for(int i=0;i<n;i++){
    scanf("%d",A+i);
  }
  
  int q;
  scanf("%d",&q);
  
  int key,sum=0;
  for(int i=0;i<q;i++){
    scanf("%d",&key);
    if(binarysearch(A,key,n)){
      sum++;
    }
  }
  
  printf("%d\n",sum);
  
  return 0;
}

Measured memory_bytes: 2976
# -*- coding: utf-8 -*-
# 標準入力の取得
N = int(input())
A = int(input())


def main() -> None:
    """Entry point
    """
    # 求解処理
    """
    500円で割ったあまりと1円の枚数を比較
    """
    result = str()
    if (N % 500) <= A:
        result = "Yes"
    else:
        result = "No"

    # 結果出力
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    REP(i,N) cin >> S[i];
    sort(S.begin(), S.end());
    REP(i,N) cout << S[i];
    cout << endl;
}


Measured memory_bytes: 256
# -*- Coding: utf-8 -*-

n = int(input())
str = input()
alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
str_list=list(str)
alphabet_list=list(alphabet)
#print(str_list)
#print(alphabet_list)
#Sprint(n%26)
i=0
j=0
if n==0:
    pass
else:
 for i in range(len(str)):
    for j in range(len(alphabet)):
        #print(str_list[i])
        #print(alphabet_list[j])
     if str_list[i]==alphabet_list[j]:
            #print(i)
            #print(j)
           if n%26+j >= 26:
             #print(1)
             #str_list[i]=alphabet_list[n%26+j-27]
             str_list[i]=alphabet_list[(n%26+j)%26]
             break
             #26文字を超えたときどうするかか
             #2パターン用意すればいいじゃない
           else:
                #print(j)
                #print((n%26+j)%25)

                str_list[i]=alphabet_list[(n%26+j)%26]
                break
     else:
           pass
#print(str_list)
mojiretu=''.join(str_list)
print(mojiretu)


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

int main()
{
	int n;
	scanf("%d",&n);
	
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	
	vector<vector<int> >dp(n,vector<int>(3));
	dp[0][0]=a,dp[0][1]=b,dp[0][2]=c;
	
	for(int i=1;i<n;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		
		dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a;
		dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b;
		dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c;
	}
	
	printf("%d\n",*max_element(dp[n-1].begin(),dp[n-1].end()));
	
	return 0;
}


Measured memory_bytes: 8796
import math

if __name__ == "__main__":
    li = list(map(int,input().split()))
    a=li[0]
    b=li[1]
    x=li[2]

    s=x/a

    if(s<=a*b/2):
        p=s*2/b
        print(90-math.degrees(math.atan(p/b)))
    else:
        p=(a*b-s)*2/a
        print(math.degrees(math.atan(p/a)))

Measured memory_bytes: 38384
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 100000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

char in[100050];

int main() {
	int N, i;
	scanf("%s", in + 1);
	N = strlen(in + 1);

	if (in[1] == '0' || in[N] == '1') return !printf("-1\n");
	for (i = 1; i < N; i++) if (in[i] != in[N - i]) return !printf("-1\n");

	int mx = N / 2;
	while (in[mx] == '0') mx--;

	vector <int> Vl;
	for (i = 1; i <= mx; i++) if (in[i] == '1') Vl.push_back(i);

	for (i = 1; i < Vl.size(); i++) {
		for (int j = Vl[i - 1]; j < Vl[i]; j++) printf("%d %d\n", j, Vl[i]);
	}
	printf("%d %d\n", Vl.back(), Vl.back() + 1);
	for (i = Vl.back() + 2; i <= N; i++) printf("%d %d\n", Vl.back() + 1, i);
	return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    REP(i, n) cin >> a[i];

    while (k--) {
        vi sum(n + 1);
        REP(i, n) {
            if (i - a[i] < 0) sum[0]++; else sum[i - a[i]]++;
            if (i + a[i] + 1 > n) sum[n]--; else sum[i + a[i] + 1]--;
        }
        // printv(sum);
        REP(i, n) sum[i + 1] += sum[i];
        // printv(sum);
        bool ok = true;
        REP(i, n) {
            if (sum[i] != n) ok = false;
            a[i] = sum[i];
        }
        if (ok) break;
    }
    printv(a);
}


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

r=0
b=[a]
while True:
    d=[]
    for x in b:
        m=min(x)
        r+=m
        d.append([i-m for i in x])

    b=[]
    for x in d:
        t=[]
        for y in range(len(x)):
            if y==len(x)-1:
                if x[y]!=0:
                    t.append(x[y])
                    b.append(t)
                if x[y]==0 and x[y-1]!=0:b.append(t)
            elif x[y]!=0:t.append(x[y])
            elif x[y]==0:
                if len(t)!=0:b.append(t)
                t=[]

    d=[]
    for x in b:
        if len(x)<=2:r+=max(x)
        else:d.append(x)
    if len(d)==0:print(r);exit()
    b=d

Measured memory_bytes: 9108
#include<bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define rep(i,n) for(ll i=0;i<n;i++)
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
//using namespace atcoder;

const ll mod=1000000007;//998244353;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

vector<vector<ll>> bunkai(ll a){
  if(a<=0) return {};
  if(a==1) return {{1,1}};
  vector<ll> f;
  ll b=a;
  for(ll i=2;i*i<=a;i++){
    if(b%i==0){
      f.push_back(i);
      b=b/i;
      i--;
    }
  if(b==1)break;
  }
  if(b!=1)f.push_back(b);

  vector<vector<ll>> u;
  ll p=f[0];
  ll c=1;
  for(ll i=1;i<f.size();i++){
    if(f[i]==p)c++;
    else{
      u.push_back({p,c});
      p=f[i];
      c=1;
    }
  }
  u.push_back({p,c});

  return u;
}

vector<ll> yakusu(ll a){
  if(a<=0)a=-a;
  if(a==1) return {1};
  vector<ll> f={1,a};
  for(ll i=2;i*i<=a;i++){
    if(a%i==0 && i*i!=a){
      f.push_back(i);
      f.push_back(a/i);
    }
    if(i*i==a)f.push_back(i);
  }
  sort(f.begin(),f.end());

  return f;
}

int main(){

  ll n,k;
  cin >> n >> k;
  vec a(n);
  for(ll i=0;i<n;i++)cin >> a[i];

  ll s=0;
  for(ll i=0;i<n;i++)s+=a[i];

  vec f=yakusu(s);

  ll ans;
  for(ll j=f.size()-1;j>=0;j--){
    ll d=f[j];
    vec r(n);
    for(ll i=0;i<n;i++)r[i]=a[i]%d;
    sort(r.begin(),r.end());
    vec dp(n+1);
    for(ll i=0;i<n;i++)dp[i+1]=dp[i]+r[i];
    ll q=inf;
    ll a,b;
    for(ll i=1;i<n+1;i++){
      a=dp[i];
      b=d*(n-i)-(dp[n]-dp[i]);
      q=min(q,max(a,b));
    }
    if(q<=k){
      ans=d;
      break;
    }
  }

  cout << ans << endl;



  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SP << " " 

using namespace std;

void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main() {

	int n, k, d, tmp, ans=0;
	vector<int> v;

	cin >> n >> k;
	v.resize(n, 0);
	rep(i, k) {
		cin >> d;
		rep(j, d) {
			cin >> tmp;
			v[tmp - 1] = 1;
		}
	}

	rep(i, n) {
		if (v[i] == 0) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;
import java.util.Set;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long x = Long.parseLong(sc.next());
        long[] candies = new long[n];
        for(int i=0;i<n;i++){
            candies[i] = Long.parseLong(sc.next());
        }
        long cnt = 0;
        for(int i=0;i<n-1;i++){
            long sum = candies[i] + candies[i+1];
            if(sum<=x){
                continue;
            }else{
                long surplus = sum - x;
                cnt+=surplus;
                candies[i+1] = Math.max(0, candies[i+1]-surplus);
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 48256
N,M,Q = map(int,input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int, input().split())
    
import itertools
A = list(itertools.combinations_with_replacement(range(1,M+1), N))
ans = 0
for j in A:
    temp = 0
    for i in range(Q):
        if j[b[i]-1]-j[a[i]-1] == c[i]:
            temp += d[i]
    ans = max(ans,temp)
print(ans)

Measured memory_bytes: 21532
#include<stdio.h>
int main() {
    int x, c[4], i;
    c[0] = 0;
    c[1] = 0;
    c[2] = 0;
    c[3] = 0;
    for (i = 0; i < 4; i++) {
        scanf("%d", &x);
        if (x == 1)
            c[0] = 1;
        if (x == 9)
            c[1] = 1;
        if (x == 7)
            c[2] = 1;
        if (x == 4)
            c[3] = 1;
    }
    if (c[0] + c[1] + c[2] + c[3] == 4)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int n, m;
  cin >> n >> m;
  vector<ll> x(n), y(m);
  REP(i, n)
  cin >> x[i];
  REP(i, m)
  cin >> y[i];
  ll w = 0, h = 0;
  REP(i, n)
  {
    w += (2 * i % MOD - n + 1) * x[i] % MOD;
    w %= MOD;
  }
  REP(i, m)
  {
    h += (2 * i % MOD - m + 1) * y[i] % MOD;
    h %= MOD;
  }
  cout << w * h % MOD << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int SIZE = 5001;
bool comp(int x,int y){
    return x > y;
}
int main(){
    long long n, k; cin >> n >> k;
    int A[SIZE];
    for (int i = 0; i < n; i++)
        cin >> A[i];
    sort(A, A+n, comp);
    long long sum_A = 0;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (sum_A + A[i] < k)
        {
            ans++;
        }
        else
        {
            ans = 0;
        }
        sum_A = (sum_A + A[i] >= k ? sum_A : sum_A+A[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
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<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int main() {
    string s;
    cin >> s;
    int n = s.length();
    int m = 7;
    REP(i,m){
        int j = m - i;
        string t = s.substr(0, i);
        t += s.substr(n - j, j);
        if (t == "keyence"){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
ans = 10**15

for i in [-1,1]:
    ansi,sum=0,0
    for a in A:
        sum+=a
        if sum*i<=0:
          ansi+=abs(sum-i)
          sum=i
        i*=-1
    ans=min(ans,ansi)
print(ans)

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

#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)

const int MX_N = 1e5+5;
const int MX_Q = 1e5+5;

int N, M, Q;
vector<int> al[MX_N];

tuple<int,int,int> que[MX_Q];
int c[MX_N][11];
queue<pair<int,int>> q;

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

    cin >> N >> M;
    FOR(i,1,M){
        int A, B; cin >> A >> B;
        al[A].push_back(B);
        al[B].push_back(A);
    }

    cin >> Q;
    FOR(i,1,Q){
        int V, D, C; cin >> V >> D >> C;
        que[i] = make_tuple(V,D,C);
    }

    RFOR(i,Q,1){
        int V, D, C; tie(V,D,C) = que[i];
        if (c[V][D] > 0) continue;
        c[V][D] = C;
        q.emplace(V,D);
        while (!q.empty()) {
            auto u = q.front(); q.pop();
            if (u.second == 0) continue;
            if (c[u.first][u.second-1] == 0) {
                c[u.first][u.second-1] = C;
                q.emplace(u.first,u.second-1);
            }
            for (int v : al[u.first]) {
                if (c[v][u.second-1] == 0) {
                    c[v][u.second-1] = C;
                    q.emplace(v,u.second-1);
                }
            }
        }
    }

    FOR(i,1,N) cout << c[i][0] << '\n';
}



Measured memory_bytes: 13304
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program{
  static void Main(){
    var num = int.Parse(ReadLine());
    var num2 = ReadLine().Split(' ').GroupBy(a => a).ToArray().Length;
    if(num == num2){
      Write("YES");
    }else{
      Write("NO");
    }
  }
}


Measured memory_bytes: 57096