akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    string S;
    std::cin >> S;
    int K;
    std::cin >> K;

    vector<int> table(S.size());
    REP(i, S.size()) {
        table[i] = 'z' - S[i] + 1;
        table[i] = (table[i] == 26) ? 0 : table[i];
    }

    REP(i, table.size()) {
        if(table[i] <= K) {
            K -= table[i];
            table[i] = 0;
        }
    }

    if(K != 0) {
        table.back() -= K % 26;
        if(table.back() < 0) table.back() += 26;
    }

    REP(i, table.size()) {
        if(table[i] == 0) {
            std::cout << 'a';
        }
        else {
            char c = 'z' - (table[i] - 1);
            std::cout << c;
        }
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 976
N, Y = map(int, input().split())

for x in range(N + 1):
    for y in range(N + 1 - x):
        z = N - x - y
        if x * 10000 + y * 5000 + z * 1000 == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)


Measured memory_bytes: 65420
#include <iostream>
#include <string>

using namespace std;

int main(void){
  string a,b,c;
  
  cin >> a >> b >> c;
  
  cout << (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0] ? "YES" : "NO") << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int a[200009];
int main()
{
    long long int n,sum=0;
    scanf("%lld",&n);
    for(long long int i=1; i<=n; i++)
    {
        scanf("%lld",&a[i]);
        a[i]-=i;
    }
    sort(a+1,a+n+1);
    long long int ans=a[n/2+1];
    for(long long int i=1; i<=n; i++)
        sum+=abs(a[i]-ans);
    printf("%lld\n",sum);
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll gcd(ll a, ll b)
{
    ll tmp;
    ll c;
    if (a < b)
    {
        tmp = a;
        a = b;
        b = tmp;
    }

    do
    {
        c = a % b;
        a = b;
        b = c;
    } while (c != 0);

    return a;
}

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

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

    vector<ll> a(n);

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

    ll ans = a[0];

    for (int i = 1; i < n; i++)
    {
        ans = gcd(ans, a[i]);
    }

    cout << ans << endl;
}


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

int main() {
  int X,Y;
  cin >> X >> Y;
  
  if ((4*X - Y) % 2 == 0 && (4*X - Y) >= 0 && 2*X <= Y){
    cout <<"Yes"<< endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(1, N):
        head = S[:i]
        tail = S[i:]
        commons = set(head) & set(tail)
        ans = max(ans, len(commons))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <stdio.h>

int main(void)
{
	int m[10];
	int max1 = 0, max2 = 0, max3 = 0;
	int i;
	
	for (i = 0; i < 10; i++){
		scanf("%d", &m[i]);
	}
	
	for (i = 0; i < 10; i++){
		if (max1 <= m[i]){
			/*max1 = m[i];
			max2 = max1;*/
			max3 = max2;
			max2 = max1;
			max1 = m[i];
		}
		else if (max2 <= m[i]){
			max3 = max2;
			max2 = m[i];
		}
		else if (max3 <= m[i]){
			max3 = m[i];
		}
	}
	
	printf("%d\n%d\n%d\n", max1, max2, max3);
	
	return (0);
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int A, B;
    cin >> A >> B;
    int num=-1;
    for (int i=1;;i++){
        int a = (i * 8) / 100;
        int b = (i * 10) / 100;
        if(a==A&&b==B){
            num = i;
            break;
        }
        if(A<a&&B<b){
            break;
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

const ll MOD = 1000000007LL;
int n;
vector <int> edge[100005];
ll dp[100005][2];

void dfs(int cur, int par) {
    dp[cur][0] = dp[cur][1] = 1;
    for (auto to : edge[cur]) {
        if (to == par) continue;
        dfs(to, cur);
        dp[cur][0] = (dp[to][0] + dp[to][1]) % MOD * dp[cur][0] % MOD;
        dp[cur][1] = dp[cur][1] * dp[to][0] % MOD;
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    dfs(0, -1);

    cout << (dp[0][0] + dp[0][1]) % MOD << "\n";
    return 0;
}

Measured memory_bytes: 14208
#include<iostream>
#include<string>
using namespace std;
int main () {
  int one = 0;
  int zero = 0;
  string S;
  cin >> S;
  for (int i = 0; i < S.size(); i ++) {
    if (S[i] == '1') one ++;
    else zero ++;
  }
  if (one < zero) cout << one * 2 << endl;
  else cout << zero * 2 << endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
		int n, m;
		cin >> n >> m;
		vector < bool > states(n + 5, 0);
		vector < int > penalty(n + 5, 0);
		int AC = 0;
		for (int i = 1; i <= m; i++) {
			int x;
			string y;
			cin >> x >> y;
			if (y == "WA") {
				if (states[x] == 0) penalty[x]++;
			}
			if (y == "AC") {
				if (!states[x]) {
					states[x] = 1;
					AC++;
				}
			}
		}
		int ans_penalty = 0;
		for (int i = 1; i <= n; i++) {
			if (states[i]) {
				ans_penalty += penalty[i];
			}
		}
		cout << AC << " " << ans_penalty << "\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t A, B, C, D;

    std::cin >> A >> B >> C >> D;

    auto check = [&]() {
        while (true) {
            C -= B;
            if (C <= 0) return "Yes";
            A -= D;
            if (A <= 0) return "No";
        }
    };

    std::cout << check() << std::endl;

    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;

#define SIZE 400
#define LLINF 1000000000000000000LL

int swapH[][2] = {{0, 1}, {0, 8}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8} };

int swapV[][2] = {{0, 6}, {0, 3}, {1, 4}, {1, 7}, {2, 5}, {2, 8}, {3, 6}, {4, 7}, {5, 8} };

int b[9], g[9];
int gHash;

void toArray(int *b, int hash) {
  for (int i=8; i>=0; i--) {
    b[i] = hash % 9;
    hash /= 9;
  }
}

int toHash(int *b) {
  int res = 0;
  for (int i=0; i<9; i++)
    res = res * 9 + b[i];

  return res;
}

int H, V;

int base9[9];

int swapp(int hash, int a, int b) {
  int p = hash / base9[a] % 9;
  int q = hash / base9[b] % 9;

  return hash + (p - q) * base9[b] + (q - p) * base9[a];
}

int isOK(int hash, int a, int b) {
  int r = hash / base9[a] % 9;
  int s = hash / base9[b] % 9;
  return r == 0 || s == 0;
}

ll dfs(ll cost = 0) {
  int hash = toHash(b);

  priority_queue<pair<ll,int> > pq;
  set<int> memo;

  pq.push({0, hash});

  while(pq.size()) {
    auto p = pq.top();
    pq.pop();

    int hash = p.second;
    ll cost = -p.first;

    if (memo.find(hash) != memo.end()) continue;
    memo.insert(hash);

    if (hash == gHash) {
      return cost;
    }

    for (int i=0; i<9; i++) {
      if (isOK(hash, swapH[i][0], swapH[i][1]))
        pq.push({-cost-H, swapp(hash, swapH[i][0], swapH[i][1])});
    }

    for (int i=0; i<9; i++) {
      if (isOK(hash, swapV[i][0], swapV[i][1]))
        pq.push({-cost-V, swapp(hash, swapV[i][0], swapV[i][1])});
    }
  }

  return LLINF;
}

bool solve() {

  scanf("%d%d", &H, &V);

  if (!H) return false;

  for (int i=0; i<9; i++)
    scanf("%d", b+i);

  for (int i=0; i<9; i++)
    scanf("%d", g+i);

  gHash = toHash(g);

  ll ans = dfs();

  assert(ans < LLINF);

  printf("%lld\n", ans);

  return true;
}

int main() {

  base9[8] = 1;

  for (int i=7;i >=0; i--)
    base9[i] = base9[i+1] * 9;

  while(solve());
  return 0;
}



Measured memory_bytes: 25808
from math import sqrt

n = int(input())
sin60 = sqrt(3) / 2
cos60 = 1 / 2


def koch(x1, y1, x2, y2, depth):
    global sin60, cos60, n
    if depth > n:
        return
    dx, dy = x2 - x1, y2 - y1
    dx3, dy3 = dx / 3, dy / 3
    xs, ys = x1 + dx3, y1 + dy3
    xt, yt = x2 - dx3, y2 - dy3
    xu, yu = xs + cos60 * dx3 - sin60 * dy3, ys + sin60 * dx3 + cos60 * dy3
    depth += 1
    for xy in koch(x1, y1, xs, ys, depth):
        yield xy
    yield (xs, ys)
    for xy in koch(xs, ys, xu, yu, depth):
        yield xy
    yield (xu, yu)
    for xy in koch(xu, yu, xt, yt, depth):
        yield xy
    yield (xt, yt)
    for xy in koch(xt, yt, x2, y2, depth):
        yield xy


print(0.0, 0.0)
for xy in koch(0.0, 0.0, 100.0, 0.0, 1):
    print(*xy)
print(100.0, 0.0)

Measured memory_bytes: 7804
#include<iostream>
using namespace std;
int a,b;

int main(){
	ios::sync_with_stdio(0);
	cin>>b>>a;
	if(a==100)++a;
	cout<<a;
	for(int i=1;i<=b;++i)cout<<"00";
	cout.put('\n');
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

#include <bits/stdc++.h>

using namespace std;

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

	string s;
	cin >> s;
	int head = 0, tail = s.size() - 1;
	int ans = 0;
	while (head < tail)
	{
		if (s[head++] != s[tail--])
			ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        sps: [(String, i64); n],
    }
    let mut sps_tmp = vec![];
    for (index, sp) in sps.iter().enumerate() {
        sps_tmp.push((sp.0.clone(), -sp.1, index + 1));
    }
    sps_tmp.sort();
    for sp_tmp in sps_tmp {
        println!("{}", sp_tmp.2);
    }
}


Measured memory_bytes: 4352
package main

import "fmt"

func main() {
	var sd, t string
	fmt.Scan(&sd)
	fmt.Scan(&t)

	lensd := len(sd)
	lent := len(t)

	for i := lensd - lent; i >= 0; i-- {
		is_matched := true
		for j := 0; j < lent; j++ {
			if sd[i + j] != '?' && sd[i + j] != t[j] {
				is_matched = false
				break
			}
		}
		if is_matched {
			s := ""
			for k := 0; k < lensd; k++ {
				if i <= k && k < i + lent {
					s += string(t[k - i])
				} else {
					if sd[k] == '?' {
						s += "a"
					} else {
						s += string(sd[k])
					}
				}
			}
			fmt.Println(s)
			return
		}
	}
	fmt.Println("UNRESTORABLE")
}

Measured memory_bytes: 512
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back

#define all(x) x.begin(),x.end()
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
int h,w;char fi[444][444];
bool used[444][444];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ret[444][444];
void init(){
    rep(i,0,h)rep(j,0,w)used[i][j]=false;
}int k=0,b=0;
int dfs(int i,int j){
    used[i][j]=true;
    if(fi[i][j]=='#')b++;else k++;
    rep(k,0,4){
        int xx=i+dx[k],yy=j+dy[k];
        if(0<=xx&&xx<h&&0<=yy&&yy<w&&!used[xx][yy]&&fi[i][j]!=fi[xx][yy]){
            dfs(xx,yy);
        }
    }
    return k*b;
}
signed main(){
    cin>>h>>w;
    rep(i,0,h)rep(j,0,w){
        cin>>fi[i][j];
        ret[i][j]=0;
        }
    int ans=0;init();
    rep(i,0,h)rep(j,0,w){
        if(fi[i][j]=='#'){
            if(!used[i][j]){
                k=0;b=0;ans+=dfs(i,j);
            }
        }
    }
    cout<<ans<<endl;return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int main() {
	ll a[3];
	REP(i, 3) cin >> a[i];
	
	if (a[0] == a[1]  && a[1] == a[2]) {
		if (a[0] & 1) puts("0");
		else puts("-1");
	}
	else {
		int cnt = 0;
		while (a[0] % 2 == 0 && a[1] % 2 == 0 && a[2] % 2 == 0) {
			ll nex[3] = {a[1] / 2 + a[2] / 2, a[0] / 2 + a[2] / 2, a[0] / 2 + a[1] / 2};
			REP(i, 3) a[i] = nex[i];
			cnt++;
		}
		
		cout << cnt << endl;
	}
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    int A[N];
    REP(i,N) cin >> A[i];
    int res, res2;
    res = -1;
    int d = 0;
    int d2 = 0;
    REP(i,N){
        if(A[i] >= d){
            res2 = res;
            d2 = A[res];
            res = i;
            d = A[i];
        }
        else{
            if (A[i] > d2){
                res2 = i;
                d2 = A[i];
            }
        }
    }

    REP(i,N){
        if(i == res) cout << A[res2] << endl;
        else cout << A[res] << endl;
    }
}

Measured memory_bytes: 2432
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    long long int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k % 2 == 0)
    {
        cout << a - b << "\n";
    }
    else
    {
        cout << b - a << "\n";
    }
    
    return 0;
}

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

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

  vector<pair<int, int>> points(N);
  for (int i = 0; i < N; i++) cin >> points[i].first >> points[i].second;

  map<pair<int, int>, int> diff;
  for (int i = 0; i < N-1; i++) {
    for (int j = i + 1; j < N; j++) {
      if (i == j) continue;
      int dx = points[i].first - points[j].first;
      int dy = points[i].second - points[j].second;
      if (dx < 0) {
        dx *= -1, dy *= -1;
      }
      if (dx == 0) {
        dy = max(dy, -dy);
      }
      diff[{dx, dy}]++;
    }
  }

  int cnt = 0;
  for (auto [p, v] : diff) cnt = max(cnt, v);

  cout << N - cnt << endl;
}

Measured memory_bytes: 3676
#include <stdio.h>
#include <math.h>
 
#define N 4097
 
 
typedef struct{
  double x, y;
}Point;
 
Point data[N], tmp[N];
int size;
 
void kochCurve(Point a, Point b, int n, int p){
  Point o = (Point){(b.x-a.x)/3.0, (b.y-a.y)/3.0};
  Point s = (Point){o.x+a.x, o.y+a.y};
  Point u = (Point){s.x + o.x / 2.0 - sqrt(3.0) * o.y / 2.0, s.y + sqrt(3.0) * o.x / 2.0 + o.y / 2.0};
  Point t = (Point){(b.x-a.x)*2.0/3.0+a.x, (b.y-a.y)*2.0/3.0+a.y};
  if(p == n) return;
  kochCurve(a, s, n, p+1);
  data[size++] = s;
  kochCurve(s, u, n, p+1);
  data[size++] = u;
  kochCurve(u, t, n, p+1);
  data[size++] = t;
  kochCurve(t, b, n, p+1);
}
 
main(){
  int i, n;
  scanf("%d", &n);
  data[size++] = (Point){0.0, 0.0};
  kochCurve(data[0], (Point){100.0, 0.0}, n, 0);
  data[size++] = (Point){100.0, 0.0};
  for(i=0;i<size;i++) printf("%.8f %.8f\n", data[i].x, data[i].y);
  return 0;
}

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

using namespace std;

int flag = 0;
constexpr int dy[] = {0, 0, 1, -1}, dx[] = {1, -1, 0, 0};

pair<int, int> find(int w, int h, vector<vector<int>> &con,
                    vector<vector<int>> &m) {
  m[w][h] = 1;
  pair<int, int> ret = {1e9, -1e9};
  int W = con.size(), H = con[0].size();
  for (int i = 0; i < 4; ++i) {
    if (w + dx[i] >= 0 && w + dx[i] < W && h + dy[i] < H && h + dy[i] >= 0) {
      int nx = w + dx[i], ny = h + dy[i];
      if (m[nx][ny])
        continue;
      if (con[nx][ny] == con[w][h]) {
        auto f = find(nx, ny, con, m);
        ret.first = min(ret.first, f.first);
        ret.second = max(ret.second, f.second);
      } else if (con[nx][ny] && i == 3) {
        ret.first = min(ret.first, nx);
        ret.second = max(ret.second, nx);
      }
    }
  }
  return ret;
}

pair<double, int> solve(int w, int h, vector<vector<int>> &con,
                        vector<vector<int>> &memo) {
  memo[w][h] = 1;
  pair<double, int> ret = {w + 0.5, 1};
  int W = con.size(), H = con[0].size();
  for (int i = 0; i < 4; ++i) {
    if (w + dx[i] >= 0 && w + dx[i] < W && h + dy[i] < H && h + dy[i] >= 0) {
      int nx = w + dx[i], ny = h + dy[i];
      if (!con[nx][ny] || memo[nx][ny])
        continue;
      if (con[nx][ny] == con[w][h]) {
        auto p = solve(nx, ny, con, memo);
        ret.first +=
            (p.first - ret.first) * (double)p.second / (p.second + ret.second);
        ret.second += p.second;
      }
      if ((con[nx][ny] != con[w][h]) && i == 2) {
        auto p = solve(nx, ny, con, memo);
        ret.first +=
            (p.first - ret.first) * (double)p.second / (p.second + ret.second);
        ret.second += p.second;
        vector<vector<int>> m(W, vector<int>(H, 0));
        auto f = find(nx, ny, con, m);
        if (!(p.first - f.first > 1e-7 && f.second + 1 - p.first > 1e-7))
          flag = 1;
      } else {
        continue;
      }
    }
  }
  return ret;
}

int main() {
  int w, h;
  while (cin >> w >> h, w) {
    vector<vector<int>> con(w, vector<int>(h + 1, 0)),
        memo(w, vector<int>(h + 1, 0));
    for (int i = h; i >= 0; --i) {
      if (i == 0) {
        for (int j = 0; j < w; ++j) {
          con[j][i] = 10;
        }
        break;
      }
      string s;
      cin >> s;
      for (int j = 0; j < w; ++j) {
        if (s[j] != '.')
          con[j][i] = s[j] - '0';
      }
    }
    flag = 0;
    solve(0, 0, con, memo);
    if (flag) {
      cout << "UNSTABLE" << endl;
    } else {
      cout << "STABLE" << endl;
    }
  }
}


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

int main(){
    int N, K;
    double prob = 0.0;
    int i, j;
    int temp;
    double p = 1.0;
    scanf("%d %d", &N, &K);
    for(i = 1; i <=N; i++){
        p = 1.0;
        if(i < K){
            temp = i;
            for(j=1; temp < K; j++){
                temp = temp*2;
                p = p*0.5;
            }
        }
        p = p * (1.0 / N);
        //printf("%f\n", p);
        prob += p;
    }
    printf("%.12f\n", prob);
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
class Program
    {
        static void Main(string[] args)
        {

            var input = Console.ReadLine().Split(' ');

            int x1 = int.Parse(input[0]);
            int x2 = int.Parse(input[1]);
            int x3 = int.Parse(input[2]);
            int x4 = int.Parse(input[3]);
            int x5 = int.Parse(input[4]);
          
          if(x1==0){
            x1 = 1;
            Console.WriteLine(x1);
          }
           if(x2==0){
            x2 = 2;
             Console.WriteLine(x2);
          }
           if(x3==0){
            x3 = 3;
             Console.WriteLine(x3);
          }
           if(x4==0){
            x4 = 4;
             Console.WriteLine(x4);
          }
           if(x5==0){
            x5 = 5;
             Console.WriteLine(x5);
          }
         
          
          
          
          
        }
}

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

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

    if(a==b)
        cout<<"Draw";
    else{
        if(a==1||b==1)
        {
            if(a==1) cout<<"Alice";
            else cout<<"Bob";
        }
        else if(a>b) cout<<"Alice";
        else cout<<"Bob";
    }


    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;

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

  // 移動のステップ
  vector<int> ans(s.size(), 0);

  for (int i = 0; i < s.size(); i++) {
    // L が出てくるまで進む
    int l = 0;
    while (s[i + l] != 'L') {
      l++;
    }

    for (int j = 0; j < l; j++) {
      if (abs(l - j) % 2 == 0) {
        ans[i + l]++;
      } else {
        ans[i + l - 1]++;
      }
    }
    i += l;
  }

  for (int i = s.size() - 1; i >= 0; i--) {
    // R が出てくるまで進む
    int r = 0;
    while (s[i - r] != 'R') {
      r++;
    }

    for (int j = 0; j < r; j++) {
      if (abs(r - j) % 2 == 0) {
        ans[i - r]++;
      } else {
        ans[i - r + 1]++;
      }
    }
    i -= r;    
  }

  for (size_t i = 0; i < s.size(); i++) {
    cout << ans[i];
    if (i == s.size() - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <queue>

using namespace std;

int main(void)
{
  int n, q, num, i = 0, ans = 0, box = 0;
  string nam;
  queue<int> que;
  queue<string> name;

  cin >> n >> q;

  for(i = 0;i < n;i++){
    cin >> nam >> num;
    name.push(nam);
    que.push(num);
  }

  while(que.size()){
    box = que.front();
    box -= q;
    if(box <= 0){
      ans += (q + box);
      cout << name.front() << ' ' << ans << endl;
      que.pop();
      name.pop();
    }
    else{
      ans += q;
      name.push(name.front());
      name.pop();
      que.push(box);
      que.pop();
    }    
  }
  
  return 0;
}


Measured memory_bytes: 6136
#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 ac = 0;
	int wa = 0;
	int tle = 0;
	int re = 0;
	rep(i, n) {
		string s;
		cin >> s;
		if (s == "AC") {
			ac++;
		}
		else if (s == "WA") {
			wa++;
		}
		else if (s == "TLE") {
			tle++;
		}
		else {
			re++;
		}
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;

	return 0;
}

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

typedef long long ll;
const int N = 1e5;

int n,v,p;
ll m;
ll li[N+5];

int cari(int x){
	int l = 1;
	int r = n;
	int ans = n+1;
	while(l<=r){
		int mid = (l+r)/2;
		if(li[mid] > x){
			ans = mid;
			r = mid-1;
		} else {
			l = mid+1;
		}
	}
	return ans;
}

ll ps[N+5];

int main(){
	scanf("%d%lld%d%d",&n,&m,&v,&p);
	for(int i=1;i<=n;i++){
		scanf("%lld",&li[i]);
	}
	sort(li+1,li+n+1);
	for(int i=1;i<=n;i++){
		ps[i] = ps[i-1] + li[i];
	}
	int ans = p;
	for(int i=n-p;i>=1;i--){
		if(v <= p){
			if(li[i] + m >= li[n-p+1]){
				ans++;
				continue;
			}
			else break;
		}
		if(li[i] == li[n-p+1]){
			ans++;
			continue;
		}
		ll tar = li[i] + m;
//		cout << ">>> " << i << " " << li[i] << " " << endl;
		int atas = cari(tar);
		if(n-atas+1 >= p) break;
		atas = n-p+2;
		int buang = v - p;
		
		if(buang < 0) break;
		ll total = buang * m;
//		cout << total << " TOTAL\n";
		ll batas_bawah = cari(tar - m - 1);
//		cout << "> batas bawah = " << batas_bawah << endl;
//		cout << "> atas = " << atas << endl;
		ll beban = (batas_bawah-1) * m;
//		cout << " cur beban " << beban << endl;
		beban += (atas - batas_bawah - 1)*tar - (ps[atas-1] - ps[batas_bawah]);
//		cout << (atas-batas_bawah-1) * tar << " - ";
//		cout << ps[atas-1] - ps[batas_bawah] << " <<< " << endl;
//		cout << " >>> beban " << beban << endl;
		if(beban >= total) ans++;
		else break;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#define int long long
using namespace std;
 main()
{
    int a,i,b,j;
    cin>>a>>b;
    int aa[a+5],cost[a+5];
    for(i=0;i<a;i++){
        cin>>aa[i];
        cost[i]=10000000000000000;
    }
    cost[0]=0;
    cost[1]=abs(aa[1]-aa[0]);
    for(i=2;i<a;i++)
    {
        for(j=1;j<=b;j++){
                if(i-j<0)
                break;
        cost[i]=min(cost[i-j]+abs(aa[i]-aa[i-j]),cost[i]);
        //cout<<cost[i]<<endl;
        }
       // cout<<cost[i]<<endl;
    }
    cout<<cost[a-1]<<endl;
}


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

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

  int idx = 0;
  while (S[idx] == '1') idx++;

  if (idx >= K) cout << 1 << endl;
  else cout << S[idx] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ar[2000010], br[100010], cr[2000010];

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

        memset(br, 0, sizeof(br));

        for(i = 1; i <= n; ++i)
        {
            scanf("%d", &ar[i]);
            ++br[ar[i]];
        }

        for(i = 1; i < 100001; ++i)
            br[i] = br[i] + br[i - 1];

        for(i = n; i > 0; --i)
        {
            cr[br[ar[i]]] = ar[i];
            --br[ar[i]];
        }

        for(i = 1; i < n; ++i)
            printf("%d ", cr[i]);
            printf("%d\n", cr[n]);

    return 0;
}

Measured memory_bytes: 19212
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, m;
  cin >> n >> m;
  ll ans = 1;

  for (ll a = 1; a * a <= m; a++) {
    if (m % a)
      continue;
    ll b = m / a;
    if (a * n <= m)
      chmax(ans, a);
    if (b * n <= m)
      chmax(ans, b);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define double          long double
#define pb              push_back
#define mp              make_pair
#define pi              pair<int,int>
#define vtiii           vector<tuple<int,int,int>>
#define vi              vector<int>
#define vpii			vector<pair<int,int>>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int>>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 	
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;


void solve(){
	string s;int q,t,f,nf=0;cin>>s>>q;char c; string str = "";
	while(q--){
		cin>>t;
		if(t==1){
			++nf;
		}else{
			cin>>f>>c;
			if(f==1){
				if(nf&1){
					s.pb(c);
				}else{
					str.pb(c);
				}
			}else{
				if(nf&1){
					str.pb(c);
				}else{
					s.pb(c);
				}
			}
		}
	}
	reverse(str.begin(),str.end());
	for(char c : s) str.pb(c);
	if(nf&1){
		reverse(str.begin(),str.end());
	}	
	cout<<str;
}	
 
int32_t main(){	
	FIO;
 	//w(x)
	solve();
	return 0;
}

Measured memory_bytes: 4108
r, c = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(r)]
for i in range(r):
    mat[i].append(sum(mat[i]))
new_row = []
for i in range(c):
    total_c = 0
    for j in range(r):
        total_c += mat[j][i]
    new_row.append(total_c)
new_row.append(sum(new_row))
mat.append(new_row)
for i in range(r+1):
    for j in range(c):
        print(f'{mat[i][j]} ', end='')
    print(mat[i][c])


Measured memory_bytes: 6248
S = str(input())
l = S.__len__()
ans = 0
for i in range(1 << (l-1)):
    p = []
    for j in range(l-1):
        if (i >> j) & 1 == 1:
            p.append(j)
    t = 0
    num = S[0]
    while(t < l-1):
        if t in p:
            ans += int(''.join(num))
            num = S[t+1]
        else:
            num += S[t+1]
        t += 1
    else:
        ans += int(''.join(num))

print(ans)


Measured memory_bytes: 3064
MOD = 10**9 + 7
N, A, B, C, D = map(int, input().split())
S = input()
# print((A-B)*(C-D))

if (A-B)*(C-D) >= 1:  # A>BかつC>D もしくは A<BかつC<D
    if S[min(A, B)-1:max(C, D)].find('##') == -1:
        print('Yes')
    else:
        print('No')
else:
    # print(S[max(A, B)-2:min(C, D)+1])
    if S[min(A, B)-1:max(C, D)].find('##') == -1 and S[max(A, B)-2:min(C, D)+1].find('...') >= 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 40560
import java.io.*;
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 k=sc.nextInt();
		int[] arr=new int[n+1];
		int temp=k;
		int d=0,val=0,count=0;
		while(k!=0)
		{
		 d=sc.nextInt();
		 for(int i=0;i<d;i++)
		 {
		     val=sc.nextInt();
		     arr[val]++;
		 }
		 k--;
		}
		 for(int i=0;i<=n;i++)
		 {
		     if(arr[i]==0)
		     count++;
		 }
		 count--;
		 System.out.println(count);
		
	}
}

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

vector<int> v;

int main(){
	int a,b;
	cin>>a>>b;
	v.push_back(a+b);
	v.push_back(a-b);
	v.push_back(a*b);
	sort(v.begin(), v.end());
	cout<<v[2];
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int size = 50;
char str[size];
int main() {
    scanf("%s", str);
    int l = strlen(str);
    if(l == 2) {
        printf("%s\n", str);
    } else {
        for(int i = 2;i > -1;i--) {
            printf("%c", str[i]);
        }
        putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int b,c,d,z;
	char ch1,ch2,ch3;
	cin>>ch1>>ch2>>ch3;
	if(ch1=='o') b=100;
	if(ch1=='x') b=0;
	if(ch2=='o') c=100;
	if(ch2=='x') c=0;
	if(ch3=='o') d=100;
	if(ch3=='x') d=0;
	z=700+b+c+d;
	cout<<z<<endl;
	return 0;
}

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

// お菓子の種類関係ない
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  int d, a;
  for(int i=0;i<K;i++){
    cin >> d;
    for(int j=0;j<d;j++){
      cin >> a;
      A.at(a-1) += 1;
    }
  }
  // count
  int count = 0;
  for(int i=0;i<N;i++){
    if(A.at(i) == 0) count++;
  }

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

Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	var s string
	fmt.Fscan(r, &n)
	fmt.Fscan(r, &s)

	if n%2 != 0 {
		fmt.Println("No")
		return
	}

	if s[:n/2] == s[n/2:] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 640
using System;

class Program
    {
        static void Main(string[] args)
        {
            string[] data;
            int H, W;
            bool flag = false;
            while (true)
            {

                data = Console.ReadLine().Split();
                //???????????¶
                if (int.Parse(data[0]) == 0 && int.Parse(data[1]) == 0)
                {
                    break;
                }
                else
                {
                    if ((int.Parse(data[0]) + int.Parse(data[1])) % 2 == 0)
                    {
                        flag = true;
                    }
                    else
                    {
                        flag = false;
                    }
                }

                for (H = int.Parse(data[0]); H > 0; H--)
                {
                    for (W = int.Parse(data[1]); W > 0; W--)
                    {

                        if (flag == true)
                        {
                            if ((H + W) % 2 == 0)
                            {
                                Console.Write("#");
                            }
                            else
                            {
                                Console.Write(".");
                            }
                        }
                        else
                        {
                            if ((H + W) % 2 != 0)
                            {
                                Console.Write("#");
                            }
                            else
                            {
                                Console.Write(".");
                            }
                        }

                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }

        }
    }

Measured memory_bytes: 8816
#include<bits/stdc++.h>
#define Ll long long
using namespace std;
const Ll N=2e5+5;
Ll a[N];
Ll n,m,ans=1e18,x,y;
int main()
{
	cin>>n;
	for(Ll i=1;i<=n;i++)cin>>a[i],x+=a[i];
	for(Ll i=1;i<n;i++){
		y+=a[i];
		ans=min(ans,abs(x-y-y));
	}
	cout<<ans;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> line1(3);
  vector<int> p(3);
  p = {5, 5, 7};
  for(int i = 0; i < 3; i++){
    cin >> line1.at(i);
  }
  sort(line1.begin(), line1.end());
  
  if(line1 == p){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}


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

using namespace std;

int main(void)
{
    int s;
    cin >> s;
    int ans;
    vector<int> a(1123456);
    a[0] = s;
    if(s==1||s==2||s==4)
        cout << 4 << endl;
        else{
    for (int i = 1; i < 112345;i++){
        if(a[i-1]%2==0)
            a[i] = a[i - 1] / 2;
            else
                a[i] = a[i - 1] * 3 + 1;
        if(a[i]==1&&a[i-1]==2&&a[i-2]==4){
            cout << i + 2 << endl;
            break;
        }
    }
        }
    return 0;
}

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

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

        cout << a * 2 - 1 << endl;
    }
    else if (a < b)
    {
        cout << b * 2 - 1 << endl;
    }
    else
    {
        cout << b + a << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
bool check()
{
  int M, N;
  int low[101][101] = {{}}, hig[101][101];
  bool graph[101][101] = {{}};
  fill_n(*hig, 101 * 101, INF);
  
  cin >> M >> N;
  for(int i = 0; i < M; i++) {
    int K;
    cin >> K;
    while(K--) {
      int s, t;
      string cond;
      cin >> s >> cond >> t;
      --s;
      if(cond == ">=") low[i][s] = max(low[i][s], t);
      else             hig[i][s] = min(hig[i][s], t);
      if(low[i][s] > hig[i][s]) return(false);
    }
  }
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < M; j++) {
      if(i == j) continue;
      for(int k = 0; k < N; k++) graph[i][j] |= low[i][k] > hig[j][k];
    }
  }
  for(int k = 0; k < M; k++) {
    for(int i = 0; i < M; i++) {
      for(int j = 0; j < M; j++) {
        graph[i][j] |= graph[i][k] & graph[k][j];
      }
      if(graph[i][i]) return(false);
    }
  }
  return(true);              
}

int main()
{
  cout << (check() ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1300
def resolve():
    S = input()
    s = len(S)
    count = 0
    if s%2 == 0:
        for i in range(s//2):
            if S[i] != S[(i+1)*-1]:
                count += 1
    else:
        for i in range((s-1)//2):
            if S[i] != S[(i+1)*-1]:
                count += 1
    print(count)
resolve()

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  int n;
  while(cin >> n) {
    if(n == 0) return 0;
    int ans = 0;
    FOR(i,1,n) {
      int sum = i;
      FOR(j,i+1,n) {
        sum += j;
        if(sum == n) ans++;
        if(sum > n) break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  int A,B;cin>>A>>B;
  OUT(max(0,A-2*B));

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N);
  rep(i,0,N) {
    cin >> A[i];
  }

  std::map<i64, i64> mp;
  mp[0] = 1000;
  rep(i,0,N) {
    {
      i64 now = mp[0];
      i64 c = now / A[i];
      now %= A[i];
      mp[c] = std::max(mp[c], now);
    }
    for(auto p: mp) {
      i64 c = p.first;
      i64 now = p.second;
      now += c * A[i];
      mp[0] = std::max(mp[0], now);
    }
  }
  i64 MAX = mp[0];
  for(auto p: mp) {
    MAX = std::max(MAX, p.second);
  }
  cout << MAX << endl;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N;
ll H[100010];
ll ans;
ll cnt;
int main(){
	cin >> N;
	REP(i,0,N){
		cin>>H[i];
	}
	REP(i,1,N){
		if(H[i-1]>=H[i]) {
			cnt++;
		}else{
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	p(max(ans, cnt));

	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    int n; cin>>n;
    vector<int> l(n);
    for(int i=0; i<n; i++) cin>>l[i];

    sort(l.begin(), l.end());

    ll ans = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            int lmin = l[i], lmid = l[j];
            int add = lmin + lmid;

            auto itr = lower_bound(l.begin(), l.end(), add);
            itr--;
            int dist = distance(l.begin(), itr);
            /*
            int ok = j, ng = n;
            while(ng - ok > 1){
                int mid = (ok + ng) / 2;
                if(l[mid] >= add) ng = mid;
                else ok = mid;
            }
            */

            ans += dist - j;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <math.h>
#include <cstring>

using namespace std;

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)

#define INF 		2000000007
#define MOD			998244353

#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int ll;

struct edge{
	int a,b;
	bool operator<(const edge& left)const{
		return (b < left.b);
	}
};

bool flag[MAX];

int main(void) {
	int N,M;cin>>N>>M;
	vector<edge> a(M);
	REP(i,M)cin>>a[i].a>>a[i].b;

	sort(a.begin(),a.end());

	int ans = 0;
	REP(i,M){
		ans++;
		int x = a[i].b;
		while(a[++i].a < x)if(i==M)break;
		--i;
	}

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
using System.Linq;
using System;

public class P
{
    public int v { get; set; }
    public int w { get; set; }
    public double vpw { get; set; }
}

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var W = int.Parse(line[1]);
        var ps = new P[n];
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var v = int.Parse(line[0]);
            var w = int.Parse(line[1]);
            ps[i] = new P { v = v, w = w, vpw = (double)v / w };
        }
        getAns(ps, W);
    }
    static void getAns(P[] ps, int W)
    {
        var vtotal = 0m; var wtotal = 0;
        foreach (var x in ps.OrderByDescending(y => y.vpw))
        {
            var t = wtotal + x.w;
            if (t < W) { vtotal += x.v; wtotal += x.w; }
            else if (t == W) { vtotal += x.v; break; }
            else { vtotal += x.v * (decimal)(W - wtotal) / x.w; break; }
        }
        Console.WriteLine(vtotal);
    }
}



Measured memory_bytes: 29604
n = int(input())
p = list(map(float, input().split()))

dp = [[0] * (n+1) for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    for j in range(n):
        if j > i+1:
            break
        dp[i+1][j+1] += dp[i][j] * p[i]
        dp[i+1][j] += dp[i][j] * (1 - p[i])

ans = 0
for j in range(n//2+1, n+1):
    ans += dp[n][j]

print(ans)


Measured memory_bytes: 255368
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;

int main()
{
	IO;
	ll n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0){
			ans+=i;
		}
	}
	cout<<ans<<endl;
 	return 0;
}







Measured memory_bytes: 3652
import numpy as np
N = int(input())
mod = 10**9+7
 
dp = np.zeros((N+1, 4, 4, 4))
dp[0][3][3][3] = 1
 
for i in range(N):
  for c1 in range(4):
    for c2 in range(4):
      for c3 in range(4):        
        for new in range(4):
          if new == 2 and c1 == 1 and c2 == 0:
            continue
          if new == 2 and c1 == 0 and c2 == 1:
            continue
          if new == 1 and c1 == 2 and c2 == 0:
            continue
          if new == 2 and c1 == 1 and c3 == 0:
            continue
          if new == 2 and c2 == 1 and c3 == 0:
            continue
          dp[i+1][new][c1][c2] += dp[i][c1][c2][c3]
          dp[i+1][new][c1][c2] %= mod


res = 0

for c1 in range(4):
  for c2 in range(4):
    for c3 in range(4):        
      res += dp[N][c1][c2][c3]
 
print(int(res%mod))

Measured memory_bytes: 13664