akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

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

    int A[M], B[M], C[M];
    rep(i,M){
        cin >> A[i] >> B [i] >> C[i];
        --A[i]; --B[i];
        C[i] = P - C[i]; 
    }

    vector<int> dist(N, INF);
    dist[0] = 0;
    rep(loop,N-1){  // ベルーマンフォード法  dist[v] : 頂点0から頂点vへの最短距離
        rep(i,M){
            if(dist[A[i]] == INF) continue;
            if(dist[B[i]] > dist[A[i]] + C[i]){
                dist[B[i]] = dist[A[i]] + C[i];
            }
        }
    }

    vector<bool> negativeCycle(N, false);
    rep(loop, N){
        rep(i,M){
            if(dist[A[i]] == INF) continue;
            if(dist[B[i]] > dist[A[i]] + C[i]){
                negativeCycle[B[i]] = true;
            }
            if(negativeCycle[A[i]]) negativeCycle[B[i]] = true;
        }
    }
    if(negativeCycle[N-1]) cout << -1 << endl;
    else cout << max((int)0, -dist[N-1]) << endl;
}

Measured memory_bytes: 512
#include<stdio.h>

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

Measured memory_bytes: 572
solve :: Int -> String
solve n =
    let xs = filter (\x -> x `elem` [1..9]) . map (\x -> n `div` x) . filter (\x -> n `mod` x == 0) $ [1..9]
    in if null xs then "No" else "Yes"

main :: IO ()
main = readLn >>= putStrLn . solve

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll mb(ll x){
  ll i=0;
  while(x>0){
    i++;
    x/=2;
  }
  i--;
  return i;
}

const ll M=60;
ll L,R;
string sl,sr;
ll dp[M+10][2][2];

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

  cin>>L>>R;

  rep(i,M){
    ll x=1LL<<i;
    bool fl;
    if(x>L) fl=true;
    else fl=false;
    bool fr=false;
    repl(j,i+1,M){
      if((R>>j)&1)fr=true;
    }
    if((x<L&&i!=mb(L))||x>R)continue;
    dp[M-i][fl][fr]=1;
  }

  {
    ll tmp=L;
    while(tmp>0){
      sl+=(char)(tmp%2+'0');
      tmp/=2;
    }
    while(sl.size()<M)sl+='0';
    reverse(all(sl));
  }
  {
    ll tmp=R;
    while(tmp>0){
      sr+=(char)(tmp%2+'0');
      tmp/=2;
    }
    while(sr.size()<M)sr+='0';
    reverse(all(sr));
  }

  rep(i,M)rep(fl,2)rep(fr,2){
    rep(x,2)repl(y,x,2){
      if(!fl&&(x<(sl[i]-'0')))continue;
      if(!fr&&(y>(sr[i]-'0')))continue;
      (dp[i+1][(fl|(x>(sl[i]-'0')))][(fr|(y<(sr[i]-'0')))]+=dp[i][fl][fr])%=mod;
    }
  }
  ll res=0;
  rep(fl,2)rep(fr,2)(res+=dp[M][fl][fr])%=mod;
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
x,n = gets.chomp.split(" ").map!{|item| item.to_i}
p = gets.chomp.split(" ").map!{|item| item.to_i}
p.sort!
if n == 0
    puts x
    exit
end

y = p.max+1
for i in 0..p.max+1 do
    if y > (x-i).abs
        if p.include?(i)
        else
        y = (x-i).abs
        a = i
        end
    end
end
puts a

    


Measured memory_bytes: 14256
(println (let [s1 (read-line)
               t  (read-line)]
           (loop [s s1 times (count t)]
             (let [rotated (apply str (last s) (butlast s))]
               (if (zero? times)
                 "No"
                 (if (= rotated t)
                   "Yes"
                   (recur rotated (dec times))))))))

Measured memory_bytes: 66732
//#include <bits/stdc++.h>                          //include all library
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <string.h>
#include <functional> // greater<int> はfunctionalヘッダ
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)          //REP(i, 10){...} //i=0～i=9までのループ
#define REPR(i, n) for(int i = n;i >= 0;i--)        //REPR(i, 10){...} //i=10～i=0までのループ
#define FOR(i, m, n) for(int i = m;i < n;i++)       //FOR(i, 3, 10){...} //i=3～i=9までのループ
#define FORR(i, m, n) for(int i = m;i >= n;i--)     //FORR(i, 10, 3){...} //i=10～i=3までのループ
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define PI 3.141592653589
#define npos -1


int main()
{
	int A, B, K;

	cin >> A >> B >> K;

	for(int i = 1000; i >= 1; i--)
	{
		if(A%i == 0 and B%i == 0)
		{
			K--;
			if(K == 0)
			{
				cout << i << endl;
			}
		}
	}
}

Measured memory_bytes: 256
import numpy as np
import sys
# https://atcoder.jp/contests/agc033/submissions/6021787
buf = sys.stdin.buffer
H,W = map(int,buf.readline().split())
# +1周分だけ
black = np.zeros((H+2,W+2),dtype=np.bool)
# \nがあることに注意
black[1:-1,1:] = (np.frombuffer(buf.read(H*(W+1)),dtype='S1') == b'#').reshape(H,W+1)

INF = 10 ** 4
dist = np.zeros((H,W),dtype=np.int16)
# .のところは０それ以外はINFで初期化
dist[~black[1:-1,1:-1]] = INF
# 右、左、下、上と展開させていく感じ
for n in range(1,H):
    np.minimum(dist[n-1]+1,dist[n],out=dist[n])
for n in range(H-2,-1,-1):
    np.minimum(dist[n+1]+1,dist[n],out=dist[n])
for n in range(1,W):
    np.minimum(dist[:,n-1]+1,dist[:,n],out=dist[:,n])
for n in range(W-2,-1,-1):
    np.minimum(dist[:,n+1]+1,dist[:,n],out=dist[:,n])

print(dist.max())


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

int main(){
    int x,a,b,n; cin>>x>>a>>b>>n;

    vector<string> s(n);

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

    int sum = x;

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

        if(s[i] == "nobiro") sum += a;

        else if(s[i] == "tidime") sum += b;

        else sum = 0;

        sum = max(sum,0);
    } 

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll, ll> pll;


ll n;
ll a[100005];
ll b[100005];
int main()
{
        cin >> n;
        for(ll i=0;i<=n;i++) {
                cin >> a[i];
        }
        ll ans = 0;
        for(ll i=1;i<=n;i++) {

                cin >> b[i];
                ll mm = min(b[i], a[i-1]);
                b[i] -= mm;
                a[i-1] -= mm;
                ans += mm;
                ll m2 = min(b[i], a[i]);
                b[i] -= m2;
                a[i] -= m2;
                ans += m2;
        }
        cout << ans << endl;
        return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main(){
	int x;
	cin >> x;
	int temp = x/500;
	x -= temp*500;
  	int ans = temp*1000;
  	temp = x/5;
	ans += temp*5;
  	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 256
let a, b, c = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let f a b c = abs (b - a) + abs (c - b)
let _ = List.fold_left min max_int [f a b c; f a c b; f b a c; f b c a; f c a b; f c b a] |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;


int main(void) {
    int n, i, t, c, dp[200003] = {}, sd[200003] = {};
    const int mod = 1e9 + 7;
    vector<int> cv;

    cv.push_back(0);
    t = 1;

    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> c;
        if (c != cv[t - 1]) {
            cv.push_back(c);
            t++;
        }
    }

    dp[0] = 1;
    sd[0] = 1;
    for (i = 0; i < t; i++) {
        dp[i] = sd[cv[i]];
        sd[cv[i + 1]] = (sd[cv[i + 1]] + dp[i]) % mod;
    }

    cout << dp[t - 1] << endl;

    return 0;
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll n, m; cin >> n >> m;
  cout << (n-1) * (m-1) << endl;

  return 0;
}



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

//Knapsack1はWが小さく、vが大きい
//　→ wに注目してDP

vector<vector<ll>> dp(200, vector<ll>(110000, 0));

int main(){
  ll N, W;
  cin >> N >> W;
  vector<ll> w(N), v(N);
  for(int i = 0; i < N; i++){
    cin >> w.at(i) >> v.at(i);
  }


  for(int i = 0; i <= W; i++){
    for(int j = 1; j <= N; j++){
      chmax(dp.at(j).at(i), dp.at(j-1).at(i));
      if(i - w.at(j-1) >= 0) chmax(dp.at(j).at(i), dp.at(j-1).at(i - w.at(j-1)) + v.at(j-1));
    }
  }

  cout << dp.at(N).at(W) << endl;


}

Measured memory_bytes: 173056
import java.util.*;
public class Main{
    Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
	new Main().run();
    }

    void run(){
	while(sc.hasNext()){
	    String sen = sc.nextLine();
	    sen = sen.replaceAll("apple", "!!!");
	    sen = sen.replaceAll("peach", "apple");
	    sen = sen.replaceAll("!!!", "peach");
	    System.out.println(sen);
	}
    }
}

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

const int INF = 1e9 + 5;

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

    if(b >= a){
        printf("unsafe");
    }else{
        printf("safe");
    }

    return 0;
}

Measured memory_bytes: 3872
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
int a[20],b[20],ten[9];
int d;
int i,j,k,l,t,n,m,tot,top;
ll num,sum,wdc,pp,ans;
bool czy;
int main(){
    ten[0]=1;
    fo(i,1,8) ten[i]=ten[i-1]*10;
    scanf("%d",&d);
    pp=1;
    if (d%10==0){
        czy=1;
        while (d%10==0){
            d/=10;
            pp*=10;
        }
        pp=pp/10*9;
    }
    fo(l,1,7)
    fo(i,0,ten[l]-1){
        t=0;
        k=i;
        top=0;
        fo(j,1,l){
            a[++top]=k%10;
            k/=10;
        }
        k=i+d;
        tot=0;
        fo(j,1,top){
            b[++tot]=k%10;
            k/=10;
        }
        if (!czy&&b[1]==0) continue;
        reverse(b+1,b+tot+1);
        fo(j,1,tot) a[++top]=b[j];
        num=0;
        wdc=1;
        fo(j,1,top){
            num+=(ll)a[j]*wdc;
            wdc*=10;
        }
        sum=0;
        wdc=1;
        reverse(a+1,a+top+1);
        fo(j,1,top){
            sum+=(ll)a[j]*wdc;
            wdc*=10;
        }
        if (num+(ll)d==sum){
            ans++;
        }
        //continue;
        reverse(a+1,a+top+1);
        top-=tot;
        a[++top]=0;
        fo(j,1,tot) a[++top]=b[j];
        num=0;
        wdc=1;
        fo(j,1,top){
            num+=(ll)a[j]*wdc;
            wdc*=10;
        }
        sum=0;
        wdc=1;
        reverse(a+1,a+top+1);
        fo(j,1,top){
            sum+=(ll)a[j]*wdc;
            wdc*=10;
        }
        if (num+(ll)d==sum){
            ans+=10;
        }
    }
    ans*=pp;
    printf("%lld\n",ans);
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> numList = new ArrayList<>();
		String ans = "Yes";
		
		for(int i = 1; i <= n; i++) {
			numList.add(sc.nextInt());
		}
		
		int max = numList.get(0) - 1;
		for(int i = 1; i < numList.size(); i++) {
			if(max < numList.get(i)){
				max = numList.get(i) - 1;
			}else if(max == numList.get(i)){
				max = numList.get(i);
			}else {
				ans = "No";
				break;
			}
		}
		
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 58560
#include"bits/stdc++.h"
using namespace std;

int lcs(string x, string y)
{
	int m = x.size();
	int n = y.size();
	x = ' ' + x;		//x[0]に空白を挿入
	y = ' ' + y;		//y[0]に空白を挿入
	vector<vector<int>> c(m + 1, vector<int>(n + 1, 0));

	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (x[i] == y[j]) c[i][j] = c[i-1][j-1] + 1;
			else c[i][j] = max(c[i - 1][j], c[i][j - 1]);
		}
	}
	return c[m][n];
}

int main(void)
{
	int N;
	string x, y;
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> x >> y;
		cout << lcs(x, y) << endl;
	}

	return 0;
}


Measured memory_bytes: 6792
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		// Input Example:
		//
		// N M
		// K1 A11 A12 ... A1k1
		// K2 A21 A22 ... A2k2
		// .
		// .
		// .
		// KN AN1 AN2 ... ANkN

		Scanner sc = new Scanner(System.in);
		// N people
		int N = sc.nextInt();
		
		// get two integers separated with half-width break
		// M kinds of foods
		int M = sc.nextInt(); 

		// Ki: the number of foods that No.i+1 person like
		int K;

		// map[M]: the table of the likeness of each foods 
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();

		for (int i=0; i<N; i++)
		{
			K = sc.nextInt();
			for (int j=0; j<K; j++)
			{
				int K_temp = sc.nextInt();
				if (map.containsKey(K_temp))
				{
					int val = map.get(K_temp); // food no. K_temp +1
					val++;
					map.put(K_temp, val);
				}
				else
				{
					map.put(K_temp, 1);
				}
			}
		}
		sc.close();

		int ans = 0;
		// for (int i=1;i<map.size();i++)
		// {
		// 	if (map.get(i) == N) //it means everyone (N people) likes it
		// 	{
		// 		ans++;
		// 	}
		// }
		for (int val : map.values())
		{
			if (val == N)
			{
				ans++;
			}
		}
		System.out.println(ans);
		
	}

}

Measured memory_bytes: 22612
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n = int(input())
    a = list(map(int, input().split()))
    rate = [0]*8
    cnt = 0
    for x in a:
        r = x//400
        if r > 7:
            cnt += 1
        elif not rate[r]:
            rate[r] = 1
    s = sum(rate)
    mins = max(s,1)
    maxs = s+cnt
    print(mins, maxs)        
        
            



if __name__ == '__main__':
    main()

Measured memory_bytes: 9140
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

/*
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()
*/

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-9;

void solve() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = INFL;
    chmin(ans, abs(b - a) + abs(c - a));
    chmin(ans, abs(a - b) + abs(c - b));
    chmin(ans, abs(a - c) + abs(b - c));
    cout << ans << endl;
    return;
}

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


Measured memory_bytes: 256
from collections import deque
import sys
n = int(input())
deq = deque()
sub_deq = {}
for cmd in sys.stdin.readlines():
    if cmd == 'deleteFirst\n':
        while deq:
            data = deq.pop()
            if data[1]:
                data[1] = 0
                break
    elif cmd == 'deleteLast\n':
        while deq:
            data = deq.popleft()
            if data[1]:
                data[1] = 0
                break
    else:
        cmd, val = cmd.split()
        if cmd == 'insert':
            data = [val, 1]
            deq.append(data)
            if val not in sub_deq:
                sub_deq[val] = [data]
            else:
                sub_deq[val].append(data)
        elif cmd == 'delete':
            if val in sub_deq:
                deq_v = sub_deq[val]
                while deq_v:
                    data = deq_v.pop()
                    if data[1]:
                        data[1] = 0
                        break
sys.stdout.write(" ".join(data[0] for data in reversed(deq) if data[1]))
sys.stdout.write('\n')


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

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        //int n = stdIn.nextInt();
        //int k = stdIn.nextInt();
        //int b = stdIn.nextInt();
        //int num[] = new int[3];
        String s = stdIn.next();
        char c[] = s.toCharArray();
        //boolean flag = true;
        int sum = 0;
        
        for(int i = 0; i < s.length(); i++){
            if(c[i] == '+'){
                sum++;
            }else{
                sum--;
            }
        }
        
        System.out.println(sum);
        
        
        //System.out.println();
        //System.out.print();
    }
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int N,M;
long long   from[5100], to[5100];
long long   cost[5100];
long long   dist[2600];
long long   const INF = 1e18;

//bellmanford
bool bellmanford(){
  fill(dist,dist+2600,-INF);
  dist[0] = 0;
  for(int k = 0; k < 2*N ; k++){  //node nums
    for(int i = 0; i < M; i++){   // edge nums
      if(dist[to[i]] < min(dist[from[i]] + cost[i] , INF)){
        dist[to[i]] = min(INF,dist[from[i]] + cost[i]);
        if(k >= N && to[i] == N-1) return  true;
      }
    }
  }
  return false;
}
//main()-----------------------------
int main(){
  ll P;
  cin >> N >> M >> P;
  for(int i = 0; i < M; i++){
    cin >> from[i] >> to[i] >> cost[i];
    from[i] --; to[i] --;
    cost[i] = cost[i] - P;
  }

  bool infFlag = bellmanford();

  if(infFlag) cout << "-1" << endl;
  else        cout << max(0LL,dist[N-1]) << endl;
  return 0;
}


Measured memory_bytes: 384
N=int(input())

int_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
 
for A in int_list:
    if N % A == 0:
        B = N // A
        if B > 0 and B <= 9:
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int max,min,dif,t,count,word_size,end;
  int c_a,point,i,j;
  string p = "0";
 
  while(1){
    string v;
    vector<int> vec;
    i = 0;
    end = 0;
    word_size = 0;
 
    cin>>v>>count;
 
    if(v == "0" && count == 0){
      break;
      }
 
    for(char e : v){
      word_size++;
    }
 
    c_a = count - word_size;
 
    for(int q = 0;q < c_a;++q){
      v = p+v;
    }
 
    point = atoi(v.c_str());
 
    vec.push_back(point);
 
    while(1){
      i++;
      sort(v.begin(),v.end());
      min = atoi(v.c_str());
 
      reverse(v.begin(),v.end());
      max = atoi(v.c_str());
 
      dif = max - min;
 
      j = 0;
 
      for(int e : vec){
        if(dif == e){
          end = 1;
          break;
        }
        j++;
      }
 
      if(end == 1){
        cout<<j<<" "<<dif<<" "<<i-j<<endl;
        break;
      }
      vec.push_back(dif);
      v = to_string(dif);
      word_size = 0;
 
      for(char e : v){
        word_size++;
      }
      c_a = count - word_size;
 
      for(int q = 0;q < c_a;++q){
        v = p+v;
      }
    }
  }
 
  return 0;
}
		




Measured memory_bytes: 3272
N,X,Y=map(int,input().split())
ans=[]
count=[0]*(N-1)
for i in range(1,N):
    for j in range(i+1,N+1):
        a=j-i
        a=min(a,abs(j-Y)+abs(i-X)+1)
        count[a-1]+=1
for i in range(0,N-1):
    print(count[i])

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  int ans = 1e15;
  for ( int i = 1; i*i <= N; i++ ) {
    if ( N%i ) continue;
    ans = min(ans, max((int)log10(i)+1, (int)log10(N/i)+1));    
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a==b+c||b==c+a||c==a+b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
#include <ctype.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;

typedef long long ll;
typedef pair<ll, int> pp;
#define mp(a, b) make_pair(a, b)

struct edge {
	int v, w;
	int next;
	edge() {}
	edge(int v_, int w_, int n_) : v(v_), w(w_), next(n_) {}
};

int n, cnt;
int head[10001];
edge e[600000];
bool vis[10001];
ll dis[10001];

void init()
{
	cnt = 0;
	memset(head, -1, sizeof head);
}
void addedge(int u, int v, int w)
{
	e[++cnt] = edge(v, w, head[u]); head[u] = cnt;
}
void dijkstra(int s)
{
	for (int i = 0; i < n; i++)
		vis[i] = 0, dis[i] = ll(1e18);
	dis[s] = 0; vis[s] = 1;
	for (int i = head[s]; i != -1; i = e[i].next)
		dis[e[i].v] = e[i].w;
	while(1)
	{
		int idx = -1;
		ll dist = 1e18;
		for (int j = 0; j < n; j++)
			if (!vis[j] && dist > dis[j])
			{
				idx = j;
				dist = dis[j];
			}
		if (idx == -1)
			break;
		vis[idx] = 1;
		for (int j = head[idx]; j != -1; j = e[j].next)
		{
			int v = e[j].v;
			ll w = e[j].w;
			if (!vis[v] && dis[v] > dis[idx] + w)
				dis[v] = dis[idx] + w;
		}
	}
}

int id[10001];

int main()
{
	int s;
	while (scanf("%d", &n) == 1)
	{
		init();
		for (int i = 0; i < n; i++)
		{
			int u, k;
			scanf("%d%d", &u, &k);
			id[i] = u;
			if (u == 0)
				s = i;
			while (k--)
			{
				int v, w;
				scanf("%d%d", &v, &w);
				addedge(u, v, w);
			}
		}
		dijkstra(s);
		for (int i = 0; i < n; i++)
			printf("%d %lld\n", id[i], dis[i]);
	}
	return 0;
}


Measured memory_bytes: 9140
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n= int(input())
d = [0] * n
for i in range(n):
    d[i] = tuple(map(int, input().split()))

for i in range(n - 2):
    if d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]:
        print('Yes')
        sys.exit(0)
print('No')


Measured memory_bytes: 62052
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  string s; cin >> s;
  reverse(ALL(s));
  int n = s.length();
  vector<vector<ll> > dp(n + 1, vector<ll>(2, LINF));
  dp[0][false] = 0;
  REP(i, n) {
    int val = s[i] - '0';
    REP(j, 10) REP(k, 10) {
      if (j - k == val) chmin(dp[i + 1][false], dp[i][false] + j + k);
      if (j + 10 - k == val) chmin(dp[i + 1][true], dp[i][false] + j + k);
      if (j - 1 - k == val) chmin(dp[i + 1][false], dp[i][true] + j + k);
      if (j - 1 + 10 - k == val) chmin(dp[i + 1][true], dp[i][true] + j + k);
    }
  }
  cout << min(dp[n][false], dp[n][true] + 1) << '\n';
  return 0;
}


Measured memory_bytes: 58012
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v) reverse(v.begin(),v.end())
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define P pair<int,int>
#define Pll pair<ll,ll>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};
int gcd(int n,int m){
	if(m>n) return gcd(m,n);
	if(m==0) return n;
	else return gcd(m,n%m); 
}

int main(void){
	ll N,T,oldt,t,sum=0;
	
	cin>>N>>T;
	cin>>oldt;
	REP(i,N-1){
		cin>>t;
		sum+=min(T,t-oldt);
		oldt=t;
	}
	print(sum+T);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define int long long
#define elif else if
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string

signed main(){
  int N,M,O,P=0,c=0,co=0,cou=0;
  double D,Do;
  char C,Ca;
  str S,T;
  cin>>N;
  vint a(N);rep(0,N)cin>>a[i];
  c=a[0];
  rep(0,N){
    if(a[i]<=c){
      c=a[i];
      co++;
    }
  }
  cout<<co<<endl;
}


Measured memory_bytes: 1792
flag = True
min_a = 0
max_a = 0
while flag:
    a = list(map(int,input().split()))
    if a[0] == 0 and a[1] == 0:
        break
    if a[0] < a[1]:
        min_a = a[0]
        max_a = a[1]
    else:
        min_a = a[1]
        max_a = a[0]
    print("{} {}".format(min_a,max_a))


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


int main(){
    int N;
    scanf("%d",&N);
    int x[N],y[N];
    for (int i=0; i<N; i++) {
        scanf("%d %d",&x[i],&y[i]);
    }
    
    double sum=0,k;
    for (int i=0; i<N-1; i++) {
        for (int j=i+1; j<N; j++) {
            if(i!=j){
                k=pow(x[i]-x[j],2)+pow(y[i]-y[j],2);
                sum+=pow(k,0.5);
            }
        }
    }
    printf("%lf\n",sum*((double)2/N));
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
using namespace std;
typedef long long ll;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
int main(){
	int n;
	cin>>n;
	int max=0;
	int min=1000000010;
	rep(i,0,n){
		int a;
		cin>>a;
		if(a>max)max=a;
		if(a<min)min=a;
	}
	cout<<abs(max-min)<<endl;
}

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

using namespace std;

int dp[100000][3];

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

	for (auto i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];

	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for (auto i = 1; i < n; i++)
	{
		dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
	}

	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
}

Measured memory_bytes: 2688
dic = {}

N = int(input())

S = input()

for i in range(N):

    if S[i] not in dic:
        dic[S[i]] = 1

    else:
        dic[S[i]] += 1
        
ans = 1

for i in dic:

    ans *= dic[i] + 1

print ((ans-1) % (10**9 + 7) )

Measured memory_bytes: 41328
#include <stdio.h>
#include <stdlib.h>
int n, l, j, u, k, tmp;
int list[100][100];
int lengthlist[100];
 
void search(int y, int length){
  int i;
  length++;
  lengthlist[y] = length;
 
 
  for( i = 0 ; i < n ; i++){
    if( list[y][i] == 1 ){
      if( lengthlist[i] <= length && lengthlist[i] >= 0 ){
        continue;
      }
      search(i, length);
    }
  }
}
 
int main(){
  scanf("%d", &n);
  for(l = 0 ; l < n ; l++){
    scanf("%d", &u);
    scanf("%d", &k);
    for( j = 0 ; j < k ; j++){
      scanf("%d", &tmp);
      list[u-1][tmp-1] = 1;
    }
  }
  for( l = 0 ; l < n ; l++){
    lengthlist[l] = -1;
  }
  search(0, -1);
 
  for(j = 0 ; j < n ; j++){
    printf("%d %d\n", j+1, lengthlist[j]);
  }
 
  return 0;
}


Measured memory_bytes: 2120
#include <iostream>
using namespace std;
int n,m,ans=0;
int d[8][8];
bool used[8];
int dfs(int i,int c){
    if(c==n-1){
        ans++;
        return 0;
    }
    for(int j=0;j<n;j++){
        if(d[i][j]&&!used[j]){
            used[j]=true;
            dfs(j,c+1);
            used[j]=false;
        }
    }
    return 0;
}
int main(void){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int s,t;
        cin>>s>>t;
        s--;
        t--;
        d[s][t]=1;
        d[t][s]=1;
    }
    for(int i=0;i<n;i++)used[i]=false;
    used[0]=true;
    dfs(0,0);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    int i=k*x;
    int j=n-k;
    j*=y;
    if(n>=k){cout<<i+j;}
    else{cout<<n*x;}
    return 0;}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    int v[n];
    REP(i,n){
        cin>>v[i];
    }
    sort(v,v+n);
    int ans=0;
    REP(i,n){
        int r=i;
        while(r+1<n&&v[r+1]==v[i]){
            r++;
        }
        int c=r-i+1;
        if(c>=v[i]){
            ans+=c-v[i];
        }else{
            ans+=c;
        }
        i=r;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

/* 二項係数 C(n,k) mod p を計算 */
const int MAX = 3000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

  vector<double> p(N+1);

  REP(i, N){
    cin >> p[i+1];
  }


  vector<vector<double>> dp(N+1, vector<double>(N+1, 0.0));
  dp[1][0] = 1 - p[1];
  dp[1][1] = p[1];

  FOR(i, 2, N+1){
    FOR(j, 0, i+1){
      if(j == 0) dp[i][0] = dp[i-1][0] * (1-p[i]);
      else{
        dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1-p[i]);
      }
    }
  }

  double ans = 0.0;

  FOR(j, N/2 + 1, N+1){
    ans += dp[N][j];
  }

  cout << fixed << setprecision(12);
  cout << ans << endl;

}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  sort(a,a+n);
  ll ans=0;
  rep(i,n) {
    ll x=min(m,a[i].S);
    m-=x;
    ans+=a[i].F*x;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;

bool whitch(char c) {
  if (c == 'y' || c == 'u' || c == 'i' ||
      c == 'o' || c == 'p' || c == 'h' ||
      c == 'j' || c == 'k' || c == 'l' ||
      c == 'n' || c == 'm')
    return true;
  else
    return false;
}

int main(int argc, char *argv[]) {
  string s;
  while (true) {
    cin >> s;
    if (s == "#")
      break;

    int count = 0;
    bool hand = whitch(s[0]);

    for (int i = 1; i < s.size(); i++) {
      if (hand != whitch(s[i])) {
        count++;
        hand = !hand;
      }
    }

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

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

int main(){
    int N, ans = 0;
    string S;
    cin >> N >> S;
    for(int i = 1; i < N; ++i){
        unordered_map<char,int> X, Y;
        for(int j = 0; j < N; ++j){
            if(j < i) ++X[S[j]];
            else ++Y[S[j]];
        }
        int buf = 0;
        for(auto x: X){
            if(Y[x.first] != 0) ++buf; 
        }
        ans = max(ans, buf);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
import javax.management.Query;
import javax.print.attribute.SupportedValuesAttribute;
import java.io.*;
import java.security.interfaces.DSAKeyPairGenerator;
import java.sql.Array;
import java.util.*;
import java.util.function.Predicate;


public class Main {

    static class TaskB {

        static int oo = Integer.MAX_VALUE - 1;

        static int MOD = 1000000007;


        public void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = in.nextIntArray(n);

            int[] dp = new int[n];
            dp[0] = 0;
            dp[1] = Math.abs(arr[1]-arr[0]);

            for(int i = 2; i < n; i++)
            {
                dp[i] = Math.min(dp[i-1]+Math.abs(arr[i]-arr[i-1]), dp[i-2]+Math.abs(arr[i]-arr[i-2]));
            }
            out.print(dp[n-1]);
        }
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }



    static void sort(int[] a)
    {
        ArrayList<Integer> list = new ArrayList<>();
        for(Integer i: a)list.add(i);
        Collections.sort(list);
        for(int i = 0; i < a.length; i++)a[i]=list.get(i);
    }


    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer = new StringTokenizer("");

        public InputReader(InputStream inputStream) {
            this.reader = new BufferedReader(
                    new InputStreamReader(inputStream));
        }

        public String next() {
            while (!tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }
    }
}

Measured memory_bytes: 43200
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define llu long long unsigned
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define ull unsigned long long int
#define pii pair<ll,ll>
#define vll vector<ll>
#define vp vector<pii>
#define mp make_pair
#define lb "\n"
#define ins insert
#define fon(i,n) for(int i = 0;i<n;i++)
#define foa(i,a) for(auto i = a.begin();i!=a.end();i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define INF 100000007
#define sz size
#define len length
ll max(ll x,ll y){if(x>y)return x;else return y;}
ll min(ll x,ll y){if(x>y)return y;else return x;}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
ll i,j,k,m,n,q,p;
cin>>k>>n;
vll a(n);
rep(i,0,n)
cin>>a[i];
sort(all(a));
m=0;
rep(i,0,n-1)
m=max(m,a[i+1]-a[i]);
m=max(m,k-a[n-1]+a[0]);
cout<<(k-m);
return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#define N 10005
#define LL long long
#define inf 1<<29
#define eps 1e-7
using namespace std;
vector<int>v[100005];
int get_sg(int u,int pre){
    int ret=0;
    for(int i=0;i<v[u].size();i++){
        if(v[u][i]!=pre)
            ret^=(1+get_sg(v[u][i],u));
    }
    return ret;
}
int main(){
    int t,n;
    //scanf("%d",&t);
   // while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            v[i].clear();
        for(int i=1;i<n;i++){
            int x,y;
            scanf("%d%d",&x,&y);
            v[x].push_back(y);
            v[y].push_back(x);
        }
        if(get_sg(1,-1))
            puts("Alice");
        else
            puts("Bob");
    //}
    return 0;
}


Measured memory_bytes: 11904
//#include <string>
//#include <set>
//#include <map>
//#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int inf = 0x7fffffff;
typedef long long ll;
void Faster( ){ ios_base::sync_with_stdio( false ); cin.tie( nullptr ); }
void iv( vector<int>& p ){ for( int& x: p ) cin >> x; }
void sa( vector<int>& p ){ sort( p.begin(), p.end() ); }
void pv( const vector<int>& p ){ for( int x: p ) cout << x << ' '; cout << '\n'; }

int main( ){
	Faster( );
	int h, n;
	cin >> h >> n;
	int kill = 0;
	while( n-- ){
		int c;
		cin >> c;
		kill += c;
	}
	cout <<(  (h > kill) ? "No" : "Yes"   );
	return 0;
}

// 08-06-2020
// Master Template 14
// kafiulshabbir@phystech.edu



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

int main() {
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << fixed << setprecision(10) <<  pow(pow(x1 - x2, 2) + pow(y1 - y2, 2), 0.5) << endl;
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int K;
    cin >> K;
    set<ll> st;
    int ans = 1;
    ll power = 1;
    ll cur = 0;
    while (1) {
        cur += power * 7 % K;
        cur %= K;
        if (cur % K == 0) {
            cout << ans << '\n';
            return 0;
        }
        if (st.find(cur) != st.end()) break;
        st.insert(cur);
        power *= 10; power %= K;
        ans++;
    }
    cout << -1 << '\n';
    return 0;
}


Measured memory_bytes: 50452
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	int X;
	cin >> X;

	int A;
	cin >> A;

	int B;
	cin >> B;

	int left_money = X - A;
	cout << left_money % B;

	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#define sz(x) ((int)(x).size())
#define mp make_pair
#define full(a) a.begin(), a.end()
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e5;

void solve()
{
    int n; cin >> n;
    vector<pair<int, int>> vp(n);
    for (auto& i : vp)
    {
        cin >> i.first >> i.second;
    }
    int c = 0;
    for (int i = 0; i < n; i++)
    {
        if (vp[i].first == vp[i].second)
        {
            c++;
            if (c == 3)
            {
                cout << "Yes\n";
                return;
            }
        }
        else c = 0;
    }
    cout << "No\n";
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); //cout.tie(NULL);
    /*int tc; cin >> tc;
    while (tc--)*/
        solve();

    return 0;
}


Measured memory_bytes: 3652
T = 1000
N = 4000
memo = [[0] * (N +1)  for _ in range(3)] 
#Java: int[][] memo = new int[3][2*T+1];
memo[0][0] = 1
for i in range(1,3):
    for j in range(i*T+1):
        memo[i][j] = sum([memo[i-1][k] for k in range(max(0,j-T),j+1)])

while True:
    try:
        n = input() 
    except EOFError:
        break
    cnt = 0
    for i in range(n+1):
        cnt += memo[2][i] * memo[2][n-i]
    print cnt

#O(T^2), 0.954

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, T;
int t[220000];
signed main() {
    cin >> N >> T;
    rep(i, N) { cin >> t[i]; }
    int ans = T * N;
    for (int i = 1; i < N; i++) {
        ans -= max(0LL, T - (t[i] - t[i - 1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792