akhauriyash/Code-Regression huggingface dataset:
require 'set'

module Graph
	def add_node(data = nil)
		Node.new(data)
	end

	def add_edge(u, v, label = nil)
		e = Edge.new(u, v, label)
		u.outgoings << e
		v.incomings << e
		e
	end
	
	def del_edge(e)
		u, v = e.from, e.to
		u.outgoings.delete(e)
		v.incomings.delete(e)
		e
	end

	class Node
		def initialize(data)
			@data = data
			@outgoings = Set.new
			@incomings = Set.new
		end

		def to_nodes
			@outgoings.map(&:to)
		end

		def from_nodes
			@incomings.map(&:from)
		end
		
		def to_s
			@label
		end

		attr_accessor :incomings, :outgoings
		attr_reader :data
	end

	class Edge
		def initialize(u, v, label = nil)
			@from = u	
			@to = v
			@label = label
		end
		attr_reader :from, :to, :label
	end

	def get_path(s, t, reached = Set.new)
		return [s] if s == t
		reached << s	
		s.outgoings.each{|e|
			v = e.to
			next if reached.include?(v)
			path = get_path(v, t, reached) 
			return [e] + path if path
		}
		nil
	end
end

extend Graph

loop {
	w, h = gets.split.map(&:to_i)
	break if w == 0
	a = (1..h).map{ gets.split.map(&:to_i) }
	nodes = (0..h-1).map{|i| (0..w-1).map{|j| add_node} }

	(0..h-1).each{|i|
		(0..w-1).each{|j|
			next if a[i][j] == 1
			u = nodes[i][j]
			if j < w-1 && a[i][j+1] != 1
				v = nodes[i][j+1]
				add_edge(u, v, :right)
				add_edge(v, u, :left)
			end
			if i < h-1 && a[i+1][j] != 1
				v = nodes[i+1][j]
				add_edge(u, v, :down)
				add_edge(v, u, :up)
			end
		}
	}

	goal_node = cargo_node = pusher_node = nil
	(0..h-1).each{|i|
		(0..w-1).each{|j|
			goal_node = nodes[i][j] if a[i][j] == 3
			cargo_node = nodes[i][j] if a[i][j] == 2
			pusher_node = nodes[i][j] if a[i][j] == 4
		}
	}
	
	movable_dir = -> pushee, pusher {
		dirs = []
		pushee.outgoings.each{|to_edge|
			dir = to_edge.label
			in_edge = pushee.incomings.find{|e| e.label == dir}
			next unless in_edge
			tmp = pushee.outgoings
			pushee.outgoings = []
			dirs << dir if get_path(pusher, in_edge.from)
			pushee.outgoings = tmp
		}
		dirs.sort
	}

	state = [cargo_node, movable_dir[cargo_node, pusher_node]]
	queue = [state]
	push = 0
	reached = Set[state]

	success = false
	loop {
		next_queue = []
		until queue.empty?
			u, dirs = queue.pop
			if u == goal_node
				success = true
				break
			end
			dirs.each{|dir|
				e = u.outgoings.find{|e| e.label == dir}
				v = e.to
				state = [v, movable_dir[v, u]]
				next if reached.include?(state)
				reached << state
				next_queue << state
			}
		end

		break if success
		if next_queue.empty?
			push = -1
			break
		end

		queue = next_queue
		push += 1
	}
	p push
}

Measured memory_bytes: 6716
#include <iostream>
#include "string.h"

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	long long int power = 1;
	long long int h = 1e9;
	for(int i = 1;i < N + 1;i++){
		power *= i ;
		if(power >= h + 7){
			power = power % (h+7);
		}
	}
	cout << power << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC157b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int[,] a = new int[3,3];
            for (int i = 0; i< 3; i++){
                a[0,i] = int.Parse(s[i]);
            }

            s = Console.ReadLine().Split(' ');
            for (int i = 0; i < 3; i++)
            {
                a[1,i] = int.Parse(s[i]);
            }

            s = Console.ReadLine().Split(' ');
            for (int i = 0; i < 3; i++)
            {
                a[2,i] = int.Parse(s[i]);
            }

            int N = int.Parse(Console.ReadLine());
            
            int[] b = new int[N];
            for(int i = 0; i < N; i++)
            {
                b[i] = int.Parse(Console.ReadLine());
            }

            int[,] bingo = new int[3,3];

            for(int i = 0; i < N; i++)
            {
                int ok = 0;
                int q = b[i];
                for(int j = 0; j < 3; j++)
                {
                    for(int k = 0; k < 3; k++)
                    {
                        if (q == a[j,k])
                        {
                            bingo[j,k] = 1;
                            ok = 1;
                            break;
                        }
                    }
                    if (ok == 1) { break; }
                }
            }
            for(int i = 0; i < 3; i++)
            {
                if(bingo[i,0]==1
                    && bingo[i,1]==1
                    && bingo[i, 2] == 1)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            for (int i = 0; i < 3; i++)
            {
                if (bingo[0, i] == 1
                    && bingo[1, i] == 1
                    && bingo[2, i] == 1)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            if (bingo[0, 0] == 1
                && bingo[1, 1] == 1
                && bingo[2, 2] == 1)
            {
                Console.WriteLine("Yes");
                return;
            }
            if (bingo[0, 2] == 1
                && bingo[1, 1] == 1
                && bingo[2, 0] == 1)
            {
                Console.WriteLine("Yes");
                return;
            }
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる



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


Measured memory_bytes: 256
from collections import defaultdict
N,M = list(map(int, input().split()))
adj_list = defaultdict(list)

for _ in range(M):
  a,b = list(map(int, input().split()))
  adj_list[a].append(b)
  adj_list[b].append(a)


def dfs(node, visited):
  if all(visited):
    return 1

  res = 0
  for nei in adj_list[node]:
    if not visited[nei]:
      visited[nei] = True
      res += dfs(nei, visited)
      visited[nei] = False

  return res

cnt = 0
for node in adj_list[1]:
  visited = [False]*(N+1)
  visited[0],visited[1],visited[node] = True,True,True
  cnt += dfs(node, visited)

print(cnt)


Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 練習１
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());

            var s1 = x / 500;
            var s2 = x - s1 * 500;
            var s3 = s2 / 5;
            var s4 = s1 * 1000 + s3 * 5;
            Console.WriteLine(s4);
        }
    }
}

Measured memory_bytes: 11092
A = []
for _ in range(3):
  A += list(map(int, input().split()))
N = int(input())
res = "No"

for _ in range(N):
  b = int(input())
  if b in A:
    ind = A.index(b)
    A[ind] = -1
if any(all(a==-1 for a in A[3*i:3*i+3])for i in range(3)): res = "Yes"
if any(all(a==-1 for a in A[i::3])for i in range(3)): res = "Yes"
if any(all(A[i]==-1 for i in a)for a in [[0,4,8],[2,4,6]]): res = "Yes"
print(res)

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

int main() {
	int H, W;
	while (1) {
		(void)scanf("%d %d", &H, &W);
		if (!H && !W) break;
		for (int i = 0; i < W; i++) {
			printf("#");
		}
		printf("\n");
		for (int i = 0; i < H - 2; i++) {
			printf("#");
			for (int i = 0; i < W - 2; i++) {
				printf(".");
			}
			printf("#\n");
		}
		for (int i = 0; i < W; i++) {
			printf("#");
		}
		printf("\n\n");
	}
	return 0;
}


Measured memory_bytes: 2556
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string S;
    cin >> S;

    vector<string> s = {"SUN", "MON","TUE","WED","THU","FRI","SAT"};

    print(7 - (find(ALL(s), S) - s.begin()));

}


Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
int A[301],K[301];
int main(){
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++){
		cin>>A[i]>>K[i];
		int a=A[i],k=K[i];
		while(true){
			a=a/k*k+a%k%(a/k+1);
			if(a%k){
				a=a-(a/k+1);
			}
			else{
				ans^=(a/k);
				break;
			}
		}
	}
	if(ans)
		cout<<"Takahashi"<<endl;
	else
		cout<<"Aoki"<<endl;
}

//asdkf

Measured memory_bytes: 256
def change(fig):
    sum = 0
    a = 100
    for keta in fig:
        if keta == 1:
            keta = 9
        elif keta == 9:
            keta = 1
        sum += keta * a
        a /= 10
    return sum
        
if __name__ == "__main__":
    n = input()
    fig = list(map(int, list(n)))
    sum = change(fig)
    print(int(sum))

Measured memory_bytes: 3060
import sys

input = sys.stdin.readline


def main():
    N = int(input())

    A = []
    i = 1
    while True:
        if 6**i <= 100000:
            A.append(6**i)
            i += 1
        else:
            break
    A.sort(reverse=True)
    B = []
    i = 1
    while True:
        if 9**i <= 100000:
            B.append(9**i)
            i += 1
        else:
            break
    B.sort(reverse=True)

    ans = float("inf")
    for i in range(N+1):
        n_6, n_9 = i, N-i
        c_6 = 0
        for a in A:
            while True:
                if a <= n_6:
                    n_6 -= a
                    c_6 += 1
                else:
                    break
        c_6 += n_6
        c_9 = 0
        for b in B:
            while True:
                if b <= n_9:
                    n_9 -= b
                    c_9 += 1
                else:
                    break
        c_9 += n_9
        c = c_6 + c_9
        if c < ans:
            ans = c
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
N = int(input())
mod = 10**9+7
no1 = 1
no19 = 1
ans = 1
for i in range(N):
  no1*= 9
  no1 %= mod
  no19 *= 8
  no19 %= mod
  ans *= 10
  ans %= mod
print((ans - no1*2 + no19)%mod)


Measured memory_bytes: 9112
def main():
    from math import ceil
    n = int(input())
    a, b = 1, 1
    for _ in range(n):
        i, j = map(int, input().split())
        x = max((a + i - 1) // i, (b + j - 1) // j)
        a, b = x * i, x * j
    print(a + b)


if __name__ == '__main__':
    main()


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

vector<int> divisor(int x) {
	vector<int> ret;
	int i;
	for (i = 1; i * i < x; i++) {
		if (x % i)
			continue;
		ret.emplace_back(i);
		ret.emplace_back(x / i);
	}
	if (i * i == x)
		ret.emplace_back(i);
	return ret;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int Q; cin >> Q;
	vector<int>v(Q); rep(i, 0, Q) { cin >> v[i]; }
	int M = *max_element(all(v));
	vector<int>hoge(M + 1);
	rep(i, 2, hoge.size()) {
		auto d = divisor(i);
		sort(all(d));
		int x = 1;
		rrep(j, 0, d.size() - 1) {
			x *= d[j];
			if (x >= 2 * i) {
				hoge[i] = 1;
				break;
			}
		}
		hoge[i] += hoge[i - 1];
	}
	dump(hoge);
	rep(i, 0, Q) {
		cout << hoge[v[i]] << endl;
	}

	return 0;
}



Measured memory_bytes: 4328
mod = 10 ** 9 + 7

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

ans = 0

for i in range(k, n + 2):
    mn = i * (i - 1) // 2
    mx = (n * 2 - i + 1) * i // 2
    ans += mx - mn + 1
    ans = ans % mod

print(ans)


Measured memory_bytes: 63564
n, m = map(int, input().split())
sub = [list(input().split()) for _ in range(m)]

ac = [0 for _ in range(n)]
wa = [0 for _ in range(n)]

for s in sub:
    if s[1] == 'AC':
        ac[int(s[0])-1] += 1
    elif ac[int(s[0])-1] == 0:
            wa[int(s[0])-1] += 1

ac_sum = 0
wa_sum = 0
for i in range(n):
    if ac[i] != 0:
        wa_sum += wa[i]
        ac_sum += 1
print(ac_sum, wa_sum)


Measured memory_bytes: 27568
#include <iostream>
#include <cstdlib>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c ;
    std::cin >> a >> b >> c ;
    if(a%2==0&&a==b&&b==c) {
        std::cout << "-1" << std::endl;
        std::exit(0); 
    }
    
    int tempA,tempB,tempC;
    int count=0;

    
    while (a%2==0 && b%2==0 && c%2==0 && count < 50){
        tempA=a;
        tempB=b;
        tempC=c;
        a=(tempB+tempC)/2;
        b=(tempA+tempC)/2;
        c=(tempA+tempB)/2;
        count+=1;
    }
    if (count == 50 ) {
        std::cout << "-1" << std::endl;
    }
    else {
        std::cout << count << std::endl;

    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

bool is_prime(ll n) {
    if (n == 1) {
        return false;
    }
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    ll x;
    cin >> x;

    while (!is_prime(x)) {
        x++;
    }
    cout << x << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    ll A, B;
    cin >> A >> B;
    ll now = 1;
    FOR(i, 0, 100000) {
        if (now >= B) {
            cout << i << endl;
            return 0;
        }
        now += A - 1;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}

bool compareg(Pi a, Pi b) {
    if(a.second != b.second){
        return a.second > b.second;
        
    }else{
        return a.first > b.first;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};



int main() {
    ll n;
    cin>>n;
    vector<ll> s(n);
    vector<ll> l(n);
    vector<ll> p(n);

    rep(i,n){
        cin>>s[i]>>l[i]>>p[i];
    }
    ll m;
    cin>>m;
    vector<ll> w(m);

    rep(i,m){
        cin>>w[i];
    }

    vector<vector<ll>> dp(n+1,vector<ll>(400));

    rep(i,n){
        rep(j,395){
            rep3(k,s[i],l[i]+1){
                if(j-k>=0){
                    dp[i+1][j] = max({dp[i+1][j],dp[i][j],dp[i][j-k]+p[i],dp[i+1][j-k]+p[i]});

                }else{
                    dp[i+1][j] = max({dp[i+1][j],dp[i][j]});
                }
            }
  
        }
    }
    vector<ll> ans(m);
    rep(i,m){
        if(dp[n][w[i]] == 0){
            cout<<-1<<endl;
            return 0;
        }else{
            ans[i] = dp[n][w[i]];
        }

    }
    
    rep(i,m){
        cout<<ans[i]<<endl;
    }
    return 0;
    

}



Measured memory_bytes: 4120
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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

int main() {
	int n;
	cin>> n;
	vector<int> d(n);
	rep(i,n) cin >> d[i];
	int ans=0;
	rep(i,n) for(int j=i+1; j<n; j++) {
		ans += d[i]*d[j];
	}

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


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const LL INF = 1e18;

int mp[12][12];

int main(){
	int x,y,sz;
	CLR(mp);
	char c1,c2;
	while(cin>>x>>c1>>y>>c2>>sz){
		if(sz==0)break;
		x++;y++;
		if(sz==1){
			for(int dx=-1;dx<=1;dx++)for(int dy=-1;dy<=1;dy++){
				if(abs(dx)+abs(dy)<=1)mp[x+dx][y+dy]++;
			}
		}else if(sz==2){
			for(int dx=-1;dx<=1;dx++)for(int dy=-1;dy<=1;dy++){
				if(abs(dx)+abs(dy)<=1||(abs(dx)==1&&abs(dy)==1))mp[x+dx][y+dy]++;
			}
		}else{
			for(int dx=-2;dx<=2;dx++)for(int dy=-2;dy<=2;dy++){
				if(abs(dx)+abs(dy)<=2)mp[x+dx][y+dy]++;
			}
		}
	}
	int cnt=0;
	int ma=0;
	REP(i,10)REP(j,10){
		if(mp[i+1][j+1]==0)cnt++;
		ma=max(ma,mp[i+1][j+1]);
	}
	cout<<cnt<<endl;
	cout<<ma<<endl;
	return 0;
}
/*
2,5,3
3,6,1
3,4,2
4,5,2
3,6,3
2,4,1
0,0,0
*/

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include <tuple>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
#define tpop(p) p.top();p.pop()
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}*/
//---------------------------------------------------
int n, m, p;
vector<P>e;
int a[3000];
bool b[3000];
vector<int>f[3000];
signed main() {
	cin >> n >> m >> p;
	for (int i = 0; i < m; i++) {
		int u, v, r;
		cin >> u >> v >> r;
		e.push_back(Q(u, v, r - p));
		f[u].push_back(v);
	}
	for (int i = 2; i <= n; i++) {
		a[i] = -inf;
	}
	vector<int>v;
	for (int i = 0; i < n; i++) {
		bool l = 0;
		for (P g : e) {
			if (a[g.xx] == -inf) continue;
			if (a[g.yy] < a[g.xx] + g.zz) {
				a[g.yy] = a[g.xx] + g.zz;
				if (i == n - 1) {
					v.push_back(g.yy);
				}
			}
		}
	}
	for (auto g : v) {
		if (a[g] == -inf) continue;
		queue<int>q;
		q.push(g);
		while (!q.empty()) {
			int t = q.front(); q.pop();
			if (b[t]) continue;
			b[t] = 1;
			for (auto r : f[t]) q.push(r);
		}
	}
	if (b[n]) {
		cout << -1 << endl;
	}
	else
		cout << max(0ll, a[n]) << endl;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))

MOD = 10**9 + 7
a_cs = [0] * (n + 1)
for i in range(n):
    a_cs[i + 1] = a_cs[i] + a[i]
    a_cs[i + 1] %= MOD

ans = sum(a_cs[i] * a[i] % MOD for i in range(n))
ans %= MOD
print(ans)


Measured memory_bytes: 31464
#C
N = int(input())
A = list(map(int, input().split()))
step=[0 for i in range(N-1)]
for i in range(N-1):
    if A[i+1] < A[i]:
        step[i]=A[i]-A[i+1]
        A[i+1]=A[i]
print(sum(step))

Measured memory_bytes: 32016
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

vector<vector<int>> ans;
void rec (ll m, ll mstart, ll k, ll kstart) {
    eprintf("%lld %lld %lld %lld\n", m, mstart, k, kstart);
    if (m <= 0) return;
    rep (i, m) {
        ans[kstart].push_back(mstart + i);
        ans[kstart + i + 1].push_back(mstart + i);
    }
    rec(m - 1, mstart + m, k - 1, kstart + 1);
}

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll ng = 0, ok = n;
    while (ok - ng > 1) {
        ll med = (ok + ng) / 2;
        if (med * (med + 1) / 2 >= n) ok = med;
        else ng = med;
    }
    if (ok * (ok + 1) / 2 != n) {
        cout << "No\n"; return 0;
    }
    ll m = ok, k = ok + 1;
    ans.resize(k);
    rec(m, 1, k, 0);
    cout << "Yes\n" << k << "\n";
    rep (i, k) {
        cout << m << " ";
        rep (j, ans[i].size()) cout << ans[i][j] << " \n"[j + 1 == j_len];
    }
    return 0;
}

Measured memory_bytes: 4200
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}

int main()
{
    int n;
    int p[101];
    int m[101][101];
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>p[i-1]>>p[i];
    }
    for(int i=1;i<=n;i++)
    {
        m[i][i]=0;
    }
    for(int c=1;c<n;c++)
        for(int i=1;i<=n-c;i++)
        {
            int j=i+c;
            m[i][j]=99999999;
            for(int k=i;k<j;k++)
            {
                m[i][j]=std::min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    cout<<m[1][n]<<endl;
    return 0;
}



Measured memory_bytes: 3132
s = input()
n = len(s)
count = 0
count2 = 0
for i in range(n):
    if i % 2 == 0:
        x = "0"
    else:
        x = "1"
    if s[i] == x:
        count2 += 1
    else:
        count += 1
print(min(count,count2))

Measured memory_bytes: 3188
N=int(input())
a=[]
for i in range(N):
  a.append(int(input())-1)
flag=True
step=[]
pivot=0
for i in range(N+1):
  step.append(pivot)
  if a[pivot]==1:
    break
  pivot=a[pivot]

if len(step)>N:
  print(-1)
else:
  print(len(step))

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int N; cin >> N;
	vector<int> h(N);
	for(int i = 0; i < N; i++) cin >> h[i];
	vector<int> dp(N);
	dp[1] = abs(h[1] - h[0]);
	for(int i = 2; i < N; i++) dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	cout << dp[N - 1] << endl;
	return 0;
}

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

int main()  {
    string s,res;
    cin>>s;
    for(auto i:s)   {
        if(i!='B')
            res+=i;
        else if(i=='B' && res.size()>0) {
            res.erase(res.size()-1,1);
        }
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 3596
N = gets.to_i
s_list = N.times.map { gets.chomp.chars }
count = s_list.map do |s|
  c = 0
  prev = nil
  s.each do |ch|
    if prev == 'A' && ch == 'B'
      c += 1
    end
    prev = ch
  end
  c
end.reduce(0) { |acc, n| acc + n }
a_count = s_list.count do |s|
  s[-1] == 'A'
end
b_count = s_list.count do |s|
  s[0] == 'B'
end
a_and_b_count = s_list.count do |s|
  s[0] == 'B' && s[-1] == 'A'
end
a_count -= a_and_b_count
b_count -= a_and_b_count
rest_count = begin
  if a_and_b_count == 0
    [a_count, b_count].min
  elsif a_count + b_count > 0
    (a_and_b_count - 1) + [a_count, b_count].min + 1
  else
    a_and_b_count - 1
  end
end
ans = count + rest_count
puts ans


Measured memory_bytes: 8572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleReadKey01
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
          	if(S.Equals("Sunny"))
            {
            Console.WriteLine("Cloudy");
          	}else if(S.Equals("Cloudy"))
            {
              Console.WriteLine("Rainy");
            }else if(S.Equals("Rainy"))
            {
              Console.WriteLine("Sunny");
            }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    cin >> N;
    vector<int> X(N), Y(N), T(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> T[i] >> X[i] >> Y[i];
    }
    
    int t = 0;
    int x = 0, y = 0;
    
    bool ans = true;
    for ( int i = 0; i < N; i++ ) {
        
        int d = abs( X[i]-x ) + abs( Y[i]-y );
        if ( T[i]-t < d ) { ans = false; break; }
        if ( d%2 != (T[i]-t)%2 ) { ans = false; break; }
        
        t = T[i];
        x = X[i];
        y = Y[i];
    }
    
    cout << ( ans ? "Yes" : "No" ) << endl;
    
    return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    string S, T;
    cin >> S >> T;
    string s = "";
    vector<string> v;
    REP(i, S.length()) {
        if (i + T.length() > S.length())
            break;
        string t = s;
        bool exist = true;
        REP(j, T.size()) {
            if (S[i + j] != '?' && S[i + j] != T[j])
                exist = false;
            t.push_back(T[j]);
        }

        if (exist) {
            FOR(j, S.length(), i + T.length()) {
                t.push_back(S[j]);
                if (t[j] == '?')
                    t[j] = 'a';
            }
            v.push_back(t);
        }
        s.push_back(S[i]);
        if (s[i] == '?')
            s[i] = 'a';
    }

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

    if (v.size() == 0)
        cout << "UNRESTORABLE" << endl;
    else
        cout << v[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, x;
	cin >> n >> x;
	
	vector<int> L(n);
	for(int i = 0; i < n; ++i) {
		cin >> L[i];
	}
	
	int ans = 1;
	int d = 0;
	for(int i = 0; i < n; ++i) {
		d += L[i];

		if( d <= x ) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define LOOP(i,x,n) for(int i=(x);i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;
int x[1000006],y[1000006],D[1000006];

signed main(){
  int h,w,d;
  cin>>h>>w>>d;

  REP(i,h)REP(j,w){
    int a;cin>>a;
    y[a]=i;x[a]=j;
  }

  LOOP(i,d+1,h*w+1){
    D[i]=D[i-d]+abs(x[i]-x[i-d])+abs(y[i]-y[i-d]);
  }
  int q;cin>>q;
  REP(i,q){
    int l,r;
    cin>>l>>r;
    cout<<D[r]-D[l]<<endl;
  }
  return 0;
}


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

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

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

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}



int main(){

    ll n, k;
    cin >> n >> k;
    
    mint ans = 0;

    for(ll i = k; k <= n+1; k++){
        mint upper = 2*n - k + 1;
        upper *= k;
        upper /=2;

        mint bottom = k;
        bottom *= k-1;
        bottom /= 2;

        ans += upper - bottom +1;
    }

    cout << ans << endl;
}  



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s,t;
	cin>>s>>t;
	for(int i=0;i<s.size();i++) {
		if(s[i]!=t[i]) {
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int m=n;
  
  int sum=0;
  while(n>0){
    sum+=n%10;
    n/=10;
  }

  if(m%sum==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;
const int maxn =  1e6 + 10;
#define ll long long
#define ios std::ios::sync_with_stdio(false)
const ll INF(0x3f3f3f3f3f3f3f3fll);
const int inf(0x3f3f3f3f);
/*


ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll pow_mod(ll x,ll n,ll mod){ll res=1;while(n){if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}//xµÄn´Î·½mod


ll mult(ll a,ll b,ll p){a%=p;b%=p;ll r=0,v=a;while(b){if(b&1){r+=v;if(r>p)r-=p;}v<<=1;if(v>p)v-=p;b>>=1;}return r;}
ll quick_pow(ll a,ll b,ll p){ll r=1,v=a%p;while(b){if(b&1)r=mult(r,v,p);v=mult(v,v,p);b>>=1;}return r;}
bool CH(ll a,ll n,ll x,ll t)
{ll r=quick_pow(a,x,n);ll z=r;for(ll i=1;i<=t;i++){r=mult(r,r,n);if(r==1&&z!=1&&z!=n-1)return true;z=r;}return r!=1;}
bool Miller_Rabin(ll n)
{if(n<2)return false;if(n==2)return true;if(!(n&1))return false;ll x=n-1,t=0;while(!(x&1)){x>>=1;t++;}srand(time(NULL));
ll o=8;for(ll i=0;i<o;i++){ll a=rand()%(n-1)+1;if(CH(a,n,x,t))return false;}return true;}


*/

#define int long long
#define sc(t) scanf("%lld",&t)
#define pr(ans) printf("%lld\n",ans)
ll pow_mod(ll x,ll n,ll mod){ll res=1;while(n){if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}//xµÄn´Î·½mod
template<typename T>void read(T &res){bool flag=false;char ch;while(!isdigit(ch=getchar()))(ch=='-')&&(flag=true);
for(res=ch-48;isdigit(ch=getchar());res=(res<<1)+(res<<3)+ch - 48);flag&&(res=-res);}
typedef unsigned long long ULL;
const double pi = 3.1415926535897932384626;
int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
#define debug(x) cout << #x << " : " << x << '\n';
#define sb cout << "sb\n";
#define fi first
#define se second
#define pb(a) push_back(a)
#define cn cout << '\n'
#define mp(a , b) make_pair(a , b)
const int mod = 8011200280112002;
int a[maxn];

signed main()
{
    ios;///60 10 50
    cin.tie(0);
    int shang = 1e18;
    int n;
    cin >> n;
    for(int i = 1 ; i <= n ; i ++){
        cin >> a[i];
    }
    sort(a + 1 , a + 1 + n);
    int ans = 1;
    for(int i = 1 ; i <= n ; i ++){
        if(a[i] == 0){
            ans = 0;
            break;
        }
        if(a[i] > shang / ans){
            ans = -1;
            break;
        }
        else{
            ans *= a[i];
            if(ans > shang){
                ans = -1;
                break;
            }
        }
    }
    cout << ans << '\n';


	return 0;
}


Measured memory_bytes: 4424
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define rep(i,a,b)  for (int i = a; i < b; ++i)
#define rrep(i,z,a) for (int i = z; i >= a; --i)
#define rep0(n)     for(int i = 0 ; i < n; ++i )
#define rep1(n)     for(int i = 1 ; i <= n; ++i )
#define pb          push_back
#define sd(x)       scanf("%d",&x)
#define tc          int test;cin>>test; while(test--)
#define all(v)      v.begin(),v.end()
#define ff          first
#define ss          second
#define mp          make_pair
#define IOS         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl        "\n"
#define spc         " "
#define mem0(a)     memset(a,0,sizeof(a))
#define extime      cout << endl << endl << "____"<<(float)clock() / CLOCKS_PER_SEC << "s____";
#define maxn        998244353
#define mod         1000000007
//#define ll          long long int
//typedef vector<ll>  vll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
void OJ()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
int solve()
{
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  int ans = INT_MAX;
  rep(i, 0, n - m + 1)
  {
    int tcnt = 0;
    rep(j, 0, m)if (s[i + j] != t[j])tcnt++;
    ans = min(tcnt, ans);
  }
  cout << ans ;
  return 0;
}
signed main()
{
  OJ();
  IOS
  //tc
  solve();
  //extime
  return 0;
}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x.ToString())).ToList();

            long cnt = 0;
            long ans = 0;
            long befa = -1;

            foreach (var a in A)
            {
                if (befa != a)
                {
                    ans += (cnt + 1) / 2;
                    cnt = 0;
                }
                else
                {
                    cnt++;
                }

                befa = a;
            }
            ans += (cnt + 1) / 2;
            Console.WriteLine(ans.ToString());


        }


    }
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n;cin>>n&&n;){
		int res=0;
		rep(i,n){
			int x; cin>>x;
			res^=x&1;
		}
		cout<<(res==0?"YES":"NO")<<endl;
	}
}


Measured memory_bytes: 256
#!/usr/bin/env python3

X, Y, A, B, C = list(map(int, input().split()))
p_list = list(map(int, input().split()))  # 10 ** 5
q_list = list(map(int, input().split()))
r_list = list(map(int, input().split()))

p_list = list(sorted(p_list, reverse=True))
q_list = list(sorted(q_list, reverse=True))
# r_list = sorted(r_list, reverse=True)

p_list = p_list[:X]
q_list = q_list[:Y]

all_list = p_list + q_list + r_list
all_list = list(sorted(all_list, reverse=True))
total = sum(all_list[: X + Y])


ans = total
print(ans)


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

int main(){
  map<int,bool>memo;
  int N;
  cin>>N;

  int cnt=0;

  for(int i=0;i<N;i++){
    int p[3];
    cin>>p[0]>>p[1]>>p[2];

    sort(p,p+3);

    int k=((p[0]-1)*1000+(p[1]-1))*1000+(p[2]-1);

    if(memo.find(k)!=memo.end()){
      cnt++;
    }else{
      memo[k]=true;
    }
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3200
var
	N,i,j:Longint;
	ans:double;
	x,y:Array[1..8]of Longint;
begin
	read(N);
	for i:=1 to N do read(x[i],y[i]);
	for i:=1 to N do for j:=1 to N do begin
		if i=j then continue;
		ans:=ans+sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
	end;
	writeln(ans/N:0:9);
end.


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1);
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Printer{
    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T>
    void print(T x, T y){
        cout << x << "," << y << endl;
    }

    template<class T>
    void print(vector<T> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class T>
    void print(vector<vector<T> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};
using namespace Printer;

//--global--//



//----------//

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    int n;
    cin >> n;
    int mi = INTINF;
    int cnt = 0;
    rep(i, n){
        int a;
        cin >> a;
        if(mi > a){
            mi = a;
            cnt++;
        }
    }

    cout << cnt << endl;
    
    return 0;
}


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

using namespace std;

typedef long long ll;

ll MOD = 998244353;
ll powmod(ll a, ll b){
  if(b == 0) return 1;
  if(b & 1) {
    return a * powmod(a, b - 1) % MOD;
  } else {
    ll d = powmod(a, b / 2) % MOD;
    return d * d % MOD;
  }
}

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

	ll n;
	cin >> n;

	vector<ll> d(n);
	rep(i, n) cin >> d[i];

	if(d[0] != 0){
		cout << 0 << endl;
		return 0;
	}

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

	ll now = -1;
	rep(i, n){
		if(i > 0 && d[i] == 0){
			cout << 0 << endl;
			return 0;
		}

		if(d[i] != now && d[i] != now + 1){
			cout << 0 << endl;
			return 0;
		}

		now = d[i];
	}

	map<ll, ll> mp;
	rep(i, n){
		if(mp.count(d[i]) == 0){
			mp[d[i]] = 0;
		}
		mp[d[i]]++;
	}

	ll ans = 1;
	rep(i, now){
		ans *= powmod(mp[i], mp[i+1]);
		ans %= MOD;
	}

	cout << ans << endl;
}


Measured memory_bytes: 7296
n=int(input())
B=[]
for i in range(n):
  x,l=map(int,input().split())
  B.append([x-l,x+l])
B.sort(key=lambda x:x[1])
max_l=-10**18-5
ans=0
for b in B:
  if max_l <= b[0]:
    max_l = b[1]
    ans+=1
print(ans)

Measured memory_bytes: 92468
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N, K = map(int, raw_input().split())
R = [0] * (10**5+10) 

for i in xrange(N):
     ia, ib = map(int, raw_input().split())
     R[ia] += ib

k = 0
c = 0
while k < K:
    c += 1
    k += R[c]
print c    

Measured memory_bytes: 4868