akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll n,t,l,b;
bool isl[200],isb[200];
double dp[200][200];
int main(){
    while(1) {
        cin >> n >> t >> l >> b;
        if(n < 5) {
            break;
        }
        REP(i,n + 1) {
            isl[i] = false;
            isb[i] = false;
        }

        REP(i,l) {
            ll lose;
            cin >> lose;
            isl[lose] = true;
        }
        REP(i,b) {
            ll back;
            cin >> back;
            isb[back] = true;
        }
        REP(i,t + 1) {
            REP(j,n + 1) {
                dp[i][j] = 0;
            }
        }

        REP(i,n + 1) {
            dp[0][i] = (i == 0);
        }

        FOR(i,1,t + 1) {
            REP(j,n + 1) {
                FOR(k,1,7) {
                    if(j - k < 0 || isb[j - k]) {
                        continue;
                    }else if(isl[j - k]) {
                        if(i - 2 >= 0) {
                            dp[i][j] += dp[i - 2][j - k] * (1.0 / 6);
                        }
                    }else{
                        dp[i][j] += dp[i - 1][j - k] * (1.0 / 6);
                    }
                }

                if(1 <= n - j && n - j <= 5) {
                    FOR(k,2 * n - 6 - j,n - 1 + 1) {
                        if(isb[k]) {
                            continue;
                        }else if(isl[k]) {
                            if(i - 2 >= 0) {
                                dp[i][j] += dp[i - 2][k] * (1.0 / 6);
                            }
                        }else{
                            dp[i][j] += dp[i - 1][k] * (1.0 / 6);
                        }

                    }
                }
                if(isb[j]) {
                    dp[i][0] += dp[i][j];
                    dp[i][j] = 0;
                }
            }
        }
        double ans = 0;
        REP(i,t + 1) {
            ans += dp[i][n];
        }
        printf("%0.10f\n",ans);
    }
}




Measured memory_bytes: 3192
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int k = scanner.nextInt();
        writer.println(n - k + 1);

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

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

Measured memory_bytes: 21460
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	int W, H;
	cin >> W >> H;
	vector< int > P(W), Q(H);
	rep(i, W) cin >> P[i];
	rep(j, H) cin >> Q[j];
	vector< pii > S(W + H);
	rep(i, W) S[i] = make_pair(P[i], 0);
	rep(j, H) S[j + W] = make_pair(Q[j], 1);
	sort(S.begin(), S.end());
	int ans = 0;
	int M = W + H;
	rep(i, M) {
		int c = S[i].first;
		if (S[i].second == 0) {
			ans += c * (H + 1);
			--W;
		} else {
			ans += c * (W + 1);
			--H;
		}
		//cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}

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

using ll = long long;

signed main(){

  int n;
  cin>>n;
  vector<ll> bit0(64),bit1(64);
  for(int i=0;i<n;++i){
    ll a;
    cin>>a;
    for(int b=0;b<64;++b){
      if(a&(1LL<<b))bit1[b]++;
      else bit0[b]++;
    }
  }

  ll ans = 0;
  ll MOD = 1e9+7;
  for(int i=0;i<64;++i){
    ans += (1LL<<i)%MOD*bit1[i]%MOD*bit0[i]%MOD;
    ans %= MOD;
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Bitset I - Bit Mask
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_10_D&lang=jp

"""
class Bit:
    def __init__(self, masks = []):
        self.data = 0
        self.masks = masks

    def process(self, op, arg):
        funcs = (self.test, self.set, self.clear, self.flip, self.all, self.any, self.none, self.count, self.val)
        funcs[op](arg)

    def test(self, arg):
        print(int(bool(self.data & 1 << int(arg))))

    def set(self, arg):
        for m in self.masks[arg]:
            self.data |= 1 << int(m)

    def clear(self, arg):
        for m in self.masks[arg]:
            self.data &= ~(1 << int(m))

    def flip(self, arg):
        for m in self.masks[arg]:
            self.data ^= 1 << int(m)

    def all(self, arg):
        print(int(all([self.data & 1 << m for m in self.masks[arg]])))

    def any(self, arg):
        print(int(any([self.data & 1 << m for m in self.masks[arg]])))

    def none(self, arg):
        print(int(all([(self.data & 1 << m)==0 << m for m in self.masks[arg]])))

    def count(self, arg):
        print(len([True for m in self.masks[arg] if self.data & 1 << m]))

    def val(self, arg):
        print(sum(self.data & 1 << m for m in self.masks[arg]))


masks = []
for _ in range(int(input())):
    _, *m = input().split()
    m = [int(i) for i in m]
    masks.append(m)
b = Bit(masks)

for _ in range(int(input())):
    op, arg = map(int, input().split())
    b.process(op, arg)


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

int main() {
    vector<int> a(3);
    rep(i,3) cin >> a[i];
    if(accumulate(a.begin(),a.end(),0) >= 22) puts("bust");
    else puts("win");
    return 0;
}

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

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 FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

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

    // input
    ll Q;
    cin >> Q;

    vector<ll> f(100001);
    FOR(i, 1, 100001){
        ll divisorCount = 0;
        for(int j=2; j*j<=i; j++){
            if(i%j==0) divisorCount++;
        }
        if(divisorCount>=2){
            f[i] = 1;
        }
    }
    // 累積和
    FOR(i, 1, 100001){
        f[i] += f[i-1];
    }

    while(Q--){
        ll N; cin >> N;

        ll ans = f[N];
        p(ans);
    }
    
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
    string k;
    cin>>k;
    int count1 = 0;
    int count2 = 0;
    int cc = 0;
    for(int i = 2 ; i < k.size();i++)
    {
        if(k[i]=='C')
        {
            count1++;
            cc = i;
        }
    }
    for(int i = 0 ; i < k.size();i++)
    {
        if (isupper(k[i]))
        {
            count2++;
        }
    }
    if(count1 == 1 && k[0]=='A' && islower(k[1]) && count2 == 2&& cc != k.size()-1)
    {
        cout<<"AC"<<endl;
    }
    else if (k[1]== 'c'|| k[1]=='C')
    {
        cout<<"WA"<<endl;
    }
    else
    {
        cout<<"WA"<<endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int l = int.Parse(input[1]);
		int r = l+n-1;
    long answer = n*(2*l+n-1)/2;
    if(l >= 0) answer -= l;
    else if(l+n-1 < 0) answer -= (l+n-1);

		Console.WriteLine(answer);
	}
}

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

bool f(pair<int,int> a, pair<int,int> b)
{
    return a.first < b.first;
}

int main() 
{
    int n;
    cin >> n;
    vector<pair<int,int>> v;
    map<pair<int,int>,int> mp;
    map<pair<int,int>,int> visited;
    for (int i=0; i<n; i++)
    {
        int a,b;
        cin >> a >> b;
        v.push_back(make_pair(a,b));
        mp[make_pair(a,b)] = 1;
    }
    for (int i=0; i<n; i++)
    {
        int a,b;
        cin >> a >> b;
        v.push_back(make_pair(a,b));
        mp[make_pair(a,b)] = 2;
    }
    sort(v.begin(), v.end(), f);
    int ans = 0;
    for (int i=2*n-1; i>=0; i--)
    {
        int x = 2*n+1;
        int y = 2*n+1;
        bool done = false;
        for (int j=2*n-1; j>i; j--)
        {
            if (mp[v[i]]==1 && mp[v[j]]==2 && !visited[v[j]] && v[j].second<y && v[j].second>v[i].second)
            {
                done = true;
                y = v[j].second;
                x = v[j].first;
            }
        }
        if (done)
        {
            visited[{x,y}] = true;
            ans++;
        }
    }    
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn calc(a: i64, b: i64) -> i64 {
    if b == 0 {
        return 1;
    }
    let mut highest = 0;
    let mut snd = 100;
    for k in (0 .. 63).rev() {
        if (b & 1 << k) != 0 {
            highest = k;
            break;
        }
    }
    let brem = b ^ 1i64 << highest;
    if brem == 0 {
        return if a != 0 {
            2 * (b - a) + 1
        } else {
            2 * b
        };
    }
    for k in (0 .. 63).rev() {
        if (brem & 1 << k) != 0 {
            snd = k;
            break;
        }
    }
    if a < 2 << snd {
        return (2 << highest) - a;
    }
    let hh = 1i64 << highest;
    (hh - a) + (2i64 << snd) + (hh - a)
}
fn solve() {
    let mut a: i64 = get();
    let mut b: i64 = get();
    for k in (0 .. 63).rev() {
        if (a & 1 << k) == (b & 1 << k) {
            a &= !(1 << k);
            b &= !(1 << k);
        } else {
            break;
        }
    }
    // essential part
    println!("{}", calc(a, b));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
if __name__ == "__main__":
	list = {}
	i = 0
	while True:
		a,op,b = input().split()
		a,b = map(int,[a,b])
		if op == '+':
			list[i] = a+b
		elif op == '-':
			list[i] = a - b
		elif op == '*':
			list[i] = a*b
		elif op == '/':
			c = a/b
			list[i] = int(c)
		else:
			break
		i +=1
	for i in range(len(list)):
		print (list[i])

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

int main(void){
    int n;
    string s;
    cin>>n>>s;
    bool dp1[10]={},dp2[100]={},dp3[1000]={};
    for(char c:s){
        int c_int = c-48;
        for(int i=0;i<100;i++){
            if(dp2[i]) dp3[i*10+c_int]=true;
        }
        for(int i=0;i<10;i++){
            if(dp1[i]) dp2[i*10+c_int]=true;
        }
        dp1[c_int] = true;
    }

    int ans=0;
    for(int i=0;i<1000;i++){
        if(dp3[i]) ans ++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, mx = -1;
    cin >> n;

    vector<string> vs;
    map<string, int> m;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        m[s] += 1;
        if (m[s] > mx)
            mx = m[s];
        vs.push_back(s);
    }
    sort(vs.begin(), vs.end());
    string last = "";
    for (int i = 0; i < n; ++i) {
        if (vs[i] != last && m[vs[i]] == mx) {
            last = vs[i];
            cout << vs[i] << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 27376
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String w = sc.next();
    String str[] = w.split("");

    Arrays.sort(str);

    boolean ans = true;
    int count = 1;
    for(int i = 0 ; i < w.length()-1 ; ++i){
      if(str[i].equals(str[i+1])){
        count++;
      }else if(count%2==1){
        ans = false;
        break;
      }else{
        count = 1;
      }

    }

    if(count%2==1) ans = false;
    if(ans) System.out.println("Yes");
    else System.out.println("No");
 
  }
}

Measured memory_bytes: 35580
def merge(a, left, mid, right):
    x = 0
    l = a[left:mid] + [float("inf")]
    r = a[mid:right] + [float("inf")]
    i = 0
    j = 0
    for k in range(left,right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else :
            a[k] = r[j]
            j += 1
            x += mid - (left+i)
    return x

def mergeSort(a, left, right,x):
    if left+1 < right:
        mid = int((left + right)/2)
        mergeSort(a, left, mid,x)
        mergeSort(a, mid, right,x)
        x[0] += merge(a, left, mid, right)

n = int(input())
s = list(map(int,input().split()))
x = [0]
mergeSort(s,0,n,x)
print(x[0])



Measured memory_bytes: 27468
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

ll gcd(ll a, ll b) {
	if(a % b == 0) return b;
	else gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	return a*b/gcd(a,b);
}
int main() {
	ll a,b;
	cin >> a >> b;
	cout << lcm(a,b) << endl;
	
	
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <deque>
using namespace std;
int main(void){
  string S;
  cin >> S;
  
  string hi;
  string answer = "No";
  for(int i=0;i<5;i++){
    hi += "hi";
    if(S==hi){
      answer = "Yes";
      break;
    }
  }
  
  cout << answer << endl;
}


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

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n; cin >> n;
  vector<int> a(n);
  map<int,int> f;
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
    f[a[i]]++;
  }
  int q; cin >> q;
  while (q--) {
    int b, c; cin >> b >> c;
    sum = sum+1LL*(c-b)*f[b];
    f[c] += f[b];
    f[b] = 0;
    cout << sum << endl;
  }

  
  return 0;
}




Measured memory_bytes: 7976
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;
const ll INF=1e18;
int main()
{
    int n, m; cin>>n>>m;
    vector<P> g[2510], gr[2510];
    for(int i=0; i<m; i++){
        int a, b; ll c; cin>>a>>b>>c;
        a--; b--;
        g[a].push_back({b, c});
        gr[b].push_back({a, c});
    }
    bool ok[2510]={};
    ok[n-1]=1;
    queue<int> que;
    que.push(n-1);
    while(!que.empty()){
        int x=que.front();
        que.pop();
        for(auto p:gr[x]){
            int y=p.first;
            if(!ok[y]){
                ok[y]=1;
                que.push(y);
            }
        }
    }
    ll d[2510];
    fill(d, d+n, -INF);
    d[0]=0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            for(auto p:g[j]){
                int k=p.first;
                if(d[k]<d[j]+p.second){
                    d[k]=d[j]+p.second;
                }
            }
        }
    }
    int cnt=0;
    for(int j=0; j<n; j++){
        for(auto p:g[j]){
            int k=p.first;
            if(d[k]<d[j]+p.second){
                if(d[k]>-INF/2 && ok[k]) cnt++;
            }
        }
    }
    if(cnt>0){
        cout<<"inf"<<endl;
        return 0;
    }
    cout<<d[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 512
// in the name of Allah ;
#include<bits/stdc++.h>
using namespace std ;
const int maxn = 1e5 + 10 ;
int arr[2][maxn] , n , m = 1e5 + 10 ;
vector <pair <  int , int > > vec[2] ;
void input() 
{
	ios::sync_with_stdio(0) , cin.tie(0) ;
	cin >> n ;
	for ( int i = 0 ; i < n ; i++ ) 
	{
		int x ;
		cin >> x ;
		arr[i%2][x]++;
	}
}
int main () 
{
	input() ;

	for ( int j = 0 ; j < 2 ; j++ ) 
		for ( int i = 0 ; i < maxn ; i++ ) 
			vec[j].push_back ( { arr[j][i] , i } ) ;
	for ( int j = 0 ; j < 2 ; j++ ) 
		sort ( vec[j].begin() , vec[j].end() ) , reverse ( vec[j].begin() , vec[j].end() ) ;
	int ans = 0 ;
	if ( vec[0][0].second == vec[1][0].second ) 
		ans = min ( n - vec[0][0].first - vec[1][1].first , n- vec[1][0].first - vec[0][1].first ) ;
	else
		ans = n- vec[0][0].first - vec[1][0].first ;
	cout << ans << endl;
	
}

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

long long n;
vector<long long> a;

long long solve();

int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  vector<vector<long long>> dp;
  dp.assign(n + 1, vector<long long>(3, -1e18));
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= 2; ++j) {
      if (dp[max(0, i - 1)][j] != -1e18)
        dp[i + 1][j] = dp[max(0, i - 1)][j] + a[i];
      if (j != 0 && i >= 3 && dp[i - 2][j - 1] != 1e18)
        dp[i + 1][j] = max(dp[i + 1][j], dp[i - 2][j - 1] + a[i]);
    }
  }
  long long res = 0;
  for (int i = n - 1; i > 0; i -= 2) res += a[i];
  if (n % 2) res = max(res, dp[n][2]);
  res = max(res, dp[n][1]);
  if (n % 2) res = max(res, dp[n - 1][1]);
  res = max({res, dp[n - 1][0]});
  return res;
}


Measured memory_bytes: 15660
from collections import Counter
a,b=map(int,input().split())
def p_fact(n):
  m=n
  i=2
  a=[1]
  while n>1:
    if i>m**.5:
      a+=[n]
      break
    if n%i==0:
      n//=i
      a+=[i]
    else:i+=1  
  return a
af,bf=p_fact(a),p_fact(b)
da,db={},{}
for i in af:
  if da.get(i):da[i]+=1
  else:da[i]=1
for i in bf:
  if db.get(i):db[i]+=1
  else:db[i]=1
dc={}
for i in da:
  if db.get(i):dc[i]=min(da[i],db[i])
print(len(dc))

Measured memory_bytes: 67160
def limit(n,k)
  2.upto(n){|i| return i if (k*i)-(i-1) >= n}
end

n, k = gets.chomp.split(" ").map(&:to_i)
arr = gets.chomp.split(" ").map(&:to_i).sort
i = 2

puts (k == 2)? n-1 :
  (k == n)?   1 :
  (n/k == 1)? 2 :
  (n*2 == k)? 3 :
      limit(n,k)

Measured memory_bytes: 10240
module DoublyLinkedList = struct
  type t = {
    mutable data : int;
    mutable next : t;
    mutable prev : t;
  }

  let make () =
    let rec head = { data = 0; next = head; prev = head } in
    head

  let insert data head =
    let x = { data = data; next = head.next; prev = head } in
    head.next.prev <- x;
    head.next <- x

  let delete x =
    x.next.prev <- x.prev;
    x.prev.next <- x.next

  let delete_first head = delete head.next

  let delete_last head = delete head.prev

  let delete_node data head =
    let rec doit ite =
      if ite == head then None
      else if ite.data = data then Some ite
      else doit ite.next
    in
    match doit head.next with
    | None -> ()
    | Some ite -> delete ite

  let iteri head ~f =
    let rec doit i ite =
      if ite == head then ()
      else (f i ite.data; doit (i + 1) ite.next)
    in
    doit 0 head.next
end

module L = DoublyLinkedList

let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> List.rev (s :: acc)
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  doit str []

let () =
  let n = read_int () in
  let head = L.make () in
  let rec read i =
    if i >= n then ()
    else begin
      match split (read_line ()) ' ' with
      | "insert" :: n :: _ -> (L.insert (int_of_string n) head; read (i + 1))
      | "delete" :: n :: _ -> (L.delete_node (int_of_string n) head; read (i + 1))
      | "deleteFirst" :: _ -> (L.delete_first head; read (i + 1))
      | "deleteLast" :: _ -> (L.delete_last head; read (i + 1))
      | _ -> exit 1
    end
  in
  read 0;
  L.iteri head ~f:(fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n);
  print_newline ()

Measured memory_bytes: 41416
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;


map<ll, ll> prime;
void factorize(ll n) {
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            prime[i]++;
            n /= i;
        }
    }
    if(n != 1) {
        prime[n] += 1;
    }
}


int main() {
    
    int n;
    cin>>n;
    ll ans=1;
    for(int i=1;i<=n;i++){
        factorize(i);
    }
    irep(j,prime){
        ans*=j->se+1;
        ans%=MOD;
    }
    cout<<ans<<endl;
    
}








Measured memory_bytes: 256
#include<stdio.h>

int main() {

	int d;
	while (scanf("%d", &d) != EOF) {
                int i,length,sum;
		length = 600; sum = 0;
		for (i = 1; i<length / d; i++) {
			sum += i*i*d*d;
		}
		printf("%d\n", sum*d);
	}
return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
    #define ll int
    #define N 100000
    #define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
    #define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
    #define po pop_back
    #define pb push_back
    #define lb lower_bound
    #define fi first
    #define se second
    #define debug(x) cout << #x << " = " << x << endl
    #define ub upper_bound
    #define ibs ios_base::sync_with_stdio(false)
    #define cti cin.tie(0)
    #define all(x) x.begin(),x.end()
    #define PI 3.14159265
    #define cot cout.tie(0)
    using namespace std;
      /**
        * @author :: Sawlani
        *
        */

       ll n,k;
       ll a[101];
       ll dp[N+1][3];
       int main()
      {
           //  freopen("input.txt","r",stdin);
            cin >> n >> k;

        memset(dp,-1,sizeof(dp));
         f(i,1,n) cin >> a[i];


         f(i,0,a[1]-1)
            dp[i][1]=2,dp[i][2]=1;


         f(i,a[1],k)
         {
              f(j,1,n)
              {
                   if(i>=a[j])
                   {
                       if(dp[i-a[j]][2]==1)
                        dp[i][1]=1;
                       if(dp[i-a[j]][1]==2)
                        dp[i][2]=2;
                   }
              }
              if(dp[i][1]==-1)
                dp[i][1]=2;
              if(dp[i][2]==-1)
                dp[i][2]=1;

        }

//        f(i,2,5)
//        cout << dp[i][1] << " " << dp[i][2] << endl;

          if(dp[k][1]==1)
            cout <<  "First";
          else
            cout << "Second" ;
            
          
      }


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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    
    return 0;
}



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

int calcul(string s1, string s2)
{
    vector<char> v;
    for (int i=0; i<s1.size(); i++)
        for (int j=0; j<s2.size(); j++)
        {
            if (s1[i] == s2[j])
            {
                if (find(v.begin(), v.end(), s1[i]) != v.end())
                    continue;
                else 
                    v.push_back(s1[i]);
            }
        }
    return v.size();
}

int main() 
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int m = 0;
    // string s1="abc";
    // string s2="def";
    // cout << calcul (s1,s2);
    for (int i=0; i<n-1; i++)
    {
        string s1 = s.substr(0,i+1);
        string s2 = s.substr(i+1,n-i);
        m = max(m, calcul(s1, s2));
        // cout << s1 << " " << s2 << endl;
    }
    cout << m;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

void _main() {
    string s;
    cin >> s;
    if (s == "Sunny") cout << "Cloudy" << endl;
    else if (s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main(){
  int N,M,X;
  cin >> N >> M >>X;
  vector<int> A(N);
  int left = 0;
  int right = 0;
  for (int i = 0; i < M; i++) {
    cin >> A[i];
    if(A[i]<X){
      right++;
    } else {
      left++;
    }
  }
  cout << min(left,right) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<list>
using namespace std;
#define inf 0x3f3f3f3f


int main(){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if(x-r>=0 && x+r<=w && y-r>=0 && y+r<=h)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////

int main() {
	ll N, K;
	cin >> N >> K;
	vector<vector<ll>> g(N + 1);

	repn(i, N) {
		ll a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	vector<vector<ll>> dist(N + 1, vector<ll>(N + 1,-1));

	repn(v, N) {
		queue<ll> q;
		dist[v][v] = 0;
		q.push(v);

		while (!q.empty()) {
			ll w = q.front();
			q.pop();
			for (ll u : g[w]) {
				if (dist[v][u] != -1) { continue; }
				q.push(u);
				dist[v][u] = dist[v][w] + 1;
			}
		}
	}

	ll ans = 0;

	if (K % 2 == 0) {
		repn(v, N) {
			ll t = 0;
			repn(u, N) { if (dist[v][u] <= K / 2) { t++; } }
			ans = max(ans, t);
		}
	}

	else {
		repn(v, N) {
			for (ll w : g[v]) {
				ll t = 0;
				repn(u, N) { if (dist[v][u] <= K / 2 || dist[w][u] <= K / 2) { t++; } }
				ans = max(ans, t);
			}
		}
	}

	cout << N - ans << endl;
	
}


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

int main() {
    //
    long long n, m;

    cin >> n >> m;
    vector<bool> vec(n + 1, true);
    vector<long long> dp(n + 1, 0);

    for (int i = 0; i < m; i++) {
        long long k;
        cin >> k;
        vec.at(k) = false;
    }

    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        if(i==1){
            if (vec.at(i) == true) dp[i] = 1;
            continue;
        }

        if (vec.at(i - 1) == true) dp[i] += dp[i - 1];
        if (vec.at(i - 2) == true) dp[i] += dp[i - 2];
        dp[i] %= 1000000007;
    }

    cout << dp[n];
    //
}


Measured memory_bytes: 4024
#!/usr/bin/env perl

use strict;
use warnings;
use feature 'say';

chomp(my $input = <STDIN>);
my ($a, $b, $c) = split(/ /, $input);
my $res = 0;
if ($c <= $a + $b){
    $res = $c + $b;
}else{
    $res =  $a + $b + 1 + $b;
}
say "$res";


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

int main(){
  int n, y;
  cin >> n >> y;
  for(int i=0; i<=n; ++i){
    for(int j=0; i+j<=n; ++j){
      int k = n - i - j;
      if(10000*i + 5000*j + 1000*k == y){
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 3608
#X = ["a", "ba", "zxx", "abb", "ab"]
#print(sorted(X))

s = str(input())
K = int(input())
ans = []
N = len(s)

for i in range(N):
  y = min(N + 1, i + K + 1)
  for j in range(i + 1,y):
    x = s[i:j]
    if x not in ans:
      ans.append(x)
#print(ans)
  
print(sorted(ans)[K - 1])


Measured memory_bytes: 40688
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class ADivideACuboid {
public:
    void solve(std::istream &in, std::ostream &out) {
        int a, b, c;
        in >> a >> b >> c;
        ll res = 0;
        if (a % 2 and b % 2 and c % 2) {
            if (a < b) {
                swap(a, b);
            }
            if (a < c) {
                swap(a, c);
            }
            res = (ll) b * c;
        }
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    ADivideACuboid solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];

//big priority queue
priority_queue <ll> pql;
priority_queue <P> pqp;

//small priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;

//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}


ll i,j,k,ii,jj,n,m;
ll a,b,c,d,e,g,h,r,l,w,num,ans;
ll x[500005],y[500005],z[500005];
ll dp[300005];

ll dfs(ll v){
	ll a = 0;
	if(dp[v] != 0){
		return dp[v];
	}
	for(int i=0;i<G[v].size();i++){
		a = max(a,dfs(G[v][i]));
	}
	a++;
	dp[v] = a;
	return a;
}

int main(){    
    cin >> n >> m;
	for(i=0;i<m;i++){
		cin >> a >> b;
		G[a].pb(b);
	}
	for(int i=1;i<=n;i++){
		if(dp[i] == 0){
			dp[i] = dfs(i);
		}
	}
	ans = -1;
	for(i=1;i<=n;i++){
		ans = max(ans,dp[i]);
	}	
	p(ans-1);
    return 0;
}


Measured memory_bytes: 31360
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
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; }

int main(){
  int n; cin >> n;
  vi sum(n);
  int i = 1;
  for(; sum[i-1] <= n; i++){
    sum[i] += sum[i-1]+i;
  }
  for(int j = 1; j < i; j++){
    if(sum[i-1]-n != j) cout << j << endl;
  }
  cout << "\n";
  return 0;
}


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

int main(){
	char s[3];
	scanf("%s",s);
	int count = 0;

	for(int i=0; i<3; i++){
		if(s[i] == '1'){
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[1000],c1=0,c2=0;
    cin>>n;
    bool flag=false;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]%2==0)
        {
            c1++;
            if(a[i]%3==0 || a[i]%5==0)
                c2++;
        }    
    }
    if(c1==c2)
        cout<<"APPROVED"<<endl;
    else
        cout<<"DENIED"<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	// b := bufio.NewReaderSize(f, 4*1024)
	return ""
}

var H, W int
var table [][]byte
var dp [][]int64

func main() {
	H = nextInt()
	W = nextInt()
	dp = make([][]int64, H)
	for i, _ := range dp {
		dp[i] = make([]int64, W)
	}
	table = make([][]byte, H)

	for i := 0; i < H; i++ {
		n := nextString()
		table[i] = []byte(n)
	}
	div := int64(math.Pow(float64(10), float64(9)) + 7)
	dp[0][0] = 1
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if string(table[i][j]) == "#" {
				dp[i][j] = 0
			} else {
				if i < 1 && j < 1 {
				} else if i < 1 {
					dp[i][j] = dp[i][j-1]
				} else if j < 1 {
					dp[i][j] = dp[i-1][j]
				} else {
					dp[i][j] = dp[i][j-1] + dp[i-1][j]
				}
				if dp[i][j] > div {
					dp[i][j] -= div
				}
			}
		}
	}
	fmt.Println(dp[H-1][W-1])
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func nextString() string {
	return nextReader()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinIn2Values(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define maxn 1000
using namespace std;
typedef long long ll;
string S,T,U;
int A,B;
int main(void)
{
    cin>>S>>T>>A>>B>>U;
//    scanf("%s %d",S,&A);
    if(U == S)
    {
        cout<<A-1<<" "<<B<<endl;
    }else
        cout<<A<<" "<<B-1<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f40;
const long long mod=1e9+7;
const long double PI = acos(0);
template <class T>void UNIQUE(vector<T> &x){
	sort(all(x));
	x.erase(unique(all(x)), x.end());
}

// }}} End Header
ll n;
ll dfs(string s){
	ll ans = 0;
	string list = "753";

	if((int)s.size() > 0){
		if(stoll(s) > n) return ans;
		bool ok = true;
		for(auto x : list) if(s.find(x) == string::npos) ok = false;
		if(ok) ans++;
	}
	for(auto x : list){
		s.push_back(x);
		ans+=dfs(s);
		s.pop_back();
	}
	return ans;
}


int main() {
	cin >> n;
	string s = "";
	cout << dfs(s) << endl;
	return 0;
}

Measured memory_bytes: 3544