akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    sort(d.begin(), d.end());
    if (n % 2 != 0) cout << 0 << endl;
    else {
        int a = d[n / 2 - 1];
        int b = d[n / 2];
        cout << b - a << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define ll long long
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1316

int h, w;

int dy[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

set<string> Set;
int Maxlen = 0;
string ans;
vector<string> donut;
vector<vector<int>> usage;

void solve(int i, int j) {
	for (int k = 0; k < 8;k++) {
		usage.clear();
		usage.resize(h, vector<int>(w, 0));
		string ret = "";
		int y = i, x = j;
		while (usage[y][x] == 0) {
			ret += donut[y][x];

			if (Set.find(ret) != Set.end()) {
				if (ret.length() > Maxlen) {
					Maxlen = ret.length();
					ans = ret;
				}
				else if (ret.length() == Maxlen && ret < ans) {
					ans = ret;
				}
			}
			else {
				Set.insert(ret);
			}

			usage[y][x] = 1;
			y = (y + dy[k] + h) % h;
			x = (x + dx[k] + w) % w;


		}
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	while (cin >> h >> w) {
		if (h == 0 && w == 0)break;
		Maxlen = 0;
		ans = "";
		donut.clear();
		donut.resize(h);
		Set.clear();
		for (int i = 0; i < h;i++) {
			cin >> donut[i];
		}

		for (int i = 0; i < h;i++) {
			for (int j = 0; j < w;j++) {
				solve(i, j);
			}
		}
		if (ans.length() < 2) cout << 0 << endl;
		else cout << ans << endl;
	}

}

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

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

int n;
int a, b;
ll res;
unordered_map<int,int> ma;

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

  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    b = i - a;
    if (ma.count(b))
      res += ma[b];
    ++ma[a + i];
  }

  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 11388
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

const lld N = 200043;
const lld MOD = 1000000007;

lld add(lld x, lld y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

lld mul(lld x, lld y)
{
    return (x * 1ll * y) % MOD;
}

lld binpow(lld x, lld y)
{
    lld z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

lld inv(lld x)
{
    return binpow(x, MOD - 2);
}

lld divide(lld x, lld y)
{
    return mul(x, inv(y));
}

// Combinations

/*
lld fact[N];

void precalc()
{
    fact[0] = 1;
    for(lld i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

lld C(lld n, lld k)
{
    return divide(fact[n], mul(fact[k], fact[n - k]));
}
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t,i,j;
    t=1;
    while(t--)
    {
        string str;
        cin>>str;
        if(str=="ABC")
            cout<<"ARC"<<endl;
        else
            cout<<"ABC"<<endl;
    }
}



Measured memory_bytes: 3656
#!/usr/bin/python

def readints(line):
    return map(int, line.split())

def cut(xs, k):
    return xs[k:] + xs[:k] 

def reffle(xs):
    ys = xs[:]
    k = len(ys)/2
    for i in range(k):
        xs[i*2] = ys[i]
        xs[i*2+1] = ys[i+k]
    return xs


def shuffler(f):
    n, = readints(f.readline())
    xs = list(range(1, 2*n+1))
    m, = readints(f.readline())
    for i in range(m):
        k, = readints(f.readline())
        if k == 0:
            xs = reffle(xs)
        else:
            xs = cut(xs, k)
    for x in xs:
        print x


import sys
shuffler(sys.stdin)

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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll V,E;cin>>V>>E;
  ll dist[V][V];
  // CLR(dist,0);
  rep(i,0,V)rep(j,0,V)dist[i][j]=INF;
  rep(i,0,E){
    ll a,b,d;cin>>a>>b>>d;
    dist[a][b]=d;
  }

  ll dp[(1<<V)][V];
  rep(i,0,(1<<V))rep(j,0,V)dp[i][j]=INF;
  dp[1][0]=0;

  rep(bit,0,(1<<V)){
    rep(i,0,V){
      if(dp[bit][i]==INF)continue;
      rep(j,0,V){
        if((bit>>j)%2==1)continue;

        ll next=bit|(1<<j);
        chmin(dp[next][j],dp[bit][i]+dist[i][j]);
      }
    }
  }
  
  ll all=(1<<V)-1;
  ll ans=INF;
  rep(i,0,V){
    if(dp[all][i]==INF)continue;
    chmin(ans,dp[all][i]+dist[i][0]);
  }
  
  if(ans==INF)out(-1);
  else out(ans);


  return 0;
}



Measured memory_bytes: 6944
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

//# include <ext/pb_ds/assoc_container.hpp>
//# include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;
//	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//	shuffle(permutation.begin(), permutation.end(), rng);

void go (int p = 0) {
	if (p == n) {
		string ans = "";
		for (int i = 0; i < n; ++i) {
			ans += char('a' + a[i]);
		}
		cout << ans << '\n';
		
		return;
	}	
	
	for (int j = 0; j <= cur; ++j) {
		a[p] = j;
		go(p+1);
	}
	if (cur < p) {
		a[p] = ++cur;
		go(p+1);
		--cur;
	}

}

int main () {
	scanf("%d", &n);
	go();
	return Accepted;
}

// B...a

Measured memory_bytes: 19968
import collections

n = int(input())
nxts = collections.defaultdict(list)
for i in range(n - 1):
    a, b = map(int, input().split())
    nxts[a - 1].append(b - 1)
    nxts[b - 1].append(a - 1)

def f(first):
    d = [-1] * n
    d[first] = 0
    stack = [first]
    while stack:
        current = stack.pop()
        for nxt in nxts[current]:
            if d[nxt] == -1:
                d[nxt] = d[current] + 1
                stack.append(nxt)
    return d

d1 = f(0)
d2 = f(n - 1)
c1 = sum(1 for x1, x2 in zip(d1, d2) if x1 <= x2)
c2 = n - c1


if c1 > c2:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 37852
N=int(input())
An=list(map(int,input().split()[:N+1]))
Bn=list(map(int,input().split()[:N]))

ret=0

for i in range(N,0,-1):
    tmp=Bn[i-1]
    if An[i] >= tmp:
        An[i]-=tmp
        ret+=tmp
        continue
    else:
        tmp-=An[i]
        ret+=An[i]
        An[i]=0
        if An[i-1]>=tmp:
            An[i-1]-=tmp
            ret+=tmp
        else:
            ret+=An[i-1]
            An[i-1]=0
print(ret)
    

Measured memory_bytes: 18800
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    string S;
    cin >> S;
    if (S == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (S == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main{
	static int lower(int[] a, int key) {
		int high = a.length, low = -1;
		while(high - low > 1) {
			int mid = (high + low) / 2;
			if(a[mid] < key) low = mid;
			else high = mid;
		}
		return low;
	}
	static int upper(int[] a, int key) {
		int high = a.length, low =  -1;
		while(high - low > 1) {
			int mid = (high + low) / 2;
			if(a[mid] > key) high = mid;
			else low = mid;
		}
		return high;
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		int[] C = new int[N];
		long ans = 0;
		for(int i = 0; i < N; i++) A[i] = sc.nextInt();
		for(int i = 0; i < N; i++) B[i] = sc.nextInt();
		for(int i = 0; i < N; i++) C[i] = sc.nextInt();
		Arrays.sort(A); Arrays.sort(B); Arrays.sort(C);

		for(int i = 0; i < N; i++) {
			int idx_A = lower(A, B[i]), idx_C = upper(C, B[i]);
			if(idx_A == -1 || idx_C == N) continue;
			ans += (long)(idx_A + 1) * (long)(N - idx_C);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 95584
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int sum[2010];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    L.push_back(INF);
    sort(L.begin(), L.end());
    ll ans = 0;
    rep(i, N) sum[L[i]]++;
    rep(i, 2000) sum[i + 1] += sum[i];
    rep(i, N) {
        REP(j, i + 1, N - 1) {
            int lower = abs(L[i] - L[j]);
            int upper = L[i] + L[j];
            ans += sum[upper - 1] - sum[lower];
            if(lower < L[i] && L[i] < upper) ans--;
            if(lower < L[j] && L[j] < upper) ans--;
            //cout << lower << " " << upper << " " << ans << endl;
        }
    }
    cout << ans/3 << endl;

    return 0;
}
// 1 2 3 4

// a - b< c
// b - a< c 
// c < a + b

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b;
  while(1){
    scanf("%d%d\n",&a,&b);
    if(a==0 && b==0){
        break;
    }
    else if(a>b)printf("%d %d\n",b,a);
    else printf("%d %d\n",a,b);
    
  }
  return 0;
}



Measured memory_bytes: 2040
n = int(input())
act = [["dammy"]]
for i in range(n):
    act.append(list(map(int, input().split())))
dp = [[0]*3 for i in range(n+1)]

for i in range(1,n+1):
    dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + act[i][0]
    dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + act[i][1]
    dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + act[i][2]
    
print(max(dp[n]))

Measured memory_bytes: 47340
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N;
      cin >> N;
     
      vector<int> math(N); // N個の数学の点数データ
      vector<int> english(N); // N個の英語の点数データ
     
      //データを受け取る
      for (int i = 0; i < N; i++) {
        cin >> math.at(i);
//        cout << math.at(i) << endl; 
      }
      sort(math.begin(), math.end());
       
      double S=math.at(0); 
      for (int i = 1; i < N; i++) {
        S= (S + math.at(i))/2;
      }
      cout<< S << endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fore(i,a) for(int i=0;i<a;i++)
#define fore1(i,j,a) for(int i=j;i<a;i++)
#define print(ar) for(int i=0;i<ar.size();i++)cout<<ar[i]<<" ";
#define END cout<<'\n'
const double pi=acos(-1.0);
 
typedef pair<int, int> PII;
 
typedef vector<long long> VI;
 
typedef vector<string> VS;
 
typedef vector<PII> VII;
 
typedef vector<VI> VVI;
 
typedef map<int,int> MPII;
 
typedef set<int> SETI;
 
typedef multiset<int> MSETI;
 
typedef long int li;
 
typedef unsigned long int uli;
 
typedef long long int ll;
 
typedef unsigned long long int  ull;
ll fastexp (ll a, ll b, ll n) {
  ll res = 1;
  while (b) {
      if (b & 1) res = res*a%n;
      a = a*a%n;
      b >>= 1;
  }
  return res;
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
 {  fast();
	int t, n, k2;
	t=1;
	while(t--) {
	    cin >> n >>k2;
	    vector<int> arr(n+1);
	     fore(i,n)cin>>arr[i+1];
          int dp[n+1];
           dp[1]=0;
          // cout<<k;
            fore1(i,2,n+1){
                   int k=INT_MAX;
                   for(int j=1;j<=k2;j++){
                       if(i-j<1)break;
                       k=min(k,dp[i-j]+abs(arr[i]-arr[i-j]));
                       //if(i==n)cout<<dp[i-j]+abs(arr[i]-arr[i-j])<<" "<<"j="<<j<<" ";
                   }
                   dp[i]=k;
                   
                        }
                       // END;
                      // for(int i=1;i<=n;i++)cout<<dp[i]<<" ";
                       cout<<dp[n]<<endl;
	}}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>
int main(){
    int i,j;
    scanf("%d",&i);
    scanf("%d",&j);
    if (i<9 && j<9) printf("%s\n","Yay!");
    else printf("%s\n",":(");
    
    return 0;
}

Measured memory_bytes: 1624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;
#include <unordered_set>

int main(void){
    Cin(string, s);
    
    CoutYN(
        s == "KIHBR" ||
        s == "KIHBRA" ||
        s == "KIHBAR" ||
        s == "KIHBARA" ||
        s == "KIHABR" ||
        s == "KIHABRA" ||
        s == "KIHABAR" ||
        s == "KIHABARA" ||
        s == "AKIHBR" ||
        s == "AKIHBRA" ||
        s == "AKIHBAR" ||
        s == "AKIHBARA" ||
        s == "AKIHABR" ||
        s == "AKIHABRA" ||
        s == "AKIHABAR" ||
        s == "AKIHABARA"
    );
}





Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  while (1) {
    int H, W;
    cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    }

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1)) {
          cout << "#";
        } else {
          cout << ".";
        }
      }

      cout << endl;
    }

    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const ll INF = 10000000000;
const ll MOD = 1000000007;
const ll MAX = 55;


int main() {
    int H,W;
    cin >> H >> W;
    vector<vector<char>> graph(H, vector<char> (W));;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> graph.at(i).at(j);
        }
    }
    
    queue<pair<int,int>> que;
    vector<vector<int>> dist(H, vector<int> (W, -1));
    
    que.push(make_pair(0,0));
    dist.at(0).at(0) = 0;
    
    pair<int,int> tmp;
    int tmph;
    int tmpw;
    int tmpdist;
    
    while(dist.at(H-1).at(W-1) == -1 && que.size() > 0){
        tmp = que.front();
        que.pop();
        tmph = tmp.first;
        tmpw = tmp.second;
        tmpdist = dist.at( tmph ).at( tmpw );
        
        if(tmph != 0){
            if(graph.at( tmph-1 ).at( tmpw ) == '.' ){
                if(dist.at( tmph-1 ).at( tmpw ) == -1 ){
                    dist.at( tmph-1 ).at( tmpw ) = tmpdist +1;
                    que.push( make_pair(tmph-1, tmpw) );
                }
            }
        }
        
        if(tmph != H-1){
            if(graph.at( tmph+1 ).at( tmpw ) == '.' ){
                if(dist.at( tmph+1 ).at( tmpw ) == -1 ){
                    dist.at( tmph+1 ).at( tmpw ) = tmpdist +1;
                    que.push( make_pair(tmph+1, tmpw) );
                }
            }
        }
        
        if(tmpw != 0){
            if(graph.at( tmph ).at( tmpw-1 ) == '.' ){
                if(dist.at( tmph ).at( tmpw-1 ) == -1 ){
                    dist.at( tmph ).at( tmpw-1 ) = tmpdist +1;
                    que.push( make_pair(tmph, tmpw-1) );
                }
            }
        }
        
        if(tmpw != W-1){
            if(graph.at( tmph ).at( tmpw+1 ) == '.' ){
                if(dist.at( tmph ).at( tmpw+1 ) == -1 ){
                    dist.at( tmph ).at( tmpw+1 ) = tmpdist +1;
                    que.push( make_pair(tmph, tmpw+1) );
                }
            }
        }
    }
    
    int blackcount = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if( graph.at(i).at(j) == '#' ){
                blackcount++;
            }
        }
    }
    
    int ans;
    if(dist.at(H-1).at(W-1) != -1){
        ans = H*W - blackcount - dist.at(H-1).at(W-1) - 1;
    }
    else{
        ans = -1;
    }
    printf("%d\n", ans);
    
}

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

int main (){
    int V, E, r;
    cin >> V >> E >> r ;
    vector<vector<pair<ll,ll>>> cost (V) ; 
    rep(i, E){
        int s, t, c;
        cin >> s >> t >> c ;
        cost[s].emplace_back(t, c) ;
    }
    vector<ll> d (V, INF) ;
    d[r] = 0 ;
    priority_queue <P, vector<P>, greater<P> > que ;
    que.push(P(0, r)) ; 
    while(!que.empty()){
        P p = que.top() ;
        que.pop() ;
        int v = p.second ;
        if(d[v] < p.first) {
            continue ;
        }
        rep(i, cost[v].size()){
            int k = cost[v][i].first ;
            if(d[k] > d[v] + cost[v][i].second){
                d[k] = d[v] + cost[v][i].second ;
                que.push(P(d[k], k)) ;
            }
        }
    }
        rep(i, V){
        if(d[i] > 1e10){
            cout << "INF" << endl ;
        }
        else {
        cout << d[i] << endl ;
        }
    }
}


Measured memory_bytes: 18272
#include <iostream>
#include <stack>
using namespace std;
int d[101],f[101],G[101][101];
stack<int>s;
int n,t;
void dfs(int u)
{
    s.push(u);
    d[u]=t++;
    int i;
    while(!s.empty()){
        u=s.top();
        for(i=1;i<=n;i++)
        {
            if(G[u][i]==1 && d[i]==0)
            {
                s.push(i);
                d[i]=t++;
                //u=i;
                break;
            }
        }
        if(i>n)
        {
            f[s.top()]=t++;
            s.pop();
        }
    }
}
int main()
{
    int k,u,v;
    cin>>n;
    for(int i=1;i<=n;i++){
        d[i]=0;
        for(int j=1;j<=n;j++)
            G[i][j]=0;
    }
    for(int i=0;i<n;i++)
    {
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            cin>>v;
            G[u][v]=1;
        }
    }
    t=1;
    for(int i=1;i<=n;i++)
    {
        if(d[i]==0)
            dfs(i);
    }
    for(int i=1;i<=n;i++)
    {
        cout<<i<<' '<<d[i]<<' '<<f[i]<<endl;
    }
    return 0;
}


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

int main(void){
  int n, m, fx = 0;
  cin >> n;
  m = n;
  for(int i = 8; i >= 0; i--){
    fx += m/pow(10, i);
    m %= (int)pow(10, i);
  }
  if(n%fx == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static llong MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

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

    llong n, a, b;
    cin >> n >> a >> b;
    llong h_max = -1;
    vector<llong> h(n);
    rep(i, n) {
        cin >> h[i];
        h_max = max(h_max, h[i]);
    }

    llong left = 0, right = (h_max / b) + 1, t;
    while (left + 1 < right) {
        t = (left + right) / 2;
        llong cnt = 0;
        rep(i, n) {
            if (h[i] > b * t) cnt += ceil((ldouble)(h[i] - b * t) / (a - b));
        }
        if (cnt <= t) right = t;
        else left = t;
    }

    cout << right << endl;

    return 0;
}

Measured memory_bytes: 1024
a, b, c, d = map(int, input().split())

if a % d == 0:
    ad_t = a // d
else:
    ad_t = a // d + 1

if c % b == 0:
    cb_t = c // b
else:
    cb_t = c // b + 1


if ad_t >= cb_t:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int s, k;
    cin >> k >> s;

    ll ans = 0;
    rep(i, k + 1){
        rep(j, k + 1){
            int n = s - (i + j);
            if(n >= 0 && n <= k){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3556
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 21:36:10 2020

@author: naoki
"""

S = int(input())
N = int(S/3)
C = 0
c1 = 1 
c2 = 1 

if S >=3:
    for n in range(1,N+1):
        if S%3 == 0:
            if n == 1 or n == N:
                C += 1
            else: 
                for i in range(S-3*n+1,S-2*n):
                    c1 = c1*i
                c2 = c2*(n-1)
                C = C + (c1//c2)%(10**9+7)
                c1 = 1 
        else:
            if n == 1:
                C += 1
            else: 
                for i in range(S-3*n+1,S-2*n):
                    c1 = c1*i
                c2 = c2*(n-1)
                C = C + (c1//c2)%(10**9+7)
                c1 = 1
                
print(int(C%(10**9+7)))





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

int min10(int x){
  return (x + 9) / 10 * 10;
}

int diff(int x){
  return min10(x) - x;
}

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

  int sum = min10(a) + min10(b) + min10(c) + min10(d) + min10(e);
  sum -= max({diff(a), diff(b), diff(c), diff(d), diff(e)});

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long H,W;
    cin>>H>>W;
    long long ans=H*W/2;
    if(H==1||W==1){
        cout<<1<<endl;
    }
    else{
        if(H*W%2==0){
            cout<<ans<<endl;    
        }
        else{
            cout<<ans+1<<endl;
        }
    }
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='+'){ans++;}
    else{ans--;}
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


  int main()
  {
ios::sync_with_stdio(false);
    cin.tie(nullptr);
i64 n,m,c;
cin>>n>>m>>c;
vi64 v[n];
vi64 b(m);
forn(i,m)
cin>>b[i];
forn(i,n)
{
  forn(j,m)
  {
  i64 a;
  cin>>a;
  v[i].pb(a);
}
}
i64 d=0;
forn(i,n)
{
  i64 ans=0;
  forn(j,m)
  {
    ans+=b[j]*v[i][j];
  }
  if(ans+c>0)
  d++;
}
cout<<d;
    return 0;
  }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int target;
int ans,anscnt;
vector <int> ans2;
vector <int> n;
int flg[7][1000001];
void saiki(int ima,int sum){
  int t = 0;
  if(ima == n.size()){
    if(sum <= target && ans < sum) ans = sum,anscnt = 1,flg[ima][sum] = 1,ans2.clear();
  else if(ans == sum) anscnt++;
  }

  if(sum<=target){
    for(int i=ima;i<n.size();i++){
      t*=10;
      t+=n[i];
      saiki(i+1,sum+t);
      if(flg[i+1][sum+t] ==1) flg[ima][sum] = 1,ans2.push_back(t),flg[i+1][sum+t] = 0;
    }
  }

  if(ima == 0) flg[ima][sum] = 0;
}



int main() {

  while(1) {
    int a;
    cin >> target >> a;
    if(target == 0 && a == 0 ) break;
    
    int c = 0;
    n.clear();
    while(a != 0){
      n.push_back(a%10);
      a /= 10;
    }
    reverse(n.begin(),n.end());
    ans = -1;
    anscnt = 0;
    ans2.clear();
    saiki(0,0);
    if(anscnt >=2) cout << "rejected"<<endl;
    else if(ans == -1) cout << "error"<<endl;
    else {
      cout << ans <<" ";
      for(int i=0;i<ans2.size();i++){
	cout << ans2[ans2.size()-1-i];
	if(i != ans2.size()-1) cout <<" ";
      }
	cout << endl;
    }
  }

    return 0;
}

Measured memory_bytes: 15560
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p==-1) printf("root, ");
  else if(T[u].l==-1) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].l!=-1) calcDepth(T[u].l,p+1);
  if(T[u].r!=-1) calcDepth(T[u].r,p);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 3412
li = list(map(int, input().split()))

count = 0

if sum(li)/len(li) == li[0]:
  print(1)
  exit()
else:
  for i in range(len(li)):
    for j in range(i,len(li)):
      if li[i] != li[j]:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <tuple>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
using node_t = tuple<int,int,int>;
using tree_t = vector<node_t>;
using info_t = struct _info_t {
	int p,s,deg,dep,h;
	string type;
	_info_t() {}
	_info_t(int _p,int _s,int _deg,int _dep,int _h,string _type): p(_p),s(_s),deg(_deg),dep(_dep),h(_h),type(_type) {}
};

// implement binary tree by using cursor
int main(void) {
	int n;
	cin >> n;
	// input nodes
	tree_t tree = tree_t(n); // vector of nodes
	for (int i = 0;i != n;++i) {
		int id,left,right;
		cin >> id >> left >> right;
		tree[i] = make_tuple(id,left,right);
	}
	// sort nodes by id
	sort(tree.begin(),tree.end(),[](node_t _n_1,node_t _n_2) { return get<0>(_n_1) < get<0>(_n_2); });
	// init information
	vector<info_t> infos = vector<info_t>(n);
	for (int i = 0;i != n;++i) {
		infos[i] = info_t(-1,-1,0,0,0,"root");
	}
	// get degree, parent, node type, sibling
	for (int i = 0;i != n;++i) {
		// get degree
		if (get<1>(tree[i]) != -1) {
			++infos[i].deg;
		}
		if (get<2>(tree[i]) != -1) {
			++infos[i].deg;
		}
		for (int j = 0;j != n;++j) {
			if (i == get<1>(tree[j]) || i == get<2>(tree[j])) {
				// get parent
				infos[i].p = get<0>(tree[j]);
				// get node type
				infos[i].type = infos[i].deg == 0 ? "leaf" : "internal node";
				// get sibling
				infos[i].s = i == get<1>(tree[j]) ? get<2>(tree[j]) : get<1>(tree[j]);
				break;
			}
		}
	}
	// find root node
	int root = 0;
	while (root != n) {
		if (infos[root].type == "root") {
			break;
		}
		++root;
	}
	// get depth and push nodes in preorder to preorder stack
	stack<int> preorder_stack;
	preorder_stack.push(root); // push root to preorder stack
	stack<int> node_stack;
	if (get<2>(tree[root]) != -1) {
		// push right node of root to stack
		node_stack.push(get<2>(tree[root]));
	}
	if (get<1>(tree[root]) != -1) {
		// push left node of root to stack
		node_stack.push(get<1>(tree[root]));
	}
	while (!node_stack.empty()) {
		int top = node_stack.top();
		node_stack.pop();
		infos[top].dep = 1 + infos[infos[top].p].dep;
		preorder_stack.push(top); // push node to preorder stack
		if (get<2>(tree[top]) != -1) {
			// push right node of top node to stack
			node_stack.push(get<2>(tree[top]));
		}
		if (get<1>(tree[top]) != -1) {
			// push left node of top node to stack
			node_stack.push(get<1>(tree[top]));
		}
	}
	// get height
	while (!preorder_stack.empty()) {
		int top = preorder_stack.top();
		preorder_stack.pop();
		if (infos[top].type == "leaf") {
			continue;
		}
		int left_h = get<1>(tree[top]) == -1 ? -1 : infos[get<1>(tree[top])].h;
		int right_h = get<2>(tree[top]) == -1 ? -1 : infos[get<2>(tree[top])].h;
		infos[top].h = 1 + (left_h > right_h ? left_h : right_h);
	}
	// output result
	for (int i = 0;i != n;++i) {
		cout << "node " << i << ": "
			 << "parent = " << infos[i].p << ", "
			 << "sibling = " << infos[i].s << ", "
			 << "degree = " << infos[i].deg << ", "
			 << "depth = " << infos[i].dep << ", "
			 << "height = " << infos[i].h << ", "
			 << infos[i].type << endl;
	}
}

Measured memory_bytes: 3208
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
using namespace std;
int main()
{
    ll n,ans=0,cnt=1,i;
    cin>>n;
    ll a[n];
    for(i=0; i<n; i++)
        cin>>a[i];
    for(i=0; i<n; i++)
    {
        if(a[i]==cnt)
        {
            cnt++;
        }
        else
        {
            ans++;
        }
    }
    if(ans==n)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;



    return 0;
}





Measured memory_bytes: 5168
#!/usr/bin/env python3
import sys
import math


def solve(A: int, B: int, H: int, M: int):
    # theta = 0.5 * (60 * H + M) - 6 * M
    theta = max(0.5 * (60 * H + M), 6 * M) - min(0.5 * (60 * H + M), 6 * M)
    th = min(theta, 360 - theta)
    csth = math.cos(math.radians(th))
    print(math.sqrt(pow(A,2) + pow(B,2) - 2 * A * B * csth))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(A, B, H, M)

if __name__ == '__main__':
    main()

Measured memory_bytes: 62524
#include <stdio.h>
#define mod 998244353
typedef long long ll;

ll mul(ll a, ll b) {
  return a * b % mod;
}

ll mpow(ll a, ll b) {
  ll ans = 1;
  while(b) {
    if(b & 1) ans = mul(ans, a);
    a = mul(a, a), b >>= 1;
  }
  return ans;
}

int main(void) {
  ll i, j, a, b, c, d, ans = 0;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
  if(a == c) {
    printf("%lld", mpow(a, d - b));
    return 0;
  }
  ll dp[d + 1], t[d + 1];
  for(i = 0; i <= d; ++i) {
    if(i < b) dp[i] = 0;
    else dp[i] = mpow(a, i - b);
  }
  dp[b] = b;
  for(i = a + 1; i < c; ++i) {
    t[0] = 0;
    for(j = 1; j <= d; ++j) t[j] = mul(t[j - 1], i) + mul(dp[j], i), dp[j] %= mod;
    for(j = 1; j <= d; ++j) dp[j] = t[j - 1] + mul(dp[j], j), dp[j] %= mod;
  }
  for(i = 0; i <= d; ++i) ans += mul(dp[i], mpow(c, d - i));
  printf("%lld", ans % mod);
  return 0;
}

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

string  a,b;
void solve(){
    cin >> a >> b;
    int n =(int)a.size() , m = (int)b.size(),ans=n;
    for(int i=0;i+m-1<n;++i) {
        string x = a.substr(i,m);
        int cnt=0,j=0;
        for(char i:x)
            cnt+=(i!=b[j++]);
        ans=min(ans,cnt);
    }
    cout << ans << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--)
        solve();
    return  0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0}; 
int H,W;
char data[55][55];

bool check_around(int y, int x){
  for(int i=0;i<4;i++){
    int nx = x+dx[i];
    int ny = y+dy[i];
    if(nx<0||nx>=W||ny<0||ny>=H) continue;
    if(data[ny][nx]=='#') return true;
  }
  return false;
}
       
  
int main(){
  cin >> H>>W;
  
  int num_sharp=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
    	cin >> data[i][j];
      	if(data[i][j]=='#') num_sharp++;
    }
  }
  
  int cnt=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(data[i][j]=='#'){
        if(check_around(i, j)) cnt++; 
      }
    }
  }
  
  if(cnt==num_sharp) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int N, C;
int arr[31][1000100];
int main(void)
{
    cin >> N >> C;
    for (int i = 0; i < N; ++i)
    {
        int s, t, c;
        cin >> s >> t >> c;
        s *= 10;
        t *= 10;
        arr[c][s - 5]++;
        arr[c][t + 1]--;
    }

    int ans = 0;

    for (int i = 1; i <= C; ++i)
    {
        for (int j = 0; j <= 1e5 * 10 + 1; ++j)
        {
            arr[i][j + 1] += arr[i][j];
        }
    }

    for (int i = 0; i <= 1e5 * 10 + 1; ++i)
    {
        int cnt = 0;
        for (int j = 1; j <= C; ++j)
        {
            if (arr[j][i])
                cnt++;
        }
        if (cnt)
            ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 119424
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	vector<vector<int>> edge(N);
	vector<pair<int, int>> memo(M);
	int a, b;
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		a--, b--;
		edge[a].emplace_back(b);
		edge[b].emplace_back(a);
		memo[i] = { a, b };
	}

	auto dfs = [&](auto &&f, int now, int par, int st, vector<int> visited) -> bool {

		visited[now] = 1;

		bool flag = (now == st);
		for (const auto &e : edge[now]) {
			if (!visited[e] && e != par) flag |= f(f, e, now, st, visited);
		}
		return flag;
	};

	int cnt = 0;
	for (int i = 0; i < M; i++) {
		if (dfs(dfs, memo[i].first, memo[i].second, memo[i].second, vector<int>(N))) cnt++;
	}

	cout << M - cnt << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
typedef long long ll;

int AscendingSort(int [101], int);

int main()
{
	int N, cnt = 1;
	scanf("%d", &N);
	int mochi[N + 1];
	for (int i = 0; i < N; i++) {
		scanf("%d", &mochi[i]);
	}
	AscendingSort(mochi, N);
	for (int j = 0; j < N - 1; j++) {
		if(mochi[j] != mochi[j + 1]) {
			cnt++;
		}
	}
	printf("%d\n", cnt);
	return 0;
}

//昇順ソート
int AscendingSort(int *number, int len) {
	int tmp;
	for (int i = 0; i < len; i++) {
		for (int j = i + 1; j < len; j++) {
			if (number[i] > number[j]) {
				tmp = number[i];
				number[i] = number[j];
				number[j] = tmp;
			}
		}
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
  
template<typename ctype, ctype INF>
class Dijkstra{
public:
  typedef tuple<int,ctype> T;  //for edge
  typedef tuple<ctype,int> T2; //for priority_queue
  int V;
  vector<vector<T> > G;
  
  Dijkstra():V(-1){}
  Dijkstra(int V):V(V),G(V){}
  
  void add_edge(int a,int b,ctype c,int oneway = 0){
    assert(a >= 0 && b >= 0);
    assert(a < V && b < V);
    G[a].push_back(T(b, c));
    if(!oneway) G[b].push_back(T(a, c));
  }

  vector<ctype> dijkstra(int start){
    vector<ctype> D(V, INF);
    vector<int> visited(V,0);
    priority_queue<T2, vector<T2>, greater<T2> > Q;
    Q.push(T2(0, start));
    D[start] = 0;
    while(!Q.empty()){
      ctype cost;
      int pos;
      tie(cost,pos) = Q.top(); Q.pop();
      assert(!visited[pos] || D[pos] <= cost);
      if(visited[pos]++) continue;
      
      for(auto t:G[pos]){
	int to = get<0>(t);
        ctype ncost = cost + get<1>(t);
        if(D[to] <= ncost) continue;
        D[to] = ncost;
        Q.push(T2(ncost, to));
      }
    }
    return D;
  }
  
  vector<vector<int> > getDAG(int start, const vector<ctype> D){
    vector<vector<int> > DAG(V);
    vector<int> visited(V,0);
    queue<int> Q;
    Q.push(start);
    while(!Q.empty()){
      int pos; pos = Q.front(); Q.pop();
      if(visited[pos]++) continue;
      
      for(auto t:G[pos]){
        int to = get<0>(t);
        ctype ncost = D[pos] + get<1>(t);
	if(D[to] != ncost) continue;
	Q.push(to);
	DAG[pos].push_back(to);
      }
    }
    return DAG;
  }
};

int main(){
  int V, E, r;
  cin>>V>>E>>r;
  Dijkstra <long long, 1LL<<55> dijkstra(V);
  for(int i=0;i<E;i++){
    int s, t, d;
    cin>>s>>t>>d;
    dijkstra.add_edge(s, t, d, 1);
  }

  auto ans = dijkstra.dijkstra(r);
  for(int i=0;i<V;i++) {
    if(ans[i] == 1LL<<55) cout<<"INF"<<endl;
    else cout<<ans[i]<<endl;
  }
}



Measured memory_bytes: 19852
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
const int N=201000;
char s[N];
int pos[26][N],cnt[26];
int v[N][26],f[N],t[N];
int n;
inline bool check_min(int a,int &b){return a<b?b=a,1:0;}
void solve()
{
	for(int i=n;i>=0;i--)
	{
		f[i]=n+1;
		for(int x=0;x<26;x++)
			if(v[i][x])
			{
				if(check_min(f[v[i][x]]+1,f[i]))t[i]=x;
			}
			else {f[i]=1,t[i]=x;break;}
	}
//	printf("%d %d\n",f[0],t[0]);

	int p=0;

	for(;;)
	{
		printf("%c",'a'+t[p]);
		p=v[p][t[p]];
		if(p==0)break;
	}
	printf("\n");
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
	{
		int x=s[i]-'a';
		pos[x][++cnt[x]]=i;
	}
	for(int i=1;i<=n;i++)
	{
		for(int x=0;x<26;x++)
		{
			int p=std::upper_bound(pos[x]+1,pos[x]+cnt[x]+1,i)-pos[x];
			if(p>cnt[x])v[i][x]=0;
			else v[i][x]=pos[x][p];
		}
	}
	for(int x=0;x<26;x++)
		v[0][x]=pos[x][1];
	/*
	for(int i=1;i<=n;i++)
	{
		printf("%d :\n",i);
		for(int x=0;x<26;x++)
			if(v[i][x])printf("---%c --> %d\n",'a'+x,v[i][x]);
	}
	*/
	
	solve();
	return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> p(n); rep(i, 0, n) cin >> p[i];

    int ans = 0;
    int min = 2 * 100000 + 1;
    rep(i, 0, n){
        if(p[i] < min) min = p[i];
        if(p[i] <= min) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();
		int M=sc.nextInt();

		int Start=sc.nextInt();
		int Last=sc.nextInt();

		boolean flag=false;

		for(int i=0;i<M-1;i++){
			int s=sc.nextInt();
			int l=sc.nextInt();

			if(Start>l){
				flag=true;
				continue;
			}
			if(Last<s){
				flag=true;
				continue;
			}

			if(s>Start && Last>=s) Start=s;
			if(Last>l && Start<=l) Last=l;

		}

		if(flag) System.out.println("0");
		else System.out.println((Last-Start)+1);

		sc.close();
	}

}


Measured memory_bytes: 64356
#include <utility>
#include <bitset>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <ios>
#include <iomanip>
#include <sstream>
#include <climits>
#include <cmath>

using namespace std;

#ifdef USE_LOG
#define LOG(str)  cout << str << endl
#define DMP(var)  cout << #var << " = " << var << endl
#else
#define LOG(...)
#define DMP(...)
#endif

#define FOR(v, b, e)   for (int v = (b); v < (e); ++v)
#define RFOR(v, b, e)  for (int v = (e) - 1; (b) <= v; --v)
#define REP(v, n)      FOR(v, 0, n)
#define RREP(v, n)     RFOR(v, 0, n)

#define ALL(c)         (c).begin(), (c).end()

typedef long long           ll;
typedef unsigned long long  ull;

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

	int N;
	cin >> N;

	int P = 0;
	int W = 0;
	int G = 0;
	int Y = 0;

	REP (i, N)
	{
		char s;
		cin >> s;
		if (s == 'P') P = 1;
		if (s == 'W') W = 1;
		if (s == 'G') G = 1;
		if (s == 'Y') Y = 1;
	}

	cout << (((P + W + G + Y) == 3) ? "Three" : "Four") << endl;
}

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

#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define wt(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  rd(int, x);
  wt(lcm(x, 360) / x);
}


Measured memory_bytes: 3608
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10 , mod = 1e9 + 7;
long long a[N];
int n , m;
int main(){
	cin >> n;
	a[0] = 0;
	for(int i = 1; i <= n; i ++)
		cin >> a[i] , a[i] += a[i - 1];
	long long res = mod;
	for(int i = 1; i <= n; i ++)
		res = min(res , abs(a[i] - (a[n] - a[i])));
	cout << res << "\n";
}

Measured memory_bytes: 256