akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
#include<utility>

using namespace std;

typedef pair<int, int > P;


int H,W;
char c[1005][1005];
int d[1005][1005];

void bfs(int sy, int sx){
    int dx[4] = {-1,0,1,0}, dy[4] = {0,1,0,-1};
    int nx, ny;
    queue<P> que;
    que.push(make_pair(sy, sx));
    d[sy][sx] = 0;

    while(!que.empty()){
        P q = que.front();
        que.pop();
        for(int i = 0; i < 4; i++){
            ny = q.first + dy[i];
            nx = q.second + dx[i];
            if(ny >= 0 && ny < H && nx >= 0 && nx < W && d[ny][nx]== 1e9 && c[ny][nx] !='#'){
                que.push(make_pair(ny, nx));
                d[ny][nx] = d[q.first][q.second] + 1;
            }
        }
    }
}

int main(){
    int white = 0, black = 0;
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> c[i][j];
            if(c[i][j] == '#')black++;
            d[i][j] = 1e9;
        }
    }
    white = H * W - black; 
    bfs(0, 0);

    if(d[H-1][W-1] == 1e9){
        cout << -1 << endl;
    }else{
        cout << white - d[H-1][W-1] -1 << endl;
    }
}

Measured memory_bytes: 2432
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def gcd(a,b):
        if a == 0:
            return b
        return gcd(b%a, a)
    N = 1000001
    f = [1]*N
    lis = []
    p = 2
    while p < N:
        while p < N and not f[p]:
            p += 1
        j = p
        lis.append(p)
        while j < N:
            f[j] = 0
            j += p
    def func(n):
        i = 0
        p = lis[i]
        if n < 2:
            return 0
        while p*p <= n:
            if n%p == 0:
                if c[p]:
                    return 1
                c[p] = 1
                while n%p == 0:
                    n //= p
            i += 1
            p = lis[i]
        if c[n]:
            return 1
        if n > 1:
            c[n] = 1
        return 0
    n = I()
    a = LI()
    g = a[0]
    for i in a[1:]:
        g = gcd(g,i)
    if g != 1:
        print("not coprime")
        return
    c = [0]*N
    for i in a:
        if func(i):
            print("setwise coprime")
            return
    print("pairwise coprime")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 202440
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int solve(){
  int n;
  cin >> n;
  int odd = 0;
  rep(i,n){
    int tmp;
    cin >> tmp;
    if(tmp % 2 != 0)odd++;
  }
  if(odd % 2 == 0)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
} 

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std; 
int main() {
  int N,sum=0;
  cin >> N;
  bool ans =false;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      sum=4*i+7*j;
      if(sum==N){
        ans = true;
      }
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  }
  


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define all(v) v.begin(),v.end()
# define pl(s)  std::cout << s << endl;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1e9+7;

void addM(ll & a, ll b){
    a = (a+b) % MOD;
}

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

    for(int i = M / N + 1; i >= 1 ; i--) {
        if(M % i == 0 && M / i >= N) {
            pl(i)
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
int main(){
int a,b,c,d,e;
  cin >>a>>b>>c>>d>>e;
  if(a==0)
    cout<<"1"<<endl;
   if(b==0)
    cout<<"2"<<endl;
   if(c==0)
    cout<<"3"<<endl;
   if(d==0)
    cout<<"4"<<endl;
   if(e==0)
    cout<<"5"<<endl;
}

Measured memory_bytes: 3524
n, k = map(int, input().split())
ref = 0
cnt = 0

for i in range(1, n + 1)[::-1]:
    if i >= k:
        ref += 1
    else:
        while i < k:
            i *= 2
            cnt += 1
            if i >= k:
                ref += 1/(2**cnt)
                cnt = 0
                break
print(ref/n)

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

int main(){
    int X;
    cin >> X;
    int c500 = 0;
    int c5 = 0;
    bool frag = true;
    c500 = X / 500;
    c5 = (X % 500)/5;
    int Y = (c500 * 1000) + (c5 * 5);
    cout << Y << endl;
    return 0;
}


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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;
  vector<int> a(n), c(n - 1);
  map<int, int> mp;
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> mp[i + 1];
  rep(i, n - 1) cin >> c[i];

  int res = 0;
  rep(i, n) {
    res += mp[a[i]];
    if (a[i] - 1 == a[i - 1] && 1 <= i) res += c[a[i - 1] - 1];
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
N = ri()
a = ri_()
print(max(a) - min(a))

Measured memory_bytes: 62956
D, N = map(int,input().split())

if D==0 and N<100:
  print(N)

elif D==0 and N==100:
  print(N+1)
  
elif D==1 and N<100:
  print(100*N)

elif D==1 and N==100:
  print(100*(N+1))

elif D==2 and N<100:
  print(10000*N)

elif D==2 and N==100:
  print(10000*(N+1))

Measured memory_bytes: 3060
n = int(input())
l = []
for i in range(n):
    l.append(list(map(str,input().split())))
x = str(input())
#print(l)
for i in range(n):
    if l[i][0] == x:
        s = i
        break
ans = 0
for i in range(s+1,n):
    ans += int(l[i][1])
print(ans)


Measured memory_bytes: 3060
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    x, a, b = LI()
    if b <= a:
        print("delicious")
    elif b <= a + x:
        print("safe")
    else:
        print("dangerous")

    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
 
typedef tree<pair<long long,int>, null_type, less<pair<long long,int>>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
 
#define f first
#define se second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pi pair<int, int>
#define all(num) num.begin(), num.end()
#define lp(i, nodess) for (int i = 0; i < nodess; i++)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define X real()
#define Y imag()
#define angle(u) (atan2(u.Y, u.X))
#define vec(u, v) ((v) - (u))
//#define length(u) (hypot(u.Y , u.X))
#define normalize(u) (u) / length(u)
#define dotP(u, v) ((conj(u) * v).X)
#define crossP(u, v) ((conj(u) * v).Y)
#define same(p1, p2) (dotP(vec(p1, p2), vec(p1, p2)) < EPS)
#define lengthSqr(u) dotP(u, u)
#define rotate0(p, ang) ((p)*exp(point(0, ang)))
#define rotateA(p, ang, about) (rotate0(vec(about, p), ang) + about)
#define reflect0(vis, m) conj(vis / m) * m
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const double PI = acos(-1.0);
const double EPS = (1e-10);
const long long int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
typedef long long int ll;
typedef unsigned long long ull;
typedef complex<double> point;
long long fastpow(ll nodess, ll num, ll m) {
  if (!num)
    return 1;
  if (num % 2)
    return nodess * fastpow(nodess, num - 1, m)%m;
  ll p = fastpow(nodess, num / 2, m);
  p %= m;
  p *= p;
  p %= m;
  return p;
}
 
ll my_mod(ll num, ll mod) {
  ll reto = num % mod;
  while (reto < 0)
    reto += mod;
  return reto;
}
 
ll gcd(ll u, ll v) { return !u ? v : gcd(v % u, u); }
long long dist(pair<ll, ll> u, pair<ll, ll> v) {
  return 
      abs(u.f - v.f)  + abs(u.se - v.se);
}
long long getDist(pair<ll, ll> &u, pair<ll, ll> &v) {
  return 
     (u.f - v.f)*(u.f - v.f)  + (u.se - v.se)*(u.se-v.se);
}
 
 
 
/*vector<int> ap;
int np[MX+5];
void s(){
    mem(np , 1);
    np[1] = np[0] = 0;
    for(ll i = 2 ; i*i<= MX ;i++){
        if(np[i]){
            for(ll j= i*i ; j <=MX; j+=i) np[j] = 0;
        }
    }
    int idx = 1;
    for(ll i = 2 ; i<= MX ; i++){
		if(np[i]){
			np[i] = idx;
			idx++; 
			ap.pb(i);
		}
	}
	//cout<<idx;
}*/
const int MX = 10009;

int main()
{
    IO;
	int k,x;
	cin>>k>>x;
	k *= 500;
	if(k >= x) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 998244353
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

ll power(ll a, ll b, ll c)
{	
	ll res = 1;	
	while(b != 0)
	{
		if(b & 1)
			res = (res * a) % c;
		a = (a * a) % c;
		b /= 2;
	}
	return res;
}
int main()
{
	int n;
	cin >> n;
	vector <int> A(n);
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> A[i];
		sum = sum + A[i];
	}
	vector <ll> dp(sum + 1);
	dp[0] = 1;
	for (int i = 0; i < n; i++)
	{
		for (int j = sum; j >= 0; j--)
		{
			if(A[i] <= j)
			{
				dp[j] += dp[j];
				dp[j] += dp[j - A[i]];
				dp[j] %= MOD;
			}
			else
			{
				dp[j] += dp[j];
				dp[j] %= MOD;
			}
		}
	}
	ll ans = power(3, n, MOD);
	for (int i = (sum + 1) / 2; i <= sum; i++)
	{
		ans -= (3 * dp[i]) % MOD;
		ans = (ans + MOD) % MOD;
	}
	if(sum % 2 == 0)
	{
		vector <ll> dp1(sum + 1);
		dp1[0] = 1;
		for (int i = 0; i < n; i++)
		{
			for (int j = sum; j >= 1; j--)
			{
				if(A[i] <= j)
				{
					dp1[j] += dp1[j - A[i]];
					dp1[j] %= MOD;
				}
			}
		}
		ans += (3 * dp1[sum / 2]) % MOD;
		ans = (ans + MOD) % MOD;
	}
	cout << ans << "\n"; 
}



Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >>a[i];
    }
    int cn=0;
    for(int i=n-1;i>0;i--){
        for(int j=n-1;j>n-i-1;j--){
            if(a[j]<a[j-1]){
                swap(a[j],a[j-1]);
                cn++;
                
            } 
        }
    }    
    for(int i=0;i<n;i++){
        if(i!=0) cout<<" ";
        cout<<a[i];
    }
    cout<<endl;
    cout<<cn<<endl;    
}


Measured memory_bytes: 3100
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
#include <queue>

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(NULL);
        std::cout.tie(NULL);
    }
    
    int n;
    std::cin >> n;
    std::vector<int> a(n), b(n);
    for (int i = 0; i != n; ++i)
        std::cin >> a[i] >> b[i];
    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());
    if (n % 2)
        std::cout << b[n/2] - a[n/2] + 1;
    else
        std::cout << b[(n-1)/2] + b[n/2] - a[(n-1)/2] - a[n/2] + 1;
    return 0;
}

Measured memory_bytes: 4780
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
  int n,i;
  double b;
  double sum = 0;
  double p = 1;
  vector<int> v;
  
  cin >> n;
  
  for(i = 0;i < n;i++)
  {
    cin >> b;
    v.push_back(b);
  }
  
  for(i = 0; i < n ; i++)
  {
    p = p * v[i];
  }
  for (i = 0;i < n ; i++)
	
  {
    sum += (p / v[i]);
  }
  
  cout << p / sum;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for(int i=0; i<N; i++){
      cin >> l[i];
  }
  sort(l.begin(), l.end(), greater<int>());
  int ans = 0;
  for(int j=0; j<K; j++){
      ans += l[j];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

class mod_int{
    private:
        ull num;
        static ull pow_mod(ull x,ull y){x%=mod;return y==0?1:y%2==0?pow_mod(x*x,y/2):x*pow_mod(x,y-1)%mod;}
    public:
        static ull mod;
        mod_int()=default;
        mod_int(ull num):num(num%mod){}
        explicit operator ull()             const{return num;}
        bool    operator==(const mod_int&mi)const{return num==mi.num;}
        bool    operator!=(const mod_int&mi)const{return !operator==(mi);}
        mod_int operator~ ()                const{return pow_mod(num,mod-2);}
        mod_int operator+ (const mod_int&mi)const{return num+mi.num;}
        mod_int operator- (const mod_int&mi)const{return num-mi.num+mod;}
        mod_int operator* (const mod_int&mi)const{return num*mi.num;}
        mod_int operator/ (const mod_int&mi)const{return num*(~mi).num;}
        mod_int&operator+=(const mod_int&mi)     {return*this=operator+(mi);}
        mod_int&operator-=(const mod_int&mi)     {return*this=operator-(mi);}
        mod_int&operator*=(const mod_int&mi)     {return*this=operator*(mi);}
        mod_int&operator/=(const mod_int&mi)     {return*this=operator/(mi);}
};
class combination_modulo:mod_int{
    private:
        vector<mod_int>factorial_mod;
    public:
        combination_modulo(ull max_n):factorial_mod(max_n+1)
        {
            factorial_mod[0]=1;
            for(ll i=1;i<=max_n;++i)factorial_mod[i]=factorial_mod[i-1]*i;
        }
        mod_int operator()(ull n,ull r)
        {
            return n<r?0:factorial_mod[n]/(factorial_mod[r]*factorial_mod[n-r]);
        }
};
ull mod_int::mod=1000000007;
int main()
{
    ll x=in(),y=in();
    if((2*y-x)%3!=0||(2*x-y)%3!=0){
        cout<<0<<endl;
    }else{
        ll a=(2*y-x)/3,b=(2*x-y)/3;
        if(a<0||b<0){
            cout<<0<<endl;
        }else{
            combination_modulo cm(a+b);
            cout<<(ull)cm(a+b,a)<<endl;
        }
    }
}


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

class Graph {
    int V;
    vector<list<int>> edges;
    public:
    Graph(int nodes){
        V = nodes;
        edges.resize(nodes + 1);
    }
    void addEdge(int from, int to){
        edges[from].push_back(to);
    }
    int min_dist(int &fin, int i, map<int ,bool> &special, vector<bool> &check){
        check[i] = true; 
        multiset<int> ms;     
        int k;
        for(auto it = edges[i].begin(); it != edges[i].end(); it++){
            if(check[*it] == true)
                continue;
            k = min_dist(fin, *it, special, check);
            if(k != 0)
                ms.insert(k);
        }
        for(auto it = ms.begin(); it != ms.end(); it++){
            fin += (*it);
            //cout << *it << " ";
        }
        //cout << endl;
        if(ms.size() % 2 == 0){
            if(special[i])    
                return 1;
            return 0;
        }
        else{
            if(special[i])
                return 0;
            auto it = ms.begin();
            fin -= (*it);
            return (*it) + 1;
        }
    }
};


int main(){
    int t = 1;
    //cin >> t;
    while(t--){
        float d, s, t;
        cin >> d >> t >> s;
        if(d/s > t){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }
    }
    return 0;
}







Measured memory_bytes: 3696
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#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<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
using namespace std;
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	int n,a[100005],ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int sol=1;
	while(a[sol]!=2){
		ans++;
		sol=a[sol];
		if(ans>=10000000){
			cout<<"-1";
			return 0;
		}
	}
	cout<<ans+1;
	//system("pause");
	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MAX 100005
using namespace std;
//char nc()
//{
//	static char buf[100000],*p1=buf,*p2=buf;
//	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
char nc(){return getchar();}
int read()
{
	int x=0,y=1;
	char c=nc();
	while(!isdigit(c))
	{
		if(c=='-')y=-1;
		c=nc();
	}
	while(isdigit(c))
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=nc();
	}
	return x*y;
}
int A,B,C,D,k;
bool check(int mid)
{
	int a=A-mid/(k+1)*k-mid%(k+1);
	int b=B-mid/(k+1);
	return b<=1ll*a*k;
}
int main()
{
	int T=read();
	while(T--)
	{
		A=read();B=read();C=read();D=read();
		k=max(ceil(1.0*A/(B+1)),ceil(1.0*B/(A+1)));
		int l=0,r=A+B,mid;
		while(l<r)
		{
			mid=l+r>>1;
			if(check(mid)) l=mid+1;
			else r=mid;
		}
		int a=A-l/(k+1)*k-l%(k+1);
		int b=B-l/(k+1);
		for(int i=C;i<=min(D,l);i++)
			putchar(i%(k+1)?'A':'B');
		int st=l+b-a*k+1;
		for(int i=max(C,l+1);i<=D;i++)
			putchar((i-st)%(k+1)?'B':'A');
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 3564
class Main{
	public static void main(String[]s){
		for(int i=8;++i<90;)
		//System.out.printf("%d,%d,%d\n",i,i/9,i%9);
		System.out.printf(i/9+"x%d=%d\n",i%9+1,i/9*(i%9+1));
	}
}

Measured memory_bytes: 12000
class ModComb
  def initialize(max, mod)
    @mod = mod
    @fac = Array.new(max + 1)
    @finv = Array.new(max + 1)
    @inv = Array.new(max + 1)
    @fac[0] = @fac[1] = 1
    @finv[0] = @finv[1] = 1
    @inv[1] = 1
    (2..max).each do |i|
      @fac[i] = @fac[i - 1] * i % @mod
      @inv[i] = @mod - @inv[@mod % i] * (@mod / i) % @mod
      @finv[i] = @finv[i - 1] * @inv[i] % @mod
    end
  end

  def comb(n, k)
    return 0 if n < k
    return 0 if n < 0 || k < 0
    @fac[n] * (@finv[k] * @finv[n - k] % @mod) % @mod
  end
end

MOD = 10 ** 9 + 7
X, Y = gets.split.map(&:to_i)
if X == Y && X % 3 != 0
  puts 0
  exit 0
end

if X == Y
  n = X / 3
  m = n * 2
  comb = ModComb.new(m, MOD)
  puts comb.comb(m, n)
  exit 0
end

diff = (X - Y).abs

if X < Y && X < diff
  puts 0
  exit 0
end
if Y < X && Y < diff
  puts 0
  exit 0
end

max = [X, Y].max
n = max - diff * 2
if n % 3 != 0
  puts 0
  exit 0
end
n = n / 3
m = n * 2
comb = ModComb.new(m + diff, MOD)
puts comb.comb(m + diff, n + diff)


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

int main(){
  int n,ue=1,st=6,mg=3,hd=4,me=2,us=5,cnt;
  string moji;
  while(1){
    cin>>n;
    if(n==0)break;
    cnt=1;
    ue=1;st=6;mg=3;hd=4;me=2;us=5;
    for(int i=0;i<n;i++){
      cin>>moji;
      if(moji=="North"){
	us=ue;
	ue=me;
	me=7-us;
	st=7-ue;
      }else if(moji=="East"){
	mg=ue;
	ue=hd;
	hd=7-mg;
	st=7-ue;
      }else if(moji=="West"){
	hd=ue;
	ue=mg;
	mg=7-hd;
	st=7-ue;
      }else if(moji=="South"){
	me=ue;
	ue=us;
	us=7-me;
	st=7-ue;
      }else if(moji=="Right"){
	hd=me;
	me=mg;
	mg=7-hd;
	us=7-me;
	
      }else if(moji=="Left"){
	mg=me;
	me=hd;
	hd=7-mg;
	us=7-me;
      }
      cnt+=ue;
    }
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define mp make_pair
#define ull unsigned long long
using namespace std;

string s;
ull sum[200200];
vector < int > cnt[26];
ull _getSum(int x);
ull getSum(int l, int r)
{
	return _getSum(r-1) - _getSum(l-1);
}
void update(int x)
{
	while(x < 200200)
	{
		sum[x]++;
		x |= x + 1;
	}
}
ull _getSum(int x)
{
	ull ret = 0;
	while(x > 0)
	{
		ret+=sum[x];
		x = (x & (x+1)) - 1;
	}
	return ret;
}
int main()
{
	cin >> s;
	for(int i = 0; i < s.length(); ++i)
	{
		cnt[s[i]-'a'].push_back(i+1);
	}
	int id = -1;
	for(int i = 0; i < 26;++i)
	{
		if(cnt[i].size() & 1)
		{
			if(id!=-1)
			{
				cout << -1 << endl;
				return 0;
			}
			id = i;
		}
	}
	ull ans = 0;
	if(id!=-1)
	{
		int position = cnt[id][cnt[id].size()/2];
		for(int i = 0; i < 26; ++i)
		{
			if( i == id) continue;
			for(int j = 0; j < cnt[i].size()/2; j++)
			{
				if(cnt[i][j] > position) ans++;
				if(cnt[i][cnt[i].size() - 1 -j] < position) ans++;
			}
		}
	}
	vector < pair < int , int > > prs;
	for(int i = 0; i < 26;++i)
	{
		for(int j=0;j < cnt[i].size()/2;++j)
		{
			prs.push_back(mp(cnt[i][j], cnt[i][cnt[i].size()-1-j]));
		}
	}
	sort(prs.begin(), prs.end());
	for(int i = 0; i < prs.size(); ++i)
	{
		ans+=2 * getSum(0,prs[i].first) + getSum(prs[i].first, prs[i].second);
		update(prs[i].second);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3832
#include<iostream>
#include<vector>
using namespace std;
int main(void){
	int a,b;
	while(1){
cin>>a>>b;
if(a==0)break;
vector<int> c(3,0);
int rest =b-a;
c[2]=(b-a)/1000;
c[0]=(rest-c[2]*1000)/100;
if(c[0]>=5){
c[1]=1;
c[0]-=5;
}
cout<<c[0]<<' '<<c[1]<<' '<<c[2]<<endl;
	}
	return 0;
}

Measured memory_bytes: 2972
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	int d, t, s;
	cin >> d >> t >> s;
	if (t*s >= d) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}

	return 0;
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n;

	cin >> n;

	vector<ll> v(n);

	REP(i, n) {
		cin >> v[i];
	}

	sort(v.begin(), v.end());

	ll ans = 0;

	FOR(i, 1, 100001) {
		auto itr = lower_bound(v.begin(), v.end(), i);
		ll d = itr - v.begin();
		if (d == n / 2) {
			ans++;
		}
	}

	cout << ans << endl;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    ll N, P;
    cin >> N >> P;
    string S; cin >> S;
    ll ans = 0;

    if (P == 2 || P == 5) {
      rrep(i, N) {
        ll num = S[i] - '0';
        if (num % P == 0) ans += i + 1;
      }
      cout << ans << endl;
      return 0;
    }

    vector<ll> cnt(P, 0);
    ll ten = 1;
    ll sum = 0;
    cnt[sum]++;
    rrep(i, N) {
      ll num = S[i] - '0';
      sum += num * ten;
      sum %= P;
      ten *= 10;
      ten %= P;
      cnt[sum]++;
    }

    rep(i, P) {
      ans += cnt[i] * (cnt[i] - 1) / 2;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 720
use proconio::input;

const MOD:i64 = 998244353;

fn powm(mut x:i64,mut k:i64) -> i64{
    let mut res = 1i64;
    while k>0 {
        if k&1==1 {
            res=res*x%MOD;
        }
        k>>=1;
        x=x*x%MOD;
    }
    res
}

fn minv(x:i64) -> i64{
    powm(x,MOD-2)
}

fn main() {
    input! {
        n:usize,
        m:usize,
        k:usize
    };
    let fact = {
        let mut fact = vec![1i64;n+1];
        for i in 0..n {
            fact[i+1] = fact[i]*(i+1) as i64%MOD;
        }
        fact
    };

    let comb=|n,k| {
        fact[n] * minv(fact[k])%MOD*minv(fact[n-k])%MOD
    };
    let mut ans = 0i64;
    for dup in 0..(k+1) {
        let pat = m as i64 * comb(n-1,dup)%MOD * powm((m-1) as i64,(n-1-dup) as i64)%MOD;
        ans+=pat;
        ans%=MOD;
    }
    println!("{}",ans);
   
}

Measured memory_bytes: 3656
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,K = MI()
LR = [tuple(MI()) for i in range(K)]
mod = 998244353

dp = [0]*(N+1)
dp[1] = 1

for i in range(2,N+1):
    dp[i] = dp[i-1]
    for j in range(K):
        l,r = LR[j]
        if i-l > 0:
            dp[i] += dp[i-l]-dp[max(i-r-1,0)]
            dp[i] %= mod

print((dp[N]-dp[N-1]) % mod)


Measured memory_bytes: 69844
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int to_int(char x) {
    return x - '0';
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string S;
    cin >> S;

    ll ans = 0;
    REP(i, 1LL << S.size() - 1) {
        ll s = 0;

        ll c = to_int(S[0]);
        REP(j, S.size() - 1) {
            if (i >> j & 1) { // +
                s += c;
                c = to_int(S[j + 1]);
            } else {
                c = c * 10 + to_int(S[j + 1]);
            }
        }
        ans += s + c;
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define MN 100005

struct xxx{
	int cnt, v;
}a[MN], b[MN];

bool cmp(xxx a, xxx b) {return a.cnt > b.cnt;}

int main()
{
	int n; scanf("%d", &n);
	for(int i = 1; i <= 100000; i++) a[i].v = i, b[i].v = i;
	for(int i = 1; i <= n; i++)
	{
		int k; scanf("%d", &k);
		if(i & 1) a[k].cnt++; 
		else b[k].cnt++;
	}
	std::sort(a + 1, a + 100001, cmp);
	std::sort(b + 1, b + 100001, cmp);
	int ans = 1e9;
	for(int i = 1; i <= 100000; i++)
	{
		if(a[i].v == b[1].v) ans = std::min(ans, n - a[i].cnt - b[2].cnt);
		else ans = std::min(ans, n - a[i].cnt - b[1].cnt);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1664
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Set<String> dictionary = new HashSet<>();
		
		int n = nextInt();
		
		for (int i = 0; i < n; i ++) {
			next();
			if (nextbuf[0] == 'i') {
				next();
				dictionary.add(new String(nextbuf, 0, nextlen));
			} else {
				next();
				if (dictionary.contains(new String(nextbuf, 0, nextlen))) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}
	}
	
	private static byte[] buf = new byte[1 << 20];
	private static int len = 0;
	private static int ptr = 0;
	
	private static byte read() {
		if (ptr >= len) {
			try {
				len = System.in.read(buf);
			} catch (Exception e) {
			}
			ptr = 0;
		}
		
		return buf[ptr++];
	}
	
	private static int nextInt() {
		int num = 0;
		
		byte b = read();
		while(!Character.isDigit(b)) b = read();
		while(Character.isDigit(b)) {
			num *= 10;
			num += b - '0';
			b = read();
		}
		
		return num;
	}
	
	private static byte[] nextbuf = new byte[11];
	private static int nextlen;
	
	private static void next() {
		nextlen = 0;
		
		byte b = read();
		while(!Character.isAlphabetic(b) && !Character.isDigit(b)) b = read();
		while(Character.isAlphabetic(b) || Character.isDigit(b)) {
			nextbuf[nextlen++] = b;
			b = read();
		}
	}
}



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

const int N = 500001;
int a[N];
typedef long long ll;

int main(void) {
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    typedef pair<int, int> pii;
    priority_queue<pii> q;
    q.push({ a[n - 1], a[n] });
    q.push({ a[n - 1], a[n] });
    ll sum = a[n];
    for (int i = n - 2; i >= 1; --i) {
        pii p = q.top(); q.pop();
        sum += p.first;
        q.push({ a[i], p.first });
        q.push({ a[i], p.second });
    }
    printf("%lld\n", sum);
    return 0;
}

Measured memory_bytes: 6148
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N, D, A;
  cin >> N >> D >> A;
  vector<i64> X;
  vector<tuple<i64, i64>> P;
  REP(i, N) {
    i64 x, h;
    cin >> x >> h;
    P.emplace_back(x, h);
    X.emplace_back(x);
  }
  sort(X.begin(), X.end());
  sort(P.begin(), P.end());
  vector<i64> acum(N);
  i64 cnt = 0;
  REP(i, N) {
    auto [x, h] = P[i];
    if (i > 0) acum[i] += acum[i - 1];
    DEBUG(h, acum[i]);
    h -= acum[i];
    if (h > 0) {
      i64 bom = (h + A - 1) / A;
      cnt += bom;
      acum[i] += bom * A;
      i64 xend = x + 2 * D;
      int j = upper_bound(X.begin(), X.end(), xend) - X.begin();
      if (j < N) {
        acum[j] -= bom * A;
      }
      DEBUG(bom, cnt, xend, j);
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 10108
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
#define N 2000001
vector<long long> arr(N,0LL),dp1(N,0LL),dp2(N,0LL);
long long n,maxi = -10000000000000;
 
long long gcd(long long a,long long b){
 
	return b == 0 ? a : gcd(b,a%b);
}

int main()
{
    //fast
    ll n;
    cin >> n;
 
	for(long long i=1;i<=n;i++){
 
		cin >> arr[i];
	}
 
	for(long long i=1;i<=n;i++){
 
		dp1[i] = gcd(dp1[i-1],arr[i]);
	}
 
	for(long long i=n;i>=1;i--){
 
		dp2[i] = gcd(dp2[i+1],arr[i]);
	}
 
	for(long long i=1;i<=n;i++){
 
		maxi = max(maxi , gcd(dp1[i-1],dp2[i+1]));
	}
	cout << maxi;
    return 0;
} 

Measured memory_bytes: 47104
#include<iostream>
#include <cmath>

using namespace std;

int main(){
    long int x, i=0, n=100;
    double X, Y;

    cin >> x;

    Y = log10(x);

    while(i<4000)
    {
        X = log10(n);
        if(X >= Y){
            cout << i << endl;
            return 0;
        }

        n = n * 1.01 ;
        
        i++;
    }

}

Measured memory_bytes: 3932
#include "bits/stdc++.h"
using namespace std;

int main() {
    char a, b;
    cin >> a >> b;
    if ((a == 'H' && b == 'H') || (a == 'D'&& b == 'D')){
        cout << 'H';
    }
    else {
        cout << 'D';
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    Rep(i, M) {
        int a, b;
        cin >> a >> b;
        graph[a - 1].push_back(b - 1);
        graph[b - 1].push_back(a - 1);
    }
    Rep(i, graph[0].size()) {
        int v = graph[0][i];
        Rep(j, graph[v].size()) {
            if (graph[v][j] == N - 1) {
                puts("POSSIBLE");
                return 0;
            }
        }
    }
    puts("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 14940
#include <iostream>
using namespace std;
int main(){
    int m,n,sum;
    cin>>m>>n;
    int mat[m][n];
    int arr[n];
    for(int i=0;i<m;i++)
    {
        for (int j = 0; j < n; j++)
            cin >> mat[i][j];
    }

    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<m;i++) {
        sum = 0;
        {
            for (int j = 0; j<n; j++) {
                sum+=mat[i][j]*arr[j];
            }
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3124
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	auto H = vecin(N);
	reverse(ALL(H));

	for(int i=0;i<N-1;i++){
		if(H[i]<H[i+1]){
			if(H[i+1]-H[i]==1){
				H[i+1]--;
			}
			else{
				out("No");
				return 0;
			}
		}
	}
	out("Yes");
	return 0;
}


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

using namespace std;

int main(){
	double a,b,c,degree,S;
	scanf("%lf %lf %lf",&a,&b,&degree);
	S = (0.5)*a*b*sin(M_PI*degree/180);
	c = sqrt(a*a+b*b-2*a*b*cos(M_PI*degree/180));
	printf("%.8lf\n",S);
	printf("%.8lf\n",a+b+c);
	printf("%.8lf\n",2*S/a);
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define bit(n) 1 << n
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;
 
const int Inf = 1000000007;
//const int mod = 998244353;//1000000007;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
 
int n, m, q, ans = 0;
int a[55], b[55], c[55], d[55], A[15];
void Back(int pos)
{
	if(pos == 11)
	{
		int temp = 0;
		for(int i = 1; i <= q; i++)
		{
			if(A[b[i]] - A[a[i]] == c[i])
			{
				temp += d[i]; 
			}
		}
		ans = max(ans, temp);
		return;
	}
	for(int i = A[pos - 1]; i <= m; i++)
	{
		A[pos] = i;
		Back(pos + 1);
	}
}
 
void Solve()
{
	A[1] = 1;
	cin >> n >> m >> q;
	for(int i = 1; i <= q; i++)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	Back(2);
	cout << ans;
}
 
int main()
{
	Fastio();
	Solve();
}

Measured memory_bytes: 3672
#include<cstdio>

int solve(int e){
    int res=e;
    for(int z=0;z*z*z<=e;z++){
        for(int y=0;y*y+z*z*z<=e;y++){
            if(res>e+y+z-y*y-z*z*z) res=e+y+z-y*y-z*z*z;
        }
    }
    return res;
}

int main(){
    while(1){
        int e;
        scanf("%d",&e);
        if(e==0) return 0;
        printf("%d\n",solve(e));
    }
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;


int main(){

  int n,m,a[1000],b[1000],c[1000],dist[100][100];
  cin >> n>> m;
  
  for(int i=0;i<m;i++){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--,b[i]--;
     
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j){
      dist[i][j] = 0;
      }
      else{
        dist[i][j] = 1000000007;
      }
    }
  }
  
  
  for(int i=0;i<m;i++){
    
      dist[a[i]][b[i]] = min(dist[a[i]][b[i]],c[i]);
    dist[b[i]][a[i]] = min(dist[b[i]][a[i]],c[i]);
    
  }
  
 
  for (int k = 0; k < n; k++){       
    for (int i = 0; i < n; i++) {    
      for (int j = 0; j < n; j++) {  
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  int ans =0;
  for(int i=0;i<m;i++){
    bool ant = false;
    for(int j=0;j<n;j++)
    if(dist[j][a[i]] == dist[j][b[i]]-c[i])
      ant = true;
    
      if(ant){
        ans++;
      }
    
  }
  
  cout << m-ans << endl;
}
  
  
  
  
  
  


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b, a%b);
}

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

//typedef pair<ll, vi> Data;
typedef tuple<ll, int, int, int> Data;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    ll A[X], B[Y], C[Z];
    REP(i, X) cin >> A[i];
    REP(i, Y) cin >> B[i];
    REP(i, Z) cin >> C[i];

    sort(A, A + X, greater<ll>());
    sort(B, B + Y, greater<ll>());
    sort(C, C + Z, greater<ll>());

    priority_queue<Data, vector<Data>, less<Data>> q;
    q.push(make_tuple(A[0] + B[0] + C[0], 0, 0, 0));
    set<tuple<int, int, int>> s;

    int cnt = 0;
    while (cnt < K) {
        ll v; int ca, cb, cc;
        tie(v, ca, cb, cc) = q.top(); q.pop();
        if (s.count(make_tuple(ca, cb, cc))) continue;
        s.insert(make_tuple(ca, cb, cc));
        ++cnt;

        cout << v << endl;

        if (ca < X - 1) q.push(Data(A[ca + 1] + B[cb] + C[cc], ca + 1, cb, cc));

        if (cb < Y - 1) q.push(Data(A[ca] + B[cb + 1] + C[cc], ca, cb + 1, cc));

        if (cc < Z - 1) q.push(Data(A[ca] + B[cb] + C[cc + 1], ca, cb, cc + 1));
    }

}


Measured memory_bytes: 640
n,m=map(int,input().split())
dim=[]
a=[]
for i in range(n):
    a=list(map(int,input().split())) 
    a.pop(0)
    dim.append(a)
ans=[1+i for i in range (m)]
b=[]
for i in range(n):
    ans=list(set(ans)&set(dim[i]))
print(len(ans))

Measured memory_bytes: 3064