akhauriyash/Code-Regression huggingface dataset:
/**
 *    created by : PawPaw       
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  

using namespace __gnu_pbds;  
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,  
        tree_order_statistics_node_update>  
        ordered_set;  

#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LL long long
#define N 1000001
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define FbO find_by_order
#define OoK order_of_key

int solve(){
  int n;
  LL sum = 0, a, cnt[100];
  fill(cnt, cnt+100, 0);
  cin >> n;
  F(i, 1, n){
    cin >> a;
    F(j, 0, 60){
      if((a | ((LL)1 << j)) == a){
        cnt[j]++;
        sum = sum + ((((LL)i-cnt[j])*(((LL)1 << j) % MOD)) % MOD ) % MOD;
      }
      else {
        sum = sum + (((cnt[j])*(((LL)1 << j) % MOD)) % MOD) % MOD;
      }
    }
  }
  cout << sum % MOD << '\n';
  return 0;
}

void fun(){
  int t = 1;
  // cin >> t;
  while(t--) solve();
} 

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

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

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	char c;
	stack<int> s;
	vector<pair<int, int>> l;
	int i = 0;
	int total = 0;
	while(cin >> c) {
		if (c == '\\') s.push(i);
		else if (c == '/' && !s.empty()) {
			total += i - s.top();
			int x = i - s.top();
			while (!l.empty() && s.top() < l.back().first) {
				x += l.back().second;
				l.pop_back();
			}
			l.push_back(mp(s.top(), x));
			s.pop();
		}
		i++;
	}

	int sum = 0;
	for (auto x : l) sum += x.second;

	cout << sum << endl;

	cout << l.size();

	for (size_t i = 0; i < l.size(); i++) {
			cout << " " << l[i].second;
	}	
	cout << endl;
	return 0;
}



Measured memory_bytes: 3200
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int
var t float64

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	as := intSliceScanner(n)
	sort.Sort(sort.Reverse(sort.IntSlice(as)))
	ans := 0
	for i := 1; i < n; i++ {
		ans += as[i/2]
	}
	fmt.Println(ans)
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

bool check(string S)
{
    string T = S;
    reverse(ALL(T));
    return S == T;
}

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

    string S; cin >> S;
    int N = S.size();
    string T;
    for (auto c : S) if (c != 'x') T += c;

    bool ok = check(T);
    if (!ok) {
        cout << -1 << endl;
        return 0;
    }

    int l = 0, r = N-1;
    int ans = 0;
    while (l<r) {
        if (S[l] == 'x' && S[l] != S[r]) {
            ans++;
            l++;
        } else if (S[r] == 'x' && S[l] != S[r]) {
            ans++;
            r--;
        } else {
            l++, r--;
        }
    }
    cout << ans << endl;
}

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

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<int64_t> a(N);
	for (auto& e: a) scanf("%d", &e);
	for (int i{1}; i < N; i++)
		a[i] += a[i - 1];
	int64_t sum{a.back()};
	int64_t min{1ll << 60};
	for (int i{}; i < N - 1; i++)
		min = std::min(min, std::abs(a[i] - (sum - a[i])));
	printf("%d\n", min);

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(a*b)/2<<endl;
 return 0;   
}

Measured memory_bytes: 256
n=int(input())

maxx=0
maxn=1
for i in range(1,n+1):
  tmp=i
  cnt=0
  while 1:
    if tmp%2==0:
      tmp=tmp//2
      cnt+=1
    else:
      break
  if cnt > maxx:
    maxn=i
    maxx=cnt

print(maxn)

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

int main(){
    int n , k;
    cin >> n >> k;
    int sum = 0;
    int h[n];
    rep(i,n){
        cin >> h[i];
        if(h[i] >= k)sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N;
    cin >> N;
    vector<vector<int>> mat(N, vector<int>(N));
    REP(i, N) {
        string x;
        cin >> x;
        REP(j, N) {
            mat[i][j] = x[j] - '0';
        }
    }
    int ans = -1;
    
    REP(i, N) {
        vector<set<int>> V;
        V.push_back({i});
        vector<bool> used(N, false);
        used[i] = true;
        vector<bool> lastused(N, false);
        bool flg = false;
        while(true) {
            set<int> st;
            vector<bool> lasttemp(N, false);
            for(int x : V[V.size()-1]) {
                lasttemp[x] = true;
                //cout << V.size() << " " << x << endl;
                REP(y, N) {
                    if(mat[x][y] == 1) {
                        if(used[y]) {
                            if(!lastused[y]) {
                                flg = true;
                                break;
                            }
                        } else {
                            st.insert(y);
                        }
                        
                    }
                }
                if(flg) break;
            }
            if(flg) break;
            lastused = lasttemp;
            for(int x : st) {
                used[x] = true;
            }
            if(st.size() == 0) break;
            V.push_back(st);
        }
        if(flg) continue;
        int sz = V.size();
        if(sz > ans) {
            ans = sz;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#define N 2002
using namespace std;
struct team{
  int tnum;
  int correct;
  int time;
};
int main(){
  int m,t,p,r,im[N],it[N],ip[N],ij[N],incorrect,i,j;
  struct team data[51];
  while(1){
    cin >> m >> t >> p >> r;
    if(m==0&&t==0&&p==0&&r==0) break;
    for(i=0;i<r;i++) cin >> im[i] >> it[i] >> ip[i] >> ij[i];
    for(i=1;i<=t;i++){
      data[i].tnum=i;
      data[i].correct=0;
      data[i].time=0;
    }
    for(i=0;i<r;i++){
      if(ij[i]==0){
	data[it[i]].correct++;
      	incorrect=0;
	for(j=0;j<i;j++){
	  if(it[i]==it[j]&&ip[i]==ip[j]) incorrect++;
	}
	data[it[i]].time=data[it[i]].time+incorrect*20+im[i];
      }
    }
    for(i=0;i<=t;i++){
      for(j=2;j<=t;j++){
	if(data[j].tnum>data[j-1].tnum) swap(data[j],data[j-1]);
      }
    }
    for(i=0;i<=t;i++){
      for(j=2;j<=t;j++){
	if(data[j].time<data[j-1].time) swap(data[j],data[j-1]);
      }
    }
    for(i=0;i<=t;i++){
      for(j=2;j<=t;j++){
	if(data[j].correct>data[j-1].correct) swap(data[j],data[j-1]);
      }
    }
    /*    for(i=1;i<t;i++){
      cout << data[i].tnum;
      if(data[i].correct==data[i+1].correct&&data[i].time==data[i+1].time)
	cout << '=';
      else cout << ',';
      if(i==t-1) cout << data[i+1].tnum;
      }*/
    //cout << endl;
        for( i = 1; i <= t-1; i++ ){
      cout << data[i].tnum;
      if( data[i].correct > data[i+1].correct )  cout << ",";
      else if( data[i].time < data[i+1].time ) cout <<  ",";
      else cout << "=";
      }
    cout << data[t].tnum << endl;
  }
  return 0;
}

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

#define ll long long

ll t[22][22], c[1<<17], dp[1<<17], res;

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

  int n;  cin >> n;

  for(int i=0; i<n; i++)
    for(int j=0; j<n; j++)
      cin >> t[i][j];

  for(int i=0; i<(1<<n); i++)
    for(int j=0; j<n; j++)
      for(int m=0; m<n; m++)
        if(i&(1<<j) and i&(1<<m))
          c[i]+=t[j][m];

  for(int i=1; i<(1<<n); i++) {
    for(int j=i; j>0; j=(j-1)&i)  {
      dp[i] = max(dp[i], c[j]/2LL+dp[i-j]);
      res = max(res, dp[i]);
    }
  }
    cout <<res;
}


Measured memory_bytes: 1280
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
#define LAST(X) X[X.size()-1]
#define MOD 1000000007
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	int a,b,h;
	cin >> a >> b >> h;
	cout << (a+b)*h/2;
}

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

using namespace std;

int main() {

	int N;
	cin >> N;

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

		int out = 0, point = 0, a[4] = {};
		string event;

		while (out < 3) {
			cin >> event;

			if (event == "HIT") {
				a[3] = a[2];
				a[2] = a[1];
				a[1] = a[0];
				a[0] = 1;
				if (a[3] == 1) {
					point++;
					a[3] = 0;
				}
			}
			if (event == "HOMERUN") {
				for (int j = 0; j < 3; j++) {
					if (a[j] == 1) {
						point++;
					}
					a[j] = 0;
				}
				point++;
			}
			if (event == "OUT") {
				out++;
			}
		}
		cout << point << endl;
	}

	return 0;
}


Measured memory_bytes: 3004
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if (b % a == 0) {
            System.out.println(a + b);
        } else {
            System.out.println(b - a);
        }
    }
}


Measured memory_bytes: 21588
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;



ll solve(void);
ll gcd(ll x, ll y);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}

ll power(ll n, ll r)
{
	if ( r == 0 ) { return 1; }
	if ( r == 1 ) { return n; }
	if ( n == 0 ) { return 0; }
	if ( n == 1 ) { return 1; }

	if (r % 2 == 0)
	{
		ll y = pow(n, r/2);
		return y * y;
	}
	else
	{
		ll y = pow(n, (r-1)/2);
		return n * y * y;
	}


}

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}


ll solve(void)
{
	ll n;
	cin >> n;

	vector<ll> x(n);
	for (auto& tx: x)
		cin >> tx;

	ll mu = 0;
	for (auto tx : x)
		mu += tx;

	mu /= n;

	vector<ll> as = {mu, mu + 1};
	ll ans = inf;

	for (auto a : as)
	{
		ll tmp = 0;
		for (auto tx: x)
			tmp += power(tx - a, 2);
		ans = min(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;


int main() {

	ll N, P, P0;
	cin >> N >> P;

	P0 = P;

	ll a = sqrt(P);

	vector<ll>s(a + 1, 0);

	repl(i, 2, a + 1) {
		while (P  % i == 0) {
			P /= i;
			s[i] ++;
		}
	}
	ll ans = 1, tmp;

	rep(i, a + 1) {
		if (s[i] >= N) {
			tmp = s[i] / N;
			ans *= pow(i, tmp);
		}
	}

	if (N == 1) {
		cout << P0;
	}
	else {
		cout << ans;
	}

	return 0;
}


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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h,w,n,a,b;
    cin>>n;
    vector<pll>arr(n),brr(n);
    map<ll,ll>m;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        arr[i]=mp(a+b,a-b);
    }
    sort(arr.begin(),arr.end());
    ll i=0,j=1,c=0;
    while(i<n && j<n){
        if(arr[j].second<arr[i].first){
            j++;
            c++;
        }
        else{
            i=j;
            j=i+1;
        }

    }
    cout<<n-c;


    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<vector>

int main(){
  int n,k;
  std::cin >> n >> k;
  int p = k*2;
  std::vector<std::vector<int> > w(p,std::vector<int>(p,0));
  std::vector<std::vector<int> > b(p,std::vector<int>(p,0));
  int wa = 0, ba = 0;
  for(int i=0;i<n;i++){
    int x,y;
    char c;
    std::cin >> x >> y >> c;
    if(c=='W') w[x%p][y%p]++, wa++;
    if(c=='B') b[x%p][y%p]++, ba++;
  }
  for(int i=0;i<p;i++){
    for(int j=1;j<p;j++){
      w[i][j] += w[i][j-1];
      b[i][j] += b[i][j-1];
    }
  }
  for(int i=0;i<p;i++){
    for(int j=1;j<p;j++){
      w[j][i] += w[j-1][i];
      b[j][i] += b[j-1][i];
    }
  }
  int m = 0;
  for(int i=0;i<p-k;i++){
    for(int j=0;j<p-k;j++){
      int L = 0, R = 0;
      L += w[i][j];
      L += w[i+k][j+k] - w[i][j+k] - w[i+k][j] + w[i][j];
      L += w[i][p-1] - w[i][j+k];
      L += w[p-1][j] - w[i+k][j];
      L += w[p-1][p-1] - w[i+k][p-1] - w[p-1][j+k] + w[i+k][j+k];
      R += b[i][j];
      R += b[i+k][j+k] - b[i][j+k] - b[i+k][j] + b[i][j];
      R += b[i][p-1] - b[i][j+k];
      R += b[p-1][j] - b[i+k][j];
      R += b[p-1][p-1] - b[i+k][p-1] - b[p-1][j+k] + b[i+k][j+k];
      int dL = ba - R, dR = wa - L;
      L += dL, R += dR;
      m = std::max(std::max(m,L),R);
    }
  }
  std::cout << m << std::endl;
  return 0;
}

Measured memory_bytes: 31616
n=int(input())
a=list(map(int,input().split()))
ans=0
b=a[0]
up=True
down=True
for i in range(1,n):
    if b<a[i] and up:
        down=False
        b=a[i]
    elif b>a[i] and down:
        up=False
        b=a[i]
    elif b<a[i] and not(up):
        ans+=1
        up=True
        b=a[i]
    elif b>a[i] and not(down):
        ans+=1
        down=True
        b=a[i]
    else:
        continue
print(ans+1)

Measured memory_bytes: 14224
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define itr(macro_v,i) macro_v.begin()+i
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;
const ll MOD = 1000000007;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    map<char, ll> mp;
    for(int i=0; i<n; i++){
        mp[s[i]]++;
    }
    ll ans=1ll;
    for(auto m: mp){
        ans = (ans%MOD)*(m.second+1)%MOD;
    }
    cout << (ans-1)%MOD << endl;
    return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h, w;
    cin >> h >> w;
    vector<vector<int>> grid(h, vector<int> (w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> grid[i][j];
        }
    }
    vector<vector<int>> seq;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (grid[i][j] & 1) {
                if (j + 1 != w) {
                    grid[i][j]--;
                    vector<int> s {i + 1, j + 1, i + 1, j + 2};
                    grid[i][j + 1]++;
                    seq.push_back(s);
                } else if (i + 1 != h) {
                    grid[i][j]--;
                    vector<int> s {i + 1, j + 1, i + 2, j + 1};
                    grid[i + 1][j]++;
                    seq.push_back(s);
                }
            }
        }
    }
    cout << seq.size() << endl;
    for (auto s: seq) {
        cout << s[0] << " " << s[1] << " " << s[2] << " " << s[3] << endl;
    }
}



Measured memory_bytes: 10032
#include<bits/stdc++.h>
#define N 20001
using namespace std;
 
struct data{
  long long t;
  int s,d;
};
 
int main(){
  while(1){
  int n,m,f[N]={},cnt=1;
  data da[N];
  cin>>n>>m;
  if(n+m==0) break;
  f[1]=1;
  for(int i=0;i<m;i++)cin>>da[i].t>>da[i].s>>da[i].d;
   
    for(int i=0;i<m-1;i++)
    for(int j=m-1;j>i;j--)
    if(da[j].t<da[j-1].t)swap(da[j],da[j-1]);
         
    for(int i=0;i<m;i++){
      if(f[da[i].s]==1)f[da[i].d]=1;
      if(da[i].s==1)f[da[i].d]=1;
    }
    for(int i=2;i<=n;i++) if(f[i]==1)cnt++;
    cout<<cnt<<endl;
  }
  
   
  return 0;
}

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

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var N = Read().ToDouble();
            double max = 1;
            for (double i = 1; i <= Math.Sqrt(N); i++)
            {
                if (N % i == 0)
                {
                    if (max - 1 + (N / max) - 1 > i - 1 + (N / i) - 1)
                    {
                        max = i;
                    }
                }
            }
            WriteRead(max - 1 + (N / max) - 1);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}


public static class Extentions
{
    public static int ToInt32(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long ToInt64(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))


        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 13140
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000)

C = input()

C = C.replace('\n', '')

alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'e', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

index_c = alphabets.index(C)

print(alphabets[index_c + 1])


Measured memory_bytes: 3060
import Data.Int
import Data.Ratio

main = do
  n <- readLn
  as <- map read.words <$> getLine
  print $ solve (Mod n) (map Mod as)

solve :: ModInt -> [ModInt] -> ModInt
solve n as = sum $ zipWith (*) as $ map (*product[1..n]) ps where
  ps = map (subtract 1) $ zipWith (+) csr (reverse csr)
  csr = scanl1 (+) $ map recip [1..n]

modulo = 10^9+7

newtype ModInt = Mod Int deriving (Eq)

instance Show ModInt where
  show (Mod a) = show a
instance Bounded ModInt where
  maxBound = Mod $ modulo - 1
  minBound = Mod 0
-- Caution! If (value>=modulo), this does not work.
instance Enum ModInt where
  toEnum a = Mod $ mod a modulo
  fromEnum (Mod a) = a
instance Num ModInt where
  (Mod a) + (Mod b) = Mod $ mod (a+b) modulo
  (Mod a) * (Mod b) = Mod $ mod (a*b) modulo
  abs = id
  signum = const (Mod 1)
  fromInteger a = Mod $ fromIntegral $ mod a $ fromIntegral modulo
  negate (Mod 0) = Mod 0
  negate (Mod a) = Mod $ modulo - a
instance Fractional ModInt where
  recip a = a ^ (modulo-2)
  fromRational r = Mod (n * signum d) / Mod (abs d) where
    [n,d] = [fromIntegral] <*> ( [numerator,denominator] <*> [r] )


Measured memory_bytes: 109948
/**
 * https://atcoder.jp/contests/abc173/tasks/abc173_c
 */
fun main() {
    val (h, w, k) = readLine()!!.split(" ").map { it.toInt() }
    val cList = Array(h) { "" }
    for (i in 0 until h) {
        cList[i]= readLine()!!
    }

    var answer = 0
    for (maskR in 0 until 1.shl(h)) {
        for (maskC in 0 until 1.shl(w)) {
            var black = 0
            for (i in 0 until h) {
                for (j in 0 until w) {
                    if (maskR.shr(i).and(1) == 0 && maskC.shr(j).and(1) == 0 && cList[i][j] == '#') {
                         black += 1
                    }
                }
            }

            if (black == k) {
                answer += 1
            }
        }
    }

    print(answer)
}


Measured memory_bytes: 37092
#include <array>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <utility>
#include <tuple>
#include <algorithm>
#include <limits>
#include <fstream>
#include <numeric>
#include <stack>
#include <queue>
#include <list>
#include <cstring>
#include <unordered_set>
#include <cmath>
#include <iomanip>
#include <map>

namespace
{
	template<int N>
	std::array<int, N> GetValue(std::istream& stream)
	{
		std::string buf;
		std::getline(stream, buf);

		std::stringstream sstr(buf);
		std::array<int, N> retval;

		for (int i = 0; i < N; ++i)
		{
			std::getline(sstr, buf, ' ');
			retval[i] = std::stoi(buf);
		}

		return retval;
	}

	std::vector<int> GetValue(std::istream& stream, int num, char delim)
	{
		std::string buf;
		std::getline(stream, buf);
		std::stringstream sstr(buf);

		std::vector<int> retval;
		retval.reserve(num);

		std::string input;;
		for (int i = 0; i < num && std::getline(sstr, input, delim); ++i)
		{
			retval.push_back(std::stoi(input));
		}

		return retval;
	}

	int GetValue(std::istream& stream)
	{
		int in;
		stream >> in;

		return in;
	}

	std::vector<std::string> GetValueString(std::istream& stream, int num, char delim)
	{
		std::string buf;
		std::vector<std::string> retval;
		retval.reserve(num);

		std::getline(stream, buf);
		std::stringstream sstr(buf);

		for (int i = 0; i < num && std::getline(sstr, buf, delim); ++i)
		{
			retval.push_back(std::move(buf));
		}

		return retval;
	}

	template<typename Itr>
	void PrintLine(Itr begin, Itr end)
	{
		bool first = true;

		for (int i = 0; begin != end; ++begin, ++i)
		{
			if (!first)
			{
				std::cout << ' ';
			}

			std::cout << (*begin);

			first = false;
		}
		std::cout << std::endl;
	}

	template<typename T>
	void Print(const std::vector<T>& sequence)
	{
		for (const auto& e : sequence)
		{
			std::cout << e << '\n';
		}

		std::cout << std::flush;
	}

}

int main(int argc, char* argv[])
{
	auto file = (argc == 1) ? std::ifstream() : std::ifstream(argv[1]);
	std::istream& stream = (argc == 1) ? std::cin : file;
	if (argc == 1)
	{
		std::cin.tie(0);
		std::ios::sync_with_stdio(false);
	}

	std::string str;
	stream >> str;

	std::string s1 = str.substr(0, str.size() / 2);
	std::string s2 = str.substr(str.size() / 2);
	std::reverse(s2.begin(), s2.end());

	int count = 0;
	int size = s1.size();
	for (int i = 0; i < size; ++i)
	{
		if (s1[i] != s2[i])
		{
			++count;
		}
	}

	std::cout << count << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int main()
{
    using namespace std;
    int K, sum(0);
    cin >> K;
    for (int i = 1; i <= K; i++)
    {
        for (int j = 1; j <= K; j++)
        {
            for (int k = 1; k <= K; k++)
            {
                sum += gcd(gcd(i, j), k);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const int Inf = 1LL << 60;
const int Maxn = 1e5;

int n;
int s[Maxn + 5];
map <LL , int >cnt;

int main ()
{
	while (~scanf("%d",&n))
	{
		int ans = 0;
		for (int i  = 1; i <= n; i++)
		{
			LL x;
			scanf("%lld",&x);
			if (cnt[x] == 0)
			{
				cnt[x] = 1; 
				ans++;
			}
			else if (cnt[x] == 1){
				cnt[x] = 0;
				ans--;
			}
		}
		printf("%d\n",ans);
		cnt.clear();
	}
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};

int h, w;
int fld[110][110];
int came[110][110]; // 訪れたことがあるか
int a[110][110]; // 隣接する建物の個数

vector<vector<int>> dx(6, vector<int>(2));
vector<vector<int>> dy(6, vector<int>(2));

int isOK(int x, int y) {
	if(x < 0 || y < 0 || w <= x || h <= y) return 0;
	return 1;
}

void move_init() {
	dx = { 
		{-1, -1, -1, 0, 1, 0},
		{0, -1, 0, 1, 1, 1}
	};
	dy = {
		{-1, 0, 1, 1, 0, -1},
		{-1, 0, 1, 1, 0, -1}
	};
}

// 隣接する建物を数える
int count(int x, int y) {
	int res = 0;
	if(!isOK(x, y)) return 0;
	if(fld[y][x]) return 0;
	rep(i, 6) {
		int nx = x + dx[y % 2][i];
		int ny = y + dy[y % 2][i];
		//cout << nx << " " << ny << endl;
		if(!isOK(nx, ny)) continue;
		if(fld[ny][nx]) res++;
	}
	return res;
}

void bfs(int sx, int sy) {
	int res = 0;
	queue<P> que;
	que.push(P(sx, sy));
	came[sy][sx] = 1;
	a[sy][sx] = count(sx, sy);

	while(que.size()) {
		P p = que.front();
		que.pop();
		rep(i, 6) {
			int nx = p.first + dx[p.second % 2][i];
			int ny = p.second + dy[p.second % 2][i];
			if(!isOK(nx, ny)) continue;
			if(fld[ny][nx] || came[ny][nx]) continue;
			res += count(nx, ny);
			a[ny][nx] = count(nx, ny);
			que.push(P(nx, ny));
			came[ny][nx] = 1;
		}
	}
	//return res;
}

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

	cin >> w >> h;
	rep(i, h) {
		rep(j, w) cin >> fld[i+1][j+1];
	}
	w += 2; h += 2;

	move_init();
	bfs(0, 0);
	int ans = 0;
	rep(i, h+2) {
		rep(j, w+2) {
			ans += a[i][j];
		}
	}

	// int x, y;
	// cin >> x >> y;
	// cout << count(x, y) << endl;

	cout << ans << endl;
	
	// Print Debug

	// rep(i, h) {
	// 	if(i % 2 == 0) cout << " ";
	// 	else cout << "  ";
	// 	rep(j, w) cout << fld[i][j] << " ";
	// 	cout << endl;
	// }
	// cout << endl;

	// rep(i, h) {
	// 	if(i % 2 == 0) cout << " ";
	// 	else cout << "  ";
	// 	rep(j, w) cout << came[i][j] << " ";
	// 	cout << endl;
	// }
	return 0;
}



Measured memory_bytes: 3392
"""
author : halo2halo
date : 31, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

W, A, B = map(int, readline().decode('utf8').split())
mi = min(A, B)
ma = max(A + W, B + W)
print(max(0, ma - mi - 2 * W))


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

int main() {
  long n, a, b;
  cin >> n >> a >>  b;
  long l = n / (a + b);
  long d = n % (a + b);
  if(d == 0){
    cout << a * l << endl;
  }else{
    if(d < a){
      cout << (a * l) + d << endl;
    }else{
      cout << (a * l) + a << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a_ary = gets.chomp.split(' ').map(&:to_i)
taoseru_ary = gets.chomp.split(' ').map(&:to_i)

ans = 0
taoseru_ary.each_with_index do |taoseru, idx|
  # 倒せる数よりAiにいるモンスターの数が多いとき
  if a_ary[idx] >= taoseru
    ans += taoseru
  else # まだ倒せるモンスターががいる時
    # 隣町のモンスターを含めると、倒しきれないとき
    if a_ary[idx+1] + a_ary[idx] >= taoseru
      ans += taoseru
      a_ary[idx+1] = a_ary[idx+1] - (taoseru - a_ary[idx])
    else
      # 隣町のモンスターを倒しきれるとき
      ans += a_ary[idx+1] + a_ary[idx]
      a_ary[idx+1] = 0
    end
  end
end
puts ans


Measured memory_bytes: 17556
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


int n, m;
int ne[10];
bool b[10][10];
signed main() {
	cin >> n >> m;
	rep(i, n)ne[i] = i + 1;
	rep(i, m) {
		int f, t; cin >> f >> t; f--; t--;
		b[f][t] = true; b[t][f] = true;
	}
	int ans = 0;
	do {
		if (!b[0][ne[0]])goto ng;
		rep(i, n - 2) {
			if (!b[ne[i]][ne[i + 1]])goto ng;
		}
		ans++;
	ng:;
	} while (next_permutation(ne, ne + n - 1));
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Mon Feb 10 22:50:12 JST 2020
 **/

signed main() {
    Int x, y; cin >> x >> y;
    cout << (x + y - 1) / y << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){

  while(1){
    int n;
    int l;
    cin >> n;
    cin >> l;
    if(n == 0 && l == 0){return 0;}

    char d[n];
    int p[n];

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

    int xn[l + 1][2]; // 0が左向き，1が右向き
    int nextxn[l + 1][2]; // 0が左向き，1が右向き

    for(int pos = 0 ; pos < l + 1 ; pos++){
      nextxn[pos][0] = -1;
      nextxn[pos][1] = -1;
    }

    for(int i = 0 ; i < n ; i++){
      if(d[i] == 'L'){
        nextxn[p[i]][0] = i;
      }else if(d[i] == 'R'){
        nextxn[p[i]][1] = i;
      }
    }

    int last;
    int time = 0;

    while( n != 0 ){

      for(int pos = 0 ; pos < l + 1 ; pos++){
        xn[pos][0] = nextxn[pos][0];
        xn[pos][1] = nextxn[pos][1];
      }

      for(int pos = 0 ; pos < l + 1 ; pos++){
        nextxn[pos][0] = -1;
        nextxn[pos][1] = -1;
      }

      if(xn[l-1][1] != -1){
        last = xn[l-1][1];
        n--;
      }

      if(xn[1][0] != -1){
        last = xn[1][0];
        n--;
      }


      if(xn[1][1] != -1){
        if(xn[3][0] != -1){
          nextxn[2][0] = xn[1][1];
        }else{
          nextxn[2][1] = xn[1][1];
        }
      }

      for(int pos = 2 ; pos < l - 1 ; pos++){
        if(xn[pos][0] != -1){
          if(xn[pos - 2][1] != -1){
            nextxn[pos - 1][1] = xn[pos][0];
          }else{
            nextxn[pos - 1][0] = xn[pos][0];
          }
        }

        if(xn[pos][1] != -1){
          if(xn[pos + 2][0] != -1){
            nextxn[pos + 1][0] = xn[pos][1];
          }else{
            nextxn[pos + 1][1] = xn[pos][1];
          }
        }
      }

      if(xn[l - 1][0] != -1){
        if(xn[l - 3][1] != -1){
          nextxn[l - 2][1] = xn[l - 1][0];
        }else{
          nextxn[l - 2][0] = xn[l - 1][0];
        }
      }

      time++;
    }
    cout << time << " " << last + 1 << endl;

  }
}



Measured memory_bytes: 3124
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> 
using namespace std;
long long d[100003],a[100003],q[100003];
int n,m,T,s,t;
int main(){
	cin>>n>>m>>T;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
        d[i]=1e15;
    }
    s=1,t=1;
    long long z=1e15;
    for(int i=1;i<=n;i++){
        while(s<=t&&2*(a[i]-a[q[s]+1])>T){
            z=min(z,d[q[s]]-a[q[s]]-2*a[q[s]+1]);
            s++;
        }
        d[i]=min(d[i],a[i]+z+2*a[i]);
        d[i]=min(d[i],d[q[s]]+a[i]-a[q[s]]+T);
        while(s<=t&&d[q[s]]-a[q[s]]>=d[i]-a[i]){
        	t--;
		}
        q[++t]=i;
    }
    long long ans=d[n]+m-a[n];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

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

    ll power = 1;
    rep(i,n) {
        power = power * (i + 1) % MOD;
    }

    cout << power << endl;
    return 0;
}


Measured memory_bytes: 256
A, B, C, X, Y = list(map(int,input().split()))

C_max = max(X, Y)
min_count = float('inf')

for i in range(0,C_max*2+1,2):
    count = 0
    count += A * max(int(X-i/2),0)
    count += B * max(int(Y-i/2),0)
    count += C * i
    if min_count > count:
        min_count = count

print(min_count)

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

namespace ConsoleApplication66
{
    class Program
    {
        static void Main()
        {
            long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            List<long[]> b = new List<long[]>();
            for (int c = 0; c < a[0]; c++)
            {
                long[] d = Console.ReadLine().Split().Select(long.Parse).ToArray();
                b.Add(d);
            }
            for (int e = 0; e < a[2]; e++)
            {
                int f = int.Parse(Console.ReadLine());
                if (b[f - 1][1] == 1)
                {
                    bool g = true;
                    if (f != b.Count)
                    {
                        for (int h = f; h < b.Count; h++)
                        {
                            if (b[h][1] == 2)
                            {
                                g = false;
                                {
                                    if ((b[h][0] + b[h - 1][0]) / 2 < b[f - 1][0] + a[1]) { Console.WriteLine((b[h][0] + b[h - 1][0]) / 2); break; }
                                    else { Console.WriteLine(b[f - 1][0] + a[1]); break; }
                                }

                            }
                        }
                    }
                    if (g) { Console.WriteLine(b[f - 1][0] + a[1]); }
                }
                else
                {
                    bool g = true;
                    if (f != 0)
                    {
                        for (int h = f - 2; h > -1; h--)
                        {
                            if (b[h][1] == 1)
                            {
                                g = false;


                                if (((b[h][0] + b[h + 1][0]) / 2) < (b[f - 1][0] - a[1])) { Console.WriteLine(b[f - 1][0] - a[1]); break; }
                                else { Console.WriteLine((b[h][0] + b[h + 1][0]) / 2); break; }

                            }
                        }
                    }
                    if (g) Console.WriteLine(b[f - 1][0] - a[1]);
                }
            }
        }
    }
}

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

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(a+b >= c){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

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

#define inf 0x3f3f3f3f

using namespace std;

typedef long long ll;

int i, j;
string s;
int n, k;
ll dp[100001][13] = {0};
const ll mod = 1e9 + 7;

void solve() {
  cin >> n >> k;
  vector<int> data(n);
  int sum = 0;
  for (i = 0; i < n; ++i) {
    cin >> data[i];
    sum += data[i];
  }
  vector<int> cand(0);
  int sqr = sqrt(sum);
  for (i = 1; i < sqr + 1; ++i) {
    if (sum % i == 0) {
      cand.push_back(i);
      cand.push_back(sum / i);
    }
  }
  sort(cand.begin(), cand.end(), greater<int>());
  int remainder_sum = 0, count = 0;
  vector<int> remainder(n);
  for (i = 0; i < cand.size(); ++i) {
    remainder_sum = 0;
    count = 0;
    for (j = 0; j < n; ++j) {
      remainder[j] = data[j] % cand[i];
      remainder_sum += remainder[j];
    }
    sort(remainder.begin(), remainder.end());
    remainder_sum /= cand[i];
    for (j = 0; j < remainder_sum; ++j) {
      count += cand[i] - remainder[n - j - 1];
    }
    if (count <= k) {
      cout << cand[i] << endl;
      return;
    }
  }
  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}


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

int main(){
  stack<int> S1;
  stack<pair<int, int> > S2;
  char ch;
  int sum=0;
  for(int i=0;cin >> ch;i++){
    if(ch=='\\')S1.push(i);
    else if(ch=='/' && S1.size()>0){
      int j=S1.top();
      S1.pop();
      sum+=i-j;
      int a=i-j;
      while(S2.size()>0 && S2.top().first>j){
	a+=S2.top().second;
	S2.pop();
      }
      S2.push(make_pair(j,a));
    }
  }
  vector<int> ans;
  while(S2.size()>0){
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(),ans.end());
  cout << sum << endl;
  cout << ans.size();
  for(int i=0;i<ans.size();i++){
    cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3160
#include<iostream>
#include<stdio.h>

#define MAX 100000
using namespace std;

int parent(int i) {
	return i / 2;
}

int left(int i) {
	return 2 * i;
}

int right(int i) {
	return (2 * i) + 1;
}

int main() {
	int H, x, T[MAX];

	cin >> H;
	
	for (int i = 1; i < H + 1; i++) {
		cin >> x;
		T[i] = x;
	}

	for (int i = 1; i < H + 1; i++) {
		printf("node %d: key = %d, ", i, T[i]);
		if (i > 1){
			printf("parent key = %d, ", T[parent(i)]);
		}
		if (left(i) < H + 1){
			printf("left key = %d, ", T[left(i)]);
		}
		if (right(i) < H + 1) {
			printf("right key = %d, ", T[right(i)]);
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 3212
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define db double
#define ui unsigned int
#define ll long long
#define ull unsiged ll
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define boots     ios::sync_with_stdio(0); cin.tie(0)
#define pb push_back
#define pp pop_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mod 998244353
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define inf 0x3f3f3f3f
#define lnf LLONG_MAX
#define mii map<int, int>
#define mll map<ll, ll>
#define mil map<int, ll>
#define umii unordered_map<int, int>
#define umll unordered_map<ll, ll>
#define umcc unordered_map<char, char>
#define si(n) scanf("%d", &n)
#define sl(n) scanf("%lld", &n)
#define pf(n) printf("%lld\n", n)
#define sz size
using namespace std;
const db pi = 3.1415926535898;
const int MX = 1e5 + 7;
const int maxn = 1e6 + 7;
const int esp = 1e-6;
bool ji[MX];
int top;
//unordered_map<pair<int, int>, int>mp;
//ll modulo(ll num, ll MOD = mod) { return ((num%MOD) + MOD) % MOD; }
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); }
//void prime() { rep(i, 2, MX - 1) { if (!ji[i])pri[++top] = i; for (int j = 2; j*i < MX; j++)ji[j*i] = 1; } }
const int N = 1e6 + 5;
umii mp;
ll p[MX];
vector<int> pri;
vector<bool> isp(MX, false);
int n;
int vj(int a) {
	if (mp[a] == 0)
		return 0;
	else {
		int b = vj(a + mp[a]);
		mp[a] += b;
		return mp[a];
	}
}
int a[1000], b[30], c[30];
int main() {
	boots;
	int n;
	cin >> n;
	n--;
	rep(i, 1, n)cin >> a[i];
	int ans = a[n];
	per(i, n-1, 1)
	{
		if (a[i] > a[i + 1])
			ans += a[i + 1];
		else ans += a[i];
	}
	cout << ans + a[1] << endl;
}

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

#define all(c) (c).begin(), (c).end()
int const inf = 1<<29;

struct MCF {
    typedef int Weight;
    typedef int Capacity;
    struct Edge;
    int n;
    vector<vector<Edge> > g;
    vector<int> level, iter;

    struct Edge {
        int src, dst;
        Capacity cap;
        int rev;
        bool isRev;
        Edge(int src, int dst, Capacity cap, int rev, bool isRev)
            :src(src), dst(dst), cap(cap), rev(rev), isRev(isRev) {}
    };

    MCF(int n_)
        : n(n_), g(vector<vector<Edge> >(n_)), level(n_), iter(n_) {}

    void add_edge(int src, int dst, Capacity cap) {
        g[src].push_back(Edge(src, dst, cap, g[dst].size(), false));
        g[dst].push_back(Edge(dst, src, 0, g[src].size() - 1, true));
    }

    void bfs(int s) {
        fill(all(level), -1);
        queue<Weight> q;
        level[s] = 0;
        q.push(s);
        while (q.size()) {
            int v = q.front(); q.pop();
            for(int i = 0; i < (int)g[v].size(); i++){
                Edge& e = g[v][i];
                if (e.cap > 0 && level[e.dst] < 0) {
                    level[e.dst] = level[v] + 1;
                    q.push(e.dst);
                }
            }
        }
    }

    Capacity dfs(int v, int t, int f) {
        if (v == t) return f;
        for (int &i = iter[v]; i < (int)g[v].size(); i++) {
            Edge &e = g[v][i];
            if (e.cap > 0 && level[v] < level[e.dst]) {
                int d = dfs(e.dst, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    g[e.dst][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    Capacity max_flow(int src, int dst) {
        int flow = 0;
        while(1){
            bfs(src);
            if (level[dst] < 0) return flow;
            fill(all(iter), 0);
            int f;
            while ((f = dfs(src, dst, inf)) > 0) {
                flow += f;
            }
        }
    }

    void view(){
        for(int i=0;i<g.size();i++){
            for(int j=0;j<g[i].size();j++){
                auto & e=g[i][j];
                printf("%d->%d (%d)\n", e.src, e.dst, e.cap);
            }
        }
    }
};

int main(){
    int X,Y,E;
    cin >> X >> Y >> E;
    int N=X+Y;
    MCF mcf(N+2);
    int S=N, T=N+1;
    for(int i=0;i<E;i++){
        int x, y;
        cin >> x >> y;
        mcf.add_edge(x,y+X,1);
    }
    for(int i=0;i<X;i++){
        mcf.add_edge(S,i,1);
    }
    for(int i=0;i<Y;i++){
        mcf.add_edge(i+X,T,1);
    }
    cout << mcf.max_flow(S,T) << endl;
    // printf("X : {");
    // for(int i=0;i<X;i++){
    //     printf("%d%s",i,i==X-1?"}\n":",");
    // }
    // printf("Y : {");
    // for(int i=0;i<Y;i++){
    //     printf("%d%s",i+X,i==Y-1?"}\n":",");
    // }
    // mcf.view();
}

Measured memory_bytes: 1528