akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
using namespace std;

int n, m, s, dp[50][3001];

int main() {
  while (scanf("%d%d%d", &n, &m, &s), n) {
    for (int i = 0; i <= n*n; i++) for (int j = 0; j <= s; j++) dp[i][j] = 0;
    dp[0][0] = 1;
    for (int k = 1; k <= m; k++) {
      for (int i = n*n-1; i >= 0; i--) {
        for (int j = k; j <= s; j++) dp[i+1][j] = (dp[i+1][j] + dp[i][j-k]) % 100000;
      }
    }
    printf("%d\n", dp[n*n][s]);
  }
}



Measured memory_bytes: 3168
#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)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

template <typename T>
struct SegmentTree {
  int N;
  T init;
  vector<T> dat;
  SegmentTree(int n, T init) : init(init) {
    N = 1;
    while (N < n) N *= 2;
    dat.assign(2*N-1, init);
  }
  void update(int i, T x) {
    i += N - 1;
    dat[i] = x;
    while (i > 0) {
      i = (i - 1) / 2;
      dat[i] = max(dat[i*2+1], dat[i*2+2]);
    }
  }
  // a <= x < b
  T query(int a, int b) { return query(a, b, 0, 0, N); }
  T query(int a, int b, int i, int l, int r) {
    if(r <= a || b <= l) return init;
    if(a <= l && r <= b) return dat[i];
    T vl = query(a, b, i*2+1, l, (l+r)/2);
    T vr = query(a, b, i*2+2, (l+r)/2, r);
    return max(vl, vr);
  }
};

SegmentTree<int>st(200009,0);
int a[200009];
vector<int>to[200009];
int ans[200009];
map<int,int>mp;

void dfs(int v,int p=-1){
  int i=mp[a[v]];
  int temp=st.query(i,i+1);
  st.update(i,st.query(0,i)+1);
  ans[v]=st.query(0,200000);
  for(auto u:to[v]){
    if(u==p)continue;
    dfs(u,v);
  }
  st.update(i,temp);
}

int main(){
  int n;
  cin>>n;
  vector<int>b;
  rep(i,n){
    cin>>a[i];
    b.push_back(a[i]);
  }
  sort(b.begin(),b.end());
  b.erase(unique(b.begin(),b.end()),b.end());
  rep(i,b.size()){
    mp[b[i]]=i;
  }
  rep(i,n-1){
    int s,t;
    cin>>s>>t;
    s--;t--;
    to[s].push_back(t);
    to[t].push_back(s);
  }
  dfs(0);
  rep(i,n){
    cout<<ans[i]<<endl;
  }
  return(0);
}


Measured memory_bytes: 45260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int N;
int a[100010], b[100010];
vector<int> G[100010];
int memo[100010];

int main(void) {
	cin >> N;
	rep(i, N - 1) cin >> a[i] >> b[i];
	rep(i, N - 1) a[i]--, b[i]--;
	rep(i, N - 1) G[a[i]].pb(b[i]), G[b[i]].pb(a[i]);

	queue<pair<int, int>> que;
	que.push(mp(0, 1)), que.push(mp(N - 1, 2));
	memo[0] = 1, memo[N - 1] = 2;
	while(!que.empty()) {
		auto tmp = que.front(); que.pop();
		int u = tmp.fi, num = tmp.se;
		// printf("u %d num %d\n", u, num);
		for(auto v : G[u]) {
			if(memo[v] != 0) continue;
			memo[v] = num;
			que.push(mp(v, num));
		}
	}
	int F = 0, S = 0;
	rep(i, N) {
		if(memo[i] == 1) F++;
		else if(memo[i] == 2) S++;
	}
	if(F > S) printf("Fennec\n");
	else printf("Snuke\n");
	return 0;
}

Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define int int64_t

int gcd(int x, int y){
    if(x%y==0) return y;
    return gcd(y, x%y);
}

signed main(){
    int a,b;
    cin>>a>>b;
    int GCD=gcd(a,b);
    set<int> facts;
    int maxx=sqrt(GCD)+1;
    for(int i=2; i<maxx; i++) {
        if(GCD%i==0) {
            facts.insert(i);
        }
        while(GCD%i==0) {
            GCD/=i;
        }
    }
    facts.insert(GCD);
    int ans=facts.size();
    if(GCD!=1) ans++;
    cout << ans << endl;
}

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

#define ll long long
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define xx first
#define yy second

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

    ll a, b;
    cin >> a >> b;
    
    cout << a*b << endl;
    
    return 0;
}


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

int N;
int C[51], V[51];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> N;
    int ans = 0;
    for (int i=0; i<N; i++)
        cin >> C[i];
    for (int i=0; i<N; i++)
        cin >> V[i];
    for (int i=0; i<N; i++)
        ans += max(0, C[i] - V[i]);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mul3(a) (a)=((a)*3)%MOD
#define mul2(a) (a)=((a)*2)%MOD
const int MOD = 1000000007;
const int MAXN = 55;
long long answer = 1ll;
char up[MAXN], bot[MAXN];
int main(){
	int n;
	scanf("%d", &n);
	scanf("%s %s", up, bot);
	vector<bool> dub;
	for(int i = 0; i < n; i++){
		if(up[i] == up[i + 1]) {
			dub.push_back(false);
			i++;
		} else dub.push_back(true);
	}
	for(int i = 0; i < dub.size(); i++){
		if(dub[i]){
			if(i == 0) mul3(answer);
			else if(dub[i - 1]) mul2(answer);
		} else {
			if(i == 0) {
				mul3(answer);
				mul2(answer);
			} else if(dub[i - 1]) mul2(answer);
			else mul3(answer);
		}
	}
	printf("%lld\n", answer);
	return 0;
}

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

//#include <unordered_map>

//#include <iostream>//POJ
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <math.h>
//#include <algorithm>
//#include <cstring>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define dd(n) cout<<fixed<<setprecision(n)
#define inp(x) (cin>>x,x)
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define repir(i,a,b) for(int i=(a)-1, i##_first=(b); i>=i##_first; --i)
#define repr(i,n) repir(i,n,0)
#define repir_(i,a,b) for(int i=(a), i##_first=(b); i>=i##_first; --i)
#define repr_(i,n) repir_(i,n,0)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
//template<typename T> T vpop(vector<T> *v) {
//    T res = v->back();
//    v->pop_back();
//    return res;
//}
//char vpop(string *v) {
//    char res = v->back();
//    v->pop_back();
//    return res;
//}
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define pi 3.14159265358979
#define co(x) cout<<x<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()

#define pb push_back
#define pq priority_queue
#define np next_permutation

#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);

//#define lint long long
typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;
typedef vector<lint> lvec;
typedef vector<vector<int> > ivvec;
typedef pair<int, int> P;

const int
dx8[8] ={ 0,1,1,1,0,-1,-1,-1 },
dy8[8] ={ 1,1,0,-1,-1,-1,0,1 },
dx9[9] ={ 0,1,1,1,0,0,-1,-1,-1 },
dy9[9] ={ 1,1,0,-1,0,-1,-1,0,1 },
dx4[4] ={ 0,1,0,-1 },
dy4[4] ={ 1,0,-1,0 };

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

int main(){
    setc;
    
    lint n;cin>>n;
    co(800*n-200*(n/15));
    gc();
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
 
    int N;
    scanf("%d", &N);  
    
    int payment = 1000;
    int i = 1;
    while(N>payment){
        payment = payment + 1000;
        }
    
    printf("%d\n", payment-N);
 
    return 0;
}

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

using namespace std;

int main()
{	
  int n;
  cin>>n;
  string s;
  cin>>s;
  
  if( n&1 ) cout<< "No\n";
  else 
  {
  
      string xx = s.substr(0,n/2);
      string yy = s.substr(n/2);
      
      if(xx != yy)
      {
        cout << "No\n";
        return 0;
      }
 
    cout << "Yes\n";
  }
}

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

int main() {
  string s = "0123456789";
  string a,b;
  cin >> a >> b;
  if(a.size() != b.size()){
    if(a.size() > b.size()){
      cout << "GREATER" << endl;
    }
    else{
      cout << "LESS" << endl;
    }
  }
  else{
    for(int i = 0;i < a.size();i++){
      int aa,bb;
      for(int j= 0;j < s.size();j++){
        if(a.at(i) == s.at(j)){
          aa = j;
        }
        if(b.at(i) == s.at(j)){
          bb = j;
        }
      }
      if(aa > bb){
        cout << "GREATER" << endl;
        return 0;
      }
      else if(aa < bb){
        cout << "LESS" << endl;
        return 0;
      }
      else if(i == a.size()-1){
        cout << "EQUAL" << endl;
      }
    }
  }     
}


Measured memory_bytes: 256
s = input()
t = input()

n = len(t) + 1
m = len(s) + 1

data = [[0 for _ in range(n)] for _ in range (m)]

ans = ''
for i in range(1,m) :
  for j in range(1,n) :
    if s[i-1] == t[j-1] :
      data[i][j] = data[i-1][j-1] + 1
    else :
      data[i][j] = max(data[i-1][j] , data[i][j-1])

i = len(s)
j = len(t)

while i>0 and j>0 :
  if data[i][j] == data[i][j-1] :
    j -= 1
  elif data[i][j] == data[i-1][j] :
    i -= 1
  else :
    ans = s[i-1] + ans
    i -= 1
    j -= 1
    
print(ans)

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

int main() {
    auto xi = std::vector<int>();
    for (int i = 0; i < 5; ++i) {
        int x;
        std::cin >> x;
        xi.push_back(x);
    }

    auto iterator = std::find(xi.begin(), xi.end(), 0);
    if (iterator == xi.end()) {
        return 1;
    }

    std::cout << std::distance(xi.begin(), iterator) + 1 << std::endl;

    return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
int m;
vector<vector<int> > res;
int main(){
	scanf("%d",&m);
	int A = 1, B = 2;
	while(A < m){
		A += B;
		B ++;
	}
	if(A == m){
		puts("Yes");
		res.resize(B);
		res[0].push_back(1);
		res[1].push_back(1);
		int c = 1;
		for(int i=2; i<B; i++){
			for(int j=0; j<i; j++){
				++c;
				res[j].push_back(c);
				res[i].push_back(c);
			}
		}
		printf("%d\n",B);
		for(int i=0; i<B; i++){
			printf("%d",res[i].size());
			for(auto x : res[i])
				printf(" %d",x);
			puts("");
		}
	}else
		puts("No");
	return 0;
}


Measured memory_bytes: 2304
a = input()
b = input()
c = input()

s = [a,b,c]
su = len(a) + len(b) + len(c)
i1 = i2 = i3 = 0
chap = 'a'

for i in range(su):
    if(chap == 'a'):
        if(i1 == len(a)):
            chap = 'A'
            break
        chap = a[i1]
        i1 += 1
    elif(chap == 'b'):
        if(i2 == len(b)):
            chap = 'B'
            break
        chap = b[i2]
        i2 += 1
    elif(chap == 'c'):
        if(i3 == len(c)):
            chap = 'C'
            break
        chap = c[i3]
        i3 += 1


print(chap)

Measured memory_bytes: 3064
N,M=map(int,input().split())
H=list(map(int,input().split()))
l=list()
for i in range(M):
  A,B=map(int,input().split())
  if H[A-1]==H[B-1]:
    l.append(A)
    l.append(B)
  elif H[A-1]>H[B-1]:
    l.append(B)
  else:
    l.append(A)
  
minus=(len(set(l)))
print(N-minus)

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    int priority;
    double value;
}data;

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//配列sの中で、keyより初めて小さくなる添字を出力
int binary_search_left(int* array,int min, int max, int key){
    if(min<max){
        int mid=min+(max-min)/2;

        if(key<array[mid]) return binary_search_left(array,min,mid,key);
        else if(key>array[mid]) return binary_search_left(array,mid+1,max,key);
    }
    if(key>array[min]) return min;
    return min-1;
}

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

    //A[0]~A[N-1]に格納する
    int* A;
    NEW(A,N);
    for(int i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    qsort(A,N,sizeof(int),asc);

    int tmp=abs(A[0]-A[N-1]/2);
    int index=0;
    for(int i=0;i<N-1;i++){
        if(tmp>=abs(A[i]-A[N-1]/2)){
            tmp=abs(A[i]-A[N-1]/2);
            index=i;
        }
    }
    printf("%d %d\n",A[N-1],A[index]);

    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
#include <array>
#include <string>
#include <map>
#include <cmath>
//#include <iomainp>
using namespace std;

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


int getIntSp(){
    string str;
    getline(cin,str,' ');
    return stoi(str);
}

int getIntLF(){
    string str;
    getline(cin,str);
    return stoi(str);
}



int main()
{
    int N;
    cin >> N;
    vector<int> vec(N);
    rep(i,N){
        int a;
        cin >> a;
        vec[i] = a;
    }
    
    int counter = 1;
    int num = 0;
    rep(i,vec.size()){
        if(vec[i] != counter){
            num++;
        }else{
            counter++;
        }
    }
    if( 0 == vec.size() - num ){
        cout << -1 << endl;
    }else{
        cout << num << endl;
    }
    return 0;
}



Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main{
	static long  memo[][];
	static int we[];
	static long v[];
	public static long dp(int i,int w) {
        if(i==we.length||w==0) return 0;
		if(memo[i][w]!=-1) {return memo[i][w];}else if(we[i]>w)memo[i][w]=dp(i+1,w);else{
		
		 memo[i][w]=Math.max(dp(i+1,w), dp(i+1,w-we[i])+v[i]);}
		return memo[i][w];}
		
	
	public static void main(String []args) throws IOException {
 		PrintWriter pw =new PrintWriter(System.out);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		StringTokenizer st =new StringTokenizer(br.readLine());
		int n=Integer.parseInt(st.nextToken());
		int w=Integer.parseInt(st.nextToken());
		we=new int [n];
		v=new long[n];
		memo=new long [n][w+1];
		for(int i=0;i<n;i++) {
			st =new StringTokenizer(br.readLine());
			we[i]=Integer.parseInt(st.nextToken());
			v[i]=Long.parseLong(st.nextToken());
		}for(int i=0;i<n;i++)for(int j=0;j<w+1;j++)memo[i][j]=-1;
		
		System.out.println(dp(0,w));
		
}}

Measured memory_bytes: 126956
#include<iostream>
               
                #include<string> 
                using namespace std;
                int main(){
                  int a,b,i,j;
                  cin>>a>>b;
                  char c[a][b];
                 string s; 
                  for(i=0;i<a;i++){
                    cin>>s;
                    for(j=0;j<b;j++)
                      c[i][j]=s[j];
                  }
                  for(i=0;i<a;i++){
                    for(j=0;j<b;j++){
                      cout<<c[i][j];
                    }
                  cout<<endl;
                  for(j=0;j<b;j++){
                      cout<<c[i][j];
                    }
                  cout<<endl;
                }
                  return 0;
                }

Measured memory_bytes: 3112
//第 4 問: ABC 087 B - Coins (200 点)

import java.util.Scanner;

public class Main{

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		int H,W,A,B = 0;

		H = scan.nextInt();
		W = scan.nextInt();
		A = scan.nextInt();
		B = scan.nextInt();

		scan.close();

		String x = "";
		String y = "";

		int arr[] = new int[W];
		int arr2[] = new int[W];

		for(int j=0; j < W; j++)
		{
			if(j<A){
				x= x.concat("1");
				y= y.concat("0");

			}

			else
			{
				x= x.concat("0");
				y= y.concat("1");
			}
		}


		for(int i=0; i < H; i++)
		{

			if(i<B){
				System.out.println(x);
			}
			else {
				System.out.println(y);

			}
		}
	}
}



Measured memory_bytes: 25812
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#define LLMAX 9223372036854775807

using namespace std;
using ll = long long;

int main() {
	ll argN, argY;
	cin >> argN >> argY;

	argY /= 1000;

	for (ll i = 0; i <= argN; ++i) {
		for (ll j = 0; j <= argN - i; ++j) {
			ll k = argN - i - j;
			ll ret = k + 5 * j + 10 * i;
			if (ret == argY) {
				cout << i << ' ' << j << ' ' << k << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define INF 987654321

int minChange(vector<int> value, int n){
  // dp[i] := i 円を払うお釣りの最小枚数
  vector<int> dp(n + 1, INF); // n + 1 個の inf (十分大きな値) で初期化
  dp[0] = 0;

  for(int i = 0; i <= n; ++i){
    for(int j = 0; j < value.size(); ++j){
      if(i - value[j] >= 0){                       // 配列の範囲外チェック
        dp[i] = min(dp[i - value[j]] + 1, dp[i]);  // i - value[j] 円払えるなら、それに value[j] 円を 1 枚足して i 円を払える
      }
    }
  }

  return dp[n];
}

int main() {
  int n;
  cin >> n;
  vector<int> c;
  c.push_back(1);
  c.push_back(6);
  c.push_back(9);

  int tmp = 6;
  while (tmp*6 < 100000) {
    c.push_back(tmp * 6);
    tmp *= 6;
  }
  tmp = 9;
  while (tmp*9 < 100000) {
    c.push_back(tmp * 9);
    tmp *= 9;
  }

  sort(c.begin(),c.end());

  cout << minChange(c,n) << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        String C[] = new String[H];
        for (int i=0; i<H; i++) {
            C[i] = sc.next();
        }
        for (int i=0; i<H; i++) {
            System.out.println(C[i]);
            System.out.println(C[i]);
        }
    }
}

Measured memory_bytes: 24232
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

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

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

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int N;
    cin >> N;

    int minimum = 1000;
    int maximum = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        chmin(minimum, a);
        chmax(maximum, a);
    }

    cout << maximum - minimum << endl;

    return 0;
}


Measured memory_bytes: 256
<?php
while($n = trim(fgets(STDIN))) {
    echo ceil(step($n)/3650).PHP_EOL;
}
   
function fact($n){
    if($n==0 || $n==1)
        return 1;
    else
        return $n*fact($n-1);
}
  
function step($n){
    $step=0;
    static $a=array();
    if(isset($a[$n]))
        return $a[$n];
   
    if($n<=3){
        for($i=0;$i*2<=$n;$i++){
            for($j=0;$j*3+$i*2<=$n;$j++){
                $s[$i][$j] = ($n-$i*2-$j*3);
                $step+= fact($i+$j+$s[$i][$j])/(fact($i) * fact($j) * fact($s[$i][$j]));    
            }
        }
        return $a[$n] = $step;
    }
    else {
        return $a[$n] = step($n-1)+step($n-2)+step($n-3);
    }
}
?>

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

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

ll cnt = 0; 

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 

int main(){ 
  string s;
  cin>>s;

  ll n = s.length();
  if(n%2==1){
    s = s.substr(0, n-1);
    n--;
  }
  else {
    s = s.substr(0, n-2);
    n--;n--;

  }

  ll m = n;
  ll ans = 0;
  rep(i, n/2){
    //cout <<s.substr(0, m/2)<<" "<<s.substr(m/2, m/2) <<endl;
    if(s.substr(0, m/2)==s.substr(m/2, m/2)) {
      ans = m;
      break;
    }
    m--;m--;
  }

  
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from collections import defaultdict, Counter
from itertools import permutations, product, combinations
from bisect import bisect, bisect_left
from fractions import gcd
MOD = 10**9 + 7

def inpl(): return list(map(int, input().split()))

N = int(input())
S = input()
C = Counter(S)
ans = 1
for v in C.values():
    ans = (ans*(v+1))%MOD
print(ans-1)

Measured memory_bytes: 5880
from bisect import bisect_right

N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())

aca = [0]*(N+1)
acb = [0]*(M+1)

for i in range(1, N+1):
    aca[i] = aca[i-1]+A[i-1]
for i in range(1, M+1):
    acb[i] = acb[i-1]+B[i-1]

ans = 0
for i in range(N+1):
    pos = bisect_right(acb, K-aca[i])-1
    if pos>=0:
        ans = max(ans, i+pos)

print(ans)


Measured memory_bytes: 47376
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
L = []
L.append({a, b, c})
L.append({d, e, f})
L.append({g, h, i})
L.append({a, d, g})
L.append({b, e, h})
L.append({c, f, i})
L.append({a, e, i})
L.append({c, e, g})
N = int(input())
B = {int(input()) for i in range(N)}
if any(l <= B for l in L):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
s = input()
t = "".join(s.split("x"))
if t!=t[::-1]:print(-1);exit()
ans = 0
i,j=0,len(s)-1
while i<j:
    if s[i]==s[j]:i+=1;j-=1
    elif s[i]=="x":ans+=1;i+=1
    elif s[j]=="x":ans+=1;j-=1
print(ans)

Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
char b;
bool a[1005][1005];
ll man=1e9+7;
ll dp[1005][1005];
ll h,w,ans;
int main()
{
	int i,j;
	cin>>h>>w;
	for(i=1;i<=h;i++)
	{
		for(j=1;j<=w;j++)
		{
			cin>>b;
			if(b=='.')
			a[i][j]=1;
			else
			a[i][j]=0;
		}
	}
	dp[1][1]=1;
	for(i=1;i<=h;i++)
	{
		for(j=1;j<=w;j++)
		{
			if(!(i==1&&j==1))
			if(a[i][j]==1)
			dp[i][j]=(dp[i][j-1]+dp[i-1][j])%man;
			else
			dp[i][j]=0;
		}	
	}
	
	cout<<dp[h][w];
}


Measured memory_bytes: 12468
#include<iostream> 
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath> 
#include<algorithm>
#define ll long long 
using namespace std;
const int maxn=500010, inf=1e9;
int n;
int a[maxn];

template<typename T>
inline void read(T &k)
{
	int f=1; k=0; char c=getchar();
	while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
	while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
	k*=f;
}

int main()
{
	read(n);
	for(int i=1;i<=n;i++) read(a[i]), a[i]-=i;
	sort(a+1, a+1+n); 
	int mid=a[(n+1)>>1];
	ll ans=0; for(int i=1;i<=n;i++) ans+=abs(mid-a[i]);
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;
#define ll long long int
int N;
int M;
int X;
int C[12];
int A[12][12];

ll r[12];
ll mincost;
int main(){
    mincost=LLONG_MAX;
    cin>>N;
    cin>>M;
    cin>>X;
        for(int i=0;i<N;i++){
                ll input1;
                cin>>input1;
                C[i]=input1;
                
            for(int j=0;j<M;j++){
                ll input;
                cin>>input;
                A[i][j]=input;
            }
        }
    //    cout<<endl<<((1<<N)-1)<<endl;
    for(ll ca=0;ca<=(1<<N)-1/*0b111111111111*/;ca++){
        for(int i=0;i<N;i++){
            if(ca&(1<<i)){
                for(int j=0;j<M;j++){
                    r[j]+=A[i][j];
                }
            }
        }
        bool enough=true;
        ll cost=0;
        for(int i=0;i<M;i++){
            if(r[i]<X){
                enough=false;
            }
            r[i]=0;
        }
        if(!enough){
            continue;
        }
        for(int i=0;i<N;i++){
            if(ca&(1<<i)){
                cost+=C[i];
            }
        }
        mincost=min(mincost,cost);
    }
    if(mincost==LLONG_MAX){
        cout<<-1;
        return 0;
    }
    cout<<mincost;
}

Measured memory_bytes: 3624
n, m = map(int, input().split())
d = [False for _ in range(n)]
x = [0 for _ in range(n)]
penalty = 0
for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if d[p]:
        continue
    if s == 'AC':
        d[p] = True
        penalty += x[p]
    else:
        x[p] += 1

print(sum(d), penalty)


Measured memory_bytes: 4696
#include <bits/stdc++.h>
using namespace std;
char dir(int a, int b){
	if(a == 0 && b == 0) return 'U'; 
	else if(a == 0 && b == 1) return 'R'; 
	else if(a == 1 && b == 0) return 'L'; 
	else if(a == 1 && b == 1) return 'D'; 
}
int main() {
	int N; 
	cin >> N; 
	long long int X[1010] = {}, Y[1010] = {}, Z[1010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> X[i] >> Y[i]; 
		Z[i] = (abs(X[i]) + abs(Y[i])) % 2; 
	}
	bool possible = true; 
	for(int i = 0; i < N; i++){
		if(Z[i] != Z[0]){
		possible = false;
		break; 
        	}
	}
	if(!possible){
		cout << -1 << endl; 
	}
	else if(Z[0] == 1){
		cout << 31 << endl; 
		for(int i = 0; i <= 30; i++){
			cout << (1 << i) << " "; 
		}
		cout << endl; 
		for(int i = 0; i < N; i++){
          		long long int a = (2147483647 - Y[i] - X[i])/2; 
			long long int b = (2147483647 - Y[i] + X[i])/2; 
			for(int j = 0; j < 31; j++){
				cout << dir((int) a % 2, (int) b % 2); 
				a = (a >> 1), b = (b >> 1);
			}
		cout << endl; 
		}
	}
	else if(Z[0] == 0){
		cout << 32 << endl; 
		cout << 1 << " "; 
		for(int i = 0; i <= 30; i++){
			cout << (1 << i) << " "; 
		}
		cout << endl; 
		for(int i = 0; i < N; i++){
			cout << 'L'; 
          		long long int a = (2147483647 - Y[i] - X[i] - 1)/2; 
			long long int b = (2147483647 - Y[i] + X[i] + 1)/2; 
			for(int j = 0; j < 31; j++){
				cout << dir((int) a % 2, (int) b % 2); 
				a = (a >> 1), b = (b >> 1);
			}
		cout << endl; 
		}
	}
}

Measured memory_bytes: 256
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
for _ in range(q):
    v,val=map(int,input().split())
    cnt[v]+=val
q=collections.deque()
q.append(1)
checked=[0]*(n+1)
while(q):
    v=q.pop()
    checked[v]=1
    for u in g[v]:
        if(checked[u]==1):
            continue
        cnt[u]+=cnt[v]
        q.append(u)
print(*cnt[1:])

Measured memory_bytes: 56060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Comparator;

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

    static class DIslandsWar {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            in.nextInt(); //>> NUL
            int m = in.nextInt();
            DIslandsWar.Tuple[] operations = new DIslandsWar.Tuple[2 * m];
            for (int i = 0; i < m; i++) {
                int a = in.nextInt(), b = in.nextInt();
                operations[i * 2] = new DIslandsWar.Tuple(a, DIslandsWar.Type.START, i);
                operations[i * 2 + 1] = new DIslandsWar.Tuple(b, DIslandsWar.Type.END, i);
            }
            Arrays.sort(operations,
                    Comparator.comparingInt(DIslandsWar.Tuple::getIslandID)
                            .thenComparing(DIslandsWar.Tuple::getType, Comparator.reverseOrder())
            );

            int res = 0;
            boolean[] deleted = new boolean[m];
            int left = 0;
            for (int i = 0; i < 2 * m; i++) {
                if (operations[i].type == DIslandsWar.Type.END && !deleted[operations[i].i]) {
                    res++;
                    for (; left <= i; left++) {
                        if (operations[left].type == DIslandsWar.Type.START) {
                            deleted[operations[left].i] = true;
                        }
                    }
                }
            }
            out.println(res);
        }

        static class Tuple {
            int pos;
            DIslandsWar.Type type;
            int i;

            Tuple(int pos, DIslandsWar.Type type, int i) {
                this.pos = pos;
                this.type = type;
                this.i = i;
            }

            int getIslandID() {
                return pos;
            }

            DIslandsWar.Type getType() {
                return type;
            }

        }

        enum Type {
            START,
            END,;
        }

    }
}



Measured memory_bytes: 99184
#include <stdio.h>
#include <stdlib.h>

int q(const void *a,const void *b)
{
    return *(int*)a-*(int*)b;
}

int main(void)
{
    int n,x,a[100],s=0,i;
    scanf("%d%d",&n,&x);
    for(i=0;i<n;++i)scanf("%d",&a[i]);
    qsort(a,n,sizeof(int),q);
    for(i=0;i<n-1;++i){
        if(x>=a[i]){
            x-=a[i];
            ++s;
        }
    }
    if(x==a[i])++s;
    printf("%d",s);
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep(i,4){
    if(s[i] == '+') ans++;
    else ans--;
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> lucas(n + 1);
    lucas.at(0) = 2;
    lucas.at(1) = 1;
    for(int i = 2; i <= n; ++i){
        lucas.at(i) = lucas.at(i - 1) + lucas.at(i - 2);
    }
    cout << lucas.at(n) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

template<typename T>
void maxi(T &a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T b) {
	a = min(a, b);
}

const int nmax = 100000;
int dp[12][nmax + 1];//i-1番目までを使ってその数字を作ったときの一番少ない引き出し回数

int main() {
	makei(N);
	rep(nmax + 1)dp[0][i] = i;
	vi v;
	for (int i = 6; i <= nmax; i *= 6)v.push_back(i);
	for (int i = 9; i <= nmax; i *= 9)v.push_back(i);
	For(i, 11) {
		For(j, nmax + 1) {
			if (j < v[i])dp[i + 1][j] = dp[i][j];
			else dp[i + 1][j] = min(dp[i][j], 1 + dp[i + 1][j - v[i]]);
		}
	}
	say(dp[11][N]);
}

Measured memory_bytes: 4992
#include <stdio.h>

int search(int a[],int n,int key){
	int i = 0;
	a[n] = key;
	while(a[i] != key){
		i++;
	}
	return i != n;
}

int main(){
	int i,n,a[10000+1],q,key,sum = 0;
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%d",&a[i]);
	}
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&key);
	
		if(search(a,n,key)){
			sum++;
		}
	}
		printf("%d\n",sum);
		return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)


int main(){
    ll N, M; cin >> N >> M;
    vector<vector<pair<ll,ll>>> G(N+1);
    rep(i, 0, M){
        ll v, u, w;
        cin >> v >> u >> w;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }
    rep(i, 1, N) {
        G[i+1].push_back({i, 0});
    }

    ll srt = 1;
    constexpr ll INF = 1e18;
    vector<ll> d(N+1, INF);
    
    /* dijkstra's scope */{
        priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> que;
        que.push({0, srt});
        d[srt] = 0;
        while(!que.empty()){
            auto q = que.top();
            que.pop();
            if(q.first > d[q.second]) continue;
            for(auto g : G[q.second]){
                if(d[g.first] <= q.first + g.second) continue;
                d[g.first] = q.first + g.second;
                que.push({d[g.first], g.first});
            }
        }
    }

    if(d[N] == INF) cout << -1 << endl;
    else cout << d[N] << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> l(n), r(n);
    vector<int> d(n,0);
    rep(i,n){
        l[i] = i + a[i];
        r[i] = i - a[i];
        if (r[i] > 0)d[r[i]] += 1;
    }
    ll ans = 0;
    rep(i, n){
        if(l[i] < n)ans += d[l[i]];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int n, W;
int w[105], v[105];
long long dp[105][100005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> W;
    for (int i = 1; i <= n; i++)
    {
        cin >> w[i] >> v[i];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= W; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if (j >= w[i])
            {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
            }
        }
    }
    cout << dp[n][W];
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  int h;
  int maxh=0;
  int x=0;
  for(int i=0;i<n;i++){
      cin>>h;
      if(h >= maxh){
          x++;
          maxh=h;
      }
  }
  cout<<x<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1001001001;
const double EPS = 1e-10;
struct Edge { ll from, to, cost; };
using Graph = vector<vector<Edge>>;

bool is_prime[101010];

void eratos(int x){
    fill(is_prime,is_prime+101010,true);
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i*i<=x;i++){
        if(!is_prime[i])continue;
        for(int j=2*i;j<=x;j+=i)is_prime[j]=false;
    }
}

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

    eratos(101010);
    int c_sum[101010]={};
    for(int x=1;x<101010;x++){
        if(x%2==0){
            c_sum[x]=c_sum[x-1];
            continue;
        }
        int y=(x+1)/2;
        if(is_prime[x]&&is_prime[y])c_sum[x]=(x>1?c_sum[x-2]:0)+1;
        else c_sum[x]=(x>1?c_sum[x-2]:0);
    }
    int q;
    cin>>q;
    for(int i=0,l,r;i<q;i++){
        cin>>l>>r;
        cout<<c_sum[r]-c_sum[l-1]<<endl;
    }
}

Measured memory_bytes: 4128
from collections import deque

n, q = map(int, input().split())

que = deque()

for _ in range(n):
	s, t = input().split()
	t = int(t)
	que.append((s, t))

t = 0
while len(que)>0:
	name, time = que.popleft()
	if time<=q:
		t += time
		print("{} {}".format(name,t))
	else:
		que.append((name, time-q))
		t += q


Measured memory_bytes: 12532
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
int n,m,l=0;
vector<int> v[601];
double dp[601][601];
double ma[601]={};
double reg(int x){
	if(dp[l][x]!=-1)return dp[l][x];
	if(x==n)return 0;
	double res=0;
	int vsi=v[x].size();
	for(int i=0;i<vsi;++i){
		res+=reg(v[x][i]);
	}
	if(x==l){
		res-=ma[x];
		vsi--;
	}
	res/=vsi;
	return dp[l][x]=res+1;
}
int main() {
	rep(i,0,601){
		rep(j,0,601)dp[i][j]=-1;
	}
	int a,b;
	cin>>n>>m;
	rep(i,0,m){
		cin>>a>>b;
		v[a].push_back(b);
	}
	double ans=reg(1);
	for(int i=1;i<n;++i){
		if(v[i].size()<2)continue;
		l=i;
		ma[i]=0;
		rep(j,0,v[i].size()){
			ma[i]=max(ma[i],dp[0][v[i][j]]);
		}
		ans=min(ans,reg(1));
//		cout<<ma[i]<<" "<<reg(1)<<endl;
	}
	cout<<fixed;
	cout << setprecision(6) << ans<<endl;
	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll A, B;
  cin >> A >> B;
  if(A == B){
    cout << A << endl;
    return 0;
  }
  ll ans;
  ll num = B - A + 1;
  ll mid;
  if(num % 2 == 0){
    if(A % 2 == 1){
      ans = A^B;
      mid = num-2;
    }
    else{
      ans = 0;
      mid = num;
    }
  }
  else{
    mid = num-1;
    if(A%2==0) ans = B;
    else ans = A;
  }
  if(mid % 4 == 2) ans ^= 1;

  cout << ans << endl;
}

Measured memory_bytes: 256
var lines = [];

var readline = require("readline");

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var tmp = lines.shift();
    var n = Number(tmp.split(" ")[0]);
    var m = Number(tmp.split(" ")[1]);

    var city = Array(m);
    var result = "";

    for (var i = 0; i < m; i++) {
        tmp = lines[i].split(" ");
        city[i] = {
            "i": i,
            "P": Number(tmp[0]),
            "Y": Number(tmp[1]),
            "KenNum": "",
            "ShiNum": "",
        }
    }

    city.sort(function (a, b) {
        if (a.P < b.P) return -1;
        if (a.P > b.P) return 1;
        if (a.Y < b.Y) return -1;
        if (a.Y > b.Y) return 1;
        return 0;
    });

    var ken  = 1;
    var shi  = 1;
    var loop = 0;
    
    for (var i=0;i<m;i++) {
        if(ken === city[i].P) {
            city[i].KenNum = ken.toString();
            loop = 6 - ken.toString().length;

            for (var k = 0; k < loop; k++) { city[i].KenNum = "0" + city[i].KenNum; }

            city[i].ShiNum = shi.toString();
            loop = 6 - shi.toString().length;

            for (var k = 0; k < loop; k++) { city[i].ShiNum = "0" + city[i].ShiNum; }
            shi++;
        }
        else{ken++; shi=1; i--;}
    }
    city.sort(function(a,b){return(a.i-b.i)});
    for (var i=0;i<m;i++) {
        console.log(city[i].KenNum+city[i].ShiNum);
    }
});

Measured memory_bytes: 90200
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;


int main(){
  int m,mi,ma;
  scanf ("%d %d %d",&m,&mi,&ma);
  while(m){
    int ans=0;
    int k=0;
    vector<int> p(m);
    for(int t=0;t<m;t++){
      scanf ("%d",&p[t]);
    }
    for(int t=mi-1;t<ma;t++){
      if(k<=(p[t]-p[t+1])){
        k=(p[t]-p[t+1]);
        ans=t;
      }
    }
    printf("%d\n",ans+1);
    scanf ("%d %d %d",&m,&mi,&ma);
  }
}




Measured memory_bytes: 3132
X = int(input())
n = 100003
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)
Y = [i for i in primes if i>=X]
print(Y[0])

Measured memory_bytes: 14312
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


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

#include <atcoder/fenwicktree>
using fwtree = atcoder::fenwick_tree<ll>;

int main()
{
    int N, Q;
    io >> N >> Q;
    fwtree fw(N);
    for (int i = 0; i < N; i++)
    {
        ll a;
        io >> a;
        fw.add(i, a);
    }

    for (int q = 0; q < Q; q++)
    {
        int c, a, b;
        io >> c >> a >> b;
        if (c == 0)
        {
            fw.add(a, b);
        }
        else
        {
            io << fw.sum(a, b) << BR;
        }
        
    }
    
}

Measured memory_bytes: 8228
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {
	ll X, Y;
	cin >> X >> Y;
	ll ans = 0;
	ll a = X;
	while (a <= Y) {
		a *= 2;
		ans++;
	}
	cout << ans << endl;
}

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

int main()
{
    int a, b, c; cin >> a >> b >> c;

    map<int, int> mp;

    mp[a]++;
    mp[b]++;
    mp[c]++;

    for(auto& pr : mp) if(pr.second == 1)
        cout << pr.first << endl;

    return 0;
}

Measured memory_bytes: 256
def chunk_list(index_list, data):
  result = []
  start = 0
  for i in index_list:
    result.append(data[start:i+1])
    start = i+2
    print(start)
  result.append(data[start:len(data)])
  return result
  
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count
  
def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import math
import fractions
import collections
from functools import reduce

def main():
  n, m = input_list()
  if n >= m:
    print(0)
    exit(0)
  x = list(set(input_list()))
  sx = list(sorted(x))
  diffs = []
  for i, xv in enumerate(range(len(x)-1)):
    diff = abs(sx[i+1]-sx[i])
    diffs.append(diff)
  sd = list(sorted(diffs, reverse=True))

  for i in range(n-1):
    sd[i] = 0
    if i == m-1:
      break

  ans = 0
  for a in sd:
    ans += a
  print(ans)
main()

Measured memory_bytes: 16216