akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split())
w=[int(input()) for i in range(m)]
s=0
k=[]
for i in w:
    j=i-s-1
    if j==-1:
        print(0)
        exit()
    k.append(i-s-1)
    s=i+1
k.append(n-s)
fib=[1,1,2]
for i in range(max(k)-2):
    fib.append(fib[-1]+fib[-2])
ans=1
for i in k:
    ans*=fib[i]
print(ans%1000000007)

Measured memory_bytes: 460020
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
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;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
void foreach_permutation(int n, std::function<void(int *)> f) {
  int indexes[n];
  for (int i = 0; i < n; i++) indexes[i] = i;
  do {
    f(indexes);
  } while (std::next_permutation(indexes, indexes + n));
}

int main() {
    string w;
    cin >> w;
    set<char> st;
    rep(i,w.size()) {
        st.insert(w[i]);
    }
    bool judge = false;
    for(auto s: st) {
        if (count(w.cbegin(), w.cend(), s)%2 == 0) {
            judge = true;
        } else {
            judge = false;
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes" << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
  char ch[250]={0};
  char a[250] ={0};
  int h;
  int i,j,k,l,n,m;
 
 
  while(1){
    i=0;
    while(1){
       
      scanf("%c",&ch[i]);
      if(ch[i] == '\n') {    
    break;
      }
       
      i++;
    }
    
    if ( i == 1 && ch[0] == '-' ) break;
 
    //  printf("%d",i);
     
    scanf("%d",&m);
     
    for(j=0;j<m;j++){
      scanf("%d", &h );
       
      for(k=0;k<i-h;k++) {
    a[k] = ch[h+k];
    //    printf("a[%d] = ch[%d]の%c\n",k ,h+k,ch[h+k]);
      }
      for(k=0;k<h;k++){
    a[i-h+k] = ch[k];
    //   printf("a[%d] = ch[%d]の%c\n",i-h+k,k,ch[k]);
      }
      for(k=0; k<i; k++){
    ch[k] = a[k];
    // printf("ch[%d] = a[%d]の%c\n",k,k,a[k]);
      }
    }
    for(k=0;k<i;k++) {
      printf("%c",ch[k]);
    }
    printf("\n");
      scanf("%c",&ch[0]);
  }
   
   
  return 0;
   
}



Measured memory_bytes: 2052
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
using namespace std;

int main () {
  long long int n, k;
  cin >> n >> k;
  if (n == k) cout << 0;
  else if (n < k) {
    if (n < labs(n - k)) cout << n;
    else cout << labs(n - k);
  }
  else{
    if (n % k == 0) cout << 0;
    else {
      n = n % k;
      cout << abs(n - k);
    }
  }
}

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

#define ll long long

string s, t;
int ans=0;

void solve() {
    cin >> s >> t;
    for(int i=0; i<s.length(); ++i) {
        if(s[i]!=t[i])
            ans++;
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    solve();
    return 0;
}

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

using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]!='h'||s[i+1]!='i'){
			cout<<"No"<<endl;
			return 0;
		}
		else{
			i++;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

int main(void) {
    int a, b;
    char buf[16];
    
    while(scanf("%d %d", &a, &b) != EOF) {
        sprintf(buf, "%d", a+b);
        printf("%lu\n", strlen(buf));
    }
    
    return 0;
}

Measured memory_bytes: 616
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!int;
  auto k = readln.chomp.to!int;
  auto x = readln.chomp.to!int;
  auto y = readln.chomp.to!int;

  if (n < k)
    writeln(x * n);
  else
    writeln(x * k + y * (n - k));
}


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

int main()
{
    string n;
    cin >> n;
    int size = (int)n.size();
    int sum = 0;

    for (size_t i = 0; i < size; i++)
    {
        sum += n[i] - '0';
    }

    if (stoi(n) % sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
while True:
    N, x = map(int, input().split())
    if N == 0 and x == 0:
        break
    count = 0
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            for k in range(j + 1, N + 1):
                if i + j + k == x:
                    count += 1
    print(count)



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

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

int main()
{
  long long N;
  cin >> N;
  long long ans = 0;
  long long min_ans = 1001001001001;
  vector<int64_t> divisor_num = divisor(N);
  rep(i, divisor_num.size())
  {
    long long num = divisor_num[i] + N / divisor_num[i];
    min_ans = min(min_ans, num);
  }

  cout << min_ans - 2 << endl;

  return 0;
}

Measured memory_bytes: 384
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

ans = 0
cnt = 0
for j in range(n):
    for i in range(m):
        ans += a[j][i] * b[i]
    if (ans + c) > 0:
        cnt += 1
    ans = 0

print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <tuple>

using namespace std;

int main()
{
    int abc[3];
    cin >> abc[0] >> abc[1] >> abc[2];
    sort(abc, abc+3, greater<int>());

    if(abc[0]==7 && abc[1]==5 && abc[2]==5) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#define mp make_pair 
#define x first
#define y second
#define ll long long
using namespace std;

int n,a,b,ct,ct2,ct3,x;
int main(){
	scanf("%d%d%d",&n,&a,&b);
	for (int i=1;i<=n;i++){
		scanf("%d",&x);
		if (x <= a)
		ct+=1;
		else
		if (x <= b)
		ct2+=1;
		else
		ct3+=1;
	}
	printf("%d\n",min(min(ct,ct2),ct3));
	return 0;
}

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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  int n; cin >> n;
  int a = 0,b = 0,c = 0,d = 0;
  rep(i,n){
    string s; cin >> s;
    if(s[0] == 'A') a++;
    else if(s[0] == 'W') b++;
    else if(s[0] == 'T') c++;
    else d++;
  }
  cout << "AC x " << a << endl;
  cout << "WA x " << b << endl;
  cout << "TLE x " << c << endl;
  cout << "RE x " << d << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  vector<string> buff;
  string str,kill;
  int y = 0, x = 0;
  while(getline(cin,str), str!="END_OF_TEXT") buff.push_back(str);
  while(getline(cin,str), str[0] != '-'){
    //printf("command: %c (x=%d, y=%d)\n",str[0],x,y);
    //REP(i,buff.size()) cout << buff[i] << endl;
    switch(str[0]){
    case 'a':
      x = 0;
      break;
    case 'e':
      x = buff[y].size();
      break;
    case 'p':
      if(y==0) x = 0;
      else{
	x = 0;
	y--;
      }
      break;
    case 'n':
      if(y==buff.size()-1) x=0;
      else{
	x = 0;
	y++;
      }
      break;
    case 'f':
      if(x < buff[y].size()) x++;
      else if(y != buff.size()-1){
	x = 0;
	y++;
      }
      break;
    case 'b':
      if(x > 0) x--;
      else if(y != 0){
	y--;
	x = buff[y].size();
      }
      break;
    case 'd':
      if(x != buff[y].size()){
	buff[y].erase(buff[y].begin()+x);
      }else if(y != buff.size()-1){
	buff[y] += buff[y+1];
	buff.erase(buff.begin() + y + 1);
      }
      break;
    case 'k':
      if(x != buff[y].size()){
	kill = buff[y].substr(x);
	buff[y] = buff[y].substr(0,x);
      }else if(y != buff.size()-1){
	buff[y] += buff[y+1];
	buff.erase(buff.begin() + y + 1);
	kill = "\n";
      }
      break;
    case 'y':
      if(kill != ""){
	if(kill == "\n"){
	  string s = buff[y].substr(x);
	  buff[y] = buff[y].substr(0,x);
	  buff.insert(buff.begin() + y + 1, s);
	  y++; x=0;
	}else{
	  buff[y].insert(x, kill);
	  x += kill.size();
	}
      }
      break;
    }
  }
  REP(i,buff.size()) cout << buff[i] << endl;
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <cmath>

using namespace std;

int main(){
  int N;
  cin>>N;
  if(N==1){cout<<"Hello World"<<endl;return 0;}
  else{
    int A,B;
    cin>>A>>B;
    cout<<A+B<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _CRT_SECURE_NO_WARNINGS
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define Pi pair<int,int>
#define IINF 1e9
#define LINF 1e18
#define vi vector<int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 0, 1,0,-1 };
int dy[] = { 1, 0,-1,0 };

void solve() {
	string s;
	cin >> s;
	int count = 0,S = 0;
	rep(i, s.length()) {
		if (s[i] == 'S') {
			S++;
		}
		else {
			if (S != 0) {
				S--;
				count++;
			}
		}
	}
	P(s.length() - (count * 2));
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define show(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)
#else
#define show(...) 42
#endif


#define f first
#define s second
#define endl "\n"
#define pb push_back
#define  oo 0x3f3f3f3f
#define limit 1000000007
#define int long long int
#define mod(x,m) ((x%m+m)%m)
#define ll long long
#define all(v) v.begin(),v.end()
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repb(i,a,b) for(int i=(a);i>=(b);i--)
#define fastio std::ios::sync_with_stdio(false)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define input_from_file  freopen("input.txt", "r", stdin);

const int INF = 1e18;

int n;
int arr[20][20];
int pre[1<<18];
int dp[1<<18];

void getans(int i,vector<int> &v,int score,int mask,int group){
  if(i == v.size()){
    dp[mask] = max(dp[mask],score+pre[group]);
    return;
  }
  getans(i+1,v,score,mask,group);
  getans(i+1,v,score,mask|(1<<v[i]),group|(1<<v[i]));
}

signed main(){

  //input_from_file;
  cin>>n;

  memset(arr,0,sizeof arr);
  memset(pre,0,sizeof pre);
  for(int i=0;i<(1<<n);i++) dp[i] = -1*INF;

  dp[0] = 0;
  for(int i=0;i<n;i++)
  for(int j=0;j<n;j++) cin>>arr[i][j];

  for(int mask=0;mask<(1<<n);mask++){
    for(int i=0;i<n;i++) if(mask&(1<<i)){
     for(int j=i+1;j<n;j++) if(mask&(1<<j))
      pre[mask] += arr[i][j];
    }
  }

  for(int mask=0;mask<(1<<n);mask++){
    vector<int> v;
    for(int i=0;i<n;i++) if(!(mask&(1<<i))) v.push_back(i);
    getans(0,v,dp[mask],mask,0);
  }

  cout<<dp[(1<<n)-1]<<endl;
}


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

void solve_A(){
	//AAAAAAAAAA
	int a,b;
	cin >> a >> b;
	cout << max(0,a-2*b) << endl;
}

void solve_B(){
	//BBBBBBBBBB
	int n,i,d[100],sum=0,sum2=0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> d[i];
		sum+=d[i];
		sum2+=(d[i]*d[i]);
	}
	cout << (sum*sum-sum2)/2 << endl;
}

void solve_C(){
	//CCCCCCCCCC
	int n,i,ans=1;
	char s[100005];
	cin >> n >> s;
	for(i=1;i<n;i++) if(s[i-1]!=s[i]) ans++;
	cout << ans << endl;
}

void solve_D(){
	//DDDDDDDDDD
	long long n,i,j,l,m,ans=0;
	vector<long long> g;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> l;
		g.push_back(l);
	}
	sort(g.begin(),g.end());
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			m=g[i]+g[j];
			ans += (n-(lower_bound(g.begin(),g.end(),m)-g.begin()));
		}
	}
	cout << n*(n-1)*(n-2)/6 - ans << endl;
}

int main() {
	// your code goes here
	solve_A();
	//solve_B();
	//solve_C();
	//solve_D();
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = 0
T = 0
R = 0
W = 0
for i in range(N):
    S = input()
    if S == 'AC':
        A += 1
    elif S == 'WA':
        W += 1
    elif S == 'TLE':
        T += 1
    elif S == 'RE':
        R += 1


print('AC x',A)
print('WA x',W)
print('TLE x',T)
print('RE x',R)

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int a, b, c, d;
  std::cin >> a >> b >> c >> d;
  if (a >= c)
    swap(a, c), swap(b, d);
  int ans = 0;
  if (b >= c)
    ans = min(b - c, d - c);
  print(ans);
}


Measured memory_bytes: 256
N, K = map(int, input().split())
W = [int(input()) for _ in range(N)]


def check(p):
    n = 0
    for i in range(K):
        s = 0
        while s + W[n] <= p:
            s += W[n]
            n += 1
            if n == N:
                return True
    return False


left = 0
right = 100000 * 100000
while right - left > 1:
    mid = (left + right) // 2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)



Measured memory_bytes: 9560
#include<algorithm>
#include<iostream>
#include<vector>
#include <cmath>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> w(n);
	int right = 0;
	int left = 0;
	int mindata = 100;

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

	for (int i = 0; i < n; i++){
		left += w[i];
		right -= w[i];
		mindata =min(abs(right - left), mindata);	
	}

	cout << mindata << endl;
	return 0;
}

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

int main(void){
    int x, y, z;
    string r = "No";
    cin >> x >> y;
    z = 4*x;
    for(int i=0; i<=x; i++) {
        if(z == y) {
            r = "Yes";
            break;
        }  
        z -= 2;        
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define MAX_N 110

int main() {
    int N,X,Y,Z;
    cin >> N;
    int A[MAX_N],B[MAX_N],C[MAX_N];

    cin >> X;
    for(int i=0;i<X;i++) cin >> A[i];
    cin >> Y;
    for(int i=0;i<Y;i++) cin >> B[i];
    cin >> Z;
    for(int i=0;i<Z;i++) cin >> C[i];

    set<int> ans;
    set<int> nA;
    for(int i=1;i<=N;i++) nA.insert(i);
    for(int i=0;i<X;i++) nA.erase(A[i]);

    for(int i=0;i<Z;i++){
        for(auto na : nA){
            if(C[i] == na) ans.insert(C[i]);
        }
    }

    for(int i=0;i<Z;i++){
        for(int j=0;j<Y;j++){
            if(C[i] == B[j]) ans.insert(C[i]);
        }
    }

    cout << ans.size() << endl;
}


Measured memory_bytes: 3100
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

V<ll> a;
VV<int> e;
V<ll> mnlast;
V<ll> ans;

void dfs(int now,int pre){
  ll st;
  auto itr = lower_bound(mnlast.begin(),mnlast.end(),a[now]);
  if(itr!=mnlast.end()){
    st=*itr;
    *itr=a[now];
  }

  ans[now]=distance(mnlast.begin(),lb(all(mnlast),LINF));
  for(auto&& i:e[now]){
    if(i==pre)continue;

    dfs(i,now);
  }

  if(itr!=mnlast.end())*itr=st;

  return ;
}

/*template<typename T>
vector<T> LIS(vector<T>& a){
  int N=a.size();
  vector<T> mnlast(N,LINF);//INFを入れる
  for(int i=0;i<N;i++){
    auto itr = upper_bound(mnlast.begin(),mnlast.end(),a[i]);//広義、狭義にしたいときはlower
    if(itr!=mnlast.end())*itr=a[i];
  }

  return mnlast;
}*/

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  a.resize(n);

  rep(i,0,n){
    cin>>a[i];
  }

  e.assign(n,V<int>(0));
  rep(i,0,n-1){
    int aa,b;cin>>aa>>b;
    aa--;b--;
    e[aa].pb(b);
    e[b].pb(aa);
  }
  mnlast.assign(n+1,LINF);

  ans.assign(n,0);

  dfs(0,-1);

  rep(i,0,n)cout<<ans[i]<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 30280
#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<char> data(4);
    int flg = 0;

    for (int i=0; i<4; i++) {
        cin >> data.at(i);
    }

    for (int i = 0; i<3; i++) {
        for (int j = i+1; j<4; j++) {
            if (data.at(i) == data.at(j)) {
                flg++;
            }
        }
    }

    if (flg == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return  0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    string S;
    cin >> S;

    if(S == "ABC")
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;

}

Measured memory_bytes: 3588
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int[] pst = new int[3];
		int[] drk = new int[2];
				for (int i = 0; i < 3; i++) {
					pst[i] = sc.nextInt();
				}
				
				for (int i = 0; i < 2; i++) {
					drk[i] = sc.nextInt();
				}
		
		Arrays.sort(pst);
		Arrays.sort(drk);
		
		System.out.println(pst[0] + drk[0] - 50);
	}

}



Measured memory_bytes: 26164
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();
            int z = in.nextInt();
            int k = in.nextInt();
            long[] a = new long[x];
            for (int i = 0; i < x; i++) {
                a[i] = in.nextLong();
            }
            long[] b = new long[y];
            for (int i = 0; i < y; i++) {
                b[i] = in.nextLong();
            }
            long[] c = new long[z];
            for (int i = 0; i < z; i++) {
                c[i] = in.nextLong();
            }
            long[] bc = new long[y * z];
            for (int i = 0; i < y; i++) {
                for (int j = 0; j < z; j++) {
                    bc[i * z + j] = b[i] + c[j];
                }
            }
            Arrays.sort(bc);
            int min_k_yz = Math.min(k, y * z);
            long[] bc_higher = new long[min_k_yz];
            for (int i = 0; i < min_k_yz; i++) {
                bc_higher[i] = bc[bc.length - 1 - i];
            }
            long[] abc = new long[x * min_k_yz];
            for (int i = 0; i < x; i++) {
                for (int j = 0; j < min_k_yz; j++) {
                    abc[i * min_k_yz + j] = a[i] + bc_higher[j];
                }
            }
            Arrays.sort(abc);
            for (int i = 0; i < k; i++) {
                System.out.println(abc[abc.length - 1 - i]);
            }
            in.close();
        }

    }
}



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

int min_num = 2000000000;
int max_profit = -1000000000;
int val;
int n;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> val;
    max_profit = max(val - min_num, max_profit);
    min_num = min(min_num, val);
  }
  cout << max_profit << endl;
  return 0;
}


Measured memory_bytes: 3096
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var sum = 0;
        
        for (var a = 1; a < n; ++a)
        {
            sum += (int) Math.Ceiling((decimal) n / a) - 1;
        }
        
        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 27548
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <set>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
const int maxn=100100;
int par[maxn];
int ranka[maxn];

void init(int n)
{
    for(int i=1;i<=n;i++)
    {
        par[i]=i;
        ranka[i]=0;
    }
}
int finda(int x)
{
    if(par[x]==x)
        return x;
    else
        return par[x]=finda(par[x]);
}
void unite(int x,int y)
{
    x=finda(x);
    y=finda(y);
    if(x==y) return;
    if(ranka[x]<ranka[y])
        par[x]=y;
    else{
        par[y]=x;
        if(ranka[x]==ranka[y])
            ranka[x]++;
    }
}

int main()
{
    int n,m;
    int x,y,z;
    scanf("%d%d",&n,&m);
    init(n);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&x,&y,&z);
        unite(x,y);
    }
    int sum=0;
    for(int i=1;i<=n;i++)
        if(par[i]==i)
            sum++;
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<string> s(N,"");
    map<string, int> m;
    for(int i=0; i<N; i++){
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
        if(m.count(s[i])){
            m[s[i]]++;
        }else{
            m[s[i]]=1;
        }
    }

    long long ans=0;
    for(auto i = m.begin(); i!=m.end(); i++){
        int x = i->second;
        ans+=(long long)x*(x-1)/2;
    }
    cout << ans << endl;

}

Measured memory_bytes: 18176
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    int S = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        S += a[i];
    }
    vector<int> div;
    for(int i = 1; i * i <= S; ++i){
        if(S % i == 0){
            div.emplace_back(i);
            if(i * i != S)  div.emplace_back(S / i);
        }
    }
    int ans = 1;
    for(int d : div){
        vector<int> foo(n);
        for(int i = 0; i < n; ++i){
            foo[i] = a[i] % d;
        }
        sort(foo.begin(), foo.end());
        vector<ll> lsum(n + 1), rsum(n + 1);
        lsum[0] = 0, rsum[0] = 0;
        for(int i = 0; i < n; ++i){
            lsum[i + 1] = lsum[i] + foo[i];
            rsum[i + 1] = rsum[i] + (d - foo[i]);
        }
        ll times = INF;
        for(int i = 1; i < n; ++i){
            chmin(times, max(lsum[i], rsum[n] - rsum[i]));
        }
        if(times > k)   continue;
        chmax(ans, d);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

///////////////////////////


	
int main() {
	ll a, b, c, d;
	cin >> a>> b>> c>> d;

	if (abs(a - c) <= d) { cout << "Yes"; }
	else if (abs(a - b) <= d && abs(b - c) <= d) { cout << "Yes"; }
	else { cout << "No"; }
	
	system("PAUSE");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


template< typename T >
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);
  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

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


int main() {
  ll H, W; cin >> H >> W;
  int N = H*W;
  vector<string> field(H);
  rep(i, H) cin >> field[i];

  WeightedGraph<int> G(N);

  rep(h, H) rep(w, W) rep(dir, 2) {
    int nh = h + dx[dir];
    int nw = w + dy[dir];
    if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;

    int u = W*h + w;
    int v = W*nh + nw;
    int c = (field[h][w] == field[nh][nw]) ? 0 : 1;
    G[u].push_back(edge<int>(v, c));
  }

  V dist = dijkstra(G, 0);
  int ans = dist[N-1] / 2;
  if (field[0][0] == '#' || field[H-1][W-1] == '#') ans++;

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


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

int main()
{
	char n[4];
	cin>>n[0]>>n[1]>>n[2];
	n[3]='\0';
	
	for(int i=0;i<3;i++){
		if(n[i]=='1') n[i]='9';
		else if(n[i]=='9') n[i]='1';
	}
	
	cout<<n<<endl;
	
	return 0;
}


Measured memory_bytes: 384
//encoding:utf-8
#include <iostream> //c++
#include<time.h> //時間にかんして
#include<stack> //スタックに関して　最新のデータから捨てる
#include<queue> //キューに関して　最古のデータから捨てる
#include<math.h>

#define ll long long
using namespace std;

int a,b,c,k;
int ans = 0;

int main(){
  cin>>a>>b>>c>>k;
  if(max(a,max(b,c))==a){
    ans = pow(2,k)*a+b+c;
  }
  else if(max(a,max(b,c))==b){
    ans = pow(2,k)*b+a+c;
  }
  else{
    ans= pow(2,k)*c+a+b;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
package main

import "fmt"

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

	for i := -500; i <= 500; i++ {
		for j := -500; j <= 500; j++ {
			if five(i) - five(j) == x {
				fmt.Println(i,j)
				return
			}
		}
	}
}

func five(l int) int{
	return l*l*l*l*l
}



Measured memory_bytes: 1756
# -*- coding: utf-8 -*-


def xcheck(n):
	
    m = int(n**.5)
    return 1 if abs(m*m - n) < 1e-6 else 0
#	if(1):
#		#兵法数なら
#		return 1
#	return 0

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
d=hoge[1]

#listx = [[0]*d]*n
listx = [[0 for i in range(d)] for j in range(n)]

for i in range(n):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	#print(hoge)
	for j in range(d):
		listx[i][j] = hoge[j]

sum = 0
for i in range(n):
	for j in range(i+1,n):
#		print("{} {}".format(i,n))
		tmp=0
		for k in range(d):
#			print(pow((listx[i][k]-listx[j][k]),2))
			tmp += pow((listx[i][k]-listx[j][k]),2)
#			print("{} {} tmp {}".format(listx[i][k],listx[j][k],tmp))

#		print("tmp")
#		print(tmp)
#		print(xcheck(tmp))
		sum += xcheck(tmp)

print(sum)




#print(min(n*a,b))

#print(n)
#print(a)
#print(b)




Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
vector<int> G[MAX];
int N,M;
int p[MAX];
bool visited[MAX];

set<int> A,B;
void dfs(int pos){
  if(visited[pos])return;
  visited[pos]=true;
  A.insert(pos);
  B.insert(p[pos]);
  for(int to:G[pos]){
    dfs(to);
  }
}

int main(){
  cin>>N>>M;
  for(int i=0;i<N;i++){
    cin>>p[i];
    p[i]--;
  }
  for(int i=0;i<M;i++){
    int x,y;
    cin>>x>>y;
    x--,y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  int ans=0;
  for(int i=0;i<N;i++){
    if(visited[i])continue;
    A.clear();
    B.clear();
    dfs(i);
    for(int x:A)ans+=B.count(x);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 18560
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
#include<string>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define inf 1000000007
#define int long long
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
struct edge{int to,cost;};
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
vector<edge> G[100005];
int d[114514];
int v,e,r;
void dijkstra(int k){
    priority_queue<P,vector<P>,greater<P> >que;
    fill(d,d+114000,inf);
    d[k]=0;
    que.push(P(0,k));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size(); i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
signed main(){
    cin>>v>>e>>r;
    rep(i,0,e){
        int a,b,c;cin>>a>>b>>c;
        G[a].push_back(edge{b,c});
    }
    dijkstra(r);
    rep(i,0,v){
        if(d[i]==inf)cout<<"INF"<<endl;
        else cout<<d[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 19596
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;


int main(int argc, char* argv[])
{
  ll a, b, h;
  std::cin >> a >> b >> h;

  ll ans = (a + b) * h / 2;
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//Hang in there!

using namespace std;


int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A + B >= C) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int fact[11000000];
Int revfact[11000000];
Int rev[11000000];

void init(){
    Int m = MOD;
    fact[0] = 1;
    revfact[0] = 1;
    rev[0] = 0;
    rev[1] = 1;
    for(int i = 1;i < 11000000;i++){
        fact[i] = fact[i-1] * i % m;
        if(i>1)rev[i] = MOD / i * (MOD-rev[MOD % i]) % MOD;
        revfact[i] = revfact[i-1] * rev[i] % MOD;
    }
}

Int nCk(Int n, Int k){
    if(n < k)return 0;
    return fact[n] * revfact[n-k] % MOD * revfact[k] % MOD;
}

Int ans;
Int n;
int main(){
    init();
    cin >> n;
    n /= 2;
    Int tmp = nCk(2*n, n);
    Int pow2 = 1;
    for(Int i = 0;i < n;i++){
//        cout << ans << " " << tmp << endl;
        ans += nCk(2*n, i) * tmp % MOD;ans %= MOD;
        tmp += nCk(2*n-i-1,n);
        tmp += nCk(2*n-i-1,n-i-1);
        tmp %= MOD;
        tmp *= rev[2];
        tmp %= MOD;
        ans += pow2 * nCk(2*n, 2*n-i);
        pow2 *= 2;
        pow2 %= MOD;
    }
    ans += nCk(2*n, n) * pow2 % MOD;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 258680
<?php
class Line {
    protected $lineData;
    protected $pointer;
    public function __construct(array $line)
    {
        $this->lineData = $line;
        $this->pointer = 0;
        $this->count = count($line);
    }

    public function next()
    {
        if ($this->count > $this->pointer) {
            return $this->lineData[$this->pointer++];
        }
        return false;
    }
}

class IOW {
    /**
     * @return Line
     */
    public static function nl()
    {
        $str = trim(fgets(STDIN));
        return new Line(explode(' ', $str));
    }

    public static function out($data)
    {
        print_r ($data . PHP_EOL);
    }
}

$line = IOW::nl();
$n = $line->next();
$m = $line->next();

$start = 1;
$end = $n;
for ($i = 1; $i <= $m; $i++) {
    $line = IOW::nl();
    $start = max($start, $line->next());
    $end = min($end, $line->next());
}

$result = $end - $start + 1;
IOW::out($result > 0 ? $result : 0);

Measured memory_bytes: 4604
a=[]
for _ in range(5):
    a.append(int(input()))

#a = [29 ,20 ,7 ,35 ,120 ]
#a = [101 ,86 ,119 ,108 ,57 ]
#a = [123 ,123 ,123 ,123 ,123]
#a = [10 ,80 ,110 ,70 ,90]

def ofooo(n):
    return int(round(n+4.9, -1))

m=0
res = 0
for n in a:
    aa = ofooo(n)
    res += aa
    if m < aa-n:
        m = aa-n
print(res - m)


Measured memory_bytes: 3060
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())
    ret = 0
    for n in range(N):
        l, r = list(map(int, sys.stdin.readline().split()))
        ret += r - l + 1

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> to(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    
    int ans = 0;
    vector<int> way;
    for(int i = 1; i < n; i++) way.push_back(i);
    do{
        bool path = true;
        rep(i, n - 1){
            bool reach = false;
            if(i == 0){
                for(int t : to[i]){
                    if(t == way[i])reach = true;
                }
            }else{
                for(int t : to[way[i - 1]]){
                    if(t == way[i])reach = true;
                }
            }
            if(!reach)path = false;
        }
        if(path)ans++;
    }while(next_permutation(way.begin(), way.end()));
    cout << ans << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
key = a[0]
a_syurui = []
count = 1
for i in a[1:]:
    if key == i:
        count += 1
    else:
        a_syurui.append(count)
        count = 1
        key = i
a_syurui.append(count)
a_syurui.sort()
if len(a_syurui) <= k:
    print(0)
else:
    for i in range(len(a_syurui)-k):
        ans += a_syurui[i]
    print(ans)


Measured memory_bytes: 25748
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1<<30;
const long long LINF = 1LL << 60;
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    cin.tie(nullptr) ;
    ios::sync_with_stdio(false) ;

    ll t;
    cin >> t;
    for (ll h = 1; h <= 3500;h++){
        for (ll n = 1; n <= 3500;n++) {
            ll g = gcd(t, gcd(h, n));
            ll l = (t * h * n) / g;
            ll u = 4 * (l / t);
            u -= (l / h + l / n);
            if (u <= 0) continue;
            if (l % u != 0) continue;
            cout << h << " " << n << " " << l/u << "\n";
            //cerr << "DEBUG [4/N] :" << (long double)(4.0 / t) << "\n";
            //cerr << "DEBUG:"
            //     << (long double)(1.0 / h) + (long double)(1.0 / n) +
            //            (long double)(1.0 / (l / u))
            //     << "\n";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();

        int count = 0;
        for(int i=0; i<=a; i++) {
            for(int j=0; j<=b; j++) {
                for(int k=0; k<=c; k++) {
                    if((500*i)+(100*j)+(50*k) == x) {
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
        sc.close();
    }
}


Measured memory_bytes: 22996
N = gets.to_i
A = 2.times.map do
  gets.split.map(&:to_i)
end

result = []

N.times do |i|
  u = A[0][i]
  if i != 0
    u = A[0][0..i].inject(:+)
  end

  result << u + A[1][i...N].inject(:+)
end

p result.max

Measured memory_bytes: 1788
#include <stdio.h>

int main()
{
  char a[110], b[110], c[110];
  int n;
  
  scanf("%d%s%s%s", &n, a, b, c);
  int x = 0;
  for (int i = 0; i < n; ++i)
  {
    if (a[i] == b[i])
    {
      if (c[i] != a[i]) ++x;
    }
    else
    {
      if (c[i] == a[i] || c[i] == b[i]) ++x; else x += 2;
    }
  }
  printf("%d\n", x);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int A,B;
  string S;
  cin >> A >> B >> S;
  if(S.size() != A+B+1){
    cout << "No" << endl;
  }for(int i=0; i<A; i++){
    if(S[i] == '-'){
      cout << "No" << endl;
      return 0;
    }
  }for(int j=A+1; j<S.size(); j++){
    if(S[j]=='-'){
      cout << "No" << endl;
      return 0;
    }
  }
  if(S[A] == '-'){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
<?php

$rooms     = array_fill_keys(range(1, 10), 0);
$floors    = array_fill_keys(range(1, 3), $rooms);
$buildings = array_fill_keys(range(1, 4), $floors);

fscanf(STDIN, '%d', $n);

for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, '%d %d %d %d', $b, $f, $r, $v);

    $buildings[$b][$f][$r] += $v;
}

foreach ($buildings as $b =>  $floors) {
    foreach ($floors as $f => $rooms) {
        $building[$b][$f] = sprintf(' %s%s', implode(' ', $rooms), PHP_EOL);
    }
    $tenant[] = implode('', $building[$b]);
}

echo implode(str_repeat('#', 20) . "\n", $tenant);

Measured memory_bytes: 6660
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<fstream>
#include<stdio.h>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

#define PI  3.141592
//----------------------------------------


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




int main(void)
{
	int n, k;

	cin >> n >> k;

	if (n == k) cout << "Yes" << endl;

	else cout << "No" << endl;


}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n,k,m,i,j,l=0;
	scanf("%d %d",&n,&k);
	m=((n-1)*(n-2)/2);
	
	if(k>m)printf("-1");
	else
	{
		printf("%d\n",(n-1+m-k));
		for(i=1;i<n;i++)
		{
			printf("%d %d\n",i,n);
		}
		
		for(i=1;i<n;i++)
		{
			for(j=i+1;j<n;j++)
			{
				k++;
				if(l<=(m-k))printf("%d %d\n",i,j);
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 128
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

cnt = n-1
i = 0
ans = 0
while cnt:
    if i == 0:
        cnt -= 1
        ans += A[i]
        i += 1
    else:
        if cnt < 2:
            ans += A[i]*cnt
            cnt = 0
        else:
            ans += A[i]*2
            cnt -= 2
            i += 1
print(ans)


Measured memory_bytes: 94188
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int H, M;
	double A, B, pi, rad_a, rad_b, rad, C;

	cin >> A >> B >> H >> M;

	pi = acos(-1);

	rad_a = pi / 360 * (60 * H + M);
	rad_b = pi / 30 * M;
	rad = abs(rad_a - rad_b);

	C = sqrt(pow(A, 2) + pow(B, 2) - 2 * A * B * cos(rad));

	cout << fixed << setprecision(9) << C << endl;

	return 0;
}


Measured memory_bytes: 4156
a,b = map(int, input().split())
if (b%2 != 0):
  print("No")
  exit()
max = 4*a
if (b <= max):
  for _ in range(a+1):
    if(max==b):
      print("Yes")
      exit()
    max-=2
  print("No")
else:
  print("No")

Measured memory_bytes: 9180