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

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a = new int[5];
        for(int i = 0; i < 5; i++){
            a[i] = sc.nextInt();
        }
        
        if(((a[2] - a[4]) < 0 || (a[2] + a[4]) > a[0]) || ((a[3] - a[4]) < 0 || (a[3] + a[4]) > a[1])){
            System.out.println("No");
        }else if(((a[2] - a[4]) >= 0 && (a[2] + a[4]) <= a[0]) && ((a[3] - a[4]) >= 0 && (a[3] + a[4]) <= a[1])){
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 26236
#include <iostream>

using namespace std;

int const nmax = 2000000;
int const modulo = 998244353;

int fact[1 + nmax], inv[1 + nmax];

void gcd(int a, int b, int &x, int &y){
  if(b == 0){
    x = 1;
    y = 0;
  } else {
    gcd(b, a % b, x, y);
    int aux = x;
    x = y;
    y = aux - a / b * y;
  }
}

void computefact(){
  fact[0] = 1;
  for(int i = 1; i <= nmax; i++)
    fact[i] = 1LL * fact[i - 1] * i % modulo;
  int x, y;
  gcd(fact[nmax], modulo, x, y);
  x %= modulo;
  if(x < 0)
    x += modulo;
  inv[nmax] = x;
  for(int i = nmax - 1; 0 <= i; i--)
    inv[i] = 1LL * inv[i + 1] * (i + 1) % modulo;
}

int comb(int n, int k){
  if(0 <= k && k <= n)
    return 1LL * fact[n] * inv[k] % modulo * inv[n - k] % modulo;
  return 0;
}

int combrep(int n, int k){
  if(n < 0 || k < 0)
    return 0;
  return comb(n + k - 1, k);
}

int main()
{
  computefact();
  int n, m;
  cin >> n >> m;
  int result = 0;
  for(int odd = m % 2; odd <= m; odd += 2) {
    result += 1LL * comb(n, odd) * combrep(n, (m * 3 - odd) / 2) % modulo;
    if(modulo <= result)
      result -= modulo;
  }

  int result2 = 0;
  for(int odd = m % 2; odd <= m; odd += 2) {
    if(1 <= odd) {
      result2 += 1LL * comb(n - 1, odd - 1) * combrep(n, (m - odd) / 2) % modulo;
      if(modulo <= result2)
        result2 -= modulo;
    }
    result2 += 1LL * comb(n - 1, odd) * combrep(n, (m - 2 - odd) / 2) % modulo;
    if(modulo <= result2)
      result2 -= modulo;
  }

  result2 = 1LL * result2 * n % modulo;

  result = (modulo + result - result2) % modulo;
  cout << result;
  return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

bool put_nums(int flag[], int now, string s, int n)
{
    if(now==n-2 || now==n-1){
        if(s[now]=='x' && flag[now+2]==flag[now+1]*(-flag[now])) return true;
        else if(s[now]=='o' && flag[now+2]==flag[now+1]*flag[now]) return true;
        else return false;
    }else{
        if(s[now]=='x'){
            flag[now+2]=flag[now+1]*(-flag[now]);
        }else{
            flag[now+2]=flag[now+1]*flag[now];
        }
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int flag[n+2], ans=0, cnt=0;//1:sheep, -1:wolf
    fill(flag, flag+n+1, 0);
    flag[0]=1, flag[1]=1, flag[n]=1, flag[n+1]=1;
    while(cnt<n){
        if(put_nums(flag, cnt, s, n)==false) break;
        cnt++;
    }
    if(cnt==n) ans=1;

    if(ans==0){
        cnt=0;
        fill(flag, flag+n+1, 0);
        flag[0]=-1, flag[1]=1, flag[n]=-1, flag[n+1]=1;
        while(cnt<n){
            if(put_nums(flag, cnt, s, n)==false) break;
            cnt++;
        }
        if(cnt==n) ans=1;
    }

    if(ans==0){
        cnt=0;
        fill(flag, flag+n+1, 0);
        flag[0]=-1, flag[1]=-1, flag[n]=-1, flag[n+1]=-1;
        while(cnt<n){
            if(put_nums(flag, cnt, s, n)==false) break;
            cnt++;
        }
        if(cnt==n) ans=1;
    }

    if(ans==0){
        cnt=0;
        fill(flag, flag+n+1, 0);
        flag[0]=1, flag[1]=-1, flag[n]=1, flag[n+1]=-1;
        while(cnt<n){
            if(put_nums(flag, cnt, s, n)==false) break;
            cnt++;
        }
        if(cnt==n) ans=1;
    }

    if(ans==1){
        for(int i=1; i<=n; i++){
            if(flag[i]==1){
                cout << 'S';
            }else{
                cout << 'W';
            }
        }
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 960
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
typedef pair <int, int> P;

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

    int n;
    cin >> n;

    int a[n];
    vector<int> pos, neg;

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

        if (a[i] > 0) {
            pos.push_back(a[i]);
        } else if (a[i] <= 0) {
            neg.push_back(a[i]);
        }
    }

    int ans = 0;
    vector <P> ret;
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end(), greater<int>());

    if (pos.size() == 0) {
        ans = neg[0];
        for (int i = 1; i < neg.size(); i++) {
            ret.push_back(P(ans, neg[i]));
            ans -= neg[i];
        }
    } else if (neg.size() == 0) {
        ans = pos[0];
        for (int i = 1; i < pos.size() - 1; i++) {
            ret.push_back(P(ans, pos[i]));
            ans -= pos[i];
        }
        ret.push_back(P(pos[pos.size() - 1], ans));
        ans = pos[pos.size() - 1] - ans;
    } else {
        ans = neg[0];
        for (int i = 0; i < pos.size() - 1; i++) {
            ret.push_back(P(ans, pos[i]));
            ans -= pos[i];
        }
        ret.push_back(P(pos[pos.size() - 1], ans));
        ans = pos[pos.size() - 1] - ans;

        for (int i = 1; i < neg.size(); i++) {
            ret.push_back(P(ans, neg[i]));
            ans -= neg[i];
        }
    }

    cout << ans << '\n';
    for (P p : ret) cout << p.first << " " << p.second << "\n";

    return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
struct node{
    int l,r;
    bool operator<(const node &x)const{
        if(r==x.r)
        return l>x.l;
        return r<x.r;
    }
}arr[1000007],brr[1000007];
int main()
{
    int n;
    cin>>n;
    string s;
    int ll=0,rr=0;
    for(int i=0;i<n;i++){
        cin>>s;
        int l=0,r=0;
        for(int j=0;j<(int)s.length();j++){
            if(s[j]=='(') l++;
            else if(l)
                l--;
            else r++;
        }
        if(r==0) ll+=l,l=0;
        else if(l==0) rr+=r,r=0;
        arr[i]={l,r};
        brr[i]={r,l};
    }
    sort(arr,arr+n);
    int l=ll;
    for(int i=0;i<n;i++){
        if(arr[i].r>l)
        {
            l=-1;
            break;
        }
        l-=arr[i].r;
        l+=arr[i].l;
    }
    l-=rr;
    if(l==0){
        cout<<"Yes"<<'\n';
        return 0;
    }
    sort(brr,brr+n);
    l=rr;
    for(int i=0;i<n;i++){
        if(brr[i].r>l)
        {
            cout<<"No"<<'\n';
            return 0;
        }
        l-=brr[i].r;
        l+=brr[i].l;
    }
    l-=ll;
    if(l==0){
        cout<<"Yes"<<'\n';
        return 0;
    }
    cout<<"No"<<'\n';
    return 0;
}


Measured memory_bytes: 19120
#include <cstdio>
#include <cstring>

#define maxn 200010
char S[maxn];
int next[maxn][26], f[maxn];
int dfs(int x)
{
	if (f[x]) return f[x];
	int ret = 0x7fffffff;
	for (int i = 0; i < 26; ++i)
		if (next[x][i])
		{
			int tmp = dfs(next[x][i]);
			ret > tmp + 1 ? ret = tmp + 1 : 0;
		}
		else return f[x] = 1;
	return f[x] = ret;
}
void print(int x)
{
	for (int i = 0; i < 26; ++i)
		if (!next[x][i])
		{
			printf("%c", i + 'a');
			return ;
		}
		else if (f[x] == f[next[x][i]] + 1)
		{
			printf("%c", i + 'a');
			print(next[x][i]);
			return ;
		}
}
int main()
{
	scanf("%s", S + 1);
	int n = strlen(S + 1);
	for (int i = n; i; --i)
	{
		memcpy(next[i - 1], next[i], sizeof (next[i]));
		next[i - 1][S[i] - 'a'] = i;
	}
//	for (int i = 0; i <= n; ++i) for (int j = 0; j < 26; ++j) if (next[i][j]) printf("next[%d][%c] = %d\n", i, j + 'a', next[i][j]);
	dfs(0);
	print(0);
	return 0;
}

Measured memory_bytes: 21888
n = $stdin.gets.to_i
a = $stdin.gets.split(" ").map(&:to_i)
avg = a.inject(:+) / n
puts [a.inject(0) {|c, v| c += (avg - v)**2}, a.inject(0) {|c, v| c += (avg + 1 - v)**2}].min

Measured memory_bytes: 1788
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

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

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n,k; cin >> n >> k;
  ll ans = k;
  
  rep(i,n-1){
    ans *= (k-1);
  }
  
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3560
/*
 *  author : Atul Anand   
 *  created on : Wed Apr 01 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int a = in.nextInt();
        int b = in.nextInt();
        String A = "";
        String B = "";
        for(int i = 0; i < b; i++){
            A += a;
        }

        for(int i = 0; i < a; i++){
            B += b;
        }

        if(A.compareTo(B) <= 0){
            println(A);
        }
        else{
            println(B);
        }

        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 23124
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
      	int m = n/1000;
      	if (n%1000 ==0){
          System.out.print(0);
        }
        else {
          int p = (m+1)*1000-n;
          System.out.print(p);
        }
      	
		
	}
}

Measured memory_bytes: 35652
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };
static const int mod = 1000000007;

int H,W;
string S[2005];

vector<int> obj_row[2005];
vector<int> obj_col[2005];

int ans=-INF;

int calc(int y,int x){
    int left,right,up,down;
    int rid=upper_bound(obj_row[y].begin(),obj_row[y].end(),x)-obj_row[y].begin();
    int did=lower_bound(obj_col[x].begin(),obj_col[x].end(),y)-obj_col[x].begin();
    if(obj_row[y].size()==0){
        left=-1;
        right=W;
    }
    else if(rid==obj_row[y].size()){
        left=obj_row[y][rid-1];
        right=W;
    }
    else if(rid==0){
        left=-1;
        right=obj_row[y][rid];
    }
    else {
        left=obj_row[y][rid-1];
        right=obj_row[y][rid];
    }
    if(obj_col[x].size()==0){
        up=-1;
        down=H;
    }
    else if(did==obj_col[x].size()){
        up=obj_col[x][did-1];
        down=H;
    }
    else if(did==0){
        up=-1;
        down=obj_col[x][did];
    }
    else {
        up=obj_col[x][did-1];
        down=obj_col[x][did];
    }
    //cout<<left<<" "<<right<<" "<<up<<" "<<down<<endl;
    //cout<<(right-left-1)+(down-up-1)<<endl;
    return (right-left-1)+(down-up-1)-1;

}

signed main(){
    cin>>H>>W;
    for(int i=0;i<H;++i)cin>>S[i];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;++j){
            if(S[i][j]=='#'){
                obj_row[i].push_back(j);
                obj_col[j].push_back(i);
            }
        }
    }
    for(int i=0;i<H;++i)for(int j=0;j<W;++j)if(S[i][j]!='#')ans=max(calc(i,j),ans);
    cout<<ans<<endl;
}


Measured memory_bytes: 71040
#include <cstdio>
int n,k;
long double ans;
int main(){
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;++i){
		if(i > k){
			ans += (n-i+1);
			break;
		}
		long double vo = 1;
		int cnt = 0,pos = i;
		while(pos < k)
			++cnt,pos*=2,vo/=2;
		ans += vo;
	}
	printf("%.12Lf",ans/n);
	return 0;
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vii=vector<vi>;
const int MAX = 510000;
const int MOD = 1000000007;
ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
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;
}


/*
* 素因数分解
* @param [in] n   自然数
* @param [in] out 素因数分解した数が入る
*/
template<typename T>
void PrimeFactors(T n, std::map<T,T> &out)
{
	while (n % 2 == 0)
	{
		++out[2];
		n = n / 2;
	}

	for (T i = 3; i <= sqrt(n); i = i + 2)
	{
		while (n%i == 0)
		{
			++out[i];
			n = n / i;
		}
	}

	if (n > 2)
		++out[n];
}



int main(void){ 
    ll n;cin>>n;
    cout<<(n-1)*(n)/2<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;  
int main(){
  int n;
  cin >> n;

    int s = 0;
    for (int _max = n;_max >0; _max--)
    {          
        int c=1;
        for (int i = 1; i <= _max/2; i++)
        {
            if(_max%i==0){
                c++;
            }
        }
        if(c==8&&_max%2==1) s++;
    }
    cout << s;
}
  
  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int hit,blow;
  vector<int> a,b;
  string ina,inb;
  while(1){
    cin >> ina >> inb;
    if(ina=="0"&&inb=="0") break;
    for(int i=0;i<4;i++){
      a.push_back(ina[i]-'0');
      b.push_back(inb[i]-'0');
    }
    hit=blow=0;
    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
	if(a[i]==b[j]){
	  if(i==j) hit++;
	  else blow++;
	}
      }
    }
    cout << hit << ' ' << blow << endl;
    a.clear();
    b.clear();
  }
  return 0;
}

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

unsigned long fact0(int n);
int main(){
  int n;
  vector<int> array;
  while(1){
    cin>>n;
    if(!n) break;
    array.push_back(n);
  }

  for( int i=0;i<array.size();i++ ){
    cout<<fact0(array[i])<<endl;
  }
  return 0;
}

unsigned long fact0(int n){
  unsigned long ten=0,five=0,two=0;
  for( int i=1;i<=n;i++ ){
    if( !(i%2) ){
      int num=i;
      while( !(num%2) ){
	num/=2;
	two++;
      }
    }
    if( !(i%5) ){
      int num=i;
      while( !(num%5) ){
	num/=5;
	five++;
      }

    }
  }

  ten=(five<two?five:two);
  return ten;
}

Measured memory_bytes: 1204
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Maybe
import Data.Function (fix)
import Data.Array (Array, array, (!))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
 
getInts :: IO [Int]
getInts = (map parseInt . BS8.words) <$> BS.getLine 
    where parseInt = fst . fromJust . BS8.readInt

solve :: String -> Int -> String
solve ('d':'r':'e':'a':'m':other) _ = solve other 1
solve ('e':'r':'a':'s':'e':other) _ = solve other 2
solve ('e':'r':'d':'r':'e':'a':'m':other) 1 = solve other 1
solve ('e':'r':other) 1 = solve other 0
solve ('r':other) 2 = solve other 0
solve [] _ = "YES"
solve _ _ = "NO"

main :: IO ()
main = do
    str <- getLine
    putStrLn $ solve str 0

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

signed main(void)
{
	int x;
	cin >> x;
	if (x == 3 || x == 5 || x == 7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque

if __name__ == '__main__':
	n, q = map(int, input().split())

	Q = deque()

	for i in range(n):
		name, time = input().split()
		Q.append([name, int(time)])

	sum = 0

	while Q:
		qt = Q.popleft()
		if qt[1] <= q:
			sum += qt[1]
			print(qt[0], sum)
		else:
			sum += q
			qt[1] -= q
			Q.append(qt)

Measured memory_bytes: 16080
#include<bits/stdc++.h>
#define ps puts("")
#define fi first
#define nd second
#define mset(x) memset((x), 0, sizeof (x))
#define mk make_pair
#define sqr(x) ((x)*(x))
#define pii pair<int,int>
#define lch (o<<1)
#define rch (o<<1|1)
using namespace std;
typedef long long ll;
ll read() {ll x = 0;char f = 1, ch = getchar();while(ch < '0' || ch > '9') {if(ch == '-')f = -1;
ch = getchar();}while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0';ch = getchar();}return x * f;}
void write(ll x) {if(x < 0) x = -x, putchar('-');if(x > 9) write(x / 10);putchar(x % 10 + '0');}
inline void writeln(ll x) {write(x);puts("");}
const int N = 210000, M = 1550000;

struct Edge {
	int u, v, w;
	void print() {
		printf("%d %d %d\n", u, v, w);
	}
}e[M];
int m, n;


int main() {
	int L = read();
	int x = L;
	while(x) {
		++n;
		x /= 2;
	}
	for(int i = 1; i < n; ++i) {
		e[++m] = {i, i + 1, 0};
		e[++m] = {i, i + 1, 1 << (n - i - 1)};
	}
	L -= (1 << (n - 1));
	int tmp = (1 << n - 1);
	for(int i = n - 1; i >= 0; --i)
		if((1 << i) & L)
			e[++m] = {1, n - i, tmp}, tmp |= (1 << i);
	printf("%d %d\n", n, m);
	for(int i = 1; i <= m; ++i)
		e[i].print();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

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

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


    int main(){
      int n;cin>>n;
      auto a = vec(int,n);
      map<int,int>mp;
      rep(i,n){
          cin>>a[i];
          mp[a[i]]++;
      }
      ll res = 1;
      ll mod = INF+7;
      if(n%2 == 1 && mp[0]>1)res = 0;
      //if(n%2 == 0 && mp[0]!=0)res = 0;
      for(auto m : mp){
          if(m.second>2)res = 0;
          res *= m.second;
          res %= mod;
      }
      cout<<res;
    }
    


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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> num;
    for(int i = 0; ; i++ ) {
        if ( N & 1 ) {
            num.push_back(1);
            if ( i % 2 == 0 ) N -= 1;
            else N += 1;
        } else {
            num.push_back(0);
        }
        N /= 2;
        if ( N == 0 ) break;
    }
    for ( int i = num.size()-1; i >= 0; i-- ) {
        cout << num[i];
    }
    cout << "\n";
    return 0;
}

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

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 

     String[] nyu=sc.nextLine().split(" ");

//     String nyu=sc.nextLine();
int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
int C=Integer.parseInt(nyu[2]);
//int D=Integer.parseInt(nyu);
int num[]={A,B,C};
Arrays.sort(num);


//StringBuffer sb = new StringBuffer(nyu);
//		String dst = sb.reverse().toString();

//     String nyu2=sc.nextLine();
//int E=Integer.parseInt(nyu2);



//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(nyu){
case "H H":
System.out.println("H") ;
break;

case "D D":
System.out.println("H") ;
break;

case "H D":
System.out.println("D") ;
break;

case "D H":
System.out.println("D") ;
break;


default:
System.out.println("NO") ;

break;
}
*/

//int res=Math.min((A*B),C);

//for(String tem:bo){
//if(tem.equals(nyu))res="vowel";
//}
//int res=0;
//for(int i=0;i<300;i++){
//if(num[i]==1)res=i;
//}

//char[] c = nyu.toCharArray();


//System.out.println(nyu+"-"+line_r_2+"-"+nyu2+"-"+line_r_1);



if(num[0]==5 && num[1]==5 && num[2]==7){
//double res=Math.ceil((AB)/2);

System.out.println("YES");
//}else if(B<A){
//System.out.println("Alice");

}else{
System.out.println("NO");
}




	}
}

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

vector<int64_t> memo;
int64_t f(int64_t n) {
    if (n == 0) {
        return 0;
    }
    if (memo[n] != -1) {
        return memo[n];
    }

    return memo[n] = (f(n % __builtin_popcountll(n)) + 1);
}

//a^b % modを求める
int64_t MODpow(int64_t a, int64_t b, int64_t mod) {
    int64_t result = 1;
    while (b) {
        if (b % 2 == 1) {
            result *= a;
            result %= mod;
        }

        b /= 2;
        a *= a;
        a %= mod;
    }

    return result;
}

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

    memo.resize(N + 2, -1);

    string X;
    cin >> X;

    int64_t b = count(X.begin(), X.end(), '1');
    //ビット数はb or (b + 1)になる

    if (b == 1) {
        //b - 1が0になって終わるので適宜計算
        int64_t one_index = find(X.begin(), X.end(), '1') - X.begin();

        for (int64_t i = 0; i < N; i++) {
            if (i == one_index) {
                //0になるので0
                cout << 0 << endl;
            } else {
                //こことone_indexだけが立つ
                int64_t v = (MODpow(2, N - 1 - i, 2) + MODpow(2, N - 1 - one_index, 2)) % 2;
                cout << f(v) + 1 << endl;
            }
        }

        return 0;
    }

    int64_t case_b_minus_1 = 0, case_b_plus_1 = 0;
    for (int64_t i = 0; i < N; i++) {
        if (X[i] == '1') {
            (case_b_minus_1 += MODpow(2, N - 1 - i, b - 1)) %= (b - 1);
            (case_b_plus_1 += MODpow(2, N - 1 - i, b + 1)) %= (b + 1);
        }
    }

    for (int64_t i = 0; i < N; i++) {
        //iを反転
        if (X[i] == '0') {
            //1になる
            int64_t v = (case_b_plus_1 + MODpow(2, N - 1 - i, b + 1)) % (b + 1);
            cout << f(v) + 1 << endl;
        } else {
            //0になる
            int64_t v = case_b_minus_1;
            //自分の影響を除く
            (v += b - 1 - MODpow(2, N - 1 - i, b - 1)) %= (b - 1);

            cout << f(v) + 1 << endl;
        }
    }
}

Measured memory_bytes: 5156
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#define int long long
using namespace std;
map<int, int>test;
map<int, int>uiop;
signed main() {
	int n, a, b = 0, c = 0, d = 0, ans = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a;
		if (h != 0) {
			if (b == a) {
				uiop[d] = h - 1;
				d++; c = 0;
				test[d] = h;
			}
		}
		b = a;
	}
	uiop[d] = n - 1; d++;
	/*for (int h = 0; h < d; h++) {
		cout << test[h] << ' ' << uiop[h] << endl;
	}*/
	for (int h = 0; h < d; h++) {
		ans = max(ans, uiop[h] - test[h - 2] + 1);
		ans = max(ans, uiop[h + 2] - test[h] + 1);
		ans = max(ans, uiop[h + 1] - test[h - 1] + 1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 9348
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<double,double>;
using vvi = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL<<60;

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

    int X,Y,Z,K;cin>>X>>Y>>Z>>K;
    vector<ll> A(X+1),B(Y+1),C(Z+1);
    REP(i,X){
        cin >> A[i];
    }
    REP(i,Y){
        cin >> B[i];
    }
    REP(i,Z){
        cin >> C[i];
    }
    A[X] = B[Y] = C[Z] = -inf;
    sort(ALL(A),greater<ll>());
    sort(ALL(B),greater<ll>());
    sort(ALL(C),greater<ll>());
    
    vector<ll> ans_long,ans;
    REP(i,Y){
        REP(k,Z){
            ans_long.push_back(B[i] + C[k]);
        }
    }
    sort(ALL(ans_long),greater<ll>());
    int mini = min(Y*Z,K);
    vector<ll> BC(mini);
    REP(i,mini)BC[i] = ans_long[i];
    
    REP(i,X){
        REP(k,mini){
            ans.push_back(A[i] + BC[k]);
        }
    }
    
    sort(ALL(ans),greater<ll>());

    REP(i,K){
        cout << ans[i] << endl;
    }



}



Measured memory_bytes: 44048
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#ifdef RUBICK
#include "dbg.h"
#endif

using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;

int main() {
    int n;
    cin >> n;

    map<int, int> M;
    for (int i = 0; i < n; i ++) {
        int x;
        cin >> x;

        if (M.count(x) == 0)
            M[x] = 0;
        M[x] ++;
    }

    vector<ll> arr;
    for (auto p : M)
        if (p.second > 1)
            arr.push_back(p.first);

    reverse(begin(arr), end(arr));
    if (arr.empty()) {
        cout << "0\n";
    } else if (M[arr[0]] >= 4) {
        cout << arr[0] * arr[0] << '\n';
    } else {
        cout << arr[0] * arr[1] << '\n';
    }

    return 0;
}



Measured memory_bytes: 4992
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;

    int w=0,r=0;
    for(int i=0;i<n;i++){
        if(s.at(i)=='W') {
            w++;
        }else{
            r++;
        }
    }
    
    int wr=0;
    if(w<=r){
        for(int i=0;i<w;i++){
            if(s.at(n-1-i)=='W') wr++;
        }
        cout << w-wr << endl;
    }else{
        for(int i=0;i<r;i++){
            if(s.at(i)=='R') wr++;
        }
        cout << r-wr << endl;
    }
}

Measured memory_bytes: 3748
#095 b-bitter alchemy
n,x=map(int,input().split())
m=[]
for i in range(n):
    m.append(int(input()))
m.sort()
g=sum(m)
ans=n
amari=x-g
while amari:
    amari=amari-m[0]
    ans+=1
    if amari-m[0]<0:
        break
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
using namespace std;
//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int n;
  cin >> n;
  if(n < 1000){
    cout << "ABC" << endl;
  }else{
    cout << "ABD" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
  long long A[200000];
  
  long long total = 0;
  long long kakeru = 0;
  
  cin >> N;
  for(int i = 0; i < N; i++)
  {
    cin >> A[i];
    kakeru += A[i];
    
    //cout << kakeru << endl;
  }
  
  for(int i = 0; i < N-1; i++)
  {
    
    kakeru -= A[i];
    
    //cout << A[i] << ' ' << kakeru << ' ';
        
    total += (A[i] * (kakeru % 1000000007)) % 1000000007;
    
    //cout << total << ' ' << endl;
  }
  
  cout << total % 1000000007 << endl;
}

Measured memory_bytes: 5192
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	vector<pair<int, int>> b(m);
	for (int i = 0; i < m; ++i) {
		cin >> b[i].second >> b[i].first;
	}
	sort(b.rbegin(), b.rend());
	for (int i = 0; i < m; ++i) {
		while (b[i].second--) {
			a.push_back(b[i].first);
			if ((int) a.size() == 2 * n) {
				goto there;
			}
		}
	}
	there:;
	sort(a.rbegin(), a.rend());
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		sum += a[i];
	}
	cout << sum << '\n';
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;
int main(){
string s;
int a;
bool c;
cin >> s;
	if(s=="RRR")a=3;
  	else if(s=="RRS" || s=="SRR")a=2;
  	else if(s=="SSS")a=0;
  	else a=1;
  	cout << a << endl;
  return 0;
}
  

Measured memory_bytes: 3636
from sys import stdin
import numpy as np
from copy import deepcopy

N = input()
T, A = list(map(int,input().split()))
H = list(map(int,input().split()))


var = float('inf')
idx = 1
for i in range(len(H)):
  if (abs(T-A-0.006*H[i]) < var):
    var = abs(T-A-0.006*H[i])
    idx = i
    
print(int(idx+1))

Measured memory_bytes: 14428
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n;
	string s;
	cin>>n>>s;
	int pre[n], suf[n];
	pre[0] = s[0] == 'W', suf[n-1] = s[n-1] == 'E';
	fore(i, 1, n) pre[i] = pre[i-1] + (s[i] == 'W');
	for(int i = n - 2; i > -1; i--) suf[i] = suf[i+ 1] + (s[i] == 'E');
	int res = MOD;
	fore(i, 0, n)
	{
		res = min(res, (i > 0? pre[i-1]:0) + (i < n-1? suf[i+1]:0));
	}
	cout<<res<<'\n';

	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;


void solve(int testCase){

    string s;
    cin >> s;

    if(s[1] == 'R') {
            s[1] = 'B';
    }
    else {
            s[1] = 'R';
    }

    cout << s << endl;

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 3608
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000



N = int(input())
A = [int(i) for i in input().split()]

A_ = list(set(A))
if len(A_) % 2 == 1:
    ans = len(A_)
else:
    ans = max(1,len(A_)-1)

print(ans)
"""

"""


Measured memory_bytes: 16976
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int K, X;
	cin >> K >> X;

	int begin = X - K + 1;
	int end = X + K;
	for (int index = begin; index < end; index++)
	{
		if (index > begin)
		{
			cout << " ";
		}

		cout << index;
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : AOJ.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){


	int a,b,c;
	cin>>a>>b>>c;

	if(a+b>=c){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}


	return 0;



}




Measured memory_bytes: 764
if __name__ == "__main__":
    s = input()
    dna = ['A', 'C', 'G', 'T']

    ans = 0
    tmp = 0
    for i in range(len(s)):
        if s[i] in dna:
            tmp += 1
        else:
            if tmp > ans:
                ans = tmp
                tmp = 0
            else:
                tmp = 0
    if tmp > ans:
        ans = tmp

    print(ans)


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

using namespace std;
using ll = long long;

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  int c[h][w];
  rep(i, h) rep(j, w) {
    char x;
    cin >> x;
    c[i][j] = ((x == '.') ? 0 : 1);
  }

  int d[h][w];
  int ans = 0;

  rep(i, 1 << h) {
    rep(y, h) rep(x, w) { d[y][x] = c[y][x]; }

    rep(y, h) {
      if (i >> y & 1) {
        rep(k, w) d[y][k] = 2;
      }
    }

    rep(j, 1 << w) {
      int e[h][w];
      rep(y, h) rep(x, w) e[y][x] = d[y][x];
      rep(x, w) {
        if (j >> x & 1) {
          rep(k, h) e[k][x] = 2;
        }
      }
      int cnt = 0;
      rep(i, h) rep(j, w) if (e[i][j] == 1) { ++cnt; }
      if (cnt == k) ++ans;
    }
  }

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


Measured memory_bytes: 3636
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	mod = 10^9+7
	s = readline() |> chomp
	l = length(s)
	dp = zeros(Int,l+1,4)
	dp[1,4] = 1
	for i in 1:l
		dp[i+1,4] = s[i]=='?'?(3*dp[i,4])%mod:dp[i,4]
		for j in 1:3
			m = s[i]=='?'?3:1
			if (j,s[i])==(3,'A')||(j,s[i])==(2,'B')||(j,s[i])==(1,'C')||s[i]=='?'
				dp[i+1,j] = (m*dp[i,j]%mod+dp[i,j+1])%mod
			else
				dp[i+1,j] = m*dp[i,j]%mod
			end
		end
	end
	println(dp[l+1,1])
end

main()

Measured memory_bytes: 153320
def main():
    N=int(input())
    A=list(map(int,input().split()))
    res=0
    for i in range(1,N):
        if A[i-1]>A[i]:
            res+=A[i-1]-A[i]
            A[i]=A[i-1]

    print(res)
if __name__=="__main__":
    main()

Measured memory_bytes: 94280
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> ref(A);
    for(int i=0; i<A; i++){
      cin >> ref[i];
    }
    vector<int> mic(B);
    for(int i=0; i<B; i++){
      cin >> mic[i];
    }
    vector<vector<int>> cp(M, vector<int>(3));
    for(int i=0; i<M; i++){
      cin >> cp[i][0] >> cp[i][1] >> cp[i][2];
    }
    int refmin = ref[0];
    for(int i=1; i<A; i++){
        if(ref[i] < refmin){
            refmin = ref[i];
        }
    }
    int micmin = mic[0];
    for(int i=1; i<B; i++){
        if(mic[i] < micmin){
            micmin = mic[i];
        }
    }
    int ot = refmin + micmin;
    int p = cp[0][0]-1;
    int q = cp[0][1]-1;
    int Mmin = (ref[p] + mic[q] - cp[0][2]);
    for(int i=1; i<M; i++){
        int s = cp[i][0]-1;
        int t = cp[i][1]-1;
        int l = ref[s] + mic[t] - cp[i][2];
        if(l < Mmin){
            Mmin = l;
        }
    }
    if(ot < Mmin){
        cout << ot;
    }
    else{
        cout << Mmin;
    }
}


Measured memory_bytes: 6528
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

template<int MAXV>
struct scc {
  std::vector<int> G[MAXV], rG[MAXV], vs;
  bool used[MAXV];
  //int cmp[MAXV];
  scc() {}
  void dfs(int v) {
    used[v] = true;
    for(auto c: G[v]) if(!used[c]) dfs(c);
    vs.push_back(v);
  }
  void rdfs(int v, int k) {
    used[v] = true;
    //cmp[v] = k;
    for(auto c: rG[v]) if(!used[c]) rdfs(c, k);
  }
  int build(int V) {
    std::fill_n(used, V, false);
    vs.clear();
    for(int v = 0; v < V; ++v) if(!used[v]) dfs(v);
    std::fill_n(used, V, false);
    int k = 0;
    for(int i = vs.size()-1; i >= 0; --i) {
      if(!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
  }
  void add_edge(int fr, int to) {
    G[fr].push_back(to); rG[to].push_back(fr);
  }
};

int const MAXN = 5e5;

scc<MAXN> sc;
int depth[MAXN];
int calc_depth(int v) {
  if(depth[v] >= 0) return depth[v];
  int res = -1;
  for(auto c: sc.G[v]) res = std::max(res, calc_depth(c));
  ++res;
  return depth[v] = res;
}

void zarray(std::string s, std::vector<int>& Z) {
  int N = s.size(), L, R = 0;
  Z.resize(N);
  for(int i = 1; i < N; ++i) {
    if(i > R) {
      L = R = i;
      while(R < N && s[R-L]==s[R]) ++R;
      Z[i] = R-- -L;
    } else if(Z[i-L] < R-i+1) {
      Z[i] = Z[i-L];
    } else {
      L = i;
      while(R < N && s[R-L] == s[R]) ++R;
      Z[i] = R-- -L;
    }
  }
}


int main() {
  std::string S, T; std::cin >> S >> T;
  int N = S.size(), M = T.size(), K = N+M-1;
  std::string U = S;
  for(int i = 0; i < (M-1)/N; ++i) U += S;
  U += S.substr(0, K - U.size());
  std::vector<int> Z;
  zarray(T+" "+U, Z);
  std::vector<int> v;
  for(int i = 0; i < N; ++i) if(Z[M+1+i]>=M) v.push_back(i);
  
  if(v.size() < 1) fin(0);
  for(int fr: v) {
    int to = (fr+M)%N;
    if(fr == to) fin(-1);
    sc.add_edge(fr, to);
  }
  if(sc.build(N) < N) fin(-1);
  std::fill_n(depth, N, -1);
  int ans = 0;
  for(int i = 0; i < N; ++i) {
    ans = std::max(ans, calc_depth(i));
  }
  fin(ans);
  
  return 0;
}


Measured memory_bytes: 86672
N, Y = map(int, input().split())

k_max = Y // 1000
extra = k_max - N
if extra < 0:
    print('-1 -1 -1')
else:
    for x in range(N + 1):
        y = (extra - 9 * x) // 4
        if (extra - 9 * x) % 4 == 0 and x + y <= N and y >= 0:
            print(x, y, N - x - y)
            break
    else:
        print('-1 -1 -1')

Measured memory_bytes: 3060
#include "iostream"
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = a; i < b + 1; i++) {
    int x4 = i / 10000;
    int x3 = (i - x4 * 10000) / 1000;
    if ((i - 10001 * x4 - 1010 * x3) % 100 == 0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const long long INF = 1e18;
const double PI = 2 * asin(1);

int main(){
  ll N; cin >> N;
  ll ans = 0;
  if (N % 2 == 0){
    while (N > 0){
      ans += N / 10;
      N /= 5;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long; 
int main(){
	int n, m;	cin >> n >> m;
  	vector<vector<int>> plc(n);
  	rep(i,m){
		int a, b;	cin >> a >> b;
      	a--;	b--;
      	plc.at(a).push_back(b);
      	plc.at(b).push_back(a);      
    }
  	queue<int> q;
  	vector<int> dist(n,-1);
  	vector<int> pre(n,-1);
    q.push(0);
  	dist.at(0) = 0;
  	while(!q.empty()){
    	int now = q.front();
      	q.pop();
      	rep(i,plc.at(now).size()){
        	if(dist.at(plc.at(now).at(i)) == -1){
            	q.push(plc.at(now).at(i));
              	pre.at(plc.at(now).at(i)) = now;
              	dist.at(plc.at(now).at(i)) = dist.at(now) + 1;
            }
        }
    }
	
  	cout << "Yes" << endl;
  	rep(i,pre.size()){
    	int tmp = pre.at(i) + 1;
      	if(i != 0) cout << tmp << endl;
    }
}

Measured memory_bytes: 10656
from collections import deque


N = 100
WHITE = 0
GRAY = 1
BLACK = 2

M = [[0 for _ in range(N)] for _ in range(N)]
color = [0 for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]
nt = [0 for _ in range(N)]
tt = 0


def main():
    n = int(input())
    for _ in range(n):
        u, k, *v_s = map(int, input().split(' '))
        for j in range(k):
            M[u-1][v_s[j-1]-1] = 1

    dfs(n)

    for i in range(n):
        print('{} {} {}'.format(i+1, d[i], f[i]))


def dfs(n):
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(n, u)


def dfs_visit(n, r):
    global tt
    color[r] = GRAY
    tt += 1
    d[r] = tt
    for v in range(0, n):
        if M[r][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(n, v)
    color[r] = BLACK
    tt += 1
    f[r] = tt


if __name__ == '__main__':
    main()



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

// 23:25-23:29
int main(void){
    int n = 0; 
    int tmp = 0;
    int min = 1000000001;
    int max = 0;

    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        scanf("%d", &tmp);
        if(min >= tmp){
            min = tmp;
        }
        if(max <= tmp){
            max = tmp;
        }
    }

    printf("%d\n", max - min);

    return 0;

} 


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


int main(){
    int N;
    int a[100001];
    int ans = -1;
    int b[100001];
    int tmp = 1;
    cin >> N;
    for(int i = 1; i <= N; i++){
        cin >> a[i];
        b[i] = 0;
    }
    for(int i = 1; i <= N; i++){
        b[tmp] = 1;
        tmp = a[tmp];
        if(b[tmp] == 1){
            break;
        }else if(tmp == 2){
            ans = i;
            break;
        }

    }


    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>  
  
using namespace std;  
  
const int N = 10;  
  
int main()  
{  
    int n;  
  
    cin >> n;  
    while(n--) {  
        bool ans = true;  
        int a, b=-1, c=-1;  
        for(int i=1; i<=N; i++) {  
            cin >> a;  
            if(ans) {  
                if(a > b)  
                    b = a;  
                else if(a > c)  
                    c = a;  
                else  
                    ans = false;  
            }  
        }  
  
        cout << (ans ? "YES" : "NO") << endl;  
    }  
  
    return 0;  
}  

Measured memory_bytes: 2988