akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int l, r;
    cin >> l >> r;
    ll ans = (ll)1e9;
    for(ll i = l; i <= min(r, l + 2019); i ++){
        for(ll j = i + 1; j <= min(r,l +  2019); j ++){
            if(ans > i * j % 2019) ans = i * j % 2019;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import Data.Bits
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
main=print.solve.B.lines=<<B.getContents
solve=f.V.accum(+)(V.replicate 5 0).map(\i->(i,1)).mapMaybe((`elemIndex`"MARCH").B.head)
f c=sum.map g$filter(\b->popCount b==3)[7..2^5]where
  g::Int->Int
  g b=product.map(c V.!)$filter(testBit b)[0..4]

Measured memory_bytes: 6744
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;

vector<bool> sieve(int MAX_A){
    vector<bool> p(MAX_A+1,true);
    p[0]=p[1]=false;
    REP(i,MAX_A+1) if(p[i]){
        for(int j=2*i;j<=MAX_A;j+=i){
            p[j]=false;
        }
    }
    return p;
}

int main(){
    int N;cin>>N;
    vector<bool> p=sieve(55555);
    vector<int> ans;
    REP(i,55556){
        if(ans.size()==N){
            REP(j,N) cout<<ans[j]<<" \n"[j+1==N];
            return 0;
        }
        if(i%5==1&&p[i]){
            ans.push_back(i);
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long a,b,n;
    cin >> a >> b >> n;
    long tmp = min(b-1,n);
    long ans = 0;
    int i=0;
    while(tmp <= n){
        ans = max(ans, (a*tmp)/b - a * (tmp/b));
        tmp += b;
        i++;
        if(i > a)break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N + 1), R(N + 1);
	for (int i = 0;i <= N;i++) {
		cin >> A[i];
	}
	R[N] = A[N];
	for (int i = N - 1;i >= 0;i--) {
		R[i] = R[i + 1] + A[i];
	}
	ll le = 1, ans = 0;
	for (int i = 0;i <= N;i++) {
		if (le < A[i]) {
			cout << -1 << endl;
			return 0;
		}
		if (le > R[i]) {
			le = R[i];
		}
		ans += le;
		le -= A[i];
		le *= 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4776
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        if(k*500 >= x){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		boolean[] base = getBitArray(k);
		boolean[][] arrs = new boolean[n][];
		for (int i = 0; i < n; i++) {
		    arrs[i] = getBitArray(sc.nextLong());
		}
		long ans = 0;
		boolean start = false;
		for (int i = 40; i >= 0; i--) {
		    int count = 0;
		    for (int j = 0; j < n; j++) {
		        if (arrs[j][i]) {
		            count++;
		        }
		    }
	        if (start) {
	            ans += pow2(i, Math.max(count, n - count));
	        } else {
	            if (base[i]) {
	                if (count >= n / 2) {
	                    start = true;
	                }
	                ans += pow2(i, Math.max(count, n - count));
	            } else {
	                ans += pow2(i, count);
	            }
	        }
		}
	    System.out.println(ans);
   }
   
   static boolean[] getBitArray(long x) {
       boolean[] ans = new boolean[41];
       for (int i = 0; i < 41 && x > 0; i++) {
           ans[i] = (x % 2 == 1);
           x /= 2;
       }
       return ans;
   }
   
   static long pow2(int pow, long count) {
       long ans = 1;
       for (int i = 0; i < pow; i++) {
           ans *= 2;
       }
       return ans * count;
   }
}




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

int main() {
    int x1, x2, x3, x4, x5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;
    if(x1 == 0){
        cout << 1 << endl;
    }
    if(x2 == 0){
        cout << 2 << endl;
    }
    if(x3 == 0){
        cout << 3 << endl;
    }
    if(x4 == 0){
        cout << 4 << endl;
    }
    if(x5 == 0){
        cout << 5 << endl;
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,s=0,a;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a);
		s+=a;
	}
	printf("%d",s-n);
	return 0;
}

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

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
};

int main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<BIT<int>> al(26,BIT<int>(N));
    rep(i,S.size()){
        int index = S[i] - 'a';
        al[index].add(i,1);
    }
    rep(_,Q){
        int q;
        cin >> q;
        if(q == 1){
            int i;
            char q;
            cin >> i >> q;
            i--;
            al[S[i]-'a'].add(i,-1);
            al[q-'a'].add(i,1);
            S[i] = q;
        } else {
            int l,r;
            cin >> l >> r;
            --l;--r;
            int ans = 0;
            rep(al_i,26){
                if(al[al_i].sum(r) - al[al_i].sum(l-1) > 0) ans++;
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 53728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	cout<<s.substr(0,4)<<' '<<s.substr(4)<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll X;

int main()
{
  std::cin >> X;

  std::cout << X/500*1000+(X%500)/5*5 << std::endl;

  return 0;
}

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

using namespace std;

int main(){
  int A,B;
  cin>>A>>B;
  if (A<=8&&B<=8){
    cout<<"Yay!"<<endl;
  }else {
    cout<<":("<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
def count(inA, inB, before, total):
  if inB >= inA:
    count = before
  else:
    if inA%inB==0:
      count = int(total / inB)
    else:
      count = int(total / inB) + 1
  
  return count

num = []
num.append(int(input()))
num.append(int(input()))
num.append(int(input()))
num.append(int(input()))
num.append(int(input()))
num.append(int(input()))

total_count = 0
for i in range(0, len(num)-1):
  if i==0:
    total_count = count(num[0], num[i+1], 1, num[0])
  else:
    total_count = count(min(num[1:i+1]), num[i+1], total_count, num[0])

print(total_count + 4)

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{

	int a, b;
	scanf("%d %d", &a, &b);
	if (a < b) { printf("a < b\n"); }
	else if (a > b) { printf("a > b\n"); }
	else if (a == b) { printf("a == b\n"); }
	return 0;
}


Measured memory_bytes: 2048
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main() {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = a; i < a + k && i <= b; i++)
		cout << i << endl;
	for (int i = b - k; i < b; i++)
		if (i+1 >= a + k)
		cout << i + 1 << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int INF = 1e9;
const int MOD = INF+7;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.rbegin(),v.rend()
#define MP make_pair
#define pb push_back
using P = pair<int,int>;
//b

signed main(){
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i,N) cin >> H[i];

    int ans = 0;
    for(int i=0;i<N;i++){
        bool ok = true;
        for(int j=0;j<i;j++){
            if(H[j] > H[i]) ok = false;

        }
        ans += ok;
    }

    cout << ans << endl;
}


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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n;
	cin >> n;
	vector <pair <ll, ll>> inp (n);
	trav (p, inp) cin >> p.f >> p.s;
	bool ok = false;
	for (i = 0; i + 2 < n; ++i)
	{
		bool cur_ok = true;
		for (j = 0; j < 3; ++j)
			if (inp[i + j].f != inp[i + j].s)
				cur_ok = false;
		ok = ok || cur_ok;
	}
	if (ok) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}



Measured memory_bytes: 3640
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<iostream>
using namespace std;
long long h;
long long ans;
long long dp[1000100];
long long f(long long x)
{
	if(x==1)
	{
		return dp[x]=1;
	}
	if(dp[x])
	{
		return dp[x];
	}
	return dp[x]=2ll*f(x/2)+1;
}
int main()
{
	cin>>h;
	int ci=0;
	long long x=1;
	while(x<=h)
	{
		x*=2ll;
	} 
	x--;
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()

	fmt.Println(dfs(n, k, 1))
}

func dfs(remain int, k int, now int) int {
	if remain == 0 {
		return now
	}

	return int(math.Min(float64(dfs(remain-1, k, now*2)), float64(dfs(remain-1, k, now+k))))
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
  return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int n, W;
int weight[110], value[110];

int dp[110][10010];

int main() {
   cin >> n >> W;
   rep (i, n) cin >> value[i] >> weight[i];

   rep (i, W+1) dp[0][W] = 0;

   for (int i = 0; i < n; i++) {
      for (int w = 0; w <= W; w++) {
         if (w >= weight[i]) {
            dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
         } else {
            dp[i+1][w] = dp[i][w];
         }
      }
   }

   cout << dp[n][W] << endl;

   return 0;
}


Measured memory_bytes: 7024
num = int(input())
num_list = list(range(10))
num_list.insert(0, 'pon')
num_list.insert(1, 'pon')
num_list.insert(2, 'hon')
num_list.insert(3, 'bon')
num_list.insert(4, 'hon')
num_list.insert(5, 'hon')
num_list.insert(6, 'pon')
num_list.insert(7, 'hon')
num_list.insert(8, 'pon')
num_list.insert(9, 'hon')

print(num_list[num%10])

Measured memory_bytes: 9144
#include <iostream>
#include <map>

using namespace std;

int main() {
    map<int, string> ans;
    ans[3] = "Three";
    ans[4] = "Four";
    map<char, int> cnt;
    int N;
    cin >> N;
    for(int n=0; n<N; n++) {
        char c;
        cin >> c;
        cnt[c]++;
    }
    cout << ans[cnt.size()] << endl;

    return 0;
    
    
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			while (true) {
				int parson = Integer.parseInt(br.readLine());
				if (parson == 0)
					break;
				int point[] = new int[parson];
				int max = 0;
				int min = 1000;
				int maxI = 0;
				int minI = 0;
				for (int i = 0; i < parson; i++) {
					point[i] = Integer.parseInt(br.readLine());
					max = Math.max(max, point[i]);
					min = Math.min(min, point[i]);
					if (max == point[i])
						maxI = i;
					if (min == point[i]) {
						minI = i;
					}
				}
				int result = 0;
				for (int i = 0; i < parson; i++) {
					if (i != maxI && i != minI) {
						result += point[i];
					}
				}
				System.out.println(result / (parson - 2));
				//System.out.println(max + " " + min);
			}
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 24324
#include<iostream>
#include <vector>
#include <list>
using namespace std;
int main(){
    list<int> l;
    int n;
    cin>>n;
    int a,b;
    auto it = l.end();
    while(n--){
        cin>>a;
        if(a==0){
            cin>>b;
            it=l.insert(it,b);
        }
        else if (a==1){
            cin>>b;
            advance(it,b);
        }
        else{
            it = l.erase(it);
        }
    }
    for(int i : l){
        cout<<i<<endl;
    }
    return 0;
}


Measured memory_bytes: 18540
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	int n;cin>>n;
	int c[100];
	rep(i,100) c[i]=0;
	for(int i=1;i<=n;i++){
		int m=i;
		for(int j=2;j<100;j++){
			while(m%j==0) {c[j]++;m/=j;}
		}
	}
	int c2[5];	// c is more than 3,5,15,25,75
	rep(i,5) c2[i]=0;
	rep(i,100){
		if(c[i]>=74) c2[4]++;
		if(c[i]>=24) c2[3]++;
		if(c[i]>=14) c2[2]++;
		if(c[i]>=4) c2[1]++;
		if(c[i]>=2) c2[0]++;
	}
	int ans=0;
	ans+=c2[4];
	if(c2[0]>=1) ans+=c2[3]*(c2[0]-1);
	if(c2[1]>=1) ans+=c2[2]*(c2[1]-1);
	if(c2[1]>=1&&c2[0]>=2) ans+=c2[1]*(c2[1]-1)*(c2[0]-2)/2;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, m; cin >> n >> m;
    vector<int> s(m), c(m);
    for(int i=0; i<m; ++i){
        cin >> s[i] >> c[i]; s[i]--;
    }
    for(int i=0; i<1000; ++i){
        vector<int> v;
        v.push_back(i%10); 
        int d = i/10;
        while(d){
            v.push_back(d%10);
            d /= 10;
        }
        if(v.size()!=n){continue;}  

        reverse(v.begin(), v.end()); 
        bool ok = true;
        for(int j=0; j<m; ++j){
            if(v[s[j]]!=c[j]){ok = false;}
        }
      	
        
        if(ok){cout << i << endl; return 0;}
    }
    cout << -1 << endl; return 0;
}

Measured memory_bytes: 3592
N, M = gets.split.map(&:to_i)

prices = []
list = []

M.times do
  a, b = gets.split.map(&:to_i)
  keys = gets.split.map(&:to_i)

  v = 0

  keys.each do |k|
    v |= (1 << k - 1)
  end

  list << [a, v]
end

dp = Hash.new(Float::INFINITY)
dp[0] = 0

list.each do |price, ks|
  dp.keys.each do |old_list|
    current_list = old_list | ks
    k = dp[old_list] + price

    if k < dp[current_list]
      dp[current_list] = k
    end
  end
end

ans = dp[2 ** N - 1]

if ans == Float::INFINITY
  puts -1
else
  puts ans
end


Measured memory_bytes: 21500
#include<cstdio>
char s[100001];
int main(){
    scanf("%s",s);
    int i=0;
    while(s[i]!='\0')i++;
    i--;
    while(i>=0){
        if(i<4){
            printf("NO");
            return 0;
        }else if(s[i]=='m'){
            char tmp[]="dream";
            for(int j=0;j<5;j++){
                if(tmp[j]!=s[i-4+j]){
                    printf("NO");
                    return 0;
                }
            }
            i-=5;
        }else if(s[i]=='e'){
            char tmp[]="erase";
            for(int j=0;j<5;j++){
                if(tmp[j]!=s[i-4+j]){
                    printf("NO");
                    return 0;
                }
            }
            i-=5;
        }else if(s[i-2]=='m'&&s[i-1]=='e'&&s[i]=='r'){
            char tmp[]="dreamer";
            if(i<6){
                printf("NO");
                return 0;
            }
            for(int j=0;j<7;j++){
                if(tmp[j]!=s[i-6+j]){
                    printf("NO");
                    return 0;
                }
            }
            i-=7;
        }else if(s[i-2]=='s'&&s[i-1]=='e'&&s[i]=='r'){
            char tmp[]="eraser";
            if(i<5){
                printf("NO");
                return 0;
            }
            for(int j=0;j<6;j++){
                if(tmp[j]!=s[i-5+j]){
                    printf("NO");
                    return 0;
                }
            }
            i-=6;
        }else{
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  vector<int> p(N);
  int num = 0;
 
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  
  for(int i = 0; i < N; ++i){
    if(!(p[i] == i + 1)){
      num++;
    }
  }
  
  if(num <= 2){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
 
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep4(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
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;}

void solve(){
    ll n;
    cin>>n;
    vec a(n);
    rep(i,n)cin>>a[i];

    ll mi=INF;
    ll ans=0;
    rep(i,n){
        if(a[i]<=mi){
            ans++;
            mi=a[i];
        }
    }
    cout<<ans<<endl;
}

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    int n, m;
    cin >> n >> m;
    vector<vector<bool>> valid(n, vector<bool>(2));
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (a == 0) {
            valid[b][0] = true;
        }
        else if (b == n - 1) {
            valid[a][1] = true;
        }
    }
    rep(i, n) {
        if (valid[i][0] && valid[i][1]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 14336
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    char s[51];
    int len,i,haveA=0,haveKIH=0,haveB=0,haveR=0;
    scanf("%s",s);
    len=strlen(s);
    if(len>10)
    {
        printf("NO");
        return 0;
    }
    for(i=0;i<len;i++)
    {
        if(haveKIH==1&&haveB==1&&haveR==1&&haveA==1)
        {
            printf("NO");
            return 0;
        }
        if(s[i]=='A')
        {
            if(haveA==0) haveA=1;
            else
            {
                printf("NO");
                return 0;
            }
        }
        else
        {
            if(s[i]=='K'&&s[i+1]=='I'&&s[i+2]=='H'&&haveKIH==0)
            {
                haveA=0;
                haveKIH=1;
                i+=2;
            }
            else
            {
                if(haveKIH==1)
                {
                    if(s[i]=='B'&&haveB==0)
                    {
                        haveA=0;
                        haveB=1;
                    }
                    else if(s[i]=='R'&&haveB==1&&haveR==0)
                    {
                        haveR=1;
                        haveA=0;
                    }
                    else
                    {
                        printf("NO");
                        return 0;
                    }
                }
                else
                {
                    printf("NO");
                    return 0;
                }
            }
        }
    }
    if(haveB==1&&haveKIH==1&&haveR==1) printf("YES");
    else printf("NO");
    return 0;
}




Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
a = [0] + LIST()
ans = [0]*(N+1)

for i in range(N, 0, -1):
	tmp = 0
	for j in range(N//i, 1, -1):
		if ans[i*j] == 1:
			tmp ^= 1
	if a[i] != tmp:
		ans[i] = 1


ans = [idx for idx, x in enumerate(ans) if 0 < x]
print(len(ans))
print(*ans)



Measured memory_bytes: 18688
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int K; cin >> K;
    int A,B; cin >> A >> B;
    bool f=false;
    for(int i=A;i<=B;i++){
        if(i%K==0) f=true;
    }
    if(f) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX_COLORS 6
#define MAX_CIRCLES 4
#define MAX_N (MAX_COLORS*MAX_CIRCLES)
#define MAX_STATES (1<<MAX_N)

int biggest, n;

struct circle{
    int x, y, r, c;
};
/*
int X[MAX_N];
int Y[MAX_N];
int R[MAX_N];
int C[MAX_N];*/

circle C[MAX_N];
char dp[MAX_STATES];

bool isOver( circle c1, circle c2 ){
    int dx, dy;
    dx = (c1.x - c2.x) * (c1.x - c2.x);
    dy = (c1.y - c2.y) * (c1.y - c2.y);
    return dx + dy < (c1.r + c2.r)*(c1.r + c2.r) ? true : false;
}

bool isDeleted( int state, int num ){
    return (state & (1<<num)) == 0 ? false : true;
}
/*
void pbit(int num){
    //cout << "bit: ";
    do{
        printf("%d", num&1);
        num = num>>1;
    }while(num);
    //printf("\n");
}*/

bool isTop( int state, int num ){
    //pbit(state);
    for( int i = num-1; i >= 0; i-- ){
        if( isDeleted(state, i) ) continue;
        if( isOver(C[num], C[i]) ) return false;
    }
    //cout << num << " is top" << endl;
    return true;
}

void search(int s){
    //for( int s = 0; s < 1<<n; s++ ){
        /*cout << "s: ";
        pbit(s);
        cout << endl;
        */
        for( int i = 0; i < n; i++ ){
            if( isDeleted(s, i) ) continue;
            //cout << "i: " << i << endl;
            for( int j = i+1; j < n; j++ ){
                if( isDeleted(s, j) ) continue;
                //cout << "i: " << i << endl;
                //cout << "j: " << j << endl;
                if( isTop(s, i) && isTop(s, j) && C[i].c == C[j].c ){
                    int next = s | 1<<i | 1<<j;
                    bool visited;
                    visited = dp[next] == -1 ? false : true;
                    //next(s);
                    //cout << "," << i << "," << j << endl;
                    if( dp[next] < dp[s]+2 ) dp[next] = dp[s]+2;
                    if( biggest < dp[next] ) biggest = dp[next];
                    if( (next|1) != (1<<n)-1 && !visited ) search(next);
                }
            }
        }
    //}
}

void init(){
    for( int s = 0; s < 1<<n; s++ ){
        dp[s] = -1;
    }
}

int main(){
    while( cin >> n, n ){
        for( int i = 0; i < n; i++ ){
            circle a;
            //scanf("%d%d%d%d", a.x, a.y, a.r, a.c);
            cin >> a.x >> a.y >> a.r >> a.c;
            C[i] = a;
        }
        biggest = 0;
        init();
        dp[0] = 0;
        search(0);
        printf("%d\n", biggest);
        //cout << "ans: " << biggest << endl;
    }
}

Measured memory_bytes: 17528
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int Q,H,S,D; cin >> Q >> H >> S >> D;
    int N; cin >> N;
    int ans=0;
    Q*=4; H*=2;
    if(D<S*2 && D<Q*2 && D<H*2){
        ans+=N/2*D;
        if(N%2==0) N=0;
        else N=1;
    }
    ans+=N*min({Q,H,S});
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long int n;
    cin>>n;
   
   int r=n%10;
    
    if(r==2||r==4||r==5||r==7||r==9){
     cout<<"hon";
    }
   else  if(r==0||r==1||r==6||r==8){
     cout<<"pon";
    }
     else  if(r== 3){
     cout<<"bon";
    }
}


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

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim()) + 1;
            if (n == 1) break;
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = Array.ConvertAll(line, int.Parse).ToList();
            var c = getList(a, n);
            var ans = check(a, c, n);
            Console.WriteLine(ans);
        }
    }
    public static List<int> getList(List<int> a, int n)
    {
        var ans = new List<int>();
        var hs = new HashSet<int>();
        for (int i = 1; i < n; i++)
            if (hs.Add(a[i] - a[i - 1])) { ans.Add(i); ans.Add(i - 1); }
        return ans.Distinct().ToList();
    }
    public static int check(List<int> a, List<int> c, int n)
    {
        foreach (var x in c)
        {
            var t = a[x];
            a.RemoveAt(x);
            var hs = new HashSet<int>();
            for (int i = 0; i < n - 2; i++)
            {
                hs.Add(a[i + 1] - a[i]);
                if (hs.Count() == 2) continue;
            }
            if (hs.Count() == 1) return t;
            a.Insert(x, t);
        }
        return -1;
    }
}






Measured memory_bytes: 18500
#include<iostream>
#include<stdlib.h>

int main(){
    int h,w;
    
    std::cin>>h>>w;
    int a[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            std::cin>>a[i][j];
        }
    }
    int min=10000000;
    for(int i=0;i<h;i++){ //交差点
        for(int j=0;j<w;j++){
            int sum=0;
            for(int k=0;k<h;k++){ //総当たり
                for(int l=0;l<w;l++){
                    int dis,dis1,dis2;
                    dis1=abs(i-k);
                    dis2=abs(j-l);
                    if(dis1>=dis2){
                        dis=dis2;
                    }else{
                        dis=dis1;
                    }
                    sum=sum+dis*a[k][l];
                }
            }
            if(min>sum){
                min=sum;
            }
        }
    }
    std::cout<<min<<"\n";
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 2e5+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, t;
int niz[maxn];

int main() {
	scanf("%d%d", &n, &t);
	for (int i = 0; i < n; i++)
		scanf("%d", niz+i);

	int sol = 0;
	for (int i = 0; i < n; i++) {
		if (i < n - 1) sol += min(t, niz[i + 1] - niz[i]);
		else sol += t;
	}
	printf("%d", sol);
	return 0;
}

Measured memory_bytes: 4464
module Main where

import Control.Applicative
import Numeric
import Data.List (transpose)

main :: IO ()
main = do
  { [r, c] <- getInts
  ; mat <- loop r
  ; mapM_ putInts (hoge mat)
  }

loop :: Int -> IO [[Int]]
loop 0  = return []
loop r  = do
  { xs <- getInts
  ; xss <- loop (r - 1)
  ; return (xs : xss)
  }

hoge :: [[Int]] -> [[Int]]
hoge = transpose . map addSum . transpose . map addSum

addSum :: [Int] -> [Int]
addSum xs = xs ++ [sum xs]
    
--

getInts :: IO[Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



Measured memory_bytes: 8344
/// Zhupengfei 2018
/// Hereby declare: this program is in public domain.

/// Solution for problem: abc103B

#include <bits/stdc++.h>

#ifdef LOCAL
#pragma GCC poison printf // To avoid fastio problems
#pragma GCC poison scanf
#endif

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
    string s, t;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        bool flag=true;
        for(int j=0;j<s.size();j++) {
            if(s[(i+j)%s.size()]!=t[j]) {
                flag=false;
                break;
            }
        }
        if(flag) {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>//??????????????????????????¢???????????????????????°
int main(void)
{
	char c[1201]={0};
	int al[256]={0};
	int i=0;

	while (scanf("%c", &c[i]) != EOF)
	{
		//scanf("%c", &c[i]);
		/*if (c[i]=='\n')
		{
			break;
		}*/
		i+=1;
	}

	for (i=0;i<1201;i++)
	{
		if(c[i] >= 'a' && c[i] <= 'z') al[c[i]]+=1;
		else if (c[i] >= 'A' && c[i] <= 'Z') al[c[i]-'A'+'a']+=1;
	}

	for (i='a';i<='z';i++)
	{
		printf("%c : %d\n", i, al[i]);
	}
	return 0;
}

Measured memory_bytes: 544
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n, k;
int rk[100002];
int tmp[100002];
const int INF=1e9;
bool compare_sa(int i, int j){
  if(rk[i]!=rk[j]) return rk[i]<rk[j];
  else{
    int ri, rj;
    if(i+k<=n) ri=rk[i+k];
    else ri=-1;
    if(j+k<=n) rj=rk[j+k];
    else rj=-1;
    return ri<rj;
  }
}

void construct_sa(string s, int *sa){
  n=s.size();
  for(int i=0; i<=n; i++){
    sa[i]=i;
    if(i<n){
      rk[i]=s[i]-'0';
    }else{
      rk[i]=-1;
    }
  }
  for(k=1; k<=n; k*=2){
    sort(sa, sa+n+1, compare_sa);
    tmp[sa[0]]=0;
    for(int i=1; i<=n; i++){
      tmp[sa[i]]=tmp[sa[i-1]];
      if(compare_sa(sa[i-1], sa[i])) tmp[sa[i]]++;
    }
    for(int i=0; i<=n; i++) rk[i]=tmp[i];
  }
}

int main()
{
	int m;
  string s;
  cin>>m; cin>>s;
  if(m==0){
    cout<<s<<endl;
    return 0;
  }
  n=s.size();
  int d=(n+m)/(m+1);
  int sa[100002];
  construct_sa(s, sa);
  if(n%(m+1)==0){
    int mx=0;
    for(int i=1; i<=n; i++){
      if(sa[i]%d==0){
        mx=max(mx, i);
      }
    }
    for(int i=sa[mx]; i<sa[mx]+d; i++){
      cout<<s[i];
    }
    cout<<endl;
    return 0;
  }
  int x1=1, x2=n;
  while(x1!=x2){
    int x=(x1+x2)/2;
    int dp[100002];
    fill(dp, dp+n+1, INF);
    dp[0]=0;
    for(int i=d-1; i<=n; i++){
      if(i>=d && rk[i-d]<=x){
        dp[i]=min(dp[i-d]+1, dp[i]);
      }
      dp[i]=min(dp[i-(d-1)]+1, dp[i]);
    }
    if(dp[n]<=m+1){
      x2=x;
    }else{
      x1=x+1;
    }
  }
  for(int i=sa[x1]; i<sa[x1]+d; i++){
    cout<<s[i];
  }
  cout<<endl;
	return 0;
}

Measured memory_bytes: 2048
#include<iostream>

using namespace std;

int main(){

	int d;
	while(1){

    cin >> d;

    if(cin.fail()) break;

	int s=0;
	for(int i=1;i<600/d;i++)
	s+=d*(i*d)*(i*d);

    cout << s << endl;


	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define p(s) cout<<(s)<<endl
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int mod=1e9+7;

int H,W;
string s[55];
string ans[55];
int main() {
	cin>>H>>W;
	REP(i,0,H) {
		cin>>s[i];
		ans[i]=s[i];
	}
	REP(i,0,H){
		REP(j,0,W){
			if(s[i][j]=='#') {
				continue;
			}
			int cnt=0;
			REP(y,-1,2){
				REP(x,-1,2){

					if(CK(i+y,0,H)&&CK(j+x,0,W)){
						if(s[i+y][j+x]=='#')
							cnt++;
					}
				}
			}
			ans[i][j]=(char)'0'+cnt;
		}
	}
	REP(i,0,H){
		p(ans[i]);
	}

	return 0;
}


Measured memory_bytes: 384
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Count Order
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 8;
const int B = 3;

/* typedef */

/* global variables */

int ps[MAX_N];

/* subroutines */

int p2i(int n, int ps[]) {
  int sum = 0;
  for (int i = 0; i < n; i++)
    sum = (sum << B) | ps[i];
  return sum;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", ps + i), ps[i]--;
  int a = p2i(n, ps);
  for (int i = 0; i < n; i++) scanf("%d", ps + i), ps[i]--;
  int b = p2i(n, ps);

  int k = 0, ai = -1, bi = -1;
  for (int i = 0; i < n; i++) ps[i] = i;

  do {
    int c = p2i(n, ps);
    if (a == c) ai = k;
    if (b == c) bi = k;
    k++;
  } while (next_permutation(ps, ps + n));

  printf("%d\n", abs(ai - bi));
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

typedef tuple<int, int, int> tup;

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

    int n, m, p;
    cin >> n >> m >> p;

    vector<tup> vt(m);
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        vt[i] = make_tuple(a, b, c);
    }

    auto edge = initVec2<int>(n + 1, 0);
    rep(i, m){
        int a, b, c;
        tie(a, b, c) = vt[i];

        edge[b].push_back(a);
    }
    vector<bool> used(n + 1, false);
    stack<int> st;
    st.push(n);
    while(not st.empty()){
        int v = st.top();
        st.pop();

        if(used[v]){
            continue;
        }
        used[v] = true;

        for(int u : edge[v]){
            if(used[u]){
                continue;
            }
            st.push(u);
        }
    }
    vector<int> dist(n + 1, INF);
    vector<int> prev(n + 1, -1);
    dist[1] = 0;
    bool negative_cycle = false;
    for (int i = 0;; i++) {
        bool update = false;
        rep(i, m){
            int a, b, c;
            tie(a, b, c) = vt[i];

            if(not used[a] || not used[b]){
                continue;
            }
            if (dist[a] != INF && dist[b] > dist[a] - c + p) {
                dist[b] = dist[a] - c + p;
                prev[b] = a;
                update = true;
            }
        }
        if (!update) break;
        if (i > n) { negative_cycle = true; break; }
    }

    if(negative_cycle){
        cout << -1 << endl;
    }else{
        cout << max(-dist[n], 0LL) << endl;
    }
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  int a,b,c;
  int d=0;
  int e=1;
  cin>>A>>B>>C;
  if(A>=B&&A>=C){
    a=A;b=B;c=C;
  }
  if(B>=A&&B>=C){
    a=B;b=A;c=C;
  }
  if(C>=A&&C>=B){
    a=C;b=A;c=B;
  }
  b=a-b;
  c=a-c;
  if(b%2==0&&c%2==1){
    b=b;
    c=c+1;
    d++;
  }
  if(b%2==1&&c%2==0){
    b=b;
    c=c+1;
    d++;
  }
  if(b%2==1||c%2==1){
    b=b-1;
    c=c-1;
    d++;
  }
  d+=b/2;
  d+=c/2;
  cout<<d;
}
    
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[50];
int main() {
	for(ll i=0;i<=49;i++){
		a[i]=i;
	}
	ll k;
	cin>>k;
	ll j=k/50;
	for(ll i=0;i<=49;i++){
		a[i]+=j;
	}
	j=k%50;
	cout << 50<<endl;
	for(ll i=0;i<=49;i++){
		a[i]-=j;
		if(i<j){
			a[i]+=51;
		}
		cout << a[i] << " ";
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
c = input()
count = 0
i, j = 0, n - 1

while i < j:
  if c[i] == 'W' and c[j] == 'R':
    count += 1
    i += 1
    j -= 1
  elif c[i] == 'W':
    j -= 1
  elif c[j] == 'R':
    i += 1
  else:
    i += 1
    j -= 1

print(count)

Measured memory_bytes: 9356
fn main() {
    let v = read_vec::<u32>();
    let _n = v[0];
    let m = v[1];
    let aa = read_vec::<u32>();

    let total = aa.iter().sum::<u32>();
    let count = aa.into_iter().filter(|&a| a * 4 * m >= total).count();
    yn(count >= m as usize);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main(){
    int a, b;
    cin >> a >> b;
    int sum = a;
    int ans = 1;
    if(b == 1) cout << 0 << endl;
    else{
        while(b > sum){
            sum += (a - 1);
            ans++;
        }
        cout << ans << endl;
    } 
    return 0;
}

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

d.sort()

if N % 2 == 1:
    print(0)
else:
    l = d[N // 2 - 1]
    r = d[N // 2]
    
    ans = r - l
    if ans > 0:
        print(ans)
    else:
        print(0)

Measured memory_bytes: 14152
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,n;
int main()
{
	scanf("%lld %lld %lld",&a,&b,&n);
	if(n<b) printf("%lld\n",a*n/b);
	else printf("%lld\n",a*(b-1)/b);
	return 0;
}

Measured memory_bytes: 3720
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    T = inputs[1]

    count = 0
    for i in range(3):
        if S[i] == T[i]:
            count += 1
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


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

int main() {
  int x,m,y,i,count;
  
  char M;
  y=0;
  x=0;

  count=3;
	while(cin >>M){
       
    	if(count%2==1){
    		if(M == '0'){
   				 x++;
   			 }else if(M == '1'){
    			y++;
    		}
    	}else if (count%2==0){
        	if(M =='1'){
   				 x++;
   			 }else if(M =='0'){
    			y++;
    		}
        }
      count++;
      
    }
  
  if(x>y){
  i=y;
  }else{
  i=x;
  }
  
 cout << i << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
  int i,n,l;
  cin>>n>>l;
  vector <string> v;
  for(i=0;i<n;i++)
  {
    string s;
    cin>>s;
      v.push_back(s);
  }
  sort(v.begin(),v.end());
  for(i=0;i<n;i++)
    cout<<v[i];
  
  return 0;
}

Measured memory_bytes: 256