akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
import sys

info = input().split(' ')
card_one = int(info[0])
card_zero = int(info[1])
card_minus = int(info[2])
number = int(info[3])

sumnum = 0

if (number >= card_one):
    number = number - card_one
    sumnum = sumnum + card_one
else:
    print(number)
    sys.exit()

if (number >= card_zero):
    number = number - card_zero
else:
    print(sumnum)
    sys.exit()

if (number >= card_minus):
    sumnum = sumnum - card_minus
    print(sumnum)
else:
    sumnum = sumnum - number
    print(sumnum)

Measured memory_bytes: 61812
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;cin>>n;
  vector<vector<int>>dist(n,vector<int>(n,2e9));
  rep(i,n)rep(j,n)cin>>dist[i][j];
  auto dist2=dist;
  int f=0;
  rep(k,n)rep(i,n)rep(j,n)f|=chmin(dist[i][j],dist[i][k]+dist[k][j]);
  if(f){cout<<-1<<endl;return 0;}
  ll res=0;
  rep(i,n)repi(j,i+1,n)
  {
    int tdist=2e9;
    rep(k,n)
    {
      if(k==i||k==j)continue;
      chmin(tdist,dist[i][k]+dist[k][j]);
    }
    if(tdist!=dist[i][j]){res+=dist[i][j];}
  }
  cout<<res<<endl;


  return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>

using namespace std;

int main()
{
    int N, i, tmp;
    cin >> N;
    vector<int> X;
    for(i=0; i<N; i++) {
        cin >> tmp;
        X.push_back(tmp);
    }
    
    int avg = round((float)accumulate(X.begin(), X.end(), 0.0) / N);
    
    int e = 0;
    for(i=0; i<N; i++) {
        e = e + pow((X[i] - avg), 2);
    }
    
    cout << e << endl;
    
    //getline(cin, str);
    //vector < vector < int > > A(x, vector(y, 0));
    return 0;
}

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

#define u unsigned
#define s short
#define ll long long
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, a, b) for (int i = (a-1); i >= (b); i--)

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    u int R;
    cin >> R;
    cout << M_PI * R * 2 << "\n";

    return 0;
}

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

int c[101][10001];

struct ITEM{
	int v;
	int w;
};

int main(void){

	int n, max_w;

	cin >> n >> max_w;
	memset(c, 0, sizeof(c));

	ITEM item[101];
	item[0].v = 0; item[0].w = 0;
	for (int i = 1; i <= n; i++)
		cin >> item[i].v >> item[i].w;

	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= max_w; j++){
			if (j >= item[i].w)
				c[i][j] = max(c[i - 1][j], c[i - 1][j - item[i].w] + item[i].v);
			else c[i][j] = c[i - 1][j];
//			cout << c[i][j] << ' ';
		}
//		cout << endl;
	}
//	cout << "----------------" << endl;
	cout << c[n][max_w] << endl;

	return 0;
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    int N; cin>>N;
    vector<vector<ll>> A(N,vector<ll>(N,0));
    rep(i,N)rep(j,N)cin>>A[i][j];
    ll res = 0;
    for(int i = 0; i < N-1; i++){
        for(int j = i+1; j < N; j++){
            ll tmp = INF;
            rep(k,N){
                if(i==k||j==k)continue;
                tmp = min(tmp,A[i][k]+A[k][j]);
                if(A[i][j]>A[i][k]+A[k][j]){
                    cout<<-1<<endl;
                    return 0;
                }
            }
            if(A[i][j]<tmp){
                res += A[i][j];
            }
        }
    }
    cout<<res<<endl;
}


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        k: usize,
        v: [i32; n],
    }
    let mut result = 0;
    for i in 1..k+1 {
        let r = std::cmp::min(n, k - i);
        if i >= n {
            let mut nums = v.iter().map(|&vi| vi).collect::<Vec<_>>();
            nums.sort();
            let mut sum = nums.iter().sum();
            for j in 0..r {
                sum -= nums[j];
            }
            if sum > result {
                result = sum;
            }
            continue;
        }
        for left in 0..i+1 {
            let mut nums = Vec::with_capacity(i);
            let right = n - (i - left);
            for j in 0..left {
                nums.push(v[j]);
            }
            for j in right..n {
                nums.push(v[j]);
            }
            nums.sort();
            let mut sum = nums.iter().sum();
            for j in 0..nums.len() {
                if nums[j] > 0 || j >= r {
                    break;
                }
                sum -= nums[j];
            }
            if sum > result {
                result = sum;
            }
        }
    }
    println!("{}", result);
}


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

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

    auto adjacency_list = vector<vector<int>>(N);
    for (auto i = 0; i < M; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        adjacency_list[a].push_back(b);
        adjacency_list[b].push_back(a);
    }

    auto seen = vector<bool>(N);
    auto path = vector<int>();
    const function<void(int)> find_path = [&](const int v)
    {
        seen[v] = true;
        path.push_back(v);
        for (const auto w : adjacency_list[v]) if (!seen[w])
        {
            find_path(w);
            break;
        }
    };

    find_path(0);
    reverse(begin(path), end(path));
    path.pop_back();
    find_path(0);

    cout << path.size() << endl;

    for (const auto v : path) cout << v+1 << " ";
    cout << endl;
}


Measured memory_bytes: 9720
w,h,n=map(int,input().split())
l,r,d,u=0,w,0,h
for i in range(n):
  x,y,a=map(int,input().split())
  if(a<2):l=max(l,x)
  elif(a<3):r=min(r,x)
  elif(a<4):d=max(d,y)
  else:u=min(u,y)
print(max(0,r-l)*max(0,u-d))

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
bool nd[10000007],can[100000007];
ll power(ll bs,int T){
	if(T==0)return 1LL;
	ll med=power(bs,T>>1);
	med=med*med%INF;
	if(T&1)med=med*bs%INF;
	return med;
}
ll solve(ll len,int cho){
	if(cho==0LL)return 0LL;
	len=9*power(10LL,len-1)%INF;
	len-=cho-1;
	if(len<0LL)len+=INF;
	return len;
}
int main(){
	int S,cur=0,dig=0,cn=0;
	ll ans=0LL;
	cin>>S;
	can[0]=true;
	for(cn++;cn<10000000;cn++){
		if(cn==1||cn%10==0&&nd[cn/10]){
			nd[cn]=true;
			dig++;
		}
		cur+=dig;
		can[cur]=true;
		if(cur>=S&&can[cur-S])ans++;
	}
	can[cur]=false;
	dig++;
	for(;cn<=30000000;cn++){
		cur+=dig;
		if(cur-S>=100000000)break;
		if(cur>=S&&can[cur-S])ans++;
	}
	for(int L=8;L<=100000000;L++){
		ans+=max((S-1)/L-S/(L+1),0);
		if(S%L==0)ans+=solve(L,S/L);
	}
	cout<<ans%INF<<'\n';
	return 0;
}

Measured memory_bytes: 72064
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int k;
	cin>>k;
	cout<<a[k-1]<<endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {

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

  int n = 0;

  cin >> n;

  int cur = 0;

  for(int i = 0; i < n; i++) {
    int d1, d2;
    cin >>  d1 >> d2;
    if(d1 == d2) cur++;
    else cur = 0;
    if(cur >= 3) { cout << "Yes\n"; return 0; }
  }

  cout << "No\n";

  return 0;
}
/*

*/


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll A,B;cin>>A>>B;
    rep(i,10000){
        if(i*8/100==A and i*10/100==B){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
def input(): return sys.stdin.readline().rstrip()

# ライブラリ参照https://ikatakos.com/pot/programming_algorithm/data_structure/binary_indexed_tree
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

def main():
    n,q=map(int, input().split())
    A=list(map(int, input().split()))
    bi=Bit(n)
    for i in range(n):
        bi.add(i+1,A[i])
    for _ in range(q):
        q1,q2,q3=map(int, input().split())
        if q1==0:
            bi.add(q2+1,q3)
        else:
            print(bi.sum(q3)-bi.sum(q2))
        
    



if __name__ == '__main__':
    main()

Measured memory_bytes: 65216
import sys
import numpy as np 

stdin = []
for l in sys.stdin:
  stdin.append(l.split(" "))
stdin=np.array(stdin).astype(int)

n=stdin[0,0]
d=stdin[0,1]**2
table=stdin[1:,:]
count=0
distance=np.power(table[:,0],2)+np.power(table[:,1],2)
print((distance<=d).sum())


Measured memory_bytes: 114852
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  int N = s.size();

  int S = 0;
  int ans = N;

  REP(i, N){
    if(s[i] == 'S') S++;
    else{
      if(S > 0){
        S--;
        ans -= 2;
      }
    }
  }

  cout << ans << "\n";

  return 0;
}

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

int main () {
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i=0; i < N ;i++) {
  cin >> X[i];
  }
  int sum=0;
  	for (int j = 0; j < N ;j++) {
    sum += X[j];
    }
  		int ans=1-2*sum;
 	 		for (int k = 1; k < 100 ;k++) {
    		 if (N*k*k - 2*k*sum > N*(k+1)*(k+1) - 2*(k+1)*sum) {
             ans = N*(k+1)*(k+1)-2*(k+1)*sum;
             }
            }
  int sum_2;
  for (int l =0;l < N; l++) {
  sum_2 += X[l]*X[l];
  }
  				cout << sum_2 + ans << endl;
}






Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#素因数分解を行う関数O(root(N))
#int -> list
def factorize(x):
      res = []
      for i in range(2, int(x**0.5)+1):
          if x%i != 0:
              continue
          cnt = 0
          while x%i == 0:
              x //= i
              cnt += 1 
          res.append((i, cnt))
      if x != 1:
          res.append((x, 1))
      return res
 
def f(x):
    l = 0     
    r = 1000
    while r-l>1:
        c = (r+l)//2
        if x >= c*(c+1)//2:
            l = c
        else:
            r = c
    return l 
def main():
    n = int(readline())    
    fact = factorize(n)     
    ans = 0
    for i, j in fact:
        ans += f(j)
    print(ans)
if __name__ == '__main__':
    main()


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

#define     mem(x,y)   memset(x,y,sizeof(x))
#define     PB(x)      push_back(x)
#define     POB()      pop_back()
#define     SZ(a)      a.size()
#define     len(a)     strlen(a)
#define     SQR(a)     (a*a)
#define     dig(a)     a-'0'
#define     all(v)     v.begin(),v.end()
#define     read(a)    scanf("%d",&a)
#define     read2(a,b) scanf("%d %d",&a,&b)
#define     read3(a,b) scanf("%d %d %d",&a,&b,&c)
#define     write(a)   printf("%d",a);
#define     nl         printf("\n")
#define     fr(i,a,b)  for(i=a;i<=b;i++)
#define     rfr(i,a,b) for(i=a;i>=b;i--)
#define     nfr(i,a,b)  for(i=a;i<b;i++)
#define     nrfr(i,a,b) for(i=a;i>b;i--)
#define     sf  scanf
#define     pf  printf
#define     mkp make_pair
#define     fs  first
#define     sd  second

#define     inf  1<<25
#define     sz   1000006
#define     primeLimit  1000005
#define     eps  1e-9
#define     mod  1000000007
#define     PI   2.0*acos(0.0)
#define     imax 2147483647
#define     lmax 9223372036854775807LL

int main() {
//    freopen("output.txt","w",stdout);
//    freopen("xinput.txt","r",stdin);
//    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n,values[104],i,sum = 0;
    sf("%d",&n);
    nfr(i,0,n){
        sf("%d",&values[i]);
        sum += values[i];
    }
    sort(values,values+n);
    i = 0;
    while(i<n){
        if(sum%10 == 0){
            if(values[i] % 10){
                sum -= values[i];
                pf("%d\n",sum);
                break;
            }
        }
        else{
            pf("%d\n",sum);
            break;
        }
        i++;
    }
    if(i==n)
        pf("0\n");
    return 0;
}


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

typedef long long ll;
typedef pair<int,int> p;

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

ll N, H;
int main(){
    ios::sync_with_stdio(false);
    cin >> N >> H;
    vector<ll> katanaA;
    vector<ll> katanaB;
    REP(i, N) {
        ll a, b;
        cin >> a >> b;
        katanaA.pb(-a);
        katanaB.pb(-b);
    }
    sort(katanaA.begin(), katanaA.end());
    sort(katanaB.begin(), katanaB.end());
    int cnt = 0;
    for(auto x: katanaB) {
        if (katanaA[0] < x) break;
        if (H <= 0) break;
        H += x;
        cnt++;
    }
    if (H > 0) {
        cnt += H / (-katanaA[0]);
        if (H%(-katanaA[0])) cnt++;
    }
    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 2036
#include <stdio.h>

int main(void) {
	char a,b;

	scanf("%c %c",&a,&b);

	if(a=='H') {
		printf("%c\n",b);
	}
	else {
		if(b=='H') {
			printf("D\n");
		}
		else {
			printf("H\n");
		}
	}

	return 0;
}


Measured memory_bytes: 128
/*
 *  stay hungry, stay foolish, stay home.
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define ml cout<<"\n"
#define tc(w) ll w;cin>>w;while(w--)

#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define in insert
#define ff first
#define ss second
#define mod 1000000007

#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
int main(){
	ios_base::sync_with_stdio(false);
     	cin.tie(NULL);
    	cout.tie(NULL);
    	ll n;cin>>n;
    	ll ar[n];
    	rep(i,0,n){
    		cin>>ar[i];
    	}
    	ll dp[n]={0};
    	dp[0]=0;
    	dp[1] = abs(ar[0]-ar[1]);
    	rep(i,2,n){
    		ll p = abs(ar[i]-ar[i-1]);
    		ll h = abs(ar[i]-ar[i-2]);
    		dp[i] = min(dp[i-1]+p , dp[i-2]+h);
    		//cout<<dp[i]<<" ";
    	}

    	cout<<dp[n-1]<<endl;

	return 0;
		
}


Measured memory_bytes: 1792
n = int(input())
p = input().split()
list=[]
for i in range(n):
    list.append(int(p[i]))
cnt=0
for i in range(1,len(p)-1):
    a=[list[i-1],list[i],list[i+1]]
    a.sort()
    if a[1] == list[i]:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int ans = -1;
    int N = read(), X = read();
    int tmp = 0;
    for (int i = 0; i<N; i++) {
        tmp += read();
        if (ans == -1 && tmp > X) {
            ans = i+1;
        }
    }
    if (ans == -1) ans = N+1;
    printf("%d\n", ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

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

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

	int a, b;
	cin >> a >> b;

	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;
	} else {
		cout << "Impossible" << endl;
	}

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;
  char A[H+2][W+2];

  int B[H+2][W+2] = {};
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin >> A[i][j];
      if(A[i][j] == '#'){
        for(int k = i-1;k<=i+1;k++){
          for(int l = j-1;l<=j+1;l++){
            B[k][l]++;
          }
        }
      }
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(A[i][j] == '#') cout << '#';
      else{
        cout << B[i][j];
      }
    }
    cout << endl;
  }

}

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

int main(){
   int n,m;
  cin>>n>>m;
   int i=n*(n-1)/2,j=m*(m-1)/2,ans=0;
   if(i>0)ans+=i;
   if(j>0)ans+=j;
   printf("%d\n",ans);
}


Measured memory_bytes: 3692
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define maxn 100010
using namespace std;
int a[maxn];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	int f=1;
	for(int i=n-2;i>=0;i--){
		if(a[i]>=a[i+1]+2){
			f=0;
			break;
		}
		else if(a[i]==a[i+1]+1){
			a[i]--;
		}
	}
	if(f) printf("Yes");
	else printf("No");
    return 0;
}

Measured memory_bytes: 640
// ABC165C - Many Requirements

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

int asd(int N, int R, int count, int L)
{
	if (N / R == 0)
	{
		if (count == 1)
		{
			return count;
		}
		return 1;
	}
	if (asd(N, R*L, ++count, L) == 1)
	{
		return count;
	}
	
}

int main() 
{
	int N, R, count=1;
	cin >> N >> R;

	cout << asd(N, R, count, R) << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [a - 1 for a in map(int, input().split())]
b = list(map(int, input().split()))
c = list(map(int, input().split()))

satisfy = 0
prev = 10000

for i in a:
    if prev + 1 == i:
        satisfy += b[i] + c[i-1]
    else:
        satisfy += b[i]
    prev = i

print(satisfy)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

bool is_prime(int n) {
	if (n % 2 == 0) return n == 2;
	for (auto i = 3; i * i <= n; i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}
int main() {
	int x; std::cin >> x;
	while (!is_prime(x)) ++x;
	std::cout << x << std::endl;
}

Measured memory_bytes: 504
#include <iostream>
 
int main() {
  int heights[16] = { 0 };
  int temp_result = 0;
  int index = 12;
 
  for(int i = 0; i < 10; i++) {
    std::cin >> heights[i];
  }
 
  for(int j = 0; j < 3; j++) {
    heights[index] = 0;
    index = 0;
    temp_result = 0;
    for(int i = 0; i < 10; i++) {
      if(temp_result < heights[i]) {
        temp_result = heights[i];
        index = i;
      }
    }
    std::cout << temp_result << std::endl;
  }
 
 
  return 0;
}
 

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		int t;
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= m; j++) {
				t = m * i + n * j - 2 * i * j;
				if (t == k) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 22996
using System;

namespace A___Buying_Sweets
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());

            Console.WriteLine((X - A) % B);
        }
    }
}


Measured memory_bytes: 13140
/** AtCoder Beginner Contest 136, by Abreto<m@abreto.net> */
#include <bits/stdc++.h>

using namespace std;

namespace abreto {

const int maxl = 100100;

int n;
char S[maxl];
int ans[maxl];

void mutate(int pos, int Rs, int Ls)
{
    ans[pos] = ((Rs + 1) >> 1) + (Ls >> 1);
    ans[pos + 1] = (Rs >> 1) + ((Ls + 1) >> 1);
}

void main(void)
{
    cin >> S;
    n = strlen(S);
    for (int i = 0; i < n; i++)
    {
        int j, k;
        for (j = i; S[j + 1] == 'R'; j++);
        assert(S[j + 1] == 'L');
        for (k = j + 1; k + 1 < n && S[k + 1] == 'L'; k++);
        assert(k + 1 == n || S[k + 1] == 'R');
        mutate(
            j,          /* position of R in RL */
            j - i + 1,  /* number of Rs */
            k - j       /* number of Ls */
        );
        i = k;
    }
    for (int i = 0; i < n; i++)
        cout << (i ? " " : "") << ans[i];
    cout << '\n';
}

}

int main(void)
{
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    abreto::main();
    return 0;
}


Measured memory_bytes: 896
/// You just can't beat the person who never gives up
/// ICPC next year

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ;

int a ,b ,m ,arra[N] ,arrb[N] ,aa ,bb ,cc ;
int main(){
    scanf("%d%d%d",&a,&b,&m);
    long long ans = 0 ;
    int mn = 1e9+5 ;
    for(int i=0;i<a;++i){
        scanf("%d",arra+i);
        mn = min(mn,arra[i]);
    }
    ans += mn ;
    mn = 1e9+5 ;
    for(int i=0;i<b;++i){
        scanf("%d",arrb+i);
        mn = min(mn,arrb[i]);
    }
    ans += mn ;
    while(m--){
        scanf("%d%d%d",&aa,&bb,&cc);
        --aa ,--bb;
        ans = min(ans ,0ll+arra[aa]+arrb[bb]-cc);
    }
    cout << ans ;
    return 0;
}


Measured memory_bytes: 1024
import std.stdio;

void main() {
	for (;;) {
		int n, x;
		"%d %d\n".readf(&n, &x);
		if (n == 0 && x == 0) break;
		
		int c = 0;
		foreach (i; 1..n-1) {
			foreach (j; i+1..n) {
				foreach (k; j+1..n+1) {
					if (i+j+k == x) ++c;
				}
			}
		}
		c.writeln;
	}
}

Measured memory_bytes: 2432
def solve(n, k, xs):

    tmp = n
    num = len(xs)
    
    while True:
        if num == len([i for i in xs if i not in str(tmp)]):
            break
        else:
            tmp += 1
    
    return tmp

if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    xs = [i for i in input().split()]
    print(solve(n, k, xs))


Measured memory_bytes: 3060
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		Long a = sc.nextLong();
        Long b = sc.nextLong();
		Long c = sc.nextLong();
		System.out.println(b*(a/(b+c))+Math.min(b,a%(b+c)));
	}
}


Measured memory_bytes: 22740
// C.

#include <iostream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
	for (int i = 0; i < 8; ++i) {
		int e = a + ((i & 1) ? b : -b) + ((i & 2) ? c : -c) + ((i & 4) ? d : -d);
		if (e == 7) {
			cout << a << ((i & 1) ? "+" : "-") << b << ((i & 2) ? "+" : "-") << c << ((i & 4) ? "+" : "-") << d << "=7" << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, size):
        self.data = [-1 for _ in range(size)]
    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)
    def same(self, x, y):
        return (self.find(x) == self.find(y))
    def size(self, x):
        return -self.data[self.find(x)]


N, M = [int(i) for i in input().split()]

uf = UnionFind(N + 1)
for x, y, z in [[int(i) for i in input().split()] for _ in range(M)]:
    uf.union(x, y)

s = set()
for i in range(1, N + 1):
    s.add(uf.find(i))

print(len(s))

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

typedef long long ll;
ll mod = 1000000007;
int n, m;
vector<vector<int> > vi;
int visited[100007];
int dp[100007];
int dfs(int start){
    if(vi[start].size() == 0){
        return 1;
    }
    if(dp[start] > 0) return dp[start];
    int mx = 1;
    for(auto j:vi[start]){
        if(!visited[j]){
            visited[j] = 1;
            int l = 0;
            l = dfs(j);
            mx = max(mx, l);
        }
        else mx = max(mx, dp[j]);
    }
    
    return dp[start] = mx+ 1;
}
int main(){
    cin >> n >> m;
    int a, b;
    //visited.assign(n+1, false);
    memset(visited, 0, sizeof(visited));
    memset(dp, -1, sizeof(dp));
    vi.resize(n+1);
    for(int j=0; j<m; j++){
        cin >> a >> b;
        --a; --b;
        vi[a].push_back(b);
    }
    int mx = -1;
    //cout<<"mx="<<mx<<endl;
    for(int i=0; i<n; i++){
        int h = 0;
        //cout << i << " " << vi[i].size() << endl;
        if(!visited[i]){
            h = dfs(i);
            //cout << h << " : " << i << endl;
            mx = max(mx, h);
        }
    }
    cout << mx-1 << endl;
}

Measured memory_bytes: 8576
#include <stdio.h>
#include <math.h>

#define UPPER_BOUND 100000
#define UPPER_BOUND_INDEX 12
#define POW_BOUND 7+1

typedef enum { false, true } bool;

int change[UPPER_BOUND_INDEX];

int min = 100000;

void change_array(void)
{
    int i, index6, index9, pow6[POW_BOUND], pow9[POW_BOUND];
    
    
    index6 = index9 = 0;
    
    
    for(i=0; i<POW_BOUND; i++)
    {
        pow6[i] = pow(6, i);
        pow9[i] = pow(9, i);
    }
    
    for(i=0; pow6[index6]<=UPPER_BOUND || pow9[index9]<=UPPER_BOUND; i++)
    {
        if(pow6[index6] < pow9[index9])
        {
            change[i] = pow6[index6];
            
            index6++;
                
            continue;
        }
        if(pow6[index6] > pow9[index9])
        {
            change[i] = pow9[index9];
            
            index9++;
            
            continue;
        }
        if(pow6[index6] == pow9[index9])
        {
            change[i] = pow6[index6];
            
            index6++;
            index9++;
            
            continue;
        }
    }
    /*for(i=0; i<UPPER_BOUND_INDEX; i++)
    {
        printf("%d\n", change[i]);
    }*/
}

int change_index(int N)
{
    int i;
    
    
    for(i=UPPER_BOUND_INDEX-1; i>=0; i--)
    {
        if(change[i] <= N)
            break;;
    }
    
    return i;
}

bool DIV(int R, int index, int num)
{
    int i;
    
    
    if(num >= min)
    {
        return false;
    }
    else if(index == 0)
    {
        if(min > num + R)
            min = num + R;
            
        return true;
    }
    else
    {
        if(R >= change[index])
        {
            for(i=R/change[index]; i>=0; i--)
            {
                if(!DIV(R-change[index]*i, index-1, num+i))
                {
                    return true;
                }
            }
        }
        else
        {
            DIV(R, index-1, num);
        }
    }
}

int main(void)
{
    int N;
  
  
    scanf("%d", &N);


    change_array();

    DIV(N, change_index(N), 0);


    printf("%d\n", min);


    //system("pause");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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 dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<ll> a(N),b(N);
    REP(i,N){
        int A,B;
        cin>>A>>B;
        a[i]=A;
        b[i]=B;
    }
    ll cnt=0;
    for(int i=N-1;i>=0;i--){
        if((a[i]+cnt)%b[i]==0) continue;
        else if(a[i]+cnt<b[i]) cnt+=b[i]-(a[i]+cnt);
        else cnt += b[i] - (a[i]+cnt)%b[i];
        //cout<<cnt<<endl;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <set>
using namespace std;
using T=tuple<int,int,int>;//i,r=0/l=1,i
int main(){
	int n,w,d;
	cin>>n>>w>>d;
	vector<T> V;
	for(int i=0;i<n;i++){
		int x,y; char dir;
		cin>>x>>y>>dir;
		if(dir=='N'){
			//left
			if(x+y<=d){
				V.emplace_back(2*w+2*d-(x+y),1,i);
			}else{
				V.emplace_back(2*w+d-(x+y-d),1,i);
			}
			//right
			if(y+w-x<=d){
				V.emplace_back(w+(y+w-x),0,i);
			}else{
				V.emplace_back(2*w+d-(x+d-y),0,i);
			}
		}else if(dir=='S'){
			//left
			if(x+y-w>=0){
				V.emplace_back(w+(x+y-w),1,i);
			}else{
				V.emplace_back(x+y,1,i);
			}
			//right
			if(y-x>=0){
				V.emplace_back(2*w+2*d-(y-x),0,i);
			}else{
				V.emplace_back(x-y,0,i);
			}
		}else if(dir=='E'){
			//left
			if(y+w-x<=d){
				V.emplace_back(w+(y+w-x),1,i);
			}else{
				V.emplace_back(2*w+d-(x+d-y),1,i);
			}			
			//right
			if(x+y-w>=0){
				V.emplace_back(w+(x+y-w),0,i);
			}else{
				V.emplace_back(x+y,0,i);
			}
		}else if(dir=='W'){
			//left
			if(y-x>=0){
				V.emplace_back(2*w+2*d-(y-x),1,i);
			}else{
				V.emplace_back(x-y,1,i);
			}
			//right
			if(x+y<=d){
				V.emplace_back(2*w+2*d-(x+y),0,i);
			}else{
				V.emplace_back(2*w+d-(x+y-d),0,i);
			}
		}
	}
	for(int i=0;i<2*n;i++){
		int a,b,c; tie(a,b,c)=V[i];
		V.emplace_back(a+2*w+2*d,b,c);
		V.emplace_back(a+4*w+4*d,b,c);
	}
	sort(V.begin(),V.end());
	/*
	for(auto v:V){
		int a,b,c; tie(a,b,c)=v;
		cout<<a<<' '<<b<<' '<<c<<endl;
	}*/
	int best = n+1;
	for(int j=0;j<2*n;j++){
		set<int> S;
		vector<int> Sta(n);//0:not covered, 1:covered
		int ans = 0;
		for(int i=j;i<j+2*n;i++){
			int loc,id,lr; tie(loc,lr,id)=V[i];
			if(lr==0){//r
				//S[id]=1;
				S.insert(id);
			}else{//l
				S.erase(id);
			}
		}
		for(int i=j+2*n;i<j+4*n;i++){
			int loc,id,lr; tie(loc,lr,id)=V[i];
			if(lr==0){//r
				//cout<<loc<<' '<<id<<endl;
				if(Sta[id]==0){
					S.insert(id);
				}
			}else{//l
				if(S.count(id)){
					ans++;
					for(auto &s:S){
						Sta[s]=1;
					}
					S.clear();
				}
			}
		}
		//cout<<ans<<endl;
		best=min(ans,best);
	}
	cout<<best<<endl;
	return 0;
}

Measured memory_bytes: 3252
from collections import Counter

c=Counter(input())
l=sorted([c["a"],c["b"],c["c"]])

if l[0]==l[1]==0:print("YES" if l[2]==1 else "NO");exit()
if l[0]==0:print("YES" if l[1]==l[2]==1 else "NO");exit()
if l[0]==l[1]==l[2]:print("YES")
elif l[0]+1==l[1]==l[2]:print("YES")
elif l[0]+1==l[1]+1==l[2]:print("YES")
else:print("NO")

Measured memory_bytes: 9452
#include <iostream>
using namespace std;
int main(void){
  int n,s[10000],q,t,ans=0;
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>s[i];
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>t;
    for(int j=0;j<n;j++){
      if(t==s[j]){
	ans++;
	break;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3068
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll n,s;
ll f(ll b,ll n)
{
	if(n<b)return n;
	return f(b,n/b)+(n%b);
}
long long int solve()
{
  
	for(ll i=2;i*i<=n;++i)
		if(f(i,n)==s)return i;
	if(n<s)return -1;
  
	if(n==s)return n+1;
  
	ll now=n-s,ans=1e12,k,b,r,mn=sqrt(n);
	for(ll i=1;i*i<=now;++i)
	{
		if(now%i==0)
		{
			k=now/i,b=i+1,r=n-k*b;
          
			if(0<=r && r<b && b>mn)ans=min(ans,b);
			k=i,b=now/i+1,r=n-k*b;
			if(0<=r && r<b && b>mn)ans=min(ans,b);
		}
	}
	if(ans==1e12)return -1;
	return ans;
}

int main()
{
	cin >> n >> s;
	cout << solve() << endl;
	
} 


Measured memory_bytes: 256
#include<stdio.h>
#include<stack>
using namespace std;

int main(){
  int n;
  stack<int> r;
  while(scanf("%d",&n)!=EOF)
    if(n){
      r.push(n);
    }else{
      printf("%d\n",r.top());
      r.pop();
    }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
int main(void){

	char moji[10001];
	int i,n,an1,an2;

	while(scanf("%s",moji)!=EOF){
		n=strlen(moji);
		an1=0; an2=0;
		for(i=0;i<n;i++){
			if(moji[i]=='J' &&moji[i+1]=='O' &&moji[i+2]=='I')an1++;
			if(moji[i]=='I' &&moji[i+1]=='O' &&moji[i+2]=='I')an2++;
		}
		printf("%d\n%d\n",an1,an2);
	}
	return 0;
}

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

using namespace std;

long long prime = 1000000007;

long long pow_mod(long long a, long long r) {
    if (r == 0) return 1LL;
    if (r == 1LL) return a;
    long long y = pow_mod(a, r / 2);
    long long z = y * y % prime;
    if (r % 2 == 0) {
        return z;
    }
    return z * a % prime;
}

long long inv(long long x) {
    return pow_mod(x, prime - 2);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> adj_list(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        adj_list[a].push_back(b);
        adj_list[b].push_back(a);
    }
    vector<long long> fac(n + 1);
    fac[0] = 1;
    // inv_fac[0] = 1;
    for (int i = 1; i <= n; ++i) {
        fac[i] = i * fac[i - 1] % prime;
        // inv_fac[i] = inv(fac[i]);
    }
    
    vector<int> subtree_sizes(n), xs(n);
    
    function<void (int, int)> down = [&](int i, int parent) {
        long long x = 1LL;
        int s = 0;
        for (int j : adj_list[i]) {
            if (j != parent) {
                down(j, i);
                x = x * xs[j] % prime;
                s += subtree_sizes[j];
            }
        }
        x = x * (s + 1) % prime;
        xs[i] = (int) x;
        subtree_sizes[i] = s + 1;
    };
    down(0, -1);
    
    function<void (int, int)> up = [&](int i, int parent) {
        if (parent != -1) {
            xs[i] = xs[parent] * inv(subtree_sizes[i]) % prime * (n - subtree_sizes[i]) % prime;
        }
        for (int j : adj_list[i]) {
            if (j != parent) {
                up(j, i);
            }
        }
    };
    up(0, -1);
    
    for (int i = 0; i < n; ++i) {
        cout << (fac[n] * inv(xs[i]) % prime) << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 17012
function Main(input) {
  var a = input.slice(0, 1);
  var b = input.slice(1, 2);
  var c = input.slice(2, 3);
  var d = input.slice(3, 4);
  
  if((a == b && c == d && a != c)
    || (a != b && a == c && b == d)
    || (a != b && b == c && a == d)){
     console.log("Yes");
     }else{
       console.log("No");
     }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int ctoi(char c) {
	return c - '0';
}

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

		int N_i = stoi(N);

		int sum = 0;
		for(int i=0; i<N.size(); i++) {
			sum += ctoi(N[i]);
		}

		bool is_harshad = false;

		if (N_i % sum == 0) {
				is_harshad = true;
		}

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

		return 0;
}


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

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

        public static void Solve()
        {
            var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(ab[0] > 12 ? ab[1] : (ab[0] > 5 ? ab[1] / 2 : 0));
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
#define inf 10000
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;

ll divisor=998244353;

int main(){
	int h,w,k;
	cin>>h>>w>>k;
	bool a[h][w]={};
	rep(i,h){
		rep(j,w){
			char c;
			cin>>c;
			a[i][j]=c=='#';
		}
	}
	bool x[h]={},y[w]={};
	int ans=0;
	rep(i,(1<<h)){
		rep(j,h){
			x[j]=(i>>j)%2;
		}
		rep(j,(1<<w)){
			rep(k,w){
				y[k]=(j>>k)%2;
			}
			int count=0;
			rep(o,h){
				if(x[o])continue;
				rep(p,w){
					if(y[p])continue;
					if(a[o][p])count++;
				}
			}
			if(count==k){
              ans++;
            }
		}
	}
	puts(ans);
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string U[150], V; int T[200][100], cnt, cnt2[1000], x[100][100], large;
int main() {
	for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { T[i][j] = -1; x[i][j] = -1; } }
	while (cin >> U[cnt]) {
		U[cnt] += ','; 
		for (int i = 0; i < U[cnt].size(); i++) {
			if (U[cnt][i] == ',') {
				T[cnt][cnt2[cnt]] = stoi(V);
				V = "";
				cnt2[cnt]++;
			}
			else {
				V += U[cnt][i];
			}
		}
		if (cnt >= 1 && U[cnt].size() == 2) { break; }
		cnt++;
	}
	large = cnt / 2; x[0][0] = T[0][0];
	for (int i = 0; i < cnt; i++) {
		for (int j = 0; j < cnt2[i]; j++) {
			if (i < large) {
				x[i + 1][j] = max(x[i + 1][j], x[i][j] + T[i + 1][j]);
				x[i + 1][j + 1] = max(x[i + 1][j + 1], x[i][j] + T[i + 1][j + 1]);
			}
			else {
				x[i + 1][j] = max(x[i + 1][j], x[i][j] + T[i + 1][j]);
				x[i + 1][j - 1] = max(x[i + 1][j - 1], x[i][j] + T[i + 1][j - 1]);
			}
		}
	}
	cout << x[cnt - 1][0] << endl;
	return 0;
}

Measured memory_bytes: 3236
#include<stdio.h>
int main()
{
    int n,a,b,t,T;
    scanf("%d %d %d",&n,&a,&b);
    T=n*a;
    if(T==b)
        printf("%d",T);
    else if(T>b)
        printf("%d",b);
    else
        printf("%d",T);

    return 0;


}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        int count = 0;
        int smaller = a <= b ? a : b;
        for (int i=smaller; i >= 1; i--) {
            if (a % i == 0 && b % i == 0) {
                count++;
            }
            if (count == k) {
                System.out.println(i);
                break;
            }
        }
        sc.close();
    }
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

string a, b, aa, bb;
int numa, numb;
 
int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif
	
	cin >> a;
	cin >> b;
	numa = a[0] - '0';
	numb = b[0] - '0';
	aa = string(numb, a[0]);
	bb = string(numa, b[0]);
	cout << (aa > bb ? bb : aa) << endl;

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

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

int main()
{
    int x,y;
    cin>>x>>y;

    int i=1;
    while(1)
    {
        int j=floor((double)i*0.08);
        int k=floor((double)i*0.1);
        if(j==x && k==y)
        {
            cout<<i<<endl;
            break;
        }
        if(j>x || k>y)
        {
            cout<<"-1"<<endl;
            break;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 256
// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long u = sc.nextLong();
        // long D = sc.nextLong();
        // long K = sc.nextLong();

        long[] p = new long[(int)u];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextLong();
        }

        int cnt = 0;
        for (int i = 1; i < p.length - 1; i++) {
            
            long[] tmp = Arrays.copyOfRange(p, i-1, i + 2);
            Arrays.sort(tmp);
            if(tmp[1] == p[i]) cnt++; 
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 21844