akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

    long n = scanner.nextLong();
    long s = scanner.nextLong();

    if (n < s) {
      System.out.println(-1);
      return;
    }

    for (int d = 39; d > 1; d--) {
      long b = lowerBound(d, n);
      while (d * Math.log(b) <= Math.log(n)) {
        if (test(b, n, s)) {
          System.out.println(b);
          return;
        }
        b++;
      }
    }

    // d = 1
    for (int a1 = (int) Math.sqrt(n - s); a1 >= 1; a1--) {
      if ((n - s) % a1 == 0) {
        long b = (n - s) / a1 + 1;
        long a0 = n - a1 * b;
        if (a0 >= 0 && a0 < b && a0 + a1 == s) {
          System.out.println(b);
          return;
        }
      }
    }

    // d = 0
    if (n == s) {
      System.out.println(n + 1);
    } else {
      System.out.println(-1);
    }
  }

  private static boolean test(long b, long n, long s) {
    if (b < 2) return false;
    long sum = 0;
    while (n > 0) {
      sum += n % b;
      n /= b;
    }
    return sum == s;
  }

  private static long lowerBound(int d, long n) {
    long left = 1;
    long right = n;
    double logn = Math.log(n);
    while (right - left > 1) {
      long mid = (left + right) / 2;
      double logm = (d + 1) * Math.log(mid);
      if (logm > logn) {
        right = mid;
      } else {
        left = mid;
      }
    }
    return right;
  }
}


Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>

#define INT32_MAX 2147483647

using namespace std;

struct cloth {
    int min,max,c;

    bool operator<(const cloth& right) const {
        return c < right.c;
    }
};

int d;
int t[201];
cloth clothes[201];
int wearablec[201][201];
int wearablenum[201];
//[day][prec]
int mem[201][101];

inline bool isrange(int temp, cloth *c) {
    return (c->min <= temp) && (temp <= c->max);
}

int cal(int today, int prec) {
    if (today == d) {
        return 0;
    }

    if (mem[today][prec] != -1) {
        return mem[today][prec];
    }

    int todaymax = -1;
    for (int i = 0; i < wearablenum[today]; ++i) {
        int temp = abs(prec - wearablec[today][i]) + cal(today + 1, wearablec[today][i]);
        if (todaymax < temp) {
            todaymax = temp;
        }
    }

    mem[today][prec] = todaymax;
    return todaymax;
}

int main() {
    for (int i = 0; i < 201; ++i) {
        for (int j = 0; j < 101; ++j) {
            mem[i][j] = -1;
        }
    }
    int n;
    cin >> d >> n;
    for (int i = 0; i < d; ++i) {
        cin >> t[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> clothes[i].min >> clothes[i].max >> clothes[i].c;
    }

    for (int i = 0; i < d; ++i) {
        int num = 0;
        for (int j = 0; j < n; ++j) {
            if (isrange(t[i], &clothes[j])) {
                wearablec[i][num] = clothes[j].c;
                num++;
            }
        }
        wearablenum[i] = num;
    }

    int max = -1;
    for (int i = 0; i < wearablenum[0]; ++i) {
        int temp = cal(1, wearablec[0][i]);
        if (max < temp) {
            max = temp;
        }
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

bool is_prime(int x){
	if(x==1){
		return 0;
	}
	for(int i=2;i*i<=x;i++){
		if(x%i==0){
			return 0;
		}
	}
	return 1;
}

int32_t main(){
	int x;
	cin>>x;
	for(int i=x;;i++){
		if(is_prime(i)){
			cout<<i;
			return 0;
		}
	}
}


Measured memory_bytes: 256
/*
ID:diamond7
PROG:
LANG:C++
*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<fstream>
#define ll long long
#define usaco freopen(".in","r",stdin);freopen(".out","w",stdout);
using namespace std;
int read(){
	int flag=1;
	int sum=0;
	char c;
	c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') flag=-1;
		c=getchar();
	}
	while('0'<=c&&c<='9'){
		sum*=10;
		sum+=c-48;
		c=getchar();
	}
	return flag*sum;
}
int n;
int a[100010][5];
long long dp[100010][5];
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=3;j++){
			a[i][j]=read();
		}
	}
	for(int i=1;i<=3;i++){
		dp[1][i]=a[1][i];
	}
	for(int i=2;i<=n;i++){
		dp[i][1]=max(dp[i-1][2]+a[i][1],dp[i-1][3]+a[i][1]);
		dp[i][2]=max(dp[i-1][1]+a[i][2],dp[i-1][3]+a[i][2]);
		dp[i][3]=max(dp[i-1][1]+a[i][3],dp[i-1][2]+a[i][3]);
	}
	cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<endl;
	return 0;
}




Measured memory_bytes: 6144
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

n,m=MAP()
a=MAP()

#dp[price]=num of coins?

dp=[float('inf') for _ in range(n+1)]
dp[0]=0

for i in range(n+1):
	for j in a:
		if i+j <= n:
			dp[i+j]=min(dp[i]+1,dp[i+j])

print(dp[-1])


Measured memory_bytes: 7388
import java.util.Scanner;
import java.util.Stack;

public class Main {

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

		String str = sc.nextLine();
		int n = str.length();

		Stack<Integer> stack1 = new Stack<>();
		Stack<Pair> stack2 = new Stack<>();

		int sum = 0;

		for (int i=0; i<n; i++) {
			if (str.charAt(i)=='\\') {
				stack1.push(i);
			} else if (str.charAt(i)=='/') {
				if (!stack1.isEmpty()) {
					int j = stack1.pop();
					int a = i - j;
					sum += a;
					while (!stack2.isEmpty()&&stack2.peek().left>j) {
						a += stack2.pop().area;
					}
					stack2.push(new Pair(j, a));
				}
			}
		}

		System.out.println(sum);

		int size = stack2.size();
		int[] areas = new int[size];
		for (int i=size-1; i>=0; i--) {
			areas[i] = stack2.pop().area;
		}
		System.out.print(size);
		for (int i=0; i<size; i++) {
			System.out.print(" "+areas[i]);
		}
		System.out.println();

		sc.close();
	}

	static class Pair {
		int left, area;
		public Pair (int left, int area) {
			this.left = left;
			this.area = area;
		}
	}

}

Measured memory_bytes: 30168
n = int(input())
ab = sorted([[int(i) for i in input().split()] for i in range(n)], key=lambda x:x[1])[::-1]

time = ab[0][1] - ab[0][0]
for a,b in ab[1:]:
    time = min(time, b)
    time -= a

print("No" if time < 0 else "Yes")

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

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

    int N;
    cin >> N;

    vector<char> S(N);

    for(int i = 0; i < N; i++) cin >> S[i];

    for(int i = 0; i < N; i++) {
        if(S[i] == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }

    cout << "Three" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> void chmax(Type_a &a,const Type_b &b){if(a<b)a=b;}
template<class Type_a,class Type_b> void chmin(Type_a &a,const Type_b &b){if(a>b)a=b;}
template<class Type> Type igcd(Type x,Type y){if(x==0||y==0)return (x>y)?x:y;return (y%x)?igcd(y%x,x):x;}
template<class Type> Type ilcm(Type x,Type y){return x/igcd(x,y)*y;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

//解説参考.
int main(){
	int n;
	cin>>n;
	
	vi a(n);
	REP(i,n){
		cin>>a[i];
		a[i]-=i+1;
	}
	sort(ALL(a));
	//line(a);
	
	if(n%2){
		int hoge=a[n/2];
		llong ans=0;
		REP(i,n) ans+=abs(a[i]-hoge);
		cout<<ans<<endl;
	}else{
		int hoge[]={a[n/2-1],a[n/2]};
		llong ans[2]={};
		REP(i,n)REP(j,2) ans[j]+=abs(a[i]-hoge[j]);
		cout<<min(ans[0],ans[1])<<endl;
	}
}

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




using namespace std;

const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;

#define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

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

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


class UnionFind{
    public:
    vector<int> par;
    vector<int> val;
    int root(int input){
        if(par[input]==input) return input;
        return par[input] = root(par[input]);
    }
    void unite(int val1, int val2){
        par[val1] = root(par[val2]);
    }
    bool same(int val1, int val2){
        return root(par[val1]) == root(par[val2]);
    }
    UnionFind(){
        return;
    }
};

ll X,M;

signed main() {
    
    int A,B,C,K; cin >> A >>B >> C >> K;
    int ret = 0;
    if(A >= K){
        ret = K;
    }
    else if ((A+B) >= K){
        ret = A;
    }
    else{
        ret = A - (K - (A+B));
    }
  
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    string s;
    cin >> s;

    s = s.substr(0,3);

    cout << s << endl;

    return 0;
}


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

#define rep0(n) for(int i=0;i<n;i++)
#define rep(n) for(int i=1;i<=n;i++)

double const pi = 3.1415926535;
int const mod = 1000000007;
int const inf = 2147483647;

int yesno(bool f, string yes, string no) {
	if (f)cout << yes << endl;
	else cout << no << endl;
	return 0;
}

int main() {

	string a, b, c;
	cin >> a >> b >> c;
	cout << a[0] << b[1] << c[2] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N,M,X,Y; cin >>N>>M>>X>>Y;
    VI x(N),y(M);
    REP(i,N) cin >> x[i];
    REP(i,M) cin >> y[i];
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());

    if(x[N-1] < y[0] && y[0] > X && x[N-1] < Y){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stdlib.h>
#include<vector>
#include<stack>
#include<bitset>
#include<set>
#define maxn 300005
using namespace std;
typedef long long ll;
int n;
int a[maxn];
set<int> s;
queue<int> q;
int main()
{
	int x;
	cin>>x;
	cout<<(1000-x%1000)%1000<<endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)

void corr(vector<ll> const& l,int& right){
  int left=0;
  int mid;
  int key=right;
  while(right-left<1){
    mid=(left+right)/2;
    if(l[mid]==l[key])right=mid;
    else left=mid;
  }
}
int bs(vector<ll> const& l,int key){
  int left=0;
  int right=l.size()-1;
  int mid;
  while(right>left+1){
    mid=(left+right)/2;
    if(l[mid]>key)right=mid;
    else left=mid;
  }
  corr(l,right);
  if(key<l[0])right=0;
  if(key>=l[l.size()-1])right=l.size();
  return right;
}
int main(){
  int n;
  cin>>n;
  vector<ll> a(n);
  vector<ll> b(n+1);
  vector<ll> c(n+1);
  vector<ll> b_sum(n+1,0);
  vector<ll> b_num(n+1,0);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  rep(i,n)cin>>c[i];
  b[n]=1000000007;
  c[n]=1000000007;
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  //  rep(i,n)b_num[i]=n-bs(c,b[i]);
  int pp=0;
  rep(i,n){
    while(c[pp]<=b[i])pp++;
    b_num[i]=n-pp;
  }
  b_sum[n-1]=b_num[n-1];
  rep1(i,n-1)b_sum[n-i-1]=b_sum[n-i]+b_num[n-i-1];
  ll ans=0;
  //  rep(i,n)cout<<b_sum[i]<<" "<<b_num[i]<<endl;
  //  rep(i,n)ans+=b_sum[bs(b,a[i])];
  int p=0;
  rep(i,n){
    while(b[p]<=a[i])p++;
    ans+=b_sum[p];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
typedef long long ll;
int N,K;
int C[1005][1005], fac[1005], inv[1005];
int L[75];
int tot;
queue<int> Q;
int nextt[75], que[75];
int vis[75];

int qpow(int a, int b) {
	int res = 1;
	while(b) {
		if(b&1) res=res*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return res;
}
void init() {
	C[0][0] = 1;
	for(int i = 1 ; i <= 1000 ; i++) {
		C[i][0] = 1;
		for(int j = 1 ; j <= i ; j++) {
			C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
			C[i][j] %= mod;
		}
	}
	fac[0] = 1;
	for(int i = 1 ; i <= 1000 ; i++) fac[i] = fac[i - 1]*i%mod;
	inv[1000] = qpow(fac[1000],mod-2);
	for(int i = 999 ; i >= 0 ; i--) inv[i] = inv[i + 1]*(i + 1)%mod;
}

bool check(int cnt) {
	if(tot < cnt) return false;
	int sum[75];
	memset(sum,0,sizeof(sum));
	int p = 1;
	for(int i = cnt ; i >= 1 ; i--) {
		sum[que[i]]++;
		if(L[p] >= 2) {
			if(nextt[que[i]]==0) return false;
			sum[nextt[que[i]]] += L[p] - 1;
		}
		p++;
	}
	for(int i = K ; i >= 1 ; i--) {
		sum[i] += sum[i + 1];
	}
	for(int i = K; i >= 1; i--) {
		if(sum[i] > K - i + 1) return false;
	}
	return true;
}

int ans=0;
bool dfs(int pre,int dep,int len) {
	if(len > N) return false;
	if(!check(dep)) return false;
	
	int k = dep + 1;
	for(int i = 1 ; i <= dep ; i++) {
		if(L[i] == 1) k++;
		else k += 2 * L[i] - 1;
	}
	int cnt = C[N + k - len  - 1][k - 1] * fac[dep]%mod;
	
	int count = 1;
	
	for(int i = 2 ; i <= dep ; i++) {
		if(L[i] != L[i - 1]) {
			cnt = cnt * inv[count] % mod;
			count = 0;
		}
		count++;
	}
	
	cnt = cnt * inv[count]%mod;
	ans += cnt;
	ans %= mod;
	ans = (ans + mod)%mod;
	
	
	if(dep >= tot) return true;
	for(int i = pre ; i <= 70 ; i++) {
		int tmp = len;
		if(dep != 0) tmp++;
		if(i == 1 || i == 2) tmp++;
		else tmp += 2 * i - 3;
		L[dep + 1] = i;
		if(!dfs(i,dep + 1,tmp)) break;
	}
	return true;
}

char s[75];
signed main() {
	init();
	cin >> N >> K;
	scanf("%s",s + 1);
	tot = 0;
	for(int i = 1 ; i <= K ; i++) {
		if(s[i] == 'r') {
			que[++tot] = i;
			for(int j = i ; j <= K ; j++) {
				if(s[j] == 'b' && !vis[j]) {
					nextt[i] = j;
					vis[j] = 1;
					break;
				}
			}
		}
	}
	dfs(1,0,0);
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    int res = INT_MAX;
    for (int i = 0; i < N; i++)
    {
        int c = 0;
        int Ai = A.at(i);
        while (Ai % 2 == 0)
        {
            c++;
            Ai /= 2;
        }
        res = min(res, c);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
/*

対角がゼロ

実際の道が最小になるとは限らないが
最小は何かしらの道?
任意のiに対して, そこからの距離が最小になるようなjは, 道?

短い順に見て行って, 未連結ならその長さでつなぐ
連結で, 
さらにすでにある長さ=Aでの長さ: 何もしない
> その区間をつなぐ
< エラー


ijを繋いだら, どこが変わる?






*/



#include<bits/stdc++.h>
using namespace std;
typedef pair<long,pair<long,long>>P;
int main(){
  long N;cin>>N;
  vector<vector<long>> A(N,vector<long>(N)),B(N,vector<long>(N,INT_MAX));
  long ans=0;
  for(long i=0;i<N;i++)B[i][i]=0;
  priority_queue<P,vector<P>,greater<P>> q;
  for(long i=0;i<N;i++)for(long j=0;j<N;j++){
    cin>>A[i][j];
    if(i<j)
      q.push(P(A[i][j],pair<long,long>(i,j)));
  }
  while(q.size()){
    P p=q.top();q.pop();
    long l=p.first,i=p.second.first,j=p.second.second;   
    if(B[i][j]<l){
      cout<<"-1"<<endl;return 0;
    }
    if(B[i][j]>l){
      B[i][j]=l;B[j][i]=l;ans+=l;
      for(long x=0;x<N;x++)for(long y=0;y<N;y++)
        B[x][y]=min(B[x][y],B[x][i]+B[i][y]);
      for(long x=0;x<N;x++)for(long y=0;y<N;y++)
        B[x][y]=min(B[x][y],B[x][j]+B[j][y]);
     
    }
    
  }
  cout<<ans<<endl;
}











Measured memory_bytes: 6360
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	char line[36][2],line2[36][2];
	int time;
	cin >> time;
	for (int i = 0; i < time; ++i) {
		cin >> line[i][0] >> line[i][1];
		line2[i][0] = line[i][0];
		line2[i][1] = line[i][1];
	}
	for (int i = 0; i < time - 1; ++i) {
		for (int i2 = time - 1; i2 > i; --i2) {
			if (line[i2][1] < line[i2 - 1][1]) {
				swap(line[i2], line[i2 - 1]);
			}
		}
	}
	for (int i = 0; i < time-1; ++i) {
		cout << line[i][0] << line[i][1] << " ";
	}
	cout << line[time - 1][0] << line[time - 1][1] << endl << "Stable" << endl;

	int place;
	for (int i = 0; i < time - 1; ++i) {
		place = i;
		for (int i2 = i+1; i2 < time; ++i2) {
			if (line2[place][1] > line2[i2][1]) {
				place = i2;
			}
		}
		if (place != i) {
			swap(line2[i], line2[place]);
		}
	}
	for (int i = 0; i < time - 1; ++i) {
		cout << line2[i][0] << line2[i][1] << " ";
	}
	cout << line2[time - 1][0] << line2[time - 1][1] << endl;
	int ans=0;
	for (int i = 0; i < time; ++i) {
		if (line[i][0] == line2[i][0])ans++;
	}
	if (ans == time) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}
	return 0;
}

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

int main() {
   string N;
   cin >> N;
   int count=0;
   for (int i=0; i<N.size(); i++) {
       count+=N[i]-'0';
   }
   if (count%9==0) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 3716
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
//int const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

int N,M;

int main(){
    cin>>N>>M;

    int ans=1900*M+100*(N-M);
    rep(i,M) ans*=2;

    cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int mincost(int n,int *h,int k){
    int dp[n+1];
    dp[0]=0;
    dp[1]=0;
    for(int i=2;i<=n;i++){
        int val=INT_MAX;
        for(int j=max(i-k,1);j<i;j++){
            val=min(val,abs(h[j-1]-h[i-1])+dp[j]);
        }
        dp[i]=val;
    }
    return dp[n];
}
int main() {
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    cout<<mincost(n,h,k)<<endl;
    
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

/////////////////////////////////////////////////////////////
ll gcd(ll a, ll b) {
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
/////////////////////////////////////////////////////////////

ll a, b, c, d;

ll cd_lcm;

ll ans;

ll calc(ll x) {
  return x - (x / c + x / d - x / cd_lcm);
}

int main(void) {
  // Here your code !
  scanf("%lld %lld %lld %lld", &a, &b, &c, &d);

  cd_lcm = c * d / gcd(c, d);

  ans = calc(b) - calc(a - 1);

  printf("%lld\n", ans);

  return 0;
}


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

using u64 = std::uint64_t;
constexpr u64 inf = std::numeric_limits<u64>::max();

#define REP(i, n) for (u64 i = 0; i < (n); ++i)

namespace io {
  constexpr int is = 1 << 17;
  char ib[is], *ip = ib + is, it;
  inline char getc() {
    if (ip == ib + is) { read(STDIN_FILENO, ib, is); ip = ib; }
    return *ip++;
  }
  inline u64 scan() {
    u64 r = 0;
    if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
    else while ((it = *ip++) & 16) r = r * 10 + it - '0';
    return r;
  }
  constexpr int os = 1 << 17;
  char ob[os], *op = ob, ot;
  inline void putc(const char c) {
    *op++ = c;
    if (op == ob + os) { write(STDOUT_FILENO, ob, os); op = ob; }
  }
  /* x shoud be greater than or equal to zero */
  inline void print(u64 x) {
    char d[20];
    int i = 0;
    while (true) {
      d[i] = x % 10 + 48;
      x /= 10;
      ++i;
      if (x <= 0) break;
    }
    while (i--) {
      putc(d[i]);
    }
  }
  inline void flush() {
    write(STDOUT_FILENO, ob, op - ob);
  }
}

u64 collect(const vector<vector<u64>> &G, const vector<u64> &H, u64 u, u64 v, u64 p) {
  if (u == v) return 0;
  for (auto e : G[u]) {
    u64 t = H[e] ^ u;
    if (t == p) continue;
    u64 s = collect(G, H, t, v, u);
    if (s != inf) {
      return s | (1ULL << e);
    }
  }
  return inf;
}

u64 search(u64 ans, u64 j, u64 m, u64 mask, vector<u64> &paths) {
  if (j != m) {
    return (
      search(ans, j + 1, m, mask, paths)
    - search(ans, j + 1, m, mask | paths[j], paths)
    );
  } else {
    return ans >> __builtin_popcountll(mask);
  }
}

signed main() {
  u64 n = io::scan();
  auto G = vector<vector<u64>>(n);
  auto H = vector<u64>(n);
  REP(i, n - 1) {
    u64 a = io::scan() - 1;
    u64 b = io::scan() - 1;
    G[a].push_back(i);
    G[b].push_back(i);
    H[i] = a ^ b;
  }
  u64 m = io::scan();
  auto paths = vector<u64>(m);
  REP(j, m) {
    u64 u = io::scan() - 1;
    u64 v = io::scan() - 1;
    paths[j] = collect(G, H, u, v, -1);
  }
  u64 ans = search(1ULL << (n - 1), 0, m, 0, paths);
  io::print(ans);
  io::flush();
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a, b, c, d;

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

  d = b/a;

  if(d>c){
    printf("%d",c);
  }
  else{
    printf("%d",d);
  }

  return 0;
}


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

int main(){
  	string s;cin>>s;
    bool flag=false;
  	for(int i=0;i<3;i++){
      if(s[i]==s[i+1]){
        flag=true;
      }
    }
  int a=0;
  	for(int i=0;i<2000000000;i++){
      a+=1;
    }
  	if(flag){
      cout<<"Bad"<<endl;
    }else{
      cout<<"Good"<<endl;
    }
  
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
string get_str(string s) {
	s+=',';
	string ret="";
	for(int i=0; i<s.size(); i++) {
		if(s[i]==',') ret+="=%ld, ";
		else ret+=s[i];
	}
	return ret;
}
#define dump(...) printf(get_str(#__VA_ARGS__).c_str(),__VA_ARGS__);cout<<endl
 
#define endl '\n'
#define IOS()                     \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
 template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
//******************************************************************************

int N,MINF=1e17;
vint a;
vint g[5050];


vector<vector<int>>dfs(int now,int par){
	auto dp = make_v<int>(2,2);
	fill_v(dp,INF);
	dp[0][0] = a[now];
	if(a[now]>0)dp[0][1] = a[now];
	for(auto e:g[now]){
		if(e==par)continue;
		auto tmp = dfs(e,now);
		int n = dp.size();
		int m = tmp.size();
		auto new_dp = make_v<int>(n+m-1,2);
		fill_v(new_dp,INF);
		rep(i,0,n){
			rep(j,0,m){
				rep(k,0,2){
					rep(l,0,2){
						chmin(new_dp[i+j][k&l],dp[i][k]+tmp[j][l]);
					}
				}
				if(i+j+1>=n+m-1)continue;
				if(tmp[j][0]<0){
					chmin(new_dp[i+j+1][0],dp[i][0]);
					chmin(new_dp[i+j+1][1],dp[i][1]);
				}
				if(tmp[j][1]<INF/2){
					chmin(new_dp[i+j+1][0],dp[i][0]);
					chmin(new_dp[i+j+1][1],dp[i][1]);
				}
			}
		}
		dp = new_dp;
	}
	return dp;
}

signed main()
{
	//IOS();
	cin>>N;
	a.resize(N);
	for(int i = 0;i < N;i++){
		cin>>a[i];
	}
	rep(i,0,N-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	auto dp = dfs(0,-1);
	int ans = INF;
	rep(j,0,N+1){
		if(dp[j][1]<INF/2)chmin(ans,j);
		if(dp[j][0]<0)chmin(ans,j);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2216
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll N, sum = 0, f = 0;
    cin >> N;
    ll A[N];

    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }
    ll ss = 0;
    ll ans = INF;
    rep(i, N - 1) {
        ss += A[i];
        ll tmp = abs(ss - sum);
        ans = min(ans, abs(ss - tmp));
    }

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

Measured memory_bytes: 1792
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define int long long

signed main(void){
  string a,b,c;
  cin >> a >> b >> c;
  if((a[a.length()-1] == b[0]) && (b[b.length()-1] == c[0])){
    cout << "YES\r\n";
  }else{
    cout << "NO\r\n";
  }
  return 0;
}


Measured memory_bytes: 256
// 3人でカードゲームイージー
#include <bits/stdc++.h>
using namespace std;

int main() {
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    queue<char> qa, qb, qc;
    for (int i; i < sa.size(); i++) {
        qa.push(sa.at(i));
    }
    for (int i; i < sb.size(); i++) {
        qb.push(sb.at(i));
    }
    for (int i; i < sc.size(); i++) {
        qc.push(sc.at(i));
    }

    char turn = 'a';
    char winner;
    while ( true ) {
        if (turn == 'a') {
            if ( qa.empty() ) {
                winner = 'A';
                break;
            }
            turn = qa.front();
            qa.pop();
        }
        else if (turn == 'b') {
            if ( qb.empty() ) {
                winner = 'B';
                break;
            }
            turn = qb.front();
            qb.pop();
        }
        else if (turn == 'c') {
            if ( qc.empty() ) {
                winner = 'C';
                break;
            }
            turn = qc.front();
            qc.pop();
        }
    }
    
    cout << winner << endl;
    
}

Measured memory_bytes: 3552
package main

import "fmt"

func main() {
	var (
		N int
	)
	fmt.Scanf("%d", &N)
	A := make([]string, N)
	m := make(map[rune]int)
	for i := range A {
		fmt.Scan(&A[i])
		m[rune(A[i][0])]++
	}
	B := []rune{'M', 'A', 'R', 'C', 'H'}
	res := 0
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			for k := j + 1; k < 5; k++ {
				res = (res + m[B[i]]*m[B[j]]*m[B[k]])
				//fmt.Printf("%c %d, %c %d, %c %d \n", B[i], m[B[i]], B[j], m[B[j]], B[k], m[B[k]])
			}
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 4736
#include<iostream>
#define FOR(i,n,a) for(int i = a;i<n;i++)
#define rep(i,n) FOR(i,n,0)
#define UNFOR(i,n,a) for(int i = a;i>n;i--)
#define unrep(i,n) UNFOR(i,0.n)
typedef long long ll;
using namespace std;
bool prime(int a) {
	for (int i = 2; i < a;i++)if (a%i == 0)return false;
	return true;
}
int ans[55556];
int main() {
	int count = 1;
	ans[0] = 2;
	for (int i = 9; i < 55556;i+=10) {
		if (prime(i)) {
			ans[count] = i;
			count++;
		}
	}
	int num;
	cin >> num;
	rep(i, num - 1)cout << ans[i] << " ";
	cout << ans[num - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

string S;

int main(){
    cin>>S;
    if(S.length()==2)out(S);
    else{
        reverse(S.begin(),S.end());
        out(S);
    }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    X=list(mi())

    X.sort()

    ans = 0
    while X[1] != X[2]:
        X[0] += 1
        X[1] += 1
        ans += 1
    
    if X[0] == X[1]:
        print(ans)
        exit()
    
    if X[0] % 2 == X[1] % 2:
        ans += (X[1] - X[0])//2
    else:
        ans += (X[1]+1 - X[0])//2
        ans += 1
    
    print(ans)







if __name__ == "__main__":
    main()

Measured memory_bytes: 61924
from itertools import accumulate
def main():
  while True:
    c, d, w, x = map(int, input().split())
    if c == 0:
      break
    es = [[] for _ in range(d)]
    for _ in range(c):
      lst = list(map(int, input().split()))
      for i in range(d):
        es[i].append(lst[i])
    
    fs = [[] for _ in range(d)]
    for _ in range(c):
      lst = list(map(int, input().split()))
      for i in range(d):
        fs[i].append(lst[i])
  
    for day in range(d):
      for i in range(c):
        if es[day][i] == 0:
          fs[day][i] = 100
  
    es = list(map(lambda lst:[0] + list(accumulate(lst)), es))
    fs = list(map(lambda lst:[0] + list(accumulate(lst)), fs))
  
    ef1 = [[] for _ in range(d)]
    ef2 = [[] for _ in range(d)]
    for day in range(d):
      ef1[day].append((0, 0))
      for i in range(c):
        for j in range(i + 1, c + 1):
          if fs[day][j] - fs[day][i] <= w:
            if j - i == 1:
              ef1[day].append((fs[day][j] - fs[day][i], es[day][j] - es[day][i]))
            else:
              ef2[day].append((fs[day][j] - fs[day][i], es[day][j] - es[day][i]))
    
    for day in range(d):   
      used = {}
      for f, e in ef1[day]:
        if f not in used or used[f] < e:
          used[f] = e
      ef1[day] = sorted([(f, e) for f, e in used.items()])
    
    for day in range(d):
      used = {}
      for f, e in ef2[day]:
        if f not in used or used[f] < e:
          used[f] = e
      ef2[day] = sorted([(f, e) for f, e in used.items()])


    dp = [[[None] * (x + 1) for _ in range(w + 1)] for _ in range(d + 1)]
    dp[0][0][0] = 0
    for day in range(d):
      for weight in range(w + 1):
        for use in range(x + 1):
          score = dp[day][weight][use]
          if score == None:continue
          
          for f, e in ef1[day]:
            if weight + f > w:break
            if dp[day + 1][weight + f][use] == None or dp[day + 1][weight + f][use] < score + e:
              dp[day + 1][weight + f][use] = score + e
          
          if use >= x:continue
          for f, e in ef2[day]:
            if weight + f > w:break
            if dp[day + 1][weight + f][use + 1] == None or dp[day + 1][weight + f][use + 1] < score + e:
              dp[day + 1][weight + f][use + 1] = score + e
  
    print(max([dp[d][weight][rest] if dp[d][weight][rest] != None else 0 for weight in range(w + 1) for rest in range(x + 1)]))

main()


Measured memory_bytes: 6432
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<queue>//队列
#include<stack>//栈
#include<set>//集合
using namespace std;
#define maxn 1000000
//sort(a,a+n);a数组排列,长度n;升序
//sort(a,a+n,greater<int>());int是数组类型;降序
int main()
{
    char a[5][5];
    for(int i=0; i<2; i++)
        scanf("%s",&a[i]);
    if(a[0][0]==a[1][2]&&a[0][1]==a[1][1]&&a[0][2]==a[1][0])
        printf("YES\n");
    else
        printf("NO\n");
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n, p):
        '木の初期化をする'
        # zero-index
        self.p  = [-1] * n
        self.rank = [1]*n

    def find(self, x):
        'x の親を返す'
        if self.p[x] == -1:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def unite(self, x, y):
        'rankの低い親を高い方のの親にする'
        if not self.same(x,y):
            x = self.find(x)
            y = self.find(y)
            if self.rank[x] > self.rank[y]:
                x,y = y,x
            elif self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.p[x] = y # x の親を y にする
            return True
        else:
            return False

    def same(self, x, y):
        return self.find(x) == self.find(y)

def main():
    n,m = map(int,input().split())
    p = list(map(int,input().split()))

    uf = UnionFind(n,p)
    for i in range(m):
        x,y = map(int,input().split())
        uf.unite(x-1,y-1)

    ans = 0
    for i,j in enumerate(p):
        ans += uf.same(i, j-1)
    print(ans)
main()


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

int main(){
  string s;
  cin >> s;
  for(int i=0; i<3; i++){
  if(s.at(i) == '1') s.at(i) = '9';
  else{
    s.at(i) = '1';
  }
}
  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define M 2000
using namespace std;
bool used2[M];
vector <int> prime;
int n,k;

int mem[200][15][1200],used[200][15][1200];
int dfs(int idx,int dep,int sum){
  if(sum==n&&dep==k) return 1;
  if(idx==(int)prime.size()||dep==k||sum>=n) return 0;
  if(used[idx][dep][sum]++) return mem[idx][dep][sum];
  
  int res=dfs(idx+1,dep,sum)+dfs(idx+1,dep+1,sum+prime[idx]);
  return mem[idx][dep][sum]=res;
}


int main(){
  used2[0]=used2[1]=1;
  for(int i=2;i*i<M;i++)
    if(!used2[i])
      for(int j=2;j<M/i;j++) used2[j*i]=1;
  
  for(int i=2;i<=1120;i++) if(!used2[i]) prime.push_back(i);
  while(1){
    cin>>n>>k;
    if(n==0&&k==0)break;
    memset(used,0,sizeof(used));
    cout<< dfs(0,0,0)<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 29284
N=int()
N = input()
l = map(int, raw_input().split())
count=int()

var = int()
indexerror = int()
for var in range(0, N):
    try:
        k = int()
        k=l[var]
        k-=1
        if k >= (var+1):
            if l[k] == var+1:
                count+=1
    except IndexError:
        indexerror+=1

print count


Measured memory_bytes: 11328
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

 
const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
 
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; }


ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

int main(){
  int n; cin>>n;
  map<int,int> m;
  rep(i,n) {
    int a; cin>>a;
    m[a-1]=i+1;
  }
  rep(i,n){
    cout<<m[i];
    if(i!=n)cout<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 5504
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
 
public class Main {
	
	public static void main(String[] args) throws IOException {
		final Scanner sc = new Scanner(System.in);
		
		final char[] input = sc.next().toCharArray();
		final char[] str = "CODEFESTIVAL2016".toCharArray();
		
		int answer = 0;
		for(int i = 0; i < str.length; i++){
			if(input[i] != str[i]){
				answer++;
			}
		}
		
		System.out.println(answer);
	}
 
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}	
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

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

int main(void)
{
  int n;
  string s1, s2;
  string ans;
  ans = "";
  cin >> n;
  cin >> s1 >> s2;

  for (int i = 0; i < n; i++)
  {
    ans += s1[i];
    ans += s2[i];
  }

  cout << ans << "\n";

  return 0;
}

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

bool orthogonal(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd);

int main(void){
  double xa,ya,xb,yb,xc,yc,xd,yd;
  while(cin>>xa>>ya>>xb>>yb>>xc>>yc>>xd>>yd){
    if(orthogonal(xa,ya,xb,yb,xc,yc,xd,yd)){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}

bool orthogonal(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd){
  if(abs((yd-yc)*(yb-ya)+(xd-xc)*(xb-xa))<0.00000000001){
    return true;
  }
  else{
    return false;
  }

}



Measured memory_bytes: 3144
import java.util.*;

public class Main {
     public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while(true) {
            int n = sc.nextInt() * 2;
            if (n == 0) {
                break;
            }
            int max = 0;
            int maxNum = 0;
            for (int i = 1; i <= Math.sqrt(n); i++) {
                if (n % i == 0) {
                    int x = n / i + 1 - i;
                    if (x > 0 && x % 2 == 0) {
                        max = i;
                        maxNum = x / 2;
                    }
                }
            }
            sb.append(maxNum).append(" ").append(max).append("\n");
        }
        System.out.print(sb);
    }
}


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

int main(){
	long long int n;
	cin >> n;
	long long int ar[n];
	long long int dp[n][n];
	for(long long int i = 0;i < n; i++){
		cin >> ar[i];
	}
	for(long long int i=n-1;i>=0;i--){
		for(long long int j=0;j<n;j++){
			if(j==0) dp[i][j] = ar[j];
			else if(i==n-1) dp[i][j] = ar[n-1];
			else if(i > j) dp[i][j] = 0;
			else dp[i][j] = max(ar[i]-dp[i+1][j],ar[j]-dp[i][j-1]);
		}
	}
	cout<<dp[0][n-1];	
}

Measured memory_bytes: 73852
import sys
from heapq import heappush, heappop
from collections import defaultdict


class HeapSet:
    def __init__(self):
        self.minQue = []
        self.maxQue = []
        self.counter = defaultdict(lambda: 0)

    def insert(self, x):
        heappush(self.minQue, x)
        heappush(self.maxQue, -x)
        self.counter[x] += 1

    def delete(self, x):
        self.counter[x] = max(0, self.counter[x] - 1)

    def get_max(self):
        while self.maxQue and self.counter[-self.maxQue[0]] == 0:
            heappop(self.maxQue)
        return -self.maxQue[0] if self.maxQue else None

    def get_min(self):
        while self.minQue and self.counter[self.minQue[0]] == 0:
            heappop(self.minQue)
        return self.minQue[0] if self.minQue else None


read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N, T = in_nn()
    A = in_nl()

    la = HeapSet()
    la.insert(A[0])

    min_sect = []
    ind_l = 0
    ind_r = 1
    pre_min = A[0]
    for i in range(N):
        min_a = la.get_min()
        if pre_min == min_a:
            ind_r = i + 1
        else:
            min_sect.append((pre_min, ind_l, ind_r))
            ind_l = i
            ind_r = i + 1

        pre_min = min_a
        if i + 1 < N:
            la.insert(A[i + 1])
    else:
        min_sect.append((min_a, ind_l, ind_r))

    max_benefit = -1
    ans = 0
    for min_a, l, r in min_sect:
        min_a = min(A[l:r])
        max_a = max(A[l:r])
        min_cnt = A[l:r].count(min_a)
        max_cnt = A[l:r].count(max_a)
        if max_a - min_a > max_benefit:
            max_benefit = max_a - min_a
            ans = min(max_cnt, min_cnt)
        elif max_a - min_a == max_benefit:
            ans += min(max_cnt, min_cnt)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31120
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;

///---program start---///

bool closed[arr];

main()
{
    #ifdef Barik
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    int n,k;
    cin>>n>>k;
    for (int i=0;i<k;i++){
        int a;
        cin>>a;
        closed[a]=1;
    }
    auto bad=[&](int a)
    {
        while (a){
            if (closed[a%10]){
                return 1;
            }
            a/=10;
        }
        return 0;
    };
    while (bad(n)){
        n++;
    }
    cout<<n<<"\n";
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split()))
    p, z, m = [], 0, []
    for i in range(n):
        t = a[i] - (i + 1)
        if t > 0:
            p.append(t)
        elif t == 0:
            z += 1
        else:
            m.append(-t)
    if sum(m) > sum(p):
        p, m = m[:], p[:]

    p.sort()
    ps, ms = sum(p), sum(m)
    pl, ml = len(p), len(m)
    x = 0
    ans = ms + ps
    for t in p:
        t, x = t - x, t
        ps -= pl * t
        pl -= 1
        if t > 0:
            ml += z
            ms += ml * t
            z = 1
            a = ms + ps
            if a < ans:
                ans = a
        else:
            z += 1
    print(ans)


main()


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

int main() {
  int N;
  cin >> N;
  bool ok = false;
  for (int x = 0; x <= N; ++x) {
    for (int y = 0; y <= N; ++y) {
      if (x* 4 + y * 7 == N) ok = true;
    }
  }
  if (ok) puts("Yes");
  else puts("No");
}
      

Measured memory_bytes: 3592
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

string s;
int dt[100010];

bool f(int x)
{
    if( ~dt[x] ) return dt[x];
    if( x == s.size() ) return true;
    bool ret = false;
    if( x+5 <= s.size() )
    {
        if( s.substr(x, 5) == "dream" or s.substr(x, 5) == "erase" )
            ret |= f(x+5);
    }
    if( x+6 <= s.size() )
    {
        if( s.substr(x, 6) == "eraser" )
            ret |= f(x+6);
    }
    if( x+7 <= s.size() )
    {
        if( s.substr(x, 7) == "dreamer" )
            ret |= f(x+7);
    }
    return dt[x] = ret;
}

int main()
{
    cin>>s;
    memset(dt, -1, sizeof(dt));
    cout<<(f(0)?"YES":"NO")<<endl;
}


Measured memory_bytes: 2816