akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> tree(n + 1);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        tree[u].emplace_back(v);
    }
    int s, t;
    cin >> s >> t;
    queue<pair<int, int>> q;
    q.emplace(pair<int, int>{s, 0});
    vector<vector<bool>> reached(3, vector<bool>(n + 1, false));
    vector<vector<int>> dis(3, vector<int>(n + 1, -1));
    reached[0][s] = true;
    dis[0][s] = 0;
    while (!q.empty()) {
        auto front = q.front();
        q.pop();
        int cur = front.first;
        int count = front.second;
        for (auto e: tree[cur]) {
            if (!reached[(count + 1) % 3][e]) {
                q.emplace(pair<int, int>{e, count + 1});
                reached[(count + 1) % 3][e] = true;
                dis[(count + 1) % 3][e] = count + 1;
            }
        }
    }
    if (dis[0][t] > 0) {
        cout << dis[0][t] / 3 << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    if( a == 1 ) a += 13;
    if( b == 1 ) b += 13;
    if( a == b ) cout << "Draw";
    else if( a < b ) cout << "Bob";
    else cout << "Alice";
    cout << endl;
    return 0;
}



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

int main() {
    int a,c,o;
    a=c=o=0;
    cin >> a;
    for (int i = 1; i <= a;i++) {
        if (i % 2 != 0){
            o++;
        }
        c++;
    }
    double r = 0;
    r = (double)o / (double)c;
    cout << r << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

#tempは空白の箱に過ぎず、一番最初のfor文では確定演出で問答無用にXの値になる。
#for文が2週目に突入してからが、tempの分かれ目。2回目のfor文でも一致はせず素直に3が代入される。
#最後のif文　temp == x-1 が一致するのは　１回目と2回目　or 2回目と3回目が連番。つまり-1して一致すれば連続


#満足度を記録していくための変数
cnt = 0

#1つ前に食べた料理を記録するための変数
temp = ""

#料理を食べた順番に処理していく
for x in A:
    
    #食べた料理の満足度を追加
    cnt += B[x-1]
    
    #今食べた料理が1つ前に食べた料理のi+1かどうかを確認
    if temp == x - 1:
        cnt += C[temp-1]
        
    #今食べた料理を記録    
    temp = x
#全ての料理に対して処理が終わったら満足度を出力   
print(cnt)


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

int searchone(string s1,string s2){
    int count = 0;
    rep(i,s1.size()){
        if(s1[i]=='1' && s1[i]==s2[i]) count++;
    }
    return count;
}

int main(){
    int N;
    cin >> N;
    string f[N];
    rep(i,N){
        f[i]="";
        rep(j,10){
            char a;
            cin >> a;
            f[i]+=a;
        }
    }
    int p[N][11];
    rep(i,N){
        rep(j,11){
            cin >> p[i][j];
        }
    }
    int max_count=INT_MIN;
    repi(i,1,(int)pow(2,10)){
        int count = 0;
        rep(j,N){
            bitset<10> k(i);
            count += p[j][searchone(k.to_string(),f[j])];
        }
        max_count = max(max_count,count);
    }
    cout << max_count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int Stack[100],top=0;

void push(int);
int pop(void);

void push(int n)
{
  Stack[++top] = n;
}

int pop()
{
  top--;
  return Stack[top+1];
}

int main()
{
  int x,y;
  char word[100];
  
  while(scanf("%s",word) != EOF) {
    if(word[0] == '+') {
      x = pop();
      y = pop();
      push(x+y);
    }else if(word[0] == '-'){
      y = pop();
      x = pop();
      push(x-y);
    }else if(word[0] == '*'){
      x = pop();
      y = pop();
      push(x*y);
    }else{
      push(atoi(word));
    }
  }

  printf("%d\n",pop());

  return 0;
  
}
      
      
      



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

int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(void){
    int k;
    cin>>k;
    cout<<a[k-1]<<endl;
}

Measured memory_bytes: 256
n = int(input())
A = [int(i) for i in input().split()]
cum_sum = [0]
ans,sum = 0,0

# 累積和を求める
for i in range(len(A)):
    cum_sum.append(cum_sum[i]+A[i])

for i in range(n):
    # A[i+1]+A[i+2]+...+A[n]を累積和で求める
    sum = (cum_sum[n]-cum_sum[i+1])%1000000007
    # A[i]*(A[i+1]+A[i+2]+...+A[n])の処理
    # なおA[i+1]=A[j],A[i+2]=A[j+2]...である
    ans += A[i]*sum
    # 1000000007で割る
    ans %= 1000000007   
print(ans)

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

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


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


int main() {
  int n,m;
  cin >> n >> m;
  vector<int> k(m);
  vector<int> p(m);
  vector<vector<int>> s(m,vector<int>(n));
  rep(i,m){
    int a;
    cin >> a;
    k[i] = a;
    rep(j,a){
      cin >> s[i][j];
    }
  }
  rep(i,m){
    cin >> p[i];
  }
  ll ans = 0;
  for(int bit = 0; bit < (1<<n); ++bit){
    bool have = true;
    rep(i,m){
      int sum = 0;
      rep(j,k[i]){
        if (bit & (1<<(s[i][j]-1))) {
              sum++;
            }
      }
      if(sum % 2 != p[i]){
        have = false;
      }
    }
    if(have){
      ans++;
    }
    }
  cout << ans;
  
  return 0;
}




Measured memory_bytes: 3664
// C - Pyramid
#include <bits/stdc++.h>
using namespace std;
using TP = tuple<int,int,int>;//<x,y,h>
using VT = vector<TP>;//[i]<x,y,h>
#define rp(i,n) for(int i=0;i<(n);i++)
#define eb(x,y,h) emplace_back((x),(y),(h))
#define manhattan(x1,y1,x2,y2) abs((x1)-(x2))+abs((y1)-(y2))
#define XMAX 100
#define YMAX 100

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

	VT A;//h!=0
	VT B;//h==0
	VT C;//center candidate

	rp(i, N){
		int x,y,h; cin>>x>>y>>h;
		if(h!=0) A.eb(x,y,h);
		else B.eb(x,y,h);
	}

	rp(y0, YMAX+1){
		rp(x0, XMAX+1){
			bool exist = true;
			int x,y,h;
			tie(x,y,h) = A[0];
			int h0 = h + manhattan(x0,y0, x,y);//h0: hight of center candidate

			for(int i=1; i<A.size(); ++i){
				tie(x,y,h) = A[i];
				if(h0 != h + manhattan(x0,y0, x,y)){
					exist = false;
					break;
				}
			}

			if(exist) C.eb(x0,y0,h0);//set center candidate
		}
	}

	rp(c, C.size()){
		int x0,y0,h0; tie(x0,y0,h0) = C[c];

		bool exist = true;
		rp(b, B.size()){
			int x,y,h; tie(x,y,h) = B[b];
			int manhattan = abs(y0 - y) + abs(x0 - x);
			int hi = max(0, h0 - manhattan);
			if(hi != h){
				exist = false;
				break;
			}
		}

		if(exist) cout<<x0<<" "<<y0<<" "<<h0<<"\n";

	}

}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    if (a < b && b < c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>

using namespace std;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

int main() {
   
 
    long long int L, R,i,j; 
    cin >> L >> R;
    if ((L-1) / 2019 != R / 2019) {
        cout << 0 << endl; return 0;
    }
    L = L % 2019; R = R % 2019;
    int ans = 2018;
    FOR(i, L, R+1) {
        FOR(j, i+1, R+1) {
            ans = min(ans, (i*j)%2019);
        }
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> point(n,0);
	for(int i=0;i<n*(n-1)/2;i++){
		int a,b,c,d; cin >> a >> b >> c >> d;
		a--; b--;
		if(c>d)point[a]+=3;
		else if(c<d)point[b]+=3;
		else point[a]++,point[b]++; 
	}
	vector<pair<int,int>> v;
	for(int i=0;i<n;i++){
		v.push_back({point[i],i});
	}
	sort(v.rbegin(),v.rend());
	for(int i=0;i<n;i++){
		int ii=i;
		int cp=v[i].first;
		while(i<n&&v[i].first==cp){
			point[v[i].second]=ii+1;
			i++;
		}
		i--;
	}
	for(int i=0;i<n;i++){
		cout << point[i] << endl;
	}
}
 


Measured memory_bytes: 3220
<?php
$inputs = str_split(file_get_contents("php://stdin"));
echo array_reduce($inputs, function($prev, $cur) {
  if ($cur === "B") {
    return strlen($prev) == 0 ? $prev : substr($prev, 0, -1);
  } else {
    return $prev.$cur;
  }
}, "");

Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
double pi = acos(-1.0);
int main(){
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double x = (h * 60 + m) / 720.0 * 2 * pi;
    double y = (m) / 60.0 * 2 * pi;
    double tmp = fabs(x - y);
    //if(tmp > 180) tmp -= 180;
    double c = a * a + b * b - 2.0 * a * b * cos(tmp);
    double ans = sqrt(c);
    printf("%.20lf\n", ans);
    return 0;
}

Measured memory_bytes: 4156
/* long long or int & the MAX_INT or MIN_INT */
/* the size of a[] & inline */
/* xx 396 */

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

const long long Max=1e9;

/* Max1_x*Max1_y-Max2_x&Max2_y */ 

signed main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	long long S; cin>>S;
	long long x1,y1,x2,y2,x3,y3;
	x1=0; y1=0; x2=Max; y3=1;
	x3=Max-S%Max; y2=(S+x3)/Max; 
	if(S==1e18) cout<<x1<<" "<<y1<<" "<<0<<" "<<Max<<" "<<Max<<" "<<Max<<endl;
	else cout<<x1<<" "<<y1<<" "<<x3<<" "<<y2<<" "<<x2<<" "<<y3<<endl;
	return 0;
}

/*
1000000000000000000
*/

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>

using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second

int main(){
	ll n;cin>>n;
  vector<ll> l(2*n);
	rep(i,n){
    cin>>l[2*i]>>l[2*i+1];
  }
  sort(all(l));
  ll ans=0;
  rep(i,n){
    ans+=l[2*i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<utility>
using namespace std;
int main(int argc, char *argv[])
{
  for(int tt = 0;;tt++){
    int n, m, cap;
    cin >> n >> m >> cap;
    if(n == 0) break;
    cap *= 10;
    map<string,int> map;
    string currN, destN;
    cin >> currN >> destN;
    auto mapping = [&map](const string &city) {
      if(map.find(city) == map.end()) map.insert(make_pair(city, map.size()));
      return map[city];
    };
    int curr = mapping(currN);
    int dest = mapping(destN);
    vector<vector<pair<int,int>>> es(6002,vector<pair<int,int>>());
    for(int i = 0; i < n; i++) {
      string src, tgt;
      int d;
      cin >> src >> tgt >> d;
      int s = mapping(src);
      int t = mapping(tgt);
      es[s].push_back(make_pair(t, d));
      es[t].push_back(make_pair(s, d));
    }
    vector<bool> gs(6002, false);
    for(int i = 0; i < m; i++) {
      string city;
      cin >> city;
      gs[mapping(city)] = true;
    }
    const int BIG = 6002*2000*2*2;
    const int nn = map.size();

    vector<vector<int>> ds(nn, vector<int>(cap+1, BIG));
    vector<vector<bool>> fixed(nn, vector<bool>(cap+1, false));
    priority_queue<pair<int, pair<int, int>>> que;
    // Dijkstra
    que.push(make_pair(-0, make_pair(curr, cap)));
    while(que.size() > 0) {
      auto dvc = que.top();
      que.pop();
      const int d = -dvc.first;
      const int v = dvc.second.first;
      const int c = dvc.second.second;
      if(fixed[v][c]) continue;
      fixed[v][c] = true;
      ds[v][c] = d;
      for(auto it = es[v].begin(); it != es[v].end(); it++) {
        int cc = c - it->second;
        if(cc >= 0) {
          int i = it->first;
          int dd = d + it->second;
          if(gs[i]) cc = cap; // gas station
          if(ds[i][cc] > dd){
            ds[i][cc] = dd;
            que.push(make_pair(-dd, make_pair(i, cc)));
          }
        }
      }
    }
    int min = BIG;
    for(int i = 0; i <= cap; i++) {
      if(min > ds[dest][i]) {
        min = ds[dest][i];
      }
    }
    cout << (min == BIG ? -1 : min) << endl;
  }
  return 0;
}




Measured memory_bytes: 52836
#include <iostream>
#define ll long long
using namespace std;
const int mask=(1<<17)-1;
int f[47][(1<<17)-1];
const int mod=1e9+7;
int append(int s,int x)
{
	return ((s<<x)|(1<<(x-1)))&mask;
} 
int main()
{
	int n,x,y,z;
	cin>>n>>x>>y>>z;
	int s=0;
	s=append(s,x);
	s=append(s,y);
	s=append(s,z);
	f[0][0]=1;
	ll j;
	for(int i=1;i<=n;i++)
	{
		for(j=0;j<=mask;j++)
		{
			for(int k=1;k<=10;k++)
			{
				int ns=append(j,k);
				if((ns&s)==s) continue;
				f[i][ns]+=f[i-1][j];
				f[i][ns]%=mod;
			}
		}
	} 
	ll ans=1;
	for(int i=1;i<=n;i++) ans=(ans*10)%mod;
	for(int i=0;i<=mask;i++) ans=(ans-f[n][i]+mod)%mod;
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 22272
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)

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

    int k, n;
    cin >>k>>n;
    int a[n];
    rep(i,0,n) {
        cin>>a[i];
    }
    int x = abs(a[0]+(k-a[n-1]));
    rep(i,1,n) {
        x = max(x, abs(a[i]-a[i-1]));
    }
    cout << k - x;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

typedef long long LL;

int main(){
  LL n;
  cin >> n;
  LL a[n];
  for(int t = 0 ; t < n ; t++){
  
  	cin >> a[t];
  }
  
  LL flag = 0;
  LL m = 0;
  
  for(int t = 0; t < n; t ++){
  	if(a[t] > m){
    	m = a[t];
        flag = t;
    }
  }
  LL sum = 0;
  for(int t = 0; t < n; t++){
	if(t != flag)sum+= a[t];
  }
  
  
  if(sum > m)cout << "Yes";
  else cout << "No";

	return 0;
  
  
  
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val v = readLine()!!.split(" ").map { it.toInt() }
    val c = readLine()!!.split(" ").map { it.toInt() }
    var ans = 0
    for (i in 0 until n) {
        if (v[i]-c[i]>0) ans += (v[i]-c[i])
    }
    println(ans)
}


Measured memory_bytes: 36080
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m, t;
    cin >> n >> m >> t;
    int minx = 0, maxx = n;
    int miny = 0, maxy = m;
    for (int i = 0; i < t; ++i)
    {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1)
            minx = max(minx, x);
        if (a == 2)
            maxx = min(maxx, x);
        if (a == 3)
            miny = max(miny, y);
        if (a == 4)
            maxy = min(maxy, y);
    }
    if (minx <= maxx && miny <= maxy)
        cout << (maxx - minx) * (maxy - miny);
    else
        cout << "0";
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 1e18
#define mod pow(10,9)+7
#define mii map<int,int>
#define pii pair<int,int>
#define setbits(x) __builtin_popcountll(x)
void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int32_t main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int i = 0;
	while (true)
	{
		if (i & 1)
		{
			a -= d;
			if (a <= 0)
			{
				cout << "No";
				break;
			}

		}
		else
		{
			c -= b;
			if (c <= 0) {

				cout << "Yes";
				break;
			}
		}
		i++;
	}

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  vector<ll> ls;
  while (n--) {
    int x; cin >> x;
    ls.push_back(x);
  }

  int ans = 0;
  for (ll x: ls) {
    for (ll y: ls) {
      for (ll z: ls) {
        if (x < y && y < z && 2 * max({x, y, z}) < x + y + z) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <map>

int main(){
   int s;
   std::cin >> s;
   int i = 1;
   std::map<int, int> mp;
   mp[s]++;
   while (true){
      if (s % 2 == 0){
         s = s / 2;
      } else{
         s = 3 * s + 1;
      }
      if (mp[s] == 0){
         mp[s]++;
      } else{
         break;
      }
      i++;
   }
   std::cout << i+1 << std::endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  string s;cin >> s;
  if(s.at(s.size()-1) == 's') cout << s + "es" << endl;
  else cout << s + "s" << endl;

  return 0;
}


Measured memory_bytes: 3636
/*
Hanit Banga
*/

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 10;

bool g[N][N] = {0};

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

	for (int i = 0; i < m; ++i)
	{
		int u, v;
		cin >> u >> v;
		g[u][v] = g[v][u] = 1;
	}	

	int p = 1;
	vector <int> order;
	order.pb(1);
	for (int i = 2; i <= n; ++i)
	{
		order.pb(i);
		p *= (i - 1);
	}

	int ans = 0;
	auto second = order.begin();
	++second;
	while (p--)
	{
		bool path = true;
		for (int i = 1; i < n; ++i)
		{
			if (!g[order[i - 1]][order[i]])
			{
				path = false;
				break;
			}
		}

		if (path)
			++ans;

		next_permutation(second, order.end());
	}

	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

#define MAX_NODE 10000
#define INF 1000000000

using namespace std;

struct Edge {int to, w;};
typedef pair<int, int> PII;

vector<Edge> adj[MAX_NODE];
int d[MAX_NODE];

void dijkstra(int n, int start) {
	priority_queue<PII, vector<PII>, greater<PII>> que;
	fill(d, d + n, INF);

	d[start] = 0;
	que.emplace(0, start);
	while (!que.empty()) {
		PII p = que.top();
		que.pop();
		int from = p.second;

		if (d[from] < p.first)
			continue;

		for (auto& e : adj[from])
			if (d[from] + e.w < d[e.to]) {
				d[e.to] = d[from] + e.w;
				que.emplace(d[e.to], e.to);
			}
	}
}

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

	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		while (k--) {
			int v, c;
			cin >> v >> c;
			adj[u].push_back({v, c});
		}
	}

	dijkstra(n, 0);

	for (int i = 0; i < n; i++)
		cout << i << " " << d[i] << endl;

	return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,a,b,h,ans,R=1000000000,L;
vector<int> v;

signed main() {
    cin >> n >> a >> b;
    rep(i,n) cin >> h,v.pb(h)
    while(R-L > 1) {
        int cnt = 0,c = (R+L)/2;
        for(auto i : v) if (i > c*b) cnt += (i-c*b+a-b-1)/(a-b);
        if (c < cnt) L = c;
        else R = c;
    }
    cout << R << endl;
}

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

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

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

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ll r = n/i;
        ans += f(r)*i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define nl "\n"
ll n;
ll a[3002];
ll dp[3002][3002][2];
ll f(ll l,ll r,ll turn)
{
	if(l>r || l+1==n || r<0)
		return 0;
	if(l==r)
	{
		if(turn==0)
			dp[l][r][turn] = a[l];
		else
			dp[l][r][turn] = -a[r];
	}
	if(dp[l][r][turn] == -1)
	{
		if(turn == 0)
			dp[l][r][turn] = max(a[l]+f(l+1,r,1),a[r]+f(l,r-1,1));
		else
			dp[l][r][turn] = min(f(l+1,r,0)-a[l],f(l,r-1,0)-a[r]);
	}
	return dp[l][r][turn];
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n;
	ll i,j,k;
	ll ans=0;
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<3002;i++)
		for(j=0;j<3002;j++)
			for(k=0;k<2;k++)
				dp[i][j][k]=-1;
	f(0,n-1,0);
	if(n==1)
		cout<<a[0]<<nl;
	else
		cout<<dp[0][n-1][0]<<nl;
	return 0;
}

Measured memory_bytes: 141184
#include <iostream>

int main()
{
	int n, k, x, y;
	std::cin >> n >> k >> x >> y;
	
	int ans = 0;
	for(int i = 1; i <= n; i++)
	{
		if(k >= i)
		{
			ans += x;
		}
		else
		{
			ans += y;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

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

	printf("%d", min(A*N, B));

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 128
class Dictionary(object):
    def __init__(self, size):
        self.size = size
        self.a = [None]*size

    def hash(self, x):
        key = hash(x) % self.size
        while self.a[key] and self.a[key] != x:
            key = (key + 10**9+7) % self.size
        return key

    def insert(self, x):
        self.a[self.hash(x)] = x

    def find(self, x):
        return self.a[self.hash(x)] is not None


if __name__ == "__main__":
    import sys
    n = int(input())
    dictionary = Dictionary(n)
    result = []
    for command, s in (l.split() for l in sys.stdin):
        if command == "insert":
            dictionary.insert(s)
        else:
            result.append("yes" if dictionary.find(s) else "no")

    print(*result, sep="\n")


Measured memory_bytes: 38000
/**
 * author: BueVonHun 🐼🎋
 * More Info: https://github.com/Bue-von-hon
**/

#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>

typedef long long ll;
using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define m_p make_pair
#define pii pair<int,int>
#define piii pair<int,pii>
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

template <class T> T _min(T a,T b){return (a<b ? a : b);}
template <class T> T _max(T a,T b){return (a>b ? a : b);}
template<class T> void read(T& x) {cin >> x;}

int test_case;
int main(void) {
    fast_cin();
    int start=7,n;
    read(n);
    int val = 7%n;
    for (long i = 0; i <= 1e7; i++) {
        if (val==0) {cout << i+1 << endl; return 0;}
        val=(val*10+7)%n;
    }

    cout << "-1" << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
#define INF 2*100000+10

int main(){
    int N;
    cin >> N;
    int P[N];
    for(int i=0;i<N;i++){
        cin >> P[i];
    }
    int min=INF, res=0;
    for(int i=0;i<N;i++){
        if(min>=P[i]){
            res+=1;
            min=P[i];
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
using System;

namespace QQ
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = @"1x1=1
1x2=2
1x3=3
1x4=4
1x5=5
1x6=6
1x7=7
1x8=8
1x9=9
2x1=2
2x2=4
2x3=6
2x4=8
2x5=10
2x6=12
2x7=14
2x8=16
2x9=18
3x1=3
3x2=6
3x3=9
3x4=12
3x5=15
3x6=18
3x7=21
3x8=24
3x9=27
4x1=4
4x2=8
4x3=12
4x4=16
4x5=20
4x6=24
4x7=28
4x8=32
4x9=36
5x1=5
5x2=10
5x3=15
5x4=20
5x5=25
5x6=30
5x7=35
5x8=40
5x9=45
6x1=6
6x2=12
6x3=18
6x4=24
6x5=30
6x6=36
6x7=42
6x8=48
6x9=54
7x1=7
7x2=14
7x3=21
7x4=28
7x5=35
7x6=42
7x7=49
7x8=56
7x9=63
8x1=8
8x2=16
8x3=24
8x4=32
8x5=40
8x6=48
8x7=56
8x8=64
8x9=72
9x1=9
9x2=18
9x3=27
9x4=36
9x5=45
9x6=54
9x7=63
9x8=72
9x9=81
";

            Console.Write(str);
        }
    }
}

Measured memory_bytes: 8680
#include <stdio.h>
#include <stdlib.h>

void push(int x);
int pop();

int S[100];
int top = 0;

int main(void) {
	char s[100];
	while(scanf("%s",s) != EOF){
		int a = 0,b = 0;
		switch(s[0]){
			case '+':
			a = pop();
			b = pop();
			push(a+b);
			break;
			case '-':
			a = pop();
			b = pop();
			push(b-a);
			break;
			case '*':
			a = pop();
			b = pop();
			push(a*b);
			break;
			default:
			push(atoi(s));
		}
	}
	printf("%d\n",S[1]);
	return 0;
}

void push(int x){
	top++;
	S[top] = x;
}

int pop(){
	top--;
	return S[top+1];
}


Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        sc.close();
        int ans = 1;
        for(int i = 2; i < 32; i++){
            int tmp = 1;
            tmp *= i;
            while(tmp <= X){
                tmp *= i;
                if(tmp <= X) ans = Math.max(ans, tmp);
                else break;
            }
        }
        System.out.println(ans);

    }

}


Measured memory_bytes: 21844
function main(input) {
   input = input.trim();
  const a = input.split(" ");
 console.log(a[0].charAt(a[0].length-1)==a[1].charAt(0)&&a[1].charAt(a[1].length-1)==a[2].charAt(0)?"YES":"NO");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int main() {

more:
  int n; cin >> n;
  if (!n) return 0;

  vector<string> occur[30];
  Dictionary ps;

  rep (i, n) {
    string name; cin >> name;
    ps[name] = 0;
    int m; cin >> m;
    rep (j, m) {
      int d; cin >> d;
      occur[d].push_back(name);
    }
  }

  rep (d, 30) {
    int p = n - occur[d].size() + 1;
    for (string name : occur[d]) {
      ps[name] += p;
    }
  }

  int min_p = INF;
  string ans;
  for (auto&pr : ps)
    if (cdr(pr) < min_p) {
      min_p = cdr(pr);
      ans = car(pr);
    }
  cout << min_p << ' ' << ans << endl;

  goto more;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
ll A[200100];
ll B[200100];
int sp(int l,int r){ //[l,r]
	ll b = (B[r+1]-B[l])/2ll+B[l];
	int k = lower_bound(B+l+1,B+r+1,b)-B;
	return k-2;
}
ll sum(int l,int r){
	return B[r+1]-B[l];
}
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%lld",&A[i]);
		B[i+1]=A[i];
	}
	for(int i=0;i<=N;i++){
		B[i+1]+=B[i];
		//printf("%lld ",B[i]);
	}
	//printf("\n");
	ll ans = LLINF;
	for(int i=1;i<N-1;i++){ //[0..i][i+1..N-1]
		int kl = sp(0,i);
		int kr = sp(i+1,N-1);
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				int L = kl+j;
				int R = kr+k;
				//printf("[%d,%d] [%d,%d] [%d,%d] [%d,%d]\n",0,L,L+1,i,i+1,R,R+1,N-1);
				vector<ll> v;
				v.pb(sum(0,L));
				v.pb(sum(L+1,i));
				v.pb(sum(i+1,R));
				v.pb(sum(R+1,N-1));
				sort(all(v));
				ans = min(ans,v[3]-v[0]);
			}
		}
		//printf("\n");
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            Aij = new long[N][];
            dct = Enumerable.Range(0, (int)N).Select(_ => new Dictionary<long, long>()).ToArray();
            for(var i=0;i<N;++i)
            {
                Aij[i] = ReadLine().Split().Select(a => long.Parse(a) - 1).ToArray();
                for (var j = 0; j < N - 1; ++j)
                    dct[i][Aij[i][j]] = j;
            }
            var ans = 0L;
            dst = new long[N, N - 1];
            loop = new bool[N, N - 1];
            try
            {
                for (var i = 0; i < N; ++i)
                    ans = Max(ans, dfs(i, N - 2));
            }
            catch (Exception)
            {
                ans = -1;
            }
            WriteLine(ans);
        }
        static Dictionary<long, long>[] dct;
        static long[][] Aij;
        static long[,] dst;
        static bool[,] loop;
        static long dfs(long i, long n)
        {
            if (n < 0) return 0;
            if (0 < dst[i, n]) return dst[i, n];
            if (loop[i, n]) throw new Exception();
            loop[i, n] = true;
            var en = Aij[i][n];
            var pos = dct[en][i];
            return dst[i, n] = Max(dfs(i, n - 1), dfs(en, pos - 1)) + 1;
        }
    }
}

Measured memory_bytes: 103088
N, A, B = list(map(int, input().split()))
#print('N:{}'.format(N), 'A:{}'.format(A), 'B:{}'.format(B))
#print(A*(N//(A+B)), min(A, N%(A+B)))
print(A*(N//(A+B)) + min(A, N%(A+B)))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
using namespace std;


int main() {
  int n;
  cin>>n;
  int s = 0, t =n;
  while(t) {
    s += t%10;
    t /= 10;
  }
  if(n%s == 0) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        long N = sc.nextLong();
        long P = sc.nextLong();
        sc.close();

        if(N == 1){
            System.out.println(P);
        } else {
            long a = P;
            long gcd = 1;
            for(long i = 2; (i*i) <= a; i++){
                long count = 0;
                while(P % i == 0){
                    count++;
                    P /= i;
                }
                if(count >= N){
                    gcd *= (long)Math.pow(i, count/N);
                }
            }
            System.out.println(gcd);
        }
   }
}

Measured memory_bytes: 23892
if __name__ == "__main__":
    b = int(input())
    a = list(map(int, input().split()))
    a = a[::-1]
    count = 0
    value = 0
    for i in range(1, b):
        if a[i-1] <= a[i]: count+=1
        else: count = 0
        value = max(count, value)
    print(value)
    

Measured memory_bytes: 63856
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def main():
    n, a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    c -= 1
    d-=1
    s = list(input())
    for i in range(b, d):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            exit()
    for i in range(a, c):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            exit()
    if c < d:
        print("Yes")
    else:
        f = True
        for i in range(b-1, d):
            if s[i] == "." and s[i+1] == "." and s[i+2] == ".":
                print("Yes")
                exit()
        print("No")



if __name__ == '__main__':
    main()


Measured memory_bytes: 7164
#include <bits/stdc++.h>
 
#define TRACE(x) cerr << #x << " = " << x << endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define SZ(x) (int)(x).size()
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
template<class Num>
Num mabs(Num A){
  if(A < 0) return -A;
  return A;
}

const int N = 2005, mod = 1e9 + 7;

inline int add(int a, int b){
  int ret = a + b;
  if(ret >= mod) ret -= mod;
  return ret;
}

inline int sub(int a, int b){
  int ret = a - b;
  if(ret < 0) ret += mod;
  return ret;
}

int a, b, c, d;
set<ll> S;

int main(){
  scanf("%d %d %d %d", &a, &b, &c, &d);
  
  S.insert((ll)a * c);
  S.insert((ll)a * d);
  S.insert((ll)b * c);
  S.insert((ll)b * d);
  //if(a <= 0 && b >= 0) S.insert(0ll);
  //if(c <= 0 && d >= 0) S.insert(0ll);
  
  printf("%lld\n", *S.rbegin());
  
  return 0;
}


Measured memory_bytes: 3836
def main():
    k = int(input())
    t = list(map(int, input().split()))
    ans = {i: t[i-1] for i in range(1, k+1)}
    ans_sort = sorted(ans.items(), key=lambda x:x[1])
    for v in ans_sort:
        print(v[0], end=' ')


if __name__ == '__main__':
    main()


Measured memory_bytes: 26268
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000
#define ll long long int
using namespace std;




int main(){

  int H,W;cin>>H>>W;
  int h,w; cin>>h>>w;

  cout<<H*W-(H*w + W*h -h*w) <<endl;
 
return 0;


}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    lli N;
    lli res;
    vector<lli> nums;
    cin >> N ;
    res = 0;
    for (int i = 0; i < 5; i++) {
        lli num;
        cin >> num;
        nums.push_back(num);
    }
    sort(nums.begin(), nums.end());
    res = N/nums[0] + 4;
    if (N%nums[0] != 0) {
        res++;
    }

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
route = [[] for _ in range(4)]
for i in range(3):
    ai, bi = list(map(int, input().split()))
    route[ai-1].append(bi)
    route[bi-1].append(ai)

#print(route)

cnt1 = 0
cnt0 = 0
for a in route:
    if len(a) == 1:
        cnt1 += 1
    elif len(a) == 0:
        cnt0 += 1
        

if cnt1 > 2 or cnt0 >0:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int map[101][101];
int xg, yg;
int w, h;
int col;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
bool flag;

void dfs(int x, int y)
{
    map[y][x] = 0;

    if (x == xg && y == yg) {
        flag = true;
        return ;
    }

    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        
        if (nx < 0 || ny < 0 || nx >= w || ny >= h)
            continue;
        else if (map[ny][nx] == col)
            dfs(nx, ny);
    }
}

void setblock(int c, int d, int bx, int by)
{
    int wlim = 4, hlim = 2;

    if (d == 1) {
        wlim = 2;
        hlim = 4;
    }

    for (int y = 0; y < hlim; y++)
        for (int x = 0; x < wlim; x++)
            map[by + y][bx + x] = c;
}


int main()
{
    while (cin >> w >> h, w || h) {
        int xs, ys;
        int n;

        for (int y = 0; y < h; y++)
            for (int x = 0; x < w; x++)
                map[y][x] = 0;

        cin >> xs >> ys >> xg >> yg >> n;

        xs--, ys--, xg--, yg--;
        for (int i = 0; i < n; i++) {
            int c, d, x, y;
            
            cin >> c >> d >> x >> y;
            x--, y--;            
            setblock(c, d, x, y);
        }
        col = map[ys][xs];
        flag = false;
        if (col)
            dfs(xs, ys);

        if (flag)
            cout << "OK" << endl;
        else
            cout << "NG" << endl;
    }

    return 0;
}

Measured memory_bytes: 1200
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void convert(string s, vector<int> & ans){
	rep(i,10){
  		rep(j,26){
			if(s[i]=='a'+j){
    			ans[j]++;
              	break;
            }
    	}
  	}
  	return;
}

ll comb(ll x){
	return x*(x-1)/2;
}

void Main()
{
	int N;
  	cin >> N;
  	vector<string> s(N);
  	rep(i,N) cin >> s[i];
  
  	vector<vector<int>> ans(N, vector<int>(26,0));
  	rep(i,N) convert(s[i], ans[i]);
	sort(ans.begin(),ans.end());
	
  	ll sum = 0;
    ll temp = 0;
  	rep(i,N-1){
		if(ans[i] == ans[i+1]){
        	temp++;
        }
      	else{
        	if(temp>0){
            	sum += comb(temp+1);
              	temp = 0;
            }
        }
    }
  	if(temp > 0){sum += comb(temp+1);}
  	cout << sum << endl;
	return;
}

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


Measured memory_bytes: 19072
#include <iostream>
#include <stdio.h>
using namespace std;


int main()
{
	int a,b;
	cin>>a;
	cin>>b;
	int d = a/b;
	int r = a % b;
	double f = (double) a/b;
	cout<<d<<" "<<r<<" ";
	printf("%11lf\n",f);
	return 0;
}

Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <utility>
#include <set>

using namespace std;

void chmax(string &a, string b) {
    if (a == "-") a = b;
    else if (a.size() < b.size()) a = b;
    else if (a.size() == b.size()) {
        if (a < b) a = b;
    }
}

long long match[10] = {2,5,5,4,5,6,3,7,6};
string dp[11000];

int main(){
    int N,M,t;
    int cnt, num;
    cin >> N >> M;
    vector<int> vi;
    for(int i = 0; i < M; i++){
        cin >> t;
        vi.push_back(t);
    }
    for(int i = 0; i < 11000; i++) dp[i] = "-";
    dp[0] = "";
    
    for(int i = 0; i <= N; i++){
        if(dp[i] == "-") continue;
        for(auto a: vi){
            chmax(dp[i+match[a-1]], dp[i] + (char)(a + '0'));
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 45056
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		if (a.equals("H"))
			if (b.equals("H"))
				System.out.println("H");
			else
				System.out.println("D");
		else
			if (b.equals("H"))
				System.out.println("D");
			else
				System.out.println("H");
	}
}

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

int A[200055];

int N;

bool isp(int X) {
	map<int, int> PQ;
	for(int i = 2; i <= N; i++) {
		if(A[i-1] < A[i]) continue;
		for(; !PQ.empty();) {
			auto it = prev(PQ.end());
			if(it->first < A[i]) break;
			PQ.erase(it);
		}
		for(int x = A[i]-1;; x--) {
			if(x < 0) return false;
			int k = 0;
			auto it = PQ.find(x);
			if(PQ.end() != it) {
				k = it->second;
				PQ.erase(it);
			}
			k++;
			if(k < X) {
				PQ.insert({x, k});
				break;
			}
		}
	}
	return true;
}

int getAns() {
	int s = 2, e = N; for(int m; s < e;) {
		m = (s+e) >> 1;
		if(isp(m)) e = m;
		else s = m+1;
	}
	return s;
}

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 1; i <= N; i++) cin >> A[i];

	{
		bool flag = true;
		for(int i = 1; i < N; i++)
			flag &= A[i] < A[i+1];
		if(flag) {
			puts("1");
			return 0;
		}
	}

	cout << getAns() << endl;
	return 0;
}

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

#define ll long long

using namespace std;

int main(){
    ll n,ele,f=1;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>ele;
        if(ele%2==0){
            if(ele%3==0 || ele%5==0);
            else  f=0;
        }
    }
    cout<<(f?"APPROVED":"DENIED")<<"\n";
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<998244353>;

//--------------------------- Solve ---------------------------//

mint dp[3005][3005];

void solve() {
    int N, S; cin >> N >> S;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= S; j++) {
            dp[i+1][j] += dp[i][j];
            if (j+A[i] <= S) {
                if (j == 0) dp[i+1][j+A[i]] += dp[i][j] * (i+1);
                else dp[i+1][j+A[i]] += dp[i][j];
            }
        }
    }

    mint ans = 0;
    for (int i = 0; i <= N; i++) {
        ans += dp[i][S];
    }

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 73996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0xfff;
const int maxn = 100005;
ll gcd(ll a, ll b)
{
	return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
int a[200] = {0};
int main()
{
    int x, n;
    cin >> x >> n;
    int b;
    for (int i = 1; i <= n;i++)
    {
        cin >> b;
        a[b]++;
    }
    int left=0, right=111;
    int i, j;
    for (i = x; i >= 1;i--)
    {
        if(!a[i]) {
            break;
        }
    }
    for ( j = x; j <= 100;j++)
    {
        if(!a[j]) {
            break;
        }
    }
    if(j-x < x-i)
        cout << j <<endl;
    else if(j-x == x-i)
        cout << i <<endl;
    else {
        cout << i<< endl;
    }
    return 0;
}

Measured memory_bytes: 3616
X, Y, Z, K = map(int, input().split())
*A, = sorted(map(int, input().split()), reverse=True)
*B, = sorted(map(int, input().split()), reverse=True)
*C, = sorted(map(int, input().split()), reverse=True)
AB = [A[x] + B[y] for y in range(Y) for x in range(X)]
AB.sort(reverse=True)
AB = AB[:K]
ABC = [AB[x] + C[z] for z in range(Z) for x in range(len(AB))]
ABC.sort(reverse=True)
for k in range(K):
    print(ABC[k])


Measured memory_bytes: 160512