akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

def main():
    K = int(input())
    if K % 7 == 0:
        L = 9 * K / 7
    else:
        L = 9 * K
    if L % 2 == 0 or L % 5 == 0:
        ans = -1
    else:
        i = 1
        tmp = 10
        while True:
            tmp %= L
            if tmp == 1:
                ans = i
                break
            i += 1
            tmp *= 10

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9128
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <unordered_map>
#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

int main() {
    int n;
    int m;
    vector<int> p;
    vector<string> s;
    int tmp_p;
    string tmp_s;
    vector<bool> is_ac;
    vector<int> num_wa;
    int ans_ac=0;
    int ans_wa=0;
    cin >> n >> m;
    for(int i=0; i<m; i++){
        cin >> tmp_p >> tmp_s;
        tmp_p--;
        p.push_back(tmp_p);
        s.push_back(tmp_s);
    }
    for(int i=0; i<n; i++){
        is_ac.push_back(false);
        num_wa.push_back(0);
    }
    for(int i=0; i<m; i++){
        if(s[i]=="AC" && is_ac[p[i]]==false){
            is_ac[p[i]]=true;
            ans_ac++;
            ans_wa+=num_wa[p[i]];
        }
        if(s[i]=="WA" && is_ac[p[i]]==false){
            num_wa[p[i]]++;
        }
    }
    cout << ans_ac << " " << ans_wa << endl;

    return 0;
}

Measured memory_bytes: 7024
H, W = map(int, input().split())
A = []
mod = 10**9
mod += 7
# print(mod)
for h in range(H):
	A.append(list(input()))
dp = [[0 for w in range(W)] for h in range(H)]
dp[0][0] = 1
for i in range(H):
	for j in range(W):
		if A[i][j] != "#":
			if i > 0 and A[i-1][j] != '#':
				dp[i][j] = (dp[i][j]%mod + dp[i-1][j]%mod)%mod
			if j > 0 and A[i][j-1] != '#':
				dp[i][j] = (dp[i][j]%mod + dp[i][j-1]%mod)%mod
# print(dp)
print(dp[H-1][W-1])



Measured memory_bytes: 91100
#include <iostream>
using namespace std;
int main(void){
    int a,b,k,m=0;
    cin>>a>>b>>k;
    for(int i=min(a,b);i>=1;i--){
        if(a%i==0&&b%i==0){
            m++;
            if(m==k){
                cout<<i<<endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
ll fac[200007],finv[200007],inv[200007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<200007;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 com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cominit();
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            ans+=m*(n-i+1)*(n-i)/2;
            ans+=n*(m-j+1)*(m-j)/2;
            ans%=mod;
        }
    }
    cout << (ans*com(n*m-2,k-2))%mod<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000000;
const ll LINF=4000000000000000010;
ll dp[200010],x[200010];
struct Segtree{
	int n;
	vector<ll> node;
    Segtree(int n_){
		n=1;
		while(n<n_)n*=2;
		node.resize(2*n,LINF);
    }
	void update(int k,ll x){
		k+=n-1;
		node[k]=x;
		while(k>0){
			k=(k-1)/2;
			node[k]=min(node[2*k+1],node[2*k+2]);
		}
	}
    ll getmin(int a,int b,int k=0,int l=0,int r=-1){
		if(r<0)r=n;
		if(r<=a||b<=l)return LINF;
		if(a<=l&&r<=b)return node[k];
		ll vl=getmin(a,b,2*k+1,l,(l+r)/2);
		ll vr=getmin(a,b,2*k+2,(l+r)/2,r);
		return min(vl,vr);
    }
};
int main(){
    int n,q,a,b;cin>>n>>q>>a>>b;
	for(int i=1;i<=q;i++)cin>>x[i];
	x[0]=a;
	fill(dp,dp+q+2,LINF);
    Segtree tree1(2*n);
	Segtree tree2(2*n);
	tree1.update(b,-b);
	tree2.update(b,b);
	ll sum=0;
	for(int i=0;i<q;i++){
        dp[i]=min(tree1.getmin(0,x[i+1]+1)+x[i+1],tree2.getmin(x[i+1],n+1)-x[i+1]);
        tree1.update(x[i],dp[i]-x[i]-abs(x[i+1]-x[i]));
        tree2.update(x[i],dp[i]+x[i]-abs(x[i+1]-x[i]));
		sum+=abs(x[i+1]-x[i]);
	}
	ll ans=LINF;
	for(ll i=0;i<=n;i++){
		ans=min(ans,tree2.getmin(i,i+1)-i);
	}
	cout<<ans+sum<<endl;
}	


Measured memory_bytes: 19712
def knapsack(items, budget)
	table = (0..1).map{ Array.new(budget+1, 0) }
	for i in 0..items.size-1
		bits, v = items[i]
		for j in bits..budget
			x = table[0][j]
			y = (j & bits == bits ? table[0][j-bits] + v : 0)
			table[1][j] = x > y ? x : y
		end
		table << table.shift
	end
	table[0][-1]
end

loop {
	n = gets.to_i
	break if n == 0
	guys = (1..n).map{
		k, value = gets.split.map &:to_i
		bits = 0
		k.times {
			s, t = gets.split.map &:to_i
			(s-6..t-7).each{|i|
				bits |= (1 << i)
			}
		}
		[bits, value]
	}
	guys.sort!.reverse!
	p knapsack(guys, (1<<16)-1)
}

Measured memory_bytes: 14292
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	char c;
	cin >> c;
	cout << ++c << endl;

	return 0;
}


Measured memory_bytes: 2912
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final int a = in.nextInt();
        final int b = in.nextInt();
        final int c = in.nextInt();
        final int d = in.nextInt();

        final String input = in.next();
        if (input.indexOf("##", a) < c && input.indexOf("##", a) > -1) {
            System.out.println("No");
            return;
        }
        if (input.indexOf("##", b) < d && input.indexOf("##", b) > -1) {
            System.out.println("No");
            return;
        }

        if (c < b) {
            System.out.println("Yes");
            return;
        }
        if (d > c) {
            System.out.println("Yes");
            return;
        }

        final char[] line = input.toCharArray();

        if (line[d - 2] == '.') {
            if (c == d + 1) {
                System.out.println("Yes");
                return;
            }
            if (line[d] == '.') {
                System.out.println("Yes");
                return;
            }
        }
        if (line[b] == '.') {
            if (a == b - 1 || line[b - 2] == '.') {
                System.out.println("Yes");
                return;
            }
        }
        if (input.indexOf("...", b - 1) != -1 && input.indexOf("...", b - 1) < d - 1) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 28476
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
    int N,T,S,A,B,dp[3001];
    for(int i=0;i<=3000;i++) dp[i]=0;

    cin>>N>>T>>S;
    for(int i=0;i<N;i++){
        cin>>A>>B;

        for(int j=T;j>=0;j--){
            if(dp[j]==-1 || (j<S && j+B>S) || j+B>T) continue;
            dp[j+B] = max(dp[j+B],dp[j]+A);
        }//puts("");
    }

    int ans=0;
    for(int i=T;i>=0;i--){
        ans=max(ans,dp[i]);
    }
    printf("%d\n",ans);
}

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

// セグメントツリー
template<class Monoid> struct SegTree {
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func F;
    const Monoid UNITY;
    int SIZE_R;
    vector<Monoid> dat;

    SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
    void init(int n) {
        SIZE_R = 1;
        while (SIZE_R < n) SIZE_R *= 2;
        dat.assign(SIZE_R * 2, UNITY);
    }

    /* set, a is 0-indexed */
    void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
    void build() {
        for (int k = SIZE_R - 1; k > 0; --k)
            dat[k] = F(dat[k*2], dat[k*2+1]);
    }

    /* update a, a is 0-indexed */
    void update(int a, const Monoid &v) {
        int k = a + SIZE_R;
        dat[k] = v;
        while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]);
    }

    /* get [a, b), a and b are 0-indexed */
    Monoid get(int a, int b) {
        Monoid vleft = UNITY, vright = UNITY;
        for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
            if (left & 1) vleft = F(vleft, dat[left++]);
            if (right & 1) vright = F(dat[--right], vright);
        }
        return F(vleft, vright);
    }
    inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }

    /* debug */
    void print() {
        for (int i = 0; i < SIZE_R; ++i) {
            cout << (*this)[i];
            if (i != SIZE_R-1) cout << ",";
        }
        cout << endl;
    }
};

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    
    long long n,k;
    cin>>n>>k;
    long long a[n];
    long long b[n+1]={};
    map<long long,int> mp;
    mp[0]=1;
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]-=k;
        b[i+1]=b[i]+a[i];
        mp[b[i+1]]=1;
    }
    int c=0;
    for(auto i:mp){
        mp[i.first]=c;
        c++;
    }
    
    SegTree<long long> seg(n+1, [](long long a, long long b) {
        return a+b ;
    },
    0);

    for (int i = 1; i <= n; ++i) {
        seg.update(mp[b[i]],seg.get(mp[b[i]],mp[b[i]]+1)+1);
    }
    seg.update(mp[0],seg.get(mp[0],mp[0]+1)+1);

    long long ans=0;
    //seg.print();
    for(int i=n;i>=1;i--){
        seg.update(mp[b[i]],seg.get(mp[b[i]],mp[b[i]]+1)-1);
        ans+=seg.get(0,mp[b[i]]+1);
        //seg.print();
    }
    cout<<ans<<endl;
    //seg.print();
    
    
}

Measured memory_bytes: 19968
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		System.out.println(Gcd(in.nextInt(), in.nextInt()));
	}
	public static int Gcd(int x,int y )
	{
		if(y == 0)
		{
			return x;
		}else if(x == 0)
		{
			return y;
		}else
		{
			if(x > y)
			{
				return Gcd(x % y, y);
			}else
			{
				return Gcd(x, y % x);
			}
		}
	}
}



Measured memory_bytes: 26368
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

ll dp[2010][2010];

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

    ll N, M, L;
    cin >> N >> M >> L;
    vector<ll> K(N), S(M + 1), sum(M + 1, 0);
    for (int i = 0; i < N; i++)
        cin >> K[i];
    for (int i = 1; i <= M; i++)
    {
        cin >> S[i];
        sum[i] = sum[i - 1] + S[i];
    }
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            dp[i][j] = 1e15;
    dp[0][0] = 0;
    sort(K.begin(), K.end());
    for (int i = 0; i < N - 1; i++)
    {
        for (int j = 0; j < N - 1; j++)
        {
            int next = max(i, j) + 1;
            ll lcost = (sum[K[next]] - sum[K[i] - 1]) / L;
            ll rcost = (sum[K[next]] - sum[K[j] - 1]) / L;
            dp[next][j] = min(dp[next][j], dp[i][j] + lcost);
            dp[i][next] = min(dp[i][next], dp[i][j] + rcost);
        }
    }
    ll ret = 1e15;
    for (int i = 0; i < N - 2; i++)
    {
        ll cost = (sum[K[N - 1]] - sum[K[i] - 1]) / L + (sum[K[N - 1]] - sum[K[N - 2] - 1]) / L;
        ret = min(ret, dp[i][N - 2] + cost);
        ret = min(ret, dp[N - 2][i] + cost);
    }
    cout << ret << endl;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  int t = 0;
  vector<int> vec(N);
  for(int i = 0;i < N;++i) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for(int i = 0;i < M;++i) {
    t = t + vec.at(i); 
  }
  cout << t << endl;
}

Measured memory_bytes: 3628
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    A, B = LI()

    ans = (B - 2) // (A - 1) + 1
    print(ans)

if __name__ == '__main__':
    resolve()


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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


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

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

    sort(a.begin(), a.end(), greater<int>());

    int ans = 0;
    for(int i = 0; i < N; i++){
        if(i%2==0){
            ans += a[i];
        }else{
            ans -=a[i];
        }
    }

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



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

#define FOR(a,b,c) for (int a=(b);a<(c);++a)
#define REP(i,n) FOR(i,0,n)
#define ll long long
#define pii pair<int,int>
#define x first
#define y second
#define pb push_back
#define lf double
#define prev asdfasdfasdfsa
#define size afdsfsf

using namespace std;

const int MAX = (int)5e5 + 5;

int n;
int col[MAX];
vector<int> prev[MAX];
vector<int> acol[MAX];
int size[MAX];

vector<int> e[MAX];
vector<int> q[MAX];

int ima[MAX];

int tot;

ll res;

void dfs2(int cx,int par){
	for (auto nx:e[cx]){
		if (nx==par) continue;
		dfs2(nx,cx);
	}
	if (cx<n){
		for (auto nx:q[cx]){
			int gore=tot-nx;
			res+=(ll)nx*gore;
			tot-=nx;
		}
		res+=tot;
		tot--;
//		res+=(ll)dsize*gsize;
	}
}

void sol(int ccol){
	tot=n;
	res=0;
	dfs2(n+ccol,-1);
	
	printf ("%lld\n",res);
}

vector<int> v[MAX];

void dfs0(int cx,int par){
	int ccol=col[cx];
	size[cx]=1;
	int npar=n*2+1;
	if (!prev[ccol].empty()){
		npar=prev[ccol].back();
		e[npar].pb(cx);
		e[cx].pb(npar);
	}
	prev[ccol].pb(cx);
	for (auto nx:v[cx]){
		if (nx==par) continue;
		ima[cx]=0;
		dfs0(nx,cx);
		size[cx]+=size[nx];
		q[cx].pb(size[nx]-ima[cx]);
		ima[cx]=0;
	}
	prev[ccol].pop_back();
	ima[npar]+=size[cx];
}

int main(){
	scanf ("%d",&n);
	REP(i,n) scanf ("%d",col+i);
	REP(i,n) col[i]--;
	REP(i,n) acol[col[i]].pb(i);
	REP(i,n) prev[i].pb(n+i);
	REP(i,n-1){
		int a,b;
		scanf ("%d%d",&a,&b);
		a--;b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	dfs0(0,-1);
	REP(i,n) sol(i);
	return 0;
}


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

void cmpswap( int * x, int * y) {
  if ( *x <= *y ) return;

  int tmp = *x;
  *x = *y;
  *y = tmp;

  return;
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  cmpswap(&a, &b);
  cmpswap(&a, &c);
  cmpswap(&b, &c);

  cout << a << " " << b << " " << c << endl;

  return 0;
}


Measured memory_bytes: 3060
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

int main(){	
	ll N, M;
	cin >> N >> M;
	vector<ll> A(N), B(N);
	map<ll,ll> m;
	priority_queue<P> que;
	rep(i,N) {
		cin >> A[i] >> B[i];
	}
	ll r[M];
	rep(i,M) {
		r[i] = 0;
	}
	rep(i,N) {
		que.push(P(-A[i],B[i]));
	}
	ll res = 0, cnt = 0;
	priority_queue<ll> que2;
	while (cnt < M) {
		if (!que.empty() && cnt >= -que.top().first-1) {
			que2.push(que.top().second);
			que.pop();
		} else {
			// cout << cnt << " " << -que.top().first << " " << que.top().second << endl;
			if (!que2.empty()) {
				// cout << cnt << " " << que2.top() << endl;
				r[cnt] = que2.top();
				que2.pop();
			}
			++cnt;
		}
	}
	// rep(i,M) cout << r[i] << endl;
	rep(i,M) res += r[i];
	cout << res << endl;
	return 0;
}


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

int main()
{
	vector<int> e(12);
	bool disable = false;
	for (int i = 0; i < 12; i++)
		cin >> e[i];

	int def = e[0];
	int fndcnt = 0;
	int i = 1;
	while (1) {
		if (def == e[i]) {
			fndcnt++;
			e.erase(e.begin() + i);
			i--;
		}
		if (fndcnt == 3) {
			e.erase(e.begin());
			if (e.empty())
				break;
			else
				def = e[0];
			i = 0;
			fndcnt = 0;
		}
		else if (fndcnt > 3 || i == e.size()-1) {
			disable = true;
			break;
		}
		i++;
	}
	if (disable)
		cout << "no" << endl;
	else
		cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 3164
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin >> a >> b;
    if(a*b%2==0){
        cout << "No";
    }
    else{
        cout << "Yes";
    }

    

    return 0;
}

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

int main(){
  int n;
  cin>>n;
  
  vector<pair<int,int>> p;
  set<pair<int,int>> s;
  
  if(n%2==0){
    for(int i=1;i<=n/2;i++){
      p.push_back({i,n+1-i});
    }
  }else{
    for(int i=1;i<=n/2;i++){
      p.push_back({i,n-i});
    }
  }
  
  for(int i=0;i<p.size();i++){
    for(int j=i+1;j<p.size();j++){
      s.insert({p[i].first,p[j].first});
      s.insert({p[i].first,p[j].second});
      s.insert({p[i].second,p[j].first});
      s.insert({p[i].second,p[j].second});
    }
  }
  
  if(n%2==1){
    for(int i=0;i<p.size();i++){
      s.insert({p[i].first,n});
      s.insert({p[i].second,n});
    }
  }
  
  cout << s.size() << endl;
  
  for(auto t:s){
    cout << t.first << " " << t.second << endl;
  }
  
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;

string name[55];
int v[55];

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

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

	string s;
	cin >> s;

	int sum = 0;

	bool flag = 0;
	for(int i = 0; i < n; i++) {
		if(s == name[i]) flag = true;
		else if(flag) sum += v[i];
	}

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

	return 0;
}

Measured memory_bytes: 764
S = list(input())
numList = [0] * (len(S) + 1)
for i in range(len(S)):
    if S[i] == '<':
        numList[i + 1] = numList[i] + 1

for i in range(len(S) - 1 , -1 , -1):
    if S[i] == '>':
        numList[i] = max(numList[i + 1] + 1 ,numList[i])
print(sum(numList))

Measured memory_bytes: 27056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=2e5+5;
const int INF=1e9+7;

int main()
{
    int t1,t2,t3,f=0;

    scanf("%d/%d/%d",&t1,&t2,&t3);
    if (t1<2019)
    {
        f=1;
    }
    else if (t1==2019)
    {
        if (t2<4)
        f=1;
        else if (t2==4)
        {
            if (t3<=30) f=1;
        }
    }

    if (f) printf("Heisei\n");
    else printf("TBD\n");



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  int n;
  const string x = "abcdefghijklmnopqrstuvwxyz";
  char s;
  cin >> s;
  rep(i,26){
    if(x[i]==s){
      cout << 'a';
      return 0;
    }
  }
  cout <<'A';
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    int count = 0;
    int J = min(A, B);
    vector<ll> P;
    for (int i = 1; i <= J; i++)
    {
        if(A%i == 0 && B%i == 0){
            P.push_back(i);
        }
    }
    reverse(P.begin(), P.end());
    cout << P[K-1] << endl;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        d: [usize; k],
    }

    let mut v = vec![false; 10];

    for nd in &d {
        v[*nd] = true;
    }

    'outer: for i in n..100000 {
        let stri = i.to_string();
        for j in stri.chars() {
            if v[(j as u8 - '0' as u8) as usize] {
                continue 'outer;
            }
        }
        println!("{}", i);
        break;
    }
}


Measured memory_bytes: 2180
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var a, b, n int
	fmt.Fscan(r, &a)
	fmt.Fscan(r, &b)
	fmt.Fscan(r, &n)

	if n < b {
		fmt.Println(a*n/b - a*(n/b))
		return
	}

	ans := a*n/b - a*(n/b)

	tmpN := b*(n/b) - 1
	ans = max(ans, a*tmpN/b-a*(tmpN/b))

	fmt.Println(ans)
}

// Union-Find
type unionFind struct {
	d []int
}

func newUnionFind(n int) *unionFind {
	uf := new(unionFind)
	uf.d = make([]int, n)
	for i := 0; i < n; i++ {
		uf.d[i] = -1
	}
	return uf
}

func (uf *unionFind) find(x int) int {
	if uf.d[x] < 0 {
		return x
	}
	uf.d[x] = uf.find(uf.d[x])
	return uf.d[x]
}

func (uf *unionFind) unite(x, y int) bool {
	rootX := uf.find(x)
	rootY := uf.find(y)
	if rootX == rootY {
		return false
	}

	if uf.d[rootX] < uf.d[rootY] {
		uf.d[rootX] += uf.d[rootY]
		uf.d[rootY] = rootX
	} else {
		uf.d[rootY] += uf.d[rootX]
		uf.d[rootX] = rootY
	}

	return true
}

func (uf *unionFind) same(x, y int) bool {
	return uf.find(x) == uf.find(y)
}

func (uf *unionFind) size(x int) int {
	return -uf.d[uf.find(x)]
}

// mod combination
func modpow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n = n / 2
	}
	return res
}

func modcomb(n, a, mod int) int {
	x := 1
	y := 1
	for i := 0; i < a; i++ {
		x = x * (n - i)
		x %= mod
		y = y * (i + 1)
		y %= mod
	}
	return x * modpow(y, mod-2, mod) % mod
}

func modfactorial(n, mod int) int {
	result := 1
	for i := 1; i <= n; i++ {
		result = (result * i) % mod
	}
	return result
}

// Utility

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func primeFactor(x int) map[int]int {
	res := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			res[i]++
			x = x / i
		}
	}
	if x != 1 {
		res[x] = 1
	}
	return res
}

func divisor(x int) []int {
	res := make([]int, 0)
	for i := 1; i*i <= x; i++ {
		if x%i == 0 {
			res = append(res, i)
			if i != x/i {
				res = append(res, x/i)
			}
		}
	}
	return res
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func reverseString(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

// Queue ...
type Queue []int

// pop ...
func (q *Queue) empty() bool {
	return len(*q) == 0
}

// push ...
func (q *Queue) push(i int) {
	*q = append(*q, i)
}

// pop ...
func (q *Queue) pop() (int, bool) {
	if q.empty() {
		return 0, false
	} else {
		res := (*q)[0]
		*q = (*q)[1:]
		return res, true
	}
}

// Stack ...
type Stack []int

// pop ...
func (s *Stack) empty() bool {
	return len(*s) == 0
}

// push ...
func (s *Stack) push(i int) {
	*s = append(*s, i)
}

// pop ...
func (s *Stack) pop() (int, bool) {
	if s.empty() {
		return 0, false
	} else {
		index := len(*s) - 1
		res := (*s)[index]
		*s = (*s)[:index]
		return res, true
	}
}


Measured memory_bytes: 1828
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
using namespace std;
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define N 1000005
int main()
{
	string s;
	cin>>s;
	lld k=sz(s);
	repd(i,k-1,2) {
		if(i%2) continue;
		string a1 = s.substr(0,(i/2));
		string a2 = s.substr((i/2),(i/2));
		if(a1==a2) {
			return 0*print(i);
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		double ans = 0.0;
		for (int i = 1; i <= N; i++) {
			double tmp = 1.0/N;
			int now = i;
			while (now < K) {
				now *= 2;
				tmp /= 2;
			}
			ans += tmp;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22996
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL m;
    cin >> m;
    LL ans=24*2-m;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#include<map>
#include<string>
using namespace std;

void a(){
    int S,W;
    cin >> S >> W;
    if(W<S){
        cout << "safe"; 
    }
    else{
        cout << "unsafe";
    }
}

void b(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int T = a/d;
    if (a%d!=0)T++;
    int A = c/b;
    if (c%b!=0)A++;
    if(A>T)
    {
        cout << "No";
    }
    else cout << "Yes";
}

void c(){
    int N;
    cin >> N;
    map<string,int> c;
    for (int i=0;i<N;i++)
    {
        string si;
        cin >> si;
        c[si] = 1;
    }    
    cout << c.size();
    return;

}
int main(void){
    //a();
    //b();
    c();

}

Measured memory_bytes: 19228
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
long long  a[100001];
int main()
{
   int n;
   cin>>n;
   for(int i=0;i<n;i++)
    cin>>a[i];
   sort(a,a+n);

   long long  x=0,y=0;
   for(int i=n-1;i>=0;i--)
   {
      if(a[i]==a[i-1])
      {
          x=a[i];
          a[i]=0;
          a[i-1]=0;
          break;
      }
   }
   for(int i=n-1;i>=0;i--)
   {
      if(a[i]==a[i-1]&&a[i]!=0&&a[i-1]!=0)
      {
          y=a[i];
          break;
      }
   }
   if(x==0||y==0) cout<<'0'<<endl;
   else cout<<x*y<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	std::ios_base::sync_with_stdio(false);
	ll n;int k;
	cin>>n>>k;
	int h[n+1];
	for (int i = 1; i <= n; ++i)	cin>>h[i];
	int c[n+1];
	c[1]=0;
	c[2]=abs(h[2]-h[1]);
	int temp;
	for (int i = 3; i <= n; ++i)
	{	c[i]=INT_MAX;
		int j=1;
		//cout<<" i "<<i<<" j "<<endl;
		while(j<=k && (i-j)>=1){
			//cout<<j<<" ";
			temp=(abs(h[i]-h[i-j])+c[i-j]);
			if(temp<c[i]) c[i]=temp;
			j++;
		}
	}
	cout<<c[n];
	

	return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  
  vector<int> num(n, 0);
  for (int i=1 ; i<n ; i++){
    vector<char> left(i);
    vector<char> right(n-i);
    for (int j=0 ; j<i ; j++){
      left.at(j) = s.at(j);
    }
    for (int j=0 ; j<n-i ; j++){
      right.at(j) = s.at(j+i);
    }
    sort(left.begin(), left.end());
    sort(right.begin(), right.end());
    left.erase(unique(left.begin(), left.end()), left.end());
    right.erase(unique(right.begin(), right.end()), right.end());
    
    for (int j=0 ; j<left.size() ; j++){
      for (int k=0 ; k<right.size() ; k++){
        if (left.at(j) == right.at(k)){
          num.at(i)++;
          break;
        }
      }
    }
  }
  
  sort(num.begin(), num.end());
  
  cout << num.at(n-1) << endl;
}

Measured memory_bytes: 3612
# D - XOR World
# https://atcoder.jp/contests/abc121/tasks/abc121_d


def xor_from0(n):
    if n % 4 == 0:
        return n
    elif n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return n+1
    else: # n % 4 == 3
        return 0

A, B = map(int, raw_input().split())
print '{}'.format(xor_from0(A-1) ^ xor_from0(B))


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

int main(int argc, char *argv[]){
        char str[4];
        fgets(str, 4, stdin);
        int f = 0;
        for(int i=0;i < 3; i++){
                if(str[i] == '7'){
                        f = 1;
                }
        }
        if(f == 1){
                printf("Yes\n");
        }else{
                printf("No\n");
        }
        return 0;
}

Measured memory_bytes: 1516
#include <bits/stdc++.h>
using namespace std;
bool clett(string S){
  int N = S.size();
  for(int i=0; i<N/2 ;i++ ){
    if(S.at(i) != S.at(N-i-1))
      return false;
  }
  return true;
} 

int main() {
  string S,buf;
  cin >> S;
  int N = S.size();
  int a = (N-1)/2 , b = (N+3)/2;
  if(!clett(S)) {cout <<  "No" << endl; return 0;}
  for(int i=0; i<a; i++){
    buf += S.at(i);
  }
  if(!clett(buf)) {cout <<  "No" << endl; return 0;}
  for(int i=b-1; i<N; i++){
    buf += S.at(i);
  }
  if(!clett(buf)) {cout <<  "No" << endl; return 0;}
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
package main

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

func solve(sc *scanner, wr *bufio.Writer) {
	n := sc.getInt()
	a, b := sc.getInt(), sc.getInt()
	m := modulus(int(1e9) + 7)

	ans := m.sum(m.pow(2, n), -1)
	ans = m.sum(ans, -f(n, a, m))
	ans = m.sum(ans, -f(n, b, m))
	fmt.Fprintln(wr, ans)
}

func f(n, k int, m modulus) int {
	ret := 1
	for i := n; i > n-k; i-- {
		ret = m.mul(ret, i)
	}
	for i := k; i > 0; i-- {
		ret = m.div(ret, i)
	}
	return ret
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// modulo --------------------------
type modulus int

func (m modulus) mod(a int) int {
	mi := int(m)
	ret := a % mi
	if ret < 0 {
		ret += mi
	}
	return ret
}
func (m modulus) sum(s ...int) int {
	ret := 0
	for _, n := range s {
		ret = m.mod(ret + n)
	}
	return ret
}
func (m modulus) mul(s ...int) int {
	ret := 1
	for _, n := range s {
		ret = m.mod(ret * n)
	}
	return ret
}
func (m modulus) div(a, b int) int {
	return m.mul(a, m.inv(b))
}
func (m modulus) pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = m.mul(ret, a)
		}
		a = m.mul(a, a)
		b >>= 1
	}
	return ret
}
func (m modulus) inv(a int) int {
	return m.pow(a, int(m)-2)
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


Measured memory_bytes: 1804
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define F first
#define S second
constexpr auto INF = 1000000000;
constexpr auto LLINF = 9223372036854775807;
constexpr auto mod = 1000000007;
int main() {

	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; i++)cin >> h[i];

	int dp[1000000];
	FOR(i, k)dp[i] = abs(h[0] - h[i]);

	for (int i = k; i < n; i++) {
		int m = INF;
		for (int j = i - k; j < i; j++)m = min(m, dp[j] + abs(h[j] - h[i]));
		dp[i] = m;
	}

	cout << dp[n - 1] << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long mp[10000005];
int main()
{
	long long n,p,ans=1;
	cin>>n>>p;
	if(n==1) {cout<<p;return 0;}
	memset(mp,0,sizeof(mp));
	for(long long i=2;i*i<=p;i++)
	while(p%i==0)
	{
		mp[i]++;
		p/=i;
		if(mp[i]>=n)
		{
			ans*=i;
			mp[i]-=n;
		}
	}
	//if(p+mp[p]>=n) ans*=p;
	cout<<ans;
}

Measured memory_bytes: 78336
/*
https://atcoder.jp/contests/dp/tasks/dp_a
*/

#include <iostream>

using namespace std;

int dp[100000];

int h_diff(int*arr, int N){
	if( N == 0 ) {
		dp[N]=0;
		return dp[N];
	}

	if( N == 1 )  {
		dp[N] = abs(arr[N]-arr[N-1]);
		return dp[N];
	}

	if(dp[N-1] == -1)
		dp[N-1] = h_diff(arr,N-1);
	if(dp[N-2] == -1)
		dp[N-2] = h_diff(arr,N-2);

	dp[N] = min(abs(arr[N] - arr[N-1]) + dp[N-1],abs(arr[N] - arr[N-2])+ dp[N-2]);
	
	return dp[N];

}


int main(){

	int N;
	cin >> N;
	int arr[N];

	for(int i=0;i<N;i++){
		cin >> arr[i];
		dp[i] = -1;
	}
	
	
	cout << h_diff(arr,N-1)<< endl;


	return 0;
}

Measured memory_bytes: 9032
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <string>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define eb emplace_back
#define in insert
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define OUT(a, e) FOR(i, e, 0) cout << a[i] << ' '
#define OUTV(a) for(auto e : a) cout << e << ' ';
#define maxim(a, n, mx) FOR(i, n, x)mx = max(mx, a[i]);

using namespace std;


int main(){
    fast;
    int a, b, c, d; cin >> a >> b >> c >> d;
    if(d == 1)cout << 1;
    else cout << 0;
    return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	S := ReadString()
	r := 0
	for i := 0; i < 3; i++ {
		if S[i] == 'R' {
			r++
		}
	}
	if r == 3 {
		fmt.Println(3)
		return
	}
	if r == 2 {
		if S[1] == 'S' {
			fmt.Println(1)
			return
		} else {
			fmt.Println(2)
			return
		}
	}
	fmt.Println(r)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<string>;
using P =pair<int,int>;
const ll mod=1000000007;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=pow(n/k,3);
    if(k%2==0)ans+=pow((n+k/2)/k,3);
    cout<<ans<<endl;
}


Measured memory_bytes: 3972
using System;
using System.Collections.Generic;

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();

            int count = 0;
            for (int i = 0; i < S.Length; i++)
                if (S[i] != T[i]) count++;

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27456
N, M = map(int, input().split())
X = list(map(int, input().split()))

if N >= M:
  print(0)
else:
  X.sort()

  diffs = [0]*(M-1)

  for i in range(M-1):
    diffs[i] = abs(X[i+1] - X[i])

  diffs.sort(key= lambda x: -x)

  print(sum(diffs[N-1:]))

Measured memory_bytes: 13968
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node * treeMinimum(Node *x) {
	while( x->left != NIL) x = x->left;
	return x;
}

Node * find(Node *u, int k) {
	while( u != NIL && k != u->key ) {
		if (k < u->key ) u = u->left;
		else u = u->right;
	}
	return u;
}

Node * treeSuccessor (Node *x) {
	if ( x->right != NIL ) return treeMinimum(x->right);
	Node *y = x->parent;
	while( y != NIL && x == y->right ) {
		x = y;
		y = y->parent;
	}
	return y;
}

void treeDelete(Node *z) {
	Node *y;
	Node *x;

	if ( z->left == NIL || z->right == NIL ) y = z;
	else y = treeSuccessor(z);
	if ( y->left != NIL ) {
		x = y->left;
	} else {
		x = y->right;
	}

	if ( x != NIL ) {
		x->parent = y->parent;
	}

	if ( y->parent == NIL ) {
		root = x;
	} else {
		if ( y == y->parent->left) {
			y->parent->left = x;
		} else {
			y->parent->right = x;
		}
	}

	if ( y != z) {
		z->key = y->key;
	}

	free(y);
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while(x != NIL){
		y = x;
		if(z->key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;
	if(y == NIL)
		root = z;
	else{
		if(z->key < y->key){
		y->left = z;
	}
	else
		y->right = z;
	}
}

void inorder (Node *u) {
	if(u == NIL)
		return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder (Node *u) {
	if(u == NIL)
		return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main() {
	int n, i, x;
	string com;

	scanf("%d", &n);

	for (i = 0; i<n; i++ ) {
		cin >> com;
		if ( com[0] == 'f' ) {
			scanf("%d", &x);
			Node *t = find(root, x);
			if ( t != NIL ) printf("yes\n");
			else printf("no\n");
		} else if ( com == "insert" ) {
			scanf("%d", &x);
			insert(x);
		} else if ( com == "print" ) {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		} else if ( com == "delete") {
			scanf("%d", &x);
			treeDelete(find(root, x));
		}
	}

	return 0;
}


Measured memory_bytes: 22020
import collections, itertools

h, w = map(int, input().split())
ch, cw = tuple(int(s) - 1 for s in input().split())
dh, dw = tuple(int(s) - 1 for s in input().split())
s = [input() for _ in range(h)]

q = collections.deque()
q.append((ch, cw, 0))
score = [[float('inf')] * w for _ in range(h)]
score[ch][cw] = 0
while q:
    x, y, p = q.popleft()

    for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):
        nx, ny = x + dx, y + dy
        if 0 <= nx < h and 0 <= ny < w and s[nx][ny] == '.' and p < score[nx][ny]:
            score[nx][ny] = p
            q.appendleft((nx, ny, p))
    
    for dx, dy in itertools.product(range(-2, 3), repeat=2):
        nx, ny = x + dx, y + dy
        if 0 <= nx < h and 0 <= ny < w and s[nx][ny] == '.' and p + 1 < score[nx][ny]:
            score[nx][ny] = p + 1
            q.append((nx, ny, p + 1))

if score[dh][dw] == float('inf'):
    print(-1)
else:
    print(score[dh][dw])

Measured memory_bytes: 138140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int  main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b==c||a+c==b||b+c==a){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<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>;

const ll MOD = 1e9 + 7;

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> c(n, 0);
  rep(i, n) ++c[a[i]];

  bool exist = true;

  if (n % 2 == 0) {
    for (int i = 1; i < n; i += 2) {
      if (c[i] != 2) exist = false;
    }
  } else {
    if (c[0] != 1) exist = false;
    for (int i = 2; i < n; i += 2) {
      if (c[i] != 2) exist = false;
    }
  }

  if (exist) {
    ll ans = modpow(2, n / 2);
    printf("%lld\n", ans);
  } else {
    printf("0\n");
  }
  return 0;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int vis[3];

int main()
{
	int n;
	cin >> n;
	long long sum = 1;
	for(int i = 1; i <= n; i++){
		int t;
		cin >> t;
		int k = 0;
		for(int i = 0; i < 3; i++){
			if(vis[i] == t)
				k++;
		}
		for(int i = 0; i < 3; i++){
			if(vis[i] == t){
				vis[i]++;
				break;
			}	
		}
		sum = (sum * k) % mod;
	}
	cout << sum << endl;
	return 0;
} 

Measured memory_bytes: 256
qu, sub = gets.split(" ").map(&:to_i)
ar = []
sub.times do
  ques, ans = gets.split(" ")
  ar << [ques.to_i, ans]
end

ac = Array.new(100000, false)
wa = Array.new(100000, 0)



ar.each_with_index do |item, i|

  next if ac[item[0]] == true

  if item[1] == "AC"
    ac[item[0]] = true
  else item[1] == "WA"
    wa[item[0]] += 1
  end
end

ac_count = ac.select { |bool| bool }.size
wa_count = wa.select.with_index { |num, i| num if ac[i] != false }.inject(:+)

puts "#{ac_count} #{wa_count.nil? ? 0 : wa_count}"


Measured memory_bytes: 18044
#include <stdio.h>

int main() {
  int a;
  scanf("%d", &a);
  long long int arr[a], max = 1e18, prod = 1, fl = 0, zero = 0;
  
  for(int i = 0; i < a; i++) {
    scanf("%lld", &arr[i]);
    fl = (arr[i] > max) ? 1 : fl;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((fl) ? puts("-1") : printf("%lld\n", prod));
  return 0;
}

Measured memory_bytes: 2512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main()
{
    long a, b, bl, br;
    double al, ar;

    std::cin >> a >> b;
    al = (double)a * 100 / 8;
    ar = (double)(a + 1) * 100 / 8;

    bl = b * 10;
    br = (b + 1) * 10;

    long ans = -1;
    if (al >= br || ar <= bl)
    {
        ans = -1;
    }
    else
    {
        if (al < bl)
        {
            ans = bl;
        }
        else
        {
            ans = al;
            if (al > ans)
            {
                ans++;
            }
        }
    }

    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
from bisect import bisect

n, a, b = map(int, input().split())
ppp = map(int, input().split())
qqq = [0] * n
for i, p in enumerate(ppp, start=1):
    qqq[p - 1] = i

dp = [(0, 0)]
for i in qqq:
    s = bisect(dp, (i,))
    ndp = [(j, cost + b) for j, cost in dp[:s]]
    stay_cost = dp[s - 1][1]
    ndp.append((i, stay_cost))
    remain = iter(dp[s:])
    for j, cost in remain:
        if stay_cost > cost + a:
            ndp.append((j, cost + a))
            break
    ndp.extend((j, cost + a) for j, cost in remain)
    dp = ndp
print(dp[-1][1])


Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceildivMod(T n, T d) {return (n+d-1)/d;}

ll times(ll a, ll b) {
    return (a*b) % mod;
}

ll expB(ll b, ll e) {
    ll ans = 1;
    while (e) {
        if (e % 2) ans = times(ans, b);
        b = times(b, b);
        e >>= 1;
    }
    return ans;
}

ll inv(ll a) {
    return expB(a, mod-2);
}

ll divMod(ll a, ll b) {
    return times(a, inv(b));
}

ll comb(ll n, ll k) {
    ll ans = 1;
    for (ll i = n; i > n-k; i--) {
        ans = times(ans, i);
    }
    for (ll i = k; i > 0; i--) {
        ans = divMod(ans, i);
    }
    return ans;
}

ll f(ll x, ll y) {
    if ((x+y)%3) return 0;
    if (x > 2*y || y > 2*x) return 0;
    ll n = (x+y)/3;
    ll k = min(x, y)-n;
    return comb(n, k);
}

void solve() {
    ll x, y; cin >> x >> y;
    cout << f(x, y);
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
void CountingSort(int *,int *,int );

int n;
int tA[10000000],tB[10000000];

int main(){
  int i,max=0;

  scanf("%d",&n);
  tA[0]=0;
  for(i=1;i<=n;i++){
    scanf("%d",&tA[i]);

    if(max<tA[i])max=tA[i];

  }

  for(i=1;i<=n;i++){
    tB[i]=0;
  }
  CountingSort(tA,tB,max);


  return 0;
}


void CountingSort(int A[],int B[],int k){
  int i,j;
  int C[100000];

  for (i = 0 ;i<=k;i++){
    C[i] = 0;
  }

  /* C[i] に i の出現数を記録する */
  for( j = 1 ;j<= n;j++){

    C[A[j]]++;
  }


    /* C[i] に i 以下の数の出現数を記録する*/
  for (i = 1 ;i<= k;i++){

    C[i] = C[i] + C[i-1];
  }

  for( j = n ;j>= 1;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i=1;i<=n;i++){
    if(i>1){
      printf(" ");
    }
    
    printf("%d",B[i]);
  }
  printf("\n");
}



Measured memory_bytes: 17376