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

using namespace std;

int main(){
    int N, W;
    cin >> N >> W;
    long long w[N], v[N];
    for(int i = 0; i < N; i++){
        cin >> w[i] >> v[i];
    }

    long long dp[N+1][W+1] = {}; // dp[i][j] := i番目までの商品から選んで重さの合計がj以下の時の価値の最大値
    
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= W; j++){
            dp[i][j] = dp[i-1][j];
            if(j - w[i-1] >= 0){
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1]);
            }
        }
    }

    cout << dp[N][W] << endl;


    return 0;
}

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

#define Yay(condition) if(condition){cout << "Yay!" << endl;}else{cout << ":(" << endl;}

typedef long long ll;

using namespace std;

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

    int a,b;
      cin >> a >> b;
      Yay(a <= 8 && b <= 8);
     
       
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i) 
#define REP(i,n) FOR(i,0,n)
#define EACH(x,a) for(auto& (x):(a))
#define ALL(obj) (obj).begin(),(obj).end()
#define Yes(n) cout<<((n)?"Yes":"No")<<endl;
#define CO(x) cout<<(x)<<endl;
#define COSP(x) cout<<(x)<<" ";
#define DICIMAL(x) fixed<<setprecision(x)
using namespace std;
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
const int INF=1e9;
const ll LINF=1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int DIV = 1e9 + 7;

bool ok(int j, int k, int l, int m){
  if(k==1 && l==2 && m==3) return false;
  if(k==2 && l==1 && m==3) return false;
  if(k==1 && l==3 && m==2) return false;
  if(j==1 && l==2 && m==3) return false;
  if(j==1 && k==2 && m==3) return false;
  return true;
}

void add(ll &a, ll b){
  a += b;
  if(a>=DIV) a-=DIV;
}

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

  int N; cin>>N;

  ll dp[110][5][5][5];
  dp[0][0][0][0] = 1;

  REP(i,N) REP(j,5) REP(k,5) REP(l,5) FOR(m,1,5){
    if(ok(j,k,l,m)) add(dp[i+1][k][l][m], dp[i][j][k][l]);
  }

  ll ans=0;
  FOR(j,1,5) FOR(k,1,5) FOR(l,1,5) add(ans, dp[N][j][k][l]);

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


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

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

  for (int i = 0; i < (1 << 3); i++) {
    int ans = S[0] - '0';
    vector<string> op(3, "");
    for (int j = 0; j < 3; j++) {
      if (i & (1 << j)) {
        ans += S[j + 1] - '0';
        op[j] = "+";
      } else {
        ans -= S[j + 1] - '0';
        op[j] = "-";
      }
    }
    if (ans == 7) {
      cout << S[0] << op[0] << S[1] << op[1] << S[2] << op[2] << S[3] << "=7" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
N, M = map(int, input().strip().split(" "))

head = [-1 for _ in range(N + 1)]
edge= [-1 for _ in range(M + 1)]
next = [-1 for _ in range(M + 1)]

tot = 0

def add_edge(a, b):
  global tot
  edge[tot] = b
  next[tot] = head[a]
  head[a] = tot
  tot += 1

for _ in range(M):
  a, b = map(int, input().strip().split(" "))
  add_edge(a, b)

def find(start, step):
  if step == 0:
    if start == N:
      return True
    else:
      return False
  p = head[start]
  while p != -1:
    if find(edge[p], step - 1) == True:
      return True
    p = next[p]
  return False

if find(1, 2) == True:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Measured memory_bytes: 20520
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int fn(long long x, long long y, long long z){
  return x*x + y*y + z*z + x*y + y*z + z*x;
}
int main(){
  long long N;
  cin >> N;
  int n = sqrt(N);
  int x, y, z;
  vector<int> ans(10001);
  for(int i =1; i < n; i++){
    for(int j = 1; j < n; j++){
      for(int k = 1; k < n; k++){
        if( fn(i,j,k) <= 10000 ) ans.at(fn(i,j,k)-1)++;
      }
    }
  }
  rep(i,N) cout << ans.at(i) << endl;
}

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

int main() {
  int n,k,a = 0,b = 0;
  cin >> n >> k;
  vector<int> x;
  REP(i,n){
    int xx;
    cin >> xx;
    x.push_back(xx);
  }
  int ans = 1000000000;
  REP(i,n-k+1){
    int r,l;
    r = abs(x.at(i))+abs(x.at(i+k-1)-x.at(i));
    l = abs(x.at(i+k-1))+abs(x.at(i)-x.at(i+k-1));
    ans = min({ans,r,l});
  }
  cout << ans << endl;
}


Measured memory_bytes: 3924
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>

typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (10000010)

int p[MAXN];
vector<ll> pp;
ll n;

int main() {
	for (int i = 0; i < MAXN; i++) {
		p[i] = 1;
	}
	for (int i = 2; i < MAXN; i++) {
		if (p[i]) {
			ll j = 2 * i;
			while (j < MAXN) {
				p[j] = 0;
				j += i;
			}
		}
	}
	
	
	cin >> n;

	for (int i = 2; i < MAXN; i++) {
		if (p[i]) {
			ll cur = i;
			while (cur <= n) {
				pp.push_back(cur);
				cur *= i;
			}
		}
	}
	sort(pp.begin(), pp.end());
	int ret = 0;
	for (int i = 0; i < pp.size(); i++) {
		if ((n % pp[i]) == 0) {
			n /= pp[i];
			ret++;
		}
	}
	int bp = 1;
	for (ll i = 2; i * i <= n; i++) {
		if ((n % i) == 0) {
			bp = 0;
			break;
		}
	}

	if ((n > 1) && (n >= MAXN)) {
		ret += bp;	
	}

	cout << ret;


	return 0;
}


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

int N;
pair<long long, long long> A[1000];

int main(){		
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%lld%lld", &A[i].first, &A[i].second);
		if(i > 0){
			long long mult = max(ceil((long double)A[i - 1].first / A[i].first), ceil((long double)A[i - 1].second / A[i].second));
			A[i].first *= mult, A[i].second *= mult;
		}
	}
	printf("%lld\n", A[N - 1].first + A[N - 1].second);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
  {
  int a,b,c;
  int A[4];
  cin>>a>>b;
  A[a]=1,A[b]=1;
  for(int i=1;i<=3;i++){
    if(A[i]!=1){
      cout<<i<<endl;
      }
    }
  }

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        long n = sc.nextLong();
        long k = sc.nextLong();

        System.out.println(Math.min(n % k, k - n % k));
    }



    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int N, K;
	cin >>N >>K;
	if (K<=(N+1)/2)
		cout <<"YES" <<endl;
	else
		cout <<"NO" <<endl;
	return 0;
}



Measured memory_bytes: 256
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

void solve()
{
	ll n,k;
	cin>>n>>k;
	ll mn=n;
	n=n%k;
	set<ll>st;
	while(st.find(n)==st.end())
	{
		st.insert(n);
		n=abs(k-n);
		mn=min(mn,n);
	}
	cout<<mn<<endl;
	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int A;
    static int B;
    static int C;

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        A = scanner.nextInt();
        B = scanner.nextInt();
        C = scanner.nextInt();

        scanner.close();

        if(A - B <= C) {
            System.out.println(C - (A - B));
        } else {
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
ll spf[10000005],cnt[10000005];
void solve(){
	ll n;
	cin>>n;
	cout<<cnt[n];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    for(ll i=2;i*i<=10000000;i++)
    if(!spf[i]){
		for(ll j=i*i;j<=10000000;j+=i)
		if(!spf[j])
		spf[j]=i;
	}
	for(ll i=2;i<=10000000;i++)
	if(!spf[i])
	spf[i]=i;
	for(ll i=1;i<=10000000;i++){
		ll k=i;
		map<ll,ll> m;
		while(k>1){
			m[spf[k]]++;
			k/=spf[k];
		}
		cnt[i]=1;
		for(auto it=m.begin();it!=m.end();it++)
		cnt[i]*=it->second+1;
		cnt[i]*=i;
		cnt[i]+=cnt[i-1];
	}
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
    solve();		
}


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

int main(){
  int h, w;
  cin >> h >> w;
  
  for (int i = 0; i < w + 2; i++)
    cout << '#';
  
  cout << endl;
  
  for (int i = 0; i < h; i++){
    //vector<int> v_i(w);
    cout << '#';
    for (int j = 0; j < w; j++){
      char x;
      cin >> x;//v_i.at(j);
      cout << x;//v_i.at(j);
    }
    cout << '#' << endl;
  }
  
  for (int i = 0; i < w + 2; i++)
    cout << '#';
}

Measured memory_bytes: 256
def lcs_len(X,Y):
    m,n=len(X),len(Y)
    LCS=[0 for _ in range(m+1)]
    for y in Y:
        previous=LCS[:]
        for i,x in enumerate(X):
            if x==y:
                LCS[i+1]=previous[i]+1
            elif LCS[i]>previous[i+1]:
                LCS[i+1]=LCS[i]
    return LCS[-1]

q=int(input())
for _ in range(q):
    X=list(input())
    Y=list(input())
    print(lcs_len(X,Y))


Measured memory_bytes: 5644
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];
        Tuple<int, int>[] keys = new Tuple<int, int>[m];
        long[] curCost = Enumerable.Repeat(1L << 60, 1 << n).ToArray();
        curCost[0] = 0;
        for (int i = 0; i < m; i++)
        {
            var a = int.Parse(Console.ReadLine().Split().First());
            int val = 0;
            foreach (var c in Console.ReadLine().Split().Select(int.Parse).ToArray())
            {
                val |= 1 << (c - 1);
            }
            for (int j = 0; j < curCost.Length; j++)
            {
                curCost[j | val] = Min(curCost[j | val], curCost[j] + a);
            }
        }
        if (curCost.Last() == (1L << 60))
        {
            Console.WriteLine(-1);
            return;
        }
        Console.WriteLine(curCost.Last());
    }

    static long GCD(long a, long b)
    {
        while (true)
        {
            if (b == 0) return a;
            a %= b;
            if (a == 0) return b;
            b %= a;
        }
    }

    static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0;
            int next = Console.In.Read();
            int sign = 1;
            while (45 > next || next > 57) next = Console.In.Read();
            if (next == 45) { next = Console.In.Read(); sign = -1; }
            while (48 <= next && next <= 57)
            {
                res = res * 10 + next - 48;
                next = Console.In.Read();
            }
            return res * sign;
        }
    }
}


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

using namespace std;

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

  int val[n+1][3];
  int x;

  for(int i=1;i<=n;i++){
    for(int j=0;j<3;j++){
      cin>>x;
      val[i][j]=x;
    }
  }

  int mat[n+1][3];
  memset(mat,0,sizeof mat);
  for(int i=1;i<=n;i++){
    for(int j=0;j<3;j++){
      if(j==0)
        mat[i][j]+=val[i][j]+max(mat[i-1][1],mat[i-1][2]);
      else if(j==1)
        mat[i][j]+=val[i][j]+max(mat[i-1][0],mat[i-1][2]);
      else
        mat[i][j]+=val[i][j]+max(mat[i-1][0],mat[i-1][1]);
    }
  }
  printf("%d\n",max(max(mat[n][0],mat[n][1]),mat[n][2]));

}


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


using namespace std;

typedef long long ll;

const int MAXN = 50 + 3;


ll dp[MAXN][MAXN][MAXN * MAXN], ans;
int n, a, x[MAXN];



int main() {
	cin >> n >> a;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	dp[0][0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++)
			for (int k = x[i - 1]; k < MAXN * MAXN; k++)
				dp[i][j][k] += dp[i - 1][j - 1][k - x[i - 1]];
		for (int j = 0; j < i; j++)
			for (int k = 0; k < MAXN * MAXN; k++)
				dp[i][j][k] += dp[i - 1][j][k];
	}
	
	for (int i = 1; i <= n; i++)
		ans += dp[n][i][i * a];
	cout << ans;
	return 0;
}

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

int main() {
    int n; cin >> n;
    map<string, int> ma;
    string s;
    for(int i = 0; i < n; ++i) {
        cin >> s;
        ++ma[s];
    }
    int m; cin >> m;
    string t;
    for(int i = 0; i < m; ++i) {
        cin >> t;
        --ma[t];
    }
    
    int max_ma = 0;
    for(auto i : ma) {
        max_ma = max(max_ma, i.second);
    }
    
    cout << max_ma << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <limits>
#include <string>
#include <stack>
#include <queue>

#define INT_MAX 2147483647
#define INT_MIN -2147483647

#define NUM 100005
#define INVALID_IDX -1
using namespace std;

struct TreeNode
{
	int p, l, r;
};

TreeNode t[NUM];
int D[NUM];

void print(int idx)
{
	cout << "node " << idx << ": ";
	cout << "parent = " << t[idx].p << ", ";
	cout << "depth = " << D[idx] << ", ";

	if (t[idx].p == INVALID_IDX) cout << "root, ";
	else if (t[idx].l == INVALID_IDX) cout << "leaf, ";
	else cout << "internal node, ";

	cout << "[";
	for (int i = t[idx].l; i != INVALID_IDX; i = t[i].r)
	{
		cout << i;
		if (t[i].r != INVALID_IDX) cout << ", ";
	}
	cout << "]" << endl;
}

void getHeight(int idx, int depth)
{
	D[idx] = depth;
	if (t[idx].r != INVALID_IDX) getHeight(t[idx].r, depth);
	if (t[idx].l != INVALID_IDX) getHeight(t[idx].l, depth + 1);
}

int main()
{
	int i, j, n, idx0, idx1, d, l, r = INVALID_IDX;

	cin >> n;
	for (int i = 0; i < n; ++i) t[i].p = t[i].l = t[i].r = INVALID_IDX;

	for (int i = 0; i < n; ++i)
	{
		cin >> idx0 >> d;
		for (int j = 0; j < d; ++j)
		{
			cin >> idx1;
			if (0 == j) t[idx0].l = idx1;
			else t[l].r = idx1;
			l = idx1;
			t[idx1].p = idx0;
		}
	}

	for (int i = 0; i < n; ++i)
	{
		if (t[i].p == INVALID_IDX){
			r = i;
			break;
		}
	}

	getHeight(r, 0);
	for (int i = 0; i < n; ++i) print(i);

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<ll> a(N),b(N);
    rep(i,N){
        cin >> a[i];
        a[i] -= i+1;
        b[i] = a[i];
    }
    sort(b.begin(),b.end());
    ll med = b[N/2];
    ll res = 0;
    rep(i,N){
        res += abs(a[i] - med);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3328
/* ex3_2
    sak_Citrus*/

#include <stdio.h>

int main(void){
    int num;
    scanf("%d",&num);
    //1桁目だけが欲しいので
    num = num % 10;
    switch(num){
        //3だったらbon
        case 3:
            printf("bon");
            break;
        //0,1,6,8だったらpon
        case 0:
        case 1:
        case 6:
        case 8:
            printf("pon");
            break;
        //2,4,5,7,9はhon
        default:
            printf("hon");
            break;
    }
    //改行
    printf("\n");
    return 0;
}

Measured memory_bytes: 1680
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
 
using namespace std;
 
struct edge
{
    int v,w,nxt;
}e[400050];
 
int head[100050],ecnt;
 
void adde(int u,int v,int w)
{
    e[++ecnt].v = v;
    e[ecnt].w = w;
    e[ecnt].nxt = head[u];
    head[u] = ecnt;
}
 
int N,M;
int l[200050],r[200050];
int d[200050];
long long dist[100005];
queue<int> que;
bool vis[100050],inq[100050];
 
bool spfa(int st)
{
    que.push(st);
    inq[st] = true;
    dist[st] = 0;
    long long curmax = 0,curmin = 0;
    while(!que.empty())
    {
        int u = que.front();
        que.pop();
        for(int i = head[u];i;i = e[i].nxt)
        {
            int v = e[i].v;
            if(dist[v] == 12345678987654321)
            {
                dist[v] = dist[u] + e[i].w;
                curmax = max(curmax,dist[v]);
                curmin = min(curmin,dist[v]);
                if(curmax - curmin > 1000000000)
                    return false;
                vis[v] = 1;
                if(!inq[v])
                    que.push(v);
            }
            else if(dist[v] != dist[u] + e[i].w)
                return false;
        }
        inq[u] = false;
    }
    return true;
}
 
int main()
{
    for(int i = 1;i <= 100000; ++ i)
        dist[i] = 12345678987654321;
    scanf("%d%d",&N,&M);
    for(int i = 1;i <= M; ++ i)
    {
        scanf("%d%d%d",&l[i],&r[i],&d[i]);
        adde(l[i],r[i],d[i]);
        adde(r[i],l[i],-d[i]);
    }
    for(int i = 1;i <= N; ++ i)
    {
        if(!vis[i])
        {
            vis[i] = 1;bool l = spfa(i);
            if(!l)
            {
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int n;
long long a[100005], wei[100005], mod = 1000000007;
long long ny[100005];
long long smny[100005];



int main() {
    n = read();
    for (int i = 1; i <= n; ++i) {
        a[i] = read();
    }
    long long res = 0;
    ny[0] = ny[1] = 1;
    smny[1] = 1;
    for (int i = 2; i <= n; ++i) {
        ny[i] = mod - (mod / (long long)i) * ny[mod % i] % mod;
        ny[i] %= mod;
        smny[i] = (smny[i - 1] + ny[i]) % mod;
    }
    for (int j = 1; j <= n; ++j) {
        wei[j] = (smny[j] + smny[n - j + 1] - 1ll + mod) % mod;
        res += wei[j] * a[j] % mod;
        res %= mod;
    }
    for (int i = 1; i <= n; ++i) (res *= (long long)i) %= mod;
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 3328
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	std::string s;
	std::cin >> s;
	bool y = true;
	rep(i,s.size()) {
		if(i%2==0) {
			if(s[i]=='R' || s[i]=='U' || s[i]=='D') continue;
			else {
				y=false;
				break;
			}
		}
		else {
			if(s[i]=='L' || s[i]=='U' || s[i]=='D') continue;
			else {
				y=false;
				break;
			}
		}
	}
	if(y) print("Yes");
	else print("No");

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define int long long
signed main(){
  int n,a,b,ans=0;
  int ss=0;
  vector<int> v;
  cin>>n;
  int f=0,sum=0;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    sum+=a;
    if(a!=b)f=1;
    if(a<=b)ans+=b,ss=b-a;
    else v.push_back(b);
  }
  sort(v.begin(),v.end());
  if(!f)cout<<0<<endl;
  else cout<<sum-v[0]<<endl;
  return 0;
}


Measured memory_bytes: 512
package main 

import (
	"fmt"
	"strconv"
	"bufio"
	"os"
	"strings"

)

func int2str(nums []int) []string{
	var tmp []string

	for i:= 0; i<len(nums);i++{
		tmp = append(tmp,strconv.Itoa(nums[i]))
	}
	return tmp
}

func main() {
	var N int
	var nums []int
	var count int
	var tmp []string

	fmt.Scan(&N)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Scan()

	tmp = strings.Split(sc.Text()," ")

	for i := 0; i < N ; i++{
		n,_:= strconv.Atoi(tmp[i])
		nums = append(nums,n)
	}


	// bubbleSort

	var flag int = 1

	for flag == 1{
		flag = 0
		for j := len(nums) -1; j>=1 ;j--{
			
			if nums[j] < nums[j-1]{
				nums[j],nums[j-1] = nums[j-1],nums[j]
				flag = 1
				count++
			}
		}
	}


	fmt.Println(strings.Join(int2str(nums)," "))
	fmt.Println(count)


}


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

using namespace std;

static const int INF = 1e9 + 7;

void hawawa()
{
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  set<tuple<int, int, int> > s;
  while (!(a % 2 | b % 2 | c % 2)) {
    ans++;
    auto status = make_tuple(a, b, c);
    if (s.count(status)) {
      cout << "-1\n";
      return;
    }
    s.insert(status);
    a = get<1>(status) / 2 + get<2>(status) / 2;
    b = get<0>(status) / 2 + get<2>(status) / 2;
    c = get<1>(status) / 2 + get<0>(status) / 2;
  }
  cout << ans << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  hawawa();
}

Measured memory_bytes: 256
package main

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

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

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	a, b := nextInt(), nextInt()
	if a < b {
		fmt.Println("a < b")
	} else if a > b {
		fmt.Println("a > b")
	} else {
		fmt.Println("a == b")
	}
}

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

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



Measured memory_bytes: 1156
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	ll X;
	cin >> X;

	ll cur = 100;
	int y = 0;
	while (1) {
		cur = (ll)((long double)cur*(1.01));
		y++;
		if (cur >= X)break;
	}
	puts(y);

	return 0;
}

Measured memory_bytes: 3532
package main

import (
	"fmt"
)

func main() {
	var N, A int
	fmt.Scan(&N)
	m := map[int]int{}
	for i := 0; i < N; i++ {
		fmt.Scan(&A)
		m[A]++
	}
	r := 1
	for k, v := range m {
		if k == 0 {
			if N%2 == 0 || v != 1 {
				fmt.Println(0)
				return
			}
		} else {
			if N%2 == k%2 {
				fmt.Println(0)
				return
			}
			if v != 2 {
				fmt.Println(0)
				return
			}
		}
		r = (r * v) % 1000000007
	}
	fmt.Println(r)
}


Measured memory_bytes: 7936
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int t,n,k;

int main() {
  cin >> t;
  for(int i=0;i<t;i++)
    {
      cin >> n;
      cin >> k;
      int x[n];
      int d[n - 1];
      for(int j = 0;j < n;j++){
        cin >> x[j];
	if(j > 0){
	  d[j - 1] = x[j] - x[j - 1];
	}
      }
      sort(d , d + (n - 1));
      int ans = 0;
      if(n > k){
	for(int j = 0;j<n - k;j++){
	  ans += d[j];
	}
      }
      cout << ans << endl;
    }
}


Measured memory_bytes: 3904
/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define ld long double
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define el '\n'
#define N 1000000007
#define re return
#define F first
#define S second
#define L length
#define mp make_pair
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                             //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

inline ll max(ll a, ll b)
{
  if(a>b) re a;
  else re b;
}

inline ll min(ll a, ll b)
{
  if(a>b) re b;
  else re a;
}

int gcd(int a, int b)
{
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=(ans*(n-i)/(i+1))%N;
  }
  re ans;
}

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

  int t=1;
  //cin>>t;
  while(t--)
  {
    ll n,m,k;
    cin>>n>>m>>k;
    swap(n,m);swap(n,k);
    cout<<n<<" "<<m<<" "<<k;


  }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

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

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

const int MAX_N = 350;

int dp[MAX_N][MAX_N];
bool enable[MAX_N][MAX_N];

void solve(int& n) {
  memset(dp, 0, sizeof(dp));
  memset(enable, 0, sizeof(enable));
  int w[MAX_N];
  for(int i = 0; i < n; i++) cin >> w[i];

  for(int width = 2; width <= n; width++) {
    for(int left = 0; left < n; left++) {
      int right = left + width;
      if(n < right) continue;
      if(dp[left + 1][right - 1] == width - 2 && abs(w[left] - w[right - 1]) <= 1) dp[left][right] = width;
      for(int mid = left; mid <= right; mid++) {
	dp[left][right] = max(dp[left][right], dp[left][mid] + dp[mid][right]);
      }
    }
  }
  cout << dp[0][n] << endl;
  return ;
}

int main(){
  int n;
  while(cin >> n, n) {
    solve(n);
  }
  return 0;
}



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

int main()
{
    deque<char> q;
    string s;
    cin >> s;
    rep(i, s.length())
    {
        if (s[i] != 'B')
            q.push_back(s[i]);
        else if (!q.empty())
            q.pop_back();
    }
    while (!q.empty())
    {
        cout << q.front();
        q.pop_front();
    }
    cout << endl;
}

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

// 插入此處

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int K; cin >> K;
	vector<int> a;
	a.push_back(0);
	while (K--) {
		int ptr = 0;
		for (; ptr < a.size(); ++ptr) {
			if (a[ptr] != 9) {
				if (ptr == a.size()-1)  break;
				if (ptr+1 < a.size() && abs(a[ptr] + 1 - a[ptr+1]) <= 1) {
					break;
				}
			}
		}
		// cout << "ptr " << ptr << endl;
		if (ptr == a.size()) {
			for (int i = 0; i <= ptr; ++i) {
				a[i] = 0;
			}
			a.push_back(1);
		} else {
			a[ptr] += 1;
			for (int i = ptr-1; i >= 0; --i) {
				a[i] = max(0, a[i+1] -1);
			}
		}
		// for (auto x : a) {
		// 	cout << x;
		// }
		// cout << endl;
	}
	for (int i = a.size()-1; i >= 0; --i) {
		cout << a[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

MOD = 998244353

def init(G, robots, fs, p):
    q = p
    while q < len(robots) and robots[q][0] < robots[p][0] + robots[p][1]:
        if fs[q]:
            G[p].append(q)
            fs[q] = False
            q = init(G, robots, fs, q) - 1
        q += 1
    return q

def calc(G, p, fs):
    fs[p] = False
    if len(G[p]) == 0:
        return 2
    tmp = 1
    for v in G[p]:
        tmp *= calc(G, v, fs)
        tmp %= MOD
    tmp += 1
    return tmp

def main():
    n = int(input())
    robots = [list(map(int, input().split())) for _ in range(n)]
    G = [[] for _ in range(n)]
    robots.sort(key=lambda x: x[0])
    fs = [True]*n
    q = 0
    while q < n:
        if fs[q]:
            fs[q] = False
            init(G, robots, fs, q)
        else:
            q += 1
    fs = [True]*n
    ans = 1
    for i in range(n):
        if fs[i]:
            ans *= calc(G, i, fs)
            ans %= MOD
    print(ans % MOD)

if __name__ == "__main__":
    main()

Measured memory_bytes: 253464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef pair<l_l,ll> lll;
typedef vector<string> vs;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll n;
ll a[3300];
ll dp[3300][3300];
int main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)dp[i][i]=0;
    for(int len=1;len<=n;len++){
        for(int i=0;i<n;i++){
            int j=i+len;
            if(j>n)continue;
            if((n-len)%2==1){
                dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1]);
            }else{
                dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1]);
            }
        }
    }
    cout<<dp[0][n]<<endl;
    return 0;
}

Measured memory_bytes: 50616
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author rahdirigs
 */

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

class taskA {
public:
    const ll inf = 1e18;
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        vector<int> h(n);
        for (int i = 0; i < n; i++)
            in >> h[i];
        vector<ll> dp(n, 0);
        dp[1] = abs(h[1] - h[0]);
        for (int i = 2; i < n; i++) {
            dp[i] = inf;
            for (int j = 1; j <= 2; j++) {
                dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j]);
            }
        }
        out << dp[n - 1];
	}
};


int main() {
	taskA solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1536
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    from functools import reduce
    def lcm_base(n1,n2):
        return (n1*n2)//math.gcd(n1,n2)
    def lcm(*numbers):
        return reduce(lcm_base, numbers)
    n,m = LI()
    s = S()
    t = S()
    l1 = lcm(n,m)
    s_unit = l1//n
    t_unit = l1//m
    l2 = lcm(s_unit, t_unit)
    time = (l1-1)//l2+1
    itr = [l2*i for i in range(time)]
    ans = l1

    for i in itr:
        si = i//s_unit
        ti = i//t_unit
        if s[si] != t[ti]:
            ans = -1

    print(ans)

main()            


Measured memory_bytes: 10836
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const long double EPS = 1e-10;
map<ll, long double> mp;
ll K;
vector<ll> v;

ll digitLen(ll n) {
  ll res = 0;
  while (n) {
    res++;
    n /= 10;
  }
  return res;
}

ll digitSum(ll n) {
  ll res = 0;
  while (n) {
    res += n % 10;
    n /= 10;
  }
  return res;
}

long double calc(ll n) {
  if (mp.find(n) != mp.end()) return mp[n];
  return mp[n] = (long double)n / digitSum(n);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> K;
  for (int i = 1; i < 1000; i++) {
    ll tmp = i;
    while (digitLen(tmp) <= 15) {
      v.emplace_back(tmp);
      tmp = tmp * 10 + 9;
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  sort(v.begin(), v.end(), [&](ll a, ll b) {
    long double ca = calc(a);
    long double cb = calc(b);
    if (ca - cb < -EPS) return true;
    if (ca - cb > EPS) return false;
    return a < b;
  });
  ll mx = -1, cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] < mx) continue;
    cout << v[i] << endl;
    mx = v[i];
    cnt++;
    if (cnt == K) break;
  }

  return 0;
}

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

int main(){

  char a,b;
  bool result=true;

  cin >> a >> b;

  if(a == 'D'){
    result = !result;
  }

  if(b == 'D'){
    result = !result;
  }

  if (result) {
    cout << "H" << "\n";
  } else {
    cout << "D" << "\n";
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n; scanf("%d", &n);
    int p = 1; while(p < n) p <<= 1;
    if(p == n){puts("No");}
    else{
        puts("Yes");
        puts("1 2");
        puts("2 3");
        printf("1 %d\n", n+3);
        printf("%d %d\n", n+3, n+2);
        printf("%d %d\n", n+2, n+1);
        int edge = (n % 2 == 0) ? n - 2 : n;
        for(int v = 4; v <= edge; v += 2){
            printf("1 %d\n", v);
            printf("%d %d\n", v, v+1);
            printf("1 %d\n", v+n+1);
            printf("%d %d\n", v+n+1, v+n);
        }
        
        if(n % 2 == 0){
            printf("%d %d\n", n, p >> 1);
            int d = n - (p >> 1) + 1;
            printf("%d %d\n", d + n, 2 * n);
        }
        
    }
    return 0;
}

Measured memory_bytes: 2304
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        sc.close();

        // 主処理
        long countR = s.replaceAll("[^R]", "").length();
        long countG = s.replaceAll("[^G]", "").length();
        long countB = s.replaceAll("[^B]", "").length();
        long count = countR * countG * countB;
        for (int i = 0; i < n - 2; i++) {
            for (int j = i + 1; j < n - 1; j++) {
                int k = j + (j - i);
                if (k < n) {
                    int c1 = s.charAt(i);
                    int c2 = s.charAt(j);
                    int c3 = s.charAt(k);
                    if (c1 != c2 && c1 != c3 && c2 != c3) {
                        count--;
                    }
                }
            }
        }
        long result = count;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 39952
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
*/
#define MAX_V 11

vector<pair<ll, ll>> G[MAX_V];

// ダイクストラ法
vector<ll> dijkstra(ll start) {
	vector<ll> dist(MAX_V, inf);
	dist[start] = 0; // dist[i] := start->iまでの最短距離
	priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que;
	que.push({ 0, start });
	while (!que.empty()) {
		ll cost, u; // 今までにかかった時間　現在の頂点
		cost = que.top().first, u = que.top().second;
		que.pop();
		if (dist[u] < cost) continue;
		for (auto tmp : G[u]) {
			ll v = tmp.first, time = tmp.second; // 隣接する頂点、その頂点まで行く時間
			if (dist[v] > dist[u] + time) {
				dist[v] = dist[u] + time;
				que.push({ dist[v], v });
			}
		}
	}
	return dist;
}

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

	int h, w;
	cin >> h >> w;
	vector<vector<int>> c(10, vector<int>(10));
	rep(i, 10) {
		rep(j, 10) {
			cin >> c[i][j];
			G[i].push_back({ j, c[i][j] });
		}
	}
	vector<vector<int>>a(h, vector<int>(w));
	rep(i, h)rep(j, w) cin >> a[i][j];

	// それぞれの数字の数を保存
	vector<int> num(10, 0);
	rep(i, h) {
		rep(j, w) {
			if (a[i][j] == -1) continue;
			num[a[i][j]]++;
		}
	}

	// これグラフ理論では？
	// ダイクストラ法使えそう

	int ans = 0;

	rep(i, 10) {
		// iから1へ行く
		if (num[i] == 0) continue;
		auto dist = dijkstra(i);
		ans += dist[1] * num[i];
	}

	// 計算量はO(HW) or O(100log(HW)) := O(1000) でいいのかな

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
import sys
import numpy as np
from collections import deque
def input(): return sys.stdin.readline().rstrip()


def main():
    n, q = map(int, input().split())

    graph = [[] for _ in range(n+1)]

    for _ in range(n-1):
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)

    clist = [0]*(n+1)

    for _ in range(q):
        p, x = map(int, input().split())
        clist[p] += x

    dist = [-1] * (n+1)
    dist[0] = 0
    dist[1] = 0

    ans = [0]*(n+1)
    d = deque()
    d.append(1)
    ans[1]=clist[1]
    while d:
        v = d.popleft()
        for i in graph[v]:
            if dist[i] != -1:
                continue
            dist[i] = dist[v] + 1
            ans[i]=ans[v]+clist[i]
            d.append(i)
    
    ans = ans[1:]
    print(*ans, sep=" ")


if __name__ == '__main__':
    main()

Measured memory_bytes: 88204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int H, W, h, w; cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
    return 0;
}

Measured memory_bytes: 3620
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

vector<pair<string, int>> ans;
vector<string> v = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};

int n;

void solve(int len, pair<string, int> s){

    if(len == n){
        ans.emplace_back(s);
        return ;
    }

    int kind = s.second;

    for(int i=0; i<kind+1; i++){
        solve(len + 1, make_pair(s.first + v[i], max(s.second, i + 1)));
    }
    
    return ;
}

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

    cin>>n;

    pair<string, int> pp = make_pair("a", 1);
    solve(1, pp);

    sort(all(ans));

    for(auto i : ans) cout << i.first << endl;

    return 0;
}

Measured memory_bytes: 8816