akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

vector<int> G[51];
bool onTheWay[51][51][51][51];
vector<pii> stk;
void dfs(int u, int p, bool on[51][51][51]) {
    each(e, stk) {
        on[u][e.first][e.second] = true;
        on[u][e.second][e.first] = true;
    }
    each(v, G[u]) {
        if (v != p) {
            stk.emplace_back(u, v);
            dfs(v, u, on);
            stk.pop_back();
        }
    }
}

void solve() {
    int N;
    cin >> N;
    vi A(N - 1), B(N - 1);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        A[i] = a;
        B[i] = b;
    }
    rep(i, N) {
        dfs(i, -1, onTheWay[i]);
    }

    int M;
    cin >> M;
    vi U(M), V(M);
    rep(i, M) {
        cin >> U[i] >> V[i];
        --U[i];
        --V[i];
    }

    vll dp(1 << M);
    dp[0] = 1;
    rep(i, N - 1) {
        int fulfilled = 0;
        rep(j, M) {
            if (onTheWay[U[j]][V[j]][A[i]][B[i]]) {
                fulfilled |= 1 << j;
            }
        }
        for (int S = (1 << M) - 1; S >= 0; --S) {
            dp[S | fulfilled] += dp[S];
        }
    }
    cout << dp.back() << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 14848
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second

signed main() {
    string s;
    cin >> s;
    map<char, int> cnt;
    for(int i = 0; i < sz(s); i++) {
        cnt[s[i]]++;
    }
    bool ans = true;
    for(auto el : cnt) {
        if(el.se % 2 == 1){
            ans = false;
        }
    }
    if(ans) {
        cout << "Yes\n";
    }else {
        cout << "No\n";
    }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

const int inf = INT_MAX;

int data[1<<23];
int H, W;
int wid;

void init(const int f[], int h, int w)
{
  H = W = 1;
  while(H < h) H <<= 1;
  while(W < w) W <<= 1;
  wid = 2*W-1;
  fill(begin(data), end(data), inf);
  for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++)
      data[(i+H-1)*wid+(j+W-1)] = f[i*w+j];

  for(int i = 2*H-2; i > H-2; i--)
    for(int j = W-2; j >= 0; j--)
      data[i*wid+j] = min(data[i*wid+(2*j+1)], data[i*wid+(2*j+2)]);

  for(int i = H-2; i >= 0; i--)
    for(int j = 0; j < 2*W-1; j++)
      data[i*wid+j] = min(data[(2*i+1)*wid+j], data[(2*i+2)*wid+j]);
}
int query_w(int lj, int rj, int aj, int bj, int i, int k)
{
  if(rj <= aj || bj <= lj) return inf;
  if(lj <= aj && bj <= rj) return data[i*wid+k];
  return min(query_w(lj, rj, aj, (aj+bj)/2, i, 2*k+1),
	     query_w(lj, rj, (aj+bj)/2, bj, i, 2*k+2));
}
int query_h(int li, int lj, int ri, int rj, int ai, int bi, int k)
{
  if(ri <= ai || bi <= li) return inf;
  if(li <= ai && bi <= ri) return query_w(lj, rj, 0, W, k, 0);
  return min(query_h(li, lj, ri, rj, ai, (ai+bi)/2, 2*k+1),
	     query_h(li, lj, ri, rj, (ai+bi)/2, bi, 2*k+2));
}
int query(int li, int lj, int ri, int rj)
{
  return query_h(li, lj, ri, rj, 0, H, 0);
}

int r, c, q;
int grid[1000100];
int lr, lc, rr, rc;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> r >> c >> q, r) {
    rep(i, r) rep(j, c) cin >> grid[i*c+j];

    init(grid, r, c);

    while(q--) {
      cin >> lr >> lc >> rr >> rc;
      cout << query(lr, lc, rr+1, rc+1) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 39744
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char three = s.charAt(2);
		char four = s.charAt(3);
		char five = s.charAt(4);
		char six = s.charAt(5);
		
		if(three == four && five == six) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;


ll check_p(ll x);

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

  ll check = n;
  vector<ll> sosuu;
  vector<ll> sosuu_kazu;
  for(ll i=2; i<sqrt(n)+1; i++){
    ll count = 0;
    while(check%i==0){
      check/=i;
      count++;
    }
    if(count){
     sosuu.push_back(count);
     sosuu_kazu.push_back(i);
    }
  }

  if(check!=1) sosuu.push_back(1);

  ll ans = 0;
  for(ll i=0; i<sosuu.size(); i++){
    ll p = 0;
    if(sosuu.at(i)==1) {p=1;}
    else{
      p = check_p(sosuu.at(i));
    }
    ans+=p;
  }
  
  //rep(i,sosuu_kazu.size()) cout << sosuu.at(i) << " " << sosuu_kazu.at(i) << endl;

  cout << ans;
}

ll check_p(ll x){
  for(ll i=1; i<x; i++){
    if(i*(i+1)<=x*2 && (i+1)*(i+2)>x*2) return i;
  }
  return 0;
}


Measured memory_bytes: 3724
import sys
def input(): return sys.stdin.readline().rstrip()
def f(n,x):#レベルnのx番目
    if n==0:return 0 if x<=0 else 1
    if x<=1+A[n-1]:return f(n-1,x-1)
    return 1+P[n-1]+f(n-1,x-A[n-1]-2)
def main():
    n,x=map(int,input().split())
    global A,P
    A=[1, 5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131069, 262141, 524285, 1048573, 2097149, 4194301, 8388605, 16777213, 33554429, 67108861, 134217725, 268435453, 536870909, 1073741821, 2147483645, 4294967293, 8589934589, 17179869181, 34359738365, 68719476733, 137438953469, 274877906941, 549755813885, 1099511627773, 2199023255549, 4398046511101, 8796093022205, 17592186044413, 35184372088829, 70368744177661, 140737488355325, 281474976710653, 562949953421309, 1125899906842621, 2251799813685245, 4503599627370493]
    P=[1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295, 8589934591, 17179869183, 34359738367, 68719476735, 137438953471, 274877906943, 549755813887, 1099511627775, 2199023255551, 4398046511103, 8796093022207, 17592186044415, 35184372088831, 70368744177663, 140737488355327, 281474976710655, 562949953421311, 1125899906842623, 2251799813685247]
    print(f(n,x))

if __name__=='__main__':
    main()

Measured memory_bytes: 3064
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

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


int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, c;
  cin >> n >> m >> c;
  int res = 0;
  vector<int> b(m);
  rep(i, m)cin >> b[i];
  rep(i, n){
    int tmp = 0;
    rep(j, m){
      int x;
      cin >> x;
      tmp += x * b[j];
    }
    if(tmp + c > 0)res++;
  }
  cout << res << endl;
	return 0;
}


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

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n;
    cin >> n;
    vector<bool> v(n, 0);
    for (i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        v[i] = (a == b);
    }
    for (i = 0; i < n - 2; i++) {
        if (v[i] && v[i + 1] && v[i + 2]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

int main(){
    int n; cin>>n;
    vector<int> d(n);
    for(int i=0; i<n; i++)cin>>d[i];
    long long sum=0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            sum += d[i]*d[j];
        }
    }

    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 256
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Thu Jan 10 09:47:06 2019
//
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	m := map[int]int{}
	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		if a%4 == 0 {
			m[4]++
		} else if a%2 == 0 {
			m[2]++
		}
	}

	if m[4] >= N/2 || m[4] >= (N-(m[2]/2)*2)/2 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, P[8], Q[8];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> P[i];
	rep(i, 0, N) cin >> Q[i];
	
	vector<int> v;
	rep(i, 0, N) v.push_back(i + 1);
	int idx = 0, a = -1, b = -1;
	do {
		bool ok = true;
		rep(i, 0, N) if (v[i] != P[i]) ok = false;
		if (ok) a = idx;

		ok = true;
		rep(i, 0, N) if (v[i] != Q[i]) ok = false;
		if (ok) b = idx;

		idx++;
	} while (next_permutation(all(v)));

	int ans = abs(a - b);
	cout << ans << endl;
}







Measured memory_bytes: 256
# encoding: utf-8


class Solution:
    @staticmethod
    def linear_search():
        array_length_1 = int(input())
        array_1 = [int(x) for x in input().split()]
        array_length_2 = int(input())
        array_2 = [int(x) for x in input().split()]

        print(len(list(set(array_1).intersection(set(array_2)))))


if __name__ == '__main__':
    solution = Solution()
    solution.linear_search()

Measured memory_bytes: 8624
n,k = map(int,input().split())

arr = [0 for i in range(n+1)]
arr[0] = 1

for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for ele in a:
        arr[ele] = 1

ans = arr.count(0)
print(ans)


Measured memory_bytes: 9052
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
ll INF = 1000000000000000001; //10^18+1
ll MOD = 1000000007; //10^9+7
//cout << fixed << setprecision(15); (小数点以下表示)


ll Fact(ll n,ll m){
  ll ans=1;
  for(ll i=2;i<=n;i++){
    ans=(ans*i)%m;
  }
  return ans%m;
}

ll Rpow(ll n,ll p,ll m){
  if(p==0)return 1;
  if(p%2==0){
    ll t=Rpow(n,p/2,m);
    return t*t%m;
  }
  return n*Rpow(n,p-1,m)%m;
}

ll Comb(ll n,ll r,ll m){
  ll a=1;
  for(int i=n-r+1;i<=n;i++){
    a*=i;
    a%=m;
  }
  return (a*Rpow(Fact(r,m),m-2,m))%m;
}


int main () {
  ll n,a,b;
  cin >> n >> a >> b;
  cout << (Rpow(2,n,MOD)-Comb(n,a,MOD)-Comb(n,b,MOD)-1+10*MOD)%MOD << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<ll,int> ii;
#define fi first
#define se second
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
ll A,B,C;
int n,h,w;
ll dp0[505][505], dp1[505][505][4];
bool player[505][505];
int min_distance[505][505];
void prep(){
	queue <int> q;
	for(int i=0;i<=h;i++)
		for(int j=0;j<=w;j++){
			if (player[i][j]) min_distance[i][j] = 0, q.push(i * 501 + j);
			else min_distance[i][j] = 100000;
		}
	while(q.size()){
		int x = q.front() / 501;
		int y = q.front() % 501;
		q.pop();
		for(int k=0;k<4;k++){
			int X = x + dx[k];
			int Y = y + dy[k];
			if (0 > X || X > h || 0 > Y || Y > w) continue;
			if (min_distance[X][Y] > min_distance[x][y] + 1)
				min_distance[X][Y] = min_distance[x][y] + 1,
				q.push(X * 501 + Y);
		}
	}
}
#define x1 asd
#define y1 jnda
#define xn addaf
#define yn nln
int x1,y1,xn,yn;
void prep_dp(){
	for(int i=0;i<=h;i++)
		for(int j=0;j<=w;j++)
			dp0[i][j] = dp1[i][j][0] = dp1[i][j][1] = dp1[i][j][2] = dp1[i][j][3] = (ll) 1e18;
	dp0[x1][y1] = 0;
}
bool  markh[505], markw[505];
 
void cal_dp(){
	priority_queue <ii,vector<ii>,greater<ii> > pq;
	
	pq.push(ii(0, x1 * 3500 + y1 * 5));
		
	while(pq.size()){
		int x = pq.top().se / 3500;
		int y = (pq.top().se % 3500) / 5;
		int type = pq.top().se % 5;
		ll dis = pq.top().fi;
		pq.pop();
		
		if (type == 0 && dp0[x][y] != dis) continue;
		if (type && dp1[x][y][type-1] != dis) continue;
		
		if (type == 0){
			for(int k=0;k<4;k++){
				int X = x + dx[k];
				int Y = y + dy[k];
				if (0 > X || X > h || 0 > Y || Y > w) continue;
				if (dp1[X][Y][k] > dp0[x][y] + A + B)
					dp1[X][Y][k] = dp0[x][y] + A + B,
					pq.push(ii(dp1[X][Y][k], X * 3500 + Y * 5 + k+1));
					
				if (dp0[X][Y] > dp0[x][y] + C)
					dp0[X][Y] = dp0[x][y] + C,
					pq.push(ii(dp0[X][Y], X * 3500 + Y * 5 + 0));
			}
		}
		else{
			int X = x + dx[type-1];
			int Y = y + dy[type-1];
			if (dp1[x][y][type-1] + min_distance[x][y] * C < dp0[x][y])
				dp0[x][y] = dp1[x][y][type-1] + min_distance[x][y] * C,
				pq.push(ii(dp0[x][y], x*3500 + y*5));
			if (0 > X || X > h || 0 > Y || Y > w) continue;
			if (dp1[X][Y][type-1] > dp1[x][y][type-1] + A)
				dp1[X][Y][type-1] = dp1[x][y][type-1] + A,
				pq.push(ii(dp1[X][Y][type-1], X * 3500 + Y * 5 + type));
			
		}
	}
}
int main(){
	iostream::sync_with_stdio(0);
	cin >> h >> w;
	cin >> A >> B >> C;
	cin >> n;
	for(int i=1;i<=n;i++){
		int x,y;
		cin >> x >> y; 
		if (i == 1) x1 = x, y1 = y;
		if (i == n) xn = x, yn = y;
		player[x][y] = 1;
	}
	prep();
	prep_dp();
	cal_dp();
	cout << dp0[xn][yn] << endl;
}

Measured memory_bytes: 18216
#include <stdio.h>
#include <string.h>

int main(void) {
	int A,B,C;
	scanf("%d%d%d",&A,&B,&C);
	for(int i=1;i<B;i++){
		if(A*i%B==C){
			printf("YES");
			return 0;
		}
	}
	printf("NO");
	// your code goes here
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  string S;
  cin >> N >> S;
  int cnt = 0;
  rep(i, N-2) {
    if(S.substr(i, 3) == "ABC") cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007
#define INF 1e9

int main(){
  int n,ma,mb;
  cin >> n >> ma >> mb;
  vector<vvi> dp(n+1,vvi(401,vi(401,INF)));
  dp.at(0).at(0).at(0) = 0;
  rep(k,n){
    int a,b,c;
    cin >> a >> b >> c;
    rep(i,401){
      rep(j,401){
        if(i-a >= 0 && j-b >= 0){
          dp.at(k+1).at(i).at(j) = min(dp.at(k).at(i).at(j),dp.at(k).at(i-a).at(j-b) + c);
        }else{
          dp.at(k+1).at(i).at(j) = dp.at(k).at(i).at(j);
        }
      }
    }
  }
  int id = 1;
  int ans = INF;
  while(ma*id < 401 && mb*id < 401){
    //cout << ans << endl;
    ans = min(ans,dp.at(n).at(ma*id).at(mb*id));
    id++;
  }
  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 28032
#include<stdio.h>

int main(void){
  int h_1,m_1,s_1,h_2,m_2,s_2;
  int h,m,s,c;
  while((scanf("%d %d %d %d %d %d",&h_1,&m_1,&s_1,&h_2,&m_2,&s_2))!=EOF){
    s=s_2-s_1; if(s<0){ s+=60; c=1; }
    m=m_2-m_1-c; c=0; if(m<0){ m+=60; c=1; }
    h=h_2-h_1-c; c=0;
    printf("%d %d %d\n",h,m,s);
  }

  return 0;
}




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

int main(){
    int x,y;
    
    while(cin >> x >> y){
        int tmp;
        
        if(x < y){
            tmp = x;
            x = y;
            y = tmp;
        }
        
        while(y){
            x %= y; tmp = x;
            x = y; y = tmp;
        }
        cout << x << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int N, L[8], A, B, C; // 1000 >= a > b > c >=1
int INF = 1000000000; // 2^29 ~= 5*10^8
//int ret0, reta, retb, retc;
int cur = 0;

int dfs(int i, int a, int b, int c){
  //cur++;
  if(i==N){
    if(!a || !b || !c){ // 最初の1本に対してはMPは使わない。
      return INF;
    }else{
      return abs(A-a) + abs(B-b) + abs(C-c) - 30;
    }
  }
  int ret0 = dfs(i+1, a,      b,      c);
  int reta = dfs(i+1, a+L[i], b,      c)      +10;
  int retb = dfs(i+1, a,      b+L[i], c)      +10;
  int retc = dfs(i+1, a,      b,      c+L[i]) +10;
//  cout << cur << "\t" << n << "\t" << a << "\t" << b << "\t" << c << "\t" << min({ret0, reta, retb, retc}) << endl;
  return min({ret0, reta, retb, retc});

}

int main(void){
  int i;
  cin >> N;
  cin >> A >> B >> C;
  for(i=0; i<N; i++)  cin >> L[i];

  cout << dfs(0, 0, 0, 0) << endl;

  return 0;
}


Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

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

vector<int> edge[100001];
int par[100001];
vector<int> child[100001];
ll m;
ll dp[100001], dp2[100001];

void dfs(int i){
  dp[i] = 1;
  rep(j, edge[i].size()){
    if(par[edge[i][j]] >= 0)continue;
    par[edge[i][j]] = i;
    child[i].pb(edge[i][j]);
    dfs(edge[i][j]);
    dp[i] = (dp[i] * ((dp[edge[i][j]] + 1) % m)) % m;
  }
}

void dfs2(int i, ll p){
  dp2[i] = dp[i] * (p + 1) % m;
  vector<ll> fr(child[i].size()), ba(child[i].size());
  ll ptmp = p + 1;
  rep(j, child[i].size()){
    if(j == 0)fr[j] = (dp[child[i][j]] + 1) % m;
    else fr[j] = fr[j-1] * ((dp[child[i][j]] + 1) % m) % m;
  }
  for(int j = sz(child[i]) - 1; j >= 0; j--){
    if(j + 1 == sz(child[i]))ba[j] = (dp[child[i][j]] + 1 ) % m;
    else ba[j] = ba[j+1] * ((dp[child[i][j]] + 1) % m) % m;
  }
  rep(j, sz(child[i])){
    ll tmp = ptmp;
    if(j + 1 < sz(child[i]))tmp = tmp * ba[j+1] % m;
    if(j-1 >= 0)tmp = tmp * fr[j-1] % m;
    dfs2(child[i][j], tmp);
  }
}

int main(int argc, char const* argv[])
{
  int n;
  cin >> n >> m;
  rep(i, n - 1){
    int x, y;
    cin >> x >> y;
    x--; y--;
    edge[x].pb(y);
    edge[y].pb(x);
  }
  fill(par, par + n, -1);
  par[0] = 0;
  dfs(0);
  dfs2(0, 0);
  rep(i, n)cout << dp2[i] << endl;
	return 0;
}


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

long N, ans;
map<long, long> X, Y;

int main(void) {

    cin >> N;
    for (long i = 0; i < N; i++) {
        long a; cin >> a;
        X[i+a]++;
        Y[i-a]++;
    }

    for (auto x: X) {
        ans += x.second * Y[x.first];
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 37872
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
 
int main()
{
	string S;
	cin >> S;
	int min = 1000;
 
	for (int i = 0; i < S.size()-2; i++) {
		int x = stoi(S.substr(i,3));
 
		if (min > abs(x-753)) {
			min = abs(x - 753);
		}
	}
 
	cout << min << endl;
}

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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount

struct UF {
	vector<int> v;
	UF(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

vector<int> check[100010], L[100010];

int main() {
    int N, M; cin>>N>>M;
    vector<int>K(N);
    for(int i = 0; i < N; i++)
    {
        cin>>K[i];
        for(int j = 0; j < K[i]; j++)
        {
            int t; cin>>t;
            t--;
            L[i].push_back(t);
        }
    }

    for(int i = 0; i < N; i++)for(int k : L[i])check[k].push_back(i);

    struct UF uf(N);
    for(int i=0;i<M;i++){
        if(check[i].empty())continue;
        int x =check[i].back();
        for(int y : check[i])if(x!=y)uf.unite(x, y);
    }
    
    for(int i=1;i<N;i++){
        if(!uf.same(0, i)){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;

    return 0;
}

Measured memory_bytes: 9384
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

//=============modpow============================
ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//=================================================

int main()
{
  ll mod = 1000000007;
  ll N, K;
  cin >> N >> K;
  vector<ll> A(100001, 0);
  ll ans = 0;
  for (ll i = 100000; i > 0; --i)
  {
    ll temp = 1;
    ll cnt = modpow(K / i, N, mod);
    // cout << temp * i << endl;
    while (temp * i <= K)
    {
      if (A.at(temp * i) == 0)
      {
        temp += 1;
        continue;
      }
      cnt -= A.at(temp * i);
      if (cnt < 0)
      {
        cnt += mod;
      }
      temp += 1;
    }
    ans = (ans +(cnt * i) % mod) % mod;
    A.at(i) = cnt;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3980
#include <iostream>
#include <string>
#include <cstdio>
#include <string.h>
using namespace std;

const int mod = 10007;
int memo[1001][2][2][2];
int N;
string s;

int func(int n, bool a, bool b, bool c){
	if(memo[n][a][b][c] != -1)
		return memo[n][a][b][c];
		
	if((s[n] == 'J' && !a) || (s[n] == 'O' && !b) || (s[n] == 'I' && !c))
		return 0;
	if(n == 0 && a)
		return a==1;
	else if(n == 0)
		return 0;
		
	int res = 0;
	for(int i = 0; i < 2; ++i)
		for(int j = 0; j < 2; ++j)
			for(int k = 0; k < 2; ++k)
				if((i && a) || (j && b) || (k && c))
					res += func(n - 1, i, j, k) % mod;

	return memo[n][a][b][c] = res % mod;
}

int main() {
	memset(memo, -1, sizeof(memo));
	cin >> N;
	cin >> s;
	cout << func(N, 1, 1, 1) << endl;
	
	return 0;
}

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

int main(){
  int r,D;
  cin >> r >> D;
  vector<int> x(11);
  cin >> x.at(0);
  for(auto iter=x.begin();iter!=x.end()-1;){
    int temp = *iter * r - D;
    iter++;
    *iter = temp;
    cout << *iter << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n1,n2,x;
	while(1){
	x=0;
		scanf("%d %d",&n1,&n2);
		if(n1==0 && n2==0){
		break;
		}
	if(n1==1 || n1==3 || n1==5 || n1==7 || n1==8 || n1==10 || n1==12){
	x=x+(31*(n1-1))+n2;
		if(n1==3 || n1==5 || n1==7 ){
		x=x-((n1-1)*0.5+1);
		}
		if(n1==8 || n1==10 || n1==12){
			x=x-(n1*0.5);
		}
	}
	if(n1==4 || n1==6 || n1==9 || n1==11){
	x=x+(30*(n1-1))+n2+((n1-1)*0.5);
	}
	if(n1==2){
	x=x+(31*(n1-1))+n2;
	}
	if(x%7==1){
		printf("Thursday\n");
	}
	if(x%7==2){
		printf("Friday\n");
	}
	if(x%7==3){
		printf("Saturday\n");
	}
	if(x%7==4){
		printf("Sunday\n");
	}
	if(x%7==5){
		printf("Monday\n");
	}
	if(x%7==6){
		printf("Tuesday\n");
	}
	if(x%7==0){
		printf("Wednesday\n");
	}
	}
	return 0;
}

Measured memory_bytes: 584
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int N = Integer.parseInt(stdin.next());
		String s[] = new String[N];
		long cnt = 0;
		
		
		for(int i=0;i<N;i++) {
			s[i] = stdin.next();
		}
		for(int h=0;h<N;h++) {
			char[] copy = s[h].toCharArray();
			Arrays.sort(copy);
			s[h] = new String(copy);
		}
		Arrays.sort(s);

		for(int i=0;i<N-1;i++) {
			int j=i+1;
			long sin=1;
			while(s[i].equals(s[j])) {
					if(j!=N-1) {
						j+=1;
						sin+=1;
					}
					else {
						sin+=1;
						break;
					}
			}
			cnt+=(sin*(sin-1))/2;
			i=j-1;
		}

		out.println(cnt);

		out.flush();
	}

	
}

Measured memory_bytes: 50920
object Main extends App {
  val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  val k = (1 to m).map { _ =>
    scala.io.StdIn.readLine.split(" ").map(_.toInt).drop(1)
  }
  val p = scala.io.StdIn.readLine.split(" ").map(_.toInt)

  var ans = 0
  (0 to n).foreach { i =>
    val l = Array.fill(i)(true) ++ Array.fill(n - i)(false)
    //l.permutations.foreach(a => println(a.mkString(",")))

    l.permutations.foreach { flaglist =>
     // println(flaglist.mkString(","))
      val xx = (0 until m).forall { j =>
        // println(j)
        //println(k(j).deep)
        val cnt = k(j).count { cnts =>
          // println(s"Cnt:${cnts}")
          //println()
          //println(s"l:${flaglist(cnts - 1)}")
          flaglist(cnts - 1)
        }

        //  println(cnt)
        //println(cnt % 2)
        //        println(p(j))
        cnt % 2 == p(j)
      }
      //    println(xx)
      if (xx) {
        ans += 1
      }
    }
  }
  println(ans)
}

/*
false,false,true,false,false
true
*/

Measured memory_bytes: 28408
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

int main() {
  int r, D, x;
  cin >> r >> D >> x;
  for (int i = 0; i < 10; i++) {
    x = r * x - D;
    cout << x << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        400005
#define mod         1000000007
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	k--;
	char ch=s[k];
	ch=ch+32;
	s[k]=ch;
	cout<<s;
}


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

int main() {
    int N, A, B;
    int ans = 0;
    cin >> N >> A >> B;
    for (int i = 1; i <= N; i++) {
        int sum = 0;
        int tmp = i;
        while (tmp > 0) {
            sum += tmp % 10;
            tmp /= 10;
        }
        if (A <= sum && sum <= B) ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int MAXN = 2e2+5,MAXM = 2e6+5,MOD = 1e9+7,INF = 0x3f3f3f3f,N=2e5;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const db eps = 1e-9;
#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define mid l + ((r-l)>>1)
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define pii pair<int,int>
#define vii vector<pii>
#define vi vector<int>
using namespace std;
int n,col[MAXN],dis[MAXN][MAXN];
char mp[MAXN][MAXN];
vi G[MAXN];
int vis[MAXN],ok=true,mx=0;
void dfs(int u,int f){
    col[u] = col[f]^1;
    vis[u]=1;
    if(!ok)return ;
    for(int v:G[u]){
        if(v==f)continue;
        if(vis[v] && col[v] == col[u]){
            ok=false;
            return ;
        }
        if(vis[v])continue;
        dfs(v,u);
    }
}
int main(){
    ios::sync_with_stdio(false);
    //freopen("../A.in","r",stdin);
    //freopen("../A.out","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>(mp[i]+1);
    memset(dis,-1,sizeof(dis));
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(mp[i][j]=='1'){
                G[i].push_back(j);
                G[j].push_back(i);
                dis[i][j] = dis[j][i] = 1;
            }
        }
    }
    for(int i=1;i<=n;i++)dis[i][i]=0;
    dfs(1,0);
    if(!ok){
        cout<<"-1\n";
        return 0;
    }
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(dis[i][k]!=-1 && dis[k][j]!=-1){
                    if(dis[i][j]==-1) dis[i][j] = dis[i][k] + dis[k][j];
                    else dis[i][j] = min(dis[i][j],dis[i][k] + dis[k][j]);
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(dis[i][j]!=-1)mx=max(mx,dis[i][j]);
        }
    }
    cout<<mx + 1<<'\n';
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>  
using namespace std;
typedef long long ll;
const int M=998244353;
int n,k,i;
char c[10005],ans[10005],mn=127;
struct str{
	char c[5005];
}p[5005];
bool cmp(str a,str b)
{
	return strcmp(a.c+1,b.c+1)<0;
}
void dfs(char c[],int k)
{
	int i,j,mx=0,s[10005];
	memset(s,0,sizeof(s));
	for(i=1;i<=n;i++)
		if(c[i]!=mn)
			break;
	if(i>n)
	{
		for(i=1;i<=n;i++)
			printf("%c",mn);
		exit(0);
	}
	for(i=n+1;i<=2*n;i++)
		c[i]=c[2*n-i+1];
	if(k==1)
	{
		for(i=1;i<=2*n;)
		{
			if(c[i]!=mn)
			{
				i++;
				continue;
			}
			for(j=i;j<=2*n&&c[i]==c[j];j++);
			s[i]=j-i;
			i=j;
		}
		for(i=1;i<=n+1;i++)
			mx=max(mx,s[i]);
		int u=0;
		for(i=1;i<=n+1;i++)
			if(mx==s[i])
			{
				u++;
				for(j=i;j<i+n;j++)
					p[u].c[j-i+1]=c[j];
			}
		sort(p+1,p+1+u,cmp);
		if(ans[1]==0||strcmp(ans+1,p[1].c+1)>0)
			for(i=1;i<=n;i++)
				ans[i]=p[1].c[i];
		return;
	}
	char m[10005];
	for(i=n*2;i>=1;)
	{
		if(c[i]!=mn)
		{
			i--;
			continue;
		}
		for(j=i;j>=1&&c[i]==c[j];j--);
		s[i]=i-j;
		i=j;
	}
	for(i=1;i<=2*n;i++)
		mx=max(mx,s[i]);
	for(i=n;i<=2*n;i++)
		if(mx==s[i])
		{
			for(j=i-n+1;j<=i;j++)
				m[j-(i-n)]=c[j];
			dfs(m,k-1);
		}
}
int main()
{
	scanf("%d %d",&n,&k);
	scanf("%s",c+1);
	for(i=1;i<=n;i++)
		mn=min(mn,c[i]);
	dfs(c,k);
	printf("%s",ans+1);
}


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

using namespace std;

int main(){
  string str1;
  string str2;
  cin >> str1 >> str2;
  for(int i=0;i<str1.size();++i){
    cout << str1[i];
    if(i<str2.size())cout<<str2[i];
  }
  cout << endl;
}


Measured memory_bytes: 3600
#include<stdio.h>

int main(){
   int X,Y;
   scanf("%d %d",&X,&Y);
   if(Y<2*X||X*4<Y){
      printf("No");
   }else if(Y%2==1){
      printf("No");
   }else{
      printf("Yes");
   }
   return 0;
}


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

vector<long> div(long n) {
  vector<long> v;
  for (long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
      if (i * i != n) v.push_back(n / i);
    }
  }
  sort(begin(v), end(v));
  return v;
}

int main() {
  int N;
  cin >> N;
  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 2 && div(i).size() == 8) cnt++;
  }
  cout << cnt << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define bash push_back
#define all(x) x.begin(),x.end()
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,-1,1,-1,1};
const int INF=1 << 30;
bool inside(int x,int y,int w,int h){
  return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vit;
typedef map<string,int> mstit;
typedef priority_queue<int> pqit;
 

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n,m,x,y;
  int X[500],Y[500];
  bool ism=true;
  cin >>n>>m>>x>>y;
  if(x>=y) ism=false;
  FOR(i,n) cin >>X[i];
  FOR(i,m) cin >>Y[i];
  sort(X,X+n,greater<int>());
  sort(Y,Y+m);
  if(X[0]>=Y[0]) ism=false;
  if(X[0]>=y||x>=Y[0]) ism=false;
  if(ism) cout <<"No ";
  cout <<"War\n";

  return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

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


def main():
    h,w,k = LI()
    a = []
    st = None
    for i in range(h):
        s = S()
        if 'S' in s:
            st = [i, s.index('S')]
        a.append([c=='#' for c in s])

    def ns(k):
        i,j = k
        r = []
        if i < h-1:
            r.append((i+1,j))
        if j < w-1:
            r.append((i,j+1))
        if i > 0:
            r.append((i-1,j))
        if j > 0:
            r.append((i,j-1))
        return r


    def search(ss,tk):
        d = collections.defaultdict(lambda: inf)
        q = []
        for s in ss:
            d[s] = 0
            heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if k >= tk:
                break
            if v[u]:
                continue
            v[u] = True

            for nu in ns(u):
                if v[nu] or a[nu[0]][nu[1]]:
                    continue
                vd = k + 1
                if d[nu] > vd:
                    d[nu] = vd
                    if nu[0] == 0 or nu[1] == 0 or nu[0] == h-1 or nu[1] == w-1:
                        return d
                    heapq.heappush(q, (vd, nu))

        return d

    d = search([tuple(st)],k)
    r = inf
    hs = []
    ws = []
    for g in d.keys():
        if 0 < g[0] < h-1 and 0 < g[1] < w-1:
            hs.append(g[0])
            ws.append(g[1])
            continue
        return 1

    return (min(min(hs),min(ws),h-max(hs)-1,w-max(ws)-1) + k - 1) // k + 1

print(main())


Measured memory_bytes: 103384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> arr(n);
  for(int i = 0; i < n; i++){
  	cin >> arr[i];
  }
  vector<int> dp(n+2);
  dp[0] = 0;
  dp[1] = abs(arr[1]-arr[0]);
  for(int i = 2; i < n; i++){
    int op1 = abs(arr[i] - arr[i-1]) + dp[i-1];
    int op2 = abs(arr[i] - arr[i-2]) + dp[i-2];
    dp[i] = min(op1,op2);
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 4044
#include<cstdio>
using namespace std;
int d2b(int n,int b,char c[])
{
    int i=0,k;                                                                                                                                                   
    while(n!=0)
    {
        k=n%b;
        n/=b;
        if(k<0){k-=b;n+=1;}
        if(k>9)c[i]=char(k-10+'A');
        else c[i]=char(k+'0');
        i++;
    }
    return i-1;
}
int main()
{
    int a,n,i;
    char b[40];
    scanf("%d",&a);n=-2;
    if(a==0)printf("0");
    for(i=d2b(a,n,b);i>=0;i--)printf("%c",b[i]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    char a, b;
    cin >> a >> b;
    char ans = 'H';
    if (a!=b) ans = 'D';
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3564
namespace ConsoleApplication2
{

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var n = input[0];
            var k = input[1];
            var man = new bool[n];
            for (int i = 0; i < k; i++)
            {
                var d = Console.ReadLine();
                var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
                for (int j = 0; j < a.Count(); j++)
                {
                    man[a[j] - 1] = true;
                }
            }
            var ans = man.Count(x => x == false);
            Console.WriteLine(ans.ToString());
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 28556
num = list(map(int, input().split()))
if num[0]==2  or num[1] ==2:
	print('No')
elif num[0] == 4:
	if num[1] == 6 or num[1] == 9 or num[1] == 11:
		print('Yes')
	else:
		print('No')
elif num[0] == 6:
	if num[1] == 9 or num[1] == 11:
		print('Yes')
	else:
		print('No')
elif num[0] == 9:
	if num[1] == 11:
		print('Yes')
	else:
		print('No')
elif num[0] == 11:
	print('No')
else:
	print('Yes')


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

using ll=long long;

int main() {
    ll A,B,x,y,t,i;
    cin >> A >> B;

    y = A * B;
    if(A < B) {
        t = A;
        A = B;
        B = t;
    }

    x = A % B;
    while(x != 0) {
        A = B;
        B = x;
        x = A % B;
    }

    cout << y/B << endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Sandglass2
            var line = ReadLine();
            int x = line[0];
            int t = line[1];

            if (x <= t)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(x - t);
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto &i: a)
        cin>>i;
    ll ans=1000;
    for(int i=1;i<n;i++)
        if(a[i]>a[i-1])
            ans=(ans/a[i-1]*a[i]+ans%a[i-1]);
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
class Main{
  public static void main(String args[]){
    int x,n;
    boolean flg[]=new boolean[102];
    x=readI();n=readI();
    for(int i=0;i<n;i++){
      int k=readI();
      flg[k]=true;
    }
    for(int i=0;;i++){
      if(!flg[x-i]){
        pl((x-i)+"");
        break;
      }
      if(!flg[x+i]){
        pl((x+i)+"");
        break;
      }
    }
  }

  static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
  public static String read(){
    try{
      return ctos((char)br.read());
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static char readC(){
    try{
      return (char)br.read();
    }catch(IOException e){
      e.printStackTrace();
      return (char)-1;
    }
  }
  public static String readL(){
    try{
      return br.readLine();
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static String readS(){
    StringBuilder sb = new StringBuilder();
    while(true){
      try{
        int k = br.read();
        if(k==-1||(char)k==' '||(char)k=='\n'){break;}
        sb.append((char)k);
      }catch(IOException e){
        e.printStackTrace();
      }
    }
    return sb.toString();
  }
  public static int readI(){
    return stoi(readS());
  }
  public static long readLong(){
    return stol(readS());
  }
  public static long stol(String s){
    return Long.parseLong(s);
  }
  public static String[] readSs(){
    return readL().split(" ");
  }
  public static int[] readIs(){
    return stoi(readSs());
  }
  public static int stoi(String s){
    return Integer.parseInt(s);
  }
  public static int[] stoi(String s[]){
    int a[]=new int[s.length];
    for(int i=0;i<s.length;i++){
      a[i]=stoi(s[i]);
    }
    return a;
  }
  public static String itos(int i){
    return String.valueOf(i);
  }
  public static String[] itos(int[] a){
    String s[]=new String[a.length];
    for(int i=0;i<a.length;i++){
      s[i]=itos(a[i]);
    }
    return s;
  }
  public static String ctos(char c){
    return String.valueOf(c);
  }
  public static String cstos(char[] c){
    return new String(c);
  }
  public static char stoc(String s){
    return s.charAt(0);
  }
  public static char[] stocs(String s){
    return s.toCharArray();
  }
}


Measured memory_bytes: 36496
from sys import stdin

def main():

    n = int(stdin.readline().strip())
    a = list(map(int, stdin.readline().strip().split()))

    if n == 1:
        print(1)
        exit()

    a.sort()

    dp = [True] * (a[-1] + 1)
    ans = 0

    for i in range(n):

        if a[i] == a[i-1]:
            continue

        if dp[a[i]]:

            for j in range(2 * a[i], a[-1] + 1, a[i]):
                dp[j] = False

            if i == n-1 or a[i] != a[i+1]:
                ans += 1

    print(ans)

main()

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

using namespace std;

int main(){

    int N;
    scanf("%d", &N);

    int c[N];
    for(int i=1; i <= N; i++){
        c[i-1] = i;
    }

    int a[N];
    int b[N];

    for(int i=0; i < N; i++){
        scanf("%d", &a[i]);
    }
    for(int i=0; i < N; i++){
        scanf("%d", &b[i]);
    }

    int aN;
    int bN;

    int count = 0;

    do{
        count++;
        bool isA = true;
        bool isB = true;
        for(int i=0; i < N; i++){
            if(a[i] != c[i]){
                isA = false;
            }
            if(b[i] != c[i]){
                isB = false;
            }

            if(!isA && !isB){ continue; }

        }

        if(isA) aN = count;
        if(isB) bN = count;

    }while(next_permutation(c, c + N));

    printf("%d\n", abs(aN - bN));




}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
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();
		
		Integer[] arr = new Integer[n];
		int sum = 0;
		for (int i=0; i<n; i++) {
			arr[i] = sc.nextInt();
			sum += arr[i];
		}
		
		Arrays.sort(arr, Collections.reverseOrder());
		double limit = (double) sum/(4*m);

		if (arr[m-1] >= limit) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}


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

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		cin >> A[i];
	}

	rep(i,N)
	{
		if (A[i] % 2 == 0)
		{
			if (A[i] % 3 != 0 && A[i] % 5 != 0)
			{
				cout << "DENIED";
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(b >= c){
		cout << "delicious" << endl;
	}
	else{
		if(a+b >= c){
			cout << "safe" << endl;
		}
		else{
			cout << "dangerous" << endl;
		}
	}
}


Measured memory_bytes: 256
s=list(input())
n=len(s)
T="ACGT"
cnt=[0]*20
total=[0]*20
for i in range(n):
    if s[i] in T:
        cnt[i]=1
for i in range(1,n+1):
    if cnt[i-1]==1:
        total[i]=total[i-1]+1
    else:
        total[i]=0
print(max(total))


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

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

  if((h * w) % 2 == 1 && (x + y) % 2 == 1){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

  return 0;
}


Measured memory_bytes: 3104
while True:
    n = int(input())
    str_list = [int(input()) for _ in range(n)]
    if n==0:
        break
    a = max(str_list)
    b = min(str_list)
    c = sum(str_list)
    tensu = (c-a-b)//(n-2)
    print(tensu)




Measured memory_bytes: 5608
#include <iostream>
#include <string>
using namespace std;
int main(){
  string a,b,c;
  cin >> a>>b >>c;
  int as=a.size();int bs=b.size();int cs=c.size();
  if(a[as-1]==b[0]){
    if(b[bs-1]==c[0]){
      cout << "YES"<<endl;
      return 0;
    }
  }
  cout <<"NO"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
   	int ans= 0, a,b,c;
	scanf("%d %d %d",&a, &b, &c);
    for (int i = a ; i <=b; i++) {
        if(c%i == 0){
            ans++;
        }
    }    
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 2104
# solution

import io
import sys
import math

array = list(map(len, input().split('T')))
nim, mike = map(int, input().split())

tom = [set([array[0]]), set([0])]

for i in range(1, len(array)):
    nxt = set()
    for j in tom[i % 2]:
        nxt.add(j + array[i])
        nxt.add(j - array[i])
    tom[i % 2] = nxt

if nim in tom[0] and mike in tom[1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3816