akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(typeof(a) i=a;i!=(b);++i)
#define CLEAR(a,v) memset(a,v,sizeof(a))
#define SORT(a) sort(a,a+sizeof(a)/sizeof(a[0]))
#define ALL(v) (v).begin(),(v).end()
using namespace std;

int main(){
    int N;
    cin >> N;
    map<int, int> mp;
    REP(i,N){
        int k;
        cin >> k;
        mp[k]++;
    }
    pair<int,int> itr = *mp.begin();
    int min = itr.first;
    int minc = itr.second;
    if(minc > 2){
        cout << "Impossible" << endl;
        return 0;
    }
    N -= minc;
    int dist = min;
    while(mp[++dist] >= 2){
        N -= mp[dist];
    }
    dist--;
    if(N != 0 || dist % 2 == minc % 2 || min * 2 < dist){
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
INF = float("inf")


def Dijkstra(n, s, g, mode):  # (頂点数，始点，グラフ，モード)を引数に
    dist = [INF] * n  # distを初期化
    dist[s] = 0  # 始点の距離は0
    hq = [(0, s)]  # (距離，頂点)で管理
    while hq:  # BFSと同様に探索
        d, v = heappop(hq)  # 最小距離とその頂点を取得
        if dist[v] < d:  # すでに最小になっている時はcontinue
            continue
        for w, *a in g[v]:  # そうでない時は隣接点への重みとその頂点を順に取得
            nd = d + a[mode]
            if dist[w] > nd:  # 最小になっていな開ければ更新してhqにpush
                dist[w] = nd
                heappush(hq, (nd, w))
    return dist


def main():
    n, m, s, t = map(int, input().split())
    s -= 1
    t -= 1
    g = [[] for _ in range(n)]
    for _ in range(m):
        u, v, a, b = map(int, input().split())
        u -= 1
        v -= 1
        g[u].append((v, a, b))
        g[v].append((u, a, b))

    d_yen = Dijkstra(n, s, g, 0)
    d_sunnk = Dijkstra(n, t, g, 1)

    ans = [0] * n
    cost = float("inf")
    for i in range(n-1, -1, -1):
        cost = min(cost, d_yen[i] + d_sunnk[i])
        ans[i] = 10 ** 15 - cost
    print(*ans, sep='\n')


if __name__ == "__main__":
    main()


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

int main(){
    char s[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++)
            cin>>s[i][j];
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++)
            if(i==j) cout<<s[i][j];
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.141592653589793238

int main() {
	int N;
	cin >> N;
	set<int> A;
	rep(i, N) {
		int a;
		cin >> a;
		if (A.count(a)) {
			A.erase(a);
		}
		else {
			A.insert(a);
		}
	}
	cout << A.size() << endl;
	return 0;
}

Measured memory_bytes: 4864
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    a = input()
    if ord(a)-65<=25:
        print('A')
    else:
        print('a')
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 61692
#include<bits/stdc++.h>
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
int MAX = 1e15;
signed main(){
    int n,m,s,t; cin >> n >> m >> s >> t;
    --t,--s;
    vector<vector<piii>>edge(n);
    rep(i,m){
        int f,t,a,b; cin >> f >> t >> a >> b;
        --f,--t;
        edge[f].push_back(piii(t,pii(a,b)));
        edge[t].push_back(piii(f,pii(a,b)));
    }
    vector<vector<int>>d(n,vector<int>(2,INF));
    d[t][1] = 0; d[s][0] = 0;
    priority_queue<pii,vector<pii>,greater<pii>>que;
    que.push(pii(0,t));
    while(!que.empty()){
        int now = que.top().second;
        int maxi = que.top().first;
        que.pop();
        rep(i,edge[now].size()){
            int next = edge[now][i].first;
            if(d[next][1]  > maxi + edge[now][i].second.second){
                d[next][1] = edge[now][i].second.second + maxi;
                que.push(pii(d[next][1],next));
            }
        }
    }
    que.push(pii(0,s));
    while(!que.empty()){
        int now = que.top().second;
        int maxi = que.top().first;
        que.pop();
        rep(i,edge[now].size()){
            int next = edge[now][i].first;
            if(d[next][0]  > maxi + edge[now][i].second.first){
                d[next][0] = edge[now][i].second.first + maxi;
                que.push(pii(d[next][0],next));
            }
        }
    }
    priority_queue<pii,vector<pii>,greater<pii>>ans;
    rep(i,n)ans.push(pii(d[i][0]+(d[i][1]),i));
    rep(i,n){
        while(true){
            if(ans.top().second >= i)break;
            else ans.pop();
        }
        cout << MAX - ans.top().first << endl;
    }
}




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

int Knapsack(int N, int capa, int value[], int weight[]) {
  int table[100][10000][2];
  int max = 0;

  for(int i = 0; i < N; i++) {
    for(int j = 0; j <= capa; j++) {
      if(i == 0) {
        if(j-weight[i] >= 0) {
          table[i][j][0] = value[i];
          table[i][j][1] = weight[i];
        }
        else {
          table[i][j][0] = 0;
          table[i][j][1] = 0;
        }
      }
      else {
        if(j-weight[i] >= 0) {
          int x = table[i-1][j][0];
          int y = table[i-1][j-weight[i]][0]+value[i];
          if(x > y) {
            table[i][j][0] = x;
            table[i][j][1] = table[i-1][j][1];
          }
          else {
            table[i][j][0] = y;
            table[i][j][1] = table[i-1][j-weight[i]][1]+weight[i];
          }
        }
        else {
          table[i][j][0] = table[i-1][j][0];
          table[i][j][1] = table[i-1][j][1];
        }
      }

      if(i == N-1 && table[i][j][1] <= capa && max < table[i][j][0])
        max = table[i][j][0];
    }
  }

  return max;
}

// void Print01(int N, int table[100][10000][2], int weight[], int max_j) {
//   if(N-1 < 0) return;
//   else if(max_j == 1)
//     Print01(N-1, table, weight, max_j-weight[N-1]);
//   else
//     Print01(N-1, table, weight, max_j);
//   cout << table[N][max_j][1];
// }

// void Knapsack01(int N, int capa, int value[], int weight[]) {
//   int table[100][10000][2];
//   int max = 0, max_j;

//   for(int i = 0; i < N; i++) {
//     for(int j = 0; j <= capa; j++) {
//       if(i == 0) {
//         if(j-weight[i] >= 0) {
//           table[i][j][0] = value[i];
//           table[i][j][1] = 1;
//         }
//         else {
//           table[i][j][0] = 0;
//           table[i][j][1] = 0;
//         }
//       }
//       else {
//         if(j-weight[i] >= 0) {
//           int x = table[i-1][j][0];
//           int y = table[i-1][j-weight[i]][0]+value[i];
//           if(x > y) {
//             table[i][j][0] = x;
//             table[i][j][1] = 0;
//           }
//           else {
//             table[i][j][0] = y;
//             table[i][j][1] = 1;
//           }
//         }
//         else {
//           table[i][j][0] = table[i-1][j][0];
//           table[i][j][1] = 0;
//         }
//       }

//       if(i == N-1 && max < table[i][j][0]) {
//         max = table[i][j][0];
//         max_j = j;
//       }
//     }
//   }

//   Print01(N-1, table, weight, max_j);

//   return;
// }

int main() {
  int N, capa;
  int value[100], weight[100];

  cin >> N >> capa;
  for(int i = 0; i < N; i++)
    cin >> value[i] >> weight[i];

  cout << Knapsack(N, capa, value, weight) << endl;

  //Knapsack01(N, capa, value, weight);

  return 0;
}

Measured memory_bytes: 10888
#include <iostream>
#include <string>

using namespace std;

int main() {
	int N,L;
	cin >> N >> L;
	string s[N];
	for(int i=0; i<N; i++){
		cin >> s[i];
	}
	
	bool check=0;
	while(!check){
	for(int j=0; j<N; j++){
		bool flag=1;
		int cnt=j;
		while(flag==1 && cnt<N-1){
			if(s[cnt]>s[cnt+1]){
				swap(s[cnt],s[cnt+1]);
			}else{flag=0;}
		}
	}
	
	check=1;
	for(int i=0; i<N-1; i++){
		if(s[i]>s[i+1]){check=0; break;}
	}
	
	}
	
	for(int i=0; i<N; i++){
		cout << s[i];
	}
	cout << endl;
	return 0;
}

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

int main(void){
    int n, a[100], s;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = n-1; i >= 0; i--) {
        cout << a[i];
        if(i != 0) cout << ' ';
    }
    cout << endl;
    return 0;
}


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


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

using namespace std;

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


const long long MAX_N = 1 << 17;

long long dat[2 * MAX_N - 1];

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

ll pow(ll a, ll b) {
	vector<ll> d = vector<ll>((ll)(log(b)) + 2);
	d[0] = a;
	rep(i, 1, d.size()) d[i] = d[i - 1] * d[i - 1];
	ll ret = 1;
	rep(i, 0, log(b) + 1) {
		if (b & 1 << i) ret *= d[i];
	}
	return ret;
}


//E
int main(void) {
	ll N, W;
	cin >> N >> W;
	vector<ll> w = vector<ll>(N), v = vector<ll>(N);
	rep(i, 0, N) cin >> w[i] >> v[i];
	vector<vector<ll>> dp = vector<vector<ll>>(N + 1, vector<ll>(1e5 + 1,1e10));
	rep(i, 0, N)dp[i][0] = 0;
	rep(i, 1, N + 1) {
		rep(j, 1, 1e5 + 1) {
			if (j < v[i - 1]) dp[i][j] = dp[i - 1][j];
			else {
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
			}
		}
	}
	ll ans = 0;
	rep(i, 0, 1e5 + 1) {
		if (dp[N][i] <= W) ans = max(ans, i);
	}
	cout << ans << endl;
}


Measured memory_bytes: 80256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <random>
#include <sstream>
#include <stack>
#include <deque>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

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

int main() {
  cin >> H >> W;
  string S[H];
  rep(i,H) cin >> S[i];
  int cc = 0;
  rep(i,H) rep(j,W) {
    if (S[i][j] == '#') cc++;
  }
  queue<pair<int, pii>> q;
  int used[H][W] = {};
  q.push(pair<int, pii>(0, pii(0, 0)));
  used[0][0] = 1;
  while (!q.empty()) {
    auto p = q.front(); q.pop();
    int c = p.first;
    int y = p.second.first;
    int x = p.second.second;
    if (y == H-1 && x == W-1) {
      cout << H*W - (c+1) - cc << endl;
      return 0;
    }
    rep(i,4) {
      if (y + dy[i] >= 0 && y + dy[i] < H && x + dx[i] >= 0 && x + dx[i] < W && S[y + dy[i]][x + dx[i]] == '.' && !used[y + dy[i]][x + dx[i]]) {
        q.push(pair<int, pii>(c+1, pii(y + dy[i], x + dx[i])));
        used[y + dy[i]][x + dx[i]] = 1;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    d=parseMap(split(readline()))
    ans=0
    for i in 1:n
        for j in i+1:n
            ans+=d[i]*d[j]
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 115044
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  ll f1, f2, s1, s2;
  if(a1 * t1 > b1 * t1) {
    f1 = a1;
    f2 = a2;
    s1 = b1;
    s2 = b2;
  } else {
    f1 = b1;
    f2 = b2;
    s1 = a1;
    s2 = a2;
  }
  ll d1, d2;
  d1 = f1 * t1 - s1 * t1;
  d2 = f2 * t2 - s2 * t2;
  if(d1 + d2 > 0) {
    cout << 0 << "\n";
    return 0;
  }
  if(d1 + d2 == 0) {
    cout << "infinity" << "\n";
    return 0;
  }
  ll diff = - d1 - d2;
  ll turns = d1 / diff;
  ll ans;
  if(d1 % diff == 0) {
    ans = turns * 2;
  } else {
    ans = turns * 2 + 1;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
struct data{
    int a,b;
};

//小さい順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}


int main(){
    int a[5];
    for(int i=0;i<5;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<5;i++){
        if(a[i]==0){
            printf("%d",i+1);
            return 0;
        }
    }
}


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

typedef struct {
	int a, b;
}Job;

bool compare(Job j1, Job j2) {
	if (j1.b < j2.b) {
		return true;
	}
	else if (j1.b == j2.b) {
		if (j1.a < j2.a) return true;
	}
	return false;
}

int main()
{
	int end = 0;
	int n; bool ispossible = true;
	vector<Job> j;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a,b;
		cin >> a >> b;
		j.push_back({ a,b });
	}
	sort(j.begin(), j.end(), compare);
	for (int i = 0; i < n; i++) {
		end+=j[i].a;
		if (end > j[i].b) ispossible = false;
	}
	if (ispossible) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 2420
K, N = map(int, input().split(' '))
A = list(map(int, input().split()))
m = 0

for i in range(N):
    if i == N - 1:
        temp = (K + A[0]) - A[N - 1]
    else:
        temp = A[i + 1] - A[i]
    m = max(m, temp)

print(K - m)

Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#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 showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n){ cin >> a[i]; }

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i+1; j < n; j++)
        {
            for (int k = j+1; k < n; k++)
            {
                if (a[i] == a[j]) continue;
                if (a[j] == a[k]) continue;
                if (a[k] == a[i]) continue;
                
                if (a[i] + a[j] <= a[k]) continue;
                if (a[j] + a[k] <= a[i]) continue;
                if (a[k] + a[i] <= a[j]) continue;
                //cout << i << j << k << endl;
                ans++;
            }
        }
    }
    cout << ans << endl;
    
}



Measured memory_bytes: 3608
//header{{{
//#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/math/common_factor_rt.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
  
using namespace std;
//using namespace boost;
//using namespace multiprecision;  

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

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

    int l;
    cin >> l;

    long double len = l / 3.0;

    cout << Fixed << len * len * len << '\n';

    return 0;
}


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

int main() {
  string a;
  int r = 700;
  cin >> a;
  
  if (a[0] == 'o') r += 100;
  if (a[1] == 'o') r += 100;
  if (a[2] == 'o') r += 100;
  
  cout << r << endl;
}

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

int main(){
	int n, sum;
	cin >> n >> sum;
	int cnt = 0;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n - i; j++){
			for(int k = 0; k <= n - j; k++){
				int a = i*10000 + j * 5000 + k * 1000;
				if(a == sum && (i+j+k) == n){
					printf("%d %d %d\n", i, j, k);
					return 0;
				}
			}	
		}
	}
	printf("-1 -1 -1\n");
	return 0;
}

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

int main(void){
    string s;
    int a = 1, b = 0, c = 0;

    cin >> s;
    char ch[4];

    char_traits<char>::copy(ch, s.c_str(), s.size() + 1);
    char x = ch[0];
    char y;
    for(int i = 1; i < 4; i++){
        if(x == ch[i]){
            a++;
        } else {
            if(y == '\0'){
                y = ch[i];
                b++;
            } else {
                if(y == ch[i]){
                    b++;
                } else {
                    c++;
                }
            }
        }
    }
    if(a == b && c == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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


int main(){

int  a ,b;
cin >> a >> b;
int n = max(a,b);
rep(i,n){
  int A = abs(a-i);
  int B = abs(b-i);
  if(A == B){
    cout << i<<endl;
    return 0;}
}
cout <<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  long long n,m; cin >> n >> m;
  if(abs(n-m) >= 2){
    cout << 0 << endl;
    return 0;
  }
  else if(abs(n-m) == 1){
    long long g,l,G=1,L=1;
    g = max(n,m);
    l = min(n,m);
    for(long long i=1;i<=g;i++) G = G * i % 1000000007;
    for(long long j=1;j<=l;j++) L = L * j % 1000000007;
    cout << G * L % 1000000007 << endl;
    return 0;
  }
  else{
    long long N=1,M=1;
    for(long long i=1;i<=n;i++) N = N * i % 1000000007;
    for(long long j=1;j<=m;j++) M = M * j % 1000000007;
    cout << N * M * 2 % 1000000007 << endl;
    return 0;
  }
}

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String H = "H";
        String D = "D";
        if(a.equals(H)){
        	if(b.equals(H)) System.out.println("H");
        	else if(b.equals(D)) System.out.println("D");
        }else if(a.equals(D)){
        	if(b.equals(H)) System.out.println("D");
        	else if(b.equals(D)) System.out.println("H");
        }
	}

}


Measured memory_bytes: 21844
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

answer = []
for i in range(1, 2 ** 10):
  tmp = 0
  for j in range(N):
    cnt = 0
    for k in range(10):
      if (i >> k) & 1 and F[j][k]:
        cnt += 1
    tmp += P[j][cnt]
  answer.append(tmp)
  
print(max(answer))

Measured memory_bytes: 42092
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		String s = sc.next();
		char[] c = s.toCharArray();
		long n = parseLong(s);
		sc.close();
		long sum=0;
		for (i = 0; i < c.length; i++) {
			sum += c[i] - '0';;
		}
		out.println(n%sum==0?"Yes":"No");
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define ll u_int64_t
#define rep(i, n) for (int i=0; i<n; i++)
 
using namespace std;
const double PI = acos(-1);
using Graph = vector<vector<int>>;
 
int main() {
	string s, t;
	cin >> s >> t;
	if (s.size() + 1 == t.size()) {
		rep(i, s.size()) {
			if (s[i] != t[i])
			{
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
		return 0;
	}
	else
		cout << "No" << endl;	
}


Measured memory_bytes: 3608
use std::io;


fn main() {
    let n = read_one::<usize>();
    let dn = read::<usize>();
    let mut ans: usize = 0;
    for i in 0..n { for j in 0..n {
        if i == j { continue; }
        ans += dn[i] * dn[j];
    }}
    println!("{}", ans / 2);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a; i<ll(b); i++) 
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}
//int:~2e9   小数:double

int main(){
  int n;
  cin >>n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  vector<int> m(n);
  m[0]=p[0];
  rep(i,n){
    if(i==0) continue;
    m[i] = min(m[i-1],p[i]);
  }
  int ans=0;
  rep(i,n){
    if(p[i]==m[i]) ans++;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
def main():
  import bisect
  n=int(input())
  A=sorted(list(map(int,input().split())))
  B=list(map(int,input().split()))
  C=sorted(list(map(int,input().split())))
  lc=len(C)
  ans=0
  for b in B:
    ma = bisect.bisect_left(A, b)
    mc = lc-bisect.bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 29372
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

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

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


int main(){
    ll N, K;
    cin >> N >> K;

    ll res = 0;
    if(K == 0){
        cout << N * N << endl;
        return 0;
    }
    for(ll b = K+1; b <= N; b++){
        ll x = N / b;
        ll y = N - b * x;
        res += (b - K) * x + max(y - K + 1, 0LL);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

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

  int N = S.size();
  ll ans = 0;
  REPR(i,N-1){
    int cnt = pow(2,i);
    int X = pow(2,i);
    ans+=pow(10,N-1-i)*(S.at(i)-'0')*X;
    int k = 1;
    while(cnt+X<=pow(2,N-1)){
      cnt+=X;
      ans+=pow(10,N-1-i-k)*(S.at(i)-'0')*X;
      X*=2;
      k++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import Data.List
import Data.Char
import Data.Maybe
import qualified Data.ByteString.Char8 as BS8

dig_impl 0 r = r
dig_impl n r = dig_impl (div n 10) (r + 1)

dig n = dig_impl n 0

cnt n r
    | dig n == 1 = n
    | dig n == 2 = 9
    | dig n == 3 = n - 90
    | dig n == 4 = 909
    | dig n == 5 = n - 9090
    | dig n == 6 = 90909

main :: IO ()
main = do
    n <- fst . fromJust . BS8.readInteger <$> BS8.getLine

    print $ cnt n n


Measured memory_bytes: 380
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

ll a, b, x;

int main()
{
    cin >> a >> b >> x;
    if (a > 0) {
        cout << b / x - (a - 1) / x << endl;
    } else {
        cout << b / x + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


int main() {
	float n,temp;
	string tani;
	float sum = 0;
	cin >> n;
	repz(i, n) {
		cin >> temp >> tani;
		if (tani == "BTC")sum += temp * 380000;
		else sum += temp;
	}

	cout << sum << endl;

	system("pause");
	return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <cstdio>

typedef long long ll;

int main() {
	int a, b, c, k;
	scanf("%d%d%d%d", &a, &b, &c, &k);
	int ans = 0;
	if(k) ans += std::min(a, k), k -= std::min(a, k);
	if(k) k -= std::min(b, k);
	if(k) ans -= std::min(c, k), k -= std::min(c, k);
	printf("%d", ans);
	return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  vector<int> l, r, u, d;
  int n, w, h;
  cin >> w >> h >> n;
  l.push_back(0);
  r.push_back(w);
  u.push_back(0);
  d.push_back(h);
  for (int i = 0; i < n; i++) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      l.push_back(x);
    } else if (a == 2) {
      r.push_back(x);
    } else if (a == 3) {
      u.push_back(y);
    } else {
      d.push_back(y);
    }
  }
  cout << max(0, *min_element(r.begin(), r.end()) - *max_element(l.begin(), l.end())) *
          max(0, *min_element(d.begin(), d.end()) - *max_element(u.begin(), u.end())) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007

int main() {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int ans=0;
    rep(i,100) {
        int j=i+1, cc=0;
        if (a<j && j<=b) cc++;
        if (c<j && j<= d) cc++;
        if (cc==2) ans++;
    }
    printf("%d\n", ans);
}


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

int main() {
    int q; cin >> q;
    while (q--) {
        long long a, b; cin >> a >> b;
        auto check = [&](long long k) {
            return (k+1)/2 * (k+1 - (k+1)/2) < a * b;
        };
        auto binary_search = [&](long long ok, long long ng) {
            assert(check(ok) == true);
            assert(check(ng) == false);
            while (abs(ng - ok) > 1) {
                long long mid = (ng + ok) / 2;
                (check(mid) ? ok : ng) = mid;
            }
            return ok;
        };
        if (a == b) cout << 2 * (a - 1) << endl;
        else cout << binary_search(0, 2e9) - 1 << endl;
    }
    return 0;
}

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

int main()
{
  cin.tie(0);
  cin.sync_with_stdio(0);
  
  int n, m;
  cin >> n >> m;
  
  string s;
  cin >> s;
  
  vector<int> dp(n + 1, -1);
  deque<int> pos { 0 };
  for(int i = 1; i <= n; ++i) {
    while(pos.size() && i - pos[0] > m)
      pos.pop_front();
    if(pos.size() && s[i] == '0') {
      dp[i] = i - pos[0];
      pos.emplace_back(i);
    }
  }
  
  if(dp.back() == -1)
    return cout << -1, 0;
  vector<int> ans;
  for(int i = n; i > 0; i -= dp[i])
    ans.emplace_back(dp[i]);
  reverse(ans.begin(), ans.end());
  for(auto x : ans)
    cout << x << ' ';
}


Measured memory_bytes: 1484
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;


    
    public class Main{
        public static int function(int[] Arr,int K)
        {
            int N=Arr.length;
            int count=0;
            for(int i=0;i<N;i++)
            {
                if(Arr[i]>=K)
                    count++;
            }
            return count;
        }
        

   public static void main (String[] args)  throws IOException{

      Scanner sc=new Scanner(System.in);
      int N=0;
      int K=0;
      if(sc.hasNextInt())
      {
          N=sc.nextInt();
          K=sc.nextInt();
      }
      
          int[] Arr=new int[N];
          for(int i=0;i<N;i++)
          {
              Arr[i]=sc.nextInt();
          }
          
      
      System.out.println(function(Arr,K));
     
      
   
   }
   
}
   

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

#define abs(a) ((a)>0?(a):-(a))
#define pb push_back
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.14159265358979323846
#define endl "\n"
#define int long long int
int gcd(int a,int b){for(int c;b;c=a,a=b,b=c%b);return a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
// int MOD = 1000000000;

signed main(){
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    int T;
    T = 1;
    int k=0;
    while(T>0){
        int R;
        cin >> R;
        cout << 2*PI*R << endl;
    T--;
    }
    return 0;
}

Measured memory_bytes: 3792
#include <stdio.h>

int main(void){
    char S[10];
    scanf("%s",S);

    if(S[0]==S[1]){
        if(S[2]==S[3]){
            if(S[0] != S[2]){
                if(S[0] != S[3]){
                    if(S[1]!= S[2]){
                        if(S[1]!=S[3]){
                            printf("Yes");
                        }else{
                            printf("No");
                    }}else{
                        printf("No");
                }}else{
                    printf("No");
            }}else{
                printf("No");
        }}else{
            printf("No");
    }}else if(S[0]==S[2]){
                if(S[1]==S[3]){
                    if(S[0]!=S[1]){
                        if(S[0]!=S[3]){
                            if(S[2]!=S[3]){
                                if(S[2]!=S[1]){
                                    printf("Yes");
                                }else{
                                    printf("No");
                            }}else{
                                printf("No");
                        }}else{
                            printf("No");
                    }}else{
                    printf("No");
                }}else{
                    printf("No");
            }}else if(S[0]==S[3]){
                if(S[1]==S[2]){
                    if(S[0]!=S[1]){
                        if(S[0]!=S[2]){
                            if(S[3]!=S[1]){
                                if(S[3]!=S[2]){
                                    printf("Yes");
                                }else{
                                    printf("No");
                            }}else{
                                printf("No");
                        }}else{
                            printf("No");
                    }}else{
                        printf("No");
                }}else{
                    printf("No");
            }}else{
            printf("No");
            }
    return 0;
}

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

using namespace std;

int n, m ,q;

struct quad
{
    int a;
    int b;
    int c;
    int d;
};

quad q_n[52];
vector<int> atual_array;

int ans, max_ans = 0;
void next_array()
{   
    if (atual_array[n - 1] < m)
    {
        atual_array[n - 1]++;
    }
    else
    {
        int id_change = n - 1;
    
        if (atual_array[id_change] == m)
        {
            while (atual_array[id_change - 1] == m)
            {
                id_change--;
            }
            for (int i = n - 1; i > id_change; i--)
                atual_array[i] = atual_array[id_change - 1] + 1;
            atual_array[id_change] = atual_array[id_change - 1] + 1;
            atual_array[id_change - 1]++;
        }
    }
    
}
int main()
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(0);

    cin >> n >> m >> q;

    for (int i = 0 ; i < q;i++)
        cin >> q_n[i].a >> q_n[i].b >> q_n[i].c >> q_n[i].d;

    for (int i = 0; i < n; i++)
        atual_array.push_back(1);

    while (atual_array[0] < m)
    {
        ans = 0;
        for (int i = 0 ; i < q;i++)
        {
            if (atual_array[q_n[i].b - 1] - atual_array[q_n[i].a - 1] == q_n[i].c)
                ans+=q_n[i].d;
        }
        if (ans > max_ans)
            max_ans = ans;
        next_array();
    }

    ans = 0;
    for (int i = 0 ; i < q;i++)
    {
        if (atual_array[q_n[i].b - 1] - atual_array[q_n[i].a - 1] == q_n[i].c)
            ans+=q_n[i].d;
    }
    if (ans > max_ans)
        max_ans = ans;

    cout << max_ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 2000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int n;
map<int, int> wow;
int main() {
	cin >> n;
	REP(i, n) {
		int b;
		cin >> b;
		wow[b]++;
	}
	wow[0]++;
	int grid[25] = {};
	if (wow[0] == 1) {
		grid[0]++;
	}
	else if (wow[0] >= 2) {
		cout << 0 << endl;
		return 0;
	}
	if (wow[12] == 1) {
		grid[12]++;
	}
	else if (wow[12] >= 2) {
		cout << 0 << endl;
		return 0;
	}
	int now = 0;
	for(int i = 1;i <= 11;++i) {
		if (wow[i] == 1) {
			if (now == 0) {
				grid[i]++;
			}
			else {
				grid[24 - i]++;
			}
			now++;
			now %= 2;
		}
		else if (wow[i] == 2) {
			grid[i]++;
			grid[24 - i]++;
		}
		else if (wow[i] >= 3) {
			cout << 0 << endl;
			return 0;
		}
	}
	int ans = 25;
	int back = -10000;
	for (int i = 0;i < 25;++i) {
		if (grid[i]) {
			ans = min(ans, i - back);
			back = i;
		}
	}
	back = 24;
	for (int i = 23;i >= 0;--i) {
		if (grid[i]) {
			ans = min(ans, back-i);
			back = i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define dd second
#define mp make_pair
#define pb push_back
#define ff first
#define dd second
#define pp pair<int,int>
using namespace std;

main()
{
    ios_base::sync_with_stdio(false);
    string s; cin >> s;
    for(int i = 1; i < s.size(); ++i)
    {
        if(s[i] == 'C' and s[i-1] == 'A')
        {
            cout << "Yes" << endl; exit(0);
        }
    }
    cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_que<int> pque;//これは大きい順
//typedef priority_que<int, vector<int>, greater<int>> pque;//これは小さい順


int main(){
	int n,m;
	cin  >> n >> m;
	if(n==m) cout << "Yes" << endl;
	else cout << "No" << endl;


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int k,a,b,i,s,flag=0;
  scanf("%d",&k);
  scanf("%d %d",&a,&b);
  s=k;
  for(i=0;i<b;i++){
    if(a<=s&&s<=b){
      flag++;
      break;
    }
    s+=k;
  }
  if(flag==0){
    printf("NG\n");
  }else{
    printf("OK\n");
  }
  return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll ceil(ll a, ll b) {  // a÷b以上の最小の整数
    if(b == 0) {
        return 0;
    }
    return (a+b-1)/b;
}
 
int main() {
    ll n, d;
    cin >> n >> d;

    out(ceil(n, 2*d+1));
    
    
    re0;
}

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

int main()
{
  ll H, W;
  cin >> H >> W;
  vector<vector<char>> ans(H + 2, vector<char>(W + 2, '#'));
  for (ll i = 0; i < H; ++i) {
    for (ll j = 0; j < W; ++j) {
      cin >> ans.at(i + 1).at(j + 1);
    }
  }
  for (ll i = 0; i < H + 2; ++i) {
    for (ll j = 0; j < W + 2; ++j) {
      cout << ans.at(i).at(j);
    }
    cout << "\n";
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long LL;
const int MAXN=1e5+5;
int n;
vector<int> g[MAXN*2];
int d1[MAXN],d2[MAXN];

void dfs(int rt,int fa,int d,int dist[])
{
    dist[rt]=d;
    for(int x:g[rt])
    {
        if(x!=fa)
            dfs(x,rt,d+1,dist);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
            g[i].clear();
        int u,v;
        for(int i=0;i<n-1;i++)
        {
            cin>>u>>v;
            u--;v--;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        dfs(0,-1,0,d1);
        dfs(n-1,-1,0,d2);
        int ans=0;
        for(int i=0;i<n;i++)
        {
            if(d1[i]<=d2[i])  ++ans;
            else --ans;
        }
        if(ans>0)
            cout<<"Fennec"<<endl;
        else
            cout<<"Snuke"<<endl;
    }
    return 0;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
const int N = 666;
const int mod = 1e9 + 7;
int f[N][N], g[N], s[N];
int n, K, to[N];
inline int A(int x, int y){
	return x + y - (x + y >= mod ? mod : 0);
}
inline int M(int x, int y){
	return 1LL * x * y % mod;
}
int main(){
	cin>>n>>K;
	n <<= 1;
	int u, v;
	for(int i = 1;i <= K; i++){
		scanf("%d%d", &u, &v);
		to[u] = v;
		to[v] = u;
	}
	g[0] = 1;
	for(int i = 1;i <= n; i++){
		s[i] = (!to[i]) + s[i-1];
		if(i > 1)g[i] = M(i - 1, g[i-2]);
	}
	for(int l = 1;l <= n; l++){
		if(to[l]){
			if(to[l] < l)continue;
			bool fl = 1;
			for(int k = l + 1;k < to[l]; k++)
				if(to[k] && (to[k] > to[l] || to[k] < l))fl = 0;
			f[l][to[l]] = fl ? g[s[to[l]]-s[l-1]] : 0;
		}
		for(int r = max(l + 1, to[l] + 1); r <= n; r++){
			bool fl = 1;
			for(int k = l + 1;k <= r; k++){
				if(to[k] && (to[k] > r || to[k] < l))fl = 0;
			}
			if(!fl)continue;
			int F = g[s[r]-s[l-1]];
			for(int p = l + 1;p < r; p++){
				F = A(F, mod - M(f[l][p], g[s[r]-s[p]]));
			}
			f[l][r] = F;
		}
	}
	int ans = 0;
	for(int i = 1;i <= n; i++){
		for(int j = i + 1;j <= n; j++){
			ans = A(ans, M(f[i][j], g[s[n]-(s[j]-s[i-1])]));
//			printf("f[%d][%d]=%d\n", i, j, f[i][j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var s = Console.ReadLine().Trim();
        getAns(n, s);
    }
    static void getAns(int n, string s)
    {
        var rtow = n - s.Replace("R", "").Length;
        var ans = rtow;
        var wtor = 0;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'W') wtor++;
            else rtow--;
            ans = Min(ans, Max(wtor, rtow));
        }
        Console.WriteLine(ans);
    }
}


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

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
vector<int> G(100010);

int main() {
	int N,M;
	cin >> N >> M;
	vector<int> H(N);
	rep(i,N) cin >> H[i];
	rep(i,N) G[i] = 0;
	rep(i,M) {
		int at,bt;
		cin >> at >> bt;
		at--;bt--;
		chmax(G[at], H[bt]);
		chmax(G[bt], H[at]);
	}
	int ans = 0;
	rep(i,N) if(H[i] > G[i]) ans++;
	cout << ans << endl;


  return 0;
}


Measured memory_bytes: 4052
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N,K;
   cin >> N >> K;
   bool ok[N];
   memset(ok,false,sizeof(ok));
   for(int i =0;i<K;i++){
      int d;
      cin >> d;
      for(int j =0;j<d;j++){
         int a;
         cin >> a;
         a--;
         ok[a]=true;
      }
   }

   int ans =0;
   for(int i=0;i<N;i++){
      if(ok[i]==false)ans++;

   }

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


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

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

	bool jud = false;
	int tmp = 10;
	while(tmp < n){
		tmp *= 10;
	}
	if(tmp == n) jud = true;

	if(jud){
		cout << 10 << endl;
		return 0;
	} else{
		int ans = 0;
		while(n > 0){
			ans += n % 10;
			n /= 10;
		}
		cout << ans << endl;
	}
}//解説参考.

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 200010, M = 1000099;
int a[N];
int t[M];
int main() {;
	// freopen("in.txt", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
		t[a[i]] ++;
	}
	int mmax = *max_element(a, a + n);
	sort(a, a + n);
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int x = a[i];
		if (t[x] == 0)continue;
		for (int j = 2 * x; j < mmax + 10; j += x) {
			t[j] = 0;
		}
		if (t[x] == 1) cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 8380
#include <stdio.h>
int main(void){
    int height_1 = 0, height_2 = 0, height_3 = 0, height;
    char str[1024];
    for (int i = 0; i < 10; i++)
    {
        fgets(str, sizeof(str), stdin);
        sscanf(str, "%d", &height);
        
        if (height_1 < height)
        {
            height_3 = height_2;
            height_2 = height_1;
            height_1 = height;
        }
        else if (height_2 < height)
        {
            height_3 = height_2;
            height_2 = height;
        }
        else if (height_3 < height)
        {
            height_3 = height;
        }
    }
    printf("%d\n%d\n%d\n", height_1, height_2, height_3);
}



Measured memory_bytes: 2040
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s[0]=='S'){
        cout<<"Cloudy"<<endl;
    }
    else if(s[0]=='C'){
        cout<<"Rainy"<<endl;
    }
    else {
        cout<<"Sunny"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner a = new Scanner(System.in);
    String input = a.nextLine();
    String[] spt = input.split(" ");
    int num1 = Integer.parseInt(spt[0]);
    int num2 = Integer.parseInt(spt[1]);
    if(num1 < num2) 
    {
            System.out.println("a < b");
     }
    else if(num1 > num2) 
    {
            System.out.println("a > b");
    }
    else 
    {
            System.out.println("a == b");
    }
  }
}


Measured memory_bytes: 26208