akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
vector<int>g[1100];
long long dp[1100][1100];
int bfs[1100];
int pr[1100];
int dep[1100];
int D;
int T=510;
int lis[1100];
int dist[1100];
int dc(int a,int b){
	int ret=0;
	int f=0;
	for(int i=0;i<g[a].size();i++){
		if(b==g[a][i])continue;
		dist[g[a][i]]=dist[a]+1;
		int q=dc(g[a][i],a)+1;
		ret=max(ret,q);
	}
	return ret;
}
void dfs(int a,int b){
	for(int i=-(D-dist[a]);i<=D-dist[a];i++){
		dp[a][T+i]=1;
	}
	for(int i=0;i<g[a].size();i++){
		if(g[a][i]==b)continue;
		dfs(g[a][i],a);
		for(int j=0;j<1100;j++){
			long long tmp=0;
			if(j)tmp=(tmp+dp[g[a][i]][j-1])%mod;
			if(j+1<1100)tmp=(tmp+dp[g[a][i]][j+1])%mod;
			dp[a][j]=dp[a][j]*tmp%mod;
		}
	}
}
int n;
long long calc(int a){
	dist[a]=0;
	dc(a,-1);
	for(int i=0;i<n;i++)for(int j=0;j<1100;j++)dp[i][j]=0;
	dfs(a,-1);
	long long ret=0;
	for(int i=0;i<1100;i++){
		ret=(ret+dp[a][i])%mod;
	}
	return ret;
}
int main(){
	int a;
	scanf("%d",&a);
	n=a;
	for(int i=0;i<a-1;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		g[p].push_back(q);
		g[q].push_back(p);
	}
	long long r=1;
	for(int i=0;i<a-1;i++)r=r*2%mod;
	queue<int>Q;
	Q.push(0);
	for(int i=0;i<a;i++)bfs[i]=-1;
	bfs[0]=0;
	while(Q.size()){
		int at=Q.front();
		Q.pop();
		for(int i=0;i<g[at].size();i++){
			int to=g[at][i];
			if(bfs[to]!=-1)continue;
			bfs[to]=bfs[at]+1;
			Q.push(to);
		}
	}
	int sz=0;
	int mv=0;
	for(int i=0;i<a;i++){
		if(bfs[mv]<bfs[i])mv=i;
	}
	for(int i=0;i<a;i++)bfs[i]=-1;
	Q.push(mv);
	bfs[mv]=0;
	pr[mv]=-1;
	while(Q.size()){
		int at=Q.front();Q.pop();
		for(int i=0;i<g[at].size();i++){
			int to=g[at][i];
			if(bfs[to]!=-1)continue;
			Q.push(to);
			bfs[to]=bfs[at]+1;
			pr[to]=at;
		}
	}
	int di=0;
	int da=0;
	for(int i=0;i<a;i++){
		if(di<bfs[i]){
			di=bfs[i];
			da=i;
		}
	}
	int at=da;
	while(~at){
		lis[sz++]=at;
		at=pr[at];
	}
	long long ret;
	if(di%2==0){
		D=sz/2;
		ret=calc(lis[sz/2]);
	}else{
		D=(sz+1)/2;
		ret=(calc(lis[sz/2-1])+calc(lis[sz/2]))%mod;
		g[n].push_back(lis[sz/2-1]);
		g[n].push_back(lis[sz/2]);
		for(int i=0;i<g[lis[sz/2-1]].size();i++){
			if(g[lis[sz/2-1]][i]==lis[sz/2])g[lis[sz/2-1]][i]=n;
		}
		for(int i=0;i<g[lis[sz/2]].size();i++){
			if(g[lis[sz/2]][i]==lis[sz/2-1])g[lis[sz/2]][i]=n;
		}
		ret=(ret+mod-calc(n))%mod;
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 8960
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>

using namespace std;

int main(void) {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int x = 0;
	vector<int>now(n);
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I') {
			if (i == 0) {
				now[i] = 1;
			}
			else {
				now[i] = now[i - 1] + 1;
			}
		}
		else {
			if (i == 0) {
				now[i] = -1;
			}
			else {
				now[i] = now[i - 1] - 1;
			}
		}
	}
	x = 0;
	for (int i = 0; i < n; i++) {
		x = max(x, now[i]);
	}
	cout << x;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,s;
  cin >> N;
  cin >> K;
  s = 1;
  for (int i=0;i<N;i++){
  	if(s>K){
      s += K;
    }else{
      s *= 2;
    }
  }
  cout << s;
} 

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

int main(){
    set<int> s;
    rep(i,3){
        int n;
        cin >> n;
        s.insert(n);
    }
    if(s.size()==2) printf("Yes\n");
    else printf("No\n");
    
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    m = int(s[5:7])
    if m <= 4:
        print("Heisei")
    else:
        print("TBD")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61528
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    SCIN(str);
    string s = "CODEFESTIVAL2016";
    int ans = 0;
    for(int a = 0;a < s.size();a++){
        if(s.at(a) != str.at(a)){
            ans++;
        }
    }
    COUT(ans);
    return 0;
}


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

int main()
{
	int n;
	while( cin >> n && n ){
		int age[ 7 ] = {0};
		for( int i = 0; i < n; ++i ){
			int a;
			cin >> a;
			a /= 10;
			++age[ min( a, 6 ) ];
		}
		for( int i = 0; i < 7; ++i ){
			cout << age[ i ] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    if(b < a)
        swap(a, b);
    cout << string(b, (char)(a + '0')) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    int N;
    string S, T, U="";
    cin>>N>>S>>T;
    rep(i, N){
        char Si=S[i], Ti=T[i];
        U.push_back(Si);
        U.push_back(Ti);
    }
    cout<<U<<endl;
    return 0;
}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}


void solve(){
  int N;
  cin >> N;
  ll sum = 0;
  rep(i, N+1){
    if(i % 3 == 0 || i % 5 == 0)
      continue;
    sum += i;
  }
  cout << sum << endl;
}

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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  for(int i=1;i<100000;i++){
    if(A*i%B==C){cout<<"YES"<<endl;return 0;}
  }
  cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i,h) cin >> s[i];
    VVI dp(h, VI(w, 1e9));
    dp[0][0] = (s[0][0] == '#');
    REP(i,h) REP(j,w){
        if (i < h - 1){
            if (s[i][j] == '.'){
                chmin(dp[i + 1][j], dp[i][j] + (s[i + 1][j] == '#'));
            }else{
                chmin(dp[i + 1][j], dp[i][j]);
            }
        }
        if (j < w - 1){
            if (s[i][j] == '.'){
                chmin(dp[i][j + 1], dp[i][j] + (s[i][j + 1] == '#'));
            }else{
                chmin(dp[i][j + 1], dp[i][j]);
            }
        }
    }
    cout << dp[h - 1][w - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef unsigned long long ll;
 
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define fi first
#define se second
#define II pair <int,int>
 
const int N=2e5+10;
 
ll cal(ll a, ll p, ll n){
   long long tich=a,du=1,p1=p;
  while (p>0)
  {
    if (p%2==1) du=du*tich%n;
    tich=tich*tich%n;
    p/=2;
  }
  return du;
}
 
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    ll f[N]; int len=s.length();
    FOR(i,1,len) {
        ll so=cal(10,i-1,2019);
        f[i]=f[i-1]+(s[i-1]-'0')*so;
    }
    map <ll,ll> dd; int ans=0;
    FOR(i,0,len) {
        ans+=dd[f[i]%2019];
        dd[f[i]%2019]++;
    }
    cout << ans;
}

Measured memory_bytes: 5312
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000
int main(){//kが要素の最大値                                                 
  int *A,*B;
  int N,C[VMAX+1],i,j,k=0;
  scanf("%d",&N);
  A = malloc(sizeof(int)*N+1);
  B = malloc(sizeof(int)*N+1);
  for(i=1;i<=N;i++){
    scanf("%d",&A[i]);
    if(A[i]>k)
      k=A[i];//最大値求めた                                                  
  }
  for(i=0;i<=k;i++)
    C[i]=0;//初期化                                                          

  for(j=1;j<=N;j++)
    C[A[j]]=C[A[j]]+1;//A[i]の出現数を記録する                               

  for(i=1;i<=k;i++)
    C[i]=C[i]+C[i-1];//前の数を足していく                                    
  for(j=N;j>0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]=C[A[j]]-1;
  }
  for(i=1;i<=N;i++){
    printf("%d",B[i]);
    if(i==N){
      printf("\n");
      break;
    }
    printf(" ");
  }
  return 0;
}






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

int main(){
  int n, d, i, j, k, sum, count=0;
  double root;
  cin >> n >> d;
  vector<vector<int>> vec(n, vector<int>(d));
  for(i=0; i<n; i++){
    for(k=0; k<d; k++){
      cin >> vec[i][k];
    }
  }

  for(i=0; i<n-1; i++){
    for(j=i+1; j<n; j++){
      sum = 0;
      for(k=0; k<d; k++){
        sum += (vec[j][k] - vec[i][k]) * (vec[j][k] - vec[i][k]);
      }
      root = sqrt(sum);
      count = (ceil(root) == floor(root)) ? count+1 : count;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a,b;
	scanf("%d %d", &a,&b);
	if (a>b)
	{
		printf("a > b\n");
	}
	else
		if (a<b)
		{
			printf("a < b\n");
		}
		else
		{
			printf("a == b\n");
		}
	return 0;
}


Measured memory_bytes: 2056
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;


int main() {

    long K, N;
    cin >> K >> N;
    vector<long> as;
    for (int i = 0; i < N; ++i) {
        long A;
        cin >> A;
        as.push_back(A);
    }

    vector<long> ts;
    long m = K - (as[N-1]-as[0]);
    for (int j = 0; j < N - 1; ++j) {
        m= max(m,as[j + 1] - as[j]);
    }


    std::cout << (K - m) << "\n";

    return 0;
}


Measured memory_bytes: 2420
use std::io;

fn main() {
    let (W, H, x, y, r) = input();

    if 0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn input() -> (i32, i32, i32, i32, i32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");

    let mut iter = s.trim().split_whitespace();

    let W: i32 = iter.next().unwrap().parse().unwrap();
    let H: i32 = iter.next().unwrap().parse().unwrap();
    let x: i32 = iter.next().unwrap().parse().unwrap();
    let y: i32 = iter.next().unwrap().parse().unwrap();
    let r: i32 = iter.next().unwrap().parse().unwrap();

    (W, H, x, y, r)
}



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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  string s,t;cin>>s>>t;
  vector<set<int>> ls(26);
  vector<set<int>> lt(26);
  int i;
  rep(i,s.size())ls[s[i]-'a'].insert(i);
  rep(i,t.size())lt[t[i]-'a'].insert(i);
  bool ok=true;
  rep(i,26)if(lt[i].size()>0&&ls[i].size()==0)ok=false;
  if(ok)
  {
    int now=-1;
    ll loop=0;
    rep(i,t.size())
    {
      int ind=t[i]-'a';
      auto it=ls[ind].upper_bound(now);
      if(it==ls[ind].end())
      {
        loop++;
        now=*ls[ind].begin();
      }
      else
      {
        now=*it;
      }    
    }
    cout<<loop*s.size()+now+1<<endl;
  }
  else cout<<-1<<endl;
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	int n;
	double d;
	cin >> n >> d;

	ll cnt = 0;
	for (int i = 0; i < n; ++i) {
		long double x, y;
		cin >> x >> y;
		long double dist = sqrt(x * x + y * y);
		if (dist <= d) {
			++cnt;
		}
	}

	cout << cnt << '\n';
	return 0;
}


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

using namespace std;

const int Mod = 1000000007;

int n;
int a[21][21];
int dp[21][1 << 21];

int GetBit(int num, int pos)
{
    return (num >> pos) & 1;
}

int Cal(int i, int Bitmask)
{
    if (i == n)
    {
        return 1;
    }
    if (dp[i][Bitmask] != -1)
    {
        return dp[i][Bitmask];
    }
    dp[i][Bitmask] = 0;
    for (int j = 0; j < n; j++)
    {
        if (a[i][j] && GetBit(Bitmask, j) == 0)
        {
            dp[i][Bitmask] = (dp[i][Bitmask] + Cal(i + 1, Bitmask | (1 << j))) % Mod;
        }
    }
    return dp[i][Bitmask];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> a[i][j];
        }
        for (int j = (1 << 21) - 1; j >= 0; j--)
        {
            dp[i][j] = -1;
        }
    }
    cout << Cal(0, 0);
    return 0;
}

Measured memory_bytes: 175672
//Induber
//PRAVEEN FULERA

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

typedef long long int ll;
#define mod 1000000007
#define speed ios_base::sync_with_stdio(false);
#define up cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define T int t; cin >> t; while(t--)

int main(){
  speed up
  int n , k;
  cin >> n >> k;
  long double ans = 0;
  for(int i = 1; i <= n; i++){
      int j = i;
      int l = 1;
      while(j < k){
          j*=2;
          l*=2;
      }
      l = l*n;
      ans = ans + 1.0/l;
  }
  cout << setprecision(12) << ans << '\n';
}

Measured memory_bytes: 256
from math import sqrt, factorial
from itertools import permutations
N = int(input())
Ts = [list(map(int, input().split())) for _ in range(N)]
points = list(range(N))

ans = 0
for pat in permutations(Ts):
  x = 0
  for i, p in enumerate(pat):
    if i==0:
      past = p
      continue
    a, b = past
    c, d = p
    x += sqrt((a-c)**2+(b-d)**2)
  ans += x

print(ans/factorial(N))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll ans = 0;
    ll l = 0;
    ll r = 0;
    ll sum = 0;
    // しゃくとり法
    while(l<N){
        while(r<N){
            if((sum^A[r])!=(sum+A[r])) break;
            sum+=A[r];
            r++;
        }
        // 区間分まとめて答えに足す
        ans += r-l;
        // 左端をずらす
        if(l==r){
            // l==rのときすでにsumは0のはず
            r++;
        }else{
            sum-=A[l];
        }
        l++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4788
/* Author: shriamrut
 * Language: C++17
 * Made on:22.08.2020
 * */
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ll long long
#define ss second
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(v) (v).begin(),(v).end()
#define maxv(v) *max_element(all(v))
#define minv(v) *min_element(all(v))
using namespace std;
void ra(auto a[],int n) { for(int i=0;i<n;i++) cin>>a[i];}
void pa(auto a[],int n) { for(int i=0;i<n;i++) cout<<a[i]<<" ";}
void rv(vector<auto>&v,int n) {v.resize(n);for(int i=0;i<n;i++)	cin>>v[i]; }
void pv(vector<auto>&v) {for(size_t i=0;i<v.size();i++) cout<<v[i]<<" ";}
ll maxl(ll a,ll b) { if(a>b) return a; return b; }
ll minl(ll a,ll b) { if(a<b) return a; return b; }
/*auto i2=upper_bound(cind[i].rbegin(), cind[i].rend(), range[1],[](int a, int b){return a>=b;});
 * to obtain largest val <=x
 * */
int main() {
	IOS;	
	//freopen("input.txt","r",stdin);
	int n,x,t;
	cin>>n>>x>>t;
	int ans=ceil((float)n/x)*t;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3584
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int W, H;
char field[100][100];

void dfs(int x, int y, char obj){
	field[x][y] = 'T';

	for(int dx = -1; dx <= 1; ++dx){
		for(int dy = -1; dy <= 1; ++dy){
			if(dx != 0 && dy != 0) continue;
			int nx = x + dx, ny = y + dy;
			if(0 <= nx && nx < H && 0 <= ny && ny < W && field[nx][ny] == obj){
				dfs(nx, ny, obj);
			}
		}
	}
}

int main(void){
	while(1){
		cin >> H, cin >> W;
		if(!W && !H) break;

		for(int i=0; i<H; ++i){
			for(int j=0; j<W; ++j){
				cin >> field[i][j];
			}
		}

		int count = 0;

		for(int i=0; i<H; ++i){
			for(int j=0; j<W; ++j){
				if(field[i][j] == '#' || field[i][j] == '@' || field[i][j] == '*'){
					dfs(i, j, field[i][j]);
					count++;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}

	

Measured memory_bytes: 2100
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<long,ii> lii;

const long MOD = 1e9+7;
long p2(long b)
{
	if(b == 0) return 1;
	else if(b == 2) return 4;
	else if(b&1) return (p2(b-1)*2)%MOD;
	else
	{
		long temp = p2(b/2);
		return (temp*temp)%MOD;
	}
}
long geo(long a, long n)
{
	return (a*(p2(n)-1))%MOD;
}

vector<lii> vec;
long arr[100003];

int main()
{
	//ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);
	
	int n; scanf("%d", &n);	
	for(int i = 1; i <= n; i++)
		scanf("%lld", &arr[i]);
	long hit = 0;
	long res = 1;
	long bed = 1;
	for(int i = 1; i <= n+1; i++)
	{
		if(arr[i] == 1 || i == n+1)
		{
			long cnt = 0;
			cnt += bed;
			for(auto j : vec)
			{
				cnt += geo(j.fi,j.se.fi-j.se.se+1);
				cnt %= MOD;
			}
			// printf("i : %d\n" , i);
			// printf("	BED : %lld\n", bed);
			// printf("	CNT : %lld\n", cnt);
			if(arr[i] == 1) hit++;
			vec.clear();
			bed = 1;
			res *= cnt;
			res %= MOD;

		}
		else if(vec.size() == 0)
		{
			vec.push_back({2,{arr[i],2}});
			bed *= 2;
		}
		else if(arr[i] > arr[i-1])
		{
			for(int j = 0; j < vec.size(); j++)
			{
				vec[j].fi *= p2(arr[i]-arr[i-1]);
				vec[j].fi %= MOD;
			}
			bed *= 2; bed %= MOD;
			vec.push_back({bed,{arr[i], arr[i-1]+1}});
		}
		else
		{
			vector<lii> temp;
			bed *= 2; bed %= MOD;
			for(int j = 0; j < vec.size(); j++)
			{
				if(vec[j].se.fi > arr[i])
				{
					if(vec[j].se.se > arr[i])
					{
						bed += 2*geo(vec[j].fi,vec[j].se.fi-vec[j].se.se+1);
						bed %= MOD;
					}
					else
					{
						bed += 2*geo(vec[j].fi, vec[j].se.fi-arr[i]);
						bed %= MOD;
						temp.push_back({(vec[j].fi*p2(vec[j].se.fi-arr[i]))%MOD,{arr[i],vec[j].se.se}});
					}
				}
				else
					temp.push_back(vec[j]);
			}
			vec = temp;
		}
	}
	res *= p2(hit);
	res %= MOD;
	// printf("%lld\n", p2(1000000000));
	printf("%lld\n", res);
}












Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str ;
    int[] a = new int[128];
    int i; 
    while(sc.hasNext()){
      str = sc.nextLine().toLowerCase();
    for(i=0;i<str.length();i++){
      a[str.charAt(i)]++;;
    }
    }
    for(char ch='a';ch<='z';ch++){
      System.out.println(ch+" : "+a[ch]);
    }
    sc.close();
    
  }
}


Measured memory_bytes: 26060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n,k,q,sum = 0;
  cin >> n >> k >> q;
  sum = n*k;
  vector<int> a(n,k);
  vector<int> mp(n,q);
  REP(i,q){
    int aa;
    cin >> aa;
    aa--;
    mp[aa]--;
  }
  
  REP(i,n){
    a[i] -= mp[i];
  }
  
  REP(i,n){
    if(a[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


Measured memory_bytes: 4036
#include <iostream>
#include <complex>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

typedef complex<double> Point, Vector;
typedef pair<Point, Point> Segment, Line;

#define X real()
#define Y imag()
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

double dot(Vector a, Vector b){
    return a.X * b.X + a.Y * b.Y;
}

double cross(Vector a, Vector b){
    return a.X * b.Y - a.Y * b.X;
}

double norm(Vector a){
    return a.X * a.X + a.Y * a.Y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

int ccw(Point p0, Point p1, Point p2){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if(cross(a, b) > EPS) return 1;
    if(cross(a, b) < -EPS) return -1;
    if(dot(a, b) < -EPS) return 2;
    if(norm(a) < norm(b)) return -2;

    return 0;
}

bool intersect(Point p1, Point p2, Point p3, Point p4){
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

bool intersect(Segment s1, Segment s2){
    return intersect(s1.first, s1.second, s2.first, s2.second);
}

Point getCrossPointSS(Segment s1, Segment s2){
    Vector base = s2.second - s2.first;
    double d1 = abs(cross(base, s1.first - s2.first));
    double d2 = abs(cross(base, s1.second - s2.first));
    double t = d1 / (d1 + d2);
    return s1.first + (s1.second - s1.first) * t;
}

int n;

int solve(vector<Segment> &sg){
    int ans = 1;
    for(int i=0; i<n; i++){
        vector<Point> ps;
        for(int j=0; j<i; j++){
            // 線分が正方形内で交わらない
            if(!intersect(sg[i], sg[j])) continue;

            Point cross = getCrossPointSS(sg[i], sg[j]);

            // 交点が正方形の辺上にある
            if(equals(cross, sg[i].first) || equals(cross, sg[i].second)) continue;
            if(equals(cross, sg[j].first) || equals(cross, sg[j].second)) continue;

            bool same = false;
            for(int k=0; k<ps.size(); k++){
                if(equals(ps[k], cross)) same = true;
            }

            if(!same){
                ps.emplace_back(cross);
            }
        }

        ans += ps.size() + 1;
    }

    return ans;
}

int main(){
    while(1){
        cin>>n;
        if(n == 0) return 0;

        vector<Segment> sg;
        for(int i=0; i<n; i++){
            double x1, y1, x2, y2; cin>>x1>>y1>>x2>>y2;
            sg.emplace_back(Point(x1, y1), Point(x2, y2));
        }

        cout << solve(sg) << endl;
    }
}


Measured memory_bytes: 3128
#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;
    cin >> n;
    int cnt = 0;
    for (int i = 1; i < n; i++)
    {
        int tmp = n - i;
        double root = sqrt(tmp);
        for (int j = 1; j <= (int)root; j++)
        {
            if (tmp % j != 0)
                continue;
            if (tmp / j == root)
                cnt++;
            else
                cnt += 2;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3672
//????????£????????¨?±?????????????A????????????, ??¨?????????????????¨?±????????°????????????¨???????????????.
//????????£????????¨?±????????????????????????????A?????????????????????????????????2^M???????????????????????°?????????
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int n, m, k;
int d[16];
vector<int> et[100];
int blackId[100];

void input() {
	int v;
	int i, j;
	cin >> n >> m >> k;
	for (i = 0; i < n; i++) { blackId[i] = -1; }
	for (i = 0; i < m; i++) {
		cin >> d[i]; d[i]--;
		blackId[d[i]] = i;
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < k; j++) {
			cin >> v; v--;
			et[i].push_back(v);
		}
	}
}

int dp[1 << 16];

int main() {
	input();
	
	for (int i = 0; i < (1 << m); i++) dp[i] = 11451419;
	queue<int> que;
	
	que.push((1 << m) - 1);
	dp[(1 << m) - 1] = 0;
	while (!que.empty()) {
		int state = que.front(); que.pop();
		
		for (int i = 0; i < k; i++) {
			int nState = 0;
			for (int j = 0; j < m; j++) {
				if ((state >> j) % 2 == 0) continue;
				int id = blackId[et[d[j]][i]];
				if (id == -1) continue;
				nState |= (1 << id);
			}
			if (dp[nState] > dp[state] + 1) {
				dp[nState] = dp[state] + 1;
				que.push(nState);
			}
		}
	}
	
	cout << dp[0] << endl;
	return 0;
}

Measured memory_bytes: 3544
import java.util.Scanner;

public class Main
{
	static int pay(int price, int tax)
	{
		return price * (100 + tax) / 100;
	}

	static int max(int a, int b)
	{
		if (a > b) {
			return a;
		} else {
			return b;
		}
	}

	static int solve(int x, int y, int sum)
	{
		int answer = 0;
		for (int i = 1;i < sum;++i) {
			for (int j = i;j < sum;++j) {
				if (pay(i, x) + pay(j, x) == sum) {
					answer = max(answer, pay(i, y) + pay(j, y));
				}
			}
		}
		return answer;
	}

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int s = sc.nextInt();
		while (x > 0) {
			System.out.println(solve(x, y, s));
			x = sc.nextInt();
			y = sc.nextInt();
			s = sc.nextInt();
		}
	}
}



Measured memory_bytes: 28968
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    ll n;
    cin>>n;
    vector<ll> p(n);
    rep(i,n)cin>>p[i];
    ll minp=200001;
    ll cnt=0;
    rep(i,n){
        minp=min(minp,p[i]);
        if(minp>=p[i]){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}



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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}


int main(){
  ll N, K; cin >> N >> K;
  cout << min(N % K, abs(K - N % K)) << endl;

  return 0;
}


Measured memory_bytes: 3588
def insertionSort(a, n, g)
    cnt=0
    for i in g..n-1 do
        v = a[i]
        j = i - g
        while j >= 0 && a[j] > v do
            a[j+g] = a[j]
            j = j - g
            cnt+=1
        end
        a[j+g] = v
    end
    return cnt
end

def shellSort(a,n,m,g)
    cnt = 0
    for i in 0..m-1 do
        cnt+=insertionSort(a, n, g[i])
    end
    return cnt
end

n=gets.to_i
a=Array.new
for i in 1..n do
  a.push(gets.to_i)
end

m = (Math.log10(2*n+1)/Math.log10(3)).floor
g = Array.new
for i in 1..m do
   g.push((3**i-1)/2)
end
g.reverse!
cnt=shellSort(a,n,m,g)

p m
printf("%s\n",g.join(" "))
p cnt
a.each{|v|
  p v
}

Measured memory_bytes: 18300
#include<bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	typedef long double db;
	#define fi first
	#define se second
	#define pi pair<ll,ll>
	#define pii pair<ll,pi>
	#define pb push_back
	#define mk make_pair
	const int siz = 100;
	vector<int>adj[siz];
	vector<bool> visited(siz);
	vector<int> tin(siz), low(siz);
	int timer;
	int ans;
	int n, m;
	void dfs(int v, int p = -1) {
		visited[v] = true;
		tin[v] = low[v] = timer++;
		for (int to : adj[v]) {
			if (to == p) continue;
			if (visited[to]) {
				low[v] = min(low[v], tin[to]);
			} else {
				dfs(to, v);
				low[v] = min(low[v], low[to]);
				if (low[to] > tin[v])
					ans++;
			}
		}
	}

	void find_bridges() {
		timer = 0;
		visited.assign(n, false);
		tin.assign(n, -1);
		low.assign(n, -1);
		for (int i = 0; i < n; ++i) {
			if (!visited[i])
				dfs(i);
		}
	}
	int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cin >> n >> m;
		for (int i = 0; i < m; i++) {
			int u, v;
			cin >> u >> v;
			adj[u].pb(v);
			adj[v].pb(u);
		}
		find_bridges();
		cout << ans << endl;
	}

Measured memory_bytes: 3600
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String ars[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        //String str[]=br.readLine().split(" ");
        long n=Long.parseLong(br.readLine());
        //int k=Integer.parseInt(str[1]);
        StringBuffer sb=new StringBuffer();
        while(n>0)
        {
            int mod=(int)((n-1)%26);
            sb.append((char)(mod+97));
            n=(n-1)/26;
        }
        sb.reverse();
        pw.println(sb.toString());
        pw.flush();
        pw.close();
    }
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

LL N, M, Q;
VLL a, b, c, d;

LL dfs(VI arr) {
    if(arr.size() == N) {
        LL ans = 0;
        REP(i, Q) {
            if(arr[b[i]-1] - arr[a[i]-1] == c[i]) {
                ans += d[i];
            } 
        }

        return ans;
    }

    int min_add_num = arr.size() == 0 ? 1 : arr[arr.size()-1];

    LL ans = 0;
    REP2(i, min_add_num, M+1) {
        arr.PB(i);
        LL tmp = dfs(arr);
        ans = max(ans, tmp);
        arr.pop_back();
    }

    return ans;
}

void solve(){
    VI tmp;
    cout << dfs(tmp) << endl;
}

int main(){
    scanf("%lld",&N);
    scanf("%lld",&M);
    scanf("%lld",&Q);
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);

    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        scanf("%lld",&c[i]);
        scanf("%lld",&d[i]);
    }
    solve();
    return 0;
}



Measured memory_bytes: 3704
import sys
from bisect import bisect_left


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    s = list(map(int, input().split()))
    _ = int(input())
    t = list(map(int, input().split()))
    cnt = 0
    for e in t:
        pos = bisect_left(s, e)

        if pos != n and s[bisect_left(s, e)] == e:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()



Measured memory_bytes: 14144
#include<iostream>
#include<cstdio>
using namespace std;
struct Edge
{
	int to,next,cost;	
}e[400005];
int head[100005],cnt=0;
bool vis[100005];
int d[100005];
bool use[100005];
void addedge(int from,int to,int cost)
{
	e[++cnt].to=to;
	e[cnt].cost=cost;
	e[cnt].next=head[from];
	head[from]=cnt;
}
bool flag=0;
void dfs(int x)
{
	vis[x]=1;
	for(int i=head[x];i;i=e[i].next)
	{
		int w=e[i].cost,v=e[i].to;
		if(d[v]>d[x]+w)
		{
			d[v]=d[x]+w;
			if(vis[v])
			{
				flag=1;
				return;
			}
			dfs(v);	
		}	
	} 
	vis[x]=0;
	return;
}
inline int read()
{
	int s=0,f=1;char x=getchar();
	while(!isdigit(x))
	{
		if(x=='-') f=-1;
		x=getchar();
	}
	while(isdigit(x))
	{
		s=(s<<1)+(s<<3)+(x^48);
		x=getchar();
	}
	return s*f;
}
int main()
{
	int n,m;
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		int x,y,z;
		x=read();y=read();z=read();
		addedge(y,x,z);
		addedge(x,y,-z);
	}
	flag=0;
	for(int i=1;i<=n;i++)
	{
		d[i]=0;
		if(!use[i])
		{
			use[i]=1;
			dfs(i);
		}	
	}
	if(flag) cout<<"No";
	else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 7808
use std::fmt::Write;

fn main() {
    let _n: usize = read();
    let mut vec: Vec<u32> = read_as_vec();
    let pivot_idx = partition(&mut vec);
    println!("{}", join2(' ', &vec, pivot_idx));
}

fn partition(slice: &mut [u32]) -> usize{
    let n = slice.len();
    let pivot = slice[n - 1];
    let mut pre_ptr  = 0usize;
    let mut post_ptr = 0usize;
    while pre_ptr < (n - 1) {
        if slice[pre_ptr] <= pivot {
            let tmp = slice[pre_ptr];
            slice[pre_ptr]  = slice[post_ptr];
            slice[post_ptr] = tmp;
            post_ptr += 1;
        }
        pre_ptr += 1;
    }
    slice[pre_ptr]  = slice[post_ptr];
    slice[post_ptr] = pivot;
    post_ptr
}

fn join2<T: std::fmt::Display>(delimiter: char, arr: &[T], idx: usize) -> String {
    let mut text = String::new();
    for (i, e) in arr.iter().enumerate() {
        if i > 0 {
            text.push(delimiter);
        }
        if i == idx {
            write!(text, "[{}]", e).unwrap();
        } else {
            write!(text, "{}", e).unwrap();
        }
    }
    text
}

fn read<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().parse::<T>().ok().unwrap()
}

fn read_as_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse::<T>().ok().unwrap())
        .collect()
}


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

bool revp2(const pair<ll,ll>&a,const pair<ll,ll>&b){return a.first>b.first;}
bool revp3(const pair<ll,ll>&a,const pair<ll,ll>&b){if(a.first==b.first)return a.second<b.second;
return a.first>b.first;}

int main()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    ll a,b,k;map<ll,ll>m;
    cin>>a>>b>>k;
    for(int i=a;i<=min(a+k-1,b);i++){m[i]=1;cout<<i<<endl;}
    for(int i=max(b-k+1,a);i<=b;i++){if(m[i]!=1)cout<<i<<endl;}
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int n,a[100005],p,cnt;

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    for(int i=2;i<=n;i++){
        if(a[i]>a[i-1]){
            if(!p) p=1;
            else if(p==2) cnt++,p=0;
        }
        else if(a[i]<a[i-1]){
            if(!p) p=2;
            else if(p==1) cnt++,p=0;
        }
    }
    cout << cnt+1;
}


Measured memory_bytes: 640
import collections
n=int(input())
a=list(map(int,input().split()))
m=max(a)
c=collections.Counter(a)
c=c.most_common()
l=[0]*n
for i in range(len(c)):
    l[c[i][0]-1]=c[i][1]
print(l[0])
for j in range(1,n):
    print(l[j])


Measured memory_bytes: 121972
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { parse(&get_word()) }

const MOD: i64 = 1_000_000_007;

fn powmod(x: i64, mut e: i64, m: i64) -> i64 {
    let mut sum = 1;
    let mut cur = x % m;
    while e > 0 {
        if e % 2 != 0 {
            sum = sum * cur % m;
        }
        cur = cur * cur % m;
        e /= 2;
    }
    sum
}

fn make_dp_table(n: usize) -> Vec<Vec<i64>> {
    let mut dp = vec![vec![0; 2 * n]; n];
    for i in 0 .. 2 * n {
        dp[0][i] = 1;
    }
    for i in 1 .. n {
        for j in 0 .. 2 * n - i {
            dp[i][j] = (dp[i - 1][j + 1] + if j > 0 { dp[i][j - 1] } else { 0 })
                % MOD;
        }
    }
    dp
}

fn main() {
    let n = get();
    let k: usize = get::<usize>() - 1;
    let mut tot: i64 = 0;
    let dp = make_dp_table(n);
    if k < n - 1 {
        for m in n - k - 1 .. n {
            let mut tmp = dp[n - m - 1][m + 1 + k - n];
            for i in 0 .. n - k - 2 {
                tmp = tmp * (m - 1 - i) as i64 % MOD;
                tmp = tmp * powmod(i as i64 + 1, MOD - 2, MOD) % MOD; 
            }
            tot += tmp;
            tot %= MOD;
        }
    } else {
        tot = dp[n - 1][0];
    }
    for _ in k + 2 .. n {
        tot = tot * 2 % MOD;
    }
    println!("{}", tot);
}


Measured memory_bytes: 72700
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
typedef long long ll;

int main(void){
  ll n=1,N;cin >> N;
  stack<ll> s;
  if(N==0)s.push(0);
  while(N!=0){
    if(N%-2){
      s.push(1);
      N-=1;
    }else s.push(0);
    N/=-2;
  }
  while(!s.empty()){
    cout << s.top();
    s.pop();
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
rn = int(n**0.5)+1
ans = 11
for i in range(1,rn+1):
    if n%i == 0:
        a = len(str(i))
        b = len(str(n//i))
        c = max([a,b])
        if c < ans:
            ans = c
print(ans)

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

using namespace std;
using ll = long long;
using lli = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vlli = vector<lli>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define all(v) v.begin(), v.end()
#define debug(x) cout << x << endl
#define vout(v) rep(i, v.size()) cout << v[i] << " ";

string s;

int solve() {
	while (s != "") {
		if (s.substr(0, 2) == "hi") {
			s = s.substr(2);
		} else {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

int main() {
	cin >> s;

	solve();
	return 0;
}

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

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    int ia=0, ib=0, ic=0;
    char next = 'a';
    char ans;
    while (true){
        if (next == 'a'){
            if (ia == a.length()){
                ans = 'A';
                break;
            }
            next = a[ia];
            ia += 1;
        }
        else if (next == 'b'){
            if (ib == b.length()){
                ans = 'B';
                break;
            }
            next = b[ib];
            ib += 1;
        }
        else{
            if (ic == c.length()){
                ans = 'C';
                break;
            }
            next = c[ic];
            ic += 1;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $n);
$A = [];
$B = [];
for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d %d", $a, $b);
    $A[] = $a;
    $B[] = $b;
}
asort($B);

$flg = true;
$tmp = 0;
foreach ($B as $key => $val) {
    $A[$key] += $tmp;

    $tmp = $A[$key];

    if ($A[$key] > $val) {
        $flg = false;
        break;
    }
}

echo $flg ? 'Yes' : 'No', PHP_EOL;


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

class Dice{
private:
	int num[6];
public:
	Dice(int input[6]);
	~Dice(){};
	int getNum(int want);
	int getTop();
	void moveStep(char direction);
};

Dice::Dice(int input[6]){
	for(int i = 0; i < 6; i++){
		num[i] = input[i];
	}
}

int Dice::getNum(int want){
	return num[want - 1];
}

int Dice::getTop(){
	return num[0];
}

void Dice::moveStep(char direction){
	int temp[6];
	for(int i = 0; i < 6; i++){
		temp[i] = num[i];
	}
	switch(direction){
	case 'N':
		num[0] = temp[1];
		num[1] = temp[5];
		num[5] = temp[4];
		num[4] = temp[0];
		break;
	case 'E':
		num[0] = temp[3];
		num[3] = temp[5];
		num[5] = temp[2];
		num[2] = temp[0];
		break;
	case 'S':
		num[0] = temp[4];
		num[4] = temp[5];
		num[5] = temp[1];
		num[1] = temp[0];
		break;
	case 'W':
		num[0] = temp[2];
		num[2] = temp[5];
		num[5] = temp[3];
		num[3] = temp[0];
		break;
	}
}

int main() {

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

	string str;
	cin >> str;

	Dice dice1(in);

	for(unsigned int i = 0; i < str.length(); i++){
		dice1.moveStep(str[i]);
	}

	cout << dice1.getTop() << endl;

	return 0;
}

Measured memory_bytes: 1204
N = int(input())
F = []
P = []
ans = -10**10
for i in range(N):
    F.append(list(map(int,input().split())))
for i in range(N):
    P.append(list(map(int,input().split())))
for i in range(1,2**10):
    profit = 0
    li = [0]*N
    for j in range(10):
        for k in range(N):
            if (i >> j & 1) and F[k][j]:
                li[k] += 1
    for k in range(N):
        profit += P[k][li[k]]
    ans = max(profit,ans)
print(ans)

Measured memory_bytes: 74172
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	vector<int> B(N - 1);
	for (int i = 0; i < N - 1; i++) cin >> B[i];

	int ans = B[0] + B.back();
	for (int i = 0; i < N - 2; i++) ans += min(B[i], B[i + 1]);

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    S = input()
    S = 'R' + S + 'L'
    a = S[0]
    b = S[1]
    s = 0
    for c in S[2:]:
        if c == 'R' and b == 'R':
            s += 1
        if b == 'L' and a == 'L':
            s += 1
        a = b
        b = c
    print(min(N-1, s + 2 * K))
main()
    


Measured memory_bytes: 3316