akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list> 
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
typedef pair<double, long long> pair_t;
bool comp(const pair_t& a, const pair_t& b) {
	if (a.first == b.first)return  a.second > b.second;
	else {
		return a.first > b.first;
	}
}

int main() {
	ll n, cnt = 0, Mcnt = -INF;
	cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	vector<ll>bucket(pow(10, 5) + 10);
	for (ll i = 0; i < n; i++) {
		if (a[i] + 1 < pow(10, 5))bucket[a[i] + 1]++;
		bucket[a[i]]++;
		if (0 < a[i] - 1)bucket[a[i] - 1]++;
	}
	sort(all(bucket));
	cout << bucket[bucket.size()-1] << endl;
}


Measured memory_bytes: 1792
public class compiler
  Shared Sub Main()
    Dim n As Integer = CType(Console.ReadLine(), Integer)
    Dim input As String = Console.ReadLine()
    Dim p(0 To n - 1) As Integer 
    For i As Integer = 0 To n - 1
        p(i) = CType(input.split(" ")(i), Integer)
    Next
    
    Dim output As Integer = 0
    For i As Integer = 0 To n - 3
        If p(i) < p(i + 1) AndAlso p(i + 1) < p(i + 2) Then
            output += 1
        ElseIf p(i) > p(i + 1) AndAlso p(i + 1) > p(i + 2) Then
            output += 1
        End If
    Next

    Console.WriteLine(output.ToString())
  End Sub
end class


Measured memory_bytes: 13268
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        k: usize,
        s: String,
    };
    let mut ret = "".to_string();
    for (i, c) in s.chars().enumerate() {
        if i == k-1 {
            ret += &*(c.to_string().to_lowercase());
        } else {
            ret += &*(c.to_string());
        }
    }

    println!("{}", ret);

}



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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

ll solve(ll k) {
	if (k <= 9) {
		cout << k << endl;
		return 0;
	}
	vector<vector<vector<ll>>> dp(1010, vector<vector<ll>>(10));
	for (int i = 0; i < 10; i++) {
		dp[0][i].push_back(i);
	}
	k -= 9;
	while (true) {
		for (int digit = 1; digit < 1010; digit++) {
			ll c = pow(10, digit);
			for (int i = 1; i < 10; i++) {
				ll u = c * i;
				{
					for (int l = i - 1; l < i + 1; l++) {
						for (auto p : dp[digit - 1][l]) {
							ll next = u + p;
							if (k == 1) {
								cout << next << endl;
								return 0;
							}
							dp[digit][i].push_back(next);
							k--;
						}
					}
				}
				if (i != 9) {
					int t = i + 1;
					for (auto p : dp[digit - 1][t]) {
						ll next = u + p;
						if (k == 1) {
							cout << next << endl;
							return 0;
						}
						dp[digit][i].push_back(next);
						k--;
					}
				}
			}
			for (int a = 0; a < 2; a++) {
				for (auto p : dp[digit - 1][a]) {
					ll next = 0 + p;
					dp[digit][0].push_back(next);
				}
			}
		}
	}
	return 0;

}

int main(void)
{
	ll k;
	cin >> k;
	//for (int i = 1; i < 100; i++) {
	//	cout << i << "   ";
	//	solve(i);
	//}
	solve(k);
	return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define size 100000
#define NUM 998244353
#define ll long long int

int main()
{
	int n,m;
  cin>>n>>m;
  ll ans=0;
  ans+=(n*(n-1))/2;
  ans+=(m*(m-1))/2;
  cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

const int MAX_N = 2e5 + 200;

int n, ai[MAX_N];
ll pre[MAX_N];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &ai[i]), pre[i] = pre[i - 1] + ai[i];
    ll ans = 1e18;
    int lptr = 1, rptr = 3;
    for (int i = 2; i <= n - 2; i++)
    {
        while (lptr + 1 < i && abs((pre[i] - pre[lptr]) - pre[lptr]) >= abs((pre[i] - pre[lptr + 1]) - pre[lptr + 1]))
            lptr++;
        while (rptr + 1 < n && abs(pre[n] - pre[rptr] - (pre[rptr] - pre[i])) >= abs(pre[n] - pre[rptr + 1] - (pre[rptr + 1] - pre[i])))
            rptr++;
        ll part1 = pre[lptr], part2 = pre[i] - pre[lptr], part3 = pre[rptr] - pre[i], part4 = pre[n] - pre[rptr];
        ans = min(ans, max(abs(part1 - part2), max(abs(part1 - part3), max(abs(part1 - part4), max(abs(part2 - part3), max(abs(part2 - part4), abs(part3 - part4)))))));
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2560
require 'prime'

n = gets.to_i
array = gets.split().map(&:to_i)

gcd_l = []
array.each.with_index do |a, i|
	if i == 0
		gcd_l[0] = array[0]
	else
		gcd_l[i] = array[i].gcd(gcd_l[i-1])
	end
end

array.reverse!
gcd_r = []
array.each.with_index do |a, i|
	if i == 0
		gcd_r[0] = array[0]
	else
		gcd_r[i] = array[i].gcd(gcd_r[i-1])
	end
end

array.reverse!
gcd_r.reverse!

result = []
(0..array.size-1).each do |i|
	result[i] =
		if i == 0
			gcd_r[i+1]
		elsif i == array.size - 1
			gcd_l[i-1]
		else
			gcd_l[i-1].gcd(gcd_r[i+1])
		end
end

p result.max


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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll a;
    cin >> a;
    cout << (a + (a*a) + (a * a*a)) << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)

template<class Edge, class State>
struct dijkstra{
	using Cost = decltype(State{}.calc_cost(Edge{}));

	static vector<Cost> shortest_path(
		State s,
		const vector<vector<Edge>> & g,
		Cost max_dist
	) {
		vector<Cost> d(State::max_state_id() + 1, max_dist);
		d[s.state_id()] = 0;
		using P = pair<ll, State>;
		priority_queue<P, vector<P>, greater<P>> que;
		que.push(P(0, s));
		while (!que.empty()) {
			Cost cur_d; State cur;
			tie(cur_d, cur) = que.top();
			que.pop();
			auto v = cur.state_id();
			if (d[v] < cur_d) continue;
			for (auto e : g[cur.node_id]) if (cur.is_valid(e)) {
				State next = cur.calc_next(e);
				auto u = next.state_id();
				if (d[u] > d[v] + cur.calc_cost(e)) {
					d[u] = d[v] + cur.calc_cost(e);
					que.push(P(d[u], next));
				}
			}
		}

		return d;
	}
};

struct Edge{ ll to; ll cost; ll h; ll r; };
struct State{
	static ll max_state_id() { return 5000; }
	bool operator<(const State & rhs) const {
		return node_id < rhs.node_id;
	}

	ll node_id;
	// more infomation
	ll h, passport; // passport = 2^8

	ll state_id() { return node_id + h * 100; }
	bool is_valid(Edge e) { return h + e.h < 25; }
	State calc_next(Edge e) { return State{ e.to, e.h + h, passport }; }
	ll calc_cost(Edge e) {
		if ((passport & (1 << e.r)) != 0) return 0;
		return e.cost;
	}
};

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	while (true) {
		ll n, m, H, K;
		cin >> n >> m >> H >> K;
		if (n == 0) break;
		vl a(m), b(m), c(m), h(m), r(m);
		REP(i, m) {
			cin >> a[i] >> b[i] >> c[i] >> h[i] >> r[i];
			a[i]--, b[i]--, r[i]--;
		}
		ll S, T;
		cin >> S >> T; S--, T--;
		ll P; cin >> P;
		vl l(P), d(P);
		vvl k(P);
		REP(i, P) {
			cin >> l[i] >> d[i];
			k[i].resize(l[i]);
			REP(j, l[i]) { cin >> k[i][j]; k[i][j]--; }
		}

		vector<vector<Edge>> g(n);
		REP(i, m) {
			g[a[i]].push_back({ b[i], c[i], h[i], r[i] });
			g[b[i]].push_back({ a[i], c[i], h[i], r[i] });
		}
		
		ll max_dist = TEN(8);
		vl dp(1 << K, max_dist); dp[0] = 0;
		REP(i, P) {
			ll passport = 0;
			REP(j, l[i]) passport |= 1 << k[i][j];
			REP(j, 1 << K) dp[j | passport] = min(dp[j | passport], dp[j] + d[i]);
		}

		ll ans = max_dist;
		REP(passport, 1 << K) {
			auto dist = dijkstra<Edge, State>::shortest_path({ S, 0, passport }, g, max_dist);
			REP(i, H + 1) if (dist[State{ T, i, passport }.state_id()] != max_dist) {
				ans = min(ans, dp[passport] + dist[State{ T, i, passport }.state_id()]);
			}
		}

		cout << (ans == max_dist ? -1 : ans) << endl;
	}
	return 0;
}

Measured memory_bytes: 3416
import java.util.*;
import java.lang.*;

public class Main {

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] match = new int[]{6,2,5,5,4,5,6,3,7,6};
        Map<Integer,Integer> number = new HashMap<>();
        for(int m=0; m<M; m++){
            int a = sc.nextInt();
            number.put(a, match[a]);
        }

        int[] digit = new int[N+1];
        Arrays.fill(digit, -1000000);
        digit[0] = 0;
        int[] first = new int[N+1];

        for(int n=1; n<=N; n++){
            for(int d: number.keySet()){
                if(n-number.get(d)>=0 && digit[n]<=1+digit[n-number.get(d)]){
                    digit[n] = 1+digit[n-number.get(d)];
                    first[n] = d;
                }
            }
        }

        int m = N;
        while(m>0){
            System.out.print(first[m]);
            m -= match[first[m]];
        }
        System.out.println();
    }
}


Measured memory_bytes: 24532
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    string s, t;
    cin >> s >> t;

    int ans = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == t[i]) ++ans;
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
	int n;
	cin >> n;
	int cur = 100000;
	while(n--){
		cur = cur + cur * 0.05;
		if(cur%1000 != 0){
			cur += 1000-(cur%1000);
		}
	}
	cout << cur << endl;
}

Measured memory_bytes: 1160
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define lld long long
#define pi pair<lld,lld>
#define mod 1000000007
#define N 2000005
#define pb push_back
lld fact[N],ifact[N];
lld expo(lld a,lld b)
{
    if(b==0) return 1; if(b==1) return a%mod;
    lld z=expo(a,b/2);
    z=(z%mod*z%mod)%mod;
    if(b%2) z=(z*a)%mod;
    return z;
}
lld ncr(lld n,lld r)
{
    if(r>n) return 0;
    if(r==n) return 1;
    lld mm=fact[n]*ifact[n-r]%mod;
    mm=mm*ifact[r]%mod;
    return mm;
}

void pre(){
    fact[0] = 1;
    ifact[0] = 1;
    rep(i,1,N){
        fact[i] = i;
        fact[i] *= fact[i-1];
        fact[i] %= mod;;
        ifact[i] = expo(fact[i],mod - 2);
    }
}
vector < int > z_function ( string s ) {
    int n = (int)s.length();
    vector<int> z(n);
    for (int i = 1,l=0,r=0;i<n;++i){
        if (i<=r)
            z[i] = min(r-i+1,z[i-l]);
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]])
            ++z[i];
        if(i+z[i]-1>r)
            l=i,r=i+z[i]-1;
    }
    return z ;
}

lld max(lld a,lld b){return a>b?a:b;}
double dis(lld a,lld b,lld c,lld d)
{
    a=(a-c)*(a-c);
    b=(b-d)*(b-d);
    return sqrt(a+b);
}
lld n;
double d=0;
void find(int a[][2],int vis[],int i)
{
    for(int j=0;j<n;++j)
    {
        if(vis[j]) continue;
        else
        {
            vis[j]=1;
            d=d+dis(a[i][0],a[i][1],a[j][0],a[j][1]);
            find(a,vis,j);
            vis[j]=0;
        }
    }
}
int main()
{
    pre();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("/home/ankit/input_10.txt","r",stdin);
    // freopen("/home/ankit/out10.txt","w",stdout);
    lld x,y; cin>>x>>y;
    lld res=0;
    for(int i=0;i<=x;i++)
    {
        int p=x-i;
        int q=y-2*i;
        if(p==2*q)
        {
            res=res+ncr(i+q,i);
            res%=mod;
        }
    }
    cout<<res<<endl;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string T;
    cin >> T;
    int L = T.length();
    for (char &c : T) {
        if (c == '?') {
            c = 'D';
        }
    }
    cout << T << '\n';
    return 0;
}

Measured memory_bytes: 3780
#include<cstdio>

int n,ne,cur;
int a[100005];

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n; i++){
		scanf("%d",&cur);
		if(!a[cur]) {
			a[cur] = 1;
			ne ++;//多少不同的数字
		}
	}
	int ans;
	int pan = n - ne; //重复的数字
	if(pan % 2 == 0) ans = ne;
	else ans = ne - 1;
	printf("%d",ans);
}

Measured memory_bytes: 512
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N],color[N],d[N],f[N],tt;
void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0) continue;
    if(color[v]==WHITE){
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}

void dfs(){
  int u;
  for(u=0;u<n;u++){
    color[u]=WHITE;
  }
  tt=0;

  for(u=0;u<n;u++){
    if(color[u]==WHITE){
      dfs_visit(u);
    }
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u,v,k,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	M[i][j]=0;
      }
    }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();

  return 0;
}



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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A.at(i).at(j);
    }
  }
  
  for (int i = 0; i < H; i++){
    bool flag = true;
    
    for (int j = 0; j < W; j++) {
      if (A.at(i).at(j) == '#') {
        flag = false;
      }
    }
    
    if (flag) {
      for (int j = 0; j < W; j++) {
        A.at(i).at(j) = 'a';
      }
    }
  }
  
  for (int i = 0; i < W; i++){
    bool flag = true;
    
    for (int j = 0; j < H; j++) {
      if (A.at(j).at(i) == '#') {
        flag = false;
      }
    }
    
    if (flag) {
      for (int j = 0; j < H; j++) {
        A.at(j).at(i) = 'a';
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
    bool flag = false;
    
    for (int j = 0; j < W; j++) {
      if (A.at(i).at(j) != 'a') {
        cout << A.at(i).at(j);
        flag = true;
      }
    }
    
    if (flag) {
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/arc103/tasks/arc103_a

use std::collections::HashMap;

// https://qiita.com/penguinshunya/items/cd96803b74635aebefd6
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<i32>();
    let ais = read_vec::<i32>();
    if n == 2 {
        if ais[0] == ais[1] {
            println!("1")
        } else {
            println!("0")
        }
        return;
    }
    let mut even_histgram: HashMap<i32, i32> = Default::default();
    let mut odd_histgram: HashMap<i32, i32> = Default::default();
    for i in 0..ais.len() {
        let hist = if i % 2 == 0 {
            &mut even_histgram
        } else {
            &mut odd_histgram
        };
        let key = ais[i];
        if hist.get(&key).is_some() {
            *hist.get_mut(&key).unwrap() += 1
        } else {
            hist.insert(key, 1);
        }
    }
    let mut even_histgram_pair: Vec<(i32, i32)> = even_histgram.clone().into_iter().collect();
    let mut odd_histgram_pair: Vec<(i32, i32)> = odd_histgram.clone().into_iter().collect();
    even_histgram_pair.sort_by(|lhs, rhs| rhs.1.cmp(&lhs.1));
    odd_histgram_pair.sort_by(|lhs, rhs| rhs.1.cmp(&lhs.1));
    let count = if even_histgram_pair[0].0 != odd_histgram_pair[0].0 {
        n - even_histgram_pair[0].1 - odd_histgram_pair[0].1
    } else {
        if even_histgram_pair.len() <= 1 && odd_histgram_pair.len() <= 1 {
            n / 2
        } else if even_histgram_pair.len() <= 1 {
            n / 2 - odd_histgram_pair[1].1
        } else if odd_histgram_pair.len() <= 1 {
            n / 2 - even_histgram_pair[1].1
        } else {
            std::cmp::min(
                n - even_histgram_pair[1].1 - odd_histgram_pair[0].1,
                n - even_histgram_pair[0].1 - odd_histgram_pair[1].1,
            )
        }
    };
    println!("{}", count);
}


Measured memory_bytes: 11432
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    for (int i = 0; i < N; i++) {
      int number = sc.nextInt();
      min = Math.min(min, number);
      max = Math.max(max, number);
    }
    System.out.println(max - min);
  }
}


Measured memory_bytes: 21076
class BIT:
  def __init__(self,n):
    self.N = n
    self.data = [0]*(N+1)
  def bit_add(self,i,a):
    j = i+1
    while j<=N:
      self.data[j] += a
      j += j&-j
  def bit_sum(self,i):
    m = 0
    j = i+1
    while j>0:
      m += self.data[j]
      j -= j&-j
    return m
  def bit_search(self,x):
    i = 0
    m = 0
    j = 1<<(self.N.bit_length()-1)
    while j:
      if i+j<=N and self.data[i+j]+m<=x:
        i += j
        m += self.data[i]
      j >>= 1
    return i
N, *A = map(int, open(0).read().split())
bit = BIT(N)
ntoi = [0]*(N+1)
ans = 0
for i, a in enumerate(A):
  ntoi[a] = i
for i in range(1,N+1):
  j = ntoi[i]
  L = bit.bit_sum(j)
  R = N-L-1
  if L!=0:
    a = bit.bit_search(L-1)
  else:
    a = -1
  if R!=0:
    b = bit.bit_search(L)
  else:
    b = N
  ans += (j-a)*(b-j)*i
  bit.bit_add(j,1)
print(ans)

Measured memory_bytes: 84356
S = input()
Q = int(input())
cnt = 0
mae = []
usiro = []
for _ in range(Q):
    q = input().split()
    if len(q) == 1:
        cnt += 1
    else:
        if cnt % 2 == 0:
            if int(q[1]) == 1:
                mae.append(q[2])
            else:
                usiro.append(q[2])
        else:
            if int(q[1]) == 1:
                usiro.append(q[2])
            else:
                mae.append(q[2])

mae = mae[::-1]
S = "".join(mae) + S + "".join(usiro)

if cnt % 2 == 1:
    S = S[::-1]
print(S)

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

int main() {
  long h, w;

  cin >> h >> w;

  if (h == 1 || w == 1)
    cout << 1;
  else if (h * w % 2)
    cout << h * w / 2 + 1;
  else
    cout << h * w / 2;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int n, m;
    cin>>n>>m;
    char a[n][m];
    string s="";
    for(int i = 0; i < n; i++){
        string pr="";
        for(int j = 0; j < m; j++){
            cin>>a[i][j];
            pr+=a[i][j];
        }
        s+=pr;
        s+='\n';
        s+=pr;
        s+='\n';
    }   
    cout<<s;
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
long long  N,A,B;
long long value[51];
long long dp[51][51];
bool comp(long long a,long long b)
{
    return a>b?true:false;
}


void init()
{
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int i=1;i<=50;i++)
	{
		dp[i][0]=1;
		for(int j=1;j<=i;j++)
			dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
	}
}
int main(void)
{
    cin>>N>>A>>B;
    init();
    for(int i=0;i<N;i++)
    {
        cin>>value[i];
    }
    sort(value,value+N,comp);
    double sum=0.0;
    for(int i=0;i<=A-1;i++)
    {
        sum+=value[i];
    }
    long long  num=0,k=0;
		for(int i=0;i<N;i++)
		{
			if(value[i]==value[A-1])
			{
				num++;
				if(i<A)
					k++;
			}
		}
		long long ans=0;
		if(k==A)//前A个相同,可以增加个数
		{
			for(int i=A;i<=B;i++)
				ans+=dp[num][i];
		}
		else
			ans+=dp[num][k];
    printf("%.15f\n",sum/A);
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 256
// 2014/06/03 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string s;
		cin >> s;

		if(cin.eof())
			break;

		int cnt = 0;
		string::size_type index = 0;
		while(true){
			index = s.find("JOI", index);

			if(index==string::npos)
				break;

			cnt++;
			index++;
		}
		cout << cnt << '\n';
 
		cnt = 0;
		index = 0;
		while(true){
			index = s.find("IOI", index);

			if(index==string::npos)
				break;

			cnt++;
			index++;
		}
		cout << cnt << '\n';
	}

	return 0;
}

Measured memory_bytes: 1200
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;


bool opx[60][60],opy[60][60];
bool vis[60][60];
int W,H,N;
int dir[4][2]={1,0,-1,0,0,1,0,-1};

struct node
{
    int x,y,step;
    node(){};
    node(int _x,int _y,int _step){
        x=_x;y=_y;step=_step;
    }
};
node S,E;
queue <node > q;
int bfs()
{
    while(!q.empty()) q.pop();
    q.push(S);
    memset(vis,0,sizeof(vis));
    vis[S.x][S.y]=1;

    while(!q.empty()){
        node now=q.front();
        q.pop();
        for(int i=0;i<4;i++){
            if(i==0&&opx[now.x+1][now.y]) continue;
            if(i==1&&opx[now.x][now.y]) continue;
            if(i==2&&opy[now.x][now.y+1]) continue;
            if(i==3&&opy[now.x][now.y]) continue;
            node sun;
            sun.x=now.x+dir[i][0];
            sun.y=now.y+dir[i][1];
            if(vis[sun.x][sun.y]||(sun.x<0)||(sun.x>=W)||(sun.y<0)||(sun.y>=H))
                continue;
            vis[sun.x][sun.y]=1;
            sun.step=now.step+1;
            if(sun.x==E.x&&sun.y==E.y) return sun.step;
            q.push(sun);
        }
    }
    return -1;
}


int main()
{
    scanf("%d%d%d",&W,&H,&N);
    memset(opx,0,sizeof(opx));
    memset(opy,0,sizeof(opy));
    for(int i=1;i<=N;i++){
        int t1,t2,t3,t4;
        scanf("%d%d%d%d",&t1,&t2,&t3,&t4);
        if(t1==t3){
            if(t4<t2) swap(t2,t4);
            for(int j=t2;j<t4;j++){
                opx[t1][j]=1;
            }
        }
        else if(t2==t4){
            if(t3<t1) swap(t1,t3);
            for(int j=t1;j<t3;j++){
                opy[j][t2]=1;
            }
        }
    }

    scanf("%d%d%d%d",&S.x,&S.y,&E.x,&E.y);
    S.step=0;
    int num1,ans=0;
    num1=bfs();

    for(int i=1;i<W;i++){
        for(int j=0;j<H;j++){
            if(!opx[i][j]){
                opx[i][j]=1;
                ans=max(ans,bfs()-num1);
                opx[i][j]=0;
            }
        }
    }

    for(int i=0;i<W;i++){
        for(int j=1;j<H;j++){
            if(!opy[i][j]){
                opy[i][j]=1;
                ans=max(ans,bfs()-num1);
                opy[i][j]=0;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

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

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve()
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int n = int.Parse(Console.ReadLine());
			string s = Console.ReadLine();

			// w -- W E E W W -- e
			//      < > > < <
			int[,] sum = new int[n, 2];
			for (int i = 0; i < n; i++) {
				if (i > 0) {
					sum[i, 0] = sum[i - 1, 0];
				}
				if (s[i] == 'W') {
					sum[i, 0]++;
				}
			}
			for (int i = n - 1; i >= 0; i--) {
				if (i < n - 1) {
					sum[i, 1] = sum[i + 1, 1];
				}
				if (s[i] == 'E') {
					sum[i, 1]++;
				}
			}
			//for (int i = 0; i < n; i++) {
			//	System.Diagnostics.Debug.Write($"{s[i]} ");
			//}
			//System.Diagnostics.Debug.WriteLine($"");
			//for (int j = 0; j < 2; j++) {
			//	for (int i = 0; i < n; i++) {
			//		System.Diagnostics.Debug.Write($"{sum[i, j]} ");
			//	}
			//	System.Diagnostics.Debug.WriteLine($"");
			//}
			int ans = sum[0, 0] + sum[0, 1] - 1;
			for (int i = 0; i < n; i++) {
				ans = Math.Min(ans, sum[i, 0] + sum[i, 1] - 1);
			}
			Console.WriteLine(ans);

		}
	}
}


Measured memory_bytes: 30984
from collections import Counter
s=input()
cnt=Counter(s)
result=True
if cnt.get("N",False) or cnt.get("S",False):
    if cnt.get("N",False) and cnt.get("S",False):
        pass
    else:
        result=False
if cnt.get("E",False) or cnt.get("W",False):
    if cnt.get("E",False) and cnt.get("W",False):
        pass
    else:
        result=False
print("Yes" if result else "No")

Measured memory_bytes: 3316
#include <iostream>

using namespace std;
int main(void)
{
  int r, D, x2000;
  cin >> r >> D >> x2000;

  int x = x2000;
  for (int i = 0; i < 10; i++) {
    x = r * x - D;
    cout << x << endl;
  }
  return 0;
}


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

const int MAX_N = 12;
const int MAX_M = 12;

void solve(long long N,
           long long M,
           long long X,
           long long C[MAX_N],
           long long A[MAX_N][MAX_M]) {
    long long ans = __INT_MAX__;
    for (int i = 0; i < 1 << N; i++) {
        bitset<12> bs(i);
        long long sum[M] = {};
        long long price = 0;
        for (int j = 0; j < N; j++) {
            if (bs[j]) {
                price += C[j];
                for (int k = 0; k < M; k++) {
                    sum[k] += A[j][k];
                }
            }
        }
        // check
        bool failed = false;
        for (int k = 0; k < M; k++) {
            if (sum[k] < X) {
                failed = true;
                break;
            }
        }
        if (!failed) {
            ans = min(ans, price);
        }
    }
    if (ans == __INT_MAX__) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  long long X;
  scanf("%lld", &X);
  long long C[MAX_N];
  long long A[MAX_N][MAX_M];
  for (int i = 0; i < N; i++) {
    scanf("%lld", &C[i]);
    for (int j = 0; j < M; j++) {
      scanf("%lld", &A[i][j]);
    }
  }
  solve(N, M, X, C, A);
  return 0;
}


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

using namespace std;

using ll = long long;

struct _IN {
    _IN() {
        ios::sync_with_stdio(0);
        cin.tie(0);
    }
    template <typename T>
    operator T() const {
        T x;
        cin >> x;
        return x;
    }
    template <typename Container>
    void operator()(Container& c) {
        for (auto& x : c)
            cin >> x;
    }
} IN;

int main() {
    int N = IN;
    vector<ll> As(N + 1);
    IN(As);
    vector<ll> tot(N + 1);
    tot[N] = As[N];
    for (int i = N - 1; i >= 0; i--) {
        tot[i] = As[i] + tot[i + 1];
    }
    ll ans = 0;
    ll avail = 1;
    for (int i = 0; i <= N; i++) {
        if (avail < As[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans += min(avail, tot[i]);
        avail -= As[i];
        if (avail < (1ll << 60))
            avail *= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4784
import numpy

n = int(input())
s = input()

li = numpy.asarray([1 if i == 'W' else 0 for i in s])
w = numpy.cumsum(li)
e = numpy.cumsum(1 - li[::-1])[::-1]

su = w + e
ans = min(su) - 1

print(ans)


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

#define rep_(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)
#define rrep_(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rrep_(v, 0, n - 1)
#define rlep(v, n) rrep_(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define eachv(v, i) rep(i, v.size())
#define reachv(v, i) rrep(i, v.size())
#define debug(x) std::cerr << #x << " = " << x << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int main()
{
    int a, b, c;
    a = in();
    b = in();
    c = in();
    puts(a && b || c ? "Open" : "Close");
    return (0);
}

Measured memory_bytes: 1168
import sys
from math import cos, sqrt, pi

a, b, h, m = map(int, sys.stdin.readline().split())

def main():
    d = 6 * m 
    c = 30 * (h + m / 60)
    theta = abs(d - c)
    ans = sqrt(a ** 2 + b ** 2 - 2*a*b*cos(theta * 2 * pi / 360))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9512
#include <stdio.h>
#include <stdlib.h>
int main(void) {
    long long int N,K,Q;
    scanf("%lld %lld %lld",&N,&K,&Q);

    long long int ans[Q];
    for (long long int i=1;i<=Q;i++){
        scanf("%lld",&ans[i]);
    }
    if (K>Q) {for (int i=0;i<N;i++){printf("Yes\n");
    }return 0;}

long long int array[N+1];
memset(array,0,(N+1)*sizeof(N+1));
for (long long int i=1;i<=Q;i++){
    array[ans[i]]++;
}
long long int max=0;
for (long long int j=1;j<=N;j++){
    if (array[j]>max) max=array[j];
}

for (long long int j=1;j<=N;j++){
    if (array[j]+K<=Q) printf("No\n");
    else printf("Yes\n");
}

return EXIT_SUCCESS;
}


Measured memory_bytes: 2048
def is_prime(n):
    for i in range(2, int(n**(1/2))+1, 1):
        if n%i == 0:
            return False
    return n != 1

def lnum(n):  # Like number
    if is_prime(n) and is_prime((n+1)//2):
        return True
    else:
        return False

MAX = 10**5+10
a = [0]*MAX
for i in range(MAX):
    if lnum(i):
        a[i] = 1
    else:
        continue

s = [0]*MAX
for i in range(MAX-1):
    s[i+1] = s[i] + a[i]
    
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(s[r+1]-s[l])

Measured memory_bytes: 7124
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int n;
    cin >> n;
    vi p(n);
    for(int i=0; i<n; i++){
        cin >> p.at(i);
    }
    int counter = 0;
    for(int i=0; i<n; i++){
        if(p.at(i) != i+1){
            counter++;
        }
    }
    if(counter>2){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
}


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

int main() {
    int N;
    cin >> N;
    int P = N;
    bool ok = 0;
    if((N*100)%108 == 0){
        cout << N / 1.08 << endl;
      	ok = 1;
    }
    else{
        N = N / 1.08;
        int a = N;

        for(int i = 0;i<2;i++){
            int b = (a+i)*1.08;
            if(b==P){
                ok = 1;
            }
            if(ok == 1){
                int ans = a+i;
                cout << ans << endl;
                break;
            }
        }
    }

    
    if (ok == 0){
        cout << ":(" << endl;
    }

    
}

Measured memory_bytes: 256
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>
#include <atcoder/segtree>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &bb) {
    for (int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &bb) {
    for (int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}

int op(int a, int b) {return std::max(a, b);}
int e() {return 0;}

using namespace std;

int main() {
    int n, k; cin >> n >> k;
    vector<int> da(n);
    rip(i,n,0) {
        cin >> da[i];
    }
    atcoder::segtree<int, op, e> st(300300);
    vector<int> dp(n);
    int ans = 0;
    rip(i,n,0) {
        int now = st.prod(max(da[i]-k, 0), min(da[i]+k+1, 300300));
        dp[i] = now+1;
        // cout << dp[i];
        st.set(da[i], dp[i]);
        chmax(ans, dp[i]);
    }
    cout << ans << endl;

}

Measured memory_bytes: 9732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  int sum=0;
  vector<int> vec(B);
  for(int i=0;i<B;i++){
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  if(sum>A){
    cout << -1 << endl;
  }
  else{
    cout << A-sum << endl;
  }
}

Measured memory_bytes: 3664
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define LOG 20
//std::ios::sync_with_stdio(false);
int par[200005][LOG];
int level[200005];
//std::ios::sync_with_stdio(false);
vector< vi> adj(100005),wet(100005);
ll d[100005];

int dfs(int cur,int prev,int lev)
{
	level[cur]=lev;
	par[cur][0]=prev;
	int i;
	rep(i,adj[cur].size())
	{
		if(adj[cur][i]!=prev)
		{
			d[adj[cur][i]]=d[cur]+wet[cur][i];
			dfs(adj[cur][i],cur,lev+1);
		}
	}
	return 0;
}
int lca(int p,int q){
	int i;
	if(level[p]<level[q]){
		//cout<<"Hi'<"<<endl;
		swap(p,q);
	}
	fd(i,LOG-1,0){
		if(level[p]-(1<<i)>=level[q]){
			//cout<<p<<" "<<i<<endl;
			p=par[p][i];
		}
	}
	//cout<<p<<endl;
	if(p==q){
		return p;
	}
	fd(i,LOG-1,0){
		if(par[p][i]!=par[q][i]){
			p=par[p][i];
			q=par[q][i];
		}
	}
	return par[p][0];

}
int main(){
	std::ios::sync_with_stdio(false);
	int n,i,j;
	int a,b,c,x,y;
	ll res;
	cin>>n;
	rep(i,n-1)
	{
		cin>>a>>b>>c;
		a--;
		b--;
		adj[a].pb(b);
		adj[b].pb(a);
		wet[a].pb(c);
		wet[b].pb(c);
	}
	d[0]=0;
	//return 0;
	dfs(0,-1,0);
	f(j,1,LOG){
    	rep(i,n){
    		if(par[i][j-1]==-1){
    			par[i][j]=-1;
    		}
    		else{
    			par[i][j]=par[par[i][j-1]][j-1];
    		}
    	}
    }
    //return 0;
	int q,k;
	cin>>q>>k;
	k--;
	rep(i,q){
		res=0;
		cin>>x>>y;
		x--;
		y--;
		//return 0;
		a=lca(x,k);
		b=lca(y,k);
		//cout<<a<<" "<<b<<" "<<d[x]<<" "<<d[k]<<endl;
		//return 0;
		res+=d[x]-d[a]+d[k]-d[a];
		res+=d[y]-d[b]+d[k]-d[b];
		cout<<res<<endl;
	}
} 


Measured memory_bytes: 28800
#include <iostream>
#include <cmath>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;
int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    vector<int> d(N,0);
    
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }
    
    int num[110] = {0};
    
    for(const auto& itr : d){
        num[itr]++;
    }
    
    int ans = 0;
    for(int i = 0; i <= 100; ++i){
        if(num[i]){
            ans++;
        }
    }
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import           Control.Monad
import           Data.Maybe

input :: IO (String, String)
input = do
  s <- getLine
  t <- getLine
  return (s, t)


diff :: String -> String -> Maybe Int
diff x [] = Just 0
diff [] y = Nothing
diff (x:xs) (y:ys) = if x /= y then (liftM2 (+)) (Just 1) (diff xs ys) else diff xs ys


check :: (String, String) -> [Maybe Int] -> [Maybe Int]
check ([], t) ns       = ns
check (s@(_:ss), t) ns = check (ss, t) ((diff s t) : ns)

output :: [Maybe Int] -> Int
output ns = fromJust . minimum . filter (/= Nothing) $ ns

main :: IO ()
main = do
  (s, t) <- input
  let
    result = output $ check (s, t) []
  print result


Measured memory_bytes: 4788
#include<bits/stdc++.h>
#define ll long long int
#define vll vector<pair<ll, ll> >
#define vl vector<ll>
#define vi vector<int>
#define vii vector<pair<int, int> >
const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
using namespace std;

ll power_mod(ll x, ll y, ll p)
{
	ll ans = 1;
	x = x%p;
	if(x==0)
	return p;

	while(y>0)
	{
		if(y&1)
		{
			ans = (ans*x)%p;
		}
		y = y>>1;
		x = (x*x)%p;
	}
	return ans;
} 

const int n = 200005;
int distt[n], dista[n];
vector<int> adj[n];


void calc_t(int v, int p)
{
    if(p==-1)
    {
        distt[v] = 0;
    }
    else distt[v] = distt[p] + 1;
    int i;
    for(i=0;i<adj[v].size();i++)
    {
        if(adj[v][i]==p)
        continue;
        
        calc_t(adj[v][i], v);
    }
}

void calc_a(int v, int p)
{
    if(p==-1)
    {
        dista[v] = 0;
    }
    else dista[v] = dista[p] + 1;
    int i;
    for(i=0;i<adj[v].size();i++)
    {
        if(adj[v][i]==p)
        continue;
        
        calc_a(adj[v][i], v);
    }
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int i,j,k,l,m,n,u,v;
	cin>>n>>u>>v;
	for(i=0;i<n-1;i++)
	{
	    int x,y;
	    cin>>x>>y;
	    x--;
	    y--;
	    adj[x].push_back(y);
	    adj[y].push_back(x);
	}
	
	calc_t(u-1, -1);
	calc_a(v-1, -1);
	
	
	//cout<<"\ndistt[v]:"<<distt[v-1]<<" size:"<<adj[u-1].size();
	if(distt[v-1]==2&&adj[u-1].size()==1)
	{
	    cout<<1;
	    return 0;
	}
	
	int maxcount = 0;
	for(i=0;i<n;i++)
	{
	    
	    int temp = dista[i] - distt[i];
	    if(temp>=0)
	    maxcount = max(maxcount, dista[i]-1);
	    //cout<<"\ni:"<<i<<" dista:"<<dista[i]<<" distt:"<<distt[i]<<" temp:"<<temp<<" maxcount:"<<maxcount;
	}
	cout<<maxcount;
	return 0;
	
}


Measured memory_bytes: 15980
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main() {
	/*string s;
	cin >> s;
	rep(i, 4) {
		int a = 0;
		rep(j, 4) { 
			if (s[i] == s[j])a++;
		}
		if (a != 2) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";*/

	int n;
	cin >> n;
	vector<int>p(n + 1);
	int i;
	for (i = 1; i < n + 1; i++)cin >> p[i];
	int ans = 0;
	for (i = 2; i < n; i++) {
		if (p[i] != min({ p[i - 1],p[i],p[i + 1] }) && p[i] != max({ p[i - 1],p[i],p[i + 1] }))ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
hat = [0, 0, 0]
MOD = 10 ** 9 + 7
answer = 1
for i in range(N):
    x = hat.count(A[i])
    if x == 0:
        answer = 0
    else:
        answer *= x
        j = hat.index(A[i])
        hat[j] += 1

print(answer%MOD)
# 30

Measured memory_bytes: 14008
n = int(input())
a = list(map(int,input().split()))
l,r = {},{}
for i in range(n):
  xl = i+a[i]
  if xl in l:
    l[xl] += 1
  else:
    l[xl] = 1
  
  xr = i-a[i]
  if xr in r:
    r[xr] += 1
  else:
    r[xr] = 1

ans = 0
for x in l:
  if x in r:
    ans += l[x] * r[x]
print(ans)

Measured memory_bytes: 56732
n = int(input())
t, a = map(int, input().split())
list = [int(i) for i in input().split()]

dif_list = []
answer = 0

for i in range(n):
    t_i = t - list[i] * 0.006
    t_i_dif = abs(a - t_i)
    dif_list.append(t_i_dif)
    if min(dif_list) == t_i_dif:
        answer = i + 1

print(answer)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <iomanip>
#define ll long long int
#define ld long double
#define IOS cin.tie(NULL);cout.tie(NULL)
#define f first
#define inf 100000000000000000
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define sc(i) scanf("%lld",&i);
#define s second
#define pb push_back
#define forn(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
ll const mod=998244353;
ll gcdfun(ll a , ll b)
{
   if(b==0) return a;
   a%=b;
   return gcdfun(b,a);
}
// int arr1[1000109];
// set<ll> sieve;
// void sievefun(ll n){
//     for(ll i=2;i<=n;i++){
//         if(arr1[i]==0){
//             for(ll j=i*i;j<=n;j+=i){
//                 arr1[j]=1;
//             }
//         }
//     }
//     for(ll i=2;i<=n;i++){
//     	if(arr1[i]==0)sieve.insert(i);
//     }
// }
ll power(ll x, ll y,ll m) {
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2,m)%m;
	if (y%2 == 0)
		return ((temp)*(temp))%m;
	else
		return (((x)%m)*((temp*temp)%m))%m;
}
// struct tt{
// 	ll val,cnt;
// };
// ll a[1000009]; 
// tt tree[5000009];
// ll num=1000000000;
// void build(int node,int start,int end){
// 	int mid=(start+end)/2;
// 	if(start==end){
// 		tree[node].val=a[start];
// 		tree[node].cnt=1;
// 		return ;
// 	}
// 	build(2*node,start,mid);
// 	build(2*node+1,mid+1,end);
// 	ll temp=gcdfun(tree[2*node].val,tree[2*node+1].val);
// 	tree[node].val=temp;
// 	if(temp==tree[2*node].val)tree[node].cnt+=tree[2*node].cnt;
// 	if(temp==tree[2*node+1].val)tree[node].cnt+=tree[2*node+1].cnt;
	
// }
// // void update(int node,int start,int end,int index,ll num){
// // 	int mid=(start+end)/2;
// // 	if(start==end){
// // 		tree[node]+=num;
// // 		return ;
// // 	}
// // 	if(start<=index&&index<=mid){
// // 		update(2*node,start,mid,index,num);
// // 	}
// // 	if(index>mid&&index<=end){
// // 		update(2*node+1,mid+1,end,index,num);
// // 	}
// // 	tree[node]=tree[2*node]+tree[2*node+1];
// // }
// tt query(int node,int start,int end,int l,int r){
// 	int mid=(start+end)/2;
// 	if(start>=l&&end<=r)return tree[node];
// 	if(start>r||end<l){
// 		tt temp={0,0};
// 		return temp;
// 	}
// 	tt L=query(2*node,start,mid,l,r);
// 	tt R=query(2*node+1,mid+1,end,l,r);
// 	tt temp;
// 	if(L.val==0)return R;
// 	if(R.val==0)return L;
// 	temp.cnt=0;
// 	temp.val=(gcdfun(L.val,R.val));
// 	if(temp.val==L.val)temp.cnt+=L.cnt;
// 	if(temp.val==R.val)temp.cnt+=R.cnt;
// 	return temp;
// }
ll dp[3009][3009];
ll m;
int main()
{	//sievefun(100000);
	// cout << fixed << setprecision(10);
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll T;
	// cin>>T;
	T=1;
	forn(_,T){
		ll n;
		cin>>n;
		m=1000000007;
		string s;
		cin>>s;
		forn(i,n){
			dp[0][i+1]=1;
		}
		forn(i,n-1){
			if(s[i]=='<'){
				for(int j=2;j<=i+2;j++){
					dp[i+1][j]=(dp[i+1][j-1]+dp[i][j-1])%m;
				}
			}else{
				for(int j=i+1;j>=1;j--){
					dp[i+1][j]=(dp[i][j]+dp[i+1][j+1])%m;
				}
			}
		}
		// for(int i=0;i<=n-1;i++){
		// 	for(int j=1;j<=n;j++)cout<<dp[i][j]<<" ";
		// 		cout<<"\n";	
		// }
		ll ans=0;
		forn(i,n)ans=(ans+dp[n-1][i+1])%m;
		cout<<ans<<"\n";
	}

}

Measured memory_bytes: 69120