akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#include <limits>
#define ll long long
using namespace std;
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;

int main()
{
    ll h, n;
    cin >> h >> n;
    ll ans = LLONG_MAX;
    vector<ll> a(n), b(n), dp(h+10005, 1000000000);
    for (ll i = 0; i < n;i++){
        cin >> a[i] >> b[i];
    }
    dp[0] = 0;
    for (ll i = 1; i <h+10005; i++)
    {
        for (ll j = 0; j < n;j++){
            if(i-a[j]>=0){
                dp[i] = min(dp[i - a[j]] + b[j], dp[i]);
                if(i>=h&&dp[i]<1000000000){
                    ans = min(ans, dp[i]);
                    //cout << dp[i] << endl;
                }
            }
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 384
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace NIKKEI2019C
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var D = ss.Next(long.Parse, 2, N).Select(d => new {A = d[0], B = d[1]}).ToArray();

            var ret = 0L;
            var sorted = D.OrderByDescending(d => d.A + d.B).ToArray();
            for (var i = 0; i < N; i++)
            {
                if (i % 2 == 0) ret += sorted[i].A;
                else ret -= sorted[i].B;
            }
            sw.WriteLine(ret);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 32188
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		
		Arrays.sort(s);
		Arrays.sort(t);
		
		System.out.println(isSmall(s, t) ? "Yes" : "No");
	}
	static boolean isSmall(char[] s, char[] t){
		for(int i=0;i<Math.min(s.length, t.length);i++){
			if(s[i]<t[t.length-1-i])
				return true;
			if(s[i]>t[t.length-1-i])
				return false;
		}
		
		return s.length<t.length;
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define longinf 9223372036854775807LL
#define intinf 2147483647
#define inf 998244353
#define lol long long
#define in(n,s) insert(n,s)//ノート参照
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,c,d,e=0,g,h;
int i[111110];
int u[111110];
lol dp[111][100010];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>a>>b;
  memset(dp,-1,sizeof(dp));
  for(int n=0;n<a;n++){
      cin >>i[n]>>u[n];
  }
  dp[0][0]=0;
  lol ans=0;
  for(int n=0;n<a;n++){
      for(int m=0;m<=b;m++){
	  if(dp[n][m]!=-1){
	      if(m+i[n]<=b) dp[n+1][m+i[n]]=max(dp[n+1][m+i[n]],dp[n][m]+u[n]);
	      dp[n+1][m]=max(dp[n][m],dp[n+1][m]);
	  }
	  if(ans<dp[n+1][m]) ans=dp[n+1][m];
      }
  }
  cout <<ans<<'\n';
  return (0);
}


Measured memory_bytes: 87040
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int W = scan.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        for(int i = 0; i < n; i++){
            w[i] = scan.nextInt();
            v[i] = scan.nextInt();
        }
        long[][] dp = new long[n + 1][W + 1];
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= W; j++){
                if(j < w[i]) dp[i + 1][j] = dp[i][j];
                else dp[i + 1][j] = Math.max(dp[i][j], dp[i][j - w[i]] + v[i]);
            }
        }
        System.out.println(dp[n][W]);
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


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

int main(){
  string str;
  while(cin >> str){
    for(int i=0; i<str.size(); ++i){
      if(str[i]=='0' && str[i+1]=='U'){
        cout << "nn";
        ++i;
      }else{
        switch(str[i]){
        case '0': cout << "w";break;
        case '2': cout << "k";break;
        case '3': cout << "s";break;
        case '4': cout << "t";break;
        case '5': cout << "n";break;
        case '6': cout << "h";break;
        case '7': cout << "m";break;
        case '8': cout << "y";break;
        case '9': cout << "r";break;
        case 'T': cout << "a";break;
        case 'L': cout << "i";break;
        case 'U': cout << "u";break;
        case 'R': cout << "e";break;
        case 'D': cout << "o";break;
        }
      }
    }
    cout << endl;
  }
  return 0;
}



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

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

int main() {
    int N, M, X, low=0, high=0, a;
    cin >> N >> M >> X;

    vector<int> A(M);
    rep(i, M){
        // cin >> A.at(i);
        cin >> a;
        if (a < X) {
            ++low;
        } else {
            ++high;
        }
    }
    cout << min(low,high) << endl;
    
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

const int upTo = 2e5 + 5;
int nbNode;
vector<int> adj[upTo];
ll res = 0;
void dfs(int node, int par) {
	if (par != -1) {
		if (node < par) {
			res += 1ll*(node+1)*(par-node);
		} else {
			res += 1ll*(node-par)*(nbNode-node);
		}
	}
	for (int nei : adj[node]) if (nei != par) {
		dfs(nei, node);
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> nbNode;
	for (int iEdge = 0; iEdge < nbNode-1; ++iEdge) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(0, -1);
	res += nbNode;
	cout << res << "\n";
}


Measured memory_bytes: 23784
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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


	bool ok = true;
	if (N % 2 != 0){
		ok = false;
	}
	if (ok){
		string t1 = "";
		for (int ii = 0; ii < N / 2; ++ii){
			t1 += S[ii];
		}
		string t2 = "";
		for (int ii = N/2; ii < N; ++ii){
			t2 += S[ii];
		}
		if (t1 != t2){
			ok = false;
		}
	}

	if (ok){
		cout << "Yes" << "\n";
	} else {
		cout << "No" << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
hs = list(map(int, input().split()))

edge = [[] for _ in range(n)]

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


cnt = 0

for node in range(n):
    good = True
    for neighbor in edge[node]:
        if hs[node] <= hs[neighbor]:
            good = False
    if good:
        cnt +=1

print(cnt)

Measured memory_bytes: 29396
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int gcd(int a, int b) {
	if(a > b) swap(a, b);
	return (a == 0) ? b : gcd(b%a, a);
}

void DFS(int R, auto & G, auto & comp, auto & live, int comp_id) {
	comp[R] = comp_id;
	for(auto v : G[R]) if(live[v] && comp[v] == -1)
		DFS(v, G, comp, live, comp_id);
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	sort(begin(A), end(A));
	vector<int> ans(N);
	vector<char> live(N, 1);

	map<int, vector<int> > prime_adj;
	for(int i = 0; i < N; i++) {
		int a = A[i];
		for(int j = 2; j*j <= a; j++) if(a%j == 0) {
			if(prime_adj.find(j) == end(prime_adj)) prime_adj[j] = {};
			prime_adj[j].push_back(i);
			while(a%j == 0) a /= j;
		}
		if(a > 1) prime_adj[a].push_back(i);
	}
	int P = 0;
	for(auto & p : prime_adj) if((int)(p.second.size()) >= 2) P++;
	live.resize(N+P, 1);
	vector< vector<int> > G(N+P);
	P = 0;
	for(auto & p : prime_adj) if((int)(p.second.size()) >= 2) {
		for(auto x : p.second) {
			G[N+P].push_back(x);
			G[x].push_back(N+P);
		}
		P++;
	}
	vector<int> comp(N+P, -1);
	for(int i = 0; i < N+P; i++) if(comp[i] == -1) DFS(i, G, comp, live, i);

	vector<int> last_nc(N, -1), last_lt(N, -1);
	for(int i = 0; i < N; i++) {
		vector<char> ok(N);
		for(int j = 0; j < N; j++) ok[j] = (live[j] && last_lt[j] <= last_nc[j]);
		vector<char> comp_state(N, 0);
		for(int j = 0; j < N; j++) if(live[j]) comp_state[comp[j]] = 1;
		int num_rm_comp = 0, num_comp = 0;
		for(int j = 0; j < N; j++) if(comp_state[j]) num_comp++;

		int this_id = -1;
		for(int j = 0; j < N; j++) if(ok[j]) {
			if(num_rm_comp+comp_state[comp[j]] < num_comp) {
				if(comp_state[comp[j]] == 1) num_rm_comp++;
				comp_state[comp[j]] = 0;
			}
			else {
				this_id = j;
				break;
			}
		}

		ans[i] = A[this_id];
		live[this_id] = 0;
		for(int j = 0; j < N; j++) if(live[j]) {
			if(gcd(A[j], A[this_id]) > 1) last_nc[j] = i;
			if(A[j] > A[this_id]) last_lt[j] = i;
		}
		int c0 = comp[this_id];
		for(int j = 0; j < N+P; j++) if(comp[j] == c0) comp[j] = -1;
		for(int j = 0; j < N+P; j++) if(comp[j] == -1 && live[j]) DFS(j, G, comp, live, j);
	}

	for(int i = 0; i < N; i++) cout << ans[i] << ((i == N-1) ? "\n" : " ");
}


Measured memory_bytes: 768
import sys

S = sys.stdin.readline().strip()

S = S[::-1]
i = 0
while i < len(S):
    if S[i:i+5] == "maerd":
        i += 5
    elif S[i:i+7] == "remaerd":
        i += 7
    elif S[i:i+5] == "esare":
        i += 5
    elif S[i:i+6] == "resare":
        i += 6
    else:
        break

if i == len(S):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 40560
//prince_bundela

#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int x, a, b;
    int dig, ans;
    cin >> x >> a >> b;
    ans = x - a;
    dig = ans / b;
    ans -= dig * b;
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define int long long
using namespace std;
const int N = 2e5 + 5;
const int mod = (int) 1e9 + 7;

pair <int, int> a[N];

int n,m,k;
int gt[N];
int inv[N];
int dp[N];

int pw(int n, int k)
{
    if (!k) return 1;
    int res = pw(n, k >> 1);
    res = res * res % mod;
    if (k & 1) return res * n % mod;
    return res;
}

void init()
{
    gt[0] = 1;
    for (int i = 1; i <= N - 5; i++)
    {
        gt[i] = gt[i - 1] * i % mod;
    }
    inv[N - 5] = pw(gt[N - 5], mod - 2);
    for (int i = N - 6; i >= 0; i--)
    {
        inv[i] = inv[i + 1] * (i + 1) % mod;
    }
}

void sub(int &a, int b)
{
    a -= b;
    if (a < 0) a += mod;
}

int C(int k, int n)
{
    return gt[n] * inv[n - k] % mod * inv[k] % mod;
}

int num(pair <int, int> cur, pair <int, int> nxt)
{
    int x = nxt.fi - cur.fi;
    int y = nxt.se - cur.se;
    return C(x, x + y);
}

int solve(int i)
{
    int &res = dp[i];
    if (res != -1) return res;
    res = num(a[0], a[i]);
    for (int j = 1; j <= k; j++) if (i != j && a[j].fi <= a[i].fi && a[j].se <= a[i].se)
    {
        sub(res, solve(j) * num(a[j], a[i]) % mod);
    }
    return res;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("file.inp","r",stdin);
    init();
    cin >> n >> m >> k;
    for (int i = 1; i <= k; i++)
    {
        cin >> a[i].fi >> a[i].se;
    }
    a[0] = mp(1LL, 1LL);
    a[++k] = mp(n, m);
    memset(dp, -1, sizeof(dp));
    cout << solve(k);
    return 0;
}


Measured memory_bytes: 8364
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int main(void) {
    int a, b, c, d, e, f;
    while (cin >> a >> b >> c >> d >> e >> f) {
        double det = a * e - b * d;
        int x = e * c - b * f;
        int y = a * f - d * c;
        cout << fixed << setprecision(3);
        if (x == 0) cout << (double) 0 << " ";
        else cout << x / det << " ";
        cout << fixed << setprecision(3);
        if (y == 0) cout << (double) 0 << endl;
        else cout << y / det << endl;
    }
    return 0;
}

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

class Program {
    static void Main (string[] args) {
        var inp = Console.ReadLine().Split(' ');
        var inp2 = Console.ReadLine().Split(' ');

        bool[] isHillGood = new bool[int.Parse(inp[0])];
        for(int i = 0;i < isHillGood.Length;i++) {
            isHillGood[i] = true;
        }

        for(int i = 0;i < int.Parse(inp[1]);i++) {
            var inpAB = Console.ReadLine().Split(' ');
            int a = int.Parse(inpAB[0]) - 1;
            int b = int.Parse(inpAB[1]) - 1;

            if(int.Parse(inp2[a]) > int.Parse(inp2[b])) {
                isHillGood[b] = false;
            } else if(int.Parse(inp2[a]) < int.Parse(inp2[b])) {
                isHillGood[a] = false;
            } else {
                isHillGood[a] = false;
                isHillGood[b] = false;
            }
        }

        int cnt = 0;
        for(int i = 0;i < isHillGood.Length;i++) {
            if(isHillGood[i]) cnt++;
        }

        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 48500
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll,int>pii;
//struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } }_io;
const int maxn=1e5+5;
int n,f;
vector<int>v[maxn];
int a[maxn],vis[maxn],odd[maxn];
int l[maxn],r[maxn];
void dfs(int u,int fa,int odd){
	if(f) return ;
	for(auto i:v[u]){
		if(i!=fa){
			if(vis[i]){
				if((a[i]&1)==odd||a[i]<l[u]-1||a[i]>r[u]+1){ f=1;return;}
			}
			else l[i]=l[u]-1,r[i]=r[u]+1;
			dfs(i,u,odd^1);
			l[u]=max(l[i]-1,l[u]);   //对称
			r[u]=min(r[i]+1,r[u]);
		}
	}
	if(r[u]<l[u]) f=1;
}
void solve(int u,int fa,int x){
	a[u]=x;
	for(auto i:v[u]){
		if(i!=fa){
			if(x-1>=l[i]&&x-1<=r[i]) solve(i,u,x-1);
			else solve(i,u,x+1);
		}
	}
}

int main(){
	cin>>n;
	for(int i=1;i<n;i++){
	  int x,y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	int k;
	cin>>k;
	int root=1;
	int tmp=0;
	while(k--){
		int x,y;
		cin>>x>>y;
		vis[x]=1;
		a[x]=y;
		root=x;
		tmp=y&1;
		l[x]=r[x]=y;
	}
	dfs(root,0,tmp);
	if(f) cout<<"No"<<'\n';
	else{
		cout<<"Yes"<<'\n';
		solve(root,0,a[root]);
		for(int i=1;i<=n;i++) cout<<a[i]<<'\n';
  }
}

Measured memory_bytes: 18400
#include <stdio.h>
#include <math.h>
int main(void){
  int cost,num;
  int totalCost=0;
  int i=0;
  double ave=0.0;
  while(scanf("%d,%d",&cost,&num)!=EOF){
    totalCost+=(cost*num);
    ave+=num;
    i++;
  }
  printf("%d\n%d\n",totalCost,(int)round(ave/i));
  return 0;
}



Measured memory_bytes: 2060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

#define LL long long
const int maxn = 1000;
int n;
int num[3][maxn];

int main() {
    #ifdef LOCAL
    freopen("test.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    #endif // LOCAL
    ios::sync_with_stdio(false);

    while(scanf("%d", &n) != EOF) {
        memset(num, 0, sizeof(num));
        for(int i = 1; i <= 2; ++i) {
            for(int j = 1; j <= n; ++j) {
                scanf("%d", &num[i][j]);
                num[i][j] += max(num[i - 1][j], num[i][j - 1]);
            }
        }
        printf("%d\n", num[2][n]);
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t ai,ao,at,aj,al,as,az;
  cin>>ai>>ao>>at>>aj>>al>>as>>az;
  int64_t ans=ao+ai+aj+al;if(ai!=0 && aj!=0 && al!=0){
  int64_t sum=0;sum+=ai%2;sum+=al%2;sum+=aj%2;
    if(sum==2 ||sum==1)
      ans--;
   }else{
  int64_t sum=0;sum+=ai%2;sum+=al%2;sum+=aj%2;
    ans-=sum;
  }
  cout<<ans<<endl;
  return 0;
}


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

#define int long long

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 2e5 + 5;
int a[N], b[N];

signed main()
{
	int n = read();
	for (int i = 1; i <= n; ++i) a[i] = read(), b[i] = read();
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	if (n % 2 == 0)
	{
		int c = a[n / 2] + a[n / 2 + 1];
		int d = b[n / 2] + b[n / 2 + 1];
		printf("%lld\n", d - c + 1);
	}
	else
	{
		int c = a[n / 2 + 1];
		int d = b[n / 2 + 1];
		printf("%lld\n", d - c + 1);
	}
	return 0;
}


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

	int main(){
     
      int A1, A2, A3, A4, A5,  N, M, K, S;
      cin >> N;
      cin >> M;
      for (N ; N <= M ; N++){
       A1 = N % 10;
        	K = N / 10;
       A2 = K % 10;
        	K = K / 10;
       A3 = K % 10;
        	K = K / 10;
       A4 = K % 10;
       A5 = K / 10;
      
        if (A1 == A5 && A2 == A4){
         S = S + 1;
        }
        else {
          continue;
        }
      }
      cout << S << endl;
    }
        

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}

void solve(){
    ll n, m;
    cin >> n >> m;
    if(m == n){
        Yes;
    }
    else No;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

int main(){
    string a,b;
    cin>>a>>b;
    ll cache[3001][3001];
    init(cache,0);
    loop(i,0,a.length()){
        loop(j,0,b.length()){
            if(a[i]==b[j]){
                cache[i+1][j+1]=1+cache[i][j];
            }
            else{
                cache[i+1][j+1] = max(cache[i][j+1], cache[i+1][j]);
            }
        }
    }
    ll i=a.length(),j=b.length();
    vector<char>ans;
    // loop(i,0,a.length()+1){
    //     loop(j,0,b.length()+1){
    //         cout<<cache[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
    while(cache[i][j]!=0){
        if(cache[i][j] == cache[i-1][j]){
            i--;
        }
        else if(cache[i][j] == cache[i][j-1]){
            j--;
        }
        else{
            ans.push_back(a[i-1]);
            i--;
            j--;
        }
    }
    auto it = ans.rbegin();
    while(it!=ans.rend()){
        cout<<*it;
        it++;
    }
    cout<<"\n";
   return 0;
}

Measured memory_bytes: 70656
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cassert>
 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
 
const int MAXN=1E5+10;
 
int n,val[MAXN],S;
int cnt[20],ans,f[1<<16];
int stk[20],top,bin[20];
 
int main()
{
    scanf("%d",&n);memset(f,0x3f,sizeof f);
    bin[0]=1;
    for(int i=1;i<=15;i++) bin[i]=bin[i-1]<<1;
    for(int i=1,u,v,w;i<n;i++)
        scanf("%d%d%d",&u,&v,&w),++u,++v,val[u]^=w,val[v]^=w;
    for(int i=1;i<=n;i++) cnt[val[i]]++;
    for(int i=1;i<=15;i++) ans+=cnt[i]>>1,S|=(cnt[i]&1)<<i;
    f[0]=0;
    for(int l=1;l<=15;l++)
        for(int s=0;s<(1<<16);s++)
            if(__builtin_popcount(s)==l&&(s&1)==0)
                {
                    top=0;
                    for(int i=1;i<16;i++) if((s>>i)&1) stk[++top]=i;
                    for(int i=1;i<=top;i++)
                        for(int j=i+1;j<=top;j++)
                            f[s]=min(f[s],f[s^bin[stk[i]]^bin[stk[j]]^bin[stk[i]^stk[j]]]+1+((s>>(stk[i]^stk[j]))&1));
                }
    printf("%d\n",f[S]+ans);
    #ifdef LOCAL
        system("pause");
    #endif
}

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

const int MAX = 1E+6; 
const int MOD = 1E+9 + 7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for (int i=2; i<MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll COM(int n, int k) {
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main() {
    COMinit();

    int X, Y;
    cin >> X >> Y;

    ll ans = 0;
    for (int a=0; a<max(X, Y); a++) {
        int b = Y - 2 * a;
        if (a + 2 * b == X) ans += COM(a+b, a) % MOD;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 23680
/*-------property of the half blood prince-----*/

#include <bits/stdc++.h>
#include <dirent.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define MIN(X,Y) X<Y?X:Y
#define MAX(X,Y) X>Y?X:Y
#define ISNUM(a) ('0'<=(a) && (a)<='9')
#define ISCAP(a) ('A'<=(a) && (a)<='Z')
#define ISSML(a) ('a'<=(a) && (a)<='z')
#define ISALP(a) (ISCAP(a) || ISSML(a))
#define MXX 10000000000
#define MNN -MXX
#define ISVALID(X,Y,N,M) ((X)>=1 && (X)<=(N) && (Y)>=1 && (Y)<=(M))
#define LLI long long int
#define VI vector<int>
#define VLLI vector<long long int>
#define MII map<int,int>
#define SI set<int>
#define PB push_back
#define MSI map<string,int>
#define PII pair<int,int>
#define PLLI pair<LLI,LLI>
#define PDD pair<double,double>
#define FREP(i,I,N) for(int (i)=(int)(I);(i)<=(int)(N);(i)++)
#define eps 0.0000000001
#define RFREP(i,N,I) for(int (i)=(int)(N);(i)>=(int)(I);(i)--)
#define SORTV(VEC) sort(VEC.begin(),VEC.end())
#define SORTVCMP(VEC,cmp) sort(VEC.begin(),VEC.end(),cmp)
#define REVV(VEC) reverse(VEC.begin(),VEC.end())
#define INRANGED(val,l,r) (((l)<(val) || fabs((val)-(l))<eps) && ((val)<(r) || fabs((val)-(r))<eps))
#define INRANGEI(val,l,r) ((val)>=(l) && (val)<=(r))
#define MSET(a,b) memset(a,b,sizeof(a))
using namespace std;
using namespace __gnu_pbds;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction


//typedef tree < int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

int costs[10][10];
int digs[203][203];

int dp[2050][10];

bool isset(int mask, int i){return (mask&(1<<i));}

int solve(int mask, int cur){
    if(cur==1)return dp[mask][cur]=0;
    if(dp[mask][cur]!=-1)return dp[mask][cur];
    int cost = 1000000009;
    FREP(i,0,9){
        if(!isset(mask,i)){
            int newmask = (mask|(1<<i));
            cost = min(cost,costs[cur][i]+solve(newmask,i));
        }
    }
    return dp[mask][cur]=cost;
}

int main(){
    MSET(dp,-1);
    int h,w;
    cin>>h>>w;
    FREP(i,0,9)FREP(j,0,9)cin>>costs[i][j];
    FREP(i,1,h)FREP(j,1,w)cin>>digs[i][j];
    FREP(i,0,9)solve(0,i);
    int ss = 0;
    FREP(i,1,h){
        FREP(j,1,w){
            if(digs[i][j]==-1)continue;
            ss+=dp[0][digs[i][j]];
        }
    }
    cout<<ss<<"\n";
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
	map<string, int> ct;
	int n;
	cin>>n;
	
	while(n--) {
		string s;
		cin>>s;
		
		int arr[26] = {0};
		for(int i=0;i<s.size();i++) {				//count the frequency of chars
			arr[int(s[i]-'a')]++;
		}
		
		string sign = "";				  	//
		for(int i=0;i<26;i++) {
//			cout<<" arr[i] : "<<arr[i];
			sign += char('0' + arr[i]);
		}		
		
//		cout<<"SIGN : "<<sign<<endl;
		ct[sign]++;
	}
	
	long long sm = 0LL;
	map<string, int>:: iterator it = ct.begin();
	for(; it != ct.end(); it++) {
		long long frq = it->second; 
		sm += ((frq) * (frq-1))/2;
	}
	
	cout<<sm;
	return 0;
}


Measured memory_bytes: 14336
a, b, c, d = map(int, input().split())
if b<=c or d<=a:
    print(0)
elif a<=c and d<=b:
    print(d-c)
elif c<=a and b<=d:
    print(b-a)
elif a<c and b<d:
    print(b-c)
else:
    print(d-a)


Measured memory_bytes: 2940
#include <iostream>
#include<cstdio>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

const double rate=380000.0;

int main()
{
    int n;
    double ans=0;
    double u;
    char s[5];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lf",&u);
        scanf("%s",s);
        if(s[0]=='B')
            u*=rate;
        ans+=u;
    }
    printf("%.10f\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define optimize() ios_base ::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n";
using namespace std;


int main()
{
    optimize();
     long long int i,a=1,b=2,c=1,m=1000000007;
     long long n=-1e18;
  
     cin>>n;
     for(i=0;i<n;i++)
     {
       a*=10,a%=m,b*=9,b%=m,c*=8,c%=m;
     }
     a-=b-c;
     cout<<(m+a)%m;

    return 0;
}



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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N + 1);
  A[0] = -1;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    if (A[i] - A[i - 1] > 1) {
      cout << -1 << '\n';
      return 0;
    }
  }
  ll res = 0;
  for (int i = 2; i <= N; i++) {
    if (A[i] == A[i - 1] + 1)
      res++;
    else
      res += 1LL * A[i];
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#define MAX 20
#define MAXV 2000
int dp[MAXV][MAXV],   //值为1 代表可以 2 代表不可以 -1代表未计算
    A[MAX];
int n;
int solve(int i,int m)
{
    if(dp[i][m] ==1 || dp[i][m] ==2) return dp[i][m];
    if(m == 0) dp[i][m] = 1;
    else if(i>n) dp[i][m] = 2;
    else if(solve(i+1,m) == 1)
        dp[i][m] = 1;
    else if(solve(i+1,m-A[i]) == 1)
        dp[i][m] = 1;
    else dp[i][m] = 2;

    return dp[i][m];
}


int main()
{

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

    int m,key;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>key;
        if(solve(0,key) == 1)
            cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }

    return 0;
}






Measured memory_bytes: 3224
#include <iostream>

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

  int Ryori[M] = {};
  int K, A;
  for( int i = 0; i < N; i++ ){
    std::cin >> K;
    for( int j = 0; j < K; j++ ){
      std::cin >> A;
      Ryori[A-1]++;
    }
  }
  
  int kaitou = 0;
  for( int i = 0; i < M; i++ ){
    if( Ryori[i] == N ) kaitou++;
  }

  std::cout << kaitou << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
z = [0, 0]
for i in range(n):
    if s[i] == '0':
        z[i%2] += 1
a = (n+1)//2 - z[0] + z[1]
b = z[0] + n//2 - z[1]
print(min(a,b))

Measured memory_bytes: 3188
program prob18
    implicit none
    character :: a,b
    logical :: c,d
    read(*,*) a,b
    if(a == 'H') then
        c = .true.
    else
        c = .false.
    end if

    if(b == 'H') then
        d = .true.
    else
        d = .false.
    end if

    if(xor(c,d)) then
        write(*,'(a)') 'D'
    else
        write(*,'(a)') 'H'
    end if

    stop
contains
end program prob18

Measured memory_bytes: 2716
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int c=2*b+1;
  if(a%c==0){
    cout<<a/c<<endl;
    return 0;
  }else{
    cout<<a/c+1<<endl;
  }
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  if(s=="RRR"){
    cout << 3 << endl;
    return 0;
  }
  if(s[0]=='R'&&s[1]=='R'){
    cout << 2 << endl;
    return 0;
  }
  if(s[1]=='R'&&s[2]=='R'){
    cout << 2 << endl;
    return 0;
  }
  if(s=="SSS")
    cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 3596
// Author: Ivan Kazmenko (gassa@mail.ru)
module solution;
import std.algorithm;
import std.stdio;

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		auto a = new bool [] [] (n, n);
		foreach (k; 0..m)
		{
			int u, v;
			readf (" %s %s", &u, &v);
			u -= 1;
			v -= 1;
			a[u][v] = true;
			a[v][u] = true;
		}

		auto c = new int [n];
		c[] = 2;
		int [2] d;

		bool recur (int v, int cur)
		{
			if (c[v] == cur)
			{
				return true;
			}
			if (c[v] != 2)
			{
				return false;
			}
			c[v] = cur;
			d[cur] += 1;
			foreach (u; 0..n)
			{
				if (u != v && !a[v][u])
				{
					if (!recur (u, !cur))
					{
						return false;
					}
				}
			}
			return true;
		}

		auto f = new bool [n + 1];
		f[0] = true;
		bool ok = true;
		foreach (v; 0..n)
		{
			if (c[v] == 2)
			{
				d = [0, 0];
				if (!recur (v, 0))
				{
					ok = false;
					break;
				}
				foreach_reverse (i; 0..n + 1)
				{
					if (f[i])
					{
						foreach (j; 0..2)
						{
							f[i + d[j]] = true;
	                                	}
	                                	if (d[].all)
	                                	{
	                                		f[i] = false;
	                                	}
					}
				}
			}
		}

		if (ok)
		{
			int res = int.max;
			foreach (i; 0..n + 1)
			{
				if (f[i])
				{
					int cur = 0;
					cur += i * (i - 1) / 2;
					cur += (n - i) * (n - i - 1) / 2;
					res = min (res, cur);
				}
			}
			writeln (res);
		}
		else
		{
			writeln (-1);
		}
	}
}


Measured memory_bytes: 1020
# from collections import deque
n,m = map(int, input().split())
ikisaki=[[] for _ in range(n+1)]

for _ in range(m):
    a,b = map(int, input().split())
    ikisaki[a].append(b)
    ikisaki[b].append(a)
ans=[0]+[1]+[0]*(n-1)
tansakuheya=[1]
tmp=[]

for _ in range(1000009):

    for bangou in tansakuheya:

        for heya in ikisaki[bangou]:
            if ans[heya]==0:
                ans[heya]=bangou
                tmp.append(heya)

    tansakuheya=tmp
    tmp=[]


    if not tansakuheya:
        break

print("Yes")
for i in range(2,n+1):
	print(ans[i])

Measured memory_bytes: 34416
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N, K;
    cin >> N >> K;
    if ((N - 1) * (N - 2) / 2 < K) {
        cout << -1 << endl;
    } else {
        vvi E(N, vi(N, 1));
        rep(i, 0, N) {
            E[i][i] = 0;
        }

        int t = 0;
        int idx = 2;
        rep(i, 1, N - 1) {
            if (t + (N - idx) > K) {
                break;
            }
            t += N - idx;
            rep(j, idx, N) {
                E[i][j] = E[j][i] = 0;
            }
            idx++;
        }
        int r = K - t;
        rep(j, idx, idx + r) {
            E[idx - 1][j] = E[j][idx - 1] = 0;
        }

        stringstream ss;
        int cnt = 0;
        rep(i, 0, N) {
            rep(j, i + 1, N) {
                if (E[i][j]) {
                    cnt++;
                    ss << i + 1 << " " << j + 1 << endl;
                }
            }
        }
        cout << cnt << endl;
        cout << ss.str();
    }
    return (0^_^0);
}



Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
	string N;
	cin >> N;
	int n = stoi(N);
	int A = 0;

	for (int i = 0; i < N.size(); i++) {
		 A += N[i]-'0';
	}
	if (n % A == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int m, n, r;
vector<pair<int, int> > graph[100010];
int dist[100010] = {};

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

  int a, b, c;
  for(int i = 0;i < m;i++){
    cin >> a >> b >> c;
    graph[a].push_back(make_pair(b,c));
  }

  queue<pair<int, int> > que;

  for(int i = 0;i < n;i++) dist[i] = INT_MAX;

  dist[r] = 0;

  que.push(make_pair(r,0));

  pair<int, int> tmp;
  while(!que.empty()){
    tmp = que.front(); que.pop();
    for(int i = 0;i < graph[tmp.first].size(); i++){
      if(dist[graph[tmp.first][i].first] > tmp.second + graph[tmp.first][i].second){
        dist[graph[tmp.first][i].first] = tmp.second + graph[tmp.first][i].second;
        que.push(make_pair(graph[tmp.first][i].first,dist[graph[tmp.first][i].first]));
      }
    }
  }

  for(int i = 0;i < n;i++){
    if(dist[i] == INT_MAX) cout << "INF" << endl;
    else cout << dist[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 12968
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        Map<Long, Long> d = new HashMap<>();
        for (int i = 0; i < N; i++) {
            long y = scan.nextLong();
            long cnt = d.getOrDefault(y, 0L);
            d.put(y, cnt + 1);
        }
        int M = scan.nextInt();
        Map<Long, Long> t = new HashMap<>();
        for (int i = 0; i < M; i++) {
            long y = scan.nextLong();
            long cnt = t.getOrDefault(y, 0L);
            t.put(y, cnt + 1);
        }
        for (long x : t.keySet()) {
            long cnt1 = t.getOrDefault(x, 0L);
            long cnt2 = d.getOrDefault(x, 0L);
            if (cnt2 < cnt1) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}


Measured memory_bytes: 161480
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	String s = sc.next();
	String a = s.substring(0,1);
	String b = s.substring(1,2);
	String c = s.substring(2,3);
	String d = s.substring(3,4);
	if((a.equals(b) && !(a.equals(c)) && c.equals(d)) || (a.equals(c) && !(a.equals(b)) && b.equals(d)) ||(a.equals(d) && !(a.equals(b)) && b.equals(c))){
		System.out.println("Yes");
	}else{
		System.out.println("No");
	}
	
}
}


Measured memory_bytes: 23636
# input = list(map(int, input().split()))
# print(input)
# W, H, x, y, r = input[0], input[1], input[2], input[3], input[4]
W, H, x, y, r = [int(i) for i in input().split()]

res = 'No'
# x??§?¨??????????
if(r <= x <= W-r):
    # y??§?¨??????????
    if(r <= y <= H-r):
        res = 'Yes'
print(res)

Measured memory_bytes: 7724
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 998244353; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;

void solve() {
	int N; cin >> N;
	vector<string>S(N);
	vector<int>A(N);
	REP(i, N) {
		cin >> S[i] >> A[i];
	}
	string T; cin >> T;
	bool found = false;
	ll ans = 0;
	REP(i, N) {
		if (found)ans += A[i];
		if (S[i] == T)found = true;
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 764
#include <iostream>
using namespace std;
int main (){
int a,b,c,d,e,f,g;
cin>>a>>b>>c>>d>>e;
if(b%d==0){
f=b/d;}
else {
f=b/d+1;}
if(c%e==0){
g=c/e;}
else {
g=c/e+1;}
if(f<g) {
f=g;}
cout<<a-f<<endl;
return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>

#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Mabs(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define Abs(a) (a)>0?(a):(-(a))
template <typename QvQ> inline QvQ Min2(QvQ a,QvQ b){if(a<b) return a;return b;}
template <typename QvQ> inline QvQ Max2(QvQ a,QvQ b){if(a>b) return a;return b;}
template <typename QvQ> inline QvQ Abs2(QvQ a){if(a>0) return a;return -a;}

#define n1kw 10000000
#define inf 0x7f7f7f7f
#define dinf 0x3f3f3f3f
#define llinf 0x7f7f7f7f7f7f7f7f
#define lldinf 0x3f3f3f3f3f3f3f3f

#define ll long long
#define rei register int
#define inv inline void
#define inb inline bool
#define ini inline int

#define bl putchar(' ')
#define ed putchar('\n')
#define test std::cout<<"this:"
#define card system("pause")

#define read2(a,b) read(a),read(b)
#define write2(a,b) write(a),bl,write(b)
#define read3(a,b,c) read(a),read(b),read(c)
#define write3(a,b,c) write(a),bl,write(b),bl,write(c)

//char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)

template <typename QvQ>inv read(QvQ &x)
{
    x=0;int f=1;
    char c=getchar();
    for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
    for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
    x=x*f;
}
template <typename QvQ>inv write(QvQ x)
{
    if(x<0) x=-x,putchar('-');
    if(x>9) write(x/10);
    putchar(x%10+48);
}
using namespace std;
int n,a[200005],b[200005],mx,cmx;
int main()
{
    read(n);
    for(rei i=1;i<=n;++i)
	{
		read(a[i]);
		if(a[i]>=mx) cmx=mx,mx=a[i];
		else if(a[i]>=cmx) cmx=a[i];
	}
    for(rei i=1;i<=n;++i)
    {
    	if(a[i]!=mx) write(mx),ed;
    	else write(cmx),ed;
    }
    return 0;
}

Measured memory_bytes: 2432
a, b, c, d, f = input().split()
lw = int(a)
lh = int(b)
x = int(c)
y = int(d)
r = int(f)

if x - r >= 0 and x + r <= lw:
    if y - r >= 0 and y + r <= lh:
        print("Yes")
    else:
        print("No")
else:
    print("No")



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

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

    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, 0, n) cin >> d[i];

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

    cout << d[n / 2] - d[n / 2 - 1] << endl;

    return 0;
}

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

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

    string S;
    cin >> S;

    bitset<4000> RED;
    bitset<4000> GREEN;
    bitset<4000> BLUE;

    for (int i = 0; i < N; ++i) {
        if (S[i] == 'R') {
            RED.set(i);
            continue;
        }
        if (S[i] == 'G') {
            GREEN.set(i);
            continue;
        }
        BLUE.set(i);
    }

    long long int ans = RED.count() * GREEN.count() * BLUE.count();

    for (int i = 1; i < N; ++i) {
        ans -= ((RED >> i) & GREEN & (BLUE << i)).count();
        ans -= ((RED << i) & GREEN & (BLUE >> i)).count();
        ans -= (RED & (GREEN >> i) & (BLUE << i)).count();
        ans -= (RED & (GREEN << i) & (BLUE >> i)).count();
        ans -= ((RED >> i) & (GREEN << i) & BLUE).count();
        ans -= ((RED << i) & (GREEN >> i) & BLUE).count();
    }

    cout << ans << endl;
}

Measured memory_bytes: 3644
N = int(input())
ans = [0, 0, 0]

for h in range(1, 3501):
    for n in range(1, 3501):
        if (4*n*h-N*n-N*h) <= 0:
            continue
        
        if ((N*h*n) % (4*n*h-N*n-N*h)) == 0:            
            ans[0] = h
            ans[1] = n
            ans[2] = (N*h*n) // (4*n*h-N*n-N*h)
            break
    if sum(ans) != 0:
        break

for a in ans:
    print(a, end=" ")

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

int main(){
	int n, k, q; cin >> n >> k >> q; std::vector<int> a(n);
	std::vector<std::pair<int, int>> vec;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		
		vec.push_back({a[i], i});
	}
	sort(begin(vec), end(vec));
	
	int ans = vec[q - 1].first - vec[0].first;
	std::vector<int> pos; pos.push_back(-1); pos.push_back(n);
	for(int i = 0; i < n - q; i++) {
		pos.push_back(vec[i].second);
		sort(begin(pos), end(pos));
		
		std::vector<int> A;
		for(int j = 0; j < pos.size() - 1; j++){
			if(pos[j + 1] - pos[j] - 1 < k) continue;
			
			std::vector<int> B;
			for(int l = pos[j] + 1; l < pos[j + 1]; l++) B.push_back(a[l]);
			sort(begin(B), end(B));
			for(int l = 0; l < B.size() - k + 1; l++) A.push_back(B[l]);
		}
		
		if(A.size() < q) break;
		sort(begin(A), end(A));
		ans = std::min(ans, A[q - 1] - A[0]);
	}
			
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384