akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        s: chars,
        t: chars,
    }
    let n = s.len();
    puts!("{}\n", (0..n).filter(|&i| s[i] != t[i]).count());
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 3132
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    char op;
    for(;;){
    cin >> a >> op >> b;
    if(op == '?') break;
    if(op == '+') cout << a + b << endl;
    if(op == '-') cout << a - b << endl;
    if(op == '*') cout << a * b << endl;
    if(op == '/') cout << a / b << endl;
    }
}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> v(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    v.at(a-1) += 1;
    v.at(b-1) += 1;
  }
  
  for (int i = 0; i < N; i++) {
    cout << v.at(i) << endl;
  }
}


Measured memory_bytes: 256
import numpy as np
n, k = map(int,input().split())
H = np.array(input().split(), dtype=np.int64)

INF = 10 ** 9 + 1
dp = np.full(n, INF, dtype=np.int64)
dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[max(i - k,0):i] + np.abs(H[max(i - k,0):i] - H[i]))

print(dp[-1])

Measured memory_bytes: 38920
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n, r;
  scanf("%d%d", &n, &r);
  int ans;
  if (n>=10)
    ans = r;
  else
    ans = r + 100*(10-n);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std;
template<class _T>inline void read(_T &_a)
{
    bool f=0; char _c=getchar(); _a=0;
    while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
    while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
    if(f) _a=-_a;
}

const int MAXN=100002;
int n;
struct NODE
{
    int a,id;
    inline bool operator < (const NODE &x) const { return a<x.a; }
}e[MAXN];

int main()
{
    read(n);
    for (int i=1;i<=n;++i)
    {
        read(e[i].a);
        e[i].id=i;
    }
    sort(e+1,e+n+1);
    for (int i=1;i<=n;++i) printf("%d ",e[i].id);
    return 0;
}

Measured memory_bytes: 4384
s = input()

out_s = []
for i in range(len(s)):
  if s[i] == '0' or s[i] == '1':
    out_s.append(s[i])
  elif s[i] == 'B':
    if len(out_s) != 0:
      del out_s[-1]

tmp = ''
for i in range(len(out_s)):
  tmp += out_s[i]
print(tmp)
      
    


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
int fact[N];
int pwr(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1)
			res = res * x % mod;
		y >>= 1;
		x = x * x % mod;
	}
	return res;
}
int ncr(int n, int r) {
	int ans = fact[n];
	ans = ans * pwr(fact[n - r], mod - 2) % mod;
	ans = ans * pwr(fact[r], mod - 2) % mod;
	return ans;
}
void solve() {
	int ans = 0;
	int n , k;
	cin >> n >> k;
	int sum = n * (n + 1) / 2;
	for (int i = k; i <= n; i++) {
		int flag = n - i;
		int mx_sum = sum - flag * (flag + 1) / 2;
		int mi_sum = (i) * (i - 1) / 2;
		ans = ans + mx_sum - mi_sum + 1;
		if (ans >= mod)
			ans %= mod;
	}
	cout << (ans + 1) % mod << endl;
}
int32_t main() {
	BOLT;
	int t;
	t = 1;
	while (t--) {
		solve();
	}
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  int x, y;
  cin >> x >> y;

  int ans = INF;
  if (y - x >= 0) chmin(ans, y - x);
  if (y + x >= 0) chmin(ans, y+x + 1);
  if (-y -x >= 0) chmin(ans, -y -x + 1);
  if (-y +x >= 0) chmin(ans, -y+x + 2);
 
  cout << ans << endl;  

  return 0;
}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


import numpy as np
from numba import njit, b1, i4, i8, f8
from heapq import heappop as hpp, heappush as hp

@njit((b1[:, :],i8,i8,i8,i8), cache=True, fastmath=True, parallel=True)
def main(ss,ch,cw,dh,dw):
    inf = 1<<30
    h,w = ss.shape
    start = ch*w+cw
    goal = dh*w+dw
    n = h*w
    seen = np.full(n, inf, np.int64)
    seen[start] = 0
    q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置
    while q:
        pnum,pu = hpp(q)
        ux,uy = divmod(pu,w)
        if pu==goal:
            break
        for xx in range(-2, 3):
            for yy in range(-2, 3):
                if xx==yy==0:
                    continue
                if abs(xx)+abs(yy)<=1:
                    vv = 0
                else:
                    vv = 1
                x,y = ux+xx, uy+yy
                u = x*w + y
                num = pnum+vv
                if x<0 or y<0 or x>=h or y>=w or ss[x][y]:
                    continue
        #         print(x,y)
                if seen[u]>num:
                    seen[u] = num
                    hp(q,(num, u))
                
    val = seen[goal]
    if val==inf:
        return -1
    else:
        return val
h,w = map(int, input().split())
ch,cw = map(int, input().split())
dh,dw = map(int, input().split())
ch -= 1
cw -= 1
dh -= 1
dw -= 1
rows,cols = h,w

OK = "."
NG = "#"

ss = np.array([[c=="#" for c in input()] for _ in range(h)])

print(main(ss,ch,cw,dh,dw))

Measured memory_bytes: 120076
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define mp make_pair
#define bp __builtin_popcountll

const int N = 100005;
const int MOD = 1000000007;
const int MOD1 = 1000000009;

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
    ll n;
    cin >> n;
    multiset<ll> s;
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin >> x;
        if(!s.size())    s.insert(x);
        else
        {
            ll mini = *s.begin();
            ll maxi = *s.rbegin();
            if(x<=mini)   s.insert(x);
            else if(x>maxi)
            {
                s.erase(s.find(maxi));
                s.insert(x);
            }
            else
            {
                auto it = s.lower_bound(x);
                it--;
                s.erase(it);
                s.insert(x);
            }
        }
    }
    cout<<s.size();
}

int main()
{
    FAST;
    ll t = 1;
  //  cin >> t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 4992
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int main(){
    //std::stack<int> stack;
    string s;
    cin >> s;
    string ans = "Yes";
    if(s == "AAA" || s == "BBB"){
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    ll d, t, s;
    cin >> d >> t >> s;
    if (t * s >= d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ld long double
#define inf 1e18
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mk make_pair
#define mod 1000000007
#define setbits __builtin_popcount
#define fi first
#define se second
int main()
{
    fastIO;
    ll n;
    cin>>n;
    ll a[n],i;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll pre[n]={0},suf[n]={0};
    pre[0]=a[0];
    suf[n-1]=a[n-1];
    for(i=1;i<n;i++)    
    {
        pre[i]=pre[i-1]+a[i];
    }
    for(i=n-2;i>=0;i--)
    {
        suf[i]=suf[i+1]+a[i];
    }
    ll val2,val,val1,ans=0,x,y;
    val=INT_MAX;
    val1=INT_MAX;
    for(i=0;i<n;i++)
    {
        x=pre[i];
        y=suf[i]-a[i];
        y=abs(x-y);
        if(val>y)
        {
            val=y;
        }
    }
    ans=val;
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for (int i=(a); i>=(b); --i)
#define REP(i,b) for (int i=0; i<(b); ++i)
#define endl '\n'
#define sz(x) (int) x.size()
#define mod %
#define fillchar(x,y,z) memset(x,z,y)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define sqr(x) ((x)*(x))
typedef long long int64;
typedef unsigned long long qword;
using namespace std;
const int maxn=1e5+5;
int n;
int h[maxn],f[maxn];
void Input()
{
    cin >> n;
    FOR(i,1,n) cin >> h[i];
    f[1]=0;
    f[0]=1e9;
    FOR(i,2,n)
        f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
    cout << f[n];
}
void Solve()
{

}
int main()
{
    #ifdef meomeomeooooo
        freopen("input.txt","r",stdin);
        //freopen(".out","w",stdout);
    #endif // meomeomeooooo
    iostream::sync_with_stdio(false);
    cin.tie(0);
    Input();
    Solve();
    return 0;
}



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

int main(){

  int n;
  cin >> n;
  int c0 = 0, c2 = 0, c4 = 0;

  rep(i,n) {
    int a;
    cin >> a;
    if (a%4 == 0) c4++;
    else if (a%2 == 0) c2++;
    else c0++;
  }
  
  if (c2 >= 1) c0++;
  cout << (c4+1 >= c0 ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
path=[list(map(int,e.split(',')))for e in sys.stdin]
for i in range(1,len(path)):
    for j in range(len(path[i])):
        if len(path[i])>len(path[i-1]):
            start=0 if j<1 else j-1
            path[i][j]+=max(path[i-1][start:j+1])
        else:
            path[i][j]+=max(path[i-1][j:j+2])
print(path[-1][-1])


Measured memory_bytes: 5608
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>


using namespace std;


int main()
{
    long long n,sum=1;
    cin>>n;
    for(int i=1;i<=n;i=i+1)
    sum=(sum*i)%1000000007;
    cout<<sum;
    system("pause");
    return 0;
}         

Measured memory_bytes: 504
#include <stdio.h>

int main(void)
{
    int i, j, k, l, n;
    int count;
    
    while (fscanf(stdin,"%d", &n) != EOF){
        
        count = 0;
        for (i = 0; i <= 9; i++){
            for (j = 0; j <= 9; j++){
                for (k = 0; k <= 9; k++){
                    for (l = 0; l <=9; l++){
                        if (i + j + k + l == n){
                            count++;
                        }
                    }
                }
            }     
        }

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

    return (0);
}



Measured memory_bytes: 2028
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il print(T x){
	if(x/10) print(x/10);
	putchar(x%10+'0');
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x%mod;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res%mod;
}
int n;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	ri ans=pow(n,3);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
# coding: utf-8
# Your code here!
import collections
N = int(input())
A = list(map(int,input().split()))
A.sort()
mod = 10 ** 9 + 7
Flg = True
if N % 2 == 1:
    a = A.pop(0)
    if a != 0:
        Flg = False

k = (N % 2) + 1
for i in range(N //2):
    if A[i *2] != k or A[i * 2 + 1] != k:
        Flg = False
    k += 2
    
if Flg:
    ans = (2 ** (N // 2)) % mod
else:
    ans = 0
    
print(ans)

Measured memory_bytes: 52332
N, M = [int(_) for _ in input().split()]
XY = [[int(_) - 1 for _ in input().split()] for _ in range(M)]

red = [False] * N
red[0] = True
num = [1] * N

for x, y in XY:
    num[x] -= 1
    num[y] += 1
    if red[x] == True:
        red[y] = True
        if num[x] == 0:
            red[x] = False
print(sum(red))

# http://agc002.contest.atcoder.jp/data/agc/002/editorial.pdf


Measured memory_bytes: 22692
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    ll mx1 = 0, mx2 = 0;
    rep(i, n){
        if(a[i] > mx1){
            mx2 = mx1; mx1 = a[i];
        }
        else if(a[i] > mx2){
            mx2 = a[i];
        }
    }
    rep(i, n)
    {
        cout << (a[i] == mx1 ? mx2 : mx1) << " ";
    }
}
main(){
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 3200
def solve(a, b, m, a_list, b_list, xyc_list):
    res = min(a_list) + min(b_list)
    for x, y, c in xyc_list:
        r = a_list[x - 1] + b_list[y - 1] - c
        res = min(res, r)
    return res


def main():
    a, b, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    xyc_list = [list(map(int, input().split())) for _ in range(m)]
    res = solve(a, b, m, a_list, b_list, xyc_list)
    print(res)


def test():
    assert solve(2, 3, 1, [3, 3], [3, 3, 3], [[1, 2, 1]]) == 5
    assert solve(1, 1, 2, [10], [10], [[1, 1, 5], [1, 1, 10]]) == 10
    assert solve(2, 2, 1, [3, 5], [3, 5], [[2, 2, 2]]) == 6


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 38568
<?php
$n = fgets(STDIN);
$nums = array_map('intval', explode(' ',fgets(STDIN)));
$sum = true;
for ($i = 0; $i < $n; $i++) {
    (int)$sum *= $nums[$i];
}

if($sum>pow(10,18)) {
    echo -1;
} else {
    echo (int)$sum;
}

Measured memory_bytes: 28640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int n,m;cin>>n>>m;
    bool flag[n+1]={false};
    int pen[n+1]={0};
    rep(i,m){
        int num;string s;cin>>num>>s;
        if(s=="AC")flag[num]=true;
        else if(!flag[num])pen[num]++;
    }
    int ans1 = 0;
    rep(i,n+1){
        if(flag[i])ans1+=pen[i];
    }
    int ans2 = count(flag,flag+(n+1), true);
    cosp(ans2);co(ans1);
}

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

int const N = 2e4;
int n, a[N+1], b[N+1], p[N+1];

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&p[i]);
	}
	int cntA = 0, cntB = 0;
	for(int i=1;i<=n;++i){
		if(i > 1){
			if(p[i] > p[i-1]){
				++cntB;
			}else{
				++cntA;
			}
		}
		a[p[i]] = p[i] * N + cntA;
		b[p[i]] = (n-p[i]+1) * N + cntB;
	}
	for(int i=1;i<=n;++i){
		printf("%d ",a[i]);
	}
	printf("\n");
	for(int i=1;i<=n;++i){
		printf("%d ",b[i]);
	}
	
	
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string S;
  cin >> S;
  if (S[2] == S[3]) {
    if (S[4] == S[5]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 2996
S = input()[::-1]
li = ["dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1]]

while len(S) > 0:
  for i in li:
    if S.find(i) == 0:
      S = S[len(i):]
      break
  else:
    print("NO")
    exit()
print("YES")

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

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  bool ok = false;
  string s;
  cin >> s;
  s = "#" + s + "#";
  for (int i = a; i + 1 <= d; i++){
    if(s[i] == '#' && s[i+1] == '#'){
      cout << "No" << endl;
      return 0;
    }
  }
  if(c > d){
    for (int i = b; i <= d; i++){
      if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') ok = true;
    }
    if(!ok){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 772
#include <stdio.h>

int main(void)
{
  float a, b, c, d, e, f;

  while (scanf("%f%f%f%f%f%f", &a, &b, &c, &d, &e, &f) != EOF)
    printf("%.3f %.3f\n", (-b*f+c*e)/(a*e-b*d)+0.00001, (-c*d+a*f)/(a*e-b*d)+0.00001);

  return 0;
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=1e3+5;
const char s4[4][4]={{'a','a','c','d'},{'b','b','c','d'},{'e','f','g','g'},{'e','f','h','h'}};
const char s5[5][5]={{'a','a','b','b','c'},{'h','i','i','.','c'},{'h','.','.','j','d'},{'g','.','.','j','d'},{'g','f','f','e','e'}};
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n;char ans[MAXN][MAXN];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read();
	if(n==1||n==2)return puts("-1"),0;
	if(n==3)return puts("aab\nd.b\ndcc"),0;
	if(n==6)return puts("aabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b\n"),0;
	if(n==7)return puts("..aeeff\ndca....\ndcb....\n..bgghh\nmli....\nmli....\nnn.jjkk"),0;		
	if(n==11)return puts("..aeeff....\ndca........\ndcb........\n..bgghh....\nmli........\nmli........\nnn.jjkk....\n.......aacd\n.......bbcd\n.......efgg\n.......efhh"),0;
	Rep(i,0,n-1)Rep(j,0,n-1)ans[i][j]='.';
	Rep(t,0,1000)if((n-4*t)%5==0){
		Rep(i,0,t-1){
			int x=i*4;
			Rep(j,0,3)Rep(k,0,3)ans[x+j][x+k]=s4[j][k];
		}
		Rep(i,0,(n-4*t)/5-1){
			int x=t*4+i*5;
			Rep(j,0,4)Rep(k,0,4)ans[x+j][x+k]=s5[j][k];
		}
		break;
	}Rep(i,0,n-1)puts(ans[i]);
	return 0;
}




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

int main () {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  bool turn = true;

  while (A > 0 && C> 0) {
    if (turn) {
    	C = C - B;
      turn = false;
    } else {
    	A = A - D;
      turn = true;
    }    
  }

  if (turn) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  
}


Measured memory_bytes: 3604
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;

const int inf = 1e9 + 7;
#define EPS 1e-9

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	int cnt0 = 0, cnt1 = 0;
	rep(i, n) {
		if (s[i] == '0') ++cnt0;
		else cnt1++;
	}
	cout << 2 * min(cnt0, cnt1) << endl;
	return 0;
}

Measured memory_bytes: 512
N, M = map(int, input().split())
List = []
for _ in range(N):
    A, B = map(int, input().split())
    List.append((A, B))
List.sort(key=lambda x: x[0])
Res = 0
for i in range(N):
    A, B = List[i]
    if B <= M:
        M -= B
        Res += A*B
    else:
        Res += A*M
        break
print(Res)

Measured memory_bytes: 23772
#include <iostream>
#include <ammintrin.h>
using namespace std;

int main()
{
   long long n,m,i,j,x,y,z;
   cin>>n>>x>>y;
   long long  s[n+1]={0};

   for(i=1;i<n;i++)
   {
       for(j=i+1;j<=n;j++)
       {
           if(i<=x&&j>=y)
           {
               z=j-i-(y-x)+1;
               s[z]++;
           }
           else if(i<=x&&j<=y&&j>=x)
           {
               z=j-i;
               m=x-i+1+y-j;
               z=min(z,m);
               s[z]++;
           }
          else if(i>=x&&i<=y&&j<=y&&j>=x)
           {
               z=j-i;
               m=i-x+1+y-j;
               z=min(z,m);
               s[z]++;
           }
           else if(i>=x&&i<=y&&j>=y)
           {
               z=j-i;
               m=i-x+1+j-y;
               z=min(z,m);
               s[z]++;
           }
           else
           {
               z=j-i;
               s[z]++;
           }
       }
   }
   for(i=1;i<n;i++)
    cout<<s[i]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define maxn 200001
#define rep(i,n) for(int i=0; i<int(n); ++i)
#define pb push_back
#define mp make_pair
#define mod 1000000007

int n, m, x, y;
int a[maxn], b[maxn], back[maxn], nxt[maxn], ans[maxn];
bool vis[maxn];
vector<int> c, e[maxn];
void circle(){
	int hd;
	for (int u = 1;; u = back[u]){
		if (vis[u]){
			hd = u;
			break;
		}
		vis[u] = 1;
	}
	for (int u = hd; ;){
		c.pb(u);
		nxt[back[u]] = u; 
		u = back[u];
		if (u == hd) break;
	}
}
void dfs(int u){
	vector<int> tmp;
	tmp.clear();
	for (int v : e[u]){
		if (v != nxt[u]){
			dfs(v);
			tmp.pb(a[v]);
		}
	}
	sort(tmp.begin(), tmp.end());
	tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
	int i = 0;
	while (tmp.size() > i && tmp[i] == i) ++i;
	a[u] = i;
	while (tmp.size() > i && tmp[i] == i + 1) ++i;
	b[u] = i + 1;
	//cout << u << ' ' << a[u] << ' ' << b[u] << endl;
}
void solve(){
	cin >> n;
	for (int i = 1; i <= n; ++i){
		cin >> x;
		e[x].pb(i);
		back[i] = x;
	}
	circle();
	for (int i : c) dfs(i);
	//
	ans[c[0]] = a[c[0]];
	for (int u = back[c[0]]; u != c[0]; u = back[u]){
		ans[u] = (ans[nxt[u]] == a[u]) ? b[u] : a[u];
	}
	if (a[c[0]] != ans[nxt[c[0]]]){
		puts("POSSIBLE");
		return;
	}
	ans[c[0]] = b[c[0]];
	for (int u = back[c[0]]; u != c[0]; u = back[u]){
		ans[u] = (ans[nxt[u]] == a[u]) ? b[u] : a[u];
	}
	if (a[c[0]] == ans[nxt[c[0]]]){
		puts("POSSIBLE");
		return;
	}
	puts("IMPOSSIBLE");
}

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    solve();
}

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

//_____
typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
typedef vector<Pii> Vp;
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define show(x) cerr << #x << ':' << x << endl
#define outl(x) cout << x << '\n';
#define INF (1 << 29)
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
inline int chmax(int &a, int b){return b>a ? a=b,1 : 0;}
inline int chmin(int &a, int b){return b<a ? a=b,1 : 0;}
//_______

int n,k;
int a[100];

main(){
  FAST();
  int sum = 0;
  cin >> n >> k;
  rep(i,n)cin >> a[i];
  sort(a,a+n, greater<int>());
  for(int i=0; i<k; ++i)sum += a[i];
  outl(sum);
}



Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < N; i++) {
			int a = in.nextInt();
			if (map.containsKey(a)) {
				map.put(a, map.get(a) + 1);
			} else {
				map.put(a, 1);
			}
		}
		Integer ans = 0;
		for (Map.Entry<Integer, Integer> e : map.entrySet()) {
			Integer key = e.getKey();
			Integer num = e.getValue();
			if (num > key) {
				ans += (num - key);
			} else if (num < key) {
				ans += num;
			}
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 63744
#include <stdio.h>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
  ll t;
  while(b) {
    t = a % b;
    a = b, b = t;
  }
  return a;
}

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

int main(void) {
  ll i, j, n, ans = 0;
  scanf("%lld", &n);
  ll p[n], m = 1 << n;
  for(i = 0; i < n; ++i) scanf("%lld", &p[i]);
  for(i = 1; i < m; ++i) {
    bool flg = true;
    ll now = 1;
    for(j = 0; j < n; ++j) if(1 & (i >> j)) now = lcm(now, p[j]);
    for(j = 0; j < n; ++j) if(!(1 & (i >> j))) if(!(now % p[j])) flg = false;
    if(flg) ++ ans;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 2760
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [0] + a
b = [0] + b
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]
i, j, z = 0, m, 0
while i <= n and a[i] <= k:
    while b[j] > k - a[i]:
        j -= 1
    z = max(z, i + j)
    i += 1
print(str(z))

Measured memory_bytes: 41580
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=10000000;
const ll INF=1000000001;
const ll LINF=4000000000000000010;
const double EPS=1e-9;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
int main(){
    int x;cin>>x;
    int d[31];
    d[9]=5;
    for(int i=8;i>=1;i--){
        d[i]=(d[i+1]-1+7)%7;
    }
    for(int i=10;i<=30;i++){
        d[i]=(d[i-1]+1)%7;
    }
    if(d[x]==0){
        cout<<"mon"<<endl;
    }else if(d[x]==1){
        cout<<"tue"<<endl;
    }else if(d[x]==2){
        cout<<"wed"<<endl;
    }else if(d[x]==3){
        cout<<"thu"<<endl;
    }else if(d[x]==4){
        cout<<"fri"<<endl;
    }else if(d[x]==5){
        cout<<"sat"<<endl;
    }else{
        cout<<"sun"<<endl;
    }
}


Measured memory_bytes: 3116
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

// X Y :
var X, Y int
var memo [][2][2]bool

func rec(x, y, dir int, a []int) bool {
	if memo[len(a)][dir][0] == true {
		return memo[len(a)][dir][1]
	}
	ret := false
	if len(a) == 0 {
		if x == X && y == Y {
			ret = true
		}
		return ret
	}
	// out(x, y, dir, a[0])

	if a[0] != 0 {
		if dir == 0 {
			ret = rec(x+a[0], y, dir, a[1:])
			ret = ret || rec(x-a[0], y, dir, a[1:])
		} else {
			ret = rec(x, y+a[0], dir, a[1:])
			ret = ret || rec(x, y-a[0], dir, a[1:])
		}
	} else {
		if dir == 0 {
			ret = rec(x, y, 1, a[1:])
		} else {
			ret = rec(x, y, 0, a[1:])
		}
	}
	memo[len(a)][dir][0] = true
	memo[len(a)][dir][0] = ret
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	s := getString()
	X, Y = getInt(), getInt()

	a := make([]int, 0)
	cnt := 0
	for _, v := range s {
		if v == 'F' {
			cnt++
		} else {
			if cnt != 0 {
				a = append(a, cnt)
			}
			a = append(a, 0)
			cnt = 0
		}
	}
	if s[len(s)-1] == 'F' {
		a = append(a, cnt)
	}

	const maxn = 8100

	var dpX [maxn][2 * maxn]bool
	var dpY [maxn][2 * maxn]bool

	dir := false
	flg := false
	cntX, cntY := 0, 0

	dpX[0][maxn] = true
	dpY[0][maxn] = true

	for i := 0; i < len(a); i++ {
		if a[i] == 0 {
			dir = !dir
		} else {
			if !dir { // x
				cntX++
				for j := 0; j < maxn*2; j++ {
					if dpX[cntX-1][j] {

						if j+a[i] < maxn*2 {
							dpX[cntX][j+a[i]] = true
						}
						if j-a[i] >= 0 && flg {
							dpX[cntX][j-a[i]] = true
						}
					}
				}
			} else {
				cntY++
				for j := 0; j < maxn*2; j++ {
					if dpY[cntY-1][j] {
						if j+a[i] < maxn*2 {
							dpY[cntY][j+a[i]] = true
						}
						if j-a[i] >= 0 && flg {
							dpY[cntY][j-a[i]] = true
						}
					}
				}
			}
		}
		flg = true
	}

	// for i := 0; i <= cntX; i++ {
	// 	out(dpX[i][maxn-4 : maxn+5])
	// }
	// out(cntX, cntY)

	if dpX[cntX][X+maxn] && dpY[cntY][Y+maxn] {
		out("Yes")
	} else {
		out("No")
	}
}


Measured memory_bytes: 75008
#include <stdio.h>

int main(void) {
	int p, n,ap=0,an=0,c=0;
	while(scanf("%d,%d",&p,&n)!=EOF){
		ap += p*n;
		an += n;
		c += 1;
	}
	an = (double)an/c + 0.5;
	printf("%d\n%d\n",ap,an);
	return 0;
}

Measured memory_bytes: 592
task = input().split(" ")
ans = 5000
if abs ( int(task [ 0 ]) - int(task [ 1 ])) + abs ( int(task [ 2 ]) - int(task [ 0 ])) < ans : 
	ans = abs ( int(task [ 0 ]) - int(task [ 1 ])) + abs ( int(task [ 2 ]) - int(task [ 0 ]))
if abs ( int(task [ 0 ]) - int(task [ 2 ])) + abs ( int(task [ 1 ]) - int(task [ 0 ])) < ans : 
	ans = abs ( int(task [ 0 ]) - int(task [ 2 ])) + abs ( int(task [ 1 ]) - int(task [ 0 ]))
if abs ( int(task [ 1 ]) - int(task [ 0 ])) + abs ( int(task [ 2 ]) - int(task [ 1 ])) < ans : 
	ans = abs ( int(task [ 1 ]) - int(task [ 0 ])) + abs ( int(task [ 2 ]) - int(task [ 1 ]))
if abs ( int(task [ 1 ]) - int(task [ 2 ])) + abs ( int(task [ 0 ]) - int(task [ 1 ])) < ans : 
	ans = abs ( int(task [ 1 ]) - int(task [ 2 ])) + abs ( int(task [ 0 ]) - int(task [ 1 ]))
if abs ( int(task [ 2 ]) - int(task [ 0 ])) + abs ( int(task [ 1 ]) - int(task [ 2 ])) < ans : 
	ans = abs ( int(task [ 2 ]) - int(task [ 0 ])) + abs ( int(task [ 1 ]) - int(task [ 2 ]))
if abs ( int(task [ 2 ]) - int(task [ 1 ])) + abs ( int(task [ 0 ]) - int(task [ 2 ])) < ans : 
	ans = abs ( int(task [ 2 ]) - int(task [ 1 ])) + abs ( int(task [ 0 ]) - int(task [ 2 ]))
print ( ans )

Measured memory_bytes: 3192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const long MOD = 1000000007;
        static void Solve()
        {
            var o = ReadAndParseIntArr();
            int a = o[0];
            int b = o[1];
            int c = o[2];

            string ans = (a + b ) >= c ? "Yes" : "No";
            Console.WriteLine(ans);
        }
#region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
#endregion
    }
}

Measured memory_bytes: 11092
import math

n, m, c = map(int, input().split())
b = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    a = [int(i) for i in input().split()]
    s = c
    for j in range(m):
        s += b[j] * a[j]
    if s > 0:
        ans += 1
print(ans)

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

int h, w, m, a[300001], b[300001], p1, p2;
typedef pair <int, int> pi;
set <pi> st;

int main() {
	int i, j, x, y;
	cin >> h >> w >> m;
	vector <int> l, r;

	for(i = 1; i <= m; ++i) {
		cin >> x >> y;
		st.insert(make_pair(x, y));
		a[x]++;
		b[y]++;
		if(a[x] > p1) {
			l.clear();
			p1 = a[x];
		}
		if(a[x] == p1) l.push_back(x);

		if(b[y] >p2) {
			r.clear();
			p2 = b[y];
		}
		if(b[y] == p2) r.push_back(y);
	}

	for(i = 0; i < l.size(); ++i) {
		for(j = 0; j < r.size(); ++j) {
			if(st.find(make_pair(l[i], r[j])) == st.end()) {
				cout << p1 + p2;
				return 0;
			}
		}
	}

	cout << p1 + p2 - 1;
	return 0;
}

Measured memory_bytes: 21852
#include <stdio.h>


int main(void){
  int k,x,i,j;
  scanf("%d %d",&k,&x );

  if(k == 1){
    printf("%d",x );
  }else{
    i = 2 * k - 1;
    x = x - (k - 1);
    //printf("  %d\n",x );
    for(j = 0; j < i; j++){
        printf("%d ",x + j );
    }
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << #x << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
    int h, w;
    cin >> h >> w;
    char c[h][w];
    REP(i,h) REP(j,w) cin >> c[i][j];
    int dy[] = {1, 0, -1, 0};
    int dx[] = {0, 1, 0, -1};
    REP(i,h) REP(j,w) {
        bool ok = false;
        if (c[i][j] == '#') { 
            REP(k,4) {
                if (i+dy[k] >= h || i+dy[k] < 0 || j+dx[k] >= w || j+dx[k] < 0) continue;
                if (c[i+dy[k]][j+dx[k]] == '#') ok = true;;
            }
            if (!ok) {
                cout << "No" << std::endl;
                return 0;
            }
        }
    }
    cout << "Yes" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 200005
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const ll mod=1e9+7ll;
/*struct node{
	int color;ll val;
}nd[maxn];*/
int n,a,b,x,y;
vector<int>c[maxn];
int cnt[maxn];
int minn=inf,minx=inf,minc,mixc;
ll jc[maxn];
void ready(){
	jc[0]=1;
	for(int i=1;i<=maxn-5;i++) jc[i]=jc[i-1]*(ll)i%mod;
}
ll qkpow(ll t,int pos){
	ll ans=1,base=t;
	while(pos){
		if(pos&1) ans=ans*base%mod;
		base=base*base%mod;
		pos>>=1;
	}
	return ans;
}
void init(){
	scanf("%d%d%d",&n,&x,&y);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a,&b);
		c[a].push_back(b);
	}
	for(int i=1;i<=n;i++){
		if(c[i].size()){
			sort(c[i].begin(),c[i].end());
			int pos;
			for(pos=1;pos<c[i].size();pos++){
				if(c[i][pos]+c[i][0]>x) break;
			} 
		    if(pos!=1)cnt[i]=pos;
			if(c[i][0]<minn) minx=minn,mixc=minc,minn=c[i][0],minc=i;
			else if(c[i][0]<minx) minx=c[i][0],mixc=i;
		}
	}
	
	for(int i=1;i<=n;i++){
		if(c[i].size()==0) continue;
		if(i==minc){
			if(c[i][0]+minx>y) {cnt[i]=0;continue;}
			for(int j=max(0,cnt[i]);j<c[i].size();j++) 
			if(c[i][j]+minx<=y) cnt[i]++;
		}
		else{
			if(c[i][0]+minn>y) {cnt[i]=0;continue;}
			for(int j=max(0,cnt[i]);j<c[i].size();j++) if(c[i][j]+minn<=y) cnt[i]++;
		}
	}
	int sum=0;
	for(int i=1;i<=n;i++) sum+=cnt[i];
	ll ans=1;
	for(int i=1;i<=n;i++){
		if(cnt[i]==0) continue;
		ll t1=jc[sum];
		ll t2=jc[sum-cnt[i]]*jc[cnt[i]]%mod;
		ll inv=qkpow(t2,(int)mod-2);
		ll tt=t1*inv%mod;
		if(tt) ans=(ans*tt)%mod;
		sum-=cnt[i];
	}
	printf("%lld",ans);
}
int main(){
	ready();
	init();
	
	return 0;
}

Measured memory_bytes: 11648
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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

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

    ll N;
    cin >> N;
    vec ans(N, 0);
    Rep (i, N-1) {
        ll a;
        cin >> a;
        a--;
        ans[a]++;
    }

    Rep (i, N) {
        cout << ans[i] << "\n";
    }
  
  	ll a = gcd(4, 6);
}

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

int main()
{
  ll n,a,b; cin>>n>>a>>b;
  ll x = a+b;
  cout << n/x*a + min(a, n%x) << endl;

  return 0;
}


Measured memory_bytes: 256
import heapq


class Dijkstra:

    def __init__(self, rote_map, start_point, goal_point=None):
        self.rote_map = rote_map
        self.start_point = start_point
        self.goal_point = goal_point

    def execute(self):
        num_of_city = 3 * 10 ** 5 + 10
        dist = [float("inf") for _ in range(num_of_city)]
        prev = [float("inf") for _ in range(num_of_city)]

        dist[self.start_point] = 0
        heap_q = []
        heapq.heappush(heap_q, (0, self.start_point))
        route_count = [0 for _ in range(num_of_city)]
        route_count[self.start_point] = 1
        while len(heap_q) != 0:
            prev_cost, src = heapq.heappop(heap_q)

            if dist[src] < prev_cost:
                continue

            for dest, cost in self.rote_map[src].items():
                if cost != float("inf") and dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
                    heapq.heappush(heap_q, (dist[dest], dest))
                    prev[dest] = src
                if dist[dest] == dist[src] + cost:
                    route_count[dest] += route_count[src]

        if self.goal_point is not None:
            return self._get_path(self.goal_point, prev)
        else:
            return dist, route_count

    def _get_path(self, goal, prev):
        path = [goal]
        dest = goal

        while prev[dest] != float("inf"):
            path.append(prev[dest])
            dest = prev[dest]

        return list(reversed(path))


N, M = map(int, input().split())
from collections import defaultdict

graph = defaultdict(dict)
for i in range(M):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph[u][v + N] = 1
    graph[u + N][v + 2 * N] = 1
    graph[u + 2 * N][v] = 1
S, T = map(int, input().split())
S -= 1
T -= 1
dj = Dijkstra(graph, S)

dist, _ = dj.execute()
if dist[T] % 3 == 0:
    print(dist[T] // 3)
else:
    print(-1)


Measured memory_bytes: 151988
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut xs = vec![0; n + 1];
    let mut ys = vec![0; m + 1];
    xs[n] = read::<i64>();
    ys[m] = read::<i64>();
    for i in 0..n {
        xs[i] = read::<i64>();
    }
    for i in 0..m {
        ys[i] = read::<i64>();
    }
    xs.sort();
    ys.sort();
    if xs.last().unwrap() < ys.first().unwrap() {
        println!("No War");
    } else {
        println!("War");
    }
}


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

int main() {
  int n;
  int sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int l,r;
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){
    
    int N, T;
    cin >> N >> T;
    vector<ll> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    ll mini = A[0];
    for(int i = 0; i < N; i++){
        mini = min(mini, A[i]);
        A[i] = A[i] - mini;
    }
    sort(reall(A));
    int cnt = 1;
    for(int i = 1; i < N; i++){
        if(A[i] == A[0]){
            cnt++;
        }
        else break;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    try(Scanner sc = new Scanner(System.in)){
      String line = sc.nextLine();
      String answer = "";
      int length = line.length();
      for(int i=0;i<length;i++){
        char ch = line.charAt(i);
        if(Character.isLowerCase(ch)){
          ch = Character.toUpperCase(ch);
        }else{
          ch = Character.toLowerCase(ch);
        }
        answer = answer + ch;
      }
      System.out.println(answer);
    }
  }
}



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

int Parent(int re){
  return re/2;
}

int Left(int re){
  return 2*re;
}

int Right(int re){
  return 2*re+1;
}

int check(int n,int i){
  if(n >= Right(i)) return 1;
  else if(n >= Left(i) && n < Right(i)) return 2;
  else if(n < Left(i)) return 3;
}

void Print(int *b, int num){

  int i;
  
  for(i=1;i<=num;i++){
    if(Parent(i) == 0){

      if(check(num,i) == 1) printf("node %d: key = %d, left key = %d, right key = %d, \n",i,b[i],b[Left(i)],b[Right(i)]);
      
      else if(check(num,i) == 2) printf("node %d: key = %d, left key = %d, \n",i,b[i],b[Left(i)]);
      
      else if(check(num,i) == 3) printf("node %d: key = %d, \n",i,b[i]);
    }
    
    else{
      if(check(num,i) == 1) printf("node %d: key = %d, parent key = %d, left key = %d, right key = %d, \n",i,b[i],b[Parent(i)],b[Left(i)],b[Right(i)]);
      else if(check(num,i) == 2) printf("node %d: key = %d, parent key = %d, left key = %d, \n",i,b[i],b[Parent(i)],b[Left(i)]);
      else if(check(num,i) == 3)printf("node %d: key = %d, parent key = %d, \n",i,b[i],b[Parent(i)]);
    }
    
  }
  
}

int main(){
  int num,i;
  int *BOX;

  scanf("%d",&num);

  BOX=(int *)malloc((num+1)*sizeof(int));

  for(i=1;i<=num;i++){
    scanf("%d",&BOX[i]);
  }
  
  Print(BOX,num);

  return 0;
}



Measured memory_bytes: 2112