akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,c,k,a[N],ans,sum,ji;
int main()
{
	cin>>n>>c>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	ji=a[0];
	sum=1;
	for(int i=1;i<n;i++)
	{
		if(k<a[i]-ji||sum==c)
			ans++,sum=1,ji=a[i];
		else
			sum++;
	}
	if(sum)ans++;
	cout<<ans<<endl;
}
/*
Ì°ÐÄË¼Â·£º½«Í¬Ò»¶ÎÊ±¼äÄÚµÄÈËÒ»µ©×øÂúÁËÒ»Á¾³µ»òÕßÊ±¼ä³¬¹ýÁË£¬ÄÇÃ´¾ÍÔÙÐÂ¿ªÒ»Á¾³µ£¬
ÖØÐÂ¼ÇÂ¼Ò»ÏÂ×îÐÂµÄÊ±¼ä£¬È¥ÈÝÄÉ¸ü¶àµÄÈË¡£ 
*/


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int k;

lint solve(vector<lint> v){
    vector<lint> w;
    int d;
    repr(j, 42){
        w.resize(0);
        d = j;
        rep(i, v.size()){
            if(v[i] >> j & 1){
                w.push_back(v[i]);
            }
        }
        if(w.size() >= k){
            break;
        }
    }
    if(w.size() < k){
        return 0;
    }
    lint res = 1LL << d;
    rep(i, w.size()){
        w[i] %= res;
    }
    res += solve(w);
    return res;
}

int main(){
    int n;
    cin >> n >> k;
    vector<lint> a(n);
    rep(i, n){
        cin >> a[i];
    }
    vector<lint> sum(n + 1);
    sum[0] = 0;
    REP(i, 1, n + 1){
        sum[i] = sum[i - 1] + a[i - 1];
    }
    vector<lint> v;
    rep(i, n){
        REP(j, i + 1, n + 1){
            v.push_back(sum[j] - sum[i]);
        }
    }
    lint ans = solve(v);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10736
/**
 *    Creator :  bizarre
 *    Date : 5/2020
 *    Problem Number : 536
**/
#include <bits/stdc++.h>
using namespace std;
#define bizarre  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define ll long long
#define ld long double
/*
vector<int> prime_Numbers;
bool primes[1000005];
void prime(int n)
{
    primes[1]=primes[0]=0;
    for(int i=2; i<=n; i++)
        primes[i]=true;
    for(int i=2; i<=n; i++)
    {
        if(primes[i]==true)
        {
            prime_Numbers.push_back(i);
            for(int j=i+i; j<=n; j+=i)
                primes[j]=false;
        }
    }
}
void move1step(long long& a, long long& b, long long q)
{
    long long c= a-q*b;
    a=b;
    b=c;
}
long long egcd(long long r0,long long r1,long long& x0,long long& y0)
{
    long long x1=0,y1=1;
    x0=1;
    y0=0;
    while(r1)
    {
        long long q=r0/r1;
        move1step(r0,r1,q);
        move1step(x0,x1,q);
        move1step(y0,y1,q);
    }
    return r0;
}
bool  solve (long long a, long long b, long long c,long long&x, long long& y)
{
    long long g=egcd(a,b,x,y);
    int m=c/g;
    x*=m;
    y*=m;
    return c%g==0;
}
int gcd(int a, int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
void PrimeFactorization(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        int c=0;
        if(n%i==0)
        {
            while(n%i==0)
            {
                n/=i;
            }

        }
    }

}
long long ncrtane(long long n, long long r)
{
    long long ans=1,cntr=1;
    for(int i=n; i>n-r; i--)
    {
        ans*=i;
        ans/=cntr;
        cntr++;
    }
    return ans;
}
const int N = 1e6 + 5, inf = 2e9, mod = 1e9 + 7;
long long fp(long long base, long long exp)
{
    if (exp == 0)
        return 1;
    long long ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}
long long fact[N], inv[N];
void pre(long long n)
{
    fact[0] = 1;
    inv[0] = 1;
    for (long long i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}
int ncr(long long n, long long r)
{
    return (((fact[n] * inv[n - r]) % mod) * inv[r]) % mod;
}

int npr(long long n, long long r)
{
    return (fact[n] * inv[n - r]) % mod;
}
*/
ll n,m,k,ans=1e9;
vector<int>grb(15);
void solve(ll cost,vector<pair<int,vector<int>>>&v, vector<int>grb,ll n)
{
    if(n == 0)
    {
        for(int i=0;i<m;i++)
        {
            if(grb[i]<k)return;
        }
        ans=min(ans,cost);
        return;
    }
    solve(cost,v,grb,n-1);
    for(int i=0;i<m;i++)grb[i]+=v[n-1].second[i];
    solve(cost+v[n-1].first,v,grb,n-1);
}
int main()
{
    bizarre
vector<pair<int,vector<int>>>v(n);
  cin >>n >>m>>k;
  for(int i=0;i<n;i++)
  {
      int x; cin>>x;
      vector<int>temp(m);
      for(int j=0;j<m;j++)
      {
          int x; cin >> x;
          temp[j]=x;
      }
     v.push_back({x,temp});
  }
  for(int i=0;i<m;i++)grb[i]=0;
  solve(0,v,grb,n);
  if(ans==1e9)cout << -1;
  else cout << ans ;
    return 0;
}


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

int main() {
	int w, a, b;
	cin >> w >> a >> b;
	if (a + w < b)
		cout << b - a - w << endl;
	else if (b + w < a)
		cout << a - b - w << endl;
	else
		cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
    public static int Main()
    {
        string S = Console.ReadLine();
        long sum = 0;

        for (int bits = 0; bits < 1 << (S.Length - 1); ++bits)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < S.Length; ++i)
            {
                sb.Append(S[i]);
                if ((bits & (1 << i)) != 0)
                {
                    sb.Append('+');
                }
            }
            string[] buf = sb.ToString().Split('+');
            foreach (string str in buf)
            {
                sum += long.Parse(str);
            }
        }
        Console.WriteLine(sum);
        return 0;
    }
}


Measured memory_bytes: 2904
// chal ab jayda mat udd, agle me niche jaega...

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

#define rep(i,st,en) for(__typeof(en) i=(st)-(st>en); i!=(en)-(st>en); i+=1-2*(st>en))
#define ff first
#define ss second
#define endl '\n'
#define all(v) v.begin(), v.end()
#define COVID_19 ios_base::sync_with_stdio(0);  cin.tie(NULL);  cout.tie(NULL);
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{cout << *it << " = " << a << endl;    err(++it, args...);}
typedef long long ll;
const ll mod = 1e9+7;

int main() {
    COVID_19
    int x;  cin>>x;
    ll ans = 0;
    ans += 1000 * (x / 500);
    x %= 500;
    ans += 5 * (x / 5);
    cout<<ans<<endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int k, x; cin >> k >> x;
	for (int i = x - k + 1; i < x + k; ++i) {
		cout << i << " ";
	}
	cout << endl;
	return 0;
}


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

int main(){
    int n,t;
    cin >> n >> t;
    ve<P> ab;
    rep(i,n){
        ll a,b;
        cin >> a >>b;
        ab.push_back(P(a,b));
    }

    ve<ve<ll>> dp1(n+1,ve<ll>(t+1)), dp2(n+1,ve<ll>(t+1));
    rep(i,n){
        ll a = ab[i].first, b = ab[i].second;
        rep(j,min(a,(ll)t)){
            dp1[i+1][j] = dp1[i][j];
        }
        rep(j,t-a+1){
            dp1[i+1][j+a] = max(dp1[i][j+a], dp1[i][j]+b);
        }
        ll a2 = ab[n-1-i].first, b2 = ab[n-1-i].second;
        rep(j,min(a2, (ll)t)){
            dp2[n-i-1][j] = dp2[n-i][j];
        }
        rep(j,t-a2+1){
            dp2[n-i-1][j+a2] = max(dp2[n-i][j+a2],dp2[n-i][j]+b2);
        }
    }

    ll ans=0;
    rep(i,n){
        ll memo = ab[i].second;
        ll memo1=0;
        rep(j,t){
            memo1 = max(memo1, dp1[i][j] + dp2[i+1][t-1-j]);
        }
        ans = max(ans, memo+memo1);
    }

    cout << ans << endl;
    return 0;
}


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

int main(){
int w = 0;
cin >> w ;
int n = 0;
cin >> n;
int i = 1;
int a[w];
for(i = 0;i < w;i++){
a[i] = i + 1;
}
for(i = 1;i <= n;i++){
int aa = 0;int bb = 0;
char split;
cin >> aa >> split >> bb ;
int c = 0;
c = a[aa - 1];
a[aa - 1] = a[bb - 1];
a[bb - 1] = c;
}
for(i = 0;i < w; i++){
cout << a[i] << endl;
}
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 200005;
const int INF = (LL)1e9 + 5;

struct Query {
	char c;
	int dir;
};

int N, Q;
string s;
Query qs[MAXN];

bool death(int pos, int dir) {
	int i = 0;
	while (i < Q && 0 <= pos && pos < N) {
		if (qs[i].c == s[pos]) {
			pos += qs[i].dir;
		}
		i++;
	}
	
	return pos == dir;
}

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

	cin >> N >> Q >> s;
	for (int i = 0; i < Q; i++) {
		char t, dir;
		cin >> t >> dir;
		qs[i] = {t, dir == 'L' ? -1 : 1};
	}
	
	int l = 0, r = N - 1, ans1 = -1;
	while (l <= r) {
		int m = (l + r) >> 1;
		if (death(m, -1)) {
			ans1 = m;
			l = m + 1;
		}
		else {
			r = m - 1;
		}
	}
	
	int ans2 = N;
	l = 0, r = N - 1;
	while (l <= r) {
		int m = (l + r) >> 1;
		if (death(m, N)) {
			ans2 = m;
			r = m - 1;
		}
		else {
			l = m + 1;
		}
	}

	int ans = N - (ans1 + 1) - (N - ans2);
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 2196
import sys
sys.setrecursionlimit(10 ** 9)

mod = 10**9 + 7
H, W = list(map(int, input().split()))
A = []
for _ in range(H):
  A.append(list(input()))

dp = [[-1]*W+[0] for _ in range(H)] + [[0]*(W+1)]# dp[i][j] (i,j)からゴールまでの数をmodで割ったもの
dp[H-1][W-1] = 1

def rec(i,j):
  if dp[i][j] != -1:
    return dp[i][j]
  else:
    if A[i][j] == '#':
      return 0
    else:
      dp[i][j] = (rec(i+1, j) + rec(i, j+1)) % mod
      return dp[i][j]

print(rec(0,0))

Measured memory_bytes: 52588
def solve():
    if not (c11 - c21 == c12 - c22 == c13 - c23):
        return False
    if not (c11 - c31 == c12 - c32 == c13 - c33):
        return False
    if not (c11 - c12 == c21 - c22 == c31 - c32):
        return False
    if not (c11 - c13 == c21 - c23 == c31 - c33):
        return False
    return True
 
 
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())
 
print('Yes' if solve() else 'No')


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

typedef pair<int,char> P;

int main() {
    int N,K,i,m=0,t,l;
    string S;
    vector<int> h;
    cin >> N >> K >> S;
    char p=S.at(0);

    h.push_back(0);
    for(i=1; i<N; i++) {
        if(p != S.at(i))
            h.push_back(i);
        p = S.at(i);
    }
    h.push_back(N);

    // for(auto x : h)
    //     cout << x << " ";
    // cout << endl;

    l = h.size()-1;
    for(i=0; i<h.size()-1; i++) {
        if(S.at(h.at(i)) == '0')
            t = h.at(min(i+K*2, l));
        else
            t = h.at(min(i+K*2+1, l));
        m = max(m, t-h.at(i));
    }

    cout << m << endl;
}

Measured memory_bytes: 1020
#include <stdio.h>

#define MAX 500

int main(void){
  int i,j,x,y,num;

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

  int arr[MAX][MAX]={};
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      x=i; y=j; num=1;
      while(1){
        if(x%2!=y%2){
          arr[i][j]=num;
          break;
        }else{
          x/=2; y/=2;
          num++;
        }
      }
    }
  }

  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      printf("%d ",arr[i][j]);
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>E[101000];
int n, v[101000], Col[101000], chk, C[3], m;
void DFS(int a, int b){
    int i;
    Col[a] = b;
    C[b]++;
    for(i=0;i<E[a].size();i++){
        if(!Col[E[a][i]])DFS(E[a][i], 3-b);
    }
    for(i=0;i<E[a].size();i++){
        if(Col[E[a][i]]+b!=3)chk = 1;
    }
}
int main(){
    int i, a, b;
    long long Res = 0;
    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++){
        scanf("%d%d",&a,&b);
        E[a].push_back(b);
        E[b].push_back(a);
    }
    for(i=1;i<=n;i++){
        if(!Col[i]){
            chk = 0;
            C[1]=C[2]=0;
            DFS(i,1);
            if(!chk){
                Res += 1ll*C[1]*C[2];
            }
            else Res += 1ll*(C[1]+C[2])*(C[1]+C[2]-1)/2;
        }
    }
    printf("%lld\n",Res-m);
}

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

int main(){
    int N, M; cin >> N >> M;
    string S; cin >> S;
    vector<int> ans;
    bool abailable = true;
    reverse(S.begin(), S.end());
    vector<int> dp(N+1);
    dp[0] = -1;
    int now = 1;
    rep(i, N){
        if(S[i] == '1') dp[i+1] = dp[i];
        else dp[i+1] = i+1;
        if(i - dp[i+1] + 1 >= M) now = -1;
    }
    if(now < 0){
        cout << now << endl;
        return 0;
    }

    while(now <= N && now >= 0){
        if(now+M > N){
            ans.push_back(N+1 - now);
            break;
        }
        ans.push_back(dp[now+M] - now);
        now = dp[now+M];
    }
    reverse(ans.begin(), ans.end());
    rep(i, ans.size()){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4400
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

int gcd(int a, int b) {
	if (a > b) {
		swap(a, b);
	}

	if (a == 0) {
		return b;
	}

	return gcd(b % a, a);
}

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

	int g = gcd(360, x);
	int k = 360 / g;
	cout << k << endl;
}

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

int main()
{
  int a;
  cin>>a;
  int b[114514]={0};
  int c[114514]={0};
  int d[114514]={0};
  int e=0;
  for(int i=0;i<a;i++){
    cin>>b[i];
  }
  for(int i=0;i<a;i++){
    cin>>c[i];
  }
  for(int i=0;i<a-1;i++){
    cin>>d[i];
  }
  for(int i=0;i<a-1;i++){
    if(b[i+1]-b[i]==1){
      e = e + d[ b[i]-1 ];
    }
  }
  for(int i=0;i<a;i++){
    e = e+ c[i];
  }
  cout<<e<<endl;
}
  
  

Measured memory_bytes: 1536
N,T,S = map(int, input().split())
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)

dp = [[0]*(T+1) for _ in range(N+1)]
for i in range(N):
  for j in range(1, T+1):
    if 0 <= j-B[i] and not(j-B[i] < S < j):
      dp[i+1][j] = max(dp[i][j], dp[i+1][j-1], dp[i][j-B[i]]+A[i])
    else:
      dp[i+1][j] = max(dp[i][j], dp[i+1][j-1])
 
print(dp[N][T])


Measured memory_bytes: 171956
N = int(input())
tuples = []
for i in range(N):
    x, u = input().split()
    tuples.append((float(x), u))
tot = 0
for tup in tuples:
    if tup[1] == 'JPY':
        tot = tot + tup[0]
    else:
        tot = tot + 380000*tup[0]
print(tot)


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>

int main(void){
    int n, ac_num=0, wa_num=0, tle_num=0, re_num=0;
    char s1[]="AC", s2[]="WA", s3[]="TLE", s4[]="RE";

    scanf("%d", &n);

    char seq[n][4];

    for(int i=0; i<n; i++){
        scanf("%s", seq[i]);

        if(strcmp(seq[i],s1) == 0){
            ac_num ++;
        }
        else if(strcmp(seq[i],s2) == 0){
            wa_num ++;
        }
        else if(strcmp(seq[i],s3) == 0){
            tle_num ++;
        }
        else if(strcmp(seq[i],s4) == 0){
            re_num ++;
        }
    }

    printf("AC x %d\n", ac_num);
    printf("WA x %d\n", wa_num);
    printf("TLE x %d\n", tle_num);
    printf("RE x %d\n", re_num);

    return 0;
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n=5;
  int d[n],k;
  REP(i,5) cin >> d[i];
  cin >> k;

  REP(i,n) {
    REP(j,n) {
      if (i == j) continue;
      if (abs(d[i]-d[j]) > k) { COUT(":("); return 0; }
    }
  }
  COUT("Yay!");
  return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i]+l[j]>l[k] and l[i]<l[j]<l[k]:
                ans += 1
print(ans)

Measured memory_bytes: 9040
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h,j,i;
	while(1){
		scanf("%d %d",&a,&s);
		if(a==0&&s==0)
			break;
		for(i=0;i<a;i++){
			for(j=0;j<s;j++){
				if((i+j)%2==1)
					printf(".");
				else
					printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2608
#include<stdio.h>
#include<stdlib.h>
#include <string.h>

#define N 100001
#define MAX 10000001
#define CMAX 500000

struct Roll{
  int fi;
  int b;
  int se;
};

struct Roll C[CMAX];

int n, result[N];

void hantei(int );

int main()
{
  int i, j;
  int k, u, count=0;
  int x, y, z;

  scanf("%d",&n);
  if(n<1 || n>N) exit(1);

  x = 1;
  y = 2;
  
  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);
    
    for(j=0; j<k; j++){
      C[count].b=u;
      z++;
      scanf("%d%d", &C[count].fi, &C[count].se);
      count++;
      x = y+z;
    }
  }
  
  hantei(count);
  x--;
  for(i=0; i<n; i++) printf("%d %d\n", i, result[i]);
  
  return 0;
}

void hantei(int x){
  int i;
  int man=1;
  int k;

  for(i=0; i<n; i++) result[i]=MAX;
  result[0]=0;
  k++;

  while(man != 0){
    man=0;
    for(i=0; i<x; i++){
      if(C[i].se + result[C[i].b] < result[C[i].fi]){
	result[C[i].fi] = C[i].se + result[C[i].b];
	man = 1;
      }
      k += 2;
    }
  }

  return ;
}



Measured memory_bytes: 7632
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, k; cin >> n >> k;
  vector<int> a(n); REP(i, n) cin >> a[i], --a[i];
  vector<vector<int> > rev(n);
  FOR(i, 1, n) rev[a[i]].emplace_back(i);
  int ans = a[0] != 0;
  a[0] = 0;
  if (k >= n - 1) {
    cout << ans << '\n';
    return 0;
  }
  if (k == 1) {
    FOR(i, 1, n) ans += a[i] != 0;
    cout << ans << '\n';
    return 0;
  }
  vector<vector<int> > dist(n);
  dist[0].emplace_back(0);
  vector<int> que{0};
  int now = 0;
  while (!que.empty()) {
    ++now;
    vector<int> nx;
    for (int src : que) {
      for (int dst : rev[src]) {
        nx.emplace_back(dst);
        dist[now].emplace_back(dst);
      }
    }
    que.swap(nx);
  }
  while (dist.back().empty()) dist.pop_back();
  map<int, int> mp;
  for (int e : dist.back()) mp[e] = 1;
  for (int i = int(dist.size()) - 2; i > 0; --i) {
    map<int, int> nx;
    for (auto pr : mp) {
      // cout << pr.first << ' ' << pr.second << '\n';
      if (pr.second == k) {
        ++ans;
      } else {
        chmax(nx[a[pr.first]], pr.second + 1);
      }
    }
    for (int e : dist[i]) chmax(nx[e], 1);
    // cout << '\n';
    mp.swap(nx);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 12236
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
typedef long long ll;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    int t,x;
    cin >> t >> x;
    cout << (double)t/(double)x << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
const int N = 1e5+ 2, mod = 1e9 + 7;

void solve() {
	int n;
	cin >> n;
	ll ans = 0;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i < n; i++) {
		if (a[i] < a[i-1]) {
			ans += a[i-1]-a[i];
			a[i] = a[i-1];
		}
	}
	cout << ans << '\n';
}

int main() {
	// reopen("input.txt", "r", stdin); 
 //    freopen("output.txt", "w", stdout); 
	int tt = 1;
	// cin >> tt;
	for (int tc = 1; tc <= tt; tc++) {
		// cout << "Case #:" << tc << " ";
		solve();
	}
}

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

//#define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

int dpt[2][10000][2];
signed main() {
	int n;
	cin >> n;
	{
		V v(n - 1);
		input(v);
		rep(k, 2)rep(i, n)rep(j, 2)dpt[k][i][j] = 1 << 29;
		dpt[0][1][0] = 0;
		int now = 1;
		int ans = 1 << 29;
		rep(i, n - 1) {
			auto next = dpt[now];
			auto prev = dpt[now ^ 1];
			rep(j, 1, n / 2 + 1) {
				if (j + 1 <= n / 2) minup(next[j + 1][0], prev[j][0]);
				minup(next[j][1], prev[j][1]);
				minup(next[j][1], prev[j][0] + v[i]);
				minup(next[j + 1][0], prev[j][1] + v[i]);
			}
			rep(j, n / 2 + 1) prev[j][0] = prev[j][1] = 1 << 29;
			now ^= 1;
		}
		cout << min(dpt[now ^ 1][n / 2][0], dpt[now ^ 1][n / 2][1]) << endl;
	}
}

Measured memory_bytes: 3232
H=int(input())
W=int(input())
N=int(input())
c=0
ans=0
if H>=W:
    while c>=0:
        c+=H
        ans+=1
        if c>=N:
            break
else:
    while c>=0:
        c+=W
        ans+=1
        if c>=N:
            break
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned int
#define ull unsigned long long
#define inf 1010000000
#define infll 1010000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
#define cbn(x,y) ((ll)fac[x]*inv[y]%mod*inv[(x)-(y)]%mod)
#define N 5009
#define mod 1000000007
using namespace std;

int read(); ll readll();

int n,A,B,f[N],g[N],h[N];
int main(){
	scanf("%d%d%d",&n,&A,&B);
	if (B>n){ puts("1"); return 0; }
	if (A>n){ puts("2"); return 0; }
	if (A>B) swap(A,B);
	int i,j,ans;
	for (i=ans=1; i<=n; i++) ans=(ans<<1)%mod;
	f[0]=g[0]=1;
	for (i=1; i<B; i++)
		for (j=h[i]=1,f[i]=max(0,i-A); i-j>A; j++){
			ad(h[i],(ll)h[j]*(i-j-A));
			ad(f[i],(ll)f[j]*(i-j-A));
		}
	for (i=1; i<=n; i++)
		for (j=0; j<i; j++){
			ad(f[i],(ll)g[j]*h[i-j]);
			if (i-j<A) ad(g[i],f[j]);	
		}
	for (i=h[0]=1; i<B; i++)
		for (j=h[i]=0; i-j>A; j++)
			ad(h[i],(ll)h[j]*(i-j-A));
	ad(ans,mod-f[n]);
	for (i=0; i<B; i++) ad(ans,mod-(ll)g[n-i]*h[i]%mod);
	printf("%d\n",ans);
	return 0;
}

int read(){
	int x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
ll readll(){
	ll x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int dif;
    dif = b - a;
    int sum = 0;
    for (int i = 1; i <= dif; i++){
        sum += i;
    }
    cout << sum - b << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static T[] Recursion<T>(int n, T v, Func<int, T, T> f) { var a = new T[n]; a[0] = v; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], X = I[1];
		var S = G;
		Array.Sort(S, (p, q) => q.CompareTo(p));
		var dp = new Dictionary<int, long>[2];
		dp[0] = new Dictionary<int, long> { [X] = 1 };
		for (var i = 0; i < N; i++)
		{
			var p = Inverse(N - i);
			var q = (1 - p + MOD) % MOD;
			var i2 = i % 2;
			var j2 = (i + 1) % 2;
			dp[j2] = new Dictionary<int, long>();
			foreach (var t in dp[i2])
			{
				var x = t.Key;
				var y = x % S[i];
				if (!dp[j2].ContainsKey(y)) dp[j2][y] = 0;
				if (!dp[j2].ContainsKey(x)) dp[j2][x] = 0;
				dp[j2][y] = (dp[j2][y] + t.Value * p % MOD) % MOD;
				dp[j2][x] = (dp[j2][x] + t.Value * q % MOD) % MOD;
			}
		}
		var s = dp[N % 2].Sum(t => t.Key * t.Value % MOD) % MOD;
		for (var i = 1; i <= N; i++) s = s * i % MOD;
		WriteLine(s);
	}
	public static long Inverse(long a, long mod = MOD)
	{
		if (a < 0) { a %= mod; if (a < 0) a += mod; }
		var t = SolveLinear(a, mod);
		return t.Item1 > 0 ? t.Item1 : t.Item1 + mod;
	}
	public static Tuple<long, long> SolveLinear(long n, long m)
	{
		if (n < 0) { var p = SolveLinear(-n, m); return p == null ? p : new Tuple<long, long>(-p.Item1, p.Item2); }
		if (m < 0) { var p = SolveLinear(n, -m); return p == null ? p : new Tuple<long, long>(p.Item1, -p.Item2); }
		if (n < m) { var p = SolveLinear(m, n); return p == null ? p : new Tuple<long, long>(p.Item2, p.Item1); }
		long a = 1, b = 0, c = 0, d = 1;
		while (m > 0)
		{
			var r = n % m;
			var q = n / m;
			n = m;
			m = r;
			var tmp = a;
			a = -a * q + b;
			b = tmp;
			tmp = c;
			c = -c * q + d;
			d = tmp;
		}
		return n != 1 ? null : new Tuple<long, long>(d, b);
	}
}

Measured memory_bytes: 32608
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

int main()
{
    int H, W;
    char A;
    int count = 0;
    
    cin >> H >> W;
    
    for (int i = 0; i < H * W; i++)
    {
        cin >> A;
        if (A == '#')
        {
            count++;
        }
    }
    
    printf("%s\n",
        count == (H + W - 1) ? "Possible" : "Impossible");
    
    return 0;
}


Measured memory_bytes: 384
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
u = False
d = False
res = 1
i = 0
while i < n-1:
    if u and a[i+1] < a[i]:
        res += 1
        u = False
        i += 1
    elif d and a[i+1] > a[i]:
        res += 1
        d = False
        i += 1
    if i < n-1:
        if a[i+1] > a[i]:
            u = True
        elif a[i+1] < a[i]:
            d = True
    i += 1
print(res)

Measured memory_bytes: 85352
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans= fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int>factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

P operator+(const P& a, const P& b) {
	return P(a.first + b.first, a.second + b.second);
}
P operator-(const P& a, const P& b) {
	return P(a.first - b.first, a.second - b.second);
}

string s;
int k,n,cnt;
set<string>st;
signed main() {
	cin>>s>>k;
	n=s.size();
	rep(i,k) {
		rep(j,n-i) {
			st.insert(s.substr(j,i+1));
		}
	}
	for(string i:st) {
		cnt++;
		if(cnt==k) {
			cout<<i<<endl;
			break;
		}
	}
}


Measured memory_bytes: 1664
import java.util.HashMap;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (true) {
      HashMap<Integer, Student> map = new HashMap<>();
      int n = sc.nextInt();
      int m = sc.nextInt();
      if ((n | m) == 0) {
        break;
      }
      for (int i = 0; i < m; i++) {
        map.put(i + 1, new Student(n));
      }
      int r = sc.nextInt();
      for (int i = 0; i < r; i++) {
        int t = sc.nextInt() - 540;
        int ni = sc.nextInt();
        int mi = sc.nextInt();
        int s = sc.nextInt();
        if (s == 1) {
          map.get(mi).login(ni, t);
        } else {
          map.get(mi).logout(ni, t);
        }
      }
      int q = sc.nextInt();
      for (int i = 0; i < q; i++) {
        int ts = sc.nextInt() - 540;
        int te = sc.nextInt() - 540;
        int m3 = sc.nextInt();
        int res = map.get(m3).time(ts, te);
        System.out.println(res);
      }
    }
  }

  static class Student {
    boolean[] login = new boolean[721];
    int[] cache;

    Student(int n) {
      this.cache = new int[n + 1];
    }

    void login(int n, int t) {
      cache[n] = t;
    }

    void logout(int n, int t) {
      for (int i = this.cache[n]; i < t; i++) {
        this.login[i] = true;
      }
    }

    int time(int ts, int te) {
      int c = 0;
      for (int i = ts; i < te; i++) {
        c += this.login[i] ? 1 : 0;
        // System.out.println(i + ":" + (this.login[i] ? 1 : 0));
      }
      return c;
    }
  }
}

Measured memory_bytes: 168604
/*
       ()       ()()()()     ()        ()       ()        ()        ()
      ()()      ()     ()    ()()      ()      ()()       ()()      ()
     ()  ()     ()      ()   ()  ()    ()     ()  ()      ()  ()    ()
    ()()()()    ()      ()   ()    ()  ()    ()()()()     ()    ()  ()
   ()      ()   ()     ()    ()      ()()   ()      ()    ()      ()()
  ()        ()  ()()()()     ()        ()  ()        ()   ()        ()

*/
#include <bits/stdc++.h>
#define MOD (int)1e9+7
#define SIZE (int)1e5+5
#define all(x) x.begin(),x.end()

#define si(i)  scanf("%d",&i)
#define sf(f)  scanf("%f",&f)
#define pi(i)  printf("%d",i)
#define pd(d)  printf("%lf",d)
#define deb(x) cout<<#x<<" is "<<x<<"\n";
#define lb     lower_bound
#define ub     upper_bound
#define pb     push_back

#define IOfast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

int64_t exponentiation(int64_t base,int exp)
{
    if (exp == 0)
        return 1;

    if (exp == 1)
        return base;

    int64_t t = exponentiation(base, exp / 2);

    t = (t * t);

    if (exp % 2 == 0)
        return t;
    else
        return base * t;
}

vector<string> board;
int64_t dp[1002][1002];

int64_t dfs(int i,int j,int dest_row,int dest_col)
{
  if( i> dest_row || j>dest_col || board[i][j] == '#')
    return 0;
  if(i == dest_row && j == dest_col)
    return 1;
  
  if(dp[i][j] != -1)
    return dp[i][j];
  
  dp[i][j] =  dfs(i+1,j,dest_row,dest_col) + dfs(i,j+1,dest_row,dest_col);
  dp[i][j] %= MOD;  
  return dp[i][j];
}

int main()
{
  IOfast;
  

  int q=1;
  //cin>>q;
  memset(dp,-1,sizeof(dp));
  while(q--)
  {
    int n,m,u,v;
    string s;
    cin>>n>>m;
    
    for(int i = 0;i<n;i++)
       cin>>s,board.push_back(s);

    cout<<dfs(0,0,n-1,m-1);//i,j;
  
  }
  
  return 0;
}


Measured memory_bytes: 9344
diagonal_string = []
for i in range(3):
    d = input()
    c = []
    for j in d:
        c.append(j)
    diagonal_string.append(c)

c11 = diagonal_string[0][0]
c22 = diagonal_string[1][1]
c33 = diagonal_string[2][2]
print("{}{}{}".format(c11,c22,c33))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//べき//
ll squ(ll n, ll p, ll m){
	if(p==0) return 1;
	if(p%2==0){
		ll t=squ(n, p/2, m);
		return t*t%m;
	}
	return n*squ(n,p-1,m);
	
}


//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//nが大

ll com(ll n,ll m){
	if(n<=0 || m<=0 || n==m){
		return 1;
	}
	if(n<m){
		return 0;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}


//


////////////////////////////////////////////////////////////////////




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

double p[n+1];
rep(i, n){
    cin>>p[i];
}

double dp[n+1][n+1];

Rep(i, n+1){
    Rep(j, n+1){
        dp[i][j]=0.0;
    }
}

dp[0][0]=1.0;
rep(i, n){
    Rep(j, n+1){
        if(i>=j&&j>=1){
            dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1.0-p[i]);
        
        }
        if(j==0){
            dp[i][j]=dp[i-1][j]*(1.0-p[i]);
           
        }
       
    }
     cout<<endl;
}

double sum=0.0;
for(int i=(n+1)/2;i<=n;i++){
sum+=dp[n][i];
}

cout<<fixed<<setprecision(12);
cout<<sum<<endl;
return 0;


}



Measured memory_bytes: 70528
#include <stdio.h>
#include <math.h>

int main(){
  int n,m;
  double x,y;
  double r = M_PI,nr;

  x = y = nr = 0;

  for(;;){
    scanf("%d,%d" ,&n ,&m);
    if(n == 0 && m == 0) break;
    
    x += n*sin(nr*r/180.0);
    y += n*cos(nr*r/180.0);      
    nr += m; 
  }

  printf("%d\n%d\n" ,(int)x ,(int)y);

  return 0;
}
 

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

vector<long long> divisor(long long n){
    vector<long long> ret;
    for(long long i = 1; i * i <= n; i++){
        if(n % i == 0){
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

void solve(long long N){
    //for(auto i : divisor(N)) cout << i << " ";
    //cout << endl;
    vector<long long> divisors = divisor(N);
    if(divisors.size() % 2 == 0) cout << divisors[divisors.size()/2-1] + divisors[divisors.size()/2] - 2 << endl;
    else cout << divisors[divisors.size()/2] * 2 - 2 << endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3748
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int temp = N;
		int sum = 0;

		for (int i = 0; i < 10; i++) {
			sum += N % 10;
			N /= 10;
		}

		if (temp % sum == 0) System.out.println("Yes");
		else System.out.println("No");
 	}
}

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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define forn(i,n) for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 

int t;

void solve(){
	int n, m;
	float tot;
	cin >> n >> m;
	vi A(n);
	for(int i=0; i<n; i++){
		// int cur;
		cin >> A[i];
		tot += A[i];
	}
	sort(A.begin(), A.end(), greater<int>());
	for(int i=0; i<m; i++) {
		float ba = tot / (4*m);
		// cout<<A[i]<<" "<<ba<<endl;
		if(A[i] < ba) {
			cout << "No";
			return ;
		}
	}
	cout << "Yes";
	// cout << x << " " <<  y << " "<< z; 
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	// cin >> t;
	// while(t--)
	solve();
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int n;
  while(cin>>n,n){
    int a[400]={360};
    for(i=1;i<n;++i){
      cin>>a[i];
      a[0]-=a[i];
    }
    int m;
    cin>>m;
    int b[400]={360};
    for(i=1;i<m;++i){
      cin>>b[i];
      b[0]-=b[i];
    }
    double c=0,d=0;
    for(i=0;i<n;++i)
      c+=sin(M_PI*a[i]/180);
    for(i=0;i<m;++i)
      d+=sin(M_PI*b[i]/180);
    if(0){
    }else if(fabs(c-d)<1e-8){
      cout<<0<<endl;
    }else if(c<d){
      cout<<2<<endl;
    }else if(c>d){
      cout<<1<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
using namespace std;
int n; char ch[4][101];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=3;i++)
		scanf("%s",ch[i]);
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		if(ch[1][i]==ch[2][i] && ch[2][i] == ch[3][i])	continue;
		if(ch[1][i]==ch[2][i] ||ch[1][i]==ch[3][i] ||ch[3][i]==ch[2][i])
		{
			ans++;continue;
		}
		ans+=2;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
from math import ceil

n = int(input())
csf = [list(map(int, input().split())) for _ in range(n - 1)]

for i in range(n):
    ans = 0
    for j in range(i, n - 1):
        c, s, f = csf[j]
        ans = c + max(s, f * ceil(ans / f))
    print(ans)

Measured memory_bytes: 3188
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int LEN = 0;

	void doIt() {
		long a = sc.nextLong();
		long b = sc.nextLong();
		System.out.println(a * b / gcd(a , b));
	}

	long gcd(long a, long b) {
		return (b != 0) ? gcd(b, a % b) : a;
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
	
}


Measured memory_bytes: 21844
include Math

def koho(x1, y1, x2, y2, n)
    if n == 0 then
        return [[x1, y1], [x2, y2]]
    else 
        x_s = (x2 - x1) / 3.0 + x1
        y_s = (y2 - y1) / 3.0 + y1
        
        x_t = (x2 - x1) * 2 / 3.0 + x1
        y_t = (y2 - y1) * 2 / 3.0 + y1
        
        l = ((x_t - x_s) ** 2 + (y_t - y_s) ** 2 ) ** 0.5
        cosX = (x_t - x_s) / l
        sinX = (y_t - y_s) / l
        x_u = l * (0.5 * cosX - 3 ** 0.5 / 2 * sinX) + x_s
        y_u = l * (3 ** 0.5 / 2 * cosX + 0.5 * sinX) + y_s
        
        a1 = koho(x1, y1, x_s, y_s, n - 1)
        a2 = koho(x_s, y_s, x_u, y_u, n - 1)
        a3 = koho(x_u, y_u, x_t, y_t, n - 1)
        a4 = koho(x_t, y_t, x2, y2, n - 1)
        a1.pop
        a2.pop
        a3.pop
        return a1 + a2 + a3 + a4
    end
end

$s =[]

x1 = 0.0
y1 = 0.0
x2 = 100.0
y2 = 0.0
n = gets.to_i

ans = koho(x1, y1, x2, y2, n)

ans.each{|a|
    printf("%.8f %.8f\n", a[0],a[1])
}


Measured memory_bytes: 7108
#include<iostream>
#include<queue>
#include<set>
using namespace std;

typedef pair<string,int> P;

int main()
{
  for(;;)
    {
      string str;
      cin>>str;
      if(str=="0")
	break;
      queue<P> qu;
      set<string> hash;       
      qu.push(P(str,0));
      hash.insert(str);
      int ans=-1;
      while(!qu.empty())
	{
	  P a= qu.front();
	  qu.pop();
	  int count=0;
	 
	  string t=a.first;
	  for(int i=0;i<t.size()-1;i++)
	    {
	      if(t[i]!=t[i+1])
		{
		  string x=t; 
		  if((x[i]=='r'&&x[i+1]=='g') ||(x[i]=='g'&&x[i+1]=='r'))
		    x[i]='b',x[i+1]='b';
		  if((x[i]=='r'&&x[i+1]=='b') ||(x[i]=='b'&&x[i+1]=='r'))
		    x[i]='g',x[i+1]='g';
		  if((x[i]=='g'&&x[i+1]=='b') ||(x[i]=='b'&&x[i+1]=='g'))
		    x[i]='r',x[i+1]='r';
		  if(hash.find(x)==hash.end())
		    {
		      hash.insert(x);
		      qu.push(P(x,a.second+1));
		    }
		}
	      else
		{
		  count++;
		}
	    }
	  if(count==t.size()-1)
	    {
	      ans=a.second;
	      break;
	    }
	}
      if(ans==-1)
	  cout<<"NA"<<endl;            
	else
	  cout<<ans<<endl;            
    }

}

Measured memory_bytes: 2668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>

using namespace std;

typedef long long    ll;
typedef long double  ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;

template <typename T> bool chmax(T &a, T& b) {if (a < b) {a = b; return true;} return false;}
template <typename T> bool chmin(T &a, T& b) {if (a > b) {a = b; return true;} return false;}
#define rep(i, n)      for (int i = 0; i < (int)(n); ++i)
#define rep3(i, m, n)  for (int i = (m); i < (int)(n); ++i)
#define rrep(i, n)     for (int i = (int)(n)-1; i >= 0; --i)
#define rrep3(i, m, n) for (int i = (int)(n)-1; i >= (m); --i)
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define mset(x, val) memset(x, (val), sizeof(x))
#define cons(a, b) make_pair((a), (b))
#define car first
#define cdr second

#define endl '\n'
#define INF  0x7f7f7f7f7f7f7f7f
#define INFi 0x7f7f7f7f


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll solve(int N, ll K, vector<ll> & p) {
  sort(all(p));

  ll res = 0;
  rep(i, K) res+=p[i];
  return res;
}

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

  ll N;
  ll K;
  cin >> N;
  vector<ll> p(N);
  cin >> K;
  rep (i, N) {
    cin >> p[i];
  }

  auto ans = solve(N, K, p);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3168