akhauriyash/Code-Regression huggingface dataset:
N,M = map(int,input().split())
H = list(map(int,input().split()))
adj = [ [] for _ in range(N) ]
for _ in range(M):
  u,v = map(int,input().split())
  u -= 1
  v -= 1
  adj[u].append(v)
  adj[v].append(u)

res = 0
for i in range(N):
   if all([ H[n] < H[i] for n in adj[i]]):
    res += 1

print(res)

Measured memory_bytes: 97736
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD=1e9+7;
//Variables End


void solve(){
	 int a,b,c,k;cin>>a>>b>>c>>k;
	 if(k<=a){
		cout<<k<<endl;
		return;
	}
	
	if(k>a && k<=a+b){
		cout<<a<<endl;
		return;
	}
	
	cout<<a-(k-a-b)<<endl;
}
int main()
{
    ios
    int ti=1;
    //cin>>ti;
    for(int i=1;i<=ti;i++)
    {
		solve();        
    }
    return 0;
        
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int n,k;
  cin >> n >> k;
  int a = n-1;
  int b = k-1;
  if( a%b == 0 ){
    cout << a/b << endl;
  }
  else{
    cout << a/b + 1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
 
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

const int NM = 1e5+10;
const ll INF = 1LL << 60;
ll h[NM];
ll dp[NM];

int main() {
    int N; cin >> N;
    rep(i, N) {
        cin >> h[i];
    }
    rep(i, NM) dp[i] = INF;
    dp[0] = 0;
    for(int i=0; i<N; i++) {
       dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
       if(i+2 < N){
            dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
       }
    }
    cout << dp[N-1] << endl;

}

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

using namespace std;

typedef long long ll;

ll a, b, c, k, sum = 0;
int main()
{
  	ios_base::sync_with_stdio(false);
  	cin.tie(NULL); cout.tie(NULL);
  	cin >> a >> b >> c >> k;
  	if (a < k)
    {
      	sum += a;
      	k -= a;
      	if (b < k)
        {
          	k -= b;
          	if (c < k)
            {
              	sum -= c;
              	cout << sum;
              	return 0;
            }
          	else
            {
             	sum -= k;
              	cout << sum;
              	return 0;
            }
        }
      	else
        {
          	cout << sum;
          	return 0;
        }
    }
  	else
    {
 		sum += k;
      	cout << sum;
      	return 0;
    }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0;
    string pre = "";
    rep(i, n) {
        if (i == n-1) {
            if (s.substr(i, 1) == pre) break;
            cnt++;
            break;
        }
        if (s.substr(i, 1) != pre) {
            cnt++;
            pre = s.substr(i, 1);
        } else {
            cnt++;
            i++;
            pre = s.substr(i, 2);
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 720
a,b,c,d=map(int,input())

if 1 <= a*10+b <= 12 and 1 <= c*10+d <= 12:
  print("AMBIGUOUS")
elif 0 <= a*10+b <= 99 and 1 <= c*10+d <= 12:
  print("YYMM")
elif 1 <= a*10+b <= 12 and 0 <= c*10+d <= 99:
  print("MMYY")
else:
  print("NA")

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vint a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int ans = 1;
	int tmp;
	int now;
	rep(i, n) {
		if (i == 0)continue;
		if (a[i - 1] < a[i]) {
			now = 1;
		}
		else if (a[i - 1] == a[i]) {
			now = 0;
		}
		else {
			now = -1;
		}
		if (i == 1 || tmp == 0)tmp = now;
		if (now == 0) {
			continue;
		}
		if (tmp != now) {
			ans++;
			tmp = 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
def main():
    s = input()
    n = len(s)

    rule1 = True
    rule2 = True
    rule3 = True

    for i in range(n):
        if s[i] != s[n - 1 - i]:
            rule1 = False
            break

    for i in range(n // 2):
        if s[i] != s[n // 2 - 1 - i]:
            rule2 = False
            break

    for i in range(n // 2):
        if s[n // 2 + 1 + i] != s[n - 1 - i]:
            rule3 = False
            break

    if rule1 and rule2 and rule3:
        ans = "Yes"
    else:
        ans = "No"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61680
# AtCoder Beginner Contest 154: C (2020/02/09)
N = int(input())
l = input().split()
A = [0 for i in range(N)]
for i in range(N):
    A[i] = int(l[i])
B = list(set(A))
if len(A) == len(B):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 38220
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rrep(i,N) for(int i=(int)(N)-1;i>=0;--i)
#define debug(x) cout<<#x<<"="<<x<<endl;
constexpr ll MOD=1000000007;
constexpr ll INF=1LL<<60;
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
    int m,a,b;
    vector<int> ok(100100),prime;
    for(int i=2;i<=100100;i++)
        if(!ok[i]){
            prime.push_back(i);
            for(int j=i<<1;j<=100100;j+=i)ok[j]=1;
        }
    while((cin>>m>>a>>b),m|a|b){
        int max=0,p=-1,q=-1;
        for(int n:prime){
            if(n>=m)break;
            for(int l:prime){
            if(n<l)break;
            if(n*l>m)break;
            if(l*b<n*a)continue;
            if(chmax(max,l*n)){p=l;q=n;}
        }
        }
        cout<<p<<" "<<q<<endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
int readin()
{
	int y=0;
	int neg=1;
	char c=getchar();
	if(c==' ')
		return y;
	while(c>='0'||c<='9')
	{
		if(c=='-')
			neg=-1;
		else
		y=10*y+c-'0';
		c=getchar();
		if(c=='\n'||c==' ')
			break;
	}
	y*=neg;
	return y;
}
void writen(int re)
{
     if(re>9)
	 	writen(re/10);
     putchar(re%10+'0');
}
int n,m;
bool vis[55],g[55][55];
int dfs(int x)
{
	vis[x]=1;
	int ret=1;
	for(int to=0;to<n;to++)
	{
		if(vis[to])
			continue;
		if(!g[x][to])
			continue;
		ret+=dfs(to);
	}
	return ret;
}
int main()
{
	n=readin();
	m=readin();
	for(int i=0;i<m;i++)
	{
		int a,b;
		a=readin();
		a--;
		b=readin();
		b--;
		g[a][b]=g[b][a]=1;
	}
	int ans=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<i;j++)
		{
			if(g[i][j])
			{
				g[i][j]=g[j][i]=0;
				for(int k=0;k<n;k++)
					vis[k]=0;
				if(dfs(0)!=n)
					ans++;
				g[i][j]=g[j][i]=1;
			}
		}
	writen(ans);
	return 0;
}

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

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

    vector<bool> v(8, false);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        for (int i = 1; i <= 8; i++) {
            if (x < i*400) {
                v[i-1] = true;
                break;
            }
        }
        if (x >= 3200) {
            cnt++;
        }
    }

    int Min = count(v.begin(), v.end(), true);
    cout << max(Min, 1) << " " << Min + cnt << endl;

    return 0;
}

Measured memory_bytes: 256
fn c() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let mut n = input.trim_right().parse::<i64>().unwrap() - 1;
    let mut ans = String::new();
    let alpha = vec!['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'];

    while n >= 0 {
        ans.push(alpha[(n % 26) as usize]);
        n = n / 26 - 1;
    }
    println!("{}", ans.chars().rev().collect::<String>());
}

fn main() {
    c();
}

Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	int odd=0,even=0;
	for(int i=1;i<=a;i++)
	{
		if(i%2==1)odd++;
		if(i%2==0)even++;
	}
	cout<<odd*even;
	return 0;
} 

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
        c: [Chars; h],
    };

    let mut ans = 0;
    for bits_y in 0..1 << h {
        for bits_x in 0..1 << w {
            let ys = (0..h)
                .map(|y| (bits_y >> y) & 1 == 1)
                .collect::<Vec<bool>>();
            let xs = (0..w)
                .map(|x| (bits_x >> x) & 1 == 1)
                .collect::<Vec<bool>>();
            let mut count = 0;
            for y in 0..h {
                for x in 0..w {
                    if c[y][x] == '#' && !(ys[y] || xs[x]) {
                        count += 1;
                    }
                }
            }
            if count == k {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2180
from collections import deque

queue = deque()
total_time = 0
n, q = map(int,input().split(' '))
for _ in range(n):
    name, time = input().split(' ')
    queue.append((name,int(time)))


while True:
    try:
        name, time = queue.popleft()
        if time - q <= 0:
            total_time += time
            print(name,total_time,sep=' ')
        elif time - q > 0:
            total_time += q
            queue.append((name,time-q))
    except IndexError:
        break


Measured memory_bytes: 12536
#include<iostream>
using namespace std;
int main(){
  int n,k;
  int boad=1;
  cin >> n >> k;
  while(n--){
    if(boad*2<boad+k)
      boad*=2;
    else
      boad+=k;
  }
  cout << boad << endl;
  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <string>

std::vector<unsigned int> res;

void solve() {
    int out=0, score=0;
    int base[4] = { 0 }; // base[0] : first
                         // base[1] : second
                         // base[2] : third
                         // base[3] : home
    std::string event;
    while (out < 3) {
        std::cin >> event;
        if (event == "OUT") {
            out++;
        } else if (event == "HOMERUN") {
            base[3] = 1;
            for (int i=0; i<4; i++) {
                score += base[i];
                base[i] = 0;
            }
        } else { // event == "HIT"
            int run=base[0];
            base[0] = 1;
            for (int i=1; i<4; i++) {
                std::swap(run, base[i]);
            }
            if (base[3] != 0) {
                score++;
                base[3] = 0;
            }
        }
    }
    std::cout << score << std::endl;
}

int main() {
    int n;
    std::cin >> n;
    for (int i=0; i<n; i++) {
        solve();
    }
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll Mod = 1000000007;

vector<P> prime;
vector<ll> cand;
void DFS(int t,ll res) {
  if (t == prime.size()) {
    cand.push_back(res);
  } else {
    ll a = 1;
    for (int i = 0; i <= prime[t].second; i++) {
      DFS(t+1,res*a);
      a *= prime[t].first;
    }
  }
  return ;
}

int main() {
  ll N,M;
  cin >> N >> M;
  ll Mm = M;
  // Mを素因数分解
  int cnt = 0;
  for (ll i = 2; i * i <= M; i++) {
    if (M % i == 0) {
      prime.push_back(make_pair(i,0));
      while (M % i == 0) {
        M /= i;
        prime[cnt].second++;
      }
      cnt++;
    }
  }
  if (M != 1) {
    prime.push_back(make_pair(M,1));
  }
  DFS(0,1);
  ll ans = -1;
  for (int i = 0; i < cand.size(); i++) {
    if (Mm / cand[i] >= N) {
      ans = max(ans,cand[i]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int a,b; cin >> a >> b;
    ll res = 0;
    ll t8,t10;
    bool ans = false;
    FOR(i,1,INF){
        t8 = i*0.08;
        t10 = i*0.1;
        if (t8 == a && t10 == b) {
            res = i;
            ans = true;
            break;
        }
    }
    if(ans) cout << res << endl;
    else cout << -1 << endl;
}


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

int main() {
  long long int N;
  cin >> N;
  vector<long long int> A(N + 1, 1);
  for (long long int X = 2; X <= N; X++) {
    for (long long int n = 1; n * X <= N; n++) A.at(n * X)++;
  }
  long long int ans = 0;
  for (long long int i = 1; i <= N; i++) ans += i * A.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 81344
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

int main()
{
	int n;
	while (cin >> n&&n)
	{
		int ans = 0;
		for (;n!=1; ans++)
		{
			if (n % 2)n = n * 3 + 1;
			else n /= 2;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  ll a,b,c,X,Y;
  cin >> a >> b >> c >> X >> Y;
  ll min=X*a+Y*b;
  for(ll i=1;i<=max(X,Y);i++) {
    ll xq=X,yq=Y,ans;
    ans = ((c*2)*i) + (X-i)*a+(Y-i)*b;
    if(X-i<=0) {
      ans = ((c*2)*i)+(Y-i)*b;
    }
    if(Y-i<=0) {
      ans = ((c*2)*i)+(X-i)*a;
    }
    if(max(X,Y)-i==0) {
      ans = ((c*2)*i);
    }
    if(min>ans) min=ans;
  }
  cout << min << endl;
}

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

struct QuickFind{
  Int n;
  vector<Int> r,p;
  vector<vector<Int> > v;
  QuickFind(){}
  QuickFind(Int sz):n(sz),r(sz),p(sz),v(sz){
    for(Int i=0;i<n;i++){
      r[i]=1,p[i]=i;
      v[i].resize(1,i);
    }
  }
  bool same(Int x,Int y){
    return p[x]==p[y];
  }
  void unite(Int x,Int y){
    x=p[x];y=p[y];
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    for(Int i=0;i<(Int)v[y].size();i++){
      p[v[y][i]]=x;
      v[x].push_back(v[y][i]);
    }
    v[y].clear();
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  QuickFind qf(n);
  for(Int i=0;i<m;i++){
    Int x,y;
    cin>>x>>y;
    qf.unite(x,y);
  }
  if(m==n-1){
    cout<<0<<endl;
    return 0;
  }
  vector<vector<Int> > G;
  Int ans=0,cnt=0;
  for(Int i=0;i<n;i++){
    if(qf.p[i]!=i) continue;
    G.emplace_back();
    for(Int j:qf.v[i])
      G.back().emplace_back(a[j]);
    sort(G.back().rbegin(),G.back().rend());
    ans+=G.back().back();
    G.back().pop_back();
    cnt++;
  }
  priority_queue<Int,vector<Int>,greater<Int> > pq;
  for(auto v:G)
    for(Int x:v)
      pq.emplace(x);

  while(m*2+cnt<(n-1)*2){
    if(pq.empty()){
      cout<<"Impossible"<<endl;
      return 0;
    }
    ans+=pq.top();pq.pop();
    cnt++;
  }
  
  cout<<ans<<endl;
  return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define f first
#define s second

ll cnt[100005];
ll a[100005];
ll ab[100005];
ll abc[100005];
string S;

int main(){

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

cin>>S;

ll N=S.size();

if(S[0]=='A'||S[0]=='?') a[0]=1;

if(S[0]=='?') cnt[0]=3;
else cnt[0]=1;

rep1(i,N){
	if(S[i]=='A'){
		cnt[i]=cnt[i-1];
		a[i]=(a[i-1]+cnt[i-1])%mod;
		ab[i]=ab[i-1];
		abc[i]=abc[i-1];
	}
	if(S[i]=='B'){
		cnt[i]=cnt[i-1];
		a[i]=a[i-1];
		ab[i]=(ab[i-1]+a[i-1])%mod;
		abc[i]=abc[i-1];
	}
	if(S[i]=='C'){
		cnt[i]=cnt[i-1];
		a[i]=a[i-1];
		ab[i]=ab[i-1];
		abc[i]=(abc[i-1]+ab[i-1])%mod;
	}
	if(S[i]=='?'){
		cnt[i]=3*cnt[i-1]%mod;
		a[i]=(a[i-1]+cnt[i-1]+a[i-1]+a[i-1])%mod;
		ab[i]=(ab[i-1]+ab[i-1]+a[i-1]+ab[i-1])%mod;
		abc[i]=(abc[i-1]+abc[i-1]+abc[i-1]+ab[i-1])%mod;
	}
}

cout<<abc[N-1]<<endl;

}
	


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main(){
    int n = 0;
    set<string>fruit;
    cin >> n;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        
        fruit.insert(s);
    }
    cout << fruit.size() << endl;
    return 0;
}


Measured memory_bytes: 19132
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using ULL = int64_t;
using P = pair<LL, LL>;
#define rep(i, n) for (LL i = 0; i < (n); ++i)
#define all(v) (v).begin(), (v).end()
#define DEBUG

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

  LL m = n % 10;
  if (m == 3) {
    cout << "bon" << endl;
  } else if (m == 0 || m == 1 || m == 6 || m == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }

  #ifdef DEBUG
  // cout << 123 << endl;
  #endif
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for(int i=3;i<=sqrtNum;i+=2){
	if(num%i==0){
	    return false;
	}
    }
  return true;
}
int main(){
  int a,b;
  int c[1000000]={};
  int w[1000000]={};
  int e=0,q;
  cin>>e;
  c[1]=0;
  for(int i=3;i<=100000;i+=2){
    if(IsPrime((i+1)/2)&&IsPrime(i)) c[i]++;
      c[i]+=c[i-2];
  }
  for(int i=0;i<e;i++){
    q=0;
    cin>>a>>b;
    if(c[a]!=c[a-2]&&a!=1) q=1;
    //cout<<c[a]<<" "<<c[5]<<" "<<c[b];
    cout<<c[b]-c[a]+q<<"\n";
  }
  //for(int i=1;i<=56;i+=2) cout<<i<<" "<<c[i]<<"\n";  
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int ans[10];
    for(int i=0;i<10;i++) cin >> ans[i];
    sort(ans, ans+10);
    for(int i=9;i>=7;i--) cout << ans[i] << "\n";
    return 0 ;
}



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

int main(){
  int a,b,at=0;
  cin>>a>>b;
  for(int i=a;i<=b;i++){
    if(i/10000==i%10&&(i/10%10==i/1000%10)){
      at++;
    }
  }
  cout<<at<<endl;
}


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

using namespace std;

long long int a[2000001];
int n;
long long int res[200001];
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n;

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

	long long int val = 0;
	for(int i=2;i<n;i+=2)
	{
		val ^= (a[i]^a[i+1]);
	}

	res[n] = (a[1]^val);

	for(int i=n-1;i>=1;i--)
	{
		res[i] = (res[n]^a[i]^a[n]);
	}

	for(int i=1;i<=n;i++)
	{
		cout << res[i] << ' ';
	}
	cout << '\n';

	return 0;
}

Measured memory_bytes: 6700
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 98765431219876543
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, string> PS;

ll n, m;

int main() {
  cin >> n >> m;
  ll ans = 1;
  REP(i, sqrt(m) + 1) {
    if (i >= 1 && m % i == 0) {
      if (i <= m / n) {
        ans = max(ans, i);
      }
      if (m / i <= m / n) {
        ans = max(ans, m / i);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
int W,H;
int dx[4] = {-1,1,0,0},dy[4] = {0,0,-1,1};
int dist[12][12] = {},inf = 1e7;
int visited[21][21] = {};
int A[11] = {1,2,3,4,5,6,7,8,9,10,11};
char F[21][21];


bool in(int x,int y){
    return 1<=x && x<=H && 1<=y && y<=W;
}

int main(){
    while(cin >> W >> H && W>0){
        int id = 1;
        map<P,int> m;
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                cin >> F[i][j];
                if(F[i][j]=='*'){
                    m[{i,j}] = id+1;
                    id++;
                }
                if(F[i][j]=='o') m[{i,j}] = 1;
            }
        }
        for(int i=1;i<=id;i++) for(int j=1;j<=id;j++){dist[i][j] = inf;}
        for(auto a:m){
            queue<P> Q;
            for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) visited[i][j] = inf;
            Q.push(a.first);
            visited[a.first.first][a.first.second] = 0;
            while(!Q.empty()){
                int x = Q.front().first,y = Q.front().second;
                Q.pop();
                for(int i=0;i<4;i++){
                    int nx = x+dx[i],ny = y+dy[i];
                    if(in(nx,ny)&&visited[nx][ny]==inf&&F[nx][ny]!='x'){
                        visited[nx][ny] = visited[x][y]+1;
                        Q.push({nx,ny});
                    }
                }
            }
            for(auto b:m){
                if(a!=b) dist[a.second][b.second] = visited[b.first.first][b.first.second];
            }
        }
        int ans = inf;
        do{
            int now = 0;
            for(int i=0;i<id-1;i++){
                now += dist[A[i]][A[i+1]];
            }
            ans = min(ans,now);
        }while(next_permutation(A+1,A+id));
        cout << (ans!=inf? ans:-1) << endl;
    }
}


Measured memory_bytes: 3048
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var n int
    fmt.Scan(&n)
    mp := make(map[string]int)
    for i:=0; i<n; i++{
        var c string
        fmt.Scan(&c)
        mp[c]++
    }
    ans := "Four"
    if len(mp)==3{
        ans = "Three"
    }
    fmt.Println(ans)
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    int M;
    cin >> N;
    N += 1;
    cin >> M;
    vector<int> a(M);
    for(int i = 0 ; i<M;i++){
        cin >> a.at(i);
    }
    vector<long long> p(N);
    p.at(0) = 0;
    int point = 0;
    long waru =  pow(10,9)+7;
    for(int s =0 ; s <N ; s++){
        if(point< M && a.at(point) == s){
            point += 1;
             p.at(s) =0;
        }else if(s == 0){ 
            p.at(s) = 1;
        }else if(s == 1){
             p.at(s)  = p.at(s-1);
        }else{
            p.at(s)  = p.at(s-1) + p.at(s-2);
            }
       p.at(s) = p.at(s)%waru;
    }
    /*for(int s =0 ; s <N ; s++){
        cout << s << ":" << p.at(s) << endl;
    }*/
   
    cout << p.at(N-1);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
const int mxN=1000, M=1e9+7;
int h, w, dp[mxN][mxN];
string g[mxN];
 
bool ie(int i, int j) {
	return i>=0&&j>=0&&g[i][j]=='.';
}
 
int main()
 {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	cin >> h >> w;
	for(int i=0; i<h; ++i)
		cin >> g[i];

	dp[0][0]=1;
	for(int i=0; i<h; ++i) 
    {
		for(int j=0; j<w; ++j)
         {
			if(ie(i-1, j))
				dp[i][j]+=dp[i-1][j];
			if(ie(i, j-1))
				dp[i][j]+=dp[i][j-1];
			dp[i][j]%=M;
		}
	}
	cout << dp[h-1][w-1];
}


Measured memory_bytes: 8580
#include<iostream>
using namespace std;
int main(void)
{
    int student[32],n;
    for(int i=1;i<31;i++){
        student[i]=0;
    }
    for(int i=0;i<28;i++){
        cin>>n;
        student[n]=1;
    }
    for(int i=1;i<31;i++){
        if(student[i]==0)cout<<i<<"\n";
    }
}
/*入力例１
3
1
4
5
7
9
6
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30



　
*/

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

int main() {
	int N,K;
	double t,mE;
	cin >> N >> K;
	vector<double> p(N);

	rep(i,N) {
		cin >> t;
		p.at(i) += t*(t+1)/(2*t);
	}

	t = 0;
	rep(i,K)
		t += p.at(i);
	mE = t;
	
	rep(i,N-K) {
		t = t-p.at(i)+p.at(i+K);
		mE = max(mE, t);
	}

	cout << setprecision(30) << mE << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <cmath>
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;


int numofdigits(int x)
{
    int d(0);
    while (x>0)
    {
        x/=10;
        d++;
    }
    return d;
}
int main ()
{
    int n,total(0);
    cin>>n;
    int temp=n;
    int digits=0;
    while (n>0)
    {
        if (numofdigits(n)%2==0)
        {
        }
        else
            total++;
        n--;
    }
    cout<<total;
}


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

template<class T>
T gcd(T a, T b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

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

    const ll MOD = 1e9+7;
    ll n; cin >> n;
    ll ans = 1LL;
    for(ll i = 1LL; i <= n; ++i) ans = ans*i%MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int A = sc.nextInt();

		double bestT = Double.MAX_VALUE;
		int bestId = 0;
		for (int i = 0; i < N; i++) {
			int H = sc.nextInt();
			double temp = T - H * 0.006;
			double def = Math.abs(A - temp);
			if (def < bestT) {
				bestT = def;
				bestId = i + 1;
			}
		}

		System.out.println(bestId);

		sc.close();
	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    vector<int> x[4];
    for(int i = 0; i < 4; i++) {
        x[i] = vector<int>(N + 1, 0);
    }
    x[0][0] = 1;
    for(int n = 0; n <= N; n++) {
        for(int r = 0; n + r * R <= N; r++) {
            x[1][n + r * R] += x[0][n];
        }
    }
    for (int n = 0; n <= N; n++) {
        for(int g = 0; n + g * G <= N; g++) {
            x[2][n + g * G] += x[1][n];
        }
    }
    for (int n = 0; n <= N; n++) {
        for (int b = 0; n + b * B <= N; b++) {
            x[3][n + b * B] += x[2][n];
        }
    }
    cout << x[3][N] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18+500
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
	a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
	a = min(a, b);
}
#define MAXN
#if !testing
#define cerr if(0)cout
#endif
int32_t main() {
	IAMSPEED
	string str; cin >> str;
	int n = str.size();
	ll ans = n;
	str = "A" + str;
	FOR(i,1,n) {
		if(str[i]!=str[i+1]) {
			minself(ans,max(i,n-i));
		}
	}
	cout<<ans;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a*b>=c*d){
    cout<<a*b<<endl;
  }
  else{
    cout<<c*d<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
 
#define endl '\n'
#define ll long long
 
using namespace std;
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
 
 
	string s;
	cin >> s;
 
	for (int i = 0; i < 3; i++)
	{
		if (s[i] == '7') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
 
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;

ll n, ans = 0;

int main()
{
    fastInp;

    cin >> n;
    vector <ll> vec(n);

    for (auto &cur : vec)
        cin >> cur;

    ll mx = vec[0];

    for (ll i = 0; i < n; ++i)
    {
        mx = max(mx, vec[i]);
        ans += mx - vec[i];
    }
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 4756
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long a = scan.nextLong();
    long b = scan.nextLong();

    long c = a%b;
    if (b-c > c){
      System.out.println(c);
    }
    else{
      System.out.println(b-c);
    }
  }
}


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

#define in(x) cin>>(x)
#define oute(x) cout<<(x)<<endl

int main(){
  int a,b;in(a);in(b);
  if((a+b)%2) oute("IMPOSSIBLE");
  else oute((a+b)/2);
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		List<int> input = IO.GetIntList();
		int n = input[0];
		int k = input[1];
		List<double> h = IO.GetDoubleList();
		h.Sort();
		
		for(int i=0;i<k;i++){
		    if(n-1-i < 0)break;
		    h.RemoveAt(n-1-i);
		}
		
		Console.WriteLine(h.Sum());
	}

}

static class IO
{
    static public string GetString() { return Console.ReadLine(); }
    static public int GetInt() { return int.Parse(Console.ReadLine()); }
    static public long GetLong() { return long.Parse(Console.ReadLine()); }
    static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
    static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
    static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
    static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
    static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
}

Measured memory_bytes: 38016
N, K = map(int, input().split())
X = list(map(int, input().split()))
M = float('inf')
for i in range(N-K+1):
    l = X[i]
    r = X[i+K-1]
    if l * r >= 0:
        M = min(max(abs(l), abs(r)), M)
    else:
        M = min(M, min(abs(l), abs(r)) * 2 + max(abs(l), abs(r)))
print(int(M))


Measured memory_bytes: 14224
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  ll A[N]; rep(i,N) cin >> A[i];

  ll m = 0, result = 0;
  rep(i,N) {
    if (A[i]<0) { m++; A[i]*=-1; }
    result += A[i];
  }

  if(m%2==1) {
    sort(A,A+N);
    result -= A[0]*2;
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>

#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define IN(x) int (x); cin >> x
#define INS(x) string (s); cin >> s
#define INL(x) ll (x); cin >> x
#define VINT(a,n) vector<int> a(n)
#define VIN(a,n) VINT(a,n); REP(i,n){cin >> a[i];}
#define ALL(x) (x).begin(),(x).end()

int main () {
  string s;
  cin >> s;
  if (s[0]==s[1]||s[1]==s[2]||s[2]==s[3])
    cout<<"Bad";
  else
    cout<<"Good";
}


Measured memory_bytes: 256
#include <cstdio>
#define ROP(i,n) for(int i=0;i<n;i++)
#define ROOP(i,n) for(int i=1;i<=n;i++)
using namespace std;
int main(){
  char MAP[60][60];
  int H,W;
  int MINE[60][60];
  int dx[8]={1,0,-1,1,-1,1,0,-1};
  int dy[8]={1,1,1,0,0,-1,-1,-1};
  scanf("%d %d",&H,&W);
  ROOP(i,H){
    ROP(j,W+1) scanf("%c",&MAP[j][i]);
  }
  ROOP(i,H){
    ROOP(j,W){
      if(MAP[j][i]=='.'){
        int cnt=0;
        ROP(k,8){
          if(MAP[j+dx[k]][i+dy[k]]=='#'){
            cnt++;
          }
        }
        MINE[j][i]=cnt;
      }
    }
  }
  ROOP(i,H){
    ROOP(j,W){
      if(MAP[j][i]=='#') printf("#");
      else printf("%d",MINE[j][i]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int n;

vector<int> cut(int k,vector<int> cards){
  vector<int>res;
  for(int i=k;i<2*n;i++)res.push_back(cards[i]);
  for(int i=0;i<k;i++)res.push_back(cards[i]);
  return res;
}

vector<int> rifle(vector<int> cards){
  vector<int>res;
  for(int i=0;i<n;i++){
    res.push_back(cards[i]);
    res.push_back(cards[n+i]);
  }
  return res;
}

int main(void){
  int m,k;
  vector<int> cards;

  cin >> n;
  for(int i=1;i<=2*n;i++)cards.push_back(i);

  cin >> m;
  for(int i=0;i<m;i++){
    cin >> k;
    cards = k ? cut(k,cards) : rifle(cards);
  }
  for(int i=0;i<2*n;i++)cout << cards[i] << endl;

  return 0;
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(3*n);
  for(int i=0;i<3*n;i++){
    cin >> a[i];
  }
  ll ans=0;
  vector<ll> P(n+1,0);
  priority_queue<ll,vector<ll>,greater<ll>> q;
  for(int i=0;i<n;i++){
    q.push(a[i]);
    P[0]+=a[i];
  }
  for(int i=0;i<n;i++){
    ll k=a[n+i];
    q.push(a[n+i]);
    ll c=q.top();
    q.pop();
    P[i+1]=P[i]+k-c;
  }
  reverse(a.begin(),a.end());
  vector<ll> M(n+1,0);
  priority_queue<ll> Q;
  for(int i=0;i<n;i++){
    Q.push(a[i]);
    M[n]+=a[i];
  }
  for(int i=1;i<=n;i++){
    ll k=a[n+i-1];
    Q.push(k);
    ll c=Q.top();
    Q.pop();
    M[n-i]=M[n-i+1]+k-c;
  }
  ans=P[0]-M[0];
  for(int i=1;i<=n;i++){
    ans=max(ans,P[i]-M[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 6516
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
typedef unsigned long long ll;
using namespace std;
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
inline int rd(){
	int res=0,sign=1;char ch;
	while((ch=getchar())<'0'||ch>'9')if(ch=='-')sign=-1;res=res*10+ch-48;
	while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;
	return res*sign;
}
ll x,y;
ll sum;
int main(){
	x=rd(),y=rd();
	sum=x*y;
	if(x==1||y==1)puts("1");
	else printf("%llu\n",(sum+1)/2);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<string.h>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<deque>
#include<string>
#include<stack>
using namespace std;

signed main() {
	string a; cin >> a;
	cout << a.substr(0, a.length() - 8) << endl;
}

Measured memory_bytes: 764
short*z,a[2][102];n,m,i,p;main(c){for(;m=scanf("%d %[^\n] %[^\n]",&n,a,a+1)*n;printf(m>n?"NA\n":"%d\n",m))for(i=2;i--;m=c)for(c=p=0;z=p+a[c+i&1],c<m&&*z&2|n+~p;)p+=p>=n|*z&2?-1:*z&1&z[1]?1:!++c+2;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int mat[16][16];
ll dp[1<<16];
ll p2[600];
ll p2r[600];
ll mo=1000000007;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	p2[0]=p2r[0]=1;
	p2[1]=2;
	p2r[1]=(mo+1)/2;
	for(i=2;i<=590;i++) p2[i]=p2[i-1]*p2[1]%mo,p2r[i]=p2r[i-1]*p2r[1]%mo;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y;
		mat[x-1][y-1]=mat[y-1][x-1]=1;
	}
	
	dp[1]=dp[2]=1;
	for(int mask=3;mask<1<<N;mask++) {
		if((mask&3)==0 || (mask&3)==3) continue;
		dp[mask]=1;
		for(int smask=(mask-1)&mask; smask>0; smask=(smask-1)&mask) {
			if((smask&3)==0) continue;
			int oth=mask^smask;
			int num=0;
			FOR(x,N) if(smask&(1<<x)) {
				FOR(y,N) if(oth&(1<<y)) {
					num+=mat[x][y];
				}
			}
			dp[mask]+=mo-dp[smask]*p2r[num]%mo;
		}
		dp[mask]%=mo;
	}
	
	ll ret=1;
	for(int mask=0;mask<1<<N;mask++) if(mask&1) {
		int left=((1<<N)-1)^mask;
		for(int smask=left; smask>0; smask=(smask-1)&left) {
			if((smask&2)==0) continue;
			if(dp[mask]==0 || dp[smask]==0) continue;
			
			int num=0;
			FOR(x,N) if(mask&(1<<x)) {
				FOR(y,N) if(smask&(1<<y)) {
					num+=mat[x][y];
				}
			}
			if(num) continue;
			num=0;
			FOR(x,N) FOR(y,N) if(mat[x][y]) {
				if((mask&(1<<x)) && ((mask&(1<<y))==0)) num++;
				if((smask&(1<<x)) && ((smask&(1<<y))==0)) num++;
			}
			ret+=mo-dp[mask]*dp[smask]%mo*p2r[num]%mo;
		}
	}
	cout<<ret%mo*p2[M]%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

#define rep(i, n) for(int (i) = 0; i < (n); ++(i))

typedef long long ll;
const ll MOD = 1e9 + 7;

template<typename T, typename IT>
std::vector< std::pair<T, int> > rle(IT first, IT last) {
  T last_value = *first;

  std::vector< std::pair<T, int> > ret;
  int cnt = 0;
  for(auto it = first; it != last; ++it) {
    T e = *(it);
    if(last_value == e) ++cnt;
    else {
      ret.push_back(std::make_pair(last_value, cnt));
      last_value = e;
      cnt = 1;
    }
  }
  ret.push_back(std::make_pair(last_value, cnt));
  return ret;
}

int main() {
  int N;
  std::string S;

  std::cin >> N >> S;
  auto encoded = rle<char>(S.begin(), S.end());

  std::cout << encoded.size() << '\n';
}


Measured memory_bytes: 1528
#include <iostream>
#include <vector>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;
 
int main() {
	uint H, W;
	cin >> H >> W;
	
	vector<vector<uint>> AB(H, vector<uint>(W));

	for(uint i=0; i<H; i++) {
		for(uint j=0; j<W; j++) {
			cin >> AB[i][j];
		}
	}
	
	for(uint i=0; i<H; i++) {
		for(uint j=0; j<W; j++) {
			int B;
			cin >> B;
			AB[i][j] = abs((int)AB[i][j] - B);
		}
	}
	
	uint nbit = 80 * (H + W) * 2 + 1;
	uint p0 = 80 * (H + W);
	vector<vector<boost::dynamic_bitset<>>> dp(2, vector<boost::dynamic_bitset<>>(W, boost::dynamic_bitset<>(nbit)));
	
	dp[1][0].set(p0);
	
	for(uint i=0; i<H; i++) {
		uint i0 = i % 2;
		uint i1 = (i + 1) % 2;
			
		dp[i0][0] = (dp[i1][0] << AB[i][0]) | (dp[i1][0] >> AB[i][0]);
			
		for(uint j=1; j<W; j++) {
			dp[i0][j] = (dp[i0][j-1] << AB[i][j]) | (dp[i0][j-1] >> AB[i][j]) | (dp[i1][j] << AB[i][j]) | (dp[i1][j] >> AB[i][j]);
			//cout << i << " " << j << " " << dp[i0][j] << endl;
		}
	}
	
	for(uint i=0; i<p0; i++) {
		if(dp[(H-1)%2][W-1][p0+i]) {
			cout << i;
			break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

#define rep(i, n) for (long long i = 0; i < n; i++)

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve() {
    ini(n);
    vll a(n);
    rep(i, n) cin >> a[i];

    ll ret1 = 0; 
    ll sum1 = 0;
    bool must_plus = true;
    rep (i, n) {
        sum1 += a[i];
        if (must_plus && sum1 <= 0)  {
            ret1 += 1 - sum1;
            sum1 = 1;
        } else if (!must_plus && sum1 >= 0) {
            ret1 += 1 + sum1;
            sum1 = -1;
        }
        must_plus = !must_plus;
    }
    
    ll ret2 = 0; 
    ll sum2 = 0;
    must_plus = false;
    rep (i, n) {
        sum2 += a[i];
        if (must_plus && sum2 <= 0)  {
            ret2 += 1 - sum2;
            sum2 = 1;
        } else if (!must_plus && sum2 >= 0) {
            ret2 += 1 + sum2;
            sum2 = -1;
        }
        must_plus = !must_plus;
    }

    out(min(ret1, ret2));
}


Measured memory_bytes: 3964