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

using namespace std;
#define ll long long int
ll mod=1e9+7,d,dp[10005][2][2][105],len;
char str[10005];

ll func(ll indx, ll isSmall, ll isStart, ll rem)
{
    if(indx==len) return (!rem);
    if(dp[indx][isSmall][isStart][rem]!=-1) return dp[indx][isSmall][isStart][rem];
    ll val=str[indx]-'0',ans=0;
    ll rng=isSmall? 9 : val;
    if(isStart)
    {
        for(ll i=1; i<=rng; i++)
        {
            ans+=func(indx+1, isSmall | i<(str[indx]-'0'), 0, (rem+i)%d);
            ans%=mod;
        }
        if(indx+1<len) ans+=func(indx+1, 1, 1, 0);
        ans%=mod;
    }
    else
    {
        for(ll i=0; i<=rng; i++)
        {
            ans+=func(indx+1, isSmall | i<(str[indx]-'0'), 0, (rem+i)%d);
            ans%=mod;
        }
    }

    return dp[indx][isSmall][isStart][rem]=ans;
}


int main()
{
    ll i,j;
    scanf("%s",str);
    scanf("%lld",&d);
    len=strlen(str);
    memset(dp, -1, sizeof dp);
    ll ans=func(0,0,1,0);
    printf("%lld\n",ans);
    return 0;

}


Measured memory_bytes: 33920
class BinaryIndexedTree
  def initialize(n, d)
    @n = n
    if d == 0 then
      @b = Array.new(@n, 0)
    else
      @b = (1..@n).map{|x| (x&-x)*d}
    end
  end
  def add(i, x)
    i += 1
    while i <= @n do
      @b[i-1] += x
      i += i&-i
    end
  end
  def sum(i)
    i+= 1
    ret = 0
    while i > 0 do
      ret += @b[i-1]
      i -= i&-i
    end
    ret
  end
end

N, Q = gets.chomp.split(" ").map(&:to_i)
C = gets.chomp.split(" ").map(&:to_i)
QU = Array.new(N){[]}
Q.times{|i|
  l, r = gets.chomp.split(" ").map(&:to_i)
  QU[r-1] << [l-1, i]
}

nxt = Array.new(N)
wk = Array.new(N)
bit = BinaryIndexedTree.new(N, 1)
ans = Array.new(N)
pnt = 0
QU.each_with_index{|w, r|
  while pnt <= r do
    bit.add(N-1-wk[C[pnt]], -1) if not wk[C[pnt]].nil?
    wk[C[pnt]] = pnt
    pnt += 1
  end
  w.each{|l, i|
    ans[i] = bit.sum(N-1-l) - (N-1-r)
  }
}

puts ans


Measured memory_bytes: 109700
N, K = list(map(int, input().split(' ')))
ll = []
for i in range(N):
    l = [c != '.' for c in input()]
    if (any(l)):
        ll.append(l)
tll = [list(x) for x in zip(*ll)]
tans = []
for i in range(len(tll)):
    if (any(tll[i])):
        tans.append(tll[i])
        
ans = [list(x) for x in zip(*tans)]
for i in range(len(ans)):
    print(''.join(['#' if c else '.' for c in ans[i]]))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
	// ll n,m, db,dc, b,c, maxi = INT_MIN, sum =0; cin>>n>>m; //tle aaya tha but impelementation dekh;
	// vector<ll> a(n);
	// for(ll i = 0 ; i < n ; i++) cin>>a[i]; 
	// sort(a.begin(),a.end());
	// vector<ll>::iterator it;
	// for(ll i = 0 ; i < m ; i++)
	// {
	// 	cin>>b>>c;
	// 	it = lower_bound(a.begin(), a.end(), c);
	// 	ll pos = it - a.begin()-1;
	// 	if(pos>=0)
	// 	fill(a.begin(), a.begin()+min(b,pos),c);
	// 	sort(a.begin(),a.end());
	// }
	// for(int i = 0 ; i< n; i++)
	// 	sum+=a[i];
	// cout<<sum<<endl;
	ll n,m, b,c, sum =0; cin>>n>>m;
	map<ll,ll> freq;
	for(int i = 0 ; i < n; i++)
	{
		cin>>b; freq[b]++;
	}
	for(int i = 0 ; i < m;i++)
	{
		cin>>b>>c;
		freq[c]+=b;
	}
	map<ll,ll>::iterator it;
	it = freq.end();
	--it;
	ll req = n;
	for(; it!=freq.begin(); it--)
	{
		if(it->second>=req)
			{
				sum+=it->first*req;
				req = 0;
				break;
			}
		else
		{
			sum+=it->first*it->second;
			req-=it->second;
		}

	}
	if(req)
	{
		it= freq.begin();
		sum+=it->first*req;
	}
	cout<<sum<<endl;

}

Measured memory_bytes: 12800
import math
from functools import reduce
n = int(input())
 
 
sum = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            tmp = math.gcd(i,j)
            tmp2 = math.gcd(j,k)
            tmp3 = math.gcd(tmp,tmp2)
            sum += tmp3
print(sum)

Measured memory_bytes: 74272
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,q,c,up,low,t,x,y,arr[4],a,b;
string str,str1;
bool f;

int main()
{
    cin >> a >> b >> c;
    x=(a+b+c);
    if (x>=22)
        cout << "bust" << endl;
    else
        cout << "win\n";
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
g=[[]for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)

import sys
sys.setrecursionlimit(10**6)

lastdp=[10**9+1]*n
recode=[[10**9+1]for i in range(n)]
ans=[0]*n
from bisect import bisect_left
def rec(me,parent):
    global lastdp
    a=A[me]
    point=bisect_left(lastdp,a)
    recode[point].append(a)
    lastdp[point]=a
    tmpans=bisect_left(lastdp,10**9+1)
    ans[me]=tmpans

    for child in g[me]:
        if child!=parent:
            rec(child,me)

    recode[point].pop()
    lastdp[point]=recode[point][-1]
    return

rec(0,-1)
print(*ans,sep='\n')


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

void numbreak(int n,int *a,int *b,int *c,int *d){
    int bb = 1000;
    for (int i = 0; i < 4; ++i) {
        int q = n / bb;
        if(i == 0) {
            *a = q;
        }else if (i == 1){
            *b = q;
        }else if (i == 2){
            *c = q;
        }else if (i == 3){
            *d = q;
        }
        n -= q * bb;
        bb /= 10;
    }
}

int main() {
    int num,a,b,c,d,qans,rans,zans;
    string ans;
    cin >> num;
    numbreak(num,&a,&b,&c,&d);
    for (int i = 0; i <2 ; ++i) {
        int x;
        if(i == 0){
            x = a + b;
        }else{
            x = a - b;
        }
        for (int j = 0; j < 2; ++j) {
            int y;
            if(j == 0){
                y = x + c;
            }else{
                y = x - c;
            }
            for (int k = 0; k < 2; ++k) {
                int z;
                if(k == 0){
                    z = y + d;
                } else{
                    z = y - d;
                }
                if(z == 7){
                    qans = i;
                    rans = j;
                    zans = k;
                    break;
                }
            }
        }
    }

    ans += to_string(a);
    if(qans == 0){
        ans += "+";
    } else{
        ans += "-";
    }
    ans += to_string(b);
    if(rans == 0){
        ans += "+";
    } else{
        ans += "-";
    }
    ans += to_string(c);
    if(zans == 0){
        ans += "+";
    } else{
        ans += "-";
    }
    ans += to_string(d);
    ans += "=7";
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

/*

5 2 2
oxoxo
//=> 1, 5

*/

fn main() {
    let (N, K, C) = read!(usize, usize, usize);
    let S = rl().chars().collect::<Vec<_>>();

    // left[i] = (i 日目より前に働く日数の最大値)
    let mut left = vec![0_usize; N + 1];

    // right[i] = (i 日目以降に働く日数の最大値)
    let mut right = vec![0_usize; N + 1];

    for i in 0..N {
        if S[i] == 'o' {
            left[i + 1] = left[(i + 1).saturating_sub(C + 1)] + 1;
        }

        left[i + 1] = max(left[i + 1], left[i]);
    }

    for i in (0..N).rev() {
        if S[i] == 'o' {
            right[i] = 1;
            if i + C + 1 < N {
                right[i] += right[i + C + 1];
            }
        }

        right[i] = max(right[i], right[i + 1]);
    }

    // let iota = (0..N).collect::<Vec<_>>();
    // debug!(iota, left, right, first);

    for i in 0..N {
        let n = left[i] + right[i + 1];
        if n < K {
            println!("{}", i + 1);
        }
    }
}


Measured memory_bytes: 9596
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define entire(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
std::vector<int> g[200005];
int vis[200005];
int n, m;
int dfs(int node) {
	// cout<<node<<endl;
	vis[node] = 1;

	int cnt = 1;
	for (auto el : g[node]) {
		if (!vis[el])
			cnt += dfs(el);
	}
	return cnt;
}
void solve()
{
	cin >> n >> m;
	std::map<pii, bool> map;
	memset(vis, 0, sizeof(vis));
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		if (map[ {u, v}])
			continue;
		map[ {u, v}] = map[ {v, u}] = true;
		g[u].pb(v);
		g[v].pb(u);
	}

	int res=1;
	// for(auto el :g[1])cout<<el<<" ";
	// 	cout<<endl;
	rep(i,200005){
		if(!vis[i] && !g[i].empty())
			res=max(res,dfs(i));
	}

	cout<<res<<endl;

}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast
	int T = 1;
	// cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 49644
import java.util.Scanner;

public class Main {

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

        String S = scanner.nextLine();

        int min = 99999;
        for (int i = 0; i < S.length() - 2; i++) {
            String temp = S.substring(i, i + 3);
            int num = Integer.valueOf(temp);
            int sa = Math.abs(num - 753);
            if (min > sa) {
                min = sa;
            }
        }

        System.out.println(min);
    }

}


Measured memory_bytes: 23124
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>		
using namespace std;
typedef long long ll;
int main()
{
    char a, b;
    scanf("%c",&a);
    if (a >= 'a' && a <= 'z') {
        printf("a\n");
    }
    else  printf("A\n");
	return 0;
}

Measured memory_bytes: 3760
//Problem: DP_A from Educational DP Contest
//Status: Working
#include <iostream>
#include <algorithm>
#include <cstring>
typedef long long int ll;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    ll h[n];
    ll dp[n];
    for(ll i=0; i<n; i++)
        cin >> h[i];
    dp[0] = 0;
    for(ll i=1; i<n; i++)
        dp[i] = ((i==1) ? abs(h[i] - h[i-1]) : min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2])));
    cout << dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
N,K = map(int,input().split(' '))

thres = (N-1) * (N-2)//2
if K <= thres:
	M = N-1+thres-K
	print(M)
	for i in range(2,N+1):
		print(1,i)
	need = thres - K
	for i in range(2,N+1):
		for j in range(i+1,N+1):
			if need == 0:
				exit()
			print(i,j)
			need -= 1
else:
	print(-1)


Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
#define repi(i,a,b) for(lint i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) tsort(v); reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif

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

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

    lint n, b;cin>>n>>b;
    vector<string> s(n);
    rep(i,n){
        cin>>s[i];
    }
    rep(i,b+2)cout<<'#';
    cout<<el;
    rep(i,n)cout<<'#'<<s[i]<<'#'<<el;
    rep(i,b+2)cout<<'#';
    cout<<el;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;

int main(){
  int n;
  cin >> n;
  int k;
  cin >> k;
  int cnt = 0;
  while(n > 0){
    n /= k;
    cnt++;
  }
  cout << cnt << endl;
  

}

Measured memory_bytes: 256
using System;

namespace November30
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] M=new int[2];
            for (int i = 0; i < 2; i++)
            {
                String input = Console.ReadLine();
                String[] splitted = input.Split(' ');
                M[i] = int.Parse(splitted[0]);
            }
            if (M[0] == M[1])
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine("1");
            }
        }
    }
}


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

using namespace std;
typedef long long ll;

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

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

    string res = "";
    rep(i, s.size())
    {
        if (s[i] == 'B')
        {
            if (res.empty())
            {
                continue;
            }
            res.pop_back();
        }
        else
        {
            res.push_back(s[i]);
        }
    }

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


Measured memory_bytes: 3608
a = input()
s = input()
d = input()
f = input()
g = input()
h = input()
j = min(int(s), int(d), int(f), int(g), int(h))

if int(a)%j == 0:
    k = int(a)//j + 4
else:
    k = int(a)//j + 5
print(k)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC Optimize("Ofast")
using namespace std;

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

    int n, m;
    cin >> n >> m;
    vector<int> as(n), bs(m);
    for (int i = 0; i < n; i++) cin >> as[i];
    for (int i = 0; i < m; i++) cin >> bs[i];

    sort(as.begin(), as.end());
    vector<long long> sum(n + 1);
    for (int i = 0; i < n; i++) {
        sum[i + 1] = sum[i] + as[i];
    }
    sort(bs.begin(), bs.end());
    map<int, long long> memo;

    long long ans = 0;
    for (int i = 0; i < m; i++) {
        int acc = 0;
        int b = bs[i];
        if (memo.count(b)) {
            ans += memo[b];
            continue;
        }
        long long M = 0;
        auto prev = as.begin();
        for (int j = 0; b * j < 202020; j++) {
            // [L, U)はbで割った商が同じ
            int L = b * j;
            int U = b * (j + 1);
            auto cur = lower_bound(as.begin(), as.end(), U);
            int now = cur - prev;
            prev = cur;
            long long dif = sum[acc + now] - sum[acc] - 1ll * L * now;
            ans += dif;
            M += dif;
            acc += now;
        }
        memo[b] = M;
    }
    cout << ans << endl;
}


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

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

        public static void Solve()
        {
            var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(Math.Max(Math.Max(ab[0] + ab[1], ab[0] - ab[1]), ab[0] * ab[1]));
        }
    }
}


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

int main() {    
    int n, m;
    cin >> n >> m;
    
    vector<vector<int>> switches(m);
    
    for(int i = 0; i < m; ++i) {
        int k;
        cin >> k;
        
        for(int j = 0; j < k; ++j) {
            int s;
            cin >> s;
            switches[i].push_back(s);
        }
    }
    
    vector<int> ps(m);
    
    for(int i = 0; i < m; ++i) {
        int p;
        cin >> p;
        ps[i] = p;
    }
    
    int ans = 0;
    
    for(int mask = 0; mask < (1 << n); ++mask) {
        bool done = false;
        
        for(int i = 0; i < m && !done; ++i) {
            
            int total = 0;
            for(int j = 0; j < (int)switches[i].size(); ++j) {
                if(mask & (1 << (switches[i][j]-1))) {
                    total++;
                }
            }
            
            if(total % 2 != ps[i]) {
                done = true;
            }
        }
        
        if(!done) {
            ans++;
        }
    }
    
    cout << ans << endl;
}


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

struct ListNode
{
	int value;
	struct ListNode *prev;
	struct ListNode *next;
};

struct ListNode *nil;

void init()
{
	nil = (struct ListNode *)malloc(sizeof(struct ListNode));
	if (NULL == nil)
		return ;
	nil->prev = nil;
	nil->next = nil;

	return ;
}

void insert(int value)
{
	struct ListNode *cur;

	cur = (struct ListNode *)malloc(sizeof(struct ListNode));
	if (NULL == cur)
		return ;
	cur->value = value;
	cur->next = nil->next;
	nil->next->prev = cur;
	nil->next = cur;
	cur->prev = nil;

	return ;
}

struct ListNode * search(int value)
{
	struct ListNode *cur = nil->next;

	while ((cur != nil) && (cur->value != value))
	{
		cur = cur->next;
	}

	return cur;
}

void delete(struct ListNode *cur)
{
	if (cur == nil)
		return;
	cur->next->prev = cur->prev;
	cur->prev->next = cur->next;
	free(cur);

	return ;
}

void deleteFirst()
{
	delete(nil->next);
	return ;
}

void deleteLast()
{
	delete(nil->prev);
	return ;
}

void deleteKey(int key)
{
	delete(search(key));
	return ;
}

void printList()
{
	struct ListNode *cur = nil->next;
	int isf = 0;
	while (1)
	{
		if (cur == nil)
			break;
		if (isf++ > 0)
			printf(" ");
		printf("%d", cur->value);
		cur = cur->next;
	}

	printf("\n");

	return ;
}

int main()
{
	int num;
	int i;
	int value;
	char cmd[20];

	init();
	scanf("%d", &num);
	for (i = 0; i < num; i++)
	{
		scanf("%s", cmd);
		if (cmd[0] == 'i')
		{
			scanf("%d", &value);
			insert(value);
		}
		else if (cmd[0] == 'd')
		{
			if (strlen(cmd) > 6)
			{
				if (cmd[6] == 'F')
				{
					deleteFirst();
				}
				else if (cmd[6] == 'L')
				{
					deleteLast();
				}
			}
			else
			{
				scanf("%d", &value);
				deleteKey(value);
			}
		}
	}

	printList();
	
	return 0;
}


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


int main(){
    ll n;cin>>n;
    char c[2][55];
    rep(i,0,2)rep(j,0,n)cin>>c[i][j];
    int tate[55];
    rep(i,0,n){
        if(c[0][i]==c[1][i])tate[i]=1;
        else tate[i]=0;
    }
    map<char,ll> m;
    if(tate[0]==1){
        m[c[0][0]]=3;
    }
    else{
        m[c[0][0]]=3;
        m[c[1][0]]=2;
    }
    rep(i,1,n){
        if(m[c[0][i]]!=0)continue;
        if(tate[i]*tate[i-1]==1)m[c[0][i]]=2;
        else if(tate[i]+tate[i-1]==0){m[c[0][i]]=3;m[c[1][i]]=1;}
        else if(tate[i]==0&&tate[i-1]==1){m[c[0][i]]=2;m[c[1][i]]=1;}
        else if(tate[i]==1&&tate[i-1]==0){m[c[0][i]]=1;}
    }
    ll an=1;
    for(auto i:m){
        an=(an*i.second)%1000000007;
    }
    cout<<an<<endl;
}







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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;

int cnt[100000];
bool flag[100000];

signed main(){
    cin>>N>>M;

    rep(i,N){
        cnt[i]=1;
        flag[i]=false;
    }
    flag[0]=true;

    rep(i,M){
        int x,y;
        cin>>x>>y;
        x--;y--;
        if(flag[x]){
            flag[y]=true;
        }
        cnt[y]++;
        cnt[x]--;
        if(cnt[x]==0)flag[x]=false;
    }

    int ans=0;
    rep(i,N)ans+=flag[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200010];
int b[200010];
bool cmp(int x,int y){
	return x > y;
}
int main(int argc,char *argv[]){
	scanf("%d",&n);
	for(int i = 1; i <= n; i++)	scanf("%d",&a[i]),b[i] = a[i];
	sort(b + 1,b + n + 1,cmp);
	for(int i = 1; i <= n; i++){
		if(b[1] == a[i])	cout << b[2] << endl;
		else	cout << b[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
	std::vector<int> vec;
	int a, b, c;
	std::cin >> a >> b >> c;
	vec.push_back(a);
	vec.push_back(b);
	vec.push_back(c);
	std::sort(vec.begin(),vec.end());
	std::cout << vec[0] << " " << vec[1] << " " << vec[2] << std::endl;
	return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m;
    cin >> n >> m;

    vvl v(n, vl(40));
    rep(i, n) {
        ll k;
        cin >> k;
        rep(j, k) {
            ll a;
            cin >> a;
            v[i][a] = 1;
        }
    }

    ll ans = 0;
    exrep(j, 1, m) {
        bool ok = true;
        rep(i, n) {
            if(v[i][j] == 0) {
                ok = false;
            }
        }
        if(ok) {
            ans++;
        }
    }
        
    out(ans);
    re0;
}

Measured memory_bytes: 256
from itertools import combinations

H, W, K = map(int, input().split())
S = [input() for _ in range(H)]

C = [[0] * (W + 1) for _ in range(H + 1)]
for h in range(H):
    wc = 0
    for w in range(W):
        wc += (S[h][w] == '1')
        C[h + 1][w + 1] = C[h][w + 1] + wc

ans = 2000
for cuth in range(H):
    for comb in combinations([h for h in range(1, H)], cuth):
        comb = [0] + list(comb) + [H]
        wi, cutw = 0, 0
        for w in range(W):
            if max([C[comb[i]][w + 1] - C[comb[i]][wi] - C[comb[i - 1]][w + 1] + C[comb[i - 1]][wi] for i in range(1, len(comb))]) > K:
                if wi == w:
                    cutw = 2000
                wi, cutw = w, cutw + 1
        ans = min(ans, cuth + cutw)

print(ans)


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout<<fixed;
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
	ll n, k;
	cin>>n>>k;
	if (n < k) cout<<min(abs(n-k), n)<<"\n";
	else cout<<min(abs(n%k - k), n%k)<<"\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	static int A = 1_000_000_007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		
		System.out.println(factorial(N));
	}
	
		public static long factorial(int a) {
		      long fact = 1;
		      long i = 1;
		      while(i <= a) {
		         fact *= i;
		         i++;
		         fact%=A;
		      }
		      return fact%=A;
		   }
}


Measured memory_bytes: 21844
# https://atcoder.jp/contests/abc049/tasks/arc065_a
# なんかこの問題知ってる気がする
# 前方向から貪欲にマッチしようとすると,dreamer なのか dream eraser なのかわかりにくい
# しかし後ろ三文字を見ると、eam,mer,ase,serと一意に決定できる。よって逆方向から貪欲にマッチングさせると即座に構成可能か判別できる

S = input()

i = len(S)
T = ''
while i - 3 > 0:
    tri = S[i - 3:i]
    if tri == 'eam':
        T += 'maerd'
        i -= 5
    elif tri == 'ase':
        T += 'esare'
        i -= 5
    elif tri == 'mer':
        T += 'remaerd'
        i -= 7
    elif tri == 'ser':
        T += 'resare'
        i -= 6
    else:
        print('NO')
        exit()

if S == T[::-1]:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 134664
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll x,y;
  cin >> x >> y;
  if(abs(x)==abs(y)) {
    cout << 1 << endl;
  }
  else if(0<=x&&x<y) {
    cout << y-x << endl;
  }
  else if(0<y&&y<x) {
    cout << 2+x-y << endl;
  }
  else if(y==0&&x>0) {
    cout << x+1 << endl;
  }
  else if(x<y&&y<=0) {
    cout << y-x << endl;
  }
  else if(y<x&&x<0) {
    cout << x-y+2 << endl;
  }
  else if(y<x&&x==0) {
    cout << x-y+1 << endl;
  }
  else if(x<0&&0<y&&abs(x)>abs(y)) {
    cout << -(x+y)+1 << endl;
  }
  else if(x<0&&0<y&&abs(x)<abs(y)) {
    cout << x+y+1 << endl;
  }
  else if(y<0&&0<x&&abs(x)>abs(y)) {
    cout << x+y+1 << endl;
  }
  else if(y<0&&0<x&&abs(x)<abs(y)) {
    cout << -y-x+1 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read() {
	char c=getchar(); int x=0,f=1;
	while (c<'0' || c>'9') {
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int main() {
	int n=read();
	if (n<1200) printf("ABC\n");
	else if (n<2800) printf("ARC\n");
	else printf("AGC\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
 
int main()
{
    int a[5];
    rep(i,5) cin >> a[i];

    int k;
    cin >> k;

    bool ans = true;
    rep(i,4) {
        for (int j = i + 1; j < 5; j++) {
            if (a[j] - a[i] > k) ans = false;
        }
    }

    cout << (ans ? "Yay!" : ":(") << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>

int top,S[1000];

void push(int x){
  S[++top]=x;
}

int pop(){
  return S[top--];
}

int main(){
  int a,b;
  char s[100];
  top=0;
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      b=pop();
      a=pop();
      push(a+b);
    }
    else if(s[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }
    else if(s[0]=='*'){
      b=pop();
      a=pop();
      push(a*b);
    }
    else{
      push(atoi(s));
    }
    }
  printf("%d\n",pop());
  return 0;
  }

Measured memory_bytes: 984
#include<bits/stdc++.h>
 using namespace std;
 inline int read(){
    int x=0,f=1; char ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    return x*f;
 }
 #define LL long long
 #define MAXN 100010
 LL N;
 int a[100010];
 int main(){
	cin>>N;
	int cnt = 0;
	LL base = 26;
	while (N){
		a[++cnt] = N%26;
		N /= 26;
	}
	//if (cnt>1 && a[cnt]==1) cnt--,a[cnt]+=26;
	for (int i=1; i<cnt; i++){
		if (a[i] <= 0){
			a[i] += 26; 
			a[i+1] --;
		}
	}
	while (a[cnt]<=0) cnt--;
	/*
	for (int i=cnt; i; i--){
		//putchar(a[i] + 'a'-1);
		printf("%d\n",a[i]);
	}
	*/
	for (int i=cnt; i; i--){
		putchar(a[i] + 'a'-1);
	}
	puts("");
 	return 0;
 }
 
 
 /*
2

27

123456789

1

26

702

475253
 */

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main() {
	bool flag = false;
	int a[10] = {0},b[3];
	for (int i = 0; i < 3; ++i) {
		cin >> b[i];
		a[b[i]]++;
	}
	for (int i = 0; i < 3; ++i) {
		if (a[b[i]] == 2)flag = true;

	}
	cout << (flag ? "Yes" : "No") << endl;
	return 0;
}

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

#ifdef DEBUG
#define debug(...) __VA_ARGS__
#else
#define endl '\n'
#define debug(...)
#endif
#define debugf(...) debug(printf(__VA_ARGS__))

const int N = 54;
using ull = unsigned long long;
using ll = long long;

using ii = pair<int, int>;
vector<ii> g[N];

int P[N], Pid[N];
int dep[N];
void build(int u, int p=0, int pid=-1) {
    dep[u] = dep[p] + 1;
    P[u] = p;
    Pid[u] = pid;
    for (auto [v, id] : g[u]) if (v != p) {
        build(v, u, id);
    }
}

ull ct[N];
void add(int u, int v, int i) {
    auto upd = [=](int x) {
        ct[i] |= 1ull << Pid[x];
    };
    while (dep[u] > dep[v]) {
        upd(u);
        u = P[u];
    }
    while (dep[v] > dep[u]) {
        upd(v);
        v = P[v];
    }
    while (u != v) {
        upd(u); upd(v);
        u = P[u]; v = P[v];
    }
}

int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;
    for (int i = 0; i < n-1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v, i);
        g[v].emplace_back(u, i);
    }

    build(1);

    int m; cin >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        add(u, v, i);
    }

    ll ans = 0;
    for (int msk = 0; msk < (1<<m); msk++) {
        ll include = __builtin_popcount(msk) & 1 ? -1 : 1;
        ull edges = 0;
        for (int b = 0; b < m; b++) {
            if (msk & (1<<b))
                edges |= ct[b];
        }
        ll f = n - __builtin_popcountll(edges) - 1;
        ans += include * (1ll << f);
    }

    cout << ans << endl;

    return 0;
%>

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

int main() {
	string A, B, C;

	cin >> A;
	cin >> B;
	cin >> C;

	int a = 0;
	int b = 0;
	int c = 0;

	int x = 0;

	while (1) {

		if (x == 0) {
			if (a >= A.size()) {
				cout << "A" << endl;
				break;
			}
			if (A.at(a) == 'a')x = 0;
			if (A.at(a) == 'b')x = 1;
			if (A.at(a) == 'c')x = 2;
			a++;
		}

		if (x == 1) {
			if (b >= B.size()) {
				cout << "B" << endl;
				break;
			}
			if (B.at(b) == 'a')x = 0;
			if (B.at(b) == 'b')x = 1;
			if (B.at(b) == 'c')x = 2;
			b++;
		}
		
		if (x == 2) {
			if (c >= C.size()) {
				cout << "C" << endl;
				break;
			}
			if (C.at(c) == 'a')x = 0;
			if (C.at(c) == 'b')x = 1;
			if (C.at(c) == 'c')x = 2;
			c++;
		}
	}
	return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    for(auto&& e:a) cin >> e;
    sort(a.begin(),a.end(),
        [](const int &a, const int &b){
            return (a>b);
        });
    double sum = accumulate(a.begin(),a.end(),0);
    cout << (a.at(m-1) < sum/(4*m) ? "No" : "Yes") << endl;
}

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

int main(){
    int n,m;cin>>n>>m;
    vector<int> A(n,0);
    int sum=0;
    rep(i,n){
        cin>>A[i];
        sum+= A[i];
    }
    int ans=0;
    rep(i,n){
        if((double)A[i] >= sum*1.0/(4*m))ans++;
    }
    if(ans >= m){
        cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    // Your code here!
    var n = readLine()!!.toInt()
    var list:MutableList<Int> = mutableListOf()
    var ans = 0.0
    
    for(i in 1..n){
        list.add(i)
    }
    
    ans = list.filter{it % 2 != 0}.count().toDouble() / n.toDouble()
    println(ans)
}


Measured memory_bytes: 33684
//ΔAGC030A
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<b+min(c,a+b+1);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
v = list(map(int, input().split()))
value = 0

v.sort()
v.reverse()

for i in range(1, N):
  if i < N-1:
    value += v[i-1] / (2**i)
  else:
    value += (v[i-1] + v[i]) / (2**i) 

print(value)

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

int main(){
    int N; cin >> N;
    vector<int> seq(N);
    for( int i = 0; i < N; i++ ) cin >> seq[i];

    int ave = 0, ans = 1000000000;
    for( int i = -100; i < 101; i++ ){
        for( int j = 0; j < N; j++ ){
            ave += (seq[j] - i) * (seq[j] - i);
        }
        ans = min( ans, ave );
        ave = 0;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Integer> A = new ArrayList<Integer>();
		for(int i = 1; i<= N ; i ++) {
			int ai = sc.nextInt();
			A.add(ai);
		}
		System.out.println(getMax(A) - getMin(A));
	}
	 private static int getMax(List<Integer> numbers){
	      int max = numbers.get(0);
	        
	      for(int i=1;i < numbers.size();i++){
	        
	         Integer number = numbers.get(i);
	            
	         if(number.intValue() > max){
	            max = number.intValue();
	         }
	      }
	      return max;
	   }
	    
	   private static int getMin(List<Integer> numbers){
	      int min = numbers.get(0);
	        
	      for(int i=1;i < numbers.size();i++){
	         Integer number = numbers.get(i);
	        
	         if(number.intValue() < min){
	            min = number.intValue();
	         }
	      }
	      return min;
	   }
	    

}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    string s; cin >> s;
    int n = s.size();
    string ans = "";
    rep(i,n) ans.push_back('x');
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static Assistant.Input;
using System.Linq;
using Assistant;

namespace ABC143D_2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt;
            var L = ReadInts;

            long ans = 0;
            L = L.OrderBy(x => x).ToArray();
            for (int i = N - 1; i >= 2; i--)
            {
                for (int j = i - 1; j >= 1; j--)
                {
                    int now = L[i] - L[j];
                    int count = LowerBound(L, now + 1);
                    if (count >= j) continue;

                    ans += j - count;
                    //Console.WriteLine(count);
                }
            }

            Console.WriteLine(ans);

        }

        /// <summary>
        /// 二分探索 key以上の最低
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="a"></param>
        /// <param name="v"></param>
        /// <returns></returns>
        public static int LowerBound<T>(T[] a, T v)
        {
            return LowerBound(a, v, Comparer<T>.Default);
        }

        public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res == -1) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }

        /// <summary>
        /// 二分探索 keyより大きい最低
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="a"></param>
        /// <param name="v"></param>
        /// <returns></returns>
        public static int UpperBound<T>(T[] a, T v)
        {
            return UpperBound(a, v, Comparer<T>.Default);
        }

        public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res <= 0) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        //drawmap
        //drawarray
    }
}


Measured memory_bytes: 13504
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var robots = new List<Tuple<int, int>>();
            foreach (var i in Enumerable.Range(0, N))
            {
                var item = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
                var X = item[0];
                var L = item[1];
                robots.Add(new Tuple<int, int>(X - L, X + L));
            }

            robots = robots.OrderBy(elem => elem.Item2).ToList();
            int count = 0;
            int current = int.MinValue;
            foreach (var i in Enumerable.Range(0, N))
            {
                if (current <= robots[i].Item1)
                {
                    count++;
                    current = robots[i].Item2;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27064
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Colorful Subsequence
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MOD = 1000000007;

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_N + 4];
int cs[26];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) cs[s[i] - 'a']++;

  ll d = 1;
  for (int i = 0; i < 26; i++) d = d * (cs[i] + 1) % MOD;
  printf("%lld\n", (d + MOD - 1) % MOD);
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <utility>
using namespace std;

int top, S[1000];

void push (int x) {
	top++;
	S[top] = x;
}

int pop() {
	top--;
	return S[top+1];
}

int main() {
	int a, b;
	char s[100];
	top = 0;
	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a+b);
		} else if (s[0] == '-') {
			a = pop();
			b = pop();
			push(b-a);
		} else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a*b);
		} else {
			push(atoi(s));
		}
	}
	printf("%d\n", pop());
	return 0;
}


Measured memory_bytes: 2764
#include<bits/stdc++.h>
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; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    int n; cin>>n;
    vector<int> p(n);
    rep(i,n)cin>>p[i];
    ll res = 0;
    rep1(i,n-2){
        if((p[i]-p[i-1])*(p[i]-p[i+1])<=0)res++;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>

int main(){
  int N,i,j,A[100],minj,temp,count=0;

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

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
    if(A[i]<0 || A[i]>100){
      exit(8);
    }
  }
 
  for(i=0;i<=N-2;i++){
    minj=i;

    for(j=i;j<=N-1;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }

    temp=A[i];
    A[i]=A[minj];
    A[minj]=temp;

    if(i!=minj){
      count++;
    }
  }
  
  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[N-1]);

  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp> //required

#define dbg(x) cerr<<#x": "<<x<<"\n"
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define st first
#define nd second

// using namespace __gnu_pbds; 
using namespace std;

// template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // ordered_set <int> s;
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }

const int N = 200100;
const int MOD = 1e9 + 7;
long long n, k, m, a[N], dp[N], last[N];

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n;
	dp[0] = 1;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		dp[i] = dp[i - 1];
		if(last[a[i]] != 0 && last[a[i]] != i - 1)
			dp[i] += dp[last[a[i]]], dp[i] %= MOD;

		last[a[i]] = i;
	}
	cout << dp[n] % MOD << '\n';
}	


Measured memory_bytes: 4992
#include <stdio.h>

#define MAX 40

void solve(int*,int*,int);

int n, post[MAX], idx;

int main(){
  int pre[MAX], in[MAX], i;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",pre+i);
  }
  for(i = 0 ; i < n ; i++){
    scanf("%d",in+i); 
  }

  solve(pre, in, n);

  for(i = 0 ; i < n ; i++){
    printf("%d%c",post[i],(i != n-1 ? ' ':'\n'));
  }

  return 0;
}

void solve(int pre[], int in[], int N){
  int i, par;

  for(i = 0 ; i < N ; i++){
    if(in[i] == pre[0]){
      par = i;
      break;
    }
  }

  if(par != 0){
    solve(pre+1, in, par);
  }
  if(par != N-1){
    solve(pre+par+1, in+par+1, N-par-1);
  }
  post[idx++] = pre[0]; 
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		StringBuffer result = new StringBuffer("");
		String moji = "";
		int N = sc.nextInt();
		String S = sc.next();

		String[] str = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
				"T", "U", "V", "W", "X", "Y", "Z" };
		if (!(N == 0)) {
			for (int a = 0; a < S.length(); a++) {
				int ind = 0;
				moji = S.substring(a, a + 1);

				for (int i = 0; i < str.length; i++) {
					if (str[i].equals(moji)) {
						ind = i;
					}
				}

				for (int i = 0; i < N; i++) {

					if (ind + 1 == 26) {
						ind = 0;
					} else {
						ind = ind + 1;
					}
				}

				moji = str[ind];

				result.append(moji);
			}
			System.out.println(result.toString());
		} else {
			System.out.println(S);
		}

	}
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
int main(){
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	unsigned long long sum=0;
	int n;
	cin>>n;
	int a[55];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			sum+=a[i]*a[j];
		}
	}
	cout<<sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    int A, P, sum;

    cin >> A >> P;

    sum = A*3+P;

    cout << sum/2 << endl;

    return 0;
}

Measured memory_bytes: 256