akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x>=10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int k,int mod){
	int res=1,bas=x;
	while(k){
		if(k&1) res=1ll*res*bas%mod;
		bas=1ll*bas*bas%mod,k>>=1;
	}
	return res;
}
const int N = 1e5+5;
int n,m,x,y,val[N];
pair<int,int> ope[N];
ll ans;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(m);
	for(ri i=1;i<=n;++i) read(val[i]);
	sort(val+1,val+1+n);
	for(ri i=1;i<=m;++i)
		read(x),read(y),ope[i]=make_pair(y,x);
	sort(ope+1,ope+1+m);
	for(ri i=m,now=1;i;--i){
		x=ope[i].second,y=ope[i].first;
		for(ri j=1;j<=x&&now<=n;++j){
			if(val[now]>=y) break;
			val[now++]=y;
		}
	}
	for(ri i=1;i<=n;++i) ans+=val[i];
	print(ans);
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long int a, b, c, k, ans = 0;
	cin >> a >> b >> c >> k;
	if (a >= k)
	{
		ans += k;
	}
	else
	{
		ans += a;
		k -= a;
		if (b < k)
		{
			k -= b;
			ans -= k;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main()
{
	int a[3][12]={{1,3,5,7,8,10,12},{4,6,9,11},{2}};
	int x,y,i,j;
	int nx,ny;
	nx=ny=-1;
	scanf("%d%d",&x,&y);
	for(i=0;i<3;i++){
		int n=sizeof(a[i])/sizeof(a[i][0]);
		for(j=0;j<n;j++){
			if(x==a[i][j])
				nx=i+1;	
			if(y==a[i][j])
				ny=i+1;	
		}
	}
	if(nx==ny)	printf("Yes\n");
	else	printf("No\n");	
		
	return 0;
}

Measured memory_bytes: 128
h,w=map(int,input().split())

A=[]
for i in range(h):
    A.append(list(map(int,input().split())))

if h==1 and w==1 :
    print(0)
else:


    aa=0
    C=[]
    ha=0
    s=1
    a=0
    b=0
    for i in range(h*w):
        if A[a][b]%2==1 :
            ha=(ha+1)%2
        if ha==1:
            if b+s<w and b+s>=0 :
                C.append([a,b,a,b+s])
            elif a<h :
                C.append([a,b,a+1,b])
        if ha==0 :
            aa=len(C)

        if b+s<w and b+s>=0 :
            b+=s
        else:
            a+=1
            s = -s

            
    print(aa)

    for i in range(aa):
        print(str(C[i][0]+1)+" "+str(C[i][1]+1)+" "+str(C[i][2]+1)+" "+str(C[i][3]+1))
        



Measured memory_bytes: 25948
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 10000;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
 
void solve()
{
     string s,t;
     cin >> s >> t;
     s += t[t.size()-1];
     if(s==t)  cout<<"Yes\n";
     else      cout<<"No\n";  
}

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

Measured memory_bytes: 3624
#include<stdio.h>
#define N 100000

struct Node{
  int p;
  int l;
  int r;
};
struct Node T[N]; 
int n,D[N];

void print(int);
int rec(int,int);

int main(){
  int i,j,d,v,c,l,r;
  
  scanf("%d",&n);
  for(i = 0; i < n; i++)
    T[i].p = T[i].l = T[i].r = -1;
  
  for(i = 0; i < n; i++){
    scanf("%d%d",&v,&d);
    for(j = 0; j < d; j++){
      scanf("%d",&c);
    if(j == 0) T[v].l = c;
    else T[l].r = c;
    l = c;
    T[c].p = v;
    }
  }
  for(i = 0; i < n; i++){
    if(T[i].p == -1) r = i;
  }
  rec(r,0);
  for(i = 0; i < n; i++) 
    print(i);
  
  return 0;
}

void print(int u){
  int i,c;
  printf("node %d:",u);
  printf(" parent = %d,",T[u].p);
  printf(" depth = %d,",D[u]);

  if(T[u].p == -1) printf(" root, ");
  else if(T[u].l == -1) printf(" leaf, ");
  else printf(" internal node, ");
  printf("[");  
  for(i = 0,c = T[u].l; c != -1; i++,c = T[c].r){
    if(i) printf(", ");
    printf("%d",c);
    }
  printf("]\n");
}

int rec(int u,int p){
  D[u] = p;
  if(T[u].r != -1) rec(T[u].r,p);
  if(T[u].l != -1) rec(T[u].l,p+1);
}

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

int main(){
	int y, m, d;
	while (cin >> y >> m >> d){
		if (y < 1868 || (y == 1868 && m < 9) || (y == 1868 && m == 9 && d < 8))cout << "pre-meiji";
		else{
			if (y < 1912 || (y == 1912 && m < 7) || (y == 1912 && m == 7 && d < 30))cout << "meiji " << y - 1867;
			else if (y < 1926 || (y == 1926 && m < 12) || (y == 1926 && m == 12 && d < 25))cout << "taisho " << y - 1911;
			else if (y < 1989 || (y == 1989 && m < 1) || (y == 1989 && m == 1 && d < 8))cout << "showa " << y - 1925;
			else cout << "heisei " << y - 1988;
			cout << " " << m << " " << d;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1164
from itertools import product
import numpy as np

N, M, X = map(int, input().split())
C = [0] * N
A = [[0] * M for _ in range(N)]
for i in range(N):
    c = list(map(int, input().split()))
    C[i] = c[0]
    A[i] = c[1:]

def calc(p):
    cnt = np.dot(np.array(list(p)), np.array(A))
    return np.dot(np.array(list(p)), np.array(C)) if all(i >= X for i in cnt) else 10 ** 30

ans = 10 ** 30
for p in product(range(2), repeat=N):
    ans = min(ans, calc(p))

print(ans if ans < 10 ** 30 else -1)


Measured memory_bytes: 27088
H,W=map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)]
A=[list(map(int,input().split())) for i in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])
ans=0
for i in range(H):
    for j in range(W):
        if A[i][j]==-1:
            continue
        ans+=c[A[i][j]][1]
print(ans)


Measured memory_bytes: 9452
from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)
                
def gcd(a,b):
    while b:
        a=a%b
        b,a=a,b
    return a

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r

def check(n,l):
    s=0
    for i in range(len(l)):
        s+=(l[i]-n)*(l[i]-n)
    return s

def solve():
    n=inp()
    x=[]
    l=li()
    for i in range(min(l),max(l)+1):
        x.append(check(i,l))
    pr(min(x))
        

for _ in range(1):
    solve()
    


Measured memory_bytes: 9268
#include <iostream>

using namespace std;

int main() {
  int n, m, l;
  long A[100][100] = {0};
  long B[100][100] = {0};
  long C[100][100] = {0};
  cin >> n >> m >> l;
  for(int y=0; y < n; ++y){
    for(int x=0; x < m; ++x){
      cin >> A[y][x];
    }
  }
  for(int y=0; y < m; ++y){
    for(int x=0; x < l; ++x){
      cin >> B[y][x];
    }
  }
  for(int y=0; y < n; ++y){
    for(int x=0; x < l; ++x){
      for(int i=0; i < m; ++i){
        C[y][x] += A[y][i] * B[i][x];
      }
    }
  }
  for(int y=0; y < n; ++y){
    for(int x=0; x < l; ++x){
      if(x) cout << ' ';
      cout << C[y][x];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3364
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*DP使ったほうがよくない？？WOWWOW*/

int main(){
  vector<int> S={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K; cin>>K;
  cout<<S.at(K-1)<<endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  int frontMax = 0;
  ll ans = 0;
  for (int i=0; i<N; i++) {
    if (A[i] > frontMax) {
      frontMax = max(frontMax, A[i]);
    } else {
      ans += frontMax - A[i];
    }
  }
  cout << ans << endl;
}


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

const int INF = 1 << 29;

int main(void){
    int n;
    cin >> n;
    vector<ll> v;
    v.push_back(1);
    for(int i = 9;i <= n;i *= 9)v.push_back(i);
    for(int i = 6;i <= n;i *= 6)v.push_back(i);
    
    vector<vector<ll>> dp(v.size()+1,vector<ll>(n+1,INF));
    dp[0][0] = 0;
    
    for(int i = 0;i < v.size();i++){
        for(int j = 0;j <= n;j++){
            if(j >= v[i])dp[i+1][j] = min(dp[i][j],dp[i+1][j-v[i]]+1);
            else dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        }
    }
    
    cout << dp[v.size()][n] << endl;
}

Measured memory_bytes: 14192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// #define int long long
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

int lcm(int, int);
map<int,int> GetPrimeFactors(int);
bool IsPrime(int);
int Factorial(int);
int npr (int, int);
int ncr (int, int);

/***** MAIN *****/
void Main() {
  int n;
  cin >> n;
  int nums[n];
  REP(i,n) {
    cin >> nums[i];
  }
  bool flag = true;
  REP(i,n) {
    if(nums[i] % 2 == 0) {
      if(nums[i] % 3 != 0 && nums[i] % 5 != 0) {
        flag = false;
        break;
      }
    }
  }
  if(flag) {
    cout << "APPROVED";
  } else {
    cout << "DENIED";
  }
  
  cout << "\n";
}
/***** MAIN *****/

signed main() {
  cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
  Main();
  return 0;
}

int lcm(int a, int b) { return a / __gcd(a,b) * b;}

map<int,int> GetPrimeFactors(int n) {
  map<int,int> mp;
  // dived by 2, 3, 5, ...
  for(int i=2; i*i<=n; i+=2) {
    if(i==4) i = 3;
    while(n%i == 0) {
      ++mp[i];
      n /= i;
    }
  }
  if(n!=1) ++mp[n];

  return mp;
}

bool IsPrime(int a) {
  if(a <= 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(int i = 3; i*i <= a; i+=2) {
    if(a%i==0) return false;
  }
  return true;
}

int Factorial(int n){
  int ans = 1;
  while(n > 1){
    ans *= n;
    --n;
  }
  return ans;
}

int npr(int n, int r) {
  return Factorial(n)/Factorial(n-r);
}

int ncr (int n, int r){
  return npr(n,r)/Factorial(r);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <iomanip>

using namespace std;

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

	double p = 0;

	for(int i = 1; i <= n; i++){
		int j = 0;
		while(true){
			if(i * pow(2.0, (double)j) >= k){
				p += pow(0.5, j) / (double)n;
				break;
			}
			j++;
		}
	}

	cout << fixed;
	cout << setprecision(12) << p << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())

def Main():
    x = I()
    for a in range(-118,120):
        for b in range(-118,120):
            if a**5-b**5 == x:
                print(a,b)
                exit()
    return

if __name__=='__main__':
    Main()

Measured memory_bytes: 9176
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;

int H, W;
string s[50];
int dist[50][50] = {};

int dh[] = {1, 0, -1, 0}, dw[] = {0, 1, 0, -1}; 

void visit(int h, int w, int step){
    if(h < 0 || h >= H || w < 0 || w >= W){
        return;
    }
    if(s[h][w] == '#'){
        return;
    }
    if(step > 50*50*2){
        return;
    }
    if(dist[h][w] <= step){
        return;
    }
    dist[h][w] = step;
    for(int i = 0; i < 4; i++){
        int h_ = h + dh[i];
        int w_ = w + dw[i];
        visit(h_, w_, step+1);
    }
}

int main(){
    cin >> H >> W;
    for(int h = 0; h < H; h++){
        cin >> s[h];
    }
    int black_count = 0;
    for(int h = 0; h < H; h++){
        for(int w = 0; w < W; w++){
            if(s[h][w] == '#'){
                black_count++;
            }
        }
    }
    memset(dist, 1000000, sizeof(dist));
    visit(0, 0, 0);
    if(dist[H-1][W-1] < 50*50*10){
        cout << (H*W) - black_count - (dist[H-1][W-1]+1) << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 384
N = int(input())
P = list(map(int, input().split()))
m_list = [0]*N
m_list[0] = P[0]
res = 1

for i in range(1, N):
  m_list[i] = min(m_list[i-1], P[i])
  if m_list[i] == P[i]:
    res += 1
  
print(res)


Measured memory_bytes: 24744
import sys
sys.setrecursionlimit(10 ** 8)

n, *a = map(int, open(0).read().split())
lose_to = [[] for _ in range(n)]
for i, x in enumerate(a, start=1):
	lose_to[x - 1].append(i)

def dfs(x):
	if not lose_to[x]:
		return 0
	else:
		s = sorted([dfs(y) for y in lose_to[x]], reverse=True)
		return max(i + z for i, z in enumerate(s, start=1))

print(dfs(0))


Measured memory_bytes: 231860
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = ((int)(n) - 1); i >= 0; i--)
#define repn(i, n) for(int i = 1; i <= (int)(n); i++)
#define reprn(i, n) for(int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
using llint = long long int;
using lint = long int;

#include <iostream>
#include <array>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <numeric>
#include <limits>
#include <type_traits>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<lint> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	lint min_a = 1000000000;
	llint sum = 0;
	int minus_num = 0;
	rep(i, n) {
		if (abs(a[i]) < min_a) {
			min_a = abs(a[i]);
		}
		if (a[i] < 0) {
			minus_num++;
		}
		sum += abs(a[i]);

	}
	if (minus_num % 2 == 0) {
		cout << sum << endl;
	} else {
		cout << sum - min_a * 2 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
k=[]
s=[]
ans=0
for i in range(m):
  kk, *ss=map(int,input().split())
  k.append(kk)
  s.append(ss)
p=list(map(int,input().split()))
for i in range(2**n):
  tmp=[]
  for j in range(n):
    if (i>>j)&1:
      tmp.append(j+1)
  for j in range(m):
    if len(set(tmp)&set(s[j])) % 2 != p[j]:
      break
  else:
    ans+=1
print(ans)

Measured memory_bytes: 74044
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a, b, c;
        a = scanner.nextInt();
        b = scanner.nextInt();
        c = scanner.nextInt();

        int n = c / (a * 7 + b), res = c % (a * 7 + b);
        int res_n = 0;
        if (res > a * 6) {
            res_n = 7;
        } else {
            res_n = (res % a == 0 ? res / a : res / a + 1);
        }

        System.out.println(n * 7 + res_n);
    }
}



Measured memory_bytes: 26396
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
fun solve(A: Long, B: Long, C: Long){
    println(Math.max(0, B+C-A))
    pw.flush()
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    val C = sc.next().toLong()
    solve(A, B, C)
}




Measured memory_bytes: 31396
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while (true) {
    C -= B;
    // 青木君のモンスターが生き残る
    if (C>0) {
      A -= D;
      if (A<=0) {
        cout << "No" << endl;
        break;
      }
    }
    else {
      cout << "Yes" << endl;
      break;
    }
  }
}

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

int main(){
    ll N, K; cin >> N >> K;
    vector<pair<ll,ll>> P(N);
    for(int i = 0; i < N; i++){
        int a,b; cin >> a >> b;
        P[i] = {a,b};
    }
    sort(P.begin(), P.end());
    ll index = 0;
    for(int i = 0; i < N; i++){
        index += P[i].second;
        if(index >= K){
            cout << P[i].first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
int main(void) {
	int a, i;
	long long int s;
	
	while(scanf("%d", &a) != EOF){
		s = 0;
		for(i = a; 600 > i; i+=a){
			s += i*i*a;
		}
		printf("%lld\n", s);
	}
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
ll pr[22], cnt[22];
int main(){
    ll n;
    while(cin>>n){
        ll ans=0;
        pr[0]=1;
        cnt[0]=0;
        int tmp;
        for(int i=1; i<15; ++i){
        	pr[i]=pr[i-1]*26;
        	cnt[i]=pr[i]+cnt[i-1];
        	if(n<=cnt[i]){
        		tmp=i;
        		break;
        	}
        }
        n-=cnt[tmp-1];
        for(int i=tmp; i>=1; --i){
        	for(int j=1; j<=26; ++j){
        		if(n<=pr[i-1]*j){
        			cout<<char('a'+j-1);
        			n-=pr[i-1]*(j-1);
        			break;
        		}
        	}
        }
        cout<<endl;
    }
  return 0;
}




Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<stdint.h>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long int
using namespace std;

int32_t main(){
	double n,x,c=0.0000000;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		c+=1.000000/x;
	}
	cout<<1.000000/c;
}


Measured memory_bytes: 256
const main = (input) => {
  input = input.trim();
  input = input.split(' ');
  const a = input[0];
  const b = input[1];
  
  if (a=="H" && b=="H") {
    console.log("H");
  }else if (a=="D" && b=="D"){
    console.log("H");
  }else{
    console.log("D");
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;
const long long MOD = 1000000007;

long long dat[2 * MAX_N - 1];

ll fact(ll n) {
	if (n == 1) return 1;
	return n * fact(n - 1);
}

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

//A

int main(void) {
	ll n;
	string x;
	cin >> n;
	map<string, ll> mp = map<string, ll>();
	vector<ll> sum = vector<ll>(n + 1);
	sum[0] = 0;
	rep(i, 0, n) {
		string s;
		ll t;
		cin >> s >> t;
		mp[s] = i+1;
		sum[i + 1] = sum[i] + t;
	}
	cin >> x;
	cout << sum[n] - sum[mp[x]] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,j,k)for(int i=j;i<=k;++i)
using namespace std;
const int N=2010;
int A[N];

bool cmp(int x,int y){
	return A[x]<A[y];
}
int bel[N],cnt[N],rk[N],n,k,q;

int main(){
	scanf("%d%d%d",&n,&k,&q);
	For(i,1,n)scanf("%d",&A[i]),rk[i]=i;
	sort(rk+1,rk+n+1,cmp);
	int ans=1e9;
	For(i,1,n-q+1){
		For(j,0,n)cnt[j]=0;
		For(j,0,n){
			bel[j]=A[j]<A[rk[i]]?j:bel[j-1];
			if(bel[j]!=j)++cnt[bel[j]];
		}
		int ret=0;
		For(j,i,n){
			if(cnt[bel[rk[j]]]>=k){
				++ret,--cnt[bel[rk[j]]];
				if(ret>=q){
					ans=min(ans,A[rk[j]]-A[rk[i]]);
					break;
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
z=[list(map(int,input().split()))for _ in range(n)]
z.sort()
a=10**20
for i in range(n):
    for j in range(i+1,n):
        x=z[j][0]-z[i][0]
        l=sorted(t[1]for t in z[i:j+1])
        for u,v in zip(l,l[k-1:]):
            a=min(a,x*(v-u))
print(a)

Measured memory_bytes: 40560
#include<bits/stdc++.h>
using namespace std;
typedef int int_t;

bool vis[1000100];
int_t A[200010];

int main() {
   int_t n; scanf("%d", &n);
   for(int_t i=1;i<=n;i++) scanf("%d", A + i);
   sort(A + 1, A + n + 1);
   for(int_t i=1;i<=n;i++) {
       if(A[i] != A[i-1]) {
           for(int_t j=A[i]*2;j<=1000000;j+=A[i]) vis[j] = true;
       } else vis[A[i]] = true;
   } 
   int_t ans = 0;
   for(int_t i=1;i<=n;i++) if(!vis[A[i]]) ++ans;
   cout << ans;
}

Measured memory_bytes: 5408
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<ll,ll>
	#define PB push_back
	#define vc vector
	void chmax(int &x,const int y) {x=x>y?x:y;}
	void chmin(int &x,const int y) {x=x<y?x:y;}
	const int MAX_N=2e5+10;
	const ll MOD=998244353;
	void add(ll &x,ll y){x+=y;if(x>=MOD) x-=MOD;if(x<=-MOD) x+=MOD;}
	ll qpower(ll x,ll e)
	{
		ll ans=1;x%=MOD;
		while(e)
		{
			if(e&1) ans=ans*x%MOD;
			x=x*x%MOD;e>>=1;
		}
		return ans;
	}
	ll inv2(ll x){return qpower(x,MOD-2);}
	
	char a[MAX_N];
	int f[MAX_N][2];
	void main()
	{
		int n=qread();scanf("%s",a+1);
		for(int i=1;i<=n;i++)
		{
			f[i][0]=min((a[i]=='#')+f[i-1][0],INF);
			f[i][1]=min((a[i]=='.')+f[i-1][0],(a[i]=='.')+f[i-1][1]);
		}
		write(min(f[n][0],f[n][1]));
	}
};
signed main()
{
	srand(time(0));
	mine::main();
}

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

int main() {
    // 3~ N-1
    // 8~ N/2 - 1
    // 15~ N/3 - 1
    // 24~ N/4 - 1
    // 24 5
    // 28 6
    ll N, ans = 0;
    cin >> N;
    for (ll i = 3, j = 5, k = 1; i <= N; i += j, j += 2, k++) {
        //cout << i << " " << j << " " << k << endl;
        if (N % k == 0) {
            ans += N / k - 1;
        
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
#include<string.h>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int from,to,cost;};
vector<edge> G;
vector<int> O[10];
P sg[10];
int d[1005];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int fi[1005][1005];
int ans[1005][1005]={};
bool graph[55][55];
bool visited[55];
int a[55],b[55];
int n,m;
int dp[41][405][405];
signed main(){
    int n,a,b;cin>>n>>a>>b;
    int an[45],bn[45],cn[45];
    rep(i,n)cin>>an[i]>>bn[i]>>cn[i];
    rep(i,n)rep(j,405)rep(k,405)dp[i][j][k]=1000;
    dp[0][an[0]][bn[0]]=cn[0];
    dp[0][0][0]=0;
    for(int i=1;i<n;i++){
        for(int j=404;j>=0;j--){
            for(int k=404;k>=0;k--){
                if(j>=an[i]&&k>=bn[i]){
                    dp[i][j][k]=min(dp[i-1][j][k],dp[i-1][j-an[i]][k-bn[i]]+cn[i]);
                }
                else dp[i][j][k]=dp[i-1][j][k];
            }
        }
    }
    int mini=inf;
    rep(j,405)rep(k,405){
        if(!(j==0&&k==0)&&j*b==k*a){
            if(mini>dp[n-1][j][k]){
                mini=dp[n-1][j][k];
            }
        }
    }
    cout<<(mini==1000?-1:mini)<<endl;
    return 0;
}


Measured memory_bytes: 53504
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	N := nextInt()
	Q := nextInt()
	edge := make([][]int, N)
	for i := 0; i < N-1; i++ {
		a := nextInt()
		b := nextInt()
		edge[a-1] = append(edge[a-1], b-1)
	}
	// fmt.Fprintln(out, edge)
	count := make([]int, N)
	for i := 0; i < Q; i++ {
		p := nextInt()
		q := nextInt()
		count[p-1] += q
	}
	solve(edge, count, 0)
	PrintOut(count, " ")
}

func solve(edge [][]int, count []int, idx int) {
	for i := 0; i < len(edge[idx]); i++ {
		count[edge[idx][i]] += count[idx]
		solve(edge, count, edge[idx][i])
	}
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


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

using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

struct BIT{
    int N;
    vector<ll> bit;
    BIT(int N) : bit(N+1),N(N){};

    ll sum(int i){
		i++;
        ll s = 0;
        while(i>0){
           s += bit[i];
           i -= i& -i;
        }
        return s;
    }

    void add(int i,ll x){
		i++;
        while(i <= N){
            bit[i] += x;
            i += i & -i;
        }
    }

    ll sum(int l, int r){
        return sum(r-1) - sum(l-1);
    }
};

const int MAX_N = 200005;
vector<vector<int>> g(MAX_N);
vector<int> c(MAX_N), in(MAX_N), out(MAX_N);
int k;

void dfs(int cur, int p=-1){
	in[cur]=k++;
	for(int next: g[cur]){
		if(next==p)continue;
		dfs(next,cur);
	}
	out[cur]=k;
}

ll f(ll x){
	return x*(x+1)/2;
}


int main()
{
	int n;
	cin>>n;
	rep(i,n)cin>>c[i];
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0);

	vector<vector<int>> color(n);
	rep(i,n)color[c[i]-1].push_back(i);

	struct BIT t(n);
	rep(i,n) t.add(i,1);
	rep(i,n){
		ll ans=f(n);

		vector<int> &cur_c=color[i];

		sort(all(cur_c),
			[&](int a, int b){
				 return in[a]>in[b];
			});

		vector<P> history;

		for(int v: cur_c){
			int cnt=1;
			for(int u: g[v]){
				if(in[u] < in[v]) continue;
				int num=t.sum(in[u], out[u]);
				ans-=f(num);
				cnt+=num;
			}
			t.add(in[v],-cnt);
			history.emplace_back(in[v],cnt);
		}
		ans-=f(t.sum(0,n));
		for(auto p: history){
			t.add(p.first, p.second);
		}
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 36100
def main():
    W, H, x, y, r = map(int, input().split())
    
    f = 1
    if x + r > W:
        f = 0
    if x - r < 0:
        f = 0
    if y + r > H:
        f = 0
    if y - r < 0:
        f = 0

    if f == 1:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 7788
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll n; cin >> n;
  if(n==0){
    cout << 0 << endl;
    return 0;
  }
  vector<ll> vout;
  ll i=1;
  while(abs(n)>0){
    ll r = abs(n)%2;
    vout.push_back(r);
    n -= r;
    n/=-2;
  }
  string out = "";
  for(auto ritr=vout.rbegin();ritr != vout.rend();++ritr) out += to_string(*ritr);
  cout << out << endl;
  return 0;
}


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

signed main() {
  string S;
  cin>>S;
  int i,j;
  int n=S.size();
  for(i=n-1;i>=0;i){
    j=i;
    if(i>=6){
      if(S[i-6]=='d'&&S[i-5]=='r'&&S[i-4]=='e'&&S[i-3]=='a'&&S[i-2]=='m'&&S[i-1]=='e'&&S[i]=='r')i-=7;
      if(S[i-5]=='e'&&S[i-4]=='r'&&S[i-3]=='a'&&S[i-2]=='s'&&S[i-1]=='e'&&S[i]=='r')i-=6;
      if(S[i-4]=='d'&&S[i-3]=='r'&&S[i-2]=='e'&&S[i-1]=='a'&&S[i]=='m')i-=5;
      if(S[i-4]=='e'&&S[i-3]=='r'&&S[i-2]=='a'&&S[i-1]=='s'&&S[i]=='e')i-=5;
    }
    if(j==5)if(S[i-5]=='e'&&S[i-4]=='r'&&S[i-3]=='a'&&S[i-2]=='s'&&S[i-1]=='e'&&S[i]=='r')i-=6;
    if(j==4){
      if(S[i-4]=='d'&&S[i-3]=='r'&&S[i-2]=='e'&&S[i-1]=='a'&&S[i]=='m')i-=5;
      if(S[i-4]=='e'&&S[i-3]=='r'&&S[i-2]=='a'&&S[i-1]=='s'&&S[i]=='e')i-=5;
    }
    if(j==i)break;
  }
  if(i==-1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll a, b, c;
    cin >> a >> b >> c;
    cout << min(a + b, min(b + c, c + a)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef set<int> si;
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    string t;
    bool flag = true;
    cin >> a >> b >> t;
    for (int i = 0; i < a; i++)
        if (!isdigit(t[i]))
            flag = false;
    flag = flag && t[a] == '-';
    for (int i = 0; i < b; i++)
        if (!isdigit(t[a + i + 1]))
            flag = false;
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define int long long
const int inf = 1e9;
void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> g[n];
    f(m)
    {
        ic(v)
        ic(u)
        g[v - 1].pb(u - 1);
        g[u - 1].pb(v - 1);
    }
    int ans[n];
    int d[n];
    f(n) d[i] = inf;
    d[0] = 0;
    queue<int> q;
    q.push(0);
    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        for(int u : g[v])
        {
            if(d[u] == inf)
            {
                ans[u] = v;
                d[u] = d[v] + 1;
                q.push(u);
            }
        }
    }
    for(int i = 1; i < n; i++)
    {
        if(d[i] == inf)
        {
            cout << "No";
            return;
        }
    }
    cout << "Yes\n";
    for(int i = 1; i < n; i++) cout << ans[i] + 1 << '\n';

}
main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    f(t) solve();
}


Measured memory_bytes: 13684
#include<bits/stdc++.h>
#define ll  long long  
#define pb push_back
#define fi first
#define se second
using namespace std;
ll mo=1e9+7;
ll i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p)%mo;
p=(p*p)%mo;
k>>=1;
}
return a;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	 ll a,b,n;
	 cin>>a>>b>>n;
	 if(n>=(b-1))
	 {
	   n=b-1;
     }
     cout<<floor(a*1.0*n/b)-a*floor(1.0*n/b);
	cout<<"\n"; 
 } 
}


Measured memory_bytes: 3776
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
vector<P> info;//position,time

bool iscan;
int ans;
int failedPosition;

void rec(int time,int k,int distance,int position){
  if(distance >= ans)return;

  if(position >= info.size()-1){
    ans = min(ans,distance+info[position].F);
    //cout << "ans = " << ans << endl;
    return;
  }


  int time1,time2;//time1 -> そのまま次へ, time2 -> 一旦家に帰る
  time1 = time+(k+1)*abs(info[position+1].F-info[position].F);
  time2 = time+(k+1)*abs(info[position].F-info[0].F)+info[position+1].F;
  
  if(k == 3){
    if(time2 <= info[position+1].S){
      rec(info[position+1].S,1,distance+abs(info[position].F-info[0].F)+info[position+1].F,position+1);
      return;
    }
    else{
      iscan = false;
      failedPosition = position+1;
      return;
    }
   
  }



 
  if(time1 <=info[position+1].S && time2 <=info[position+1].S ){
    rec(info[position+1].S,k+1,distance+abs(info[position+1].F-info[position].F),position+1);
    rec(info[position+1].S,1,distance+abs(info[position].F-info[0].F)+info[position+1].F,position+1);
  }
  else if(time1<=info[position+1].S){
    rec(info[position+1].S,k+1,distance+abs(info[position+1].F-info[position].F),position+1);
  }
  else if(time2<=info[position+1].S){
    rec(info[position+1].S,1,distance+abs(info[position].F-info[0].F)+info[position+1].F,position+1);
  }
  else {
    iscan = false;
    failedPosition = position+1;
    return;
  } 



}


int main(){
  int n,p,t;
  const int INF=999999999;

  while(cin >> n && n){
    ans = INF;
    info.clear();
    iscan = true;

    info.push_back(P(0,0));
    for(int i=0;i<n;i++){
      cin >> p >> t;
      info.push_back(P(p,t));
    }
   
    rec(0,0,0,0);

    if(!iscan && ans == INF){
      cout << "NG " << failedPosition << endl;
    }
    else{
      cout << "OK " << ans << endl;
    }

  }
  return 0;
}

Measured memory_bytes: 1204
//C. Social Distance
//https://codeforces.ml/contest/1367/problem/C
#include <bits/stdc++.h>
using namespace std; 
int main()
{
	long long  t=0,n=0;
	cin>>n;
	int i=0,k=0,tmp=0;
	string s;
	while(n>t)
	{
		t=26*(t+1);
		i++;
	}
	for(k=1;k<=i;k++)
	{
		tmp=n%26;
		if(tmp==0)
		{
			tmp=26;
			n--;
		}
		s+='a'+tmp-1;
		n/=26;	
	}
	for(k=s.size()-1;k>=0;k--)
		cout<<s[k];
	return 0;
}
	

Measured memory_bytes: 3596
#include <cstring>
#include <iostream>

using namespace std;

#define UNMEMOIZED -1
#define MODULUS 1000000007

int sequenceCountCache[2001];

int memoizeSequenceCount(int s) {
    if (s < 3) return 0;

    int &sequenceCount = sequenceCountCache[s];

    if (sequenceCount != UNMEMOIZED) return sequenceCount;

    sequenceCount = 1;

    for (int i = 3; i <= s - 3; i++) {
        sequenceCount = (sequenceCount + memoizeSequenceCount(i)) % MODULUS;
    }

    return sequenceCount;
}

int main() {
    int s;

    memset(sequenceCountCache, UNMEMOIZED, sizeof(sequenceCountCache));

    cin >> s;

    cout << memoizeSequenceCount(s) << endl;

    return 0;
}


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

def main():
    INF = 10**9 + 1
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,M = LI()
    x = []; y = []
    A = []
    D = []
    for _ in range(N):
        a,b,c = LI()
        A.append((a,b,c))
        x.append(a); x.append(b)
        y.append(c); y.append(c)
    for _ in range(M):
        d,e,f = LI()
        D.append((d,e,f))
        x.append(d); x.append(d)
        y.append(e); y.append(f)

    x.append(-INF); x.append(INF); x.append(0)
    y.append(-INF); y.append(INF); y.append(0)
    x.sort(); y.sort()
    lx = len(x); ly = len(y)
    fld = [[0] * ly for _ in range(lx)]
    for a,b,c in A:
        j = bisect.bisect_left(y,c)
        for i in range(bisect.bisect_left(x,a),bisect.bisect_left(x,b)):
            fld[i][j] = 1
    for d,e,f in D:
        i = bisect.bisect_left(x,d)
        for j in range(bisect.bisect_left(y,e),bisect.bisect_left(y,f)):
            fld[i][j] = 1

    q = collections.deque()
    i = bisect.bisect_left(x,0)
    j = bisect.bisect_left(y,0)
    q.append((i,j))
    fld[i][j] = 1
    ans = 0
    while q:
        i,j = q.popleft()
        ans += (x[i+1]-x[i]) * (y[j+1]-y[j])
        for di,dj in ((0,1),(1,0),(0,-1),(-1,0)):
            if 0 < i+di < lx-1 and 0 < j+dj < ly-1:
                if fld[i+di][j+dj] == 0:
                    fld[i+di][j+dj] = 1
                    q.append((i+di,j+dj))
            else:
                print('INF')
                exit(0)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 281308
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    let mut g = vec![vec![]; n];
    for _ in 0..m {
        let a = sc.cin::<usize>() - 1;
        let b = sc.cin::<usize>() - 1;
        g[a].push(b);
        g[b].push(a);
    }
    let mut prev = vec![None; n];
    let mut stack = std::collections::VecDeque::new();
    stack.push_back(0);
    while let Some(u) = stack.pop_front() {
        for &v in g[u].iter() {
            if prev[v] == None {
                prev[v] = Some(u);
                stack.push_back(v);
            }
        }
    }
    put!("Yes");
    for i in 1..n {
        put!(prev[i].unwrap() + 1);
    }
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 12676
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    long k = sc.nextLong();
    long[] a = new long[n+1];
    long[] b = new long[m+1];
    a[0] = 0;
    b[0] = 0;
    int j = m, count = 0;
    
    for(int i=1;i<=n;i++) {
    	a[i] = a[i-1]+sc.nextLong();
    	}
    for(int i=1;i<=m;i++) {
    	b[i] =b[i-1]+ sc.nextLong();
    	}
    for (int i = 0; i <= n; i++) {
        if (a[i] > k) {
            break;
        }
        while (b[j] > k - a[i]) {
            j--;
        }
        count = Math.max(count, i+j);
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 63876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll a[n+5];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	ll p[n+5];
	p[0]=1;
	for(ll i=1;i<=n;i++)
	{
		p[i]=p[i-1]*2;
		if (p[i]>=mod)
			p[i]%=mod;
	}

	ll ans = 0;
	for(ll i=1;i<=n;i++)
	{
		ll Ans = p[n-i-1]*(n-i);
		if (Ans>=mod)
			Ans%=mod;
		Ans += p[n-i];
		if (Ans>=mod)
			Ans%=mod;

		Ans*=p[i-1];
		if (Ans>=mod)
			Ans%=mod;

		Ans*=a[i-1];
		if (Ans>=mod)
			Ans%=mod;
		ans+=Ans;
		if (ans>=mod)
			ans%=mod;
		//cout<<Ans<<" ";
	}
	//cout<<"\n";
	ans*=p[n];
	if (ans>=mod)
		ans%=mod;
	cout<<ans;
}

Measured memory_bytes: 3328
from sys import stdin

input = stdin.readline

X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

lis = []

for i in range(X):
    lis.append(P[i])

for i in range(Y):
    lis.append(Q[i])

for i in range(min(len(R), X + Y)):
    lis.append(R[i])

lis.sort(reverse=True)

ans = 0

for i in range(X + Y):
    ans += lis[i]

print(ans)


Measured memory_bytes: 23312
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){

  int a,b,c; cin >> a >> b >> c;
  int ans = 0;
  if(a + b < c){
    ans += (a+b)+1 + b;
  }
  else{
    ans += c + b;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
h, n = map(int, input().split())
M = [list(map(int, input().split())) for _ in range(n)]

INF = 10**9
dp = [[INF] * (h+1) for _ in range(n+1)]
dp[0][h] = 0
for i in range(n):
    for j in reversed(range(h+1)):
        a, b = M[i]
        if j > h - a:
            dp[i+1][j] = min(dp[i][j], b)
        else:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j+a] + b)
print(dp[n][0])

Measured memory_bytes: 119404
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  int max=0;
  
  for(int j=1;j<N;j++){
    int sum=0;

for(char c='a';c<='z';c++){
  bool left=false;
  bool right=false;
  
  for(int i=0;i<j;i++){
    if(S.at(i)==c){
left=true;
    }
  }
  
  for(int k=j;k<N;k++){
    if(S.at(k)==c){
      right=true;
    }
  }
  
  if(left&&right){
sum++;
  }
}

    if(sum>max){
      max=sum;
    }
  }
  cout<<max<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   string S;
   cin>>S;

   bool flag=true;
   for(int i=0;i<4;i++){
      int count=0;
      for(int j=0;j<4;j++){
         if(S.at(i)==S.at(j))
            count++;
      }
      if(count!=2)
         flag=false;
   }
   if(flag==true)
      cout<<"Yes"<<endl;
   else
      cout<<"No"<<endl;
}

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

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

    int scnt = 0;
    int cut = 0;
    for(int i = 0; i < x.length(); i++){
        if(x[i] == 'S'){
            scnt++;
        }else if(x[i] == 'T' && scnt > 0){
            scnt--;
            cut++;
        }
    }

    cout << x.length() - cut*2 << endl;
    return 0;
}

Measured memory_bytes: 640
n, k = map(int, input().split())
s1, s2, s3, s4, s5, s6 = k, k+n-1, k+n, k+2*n-1, k+2*n, k+3*n-1
if s1 + s4 <= (s5 + s6)/2:
  for i in range(n//2+n%2):
    a = s1 + i*2
    b = s4 - i
    c = s5 + n//2 + i
    print(a, b, c)
  for i in range(n//2):
    a = s1 + 1 + i*2
    b = s4 - (n+1)//2 - i
    c = s5 + i
    print(a, b, c)
else:
  print(-1)

Measured memory_bytes: 5172
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
#define MAX_N (22)
#define MAX_M (2010)
int n;
int A[MAX_N];
int q;
bool dp[2][MAX_M+1];
int main()
{
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);
    dp[1][0] = true;
    
    for ( int i = 0; i < n; i++ ) {
	for ( int j = 0; j <= MAX_M; j++ ) {
	    if ( dp[((i+1)%2)][j] ) {
		dp[(i%2)][j] = true;
		if ((j + A[i]) <= MAX_M ) {
		    dp[(i%2)][j + A[i]] = true;
		}
	    }
	}
    }

    scanf("%d", &q);
    for ( int i = 0; i < q; i++ ) {
	int m;
	scanf("%d", &m);
	printf("%s\n", (dp[(n+1) % 2][m]) ?  "yes" : "no");
    }
    
    return 0;
}

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

using namespace std;

int main() {
    int N, result;
    double printed;
    cin >> N;
    printed = N%2;
    if (printed == 1){
        result = (N/2) +1;
    }
    else{
        result = N/2;
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 256