akhauriyash/Code-Regression huggingface dataset:
n,m = map(int,input().split())

import numpy as np
graph = np.zeros((n,n))
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1][b-1] = graph[b-1][a-1] = 1

from itertools import permutations
nv = [i for i in range(1,n)]
def main():
    def checkroot(root,graph):
        if graph[0][root[0]] == 0:
            return 0
        for i in range(1,len(root)):
            if graph[root[i]][root[i-1]]==0:
                return 0
        return 1

    ans = 0
    for root in permutations(nv):
        if checkroot(root,graph)==1:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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

typedef long long ll;

ll a, b, c, d, n;

int main() {
    cin >> a >> b >> c >> d >> n;
    n*=4;
    b = min(b, 2*a);
    c = min(c, 2*b);
    d = min(d, 2*c);

    ll ans = 0;
    ans += n / 8 * d; n %= 8;
    ans += n / 4 * c; n %= 4;
    ans += n / 2 * b; n %= 2;
    ans += n;

    cout << ans;
}


Measured memory_bytes: 256
N = int(input())
X = input()

cnt = 0
for i in range(N):
    if X[i] == "1":
        cnt += 1
    
down = [0] * N
up = [0] * N
ald = 0
alu = 0
for i in range(N):
    up[i] = pow(2, N-1-i, cnt+1)
    if X[i] == "1":
        alu += up[i]
        alu %= cnt+1
    if cnt <= 1:
        continue
    down[i] = pow(2, N-1-i, cnt-1)
    if X[i] == "1":
        ald += down[i]
        ald %= cnt-1

for i in range(N):    
    if X[i] == "1":
        if cnt == 1:
            print(0)
            continue
        n = (ald - down[i]) % (cnt-1)
    else:
        n = (alu + up[i]) % (cnt+1)
    ans = 1
    while n != 0:
        c = 0
        for j in range(20):
            if (n >> j) % 2 == 1:
                c += 1
        n %= c
        ans += 1
    print(ans)
        
    
    

Measured memory_bytes: 77720
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
	int n;
	cin >> n;
	if (n % 2 == 0) {
		cout << 0.5 << endl;
	} else {
		double d = n;
		cout <<  fixed << setprecision(11) << (double) (n / 2 + 1)  / (double) n << endl; 
	}



	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long

using namespace std;

int n, arr[200001], cnt[200001];

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

    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> arr[i];

    vector<int> ans;
    for (int i = n; i >= 1; i--)
        if (cnt[i] % 2 != arr[i])
        {
            ans.push_back(i);
            for (int j = 1; j * j <= i; j++)
                if (j * j == i)
                    cnt[j]++;
                else if (i % j == 0)
                    cnt[j]++, cnt[i / j]++;
                else;
        }
    cout << ans.size() << '\n';
    for (int i : ans)
        cout << i << ' ';
    cout << '\n';

    return 0;
}

Measured memory_bytes: 5108
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

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

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}

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

	static public class Record {
		boolean flag = false;
		public final Record[] sub;
		public Record(int depth) {
			if(depth == 0) {
				sub = null;
				return;
			}
			sub = new Record[10];
			for(int i=0;i<10;i++) {
				sub[i]=new Record(depth-1);
			}
		}
		public int sum() {
			if(!flag) {
				return 0;
			}
			if(sub == null) {
				return 1;
			}
			int sum = 0;
			for(Record s : sub) {
				sum += s.sum();
			}
			return sum;
		}
		public void append(int n) {
			for(int i=0;i<10;i++) {
				Record s = sub[i];
				if(s.flag && s.sub!=null) {
					s.append(n);
				}
			}
			sub[n].flag = true;
		}
	}

	public void exec() throws Exception{
		final int N = sc.nextInt();
		final String S = sc.next();
		Record root = new Record(3);
		root.flag = true;

		for(int i=0;i<N;i++) {
			final int s = S.charAt(i)-'0';
			root.append(s);
		}
		out.println(root.sum());
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<queue<int>> q(n);
    vector<int> v(n, 1);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        q[a-1].emplace(b-1);
        q[b-1].emplace(a-1);
    }
    int x = 0, y = q[0].front(); q[0].pop();
    v[x] = 0, v[y] = 0;
    deque<int> ans;
    ans.emplace_front(x);
    ans.emplace_back(y);

    while(!q[x].empty() || !q[y].empty()){
        int x2 = x , y2 = y;
        if(!q[x].empty()){
            if(v[q[x].front()]) {
                x2 = q[x].front();
                v[x2] = 0;
                ans.emplace_front(x2);
            }
            q[x].pop();
        }
        if(!q[y].empty()){
            if(v[q[y].front()]){
                y2 = q[y].front();
                v[y2] = 0;
                ans.emplace_back(y2);
            }
            q[y].pop();
        }
        x = x2, y = y2;
    }
    int len = static_cast<int>(ans.size());
    cout << len << "\n";
    for (int i = 0; i < len; ++i) {
        if(i) printf(" ");
        printf("%d", ans.front()+1);
        ans.pop_front();
    }
    return 0;
}


Measured memory_bytes: 68864
class Factorial:
    def __init__(self,n,mod):
        self.f=f=[0]*(n+1)
        f[0]=b=1
        self.mod=mod
        for i in range(1,n+1):f[i]=b=b*i%mod
        self.inv=inv=[0]*(n+1)
        inv[0]=b=pow(self.f[n],mod-2,mod)
        for i in range(1,n+1):inv[i]=b=b*(n+1-i)%mod
        self.inv.reverse()
    def factorial(self,i):
        return self.f[i]
    def ifactorial(self,i):
        return self.inv[i]
    def comb(self,n,k):
        return self.f[n]*self.inv[n-k]%self.mod*self.inv[k]%self.mod if n>=k else 0
M=10**9+7
a,b,c,d=map(int,input().split())
comb=Factorial(c+d+2,M).comb
f=lambda r,c:comb(c+r+2,r+1)-c-r-2
print((f(c,d)-f(c,b-1)-f(a-1,d)+f(a-1,b-1))%M)

Measured memory_bytes: 69872
#include <stdio.h>

int main(void){

    char base;
    scanf("%c", &base);

    if (base == 'A'){
        printf("T");
    } else if (base == 'T'){
        printf("A");
    } else if (base == 'G'){
        printf("C");
    } else {
        printf("G");
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    
    rep(i,5){
        int a;cin >> a;
        if(a == 0){
            cout << i+1 << endl;
            return 0;
        }

    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int main()
{
	int n,m;
	cin>>n>>m;
	cout<<n*(n-1)/2+m*(m-1)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7, MX=200010;

int h, w, a, b;
ll F[MX]={1}, I[MX];

ll pw(ll a, int e){
	if(e==0) return 1;
	ll t = pw(a,e/2); t=t*t%MOD;
	return e%2 ? t*a%MOD : t;
}
ll C(int n, int r){
	return F[n]*I[r]%MOD*I[n-r]%MOD;
}
int main(){
	cin>>h>>w>>a>>b;
	for(int i=1; i<=200005; i++) F[i]=1LL*F[i-1]*i%MOD;
	for(int i=0; i<=200005; i++) I[i]=pw(F[i], MOD-2);

	ll ans=0;

	for(int i=b+1; i<=w; i++){
		ll now=C(i-1 + h-a-1, i-1);
		now = now * C(w-i + a-1, w-i) % MOD;
		ans = (ans+now)%MOD;
	}
	cout<<ans<<'\n';
	
	return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>

int main() {
    int n, i, sum = 0, sum_left = 0, ans = 0;
    scanf("%d", &n);
    int w[n - 1], temp[n - 1];
    for ( i = 0; i < n; i++ ) {
        scanf("%d", &w[i]);
        sum += w[i];
    }
    sum_left = w[0];
    temp[0] = abs(sum_left - (sum - sum_left));
    ans = temp[0];
    for ( i = 1; i < n; i++ ) {
        sum_left += w[i];
        temp[i] = abs(sum_left - (sum - sum_left));
        if ( temp[i] < ans ) {
            ans = temp[i];
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int n;
int a[100010];
int acc[100010];
signed main() {
    cin >> n;
    rep(i,0,n) cin >> a[i];
    sort(a, a+n);

    rep(i,0,n) {
        if(i == 0) acc[i] = a[i];
        else acc[i] = a[i] + acc[i-1];
    }

    int ans = 1;
    bool ok[100010] = {};
    ok[n-1] = true;
    repr(i,n-2,0) {
        if(acc[i] * 2 >= a[i+1] && ok[i+1]) {
            fprintf(stderr, "debug: ok(%lld): %lld\n", i, a[i]);
            ans++;
            ok[i] = true;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
import itertools

n,m,q = map(int, input().split())
list_ = [list(map(int, input().split())) for _ in range(q)]

num=1
seed = [[i] for i in range(1,m+1)]
while num!=n:
  num+=1
  tmp_list = []
  while seed:
    tmp = seed.pop()
    for i in range(tmp[-1],m+1):
      tmp_list.append(tmp+[i])
  seed = tmp_list.copy()

max_score = 0
visited = set()
for arr in seed:
  score = 0
  for arr_2 in list_:
    if arr[arr_2[1]-1] - arr[arr_2[0]-1] == arr_2[2]:
      score+=arr_2[3]
      max_score = max(max_score, score)
print(max_score)

Measured memory_bytes: 23900
#include <iostream>

using namespace std;

class Dice{
public:
    int dice[6];

    void move(char c){
        int tmp;
        switch(c){
            case('S'):
                tmp = dice[5];
                dice[5] = dice[1];
                dice[1] = dice[0];
                dice[0] = dice[4];
                dice[4] = tmp;
                break;
            case('N'):
                tmp = dice[5];
                dice[5] = dice[4];
                dice[4] = dice[0];
                dice[0] = dice[1];
                dice[1] = tmp;
                break;
            case('E'):
                tmp = dice[5];
                dice[5] = dice[2];
                dice[2] = dice[0];
                dice[0] = dice[3];
                dice[3] = tmp;
                break;
            case('W'):
                tmp = dice[5];
                dice[5] = dice[3];
                dice[3] = dice[0];
                dice[0] = dice[2];
                dice[2] = tmp;
                break;
        }
    }
};

int main()
{
    Dice dice1;
    Dice dice2;

    for(int i=0; i<6; ++i){
        cin >> dice1.dice[i];
    }
    for(int i=0; i<6; ++i){
        cin >> dice2.dice[i];
    }

    for(int s=0; s<4; ++s){
        dice2.move('S');
        for(int e=0; e<4; ++e){
            dice2.move('E');
            for(int n=0; n<4; ++n){
                dice2.move('N');
                if( dice1.dice[0] == dice2.dice[0] and dice1.dice[1]== dice2.dice[1] and dice1.dice[2] == dice2.dice[2] and dice1.dice[3] == dice2.dice[3]){
                    cout << "Yes" << endl;
                    goto dend;
                }
            }
        }
    }
    cout << "No" <<endl;
    dend:;

    return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>
#define N 100

int main(){
  int M[N][N];
  int n,u,k,v,i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j] = 0;
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;

ll nCr(int n,int r){
    long long p=1,k=1;


    if(n<r)
        return 0;

    if(n-r<r){
        r = n-r;
    }
    if(r!=0){
        while(r){
            p *= n;
            k *= r;

            ll m = __gcd(p,k);

            p /= m;
            k /= m;

            n--;
            r--;
        }
    }
    else
        p = 1;

    return p;
}

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

    cout<<nCr(n,2)+nCr(m,2);

    return 0;

}


Measured memory_bytes: 3644
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {

    input!{
        k: i32,
    }
    let result:i32;
    if k % 2 == 0 {
        result = (k/2) * (k/2);
    } else {
        result = (k/2) * ((k/2)+1);
    }

    println!("{}", result);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

struct Dice {
    array<int, 6> dice;

    Dice(int d1, int d2, int d3, int d4, int d5, int d6)
    {
        dice[0] = d1;
        dice[1] = d2;
        dice[2] = d3;
        dice[3] = d4;
        dice[4] = d5;
        dice[5] = d6;
    }

    void _roll(int a, int b, int c, int d)
    {
        int tmp = dice[a];
        dice[a] = dice[b];
        dice[b] = dice[c];
        dice[c] = dice[d];
        dice[d] = tmp;
    }

    void roll(char dir)
    {
        switch (dir) {
        case 'S':
            _roll(0, 1, 5, 4);
            _roll(0, 1, 5, 4);
        case 'N':
            _roll(0, 1, 5, 4);
            break;
        case 'E':
            _roll(0, 2, 5, 3);
            _roll(0, 2, 5, 3);
        case 'W':
            _roll(0, 2, 5, 3);
            break;
        }
    }

    int right(int _top, int _front)
    {
        for (size_t i = 0; i < 6; i++) {
            for (size_t j = 0; j < 4; j++) {
                if (dice[0] == _top && dice[1] == _front)
                    goto out;

                _roll(1, 2, 4, 3);
            }

            if (i % 2) {
                _roll(0, 1, 5, 4);
            } else {
                _roll(0, 2, 5, 3);
            }
        }

    out:
        return dice[2];
    }

    bool operator==(Dice& other)
    {
        bool ret = false;

        for (size_t i = 0; i < 6; i++) {
            for (size_t j = 0; j < 4; j++) {
                if (dice == other.dice) {
                    ret = true;
                    goto out;
                }

                _roll(1, 2, 4, 3);
            }

            if (i % 2) {
                _roll(0, 1, 5, 4);
            } else {
                _roll(0, 2, 5, 3);
            }
        }

    out:
        return ret;
    }
};

int main()
{
    array<int, 6> d;
    for (auto&& i : d) {
        cin >> i;
    }
    Dice d1(d[0], d[1], d[2], d[3], d[4], d[5]);

    for (auto&& i : d) {
        cin >> i;
    }
    Dice d2(d[0], d[1], d[2], d[3], d[4], d[5]);

    cout << (d1 == d2 ? "Yes" : "No") << endl;
}



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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1000000000000000000ll;

int C(int x){
    int d=1;

    int sum=0;
    for(int i=1;;i++){
        int dd=d*10;

        int l=d-1,u=min(dd-1,x);

        int tmp=u/3-l/3;
        sum+=tmp*4;
        tmp=u/5-l/5;
        sum+=tmp*4;
        if(sum>=INF)return INF;
        tmp=u-l-(u/3-l/3)-(u/5-l/5)+(u/15-l/15);
        sum+=tmp*i;
        if(sum>=INF)return INF;
        d*=10;
        if(x<d)return sum;
    }
}

signed main(){
    int S;
    cin>>S;

    int lb=0,ub=INF;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        if(C(mid)<S)lb=mid;
        else ub=mid;
    }

    string str;
    for(int i=lb+1;i<lb+100;i++){
        if(i%3==0&&i%5==0){
            str+="FizzBuzz";
        }
        else if(i%3==0){
            str+="Fizz";
        }
        else if(i%5==0){
            str+="Buzz";
        }
        else{
            stringstream ss;
            ss<<i;
            str+=ss.str();
        }
    }

    cout<<str.substr(S-C(lb)-1,20)<<endl;
    return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,sum=0;
    cin>>n;
    int arr[n];
    for (int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for(int i=0;i<n-1;i++){
        sum+=arr[i];
    }
    int max=arr[n-1]/2;
    cout<<sum+max<<endl;
	return 0;
}


Measured memory_bytes: 3476
#include <stdio.h>

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

	int i, j, k, n, p[1000] = {};
	for (n = 1; n * (n + 1) / 2 < N; n++);
	if (n * (n + 1) / 2 > N) printf("No\n");
	else {
		printf("Yes\n%d\n%d", n + 1, n);
		for (j = 1; j <= n; j++) printf(" %d", j);
		for (i = 1, k = n + 1; i <= n; i++) {
			printf("\n%d %d", n, i);
			for (j = 2; j <= n - i + 1; j++) printf(" %d", k++);
			p[i] = k - 1;
			for (j = 1; j < i; j++) printf(" %d", p[j]--);
		}
		printf("\n");
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1708
# coding: utf-8

def main():
    s = input().strip()
    if len(s) == 2:
        return ("1 2" if s[0] == s[1] else "-1 -1")
    for i in range(len(s) - 2):
        if len(set(s[i:i + 3])) <= 2:
            return "{} {}".format(i + 1, i + 3)
    return "-1 -1"


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

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>

int N = 0, L = 0;
std::vector< std::string > S;

int main(void){
    std::cin >> N >> L;

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

    std::sort(S.begin(), S.end());

    for(i=0; i<N; ++i) std::cout << S[i];
    std::cout << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define range(n) for(int i = 0; i < n; i++)
#define forn(x, n) for(int x = 0; x < n; x++)
#define maxn "100000"
#define mod "1000000007"
#define md(x) ((((x) % mod) + mod) % mod)
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF INT_MAX
#define INFd 1e9

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;

//Trace dinamico
template<typename T>
void trace(T a) { cout << a << "\n"; }
template<typename T, typename... Args>
void trace(T a, Args... args) { cout << a << " "; trace(args...); }

//DP debug
int recNum = 0;
void prTabs() { range(recNum) cout << "    "; }
template<typename... Args>
void recInit(Args... args) { prTabs(); trace("rec(", args..., ")"); recNum++; }
template<typename T>
void recEnd(T a) { prTabs(); trace("->", a); recNum--;}
int n, m, a, b, c, d;
map<int, int> s;
void mapInsert(int x) {
    if (s.count(x)) {
        s[x]++;
    } else {
        s[x] = 1;
    }
}
void mapErase(int x) {
    if (!s.count(x) || s[x] <= 1) {
        s.erase(x);
    } else {
        s[x]--;
    }
}

int mapCount(int x) {
    return s.count(x);
}

int first() {
    return (*(s.begin())).fi;
}
int last() {
    return (*(--s.end())).fi;
}
int main(){
	sc("%d", &n);
    int li[100000];
    vector<ii> steps;
    int sz = 0;
    for(int i = 0; i < n; i++) {
        sc("%d", &a);
        mapInsert(a);
        sz++;
    }
    
    
    while(sz > 2) {
        map<int, int>::iterator it1 = s.begin();
        map<int, int>::iterator it2 = s.end();
        it2--;
        a = first(); b = last();
        mapErase(a); mapErase(b);
        c = first(); d = last();
        //trace(a, b, c, d);
        
        if (abs((a-b)-d) > abs((b-a)-c)){
            mapInsert(a-b);
            steps.pb({a, b});
            //trace("insere:", a-b);
        } else {
            mapInsert(b-a);
            steps.pb({b, a});
            //trace("insere:", b-a);
        }
        sz--;
    }
    
    steps.pb({last(), first()});
    //trace(*it2, *it1);
    pr("%d\n", last()-first());
    for(int i = 0; i < (int)steps.size(); i++) {
        pr("%d %d\n", steps[i].fi, steps[i].se);
    }
 	return 0;
}


Measured memory_bytes: 3576
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

int N;
string s1, s2;

signed main(void){
	cin >> N;
	cin >> s1;
	cin >> s2;

	int pre = 0;
	float ans = 3;

	rep(i,N){
		if(s1[i]!=s2[i]){
			if(pre==1){
				ans*=2;
			}else if(pre==2){
				ans*=3;
			}
			if(i==0){
				ans*=2;
			}
			i++;
			pre=2;
		}else{
			if(pre==1){
				ans*=2;
			}else if(pre==2){
				ans*=1;
			}
			pre=1;
		}
	}

	cout << (int)ans%1000000007 << endl;

	return 0;
}

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

int main() {
	int	n;
	cin >> n;
	bitset<64>	bs;
	rep(i, n)
	{
		int	a;
		cin >> a;
		if (a >= 0 && a < 4)
		{
			int	b;
			cin >> b;
			if (a == 0) // test
				cout << bs.test(b) << endl;
			else if (a == 1) // set
				bs.set(b);
			else if (a == 2) // clear
				bs.reset(b);
			else // flip
				bs.flip(b);
		}
		else if (a == 4) // all
			cout << bs.all() << endl;
		else if (a == 5) // any
			cout << bs.any() << endl;
		else if (a == 6) // none
			cout << bs.none() << endl;
		else if (a == 7) // count
			cout << bs.count() << endl;
		else // val
			cout << bs.to_ullong() << endl;
	}
}



Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long
int main() {
	int N;
	string s;
	cin >> N;
	int v[114514]={};//0? 1M 2F 3V
	cout << 0 <<endl;
	fflush(stdout);
	cin >> s;
	if(s=="Vacant"){
		return 0;
	}else if (s=="Male") {
		v[0]=1;
	}
	else {
		v[0]=2;
	}

	cout << N-1 <<endl;
	fflush(stdout);
	cin >> s;
	if(s=="Vacant"){
		return 0;
	}else if (s=="Male") {
		v[N-1]=1;
	}
	else {
		v[N-1]=2;
	}
	int left=0,right=N-1,mid;
	while (right-left>1) {
		mid=(left+right)/2;
		cout << mid <<endl;
		fflush(stdout);
		cin >> s;
		if(s=="Vacant"){
			return 0;
		}else if (s=="Male") {
			v[mid]=1;
		}
		else {
			v[mid]=2;
		}
		if ((((left+mid)%2==0 && v[left]==v[mid])||((left+mid)%2==1 && v[left]!=v[mid]))) {
			left=mid;
		}
		else {
			right=mid;
		}
	}
	return 0;
}


Measured memory_bytes: 1364
// C.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5+200;

int height[MAX_N], n;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &height[i]);
	int ans = 0;
	for (int i = 2, curt = 0; i <= n; i++)
	{
		if (height[i] <= height[i - 1])
			curt++;
		else
			curt = 0;
		ans = max(ans, curt);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 640
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

int main(){
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  sort(A,A+3);
  int total = A[2] - A[0];
  printf("%d\n",total );
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<iomanip>
#include<algorithm>

using namespace std;

#define debug(x) cout<< #x <<" : "<< x << endl;
#define repi(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n);
#define int long long

const int INF = (1<<30);
const int MOD = (int)1e9 + 7;

const int NUM = 9;

bool check(vector<int> &a, vector<int> &b){
    int A = 0, B = 0;
    for(int i = 0; i < a.size(); i++){
        if(a[i] > b[i]) A += a[i] + b[i];
        else B += a[i] + b[i];
    }

    return A > B;
}

signed main(){
    cout<<fixed<<setprecision(7);
    int n;

    cin>>n;


    for(int i = 0; i < n; i++){
        vector<int> a(NUM),b(NUM);
        int con = 0;
        int k = 1;

        for(int j = 0; j < NUM; j++){
            cin>>a[j];
            k *= (j+1);
        }

        for(int j = 0; j < NUM; j++){
            cin>>b[j];
        }

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

        while(true){

            bool flag = next_permutation(a.begin(), a.end());

            con += check(a, b);

            if(flag ==  false) break;
        }

        cout<<((double)con/k)<<" "<<((double)(k-con)/k)<<endl;
    }

    return 0;
}




Measured memory_bytes: 3284
using System;

namespace AOJ.Volume1
{
    public class Lottery
    {
        public static int Main()
        {
            var prime = new bool[1000001];
            prime[0] = false;
            prime[1] = false;
            prime[2] = true;
            // 1000000??\???????´???°????±???????
            for(int i = 3; i <= 1000000; i++)
            {
                bool is_prime = true;
                for(int j = 2; j <= i; j++)
                {
                    if (prime[j])
                    {
                        if (i % j == 0)
                        {
                            is_prime = false;
                            break;
                        }

                        // i?????????????????§??????????????????
                        if (j * j >= i) { break; }
                    }
                }

                if (is_prime) { prime[i] = true; }
            }

            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }

                int answer = 0;
                for(int i = 0; i < n; i++)
                {
                    var input = Console.ReadLine().Split(' ');
                    int p = int.Parse(input[0]);
                    int m = int.Parse(input[1]);
                    // ??????????¨????
                    int prize = 0;
                    int from = p - m >= 0 ? p - m : 0;
                    int to = p + m <= 1000000 ? p + m : 1000000;
                    for(int t = from; t <= to; t++)
                    {
                        if (prime[t]) { prize++; }
                    }
                    // ?????????????????´??????1????????????????§??????????
                    // ?????????????????´??????????§????prize - 1??????????????????
                    if(prize == 0) { answer--; }
                    else { answer += prize - 1; }
                }

                Console.WriteLine(answer);
            }
            return 0;
        }
    }
}

Measured memory_bytes: 10700
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main(){
  ll A,B;
  cin>>A>>B;
  ll C;
  if(A>B)swap(A,B);
  if(A==1){
    if(B==2){
      C=3;
    }else{
      C=2;
    }
  }else if(A==2){
    C=1;
  }
  cout<<C<<endl;
      
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int sum=0,h,w,n,t,a;
	scanf("%d %d %d",&h,&w,&n);
	if(h>w)
	{
		t=w;
		w=h;
		h=t;
	}
	a=n%w;
	if(!a)
		printf("%d",n/w);
	else
	{
		printf("%d",n/w+1);
	}
 } 

Measured memory_bytes: 128
from collections import defaultdict


def factorization(n):
    global d, mod
    temp = n
    flag = True
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            flag = False
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            d[i] += cnt
            d[i] %= mod

    if temp!=1:
        flag = False
        d[temp] += 1
        d[temp] %= mod

    if flag:
        d[n] += 1
        d[n] %= mod

    return


d = defaultdict(int)
N = int(input())
mod = 10**9 + 7
for i in range(2, N+1):
    factorization(i)

ans = 1
for key, value in d.items():
    ans *= (value+1)
    ans %= mod

print(ans)


Measured memory_bytes: 39664
#include<bits/stdc++.h>
#define maxn 2030

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
char s[30];
bool f[30];
int n,k,j;

int main()
{
    scanf("%s",s);
    n=strlen(s);
    if (n<26){
        for (int i=0;i<n;i++) f[s[i]-'a']=true;
        while (f[j]) j++;
        printf("%s%c\n",s,'a'+j);
    }
    else {
        j=25;
        while (j>0&&s[j]<s[j-1]) j--;
        if (j==0) {printf("-1\n"); return 0;}
        j--;
        for (int i=0;i<j;i++) f[s[i]-'a']=true;
        for (int i=0;i<j;i++) printf("%c",s[i]);
        for (int i=s[j]-'a'+1;i<26;i++) if (!f[i]) {printf("%c\n",'a'+i);return 0;}
    }
    return 0;
}


Measured memory_bytes: 768
fun main(args: Array<String>) {
  val N = readLine()!!.toInt()
  val A = readLine()!!.split(" ").map(String::toInt).toMutableList()

  println(A.joinToString(" "))

  (1 until N).forEach { i ->
    val v = A[i]
    var j = i - 1
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j]
      j = j - 1
    }
    A[j+1] = v
    println(A.joinToString(" "))
  }
}


Measured memory_bytes: 33696
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	printf("%d",(48-n));
	return putchar(10),0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	string in;
	while(cin>>in,in!="#"){
		set<string>out;
		out.insert(in);
		for(char i='y';i>='a';i--){
			set<string>next;
			for(set<string>::iterator it=out.begin();it!=out.end();it++){
				bool h=true;
				rep(k,(*it).size())if((int)(*it)[k]==i){
					string tmp=(*it);
					tmp[k]++;
					next.insert(tmp);
				}else if((int)(*it)[k]==i+1){
					h=false;
					break;
				}
				if(h)next.insert(*it);	
			}
			out=next;
		}
		cout<<out.size()<<endl;
		if(out.size()<=10)for(set<string>::iterator it=out.begin();it!=out.end();it++)cout<<(*it)<<endl;
		else{
			vector<string>ans;
			for(set<string>::iterator it=out.begin();it!=out.end();it++)ans.pb(*it);
			rep(i,5)cout<<ans[i]<<endl;
			loop(i,ans.size()-5,ans.size())cout<<ans[i]<<endl;
		}
	}
}

Measured memory_bytes: 4324
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta (bas + (son-bas)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1e18
#define N 1000005
#define lim 10000
using namespace std;
 
typedef long long ll;

int n,v = 1;
string s;

int main()
{

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	
	cin >> n;
	cin >> s;
	if(n % 2 == 0)
		for (int i = 0; i < n / 2; ++i)
			if(s[i] != s[i+n/2])
				v = 0;
			
	if(n % 2 != 0 || v == 0)
		cout << "No";
	else
		cout << "Yes";

    return 0;
}


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

#define ll long long
#define vec vector<ll>
#define sortv(a); sort(a.begin(), a.end());
#define rev(a); reverse(a.begin(), a.end());
#define FOR(i,a,b) for (ll i = (ll)(a); i < (b); i++)
#define ROF(i,a,b) for (ll i = (ll)(b)-1; i >= (a); i--)
#define printarray(a) FOR(Q,0,(int)(a).size()) cout<<(a)[Q]<<" "; cout<<'\n';

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

/*****************************************************************************/
int h,w,mid;
int out = 6969;
bool good = false;
int grid[102][102];

void dfs(int i,int j,int flips) {
	if (good) return;
	if(flips>out) return;
	if (i+1<h) {
		if (grid[i+1][j]==1&&grid[i][j]==0) {
			dfs(i+1,j,flips+1);
		} else {
			dfs(i+1,j,flips);
		}
	}
	if (j+1<w) {
		if (grid[i][j+1]==1&&grid[i][j]==0) {
			dfs(i,j+1,flips+1);
		} else {
			dfs(i,j+1,flips);
		}
	}

	if (i==h-1&&j==w-1) {
		out=min(out,flips);
	}
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	// freopen("input.txt", "r", stdin);
	cin>>h>>w;
	FOR(i,0,h) {
		string s;cin>>s;
		FOR(j,0,w) {
			grid[i][j]=(s[j]!='.');
		}
	}
	// FOR(i,0,h)FOR(j,0,w)cout<<grid[i][j];
	// long lo = 0, hi = 102;
	// while (lo + 1 < hi) {
	// 	mid = lo + ((hi - lo) >> 1);
	// 	good = false;
	// 	dfs(0,0,grid[0][0]);
		
	// 	if (true) {
	// 		lo = mid;
	// 	} else {
	// 		hi = mid - 1;
	// 	}
	// }
	// dfs(0,0,grid[0][0]);

	int dp[h][w];
	dp[0][0]=grid[0][0];
	FOR(j,1,w) {
		dp[0][j]=dp[0][j-1]+(!grid[0][j-1]&&grid[0][j]);
	}
	FOR(i,1,h) {
		dp[i][0]=dp[i-1][0]+(!grid[i-1][0]&&grid[i][0]);
		FOR(j,1,w) {
			dp[i][j]=min(
				dp[i-1][j]+(!grid[i-1][j]&&grid[i][j]), 
				dp[i][j-1]+(!grid[i][j-1]&&grid[i][j]));
		}
	}

	// FOR(i,0,h) {
	// 	FOR(j,0,w) cout<<dp[i][j]<<" ";
	// 	cout<<'\n';
	// }

	cout<<dp[h-1][w-1];
}

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

 int main() {
   vector<ll>v(3);
   cin >> v[0] >> v[1] >> v[2];
   sort(v.begin(),v.end());
   (v[0]==v[1] && v[0]==5)?cout<<"YES\n":cout<<"NO\n";
 }

Measured memory_bytes: 3560
#include <iostream>
//#include <fstream>
#include <vector>

using namespace std;
typedef long long ll;

struct Rest {
    int id, point;
    string city;
    Rest(int id, string city, int point)
    : id(id), point(point), city(city){}
    bool operator< (const Rest& rest) const {
        if (rest.city == city) {
            return point > rest.point;
        } else {
            return city < rest.city;
        }
    }
};

int main() {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());
    
    int N;
    cin >> N;
    vector<Rest> rests;
    for (int i = 0; i < N; i++) {
        string S;
        int P;
        cin >> S >> P;
        rests.push_back(Rest(i + 1, S, P));
    }
    sort(rests.begin(), rests.end());
    for (Rest rest : rests) {
        cout << rest.id << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define P printf
#define S scanf
#define PII pair<int,int>
#define x first
#define y second
#define eb emplace_back
#define pb push_back
#define heap priority_queue
#define Q queue
#define V vector
#define T top
#define F front
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define PLL pair<ll,ll>
using namespace std;
const long long N=200005;
ll seg[4*N];
struct A{
    int p,ch,l,r;
    ll w;
    bool operator <(const A& o) const{
        return p<o.p;
    }
};
int idx=0;
A swp[2*N];
ll lazy[4*N];
void update(int l,int r,int now,int LL,int RR,ll val){
    if(lazy[now]){
        seg[now]+=lazy[now];
        if(l!=r){
            lazy[now<<1]+=lazy[now];
            lazy[(now<<1)+1]+=lazy[now];
        }
        lazy[now]=0;
    }
    if(l>RR || r<LL) return ;
    if(l>=LL && r<=RR){
        seg[now]+=val;
        if(l!=r){
            lazy[now<<1]+=val;
            lazy[(now<<1)+1]+=val;
        }
        return ;
    }
    int mid=(l+r)>>1,L=now<<1,R=L+1;
    update(l,mid,L,LL,RR,val); update(mid+1,r,R,LL,RR,val);
    seg[now]=max(seg[L],seg[R]);
}
ll query(int l,int r,int now,int LL,int RR){
    if(lazy[now]){
        seg[now]+=lazy[now];
        if(l!=r){
            lazy[now<<1]+=lazy[now];
            lazy[(now<<1)+1]+=lazy[now];
        }
        lazy[now]=0;
    }
    if(l>RR || r<LL) return -1e18;
    if(l>=LL && r<=RR) return seg[now];
    int mid=(l+r)>>1,L=now<<1,R=L+1;
    return max(query(l,mid,L,LL,RR),query(mid+1,r,R,LL,RR));
}
int main(){
    int n,m;
    S(" %d %d",&n,&m);
    FOR(i,0,m-1){
        int l,r;
        ll w;
        S(" %d %d %lld",&l,&r,&w);
        swp[2*i]={l,0,l,r,w};
        swp[2*i+1]={r+1,1,l,r,w};
    }
    lazy[1]=-1e14;
    sort(swp,swp+2*m);
    ll val=0,best=0;
    FOR(i,1,n){
        while(idx<2*m && swp[idx].p==i){
//            P("##%d %d %lld ",swp[idx].l,swp[idx].r,swp[idx].w);
            if(swp[idx].ch){
//                P("OUT\n");
                update(1,n,1,swp[idx].l,swp[idx].r,swp[idx].w);
                val-=swp[idx].w;
            }else{
//                P("IN\n");
                val+=swp[idx].w;
            }
            idx++;
        }
        ll dp=-1e14;
        if(i>1) dp=max(dp,max(val,val+query(1,n,1,1,i-1)));
        else dp=max(dp,val);
        best=max(dp,best);
//        P("==%lld %lld %lld\n",val,dp,query(1,n,1,1,i-1));
        update(1,n,1,i,i,1e14+dp-val);
    }
    P("%lld",best);
    return 0;
}


Measured memory_bytes: 20736
S = input()
flag = 0
for index, word in enumerate(S):
    if (word == 'U' or word == 'D') or (index%2 == 1 and word == 'L') or (index%2 == 0 and word == 'R'):
        pass
    else:
        flag = 1
        break;
print('Yes' if flag ==0 else 'No')

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>

int main() {
    int N;
    std::cin >> N;
    int dp[N][3],a[N],b[N],c[N];
    for(int i = 0; i < N; i++) {
        std::cin >> a[i] >> b[i] >> c[i];
    }
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for(int i = 1; i < N; i++) {
        dp[i][0] = std::max(dp[i-1][1] + a[i], dp[i-1][2] + a[i]);
        dp[i][1] = std::max(dp[i-1][0] + b[i], dp[i-1][2] + b[i]);
        dp[i][2] = std::max(dp[i-1][0] + c[i], dp[i-1][1] + c[i]); 
    }
    std::cout << std::max(std::max(dp[N-1][0], dp[N-1][1]), dp[N-1][2]) << std::endl;
}

Measured memory_bytes: 2560
N = int(input().strip())
A = list(map(int, input().strip().split()))
A.sort()
AMAX = max(A)
ans = 0
is_div = [True for i in range(AMAX+1)]
for i in range(N):
  a = A[i]
  if is_div[a]:
    if not ((i > 0 and A[i] == A[i-1]) or (i < N-1 and A[i] == A[i+1])):
      ans += 1
    for j in range(a, AMAX+1, a):
      is_div[j] = False
print(ans)

Measured memory_bytes: 32224
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
using namespace std;

int main() {
    string number;
    cin >> number;
    int bit = number.size() - 1;
    int num_plus  = pow(2, bit);
    long ans = 0;
    for (int i = 0; i < num_plus; ++i) {
        long element = number.at(0) - '0';
        for (int j = 0; j < bit; ++j) {
            if (i & (1 << j)) {
                ans += element;
                element = 0;
            }
            element = element * 10 + number.at((j+1)) - '0';
        }
        ans += element;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include<algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;

int n,q,type,one,two;

int par[10005],ran[10005];

void init(int x){
	for(int i=0;i<x;i++){
		par[i]=i;
		ran[i]=0;
	}
}

int find(int x){
	if(par[x]==x) return x;
	else return par[x]=find(par[x]);
}

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(ran[x]<ran[y]) par[x]=y;
	else{
		par[y]=x;
		if(ran[x]==ran[y]) ran[x]++;
	}
}

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

int main(){
	cin>>n>>q;
	init(n);
	for(int i=0;i<q;i++){
		cin>>type>>one>>two;
		if(type==0) unite(one,two);
		else{
			if(same(one,two)) cout<<'1'<<endl;
			else cout<<'0'<<endl;
		}
	}
}

Measured memory_bytes: 1228
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
 string s;
 cin>>s;
 if(s[0]!=s[1] && s[1]!=s[2] && s[2]!=s[0])
 cout <<"Yes"<<endl;
 else 
 cout<<"No"<<endl;
}


Measured memory_bytes: 256
// A Dynamic Programming based solution for 0-1 Knapsack problem 
#include<bits/stdc++.h> 
using namespace std;
// A utility function that returns maximum of two integers 
unsigned long long int max(unsigned long long int a,unsigned long long  int b) { return (a > b)? a : b; } 
vector<unsigned long long int> wt,val;
// Returns the maximum value that can be put in a knapsack of capacity W 
long long int knapSack(unsigned long long int W,unsigned long long int n) 
{ 
unsigned long long int i, w; 
unsigned long long int K[n+1][W+1]; 

// Build table K[][] in bottom up manner 
for (i = 0; i <= n; i++) 
{ 
    for (w = 0; w <= W; w++) 
    { 
        if (i==0 || w==0) 
            K[i][w] = 0; 
        else if (wt[i-1] <= w) 
                K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]); 
        else
                K[i][w] = K[i-1][w]; 
    } 
} 

return K[n][W]; 
} 

int main() 
{ 
    
    unsigned long long int n,w;
    cin>>n>>w;
    
    for(long long int i=0;i<n;i++)
    {
        unsigned long long int x,y;
        cin>>x>>y;
        wt.push_back(x);
        val.push_back(y);
    }

    cout<<knapSack(w,n); 
    return 0; 
} 


Measured memory_bytes: 79104