akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = (1e5) + 5;
int par[N], rnk[N], w[N];
int U[N], V[N];

void DSU_init(int n) {
  for (int i = 0; i < n; ++i) {
    par[i] = i;
    rnk[i] = 0;
    w[i] = 1;
  }
}

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

void Union(int x, int y) { 
  x = Find(x);
  y = Find(y);
  if (x == y) return;
  if (rnk[x] > rnk[y]) {
    par[y] = x;
    w[x] += w[y];
  } else {
    par[x] = y;  
    w[y] += w[x];
    if (rnk[x] == rnk[y]) ++rnk[y];
  }
}

bool sameSet(int x, int y) {
  return Find(x) == Find(y);
}

ll f(ll n) {
  return n * (n - 1) / 2;
}

int main() { // claudio van
  int n, m; scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &U[i], &V[i]);
    U[i]--; V[i]--;
  }
  DSU_init(n);
  vector<ll> ans;
  ll tot = f(n);
  ans.emplace_back(tot);
  for (int i = m - 1; i >= 0; --i) {
    if (sameSet(U[i], V[i])) {
      ans.emplace_back(ans.back());
    } else {
      ll x = ans.back();
      x += f(w[Find(U[i])]);
      x += f(w[Find(V[i])]);
      Union(U[i], V[i]);
      x -= f(w[Find(V[i])]);
      ans.emplace_back(x);
    }
  }
  for (int i = (int) ans.size() - 2; i >= 0; --i) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}

Measured memory_bytes: 4212
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char c[] = sc.next().toCharArray();
		int ans = N;
		
		for (int i=0; i<N-1; i++) {
			if (c[i] == c[i+1]) {
				ans--;
			}
		}
		System.out.println(ans);
	}
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, d[20];
	cin>>n>>k;
	REP(i, k){
		cin>>d[i];
	}
	while(true){
		int tmp=n;
		bool ok=true;
		while(tmp>0){
			int a=tmp%10;
			tmp/=10;
			REP(i, k){
				if(a==d[i]){
					ok=false;
					break;
				}
			}
		}
		if(ok){
			cout<<n<<'\n';
			return 0;
		}
		++n;
	}
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

struct UnionFind{
    vector<int> data;
    UnionFind(int size){
        data=vector<int>(size,-1);
    }
    bool union_set(int x,int y){
        x=root(x);
        y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];
            data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    string s=get_str();
    int a,z;
    FOR(i,s.size()){
        if(s[i]=='A'){
            a=i;
            break;
        }
    }
    for(int i=s.size()-1;i>=0;--i){
        if(s[i]=='Z'){
            z=i;
            break;
        }
    }
    print(z-a+1);
    return 0;
}

Measured memory_bytes: 640
#define lp(i,n) for(int i=0;i<n;i++)
#define pau system("pause")
#include<bits/stdc++.h>
using namespace std;
using dl=long long;

int main(){
    string s,ans;
    cin>>s;
    lp(i,s.size()){
        if(s[i]=='B'&&ans.empty()==false)
            ans.pop_back();
        else if(s[i]=='0')
            ans.push_back('0');
        else if(s[i]=='1')
            ans.push_back('1');
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		String s = fs.next();
		
		HashSet<Integer> rIndexSet = new HashSet<>();
		HashSet<Integer> gIndexSet = new HashSet<>();
		HashSet<Integer> bIndexSet = new HashSet<>();
		
		for(int i = 0; i < s.length(); i++) {
			char charAt = s.charAt(i);
			if(charAt == 'R') {
				rIndexSet.add(i);
			}else if(charAt == 'G'){
				gIndexSet.add(i);
			}else {
				bIndexSet.add(i);
			}
		}
		
		long ans = 0;
		for(Integer rIndex : rIndexSet) {
			for(Integer bIndex : bIndexSet) {
				
				int contain = 0;
				int first;
				int second;
				
				if(rIndex < bIndex) {
					
					first = rIndex;
					second = bIndex;
				}else {
					first = bIndex;
					second = rIndex;
				}
				
				int diff = second - first;
				int left = first - diff;
				
				if(gIndexSet.contains(left)) {
					contain++;
				}
				
				int right = second + diff;
				if(gIndexSet.contains(right)) {
					contain++;
				}
				
				if((second - first) % 2 == 0) {
					int mid = first + (second - first) / 2;
					if(gIndexSet.contains(mid)) {
						contain++;
					}
				}
				
				ans += gIndexSet.size() - contain;
			}
		}
		
		System.out.println(ans);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

ll fact[200001];
const int mod = 1e9 + 7;

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * x % mod;
            x = x * x % mod;
            n >>= 1;
    }
    return res;
}

void init() {
    fact[0] = 1;
    for(ll i = 1; i <= 200000; i++) {
        fact[i] = fact[i - 1] * i;
        fact[i] %= mod;
    }
}

ll inv(ll x) {
    return mod_pow(x, mod - 2, mod);
}

ll comb(ll n, ll r) {
    return ((fact[n] * inv(fact[n - r])) % mod * inv(fact[r])) % mod;
}

void solve() {
    init();

    int N, M;
    cin >> N >> M;
    map<int, int> fact;

    for(int i = 2; i * i <= M; i++) {
        if (M % i == 0) {
            while(M % i == 0) {
                M /= i;
                fact[i]++;
            }
        }
    }
    if (M > 1) fact[M]++;

    ll ans = 1;
    for(auto && f : fact) {
        int c = f.second;
        ans *= comb(c + N - 1, N - 1);
        ans %= mod;
    }
    cout << ans << endl;

}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 1792
N,A,B = map(int, input().split())
#質問 1 に対して「はい」と回答した人の数は A 人、質問 2 に対して「はい」と回答した人の数は B人でした。
#このとき、調査の対象者のうち新聞 X, Y の両方を購読している人の数は最大で何人であり、また最小で何人であると考えられるでしょうか？
if N-A-B >= 0:
    print(min(A,B),0)
else:
    print(min(A,B),abs(N-A-B))

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

int main(){
    ll n, a, b; cin >> n >> a >> b;
    if(a <= 0){
        cout << 0 << endl;
        return 0;
    }

    ll c = n / (a + b);
    ll ans = a * c;
    ll d = n % (a + b);
    if(d <= a){
        ans += d;
    }else{
        ans += a;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
k,n = map(int,input().split())
ll = list(map(int,input().split()))
tmp = [k-ll[-1]+ll[0]]
#print(tmp)
for i,l in enumerate(ll):
    if i == 0:
        continue
    tmp.append(ll[i]-ll[i-1])
#print(tmp)
m = max(tmp)
print(k-m)

Measured memory_bytes: 26444
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	d := make([]int, n)
	//N := 4
	//D := []int{50, 30, 50, 100, 50, 80, 30, 120, 120, 40, 90, 0, 120, 11, 1, 2, 3, 4}
	//count := 0
	for i := 0; i < n; i++ {
		d[i] = nextInt()
	}
	m := map[int]int{}

	sort.Sort(sort.IntSlice(d))

	for _, key := range d {
		if _, ok := m[key]; !ok {
			m[key] = 1
		} else {
			m[key]++
		}
	}

	fmt.Println(len(m))

}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 500006
#define P 998244353
int n , m;

int Pow( int x , int a ) {
    int ret = 1;
    while( a ) {
        if( a & 1 ) ret = 1ll * ret * x % P;
        x = 1ll * x * x % P , a >>= 1;
    }
    return ret;
}

int J[MAXN] , iJ[MAXN];

int C( int a , int b ) {
    return J[a] * 1ll * iJ[b] % P * iJ[a - b] % P;
}

int main() {
    J[0] = iJ[0] = 1;
    for( int i = 1 ; i < MAXN ; ++ i ) J[i] = J[i - 1] * 1ll * i % P , iJ[i] = Pow( J[i] , P - 2 );
    cin >> n >> m;
    int lim = min( n , m );
    int c = 0 , res = 0;
    for( int i = 0 , zjk ; i <= lim ; ++ i ) {
        zjk = C( n , i ) * 1ll * C( m , i ) % P * J[i] % P * Pow( n + 1 , m - i ) % P * Pow( m + 1 , n - i ) % P;
        if( c ) zjk = P - zjk;
        c ^= 1;
        res = ( res + zjk ) % P;
    }
    cout << res << endl;
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    LL i,n,x,rt,ans;
    cin >> n;
    rt=sqrt(n);
    ans=n;
    for(i=1;i<=rt;i++)
    {
        if(n%i == 0)
        {
            x=n/i;
            ans=min(ans,i-1+x-1);
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 100010
typedef long long ll;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,odd,a[N];
ll sum;
bool dfs(){
	int odd=0;
	bool flag=false;
	for(int i=1;i<=n;++i){
		if(a[i]&1)++odd;
		if(a[i]==1)flag=true;
	}
	if((n-odd)&1)return true;
	if(flag||odd>1)return false;
	int g=0;
	for(int i=1;i<=n;++i){
		if(a[i]&1)--a[i];
		g=__gcd(a[i],g);
	}
	for(int i=1;i<=n;++i){
		a[i]/=g;
	}
	return dfs()^1;
}
int main(){
	n=read();
	int tmp=0;
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	puts(dfs()?"First":"Second");
	return 0;
}


Measured memory_bytes: 3996
#include "cmath"
#include "cstdio"
#include "iostream"
#include "vector"
#include "algorithm"
using namespace std;

const int maxn = 1e5 + 10;

int ar[maxn];

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int t; scanf("%d", &t);
		ar[i] = t;
	}
	sort(ar, ar + n);
	double res = ar[0];
	for (int i = 1; i < n; i++)	{
		res = (res + double(ar[i]))/2.0;
	}
	printf("%.6f\n", res); 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++)
    cout << s[i] << t[i];
  puts("");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back

#define INT 1.01

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

    ll X; // llと比較して実行時間が大幅に速い (2205ms->2ms)
    cin >> X;

    int64_t v = 100;
    //while(true){ //while, for文では実行時間は変わらない
    rep(ret, INF){
        if(X<=v){
            cout << ret << endl;
            break;
        }
        //v *= INT; // 実行時間が2ms->6msへと伸びる
        v += 0.01*v;
    }

    //cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5+10;
const double inf=1e9;
typedef long long ll;
typedef pair<int,int>pr;
const ll mod=1e9+7;
ll _pow(ll  a,ll b) {
    ll ans=1;
    while(b) {
        if(b&1)
            ans=ans*a;
        a=a*a;
        b>>=1;
    }
    return ans;
}
ll gcd(ll a,ll b){
    if(!b) return a;
    else return gcd(b,a%b);
}
int a[maxn];
int main(){
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin>>n;
  vector<int>ans;
  for(int i=1;i<=n;i++){
     cin>>a[i];
  }
  ans.push_back(1);
  for(int i=2;i<=n;i++){
    while(i<=n&&a[i]<=a[i-1]){
        i++;
    }
    ans.push_back(i);
  }

  int num=0;
  for(int i=0;i+1<ans.size();i++){
     num=max(num,ans[i+1]-ans[i]-1);
  }
  cout<<num<<endl;
  return 0;
}


Measured memory_bytes: 1276
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::vec::Vec;
use std::cmp::Ordering;
//use std::collections::HashSet;


struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let s: String = sc.read();
    let t: String = sc.read();
    let mut s: Vec<char> = s.chars().collect();
    let mut t: Vec<char> = t.chars().collect();
    s.sort(); t.sort();
    t.reverse();
    match s.cmp(&t) {
        Ordering::Less => println!("Yes"),
        _              => println!("No"),
    }
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
    int n;cin>>n;
    vector<int> s(n);
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>s[i];
        sum+=s[i];
    }
    
    int m;
    if(sum%10==0){
        m=0;
        for(int i=0;i<n;i++){
            int score=sum-s[i];
            if(score%10!=0) m=max(m,score);
        }
    }
    else m=sum;

    cout<<m<<endl;
}    

Measured memory_bytes: 256
#import numpy as np
N,M=map(int,input().split())
inf=10**9

class Node():
	def __init__(self, ix):
		self.ix = ix # ノード番号
		self.done = False # 確定ノードかどうか
		self.pay = {} # 頂点番号:コストの一覧を容れる辞書
		self.paid = -1 # ここに到達するための最小コスト(未定義なら-1)
		self.prev = -1 # 最小コストを与える親ノード(未定義なら-1)
	def __str__(self):
		# デバッグ用
		return '{} <- [{}] <- {}, done:{}, pay:{}'.format(self.ix, self.paid, self.prev, self.done, self.pay)

# ノードのリストを生成
nodes = []
for i in range(N):
	nodes.append(Node(i))

# エッジのリストを生成(これはこの問題用)
# edges = np.zeros((N,N), dtype=np.uint8)
edges = []
for _ in range(N):
	edges.append([0]*N)

# エッジ情報を取得
# 全エッジを格納
# 注意: 標準入力は1-indexedだがここでは0-indexedに直す
for _ in range(M):
	a,b,c = map(int,input().split())
	nodes[a-1].pay[b-1] = c
	nodes[b-1].pay[a-1] = c
	edges[a-1][b-1] = 1
	edges[b-1][a-1] = 1
		
		
# 出発ノードを0からN-1まで変化させる
for i in range(N):
	##### DEBUG
	# print('start node: {}'.format(i))
	nodes[i].prev = i # 出発点の最良親を自分自身に
	nodes[i].paid = 0 # 出発点のコストは0
	nodes[i].done = True # 出発点は確定済み
	n_done = 1 # 確定ノード数を1に
	while n_done < N: # 全部確定するまで続行
		to_conf_ix = -1 # 次に確定されるべきノード番号
		to_conf_paid = 10**9 # そのコスト
		for node in nodes:
			# 確定ノードすべてに対して操作を行う
			if node.done:
				##### DEBUG
				# print('confirmed parent: {}'.format(node.ix))
				# 接続先を全列挙
				for child in list(node.pay.keys()):
					# その接続先が未確場合のみ進む定なら処理続行
					if not nodes[child].done:
						# その接続先の仮の最小コストと仮の親を更新
						# まだ確定済みにはしない
						newcost = node.paid + node.pay[child]
						# 更新するための条件
						flag = (nodes[child].paid < 0) or (newcost < nodes[child].paid)
						##### DEBUG
						# print('p{} -> c{}, prevcost={}, newcost={}'.format(node.ix, child, nodes[child].paid, newcost))
						# 条件をみたせば接続先の情報を更新
						# また次に確定されるノード候補の情報も更新
						if flag:
							nodes[child].paid = newcost
							nodes[child].prev = node.ix
						if newcost < to_conf_paid:
							to_conf_paid = newcost
							to_conf_ix = child
						##### DEBUG
						# print('to_conf: ix:{}, cost:{}'.format(to_conf_ix, to_conf_paid))
		# 操作が完了したら現段階の候補ノードを確定させる
		nodes[to_conf_ix].done = True
		# 確定ノード数を1増やす
		n_done += 1
		##### DEBUG
		# print('--- n_done: {} ---'.format(n_done))
		# for j in range(N):
		# 	print(nodes[j])
		# print('------------------')
		
	# 各ノードについてそれを親と連結するパスをedgeから削除
	for j in range(N):
		k = nodes[j].prev
		edges[j][k], edges[k][j] = 0, 0

	# 全ノードのpaid,prevをリセット
	for j in range(N):
		nodes[j].paid, nodes[j].prev = -1, -1
		nodes[j].done = False

# 最後にedgesに残っているエッジの本数を出力
# print(int(np.sum(edges)//2)) # NumPy
ans = 0
for i in range(N):
	ans += sum(edges[i])
print(ans//2)


Measured memory_bytes: 46428
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define MOD1 1000000007
#define MOD2 998244353
#define IOS std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define print(a) for(auto x : a)    cout<<x<<" "; cout<<"\n";
using namespace std;

void OFFLINE(){ 
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 
    #endif
}
ll GCD(ll a, ll b){ int gcd = b != 0 ? a : GCD(b, a % b); return gcd;}

int main(){

    IOS;

    ull n;
    cin >> n;
    ull val = 100;

    ull years = 0;
    while(val < n)
    {
        val += (val * 1) / 100;
        years++;
    }

    cout<<years<<"\n";

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  int ans = A.at(N - 1) - A.at(0);
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int table[200][200]={{0}};
    int c,r;
    cin>>r>>c;
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            cin>>table[i][j];
        }
    }
    for(int i=0; i<r+1; i++){
        int sum=0;
        for(int j=0; j<c; j++){
            sum+=table[i][j];
        }
        table[i][c]=sum;
    }
    for(int j=0; j<c+1; j++){
        int sum=0;
        for(int i=0; i<r; i++){
            sum+=table[i][j];
        }
        table[r][j]=sum;
    }
    for(int i=0; i<r+1; i++){
        for(int j=0; j<c; j++){
            cout<<table[i][j]<<" ";
        }
        cout<<table[i][c]<<endl;
    }
    
}



Measured memory_bytes: 3240
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	string s;
	cin >> s;
	for(int i = 0;i < s.size();i++){
		if(s[i] == ',')s[i] = ' ';
	}

	cout << s << endl;
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n; cin>>n;
	ll sum=0;
	ll best=0;
	for(int i = 1; i <= n; i++)
	{
		sum+=i;
		best++;
		if(sum>=n) break;
	}
	sum=n;
	for(int i = best; i >= 1; i--)
	{
		if(sum>=i)
		{
			cout<<i<<'\n';
			sum-=i;
		}
	}	
}


Measured memory_bytes: 256
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
const char bn = '\n';
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;



int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int N = S.size();

    vector<vector<int>> next(N);
    vector<int> last(26,N);
    for(int i=N-1;i>=0;i--){
        last[S[i]-'a'] = i;
        next[i] = last;
    }

    vector<int> DP(N+1,N); //DP[i]:=i文字目以降で「部分文字列」にならない最短の文字列
    vector<int> memo(N+1,0);
    DP[N] = 1;
    for(int i=N-1;i>=0;i--){
        REP(c,26){
            int to = next[i][c];
            if(to==N){
                memo[i] = c;
                DP[i] = 1;
                break;
            }
            if(chmin(DP[i],DP[to+1]+1)){
                memo[i] = c;
            }
        }
    }
    
    string ans = "";
    for(int now=0; now<N ;){
        int next_char = memo[now];
        ans += next_char + 'a';
        now = next[now][next_char]+1;
        // if(now == next[now][next_char]){
        //     now++;
        // }else{
        // }
    }
    cout << ans << bn;
}

Measured memory_bytes: 28564
#include <stdio.h>
int min(int a,int b)
{
    if(a<b)
        return a;
    else
        return b;
}
int main()
{
    int a1,a2,b1,b2;
    while(~scanf("%d%d%d%d",&a1,&a2,&b1,&b2))
    {
        printf("%d\n",min(a1,a2)+min(b1,b2));
    }

}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <stdio.h>
#include <string.h>
#define MAXN 200000
#define ll long long
using namespace std;


vector<int> edges[MAXN+2];

int dfs(int par,int u,int* ans) {
    
    
    
    vector<int> leaf_dists;
    for(int v : edges[u]) {
        if (v == par)
            continue;
        leaf_dists.push_back(dfs(u,v,ans));
    }
    
    
    sort(leaf_dists.begin(),leaf_dists.end(),greater<int>());
    
    
    if (leaf_dists.size() >= 2) {
        *ans = max(*ans, 2+leaf_dists[0]+leaf_dists[1]);
    } else if (leaf_dists.size() == 1) {
        *ans = max(*ans, 1+leaf_dists[0]);
    }
    
    if (leaf_dists.empty()) {
        return 0;
    } else {
        return leaf_dists[0]+1;
    }
}

bool canwin[222222];

int main() {
    int N;
    cin>>N;
    for(int i=1;i<=N-1;i++) {
        int u,v;
        cin>>u>>v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    int dia=0;
    dfs(-1,1,&dia);
    
    
    if (dia == 0) {
        cout << "First" << endl;
        return 0;
    }
    
    if (dia == 1) {
        cout << "Second" << endl;
        return 0;
    }
    
    int len=dia+1;
    
    canwin[0]=false;
    canwin[1]=true;
    canwin[2]=false;
    for(int i=3;i<=len;i++) {
        canwin[i]=(!canwin[i-1]||!canwin[i-2]);
    }
    
    
    
    if (canwin[len]) {
        cout << "First" << endl;
    } else {
        cout << "Second" << endl;
    }
    
    
    
}


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

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        return;

    }

    public static string Solve()
    {
        int s = ReadInt();
        int a = s;
        switch(a)
        {
            case 1:
            case 2:
                return "4";
                break;
            default:
                for (int i = 0; i < 1000000; i++)
                {
                    //Console.WriteLine(i.ToString() + ":" + a.ToString());
                    if (a == 4)
                    {
                        return (i + 4).ToString();
                    }
                    a = Funciton(a);
                }
                break;
        }
        return "0";
    }

    static int Funciton(int n)
    {
        if(n%2 == 0)
        {
            return n / 2;
        }
        else
        {
            return 3 * n + 1;
        }
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 11092
#include<iostream>
using namespace std;
int main(){
    int a[3];
    int temp,sum;
    for(int i = 0; i < 3; i++){
        cin >> a[i];
    }
    for(int i = 0; i < 3; i++){
        for(int j = 3-1; j > i; j--){
            if(a[j] < a[j - 1]){
                temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
            }
        }
    }
    sum = (a[1] - a[0]) + (a[2] - a[1]);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
count = int(input())
 
str_data = dict()
result = 0
for i in range(count):
    judge_str = ''.join(sorted(input()))
    if judge_str in str_data:
        str_data[judge_str] += 1
        result += str_data[judge_str]
    else:
        str_data[judge_str] = 0
    
print(result)

Measured memory_bytes: 17852
#include <iostream>

using namespace std;

int main() {

	int input[10001];
	int end_of_input;

	for (int i = 0; i < 10001;i++) {
		cin >> input[i];
		if (input[i] == 0) {
			end_of_input = i;
			break;
		}
	}

	for (int i = 0; i < end_of_input; i++) {
		cout << "Case " << i + 1 << ": " << input[i] << endl;
 	}

	return 0;

}

Measured memory_bytes: 3104
#include<stdio.h>

int main(void)
{
      int a ,b ;
      
      char op;
      
      int ans=0;
      
      while(scanf("%d %c %d",&a ,&op ,&b))
      {
      	if(op == '?')
      	{
      		break;
		  }
      	else if(op == '+')
      	{
      		ans = a+b;
      		
		  }
      	else if(op == '-')
      	{
      		ans = a-b;
      		
		  }
		  else if(op == '*')
      	{
      		ans = a*b;
      		
		  }
		  else if(op == '/')
      	{
      		ans = a/b;
      		
		  }
		  printf("%d\n", ans);
      	
      	
      	
      	
      	
	  }
      
      return 0;
}


Measured memory_bytes: 2672
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		List<Some> list = new ArrayList<Some>();
		for (int i = 0; i < N; i++) {
			list.add(new Some(sc.nextLong(), sc.nextInt()));
		}
		list.sort((s1, s2) -> {
			int a = 0;
			if (s1.A - s2.A > 0) {
				a = 1;
			} else if (s1.A - s2.A < 0) {
				a = -1;
			}
			return a;});
		long ans = 0;
		int count = 0;
		for (int i = 0;;i++){
			ans += list.get(i).A * list.get(i).B;
			count += list.get(i).B;
			if (count >= M) {
				ans -= list.get(i).A * (count - M);
				break;
			}
		}
		System.out.println(ans);
	}

	static class Some {
		long A;
		int B;

		public Some(long A, int B) {
			this.A = A;
			this.B = B;
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 29364
n = int(input())
a = list(map(int, input().split()))
minhp = -1
while 1:
  minhp = min(a)
  minhpi = a.index(minhp)
  for i in range(len(a)):
    if i == minhpi:
      continue
    a[i] = a[i] % minhp
  a = list(filter(lambda x:x!=0, a))
  if min(a) == minhp:
    break
print(minhp)

Measured memory_bytes: 14252
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
cnt = sum(b)

for i in range(n-1):
    if a[i+1] - a[i] == 1:
        cnt += c[a[i]-1]
        
print(cnt)

Measured memory_bytes: 61796
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
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; }

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

int main(){
    int r, d; cin >> r >> d;
    ll x; cin >> x;
    rep(i, 10){
        x = r*x - d;
        out(x);
    }
}

Measured memory_bytes: 3620
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    long long n,k;
    cin>>n>>k;
    long long count=0;
    if(k%2==0&&n>=k/2)
    {
        count+=((n-(k/2))/k +1)*((n-(k/2))/k +1)*((n-(k/2))/k +1);
    }
    if(n>=k)
    {
        count+=((n-k)/k +1)*((n-k)/k +1)*((n-k)/k +1);
    }
    cout<<count<<endl;
	return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[5005][5005]; // iとjから始めた時、一致する最長の長さ

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  string s; cin>>s;
  rrep(i,n){
    rrep(j,n){
      if(s[i]!=s[j]) dp[i][j]=0;
      else dp[i][j]=dp[i+1][j+1]+1;
    }
  }
  ll ans=0;
  rep(i,n) rep(j,n){
    if(i>=j) continue;
    ll now=min(dp[i][j],(ll)j-i);
    chmax(ans,now);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 195840
#include <iostream>
#include <vector>
#include <map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int main(){
    int i;
    int N;
    cin >> N;
    int a[N],count=0;
    rep(i,N) cin >> a[i];
    REP(i,0,N-2){
        if(a[i] <= a[i+1] && a[i+1] <= a[i+2]){
            count++;
        } else if (a[i] >= a[i+1] && a[i+1] >= a[i+2]){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func isOdd(n int) bool { return n%2 != 0 }

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	for i := 1; i <= n; i++ {
		if isOdd(len(strconv.Itoa(i))) {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	ll a, b;
	cin>>a>>b;
	if(a>=13){
		cout<<b<<endl;
		return 0;
	}
	if(a>=6){
		cout<<b/2<<endl;
		return 0;
	}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define reps(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) for(int i=0;i<a;i++)
typedef long long int ll;
using namespace std;


struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main(){
    int A,B;
    cin>>A>>B;
    if(A<=5){
        cout<<0<<endl;
    }
    else if(A>=13){
        cout<<B<<endl;
    }
    else{
        cout<<B/2<<endl;
    }




    
    return 0;
}


Measured memory_bytes: 256
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

A, B, C, D = map(int, input().split())

sa = B - A + 1

C2 = (B // C) - ((A - 1) // C)
D2 = (B // D) - ((A - 1) // D)

CD = lcm(C, D)

CD2 = (B // CD) - ((A - 1) // CD)

print(sa - (C2 + D2 - CD2))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<ll,ll>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////

void solve(){
  ini(N);
  vi a(1 << N); in(a);

  sort(all(a) , greater<int>());


  multiset<int , greater<int>> used , unused;
  used.insert(a[0]);
  rep1(i , (1 << N) - 1) unused.insert(a[i]);
  
  rep(i , N){
    auto cur = used;
    auto it = unused.begin();
    each( x , cur ){
      if(it == unused.end()) die("No");
      while(*it >= x){
        if(++it == unused.end()) die("No");
      }
      used.insert(*it);
      it = unused.erase(it);
    }

  }

  out("Yes");

  
}

Measured memory_bytes: 19712
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n, k;
    scanf("%d%d", &n, &k);
    k++;

    vector<int> a(n),b(n);
    int i,j;
    for(i=0; i<n; i++) {
        scanf("%d%d", &a[i], &b[i]);
    }

    ll ans=-LINF;
    vector<int> bad(n,0);
    for(i=31; i>=0; i--) {
        ll sum=0;
        if(k & (1<<i)) {
            for(j=0; j<n; j++) {
                if(bad[j]==0) {
                    if(!(a[j] & (1<<i))) sum+=b[j];
                }
            }
        }
        else {
            for(j=0; j<n; j++) {
                if(bad[j]==0) {
                    if(a[j] & (1<<i)) bad[j]=1;
                }
            }
        }
        //printf("%lld\n", sum);
        ans = MAX(ans,sum);
    }
    printf("%lld\n", ans);

    return 0;
}



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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define endl '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    int n, l=inf, r=-1, x ;
    cin>> n ;
    vi a(n) ;
    for(int i=0 ; i<n ; i++)
      {
        cin>> x ;
        l=min(l, x) ;
        r=max(r, x) ;
      }
    cout<< r-l ;
  }


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, y) = readLine()!!.split(" ").map { it.toInt() }

    for (i in 0..n) {
        for (j in 0..n-i) {
            if (i*10000 + j*5000 + (n - i - j)*1000 == y) {
                println("$i $j ${n-i-j}")
                return
            }
        }
    }
    println("-1 -1 -1")
}

Measured memory_bytes: 37776