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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    vector<ll> C(N);
    rep(i, N) C[i] = A[i] + B[i];
    sort(C.rbegin(), C.rend());

    ll ans = 0;
    rep(i, N) ans -= B[i];
    for (int i = 0; i < N; i += 2) ans += C[i];

    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int main(){
    int N, D;
    cin >> N >> D;
    vector<vector<double>> X(N, vector<double>(D, 0.0));

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }


    int count = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            double sum = 0.0;
            for (int d = 0; d < D; d++) {
                sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
            }
            double dist = sqrt(sum);
            if (ceil(dist) == floor(dist))
                count++;
        }
    }
    cout << count << endl;
}


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

int cnt[111111];
bool ball[111111];

int main(){
    int n,m;

    scanf("%d %d",&n,&m);

    ball[1]=1;
    for(int i=1;i<=n;i++) cnt[i]=1;

    while(m--){
        int a,b;
        scanf("%d %d",&a,&b);

        cnt[a]--,cnt[b]++;
        if(ball[a]) ball[b]=1;
        if(!cnt[a]) ball[a]=0;
    }

    int ans=0;
    for(int i=1;i<=n;i++) ans+=ball[i];

    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
  int height[300], weight[300];
  int i = 0, j = 0, count = 0, l = 0;

  for(i=1;i<=300;i++){
    scanf("%d %d", &height[i], &weight[i]);
    if(height[i]==0&&weight[i]==0) break;
    count++;
  }

  for(l=1;l<=count;l++){
    for(i=0;i<height[l];i++){
      for(j=0;j<weight[l];j++) printf("#");
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 1000
#from collections import *
#from itertools import *
#from bisect import *
from heapq import *
#import copy
#N=int(input())
#X,Y=map(int,input().split())
#S=list(map(int,input().split()))
#S=[list(map(int,input().split())) for i in range(N)]

N,C=map(int,input().split())
XV=[list(map(int,input().split())) for i in range(N)]
XVR=list(reversed(XV))
value=0
tempvalue=0
csXV=[[0,0] for i in range(N)]
csXVR=[[0,0] for i in range(N)]
csXV[0][0]=XV[0][0]
csXV[0][1]=XV[0][1]
csXVR[0][0]=XV[-1][0]
csXVR[0][1]=XV[-1][1]
csXVR[0][0]=C-csXVR[0][0]
for i in range(1,N):
    csXV[i][0] =XV[i][0]
    csXV[i][1] =XV[i][1]+csXV[i-1][1]
    csXVR[i][0]=C-XV[N-1-i][0]
    csXVR[i][1]=XVR[i][1]+csXVR[i-1][1]


csXV[0].append(csXV[0][1]-csXV[0][0])
csXVR[0].append(csXVR[0][1]-csXVR[0][0])

for i in range(1,N):
    csXV[i].append(csXV[i][1]-csXV[i][0])
    csXVR[i].append(csXVR[i][1]-csXVR[i][0])

csXV[0].append(csXV[0][2])
csXVR[0].append(csXVR[0][2])



for i in range(1,N):
    csXV[i].append(max(csXV[i][2],csXV[i-1][3]))
    csXVR[i].append(max(csXVR[i][2],csXVR[i-1][3]))

#距離、価値、累積価値ー距離、３の累積最大値

value=0
for i in range(N-1):
    B=N-1 -i-1
    tempvalue=csXV[i][2]-csXV[i][0]+csXVR[B][3]
    value=max(tempvalue,value,csXV[i][3])

for i in range(N-1):
    B=N-1 -i-1
    tempvalue=csXVR[i][2]-csXVR[i][0]+csXV[B][3]
    value=max(tempvalue,value,csXV[i][3])

value=max(value,csXV[-1][3],csXVR[-1][3])

print(value)


Measured memory_bytes: 99044
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cctype>
#include <vector>
#include <string>

int nya(std::vector<std::string> const& s, size_t h, size_t w) {
  if (isdigit(s[h].back())) return s[h].back()-'0';
  if (s[h].back() == '+') {
    int res = 0;
    for (size_t i = h+1; i < s.size(); ++i) {
      if (s[i].length() <= s[h].length()) break;
      if (s[i][w+1] == '.') continue;
      res += nya(s, i, w+1);
    }
    return res;
  }
  if (s[h].back() == '*') {
    int res = 1;
    for (size_t i = h+1; i < s.size(); ++i) {
      if (s[i].length() <= s[h].length()) break;
      if (s[i][w+1] == '.') continue;
      res *= nya(s, i, w+1);
    }
    return res;
  }
  assert(false);
}

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  std::vector<std::string> s(n);
  for (auto& si: s) {
    char buf[1024];
    scanf("%s", buf);
    si = buf;
  }

  printf("%d\n", nya(s, 0, 0));
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2828
#coding:utf-8

N = int(input())

sa_lis = []
wa_lis = []

for i in range(N):
    x,y = map(int,input().split())
    sa_lis.append(x-y)
    wa_lis.append(x+y)

sa = max(sa_lis) - min(sa_lis)
wa = max(wa_lis) - min(wa_lis)

ans = max(sa,wa)

print("{}".format(ans))

Measured memory_bytes: 24988
#include <bits/stdc++.h> 
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define sp(x) fixed<<setprecision(x)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define inf 1e18
using namespace std;

ll dp[401][401];
ll s[401];

ll sum(ll i, ll j)
{
    if(i == 0)
    return s[j];
    
    return (s[j] - s[i-1]);
}

ll fun(ll i, ll j)
{
    //Base Case
    if(i == j)
    return 0;
    if(i > j)
    return 0;
    
    //Lookup
    if(dp[i][j] != -1)
    return dp[i][j];
    
    //Rec Case
    ll ans = inf;
    for(ll k=i;k<j;k++)
    {
        ans = min(ans, fun(i,k)+fun(k+1,j)+sum(i,j));
    }
    
    return dp[i][j] = ans;
}

int main()
{
    fast_io;
    
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++)
    cin>>s[i];
    
    for(ll i=1;i<n;i++)
    {
        s[i] += s[i-1];
    }
    memset(dp,-1,sizeof(dp));
    
    cout<<fun(0,n-1)<<endl;
    
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> X(M);
  for(int i=0; i<M; ++i) cin >> X[i];
  sort(X.begin(), X.end());

  vector<long long> Y(M-1);
  for(int i=0; i+1<M; ++i) Y[i] = X[i+1] - X[i];
  sort(Y.begin(), Y.end());

  long long ans = 0;
  for(int i=0; i+N-1<Y.size(); ++i) ans += Y[i];
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;



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

	string s;
	cin >> s;

	ll y = stoi(s.substr(0, 4));
	ll m = stoi(s.substr(5, 7));
	ll d = stoi(s.substr(8, 10));

	//cout << y << "\n";
	//cout << m << "\n";
	//cout << d << "\n";

	string ans = "TBD";

	if (y < 2019)
	{
		ans = "Heisei";
	}
	if (y == 2019)
	{
		if (m < 4)
		{
			ans = "Heisei";
		}

		if (m == 4)
		{
			if (d <= 30)
			{
				ans = "Heisei";
			}
		}
	}

	cout << ans << "\n";

	//system("pause");
}

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

class UnionFind {
private:
  vector<int> par, rank;
public:
  UnionFind(int n) {
    par = rank = vector<int>(n);
    for(int i = 0; i < n; ++i) par[i] = i;
  }

  int find(int x) {
    return par[x] == x ? x : par[x] = find(par[x]);
  }

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

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

int main() {
  for(int n, p1, p2; cin >> n >> p1 >> p2 && (n|p1|p2); ) {
    int m = p1+p2;
    UnionFind uf(m*2);
    for(int i = 0; i < n; ++i) {
      int x, y;
      string a;
      cin >> x >> y >> a;
      --x; --y;
      if(a == "yes") {
        uf.unite(x, y);
        uf.unite(x+m, y+m);
      } else {
        uf.unite(x, y+m);
        uf.unite(x+m, y);
      }
    }

    bool no_flag = false;
    map<int, pair<int, int> > group;
    for(int i = 0; i < m; ++i) {
      if(uf.same(i, i+m)) {
        no_flag = true;
        break;
      }
      int root = uf.find(i);
      int add = 1;
      if(root >= m) {
        root -= m;
        add = 0;
      }
      group[root].first++;
      group[root].second += add;
    }
    if(no_flag) {
      cout << "no" << endl;
      continue;
    }

    vector<int> roots;
    vector<pair<int, int> > v;
    for(map<int, pair<int,int> >::iterator it = group.begin();
        it != group.end(); ++it) {
      roots.push_back(it->first);
      v.push_back(make_pair(it->second.second, 
                            it->second.first - it->second.second));
    }

    int size = v.size();
    vector<vector<int> > dp(size+1, vector<int>(p1+1, 0));
    vector<vector<int> > prev(size+1, vector<int>(p1+1, -1));
    dp[0][0] = 1;
    for(int i = 0; i < v.size(); ++i) {
      for(int j = 0; j <= p1; ++j) {
        if(!dp[i][j]) continue;
        try {
          int nj = j + v[i].first;
          if(nj > p1) throw 0;
          dp[i+1][nj] += 1;
          prev[i+1][nj] = 0;
        } catch(...) {}
        try {
          int nj = j + v[i].second;
          if(nj > p1) throw 0;
          dp[i+1][nj] += 1;
          prev[i+1][nj] = 1;
        } catch(...) {}
      }
    }

    if(dp[v.size()][p1] != 1) {
      cout << "no" << endl;
      continue;
    }

    vector<int> r(m*2);
    {
      int i = v.size();
      int j = p1;
      while(prev[i][j] != -1) {
        if(prev[i][j] == 0) {
          r[roots[i-1]] = 1;
          j -= v[i-1].first;
        } else {
          r[roots[i-1]+m] = 1;
          j -= v[i-1].second;
        }
        --i;
      }
    }
    for(int i = 0; i < m; ++i) {
      if(r[uf.find(i)]) {
        cout << i+1 << endl;
      }
    }
    cout << "end" << endl;
  }
  return 0;
}

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

#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)                                      \
  cout << #v << ":";                                      \
  for (int i = 0; i < v.size(); i++) cout << " " << v[i]; \
  cout << endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int> >
#define vll vector<vector<ll> >
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
#define pll pair<ll, ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout << setprecision(15) << fixed << p << endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};


int main(){
  ll n, m, i, j;
  cin >> n >> m;
  vl a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  vii num(m);
  for (i = 1; i < n; i++) {
    num[a[i]].push_back(i);
  }
  vi cnt0(2 * m);
  
  for (i = 1; i < n; i++) {
    int from = a[i - 1], to = a[i];
    if (from > to) {
      to += m;
    }
    cnt0[from + 1]++;
    cnt0[to]--;
  }
  vi cnt1(2 * m);
  cnt1[0] = cnt0[0];
  for (i = 1; i < 2*m; i++) {
    cnt1[i] = cnt1[i - 1] + cnt0[i];
  }
  vi cnt(m);
  for (i = 0; i < m; i++) {
    cnt[i] = cnt1[i] + cnt1[i + m];
  }
  /*
  DEBUG_VEC(cnt);
  for (i = 0; i < m; i++) {
    for (j = 0; j < num[i].size(); j++) {
      cout << num[i][j] << " ";
    }
    cout << endl;
  }
  */
  vl dp(m);
  for (i = 1; i < n; i++) {
    dp[0] += min(1 + (a[i] + m)%m, (a[i] + m - a[i-1])%m);
  }
  ll mn = dp[0];
  for (i = 1; i < m; i++) {
    dp[i] = dp[i - 1] - cnt[i - 1];
    for (j = 0; j < num[i - 1].size(); j++) {
      int i0 = num[i - 1][j];
      dp[i] += (a[i0] + m - a[i0-1])%m - 1;
    }
    mn = min(mn, dp[i]);
  }
  //DEBUG_VEC(dp);
  cout << mn << endl;
  //cout << dp[0] << endl;
}

/*
4 6
1 5 1 4
*/


Measured memory_bytes: 8448
#include <iostream>

using namespace std;
bool link[9][9];
int N, M;

int search(int num, int visited) {
	int ans = 0;
	bool end = true;
	int nowVisited = visited + (1 << (num-1));

	for (int i=1; i<=N; i++) {
		if ((nowVisited >> (i-1))%2 == 0) {
			end = false;
			break;
		}
	}
	if (end) {
		return 1;
	}
	for (int i=1; i<=N; i++) {
		if (link[num][i] && (nowVisited >> (i-1))%2==0) {
			ans += search(i, nowVisited);
		}
	}
	return ans;
}
int main(){
	int a[32], b[32];

	cin >> N >> M;
	for (int i=0; i<M; i++) {
		cin >> a[i] >> b[i];
		link[a[i]][b[i]] = link[b[i]][a[i]] = true;
	}
	int visited = 0;
	cout << search(1, visited) << endl;
	return 0;
}
	

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		String c = scan.next();
		String anser = c.equals("a")
				|| c.equals("e")
				|| c.equals("i")
				|| c.equals("o")
				|| c.equals("u")
						? "vowel"
						: "consonant";
		System.out.println(anser);
	}

}


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  = 3.141592653589793238463;
const int N = 1e5+10;
const ll INF = 1LL << 60;

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


// Main Code

int a[N], b[N], c[N], q[N];


ll ppow(ll x, ll y)
{
  ll res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

ll mul(ll x, ll y)
{
  return (((x%M)*(y%M))%M);
}

int main()
{
	string s;
	cin>>s;
	int cnta, cntb, cntc, cntq;
	cnta = cntb = cntc = cntq = 0;
	rep(i, 0, s.length())
	{
		if(s[i] == 'A') cnta++;
		else if(s[i] == 'B') cntb++;
		else if(s[i] == 'C')cntc++;
		else cntq++;
		a[i] = cnta;
		b[i] = cntb;
		c[i] = cntc;
		q[i] = cntq;
	}
	ll ans = 0;
	int n = s.length() - 1;
	rep(i, 0, s.length())
	{
		if(s[i] == 'B' || s[i] == '?')
		{
			if(s[i] == 'B')
			{
				ll qa = q[i];
				ll qc = q[n] - q[i];
				ll na = a[i];
				ll nc = c[n] - c[i];
				ll totalq = qa + qc;
				ll total = mul(na, mul(nc, ppow(3, totalq)));
				total = (total + mul(qa, mul(nc, ppow(3, totalq-1)))) % M;
				total = (total + mul(qc, mul(na, ppow(3, totalq-1)))) % M;
				total = (total + mul(qa, mul(qc, ppow(3, totalq-2)))) % M;
				ans  = (ans + total) % M;
			}
			else if(s[i] == '?')
			{
				ll qa = q[i] - 1;
				ll qc = q[n] - q[i];
				ll na = a[i];
				ll nc = c[n] - c[i];
				ll totalq = qa + qc;
				ll total = mul(na, mul(nc, ppow(3, totalq)));
				total = (total + mul(qa, mul(nc, ppow(3, totalq-1)))) % M;
				total = (total + mul(qc, mul(na, ppow(3, totalq-1)))) % M;
				total = (total + mul(qa, mul(qc, ppow(3, totalq-2)))) % M;
				ans  = (ans + total) % M;
			}
		}
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
using matrix = vector<vector<int> >;

matrix mul(const matrix &A, const matrix &B) {
	matrix res(A.size(), vector<int>(B[0].size(), 0));
	for (int i = 0; i < A.size(); i++) {
		for (int j = 0; j < B[0].size(); j++) {
			for (int k = 0; k < B.size(); k++) {
				res[i][j] = (res[i][j] + A[i][k] * B[k][j]) % MOD;
			}
		}
	}
	return res;
}
matrix matpow(const matrix &A, int K) {
	if (K == 1)return A;
	matrix res = mul(A, A);
	res = matpow(res, K / 2);
	if (K % 2 == 1) {
		res = mul(res, A);
	}
	return res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<vector<int> > A(N,vector<int>(N));
	int res = 0;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> A[i][j];
		}
	}
	matrix B = matpow(A, K);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			res += B[i][j];
		}
	}
	res %= MOD;
	cout << res << endl;
}

Measured memory_bytes: 1536
N, K = map(int,input().split())
import math
ans =0
for n in range(1,N+1):
  if math.ceil(math.log2(K/n))>=1:
    ans += (1/N) * (1/2)**(math.ceil(math.log2(K/n)))
  else:
    ans += 1/N
print(ans)

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

int main() {
  double a,b,h,m;
  double pi = 3.1415926539; 
  cin >> a >> b >> h >> m;

  double hh = h*30 + m*0.5;
  double mm = m*6;

  double rad = abs(hh-mm);
double rad2 = rad * pi;
double rad3 = rad2 / 180;
  double aa = a*a;
  double bb = b*b;

  double ab = a*b;
  double ab2 = ab*2;

  double co = cos(rad3);

  double x = aa + bb;
  double y = ab2*co;
  double ans = x-y;

  cout << fixed << setprecision(10) << sqrt(ans);


}

Measured memory_bytes: 4228
#-*-coding:utf-8-*-

#累積和を求める
def get_cum_sum(s, c):
	cum_sum =[]
	cnt = 0
	
	for i in s:
		if i == c:
			cnt += 1
			cum_sum.append(cnt)
		else:
			cum_sum.append(cnt)
			
	return cum_sum
    
	

def main():
    #入力
    N = int(input())
    S = input()
		
    cum_sum_w = get_cum_sum(S, 'W')
    cum_sum_e = get_cum_sum(S, 'E')
    min_cnt = 300000
    
    for i in range(N):
    	if S[i] == 'W':
    		first_total_w = cum_sum_w[i] - 1
    	else:
    		first_total_w = cum_sum_w[i]
    		
    	last_total_e = cum_sum_e[-1] - cum_sum_e[i]
    	
    	#print(S[:i], S[i+1:], first_total_w, last_total_e)
    	
    	if min_cnt > first_total_w + last_total_e:
    		min_cnt = first_total_w + last_total_e
    
    print(min_cnt)
    	
    	
        


if __name__ == '__main__':
    main()

Measured memory_bytes: 17872
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 100100100100100100
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

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

int main() 
{
    int d; cin >> d;
    
    switch(d) {
        case 22 : cout << "Christmas Eve Eve Eve" << endl; break;
        case 23 : cout << "Christmas Eve Eve" << endl; break;
        case 24 : cout << "Christmas Eve" << endl; break; 
        case 25 : cout << "Christmas" << endl; break;
        default : break;
    }
    
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

ll n;
vll a;
map<ll,ll> mp;

void prime(ll x){
  for(ll p=2;p*p<=x;p++){
    if(x%p!=0) continue;
    ll c=0;
    while(x%p==0){
      x/=p;
      c++;
    }
    if(c>mp[p]) mp[p]=c;
  }
  if(x!=1&&1>mp[x]) mp[x]=1;
}

auto modpow(auto a,auto n){
 long long pow=1;
  while(n){
   if(n&1) pow=pow*a%mod;
   a=a*a%mod;
   n>>=1;    
}  
 return pow;
}

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

  cin >> n;
  a.resize(n);
  rep(i,0,n) {
    cin >> a[i];
    prime(a[i]);
  }
  
  ll res=0;
  for(auto p:a) {
    res+=modpow(p,mod-2);
    res%=mod;
  }
  for(auto m:mp) {
    res*=modpow(m.first,m.second);
    res%=mod;
  }
  cout << res << endl;
  
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<queue>
#define INF 1000000000
using namespace std;

//to[u] = v : uからvへの道がある
vector<int> to[100001];

int main(){
    int n,m;
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    vector<int> dist (n, INF);
    vector<int> pre(n , -1);
    queue<int> q;

    dist[0] = 0;
    q.push(0);
    while(!q.empty()){
        int v = q.front(); q.pop();
        for(int i = 0;i < to[v].size();i++){
            int u = to[v][i];
            if(dist[u] != INF){
                continue;
            }
            dist[u] = dist[v] + 1;
            q.push(u);
            pre[u] = v; 
        }
    }

    cout << "Yes" << endl;

    for(int i = 1;i < n;i++){
        cout << pre[i] + 1 << endl;
    }


    return 0;
}

Measured memory_bytes: 10520
n = int(input())
a = [int(input()) for i in range(n)]

even_num = set([a[i] for i in range(0,n) if i % 2 == 0])

a = sorted(a)

odd_num = set([a[i] for i in range(0, n) if i % 2 == 1])

count = len(even_num & odd_num)
print(count)


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> V;
    for(int i = 0;i < M;++i){
        int k, tmp = 0;
        cin >> k;
        for(int j = 0;j < k;++j){
            int m;
            cin >> m;
            tmp += pow(2.0, m-1);
        }
        V.push_back(tmp);
    }
    vector<int> S;
    for(int i = 0;i < M;++i){
        int tmp;
        cin >> tmp;
        S.push_back(tmp);
    }
    int c = 0;
    int ans = 0;
    for(int i = 0;i < pow(2.0, N);++i){
        int comp = 0;
        for(int j = 0;j < M;++j){
            int bit = 1;
            int A = i & V[j];
            int sum_s = 0;
            for(int k = 0;k < N;++k){
                if(bit&A){
                    ++sum_s;
                }
                bit = (bit << 1);
            }
            if(sum_s%2 == S[j]){
                ++comp;
            }
        }
        if(comp == M){
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

	char a, b;
	cin >> a >> b;

	if (a == 'H') {
		cout << b;
	}
	else {
		b == 'H' ? cout << "D" :  cout << "H";
	}


	return 0;
}
//*/

Measured memory_bytes: 384
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;

int main(){
  lint K,A,B;
  cin>>K>>A>>B;
  lint res=1+K;

  if(A<B){
    lint turn=(K-(A-1))/2;
    chmax(res,turn*(B-A)+(K-turn*2)+1);
  }
  cout<<res<<endl;
  return 0;
}





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

void solve(long long N, std::vector<long long> A) {
    map<ll, ll> map;
    rep(i, N) { map[A[i]]++; }
    vector<ll> edge;
    for (auto i = map.begin(); i != map.end(); i++) {
        if (i->second >= 4) {
            edge.push_back(i->first);
            edge.push_back(i->first);
        } else if (i->second >= 2) {
            edge.push_back(i->first);
        }
    }
    if (edge.size() < 2) {
        cout << 0 << endl;
        return;
    }
    sort(edge.begin(), edge.end(), greater<ll>());
    cout << edge[0] * edge[1] << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 10164
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		String str1 = input.readLine(); // 命令を実行する文字列
		int n = Integer.parseInt(input.readLine()); // 命令の数
		String com = "", p = "";
		int num1 = 0, num2 = 0;

		StringBuilder sb1 = new StringBuilder(str1);
		StringBuilder sb2 = new StringBuilder();

		for (int i = 0; i < n; i++) {
			String str2 = input.readLine(); // 命令を何行かで受け取る
			String[] str3 = str2.split("\n"); // 改行で文字列に分ける
			for (int j = 0; j < str3.length; j++) {
				int n1 = str3[j].indexOf(" ");
				int n2 = str3[j].indexOf(" ", n1 + 1);
				int n3 = str3[j].indexOf(" ", n2 + 1);
				// コマンドと数字に分ける
				if (n3 == -1) {
					com = str3[j].substring(0, n1);
					num1 = Integer.parseInt(str3[j].substring(n1 + 1, n2));
					num2 = Integer.parseInt(str3[j].substring(n2 + 1));
				}
				// コマンドと数字に分ける（replace）
				else {
					com = str3[j].substring(0, n1);
					num1 = Integer.parseInt(str3[j].substring(n1 + 1, n2));
					num2 = Integer.parseInt(str3[j].substring(n2 + 1, n3));
					p = str3[j].substring(n3 + 1);
				}
				// コマンド別に機能を記述（sb1は変更可能な状態の文字列 ,sb2は出力用）

				// print a b:str の a 文字目から b 文字目までを出力する
				if (com.equals("print")) {
					sb2.append(sb1.substring(num1, num2 + 1) + "\n");
				}
				// reverse a b: str の a 文字目から b 文字目までを逆順にする
				if (com.equals("reverse")) {
					String st1 = sb1.substring(0, num1);
					String st2 = sb1.substring(num2 + 1);
					sb1.delete(num2 + 1, sb1.length());
					sb1.delete(0, num1);
					sb1.reverse();
					sb1.insert(0, st1);
					sb1.append(st2);

				}
				// replace a b p: str の a 文字目から b 文字目までを p に置き換える。
				if (com.equals("replace")) {
					sb1.replace(num1, num2 + 1, p);
				}

			}

		}
		System.out.print(sb2);

	}

}

Measured memory_bytes: 20644
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    struct dice{int u,e,w,n,s,d;
    void rotate(char c){
        int temp=u;
        if(c=='E'){u=w;w=d;d=e;e=temp;}
        else if(c=='W'){u=e;e=d;d=w;w=temp;}
        else if(c=='N'){u=s;s=d;d=n;n=temp;}
        else if(c=='S'){u=n;n=d;d=s;s=temp;}
    }
    };
    dice a;
    in(a.u,a.s,a.e,a.w,a.n,a.d);
    int x,y;
    string s="NNNNENNNN";
    codefor{
        in(x,y);
        rep(i,9){
            if(a.s==y)break;
            a.rotate(s[i]);
        }
        while(a.u!=x){
            a.rotate('E');
        }
        //debug(a.u,a.s,a.e);
        out(a.e);
    }
}



Measured memory_bytes: 3252
#include<iostream>
#include<set>
using namespace std;
int main()
{
    int n;
    set<char> s;
    char c;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> c;
        s.insert(c);
    }
    cout << (s.size() == 3 ? "Three" : "Four") << endl;
    return 0;
}

Measured memory_bytes: 256
//Author: Prakhar Asaiya
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(ll i=a;i<b;++i)
#define REPN(i,a,b) for(ll i=a;i<=b;++i)
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define ll long long
const int M=1e9+7;
const int INF=1e9+5;

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

  int s,w;
  cin>>s>>w;
  if(w>=s)
  cout<<"unsafe\n";
  else
  cout<<"safe\n";
 
  
   return 0;
}


Measured memory_bytes: 3644
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int i,j,n,a[131072],r=inf,zr;
    scanf("%d",&n);
    for(i=1;i<=n;i++){scanf("%d",&a[i]);}
    for(i=-100;i<=100;i++){
        zr=0;
        for(j=1;j<=n;j++){
            zr+=((a[j]-i)*(a[j]-i));
        }
        r=min(r,zr);
    }
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main() {
	int A, B, M;
	cin >> A >> B >> M;
	vector<int>a(A), b(B), c(M);
	for (size_t i = 0; i < A; i++)
	{
		cin >> a.at(i);
	}
	for (size_t i = 0; i < B; i++)
	{
		cin >> b.at(i);
	}
	int p, q,r;
	for (size_t i = 0; i < M; i++)
	{
		cin >> p >> q>>r;
		p--;
		q--;
		c.at(i) += (a.at(p) + b.at(q));
		c.at(i) -= r;
	}
	sort(c.begin(), c.end());
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	cout << min(c.at(0), a.at(0) + b.at(0));
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;
int main(){
    vector<int> num;
	int m,i,a,count=0;
	int sum1=0,sum2=0;
	scanf("%d",&m);
	for(i=0;i<m;i++){
		scanf("%d",&a);
		num.push_back(a);
	}	
	sort(num.begin(),num.end());
	/*for(i=0;i<m;i++){
		printf("%d ",num[i]);
	}*/
	for(i=m-1;i>=0;i--){
		count++;
		if(count==1){
			sum1+=num[i];
		}
		else if(count==2){
			sum2+=num[i];
			count=0;
		}
	}
	printf("%d\n",sum1-sum2);
	return 0;
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

using ll = long long;
int N;
ll T[1003], A[1003];
const ll INF = 1e12;
ll f2(int i, ll t, ll a) {
    ll ret = 0;
    ll lb = -1, ub = INF;
    while (ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        // cout << lb << ", " << ub << endl;
        if (T[i] * mid >= t && A[i] * mid >= a)
            ub = mid;
        else
            lb = mid;
    }
    return ub;
}
ll f(int i, ll t, ll a) {
    ll ret = 0;
    while (1) {
        if (T[i] * ret >= t && A[i] * ret >= a) break;
        ret++;
    }
    return ret;
}
ll f3(int i, ll t, ll a) {
    ll t1 = t / T[i] + (t % T[i] != 0);
    ll t2 = a / A[i] + (a % A[i] != 0);
    return max(t1, t2);
}
int main() {
    cin >> N;
    rep(i, N) cin >> T[i] >> A[i];
    ll t = T[0], a = A[0];
    ll ans = 0;

    rep(i, N) if (i) {
        ll s = f3(i, t, a);
        T[i] *= s;
        A[i] *= s;
        t = T[i];
        a = A[i];
    }
    // rep(i, N) cout << T[i] << " " << A[i] << endl;
    ans = T[N - 1] + A[N - 1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n;
long a,b,h[1<<17];
main()
{
	cin>>n>>a>>b;
	for(int i=0;i<n;i++)cin>>h[i];
	long F=0,L=1e10;
	for(int j=0;j<100;j++)
	{
		long M=(L+F)/2;
		long D=b*M;
		long cnt=0;
		for(int i=0;i<n;i++)
		{
			if(h[i]<=D)continue;
			cnt+=(h[i]-D+a-b-1)/(a-b);
		}
		if(cnt<=M)L=M;
		else F=M;
	}
	cout<<L<<endl;
}


Measured memory_bytes: 1024
import sys
num, price = map(int,sys.stdin.readline().rstrip().split())
for x in range(num+1):
  for y in range(num-x+1):
    sum = x *1000 + y * 5000 + (num-x-y) * 10000
    if sum == price:
      print(num-x-y,y,x)
      sys.exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long int ll;
typedef long double ld;
const ll inf = (1 << 30);
const int MOD = 1000000007;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main() {
    ll n,sum = 0; cin >> n; ll res = 0; int right = 0;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    rep(left, n) {
        while (right < n && (sum^a[right]) == (sum + a[right])) {
            sum += a[right];
            right++;
        }
        res += right - left;
        if (right == left) right++;
        else sum -= a[left];
    }cout << res << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define REP(i,n) for (int i=1;i<=n;i++)
#define print(x) cout << x << endl;
typedef long long ll;

ll ketasu(ll n) {
	ll count = 1;
	while (n >= 10) {
		n /= 10;
		count++;
	}
	return count;
}


int main() {
	ll n, ans; cin >> n;
	ll m = sqrt(n);
	for (ll i = m; i > 0; i--) {
		if (n % i == 0) {
			ans = ketasu(n / i);
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int k=0;
  for(int i=1;i<=n;i++){
    if(i>=10&&i<100){
      ;
    }
    else if(i>=1000&&i<10000){
      ;
    }
    else if(i>=100000&&i<1000000){
      ;
    }
    else{
      k++;
    }
  }
  cout<<k<<endl;
}

Measured memory_bytes: 256
num = input()
if num[-1] == '2' or num[-1] == '4' or num[-1] == '5' or num[-1] == '7' or num[-1] == '9':
    print("hon")
elif num[-1] == '0' or num[-1] == '1' or num[-1] == '6' or num[-1] == '8':
    print("pon")
else:
    print("bon")


Measured memory_bytes: 9136
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int dfs(int cur, int x, int n, int c7, int c5, int c3)
{
    if(cur == 0)
    {
        if(x <= n && c7 > 0 && c5 > 0 && c3 > 0)
            return 1;
        else
            return 0;
    }

    int cnt = 0;
    int dig = pow(10,cur-1);
    cnt += dfs(cur-1,x+7*dig,n,c7+1,c5,c3);
    cnt += dfs(cur-1,x+5*dig,n,c7,c5+1,c3);
    cnt += dfs(cur-1,x+3*dig,n,c7,c5,c3+1);
    if(x == 0)
        cnt += dfs(cur-1,x,n,c7,c5,c3);
    
    return cnt;
}

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

    cout << dfs(9,0,n,0,0,0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int maxn=2010,P=1e9+7;
int n,k,fac[maxn*maxn],ifac[maxn*maxn],inv[maxn*maxn],dp[maxn][maxn];
inline int C(int n,int k){return 1ll*fac[n]*ifac[k]%P*ifac[n-k]%P;}
int main(){
    scanf("%d%d",&n,&k);int N=n*k;inv[1]=fac[0]=ifac[0]=1;
    if(k==1) return puts("1"),0;
    rep(i,2,n*k) inv[i]=1ll*(P-P/i)*inv[P%i]%P;
    rep(i,1,n*k) fac[i]=1ll*fac[i-1]*i%P,ifac[i]=1ll*ifac[i-1]*inv[i]%P;
    dp[0][0]=1;
    rep(i,1,n) rep(j,0,i){
        dp[i][j]=dp[i-1][j];
        if(j) dp[i][j]=(dp[i][j]+1ll*dp[i][j-1]*(n-j+1)%P*C(n*k-i-(j-1)*(k-1)-1,k-2)%P)%P;
    }
    printf("%d\n",dp[n][n]);
    return 0;
}

Measured memory_bytes: 62336
/*package whatever //do not write package name here */

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		float s = 0;
		int j;
		for(int i = 0;i < n;i++)
		{
		    a[i] = sc.nextInt();
		    s += a[i];
		}
		s /= n;
		float m = Math.abs(a[0] - s);
		j = 0;
		for(int i = 1;i < n;i++)
		{
		    float m1 = Math.abs(a[i] - s);
		    if(m1 < m)
		    {
		    m = m1;
		    j = i;
		    }
		}
		System.out.print(j);
	}
}

Measured memory_bytes: 23764
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<stack>
#include<cassert>
#define F first
#define S second
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define mem(x,y) memset(x,y,sizeof x)
#define sqr(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef double db;
const int INF=2e9;
const db eps=1e-12;
template<typename T>
inline void read(T &x)
{
	x=0; int f=1; char ch=getchar();
	while( (ch<'0' || ch>'9') && ch!='-') ch=getchar(); if(ch=='-') {f=-1; ch=getchar();}
	while(ch>='0' && ch <='9') x=x*10+ch-'0',ch=getchar();
	x*=f;
}
//==========================head template==========================
const int N=4010;
const ll P=998244353;
int K,n;
ll f[N][N],g[N];
ll C[N][N];
ll ans[N];
signed main() {
	read(K); read(n);
	for(int j=0;j<=K;j++) f[0][j]=1;
	for(int i=0;i<=n;i++) g[i]=1;
	for(int j=1;j<=K;j++) {
		for(int i=1;i<=n;i++) {
			f[i][j]=(g[i-1]*2%P+f[i][j-1])%P;
			if(i!=1) g[i-1]=(g[i-2]+f[i-1][j])%P;
		}
	}
	for(int i=0;i<=n+K;i++) C[i][0]=1;
	for(int i=1;i<=n+K;i++)
		for(int j=0;j<=K;j++)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%P;
	for(int k=2;k<=K;k++) {
		if(k&1) {
			for(int i=0;i<=n;i++) {
				(ans[k]+=f[i][k/2]*C[n-i + K-k][K-k]%P)%=P;
			}
		} else {
			for(int i=0;i<=n;i++) {
				(ans[k]+=f[i][k/2-1]*((C[n-i + K-k][K-k]+(i==n ? 0 : C[n-i-1 + K-k][K-k]))%P)%P)%=P;
				// if(k==4) printf("%lld %lld\n",f[i][k/2-1],(C[n-i + K-k][K-k]+(i==n ? 0 : C[n-i-1 + K-k][K-k])));
			}
		}
		assert(ans[k]>=0);
	}
	if((K+1)&1) {
		ans[K+1]=f[n][(K+1)/2];
	} else {
		ans[K+1]=(f[n][(K+1)/2-1]+f[n-1][(K+1)/2-1])%P;
	}
	for(int i=2;i<=K+1;i++)
		printf("%lld\n",ans[i]);
	for(int i=K;i>=2;i--)
		printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 187904
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvin;
typedef vector<pair<ll,ll>> vpll;
typedef vector<pair<int,int>> vpin;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef queue<int> qin;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
int main()
{
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
ll x; cin>>x;
string ans;
while (x) {
  if (x%26) ans+=('a'+(x%26)-1);
  else {--x; ans+='z';}
  x/=26;
}
reverse (fall(ans));
cout<<ans;
return 0;
}


Measured memory_bytes: 3656
# 入力
N, M = map(int, input().split())

# 15行目ぐらいまでワーシャルフロイドの前処理
INF = 10 ** 10
dist = [[INF] * N for _ in range(N)]
for i in range(N):
    dist[i][i] = 0

a = [0] * M
b = [0] * M
c = [0] * M
for i in range(M):
    a[i], b[i], c[i] = map(int, input().split())
    dist[a[i]-1][b[i]-1] = c[i]
    dist[b[i]-1][a[i]-1] = c[i]

#ワーシャルフロイド
for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

res = 0
for i in range(M):
    # 最短経路が直接の頂点a-b間の距離でなかった時、（迂回ルートが最短距離の時）
    # 辺a-bはどの最短経路にも含まれないので+1する。
    if c[i] > dist[a[i]-1][b[i]-1]:
        res += 1

print(res)


Measured memory_bytes: 3408
# https://atcoder.jp/contests/abc121/tasks/abc121_b
# B - Can you solve this?

n, m, c = list(map(int, input().split()))
b_list = list(map(int, input().split()))
a_list_list = []

for _ in range(n):
    a_list = list(map(int, input().split()))
    a_list_list.append(a_list)

count = 0

for a_list in a_list_list:
    total = sum([a * b for a, b in zip(a_list, b_list)]) + c
    if total > 0:
        count += 1

print(count)


Measured memory_bytes: 3060
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

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

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n,a;
	cin >> n >> a;
	if(n % 500 <= a)	OUT("Yes") BR;
	else OUT("No") BR;
	RET;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <string>

using namespace std;

struct Dize{
    int sf[6];

    void roll(char ch){
        int tmp=0;
        switch (ch) {
            case 'N':
                tmp=sf[0];
                sf[0]=sf[1];
                sf[1]=sf[5];
                sf[5]=sf[4];
                sf[4]=tmp;
                tmp=0;
                break;
            case 'E':
                tmp=sf[0];
                sf[0]=sf[3];
                sf[3]=sf[5];
                sf[5]=sf[2];
                sf[2]=tmp;
                tmp=0;
                break;
            case 'S':
                tmp=sf[0];
                sf[0]=sf[4];
                sf[4]=sf[5];
                sf[5]=sf[1];
                sf[1]=tmp;
                break;
            case 'W':
                tmp=sf[0];
                sf[0]=sf[2];
                sf[2]=sf[5];
                sf[5]=sf[3];
                sf[3]=tmp;
                break;
            default:
                break;
        }
    }
    
     int ref_2(int i,int j){
         bool jud=true;
         for(int k=0;k<4;++k){
             roll('N');
             if(sf[0]==i){
                 jud=false;
                 break;
             }
         }
         if(jud){
             roll('E');
             for(int k=0;k<4;++k){
                 roll('N');
                 if(sf[0]==i){
                     jud=false;
                     break;
                 }
             }
         }
         
         int yoko_sf[5]={1,2,4,3,1};
         /*
         for(int k=0;k<6;++k){
             cout<<sf[k]<<" ";
         }
         cout<<endl;
         */
         for(int k=0;k!=5;++k){
             
             if(sf[yoko_sf[k]]==j){
                 return sf[yoko_sf[k+1]];
                 
             }
             
         }
         return 0;
     }
};


int main(){
    
    Dize dz;
    
    for(int i=0;i!=6;++i){
        cin>>dz.sf[i];
    }
    int a,x,y;
    cin>>a;
    
    for(int i=0;i!=a;++i){
        cin>>x>>y;
        cout<<dz.ref_2(x,y)<<endl;
    }
    
  
    
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
//#include <iostream>
//#include <string>
//#include <algorithm>
//#include <stdio>
using namespace std;
#define fr(i, r, n) for(int i = r; i < n; ++i)
const int maxn = (int)1e3 +10;

int main()
{
   int n, m;
   cin>>n>>m;
   int ans;
   ans = n/(2*m+1);
   if(n%(2*m+1)!= 0)
    ans++;
   cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 256