akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll a,b,c,d=0,e=1,i,j,k,l;
 cin>>a>>d;
  vector < double >v,vv;
  double x,y,z;
  for(i=1;i<=a;i++)
    {
    cin>>x;v.push_back(x);
    }
   
    for(i=0;i<a;i++)    
    {
   x=v[i];
   y=((x/2.0)*(x+1))/x;
   vv.push_back(y);
     
    }
    x=0.0;z=0.0;
    for(i=0;i<d;i++)
    {
    x+=vv[i];
    }
   z=max(z,x);//cout<<z<<endl;
   for(i=d,j=0;i<a;i++,j++)
    {
    
     x=x+vv[i]-vv[j];
        //cout<<x<<" "<<v[j]<<endl;
    z=max(x,z) ;
    }
printf("%0.12f\n",z);
}

Measured memory_bytes: 4848
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-(n ** 0.5) // 1)) + 1):
            if temp % i == 0:
                cnt = 0
                while temp % i == 0:
                    cnt += 1
                    temp //= i
                arr.append([i, cnt])
        if temp != 1:
            arr.append([temp, 1])
        if arr == []:
            arr.append([n, 1])
        return arr

    N, P = map(int, input().split())
    arr = factorization(P)
    answer = 1
    for a in arr:
        if a[1] >= N:
            ans = a[0] ** (a[1] // N)
            answer *= ans
    print(answer)


if __name__ == "__main__":
    main()


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

#define ll long long
#define mod 1000000007
#define f(i, a, b) for (long long i = a; i < b; i++)
#define fm(i, a, b, c) for (long long i = a; i > b; i--)
#define vi vector<i>
#define vl vector<long long>
#define vs vector<string>
#define t     \
    ll t;     \
    cin >> t; \
    while (t--)
#define pb(i) push_back(i)
#define mp(i, j) make_pair(i, j)
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL)
int main()
{
    string s;
    cin >> s;
    bool lol = true;
    if (s.at(2) != s.at(3) || s.at(4) != s.at(5))
        lol = false;

    if (lol == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	char s[10000];
	scanf("%s", s);
	int n;
	n = strlen(s);
	if (s[n-1] == 's')
	{
		s[n] = 'e';
		s[n+1] = 's';
		s[n+2] = 0;
	}
	else
	{
		s[n] = 's';
		s[n+1] = 0;
	}
	printf("%s\n", s);
	return 0;
}

Measured memory_bytes: 1632
import math
N = int(input())
ABCDE = []
for _ in range(5):
    i = int(input())
    ABCDE.append(i)

X = min(ABCDE)

#ボトルネックに通れる人の数でグループ分けする。
group = math.ceil(N/X)

#3グループに分けられる場合、最後のグループは2分待ってから5分で6に到着する。
ans = (group-1) + 5
print(ans)


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

int main() {
  int N, X, sum, sumg, rem, min;
  cin >> N >> X;
  vector<int> m(N);
  sumg = 0;
  min = 1000;
  
  for (int i = 0; i < N; i++){
    cin >> m.at(i);
    sumg += m.at(i);
    if (m.at(i) < min) min = m.at(i);
  }
  rem = X - sumg;
  sum = N + rem / min;
  
  cout << sum << endl;
  
}

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

using namespace std;


template<typename T>
class UF
{
public:
	UF() {
		size = 0;
	}

	//???????????\??????
	void push( T a ) {
		M[a] = size;
		V.push_back( size );
		rank.push_back( 0 );
		C.push_back( 1 );
		size++;
	}

	//????????°??????????????????
	void unite( T a, T b ) {
		long long int x = find( M[a] );
		long long int y = find( M[b] );
		if( x == y )return;
		if( rank[x] < rank[y] ) {
			V[x] = y;
			C[y] += C[x];
		} else {
			V[y] = x;
			C[x] += C[y];
			if( rank[x] == rank[y] )rank[x]++;
		}
	}

	void merge( T a, T b ) {
		unite( a, b );
	}

	//????????°??????????????????????????????????????????
	bool same( T a, T b ) {
		return find( M[a] ) == find( M[b] );
	}

	//????????°????????????????????°?????????
	long long int group() {
		set<long long int >S;
		for( long long int i = 0; i < V.size(); i++ ) {
			S.insert( find( V[i] ) );
		}
		return S.size();
	}

	//??°?????????????±???????????????°?????????
	long long int count( T a ) {
		return C[find( M[a] )];
	}

private:
	vector<long long int>
		C, V, rank;
	map < T, long long int>M;
	long long int size;

	//?\?????????§?????????
	long long int find( long long int x ) {
		if( V[x] == x )return x;
		else return V[x] = find( V[x] );
	}
};

int main() {
	UF<long long int> uf;
	long long int N, Q;
	cin >> N >> Q;
	for( size_t i = 0; i < N; i++ ) {
		uf.push( i );
	}
	for( size_t i = 0; i < Q; i++ ) {
		int com, x, y;
		cin >> com >> x >> y;
		if( com == 0 ) {
			uf.unite( x, y );
		} else {
			if( uf.same( x, y ) ) {
				cout << 1 << endl;
			} else {
				cout << 0 << endl;
			}
		}
	}
}

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

using namespace std;

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

    int n, m;
    cin >> n >> m;
    vector<int> lovedFood(m+1);

    for(int i = 0 ; i < n; ++i)
    {
        int k;
        cin >> k;
        for(int j = 0 ; j < k ; ++j)
        {
            int c;
            cin >> c;
            lovedFood[c]++;
        }
    }
    int count = 0;
    for(int x : lovedFood)
    {
        if(x == n)
            count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  char s[3],r[3];
  for(int i=0;i<3;i++) cin >> s[i];
  for(int i=0;i<3;i++) cin >> r[i];
  if(s[0]==r[2] && s[1]==r[1] && s[2]==r[0]) cout <<"YES" << endl;
  else cout <<"NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

int64_t N;

void solve()
{
    std::cin >> N;
	std::vector<int64_t> L(N);
	for (auto& v : L) std::cin >> v;

	std::sort(L.begin(), L.end());

	int64_t ans = 0;
	for (int64_t i = 0; i < N - 2; i++)
	{
		for (int64_t j = i + 1; j < N - 1; j++)
		{
			for (int64_t k = j + 1; k < N; k++)
			{
				if (L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[j] + L[k] > L[i] && L[i] != L[j] && L[j] != L[k] && L[i] != L[k]) ans++;
			}
		}
	}

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

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	if(n%2 == 1){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0, div = 10;
	while(n > 0){
		ans += n / div;
		n /= 5;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 #include <queue>
 #include <iostream>
 #include <string.h> 
 #include <algorithm>
 using namespace std;
int e[500000],w[6000];
int f[6000],g[56];
int main(){
	int i,j,k=0,l,m,n;
	for(i=2;i<=55555;i++){
		l=1;
	 for(j=2;j*j<=i;j++){
	 if(!(i%j)){l=0;break;
	 }
	 }
	 if(l){k++;
	 e[i]=1;
	 }
	 
	}
  j=2;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
  while(!(e[j]&&(j%5==1)))j++;
  printf("%d ",j);
  j++;
  }	
	return 0;
}
	
	


	
	

 	
 	
 	
 	
 	
 	
 	
 

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
	int a,b,c;
	cin>>a>>b>>c;
	int mx,mn;
	mx=max(a,b);
	mx=max(mx,c);
	mn=min(a,b);
	mn=min(mn,c);
	cout<<mx-mn<<endl;
    return 0;
}

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

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int sum = 0;
  for (int i = 0; i < n; i++){
    if (i < k)
      sum += x;
    else
      sum += y;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
typedef long long ll;
const ll INF=1e18;
#define rep(i,n) for(int i=0;i<n;i++)
#define print(a) cout << a << endl

int main()
{
    int n,k;cin >> n >> k;
    vector<ll> x(n),sum(n);
    vector<int> cnt(n);
    ll ans=INF;
    rep(i,n)cin >> x.at(i);
    rep(i,n-k+1){
        ll p=x[i];ll q=x[i+k-1];
        if(p>=0){
            ans=min(ans,q);
        }else if(q<=0){
            ans=min(ans,abs(p));
        }else{
            ans=min(ans,-2*p+q);
            ans=min(ans,2*q-p);
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    //
    vector<int> time(N);
    for(int i=0;i<N;i++){
        cin >> time[i];
    }
    //
    int M;
    cin >> M;
    for(int i=0;i<M;i++){
        int total__time=0;
        int P,X;
        cin >> P>> X;
        for(int j=0;j<N;j++){
            if(j==(P-1)){
                total__time += X;
            }
            else{
                total__time += time[j];
            }
        }
        cout << total__time << endl;
    }
}

Measured memory_bytes: 3576
#include<iostream>
#include<vector>
using namespace std;
static const int INF = 1 << 20;

int main(){
	int V, E;
	cin >> V >> E;
	vector<vector<int> > adj(V, vector<int>(V, INF));
	vector<int> cnt(V, 0);
	for(int i = 0; i < V; i++) adj[i][i] = 0;
	int sum = 0;
	for(int i = 0; i < E; i++){
		int s, t, d;
		cin >> s >> t >> d;
		adj[s][t] = min(adj[s][t], d);
		adj[t][s] = min(adj[t][s], d);
		cnt[s]++;
		cnt[t]++;
		sum += d;
	}
	for(int k = 0; k < V; k++){
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
			}
		}
	}
	vector<int> v;
	for(int i = 0; i < V; i++){
		if(cnt[i] % 2 == 1) v.push_back(i);
	}
	int n = v.size();
	vector<int> memo(1 << n, INF);
	for(int i = 0; i < (1 << n); i++){
		if(i == 0){
			memo[i] = 0;
			continue;
		}
		for(int j = 0; j < n; j++){
			if(!(i & (1 << j))) continue;
			for(int k = 0; k < n; k++){
				if(k == j) continue;
				if(!(i & (1 << k))) continue;
				memo[i] = min(memo[i], memo[i - (1 << j) - (1 << k)] + adj[v[j]][v[k]]);
			}
		}
	}
	cout << sum + memo[(1 << n) - 1] << endl;
	return 0;
}



Measured memory_bytes: 3188
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
	        
			String a1 = sc.next();
			String b1 = sc.next();
			BigDecimal a = new BigDecimal(a1);
			BigDecimal b = new BigDecimal(b1);
			BigDecimal ret = a.multiply(b);
			ret = ret.setScale(0,RoundingMode.DOWN);
			
			System.out.println(ret);
		}
		
	}


Measured memory_bytes: 35892
import java.util.Scanner;
 
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
 
        while(true){
            int n = sc.nextInt();
            if(n == 0) break;
 
            int[] s = new int[n];
 
            for(int i = 0; i < n; i++){
                s[i] = sc.nextInt();
            }
 
            int min = s[0];
            int max = s[0];
 
            for(int j = 1; j < n; j++){
                min = Math.min(min, s[j]);
                max = Math.max(max, s[j]);
            }
 
            int sum = 0;
 
            for(int k = 0; k < n; k++){
                sum += s[k];
            }
 
            int ave = (sum - min - max) / (n - 2);
 
            System.out.println(ave);
 
        }
 
    }
}


Measured memory_bytes: 28640
#include <stdio.h>

int main(void) {
	int h, w;
	int i, j;
	while(1) {
		scanf("%d %d", &h, &w);
		if(h == 0 && w == 0) break;
		for(i = 0; i < h; i++) {
			for(j = 0; j < w; j++) printf("#");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#ifdef Rahul
# define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
# define error(...) 42;
#endif
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/***********************************************************************/
int32_t main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  long double x; cin >> x;
  x /= 3;
  cout.precision(9);
  cout << fixed << x * x * x << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <functional>
#include <numeric>
#include <cstring>

using namespace std;

int main()
{
    long long a[4], N;
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    cin >> N;
    vector<pair<long long, long long> > b(4);
    b[0] = make_pair(a[0] * 8, 0);
    b[1] = make_pair(a[1] * 4, 1);
    b[2] = make_pair(a[2] * 2, 2);
    b[3] = make_pair(a[3], 3);
    sort(b.begin(), b.end());
    long long ans = 0;
    if (N % 2 == 0)
    {
        ans = b[0].first * (N / 2);
    }
    else
    {
        ans = b[0].first * (N / 2);
        long long t1 = a[0] * 4;
        long long t2 = a[1] * 2;
        long long t3 = a[2];
        ans += min(t1, min(t2, t3));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int D = sc.nextInt();
    
    if (D == 25) {
      System.out.println("Christmas");
    }
    if (D == 24) {
      System.out.println("Christmas Eve");
    }
    if (D == 23) {
      System.out.println("Christmas Eve Eve");
    }
    if (D == 22) {
      System.out.println("Christmas Eve Eve Eve");
    }
  }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

bool ok[33][55];
bool dp[55];

int solve(int N) {
	for (int day = 1; day <= 30; day++) {
		for (int last = 0; last < N; last++) {
			memset(dp, false, sizeof(dp));
			dp[last] = true;
			for (int i = day; i >= 1; i--) {
				queue<int> que;
				for (int j = 0; j < N; j++) {
					if (dp[j]) que.push(j);
				}
				while (!que.empty()) {
					int now = que.front(); que.pop();
					for (int v = 0; v < N; v++) {
						if (dp[v]) continue;
						if (ok[i][now] && ok[i][v]) {
							que.push(v);
							dp[v] = true;
						}
					}
				}
			}
			bool finish = true;
			for (int i = 0; i < N; i++)
				finish &= dp[i];
			if (finish) return day;
		}
	}
	return -1;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	while (cin >> N) {
		if (N==0) break;
		memset(ok, false, sizeof(ok));
		for (int i = 0; i < N; i++) {
			int f;
			cin >> f;
			for (int j = 0; j < f; j++) {
				int d;
				cin >> d;
				ok[d][i] = true;
			}
		}
		cout << solve(N) << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
/***from dust i have come, dust i will be***/

#include<bits/stdc++.h>

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

#define dbg printf("in\n")
#define nl printf("\n");
#define N 101010
#define inf 1e9

#define sf(n) scanf("%d", &n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define sfl(n) scanf("%I64d", &n)
#define sffl(n,m) scanf("%I64d%I64d",&n,&m)

#define pf(n) printf("%d",n)
#define pff(n,m) printf("%d %d",n,m)
#define pffl(n,m) printf("%I64d %I64d",n,m)
#define pfl(n) printf("%I64d",n)
#define pfs(s) printf("%s",s)

#define pb push_back
#define pp pair<int, int>

using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);

    int i, j, k;
    int n, m;
    int r, s, p;
    string str;

    sff(n, k);
    sff(r, s), sf(p);
    cin >> str;

    vector<pair<int, char>> ch;
    ch.pb({r, 'R'});
    ch.pb({s, 'S'});
    ch.pb({p, 'P'});

    sort(ch.begin(), ch.end(), greater<pair<int, char>>());

    string used;
    for(i = 0; i < n; i++)
        used.pb('#');

    ll ans = 0;
    char oppo;
    for(i = 0; i < 3; i++)
    {
        if(ch[i].second == 'R') oppo = 's';
        else if(ch[i].second == 'S') oppo = 'p';
        else oppo = 'r';

        for(j = 0; j < n; j++)
        {
            if(str[j] == oppo)
            {
                if(j - k < 0 ||  (j - k >= 0 && used[j - k] != ch[i].second))
                    ans += ch[i].first, used[j] = ch[i].second;
            }
        }
    }

    pfl(ans);

    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

void revdfs(ll u,vector<vector<ll>> revadj,ll used[])
{
    used[u]=1;
    for(auto v:revadj[u])
    {
        if(!used[v]) revdfs(v,revadj,used);
    }
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,m,n,i,f=0,j,ans=0,u,v,k,q,c,p;
    cin >> n >> m >> p;
    vector<pair<pair<ll,ll>,ll>> edge(m);
    vector<vector<ll>> revadj(n+1);
    rep(i,m)
    {
        cin >> u >> v >> c ;
        c-=p;
        edge[i]=(mp(mp(u,v),-1*c));
        revadj[v].pb(u);
    }
    //cout << edge[0].fi.fi ;
    ll used[n+1]={0};
    revdfs(n,revadj,used);
    vector<ll> d;
   
    d.assign(n+1,1e18);
    d[1]=0;
    for(i=0;i<n-1;++i)
    {
       
        for(j=0;j<m;++j)
        {
            //cout << d[edge[j].fi.fi] << endl ;
            if(d[edge[j].fi.fi]!=1e18)
            {
                if(d[edge[j].fi.se] > d[edge[j].fi.fi] + edge[j].se )
                {
                    d[edge[j].fi.se] = d[edge[j].fi.fi] + edge[j].se;
                    
                }
            }
            //cout << f << endl ;
        }
        
    }
    f=0;
    for(j=0;j<m;++j)
    {
        //cout << d[edge[j].fi.fi] << endl ;
        if(d[edge[j].fi.fi]!=1e18)
        {
            if(d[edge[j].fi.se] > d[edge[j].fi.fi] + edge[j].se )
            {
                d[edge[j].fi.se] = d[edge[j].fi.fi] + edge[j].se;
                if(used[edge[j].fi.se]) 
                {
                    f=1;
                    break;
                }
            }
        }
        //cout << f << endl ;
    }
    if(f!=0)
    {
        cout << -1 ;
    }
    else if(d[n] > 0) cout << 0 ;
    else cout << -1 * d[n] ;
    return 0;
}

Measured memory_bytes: 342656
N=int(input())
A=list(map(int,input().split()))
import copy
B = copy.deepcopy(A)
B.sort()
cnt = 0
for i in range(N):
    if A[i] != B[i]:
        cnt += 1
if cnt == 0 or cnt == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3444
#import math
#import collections
n,k = map(int, input().split( ))
#A = list(map(int, input().split( )))
mod = 10**9+7
ans = 0
l,h = 0,0
for x in range(1,n+2):
  l += x -1
  h += n -x +1
  if x >= k:
    ans += (h-l+1)
    ans = ans%mod
print(ans)

Measured memory_bytes: 8904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Inarr(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18;

ll  perser(int cut,string s){
    ll ret=0;

}
int main(){
    string s;
    cin>>s;
    ll ans=0,tos,pow2 = 1<<(s.size()-1);
    rep(i,pow2){
        tos=s[0]-'0';
        rep(j,s.size()-1){
            if(i&(1<<j)){
                ans+=tos;
                tos=0;
            }
            tos = tos*10 + s[j+1]-'0';
        }
        ans+=tos;
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;



int main(void){
    int a,b;
    cin>>a>>b;
    cout<<max(a-2*b,0)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const long long MOD_NUM = 1000000007LL;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}

static void B_task();

int main()
{
	B_task();
	fflush(stdout);
	return 0;
}

static void B_task()
{
	int N;
	get1int(N);

	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			if ((i * j) == N) {
				printf("Yes\n");
				return;
			}
		}
	}
	printf("No\n");
}


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

int main(){
    ll a,b;
    cin >> a >> b;
    if((a+b)%2 != 0) cout << "IMPOSSIBLE" << endl;
    else cout << (a+b)/2 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.next();
        int[] r = new int[n];
        int[] g = new int[n];
        int[] b = new int[n];
        char last = s.charAt(n-1);
        switch(last) {
            case 'R':
                r[n-1]=1;
                break;
            case 'G':
                g[n-1]=1;
                break;
            case 'B':
                b[n-1]=1;
                break;
        }
        for(int i=n-2; i>=0; i--) {
            char c = s.charAt(i);
            r[i] = r[i+1] + (c=='R'?1:0);
            g[i] = g[i+1] + (c=='G'?1:0);
            b[i] = b[i+1] + (c=='B'?1:0);
        }
        long c = 0;
        for(int i=0; i<n-2; i++) {
            char si = s.charAt(i);
            for(int j=i+1; j<n-1; j++) {
                char sj = s.charAt(j);
                if(si==sj) {
                    continue;
                }
                char sk = 'R';
                int[] skArray = r;
                if((si=='R' && sj=='G') || (si=='G' && sj=='R')) {
                    sk = 'B';
                    skArray = b;
                }
                else if((si=='R' && sj=='B') || (si=='B' && sj=='R')) {
                    sk = 'G';
                    skArray = g;
                }
                
                c += skArray[j+1];
                int excludedIndex = j + (j-i);
                if(excludedIndex < n && s.charAt(excludedIndex)==sk) {
                    c--;
                }
            }
        }

        System.out.println(c);
    }
}


Measured memory_bytes: 37476
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> a[100000];
bool check[100000];
int low[100000];
int num[100000];
bool isPoint[100000];

int func(int u, int n){
    if(check[u])return n;

    num[u] = n;
    n++;
    check[u] = true;
    int i;
    int tmp1 = num[u];
    int tmp2;
    for(i=0;i<a[u].size();i++){
        tmp2 = a[u][i];
        if(check[tmp2]){
            tmp1 = min(tmp1,num[tmp2]);
        }else{
            n = func(tmp2,n);
            tmp1 = min(tmp1,low[tmp2]);
            if(low[tmp2]>=num[u])isPoint[u] = true;
        }
    }

    low[u] = tmp1;

    return n;
}

int func0(int u, int n){
    if(check[u])return n;

    num[u] = n;
    n++;
    check[u] = true;
    int i;
    int tmp = 0;
    int tmp1 = num[u];
    int tmp2;
    for(i=0;i<a[u].size();i++){
        tmp2 = a[u][i];
        if(check[tmp2]){
            tmp1 = min(tmp1,num[tmp2]);
        }else{
            tmp++;
            n = func(tmp2,n);
            tmp1 = min(tmp1,low[tmp2]);
            if(low[tmp2]>=num[u])isPoint[u] = true;
        }
    }

    low[u] = tmp1;

    if(tmp<2)isPoint[u] = false;

    return n;
}

int main(){
    int i,s,t,V,E;

    scanf("%d %d",&V,&E);

    for(i=0;i<V;i++){
        check[i] = false;
        isPoint[i] = false;
    }
    for(i=0;i<E;i++){
        scanf("%d %d",&s,&t);
        a[s].push_back(t);
        a[t].push_back(s);
    }

    func0(0,1);

    for(i=0;i<V;i++)if(isPoint[i])printf("%d\n",i);

    return 0;
}



Measured memory_bytes: 6304
#include <bits/stdc++.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 VI = vector<int>;
using VVI = vector<vector<int>>;

int main(){
  string s;
  cin >> s;
  int len = s.length();
  VI a(26,0);
  
  rep(i,len){
    int x = s[i] - 'a';
    a[x]++;
  }
  
  bool flag=true;
  rep(i,26){
    if(a[i]%2==1){
      flag = false;
      break;
    }
  }
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")

#define F first
#define S second
#define MT make_tuple
#define SZ(a) ((int)(a).size())
#define PB push_back
#define LBS 20
#define MOD ((long long)1e9+7) //1e9+9
#define LEFT(i) (2*(i))
#define RIGHT(i) (2*(i)+1)
#define PAR(i) ((i)/2)

using namespace std;

typedef long long ll;
typedef double rat;
typedef long long bi;
typedef pair<int, int> ii;
typedef std::vector<ii> vii;
typedef std::map<ll, int> mii;
typedef bitset<LBS> bis;
typedef std::vector<bis> vbs;

template<class T>
void vin(std::vector<T> &a){
  for(auto &x: a)
    cin >> x;
}

template<class T>
void vout(std::vector<T> &a){
  for(auto x: a)
    cout << x << " ";
  cout << endl;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n; cin >> n;
  mii s;
  for(int i=0; i<1<<n; i++){
    ll a; cin>> a;
    s[a]++;
  }
  std::vector<ll> h;
  auto it=s.end();
  it--;
  h.PB(it->F);
  s[h[0]]--;
  if(s[h[0]]==0)
    s.erase(h[0]);
  else{
    cout <<"No\n";
    return 0;
  }
  for(int i=1; i<=n; i++){
    for(int j=0; j<(1<<(i-1)); j++){
      it=s.lower_bound(h[j]);
      if(it==s.begin()){
        cout << "No\n"; return 0;
      }
      it--;
      ll nh=it->F;
      h.PB(nh);
      s[nh]--;
      if(s[nh]==0)
        s.erase(nh);
    }
  }
  cout << "Yes\n";
}


Measured memory_bytes: 18808
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8101145141919364364;

int main(){
	int n,a,b; cin>>n>>a>>b;
	int ans=0;
	rep(i,n){
		int t; cin>>t;
		if(t<a||b<=t) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
struct F{
	int n,d;
	F(int n,int d):n(n),d(d){}
};
F operator-(const F &a,const F &b){
	int rn=a.n*b.d-b.n*a.d,rd=a.d*b.d,g;
	return F(rn,rd);
}
int p,q,a,n;
int rec(int cp,int cq,int cd,int ca,int cn){
	int r=0;
	for(int nd=cd;nd*ca<=a;nd++)if(cp*nd>=cq&&cn!=n){
		if(cp*nd==cq)r++;
		else{
			F nF=F(cp,cq)-F(1,nd);
			r+=rec(nF.n,nF.d,nd,nd*ca,cn+1);
		}
	}
	return r;
}
int main(){
	while(cin>>p>>q>>a>>n,p)cout<<rec(p,q,1,1,0)<<endl;
	return 0;
}

Measured memory_bytes: 864
import sys
import fractions
import functools
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()

L = [0]*n
R = [0]*n
L[0] = INF
L[1] = a[0] 
R[n-1] = INF
R[n-2] = a[n-1]

GCDs = [0]*n

for i in range(2, n):
    L[i] = fractions.gcd(L[i-1], a[i-1])

for i in range(n-3,-1,-1):
    R[i] = fractions.gcd(R[i+1], a[i+1])

GCDs[0] = R[0]
GCDs[n-1] = L[n-1]

for i in range(1,n-1):
    GCDs[i] = fractions.gcd(L[i], R[i])

res = max(GCDs)

print(res)

Measured memory_bytes: 89580
#include <iostream>
#include <iomanip>

int main(){
	
	double a, b, c, d, e, f;
	// input
	while(std::cin >> a >> b >> c >> d >> e >> f){
		
		/*	solve the equation
		*	y = (f - d*x) / e
		*	x = (c*e - b*f) / (a*e - b*d)
		*/
		double x = (c*e - b*f) / (a*e - b*d);
		double y = (a*f - c*d) / (a*e - b*d);
		
		// need this process for submitting
		if(x == -0)	x = 0.0;
		if(y == -0)	y = 0.0;
		// output
		std::cout << std::fixed << std::setprecision(3) << x << " " << y << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 1284
package main

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

type Io struct {
    reader    *bufio.Reader
    writer    *bufio.Writer
    tokens    []string
    nextToken int
}

func NewIo() *Io {
    return &Io{
        reader: bufio.NewReader(os.Stdin),
        writer: bufio.NewWriter(os.Stdout),
    }
}

func (io *Io) Flush() {
    err := io.writer.Flush()
    if err != nil {
        panic(err)
    }
}

func (io *Io) NextLine() string {
    var buffer []byte
    for {
        line, isPrefix, err := io.reader.ReadLine()
        if err != nil {
            panic(err)
        }
        buffer = append(buffer, line...)
        if !isPrefix {
            break
        }
    }
    return string(buffer)
}

func (io *Io) Next() string {
    for io.nextToken >= len(io.tokens) {
        line := io.NextLine()
        io.tokens = strings.Fields(line)
        io.nextToken = 0
    }
    r := io.tokens[io.nextToken]
    io.nextToken++
    return r
}

func (io *Io) NextInt() int {
    i, err := strconv.Atoi(io.Next())
    if err != nil {
        panic(err)
    }
    return i
}

func (io *Io) NextFloat() float64 {
    i, err := strconv.ParseFloat(io.Next(), 64)
    if err != nil {
        panic(err)
    }
    return i
}

func (io *Io) PrintLn(a ...interface{}) {
    fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
    fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
    b := []interface{}{}
    for _, x := range a {
        b = append(b, x)
    }
    io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
    b := []interface{}{}
    for _, x := range a {
        b = append(b, x)
    }
    io.PrintLn(b...)
}

func main() {
    io := NewIo()
	defer io.Flush()
	
	N := io.NextInt()
	A := make([]int, N)
	for i:=0; i<N; i++ {
		A[i] = io.NextInt()
	}

	for i:=1; i<N; i++ {
		io.PrintIntLn(A)
		 v := A[i]
		 j := i-1
		 for j >= 0 && A[j] > v {
			 A[j+1] = A[j]
			 j--
		 }
		 A[j+1] = v
	}
	io.PrintIntLn(A)
}


Measured memory_bytes: 1596
using namespace std;


#ifndef fileio
#include <iostream>
#endif
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <string>
#include <ctime>

typedef long long ll;




struct mcmf {
	int N;
#define BND 1LL<<61
	vector<vector<ll> > cap, fl, cost;
	vector<bool> found;
vector<ll> dist, pi, width;
vector<pair<int, int> > dad;

mcmf(int N) :
	N(N), cap(N, vector<ll>(N)), fl(N, vector<ll>(N)), cost(N, vector<ll>(N)),
	found(N), dist(N), pi(N), width(N), dad(N) {}


mcmf(vector<vector<pair<int, pair<ll, ll>>> > graph) :
	mcmf(graph.size()) {
	for (int u = 0; u < graph.size(); u++) {
		for (auto p : graph[u]) {
			add_edge(u, p.first, p.second.first, p.second.second);
		}
	}
}


void add_edge(int from, int to, ll cap, ll cost) {
	this->cap[from][to] = cap;
	this->cost[from][to] = cost;
}

inline void relax(int s, int k, ll cap, ll cost, int dir) {
	ll val = dist[s] + pi[s] - pi[k] + cost;
	if (cap && val < dist[k]) {
		dist[k] = val;
		dad[k] = make_pair(s, dir);
		width[k] = min(cap, width[s]);
	}
}

ll dijkstra(int s, int t) {
	fill(found.begin(), found.end(), 0);
	fill(dist.begin(), dist.end(), BND);
	fill(width.begin(), width.end(), 0);
	dist[s] = 0;
	width[s] = BND;
	while (s != -1) {
		int best = -1;
		found[s] = true;
		for (int k = 0; k < N; k++) {
			if (found[k]) continue;
			relax(s, k, cap[s][k] - fl[s][k], cost[s][k], 1);
			relax(s, k, fl[k][s], -cost[k][s], -1);
			if (best == -1 || dist[k] < dist[best]) best = k;
		}
		s = best;
	}
	for (int k = 0; k < N; k++)
		pi[k] = min(pi[k] + dist[k], BND);
	return width[t];
}

pair<ll, ll> flow(int s, int t) {
	ll totflow = 0, totcost = 0;
	while (ll amt = dijkstra(s, t)) {
		totflow += amt;
		for (int x = t; x != s; x = dad[x].first) {
			if (dad[x].second == 1) {
				fl[dad[x].first][x] += amt;
				totcost += amt * cost[dad[x].first][x];
			}
			else {
				fl[x][dad[x].first] -= amt;
				totcost -= amt * cost[x][dad[x].first];
			}
		}
	}
	return make_pair(totflow, totcost);
}
};


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

	int n;
	int k;
	cin >> n >> k;
	mcmf d(2 * n + 2);
	vector<vector<int> > v(n, vector<int>());
	for (int i = 0; i < n; i++) {
		d.add_edge(0, i + 1, k, 0);
		d.add_edge(i + n + 1, 2 * n + 1, k, 0);

		for (int j = 0; j < n; j++) {
			d.add_edge(i + 1, 2 * n + 1, k, 0);
			int x;
			cin >> x;
			v[i].push_back(x);
			d.add_edge(i + 1, j + n + 1, 1, -x);
		}
	}

	ll l = d.flow(0, n * 2 + 1).second;
	cout << -l << endl;
	for (int i = 0; i < n; i++) {

		for (int j = n; j < n*2; j++) {
			if (d.fl[i+1][j+1]){
				cout << "X";
			}
			else {
				cout << ".";
			}
		}
		cout << endl;
	}



}





Measured memory_bytes: 3900
import bisect,collections,copy,heapq,itertools,math,string
import sys
import fractions
 
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
 
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
a, b = M()
ans = lcm(a, b)
print(ans)

Measured memory_bytes: 59628
/*
  Code By RyeCatcher
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <vector>
#include <queue>
#include <utility>
#define ri register int
#define ll long long
#define ull unsigned long long
#define pb push_back
#define DEBUG freopen("dat.in","r",stdin);freopen("wa.out","w".stdout);
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define SIZE 23333
using std::min;
using std::max;
using std::pair;
using std::queue;
using std::priority_queue;
using std::vector;
inline char gc(){
    static char buf[SIZE],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,SIZE,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
template <class T>inline void read(T &x){
	x=0;int ne=0;char c;
    while((c=gc())>'9'||c<'0')ne=c=='-';x=c-48;
    while((c=gc())>='0'&&c<='9')x=(x<<3)+(x<<1)+c-48;x=ne?-x:x;return ;
}
int n,m;
int main(){
	read(n),read(m);
	for(ri i=m/n;i>=1;i--){
		if(m%i==0){printf("%d\n",i);break;}
	}
	return 0;
}

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

priority_queue<int> que;

int main(void)
{
	int n;
	cin>> n;
	int two=0;
	unordered_map<int,int> mp;
	for (int i = 0; i < n; i++) {
		int x;
		cin>>x;
		mp[x]++;
	}
	for(auto &x:mp){
		two+=x.second%2==0;
	}
	int ret=mp.size()-two%2;
	cout<<ret<<endl;
	return 0;
}


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

#include <iostream>
#include <fstream>

#include <iostream>
#include <set>

class TaskC {
public:
    void solve(std::istream &in, std::ostream &out) {
        int N;
        in >> N;
        int odds_count = 0;
        int div_by_2_count = 0;
        int div_by_4_count = 0;

        for (int i = 0; i < N; ++i) {
            int number;
            in >> number;
            if (number % 2 == 1) {
                ++odds_count;
            } else if (number % 4 == 0) {
                ++div_by_4_count;
            } else {
                ++div_by_2_count;
            }
        }

        if (odds_count == 0 && div_by_4_count == 0 && div_by_2_count == 1) {
            out << "No\n";
            return;
        }

        if (odds_count > div_by_4_count + 1) {
            out << "No\n";
        } else {
            if (odds_count == div_by_4_count + 1 && div_by_2_count > 0) {
                out << "No\n";
            } else {
                out << "Yes\n";
            }
        }
    }
};


int main() {
    TaskC solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

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

string replaceAll(string s, const string &from, const string &to) {
  int pos = 0, find_pos;
  while ((find_pos = s.find(from, pos)) != string::npos) {
    s.replace(find_pos, from.size(), to);
    pos = find_pos + to.size();
  }
  return s;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    vector<string> a(n), b(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    string s, t;
    cin >> s >> t;

    int tz = t.size();
    map<string, int> d;
    d[s] = 0;
    queue<string> que;
    que.emplace(s);
    while (que.size()) {
      string u = que.front(); que.pop();
      if (u == t) break;
      for (int i = 0; i < n; i++) {
        string v = replaceAll(u, a[i], b[i]);
        if (v.size() <= tz && d.find(v) == d.end()) {
          d[v] = d[u] + 1;
          que.emplace(v);
        }
      }
    }
    cout << (d.find(t) != d.end() ? d[t] : -1) << endl;
  }

  return 0;
}


Measured memory_bytes: 3376
#include<iostream>
using namespace std;
int main()
{
	int n,t;
	int ans=1e9;
	cin>>n>>t;
	for(int i=1;i<=n;i++)
	{
		int a,b;
		cin>>a>>b;
		if(b<=t)ans=min(ans,a);
	}
	if(ans!=1e9) cout<<ans<<endl;
	else cout<<"TLE"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>b(n-1);
    rep(i,n-1){
        cin>>b[i];
    }
    vector<int>a(n);
    for(int i=1; i<n-1; ++i){
        a[i]=min(b[i-1],b[i]);
    }
    a[0]=b[0];
    a[n-1]=b[n-2];
    long ans=0;
    rep(i,n){
        ans+=a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*input
4
aaaa
a
aaa
aa
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
#define DEC(N)	cout << std::fixed; cout << setprecision(N);
void solve()
{
	set <string> s;
	lld n;
	cin >> n;
	rep(i,0,n){
		string a;
		cin >> a;
		s.insert(a);
	} 
	cout << s.size() << endl;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

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

long long Gcd(long long m, long long n){
	long long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

int main(){
  long long A, B, C, D, E, F, G, maxSp, minMt, tmp, result;
  cin >> A >> B >> C >> D;
  result = 0;
  E = max(C, D);
  F = min(C, D);

  
  maxSp = Gcd(C, D);
  minMt = C * D / maxSp;


  result = B-A+1 - (B/C - (A-1)/C) - (B/D - (A-1)/D) + (B/minMt - (A-1)/minMt);
  cout << result << endl;
}

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

using namespace std;

int main()
{
	int n, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		ans += i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int num_5,num_7;
  int i;
  char str[3][10];
  num_5=num_7=0;
  
  scanf("%s",str[0]);
  scanf("%s",str[1]);
  scanf("%s",str[2]);
  
  for(i=0;i<3;i++){
   	if(atoi(str[i])==5){
      	num_5++;
  	}else if(atoi(str[i])==7){
    	num_7++;
    }
  }
  
  if(num_5==2&&num_7==1){
  	printf("YES\n");
  }else{
  	printf("NO\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		int num = sc.nextInt();

		for (int i = 0; i < num; i++) {
			int[] listLeft = new int[11];
			int[] listRight = new int[11];

			listLeft[0] = sc.nextInt();

			int leftNum = 0;
			int rightNum = 0;
			int yesFlag = 0;

			for (int j = 1; j < 10; j++) {
				int inputNum = sc.nextInt();

				if (inputNum < listLeft[leftNum]) {
					if (inputNum < listRight[rightNum]) {
						yesFlag = 1;
					} else {
						rightNum += 1;
						listRight[rightNum] = inputNum;
					}
				} else {
					leftNum += 1;
					listLeft[leftNum] = inputNum;
				}
				
			}
			if (yesFlag == 0) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
			
		}

	}

}

Measured memory_bytes: 26012
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};


int main(){
    int x; cin >> x;
    if(x == 0){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }

}

Measured memory_bytes: 3620
#include<stdio.h>
 
int isPrime(int x){
	int i;
	if(x <= 1)return 0;
	else if (x <= 3)return 1;

	if(x % 2 == 0)return 0;
	if(x % 3 == 0)return 0;

	for(i = 6 ; (i-1)*(i-1) <= x ;i += 6){
		if(x % (i-1) == 0)return 0;
		if(x % (i+1) == 0)return 0;
	}
	return 1;
}
 
int main(){
	int x,i,n;
	int count = 0;
	scanf("%d", &n);
	for(i = 0 ; i < n ; i++){
		scanf("%d", &x);
		if(isPrime(x))count++;
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
 
int main()
{
	int a = 0, dis = 0,maxi = 0,mini=0;
	int num[100000] = {};
	std::cin >> a;


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

		std::cin >> num[i];

	}
	for (int i = 0; i<= a;i++) {
		dis += abs(num[i + 1] - num[i]);
	}
	for (int i = 1; i <= a; i++) {
		
	    std::cout << dis - abs(num[i + 1] - num[i]) - abs(num[i] - num[i - 1]) + abs(num[i + 1] - num[i - 1]);
		std::cout << std::endl;

	}

}



Measured memory_bytes: 1664
N = gets.to_i
S = N.times.map{
	gets.to_i(2)
}

DsMax = lambda{|dbase|
	d, p, q, r, r_1 = 0, 0, 1<<(N-1-dbase), 0, 0
	until q == 0
		raise if 0 != q&r_1
		d, p, q, r = d+1, p|q, 0, (p^q)&q
		r_1 = r
		until 0 == (s = r&(-r))
			q |= S[N-s.bit_length]
			r ^= s
		end
	end
	return d-1
}
begin
	p (0...N).map{|i| DsMax[i] }.max
rescue RuntimeError
	p(-1)
end


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

int main(){
    vector<int> A(4);
    cin >> A[0] >> A[1] >> A[2] >> A[3];
    sort(A.begin(), A.end());
    if (A[0] == 1 && A[1] == 4 && A[2] == 7 && A[3] == 9)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
#-*- coding: utf-8 -*-

# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_C

if __name__ == '__main__':
    a, b = map(int, raw_input().split())
    print a * b, 2 * (a + b)


Measured memory_bytes: 4624