akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

int d[5*100000+1];
int main(){
    ll a,b;cin>>a>>b;
    if(a==0||b==0){
        cout<<"Zero"<<endl;
        return 0;
    }
    if(a>0){
        cout<<"Positive"<<endl;
        return 0;
    }
    if(b>0 && a<0){
        cout<<"Zero"<<endl;
        return 0;
    }
    if(b<0){
        if(abs(abs(b)-abs(a))%2==1)cout<<"Positive";
        else cout<<"Negative";
        cout<<endl;
        return 0;
    }
}



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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()


int main(int argc, char **argv)
{
	ll N, L; cin >> N >> L;
	vector<ll> A(N);
	REP(i, N) cin >> A[i];

	bool ok{false};
	ll j;
	REP(i, N-1)
	{
		if (A[i] + A[i+1] >= L)
		{
			ok = true;
			j = i;
		}
	}

	if (!ok)
	{
		std::cout << "Impossible"<< std::endl;
		return 0;
	}

	std::cout << "Possible" << std::endl;
	REP(i, j)
		std::cout << i+1 << std::endl;
	for (ll i = N-2; i >= j; --i)
		std::cout << i+1 << std::endl;
}


Measured memory_bytes: 1664
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)


def main():
    n,k = LI()
    a = LI()
    r = 0
    for i in range(1,min(n,k)+1):
        for j in range(i+1):
            ii = i - j
            t = a[:j]
            if ii > 0:
                t += a[-ii:]
            t.sort()
            l = min(k - i,i-1)
            for ll in range(l):
                if t[ll] >= 0:
                    l = ll
                    break
            s = sum(t[l:])
            if r < s:
                r = s

    return r


print(main())



Measured memory_bytes: 6212
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
using std::cin;using std::cerr;
using std::max;using std::min;
#define ll long long
#define db double
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
int n,m,K,tmp;
struct road{int fr,to,v;}e[99];
int main()
{
	scanf("%d",&K),tmp=K;
	for(int i=0;1<<i<K;i++) e[++m]={n,n+1,0},e[++m]={n,n+1,1<<i},K-=1<<i,n++;
	K=tmp;
	for(int i=0,v=1<<n;i<n;i++) if(K>>i&1) e[++m]={i,n,v},v|=1<<i;
	printf("%d %d\n",n+1,m);
	for(int i=1;i<=m;i++) printf("%d %d %d\n",e[i].fr+1,e[i].to+1,e[i].v);
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
ans = {}
for k in cnt.keys():
    ans[k] = (cnt[k] * (cnt[k]-1)) // 2
s = sum(list(ans.values()))
for ai in a:
    if cnt[ai] == 1:
        print(s)
    else:
        print(s - ans[ai] + int((ans[ai] / cnt[ai]) * (cnt[ai] - 2)))

Measured memory_bytes: 32028
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-12 08:58:36
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

using ull = unsigned long long;

class RollingHash {
 public:
  RollingHash(const std::string& s) : s_(s) { Initialize(); }

  std::pair<ull, ull> GetHash(int left, int right) {
    ull ret0 =
        (hash0_[right] - hash0_[left] * power0_[right - left] % mod0_ + mod0_) %
        mod0_;
    ull ret1 =
        (hash1_[right] - hash1_[left] * power1_[right - left] % mod1_ + mod1_) %
        mod1_;
    return {ret0, ret1};
  }

 private:
  const std::string s_;
  static ull base0_;
  static ull base1_;
  static constexpr ull mod0_ = 2020202077;
  static constexpr ull mod1_ = 2020202111;
  std::vector<ull> hash0_;
  std::vector<ull> hash1_;
  static std::vector<ull> power0_;
  static std::vector<ull> power1_;
  static std::mt19937_64 mt_;

  void Initialize() {
    size_t n = s_.size();
    hash0_.assign(n + 1, 0);
    hash1_.assign(n + 1, 0);
    for (size_t i = 0; i < n; ++i) {
      hash0_[i + 1] = (hash0_[i] * base0_ + s_[i]) % mod0_;
      hash1_[i + 1] = (hash1_[i] * base1_ + s_[i]) % mod1_;
    }
    while (power0_.size() <= n) {
      power0_.emplace_back(power0_.back() * base0_ % mod0_);
      power1_.emplace_back(power1_.back() * base1_ % mod1_);
    }
  }
};

std::mt19937_64 RollingHash::mt_(
    std::chrono::steady_clock::now().time_since_epoch().count());
ull RollingHash::base0_ =
    std::uniform_int_distribution<ull>(2, RollingHash::mod0_)(RollingHash::mt_);
ull RollingHash::base1_ =
    std::uniform_int_distribution<ull>(2, RollingHash::mod1_)(RollingHash::mt_);
std::vector<ull> RollingHash::power0_{1};
std::vector<ull> RollingHash::power1_{1};

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

  int n; string s;
  cin >> n >> s;
  string t = "ABC";

  RollingHash rh1(s);
  RollingHash rh2(t);

  int cnt = 0;

  for (int i = 0; i < n - 2; ++i) {
    if (rh1.GetHash(i, i + 3) == rh2.GetHash(0, 3)) {
      ++cnt;
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
  
#define mp make_pair
#define f first
#define s second
#define ll long long
#define pb push_back
#define popb pop_back
#define popf pop_front

using namespace std;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int inf = 2e9+7, mod=1e9+7;
const int N = 2e6+321, E=14e5;

ll xx[8]={1, 1, -1, -1, 1, -1, 0, 0};
ll yy[8]={1, -1, 1, -1, 0, 0, 1, -1};

int a[N], b[N], used[N], ans;

vector <int> v[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		if(!used[a[i]]){
			used[a[i]]=1;
			for(int j=2; j*a[i]<=N/2; j++)
				b[j*a[i]]=1;
		}
		else
			b[a[i]]=1;
	}
	for(int i=0; i<n; i++)
		if(!b[a[i]])
			ans++;
	cout << ans;
    return 0;
}


Measured memory_bytes: 59136
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>

 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;


class UnionFind {
    public:
      vector<int> parent;
      vector<int> size;
//      size[i] = number of nodes in tree rooted at i
// Note: not necessarily correct if i is not a root node
      set<int> roots;

    UnionFind(int n) : parent(n), size(n) {
        forr(i,0,n) { roots.insert(i); }
        forr(i,0,n) {
            parent[i] = i; size[i] = 1;
        }
    } 

    int Find(int p) {
        int root = p;
        while (root != parent[root]) {  root = parent[root]; }
        while (p != root) {
            int newp = parent[p];
            parent[p] = root;
            p = newp;
        }
        return root;
    }

    void Union(int p, int q) {
        int rootP = Find(p);
        int rootQ = Find(q);
        if (rootP == rootQ) return;

        if (size[rootP] < size[rootQ]) {
            parent[rootP] = rootQ;
            size[rootQ] += size[rootP];
            roots.erase(rootP);
        }
        else {
            parent[rootQ] = rootP;
            size[rootP] += size[rootQ];
            roots.erase(rootQ);
        }
    }

};


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

//    auto start = chrono::steady_clock::now()

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n); readint(m);
        UnionFind uf(n);
        forr(i,0,m) {
            readint(a); readint(b); a--; b--;
            uf.Union(a,b);
        }
        map<int,int> groups;
        forr(i,0,n) {
            groups[uf.Find(i)]++;
        }
        vector<int> gr_reverse;
        for(auto x : groups) {
            gr_reverse.push_back(x.second);
        }
        sort(gr_reverse.begin(), gr_reverse.end());
        reverse(gr_reverse.begin(), gr_reverse.end());

        int ret = 0;
        while (!gr_reverse.empty()) {
            ret++;
            for(int& q : gr_reverse) {   q--;    }
            while ((!gr_reverse.empty()) && (gr_reverse.back()==0)) {  gr_reverse.pop_back(); }
        }
 
        cout << ret << endl;
    }

//    auto end = chrono::steady_clock::now();
//    cerr << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;

    return 0;
}

Measured memory_bytes: 24476
import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    C = list(input().strip())
    return N, C


def solve(N, C):
    ans = 0
    l = 0
    r = N-1
    while l < r:
        while l < N and C[l] == "R":
            l += 1
        while 0 <= r and C[r] == "W":
            r -= 1
        if l < r:
            ans += 1
            l += 1
            r -= 1
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 10716
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


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

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(int argc, char**argv){
    int a, b, x;
    cin >> a >> b >> x;

    if (x >= a && a + b >= x) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}



















Measured memory_bytes: 256
N = int(input())
A_list = [int(i) for i in input().split()]

Total_list = []
s = 0
for num in A_list:
  s += num
  Total_list.append(s)

L = 0
R = 2
ans = Total_list[N-1]+1
for Mid in range(1, N-2):
  sum_L = Total_list[Mid]
  sum_R = Total_list[N-1] - sum_L

  while abs(sum_L - 2*Total_list[L]) > abs(sum_L - 2*Total_list[L+1]):
    L += 1
  
  while abs((Total_list[N-1]-Total_list[R])-(Total_list[R] - sum_L)) > abs((Total_list[N-1]-Total_list[R+1])-(Total_list[R+1] - sum_L)):
    R += 1
  
  P = Total_list[L]
  Q = sum_L - Total_list[L]
  S = Total_list[R] - sum_L
  T = Total_list[N-1] - Total_list[R]

  ans = min(ans, max(P, Q, S, T) - min(P, Q, S, T))

print(ans)


Measured memory_bytes: 25676
#include<stdio.h>
int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int i;
	long long int d[100005];
	for (i = 0; i < n; i++)
		scanf("%lld", &d[i]);
	long long int p = 998244353;
	if (d[0] > 0)
	{
		printf("0\n");
		return 0;
	}
	long long int ans = 1;
	long long int count[100005];
	for (i = 0; i <= n; i++)
		count[i] = 0;
	for (i = 0; i < n; i++)
		count[d[i]]++;
	for (i = 1; i < n; i++)
	{
		if (d[i] == 0)
			ans = 0;
		else
			ans = ans * count[d[i] - 1] % p;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1664
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=3e5+7,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
//int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}

ll dp[110][110000],arr[110000];
int a[N];
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    if(k==0) {
        puts("1");
        return 0;
    }
    if(n==1){
        if(a[1]>=k) puts("1");
        else puts("0");
        return 0;
    }
    arr[0]=1;
    for(int i=1;i<=k;i++){
        if(i<=a[1])arr[i]=arr[i-1]+1;
        else arr[i]=arr[i-1];
//        cout<<arr[i]<<' ';
    }
//    cout<<endl;
    for(int i=2;i<=n;i++){
        for(int j=1;j<=k;j++){
            dp[i][j]=((j-a[i]-1<0?arr[j]:arr[j]-arr[j-a[i]-1])+mod)%mod;
        }
        for(int j=1;j<=k;j++){
            arr[j]=arr[j-1]+dp[i][j];
            arr[j]%=mod;
        }
    }
//    for(int i=1;i<=n;i++){
//        for(int j=1;j<=k;j++){
//            cout<<dp[i][j]<<' ';
//        }
//        cout<<endl;
//    }
    printf("%lld\n",dp[n][k]);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}




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

#define INF 1e9

int solve(int i,vector <int>& h,vector <int>& dp,int k){
	if(dp[i]>=0) return dp[i];
	int n = h.size();
	if(i==n-1){dp[i] = 0; return 0; }
	int m = INF;
	for(int j=i+1;j<=i+k&&j<n;j++){
		m=min(m,abs(h[i]-h[j])+solve(j,h,dp,k));
		}
	dp[i]= (m == INF) ? 0 : m;
	return m;
	}
int main(){
	int n,k;
	cin>>n>>k;
	vector <int> h (n,0);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	vector <int> dp (n+1,-1);
	cout<<solve(0,h,dp,k)<<"\n";
	return 0;
}



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

int main(){
	string s;
	int i=0;
	int a=0;
	int b=0;
	cin>>s;
	size_t size=s.length();  
	
	for(i=0;i<size;i++){
		if(s[i]=='A') a=a+1;
		if(s[i]=='B') b=b+1;
	}
	if(a>0 && b>0){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
al = list(map(int,input().split()))

ans = 1
mode = "center"
now = al[0]
for a in al:
    if mode == "center":
        if a > now:
            mode = "up"
            now = a
        elif a < now:
            mode = "down"
            now = a
    elif mode == "up":
        if a > now:
            now = a
        elif a < now:
            now = a
            mode = "center"
            ans += 1
    elif mode == "down":
        if a > now:
            now = a
            mode = "center"
            ans += 1
        elif a < now:
            now = a
print(ans)


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

int main() {
    int N;
    cin >> N;
    vector<int> T(N + 1), X(N + 1), Y(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> T[i] >> X[i] >> Y[i];
    }

    for (int i = 1; i <= N; i++) {
        int dist = abs(X[i] - X[i - 1]) + abs(Y[i] - Y[i - 1]);
        int time = T[i] - T[i - 1];
        if (time < dist || (time + dist) % 2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int a[30],n;
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	fo(i,0,n)cin>>a[i];
	int ans=0;
	fo(i,1,n-1) if((a[i]>a[i-1]&&a[i]<a[i+1])||(a[i]>a[i+1]&&a[i]<a[i-1]))ans++;
	cout<<ans<<endl;
	return 0;
}


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


int main()
{
    int t=1;
    //cin>>t;
    while( t-- )
    {
        int n,m,k;
        cin>>n>>m>>k;

        ll a[n],b[m];

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

            if( i>0 )
                a[i]=a[i]+a[i-1];
        }

        for( int i=0 ; i<m ; i++ )
        {
            cin>>b[i];

            if( i>0 )
                b[i]=b[i]+b[i-1];
        }

        if( k<a[0] && k<b[0] )
        {
            cout<<0;
            return 0;
        }
        if( k<b[0] )
        {
            auto it=upper_bound( a , a+n , k );
            it--;
            cout<<it-a+1;
            return 0;
        }

        if( k<a[0] )
        {
            auto it=upper_bound( b , b+n , k );
            it--;
            cout<<it-b+1;
            return 0;
        }


        auto it=upper_bound( b, b+m , k );
        it--;
        ll ans=it-b+1;

        for( int i=0 ; i<n ; i++ )
        {
            if( k<a[i] )
            break;

            ll rem=k-a[i];
            //3 4 240
            //60 90 120
            //80 150 80 150

            it = upper_bound( b , b+m , rem );
            it--;
            ll cur=it-b+1+(i+1);

            ans= max( ans, cur );
        }


        cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 6720
/*
___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat.
___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat.
___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb.

___az dast o zabane ke barayad ?
___kaz ohdeye shokrash be dar ayad !


___man be to dami gharar natvanam kard
___va ehsane to ra shomar natvanam kard
####################
___gar bar tane man zaban shavad har moyee
___yek shokre to az hezar natvanam kard

*/

#include <bits/stdc++.h>

#define pb push_back
#define SALI main
#define left(x) ((x)*2)
#define right(x) (((x)*2)+1)
#define fuck(x) cout << #x << " : " << x << endl;
#define findLowVec(v,x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define findUpVec(v,x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define findLowArr(a,n,x) (lower_bound(a, a+n, x) - a)
#define findUpArr(a,n,x) (upper_bound(a, a+n, x) - a)
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;

template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p)
{return out << "(" << p.first << ", " << p.second << ")";}

template<class A> ostream& operator <<(ostream& out, const vector<A> &v)
{out << "[";for(int i = 0; i < v.size(); i++) {if(i) out << ", ";out << v[i];}return out << "]";}

template<class A,class B> ostream& operator <<(ostream& out, const set<A,B> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

template<class A> ostream& operator <<(ostream& out, const set<A> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

const int N = 1e5 + 10;
int dp[N];
const int inf = 1e18L + 10;
int32_t SALI()
{
    int n,W; cin >> n >> W;
    int w[n];
    int v[n];
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
        sum += v[i];
    }
    for(int i = 1; i < N; i++){
        dp[i] = inf;
    }

    for(int i = 0; i < n; i++){
        for(int j = sum; j >= v[i]; j--){
            dp[j] = min(dp[j],dp[j-v[i]] + w[i]);
        }
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(dp[i] <= W){
            ans = i;
        }
    }
    cout << ans << endl;
}


/**< WRITEN BY ALI ADELKHAH */



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

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;}

const ll INF = 100100100100100100;
const ll MAX_V = 1000;
const ll MAX_E = 1000;
vector<vector<ll>> cost(MAX_V,vector<ll>(MAX_E,INF));

struct edge{
    // Dijkstraでは隣接リストを用いるのでfromはいらない
    // int from;
    int to;
    int c;

    public:
    edge(ll to, ll c){
        this->to = to;
        this->c = c;
    }
};

// 集合Xからの辺の最小コスト
vector<ll> mincost(MAX_V);

ll prim(const ll &V, const vector<vector<edge>> &ed){
    // V:頂点数

    ll res = 0;
    vector<bool> used(V+5,false);
    priority_queue<P, vector<P>, greater<P>> pq; // first:その頂点を接続するのに必要なコスト ,second:頂点番号
    P ps;
    ps.first = 0;
    ps.second = 0;
    pq.push(ps);
    // pq.push(P(0,0)):

    while(!pq.empty()){
        P p = pq.top();
        pq.pop();
        if(used[p.second]) continue; // もう集合Xに入っていたら無視
        used[p.second] = true;
        res += p.first; // priorityQueueを用いていることで必ず最適な辺を取得することができる．
        for(edge e : ed[p.second]){
            if(!used[e.to]) pq.push({e.c,e.to});
        }
    }

    return res;
}

int main(){
    ll V;
    cin >> V;

    vector<vector<edge>> ed(V);
    vector<P> X;
    vector<P> Y;
    rep(i,V){
        ll x,y; cin >> x >> y;
        X.push_back(P(x,i));
        Y.push_back(P(y,i));
    }
    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());
    rep(i,V-1){
        ll z1, z2 ,c, from, to;
        z1 = X[i].first; 
        z2 = X[i+1].first;
        c = abs(z1-z2);
        from = X[i].second; 
        to = X[i+1].second;
        edge e(from,c);
        edge re(to,c);
        ed[to].push_back(e);
        ed[from].push_back(re);
    }
    rep(i,V-1){
        ll z1, z2 ,c, from, to;
        z1 = Y[i].first; 
        z2 = Y[i+1].first;
        c = abs(z1-z2);
        from = Y[i].second; 
        to = Y[i+1].second;
        edge e(from,c);
        edge re(to,c);
        ed[to].push_back(e);
        ed[from].push_back(re);
    }

    // rep(i,V){
    //     cout << i << " :" << endl;
    //     rep(j,ed[i].size()){
    //         cout << ed[i][j].to << " " << ed[i][j].c << endl;
    //     }
    // }

    cout << prim(V, ed) << endl;
    return 0;
}

Measured memory_bytes: 19180
import sys
sys.setrecursionlimit(10**6)
 
N = int(input())  # 頂点数
C = [int(x) - 1  for x in input().split()]  # 頂点の色番号 (1~N) -> (0~N-1)
 
E = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)
    
def dfs(u, p = -1):
 
    color = C[u]  # 色番号
    VC[color].append(u)  # 色ごとに stack しておく
    
    s = 1  # 部分木サイズ（を格納する）
    for v in E[u]:
        if v == p:
            continue
            
        child[u] = 0  # v の方向にある子孫のうち辿れる頂点の数 = s - 子孫にある、同色を根とする部分木のサイズの合計
        ret = dfs(v, u)
 
        s += ret  # 純粋な部分木のサイズを計算
        child[u] += ret  # 同色の頂点が切り離されたあとの部分木サイズ
        
        ans[color] -= child[u] * (child[u] + 1) // 2        
 
    VC[color].pop()
    if VC[color]: # 上位に同じ色がある場合
        child[VC[color][-1]] -= s  # 一番近い同色から、自分の部分木の大きさをひく
    else:  # 上位に同じ色がない場合
        root_size[color] -= s  # 上位に残っている頂点の数
        
    return s

child = [0] * N  # 辿っている子の中でのの残り数　とりあえず 0で初期化
root_size = [N] * N  # 根方向に残っている頂点の数（を格納する。操作前は N 全部）
VC = [ [] for _ in range(N)]  # 色番号ごと
ans = [N*(N+1)//2] * N  # 色ごとの（残りの）組み合わせ数　初期値は 全点の組み合わせ
 
dfs(0)
 
for i in range(N):
    print(ans[i] - root_size[i] * (root_size[i] + 1) // 2)

Measured memory_bytes: 305068
//
//  main.cpp
//  Hello
//
//  Created by Gasser Mamdouh on 29/10/2019.
//  Copyright © 2019 Gasser Mamdouh. All rights reserved.
//

#include <iostream>
#include <map>
#include <utility>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <string.h>
#include <list>
#include <set>
#include <stdio.h>
#include <numeric>
#include <queue>
#include <memory>
#include <limits>
#include <iomanip>

using namespace std;


int main(){
    int n;
    cin >> n;
    vector<int> height(n), ans(n);
    for(int i = 0; i < n; i++){
        cin >> height[i];
    }
    
    ans[0] = 0;
    ans[1] = abs(height[0] - height[1]);
    for(int i = 2; i < n; i++){
        ans[i] = min(ans[i - 1] + abs(height[i] - height[i - 1]), ans[i - 2] + abs(height[i] - height[i - 2]));
    }
    
    cout << ans[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#include <queue>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	map<ll, bool> can;
	rep(i, 0, n) {
		int a;
		cin >> a;
		if (can[a])can[a] = false;
		else can[a] = true;
	}
	ll ans = 0;
	for (auto i = can.begin();i != can.end();i++) {
		if (i->second)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
  int n, x;
  cin >> n >> x;
  int min = INT_MAX;
  int ans = 0;
  
  for(int i = 0; i < n; i++)
  {
    int m;
    cin >> m;
    if(min > m)
    {
      min = m;
    }
    x -= m;
  }
  
  ans += n;
  ans += x / min;
  
  cout << ans << endl;
  
}

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

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    srand(322179);
#ifdef LOCAL
    freopen("/root/alg/clion_main/input.txt", "rt", stdin);
    freopen("/root/alg/clion_main/output.txt", "wt", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#define all(x) x.begin(), x.end()
#define vb vector<bool>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define vc vector
#define $ make_pair

#ifndef LOCAL
#define cerr if(0) cerr
#define DBG(...) (true)
#endif

#define D double
#define int long long

// ----------------------------- CODE NOW ------------------------




signed main() {
    doRoutine();

    int n, k;
    cin >> n >> k;

    int ans = (n / k) * (n / k) * (n / k);
    if (k % 2 == 0) {
        int x = k / 2;
        if (n >= x) {
            ans += ((n - x) / k + 1) * ((n - x) / k + 1) * ((n - x) / k + 1);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, x;
  cin>>n>>x;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  sort(a, a+n);
 
  int ans = 0;
  for (int i=0; i<n; i++) {
    x -= a[i];
    if (x < 0) {
      break;
    }
    ++ans;
  }
  if (x > 0) {
    cout<<ans-1<<endl;
  } else {
    cout<<ans<<endl;
  }
}

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

int main()
{
  string s;
  cin>>s;
  int n,i;
  bool flag=0;
  n=s.length();
  for(i=0;i<n;i++){
    if(i%2==0&&s[i]=='L'){
      flag=1;break;
    }
    else if(i%2==1&&s[i]=='R'){
      flag=1;break;
    }
  }
  if(flag==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

using namespace std;

#define ll long long
#define mod (ll)1000000007

const ll INF = 1e11;

void solve(){

    int n; cin >> n;
    ll arr[n];
    for(int i = 0; i < n; ++i)
        cin >> arr[i];
    int ans = 0;
    sort(arr, arr+n);
    //vector<ll> arr;
    //for(int i = 0; i < n-1; ++i)
    //    if(tarr[i] != tarr[i+1]) arr.push_back(tarr[i]);
    //arr.push_back(tarr[n-1]);
    //n = arr.size();
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            for(int k = j+1; k < n; ++k){
                if( arr[i] != arr[j] && arr[j] != arr[k] && arr[k] != arr[i] 
                 && arr[i] + arr[j] > arr[k]) ++ans;
            }
        }
    }
    cout << ans << endl;

    return;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    //int test; cin >> test;
    //for(int t = 1; t <= test; ++t){
        solve();    
    //}

	return 0;
}



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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

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

class UnionFind {
    std::vector<int> p;

public:
    UnionFind(int n) : p(n, -1) {}

    int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }

    bool same(int x, int y) { return root(x) == root(y); }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (p[y] < p[x]) std::swap(x, y);
        if (p[x] == p[y]) --p[x];
        p[y] = x;
        return true;
    }
};


int conn[200][200];

int color[200];

int flg = 1;

void check(int r, int c) {
    if (color[r] != -1) {
        if (color[r] != c) {
            flg = 0;
        }
        return;
    } else {
        color[r] = c;
    }

    for (int i = 0; i < 200; i++) {
        if (conn[i][r]) {
            check(i, c ^ 1);
        }
    }
}

void solve(long long N, std::vector<string> S) {
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            conn[i][j] = S[i][j] == '1';
    memset(color, -1, sizeof(color));
    for (int i = 0; i < N; i++) {
        if (color[i] == -1) {
            check(i, 0);
        }
    }

    if (!flg) {
        cout << -1 << endl;
        return;
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (conn[i][j] == 0) {
                conn[i][j] = static_cast<int>(1e9);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for(int k = 0 ; k < N; k++){
                conn[j][k] = min(conn[j][k], conn[j][i] + conn[i][k]);
            }
        }
    }
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < N ; j++){
            if( i != j ) ans = max(conn[i][j], ans);
        }
    }
    cout << ans + 1 << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
using namespace std;
double p[110];
int q[110];
double r[110];
long long mod=100000007;
int v[110];
double eps=1e-9;
int C[110][110];
int main(){
	int a;
	C[0][0]=1;
	for(int i=0;i<106;i++){
		for(int j=0;j<=i;j++){
			C[i+1][j]=(C[i+1][j]+C[i][j])%mod;
			C[i+1][j+1]=(C[i+1][j+1]+C[i][j])%mod;
		}
	}
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%lf%d%lf",p+i,q+i,r+i);
		for(int i=0;i<a;i++)v[i]=0;
		long long ret=1;
		double val=0;
		int rem=a;
		for(int i=0;i<a;i++){
			if(v[i])continue;
			int at=i;
			double m=999999999;
			int cnt=0;
			int sz=0;
			while(!v[at]){
				v[at]=1;
				val+=1.0/r[at];
				if(m-eps>1.0/p[at]-1.0/r[at]){
					m=1.0/p[at]-1.0/r[at];
					cnt=1;
				}else if(m>1.0/p[at]-1.0/r[at]-eps){
					cnt++;
				}
				at=q[at];
				sz++;
			}
			ret=ret*cnt%mod;
			val+=m;
			ret=ret*C[rem][sz]%mod;
			rem-=sz;
		}
		printf("%.12f %lld\n",val,ret);
	}
}

Measured memory_bytes: 1136
#include <bits/stdc++.h>
//https://qiita.com/ysuzuki19/items/d89057d65284ba1a16ac
#define debug(var)                  \
    do {                            \
        std::cout << #var << " : "; \
        view(var);                  \
    } while (0)
template <typename T>
void view(T e) { std::cout << e << std::endl; }

template <typename T>
void view(const std::vector<T>& v) {
    for (const auto& e : v) {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}

template <typename T>
void view(const std::vector<std::vector<T>>& vv) {
    for (const auto& v : vv) {
        view(v);
    }
}

using namespace std;
//yosupo
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

int main() {
    int K;
    cin >> K;
    if (K % 2 == 0 || K % 5 == 0) {
        cout << -1 << endl;
        return 0;
    }
    int L = K % 7 == 0 ? 9 * K / 7 : 9 * K;
    int res = 1;
    int Mod = 10 % L;
    int Max = 90000000;
    while (Max--) {
        if (Mod == 1) {
            cout << res << endl;
            return 0;
        }
        Mod = (Mod * 10) % L;
        ++res;
    }
    return 0;
}

Measured memory_bytes: 3640
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
cnt = Counter(S)
n = len(S)

if n == 1:
    print("YES")
    exit()
elif n == 2:
    if S[0] != S[-1]:
        print("YES")
    else:
        print("NO")
    exit()

ok = False
x = list(cnt.values())
if len(x) < 3:
    print("NO")
    exit()
mn = min(x)
for i in range(3):
    x[i] -= mn
x = sorted(x)
if x[1] <= 1 and x[2] <= 1:
    ok = True

if ok:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9488
L,R = map(int,input().split())
a = [i for i in range(L,min(L+2019,R)+1)]
b = len(a)
ans = 10**10
for i in range(b):
    for j in range(b):
        if i==j:
            break
        ans = min(ans,a[i]*a[j]%2019)
print(ans)

Measured memory_bytes: 3060
import std.stdio, std.algorithm, std.conv, std.array, std.string;

void main()
{
    long[][][] MEMO;
    MEMO.length = 51;
    foreach (ref memo1; MEMO) {
        memo1.length = 51;
        foreach (ref memo2; memo1) {
            memo2.length = (50*50+1);
            foreach (ref memo3; memo2) {
                memo3 = -1;
            }
        }
    }

    auto na = readln.chomp.split(" ").map!(to!int).array;
    auto n = na[0];
    auto a = na[1];

    auto xs = readln.chomp.split(" ").map!(to!int).array;

    long solve(int i, int num, int sum) {
        if (MEMO[i][num][sum] != -1) return MEMO[i][num][sum];
        MEMO[i][num][sum] = i == n ?
            (sum != 0 && sum == num*a ? 1 : 0)
        :
            (solve(i+1, num, sum) + solve(i+1, num+1, sum+xs[i]));

        return MEMO[i][num][sum];
    }
    writeln(solve(0, 0, 0));
}

Measured memory_bytes: 54268
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  xs <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  print . fst . head . filter ((== 0) . snd) . zip [1..] $ xs

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 3804
#include <stdio.h>

int main(void)

{

  int a,b,c,i,w;

  w=0;


  scanf("%d %d %d",&a,&b,&c);

  for(i=a;i<=b;i++)


  {


    if(c%i==0)


    {


      w=w+1;


    }


  }


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


  return 0;


}

Measured memory_bytes: 596
# coding: utf-8
str_input = input()

counter = 0

counter = str_input.count("R")

if counter == 3 and str_input[1] in "R":
    pass
elif counter == 2 and str_input[1] in "R":
    pass
elif counter == 2 and str_input[1] in "S":
    counter -= 1
print(counter)

Measured memory_bytes: 8972
#include <iostream>
#include <string>
using namespace std;
char plusminus(int a) {
	if (a == 1) {
		return '+';
	}
	else {
		return '-';
	}
}

int main() {
	int pattern[3][8] = {
		{-1,-1,-1,-1,1,1,1,1},
		{-1,-1,1,1,-1,-1,1,1},
		{-1,1,-1,1,-1,1,-1,1} 
	};
	int num[4];
	int X = 7;
	int ans = 0;
	string s;

	cin >> s;

	for (int i = 0; i < 4; i++)
	{
		num[i] = s[i] - '0';
	}

	for ( ans = 0; ans < 8; ans++)
	{
		int tmp = num[0];
		
		for (int i = 0; i < 3; i++)
		{
			tmp += pattern[i][ans] * num[i + 1];
		}

		if (tmp == X) {
			break;
		}
	}

	cout << num[0];
	for (int i = 0; i < 3; i++)
	{
		cout << plusminus(pattern[i][ans]) << num[i + 1];
	}
	cout << "=" << X << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include <vector>
using namespace std;
int main(){
  int N = 0;
  cin >> N;

  string S = "";
  cin >> S;

  if (N % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }

  for (int i = 0; i < (N / 2); i++) {
    if (S[i] != S[(N / 2) + i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N;
        N = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        int[] a = new int[N];
        for(int j=0;j<N;j++){
            a[j] = int.Parse(str[j]);
        }
        Array.Sort(a,(x,y) => y - x);
        int i = 0;
        while(i < N-1 && a[i+1] > i+1){
            i++;
        }
        if((a[i] - i) % 2 == 0){
            sb.Append("First\n");
        }
        else{
            int c = 1;
            while(i+c < N && i+1 == a[i+c]){
                c++;
            }
            if(c % 2 == 0){
                sb.Append("First\n");
            }
            else{
                sb.Append("Second\n");
            }
        }
    }    
}

Measured memory_bytes: 16856
from collections import Counter

n = int(input())
A = list(map(int,input().split()))

cnt = Counter(A)

parts = []
for k in sorted(cnt.keys(),reverse=True):
    if cnt[k] >= 4:
        parts += [k,k]
    elif cnt[k] >= 2:
        parts.append(k)

if len(parts) >= 2:
    print(parts[0]*parts[1])
else:
    print(0)

Measured memory_bytes: 105524
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())
 
int main()
{
    int k,a,b;
    cin >> k >> a >>b;

    int a0 = a/k;
    int b0 = b/k;

    if(a%k==0 || b%k==0 || b0>a0) cout << "OK" << endl;
    else cout << "NG" << endl;
}

Measured memory_bytes: 3636
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long  i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}


int main()
{
	long long n, cnt = 0;
	string s, t;

	cin >> s >> t;

	cout << t + s << endl;

	return 0;
}

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define prll(v) for (auto i: v) cout << i << " ";

int main() {
    fast
    ll n, k;
    cin >> n;
    ll a = 0;
    vi v(n+1), r(n+1);
    REP(i, 1, n+1) {
        cin >> v[i];
        r[v[i]] = i;
    }
    REP(i, 1, n+1)
        cout << r[i] << " ";
    cout << endl;
}


Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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

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

    string N;
    ll K;
    cin >> N >> K;

    while (N.size() < 100) {
        N = '0' + N;
    }

    ll dp[101][2][4];

    Rep (i, 101) Rep (j, 2) Rep (k, 4) dp[i][j][k] = 0;
    dp[0][0][0] = 1;

    Rep (i, 100) {
        // smaller 1 to 1
        Rep (j, 4) {
            dp[i+1][1][j] += dp[i][1][j];
        }
        Rep (j,3) {
            dp[i+1][1][j+1] += 9 * dp[i][1][j];
        }

        // smaller 0 to 0
        if (N[i] == '0') {
            Rep (j, 4) dp[i+1][0][j] += dp[i][0][j];
        } else {
            Rep (j, 3) dp[i+1][0][j+1] += dp[i][0][j];
        }

        // smaller 0 to 1
        ll now = N[i] - '0';
        if (now != 0) {
            Rep (j, 4) dp[i+1][1][j] += dp[i][0][j];
            Rep (j, 3) dp[i+1][1][j+1] += (now - 1) * dp[i][0][j];
        }
    }

    // for (int i = 90; i <= 100; i++) {
    //     Rep (j, 4) {
    //         cout << dp[i][1][j] << " \n"[j==3];
    //     }
    // }

    cout << dp[100][0][K] + dp[100][1][K] << "\n";
}

Measured memory_bytes: 256
n=input()
n=int(n)
c=0
a=list(map(int,input().split()))
b=list(map(int,input().split()))
m=0
for i in range(n):
  kill=min(a[i],b[i]+m)
  c+=kill
  m=min(b[i]+m-kill,b[i])
c+=min(m,a[n])
print(c)

Measured memory_bytes: 19116
#include <iostream>
using namespace std;
int main(){
int x,y;
  while(cin>>x>>y){
     if(x==0&&y==0)break;
          for(int k=1;k<=x;k++){
                       for(int j=1;j<=y;j++){
                               cout<<"#";
                         }    
                 cout<<endl;
           }
cout<<endl;
  }
}

Measured memory_bytes: 3096
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "unsafe"
no = "safe"

def main():
    s,w = mi()
    if w>=s:
        print(yes)
    else:
        print(no)




main()




Measured memory_bytes: 10020
#include <stdio.h>

int main()
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x+r>W||x-r<0||y+r>H||y-r<0)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
	
}

Measured memory_bytes: 584