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

int main() {
    int W, a, b;
    cin >> W >> a >> b;
    int ans = 0;
    if(a < b){
        ans = b - a - W;
    } else{
        ans = a - b - W;
    }
    ans = max(ans, 0);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin>>n;
	vi p(n);
	int c=0;
	rep(i,n)cin>>p[i];
	repa(i,1,n-1){
		if(p[i] < p[i-1] && p[i] > p[i+1])c++;
		else if(p[i] < p[i+1] && p[i] > p[i-1])c++;
	}	
	cout<<c;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val list = readLine()!!.split(" ").map { it.toInt() }
    val numList = readLine()!!.split(" ").map { it.toInt() }

    val sortedNumList = numList.sortedDescending()

    var summary = 0

    // LOOK indexが1ベースの場合はuntilで調整する
    for (i in 0 until list[1])
        summary += sortedNumList[i]

    println(summary)
}

Measured memory_bytes: 36060
s = input()
a = int(s[:2])
b = int(s[2:])

if 1 <= a <= 12 and not (1 <= b <= 12):
  print("MMYY")
elif not (1 <= a <= 12) and 1 <= b <= 12:
  print("YYMM")
elif 1 <= a <= 12 and 1 <= b <= 12:
  print("AMBIGUOUS")
else:
  print("NA")

Measured memory_bytes: 3060
package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	Nstr := scanner.Text()
	N, _ := strconv.Atoi(Nstr)
	//fmt.Printf("N: %d\n", N)

	scanner.Scan()

	strinput := scanner.Text()

	strlist := strings.Split(strinput, " ")

	//fmt.Printf("%s, %d\n", strlist[0], len(strlist))

	if N*2 != len(strlist) {
		os.Exit(0)
	}

	Llist := make([]int, 0)
	for i := 0; i < len(strlist); i++ {

		Lval, _ := strconv.Atoi(strlist[i])
		Llist = append(Llist, Lval)
	}

	sort.Ints(Llist)

	var Sum int
	Sum = 0
	for i := 0; i < len(Llist); i += 2 {
		val1 := Llist[i]
		val2 := Llist[i+1]

		if val1 < val2 {
			Sum += val1
		} else {
			Sum += val2
		}

	}

	fmt.Printf("%d\n", Sum)

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll w,i=0;
  string S;
  cin >> S >> w;
  while(i<S.size()){
    cout << S.at(i);
    i+=w;
  }
  cout << endl;
  
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int a, p;
   cin >> a >> p;
   cout << (3 * a + p) / 2 << endl;
   return 0;
}


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

using namespace std;

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

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

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

    vector<int> a(5);
    int k;
    for (int i = 0; i < 5; i++)
        cin >> a[i];
    cin >> k;
    bool f = false;
    for (int i = 0; i < 5; i++)
    {
        for (int j = i + 1; j < 5; j++)
        {
            if (abs(a[i] - a[j]) > k)
                f = true;
        }
    }
    cout << (f ? ":(" : "Yay!") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

vector<int> read_vec(int n){
    vector<int> ret(n);
    for (int i = 0; i < n; i++){
        cin >> ret[i];
    }
    return ret;
}

int main() {
    int n;
    long long p = 1;
    cin >> n;
    vector<int>as(n), bs(n);
    for (int i = 0; i < n; i++){
        cin >> as[i];
    }
    sort (as.begin(), as.end());
    for (int i = 0; i < n; i++){
        bs[i] = abs (i - (n - i - 1));
    }
    sort (bs.begin(), bs.end());
    for (int i = 0; i < n; i++){
        if (as[i] != bs[i]){
            cout << 0 << endl;
            return 0;
        }
        if ((i + 1) % 2 == 0){
            p = p * 2;
            p = p % 1000000007;
        }
    }
    cout << p << endl;
}

Measured memory_bytes: 1024
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanInt()
	w := scanInt()

	if w >=s {
		fmt.Fprintln(wr, "unsafe")
	} else {
		fmt.Fprintln(wr, "safe")
	}
}


Measured memory_bytes: 1760
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

#define MAX 100005

int main(void) {
    int n,d,x;
    cin >> n >> d >> x;
    int p[10][10];
    rep(i,d)rep(j,n)cin >> p[i][j];
    int dp[MAX];
    int ans = x;
    rep(i,d-1){
        rep(j,MAX){
            if(j <= ans)dp[j] = j;
            else dp[j] = 0;
        }
        int ma = ans;
        rep(j,n)rep(k,ans+1){
            if(k < p[i][j])continue;
            dp[k] = max(dp[k], dp[k - p[i][j]]+p[i+1][j]);
            ma = max(ma, dp[k]);
        }
        ans = ma;
    }
    cout << ans << endl;
}



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

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n,p=1,mx=1e18;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++){
        int x=a[i];
        if(x==0){
            cout << 0;
            return 0;
        }
        if(mx/x>=p)p*=x;
        else{
            cout << -1 ;
            return 0;
        }
    }
    cout << p;
}


Measured memory_bytes: 4436
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
using namespace std;
typedef long long ll;
const int maxn = 200005;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "w", stdout);
#endif
  int a ,b;
  cin>>a>>b;
  if (b%a==0)cout<<a+b<<endl;
  else cout<<b-a<<endl;
  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define int long long
//for set
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   
// for multiset
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_multiset;

#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return ((a%md)*(b%md))%md;}
int addmod(int a, int b, int md) {return (a+b)%md;}
int submod(int a, int b, int md) {return (((a-b)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
int mat[20][20], prec[(1<<16)], dp[(1<<16)], vis[(1<<16)], n;
void solve(int mask) {
	// cout<<mask<<endl;
	if(mask==0) {
		vis[0]=1;
		return;
	}
	for(int i = mask; i > 0; i = (i-1) & mask){
    	if(!vis[(i^mask)])
    		solve((i^mask));
    	dp[mask]=max(dp[mask],dp[(i^mask)]+prec[i]);
    }
    vis[mask]=1;
}
int32_t main(void)
{
	// IOS;
	cin>>n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++)
			cin>>mat[i][j];
	}
	for(int mask = 1; mask < (1<<n); mask++) {
		for(int i = 0; i < n; i++) {
			if(__check(mask,i)) {
				prec[mask] = prec[__unset(mask,i)];
				for(int j = 0; j < n; j++) {
					if(__check(mask,j))
						prec[mask] += mat[i][j];
				}
				break;
			}
		}
	}
	solve((1<<n)-1);
	cout<<dp[(1<<n)-1]<<endl;
	time();	
	return 0;
}

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

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

    char A[n][n], B[m][m];

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

    for(int i = 0; i < m; i++){
        for(int j = 0; j < m; j++){
            cin >> B[i][j];
        }
    }

    for(int i = 0; i <= n-m; i++){
        for(int j = 0; j <= n-m; j++){
            // check
            bool res = true;
            for(int k = 0; k < m; k++){
                for(int l = 0; l < m; l++){
                    if(B[k][l] != A[i+k][j+l])  res = false;
                }
            }

            if(res){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::{input,fastout};

#[fastout]
fn main() {
  input!{n: usize, a: [usize;n]};
  if a.iter().any(|&x| x == 0) {
    println!("0");
    return;
  }
  let mut r = 1usize;
  for a in a.into_iter() {
    r = match r.checked_mul(a) {
      Some(v) => v,
      None => {
        println!("-1");
        return;
      }
    }
  }
  if r > 10usize.pow(18) {
    println!("-1");
  } else {
    println!("{}", r);
  }
}


Measured memory_bytes: 4564
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,c[100],i,a=0,b=0;
	bool q=true;
	cin>>n;
	for (i=0;i<n;i++){
		cin>>c[i];
	}
	sort(c,c+n);
	for (i=n-1;i>=0;i--){
		if (q==true){
			a+=c[i];
			q=false;
		}
		else {
			b+=c[i];
			q=true;
		}
	}
	cout<<a-b;
	return 0;
}

Measured memory_bytes: 256
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int n=gi();
	    long[] x=new long[n];
	    long[] l=new long[n];
	    long[] ae=new long[n];
	    List<Pair<Long, Long>> li=new ArrayList<Pair<Long, Long>>();

	    for (int i=0; i<n;i++) {
	    	x[i]=gl();
	    	l[i]=gl();
	    	Pair<Long, Long> p=new Pair<Long,Long>(x[i]+l[i], x[i]-l[i]);
	    	li.add(p);
	    }

	    Collections.sort(li);
	    
	    int c=0;
	    long last=Long.MIN_VALUE;
	    for (int i=0; i< li.size();i++) {
	    	Pair<Long, Long> p= li.get(i);
	    	if (p.getValue()>=last) {
	    		last=p.getKey();
	    		c++;
	    	}
	    }

	    System.out.println(c);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}

	public static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> implements Comparable<Pair<K, V>>{
		/** serialVersionUID. */
	    private static final long serialVersionUID = 6411527075103472113L;

	    public Pair(final K key, final V value) {
	        super(key, value);
	    }

		@Override
		public int compareTo(Pair<K, V> o) {

			Comparable key = (Comparable)this.getKey();
			Comparable key2 = (Comparable)o.getKey();

			return key.compareTo(key2);
		}


	}
}

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))

int main()
{
    ll i,j,k,l,m,n,a,b,kela,cnt,fin=0;

    cin >> n >> a >> b;

    ll ar[n+10];

    for(i=0; i<n; i++)
        cin>>ar[i];

    sort(ar,ar+n);
    reverse(ar,ar+n);

    ll low = 0,high=1e10,mid,kota,ans;

    bool ok = true;

    while(high-low > 1)
    {
        mid = (low+high)/2;
        m = mid*b;
        ok = true;
        cnt = 0;
        for(i=0; i<n; i++)
        {
            l = ar[i];
            l -= m;
            if(l<=0)continue;
            cnt += (l+(a-b)-1)/(a-b);

        }
        if(cnt<=mid)
        {
           high = mid;
        }
        else
        {
            low = mid;
        }
    }
    cout << high <<endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>	
using namespace std;
typedef long long ll;
#define bay_bay return 0;
#define fori(n) for(int i=0;i<n;++i)
#define for1(n) for(int i=1;i<=n;i+=3)
#define all(v) ((v).begin()), ((v).end())	
#define sz(v) v.size()
#define endl "\n"
constexpr auto EPS = 1e-9;
#define ff fflush(stdout);
const int mod = 1000000007LL;
clock_t T;
#define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl
void GOAT()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	//freopen("in.txt", "r", stdin);
	//freopen("output.txt", "w	", stdout);
#else
#endif
}
ll arr[100009],dp[100009], n;

int main()
{
	GOAT();
	cin >> n;
	for (int i = 1; i <= n;i++)
		cin >> arr[i];
	arr[0] = arr[1];
	for (int i = 1; i <= n; i++)
	{
		if (i < 2)dp[i] = abs(arr[i]- arr[i - 1]);
		else {
			ll ch1 = dp[i - 1] + abs(arr[i] - arr[i - 1]);
			ll ch2 = dp[i - 2] + abs(arr[i] - arr[i - 2]);
			dp[i] = min(ch1, ch2);
		}

	}
	cout << dp[n] << endl;
}

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

using ll = long long;

ll f(ll x, ll y) { return x + 10000 + (y + 10000) * 20000; }

int main() {

  int n;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    map<ll, map<int, ll>> mp;
    for (int i = 0; i < n; i++) {
      ll x, y;
      cin >> x >> y;
      ll a[6];
      for (int j = 0; j < 6; j++)
        cin >> a[j];
      swap(a[3], a[2]);
      int down = 4;
      string s;
      cin >> s;
      mp[f(x, y)][i] = a[down];
      for (auto &c : s) {
        if (c == 'L') {
          x -= 1;
          ll b[6] = {a[5], a[4], a[2], a[3], a[0], a[1]};
          for (int j = 0; j < 6; j++)
            a[j] = b[j];
          mp[f(x, y)][i] = a[down];
        } else if (c == 'R') {
          x += 1;
          ll b[6] = {a[4], a[5], a[2], a[3], a[1], a[0]};
          for (int j = 0; j < 6; j++)
            a[j] = b[j];
          mp[f(x, y)][i] = a[down];
        } else if (c == 'F') {
          y -= 1;
          ll b[6] = {a[0], a[1], a[4], a[5], a[3], a[2]};
          for (int j = 0; j < 6; j++)
            a[j] = b[j];
          mp[f(x, y)][i] = a[down];
        } else {
          y += 1;
          ll b[6] = {a[0], a[1], a[5], a[4], a[2], a[3]};
          for (int j = 0; j < 6; j++)
            a[j] = b[j];
          mp[f(x, y)][i] = a[down];
        }
      }
    }
    ll size = 1LL << n;
    vector<vector<ll>> score(size);
    for (int i = 0; i < size; i++)
      score[i].resize(n);
    for (auto &v : mp) {
      ll bit = 0;
      for (auto &w : v.second) {
        bit |= 1LL << w.first;
      }
      for (auto &w : v.second) {
        score[bit][w.first] += w.second;
      }
    }
    vector<ll> dp(size);
    dp[0] = 0;
    for (int i = 0; i < size; i++) {
      for (int j = 0; j < n; j++) {
        if ((i >> j) & 1) {
          continue;
        }
        ll next = i | (1LL << j);
        ll sum = 0;
        for (ll u = size - 1; u >= 0; u--) {
          u &= i;
          sum += score[u | (1LL << j)][j];
        }
        dp[next] = max(dp[next], dp[i] + sum);
      }
    }
    cout << dp[size - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 8212
#include <bits/stdc++.h>
using namespace std;
 
using bellman_cost = int;
template<class V, class E>
struct Graph
{
	int sz;
	vector<V> v;
	vector<vector<E>> e;
	Graph(int n) : sz(n), v(n), e(n) {}
	template<class... Args>
	inline void assign_vertex(int pos, Args... args) {
		v[pos] = V(args...);
	}
	template<class... Args>
	inline void add_edge(int pos, Args... args) {
		e[pos].emplace_back(args...);
	}
	inline int size() {
		return sz;
	}
};
 
template<class T>
struct Vertex_Cost
{
	T cost;
	bool valid = false;
	Vertex_Cost(T v1) : cost(v1) {}
	Vertex_Cost() {}
};
using vertex = Vertex_Cost<bellman_cost>;
 
template<class T>
struct Edge_Cost
{
	int to;
	T cost;
	Edge_Cost(int t, T c) : to(t), cost(c) {}
	Edge_Cost() {}
};
using edge = Edge_Cost<bellman_cost>;
using graph = Graph<vertex, edge>;
 
template<class T, class V, class E>
void Bellmanford(Graph<V, E>& G, int s, T INF_COST)
{
	auto &v = G.v;
	auto &e = G.e;
	for (auto& vv : v) vv.cost = INF_COST, vv.valid = false;
	v[s].cost = 0;
	v[s].valid = true;
	for (int i = 0; i + 1 < (int) v.size(); i++) {
		for (int j = 0; j < (int) v.size(); j++) {
			for (auto& x: e[j]) {
				if (v[j].cost == INF_COST) continue;
				v[x.to].cost = min(v[x.to].cost, v[j].cost + x.cost);
				v[x.to].valid = true;
			}
		}
	}
	auto valid_check = [&](auto f, int pos) {
		if (!v[pos].valid) return;
		v[pos].valid = false;
		for (auto& y: e[pos]) {
			f(f, y.to);
		}
	};
	for (int i = 0; i < (int) v.size(); i++) {
		for (auto& x: e[i]) {
			if (v[i].cost == INF_COST) continue;
			if (v[x.to].cost > v[i].cost + x.cost) {
				valid_check(valid_check, x.to);
			}
		}
	}
}
 
 
void solve(long long N, long long M, long long P, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C) {
	graph g(N);
	for (int i = 0; i < M; i++) {
		g.add_edge(A[i]-1, B[i]-1, -(C[i]-P));
	}
	Bellmanford(g, 0, INT_MAX);
	if (!g.v[N-1].valid) cout << -1 << endl;
	else cout << max(-g.v[N-1].cost, 0) << endl;
}
 
signed main() {
	long long N;
	scanf("%lld",&N);
	long long M;
	scanf("%lld",&M);
	long long P;
	scanf("%lld",&P);
	std::vector<long long> A(M);
	std::vector<long long> B(M);
	std::vector<long long> C(M);
	for(int i = 0 ; i < M ; i++){
		scanf("%lld",&A[i]);
		scanf("%lld",&B[i]);
		scanf("%lld",&C[i]);
	}
	solve(N, M, P, std::move(A), std::move(B), std::move(C));
	return 0;
}

Measured memory_bytes: 512
n, k, l = map(int, input().split())

ar = [i for i in range(n)]
ah = [0 for _ in range(n)]
br = [i for i in range(n)]
bh = [0 for _ in range(n)]

def root(l, i):
  if l[i] == i:
    return i
  else:
    l[i] = root(l, l[i])
    return l[i]

def union(l, h, i, j):
  ip = root(l, i)
  jp = root(l, j)
  if ip == jp:
    return
  else:
    if h[ip] < h[jp]:
      l[ip] = jp
    elif h[ip] > h[jp]:
      l[jp] = ip
    else:
      if ip < jp:
        l[jp] = ip
        h[ip] += 1
      else:
        l[ip] = jp
        h[jp] += 1

for _ in range(k):
  p, q = map(int, input().split())
  if p < q:
    union(ar, ah, p-1, q-1)
  else:
    union(ar, ah, q-1, p-1)

for _ in range(l):
  r, s = map(int, input().split())
  if r < s:
    union(br, bh, r-1, s-1)
  else:
    union(br, bh, s-1, r-1)

abd = {}
for a, b in zip(ar, br):
  if (root(ar, a), root(br, b)) in abd:
    abd[(root(ar, a), root(br, b))] += 1
  else:
    abd[(root(ar, a), root(br, b))] = 1

for a, b in zip(ar, br):
  print(abd[(root(ar, a), root(br, b))])


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

int main(){
    string S;
    cin >> S;
    bool Flag = false;
    
    if (S[0] == S[1] && S[1] == S[2]) {
        Flag = true;
    } else if (S[1] == S[2] && S[2] == S[3]) {
        Flag = true;
    }
    
    cout << ((Flag) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<complex>

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

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  int b,c1,c2,q1,q2;
  while(cin>>q1, q1){
    cin>>b>>c1>>c2>>q2;
    /*
      b = c1 * x + c2 * (q1 - x);
      b = (c1 - c2) * x + c2 * q1;
      x = (b - c2 * q1) / (c1 - c2);
    */
    int aizu;
    int norm;

    if(c1 <= c2){
      aizu = min(q2, b / c1);
    }else{
      if(b >= q1 * c1){
        aizu = min(q2, b / c1);
      }else{
        aizu = min(q2, (b - c2 * q1) / (c1 - c2));
      }
    }
    int money = b - c1 * aizu;
    if(aizu == 0) goto err;
    //printf("aizu = %d\n", aizu);
    //printf("money = %d\n",money);
    if(money < 0) goto err;
    norm = money / c2;
    if(norm + aizu < q1) goto err;
    cout << aizu << " " << norm << endl;
    continue;
  err:
    cout << "NA" << endl;
  }
  return 0;
}

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

const double PI = 2 * acos(0.0);
const double EPS = 1e-6;
double teta;

bool eq(double a, double b)
{
    return fabs(a-b) <= EPS;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> teta;
    // if (360%teta == 0)
    // {
    //     cout << 360/teta << '\n';
    //     return 0;
    // }
    teta = teta/180 * PI; // ubah teta jadi radian
    double x = cos(PI/2); // langkah ke-1
    double y = sin(PI/2);
    int ans = 1; // ans set jadi 1
    int cur = 1; // cur juga 1 
    while (!eq(x,0) || !eq(y,0))
    {
        // cout << "vector " << ans << " = " << x << ' ' << y << '\n';
        x += cos((PI/2) + (cur*teta));
        y += sin((PI/2) + (cur*teta));
        cur++;
        ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4108
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long a, b, r, tmp, x;
    cin >> a >> b;

    x = a*b;
    if(a<b){
      tmp = a;
      a = b;
      b = tmp;
    }
 


    r = a % b;
    while(r!=0){
      a = b;
      b = r;
      r = a % b;
    }

    cout << x/b << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <math.h>
using namespace std;

char game(char k);
string a, b, c;
int main()
{
	cin >> a >> b >> c;
	char ans = game('a');
	if (ans == 'a') {
		cout << "A" << endl;
	} else if (ans == 'b') {
		cout << "B" << endl;
	} else {
		cout << "C" << endl;
	}
}

char game(char k) {
	char tmp;
	if (k == 'a') {
		if (a.length() == 0) {
			return 'a';
		}
		tmp = a[0];
		a = a.substr(1, a.length() - 1);
		game(tmp);
	} else if (k == 'b') {
		if (b.length() == 0) {
			return 'b';
		}
		tmp = b[0];
		b = b.substr(1, b.length() - 1);
		game(tmp);
	} else if (k == 'c') {
		if (c.length() == 0) {
			return 'c';
		}
		tmp = c[0];
		c = c.substr(1, c.length() - 1);
		game(tmp);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const ll INF = LLONG_MAX / 10;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int n;
vector<pii> tree;
vi leaves, nosave, ans, depth;

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	cin >> n;
	tree.resize(n);
	REP(i, n - 1)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		if (a == n - 1) a = n-1;
		if (b == n - 1) b = n-1;
		tree[i] = pii(a, b);
	}
	vi per;
	stack<int> st;
	st.push(0);
	while (!st.empty())
	{
		int v = st.top(); st.pop();
		per.push_back(v);
		if (v == n - 1) continue;
		st.push(tree[v].first);
		st.push(tree[v].second);
	}
	depth.resize(n);
	leaves.resize(n);
	nosave.resize(n);
	ans.resize(n);
	REP(i, per.size())
	{
		int v = per[i];
		if (v == n - 1) continue;
		int l = tree[v].first, r = tree[v].second;
		depth[l] = depth[v] + 1;
		depth[r] = depth[v] + 1;
	}
	reverse(ALL(per));
	REP(i, per.size())
	{
		int v = per[i];
		if (v == n - 1)
		{
			leaves[v] = 1;
			nosave[v] = 0;
		}
		else
		{
			int l = tree[v].first, r = tree[v].second;
			leaves[v] = leaves[l] + leaves[r];
			nosave[v] = nosave[l] + nosave[r] + leaves[v];
		}
	}
	REP(i, per.size())
	{
		int v = per[i];
		if (v == n - 1) ans[v] = 0;
		else
		{
			ans[v] = INF;
			int l = tree[v].first, r = tree[v].second;
			chmin(ans[v], nosave[l] + leaves[l] + ans[r] + 1);
			chmin(ans[v], ans[l] + nosave[r] + leaves[r] + 1);
			chmin(ans[v], ans[l] + ans[r] + depth[v] + 2);
		}
	}
	cout << ans[0] << endl;
	return 0;
}

Measured memory_bytes: 31180
#include <bits/stdc++.h>
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;

int main() {
	IOS;
	string s;
	cin >> s;
	map<string, int> ans;
	// SUN, MON, TUE, WED, THU, FRI, or SAT.
	ans["SUN"] = 7;
	ans["MON"] = 6;
	ans["TUE"] = 5;
	ans["WED"] = 4;
	ans["THU"] = 3;
	ans["FRI"] = 2;
	ans["SAT"] = 1;
    cout << ans[s];
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = list(map(int,input().split()))

t = 0
for i in range(n):
  t += a[i]
  
b = t/(4*m)

c = 0
for j in range(n):
  if a[j] >= b:
    c += 1

if c >= m :
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
a = list(map(int,input().split()))
b = list(map(int,input().split()))

n = a[0]
m = a[1]
co = 0
for i in range(n):
  if b[i]>=sum(b)/(4*m):
    co = co+1
if co >= m:
  print("Yes")
else:
  print("No")

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

const int mod = 1000000007;
//const int mod = 998244353;
const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

struct mint {
  ll x;
  mint(ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, 0, n) cin >> s[i];
    map<string, int> mp;
    rep(i, 0, n) mp[s[i]]++;
    vector<string> ans;
    int mx = 0;
    for(auto i : mp){
        mx = max(mx, i.second);
    }
    for(auto i : mp){
        if(i.second == mx) ans.push_back(i.first);
    }
    sort(ans.begin(), ans.end());
    for(auto i : ans){
        cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 33416
n,k=map(int,input().split())
l=[input().split() for _ in range(n)]
w=[[0]*(k+1) for _ in range(k+1)]
b=[[0]*(k+1) for _ in range(k+1)]
for i in range(n):
    if ((int(l[i][0])//k+int(l[i][1])//k)%2==0)^(l[i][2]=='W'):
        b[int(l[i][0])%k][int(l[i][1])%k]+=1
    else:
        w[int(l[i][0])%k][int(l[i][1])%k]+=1

for i in range(1,k+1):
    b[0][i]+=b[0][i-1]
    b[i][0]+=b[i-1][0]
    w[0][i]+=w[0][i-1]
    w[i][0]+=w[i-1][0]
for i in range(1,k+1):
    for j in range(1,k+1):
        b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1]
        w[i][j]+=w[i-1][j]+w[i][j-1]-w[i-1][j-1]

ans=0
for i in range(k+1):
    for j in range(k+1):
        ans=max(ans,b[k][k]-b[i][k]-b[k][j]+2*b[i][j]+w[i][k]+w[k][j]-2*w[i][j])
        ans=max(ans,w[k][k]-w[i][k]-w[k][j]+2*w[i][j]+b[i][k]+b[k][j]-2*b[i][j])
print(ans)

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

typedef long long ll;
typedef unsigned long long ull;

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

  double a = 0;
  for (ll i = 0; i < n; ++i) {
    ll tmp;
    cin >> tmp;
    a += double(1) / double(tmp);
  }

  cout << fixed << setprecision(10);
  cout << double(1) / a << endl;
  
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"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 scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := scanNums(n + 1)
	b := scanNums(n)
	monster := 0
	for i := 0; i < n; i++ {
		for j := i; j < i+2; j++ {
			if b[i] >= a[j] {
				b[i] -= a[j]
				monster += a[j]
				a[j] = 0
			} else {
				a[j] -= b[i]
				monster += b[i]
				b[i] = 0
			}
		}
	}
	fmt.Println(monster)
}


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

int main() {
  vector<int> a(5);
  for(int i=0;i<5;i++) {
    cin >> a[i];
  }
  int k;
  cin >> k;
  bool ok = true;
  for(int i=0;i<5;i++){
    for(int j=i+1;j<5;j++) {
      if(a[j]-a[i]>k) {
        ok = false;
        break;
      }
    }
  }

  if(ok) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.Stream;

class Main{
	private void solve(){
		int n=gInt();
		int[] b=new int[n];
		Arrays.fill(b,-1);
		b[0]=1;
		for(int i:rep(gInt())){
			int f=gInt()-1,t=gInt()-1;
			if(b[f]>0){
				--b[f];
				b[t]=Math.abs(b[t])+1;
			}else{
				++b[f];
				if(b[t]>0)
					++b[t];
				else
					--b[t];
			}
		}
		System.out.println(
				REPS(n).filter(i->b[i]>0)
						.count());
	}


	public static void main(String[]$){
		new Main().solve();
	}

	static Scanner s=new Scanner(System.in);


	static int gInt(){
		return s.nextInt();
	}
	static long gLong(){
		return s.nextLong();
	}
	static long gDouble(){
		return s.nextLong();
	}


	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}

	static class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{

		int to,cur,d;

		Range(int from,int to,int d){
			this.cur=from-d;
			this.to=to;
			this.d=d;
		}

		Range(int n){
			this(0,n-1,1);
		}

		@Override
		public Iterator<Integer> iterator(){
			return this;
		}

		@Override
		public boolean hasNext(){
			return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
		}

		@Override
		public int nextInt(){
			return cur+=d;
		}
	}


	static IntStream REPS(int v){
		return IntStream.range(0,v);
	}

	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}


	static IntStream ints(int n){
		return REPS(n).map(i->gInt());
	}

	static Stream<String> strs(int n){
		return REPS(n).mapToObj(i->s.next());
	}

}


Measured memory_bytes: 65536
#include <cstdio>
#include <set>

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

  std::multiset<long> ls, rs;
  long qs,a,b;
  scanf("%ld%ld%ld", &qs, &a, &b);
  ls.insert(a);
  rs.insert(a);
  long min_val = b;
  for(int qi = 0; qi < Q-1; qi++){
    scanf("%ld", &qs);
    if(qs == 1){
      scanf("%ld%ld", &a, &b);
      auto lend = *(--ls.end());
      auto rbegin = *(rs.begin());
      if(a < lend){
        ls.erase(--ls.end());
        rs.insert(lend);
        ls.insert(a); ls.insert(a);
        min_val += lend-a+b;
      }else if(a > rbegin){
        rs.erase(rs.begin());
        ls.insert(rbegin);
        rs.insert(a); rs.insert(a);
        min_val += a-rbegin+b;
      }else{
        ls.insert(a); rs.insert(a);
        min_val += b;
      }
    }else{
      printf("%ld %ld\n", *(--ls.end()), min_val);
    }
  }

  return 0;
}



Measured memory_bytes: 18944
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int N;
int bit[500005];
map<int, int> amap;

void add(int x, int index) {
  int tmp;
  if(amap[x]>-1) {
    tmp = index;
    while(tmp<=N) {
      bit[tmp]++;
      tmp += tmp & -tmp;
    }
    tmp = amap[x];
    while(tmp<=N) {
      bit[tmp]--;
      tmp += tmp & -tmp;
    }
  }
  else {
    tmp = index;
    while(tmp<=N) {
      bit[tmp]++;
      tmp += tmp & -tmp;
    }
  }
  amap[x] = index;
}

int sum(int x) {
  int ans = 0;
  while(x>0) {
    ans += bit[x];
    x -= x & -x;
  }
  return ans;
}

int main() {
  int Q;
  cin>>N>>Q;
  for(int i=1;i<=N;++i) amap[i] = -1;
  int c[N];
  for(int i=0;i<N;++i) cin>>c[i];
  vector<tuple<int, int, int> > arr(Q);
  int l, r;
  for(int i=0;i<Q;++i) {
    cin>>l>>r;
    arr[i] = make_tuple(r, l, i);
  }
  sort(arr.begin(), arr.end());
  int ans[Q];
  int index = 0;
  for(int i=0;i<Q;++i) {
    while(index<get<0>(arr[i])) {
      add(c[index], index+1);
      index++;
    }
    ans[get<2>(arr[i])] = sum(get<0>(arr[i])) - sum(get<1>(arr[i])-1);
  }
  for(int i=0;i<Q;++i) cout<<ans[i]<<endl;
}


Measured memory_bytes: 38988
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    c = LI()
    dp = [float("inf")]*(n+1)
    dp[0] = 0
    for i in range(m):
        ci = c[i]
        for j in range(n):
            nj = j+ci
            if nj <= n:
                nd = dp[j]+1
                if nd < dp[nj]:
                    dp[nj] = nd
    print(dp[n])
    return

#Solve
if __name__ == "__main__":
    solve()



Measured memory_bytes: 7980
#include<stdio.h>

int main(void){
  char N[4];
  scanf("%s",N);
  if(N[2]=='7')
    printf("Yes");
  
  else if(N[1]=='7')
    printf("Yes");
  
  else if(N[0]=='7')
    printf("Yes");
  else 
    printf("No");
}


Measured memory_bytes: 1720
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string.h>
#include <stack>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
int main() {
    string s;
    cin >> s;
    stack<char> ans;
    rep(i, 0, s.size()){
        
        if(s[i] == 'B' && !ans.empty()){
            ans.top();
            ans.pop();
        }
        if(s[i] != 'B'){
            ans.push(s[i]);
        }
    }
    string anss= "";
    while(!ans.empty()) {
        char t = ans.top();
        anss+=t;
        ans.pop();
    }
    reverse(anss.begin(), anss.end());
    cout << anss << endl;
}


Measured memory_bytes: 3568
#043b
s = list(input())
ans = []

for pushed_key in s:
    if pushed_key == "0":
        ans.append("0")
    elif pushed_key == "1":
        ans.append("1")
    elif pushed_key == "B":
        if len(ans) != 0:
            ans.pop(-1)
            
print(''.join(ans))

Measured memory_bytes: 3060
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const ll inf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl;
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

ll n,a[300005] = {},ma = 0,mi = 0,ans = -inf;
rp_queue(ll) rpq;
p_queue(ll) pq;
vector<ll> r2;

int main(){
    cin >> n;
    rep(i,0,3*n){
        cin >> a[i];
        if(i < n){
            rpq.push(a[i]);
            ma += a[i];
        }else if(i < 2*n){
            pq.push(a[i]);
            mi += a[i];
        }else{
            pq.push(a[i]);
            mi += a[i];
            mi -= pq.top();
            r2.pb(pq.top());
            pq.pop();
        }
    }
    vsort(r2)
    
    ans = max(ans,ma-mi);
    rep(i,n,2*n){
        rpq.push(a[i]);
        ma += a[i];
        ma -= rpq.top();
        rpq.pop();

        if(a[i] <= pq.top()){
            mi -= a[i];
            mi += r2[0];
            pq.push(r2[0]);
            r2.erase(r2.begin());
        }else{
            r2.erase(r2.begin() +  vlb(r2,a[i]));
        }
        ans = max(ans,ma-mi);
    }
    
    P(ans);	

	return  0;
}

Measured memory_bytes: 6388
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        StringBuilder head = new StringBuilder();
        StringBuilder tail = new StringBuilder();
        int Q = sc.nextInt();
        boolean flag = true;
        for (int i = 0; i < Q; i++) {
            int qn = sc.nextInt();
            if (qn == 1 && flag == true) {
                flag = false;
            } else if (qn == 1 && flag == false) {
                flag = true;
            } else {
                int qn2 = sc.nextInt();
                if (flag == true) {
                    if (qn2 == 1) {
                        head.append(sc.next());
                    } else {
                        tail.append(sc.next());
                    }
                } else {
                    if (qn2 == 1) {
                        tail.append(sc.next());
                    } else {
                        head.append(sc.next());
                    }
                }

            }

        }
        // System.out.println(flag);
        S = head.reverse() + S + tail;
        if (flag == true) {
            System.out.println(S);
        } else {
            // System.out.println(flag);
            int tmp = S.length();
            char[] SC = S.toCharArray();
            for (int i = 0; i < S.length(); i++) {
                System.out.print(SC[tmp - 1 - i]);

            }
        }
    }
}

Measured memory_bytes: 129552
import java.util.*;
public class Main {
	public static void main(String[] args){
      	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int arr[] = new int[N];
		
		for (int i = 0; i < arr.length-1; i++) {
			arr[sc.nextInt()-1]++;
		}
		for (int i = 0; i < arr.length; i++) {
			System.out.println(arr[i]);
		}
		sc.close();
    }	
		
}

Measured memory_bytes: 54548
N=int(input())
SP=[list(input().split()) for _ in range(N)]

base=[]

for i in range(N):
    SP[i].append(i+1)
    SP[i][1]=int(SP[i][1])

sp=sorted(SP)

#print(sp)

for i in range(1,N):
    if sp[i][0]==sp[i-1][0]:
        base.append(sp[i-1][1:])
    else:
        base.append(sp[i-1][1:])
        base=sorted(base,reverse=True)
        for j in base:
            print(j[1])
        base=[]
    #print(base)
if sp[N-1][0]==sp[N-2][0]:
        base.append(sp[N-1][1:])
        base=sorted(base,reverse=True)
        for j in base:
            print(j[1])
        base=[]
else:
    print(sp[N-1][2])



#print(sp)


Measured memory_bytes: 3064
lista = list(map(int, input().split()))
lista.sort()

count = 0

A = lista[0]
B = lista[1]
C = lista[2]

while A!= B or B!= C or C!= A:
  if(C- A>= 2):
    lista[0]+= 2
  else:
    lista[0]+= 1
    lista[1]+= 1
  lista.sort()
  A = lista[0]
  B = lista[1]
  C = lista[2]
  count+= 1
  
print(count)
    

Measured memory_bytes: 3064
from itertools import product
n = int(input())
a = ["3", "5", "7"]
b = []
for i in range(3, 10):
    for p in product(a, repeat=i):
        if all(p.count(q) for q in a):
            x = ""
            for j in range(len(p)):
                x += p[j]
            x = int(x)
            b.append(x)
ans = 0
for i in b:
    if i <= n:
        ans += 1
print(ans)


Measured memory_bytes: 4072