akhauriyash/Code-Regression huggingface dataset:
row , col = map(int,input().split())
row = int(row)
end_num = 0

row_col_list = []
while True:
    base_suit = input()
    row_col_list.append(base_suit)

    end_num += 1
    if row == end_num:
        break

col_sum_list = []
for row in row_col_list:
    term = row.split()
    row_sum = 0
    col_list = []
    for r in term:
        row_sum += int(r)
        col_list.append(int(r))
        print('{} '.format(r),end='')
    
    col_list.append(row_sum)
    print(row_sum)
    col_sum_list.append(col_list)

for i in range(0,col+1):
    col_sum = 0
    for c in col_sum_list:
        col_sum += c[i]

    print('{}'.format(col_sum),end='')
    if i != col:
        print(' ',end='')

print()



Measured memory_bytes: 6240
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n, h;

vector<int> v;

signed main() {

    cin >> n >> h;
    int a, b;
    int maxi = 0;
    for(int i = 0; i <  n; i++) {
        cin >> a >> b;
        chmax(maxi,a);
        v.bash(b);
    }
    sort(ALL(v), greater<int>());
    int sum = 0;
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        if(v[i] < maxi) break;
        sum += v[i];
        cnt++;
        if(sum >= h) break;
    }

    if(sum >= h) cout << cnt << endl;
    else cout << cnt + (h-sum+maxi-1)/maxi << endl;


  
    return 0;
}



Measured memory_bytes: 1400
#include<stdio.h>

#define PRICE 700
#define TOPPING 100
#define ODR_NUM 3

int main(void)
{
  int i,pay=PRICE;
  char odr[ODR_NUM];
  
  scanf("%s",odr);
  
  for(i=0;i<ODR_NUM;i++)
  {
    if(odr[i] == 'o')
    {
      pay += TOPPING;
    }
  }
  
  printf("%d\n",pay);
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
bool a[10];
int n,x,ans,temp;
int main(){
    scanf("%d",&n);
    while (n--) {
        scanf("%d",&x);
        if (x<400&&!a[1]) a[1]=true,ans++;
        if (x>=400&&x<800&&!a[2]) a[2]=true,ans++;
        if (x>=800&&x<1200&&!a[3]) a[3]=true,ans++;
        if (x>=1200&&x<1600&&!a[4]) a[4]=true,ans++;
        if (x>=1600&&x<2000&&!a[5]) a[5]=true,ans++;
        if (x>=2000&&x<2400&&!a[6]) a[6]=true,ans++;
        if (x>=2400&&x<2800&&!a[7]) a[7]=true,ans++;
        if (x>=2800&&x<3200&&!a[8]) a[8]=true,ans++;
        if (x>=3200) temp++;
      }
    printf("%d %d\n",max(ans,1),ans+temp);
    return 0;
  }

Measured memory_bytes: 256
N = int(input())
if N<105:
    print(0)

else:
    ans = 0
    for i in range(105,N+1,2):
        temp = 0
        for j in range(1,i+1):
            if i%j == 0:
                temp +=1
        if temp == 8:
            ans += 1
    print(ans)



Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N, M; cin >> N >> M;
    vec A(N); cin >> A;
    int S = 0;
    REP(i, N) S += A[i];

    int cnt = 0;
    REP(i, N) if(A[i] * 4 * M >= S) cnt++;

    Ans(cnt >= M, "Yes", "No");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
ll a[100005];
ll ans = 0;
int main() {
  IOS;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (i == a[a[i]]) {
      ans++;
    }
  }
  cout << ans / 2 << endl;
}


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


using namespace std;
constexpr long long int mod = 1000000007, MOD = 998244353, MAX = 200000;
const double PI = 3.14159265358979323846;
int main() {
    cout << fixed << setprecision(10);
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double ans = pow(A, 2) + pow(B, 2) - 2 * A * B * cos((H/12+M/720-M/60)* 2 * PI);
    cout << sqrt(ans);
}

Measured memory_bytes: 4104
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define EPS 1e-6
#define MOD 998244353ll
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;

inline void solve()
{
	int n, m, x, y, z;
	cin >> n >> m >> x >> y >> z;
	vector<int> r(x), g(y);
	multiset<int> l;

	fore(i, 0, x)
		cin >> r[i];

	fore(i, 0, y)
		cin >> g[i];

	fore(i, 0, z)
	{
		int a;
		cin >> a;
		l.insert(a);
	}

	sort(r.rbegin(), r.rend());
	sort(g.rbegin(), g.rend());

	fore(i, 0, min(x, n))
		l.insert(r[i]);

	fore(i, 0, min(y, m))
		l.insert(g[i]);

	ll otv = 0;

	fore(i, 0, n + m)
	{
		otv += *l.rbegin();
		l.erase(--l.end());
	}

	cout << otv;
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	while (q--)
	{
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 14208
/* C++標準ヘッダファイル */
/* 文字列ライブラリ */
#include <string>

/* コンテナライブラリ */
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>

/* アルゴリズムライブラリ */
#include <algorithm>

/* 数値演算ライブラリ */
#include <cmath>
#include <math.h>

/* 入出力ライブラリ */
#include <iostream>

/* std使用<-namespace */
using namespace std;

/* define, typedef */
#define rpt(i, n) for(ll i = 0; i < (n); i++)  // リピート
typedef long long ll;

/* main関数 */
int main(void) {
	ll n;
	cin >> n;
	ll min = 1 + n, d, p, q;
	for (p = 1; p * p <= n; p++) {
		if (n % p == 0) {
			q = n / p;
			d = p + q - 2;
			if (d < min) min = d;
		}
	}
	cout << min << endl;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define FORS(i, m, n) for(ll i = m;i < n;i++)
#define ALL(v) accumulate(v.begin(),v.end(),0)
#define SORT(v) sort(v.begin(),v.end())
#define FIND(v,item) find(v.begin(),v.end(),item)
#define OUT(n) (cout << n << endl)
#define IN1(a) (cin >> a)
#define IN2(a,b) (cin >> a >> b)
#define IN3(a,b,c) (cin >> a >> b >> c)
#define IN4(a,b,c,d) (cin >> a >> b >> c >> d)
#define REVS(v) reverse(v.begin(),v.end())
#define PI 3.14159265359
using namespace std;
typedef long long ll;

int main(){
  ll n,ans;
  ans = 0;
  IN1(n);
  vector<ll> data(n);
  for (int i = 0; i < n; i++) {
    cin >> data.at(i);
  }
  FOR(i,n){
    while (data[i]%2 == 0){
      data[i] = data[i] / 2;
      ans++;
    }
    
  }
  OUT(ans);
}

Measured memory_bytes: 384
#include <stdio.h>
#define TRUE 1
#define FALSE 0

int serch(int,int);
int n,A[50];


int main(){
  int q,m,i;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(serch(0,m)==TRUE)printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int serch (int i,int m){
  int res;
  if(m==0)return TRUE;
  if(i>=n)return FALSE;
  res=serch(i+1,m) || serch(i+1,m-A[i]);
  return res;
}

Measured memory_bytes: 580
import java.util.Scanner;

public class Main{
  static final int INF = Integer.MAX_VALUE / 2;
  static int n;
  static char[][] s;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt();
    s = new char[n][];
    for(int i = 0; i < n; i++){
      s[i] = sc.next().toCharArray();
    }

    int[][] counts = new int[n][26];
    for(int i = 0; i < n; i++){
      for(int j = 0; j < s[i].length; j++){
        ++counts[i][s[i][j] - 'a'];
      }
    }

    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < 26; i++){
      int min = INF;
      for(int j = 0; j < n; j++){
        min = Math.min(min, counts[j][i]);
      }
      if(min != 0){
        for(int j = 0; j < min; j++){
          sb.append((char)(i + 'a'));
        }
      }
    }

    System.out.println(sb);
  }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int a,h1,m1,b,h2,m2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  a=60*h1+m1;
  b=60*h2+m2;
  cout<<b-a-k<<endl;
}

Measured memory_bytes: 3676
s = input()
K = int(input())
a = 1
ans = 0
e = 0
l_s = []
for i in range(1,len(s)):
    if s[i] == s[i-1]:
        a += 1
    else:
        l_s.append(a)
        a = 1
l_s.append(a)
if len(l_s) == 1:
    print((l_s[0]*K)//2)
    exit()
if s[0] == s[-1]:
    f = l_s[0]
    l = l_s [-1]
    l_s[-1] += l_s[0]
    del l_s[0]
    e = 1
for i in l_s:
    ans += i//2
if e == 1:
    M = ans*K - l_s[-1]//2
    M += f//2
    M += l//2
else:
    M = ans*K
print(M)

Measured memory_bytes: 38256
#include<stdio.h>
#include<math.h>
int main()
{
    int n,num[10000],i,d,prime=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&num[i]);
    for(i=0;i<n;i++)
    {
        for(d=2;d<=sqrt(num[i]);d++)
        {
            if(num[i]%d==0)
            {
                break;
            }
        }
        if(d>sqrt(num[i]))
        {
            prime++;
        }
    }
    printf("%d\n",prime);
    return 0;
}



Measured memory_bytes: 2112
using System;

namespace Procon20191202_1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] line1 = Console.ReadLine().Trim().Split(' ');
                int n = int.Parse(line1[0]);
                int m = int.Parse(line1[1]);
                if (n == 0 && m == 0)
                {
                    break;
                }
                string[] line2 = Console.ReadLine().Trim().Split(' ');
                int[] array = new int[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = int.Parse(line2[i]);
                }
                int value = -1;
                for (int i = 0; i < n - 1; i++)
                {
                    for (int j = i + 1; j < n; j++)
                    {
                        int a = array[i] + array[j];
                        if ( a <= m && a > value)
                        {
                            value = a;
                        }
                    }
                }
                if (value == -1)
                {
                    Console.WriteLine("NONE");
                }
                else
                {
                    Console.WriteLine(value);
                }
            }
        }
    }
}



Measured memory_bytes: 15884
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;



int main(){

	int table[100][100],n,m,sum,fixed[100],count,a,b,cost,minimum,checkTable[100],min_index;

	while(true){
		scanf("%d %d",&n,&m);
		if(n == 0 && m == 0)break;

		for(int i=0; i < n; i++){
			checkTable[i] = 0;
			for(int k=0; k < n; k++)table[i][k] = 0;
		}

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

		checkTable[0] = 1;
		fixed[0] = 0;
		count = 1;
		sum = 0;

		while(count < n){
			minimum = 1000000000;
			for(int i = 0; i < count; i++){
				for(int k=0; k < n; k++){
					if(table[fixed[i]][k] > 0 && checkTable[k] == 0 && table[fixed[i]][k] < minimum){
						minimum = table[fixed[i]][k];
						min_index = k;
					}
				}
			}

			sum += minimum;
			checkTable[min_index] = 1;
			fixed[count] = min_index;
			count++;
		}

		printf("%d\n",sum);

	}

    return 0;
}

Measured memory_bytes: 2748
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int>a(n),b;
  rep(i,n)cin>>a[i];
  map<int,int>ma;
  rep(i,n)ma[a[i]]++;

  for(auto tp:ma)
  {
    b.push_back(tp.second);
  }
  sort(all(b),greater<int>());
  vector<int>res(n+1);
  int s=n;
  int id=1;
  int wei=0;
  rep(i,b.size())
  {
    int nid=s/b[i]+1+wei;
    repi(j,id,nid)
    {
    //  cout<<j<<s;
      res[j]=s/(j-wei);
    }
    id=nid;
    s-=b[i];
    wei++;
  }
  rep(i,n)cout<<res[i+1]<<"\n";
  cout<<endl;


  return 0;

}


Measured memory_bytes: 17904
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
	int R[MAX],n;
	cin >> n;
	for( int i=0; i < n; i++) cin >> R[i];
	
	int maxv = -2000000000;
	int minv = R[0];
	
	for( int i = 1; i < n; i++){
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	
	cout << maxv << endl;
	
	return 0;
}
	
	

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

int main(){
  bool data[1000001];
  int n,m,k,count;

  for(int i = 0;i < 1000001;i++){
    k = i;
    while(k%2 == 0&&k >=2)k /= 2;
    while(k%3 == 0&&k >=3)k /= 3;
    while(k%5 == 0&& k >= 5)k /= 5;
    if( k == 1)
      data[i] = true;
    else
      data[i] = false;
  }

  while(1){
    cin >> m;
    if(m == 0)break;
    cin >> n;
    count = 0;
    for(int i = m; i <= n;i++)
      if(data[i] == true)count++;

    cout << count << endl;
    }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
int main(){
    int n,K;std::cin>>n>>K;
    std::vector<std::complex<double>>P(n);
    std::vector<double>C(n),R(n);
    for(int i=0;i<n;i++){
        double x,y;std::cin>>x>>y;
        P.at(i)={x,y};
        std::cin>>C.at(i);
    }
    double eps=1e-12;
    double lwr=0,upr=200'000;
    for(int ngtkana=0;ngtkana<70;ngtkana++){
        double T=(lwr+upr)/2;
        for(int i=0;i<n;i++)R.at(i)=T/C.at(i);
        auto covered_by_K=[&](std::complex<double>p, int i, int j){
            int counter=0;
            for(int k=0;k<n;k++){
                counter+=k==i||k==j||std::abs(p-P.at(k))<R.at(k);
            }
            return K<=counter;
        };
        for(int i=0;i<n;i++){
            if(covered_by_K(P.at(i),i,i))goto Upr;
        }
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                double d=std::abs(P.at(j)-P.at(i));
                if(d<std::abs(R.at(j)-R.at(i))+eps||R.at(i)+R.at(j)-eps<d)continue;
                double t0=std::arg(P.at(j)-P.at(i));
                double t1=std::acos((R.at(i)*R.at(i)+d*d-R.at(j)*R.at(j))/(2*R.at(i)*d));
                if(covered_by_K(P.at(i)+R.at(i)*std::exp(std::complex<double>(0,t0+t1)),i,j)
                    ||covered_by_K(P.at(i)+R.at(i)*std::exp(std::complex<double>(0,t0-t1)),i,j)){
                    goto Upr;
                }
            }
        }
        lwr=T;
        continue;
        Upr:upr=T;
    }
    std::cout<<std::setprecision(13)<<lwr<<std::endl;
}


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



int main() {
  string S;
  cin>>S;

  //cout << S[S.size() - 1] << endl;
  if(S[S.size()-1] != 's'){
    cout << S + "s" << endl;
    return 0;
  }else{
    cout << S + "es" << endl;
  }
  

}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int pinv = 1, x = 1900 * m + (n - m) * 100;
	for (int i = 0;i < m;i++)pinv *= 2;
	cout << pinv * x << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int h = Integer.parseInt(scanner.next());
    int w = Integer.parseInt(scanner.next());
    String[] a = new String[h];
    int[][] dp = new int[h + 1][w + 1];
    int MAX = 1000000007;
    for (int i = 0; i < h; i++) {
      a[i] = scanner.next();
      dp[i][0] = 0;
    }
    for (int i = 1; i < w; i++) {
      dp[0][i] = 0;
    }
    dp[0][1] = 1;
    for (int i = 1; i < h + 1; i++) {
      for (int j = 1; j < w + 1; j++) {
        if (a[i - 1].charAt(j-1) == '.') {
          dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
        } else {
          dp[i][j] = 0;
        }
        if (dp[i][j] >= MAX) {
          dp[i][j] %= MAX;
        }
      }
    }
    System.out.println(dp[h][w]);
  }
}


Measured memory_bytes: 34700
#include <stdio.h>

int main(){
   int n,i,b[100],s;
 
   scanf("%d",&n);
   for (i=0;i<n-1;i++) scanf("%d",&b[i]);
   s=b[0];
   for (i=1;i<n-1;i++) 
      if (b[i]>b[i-1]) s+=b[i-1];
      else             s+=b[i];
   s+=b[n-2];
   printf("%d",s);
   return 0;
}


Measured memory_bytes: 256
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

LL n,MOD,x,y,dp[100010],ans[100010],pro[200];
vector <LL> g[100010];

LL dfs(LL pos,LL no)
{
  dp[pos]=1;
  rep(i,g[pos].size()) if(g[pos][i]!=no) dp[pos]=dp[pos]*(dfs(g[pos][i],pos)+1)%MOD;
  return dp[pos];
}

void dfs2(LL pos,LL no,LL val)
{
  ans[pos]=dp[pos]*(val+1)%MOD;
  vector <LL> sons;
  sons.clear();
  rep(i,g[pos].size()) if(g[pos][i]!=no) sons.pb(g[pos][i]);
  vector <LL> pref(sons.size()),suf(sons.size());
  rep(i,sons.size())
  {
  	if(i==0) pref[i]=dp[sons[i]]+1;
  	else pref[i]=pref[i-1]*(dp[sons[i]]+1)%MOD;
	}
	for(int i=sons.size()-1;i>=0;i--)
	{
		if(i==sons.size()-1) suf[i]=dp[sons[i]]+1;
		else suf[i]=suf[i+1]*(dp[sons[i]]+1)%MOD;
	}
  rep(i,sons.size()) dfs2(sons[i],pos,(val+1)*(i==0 ? 1:pref[i-1])%MOD*(i==sons.size()-1 ? 1:suf[i+1])%MOD);
}

int main()
{
  cin>>n>>MOD;
  rep(i,n-1)
  {
    scanf("%lld%lld",&x,&y);
    g[x].pb(y);
    g[y].pb(x);
  }
  dfs(1,0);
  dfs2(1,0,0);
  repn(i,n) printf("%lld\n",ans[i]);
  return 0;
}

Measured memory_bytes: 22016
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 1LL<<60;
/* -- template -- */

int main(){
    int N; cin >> N;
    vector<P> work(N);
    rep(i, N){
        cin >> work[i].first >> work[i].second;
    }
    sort(work.begin(), work.end(), [](P a, P b) {
        return a.second < b.second;
    });
    int accumulatedTime = 0;
    rep(i, N){
        accumulatedTime += work[i].first;
        if(accumulatedTime > work[i].second){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int  main()
{
    string s;
    cin>>s;
    int len = s.size();
    int n = 1<<(len-1);
    ll sum = 0;
    for(int i=0 ; i<n; i++)
    {

        ll cnt = s[0] - '0';//将字符ascii转换

        for(int j=0; j<len; j++)
        {
            if(j==len-1||i&1<<j)//从左往右数去i+1上那一个值
            {

                sum +=cnt;
                cnt = 0;//加完后清0
                if(j==len-1)
                {
                    break;
                }
            }
            cnt*=10;
            cnt+=s[j+1]-'0';
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        double Ans = 0;
        int count = 0;
        double an = 0;
        double an1 = 0;
        double an2 = 0;
        for(int i =0 ; i < N; i++){
            int X = sc.nextInt();
            int Y = sc.nextInt();
            Ans = Math.sqrt(Math.pow(X,2) + Math.pow(Y,2));
            if(Ans <= D){
                count++;
            }
        }
        sc.close();

        System.out.println(count);
        }
}


Measured memory_bytes: 59304
#include <queue>
#include <cstdio>
typedef long long ll;

int n,p[400005],Fa[400005],c[400005][2];
struct Node{int c0,c1,ID;inline bool operator<(const Node &o)const{return (ll)c0*o.c1<(ll)c1*o.c0;}};
std::priority_queue<Node> q;
int Get(const int x){return x==Fa[x]?x:Fa[x]=Get(Fa[x]);}

int main()
{
    scanf("%d",&n);
    for(int i=2;i<=n;++i)scanf("%d",&p[i]);
    for(int i=1,v;i<=n;++i)scanf("%d",&v),++c[Fa[i]=i][v];
    ll Ans=0;
    for(int i=2;i<=n;++i)q.push((Node){c[i][0],c[i][1],i});
    while(!q.empty())
    {
        Node Now=q.top();
        q.pop();
        int Pos=Now.ID;
        if(c[Pos][0]==Now.c0&&c[Pos][1]==Now.c1)
        {
            int Np=Fa[Pos]=Get(p[Pos]);
            Ans+=(ll)c[Pos][0]*c[Np][1];
            c[Np][0]+=c[Pos][0],c[Np][1]+=c[Pos][1];
            if(Np!=1)q.push((Node){c[Np][0],c[Np][1],Np});
        }
    }
    printf("%lld\n",Ans);
    return 0;
}

Measured memory_bytes: 10612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  string str = "";
  for(int i=0; i<5; i++){
  	str += "hi";
    if(str == S){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

using namespace std;

typedef long long BigInt;

int main() {
  vector<BigInt> min_n, max_n, base;
  min_n.push_back(0);
  max_n.push_back(9);
  base.push_back(1);
  while (not (min_n[base.size() - 1] <= -(1LL << 31) and max_n[base.size() - 1] <= (1LL << 31))) {
    int p = base.size();
    base.push_back(base[p - 1] * 10);
    if (p % 2 == 0) {
      max_n.push_back(max_n[p - 1] + 9 * base[p]);
      min_n.push_back(min_n[p - 1]);
    } else {
      max_n.push_back(max_n[p - 1]);
      min_n.push_back(min_n[p - 1] - 9 * base[p]);
    }
  }
  while (true) {
    BigInt n;
    int p = 0;
    string md = "";
    cin >> n;
    if (n == 0) {
      return 0;
    }
    while (not (min_n[p] <= n and n <= max_n[p])) {
      ++p;
    }
    while (p > 0) {
      for (int d = 0; d < 10; ++d) {
        BigInt r = n + (p % 2 == 0? -1: 1) * base[p] * d;
        if (min_n[p - 1] <= r and r <= max_n[p - 1]) {
          n = r;
          md += '0' + d;
          break;
        }
      }
      --p;
    }
    if (0 <= n and n < 10) {
      md += '0' + n;
    } else {
      md += '0';
    }
    cout << md << endl;
  }
}

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

int main(){
    int x,y;
    cin >> x >> y;
    if(x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12){
        if(y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12){
            cout << "Yes" << endl;
        }else cout << "No" << endl;
    }else if(x == 4 || x == 6 || x == 9 || x == 11){
        if(y == 4 || y == 6 || y == 9 || y == 11){
            cout << "Yes" << endl;
        }else cout << "No" << endl;
    }else if(x == 2 && y == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int S, h, m, s;

  scanf("%d", &S);
  
  h = S/3600;
  m = S/60 - h*60;
  s = S - h*3600 - m*60;

  printf("%d:%d:%d\n", h, m, s);

  return 0;
}



Measured memory_bytes: 2128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long int ll;

int main() {
	ll x,y,z,k;
	cin>>x>>y>>z>>k;
	vector<ll> alist(x);
	vector<ll> blist(y);
	vector<ll> clist(z);
	for(int i=0; i<x; i++) cin>>alist.at(i);
	for(int i=0; i<y; i++) cin>>blist.at(i);
	for(int i=0; i<z; i++) cin>>clist.at(i);
	
	vector<ll> ablist;
	vector<ll> abclist;
	for(int i=0; i<x; i++){
		for(int j=0; j<y; j++){
				ablist.push_back(alist.at(i)+blist.at(j));
		}
	}

	sort(ablist.begin(),ablist.end());
	reverse(ablist.begin(),ablist.end());

	for(int i=0; i<min(k,x*y); i++ ){
		for(int j=0; j<z; j++){
			abclist.push_back(ablist.at(i)+clist.at(j));
		}
	}

	sort(abclist.begin(),abclist.end());
	reverse(abclist.begin(),abclist.end());
	
	for(int i=0; i<k; i++) cout<<abclist.at(i)<<endl;


}	





Measured memory_bytes: 43368
#include <cstdio>

int max(int x, int y, int z){
    if(x>=y && x>=z) return x;
    else if(y>=x && y>=z) return y;
    else return z;
}

int main(){
    int A, B, C;
    scanf("%d%d%d", &A, &B, &C);
    printf("%d\n", 9*max(A,B,C)+A+B+C);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
  
int main()
{
	int a,b,k;
 
	scanf("%d%d%d",&a,&b,&k);
 
	int min;
	int ar[1000];
	int t=0;
  
	if(a<=b)
      	min=a;
	else
		min=b;
 
	for(int i=1;i<=min;i++){
		if(a%i==0&&b%i==0){
			ar[t]=i;
			t++;
		}
	}
  
	printf("%d",ar[t-k]);
 
	return 0;
}

Measured memory_bytes: 128
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n;
  vector<int> v;
  cin >> n;
  cout << n << ": ";
  for(int i=2; i*i<=n; i++) {
    while(n%i==0) {
      v.push_back(i);
      n/=i;
    }
  }
  if(n>1) {
    v.push_back(n);
  }
  for(int i=0; i<v.size()-1; i++) {
    cout << v[i] << " ";
  }
  cout << v[v.size()-1] << endl;
}


Measured memory_bytes: 3220
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	s := getString()
	ans := 0
	cnt := 0
	for i := 0; i < len(s)-1; i++ {
		// out(i, cnt, ans)
		if s[i] == 'A' {
			cnt++
		} else if s[i] == 'B' && s[i+1] == 'C' {
			ans += cnt
			i++
		} else {
			cnt = 0
		}
	}
	out(ans)
}


Measured memory_bytes: 1280
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll ans = 0;
    rep(i, 0, s.size()) if (s[i] == '0') ans++;
    ans = 2 * min(ans, ll(s.size()) - ans);
    cout << ans << endl;
}


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

bool pr(ll x){
    if(x == 2 || x == 3) return false;
    bool ok = false;
    for(ll i = 2; i <= sqrt(x);++i){
        if(x%i == 0) ok = true;
    }
    return ok;
}

int main(){
    int X; cin >> X;
    while(pr(X)){
        X++;
    }
    cout << X << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int MOD = 998244353;


//---------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& os, const ModInt<MOD>& mi) { return os << mi.get(); }
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
template<typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac;
    Comb() { fac.resize(FAC_MAX + 1, 1); ifac.resize(FAC_MAX + 1, 1);
        for (int i = 1; i <= FAC_MAX; i++) fac[i] = fac[i - 1] * i;
        for (int i = 1; i <= FAC_MAX; i++) ifac[i] = T(1) / fac[i]; }
    T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; }
    T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; }
    T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0;
        return aCb(n + k - 1, k); }
    T fact(int n) { if (n < 0) return T(0); return fac[n]; }
};
typedef ModInt<MOD> mint;
//---------------------------------------------------------------


int main() {
    Comb<mint, 300000> com;
    int N;
    ll A, B, K;
    cin >> N >> A >> B >> K;

    mint ans = 0;
    for (ll a = 0; a <= K / A; a++) {
        // A*a + B*b = K
        if ((K - A * a) % B) continue;
        ll b = (K - A * a) / B;
        if (0 <= b <= N) {
            ans += com.aCb(N, a) * com.aCb(N, b);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
int main(void){
  ll a,b;
  cin>>a>>b;

  cout<<max((ll)0,a-2*b);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
struct Node {
  int parent;
  int left;
  int right;
};
int n;
void Preorder(int);
void Inorder(int);
void Postorder(int);
struct Node tree[30];
int dipth[30],height[30];
int main(){
  int i,id,left,right,root;
  scanf("%d",&n);
  for(i=0;i<n;i++)tree[i].parent=tree[i].left=tree[i].right=-1;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&id,&left,&right);
    tree[id].left=left;
    tree[id].right=right;
    if(left!=-1)tree[left].parent=id;
    if(right!=-1)tree[right].parent=id;
  }
  for(i=0;i<n;i++){
    if(tree[i].parent==-1)root=i;
  }
  printf("Preorder\n");
  Preorder(root);
  printf("\nInorder\n");
  Inorder(root);
  printf("\nPostorder\n");
  Postorder(root);
  printf("\n");
  return 0;
}
void Preorder(int u){
  if(u==-1)return;
  printf(" %d",u);
  Preorder(tree[u].left);
  Preorder(tree[u].right);
}
void Inorder(int u){
  if(u==-1)return;
  Inorder(tree[u].left);
  printf(" %d",u);
  Inorder(tree[u].right);
}
void Postorder(int u){
  if(u==-1)return;
  Postorder(tree[u].left);
  Postorder(tree[u].right);
  printf(" %d",u);
}




Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
 
int main(){
  ll X, i, ans = 0;
  cin >> X;
  
  ans += X/500*1000;
  X = X%500;
  ans += X/5*5;
 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var a = int.Parse(Console.ReadLine());
            Console.WriteLine(a + a * a + a * a * a);
        }
    }
}


Measured memory_bytes: 27364
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
using namespace std;

using ll = long long;
const int MAXN = 3005;
const int MOD = 1e9+7;
ll dp[MAXN][MAXN][2];

void add(ll& a, ll b) {
    a += b; if (a >= MOD) a -= MOD;
}

int main() {
    int n, m;
    cin >> n >> m;
    for (int j = 0; j <= n; ++j) dp[0][j][j==0] = 1;

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k < 2; ++k) {
                for (int j1 = 0; j1 < 2; ++j1) for (int j2 = 0; j2 < 2; ++j2) {
                    if (j == 0 && j1 == 1) continue;
                    if (j == n && j1 == 0) continue;
                    int nj = j-j1+1-j2;
                    int nk = (k || j == j1);
                    add(dp[i+1][nj][nk], dp[i][j][k]);
                }
            }
        }
    }
    ll res = 0;
    for (int j = 0; j <= n; ++j) add(res, dp[m][j][1]);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 141184
# include <bits/stdc++.h>
# define rr
# define int long long
const int N=200010,INF=0x3f3f3f3f;
std::map <int,int> ansa;
std::map <int,int> ansb;
int a[N];
int n;
inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-')f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}
signed main(void){
	n=read();
	for(rr int i=1;i<=n;++i){
		a[i]=read();
		++ansa[i+a[i]],++ansb[i-a[i]];
	}
	long long ans=0;
	for(rr int i=1;i<=n;++i){
		ans+=ansa[i+a[i]]*ansb[i+a[i]];
		ansa[i+a[i]]=0,ansb[i+a[i]]=0;
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 39500
n,k = gets.split.map(&:to_i)
place = gets.split.index{|item| item == "1"}
count = 1
n -= k
while n>0
  n -= k-1
  count += 1
end
if place < k || place >= n-k || (place+1)%k == k-1 || (n-place+1)%k ==k-1
  puts count
else
  puts count+1
end


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

using namespace std;

int main()
{
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	int dpa[n],dpb[n],dpc[n];
	dpa[n-1]=a[n-1];
	dpb[n-1]=b[n-1];
	dpc[n-1]=c[n-1];
	for(int i=n-2;i>=0;i--)
	{
		dpa[i] = a[i]+max(dpb[i+1],dpc[i+1]);
		dpb[i] = b[i]+max(dpa[i+1],dpc[i+1]);
		dpc[i] = c[i]+max(dpb[i+1],dpa[i+1]);
	}
	// cout<<dpa[1]<<" "<<dpb[1]<<" "<<dpc[1]<<endl;
	// cout<<dpa[0]<<" "<<dpb[0]<<" "<<dpc[0]<<endl;
	cout<<max(dpa[0],max(dpb[0],dpc[0]))<<endl;
	return 0;
}


Measured memory_bytes: 2560
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define    endl        '\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x)     for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)    (a>b?a:b)
#define min(a,b)    (a<b?a:b)

/*    For Debugging    */
#define DEBUG         cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

void solve()
{
    ll n,m;
    cin>>n>>m;
    ll num=1,num1=m+2;
    for(ll i=m;i>=1;i-=2){
        cout<<num<<" "<<num+i<<endl;
        num++;
    }
    for(ll i=m-1;i>=1;i-=2){
        cout<<num1<<" "<<num1+i<<endl;
        num1++;
    }
    return;
}
int main()
{
    FAST
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    TIME
    return 0;
}

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

int main(){

    // input
    ll n;
    cin >> n;
    vector<pair<ll,ll>> b(n);
    rep(i, 0, n){
        cin >> b[i].first;
        b[i].second = i+1;
    }
    vector<ll> res(n);
    rep(i, 0, n) {
        ll cur = n - i;
        bool f = true;
        for(ll j = n-1; j >= 0; j--) {
            if(b[j].first == cur) {
                b[j].second = -1;
                for(ll k = j+1; k < n; k++) {
                    b[k].second--;
                }
                res[i] = b[j].first;
                f = false;
                break;
            }
            if(b[j].second >= 0) cur--; 
        }
        if(f) {
            cout << -1 << endl;
            return 0;
        }
    }
    for(ll i = n-1; i >= 0; i--) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
using namespace std;
const int maxn=100005;
int n;
int a[maxn];
int maxv;
long long minv=1000000005;
int ans;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		maxv=max(maxv,a[i]);
	}
	
	int maxx=maxv/2;
	for(int i=1;i<=n;i++){
		if(fabs(maxx-a[i])<minv && a[i]!=maxv){
			minv=fabs(maxx-a[i]);
			ans=a[i];
		}
	}
	
	cout<<maxv<<' '<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

int main (void) {

  int P, Q, R;
  std::cin >> P >> Q >> R;

  int ans = P + Q + R - std::max( { P, Q, R} );
  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(1000000)

class Node():
    def __init__(self, p, l, r):
        self.p = p
        self.l = l
        self.r = r


def rec(u, p):
    D[u] = p
    if T[u].r != -1:
        rec(T[u].r, p)
    if T[u].l != -1:
        rec(T[u].l, p + 1)


N = int(input())
T = [Node(-1, -1, -1) for _ in range(N)]
D = [-1] * N
for i in range(N):
    i, k, *cs = map(int, input().split())
    for j, c in enumerate(cs):
        if j == 0:
            T[i].l = c
        else:
            T[l].r = c
        l = c
        T[c].p = i
for i, t in enumerate(T):
    if t.p == -1:
        r = i
rec(r, 0)
for i, t in enumerate(T):
    cs = []
    c = t.l
    while c != -1:
        cs.append(c)
        c = T[c].r
    if t.p == -1:
        print('node {}: parent = {}, depth = {}, root, {}'
              .format(i, t.p, D[i], cs))
    elif t.l == -1:
        print('node {}: parent = {}, depth = {}, leaf, {}'
              .format(i, t.p, D[i], cs))
    else:
        print('node {}: parent = {}, depth = {}, internal node, {}'
              .format(i, t.p, D[i], cs))



Measured memory_bytes: 125692
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int flag=0;
		while(n--)
		{
			int t,x,y;
			scanf("%d%d%d",&t,&x,&y);
			if((t-(x+y))%2!=0||t<(x+y))
			{
				flag=1;
			}
		}
		if(flag)
		{
			printf("No\n");
		}else
		{
			printf("Yes\n");
		}
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    string S; cin >> S;

    int s1 = stoi(S.substr(0, 2));
    int s2 = stoi(S.substr(2));
    bool m1, m2;

    if(0 < s1 && s1 < 13) m1 = true;
    else m1 = false;
    if(0 < s2 && s2 < 13) m2 = true;
    else m2 = false;

    if(m1 || m2) {
        if(m1 && m2) cout << "AMBIGUOUS" << endl;
        else if (m1) cout << "MMYY" << endl;
        else cout << "YYMM" << endl;
    } else cout << "NA" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = 1e9+7;
const ll INF = (ll)1e18+1;

map<int, int> mp;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("A.txt", "r", stdin);
    #endif
    int n, a, ans=0;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> a;
        mp[a]++;
    }
    for(auto p : mp)
    {
        if(p.second%2==1) ans++;
    }
    cout << ans;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	long double A,B; cin>>A>>B;
	cout<<ll(A*B)<<"\n";
	return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    map<string,ll> mp;

    mp["AC"]=0;mp["WA"]=0;mp["TLE"]=0;mp["RE"]=0;

    ll n;cin>>n;

    while(n--)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}


Measured memory_bytes: 3636
(N,W),*WV=$<.map{|s|s.split.map &:to_i}
W0=WV[0][0]
V=[],[],[],[]
WV.map{|w,v|V[w-W0]<<v}
S=V.map{|t|
  t.sort!.reverse!
  s=[0]
  t.map{|e|s<<s[-1]+e}
  s
}
res=[]
(0..[V[0].size,W/W0].min).map{|a|
  (0..[V[1].size,(W-W0*a)/(W0+1)].min).map{|b|
    (0..[V[2].size,(W-W0*a-(W0+1)*b)/(W0+2)].min).map{|c|
      (0..[V[3].size,(W-W0*a-(W0+1)*b-(W0+2)*c)/(W0+3)].min).map{|d|
        res<<S[0][a]+S[1][b]+S[2][c]+S[3][d]
      }
    }
  }
}

p res.max


Measured memory_bytes: 6396