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

using namespace std;

int main(){
  int n;
  int x;
  cin >> n >> x;
  vector<int> line(n);
  for(auto&i:line)cin>>i;
  sort(line.begin(),line.end());
  int ans = 0;
  for(auto&i:line){
    if(x>=i){
      ++ans;
      x -= i;
    }else{
      break;
    }
  }
  if(ans==n and x)--ans;
  cout << ans << endl;
}

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

int main() {
    int N, K; cin >> N >> K;
    vector<long long> h(N);
    for (int i = 0; i < N; ++i) cin >> h[i];
    sort(h.begin(), h.end());

    long long res = 1LL<<60;
    for (int i = 0; i+K-1 < N; ++i) res = min(res, h[i+K-1] - h[i]);
    cout << res << endl;
}


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

int main(){
    ll n,q;
    ll tmp;
    cin>>n;
    ll sum=0;
    map<ll,ll> list;
    map<ll,ll>::iterator iter;
    map<ll,ll>::iterator iter2;

    rep(i,n){
        cin>>tmp;
        if (iter = list.find(tmp); iter != end(list) ) {//ある場合
            list[tmp]++;
            // std::cout << iter->second << std::endl;
        } else {//ない場合
            list.insert(make_pair(tmp,1));
        }

        sum+=tmp;
    }

// rep(j,4){
//             cout<<list[j+1]<<endl;
//         }


    cin>>q;
    ll x,y;
    rep(i,q){
        cin>>x>>y;
        if (iter = list.find(x); iter != end(list) ) {//ある場合
            tmp=list[x];
            list[x]=0;
            sum += (y-x)*tmp;
            if (iter2 = list.find(y); iter2 != end(list) ) {//ある場合
                list[y] += tmp;
            } else {//ない場合
                list.insert(make_pair(y,tmp));
            }
         }

        cout<<sum<<endl;

        // cout<<"======"<<endl;

        // rep(j,4){
        //     cout<<list[j+1]<<endl;
        // }

        // cout<<"======"<<endl;
    }



}


Measured memory_bytes: 8644
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1000000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	int c;
	if(b < 10) c = 10*a+b;
	else if(b<100) c = 100*a+b;
	else c = 1000*a+100;
	int k = (int)pow((double)c, 0.5);
	if(k*k == c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 512
class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

mc = ModComb(210000, mod=mod)

used = {}
left, right = 0, 0
for i, a in enumerate(A):
    if a in used:
        right = i
        left = used[a]
        break
    used[a] = i

m = left + N - right
for k in range(1, N + 2):
    print((mc.nCk(N + 1, k) - mc.nCk(m, k - 1)) % mod)


Measured memory_bytes: 42500
#include <iostream>
#define ll long long
using namespace std;
int main(void){
    int N;cin>>N;
    ll a[N+10];
    a[0]=2;a[1]=1;
    for(int i=2;i<=N;i++)a[i]=a[i-1]+a[i-2];
    cout<<a[N];
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;

int num[100005];




int main()
{

	cin >> N;



	REP(i,N){
		int a;
		cin >> a;
		num[a]++;
		num[a+1]++;
		num[a+2]++;
	}

	int ans=-1;
	REP(i,100005){
		ans = max(ans,num[i]);
	}
	cout << ans;

}



Measured memory_bytes: 640
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b = LI()
print(a*b - a - b + 1)


Measured memory_bytes: 38256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
import math

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

R = i_i()

print(2*R * math.pi)

Measured memory_bytes: 9180
import java.util.Scanner;

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

    if ((x - a) >= 0 && (x - a) <= b) {
      System.out.println("YES");
    }
    else {
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 21844
N = int(input())
TS = []
for i in range(N):
    X, L = map(int, input().split())
    TS.append((X + L, X - L))
TS = sorted(TS)
cur = -10**10
ans = 0
for i in range(N):
    if TS[i][1] >= cur:
        ans+=1
        cur = TS[i][0]
print(ans)

Measured memory_bytes: 17756
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

typedef long long ll;

const ll inf = 1 << 30;
const ll mod = 1000000000 + 7;


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

	bool f = false;
	string b = a.substr(0, 1);
	for (int i = 1; i < a.length(); i++)
	{
		if (a.substr(i, 1) == b)
		{
			f = true;
		}

		b = a.substr(i, 1);
	}
	cout << (f ? "Bad" : "Good") << endl;
}

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

using namespace std;

const int N = 1e5 + 7;

int n, a[N], b[N], c[N];
long long ans = 0;


int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[i] = 0;
		for (int j = 0; j <= 30; j++) {
			if (a[i] >= (1 << j)) {
				b[i] = j;
			}
		}
		if (a[i] > (1 << b[i])) {
			c[i] = 1;
			b[i]++;
		} else {
			c[i] = 0;
		}
		ans += b[i];
	}
	int last = 0;
	for (int i = 0; i < n; i++) {
		// printf("%d %d\n", b[i], last);
		if (last >= b[i]) {
			ans -= b[i];
			if (c[i]) last = b[i] - 1;
			else {
				last = b[i];
			}
		} else {
			ans -= last;
			last = b[i];
		}
	}
	cout << ans << endl;
	return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int N;

int p2n(pair<int,int> p){
    int i = min(p.first, p.second), j = max(p.first, p.second);
    return N*(N-1)/2 - (N-i)*(N-i-1)/2-1 + j-i;
}

int main(void){
    cin >> N;
    int A[N][N-1];
    REP(i,N)REP(j,N-1){
        int a; cin >> a;
        a--;
        A[i][j] = a;
    }
    int n = N*(N-1)/2;
    vector<int> edge[n+1], deg(n+1,0);
    REP(i,N)REP(j,N-2){
        int from = p2n(pair<int,int>(i, A[i][j]));
        int to = p2n(pair<int,int>(i, A[i][j+1]));
        edge[from].push_back(to);
        deg[to]++;
    }

    REP(i,n){
        if(deg[i] == 0){
            edge[n].push_back(i);
            deg[i]++;
        }
    }

    if(edge[n].size() == 0){
        cout << -1 << endl;
        return 0;
    }
    
    int ans = 0;
    queue<pair<int,int>> q;
    q.push(P(n,0));
    while(q.size()){
        auto p = q.front(); q.pop();
        int node = p.first, day = p.second;
        chmax(ans, day);
        for(int e : edge[node]){
            deg[e]--;
            if(deg[e] < 0){
                cout << -1 << endl;
                return 0;
            }
            else if(deg[e] == 0){
                q.push(P(e, day+1));
            }
        }
    }

    REP(i,n){
        if(deg[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 33408
#include <algorithm> // sort
#include <iostream>
using namespace std;

int N, K, p[1010];

int main(){
    cin >> N >> K;
    for(int i = 0; i < N; ++i) cin >> p[i];
    sort(p, p + N);
    int ans = 0;
    for(int i = 0; i < K; ++i) ans += p[i];
    cout << ans << endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N], ans;

bool isgood(string str){
   bool good = true;
   for(auto &c: str){
      good &= (c == 'A' or c == 'G' or c == 'T' or c == 'C');
   }
   return good;
}

int32_t main(){_


   string s;
   cin>>s;

   n = sz(s);

   for (int i = 0; i < n; ++i)
   {
      string str = "";
      for (int j = i; j < n; ++j)
      {
         str += s[j];
         if(isgood(str)){
            smax(ans, j-i+1);
         }
      }      
   }

   cout<<ans;
   #warning make sure N size is correct!
   return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string s; cin >> s;
	string key = "keyence";
	bool is = false;
	rep(i, key.size()) {
		string a = s;
		string str = a.erase(i, s.size() - key.size());
		if (str == key)is = true;
	}
	cout << (is ? "YES" : "NO") << "\n";

	return 0;
}

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

bool isPalindrome (string s) {
	string t(s.rbegin(), s.rend());

	return s == t;
}

int main() {
	string s;
	cin >> s;
    int n = s.size();
	if (isPalindrome(s) && isPalindrome(s.substr(0, (n - 1) / 2)) && isPalindrome(s.substr((n + 1) / 2))) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}

}

Measured memory_bytes: 256
package main

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

func main() {
	n := getInt()
	as := make([]int, n)
	for i := range as {
		as[i] = getInt()
	}

	flags := make([]bool, n)
	ans := 0
	i := 0
	for {
		if flags[i] == true {
			ans = -1
			break
		} else if i == 1 {
			break
		}
		flags[i] = true
		i = as[i] - 1
		ans++
	}

	fmt.Println(ans)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 2048
//#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {
    int ans = -1;
    double a;
    double b;
    cin>>a>>b;
    for (double i = 1; i <= 100000; i+=1) {
        if(floor(i * 0.08) == a && floor(i * 0.1) == b){
            ans = i;
            break;
        }
    }

    cout<<ans<<endl;
}
//
// Created on 2020/03/07.
//



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int a[110000];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	int ans=1<<31-1;
	for(int i=1;i<=n-k+1;i++)
	{
		if(a[i]<0&&a[i+k-1]>0) ans=min(a[i+k-1]-a[i]+min(abs(a[i]),a[i+k-1]),ans);
		else if(a[i+k-1]<=0) ans=min(abs(a[i]),ans);
		else if(a[i]>=0) ans=min(a[i+k-1],ans);
	}
	printf("%d\n",ans);
	return 0;
}

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

int a, l;

int ma_f(vector<int> a) {

    sort(a.begin(), a.end(), greater<int>());

    int b = 1;
    rep(i, l-1) b *= 10;

    int res = 0;
    rep(i, l) {
        res += a[i] * b;
        b /= 10;
    }

    return res;

}

int mi_f(vector<int> a) {

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

    int res = 0;
    int b = 1;
    for (int i=l-1; i>=0; --i) {
        res += a[i] * b;
        b *= 10;
    }

    return res;
}

int main() {
    int a;
    while (cin >> a >> l, (a or l)) {

        int b = 1;
        rep(i, l-1) b *= 10;

        bool update=true;
        int cnt=1;

        vector<int> z;
        z.push_back(a);

        while (update) {
            vector<int> t(l);

            int tb = b;
            rep(i, l) {
                t[i] = a / tb;
                a -= (a / tb) * tb;
                tb /= 10;
            }

            a = ma_f(t) - mi_f(t);

            rep(i, z.size()) {
                if (a == z[i]) {
                    cout << i << ' ' << a << ' ' << cnt-i << endl;
                    update = false;
                    break;
                }
            }

            z.push_back(a);
            cnt++;
        }



    }
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define ci(n) cin >> n
#define co(n) cout << n << endl
using namespace std;

int main(){
  long a, b, c=0;
  cin >> a >> b;
  rep(i,0,a+1){
    rep(j,0,a+1){
      if(0<=b-i-j && b-i-j<=a) c++;
    }
  }
  co(c);
  
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint d, t, s;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> d >> t >> s;
	if(d <= s*t) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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

int main() {
  int W,H,N;
  cin>>W>>H>>N;
  vector<int>x(N);
  vector<int>y(N);
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>x.at(i)>>y.at(i)>>a.at(i);
  }
  vector<vector<int>>A(H,vector<int>(W));
  for(int i=0;i<N;i++){
    if(a.at(i)==1){
      for(int j=0;j<H;j++){
        for(int k=0;k<x.at(i);k++){
          A.at(j).at(k)=1;
        }
      }
    }
    if(a.at(i)==2){
      for(int j=0;j<H;j++){
        for(int k=x.at(i);k<W;k++){
          A.at(j).at(k)=1;
        }
      }
    }
    if(a.at(i)==3){
      for(int j=0;j<W;j++){
        for(int k=0;k<y.at(i);k++){
          A.at(k).at(j)=1;
        }
      }
    }
    if(a.at(i)==4){
      for(int j=0;j<W;j++){
        for(int k=y.at(i);k<H;k++){
          A.at(k).at(j)=1;
        }
      }
    }
  }
    int answer=0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(A.at(i).at(j)==0){
          answer++;
        }
      }
    }
    cout<<answer<< endl;
  }
    

Measured memory_bytes: 256
import math

EPS = 0.0000000001
PI = math.pi


def f(a, b, theta):
    if theta > PI / 2.0 - EPS:
        return 0.0

    if a * math.tan(theta) <= b:
        ret = a * a * b - a * a * a * math.tan(theta) / 2.0
    else:
        ret = b * b / math.tan(theta) * a / 2.0
    return ret


a, b, x = map(int, input().split())
ok = PI / 2.0
ng = 0.0
for i in range(1, 100001):
    mid = (ok + ng) / 2.0
    if f(a, b, mid) < x:
        ok = mid
    else:
        ng = mid
print(ok / PI * 180)

Measured memory_bytes: 3064
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    cin >> s;

    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
        cout << "Bad\n";
    else
        cout << "Good\n";

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <map>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
  int N,T;
  cin>>N>>T;
  int c,t,ans;
  bool first=true;
  for(int i=0;i<N;++i){
    cin>>c>>t;
    if(t<=T){
      if(first){
        ans=c;
        first=false;
      }
      else{
      ans=min(ans,c);
    }
    }
  }
  if(first){
    cout<<"TLE";
  }
  else{cout<<ans;}
return 0;
}

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

int main(void) {
	int N,K;
	cin >> N >> K;
	int h[N];
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}

	int dp[N+1];
	for (int i = 0; i < N + 1; i++) {
		dp[i] = 1000000000;
	}
	dp[0] = 0;
	for (int i = 1; i < N; i++) {
		for (int j = 1; j <= K; j++) {
			if (i < j) break;
			dp[i] = min(dp[i - j] + abs(h[i - j] - h[i]), dp[i]);
		}
	}
	cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<string, int> psi;
int N, t; psi p[200010];
unordered_map<string, int> dict;
bool cmp(psi a, psi b){
    if (a.second == b.second) return a.first < b.first;
    return a.second > b.second;
}
int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> N;
    for (int i = 0; i < N; i++){
        string str; cin >> str;
        if (!dict.count(str)){
            dict[str] = ++t;
            p[t].first = str;
        }
        p[dict[str]].second++;
    }
    sort(p + 1, p + t + 1, cmp);
    cout << p[1].first << '\n';
    for (int i = 2; i <= t; i++){
        if (p[i].second == p[i - 1].second) cout << p[i].first << '\n';
        else return 0;
    }
}

Measured memory_bytes: 25928
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,t,ans=0;
	cin>>a>>b>>t;
	cout<<t/a*b;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (ll& x : a) cin >> x;
  vector<vector<int>> g(n);
  rep(i, 0, m) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }

  // 木の数がkだったら、辺はk-1個必要
  // 頂点2つで辺を1本生やせるので、 (k - 1) * 2 > nだったら不可能
  vector<priority_queue<ll, vector<ll>, greater<ll>>> vert(n);
  vector<bool> used(n);
  auto dfs = [&](auto self, int v, int cnt) -> void {
    vert[cnt].emplace(a[v]);
    used[v] = true;
    for (int nv : g[v])
      if (!used[nv]) self(self, nv, cnt);
  };
  int cnt = 0;
  rep(i, 0, n) {
    if (!used[i]) {
      dfs(dfs, i, cnt);
      ++cnt;
    }
  }
  if ((cnt - 1) * 2 > n) {
    cout << "Impossible" << endl;
  } else {
    int need = (cnt - 1) * 2;
    ll ans = 0;
    rep(i, 0, cnt) {

      ll v = vert[i].top();
      if (need > 0) {
        ans += v;
        --need;
      }
      vert[i].pop();
    }
    if (need > 0) {
      vector<ll> nokori;
      rep(i, 0, cnt) {
        while (vert[i].size()) {
          ll v = vert[i].top();
          vert[i].pop();
          nokori.push_back(v);
        }
      }
      sort(nokori.begin(), nokori.end());
      rep(i, 0, need) ans += nokori[i];
    }
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 15088
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    abc = [chr(i) for i in range(97, 97+26)]
    N=ii()
    ans = ''
    while N:
        N-=1
        ans = abc[N%26] + ans
        N //= 26
    print(ans)




main()



Measured memory_bytes: 10024
#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////




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

	int n;
	cin >> n;
	long long res = 0;

	for (int i = 1; i <= n; i++) {
		long long temp = n / i;

		long long sommatoria = i * (temp * (temp + 1) / 2);
		res += (sommatoria);


	}


	cout << res << endl;



}


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

typedef long long int ll;
ll powk(ll a, ll n){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> d(k);
    for(ll i = 0;i < k;i++){
        cin >> d[i];
    }
    string s;
    for(ll i = n;i <= 10 * n;i++){
        s = to_string(i);
        bool f = true;
        for(ll j = 0;j < s.size();j++){
            for(ll m = 0;m < k;m++){
                if(s[j] - '0'== d[m]){
                    f = false;
                    break;
                }
            }
            if(!f){
                break;
            }
        }
        if(f){
            break;
        }
    }

    cout << s;

    return 0;
}

Measured memory_bytes: 256
def CardGame( c1, c2, c3 )
	cards = Array.new
	1.upto( 10 ){ |n|
		cards << n
	}
	cards.delete( c1 )
	cards.delete( c2 )
	cards.delete( c3 )

	mynum = c1 + c2
	count = 0
	cards.each{ |n|
		if mynum + n <= 20
			count += 1
		end
	}

	#p count
	if count >= 4 
		return "YES"
	else
		return "NO"
	end
end

answers = Array.new
while line = $stdin.gets
	nums = line.chomp.split( /\s/ ).map{ |i| i.to_i }
	answers << CardGame( nums[ 0 ], nums[ 1 ], nums[ 2 ] )
end
answers.each{ |a| puts a }


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

int  main()
{
	int n,i; cin >> n >> i;
	cout << n- i + 1;
	return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main() {
  int n, ma, mb;
  cin >> n >> ma >> mb;
  vector<int> a(n), b(n), c(n);
  int INF = 1000000;
  for(int i=0;i<n;i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  int lb = -1, ub = 15000;
  vector< vector< vector<int> > > dp;
  dp = vector<vector<vector<int> > >(42, vector<vector<int> >(402, vector<int>(402, INF)));
  dp[0][0][0] = 0;
  for(int i=1;i<=n;i++) {
    for(int j=0;j<=400;j++) {
      for(int k=0;k<=400;k++) {
        if(j-a[i-1] < 0 || k-b[i-1] < 0)
          dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k]);
        else {
          dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k]);
          dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-a[i-1]][k-b[i-1]]+c[i-1]);
        }
      }
    }
  }

  int mi = INF;
  for(int i=1;ma*i<=400&&mb*i<=400;i++) {
    mi = min(dp[n][ma*i][mb*i], mi);
  }
  if(mi == INF)
    cout << -1 << endl;
  else
    cout << mi << endl;
}


Measured memory_bytes: 29952
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string w;
  cin>>w;
  int a[26]{};
  for (int i = 0; i < w.size(); i++)
    {
        a[w[i]-'a']++;
    }
  for (int i = 0; i < 26; i++)
    {
      if (a[i]%2!=0)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(min(b, d) - max(a, c), 0) << "\n";
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    vii l(h,vi(w,0)),r(h,vi(w,0)),u(h,vi(w,0)),d(h,vi(w,0));
    rep(i,h)cin>>s[i];
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#')continue;
            if(j==0)l[i][j]=1;
            else l[i][j]=l[i][j-1]+1;
            if(i==0)u[i][j]=1;
            else u[i][j]=u[i-1][j]+1;
        }
    }
    for(int i=h-1;i>=0;i--){
        for(int j=w-1;j>=0;j--){
            if(s[i][j]=='#')continue;
            if(j==w-1)r[i][j]=1;
            else r[i][j]=r[i][j+1]+1;
            if(i==h-1)d[i][j]=1;
            else d[i][j]=d[i+1][j]+1;
        }
    }
    int ans=0;
    rep(i,h){
        rep(j,w){
            ans=max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3);
        }
    }
    cout<<ans<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 67200
#include <stdio.h>

int N, M, Q;
int L[271828], R[271828];
int p[114514], q[114514];

int kitaeri[512][512];
int asumisu[512];

int main(void) {
	int i, j;
	if (scanf("%d%d%d", &N, &M, &Q) != 3) return 1;
	for (i = 0; i < M; i++) {
		if (scanf("%d%d", &L[i], &R[i]) != 2) return 1;
	}
	for (i = 0; i < Q; i++) {
		if (scanf("%d%d", &p[i], &q[i]) != 2) return 1;
	}

	for (i = 0; i < M; i++) {
		kitaeri[L[i]][R[i]]++;
		kitaeri[R[i] + 1][R[i]]--;
		asumisu[R[i]]++;
	}
	/* 都市iを走る(すなわち、始点が都市1～i)、都市jが終点の列車は何本あるか */
	for (i = 1; i <= N + 1; i++) {
		for (j = 1; j <= N; j++) {
			kitaeri[i][j] += kitaeri[i - 1][j];
		}
	}
	/* 都市iを走る、都市j～都市Nが終点の列車は何本あるか */
	for (i = 1; i <= N; i++) {
		for (j = N - 1; j >= 1; j--) {
			kitaeri[i][j] += kitaeri[i][j + 1];
		}
	}
	/* 都市j～都市Nが終点の列車は何本あるか */
	for (i = N - 1; i >= 1; i--) {
		asumisu[i] += asumisu[i + 1];
	}

	for (i = 0; i < Q; i++) {
		/* 都市p[i]～都市q[i]が終点の列車 */
		int satorina = asumisu[p[i]] - asumisu[q[i] + 1];
		/* そのうち、都市(p[i]-1)を走っているもの */
		int zaasan = kitaeri[p[i] - 1][p[i]] - kitaeri[p[i] - 1][q[i] + 1];
		/* 都市p[i]～都市Nが始発で、都市p[i]～都市q[i]が終点の列車 */
		printf("%d\n", satorina - zaasan);
	}

	return 0;
}

/*

Nが小さい
それぞれの地点において、「どこまでの列車が何本あるか」という情報を積む

*/

/* ↓の方法は方程式が解なしになってダメそう */

/*

完全に含まれないとは？

a. L <= R < p
b. L      < p      <= R <= q
c. L      < p           <= q < R
d.          p <= L      <= q < R
e.          p           <= q < L <= R

完全に含まれるとは？

f.          p <= L <= R <= q

x1. L < p               : a+b+c
x2.     p <= L <= q     :       d  +f
x3.               q < L :         e

x4. R < p               : a
x5.     p <= R <= q     :   b      +f
x6.               q < R :     c+d+e

a : x1           + x4           = 1
b : x1                + x5      = 1
c : x1                     + x6 = 1
d :      x2                + x6 = 1
e :           x3           + x6 = 1
f :      x2           + x5      = 0

1 0 0 1 0 0 | 1
1 0 0 0 1 0 | 1
1 0 0 0 0 1 | 1
0 1 0 0 0 1 | 1
0 0 1 0 0 1 | 1
0 1 0 0 1 0 | 0

1 0 0  1 0 0 | 1
0 0 0 -1 1 0 | 0
0 0 0 -1 0 1 | 0
0 1 0  0 0 1 | 1
0 0 1  0 0 1 | 1
0 1 0  0 1 0 | 0

1 0 0  1 0  0 |  1
0 1 0  0 0  1 |  1
0 0 0 -1 1  0 |  0
0 0 0 -1 0  1 |  0
0 0 1  0 0  1 |  1
0 0 0  0 1 -1 | -1

1 0 0  1 0  0 | 1
0 1 0  0 0  1 | 1
0 0 1  0 0  1 | 1
0 0 0 -1 1  0 | 0
0 0 0 -1 0  1 | 0
0 0 0  0 1 -1 |-1

1 0 0  1  0  0 | 1
0 1 0  0  0  1 | 1
0 0 1  0  0  1 | 1
0 0 0  1 -1  0 | 0
0 0 0  0 -1  1 | 0
0 0 0  0  1 -1 |-1

1 0 0  1  0  0 | 1
0 1 0  0  0  1 | 1
0 0 1  0  0  1 | 1
0 0 0  1 -1  0 | 0
0 0 0  0  1 -1 | 0
0 0 0  0  0  0 |-1

*/


Measured memory_bytes: 4224
x, y = map(int, input().split())

tmp = 4 * x - y
f = 0
if tmp % 2 == 0 and tmp >= 0:
    crane = tmp / 2
    turtle = x - crane
    if turtle >= 0:
        f = 1
    else:
        pass
else:
    pass

if f == 1:
    print('Yes')
else: 
    print('No')

Measured memory_bytes: 9172
#include<cstdio>
#define N 1001
inline int abs(int x){return x<0?-x:x;}
inline int max(int x,int y){return x<y?y:x;}
int a[N],b[N],c[40],i,j,m,n,s;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d%d",a+i,b+i),s=max(s,abs(a[i])+abs(b[i]));
	for(i=1;i<n;i++)if((a[i]^b[i]^a[i+1]^b[i+1])&1)return 0&puts("-1");
	while(1ll<<m<s)m++;
	for(s<2?m++:0,i=m;i--;)c[m-i]=1<<i;
	for(~(a[1]^b[1])&1?c[++m]=1:0,printf("%d\n",m),i=1;i<=m;i++)printf("%d%c",c[i],i==m?'\n':' ');
	for(i=1;i<=n;puts(""),i++)for(j=1;j<=m;j++)
	if(!a[i]&&!b[i]||a[i]+b[i]<0&&a[i]-b[i]<=0)a[i]+=c[j],putchar('L');
	else if(0<=a[i]+b[i]&&a[i]-b[i]<0)b[i]-=c[j],putchar('U');
	else if(0<a[i]+b[i]&&0<=a[i]-b[i])a[i]-=c[j],putchar('R');
	else if(a[i]+b[i]<=0&&0<a[i]-b[i])b[i]+=c[j],putchar('D');
	return 0;
}

Measured memory_bytes: 256
n,k = list(map(int, input().split()))
r,s,p = list(map(int, input().split()))
t = str(input())
mine = []

for i in range(n):
  if t[i]=="r":
    mine.append("p")
  elif t[i]=="s":
    mine.append("r")
  elif t[i]=="p":
    mine.append("s")
  
for i in range(len(mine)-k):
  if mine[i]==mine[i+k]:
    mine[i+k] = "x"
    
ans = mine.count("r") * r + mine.count("s") * s + mine.count("p") * p
print(ans)

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  if (U == T) {
    int a = A;
    int b = B - 1;
    cin >> a >> b;
    cout << a << " " << b << endl;
  }
  else {
    int c = A - 1;
    int d = B;
    cin >> c >> d;
  cout << c << " " << d << endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}
 
const long long MOD = 998244353;
 
ll pw(ll x, ll y) {
  ll ans=1;
  for(int i=0; i<y; i++) {
    ans = (ans*x)%MOD;
  }
  return ans;
}
 
void solve(long long N, std::vector<long long> D){
  if(D[0]!=0){
    std::cout << 0 << std::endl;
    return;
  }
  sort(D.begin(), D.end());
  for(ll i=1; i<N; i++) {
    if(D[i]==0) {
      std::cout << 0 << std::endl;
      return;
    }
  }
 
  vector<ll> v;
  ll p = 0;
  ll c = 1;
  for(int i=1; i<N; i++) {
    if(D[i]==p) {
      c++;
    } else if(D[i]-1==p){
      v.push_back(c);
      c = 1;
    } else {
      std::cout << 0 << std::endl;
      return;
    }
    p = D[i];
  }
  v.push_back(c);
 
  ll ans=1;
  for(int i=0; i+1<v.size(); i++) {
    ans = (ans*pw(v[i], v[i+1]))%MOD;
  }
  std::cout << ans << std::endl;
 
}
 
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> D(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&D[i]);
    }
    solve(N, std::move(D));
    return 0;
}


Measured memory_bytes: 2168
/**
class cfmaster {
 struct code {
   see the details down there
 };
};
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int x,  y;
  cin >> x >> y;
  string u;
  cin >> u;
  if (u == s) {
    cout << x - 1 << " " << y << '\n';
  } else {
    cout << x << " " << y - 1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());

		String aaa = sc.next();
		Map<String, String> prizeMap = new HashMap<>();
		prizeMap.put(aaa,aaa);

		for(int i = 1;i < N; i++) {
			String prize = sc.next();
			if(prizeMap.containsKey(prize)) {
				//取れちゃった
			}else {
				prizeMap.put(prize, prize);
			}
		}
		sc.close();
		System.out.println(prizeMap.size());
	}

}


Measured memory_bytes: 66868
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES":"NO");}
void Yn(bool z){cout<<(z?"Yes":"No");}
void yn(bool z){cout<<(z?"yes":"no");}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 0;
int n, a;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> a;
  Yn(n%500 <= a);
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

#include <cstdio>
using namespace std;

typedef struct
{
  int idx, dist, num;
} Store;

const double INF = 1e20;

int n, dist[16][16], weight[1 << 15];
pair<double, int> dp[1 << 15][16];

pair<double, int> solve(int S, int p)
{
  if (S == (1 << n)-1)
    return make_pair(0.0, -1);

  if (dp[S][p].first != INF)
    return dp[S][p];

  pair<double, int> res(INF, -1);
  for (int i = 0; i < n; ++i) {
    if (!(S & (1 << i))) {
      pair<double, int> tmp = solve(S | (1 << i), i);
      tmp.first += dist[p][i] / (2000.0 / (70.0+weight[S]));
      if (tmp.first < res.first) {
	res.first = tmp.first;
	res.second = i;
      }
    }
  }
  return dp[S][p] = res;
}

int main()
{
  while (cin >> n) {
    vector<Store> store(n);
    for (int i = 0; i < n; ++i)
      cin >> store[i].idx >> store[i].dist >> store[i].num;

    for (int i = 0; i < n; ++i) {
      for (int j = i+1; j < n; ++j)
	dist[i][j] = dist[j][i] = 60 * abs(store[i].dist-store[j].dist);
      dist[n][i] = 0;
    }

    for (int S = 0; S < (1 << n); ++S) {
      weight[S] = 0;
      for (int i = 0; i < n; ++i) {
	if (S & (1 << i))
	  weight[S] += store[i].num;
      }
      weight[S] *= 20;
    }

    for (int S = 0; S < (1 << n); ++S) {
      for (int i = 0; i <= n; ++i)
	dp[S][i].first = INF;
    }

    solve(0, n);

    int S = 0, p = n;
    vector<int> ans;
    while (S != (1 << n)-1) {
      int next = dp[S][p].second;
      S |= (1 << next);
      p = next;
      ans.push_back(store[next].idx);
    }

    for (int i = 0; i < ans.size()-1; ++i)
      cout << ans[i] << " ";
    cout << ans.back() << endl;
  }
  return 0;
}

Measured memory_bytes: 7144
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define llint long long
#define inf 1e18

using namespace std;

llint n;
llint a[5005];
vector<llint> G[5005];
llint sum[5005];
llint dp[5005][5005][2];
llint dp2[5005][5005][2];

llint dfs(llint v, llint p)
{
	sum[v] = 1;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		sum[v] += dfs(G[v][i], v);
	}
	
	int m = G[v].size();
	for(int i = 0; i <= m; i++){
		for(int j = 0; j <= sum[v]; j++){
			for(int k = 0; k < 2; k++){
				dp2[i][j][k] = inf;
			}
		}
	}
	if(a[v] > 0) dp2[0][0][0] = a[v];
	else dp2[0][0][1] = a[v];
	
	llint psum = 1;
	for(int i = 0; i < m; i++){
		llint u = G[v][i];
		if(u == p){
			for(int j = 0; j <= psum; j++){
				for(int k = 0; k < 2; k++){
					dp2[i+1][j][k] = dp2[i][j][k];
				}
			}
			continue;
		}
		for(int j = 0; j <= psum; j++){
			for(int k = 0; k < 2; k++){
				for(int l = 0; l <= sum[u]; l++){
					for(int s = 0; s < 2; s++){
						dp2[i+1][j+l][min(1,k+s)] = min(dp2[i+1][j+l][min(1,k+s)], dp2[i][j][k] + dp[u][l][s]);
						if(j+l+1 <= psum+sum[u]){
							if((s == 0 && dp[u][l][s] < inf/2) || (s == 1 && dp[u][l][s] < 0)){
								dp2[i+1][j+l+1][k] = min(dp2[i+1][j+l+1][k], dp2[i][j][k]);
							}
						}
					}
				}
			}
		}
		psum += sum[u];
	}
	for(int j = 0; j <= psum; j++){
		for(int k = 0; k < 2; k++){
			dp[v][j][k] = dp2[m][j][k];
		}
	}
	return sum[v];
}

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	llint u, v;
	for(int i = 1; i <= n-1; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, -1);
	
	llint ans = inf;
	for(llint i = 0; i <= n-1; i++){
		if(dp[1][i][0] < inf/2) ans = min(ans, i);
		if(dp[1][i][1] < 0) ans = min(ans, i);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 782976
import scala.io.StdIn.{readLine,readInt}

object Main {

  def main(args: Array[String]) = {
    val d = readLine.split(" ").map(_.toInt)
    val m1 = Array.ofDim[Int](d(0),d(1))
    val m2:Array[Int] = new Array(d(1))

    0 until d(0) foreach { m1(_) = readLine.split(" ").map(_.toInt) }
    0 until d(1) foreach { m2(_) = readInt() }

    m1.foreach { e => println(e.zip(m2).foldLeft(0) { (x,y) => x + y._1*y._2 }) }
  }
}

Measured memory_bytes: 47372