akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
	int goods_num_n, max_cost_m;
	int goods_cost_a[1000];
	int n_sum = 0;
	int counter_i, counter_j;
	int buying_goods = 0, buying_max = 0;
	
	for(n_sum = 0 ; n_sum <= 50000 ; n_sum += goods_num_n)
	{
		scanf("%d %d", &goods_num_n, &max_cost_m);
		if(goods_num_n == 0 && max_cost_m == 0)
			break;

		for(counter_i = 0 ; counter_i < goods_num_n ; counter_i++)
		{
			scanf("%d", &goods_cost_a[counter_i]);
		}
		
		for(counter_i = 0 ; counter_i < goods_num_n ; counter_i++)
		{
			if(goods_cost_a[counter_i] >= max_cost_m)
				continue;
			
			for(counter_j = counter_i + 1 ; counter_j < goods_num_n ; counter_j++)
			{
				if(goods_cost_a[counter_j] >= max_cost_m)
					continue;
				
				buying_goods = goods_cost_a[counter_i] + goods_cost_a[counter_j];
				if(buying_goods <= max_cost_m && buying_goods >= buying_max)
					buying_max = buying_goods;
			}
		}
		if(buying_max == 0)
			printf("NONE\n");
		else
			printf("%d\n", buying_max);

		buying_max = 0;
	}
	return 0;
}



Measured memory_bytes: 2128
#include <stdio.h>

int A[500001],H;
void maxHeapify(int *A,int i){
  int largest,l,r,tmp;
  l = 2*i;
  if(2*i+1 <= H)r = 2*i+1;
  else r = NULL;
  if(l <= H && A[l] > A[i])largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest] && r != NULL)largest = r;

  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A,largest);
  }
}

int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  for(i = H/2;i > 0;i--){
    maxHeapify(A,i);
  }

  
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 3696
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		Deque<Integer> deque = new ArrayDeque<>();
		for(int i = 0 ; i < n ; i++) {
			if((n + 1) % 2 == i % 2) {
				deque.addLast(a[i]);
			} else {
				deque.addFirst(a[i]);
			}
		}
		for(int i = 0 ; i < n ; i++) {
			System.out.print(deque.pollLast() + " ");
		}
	}
}


Measured memory_bytes: 94964
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

template <long long mod>
long long mod_pow(long long a, long long b) {
    if (b == 0) return 1;
    long long ret = mod_pow<mod>(a, b / 2);
    ret = ret * ret % mod;
    if (b % 2 == 1) ret = a * ret % mod;
    return ret;
}

template <long long mod>
struct Comb {
    int n;
    vector<long long> fact, inv;

    Comb(int n)
        : n(n), fact(n + 1, 0), inv(n + 1, 0) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
        inv[n] = mod_pow<mod>(fact[n], mod - 2);
        for (int i = n; i >= 1; i--) inv[i - 1] = inv[i] * i % mod;
    }

    long long operator()(int m, int k) {
        if (m > n || m < k || k < 0)
            return 0;
        else
            return fact[m] * inv[m - k] % mod * inv[k] % mod;
    }
};

const ll MOD = 998244353;
ll n, m, k;

int main() {
    fastio();

    cin >> n >> m >> k;

    Comb<MOD> comb(n);

    ll ans = 0;
    for (ll i = 0; i <= k; i++) {
        ll temp = comb(n - 1, i); // 左と同色で塗るブロックを選ぶ
        ll c = n - i;
        temp = temp * m % MOD * mod_pow<MOD>(m - 1, c - 1) % MOD;
        ans = (ans + temp) % MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6300
/*****include*****/
#include <iostream>
#include <fstream>
#include <string>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return 0;
	}
#endif
	/*****変数置き場*****/
	string words;
	int n;
	int index;
	/*****処理部*****/
	cin >> n;
	for(int i=0;i<n;i++){
		do{
			getline(cin,words);
		}while(words == "");
		//cin >> words;
		int j;
		j=0;
		while(1){
			index = words.find("Hoshino",j);
			if(index == string::npos){
				//cout << j << endl;
				break;
			}
			words.replace(index,7,"Hoshina");
			j += 6;
			//cout << words << endl;
		}
		cout << words << endl;
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

Measured memory_bytes: 1212
n,m,c = map(int, input().split())
b = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]

num = 0
for i in range(len(a)):
    ad = 0    
    for n in range(m):
        ad += a[i][n]*b[n]
    ad +=c
    if ad >0:
        num +=1
    else:
        pass
print(num)

Measured memory_bytes: 3064
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int Area = a * b;
		int length = 2 * (a + b);
		System.out.println(Area + " " + length);
	}
}


Measured memory_bytes: 26372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000007
int main()
{
    int n,W;
    cin>>n>>W;
    int w[n+1],v[n+1];
    for(int i=1;i<=n;i++)
    cin>>w[i]>>v[i];
    ll dp[n+1][100002];
    for(int i=0;i<=n;i++)
    dp[i][0]=0;
    for(int i=0;i<100002;i++)
    dp[0][i]=-1;
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<100002;j++)
        {
            if(v[i]<=j)
            {
                if(dp[i-1][j]==-1 && dp[i-1][j-v[i]]==-1)
                {
                    dp[i][j]=-1;
                }
                else if(dp[i-1][j]==-1)
                dp[i][j]=w[i]+dp[i-1][j-v[i]];
                else if(dp[i-1][j-v[i]]==-1)
                {
                    dp[i][j]=dp[i-1][j];
                }
                else
                dp[i][j]=min(w[i]+dp[i-1][j-v[i]],dp[i-1][j]);
            }
            else
            dp[i][j]=dp[i-1][j];
        }
    }
    for(int i=n;i>=0;i--)
    {
        for(int j=100001;j>=0;j--)
        {
            if(dp[i][j]<=W && dp[i][j]!=-1)
            {
                cout<<j<<"\n";
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
int N;
int Lv[101010];
int Rv[101010];
int R, C;
int normailze(int x, int y)
{
    if(y==0) return x;
    if(x==R) return R+y;
    if(y==C) return R+C+(R-x);
    if(x==0) return R+C+R+(C-y);
    return -1;
}
bool solve()
{
    stack<int> S;
    vector<pair<int, int> > V;
    for(int i=0; i<N; ++i)
    {
        V.emplace_back(Lv[i], i+1);
        V.emplace_back(Rv[i], -i-1);
    }
    sort(V.begin(), V.end());
    for(int i=0; i<V.size(); ++i)
    {
        int v1, ind; tie(v1, ind) = V[i];
        if(ind > 0) S.push(ind);
        else
        {
            if(S.top() != -ind) return false;
            S.pop();
        }
    }
    return true;
}

int main()
{
    int _N; scanf("%d%d%d", &R, &C, &_N );
    for(int i=0; i<_N; ++i)
    {
        int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        int v1 = normailze(x1, y1);
        int v2 = normailze(x2, y2);
        if(v1 == -1 || v2 == -1) continue;
        if(v1>v2) swap(v1, v2);
        Lv[N] = v1; Rv[N] = v2;
        ++N;
                    
    }
    if(solve()) puts("YES");
    else puts("NO");
}

Measured memory_bytes: 3188
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

enemy = sum(a)
for i in range(len(b)-1, -1, -1):
    tmp = max(a[i + 1] - b[i], 0)
    b[i] -= a[i + 1] - tmp
    a[i + 1] = tmp
    tmp = max(a[i] - b[i], 0)
    b[i] -= a[i] - tmp
    a[i] = tmp
ans = enemy - sum(a)
print(ans)

Measured memory_bytes: 82020
#include <bits/stdc++.h>
#if ONLINE_JUDGE
    #define DEBUG false
#else
    #define DEBUG true
#endif
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define rrep(i, n) rREP(i, 0, n)
#define forlist(i, vec) for(auto &&i : vec)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) cerr << #x << ": " << (x) << endl
using namespace std;
typedef long long LL;
typedef long long int64;
typedef std::vector<int> VI;
typedef std::vector<VI> VVI;
typedef std::vector<LL> VL;
typedef std::vector<VL> VVL;
typedef std::vector<std::string> VS;
typedef std::pair<int, int> PII;
typedef std::pair<LL, LL> PLL;
typedef std::queue<int> QI;
typedef std::priority_queue<int> PQI;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline void vcinpb(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}
template<class T>inline void dumpv(T &v){
    if(!DEBUG)return;cout<<"{";rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1)?",":"}";}cout<<endl;
}

const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;
// M_PI 3.1415...

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cis(s);
    string ans;
    if (s == "ABC"){
        ans= "ARC";
    }else{
        ans = "ABC";
    }
    co(ans);
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int A, B;
int main(void){
    cin >> A >> B;
    cout << A * B << endl;
    return 0;
}



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

int R,G,B,N;
int main (){
    cin >> R >> G >> B >> N;
    int ans = 0;
    for(int r=0; r<=N;r+=R) {
        for(int g=0; g<=N-r;g+=G) {   
            if ( (N - (r + g)) % B == 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int p[6],q[6];
double B(double x){
	double value=0;
	rep(i,6) value+=max(p[i]*x,q[i]*(1-x));
	return value/100;
}
int main(){
	rep(i,6) scan(p[i]);
	rep(i,6) scan(q[i]);
	double aka=0,ao=0;//赤と青それぞれを選んだときにtouristが勝つ確率
	double xmin=0,xmax=1;
	while(xmax-xmin>1e-10){
		double x1=(xmin*2+xmax)/3,x2=(xmin+xmax*2)/3;
		double B1=B(x1),B2=B(x2);
		if(B1<B2) xmax=x2;
		else xmin=x1;
	}
	prin(setprecision(11)<<B(xmax));
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  string str;
  cin >> str;
  cout << "ABC" << str << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3,inline,unroll-loops")
#include <iostream>
#include <algorithm>
#include <cstdio>
#define N 500020
#define MOD 1000000007
using namespace std;

namespace Comb
{
    int f[N], g[N];

    int Power(int x, int y)
    {
        int o;

        for(o = 1; y; y >>= 1)
        {
            if(y & 1)
                o = (long long)o * x % MOD;
            x = (long long)x * x % MOD;
        }

        return o;
    }

    void InitComb(void)
    {
        int i;

        for(i = f[0] = 1; i < N; i ++)
            f[i] = (long long)f[i - 1] * i % MOD;
        g[N - 1] = Power(f[N - 1], MOD - 2);
        for(i = N - 2; i > -1; i --)
            g[i] = (long long)g[i + 1] * (i + 1) % MOD;

        return;
    }

    int C(int n, int m)
    {
        return m > n ? 0 : (long long)f[n] * g[m] % MOD * g[n - m] % MOD;
    }
}

int main(void)
{
    int n, m;
    int i, o;

    Comb::InitComb();
    cin >> n >> m;
    for(i = o = 0; i <= n; i ++)
        o = (o + (long long)(i & 1 ? MOD - 1 : 1) * Comb::C(n, i) % MOD * Comb::C(m, i) % MOD * Comb::f[i] % MOD * Comb::C(m - i, n - i) % MOD * Comb::C(m - i, n - i) % MOD * Comb::f[n - i] % MOD * Comb::f[n - i] % MOD) % MOD;
    cout << o << endl;

    return 0;
}


Measured memory_bytes: 7556
from bisect import bisect_left,bisect
 
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
lenc=len(c)

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

jsum=0
for j in b:
    ai=bisect(a,j-1)
    ci=lenc-bisect_left(c,j+1)
#    print(j,ai,ci)
    jsum+=ai*ci

print(jsum)

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

int main()
{
	int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int in;
	cin>>in;
	cout<<arr[in-1];
}


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

constexpr ll NMAX = 200010;
constexpr ll mod = 1e9+7;

int main(){
    ll N;
    cin >> N;
    vector<ll> C(N+1);
    rep(i, 1, N+1) cin >> C[i];
    vector<ll> seen(NMAX, -1);
    vector<ll> dp(N+1, 0);
    dp[0] = 1;
    rep(i, 1, N+1){
        dp[i] = dp[i-1];
        if(i != N && C[i] == C[i+1]) continue;
        if(seen[C[i]] != -1) dp[i] += dp[seen[C[i]]];
        dp[i] %= mod;
        seen[C[i]] = i;
        // cerr << "dp["  << i << "]: " << dp[i] << endl;
    }
    cout << dp[N] << endl;
    return 0;
}

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

using namespace std;

#define M 21
#define N (1<<M)

int n,m,a[M][N],H[N],f[M][N],g[M][N];
char s[N];

int main(){
	scanf("%d%d",&n,&m);
	for (int i=0;i<=n;++i){
		scanf("%s",s);
		for (int j=0;j<1<<i;++j) a[i][j]=s[j];
	}
	for (int i=1;i<1<<(n+1);++i)
		for (int j=0;j<=n;++j)
			if (i>>j&1) H[i]=j;
	for (int i=(1<<(n+1))-1;i;--i){
		int t=H[i];
		f[0][i]=a[t][i^(1<<t)]-'0';
		if (!(i>>n&1)) f[0][i]+=f[0][i<<1]+f[0][i<<1|1];
	}
	for (int i=1;i<=n;++i){
		for (int j=1;j<1<<(n+1);++j){
			int t=H[j];
			if (t>=i){
				int x=j;
				int y=x%(1<<i);
				x>>=i;
				int o=y>>(i-1)&1;
				for (int k=1;t+k-1<=n;++k){
					x<<=1; x|=o;
					f[i][j]+=f[i-1][(x<<(i-1))|(y^(o<<(i-1)))];
					x^=1;
				}
				if (t==i) g[i][y]+=f[i][j];
			}
		}
	}
	for (int i=n;i;--i)
		for (int j=0;j<1<<n;++j)
			if (g[i][j]>=m){
				for (int k=i-1;~k;--k) printf("%d",j>>k&1);
				puts("");
				return 0;
			}
	
	return 0;
}
			

Measured memory_bytes: 275840
from itertools import accumulate
N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
sumA1 = list(accumulate(A1))
sumA2 = list(accumulate(A2))
ans = 0

for i in range(N):
  if i == 0:
    ans = max(ans,sumA1[N-1]+A2[N-1], sumA2[N-1]+A1[i])
  else:
    ans = max(ans, sumA2[N-1]-sumA2[i-1]+sumA1[i])
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
 
public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new aoj108().doIt();
	}
	class aoj108{
		int C(int a[],int n){
			int result = 0;
			int b[] = new int [n];
			int c[] = new int [n];
			for(int i = 0;i < n;i++){
				b[i] = a[i];
				c[i] = a[i];
			}
			while(true){
				int out = 0;
				for(int i = 0;i < n;i++){
					int cnt = 0;
					for(int j = 0;j < n;j++){
						if(a[i] == b[j])cnt++;
					}
					c[i] = cnt;
				}
				for(int i = 0;i < n;i++){
					if(c[i] == b[i])out++;
					a[i] = c[i];b[i] = c[i];
				}
				if(out == n)break;
				result++;
			}
			return result;
		}
		void doIt() {
			while(true){
				int n = sc.nextInt();
				if(n == 0)break;
				int a[] = new int [n];
				for(int i = 0;i < n;i++)a[i] = sc.nextInt();
				System.out.println(C(a,n));
				for(int i = 0;i < n-1;i++)System.out.print(a[i]+" ");
				System.out.println(a[n-1]);
			}
		}
	}
}

Measured memory_bytes: 23360
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
int main() {
	fastio;
	int K;
	cin >> K;

	ll sum = 0;
	for (int i = 1; i <= K; ++i)
		for (int j = 1; j <= K; ++j)
			for (int k = 1; k <= K; ++k)
				sum += gcd(i, gcd(j, k));

	cout << sum;

	return 0;
}


Measured memory_bytes: 3648
N,M=map(int,input().split())
a=[0 for i in range(M)]
b=[0 for i in range(M)]
for i in range(M):
    a[i],b[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
par=[0 for i in range(N)]
rnk=[0 for i in range(N)]
def init(n):
    for i in range(N):
        par[i]=i
        rnk[i]=0
def find(x):
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
def unite(x,y):
    x=find(x)
    y=find(y)
    if x==y:
        return
    if (rnk[x]<rnk[y]):
        par[x]=y
    else:
        par[y]=x
        if(rnk[x]==rnk[y]):
            rnk[x]+=1
def same(x,y):
    return find(x)==find(y)
ans=0
for i in range(M):
    init(N)
    for j in range(M):
        if i==j:
            continue
        unite(a[j],b[j])
    flag=0
    for j in range(1,N):
        if find(0)!=find(j):
            flag=1
            break
    if flag==1:
        ans+=1
print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,D; cin>>N>>D;
  
  int zahyo[N][D];
  for(int i=0; i<N; i++){
    for(int j=0; j<D; j++){
      cin>>zahyo[i][j];
    }
  }
  
  int ans=0;
  
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      int X=0;
      for(int k=0; k<D; k++){
        X+=(zahyo[i][k]-zahyo[j][k])*(zahyo[i][k]-zahyo[j][k]);
      }
      double X1=sqrt(X);
      if(floor(X1)==X1){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stack>
#include<cstdio>

using namespace std;

int main()
{
	int train;
	stack<int>station;
	while (scanf("%d", &train) != EOF)
	{
		if (train == 0)
		{
			printf("%d\n", station.top());
			station.pop();
		}
		else
		{
			station.push(train);
		}
	}
	return 0;
}

Measured memory_bytes: 1036
N = gets.to_i
A = gets.split.map &:to_i
B = gets.split.map &:to_i
queue = (0...N).sort_by{ |i| -B[i] }
ans = 0
k = N
while j = queue.shift do
  aj = A[j]
  a,b,c = B[j-1],B[j],B[(j+1)%N]
  if b < aj
    p -1; exit
  end
  if b == aj
    next
  end
  if a == b || b == c
    p -1; exit
  end

  x = [a, c, aj].max
  k -= 1
  if b > x
    d = a + c
    r = b % d
    if x-r >= 0
      bb = (x-r) / d * d + r
      m = (b-bb) / d
      ans += m
      B[j] = bb
      if m > 0
        k = N
      end
    end
  end
  if k == -1
    p -1; exit
  end
  queue << j
  #p [j,B,A,m,k,x]
end

p (0...N).all?{ |i| A[i] == B[i] } ? ans : -1


Measured memory_bytes: 35980
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
const long long MOD =1000000000+7;
int main(){
	int n,k;
	cin >>n>>k;
	long long ans=0;
	long long turn=0;
	int ruse;
	/*
	find amout of b%a >=k 

	-->a >k and b =>k 

	max::10^10/2
	*/
	for(int i=n;i>k;i--){
		turn=(long long)n/i;
		ruse=n-(int)(turn*i);
		if(ruse >=k ){
			ans+=1+ruse-k;
			if(k==0){
				ans-=1;
			}
		}
		ans+=turn*(i-k);
		//cout<<turn<<"  "<<ruse;
		//cout<<"-"<<ans<<endl;
	}
	cout << ans<< endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
int res[26];
int main(void){
    // Your code here!
    cin >> n;
    for (int i = 0; i < n; i++) {
        int al[26];
        for (int i = 0; i < 26; i++) al[i] = 0;
        string str;
        cin >> str;
        for (int j = 0; j < str.length(); j++) {
            al[str[j] - 'a']++;
        }
        for (int j = 0; j < 26; j++) {
            if (i == 0) res[j] = al[j];
            else res[j] = min(res[j], al[j]);
        }
    }
    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < res[i]; j++) {
            printf("%c", 'a' + i);
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;

vector<int> ra(MX,0);
vector<int> par(MX,0);
using P = pair<int, int>;
using ll = long long;
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int find(int x) {
    if(par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x==y) return;
    if(ra[x]<ra[y]) {
        par[x] = y;
    }else {
        par[y] = x;
        if(ra[x]==ra[y]) {
            ra[x]++;
            
        }
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int a[MX];
int c[10][1000];

signed main(){
    int n;
    cin >> n;
    int d[n];
    rep(i,n) cin >> d[i];

    int ans = 0;

    rep(i,n) {
        FOR(j,i,n) {
            if(i==j) continue;
            ans += d[i]*d[j];
        }
    }
    cout << ans << endl;
    return 0;

}



Measured memory_bytes: 15872
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
nleaf=[0 for i in range(n+1)]
nleaf[0]=1-lis[0]
if nleaf[0]<0:
    print(-1)
    sys.exit()
for i in range(n):
    nleaf[i+1]=nleaf[i]*2-lis[i+1]
    if nleaf[i+1]<0:
        print(-1)
        sys.exit()
#print(lis)
#print(nleaf)
u=list(reversed(lis))
sup=[0 for i in range(n+1)]
for i in range(n):
    sup[i+1]=min(sup[i]+u[i],nleaf[n-i-1])
    #print(sup[i]+u[i],nleaf[n-i-1])
    #print(min(sup[i]+u[i],nleaf[n-i-1]))
#print(sup)
print(sum(lis)+sum(sup))
    
    
        


Measured memory_bytes: 675240
/*
    Author : MAHIM_JU_CSE
    From   : CSE,JU,Batch:47
    Date   : 27.09.2020
*/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX 1e19
#define MIN -1e19
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define mk make_pair
#define pii pair<int,int>
#define psi pair<string,int>
#define pis pair<int,string>
#define pli pair<long long int,int>
#define pll pair<long long int,long long int>
#define mii map<int,int>
#define msi map<string,int>
#define mis map<int,string>
#define mli map<long long int,int>
#define mll map<long long int,long long int>
#define qi queue<int>
#define qll queue<ll>
#define dqll deque<ll>
#define dqi deque<int>
#define memset(array,value) memset(array,value,sizeof(array))
#define endl "\n"
#define LCM(a,b) a*b/__gcd(a,b)
#define GCD(a,b) __gcd(a,b)
#define Sort(name) sort(name.begin(),name.end())
#define SorT(name) sort(name.rbegin(),name.rend())
const double pi = acos(-1.0);
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

int fact(int n)
{
    return (n==0) || (n==1) ? 1 : n* fact(n-1);
}
void sieve(ll n)
{
    bool check[n+1];
    memset(check,true);
    for(ll i=2; i*i<=n; i++)
        if(check[i]==true)
            for(ll j=i*i; j<=n; j+=i)
                check[j]=false;
    for(ll i=2; i<=n; i++)
    {
        if(check[i]==true)
        {
            cout<<i<<" ";
        }
    }
}

bool isprime(ll n)
{
    if(n<=1)
        return false;
    if(n<=3)
        return true;
    if(n%2==0||n%3==0)
        return false;
    for(ll i=5; i*i<=n; i=i+6)
        if(n%i==0||n%(i+2)==0)
            return false;
    return true;
}


int main()
{
    fio;
    ll t;
    cin>>t;
    while(t--)
    {
        cout<<"ACL";
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define all(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())

int main(void)
{
  // code begin

  string s, t, u;
  int a, b;

  cin >> s >> t;
  cin >> a >> b;
  cin >> u;

  if (u == s)
    cout << a - 1 << " " << b << endl;
  else
    cout << a << " " << b - 1 << endl;

  // code end
  return 0;
}


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

using namespace std;

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

    int P;
    int min=1000000, ans=0;
    for (int i = 0; i < N; i++) {
        cin >> P;
        if (min > P) {
            min = P;
            ans++;
        }
    }

    cout << ans << endl;
}

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

p_list = list(map(int, input().split()))
count = 0
for i in range(2**n):
  s_str = format(i, 'b').zfill(n)
  for j in range(len(k_list)):
    on = 0
    for s in k_list[j]:
      on += int(s_str[s-1])
    if on % 2 != p_list[j]:
      break
  else:
    count += 1

print(count)

Measured memory_bytes: 3064
defmodule Main do
  def main do
    k =
      IO.read(:line)
      |> String.trim()
      |> String.to_integer()
 
    [a, b] =
      IO.read(:line)
      |> String.trim()
      |> String.split()
      |> Enum.map(&String.to_integer/1)
 
    s =
      if(Enum.any?(a..b, fn x -> rem(x, k) === 0 end)) do
        "OK"
      else
        "NG"
      end
 
    IO.puts(s)
  end
end

Measured memory_bytes: 31144
void main()
{
    long n, q;
    rdVals(n, q);

    foreach (i; 0 .. q)
    {
        long v, w;
        rdVals(v, w);

        if (n == 1)
        {
            min(v, w).writeln;
            continue;
        }

        while (v != w)
        {
            if (v < w) w = (w + n - 2) / n;
            else v = (v + n - 2) / n;
        }
        v.writeln;
    }
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

int main()
{
    ll x,y;
    cin >> x >> y;
    string ans;
    if(y%2)
      ans="No";
    else 
    {
      if(x>y/2)
        ans="No";
      else if(x<y/4 || (x==y/4 && y%4))
        ans="No";
      else
        ans="Yes";
    }

     
     cout << ans << "\n";
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9;
int main(){ 
  int d, g;
  cin >> d >> g;
  vector<int> p(d), c(d);
  rep(i,d) cin >> p[i] >> c[i];
  int res = INF;
  for (int bit = 0; bit < (1 << d); bit++) {
    int sum = 0;
    int cnt = 0;
    for (int i = 0; i < d; i++) {
      if (bit & (1 << i)) sum += (i+1)*100*p[i] + c[i], cnt += p[i];
    }
    if (sum >= g) res = min(res,cnt);
    else {
      for (int i = d-1; i >= 0; i--) {
        if (bit & (1 << i)) continue;
        for (int j = 0; j < p[i]; j++) {
          if (sum >= g) break;
          sum += (i+1)*100;
          cnt++;
        }
      }
      res = min(res,cnt);
    }
  }
  
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  char e;
  cin>>n>>a;
  ll ar[n];
  rep(i,0,n) cin>>ar[i];
  sort(ar,ar+n);
  per(i,n-1-a,-1) k+=ar[i];
  cout<<k;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
//   cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 5188
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

int main(){
	int n , k ; 
	cin >> n >> k ; 
	long double ans = 0 ; 
	for(int i=1;i<=n;i++){
		int start = i ; 
		int den = 1 ; 
		while(start<k){
			start*=2 ; 
			den*=2 ; 
		}
		ans += (1.0/n) * (1.0/den) ; 
	}
	cout << fixed << setprecision(12) << ans << endl;
    return 0 ;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int

	fmt.Scanf("%d\n", &N)
	arr := []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9}
	var a uint64
	for i := 0; i < N; i++ {
		a = arr[0]
		arr = arr[1:]
		if a%10 != 0 {
			arr = append(arr, a*10+a%10-1)
		}
		arr = append(arr, 10*a+a%10)
		if a%10 != 9 {
			arr = append(arr, 10*a+a%10+1)
		}
	}
	fmt.Println(a)
}


Measured memory_bytes: 7680
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 10000;
const int INF = 1 << 30;

int main(){
    int H,N;
    int A[MAX],B[MAX];
    int dp[10000] = {0};

    cin >> H >> N;
    for(int i = 0;i < N;i++){
        cin >> A[i] >> B[i];
    }

    for(int i = 0;i <= H;i++){
        dp[i] = INF;
    }
    dp[0] = 0;

    for(int i = 0;i < H;i++){
        if(dp[i] == -1)continue;

        for(int j = 0;j < N;j++){
            int x = min(i + A[j],H);
            dp[x] = min(dp[i] + B[j],dp[x]); 
        }
    }

    cout << dp[H] << endl;

    return 0;
}

Measured memory_bytes: 256
import sys

N = int(input())
xyz = [list(map(int, input().split())) for _ in range(N)]

idx = 0
for i in range(N):
    if xyz[i][2] != 0:
        idx = i
        break

for cx in range(101):
    for cy in range(101):
        switch = 1
        H = xyz[idx][2] + abs(xyz[idx][0] - cx) + abs(xyz[idx][1] - cy)
        for x,y,h in xyz:
            if h != max(H - abs(x - cx) - abs(y - cy), 0):
                switch = 0
                break
        if switch == 1:
            print(cx, cy, H)
            sys.exit()
            

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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

vector<vector<int>> e;

pair<int,int> dfs(int x,int par){
  pair<int,int> p = {0,x};
  for(auto nx:e[x]){
    if(nx!=par){
      auto np=dfs(nx,x);
      p=max(p,np);
    }
  }
  // cout << x SP p.second SP p.first << endl;
  p.first++;
  return p;
}

int main(){
  int n;
  cin >> n;
  e=vector<vector<int>>(n);
  for(int i=0;i<n-1;i++){
    int a,b;
    cin >> a >> b;
    a--,b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  int r = dfs(0,-1).second;
  int x = dfs(r,-1).first;
  x--;
  // cout << x << endl;
  if((x+1)%3==2){
    cout << "Second" << endl;
  }else{
    cout << "First" << endl;
  }
  return 0;
}


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

void string_reverse(string &s) {
    reverse(s.begin(), s.end());
}

void insert_front(string &s, string c) {
    s.insert(0, c);
}

void insert_back(string &s, string c) {
    s.insert(s.length(), c);
}

int main() {
    string s;
    cin >> s;
    int n;
    cin >> n;
    int t, f;
    string c;
    bool reverse = false;
    for(int i = 0; i < n; i++) {
        
        cin >> t;
        if(t == 1) {
            if(reverse == false) {
                reverse = true;
            }
            else {
                reverse = false;
            }
        }
        else {
            cin >> f >> c;
            if(f == 1) {
                if(reverse == true) {
                    insert_back(s, c);
                }
                else {
                    insert_front(s, c);
                }
            }
            else {
                if(reverse == true) {
                    insert_front(s, c);
                }
                else {
                    insert_back(s, c);
                }
            }
        }
    }
    if(reverse == true) {
        string_reverse(s);
    }
    cout << s << endl;
}

Measured memory_bytes: 900
"""
Writer: SPD_9X2
https://atcoder.jp/contests/arc102/tasks/arc102_c

各Kに関して O(N)くらいで求める必要がある
とあるkについて考えてみようか

kが奇数の時を考える。

1,k-1
2,k-2
3,k-3
…

の各ペアに関して片方のみ登場していい。
登場して良い数字の選び方は2^(k/2)通り
登場していいのに出ないやつがいると、重複する
包除原理で消すか？ t(=k/2)ペアあるとする。いつ出ても構わないのがx個あったとする

{2^t * H(n,x+t) } - tC1 * {2^(t-1) * H(n,x+t-1) } + tC2 * {}　…
で求まる。 計算量はO(K)くらい

kが偶数の時は,k/2が1度だけ登場する or しないを選んでおく
登場すると決めたら,nが1だけ小さくなる　後は同様にやるだけ

tの数、k/2 じゃないじゃん
→これを考え直さなきゃ k > Kのとき上手く計算できない
l,rで考えよう→ rが最大はK なのでl最小は k-K
k-K-1をKから引くと K-(k-K-1) = 2*K-k+1 の長さ
ここから両端からとっていくので　t = (2*K-k)//2となる


"""

#modのn!と、n!の逆元を格納したリストを返す(拾いもの)
#factorialsには[1, 1!%mod , 2!%mod , 6!%mod… , n!%mod] が入っている
#invsには↑の逆元が入っている

def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs

def modnCr(n,r,mod,fac,inv): #上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる)
    return fac[n] * inv[n-r] * inv[r] % mod

def modnHr(n,r,mod,fac,inv):
    return modnCr(n+r-1,n,mod,fac,inv)

K,N = map(int,input().split())
mod = 998244353
fac,inv = modfac(N+K+10,mod)

for k in range(2,2*K+1):

    ans = 0

    if k % 2 == 1: #奇数の時
        if k <= K:
            t = k // 2
        else:
            t = (2*K-k+1)//2
        x = K - t*2

        if x == 0:
            end = t
        else:
            end = t+1

        for u in range(0,end):
            now = modnCr(t,u,mod,fac,inv) * pow(2,t-u,mod) * modnHr(N,x+t-u,mod,fac,inv)
            if u % 2 == 0:
                ans += now
            else:
                ans -= now
            ans %= mod
            #print (u,now)

    else: #偶数の時

        if k <= K:
            t = (k-1) // 2
        else:
            t = (2*K-k)//2
 
        x = K - t*2 - 1

        if x == 0:
            end = t
        else:
            end = t+1

        for u in range(0,end):
            now = modnCr(t,u,mod,fac,inv) * pow(2,t-u,mod) * ( modnHr(N,x+t-u,mod,fac,inv) + modnHr(N-1,x+t-u,mod,fac,inv) )
            if u % 2 == 0:
                ans += now
            else:
                ans -= now
            ans %= mod
            #print (u,now)

    
    print (ans % mod)


Measured memory_bytes: 54864
#include<stdio.h>
#include<algorithm>

using namespace std;

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


int main(void) {
  int n;
  int array[100000];

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

  int index = partition(array, 0, n - 1);

  for(int i = 0; i < n; i++) {
    if(i > 0) {
      printf(" ");
    }


    if(i == index) {
      printf("[%d]", array[i]);
    }
    else {
      printf("%d", array[i]);
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 1420
#include<stdio.h>

unsigned length(char text[])
{
  unsigned len = 0;

  while(text[len])
    len++;
  return(len);
}

void count(char str[])
{
  int cnt[26] = {0};
  int i = 0;
  int j = 0;
  int num = 0;  //2回出現した文字数


  while(i<=26){
    if(str[i]>='A' && str[i]<='Z' && ++cnt[str[i]-'A'] == 2){
        j++;
    }
    i++;
  }

  if(j==2)
    puts("Yes");
  else
    puts("No");
}

int main(void)
{

  char text1[4];
  char text2;
  int flag1=0;
  int flag2=0;

  while(1)
  {
    scanf("%s",text1);
    if(length(text1) != 4)
    {
      puts("4 letters");
    }
    else
      break;
  }

  count(text1);

  return(0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define repn(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) for(int i = 0; i < (a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int dp[100005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, k;
	cin >> n >> k;
	int a[n + 1];
	repn(i, 1, n + 1){
		cin >> a[i];
	}
	repn(i, 1, k + 1){
		repn(j, 1, n + 1){
			if(i >= a[j] && !dp[i - a[j]]){
				dp[i] = 1;
				break;
			}
		}
	}
	cout << (dp[k] ? "First" : "Second") << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
	int n,y,a,b,c;
	cin>>n>>y;
	for(int a=0;a<=n;a++)
	for(int b=0;b<=n;b++)
	{
		c=n-a-b;
		if(c>=0 && a*10000+b*5000+c*1000==y)
		{
			cout<<a<<' '<<b<<' '<<c;
			return 0;
		}
	}
	cout<<"-1 -1 -1";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int dp[101][10200];
int main(){
	dp[0][0]=1;
	int n;
	int s[101];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<=10000;j++){
			if(dp[i][j]==1){
				dp[i+1][j]=1;
				dp[i+1][j+s[i]]=1;
			}
		}
	}
	for(int i=10000;i>=0;i--){
		if(i%10!=0 && dp[n][i]==1){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 2560
/*
 *  A - Weather Prediction
 * author: roy4801
 * (C++)
 */
#include <bits/stdc++.h>

using namespace std;

#define PROB "A"
#define TESTC ""

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;
#define F first
#define S second
#define INF 0x3f3f3f3f
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PPB pop_back
#define PF push_front
#define PPF pop_front
string s;
string p[] = {"Sunny", "Cloudy", "Rainy"};
int i;
int main()
{
	#ifdef DBG
	freopen("./testdata/" PROB TESTC ".in", "r", stdin);
	freopen("./testdata/" PROB ".out", "w", stdout);
	#endif
	while(cin >> s)
	{
		for(int i = 0; i < 3; i++)
			if(s == p[i])
				cout << p[(i+1)%3] << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)

typedef unsigned long long ll;
const int maxn = 105;
const ll mod = 1e9+7;
const int INF = 0x3f3f3f;
const double eps = 1e-9;

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

ll nlcm(ll *a,int n)
{
    if(n==1) return *a;
    return lcm(a[n-1],nlcm(a,n-1));
}

int main()
{
    ll a[105];
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
        {
            scanf("%lld",&a[i]);
        }
        ll ans=nlcm(a,n);
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int target = sc.nextInt();
        if(n*500>=target)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
    }

Measured memory_bytes: 21844
import numpy as np
s = np.array([int(i) for i in list(input())])
if len(s)%2==0:
  t1 = np.array([int(i) for i in list("10"*int(len(s)/2))])
  t2 = np.array([int(i) for i in list("01"*int(len(s)/2))])
else:
  t1 = np.array([int(i) for i in list("10"*int((len(s)-1)/2)+"1")])
  t2 = np.array([int(i) for i in list("01"*int((len(s)-1)/2)+"0")])
ans = min(len(np.where((t1+s) == 1)[0]), len(np.where((t2+s) == 1)[0]))
print(ans)

Measured memory_bytes: 15780
import java.util.Scanner;

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

        if(n == 1) {
            System.out.println(1);
            System.exit(0);
        }

        int count = 0;
        int tmpCount = 0;
        int outputNum = 0;

        for(int i=n; i>0; i--) {
            if(i % 2 == 0) {
                int tmp = i;
                while(true) {
                    if(tmp % 2 == 0) {
                        tmp /= 2;
                        tmpCount++;
                    } else {
                        break;
                    }
                }
                if(count < tmpCount) {
                    outputNum = i;
                    count = tmpCount;
                }
            }
            tmpCount = 0;
        }
        System.out.println(outputNum);
    }
}


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

int compare_int(const void *a,const void *b){
  if(*(int*)a > *(int*)b) return 1;
  return -1;
}

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

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

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

  qsort(B, N, sizeof(int), compare_int);
  for (int i = 0; i < N; i++) {
    if(A[i] == B[N-1]) printf("%d\n", B[N-2]);
    else printf("%d\n", B[N-1]);
  }

  return 0;
}

Measured memory_bytes: 3116