akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

string s;
int kth;
int n;

char b[10];

bool go(int i) {
  for(b[i] = 'a'; b[i] <= 'z'; ++b[i]) {
    b[i+1] = 0;
    if(s.find(b) != string::npos) {
      --kth;
      if(kth == 0) {
        cout << b << endl;
        return true;
      }
      bool res = go(i+1);
      if(res) {
        return true;
      }
    } else {
      continue;
    }
  }
  return false;
}

int main(void) {
  cin >> s >> kth;
  n = s.size();
  go(0);
  return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

int main(){
    int n,k;
    cin >> n>> k;
    vector<int> p(n),c(n);
    rep(i,n){cin >> p[i];p[i]--;}
    rep(i,n){cin >> c[i];}
    mat score(n, vec(0));
    vec num(n);
    ll res=*max_element(ALL(c));
    rep(i,n){
        num[i]++;
        ll temp=c[p[i]];
        ll now=p[i];
        score[i].push_back(0);
        score[i].push_back(temp);
        while(now!=i){
            now=p[now];
            temp+=c[now];
            num[i]++;
            score[i].push_back(temp);
        }
        if(score[i][num[i]] > 0){
            ll roop_num = k / num[i] - 1;
            if(roop_num >= 0){
                temp = score[i][num[i]] * roop_num;
                temp += *max_element(ALL(score[i]));
                if(res<temp){
                    res=temp;
                }
            }
            ++roop_num;
            temp = score[i][num[i]] * roop_num;
            temp += *max_element(score[i].begin(), score[i].begin() + (k % num[i]) + 1);
            if(res<temp){
                res=temp;
            }
        }else{
            if(res<*max_element(score[i].begin() + 1, score[i].end())){
                res=*max_element(score[i].begin() + 1, score[i].end());
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 218956
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
#define bin(x)     (bitset<3>(x))
using namespace std;
using ll = long long;

int swap_bits(int x,int i,int j) {
	int bit_i=x>>i&1;
	int bit_j=x>>j&1;
	return x^(bit_i<<i)^(bit_j<<j)^(bit_i<<j)^(bit_j<<i);
}

vector<int> solve(int n,int a,int b) {
	if (__builtin_parity(a)==__builtin_parity(b)) return {};

	if (n==1) return {a,b};

	int bit=1<<(n-1);
	if ((bit&a)!=(bit&b)) {
		auto p=solve(n-1,a,a^1);
		auto q=solve(n-1,a^1^bit,b);
		p.insert(p.end(),q.begin(),q.end());
		return p;
	} else {
		auto p=solve(n-1,a,b);
		auto q=solve(n-1,a^bit,p[1]^bit);
		p.insert(p.begin()+1,q.begin(),q.end());
		return p;
	}
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N,A,B;
	cin>>N>>A>>B;
	auto res=solve(N,A,B);
	if (res.empty()) {
		cout<<"NO\n";
	} else {
		cout<<"YES\n";
		for (int x:res) cout<<x<<" ";
		cout<<"\n";
	}
}


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

using namespace std;

typedef long long ll;

ll f(ll b, ll n) {
    ll res = 0;
    while (n >= b) {
        res += n % b;
        n /= b;
    }
    return res + n;
}

ll solve(ll n, ll s) {
    if (n < s) return -1;
    if (n == s) return n + 1;
    for (ll b = 2; b * b <= n; b++) {
        if (f(b, n) == s) return b;
    }
    for (ll p = (ll)sqrt(n - 1); p > 0; p--) {
        if ((n - s) % p) continue;
        ll b = (n - s) / p + 1;
        if (f(b, n) == s) return b;
    }
    return -1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, s;
    cin >> n >> s;
    cout << solve(n, s) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
struct ST{
	int a;
	int b;
	int c;
	int d;
};
int map[1001][1001];
int check[1001][1001];
int q[4]={1,0,-1,0};
int p[4]={0,-1,0,1};
int main(){
	queue <ST> Q;
	ST x;
	ST y;
	int h,w,n;
	int i,j,m;
	char s;
	memset(map,0,sizeof(map));
	memset(check,0,sizeof(check));
	char num[10]={'0','1','2','3','4','5','6','7','8','9'};
	cin>>h>>w>>n;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin>>s;
			if(s=='S'){
				x.a=i;
				x.b=j;
				x.c=0;
				x.d=1;
				Q.push(x);
			}
			else if(s=='X'){
				map[i][j]=-1;
			}
			else{
				for(m=1;m<10;m++){
					if(s==num[m]){
						map[i][j]=m;
					}
				}
			}
		}
	}
	/*for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cout<<map[i][j];
		}
		cout<<endl;
	}*/
	while(!Q.empty()){
		y=Q.front();
		Q.pop();
		if(check[y.a][y.b]==1)continue;
		check[y.a][y.b]=1;
		if(y.d==map[y.a][y.b]){
			if(n==y.d){
				cout<<y.c<<endl;
				break;
			}
			while(!Q.empty()){
				Q.pop();
			}
			y.d++;
			x=y;
			Q.push(x);
			memset(check,0,sizeof(check));
			continue;
		}
		for(i=0;i<4;i++){
			if(y.a+q[i]>=0&&y.b+p[i]>=0&&y.a+q[i]<h&&y.b+p[i]<w&&map[y.a+q[i]][y.b+p[i]]!=-1&&check[y.a+q[i]][y.b+p[i]]==0){
				x.a=y.a+q[i];
				x.b=y.b+p[i];
				x.c=y.c+1;
				Q.push(x);
			}
		}
	}
	return 0;
}

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

  public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int c = sc.nextInt();
      Map<Integer, ArrayList<int[]>> channels = new HashMap<>();
      for(int i = 1;  i <= c; i++) {
          channels.put(i, new ArrayList<>());
      }
      for(int i = 0; i < n; i++) {
          int[] itv = new int[]{sc.nextInt(), sc.nextInt()};
          channels.get(sc.nextInt()).add(itv);
      }

      int maxEnd = 0;
      ArrayList<int[]> allItvs = new ArrayList<>();
      for(int i = 1;  i <= c; i++) {
          ArrayList<int[]> itvs = channels.get(i);
          if(itvs.size() == 0) continue;
          Collections.sort(itvs, (itv1, itv2) -> itv1[0] - itv2[0]);
          int start = itvs.get(0)[0];
          int end = itvs.get(0)[1];
          for(int j = 1; j < itvs.size(); j++) {
            int[] itv = itvs.get(j);
            if(itv[0] == end || itv[0] + 1 == end) {
              end = itv[1];
            } else {
              allItvs.add(new int[] { start - 1, end});
              start = itv[0];
              end = itv[1];
            }
          }
          maxEnd = Math.max(maxEnd, end);
          allItvs.add(new int[] { start - 1, end});
      }

      int[] itvArr = new int[maxEnd + 1];
      for(int[] itv : allItvs) {
        itvArr[itv[0]]++;
        itvArr[itv[1]]--;
      }
      int min = itvArr[0];
      for(int i = 1; i < itvArr.length; i++) {
        itvArr[i] = itvArr[i] + itvArr[i-1];
        min = Math.max(min, itvArr[i]);
      }

      System.out.println(min);
  }
}



Measured memory_bytes: 98200
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <limits>
#include <random>
#include <utility>
#include <vector>

namespace procon {
  class UnionFind {
  private:
    struct nodeinfo {
      int par;
      int rank;
      nodeinfo(int par) : par(par), rank(0) {}
    };
    std::vector<nodeinfo> node;

  public:
    UnionFind(int n) : node() {
      node.reserve(n);
      for (int i = 0; i < n; ++i) {
	node.push_back(nodeinfo(i));
      }
    }
    int root(int x) {
      if (node[x].par == x) {
	return x;
      }
      return node[x].par = root(node[x].par);
    }
    void unite(int x, int y) {
      x = root(x);
      y = root(y);
      if (x == y) {
	return;
      }
      if (node[x].rank < node[y].rank) {
	node[x].par = y;
      } else {
	node[y].par = x;
	if (node[x].rank == node[y].rank) {
	  ++node[x].rank;
	}
      }
    }
    bool is_same_set(int x, int y) { return root(x) == root(y); }
  };
}
  
int main(void) {
  int size, n_query;
  std::cin.read((char *)&size, sizeof(int));
  std::cin.read((char *)&n_query, sizeof(int));

  std::vector<uint64_t> query(n_query);
  std::cin.read((char *)query.data(), sizeof(uint64_t) * n_query);

  const int mask = (1 << 30) - 1;

  uint64_t res = 123456789;
  procon::UnionFind uf(size);
  for (uint64_t q : query) {
    const int com = q >> 60;
    const int x = (q >> 30) & mask;
    const int y = (q >> 0) & mask;
    assert(0 <= x && x < size);
    assert(0 <= y && y < size);
    if (com) {
      res = res * 17 + (uf.is_same_set(x, y) ? 1 : 0);
    } else {
      uf.unite(x, y);
    }
  }
  std::cout << res << std::endl;
  return 0;
}



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

int main(){
    string s;
    cin >> s;
    int ans=s.size();
    
    while(ans){
        s.pop_back();
        ans = s.size();
        if(ans%2!=0) continue;
        
        if(s.substr(0, ans/2)==s.substr(ans/2)){
            cout << ans << endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(void){
    int n,k,q;
    cin >> n >> k >> q;
    int a[q];
    int ans[n] = {};
    for(int i = 0; i < q;i++){
      int in;
      cin >> in;
      a[i] = in;
      ans[in-1]++;
    }
    for(int i = 0; i < n;i++){
      ans[i] = k - q + ans[i];
      if(ans[i] > 0){
        cout << "Yes" << endl;
      }
      else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main{
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int p[] = new int[n];
    int ans = 0;
    for(int i=0 ; i<n ; i++){
      p[i] = sc.nextInt();
    }

    Arrays.sort(p);

    for(int i=0 ; i<k ; i++){
      ans += p[i];
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 38928
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define pint pair<int,int>
#define Lower(v,X) lower_bound(v.begin(),v.end(),X)-v.begin();
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
   lli A,B,C,L,R,N,M,K,X=0,Y=0,W,H=INF,sum=0,num=0,flag=0;string S,T,O;
   cin >> S;
   N=S.size();
   rep(i,1,N)if(S[i]!=S[i-1])sum++;
   Out(sum);
}

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

int main(){
	int n,k;
	string s;
	cin>>n>>s>>k;
	char c=s[k-1];
	string cnt=""; 
	for(int i=0;i<s.size();i++){
		if(s[i]!=c){
			cnt+='*';
		}
		else if(s[i]==c){
			cnt+=s[i];
		}
	}
	cout<<cnt<<endl;
	return 0;
}

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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
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; }

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

// 繰り返し二乗法
ll power(ll a, ll b){
    if(a==1)return a;
    // if(a==0)re
    ll res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int MAX=2100000;

ll fact[MAX], fact_inv[MAX];

void init_fact(ll n){
    fact[0]=1;
    // 階乗の計算
    for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
    fact_inv[n]=power(fact[n], MOD-2);
    // 逆元の計算
    for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll perm(ll n, ll r){
    return (fact[n]*fact_inv[n-r])%MOD;
}

int main() {
    cout<<fixed<<setprecision(10);

    ll k,n; cin>>k>>n;
    vint a(n); rep(i,n) cin>>a[i];

    a.push_back(k+a.front());
    ll maxval=0;
    rep(i,n) chmax(maxval, a[i+1]-a[i]);
    cout<<k-maxval<<endl;

    return 0;

}

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

namespace ABC134E_2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
            }
            A = A.Reverse().ToArray();

            int[] dp = new int[N].Select(x => x = int.MaxValue).ToArray();

            for (int i = 0; i < N; i++)
            {
                int a = UpperBound(dp, A[i]);
                if (dp[a] == A[i]) dp[a + 1] = A[i];
                else dp[a] = A[i];
            }

            Console.WriteLine(UpperBound(dp, int.MaxValue - 1));
            Console.ReadKey();
        }


        /// <summary>
        /// 二分探索 vを超えない最高
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="a"></param>
        /// <param name="v"></param>
        /// <returns></returns>
        public static int UpperBound<T>(T[] a, T v)
        {
            return UpperBound(a, v, Comparer<T>.Default);
        }

        public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res <= 0) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


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

int main () {
  int N;
  int a[1000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort (a, a + N);
  cout << a[N - 1] - a[0] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

int cnt[100500];

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

  int n, k, q;
  cin >> n >> k >> q;
  for(int i = 0; i < q; i++){
    int x;
    cin >> x;
    cnt[x]++;
  }
  for(int i = 1; i <= n; i++){
    cout << (k - (q - cnt[i]) <= 0 ? "No\n" : "Yes\n");
  }
}

Measured memory_bytes: 1024
#!/usr/bin/env python
import numpy as np
a, b, h, m  = map(float, input().split())
m_ = (np.pi * m/ 30) 
h_ = (np.pi * h/ 6)  + (np.pi * m/360)


r = ((a * np.cos(h_) - b * np.cos(m_)) ** 2
     + (a * np.sin(h_) - b * np.sin(m_)) ** 2)** 0.5

print(r)
      


Measured memory_bytes: 27184
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>s;
    rep(i,Size(s)){
        if(i%2==0){
            if(s[i]=='R'||s[i]=='U'||s[i]=='D')continue;
            Cout("No");
            return 0;
        }
        else{
            if(s[i]=='L'||s[i]=='U'||s[i]=='D')continue;
            Cout("No");
            return 0;
        }
    }
    Cout("Yes");
    return 0;
}

Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())

ans1 = a * x + b * y
ans = ans1
for i in range(0, max(x,y)*2+1):
    if i % 2 == 0:
        ans2 = i * c + max(0, x - i // 2) * a + max(0, y - i // 2) * b
        ans = min(ans, ans2)

print(ans)


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

using namespace std;
#define int long long
int x;
vector<int>rev;
int ptr=0;
#undef int
int main(){
	#define int long long
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>x;
	int k;cin>>k;
	rev.push_back(0);
	for(int i=0;i<k;i++){
		int t;cin>>t;
		rev.push_back(t);
	}
	int q;cin>>q;
	int d=0,u=x,dans=0,uans=x;
	for(int i=0;i<q;i++){
		int t,a;cin>>t>>a;
		while(ptr<rev.size()-1&&t>=rev[ptr+1]){
			if(ptr%2==0){
				dans-=(rev[ptr+1]-rev[ptr]);
				if(dans<0){
					d+=(-dans);
					dans=0;
				}
				if(d>u){
					d=u;uans=0;
				}else{
					uans-=(rev[ptr+1]-rev[ptr]);
				}
			}else{
				uans+=(rev[ptr+1]-rev[ptr]);
				if(uans>x){
					u-=(uans-x);
					uans=x;
				}
				if(u<d){
					u=d;dans=x;
				}else{
					dans+=(rev[ptr+1]-rev[ptr]);
				}
			}
			ptr++;
		}
		if(ptr%2==0){
			if(a>=u){
				cout<<max(0LL,uans-(t-rev[ptr]))<<"\n";
			}else if(a<=d){
				cout<<max(0LL,dans-(t-rev[ptr]))<<"\n";
			}else{
				int stans=(a-d)+dans;
				cout<<max(0LL,stans-(t-rev[ptr]))<<"\n";
			}
		}else{
			if(a>=u){
				cout<<min(x,uans+(t-rev[ptr]))<<"\n";
			}else if(a<=d){
				cout<<min(x,dans+(t-rev[ptr]))<<"\n";
			}else{
				int stans=(a-d)+dans;
				cout<<min(x,stans+(t-rev[ptr]))<<"\n";
			}
		}
	}
	return 0;
}

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

const int maxn = 100010;
int r, c, n;
bool vis[maxn];
stack<int> st;

int main() {
    scanf("%d %d %d", &r, &c, &n);
    auto get = [&](int x, int y) {
        if (!y) return x;
        if (x == r) return r + y;
        if (y == c) return r + c + r - x;
        return r + c + r + (c - y);
    };
    vector<pair<int, int>> V;
    for (int i = 1, x1, y1, x2, y2; i <= n; i++) {
        scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
        if (!(x1 == 0 || x1 == r || y1 == 0 || y1 == c)) continue;
        if (!(x2 == 0 || x2 == r || y2 == 0 || y2 == c)) continue;
        V.push_back(make_pair(get(x1, y1), i));
        V.push_back(make_pair(get(x2, y2), i));
    }
    sort(V.begin(), V.end());
    bool flag = 1;
    for (int i = 0; i < V.size(); i++) {
        if (!vis[V[i].second]) {
            st.push(V[i].second), vis[V[i].second] = 1;
        } else {
            if (st.top() ^ V[i].second) { flag = 0; break; }
            st.pop();
        }
    }
    printf("%s", flag ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
const int M=100000,N=102,P=1000000007;
int n,a,b,k,C[M],F[N][M],S[M];
int main() {
	scanf("%d%d",&n,&k),a=b=(int)sqrt(n);
	if(b*b==n) --b;
	For(i,1,b) C[i]=n/i-max(a,n/(i+1));
	For(i,1,a) F[1][i]=1;
	For(i,a+1,a+b) F[1][i]=C[a+b-i+1];
	For(i,2,k) {
		For(j,1,a+b) S[j]=(S[j-1]+F[i-1][j])%P;
		For(j,1,a) F[i][j]=S[a+b-j+1];
		For(j,a+1,a+b) {
			int u=a+b-j+1;
			F[i][j]=1LL*C[u]*S[u]%P;
		}
	}
	int ans=0;
	For(i,1,a+b) ans=(ans+F[k][i])%P;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 38784
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int ans;
    ans = 0;
    for(int i=1; i<=2; i++){
        if(a>b){
            ans += a;
            a--;
        }else{
            ans += b;
            b--;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ITP1_7-D

Structured Program II - Matrix Multiplication
Time Limit : 1 sec, Memory Limit : 65536 KB
????????????

n??m
????????? A ??¨ m??l ????????? B ?????\??????????????????????????§?????? n??l ????????? C ???????????????????????°?????????????????????????????????????????? C ??????????´? cij

????¬?????????§??????????????????
cij=???k=1maikbkj

????????§???A
???B???C ??????????´???????????????? aij???bij???cij

??¨????????????
Input

???????????? n???m???l

????????????????????§?????????????????????

?¶?????????? n??m
????????? A ??¨ m??l ????????? B

????????????????????????
Output

n??l
????????? C ???????´? cij

?????????????????????????????????????????£?????????????´?????????????????????§????????£??????????????????
Constraints

    1???n,m,l???100

0???aij,bij???10000

Sample Input

3 2 3
1 2
0 3
4 5
1 2 1
0 3 2

Sample Output

1 8 5
0 9 6
4 23 14

=end
fh=STDIN
#fh=open("IPT1_7_D.txt")
f=fh.gets.chomp.split.map{|x| x.to_i}
n=f[0]
m=f[1]
l=f[2]
a = Array.new(n+1).map{ Array.new(m+1,0) }
b = Array.new(m+1).map{ Array.new(l+1,0) }
c = Array.new(n+1).map{ Array.new(l+1,0) }

(1..n).each {|i|
  f = fh.gets.chomp.split
  (1..m).each {|j| a[i][j] = f[j-1].to_i}
}

(1..m).each {|i|
  f = fh.gets.chomp.split
  (1..l).each {|j| b[i][j] = f[j-1].to_i}
}

(1..n).each {|i|
  (1..l).each {|j|
    (1..m).each {|k| c[i][j] += a[i][k] * b[k][j]}
    }
 }

(1..n).each {|i|
  s=""
  (1..l).each {|j|
    s = s + c[i][j].to_s + " " 
  }
  puts s.sub(/ *$/,"")
}

Measured memory_bytes: 15124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int depth;

long long int GCD(long long int a, long long int b){
	depth++;
	long long int rest = a % b;
	a = rest;
	swap(a, b);
	if(b == 0){
		return a;
	}
	return GCD(a, b);
}

int main(){
	
	long long int a, b;
	
	while(true){
		
		cin >> a >> b;
		
		if(a == 0 && b == 0){
			break;
		}
		
		depth = 0;
		
		if(a < b){
			swap(a, b);
		}
		
		long long int ans = GCD(a, b);
		
		cout << ans << " " << depth << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3044
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String s = sc.nextLine();

        String ans = solve(n, s);
        System.out.println(ans);
    }

    static String solve(int n, String s) {
        int needOpen = 0;
        int needClose = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '(') {
                needClose++;
            } else {
                if (needClose == 0) {
                    needOpen++;
                } else {
                    needClose--;
                }
            }
        }

        System.err.printf("%s-%s %s \n", needOpen, needClose, s);
        String tmp = s.concat(makeString(")", needClose));
        String ans = makeString("(", needOpen).concat(tmp);
        return ans;
    }

    private static String makeString(String s, int needClose) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < needClose; i++) {
            sb.append(s);
        }
        return sb.toString();
    }
}


Measured memory_bytes: 23764
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> result;
  if(A >= B){
    for(int i=B; i>0; i--){
      if(A%i==0 && B%i==0){
        result.push_back(i);        
      }
    }
    cout << result[K-1];
  }
  if(B > A){
    for(int j=A; j>0; j--){
      if(B%j==0 && A%j==0){
        result.push_back(j);  
      }
    }
    cout << result[K-1];
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	ll X,Y,x,y;
	cin >> X >> Y >> x >> y;
	cout << X*Y/2.0 << " " << (x*2 == X && y*2 == Y ? 1 : 0) << endl;
}


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

#############
# Libraries #
#############

import math
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#############
# Main Code #
#############

N = int(input())
l = list(map(int,input().split()))

LCM = {}

for i in l:
  fact = factorization(i)
  for j in fact:
    if j[0] not in LCM:
      LCM[j[0]] = j[1]
    else:
      if LCM[j[0]] < j[1]:
         LCM[j[0]] = j[1]

lcm = 1
for i in LCM:
  lcm = lcm * pow(i,LCM[i],MOD) % MOD

ans = 0
for i in l:
  ans = (ans + lcm * pow(i,MOD-2,MOD)) % MOD

print(ans)

Measured memory_bytes: 46044
#include <iostream>
using namespace std;
int main(){
  int D;
  cin >> D;
  if(D == 25) cout << "Christmas" << endl;
  else if(D == 24) cout << "Christmas Eve" << endl;
  else if(D == 23) cout << "Christmas Eve Eve" << endl;
  else if(D == 22) cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List
import Data.Array

strToInt s = (read :: String -> Int)

main = do

   s <- getLine
   let ss = sub (sort s)
   let xs = sort ("abcdefghijklmnopqrstuvwxyz" \\ ss)
   
   if (length xs) == 0 then putStrLn "None"
                       else putStrLn [(head xs)]

sub :: [Char] -> [Char]
sub [] = []
sub (x:[]) = [x]
sub (x:xs) = if (x == (head xs))
             then sub xs
             else ([x] ++ sub xs)


Measured memory_bytes: 11644
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

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

  int max_val = *max_element(a.begin(), a.end());
  int min_val = *min_element(a.begin(), a.end());
  cout << max_val - min_val << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = 0
while True:
  for i in range(n):
    b = a[i]
    c = b//n
    b = b%n
    a[i] = b
    for j in range(n):
      if j == i:
        continue
      a[j] += c
    ans += c
  if max(a) < n:
    break
print(ans)

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


int main() {
	string N = "";
	string Str[7] = { "SAT","FRI","THU","WED","TUE","MON","SUN" };
	
	cin >> N;
	for (int n = 0; n < 7; n++) {
		if (Str[n] == N) {
			cout << n + 1 << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		while((str = br.readLine()) != null) {
			String ns[] = str.split(",");
			int len[] = new int[10];
			int v1, v2;
			for(int i = 0; i < 10; i++) {
				len[i] = Integer.parseInt(ns[i]);
				if(i > 0) len[i] += len[i - 1];
			}
			v1 = Integer.parseInt(ns[10]);
			v2 = Integer.parseInt(ns[11]);
			for(int i = 0; i < 10; i++) {
				if(len[9] * v1 <= (v1 + v2) * len[i]) {
					System.out.println(i+1);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 16880
import heapq

n, m = map(int, input().split())
list_score = list(map(int, input().split()))
list_kard = [list(map(int, input().split(" "))) for i in range(m)]

list_kard.sort(key=lambda x: x[1], reverse=True)
heapq.heapify(list_score)

for i in range(m):
    k = list_kard[i]
    for _ in range(k[0]):
        if list_score[0] < k[1]:
            heapq.heappop(list_score)
            heapq.heappush(list_score, k[1])
        else:
            break

print(sum(list_score))

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

int main() {
  int N,K;
  cin >> N >> K;
  int a=1;
  int i;
  for(i=0;i<N;i++) {
    if(a<K) a=a*2;
    else a=a+K;
  }
  cout << a << endl;
  return 0;  
}

Measured memory_bytes: 256
function Main(input) {
  input = input.trim().split('\n');
  H = input[0].split(' ')[0];
  console.log(input[1].split(' ').map(Number).reduce((a,v)=>a+v) >= H ? 'Yes':'No');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 25160
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXLEN=500000-1;

char s[MAXLEN+1]; int slen;

int n;
int a[MAXLEN+1];

ll solve() {
	n=slen+1;
	REP(i,n) a[i]=-1;
	REP(i,n) if(a[i]==-1) {
		if(i>=slen||s[i]=='<') { a[i]=i==0||s[i-1]=='>'?0:a[i-1]+1; continue; }
		int j=i; while(j<slen&&s[j]=='>') ++j;
		a[j]=0; --j; while(j>=i) { a[j]=a[j+1]+1; --j; } if(i-1>=0&&s[i-1]=='<') a[i]=max(a[i],a[i-1]+1);
	}
	//REP(i,n) { printf("%d",a[i]); if(i<slen) printf("%c",s[i]); } puts("");
	ll ret=0; REP(i,n) ret+=a[i]; return ret;
}

void run() {
	scanf("%s",s); slen=strlen(s);
	printf("%lld\n",solve());
}

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


Measured memory_bytes: 2688
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }

int main() {
    int h, a;
    cin >> h >> a;
    cout << ((h % a == 0) ? h / a : h / a + 1) << endl;

    return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<char> s(n);
  rep(i, n) cin >> s[i];
  set<char> st;
  rep(i, n) st.insert(s[i]);
  if(st.size() == 3) cout << "Three" << endl;
  else cout << "Four" << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll x;
  cin >> x;
  if(x <= (x/100)*105){
    cout << 1 << endl;
  }else cout << 0 << endl;
  return 0;
}

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

int main() {
  int N , M , S=0;
  cin >> N >> M;
  vector<int> A(M);
  for(int i=0; i<M; i++){
    cin >> A.at(i);
    S += A.at(i);
  }
  if(S > N){
    cout << -1 << endl;
  }else{
  cout << N-S << endl;
  }
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n,m;
    cin>>n>>m;
    cout<<(n==m?"Yes":"No")<<endl;
    return 0;
}


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

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (s[0] != 0)
            {
                WriteLine(0);
                return;
            }
            Array.Sort(s);
            var ls = new List<long>();
            long remain = s[0];
            long cnt = 1;
            for (int i = 1; i < n; i++)
            {
                if(Abs(remain - s[i]) >= 2 || s[i] == 0)
                {
                    WriteLine(0);
                    return;
                }
                if (remain == s[i])
                {
                    cnt++;
                }
                else
                {
                    ls.Add(cnt);
                    cnt = 1;
                    remain = s[i];
                }
            }
            ls.Add(cnt);
            long ans = 1;
            for (int i = 0; i < ls.Count-1; i++)
            {
                long tmp = 1;
                for (int j = 0; j < ls[i+1]; j++)
                {
                    tmp *= ls[i];
                    tmp %= 998244353;
                }
                ans *= tmp;
                ans %= 998244353;
            }
            WriteLine(ans);
        }

    }
}


Measured memory_bytes: 20448
#include<iostream>
#include<cmath>
#include<vector>
#include<stack>
#include<algorithm>
#include<numeric>

using namespace std;

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

double PI = acos(-1);
int N;
ll R, C;
vector<Pdi> candidate;
double cx, cy;

bool isframe(P x) {
	if ((x.first == 0 || x.first == R) || (x.second == 0) || (x.second == C))return true;
	else return false;
}

/*
double getasin(P a) {
	//The function's return value's range is [0, 2 * PI)
	double A = sqrt((a.first - cx) * (a.first - cx) + (a.second - cy) * (a.second - cy));
	if (a.first - cx == 0 && a.second - cy > 0)return PI / 2.0;
	else if (a.first - cx == 0 && a.second - cy < 0)return 3.0 * PI / 2.0;
	else if (a.second - cy == 0 && a.first - cx > 0)return 0;
	else if (a.second - cy == 0 && a.first - cx < 0)return PI;
	else {
		if (a.first - cx > 0 && a.second - cy > 0) {
			return asin((a.first - cx) / A);
		}
		else if (a.first - cx < 0 && a.second - cy > 0) {
			return PI + asin((a.first - cx) / A);
		}
		else if (a.first - cx < 0 && a.second - cy < 0) {
			return PI - asin((a.first - cx) / A);
		}
		else if (a.first - cx > 0 && a.second - cy < 0) {
			return 2 * PI + asin((a.first - cx) / A);
		}
	}
	return (a.second - cy) / A;
}
*/

ll parse(P a) {
	if (a.first == 0)return a.second;
	else if (a.second == C)return C + a.first;
	else if (a.first == R)return C + R + (C - a.second);
	else if(a.second == 0) return 2 * C + R + (R - a.first);
	return -1;
}

int main() {
	cin >> R >> C >> N;
	cx = R / 2.0, cy = C / 2.0;
	for (int i = 0; i < N; i++) {
		P a, b;
		cin >> a.first >> a.second >> b.first >> b.second;
		if (isframe(a) && isframe(b)) {
			candidate.push_back(Pdi(parse(a), i));
			candidate.push_back(Pdi(parse(b), i));
		}
	}

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

	stack<int> S;
	
	for (int i = 0; i < candidate.size(); i++) {
		if (S.size() == 0 || S.top() != candidate[i].second)S.push(candidate[i].second);
		else S.pop();
	}
	if (S.size() == 0)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 6256
import java.util.Scanner;
import java.util.Vector;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double dp[][] = new double[n+1][n+1];
		double p[] = new double[n+1];
		for (int i=1;i<=n;i++) 
			p[i] = sc.nextDouble();
		
		dp[0][0]= 1;
		for (int i=1;i<=n;i++)
			for (int j=0;j<=i;j++) {
				dp[i][j] =  dp[i-1][j] * (1-p[i]);
				if (j>0) dp[i][j] +=  dp[i-1][j-1] * p[i];
			}
		double ans = 0.0;
		for (int i=(n+1)/2;i<=n;i++)
			ans+=dp[n][i];
		System.out.println(ans);
		

	}
}


Measured memory_bytes: 133228
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int K,x,y;
  cin >> K;
  queue<long long int> que;
  for(int i=1; i<10; i++){
    que.push(i);
  }
  for(int i=1; i<K; i++){
    x = que.front();
    y = x % 10;
    if(y != 0){
      que.push(10* x+ y - 1);
    }
    que.push(10* x+ y);
    if(y != 9){
      que.push(10* x+ y + 1);
    }
    que.pop();
  }
  cout << que.front() << endl;
}


Measured memory_bytes: 1792
from math import sqrt

n = int(input())

i = 2

c = []

while i*i <= n:
    j = 0
    while n%i == 0:
        j += 1
        n //= i   
    else:
        if j != 0:
            c.append(j)
    i += 1
if n > 1:
    c.append(1)
             
d = 0        
if c == []:
    print(d)
else:
    for k in c:
        d += int((sqrt(1 + 8*k)-1)/2)
    print(d)
            
            

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

typedef long long ll;
typedef vector<int> vi;

const double PI=acos(-1.0);

int N;
int input()
{
    cin>>N;
}

int solve()
{
    int mae=N/100;
    int ato=N%100;
    if(mae>=1 && mae<=12 && ato>=1 && ato<=12) cout<<"AMBIGUOUS\n";
    else if(mae>=1 && mae<=12 && (ato>=13 || ato==0)) cout<<"MMYY\n";
    else if((mae>=13 || mae==0) && ato>=1 && ato<=12) cout<<"YYMM\n";
    else cout<<"NA\n";
    return 0;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+3;
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t,i,j,n,m,l,r,s=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(i=n;i>0;i-=2)
    {
        cout<<a[i]<<" ";
    }
    if(n%2==1)
    {
        i=2;
    }
    else
    {
        i=1;
    }
    for(;i<=n;i+=2)
    {
        cout<<a[i]<<" ";
    }
    return 0;
}



Measured memory_bytes: 2944
#include<iostream>
using namespace std;
int main(){
	//freopen("in.txt","r",stdin);
	int x,y,z;
	while(cin>>x>>y>>z){
		int ans=0;
		while(x){
			x-=z;
			if(x<=0) break;
			if(x<z) break;
			x-=y;
			if(x<=0) break;
			if(x<z) break;
			ans++;
		}
		cout<<ans<<endl;
	}
}


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

int main(){
	int N;
	cin>>N;
	int h[N];
	for(int i=0;i<N;++i){
		cin>>h[i];
	}
	int dp[N];
	dp[0]=0;
	for(int i=1;i<N;++i){
		if(i==1){
			dp[i]=dp[0]+abs(h[0]-h[1]);
		}
		else{
			dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
		}
	}
	cout<<dp[N-1]<<endl;
}


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

typedef pair<int,int> P;
typedef queue<P> Q;

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

int main ()
{
    int n;
    cin >> n;
    int count = 0;
    while (n > count) {
        vector<string> v(8,"00000000");
        for (auto& i : v) {
            string t;
            cin >> t;
            i = t;
        }
        int x, y;
        cin >> y >> x;

        Q q;
        q.push(P(x-1,y-1));
        while (!q.empty()) {
            P p = q.front(); q.pop();
            x = p.first;
            y = p.second;
            v[x][y] = '0';
            for (int i = 0; i < 4; i++) {
                for (int j = 1; j <= 3; j++) {
                    int nx = x + dx[i] * j, ny = y + dy[i] * j;
                    if (0 <= nx && nx < 8 && 0 <= ny && ny < 8 && v[nx][ny] == '1') {
                        q.push(P(nx,ny));
                    }
                }
            }
        }
        cout << "Data " << (++count) << ":" << endl;
        for (auto i : v) {
            cout << i << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1236
#include<stdio.h>
int main(void){
int i,j,n,num,card[4][13];
char mark;
for(i=0;i < 4;i++){
for(j=0;j < 13;j++){
card[i][j]=0;
}
}
scanf("%d\n",&n);
for(i=0;i < n;i++){
scanf("%c %d\n",&mark ,&num);
switch(mark){
case 'S':
card[0][(num-1)]=1;
break;
case 'H':
card[1][(num-1)]=1;
break;
case 'C':
card[2][(num-1)]=1;
break;
case 'D':
card[3][(num-1)]=1;
break;
}
}
for(i=0;i < 4;i++){
for(j=0;j < 13;j++){
if (card[i][j] == 0){
switch(i){
case 0:
printf("S %d\n",(j+1));
break;
case 1:
printf("H %d\n",(j+1));
break;
case 2:
printf("C %d\n",(j+1));
break;
case 3:
printf("D %d\n",(j+1));
break;
}
}
}
}
return 0;
}

Measured memory_bytes: 600