akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        int[] a=cin.ArrayInt(N,0);
        Array.Sort(a);
        double ans=a[0];
        for(int i=1;i<N;i++)
        {
            ans=(((double)a[i]+ans)/2);
        }
        Console.WriteLine(ans);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

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

int main(){
  string s; cin>>s;
  ll ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'){
      ll count=0;
      while(true){
        while(i<s.size() && s[i]=='A'){
          count++;
          i++;
        }
        if(i+1<s.size() && s[i]=='B' && s[i+1]=='C'){
          ans+=count;
          i+=2;
        }else{
          break;
        }
      }
    }
  }
  cout<<ans<<endl;
}

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

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

	string t;
	int n;
	vector<int> c;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; ++i){
		cin >> s[i];
		c.push_back(0);
	}
	for (int i = 0; i <= 26; ++i){
		for (int j = 0; j < n; ++j){
			c[j] = 0;
		}
		for (int j = 0; j < n; ++j){
			for (int k = 0; k < s[j].size(); ++k){
				if (s[j][k] == 'a'+i){
					c[j]++;
				}
			}
		}
		sort(c.begin(), c.end());
		for (int j = 0; j < c[0]; ++j){
			printf("%c", char('a'+i));
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
using namespace std;

#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>

#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;

int n;
int x[105], y[105];
int h[105];

signed main() {
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld%lld", &x[i], &y[i], &h[i]);
  }
  bool done = false;
  for (int i = 0; !done && i <= 100; i++) {
    for (int j = 0; !done && j <= 100; j++) {
      bool ok = true;
      int H = 0;
      for (int k = 0; k < n; k++) {
	int newH = h[k] + abs(i - x[k]) + abs(j - y[k]);
	if (h[k] == 0) {
	  if (H != 0) {
	    if (H - abs(i - x[k]) - abs(j - y[k]) > 0) {
	      ok = false;
	      break;
	    }
	  }
	}
	else {
	  if (H == 0) H = newH;
	  else {
	    if (H != newH) {
	      ok = false;
	      break;
	    }
	  }
	}
      }
      for (int k = 0; k < n; k++) {
	int newH = h[k] + abs(i - x[k]) + abs(j - y[k]);
	if (h[k] == 0) {
	  if (H != 0) {
	    if (H - abs(i - x[k]) - abs(j - y[k]) > 0) {
	      ok = false;
	      break;
	    }
	  }
	}
	else {
	  if (H == 0) H = newH;
	  else {
	    if (H != newH) {
	      ok = false;
	      break;
	    }
	  }
	}
      }
      if (H != 0 && ok) {
	printf("%lld %lld %lld\n", i, j, H);
	done = true;
	break;
      }
    }
  }
  if (!done) {
    printf("0 0 1\n");
  }
}



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

using namespace std;

#define all(c) ((c).begin()),((c).end())
#define debug(c) cerr<<"> "<<#c<<" = "<<(c)<<endl;
#define iter(c) __typeof((c).begin())
#define tr(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

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

#define EPS 1.0e-6

//ツ点
typedef complex<double> P;

struct C{
	P p;
	double r;
};

vector<P> isCC(const C &c1, const C &c2) {
	double d = abs(c1.p - c2.p);
	if (c1.r + c2.r - d < -EPS || fabs(c1.r - c2.r) - d > EPS) return vector<P>();
	double x = (d*d + c1.r * c1.r - c2.r * c2.r) / 2 / d;
	double y = sqrt(c1.r * c1.r - x * x);
	P diff = (c2.p - c1.p) / d;
	vector<P> res(2);
	res[0] = c1.p + diff * P(x, y);
	res[1] = c1.p + diff * P(x, -y);
	return res;
}

int main() {
	for (int N; cin >> N, N != 0; ) {
		vector<P> ps;
		rep (i, N) {
			double x, y; cin >> x >> y;
			ps.pb(P(x, y));
		}
		int res = 0;
		rep (i, N) REP (j, i + 1, N-1) {
			vector<P> isp = isCC((C){ps[i],1},(C){ps[j],1});
			rep (k, isp.size()) {
				int cnt = 0;
				rep (l, N) if (abs(isp[k] - ps[l]) <= 1 + EPS) cnt++;
				res = max(res, cnt);
			}
		}
		if (res == 0) res++;
		cout << res <<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void)
{int first,second,third,x,i;

  third=0;
  second=0;
  first=0;

  for(i=0; i<10; i++){

  scanf("%d",&x);
  if(first<=x){
    third=second;
    second=first;
    first=x;}
  else if(second<=x&&first>x)
    {third=second;
      second=x;}
  else if(third<=x&&second>x)
    third=x;
  }


  printf("%d\n",first);
  printf("%d\n",second);
  printf("%d\n",third);
  return(0);

}

Measured memory_bytes: 600
a,b,c = map(int,input().split())
modb = [0]*100
for i in range(1,100000):
    n = a*i
    m = n%b
    # print(n,m)
    if(modb[m] != 0):
        break
    modb[m] = 1

print("YES" if(modb[c] == 1) else "NO")

Measured memory_bytes: 9120
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;

#define int long long

const int INF = (1LL << 60);
using namespace std;

int n, z, w;
int* a;

typedef tuple<int,int,int> Tuple;

//map<Tuple,pair<int, int>> memo;
map<pair<int, int>,pair<int, int>> memo;
pair<int, int> dfs(int cur, int turn){
	//if(memo.count(Tuple(cur,pre,turn))) return memo[Tuple(cur, pre, turn)];
	if(memo.count(make_pair(cur,turn))) return memo[make_pair(cur, turn)];

	pair<int, int> res = make_pair(-1,-1);
	if(turn){
		int dif = INF;
		range(i,cur,n){
			int point = a[i];
			pair<int, int> tmp = dfs(i + 1, (turn + 1) % 2);
			
			tmp.first = tmp.first == -1 ? a[cur - 1] : tmp.first;
			tmp.second = tmp.second == -1 ? point : tmp.second;
			//cout << "point  " << pre << ' ' << point << endl;
			if(dif > abs(tmp.first - tmp.second)){
				res = tmp;
				dif = abs(tmp.first - tmp.second);
			}
		}
	}else{
		int dif = 0;
		range(i,cur,n){
			int point = a[i];
			pair<int, int> tmp = dfs(i + 1, (turn + 1) % 2);
			
			tmp.first = tmp.first == -1 ? point : tmp.first;
			tmp.second = tmp.second == -1 ? a[cur - 1] : tmp.second;
			if(dif < abs(tmp.first - tmp.second)){
				res = tmp;
				dif = abs(tmp.first - tmp.second);
			}
		}
	}
	//cout << cur << ' ' << pre << ' ' << turn << endl;
	//cout << res.first << ' ' << res.second << endl;

	//return memo[Tuple(cur, pre, turn)] = res;
	return memo[make_pair(cur,turn)] = res;
}

signed main(){
	cin >> n >> z >> w;
	int b[2005];
	rep(i,n) cin >> b[i + 1];
	b[0] = w;
	a = &b[1];

	pair<int, int> ans = dfs(0,0);
	cout << abs(ans.first - ans.second) << endl;
}


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

struct UnionFind {
  vector<int> par; //親の番号
  UnionFind(int N) : par(N) {
    rep(i, N) par[i] = i;
  }

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

  void unite(int x, int y){
    int rx = find(x);
    int ry = find(y);
    if(rx == ry) return;
    if(par[rx] > par[ry]) swap(rx, ry);
    par[ry] = rx;
  }

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> p(N);
  UnionFind uf(N);
  rep(i, N){
    cin >> p[i];
  }
  rep(i, M){
    int x, y;
    cin >> x >> y; x--; y--;
    if(!uf.same(x, y)){
      uf.unite(x, y);
    }
  }
  int ans = 0;
  rep(i, N){
    if(uf.same(i, p[i]-1)) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    int a, b;
    int sum = 1;
    int cnt = 0;

    cin >> a >> b;

    while (sum < b) {
        sum += a;
        sum--;
        cnt++;
    }

    cout << cnt << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  int h,n;
  cin >> h >> n;
  vector<int> a(n),b(n);
  rep(i,n)
    cin >> a.at(i) >> b.at(i);
  int dp[h+1];
  rep(i,h)
    dp[i]=2000000000;
  dp[h]=0;
  rep(i,n){
    if(a.at(i)>h){
      dp[0]=min(dp[0],b.at(i));
      continue;
    }
    for(int j=h-a.at(i);j>=0;j--)
      dp[j]=min(dp[j],dp[a.at(i)+j]+b.at(i));
    for(int j=a.at(i)-1;j>0;j--)
      dp[0]=min(dp[0],dp[j]+b.at(i));
  }
  cout << dp[0] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
    ll N, W;
    cin >> N >> W;
    ll i, j;
    ll w[111], v[111];
    ll v_sum=0;
    for(i=0; i<N; i++) {
        cin >> w[i] >> v[i];
        v_sum+=v[i];
    }
    
    ll dp[N+1][v_sum+1];
    for(i=0; i<=N; i++) {
        for(j=0; j<=v_sum; j++)
            dp[i][j]=INF;
    }
    dp[0][0]=0;
    for(i=0; i<N; i++) {
        for(j=0; j<=v_sum; j++) {
            dp[i+1][j]=dp[i][j];
            if(j>=v[i])
                dp[i+1][j]=min(dp[i][j], dp[i][j-v[i]]+w[i]);
        }
    }
    ll ans=0;
    for(j=0; j<=v_sum; j++) {
        if(dp[N][j]<=W) ans=max(ans, j);
    }
    
    pr(ans);
}



Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    cin >> A;
    priority_queue<ll> pq;
    rep(i,N)pq.push(A[i]);
    while(M--){
        ll a = pq.top();
        pq.pop();
        pq.push(a/2);
    }
    ll ans = 0;
    while(not pq.empty()){
        ll a = pq.top();
        pq.pop();
        ans += a;
    }
    cout << ans << endl;
}


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

int main(){
  int r, c;
  cin >> r >> c;
  vector< vector<int> > data(r, vector<int>(c));
  // cout << data[0][0] << endl;
  int tmp;
  for (int a = 0; a < r; a++){
    for (int b = 0; b < c; b++){
      cin >> tmp;
      data[a][b] = tmp;
    }
  }
  

  // for (int a = 0; a < r; a++){
  //   for (int b = 0; b < c; b++){
  //     cout << data[a][b];
  //   }
  //   cout << endl;
  // }
  for (int a = 0; a < r; a++){
    int sum = 0;
    for (int b = 0; b < c; b++){
      sum += data[a][b];
    }
    data[a].push_back(sum);
  }

  vector<int> last_line(c + 1);
  for (int b = 0; b <= c; b++){
    int sum = 0;
    for (int a = 0; a < r; a++){
      sum += data[a][b];
    }
    last_line[b] = sum;
  }

  data.push_back(last_line);

  for (int a = 0; a <= r; a++){
    for (int b = 0; b <= c; b++){
      if (b == c){
        cout << data[a][b] << endl;
      }else{
        cout << data[a][b] << " ";
      }
    }
  }
}


Measured memory_bytes: 3300
# frozen_string_literal: true

_ = gets.to_i
a = gets.split.map(&:to_i).group_by(&:itself).map { |k, v| [k, v.count] }.to_h
sum = a.map { |k, v| k * v }.sum
q = gets.to_i
rep = (1..q).map { |_n| gets.split.map(&:to_i) }

q.times do |n|
  unless a[rep[n][0]].nil?
    diff = a[rep[n][0]] * (rep[n][1] - rep[n][0])
    sum += diff
    if a[rep[n][1]].nil?
      a[rep[n][1]] = a[rep[n][0]]
    else
      a[rep[n][1]] += a[rep[n][0]]
    end
    a.delete(rep[n][0])
  end
  # pp a
  puts sum
end


Measured memory_bytes: 30592
#include <bits/stdc++.h>
using namespace std;
int main()
{
char a1,b1,c1,d1;
int ans,a,b,c,d;
cin>>a1>>b1>>c1>>d1;
a=a1-'0';b=b1-'0';c=c1-'0';d=d1-'0';
for(char i='+';i<='-';i++)
    for(char j='+';j<='-';j++)
        for(char k='+';k<='-';k++)
        {
            ans=a;
            if(i=='+') ans+=b;
            else if(i=='-') ans-=b;
            if(j=='+') ans+=c;
            else if(j=='-') ans-=c;
            if(k=='+') ans+=d;
            else if(k=='-') ans-=d;
            if(ans==7)
            {
                cout<<a<<i<<b<<j<<c<<k<<d<<"="<<ans<<"\n";
                return 0;
            }
        }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=105;
int a[N][N],ans[N][N],n,m,dfn[N],match[N];
vector<int> g[N],to[N][N];

bool dfs(int x,int tg){
	if(dfn[x]==tg) return 0;
	dfn[x]=tg;
	for(int y:g[x]){
		if(!match[y]||dfs(match[y],tg)){
			match[y]=x;
			return 1;
		}
	}
	return 0;
}

signed main(){
	read(n,m);
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) read(a[i][j]),to[i][(a[i][j]-1)/m+1].push_back(j);
	for(int k=1;k<=m;k++){
		for(int i=1;i<=n;i++) dfn[i]=match[i]=0,g[i].clear();
		for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(to[i][j].size()) g[i].push_back(j);
		for(int i=1;i<=n;i++) dfs(i,i);
		for(int i=1;i<=n;i++){
			int j=match[i];
			ans[j][k]=a[j][to[j][i].back()];
			to[j][i].pop_back();
		}
	}
	for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=m;j++,putchar(' ')) write(ans[i][j]);
	for(int j=1;j<=m;j++){
		int tp[N];
		for(int i=1;i<=n;i++) tp[i]=ans[i][j];
		sort(tp+1,tp+1+n);
		for(int i=1;i<=n;i++) ans[i][j]=tp[i];
	}
	for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=m;j++,putchar(' ')) write(ans[i][j]);
}

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

int main() {
	int R;
	cin >> R;
	if (R < 1200) {
		cout << "ABC" << endl;
	} else if (R >= 1200 && R < 2800) {
		cout << "ARC" << endl;
	} else {
		cout << "AGC" << endl;
	}
}


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

#define INF INT_MAX
#define MOD 1000000007

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

int main(){
    int n;
    cin >> n;
    vi stones(n + 1);
    for(int i =1; i<=n; i++){
        cin >> stones[i];
    }
    vi dp(n+1);
    dp[2] = abs(stones[2] - stones[1]);
    for(int i=3; i<=n; i++){
        dp[i] = min(abs(stones[i] - stones[i-2]) + dp[i-2], abs(stones[i] - stones[i-1]) + dp[i-1]);
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1024
import sys

H, W = map(int, input().split())


board = [
  list(input())
  for _ in range(H)]

def calc(board, x, y):
    num = 0
    if board[x][y] == '#':
        return '#'
    for i in (x-1, x, x+1):
        for j in (y-1, y, y+1):
            if i == x and j == y:
                continue
            elif 0 <= i <= H-1 and 0 <= j <= W-1:
                if board[i][j] == '#':
                    num += 1
    return str(num)

for i in range(H):
    for j in range(W):
        sys.stdout.write(calc(board, i, j))
    sys.stdout.write('\n')

Measured memory_bytes: 3188
def solve():

    N = int(input())
    S = input()

    r = S.count('R')
    g = S.count('G')
    b = S.count('B')

    ans = r*g*b

    for i in range(N-2):
        for j in range(i+1, N-1):
            # j - i = k - j
            k = j-i+j
            if k >= N:
                continue
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1

    print(ans)


if __name__ == "__main__":
    solve()


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

using namespace std;

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

    if (n % 2) {
        cout << 0 << endl;
        return 0;
    }

    n /= 2;

    long r = 0;
    while (n>0) {
        r += n/5;
        n /= 5;
    }
    cout << r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){
  while (1) {
  int n;
  cin >> n;
  if (!n) break;
  vector<int> w(n);
  rep(i,n) cin >> w[i];

  vector<vector<int>> dp(n+1,vector<int>(n+1,0));

  for (int len = 2; len <= n; len++) {
    for (int l = 0; l + len <= n; l++) {
      int r = l + len;
      if (abs(w[r-1] - w[l]) <= 1 && dp[l+1][r-1] == len - 2) dp[l][r] = len;
      for (int k = l; k <= r; k++) {
        dp[l][r] = max(dp[l][r], dp[l][k] + dp[k][r]);
      }
    }
  }
  cout << dp[0][n] << endl;
  }
  return 0;
} 


Measured memory_bytes: 3280
#include <cstdio>
#include <vector>

using namespace std;

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

    vector <int> element(no_of_elements + 1, 0);
    for(int i = 1; i <= no_of_elements; i++)
        scanf("%d", &element[i]);

    int no_of_swaps = 0;
    for(int i = 1; i < no_of_elements; i++)
    {
        if(element[i] == i)
        {
            swap(element[i], element[i + 1]);
            no_of_swaps++;
        }
    }

    if(element[no_of_elements] == no_of_elements)
        no_of_swaps++;

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


Measured memory_bytes: 640
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define ll long long
#define ld long double
using namespace std; 
 
const int N = 2e5 + 1000, OO = 1e9 + 100, M = 1e9 + 7, P = 6151, SQ = 120, lg = 100;
typedef pair <int, int> pii;

int32_t main() {
    use_fast;
    int k, n;
    cin >> n >> k;
    n *= 500;
    if(n >= k)
    	return cout << "Yes", 0;
    cout << "No" << endl;
	return 0; 
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/	

Measured memory_bytes: 256
// Author: Jinhai Chen
#include <bits/stdc++.h>
typedef long long ll;
ll INF = 0x3f3f3f3f3f3f3f3f;
#define mst(a,x) memset(a,x,sizeof(a))
using namespace std;

int n;
int c[1000];
int main() {
#ifdef CJHCJH
	freopen("data.in","r",stdin);
#endif
	ios::sync_with_stdio(false);
	int a,b,k;
	cin>>a>>b>>k;
	for(int i=1;i<=min(a,b);i++) {
		if(a%i==0 && b%i==0) c[n++]=i;
	}
	sort(c,c+n);
	cout<<c[n-k]<<endl;
	return 0;
}















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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string ss;
	cin >> ss;
	string ns;
	if (ss[ss.length() - 1] == '2' || ss[ss.length() - 1] == '4' || ss[ss.length() - 1] == '5' || ss[ss.length() - 1] == '7' || ss[ss.length() - 1] == '9')
		ns = "hon";
	if (ss[ss.length() - 1] == '0' || ss[ss.length() - 1] == '1' || ss[ss.length() - 1] == '6' || ss[ss.length() - 1] == '8')
		ns = "pon";
	if (ss[ss.length() - 1] == '3')
		ns = "bon";

		cout << ns;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3612
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = tuple(map(int, args[1].split()))

    left = 0
    right = sum(A)

    ret = 0
    for i in range(0, n):
        r_g = right - left
        left += A[i]
        right -= A[i]
        if left == right:
            break
        elif left > right:
            l_g = left - right
            ret = min(r_g, l_g)
            break

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 27556
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var nm = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        if (Abs(nm[0] - nm[1]) > 1) WriteLine(0);
        else if (Abs(nm[0] - nm[1]) == 1)
            WriteLine(Get(nm[0], nm[1]));
        else WriteLine((long)2 * Get(nm[0], nm[1]) % MOD);
    }
    private static int Get(int n,int m)
    {
        var l = 1L;
        for(var i = 1; i <= n; i++)
        {
            l *= i;
            l %= MOD;
        }
        for(var i = 1; i <= m; i++)
        {
            l *= i;
            l %= MOD;
        }
        return (int)l;
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)


int N;
vector<int> LIS(vector<int>& v) {
    int i;
    vector<int> dp(N, 1 << 30), id(N);
    rep(i, 0, v.size()) {
        id[i] = lower_bound(dp.begin(), dp.end(), v[i]) - dp.begin();
        dp[id[i]] = v[i];
    }
    int nl = *max_element(id.begin(), id.end());
    vector<int> ret(nl + 1);
    rep(i, 0, N) if (id[N - 1 - i] == nl) ret[nl--] = v[N - 1 - i];
    return ret;
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> N;

    vector<int> v;
    rep(i, 0, N) {
        int x; scanf("%d", &x);
        v.push_back(x);
    }

    auto a = LIS(v);
    cout << a.size() << endl;
}

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

int main() {
    int k, n;
    cin >> k >> n;
    vector<int> a(n);

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

    sort(a.begin(), a.end());
    int dmax;
    dmax = a[0] + (k-a[n-1]);
    for(int i=0; i<n-1; i++){
        int dif = a[i+1] - a[i];
        dmax = max(dmax, dif);
    }

    cout << k - dmax << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I h,w;
  cin >> h >> w;
  vector<string> v(h);
  REP(i,h){
    cin >> v.at(i);
  }
  vector<vector<P>> an(h,vector<P>(w));
  REP(i,h){
    V tmpV;
    REP(j,w){
      if (v.at(i).at(j) == '#'){
        V tmpV2;
        an.at(i).at(j).first = 0;
        if (tmpV.size() > 0){
          REP(k,tmpV.size()){
            an.at(i).at(tmpV.at(k)).first = tmpV.size();
          }
        }
        swap(tmpV,tmpV2);
      }else{
        tmpV.push_back(j);
      }
    }
    if (tmpV.size() > 0){
      REP(k,tmpV.size()){
        an.at(i).at(tmpV.at(k)).first = tmpV.size();
      }
    }
    V tmpV3;
    swap(tmpV,tmpV3);
  }
  REP(j,w){
    V tmpV;
    REP(i,h){
      if (v.at(i).at(j) == '#'){
        V tmpV2;
        an.at(i).at(j).second = 0;
        if (tmpV.size() > 0){
          REP(k,tmpV.size()){
            an.at(tmpV.at(k)).at(j).second = tmpV.size();
          }
        }
        swap(tmpV,tmpV2);
      }else{
        tmpV.push_back(i);
      }
    }
    if (tmpV.size() > 0){
      REP(k,tmpV.size()){
        an.at(tmpV.at(k)).at(j).second = tmpV.size();
      }
    }
    V tmpV3;
    swap(tmpV,tmpV3);
  }
  I t=0;
  REP(i,h){
    REP(j,w){
      t = max(t,an.at(i).at(j).first + an.at(i).at(j).second);
    }
  }
  cout << t-1 << endl;
  return 0;
}



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

using namespace std;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n;
int d[N];
vector < int > g[N];

void dfs (int v) {
	vector < int > val;
	for (auto to : g[v]) {
		dfs(to);
		val.pb(d[to]);
	}
	sort(val.rbegin(), val.rend());
	for (int i = 0; i < sz(val); i++)
		d[v] = max(d[v], val[i] + 1 + i);
}

int main () {
	SpeedForce;
	cin >> n;
	for (int i = 2; i <= n; i ++) {
		int x;
		cin >> x;
		g[x].pb(i);
	}

	dfs(1);
	cout << d[1] << '\n';
   	return Accepted;
}

// B...a

Measured memory_bytes: 30720
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>
#include<bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n"
using namespace std;
using ll=long long;
using ld=long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
void bl(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void bl2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) {
            for (auto vvv : vv) cout << vvv << " ";
            cout << endl;
        }
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class a {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        if(n == 0 || n == 1) {
            out << 1 << enl;
            return;
        }
        vi dp(n+1, 0);
        dp[0] = dp[1] = 1;
        for(int i=1; i<n; i++){
            dp[i+1] = dp[i] + dp[i-1];
        }
//
//        debug.vd(dp);

        out << dp[n] << enl;
	}
};


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	a solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}



Measured memory_bytes: 3188
import scala.io.StdIn.readLine

object Main {
    def main(args: Array[String]){
        val intArray= readLine.split(" ").map(_.toInt)
        println(calc(intArray))
    }

    def calc(args: Array[Int]): Int = {
        val a = args(0)
        val b = args(1)
        val c = args(2)
        val d = args(3)

        val e1 = List(a, c).max
        val e2 = List(b, d).min

        if (e2 - e1 < 0) return 0
        return e2 - e1
    }
}


Measured memory_bytes: 25288
//@source: 
//@create: 19:03:16 Saturday 15/08/2020
//@author: nghethuat102
#include <bits/stdc++.h>
using namespace std;

#define len(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define discrete(x) sort(all(x)), x.erase(unique(all(x)), x.end())

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                if (a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) {
                    if (a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i]) {
                        ++ans;
                    }
                }
            }
        }
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    for (int it = 1; it <= t; ++it) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
typedef pair<int,int> P;

int N;
vector<int> graph[100010];
int fennec[100010];
int snuke[100010];

void bfsf(int s)  {
    for(int i = 0;i < N;i++) {
        fennec[i] = INF;
    }
    priority_queue<int,vector<int>,greater<int>> que;
    que.push(s);
    fennec[s] = 0;
    while(!que.empty()) {
        int p = que.top();
        que.pop();
        bool update = false;
        for(int i = 0;i < graph[p].size();i++) {
            if(fennec[p] + 1 < fennec[graph[p].at(i)]) {
                fennec[graph[p].at(i)] = fennec[p] + 1;
                que.push(graph[p].at(i));
                update = true;
            }
        }
    }
}

void bfss(int s)  {
    for(int i = 0;i < N;i++) {
        snuke[i] = INF;
    }
    priority_queue<int,vector<int>,greater<int>> que;
    que.push(s);
    snuke[s] = 0;
    while(!que.empty()) {
        int p = que.top();
        que.pop();
        bool update = false;
        for(int i = 0;i < graph[p].size();i++) {
            if(snuke[p] + 1 < snuke[graph[p].at(i)]) {
                snuke[graph[p].at(i)] = snuke[p] + 1;
                que.push(graph[p].at(i));
                update = true;
            }
        }
    }
}

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int A,B;
        cin >> A >> B;
        graph[A - 1].push_back(B - 1);
        graph[B - 1].push_back(A - 1);
    }
    bfsf(0);
    bfss(N - 1);
    int F = 0;
    int S = 0;
    for (int i = 0; i < N; i++) {
        if(fennec[i] > snuke[i]) {
            S++;
        }
        else {
            F++;
        }
    }
    if(S >= F) {
        cout << "Snuke" << endl;
    }
    else {
        cout << "Fennec" << endl;
    }
}

Measured memory_bytes: 7984
s_ = input()
t = input()

if len(s_) < len(t):
    print("UNRESTORABLE")
    exit(0)

flag = True
for i in range(len(s_) - len(t), -1, -1):
    flag = True
    for j in range(len(t)):
        if s_[i + j] != t[j] and s_[i + j] != "?":
            flag = False
    if flag is True:
        s_ = s_[0:i] + t + s_[i + len(t):]
        break

if flag is False:
    print("UNRESTORABLE")
else:
    print(s_.replace("?", "a"))


Measured memory_bytes: 3064
#include <stdio.h>
 
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
 
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}
 
void skip(int k) { while (k--) gc(); }
 
void out(int n)
{
	int i;
	char ob[20];
 
	if (!n) { pc('0'); return; }
	i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
	while (i--) pc(ob[i]); 
}
 
int que[1500005]; int top, end;
 
int main()
{
	int n, i, t;
	char op;
 
	n = in(); top = 0, end = 1;
	while (n--) {
		if (gc() == 'i') {
			skip(6);
			que[end++] = in();
		} else {
			skip(5);
			op = gc();
			if (op == 'L') {
				skip(4);
				top++;
			} else if (op == 'F') {
				skip(5);
				end--;
			} else {
				que[top] = t = in();
				i = end; while (que[--i] != t);
				if (i > top) {
					if (end - i < i - top) {
						while (++i < end) que[i-1] = que[i];
						end--;
					} else {while (--i > top) que[i+1] = que[i];
						top++;
					}
				}
			}
		}
	}
	i = end-1; out(que[i--]);
	while (i > top) pc(' '), out(que[i--]);
	pc('\n');
	return 0;
}




Measured memory_bytes: 5520
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }

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

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

int main(){
  int N,M;
  cin >> N >> M;
  int num[N];
  rep(i,N) {
    cin >> num[i];
    num[i]--;
  }

  UnionFind uf(N);
  rep(i,M){
    int x,y;
    cin >> x >> y;
    x--; y--;
    uf.merge(x,y);
  }
  int ans = 0;
  rep(i,N){
    if(uf.issame(num[i], i)) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll long long
#define P pair<int,int>
#define cat(p) cout<<p<<endl
#define catA(p,n) for(int i=0;i<n;i++)cout<<p[i]<<((i==n-1)?"\n":" ")

const int MAX_N=3000;
ll F[MAX_N];
ll IF[MAX_N];

ll invl(ll a,ll b,ll m){//ap-2乗るを返す
	ll tmp=1;

	while(b){
		if(b&1){
			tmp=(tmp*a)%m;
		}
		a=(a*a)%m;
		b/=2;
	}

	return tmp%m;
}

ll po(ll a,ll b,ll m){
  ll tmp=1;

  while(b){
    if(b&1){
      tmp=(tmp*a)%m;
    }
    a=(a*a)%m;
    b/=2;
  }
  return tmp%m;
}

void init(ll m){
	F[0]=1;
	IF[0]=1;

	for(ll i=1;i<MAX_N;i++){
		F[i]=(F[i-1]*i)%m;
		IF[i]=invl(F[i],m-2,m)%m;//逆元を、フェルマーの小定理を利用して求める
	}
}

ll C(int n,int r,int m){

	if(n<0||r<0||r>n)return (ll)0;
	if(r>n/2)r=n-r;

	//cout<<F[n]<<" "<<IF[r]<<" "<<IF[n-r]<<endl;
	ll ret=F[n]*IF[r]%m*IF[n-r]%m;
	return ret;
}

ll one=1;
ll p(ll n, ll m)
{

    if (n == m)
        return one + p(n, m - one);
    if (m == 0 || n < 0)
        return 0;
    if (n == 0 || m == one)
        return one;

    return p(n, m - one) + p(n - m, m);

}

ll n,k;
ll MOD=1000000007;
int main(){

  cin>>n>>k;
  init(MOD);


  for(ll i=1;i<=k;i++){
      ll amari=(n-k)-(i-1);
      cout<<C(k-1,i-1,MOD)*C(i+1+amari-1,amari,MOD)%MOD<<endl;//<<" "<<" "<<i+1<<" "<<amari<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int h = scanner.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int aMax = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
            aMax = Math.max(aMax, a[i]);
        }

        Arrays.sort(b);
        for (int i = n - 1; i >= 0 && h > 0 && b[i] > aMax; i--) {
            h -= b[i];
            ans++;
        }

        if (h > 0) ans += Math.ceil((double)h / aMax);

        System.out.println(ans);
    }
}

Measured memory_bytes: 75816
<?php
fscanf(STDIN,'%d %d',$H,$N);
$A = array_map('intval', explode(' ', fgets(STDIN)));

foreach ($A as $row){
  $H = $H - $row;
}

If ($H <= 0) {
 echo 'Yes';
} Else {
 echo 'No';
}

Measured memory_bytes: 35620
N, T = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort()

ans = 0
dp = dp = [[0 for _ in range(3005)] for _ in range(3005)]
for i in range(N):
    a, b = AB[i]
    for j in range(T):
        # iを使わないパターン
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
        # iを使うパターン
        nj = j + a
        if nj < T:
            dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + b)
    now = dp[i][T - 1] + b
    ans = max(ans, now)

print(ans)


Measured memory_bytes: 123864
#include <iostream>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll i=1; i<=n; i++) {
    ll x;
    cin >> x;
    if(i%2==1 && x%2==1) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
 
#pragma comment(linker, "/STACK:336777216")  
 
using namespace std;
 
const int K = 38;
const int N = K * (K - 1) + 1;
 
int c[N][N];
 
void Work()
{
	printf("%d %d\n", N, K);
	for (int i = 0; i < K; i ++)
	{
		c[i][0] = c[0][i] = 1;
		for (int j = 0; j < K - 1; j ++)
			c[i][j + (K - 1) * i + 1] = c[j + (K - 1) * i + 1][i] = 1;
	}
	for (int i = 0; i < K - 1; i ++)
		for (int j = 0; j < K - 1; j ++)
		{
			int si = K + (K - 1) * i;
			int sj = K + (K - 1) * j;
			int delta = i;
			//c[si][sj] = 5;
			for (int ii = 0; ii < K - 1; ii ++)
				c[si + ii][sj + (ii + delta * j) % (K - 1)] = 1;
		}
	for (int i = 0; i < N; i ++)
	{
		for (int j = 0; j < N; j ++)
			if (c[i][j])
				printf("%d ", j + 1);
		printf("\n");
	}
}
 
int main()
{
	Work();
	return 0;
}

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

using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(vr) vr.begin(),vr.end()
const int N=1e5+10;
vector<pii> G[N];
int d[N],n,m,p[N];

void read()
{
    cin>>n>>m;
    for (int i=1,u,v;i<n+m;i++)
    {
        cin>>u>>v;
        G[u].pb(mp(v,1));
        d[v]++;
    }
}

void dfs(int u)
{
    for (int i=0;i<(int)G[u].size();i++)
    {
        d[G[u][i].fi]--;
        if (d[G[u][i].fi]>0) G[u][i].se=0;
    }
    for (pii v : G[u])
        if (v.se)
        {
            p[v.fi]=u;
            dfs(v.fi);
        }
}


void process()
{
    int root=1;
    for (int i=1;i<=n;i++)
        if (d[i]==0) root=i;
    dfs(root);
    for (int i=1;i<=n;i++) cout<<p[i]<<"\n";
}

int main()
{
    //freopen("ss.inp","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    read();
    process();
    return 0;
}


Measured memory_bytes: 10240
S = list(map(int, input().split("/")))

if S[0] <= 2019:
    if S[1] <= 4:
        if S[2] <= 30:
            print("Heisei")
        else:
            print("TBD")
    else:
        print("TBD")
else:
    print("TBD")

Measured memory_bytes: 2940
#include <iostream>

int main(){
    char src[17];
    char ans[17] = "CODEFESTIVAL2016";
    int result = 0;
    
    scanf("%s", src);
    for(int i = 0; i < 17; i++){
        if(src[i] != ans[i])
            result++;
    }
    printf("%d\n", result);

    return 0;
}

Measured memory_bytes: 256
s = int(input())
mod = 10**9+7

memo = {0: 0,
        1: 0,
        2: 0,
        3: 1,
        4: 1}

def dfs(n):
    if n in memo:
        return memo[n]
    else:
        ret = 0
        for i in range(3, n):
            ret += dfs(n-i)
            ret %= mod
        ret += 1
        ret %= mod
        memo[n] = ret
        return ret

print(dfs(s))


Measured memory_bytes: 70584
#include "bits/stdc++.h"
#include<stdio.h>
#include <sstream>
#define pi 3.141592653589793238462
#define limit 100005
#define mo 1000000007;
typedef long long int lli;
typedef unsigned long long int ulli;
const lli mod=9999999999999983;
lli primes[6]={1125899906842597,1495921043,1005985879,1495921043,1005985879,1495921043};
using namespace std;
vector<lli>adj[2000009];
vector<lli>adj2[2000009];
lli parent[2000009];
lli vis[2000009];
lli visited[2000009];
lli level[2000009];
lli dist[2000009];
lli dp[2000009];
lli arr[2000009];
lli brr[2000009];
lli crr[2000009];
lli hashing[2000009];
lli ar[509][509];
lli br[509][509];
lli cr[509][509];
lli indeg[2000009];
lli mark[2000009];
lli res;


lli solve(lli n)
{
    if(dp[n]!=-1)
        return dp[n];

        if(n<=0)
            return 0;

    lli res=0,i;

    for(i=0;i<adj[n].size();i++)
    {
        res=max(res,1+solve(adj[n][i]));
    }

    return dp[n]=res;
}



int main()
{
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    int start_s = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    vector< pair<lli,lli> >vect,vt,vct;
    vector<lli>::iterator itt;
    set<lli>st;
    set<lli>::iterator itr;
    map<lli,lli>mp;
    map<lli,lli>::iterator it;
    string str;
    queue<lli>q,q2;

    lli i,j,k,n,m,t,p,a,b,c,maxi=INT_MIN,mini=INT_MAX,sum=0,ans=0,val=0,ans1=0,ans2=0,rem=0,diff=0,cnt=0,l,r,flag=0,e,index,val1=0,val2=0,x,y,z,h=0,u,v,mid,len,tot,fl=0;

    cin>>n>>m;

    for(i=0;i<m;i++)
    {
        cin>>u>>v;
        adj[v].push_back(u);
        indeg[v]++;
    }

    memset(dp,-1,sizeof(dp));

    for(i=1;i<=n;i++)
    {
        if(indeg[i]==0)
            dp[i]=0;
    }

    for(i=1;i<=n;i++)
    {
        solve(i);
    }

    for(i=1;i<=n;i++)
    {
       // cout<<"i="<<i<<" "<<"dp="<<dp[i]<<endl;
        maxi=max(maxi,dp[i]);
    }

    cout<<maxi<<endl;


}


Measured memory_bytes: 125312
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll gcd(ll a, ll b){
  ll v0 = a, v1 = b, v2 = a%b;
  while(v2!=0){
    v0 = v1;
    v1 = v2;
    v2 = v0 % v1;
  }
  return v1;
}

int main() {
  int N;
  cin>>N;
  ll A[N];
  for(int i=0;i<N;++i){
    cin>>A[i];
  }
  ll ans = A[0];
  for(int i=1;i<N;++i){
    ans = gcd(ans, A[i]);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4372