akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<functional>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;
vector<int> map[10][10];
bool check(vector<int> line,int cul,int start){
    REP(i,10){
        vector<int> nline;
        REP(j,line.size()){
            REP(k,map[cul][i].size()){
                if(line[j]&map[cul][i][k])continue;
                nline.push_back(line[j]|map[cul][i][k]);
            }
        }
        sort(ALL(nline));
        nline.erase(unique(ALL(nline)),nline.end());
        if(nline.size()==0)continue;
        if(start == i)return true;
        if(check(nline,i,start))return true;
    }
    return false;
}
string func(){
    string str;
    cin >> str;
    REP(i,10){
        REP(j,10){
            map[i][j].clear();
        }
    }
    int num = 0;
    REP(i,str.size()){
        if(str[i] == 'u'){
            num = 0;
        }else{
            int nn = str[i] - '0';
            if(num != 0){
                if(num & BIT(nn))return "UNSAFE";
                REP(j,10){
                    if(BIT(j) & num){
                        map[j][nn].push_back(num);
                    }
                }
            }
            num |= BIT(nn);
        }
    }
    REP(i,10){
        REP(j,10){
            sort(ALL(map[i][j]));
            map[i][j].erase(unique(ALL(map[i][j])),map[i][j].end());
        }
    }
    REP(i,10){
        REP(j,10){
            if(check(map[i][j],j,i))return "UNSAFE";
        }
    }
    return "SAFE";
}
int main(){
    int n;
    while(cin >> n && n){
        cout << func() << endl;
    }
    return 0;
}



Measured memory_bytes: 3220
//
// tested with : g++ (GCC) 8.3.0
//

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

int main() {
    string s;//internationalization -> i18nこれ
    cin >> s;

    int middlenum = 0;
    int slength = s.length();
    middlenum = slength - 2;

    char firstchar = s[0];
    char lastchar = s[slength - 1];

    cout << firstchar << middlenum << lastchar << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define pi 3.1415926535897932384626433832
#define ll long long
using namespace std;
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / __gcd(a, b); }
bool isPrime(int n) {if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;}

void lok(){

}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    cout<<8-(t-400)/200<<endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll,pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(2e5) + 5;
const int MAX_V = 100005;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

ll n,a[MAX_N]{};

int main() {
    cin >> n;
    REP(i,n){
        ll tmp;
        cin >> tmp;
        a[i+1] = tmp-i-1;
    }
    sort(a+1,a+n+1);
    REP(i,n){
        a[i+1] += a[i];
    }
    ll ans = LLINF;
    REP(i,n){
        ans = min(ans,abs((a[i+1]-a[i])*i-a[i])+abs(a[n]-a[i+1]-(a[i+1]-a[i])*(n-i-1)));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
mx = 100005
q = int(input())

primes = [True for x in range(mx)]
primes[0] = False
primes[1] = False
for i in range(2, mx):
    if primes[i]:
        for j in range(i*i, mx, i):
            primes[j] = False

dp = [0 for x in range(mx)]
for i in range(1, mx):
    if i % 2 == 0:
        dp[i] = dp[i-1]
    else:
        if primes[i] and primes[(i+1)//2]:
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]

for i in range(q):
    l, r = map(int, input().split())
    print(dp[r] - dp[l-1])
    


Measured memory_bytes: 85576
n = int(input())
s = list(input())

s=s[::-1]
balance = 0
i = 0
while i < len(s):
    if s[i] == ')':
        balance+=1
    else:
        balance-=1
    if balance<0:
        s.insert(0, ')')
        balance+=1
        i+=1
    i+=1


balance = 0
i = 0
s=s[::-1]
while i < len(s):
    if s[i] == '(':
        balance+=1
    else:
        balance-=1
    if balance<0:
        s.insert(0, '(')
        balance+=1
        i+=1
    i+=1

print(''.join(s))
    


Measured memory_bytes: 9192
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest115-B
#  https://beta.atcoder.jp/contests/abc115/tasks/abc115_b


def christmasPurchase(intList) :

	intList.sort()
	i = 0
	purchasePrice = 0
	while i < len(intList):
		purchasePrice = purchasePrice + intList[i]
		i = i + 1

	purchasePrice = purchasePrice - intList[-1]//2
	ans = purchasePrice

	return ans


if __name__ == '__main__':

	saleNumber = int(input())
	priceList = [int(input()) for i in range(saleNumber)]
	ans = christmasPurchase(priceList)
	print(ans)

Measured memory_bytes: 3064
n, q = gets.split.map(&:to_i)

queue = Array.new(n).map do
  a = gets.split
  [a[0], a[1].to_i]
end

ans = []
time = 0

while !queue.empty?
  tmp = queue.shift
  tmp[1] -= q
  if tmp[1] > 0
    time += q
    queue.push(tmp)
  else
    time += q + tmp[1]
    ans.push([tmp[0],time])
  end
end

puts ans.map{|a| a.join(" ")}


Measured memory_bytes: 24556
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  long long a, b;
  std::cin >> a >> b;
  if (a > b) std::swap(a, b);
  if (a == 1) {
    std::cout << "1\n";
    return 0;
  }
  std::cout << (a * b + 1) / 2 << '\n';
  return 0;
}


Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
bool pos(int n){
	int count=0;
	for(int i=1;i<=sqrt(n);i++){
		if(n%i==0){
			count++;
			if(i*i!=n){
				count++;
			}
		}
	}
	return count==8;
}
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	vector<int>dp(201);
	for(int i=0;i<=104;i++){
		dp[i]=0;
	}
	for(int i=105;i<=200;i++){
		if(i%2==0){
			dp[i]=dp[i-1];
		}
		else{
			if(pos(i)){
				dp[i]=dp[i-1]+1;
			}
			else{
				dp[i]=dp[i-1];
			}
		}
	}
	int n;
	cin>>n;
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN = 200;
int clr[MAXN + 5], dis[MAXN + 5];
int G[MAXN + 5][MAXN + 5], N;
char S[MAXN + 5];
bool check() {
	for(int i=1;i<=N;i++)
		clr[i] = -1;
	queue<int>que; que.push(1), clr[1] = 0;
	while( !que.empty() ) {
		int f = que.front(); que.pop();
		for(int i=1;i<=N;i++)
			if( G[f][i] ) {
				if( clr[i] != -1 ) {
					if( clr[i] == clr[f] )
						return false;
				}
				else {
					clr[i] = clr[f] ^ 1;
					que.push(i);
				}
			}
	}
	return true;
}
int get_ans(int x) {
	for(int i=1;i<=N;i++) dis[i] = 0;
	queue<int>que; que.push(x), dis[x] = 1;
	int ret = 0;
	while( !que.empty() ) {
		int f = que.front(); que.pop();
		for(int i=1;i<=N;i++)
			if( G[f][i] ) {
				if( dis[i] == 0 ) {
					dis[i] = dis[f] + 1;
					ret = max(ret, dis[i]);
					que.push(i);
				}
			}
	}
	return ret;
}
int main() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++) {
		scanf("%s", S + 1);
		for(int j=1;j<=N;j++)
			G[i][j] = S[j] - '0';
	}
	if( !check() ) {
		puts("-1");
		return 0;
	}
	int ans = 0;
	for(int i=1;i<=N;i++)
		ans = max(ans, get_ans(i));
	printf("%d\n", ans);
}

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

//回転させる行為ではmax２しか増えない。

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



int main(){
    int n,k,c=0;
    string s;
    cin>>n>>k>>s;
    REP(i,n-1){
        if(s[i]-s[i+1]!=0) c++;
    }
    if(c/2>=k) cout<<(n-1)-2*(c/2-k)-c%2;
    else cout<<n-1;
    cout<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int n, q;cin>>n>>q;
  string s;cin>>s;
  vector<int> sum(n);
  int count=0;
  for(int i=0;i<n-1;i++){
    sum[i]=count;
  	if(s[i]=='A'&&s[i+1]=='C')count++;
  }
  sum[n-1]=count;
  for(int i=0;i<q;i++){
  	int l, r;cin>>l>>r;l--;r--;
    int res=(l==0?sum[r]:sum[r]-sum[l-1]);
    if(l!=0&&(s.substr(l-1, 2)=="AC")){
      res--;
    }
    cout<<res<<endl;
  }
}


Measured memory_bytes: 1408
# B - Collatz Problem


def main():
    s1 = input()
    ret = solve(s1)
    print(ret)


def solve(s1):
    s = int(s1)
    a = []
    m = 0
    for i in range(1000000):
        if (i == 0):
            w = s
        elif (a[i-1] % 2 == 1):
            w = 3 * a[i-1] + 1
        else:
            w = a[i-1] / 2
        if (w in a):
            return i+1
        a.append(w)


main()


Measured memory_bytes: 3188
import sys
h,w=map(int,input().split())
s=[input() for i in range(h)]
ss=[[0 for _ in range(w+2)] for _ in range(h+2)]
for j in range(w):
    for i in range(h):
        ss[i+1][j+1]=s[i][j]
for j in range(1,w+1):
    for i in range(1,h+1):
        c=True
        if ss[i][j]=='.':
            continue
        if not(ss[i-1][j]=='#' or ss[i][j-1]=='#' or ss[i][j+1]=='#' or ss[i+1][j]=='#'):
            print('No')
            sys.exit()
print('Yes')

Measured memory_bytes: 9084
#!/usr/bin/env python3
# DSL_2_I: RSQ and RUQ
# Range Sum Query and Range Update Query

import sys


class SegmentTree:

    def __init__(self, n):
        size = 2 ** (n.bit_length())
        self.size = 2*size - 1
        self.data = [0] * self.size
        self.lazy = [None] * self.size

    def update(self, lo, hi, v):
        def _update(r, i, j, lz):
            left, right = r*2 + 1, r*2 + 2
            if lz is None:
                lz = lazy[r]
            lazy[r] = None

            if lo <= i and j <= hi:
                data[r] = v * (j - i + 1)
                if i < j:
                    lazy[left] = v
                    lazy[right] = v
            else:
                mid = (i + j) // 2
                if mid >= lo:
                    lv = _update(left, i, mid, lz)
                else:
                    if lz is not None:
                        lazy[left] = lz
                        lv = lz * (mid - i + 1)
                    elif lazy[left] is not None:
                        lv = lazy[left] * (mid - i + 1)
                    else:
                        lv = data[left]

                if mid < hi:
                    rv = _update(right, mid+1, j, lz)
                else:
                    if lz is not None:
                        lazy[right] = lz
                        rv = lz * (j - mid)
                    elif lazy[right] is not None:
                        rv = lazy[right] * (j - mid)
                    else:
                        rv = data[right]

                data[r] = lv + rv

            return data[r]

        data = self.data
        lazy = self.lazy
        _update(0, 0, self.size//2, None)

    def sum(self, lo, hi):
        def _sum(r, i, j, lz):
            if lz is None:
                lz = lazy[r]
            lazy[r] = None
            if lz is not None:
                data[r] = lz * (j - i + 1)

            left, right = r*2 + 1, r*2 + 2
            if lo <= i and j <= hi:
                if lz is not None and i < j:
                    lazy[left] = lz
                    lazy[right] = lz
                return data[r]
            else:
                mid = (i + j) // 2
                lv, rv = 0, 0

                if mid >= lo:
                    lv = _sum(left, i, mid, lz)
                else:
                    if lz is not None:
                        lazy[left] = lz
                if mid < hi:
                    rv = _sum(right, mid+1, j, lz)
                else:
                    if lz is not None:
                        lazy[right] = lz
                return lv + rv

        data = self.data
        lazy = self.lazy
        return _sum(0, 0, self.size//2, None)


def run():
    n, q = [int(i) for i in input().split()]
    tree = SegmentTree(n)

    for line in sys.stdin:
        com, *args = line.split()
        if com == '0':
            s, t, x = [int(i) for i in args]
            tree.update(s, t, x)
        elif com == '1':
            s, t = [int(i) for i in args]
            print(tree.sum(s, t))


if __name__ == '__main__':
    run()



Measured memory_bytes: 15356
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main(){
    ll a,b; cin>>a>>b;
    ll g=__gcd(a,b);
    // gの素因数の個数を求める.
    ll cnt=0;
    priority_queue<ll, vector<ll>, greater<ll>> que;
    for(ll i=2; i*i<=g; i++){
        if(g%i==0){
            que.push(i);
            que.push(g/i);
        }
    }
    while(!que.empty()){
        ll fnt=que.top();
        if(g%fnt==0) cnt++;
        while(g%fnt==0) g/=fnt;
        que.pop();
    }
    if(is_prime(g)) cout<<cnt+2<<endl;
    else cout<<cnt+1LL<<endl;
}

Measured memory_bytes: 384
N = int(input())
A = map(int, input().split())
B = []
cnt = 0

for a in A:
    if a == len(B)+1:
        B.append(a)
    else:
        cnt += 1

if len(B) != 0 and B[-1] == N-cnt:
    print(cnt)
else:
    print(-1)


Measured memory_bytes: 25696
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}


void solve(){
	int n;
	cin>>n;
	int ans = INT_MAX;
	rep(i,0,n){
		int t;
		cin>>t;
		int cnt = 0;
		while(t%2 == 0){
			t/=2;
			cnt++;
		}
		ans = min(ans, cnt);
	}
	cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
  t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Applicative

move [a,b,c,d,e,f] o
	| o == 'E' = [d,b,a,f,e,c]
	| o == 'N' = [b,f,c,d,a,e]
	| o == 'S' = [e,a,c,d,f,b]
	| o == 'W' = [c,b,f,a,e,d]

solve dice@[a,b,c,d,e,f] q@[a',b'] (x:xs)
	| a == a' && b == b' = c
	| otherwise = solve (move dice x) q xs

main = do
	dice <- words <$> getLine
	n <- readLn
	replicateM_ n $ do
		qs <- words <$> getLine
		putStrLn $ solve dice qs (cycle "EEENNWWS")

Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll a,b;cin>>a>>b;
    cout << (a <= b ? a : a-1) <<ednl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args){
		InputStreamReader ir = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(ir);

		String str = null;
		try{
			str = br.readLine();
		}catch(IOException ex){
			ex.printStackTrace();
		}

		String[] arg = str.split(" ");
		int a = Integer.parseInt(arg[0]);
		int b = Integer.parseInt(arg[1]);
		int c = Integer.parseInt(arg[2]);

		if(a * c < b){
			System.out.println(c);
			return;
		}

		int res = b / a;

		if(res > 0){
			System.out.println(res);
		}else{
			System.out.println(0);
		}
	}
}


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

int n, m, q, ans = 0;
vector<int> arr;
vector<vector<int>> group;

int score();
void dfs(int depth);

int main() {
    cin >> n >> m >> q;
    arr.resize(n + 1, 1);
    group.resize(q, vector<int>(4));
    rep(i, q) {
        rep(j, 4) cin >> group.at(i).at(j);
    }
    dfs(1);
    cout << ans << endl;
}

int score() {
    int temp = 0;
    rep(i, q) {
        if(arr.at(group.at(i).at(1)) - arr.at(group.at(i).at(0)) == group.at(i).at(2)) temp += group.at(i).at(3);
    }
    return temp;
}

void dfs(int depth) {
    if(depth <= n) {
        rep(i, m - arr.at(depth - 1) + 1) {
            arr.at(depth) = arr.at(depth - 1) + i;
            dfs(depth + 1);
        }
    } else {
        ans = max(ans, score());
    }
}

Measured memory_bytes: 3624
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, long long K){
  ll ans = 0;
  for(ll a=K+1; a<=N; a++) {
    ans+=(N/a)*(a-K)+max(0ll, N%a-K+1);
  }
  if(K==0) {
    ans -= N;
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  solve(N, K);
  return 0;
}



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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define lli long long
#define vi vector<int>
#define vli vector<li>
#define vlli vector<lli>
#define pi pair<int,int>
#define pli pair<li, li>
#define vpi vector<pi>

using namespace std;

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

    int n;
    cin >> n;

    int arr[n];

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

    int ans = 0;
    for(int i = 1; i < n - 1; i++) {
        int a[3];
        a[0] = arr[i-1];
        a[1] = arr[i];
        a[2] = arr[i+1];

        sort(a, a + 3);
        if(a[1] == arr[i]) ans++;
    }

    cout << ans << endl;

}


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

#define rep(i,a,b)                for(ll i=a;i<b;i++)
#define re(i,b)                for(ll i=0;i<b;i++)
#define repr(i,n)                for(ll i=n-1;i>=0;i--)
#define ll long long
#define ld long double
#define llu long long unsigned
#define pll std::pair<ll, ll> 
#define ppll std::pair<ll, pll>
#define vll std::vector<ll> 
#define vpll std::vector<pll> 
#define vppll std::vector<ppll> 
#define mll std::unordered_map<ll, ll> 
#define mpll std::unordered_map<pll, ll>
#define mppll std::unordered_map<ppll, ll>
#define sll std::set<ll>
#define ff first
#define ss second
#define msll std::multiset<ll>
#define all(c) c.begin(), c.end()
#define allr(c) c.rbegin(), c.rend()
#define srt(x) sort(all(x))
#define rsrt(x) sort(allr(x))
#define eb emplace_back
#define pb push_back
#define s(yy) ll yy;cin>>yy
#define mod 1000000007
#define maxlong 1e18+5
#define len length()
#define sz size()


/*#################################################### 
#                                                    #
#                     @author                        #
#                  Parth Lathiya                     #
#      https://www.cse.iitb.ac.in/~parthiitb/        #
#                                                    #
####################################################*/

ll n,a,b,c;
ll dpp[4123];

ll dp(ll k)
{
    

    if(k<0)
        return -10000000000000;
    if(dpp[k]!=-1)
        return dpp[k];
    if(k==0)
        return dpp[k]=0;
    return dpp[k]=1+max(dp(k-a),max(dp(k-b),dp(k-c)));
    // return 1+   
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifdef PARTH_LATHIYA_HOME

        freopen("A_in.txt","r",stdin);
    
        ll ttt,bkkk;
        cin>>ttt;
        bkkk=ttt;
        while(ttt--) {
            cout<<"Testcase - "<<bkkk-ttt<<"\n";
    #endif

//--------------------------------------------------------------------------------------

    string a;
    cin>>a;
    re(i,a.len)
    {
    	if(a[i]=='9'){
    		cout<<"Yes";return 0;
    	}
    }
    		cout<<"No";


//--------------------------------------------------------------------------------------
    
    #ifdef PARTH_LATHIYA_HOME
        cout<<"\n"; }
    #endif

    return 0;
}

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

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int n;
    cin >> n;
    int v[n],c[n];
    for(int i=0;i<n;i++)cin >> v[i];
    for(int i=0;i<n;i++)cin >> c[i];
    int ans=0;
    for(int i=0;i<n;i++){
        if(v[i]>c[i])ans += v[i] - c[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
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: usize = read();
    let mut field = vec![vec![]; n];
    for y in 0..n {
        field[y] = read::<String>()
            .chars()
            .map(|c| (c as u8 - 'a' as u8) as i64)
            .collect::<Vec<i64>>();
    }
    let modulo = (1i64 << 30) + 7;
    let base = 1e+9 as i64 + 7;
    let mut rolling_hash_x = vec![vec![0 as i64; n]; n];
    for y in 0..n {
        let mut hash = 0;
        let mut base2 = 1;
        for x in 0..n {
            hash = (hash * base + field[y][x]) % modulo;
            base2 = (base2 * base) % modulo;
        }
        for x in 0..n {
            rolling_hash_x[y][x] = hash;
            hash = (hash * base + field[y][x]) % modulo;
            hash = (hash - base2 * field[y][x] + modulo * modulo) % modulo;
        }
    }
    let mut rolling_hash_y = vec![vec![0 as i64; n]; n];
    for x in 0..n {
        let mut hash = 0;
        let mut base2 = 1;
        for y in 0..n {
            hash = (hash * base + field[y][x]) % modulo;
            base2 = (base2 * base) % modulo;
        }
        for y in 0..n {
            rolling_hash_y[y][x] = hash;
            hash = (hash * base + field[y][x]) % modulo;
            hash = (hash - base2 * field[y][x] + modulo * modulo) % modulo;
        }
    }
    let mut ans = 0;
    for dy in 0..n {
        'offset_loop: for dx in 0..n {
            for iter in 0..n {
                let ny = (iter + dy) % n;
                let nx = (iter + dx) % n;
                if rolling_hash_x[ny][dx] != rolling_hash_y[dy][nx] {
                    continue 'offset_loop;
                }
            }
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6524
# -*- coding: utf-8 -*-

n, x = map(int, input().split())
sa = input().split()
a = []

for s in sa:
    a.append(int(s))

a = sorted(a)

ans = 0
sum = 0
dif = x
for i in a:
    sum += i
    dif -= i
    if sum > x:
        break
    ans += 1

if dif > 0:
    ans -= 1

print(ans)


Measured memory_bytes: 3060
import math

k = int(input())

k += 1
ans = 0

ab = []

for a in range(1, k):
    for b in range(1, k):
       ab.append(math.gcd(a, b))

for a in ab:
    for c in range(1, k):
        ans += math.gcd(a, c)

print(ans)


Measured memory_bytes: 9428
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
  int W, H;

  while(1){
    cin >> H >> W;
    if(W==0&&H==0) break;
  for(int i=1;i<=H;i++){

    for(int j=1;j<=W;j++) {
    if(i==1||i==H||j==1||j==W) printf("#");
    else printf(".");
    }
    printf("\n");
  }
  printf("\n");
}


}



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

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

#define INF 10000000000
#define MOD 10007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

//#define DEBUG

int main_(){
  int N;
  cin>>N;
  vector<int>b(N);
  for(int i=0;i<N;i++)cin>>b[i];
  vector<int>ans;
  for(int i=0;i<N;i++){
    bool f=false;
    for(int j=b.size()-1;j>=0;j--){
      if(b[j]==j+1){
        ans.push_back(b[j]);
        b.erase(b.begin()+j);
        f=true;
        break;
      }
    }
    if(!f){
      cout<<-1<<endl;
      return 0;
    }
  }
  reverse(rng(ans));
  for(auto it:ans)cout<<it<<endl;
  return 0;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  vector<string>test;
  /*
   * input for debug
   */
  for(int i=0;i<test.size();++i){
    stringbuf buf;
    streambuf*out=cout.rdbuf(&buf);
    cout<<test[i]<<flush;
    cout.rdbuf(out);
    streambuf*in=cin.rdbuf(&buf);
    main_();
    cin.rdbuf(in);
    cout<<endl;
  }
#else
  main_();
#endif

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int k,A,B;
    scanf("%d",&k);
    scanf("%d%d",&A,&B);
    int i,j;
    for(i=A;i<=B;i++)
    {
    j=i%k;
    if(j==0)
    break;
    }
    if(j==0)
    printf("OK\n");
    else
    printf("NG\n");
    return 0;
}

Measured memory_bytes: 1616
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

cost=[0]*200010
G=[[] for _ in range(200010)]
visited=[False]*200010
visited[0]=True

def dfs(s):
  global cost
  global G
  global visited
  for e in G[s]:
    if visited[e]==False:
      cost[e]+=cost[s]
      visited[e]=True
      dfs(e)
      visited[e]=False

def main():
  global cost
  global G
  global visited
  n,q=LI()
  for _ in range(n-1):
    a,b=LI()
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

  for i in range(q):
    p,x=LI()
    p-=1
    cost[p]+=x
  dfs(0)

  return ' '.join([str(x) for x in cost[:n]])

# main()
print(main())


Measured memory_bytes: 235888
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n=int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]


print(sum(list(map(lambda x: x-1, arr))))

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n ;
    cin >> n;
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();
    vector<int> a(n) ;
    REP(i,n){
        cin >> a[i] ;
    }
    vector<int> b(n) ;
    REP(i,n){
        b[i] = a[i] - (i+1) ;
    }
    sort(ALL(b)); 
    int ave = (b[(int)(ceil(n/2))]+b[n/2])/2 ;
    ll ans = 0 ;
    REP(i,n){
        ans += abs(b[i]-ave) ;
    }
    cout << ans <<endl;




    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=100005;
struct edge{int x,y,next;}a[4*MAXN];int len,last[MAXN];
void ins(int x,int y){len++;a[len].x=x;a[len].y=y;a[len].next=last[x];last[x]=len;}
int vis[MAXN],rt[MAXN],ok[MAXN],tot[MAXN],num,n,m;
bool OK;
void dfs(int x,int col)
{
	vis[x]=col;bool ret=true;++num;
	for(int k=last[x];k;k=a[k].next)
	{
		int y=a[k].y;if(vis[y]==-1)dfs(y,col^1);
		else if(vis[y]!=vis[x]^1)OK=false;
	}
}
int main()
{
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		ins(x,y);ins(y,x);
	}memset(vis,-1,sizeof(vis));
	int siz=0,siz1=0;
	for(int i=1;i<=n;i++)if(vis[i]==-1)
	{
		rt[i]=1;num=0;++siz;OK=1;
		if(!last[i])ok[i]=2,++siz1;
		else dfs(i,0),ok[i]=OK;tot[i]=num;
	}int cnt=0;LL ans=0;
	for(int i=1;i<=n;i++)if(rt[i]&&ok[i]==1)++cnt;
	for(int i=1;i<=n;i++)if(rt[i])
	{
		if(ok[i]==2)ans+=n;
		else if(!ok[i])ans+=siz-siz1,ans+=1LL*siz1*tot[i];
		else
		{
			ans+=cnt*2;
			ans+=siz-siz1-cnt;
			ans+=1LL*siz1*tot[i];
		}
	}pr2(ans);
	return 0;
}


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

typedef long long ll;
const ll mod=1e9+7;
const int N=200000;

void Run()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
//ll s[N],c[N];
ll a[N],b[N];
vector<string>v;
map<string,int>mp;
int main()
{
    Run();
    ll x,y,z=1;
    cin>>x>>y;
    z=x*y;
    cout<<z;
}


Measured memory_bytes: 3580
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;
 
int N, M, X[101010], Y[101010];
bool ok[101010];
int n[101010];
 
int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; ++i) {
		ok[i] = false;
		n[i] = 1;
	}
 
	ok[0] = true;
	for (int i = 0; i < M; ++i) {
		scanf("%d%d", X + i, Y + i);
		--X[i]; --Y[i];
		ok[Y[i]] |= ok[X[i]];
		n[X[i]]--;
		n[Y[i]]++;
		if (n[X[i]] == 0) ok[X[i]] = false;
	}
	int a = 0;
	for (int i = 0; i < N; ++i) if (ok[i]) ++a;
	printf("%d\n", a);
	return 0;
}

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

#define int long long
const int MOD = 1000000007LL;

signed main(){

    int n, k; cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    vector<int> dp(n, MOD);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            if(i + j < n) dp[i + j] = min(dp[i + j], dp[i] + (int)abs(h[i + j] - h[i]));
        }
    }

    cout << dp[n - 1] << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n;
/******* define variable end *******/
map<int64_t, ll> prime_factor(int64_t n) {
  map<int64_t, ll> ret;
  for (int64_t i = 2; i * i <= n; i++) {
	while (n % i == 0) {
	  ret[i]++;
	  n /= i;
	}
  }
  if (n != 1)
	ret[n] = 1;
  return ret;
}
int solve() {
	cin >> n;
	ll ans = 0;
	map<int64_t, ll> pf = prime_factor(n);
	for(auto& [key, value] : pf){
		if(value > 0 && key != 1){
			ll i = 0;
			ll j = 1;
			while(true){
				if(value < j){
					break;
				}
				value -= j;
				j++;
				i++;
			}
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


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

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

    long long int a,b,c,k;

    cin >> a >> b >> c >> k;

    if(k < a)
    {
	    cout << k << '\n';
    }
    else if(k >=a && k <= a + b)
    {
    	cout << a << '\n';
    }
    else
    {
    	long long int d = (k - a - b);
    	cout << a - d << '\n';
    }

    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


int main(){
    ll N, K;
    //cin >> N >> K;
    N=3;
    cin>>K;
    ll ans[100001]={};
    ll already[100001]={};
    for(ll i=K; i>=1; i--){
        ll temp = (K/i)*(K/i)*(K/i);
        ans[i] += temp-already[i];

        temp -= already[i];

        for(ll j=1; j*j<=i; j++){
            if(i%j==0){
                already[j]+=temp;
                if(j*j!=i){
                  already[i/j]+=temp;
                }
            }
        }
    
    } 

    ll sum = 0;
    for(ll i=0; i<=K; i++){
        //cout<<ans[i]<<endl;
        sum += ans[i]*i;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 5192
/* 
 *     author-->@harshrajani460
 *     codeforces round-567
 *
 */
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define mp make_pair
#define pe(x) cout<< x << endl ;
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define el endl
#define M 1000000007 
#define int long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROR(i,a,b) for(int i=a;i>=b;i--)
const int N = 1e3 + 5;
int dp[N][N],h,w;
char a[N][N];
void solve()
{
    for(int i=2;i<=h;i++)
    {
        for(int j=2;j<=w;j++)
        if(a[i][j]=='.')
        dp[i][j]=((dp[i-1][j]%M)+(dp[i][j-1]%M))%M;
    }
}
int32_t main() 
{ 
   cin>>h>>w;
   memset(dp,0,sizeof(dp));
   
   for(int i=1;i<=h;i++)
   {
       for(int j=1;j<=w;j++)
       {
           cin>>a[i][j];
       }
   }
   for(int i=1;i<=h;i++)
   if(a[i][1]=='.')
   dp[i][1]=1;
   else
   break;
   for(int i=1;i<=w;i++)
   if(a[1][i]=='.')
   dp[1][i]=1;
   else 
   break;
   solve();
    
   cout<<dp[h][w];
   
   
   
} 

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <bitset>

using namespace std;

int N, M;
int p[100005];
map<int, set<int>> edges;
bitset<100005> black;

void scan_clusters(set<int>& out, int from) {
    if(black[from]) return;
    black[from] = true;
    out.insert(from);

    for(int e : edges[from]) {
        scan_clusters(out, e);
    }
}

int main() {
    cin >> N >> M;
    for(int i = 1; i <= N; i++) {
        cin >> p[i];
    }
    for(int i = 1; i <= M; i++) {
        int x, y;
        cin >> x >> y;
        edges[x].insert(y);
        edges[y].insert(x);
    }

    vector<set<int>> clusters;
    clusters.push_back(set<int>());

    for(int i = 1; i <= N; i++) {
        scan_clusters(*clusters.rbegin(), i);
        if(clusters.rbegin() -> size() > 0) {
            clusters.push_back(set<int>());
        }
    }

    int acc = 0;
    for(auto& cls : clusters) {
        for(int idx : cls) {
            if(cls.find(p[idx]) != cls.end()) {
                acc++;
            }
        }
    }

    cout << acc << endl;

    return 0;
}


Measured memory_bytes: 30124
n,m = list(map(int,input().split()));
h = list(map(int,input().split()));

graph = [[] for i in range(n)];

for i in range(m) :
    a,b = list(map(int,input().split()));
    graph[a-1].append(b-1);
    graph[b-1].append(a-1);

ans = 0;
for i in range(n) :
    check = 1;
    for j in graph[i] :
        if h[i] <= h[j] :
            check = 0;
    if check :
        ans += 1;

print(ans);

Measured memory_bytes: 29280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }



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

  int start = -1;
  bool flug = true;

  if(s.length()>=t.length()){
  FOR(i,0,s.length()-t.length()){
    flug = true;
    FOR(j,0,t.length()-1){
      if(s[i+j] != t[j] && s[i+j] != '?') flug = false;
    }
    if(flug == true){
      start = i;
    }
  }

  FOR(j,0,t.length()-1){
    s[start+j]=t[j];
  }
  // cout << s << endl;
  FOR(i,0,s.length()-1){
    if(s[i]=='?') s[i] = 'a';
  }

  // cout << start << endl;

  if(start==-1) cout << "UNRESTORABLE" << endl;
  else cout << s << endl;

  }

  else{
    cout << "UNRESTORABLE" << endl;
  }

}



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

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

	int A[100];
	double ans;
	double den = 0.0;

	for (int i = 0; i < n; i++) {
		cin >> A[i];
		den += 1.0 / A[i];
	}

	ans = 1.0 / den;
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var r = ReadLine().Split().Select(int.Parse).ToArray();
        int num = int.Parse(string.Join("", r));
        WriteLine(num%4==0?"YES":"NO");
    }
}


Measured memory_bytes: 28076
n = int(input())
A = []
X = []
for i in range(n):
    a = int(input())
    A.append(a)
    lis = []
    for j in range(a):
        lis.append(list(map(int, input().split())))
    X.append(lis)

ans = 0
for i in range(2 ** n):
    H_lis = [0 for i in range(n)]
    for j in range(n):
        if ((i >> j) & 1):
            H_lis[j] = 1
    flag = True
    j = 0
    while j < n and flag:
        if H_lis[j] == 1:
            for k in range(A[j]):
                if X[j][k][1] != H_lis[X[j][k][0] - 1]:
                    flag = False
                    break
        j += 1
    if flag:
        ans = max(ans, H_lis.count(1))
print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] B = new int[N-1];
		int ans = 0,count = 0;
		for( int i=0; i<N-1; i++ ){
			B[i] = sc.nextInt();
		}
		for( int i=1; i<N-1; i++ ){
			if( B[i-1]<=B[i] ){
				count++;
				ans += B[i-1];
			}
			if( B[i-1]>B[i] ){
				ans += B[i-count-1];
				count = 0;
			}
			if( i==N-2 ){
				ans += B[i]+B[i-count];
			}        
		}
		if( N==2 ){
			ans = B[0]*2;          
        }          
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=100000000;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	ll g=gcd(a,b);
	return a/g*b;
}
 
ll digitsum(ll a){
	ll x=0;
	while(a>0){
		x+=a%10;
		a/=10;
	}
	return x;
}
int r,c;
char s[55][55];
int d[55][55];
int mazebfs(){
	int sx=0,sy=0,gx=r-1,gy=c-1;
	int dx[4]={1,0,-1,0} ,dy[4]={0,1,0,-1};
	queue<p> que;
	rep(i,0,r){
		rep(j,0,c){
			d[i][j]=inf;
		}
	}
	que.push(p(sx,sy));
	d[sx][sy]=0;
	while(que.size()){
		p pf=que.front();
		que.pop();
		
		if(pf.first==r-1&&pf.second==c-1) break;
		rep(i,0,4){
			int nx=pf.first+dx[i],ny=pf.second+dy[i];
			if(nx>=0&&nx<r&&ny>=0&&ny<c&&s[nx][ny]!='#'&&d[nx][ny]==inf){
				que.push(p(nx,ny));
				d[nx][ny]=d[pf.first][pf.second]+1;
			}
		}
	}
	return d[r-1][c-1];
}
int main(){
	ll a;
	cin>>a;
	if(a==7||a==5||a==3)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256