akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BUnevenNumbers solver = new BUnevenNumbers();
        solver.solve(1, in, out);
        out.close();
    }

    static class BUnevenNumbers {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), ans = 0;
            for (int i = n; i >= 1; i--) {
                if (has(i)) ans++;
            }
            w.println(ans);
        }

        boolean has(int n) {
            int dig = 0;
            while (n > 0) {
                dig++;
                n /= 10;
            }
            return dig % 2 == 1;
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22740
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());

            if (a < b) {
                System.out.println("a < b");
            }
            if (a > b) {
                System.out.println("a > b");
            }
            if (a == b) {
                System.out.println("a == b");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 24188
n,q=map(int,input().split())
s=input()
v=[list(map(int,input().split())) for i in range(q)]
r=[0]*n
count=0
a=0
for i in range(n-1):
    r[i]=a
    if s[i]=='A':
        if s[i+1]=='C':
            a+=1
        else:
            pass
r[n-1]=a
for i in range(q):
    print(r[v[i][1]-1]-r[v[i][0]-1])

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int a_i;
  long long int answer;
  vector<int> a;
  while (true) {
    cin >> a_i;
    if (cin.eof()) break;
    a.push_back(a_i);
  }
  
  sort(a.begin(), a.end());

  answer = 0;
  int i = 3 * N - 2;
  for (int cnt = 0; cnt < N; cnt++) {
    answer += a[i];
    i -= 2;
  }

  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>

int main(void){
    int n;
    scanf("%d\n",&n);
    int p[n];
    
    int count = 0;

    
    
    for(int s=0; s<n; s++){
    scanf("%d",&p[s]);
    }
int i;
for(i=1; i<n-1;  i++){

    if(p[i-1] < p[i] && p[i]< p[i+1]){
        count++;
    
    }else if(p[i+1]<p[i]&&p[i]<p[i-1]){
        count++;
    }



}
printf("%d\n",count);

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2, 62);

int main()
{
    ll n,k;
    cin >> n >> k;
    vec ten(n+1);
    rep(i,n){
        cin >> ten[i+1];
    };
    for(int j = 1;j+k <= n;j++){
        if(ten[j] < ten[k+j]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 4780
def main():
    N = int(input())
    if N == 0:
        return 0
    l = set()
    while N != 0:
        if N > 0:
            r = plus(N)
            l.add(r)
            N -= pow(2, r)
        else:
            r = minus(N)
            l.add(r)
            N += pow(2, r)
    s = [0] * (max(l)+1)
    for i in range(max(l)+1):
        if i in l:
            s[i] = 1
    s.reverse()
    return ''.join(str(i) for i in s)
def plus(N):
    p = 0
    n = 0
    while True:
        p += pow(2, n)
        if p >= N:
            break
        n += 2
    return n
def minus(N):
    p = 0
    n = 1
    while True:
        p -= pow(2, n)
        if p <= N:
            break
        n += 2
    return n

print(main())


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

int main()
{
	vector<int> a(100, 0);
	int n;
	int max_num = 0;
	
	while(cin >> n)
	{
		a[n-1] = a[n-1]+1;

	}
	max_num = *max_element(a.begin(), a.end());
	for(int i=0; i<a.size(); i++)
	{
		if(a[i] == max_num)
		{
			cout << i+1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3072
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
char c='A';
int a=0,ans=0;
int main() {	
	while(isalpha(c)){
		c=getchar();
		if(c=='C'){
			a=1;
		}
		if(a==1&&c=='F'){
			ans=1;
		}
	}
	if(ans)
		printf("Yes");
	else
		printf("No");
	printf("\n");
	return 0;
}

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

int canMove(char road[],int s,int g){
	char oldRock='.';
	for(int i=s;i<g;i++){
		if(oldRock=='#' && road[i]=='#')return 0;
		oldRock=road[i];
	}
	return 1;
}
int canMoveA(char road[],int Bs,int Bg){
	for(int i=Bs;i<=Bg;i++){
		if(road[i-1]=='.' && road[i]=='.' && road[i+1]=='.'){
			return 1;
		}
	}
	return 0;
}

int main(){
	int num,As,Bs,Ag,Bg;
	char road[200000];
	cin>>num>>As>>Bs>>Ag>>Bg;
	As--;Ag--;Bs--;Bg--;
	cin>>road;
	if(Ag<Bg){
		if(canMove(road,As,Ag)==1 && canMove(road,Bs,Bg)==1){
			printf("Yes");
		}else{
			printf("No");
		}
	}else{
		if(canMove(road,Bs,Bg)==1 && canMove(road,As,Ag)==1 && canMoveA(road,Bs,Bg)==1){
			printf("Yes");
		}else{
			printf("No");
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>

int main() {
  int n;
  std::cin >> n;

  int a1 = n / 1000;
  int a2 = (n % 1000) / 100;
  int a3 = (n % 100) / 10;
  int a4 = n % 10;

  if (a1 == a2 && a2 == a3) {
    std::cout << "Yes" << std::endl;
  } else if (a2 == a3 && a3 == a4) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}


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

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

int main(){
	int K, A, B;
	cin >> K >> A >> B;
	for(int i=A; i<=B; i++){
		if(i%K==0){
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;

	return 0;
}

Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        static void SolveA(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            bool ans = IsValid(s, t);
            ans &= IsValid(t, s);
            if( ans)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
        private static bool IsValid(string s, string t)
        {
            var convertHash = new Dictionary<char, char>();

            for (int i = 0; i < s.Length; ++i)
            {
                char cs = s[i];
                char ct = t[i];
                if (!convertHash.ContainsKey(cs))
                {
                    convertHash.Add(cs, ct);
                }
                else
                {
                    if (ct != convertHash[cs])
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}

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

int main(){
        int r, g, b, n;
        cin >> r >> g >> b >> n;
        int ans = 0;
        for(int r_num=0; r_num <= n/r; r_num++){
                for(int g_num=0; g_num <= (n-r*r_num)/g; g_num++){
                        if((n-r*r_num-g*g_num)%b == 0) ans++;
                }
        }
        cout << ans << endl;

        return 0;
}


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

int main(){
    string s, t; cin >> s >> t;
    vector<int> salpha(26, 0), talpha(26, 0);
    for(int i = 0; i < s.size(); i++){
        salpha[s[i]-'a']++;
        talpha[t[i]-'a']++;
    }
    vector<int> lis1(3*1e5, 0), lis2(3*1e5, 0);
    for(int i = 0; i < 26; i++){
        lis1[salpha[i]]++;
        lis2[talpha[i]]++;
    }
    for(int i = 0; i < lis1.size(); i++){
        if(!(lis1[i] == lis2[i])){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3080
using System;

namespace AtCoderABC134D
{
    class Program
    {
        static void Main(string[] args)
        {

            int N = int.Parse(Console.ReadLine());

            string[] s = Console.ReadLine().Split(' ');

            int[] a = new int[N+1];

            int[] b = new int[N+1];

            for (int i = 0; i < N; i++)
            {
                a[i+1] = int.Parse(s[i]);
            }

            int total = 0;

            for(int i=N;i>0;i--)
            {
                b[i] = a[i];

                for(int j=2;j*i<=N;j++)
                {
                    b[i] = (b[i] + b[j * i]) % 2;
                }

                if (b[i] == 1)
                    total++;
            }

            Console.WriteLine(total.ToString());

            if (total != 0)
            {

                bool space = false;

                for (int i = 1; i <= N; i++)
                {

                    if (b[i] == 1)
                    {
                        if (space)
                        {
                            Console.Write(" ");
                        }
                        else
                        {
                            space = true;
                        }
                        Console.Write(i.ToString());
                    }
                }

                Console.WriteLine();
            }
        }
    }
}


Measured memory_bytes: 27096
#include <cstdio>
#include <cstdlib>
using namespace std;
char s[100];
int vis[100];
int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i ++) s[i] = '0';
    int flag = 1;
    for(int i = 0; i < m; i ++){
        int pos, num;
        scanf("%d %d", &pos, &num);
        if(!vis[pos]){
            vis[pos] = 1;
        }
        else{
            if(num + '0' != s[pos]) {
                flag = 0;
            }
        }
        s[pos] = num + '0';
    }
    s[n + 1] = '\0';
    if(s[1] == '0' && !vis[1] && n > 1){
        s[1] = '1';
    }
    int num = atoi(s + 1);
    int temp = num;
    int len = 0;
    if(temp == 0) len = 1;
    while(temp){
        temp /= 10;
        len ++;
    }
    if(!flag || len != n){
        printf("-1\n");
    }
    else{
        printf("%d\n", num);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    cin >> c;
    set <string> s;
    while(c--){
        string t;
        cin >> t;
        s.insert(t);
    }
    cout << s.size() << endl;

    return 0;
}


Measured memory_bytes: 19244
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>

using namespace std;

typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef map<int, int> M;
typedef pair<int, int> P;
typedef stack<int> S;
typedef queue<int> Q;

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

    VI d;
    for (int i = 1; i<=100000; i *= 6) d.push_back(i);
    for (int i = 9; i<=100000; i *= 9) d.push_back(i);
    sort(d.begin(), d.end());

    VVI dp = VVI((int)d.size(), VI(100000+1, 0));
    for (int i = 0; i <= n; ++i) dp[0][i] = i;

    for (int i = 1; i < (int)d.size(); ++i)
    {
        for (int j = 0; j <= n; ++j)
        {
            if (j < d[i]) dp[i][j] = dp[i-1][j];
            else dp[i][j] = min(dp[i-1][j], dp[i][j-d[i]]+1);
        }
    }
    cout << dp[(int)d.size()-1][n] << endl;
    
    return 0;
}


Measured memory_bytes: 5376
#include<stdio.h>
void Swap(int x[ ], int i, int j)
{
    int temp;
    
    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}

/* クイックソートを行う */
void QSort(int x[ ], int left, int right)
{
    int i, j;
    int pivot;
    
    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */
    
    pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */
    
    while (1) {                    /* 無限ループ */
        
        while (x[i] < pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */
        
        while (pivot < x[j])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */
        
        Swap(x, i, j);             /* x[i] と x[j]を交換 */
        i++;                       /* 次のデータ */
        j--;
    }
    //ShowData(x, 10);               /* 途中経過を表示 */
    
    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
}

int main(){
    int n,i,j;
    int a[200000];
    
    scanf("%d",&n);
    for(i = 0 ; i < n ; i++) scanf("%d",&a[i]);
    QSort(a,0,n-1);
    for(i = 0 ; i < n-1 ; i++){
        if(a[i] == a[i+1]){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
    
}

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

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

const int MAXN = 3e5 + 5;
const int BASE = 3137;
const int MOD1 = 1e9 + 7;
const int MOD2 = 1e9 + 9;

int N;
char s[MAXN];
pii pref[MAXN], pot[MAXN];
map <pii, int> cnt;

void load() {
	scanf("%d%s", &N, s + 1);
}

inline int add(int x, int y, int mod) {
	x += y;
	if (x >= mod)
		x -= mod;
	else if (x < 0)
		x += mod;
	return x;
}

inline int mul(int x, int y, int mod) {
	return (ll)x * y % mod;
}

int power(int x, int y, int mod) {
	int res = 1;
	for (; y; y /= 2) {
		if (y % 2)
			res = mul(res, x, mod);
		x = mul(x, x, mod);
	}
	return res;
}

pii operator +(const pii &l, const pii &r) {
	return {add(l.first, r.first, MOD1), add(l.second, r.second, MOD2)};
}

pii operator *(const pii &l, const pii &r) {
	return {mul(l.first, r.first, MOD1), mul(l.second, r.second, MOD2)};
}

ll solve() {
	int inv1 = power(BASE, MOD1 - 2, MOD1);
	int inv2 = power(BASE, MOD2 - 2, MOD2);
	pot[0] = {1, 1};
	for (int i = 1; i <= N; i++) {
		pot[i] = pot[i - 1];
		pref[i] = pref[i - 1];
		if (s[i] == '>')
			pot[i] = pot[i] * pii(BASE, BASE);
		else if (s[i] == '<')
			pot[i] = pot[i] * pii(inv1, inv2);
		else if (s[i] == '+') 
			pref[i] = pref[i] + pot[i];
		else 
			pref[i] = pref[i] + pii(-pot[i].first, -pot[i].second);
	}
	
	ll ans = 0;
	for (int i = N; i; i--) {
		cnt[pref[i]]++;
		ans += cnt[(pref[N] * pot[i - 1]) + pref[i - 1]];
	}
	
	return ans;
}

int main() {
	load();
	printf("%lld\n", solve());
	return 0;
}

Measured memory_bytes: 35968
#include <bits/stdc++.h> 
using namespace std; 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin>>n>>m;

    int x = (n * (n -1))/2;
    int y = (m * (m -1))/2;

    cout<<x+y<<"\n";

	return 0; 
} 



Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 22;
char dn[dm], * di = dn;
char C[10];
int keta = 0;
inline void putint(int X) {
	keta = 0;
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}
inline void putmae() {
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint();
	int n = 1 << N;
	int dp1[1 << 18], dp2[1 << 18];
	rep(i, n) {
		dp1[i] = getint();
		dp2[i] = 0;
	}

	rep(k, N) {
		int m = 1 << k;
		int m2 = ~(1 << k);
		for (int j = n - 1 & m2; j >= 0; j = j - 1 & m2) {
			int i = j | m;

			if (dp1[i] >= dp1[j]) {
				dp2[i] = max(dp2[i], dp1[j]);
			}
			else {
				dp2[i] = max(dp1[i], dp2[j]);
				dp1[i] = dp1[j];
			}
		}
	}

	int saidai = 0;
	rep1(i, n - 1) {
		if (saidai < dp1[i] + dp2[i]) {
			saidai = dp1[i] + dp2[i];
			putint(saidai);
		}
		else putmae();
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#ifdef LOCAL
#define D(x) cout<<"D: "<<#x<<'='<<x<<endl;
#define R(x, l) cout<<"R: Array "<<#x<<endl; rep(i, 0, l) cout<<' '<<i<<':'<<*(x+i)<<endl;
#else
#define D(x)
#define R(X, l)
#endif
#define pb push_back
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
inline int _max(int cnt, ...);
inline int _min(int cnt, ...);
int ans, r, g, b;
signed main(void)
{
	#ifdef LOCAL
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n = next<int>();
	string str = next<string>();
	rep(i, 0, n)
		if (str[i] == 'R') r++;
		else if (str[i] == 'G') g++;
		else b++;
	ans = r*g*b;
	rep(i, 0, n)
		rep(l, 1, n)
		{
			int j = i+l, k = i+2*l;
			if (k >= n) continue;
			if (str[i]+str[j]+str[k] == 'R'+'G'+'B') ans--;
		}
	cout<<ans<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}
inline int _max(int cnt, ...)
{
	int mx = -1e18;
	va_list l;
	va_start(l, cnt);
	while(cnt--) mx = max(mx, va_arg(l, int));
	va_end(l);
	return mx;
}
inline int _min(int cnt, ...)
{
	int mn = 1e18;
	va_list l;
	va_start(l, cnt);
	while(cnt--) mn = min(mn, va_arg(l, int));
	va_end(l);
	return mn;
}


Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n,m;
vector<int> G[200010];
int d[200010],pre[200010];

void solve(){
    cin >> n >> m;
    rep(i,n){
        d[i]=mod;
    }
    rep(i,m){
        int a,b;cin >> a >> b;a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    d[0]=0;
    queue<int> que;que.push(0);
    while(!que.empty()){
        int s=que.front();que.pop();
        for(int t:G[s]){
            if(d[t]!=mod) continue;
            d[t]=d[s]+1;
            pre[t]=s;
            que.push(t);
        }
    }
    rep(i,n){
        if(d[i]==mod){
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
    Rep(i,1,n){
        cout << pre[i]+1 << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 13320
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll freq[1005];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	for (int i=1; i<=k; i++) {
		ll x;
		cin >> x;
		for (int j=1; j<=x; j++) {
			ll val;
			cin >> val;
			freq[val]++;
		}
	}
	ll ans = 0;
	for (int i=1; i<=n; i++) {
		if (freq[i] == 0) ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3640
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

struct que {
	int a;
	int b;
	int c;
	int d;
	friend istream& operator>>(istream& in, que& x) { return in >> x.a >> x.b >> x.c >> x.d; }
};

typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
// #define mp make_pair
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'
// #define int ll
vector<ll> ft(1, 1LL);

/*======================================================================*/
int n, m, q;
que arr[55];
int val [11], ans;
void recur(int z){
    if(z == n+1){
        int tans = 0;
        for(int i = 0; i < q; i++){
            que r = arr[i];
            if(val[r.b] - val[r.a] == r.c)tans += r.d;
        }
        ans = max(ans, tans);
        return;
    }
    for(int i = val[z-1]; i <= m; i++){
        val[z] = i;
        recur(z+1);
    }
}

void solve(){
    cin >> n >> m >> q;
    rep(i, 0, q)cin >> arr[i];
    val[0] = 1;
    recur(1);
    cout << ans;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

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

int main(){
    int N;
    cin >> N;
    double ans = 0;
    vector<double> a(N);
    for(int i = 0;i < N;i++){
        cin >> a.at(i);
        ans += (double)1/a.at(i);
    }

    cout << 1/ans << endl;
}


Measured memory_bytes: 256
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}
ll dx[2]={1,0};
ll dy[2]={0,1};

int main(){
    IOS;
    make(ll,n);
    cout<<(n*(n-1))/2<<endl;


    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 10010;
const int MAXM = 10;
const int MAXK = 510;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    cout << fixed << setprecision(9) << (ld) n / m;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

import java.util.Arrays;
import java.util.ArrayList;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int [] h = new int[N];
		int hmin = 1000;
		for (int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		int total = h[0];
		if (N == 1) {
			System.out.println(total);
		}
		else if (N==2) {
			total = Math.max(h[0], h[1]);
			System.out.println(total);
		}
		else {
			for (int i = 1; i < N; i++) {
				if(h[i] > h[i-1]) {
					total += h[i] - h[i-1];
				}
			}
			System.out.println(total);
		}
	}
}	


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll                long long int
#define ld                long double
#define pb                push_back
#define mk                make_pair
#define in(i,a,n)         for(ll i=0;i<n;++i) cin>>a[i];
#define out(i,a,n)        for(ll i=0;i<n;++i) cout<<a[i]<<" ";
#define sz(c)             (ll)c.size()
#define all(c)            c.begin(), c.end()
#define rall(c)           c.rbegin(), c.rend()
#define loop(i,a,b)       for(ll i=a;i<b;i++)
#define rloop(i,a,b)      for(ll i=a;i>b;i--)
#define F                 first
#define S                 second
#define copy(a,b)         copy(all(a),back_inserter(b));
#define intersect(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
const ll N=300001;
const ll MOD = 1000 * 1000 * 1000 + 7;
ll mod(ll n) {
    return (n % MOD + MOD) % MOD;
}

void solve(){
    ld n, k, i, x, y;
    cin >> n;
    cout << (ld)((ld)(2) * (ld)((ld)22/(ld)7) * (ld)(n));
}

signed main(){
    //fin fout
    fast
    ll t=1; //cin>>t;
    while(t--) solve();
}  

Measured memory_bytes: 3804
#include<cstdio>
//#include<algorithm>
//#include<functional>
using namespace std;
int main(void)
{
	int n,i,x,j,p;
	int suu[6];
	float sin[41];
	scanf("%d",&n);
	x=0;
	p=0;
	for(i=0;i<n;i++){
		scanf("%f",&sin[i]);
		
	}
	for(i=0;i<6;i++){
		suu[i]=0;
	}
	//sort(sin,sin+41);
	for(i=0;i<n;i++){
		if(sin[i]<165){
			suu[0]++;
		}
		else if(sin[i]>=165 && sin[i]<170){
			suu[1]++;
		}
		else if(sin[i]>=170 && sin[i]<175){
			suu[2]++;
		}
		else if(sin[i]>=175 && sin[i]<180){
			suu[3]++;
		}
		else if(sin[i]>=180 && sin[i]<185){
			suu[4]++;
		}
		else if(sin[i]>=185){
			suu[5]++;
		}
	}
	for(i=0;i<6;i++){
		x++;
		p=suu[i];
		printf("%d:",x);
		if(p!=0){
			for(j=0;j<p;j++){
				printf("*");
			}
		}
		printf("\n");
	}
	return 0;
}

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

int num[100005];
int num2[100005];

int main(){
    int N,a,b;
    cin>>N;
    for(int n=0;n<N;n++){
        cin>>a>>b;
        // cout<<a<<' '<<b<<endl;
        num[a]++;
        num[b+1]--;
    }
    int ans=num2[0]=num[0];
    for(int i=1;i<100005;i++){
        num2[i]=num2[i-1]+num[i];
        if(num2[i]>=i-1) ans=i;
    }
    ans--;
    cout<<max(0,ans)<<endl;
}

Measured memory_bytes: 3864
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#define MAX_N 10000
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dp[2][MAX_N / 2 + 1][2];
int main() {
	int n, ans = INF, t[MAX_N + 1] = {};
	cin >> n;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n / 2 + 1; j++) {
			fill(dp[i][j], dp[i][j] + 2, INF);
		}
	}
	for (int i = 0; i < n - 1; i++) {
		cin >> t[i];
	}
	dp[1][1][1] = t[0];
	for (int i = 1; i < n ; i++) {
		for (int j = 0; j < n / 2 + 1; j++) {
			for (int k = 0; k < 2; k++) {
				dp[0][j][k] = dp[1][j][k]; 
				dp[1][j][k] = INF;
			}
		}
		for (int j = 0; j < n / 2; j++) {
			if (j > i) break;
			dp[1][j + 1][0] = min(dp[0][j + 1][1], dp[0][j + 1][0]);
			
			dp[1][j + 1][1] = min(dp[1][j + 1][1], dp[0][j][1] + t[i] - t[i - 1]);
			dp[1][j + 1][1] = min(dp[1][j + 1][1], dp[0][j][0] + t[i] + t[i - 1]);
		}
		ans = min(ans, min(dp[1][n / 2][0], dp[1][n/2][1]));
	}
	cout << ans << endl;
}

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

const int MAX_N=10e4+5;
ll n,m,s,a[MAX_N];

int main(){
  cin >> n >> m;
  for(int i=0;i<m;++i){
    cin >> a[i];
    s+=a[i];
  }
  if(s>n){cout << -1 << endl;}
  else{cout << n-s << endl;}
  return 0;
}


Measured memory_bytes: 3716
N,S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp =[[0]*(S+1) for _ in range(N+1)]
dp[0][0]=1
for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod
        if j+A[i]<=S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= mod
print(dp[N][S])


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

vector<int> g[100000];
int c[100000] = { 0 };

int k = 0;

void paint(int v, int prevColor) {
	int curr = 1;
	queue<pair<int, int>> q;

	for (int i = 0; i < g[v].size(); ++i) {
		if (curr == prevColor) {
			++curr;
		}

		c[g[v][i]] = curr;
		++k;
		++curr;

		q.push(make_pair(g[v][i], curr - 1));
	}

	while (!q.empty()) {
		pair<int, int> p = q.front();
		paint(p.first, p.second);
		q.pop();
	}
}

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

	vector<int> l;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;

		g[a - 1].push_back(b - 1);
		l.push_back(b - 1);
	}

	paint(0, 0);

	int m = 0;
	for (int i = 1; i < n; ++i) {
		m = max(m, c[i]);
	}

	cout << m << endl;

	for (int li : l) {
		cout << c[li] << endl;
	}
	
	return 0;
}
	

Measured memory_bytes: 55036
fun main(args: Array<String>) {
    a108(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}


fun a108(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val num = args[0].toInt()
    fun square(number: Int): Int = number * number
    println(if (num % 2 == 0) square(num / 2) else num / 2 * (num / 2 + 1))
}

Measured memory_bytes: 33700
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

template<typename T>
class BIT {
private:
  vector<T> bit;
  int n;
public:
  BIT(int _n) : n(_n) {
    bit = vector<T>(n+1, 0); //0初期化
  }
  void add(int v, T a){ //vは0-indexed
    for(int x=v+1; x<=n; x += x&(-x)) bit[x] += a;
  }
  T sum(int v){ //vは0-indexed
    T ret=0;
    for(int x=v+1; x>0; x -= x&(-x)) ret += bit[x];
    return ret;
  }
};

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

  auto arrange = [&](double m){
    vector<pair<double,int>> v;
    rep(i,n) v.pb(mp((double)(c[i]-m*a[i])/b[i], i));
    sort(all(v));
    return v;
  };

  auto sol = [&](){
    auto vl = arrange(-INF);
    vector<int> perm(n);
    rep(i,n) perm[vl[i].se] = i;

    auto calc = [&](double m){
      auto v = arrange(m);

      BIT<int> bit(n);
      int ret = 0;
      rep(i,n){
        int x = perm[v[i].se];
        ret += i - bit.sum(x);
        bit.add(x,1);
      }
      //dbg(m,ret);
      return ret;
    };

    double l = -INF, r = INF;
    rep(_,70){
      double m = (r+l)/2.0;
      if( calc(m)>=(n*(n-1)/2+1)/2 ) r = m;
      else l = m;
    }
    return r;
  };

  double x = sol();
  swap(a,b);
  double y = sol();

  printf("%.10f %.10f\n", x, y);

  return 0;
}


Measured memory_bytes: 3508
n,k = map(int,input().split())
v = list(map(int,input().split()))

ans = 0
for i in range(1,k+1):
    if i > n:
        break
    for j in range(i):
        tmpv = v[-j:]+v
        newv = tmpv[:i]
        newv.sort()
        rmsum = 0
        for t in range(min(k-i,len(newv))):
            if newv[t] < 0:
                rmsum += newv[t]
        ans = max(sum(newv) - rmsum,ans)
print(ans)

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N=0;
    string S,T;
    cin >> S>>T;

    REP(i,3){
        if(S.at(i)==T.at(i)){
            N++;
        }
    }
    cout << N << endl;
}


Measured memory_bytes: 256
from functools import reduce

def lcm(a, b):
  if b > a:
    a, b = b, a
  
  while b != 0:
    a, b = b, a % b
  
  return a

city_num, start = map(int, input().split())

cities = list(map(int, input().split()))

for i in range(len(cities)):
  cities[i] = abs(start - cities[i])

cities.sort()
  
a = reduce(lcm, cities)  

print(a)


Measured memory_bytes: 14748
#include<stdio.h>
int main()
{
    int N;
    scanf("%d",&N);
    while(N)
    {
        if(N%10==7)
        {
            printf("Yes\n");
            return 0;
        }
        N=N/10;
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int N, M, P;

const int INF = 1e9;
struct edge { int from, to, cost; };

vector<int> bellmanFord(int V, vector<edge> &edges, int source) {
  int E = edges.size();
  vector<int> distances(V, INF);

  distances[source] = 0;
  bool updated = true;
  int count = 0;
  while(updated) {
    updated = false;
    rep(i,E) {
      edge e = edges[i];
      if(distances[e.from] != INF && distances[e.to] > distances[e.from] + e.cost) {
        distances[e.to] = distances[e.from] + e.cost;
        updated = true;
      }
    }
    count++;
    if(updated && count == V) return vector<int>(); // negative cycle
  }
  return distances;
}


int main () {
  cin >> N >> M >> P;

  vector<edge> edges(M);
  rep(i,M) {
    cin >> edges[i].from >> edges[i].to >> edges[i].cost;
    edges[i].from--, edges[i].to--;
    edges[i].cost = P - edges[i].cost;
  }

  vector<int> rf(N, 0), rb(N, 0);
  rf[0] = 1;
  rb[N-1] = 1;
  rep(i,N) rep(j,M) {
    if(rf[edges[j].from]) rf[edges[j].to] = 1;
    if(rb[edges[j].to]) rb[edges[j].from] = 1;
  }

  vector<edge> cleanEdges;
  rep(i,M) {
    if(!rf[edges[i].from] || !rf[edges[i].to] || !rb[edges[i].from] || !rb[edges[i].to]) continue;
    cleanEdges.push_back(edges[i]);
  }

  auto res = bellmanFord(N, cleanEdges, 0);

  if(res.empty()) {
    cout << -1 << endl;
  } else {
    cout << -min(res[N-1], 0) << endl;
  }

  return 0;
}


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

#define ll long long
#define mx  300005
#define mod 1000000009
#define lim 10000000
#define N 18
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n,e=0,w=0;cin>>n;
	string s;cin>>s;
	s=" "+s;

	for(int i=1;i<=n;i++)
	    if(s[i]=='E')e++;

	int ans=INT_MAX;
	for(int i=1;i<=n;i++)
	{
            if(s[i]=='E')e--;
            ans=min(ans,w+e);
            if(s[i]=='W')w++;
	}
	cout<<ans<<"\n";
     return 0;
}


Measured memory_bytes: 916
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<string> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        a[i] += a[i];
    }
    for (int i = 0; i < n; ++i)
        a.push_back(a[i]);
    int il_ok;
    int odp = 0;
    vector< vector<bool> > odw(n, vector<bool>(n, false));
    for (int x = 0; x < n; ++x)
    {
        for (int y = 0; y < n; ++y)
        {
            if (!odw[x][y])
            {
                il_ok = 0;
                int i, j;
                for (i = x; i <= x + n - 1; ++i)
                {
                    for (j = y; j <= y + n - 1; ++j)
                    {
                        int q = i - x, w = j - y;
                        swap(q, w);
                        q += x;
                        w += y;
                        if (a[i][j] == a[q][w])
                            ++il_ok;
                    }
                }
                if (il_ok == n * n)
                    ++odp;
                odw[x][y] = true;
                i = x;
                j = y;
                while (i + 1 < n && j + 1 < n)
                {
                    ++i;
                    ++j;
                    il_ok -= 2 * n - 1;
                    ++il_ok;
                    for (int k = i + n - 1, l = j; l < j + n - 1; ++l)
                    {
                        int q = k - i, w = l - j;
                        swap(q, w);
                        q += i;
                        w += j;
                        if (a[k][l] == a[q][w])
                            il_ok += 2;
                    }
                    if (il_ok == n * n)
                        ++odp;
                    odw[i][j] = true;
                }
            }
        }
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 640
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }

struct UnionFind {
  private:
  vector<int> child,tree;
  vector<vector<int>> list;

public:
  UnionFind(int v) {
    tree.resize(v);
    list.resize(v);
    REP(i,v) tree[i] = i, list[i].push_back(i);
  }

  int root(int i){
    if(i == tree[i]){
      REP(j,child.size()) tree[child[j]] = i;
      child.clear(); 
      return i;
    }
    else{
      child.push_back(i);
      return i = root(tree[i]);
    }
  }

  int size(int i){
    return list[root(i)].size();
  }

  vector<int> nodes(int no){
    return list[root(no)];
  }

  bool unit(int x, int y){
    x = root(x);
    y = root(y);
    if(x==y) return false;
    if(list[x].size() < list[y].size()) swap(x,y);
    for(int no:list[y]) list[x].emplace_back(no);
    tree[y] = x;
    return true;
  }

  bool isUnit(int x, int y){
    return root(x) == root(y);
  }
};

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,m;
    cin>>n>>m;
    vector<int> p(n);
    REP(i,n) cin >> p[i],p[i]--;
    UnionFind uf(n);
    rep(i,m){
        int x,y;
        cin>>x>>y;
        x--;y--;
        uf.unit(x,y);
    }
    ll ans=0;
    rep(i,n){
        int num=p[i];
        int posi=i;
        if(uf.isUnit(num,i)) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 14828
#include <bits/stdc++.h>
#define int long long
#define rint register int
#define fo(i, n) for(rint i = 1; i <= (n); i ++)
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
int n, ans = 1e9;
inline int cal(int n) {
  return n < 10 ? n : cal(n / 10) + (n % 10);
}
main(void) {
  read(n);
  for(int i = 1; i < n; i ++)
      ans = min(ans, cal(i) + cal(n - i));
  cout << ans << "\n";
}


Measured memory_bytes: 256