akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
    int X, Y, Z;
    cin >> X >> Y >> Z;

    int N = X + Y + Z;
    
    ll ans = 0;    

    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        cin >> B[i];
        cin >> C[i];

        ans += A[i];
        B[i] -= A[i];
        C[i] -= A[i];
    }
    
    
    vector<pair<ll, ll> > points(N);
    for(int i=0;i<N;i++){
        points[i] = make_pair(B[i], C[i]);
    }

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

    priority_queue<ll> pq;
    for(int i=0;i<X;i++){
        ll curC = points[i].second;
        pq.push(curC);
    }

    vector<ll> sumCs(N, 0);
    ll cur = 0;
    for(int i=X;i<X+Z;i++){
        pq.push(points[i].second);
        cur += pq.top();
        sumCs[i+1] = cur;
        pq.pop();
    }

    priority_queue<ll> pq2;
    cur = 0;
    for(int i=X+Z;i<N;i++){
        cur += points[i].first;
        pq2.push(points[i].second - points[i].first);
    }

    vector<ll> sumCmBs(N, cur);
    for(int i=X+Z-1;i>=X;i--){
        pq2.push(points[i].second - points[i].first);
        cur += points[i].first;
        cur += pq2.top();
        sumCmBs[i] = cur;
        pq2.pop();
    }
    
    ll best = sumCs[X] + sumCmBs[X];
    for(int i=X;i<=X+Z;i++){
        if(sumCs[i] + sumCmBs[i] > best){
            best = sumCs[i] + sumCmBs[i];
        }
    }

    ans += best;
    cout << ans << endl;
    
    return 0;
}


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

int parent(int);
int left(int);
int right(int);


int main(){
  int i,n;
  int *num;
  int p;

  scanf("%d",&n);

  num=malloc(sizeof(int)*(n+1));

  for(i=1;i<n+1;i++){ scanf("%d",&num[i]); }

  
  for(i=1;i<n+1;i++){
    printf("node %d: key = %d, ",i,num[i]);
    p=parent(i);
    
    if(p>0) printf("parent key = %d, ",num[p]);
    if(left(i)<n+1) printf("left key = %d, ",num[left(i)]);
    if(right(i)<n+1) printf("right key = %d, ",num[right(i)]);
    printf("\n");
  }

  return 0;

}

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

Measured memory_bytes: 600
num=int(input())
height=list(map(int,input().split()))
 
dp=[0]*(num)
dp[1]=abs(height[1]-height[0])

for i in range(2,num):
  dp[i] = min(dp[i-1]+abs(height[i]-height[i-1]), dp[i-2]+abs(height[i]-height[i-2]))
print(dp[-1])

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

int main() {
	// your code goes here
	int a[10];

for (int i = 0; i<10; ++i)
{
 scanf("%d",&a[i]);
}
sort(a,a+10);
printf("%d\n",a[9]);
printf("%d\n",a[8]);
printf("%d\n",a[7]);
	 return 0;
}

Measured memory_bytes: 3220
#include <stdio.h>
#define N 500000

int H, A[N];

void maxHeapify(int);

int main(){
  int i;
  scanf("%d",&H);

  for( i = 1; i <= H; i++ )
    scanf("%d", &A[i]);

  for( i = H/2; i >= 1; i-- )
    maxHeapify(i);

  for( i = 1; i <= H; i++ )
    printf(" %d", A[i]);
  printf("\n");

  return 0;
}

void maxHeapify(int i){
  int left, right, largest, tmp;
  left = 2 * i;
  right = 2 * i + 1;

  if( left <= H && A[left] > A[i] )
    largest = left;
  else
    largest = i;
  if( right <= H && A[right] > A[largest] )
    largest = right;

  if( largest != i ){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}



Measured memory_bytes: 3696
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstring>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD = 1e9+7;
const ll CFMOD = 998244353;
const double PI  = 3.14159265358;
const double EPS = 1e-6;
 
#define INT_MAX 2147483647
#define INF ((int)1e9)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define siz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define PB push_back
#define PF push_front
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define vec vector
#define __ <<' '<<
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void solve(){
    int n;
    
    cin >> n;
    vec<pii> v(n);
    vec<ll> dp(n+1);
    for(auto &i:v)  cin >> i.F >> i.S, i.S += i.F;
    sort(ALL(v));
    
    stack<pii> stk;
    stk.push(MP(INT_MAX, 0));
    int k;
    dp[n] = 1;
    for(int i=n-1; i>=0; i--){
        k = i;
        while(v[i].S > stk.top().F){
            v[i].S = max(v[i].S, v[stk.top().S].S);
            k = stk.top().S;
            stk.pop();
        }
        stk.push(MP(v[i].F, k));
        dp[i] = (dp[i+1] + dp[stk.top().S + 1]) % CFMOD;
    }
    
    cout << dp[0] << '\n';
}

int main() {
    int T = 1;
    
    //cin >> T;
    while(T--){
        solve();
    }
}


Measured memory_bytes: 4224
nums = list(str(input()))
l = len(nums) - 1
for i in range(2**l):
    op = [""] * l
    res = ""
    for j in range(l):
        if (i >> j) & 1:
            op[j] = "+"
        else:
            op[j] = "-"
    for n, k in zip(nums, op+[""]):
        res += n + k
    ans = eval(res)
    if ans == 7:
        print(res + "=7")
        break

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

func main() {
	n := readi()
	a := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		a[i] = readi()
	}
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}

	ans := 0
	for i := 0; i < n; i++ {
		if a[i] <= b[i] {
			ans = ans + a[i]
			tmp := (b[i] - a[i])
			if a[i+1] <= tmp {
				ans = ans + a[i+1]
				a[i+1] = 0
			} else {
				ans = ans + tmp
				a[i+1] = a[i+1] - tmp
			}
		} else {
			ans = ans + b[i]
		}
	}

	fmt.Println(ans)
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return (a * b) / gcd(a, b)
}

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

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7

	COMB_MAX = 510000
)

var (
	readString func() string
)

var (
	fac  = [COMB_MAX]int{}
	finv = [COMB_MAX]int{}
	inv  = [COMB_MAX]int{}
)

func init() {
	readString = newReadString(os.Stdin)
}

func combInit() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < COMB_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
	}
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
using namespace std;

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

typedef long long ll;

const int INF = 1e8;

int main() {
    int N; cin >> N;
    int A[N]; rep(i, N) cin >> A[i]; 

    int res = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            res = max(res, abs(A[i] - A[j]));
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = readline().rstrip().decode()
if s[n // 2:] == s[:n // 2]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int[,] map = new int[11, 7];

            for (int i = 1; i <= 9; i++)
            {
                string input = Console.ReadLine();

                if (i % 2 == 1) input = "00" + input;
                else input = "0" + input;

                for (int j = 0; j < input.Length; j++)
                {
                    map[i, j] = int.Parse(input[j].ToString());
                }
            }

            int posX = 1, posY = 1;
            char dir = 'R';

            while (true)
            {
                switch (dir)
                {
                    case 'R':
                        if (map[posY - 1, posX] == 1) { posY--; dir = 'U'; }
                        else if (map[posY, posX + 1] == 1) { posX++; }
                        else if (map[posY + 1, posX] == 1) { posY++; dir = 'D'; }
                        else { dir = 'L'; }
                        break;
                    case 'L':
                        if (map[posY + 1, posX - 1] == 1) { posY++; posX--; dir = 'D'; }
                        else if (map[posY, posX - 1] == 1) { posX--; }
                        else if (map[posY - 1, posX - 1] == 1) { posY--; posX--; dir = 'U'; }
                        else { dir = 'R'; }
                        break;
                    case 'D':
                        if (map[posY + 1, posX + 1] == 1) { posY++; posX++; dir = 'R'; }
                        else if (map[posY + 2, posX] == 1) { posY += 2; }
                        else if (map[posY + 1, posX] == 1) { posY++; dir = 'L'; }
                        else { dir = 'U'; }
                        break;
                    case 'U':
                        if (map[posY - 1, posX] == 1) { posY--; dir = 'L'; }
                        else if (map[posY - 2, posX] == 1) { posY -= 2; }
                        else if (map[posY - 1, posX + 1] == 1) { posY--; posX++; dir = 'R'; }
                        else { dir = 'D'; }
                        break;
                }
                sb.Append(dir);

                if (dir == 'L' && posX == 2 && posY == 1) break;
                if (dir == 'U' && posX == 1 && posY == 2) break;
            }
            Console.WriteLine(sb);
        }
    }
}

Measured memory_bytes: 8868
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var N, K int
  var A []int
  NextInt(&N, &K)
  NextIntVec(&A)
  B := make([][]int, 2)
  for i := range B { B[i] = make([]int, N + 1) }
  for i, a := range A { B[0][i] = a }
  for k := 0; k < K; k++ {
    i := k % 2
    for j := range B[1 - i] { B[1 - i][j] = 0 }
    for j, b := range B[i][:N] {
      B[1 - i][MaxInt(j - b, 0)]++
      B[1 - i][MinInt(j + b + 1, N)]--
    }
    for j, b := range B[1 - i][:N] {
      B[1 - i][j + 1] += b
    }
    if SumInt(B[i]...) == N * N { break }
  }
  WriteIntVec(B[K % 2][:N])
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntVec(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  Write(B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define lin "\n"
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(0)

void solve() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n&1){
        cout<<"No";
        return;
    } else{
        for(int i=0;i<n/2;++i){
            if(s[i]!=s[i+n/2]){
                cout<<"No";
                return;
            }
        }
    }
    cout<<"Yes";
}

int main() {
    fast_io;
    int t = 1;
//    cin >> t;
    int c = 1;
    while (t--) {
//        printf("Case %lld: ",c);
//        cout<<"Case "<<c<<": ";
        solve();
        c++;
    }
}

Measured memory_bytes: 3588
#include<stdio.h>

int main()
{
  int A,B,max;
  scanf("%d %d",&A,&B);
  max=A+B;
  if((A-B)>max)max=A-B;
  if((A*B)>max)max=A*B;

  printf("%d\n",max);

  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <map>
using namespace std;



double dis(int i, int j, const vector<pair<int,int>> & pos ){
    return sqrt(pow(pos[i].first-pos[j].first,2)+pow(pos[i].second-pos[j].second,2));
}

int main(){
    long n;
    map<long,long> pr;
    cin >> n ;
    
    for(long i=1; i<n; i++){
        long tmp;
        cin >> tmp;
        pr[tmp]++;
    }
    for(long i=1;i<n+1;i++){
        if(pr.count(i)){
            cout << pr[i] << endl;
        }else{
            cout << 0 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 16012
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

sx,sy,tx,ty = I()
a = ty-sy
b = tx-sx
ans1 = 'U'*a+'R'*b+'D'*a+'L'*(b+1)
ans2 = 'U'*(a+1)+'R'*(b+1)+'D'+'R'+'D'*(a+1)+'L'*(b+1)+'U'
print(ans1+ans2)

Measured memory_bytes: 27072
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>


using namespace std;
int MIN (int a,int b){
    return a>b?b:a;
}



int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int Slen = S.length();
    char wb[Slen],bw[Slen];
    ll min = 100000;
    for(int i = 0; i < Slen;i++){   
        if(i%2 == 0){
            bw[i] = '0';
            wb[i] = '1';
        }else{
            bw[i] = '1';
            wb[i] = '0';
        }
    }
    int countWb = 0;
    int countBw = 0;
    for(int i = 0; i < Slen;i++){
        if(S[i] != wb[i]){
            countWb++;
        }
    }
    for(int i = 0; i < Slen;i++){

        if(S[i] != bw[i]){
            countBw++;
        }
    }
    min = MIN(countWb,countBw);
    cout << min << endl;


    


    return 0;
}

Measured memory_bytes: 720
def main():
    A,B,C,D = map(int,input().split())
    temp = 0

    while A>0 and C>0:
        temp += 1
        if temp%2 == 1:
            C = C - B
        else:
            A -= D
        #print(temp,A,C)

    if temp%2 == 1:
        return 'Yes'
    else:
        return 'No'

print(main())


Measured memory_bytes: 9144
N,M = map(int, input().split())
edge = [[] for _ in range(N)]
deg = [0]*N
parent = [[] for _ in range(N)]
for _ in range(N-1+M):
    x, y = map(int, input().split())
    edge[x-1].append(y-1)
    deg[y-1] += 1
    parent[y-1].append(x-1)
    
from collections import deque
res = list(v for v in range(N) if deg[v] == 0)
q = deque(res)
while q:
    v = q.popleft()
    for t in edge[v]:
        deg[t] -= 1
        if deg[t] == 0:
            q.append(t)
            res.append(t)
    
res.reverse()
f = [0]*N
for i in range(N):
    f[res[i]] = i
    
ans = [0]*N
for i in range(N):
    if parent[i]:
        temp = parent[i][0]
        for p in parent[i]:
            if f[temp] > f[p]:
                temp = p
        ans[i] = temp+1
        
for i in range(N):
    print(ans[i])

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

const int N = 2e+3 + 5;
long long int a[N], isf[N], ans, dp[N][N];
vector<pair<long long int, int>> v;
int n;

long long int solve(int i, int j)
{
    if (i == v.size())
        return 0;
    if (dp[i][j] == -1)
    {
        int i1 = v[i].second;
        int k = n - 1 - (i - j);
        dp[i][j] = max((long long)abs(i1 - j) * v[i].first + solve(i + 1, j + 1), (long long)abs(i1 - k) * v[i].first + solve(i + 1, j));
    }
    return dp[i][j];
}

int main()
{
    memset(dp,-1,sizeof(dp));
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        v.push_back(make_pair(a[i], i-1));
    }
    sort(v.begin(), v.end(), greater<pair<long long int, int>>());
    // for (int j = 0; j < n; j++)
    // {
    //     int maxi = 0;
    //     int k = v[j].second;
    //     for (int i = 1; i <= n; i++)
    //     {
    //         if (isf[i] == 0)
    //         {
    //             if (maxi == 0)
    //                 maxi = i;
    //             if (abs(i - k) > abs(maxi - k))
    //                 maxi = i;
    //         }
    //     }
    //     cout << k << " " << maxi << "\n";
    //     ans += (long long)abs(maxi - k) * a[k];
    //     isf[maxi] = 1;
    // }
    ans = solve(0, 0);
    cout << ans;
}

Measured memory_bytes: 35264
#include <iostream>
using namespace std;
 
int main(void)
{
  int N, M;
  cin >> N >> M;
  int road[N];
  for (int i = 0; i < N; ++i) {
    road[i] = 0;
  }
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    road[a-1]++;
    road[b-1]++;
  }
  for (int i = 0; i < N; ++i) {
    cout << road[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

  ll x;
  cin >> x;

  ll ans = x / 11 * 2;
  if(x % 11 != 0 && x % 11 <= 6) {
    ans++;
  } else if(x % 11 > 6) {
    ans += 2;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int l,r,n,m;
int main()
{
    scanf("%d%d",&n,&m);
    scanf("%d%d",&l,&r);
    for(int i=1;i<m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        l=max(x,l);
        r=min(y,r);
    }
    printf("%d\n",r>=l?r-l+1:0);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	vector<ll> a(5);
	for (ll i = 0; i < 5; i++) {
		cin >> a[i];
		if (a[i] == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3652
input_num=input().split()# 2 4 5のような入力
input_num=[int(num) for num in input_num]#intへ変換

A,B,C=input_num

cup_1=B
cup_2=C

cup_1=B+cup_2
cup_2=0

if cup_1>=A:
    cup_1=A
    cup_2=B+C-cup_1
    print(cup_2)
else:
    print(0)

Measured memory_bytes: 3060
n = gets.chomp.to_i
graph = Hash.new{ |h,k| h[k] = {} }

(n-1).times do |i|
  u, v, w = gets.chomp.split.map(&:to_i)
  graph[u][v] = w & 1
  graph[v][u] = w & 1
end

color = [0]
queue = graph[1].to_a
while q = queue.shift
  dist, parity = q
  next if color[dist-1] != nil

  color[dist-1] = parity

  graph[dist].each do |d, w|
    queue << [d, parity ^ w]
  end
end

puts(color.join("\n"))

Measured memory_bytes: 38396
#include <iostream>
using namespace std;
const int INF = 1000000000;

int main() {
    int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
    int ans = INF;
    for (int i = 0; i <= max(X, Y); i++) {
        int cost = A * max(0, X - i) + B * max(0, Y - i) + 2 * C * i;
        ans = min(ans, cost);
    }
    cout << ans << endl;
    return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
	a[i]=(s[i]=='R');
    }
    int z = std::count(a.begin(), a.end(), 0);
    
    vector<int> g = a;
    sort(g.rbegin(), g.rend());

    
    int diffs=0;
    for (int i=0; i<n; i++) {
	diffs += (a[i]!=g[i]);
    }

    assert(diffs%2==0);
    int ans1 = diffs/2;
    out(ans1);
    // int ans2 = min(z, n-z);
    // //assert(ans1<=ans2);

    // cout<<min(ans1,ans2)<<endl;    
    
    return 0;
}


Measured memory_bytes: 5512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int W = sc.nextInt();
    int[] w = new int[n];
    long[] v = new long[n];
    for(int i = 0; i < n; i++) {
      w[i] = sc.nextInt();
      v[i] = sc.nextLong();
    }
    long[][] dp = new long[n][W + 1];
    dp[0][w[0]] = v[0];
    for(int i = 1; i < n; i++) {
      for(int j = 1; j <= W; j++) {
        if(j >= w[i]) {
          dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
        } else {
          dp[i][j] = dp[i - 1][j];
        }
      }
    }
    long ans = 0; 
    for(int j = 1; j <= W; j++) {
      ans = Math.max(ans, dp[n - 1][j]);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 127060
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  ll n;
  cin >> n;
  if(n%2==0||n%5==0){
    cout << -1 << endl;
    return 0;
  }
  int ans=1;
  ll o=7;
  while(true){
    if(o%n==0){
      cout << ans << endl;
      return 0;
    }
    o=(o*10+7)%n;
    ans++;
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
int32_t main(){
    fastio;
    int l,r;
    cin >> l >> r;
    int ans = inf;
    int j = 0;
    for(int i=l;i<=r && i < l + 3000;i++){
        for(int j=i+1;j<=r && j < l+3000;j++){
            ans = min(ans,mod(i*j,2019));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 1000010
using namespace std;
ll n,ans=1;
bool pm[N];
vector<ll> prime;
vector<pair<ll,ll> > tk;
void dfs(ll num,ll val,ll mn)
{
	ll i;
	if(num==tk.size())
	{
		if(val==1)
		{
			return;
		}
		if((ll)(n/pow(val,mn))%val==1)
		{
			ans++;
		}
		return;
	}
	for(i=0;i<=tk[num].S;i++)
	{
		if(i==0)
		{
			dfs(num+1,val,mn);
		}
		else
		{
			dfs(num+1,val*pow(tk[num].F,i),min(mn,tk[num].S/i));
		}
	}
	return;
}
int main(){
	ll i,j,x,t;
	cin>>n;
	memset(pm,true,sizeof(pm));
	pm[0]=pm[1]=false;
	for(i=2;i<N;i++)
	{
		if(pm[i])
		{
			prime.push_back(i);
			for(j=i*2;j<N;j+=i)
			{
				pm[j]=false;
			}
		}
	}
	x=n;
	for(i=0;i<prime.size();i++)
	{
		if(x%prime[i])
		{
			continue;
		}
		tk.push_back(make_pair(prime[i],0));
		while(x%prime[i]==0)
		{
			x/=prime[i];
			tk[tk.size()-1].S++;
		}
	}
	if(x!=1)
	{
		tk.push_back(make_pair(x,1));
	}
	x=n-1;
	for(i=0;i<prime.size();i++)
	{
		if(x%prime[i])
		{
			continue;
		}
		t=1;
		while(x%prime[i]==0)
		{
			x/=prime[i];
			t++;
		}
		ans*=t;
	}
	if(x!=1)
	{
		ans*=2;
	}
	ans--;
	dfs(0,1,INF);
	cout<<ans<<endl;
	return 0;
}

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

string days[8]={"", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};

int main(){
	string s;
	cin >> s;
	int spoint;
	for(int i=1; i<=8; i++) if(s==days[i]){
		spoint = i;
		break;
	}
	
	int total=0;
	bool z=false;
	for(int i=spoint; ;i++){
		if(i==7 && z==true){
			cout << total;
			return 0;
		}
		if(i==7 && z==false){
			i = 1;
			total++;
			z = true;
		}
		else z=true;
		total++;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e3+9;
int main(){
	int a[maxn],b[maxn],h,w;
	int n;
	scanf("%d",&n);
	scanf("%d%d",&h,&w);
	for(int i=0;i<n;++i)
		scanf("%d%d",&a[i],&b[i]);
	
	int ans=0;
	for(int i=0;i<n;++i)
		if(h<=a[i]&&w<=b[i])
			ans+=1;
	
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll N, W[101] = {}, sum[101] = {}, ans = 1e6;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> W[i];
		sum[i] = sum[i - 1] + W[i];
	}
	for (int i = 1; i < N; i++)ans = min(ans, abs(2 * sum[i] - sum[N]));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define mod 1000000007 
#define rep(i,j,l) for(int i=j;i<=l;i++)
#define dec(i,j,l) for(int i=j;i>=l;i--)
#define input(a,n) rep(i,0,n-1)cin>>a[i]
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction


int main()
{  ios_base::sync_with_stdio(0); 
   cin.tie(NULL);
   ll t,n,i,q,x,mx,k;
   cin>>n;
   int a[n]; 
   input(a,n);
   int cost[n];
   cost[0]=0;
   cost[1]=abs(a[0]-a[1]);
   rep(i,2,n-1)
    cost[i]=min(abs(a[i]-a[i-1])+cost[i-1],abs(a[i]-a[i-2])+cost[i-2]);
   
   cout<<cost[n-1];
   return 0;            
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>

int main()
{
    int a;
    scanf("%d",&a);
    if(a<1200)
        printf("ABC");
    else if(a<2800)
        printf("ARC");
    else 
        printf("AGC");
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;

int N, A, B;
ll h[MAX_N];
ll check[MAX_N];

bool judge(ll hit){
	for(int i = 0; i < N; i++) check[i] = h[i];
	for(int i = 0; i < N; i++) check[i] -= B * hit;
	ll a_num = 0;
	for(int i = 0; i < N; i++){
		//printf("%d %d\n", i, check[i]);
		if(check[i] <= 0) break;
		a_num += ceil((double)check[i] / (double)(A - B));
	}
	//printf("%d %d\n", a_num, hit);
	if(a_num > hit) return false;
	else return true;
}

void solve(){
	sort(h, h + N);
	reverse(h, h + N);
	ll lb = 1L; ll rb = h[0];
	ll mid = lb + (rb - lb) / 2;
	while(lb < rb){
		//printf("%lld %lld %lld\n", lb, rb, mid);
		if(judge(mid) == true) rb = mid;
		else lb = mid + 1;
		mid = lb + (rb - lb) / 2;
	}
	printf("%lld\n", mid);
}

int main(){
	scanf("%d %d %d", &N, &A, &B);
	for(int i = 0; i < N; i++) scanf("%lld", &h[i]);
	solve();
	return 0;
}


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

long long mod = 1000000007;

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

  set<int> s;
  map<int,int> num;

  for(int i = 2;i <= n;i++){
    int cur = i;
    for(int j = 2;j <= i;j++){
      while(cur%j==0){
	s.insert(j);
	num[j]++;
	cur/=j;
      }
    }
  }

  long long ret = 1;

  for(auto itr = s.begin();itr!=s.end();itr++){
    ret *= num[*itr]+1;
    ret = ret%mod;
  }

  cout << ret << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
string s,p,x;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    ll t,i,j,n,m,l,r;
    cin>>s>>p>>x;
    cout<<"A"<<p[0]<<"C\n";
    return 0;
}



Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#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>

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 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(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

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

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main(){
       string s;
       cin >> s;
       int st = s.find('*');
       int rr=0, r=0, l=0, ll=0, ans;
       ll = s.find( '(');
       rr = s.rfind(')');
       
       for(int i = ll; i < st; i++){
           if(s[i]=='(') l++;
           if(s[i]==')') l--;
       }
       for(int i = st+1; i <=rr; i++){
           if(s[i]==')') r++;
           if(s[i]=='(') r--;
       }
       if(r<=l) ans = r;
       else ans = l;
       if(ans<=0) ans=0;
       cout << ans << endl;
       
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#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 rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)

ll C[51][51];
ll N,A,B;
vector<ll> v;

void calc_C() {
  C[0][0] = 1;

  for (int i = 1;i <= 50;i++) {
    C[i][0] = 1;
    for (int j = 1;j <= 50;j++) {
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
    }
  }
}

void solve() {
  calc_C();
  sort(v.begin(),v.end(),greater<ll>());
  ll maxi = 0;

  rep(i,N) maxi = max(v[i],maxi);

  ll nmax = 0;
  rep(i,N) nmax += (v[i] == maxi);

  ll kumi = 0;
  if (nmax < A) {
    map<ll,ll> m;

    rep(i,A) {
      if (m.find(v[i]) == m.end()) {
        m[v[i]] = 1;
      } else {
        m[v[i]]++;
      }
    }

    kumi = 1;

    for (auto p : m) {
      ll cou = 0;
      rep(i,N) {
        if (v[i] == p.first) {
          cou++;
        }
      }

      kumi *= C[cou][p.second];
    }
  } else {
    ll D = min(B,nmax);

    for (int i = A;i <= D;i++) {
      kumi += C[nmax][i];
    }
  }

  double kati = 0.0;

  rep(i,A)kati += v[i];

  kati /= A;

  printf("%.10f\n%lld\n",kati,kumi);
}

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

  v.resize(N);
  rep(i,N) {
    cin >> v[i];
  }
  solve();
  return 0;
}



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

#define NUM 100

double Manhattan(double x[NUM], double y[NUM], int n);
double Euclidean(double x[NUM], double y[NUM], int n);
double MinkowskiP3(double x[NUM], double y[NUM], int n);
double Chebyshev(double x[NUM], double y[NUM], int n);

int a;

int main(void)
{
	int i ;
	int j = 0;
	int  n ;
	double ans1,ans2,ans3,ans4;
	double x[NUM];
	double y[NUM];

	scanf("%d", &n);
	for (i = 0; i < n;i++){
		scanf("%lf", &x[i]);
	}
	for (i = 0; i < n; i++){
		scanf("%lf", &y[i]);
	}

	ans1 = Manhattan(x, y, n);
	ans2 = Euclidean(x, y, n);
	ans3 = MinkowskiP3(x, y, n);
	ans4 = Chebyshev(x, y, n);

	printf("%lf\n%lf\n%lf\n%lf\n", ans1,ans2,ans3,ans4);

	return 0;
}

double Manhattan(double x[NUM], double y[NUM], int n){
	
	double z[NUM];
	double p1 = 0;

	for (a = 0; a < n; a++){
		z[a] = x[a] - y[a];
		p1 += abs(z[a]);
	}

	return p1;
}

double Euclidean(double x[NUM], double y[NUM], int n){

	double z[NUM];
	double s[NUM];
	double p2 = 0;

	for (a = 0; a < n; a++){
		z[a] = x[a] - y[a];
		s[a] = abs(z[a])*abs(z[a]);
		p2 += s[a];
	}

	return sqrt(p2);
}

double MinkowskiP3(double x[NUM], double y[NUM], int n){
	double z[NUM];
	double s[NUM];
	double p3 = 0;

	for (a = 0; a < n; a++){
		z[a] = x[a] - y[a];
		s[a] = abs(z[a])*abs(z[a])*abs(z[a]);
		p3 += s[a];
	}

	return pow(p3,1.0/3.0);
}

double Chebyshev(double x[NUM], double y[NUM], int n){

	double z[NUM];
	double s[NUM];

	for (a = 0; a < n; a++){
		z[a] = x[a] - y[a];
		s[a] = abs(z[a]);
	}
	double max = s[0];
	for (a = 0; a < n; a++){
		if (max<s[a])
			max = s[a];
	}

	return max;
}

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

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define eb emplace_back
#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

vector<vector<pair<int, int>>> g;
vector<int> ans;

void dfs(int v, int now = 0, int pr = -1) {
	ans[v] = now % 2;
	for (auto& p : g[v]) {
		if (p.first != pr) {
			dfs(p.first, now + p.second, v);
		}
	}
}

void solve() {
	int n;
	cin >> n;
	g.resize(n);
	for (int i = 0; i < n - 1; i++) {
		int from, to, w;
		cin >> from >> to >> w;
		from--; to--;
		g[from].eb(to, w);
		g[to].eb(from, w);
	}

	ans.resize(n);
	dfs(0);
	for (int i : ans) cout << i << '\n';
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 9472
#include<bits/stdc++.h>
#define REP(N) for(int i = 0; i < N; i++)
using namespace std;
const int INF = 1e9 + 7;

class State{
  public:
    int step, node, kenkenpa;
    State(int s, int n, int k) { step = s; node = n; kenkenpa = k; }
    bool operator > (const State& s) const { return step > s.step; }
};

int dijkstra(int N, int S, int T, vector< vector<int> >& graph){
  vector< vector<int> > dist(N, vector<int>(4, INF));
  dist[S][0] = 0;
  priority_queue< State, vector<State>, greater<State> > q;
  q.push(State(0, S, 0));

  while(!q.empty()){
    State s = q.top(); q.pop();
    //cout <<"node: " <<s.node <<", step: " <<s.step <<", kenkenpa: " <<s.kenkenpa <<endl;
    if(dist[s.node][s.kenkenpa] < s.step) continue;
    for(int next : graph[s.node]) {
      int next_kenkenpa = s.kenkenpa == 3 ? 1 : s.kenkenpa + 1;
      if(s.step + 1 >= dist[next][next_kenkenpa]) continue;
      dist[next][next_kenkenpa] = s.step + 1;
      q.push(State(s.step + 1, next, next_kenkenpa));
    }
  }
  int ans = min(dist[T][0], dist[T][3]);
  return ans == INF ? -1 : ans / 3;
}

int main(){
  int N, M; cin >>N >>M;
  vector< vector<int> > graph(N, vector<int>());
  REP(M){
    int a, b; cin >>a >>b;
    graph[a - 1].push_back(b - 1);
  }
  int S, T; cin >>S >>T;
  cout <<dijkstra(N, S - 1, T - 1, graph) <<endl;
  return 0;
}


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

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

   if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
       cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

 struct  Node{
  int key;
  struct Node *next, *pre;
};
typedef struct Node *NodePointer; 

NodePointer nil;

void insert( int);
void del( NodePointer t);

int main(){
  int k,n, i ,inpn=0;
  NodePointer j;
  scanf("%d",&n);
  char command[12];
  nil = ( NodePointer )malloc( sizeof( int ) + sizeof ( int *)*2);
  nil->pre =nil;  nil->next =nil;


  for ( i = 0; i < n;i++){
    scanf("%s%d" ,command , &k);
    if ( strcmp(command, "insert") == 0){ insert( k);}
    else if (  strcmp(command, "delete") == 0 ){
      for( j = nil -> next ; j != nil ;j = j-> next){
	if ( j-> key== k){break;}
      }
        del ( j); }
    else if (  strcmp(command, "deleteFirst") == 0){ del ( nil ->next) ;}
    else if (  strcmp(command, "deleteLast") == 0){  del ( nil -> pre) ;}

  }



  NodePointer nf;
  for ( nf = nil ->next ; nf != nil ; nf = nf -> next){
    printf("%d" ,nf ->key );
    if ( nf->next != nil){ printf(" ");}
  }
  
  printf("\n");
  return 0;
}


void insert ( int k){
  NodePointer x;
  x = ( NodePointer)malloc(sizeof( int ) + sizeof ( int *)*2);
  x->key = k;
  x -> next = nil -> next ;
  nil -> next -> pre = x;
  nil -> next =x;
  x -> pre =nil;
  
}


void del( NodePointer tag){
  if ( tag== nil ){return ;}
  tag -> next -> pre = tag -> pre;
  tag ->pre ->next = tag -> next;
  free(tag);
}


Measured memory_bytes: 32968
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF INT_MAX
typedef unsigned int uint;
int in() {
    int x = 0, c;
    for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; }
    do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
    return x;
}

vector< vector<int> > one , two;

void put(vector<int> &s,int x,int v){
	x += s.size()/2-1;
	while(x){
		s[x] = min(v,s[x]);
		x /= 2;
	}
}
int get(vector<int> &s,int l,int r,int k,int a,int b){
	//cout << a << " " << b << " " << s.size() << " " << endl;
	if(l==a && r==b) return s[k];
	if(b < l || r < a) return INF;
	return min(get(s,l,min((a+b)/2,r),k*2,a,(a+b)/2),get(s,max((a+b+1)/2,l),r,k*2+1,(a+b+1)/2,b));
}

int gen(int n){
	int ans = 1;
	while(ans < n) ans *= 2;
	return ans;
}

int main(){
	int H,W,Q;
	while(H = in() , W = in() , Q = in() , H){
		one.resize(H+1);
		two.resize(W+1);
		int hH = gen(H) , wW = gen(W);
		for(int i = 1 ; i <= H ; i++){
			one[i].resize(2*wW+1);
			fill(one[i].begin(),one[i].end(),INF);
		}
		for(int i = 1 ; i <= W ; i++){
			two[i].resize(2*hH+1);
			fill(two[i].begin(),two[i].end(),INF);
		}
		for(int i = 1 ; i <= H ; i++)
			for(int j = 1 ; j <= W ; j++){
				int a; a = in();
				put(one[i],j,a);
				put(two[j],i,a);
			}
		for(int i = 0 ; i < Q ; i++){
			int y1 = in() , x1 = in() , y2 = in() , x2 = in();
			x1++,y1++,x2++,y2++;
			if(x2-x1 >= y2-y1){
				int ans = INT_MAX;
				for(int j = y1 ; j <= y2 ; ++j) ans = min( ans , get(one[j],x1,x2,1,1,wW) );
				printf("%d\n",ans);
			}else{
				int ans = INT_MAX;
				for(int j = x1 ; j <= x2 ; ++j) ans = min( ans , get(two[j],y1,y2,1,1,hH) );
				printf("%d\n",ans);
			}
		}
		
	}
}

Measured memory_bytes: 0
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  rep(i,s.size()){
    s[i]=(s[i]-'A'+n)%26+'A';
  }
  cout<<s<<endl;
    
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
public static boolean isValid(String ans,String s)
{
	
	int []f=new int [26];
	for(int i=0;i<ans.length();i++)
		f[ans.charAt(i)-'a']++;
	for(int x:f)
		if(x>1)
			return false;
	for(char c='z';c>='a';c--)
		if(f[c-'a']==0)
			ans=ans+c;
	
	return ans.compareTo(s)>0;
	
}
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		String s=sc.nextLine();
		String ans="";
		for(int i=0;i<=s.length();i++)
		{	
			if(ans.compareTo(s)>0)
				break;
			for(char c='a';c<='z';c++)
			{
				if(isValid(ans+c,s))
				{
					ans=ans+c;
				
					break;
				}
				//System.out.println(ans);
				if(c=='z')
				{
					System.out.println(-1);
					return;
				}
			}
		}
		System.out.println(ans);
		
		
		
		
		
		pw.close();
		

	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		public Scanner(InputStream s)
		{
			br=new BufferedReader(new InputStreamReader(s));
		}
		public String nextLine() throws IOException
		{
			return br.readLine();
		}
		public String next() throws IOException
		{
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
			
		}
		public double nextDouble() throws IOException
		{
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException
		{
			return br.ready();
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
	}
}


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

int main(){
    string s, t;
    cin >> s >> t;
    int n = (int)s.size();
    int m = (int)t.size();

    string ans = "~";
    for(int i = 0; i <= n-m; i++){
        bool ok = true;
        string s2 = s;
        for(int j = 0; j < m; j++){
            if(s[i+j] != '?' && s[i+j] != t[j]){
                ok = false;
            }
            s2[i+j] = t[j];
        }
        if(ok){
            replace(s2.begin(), s2.end(), '?', 'a');
            ans = min(ans, s2);
        }
    }

    if(ans == "~") cout << "UNRESTORABLE" << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NUM 200001
int main(){
  int i,cnt=0,errno;
  char s[NUM],t[NUM];
  errno=scanf("%s",s);
  errno=scanf("%s",t);
  
  if(errno){
    ;
  }
  
  for(i=0;s[i]!='\0';i++){
    if(s[i]!=t[i]){
      cnt++;
    }
  }
  printf("%d",cnt);
}

Measured memory_bytes: 2120
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int n;
 	cin>>n;
  	double p[n];
  	for(int i=0;i<n;i++){
    	cin>>p[i];
    }
  	double dp[n+1][n+1];
  	for(int i=0;i<=n;i++){
    	for(int j=0;j<=n;j++){
        	if(i==0 && j==0){
            	dp[i][j]=1;
            }
          	else if(i!=0 && j==0){
              	dp[i][j]=0;
            }
            else if(j!=0 && i==0){
                dp[i][j]=(1-p[j-1])*dp[i][j-1];
            }
          	else{
            	dp[i][j]=(1-p[j-1])*dp[i][j-1]+p[j-1]*dp[i-1][j-1];
            }
        }
    }
  	double psum=0;
  	for(int i=n/2+1;i<=n;i++){
      	psum+=dp[i][n];
    }
    cout<<std::fixed;
  	cout<<setprecision(10)<<psum<<endl;
}


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

using namespace std;
 
int main() {
	const int INF = 1e9;
	int K;
	cin >> K;

	vector<int> d(K, INF);
	d[1] = 0;
	deque<int> que;
	que.push_front(1);
	while (!que.empty()) {
		int from = que.front(); 
		que.pop_front();

		int to1 = (from + 1) % K;
		int to10 = (from * 10) % K;

		if (d[to1] > d[from] + 1) {
			d[to1] = d[from] + 1;
			que.push_back(to1);
		}
		if (d[to10] > d[from]) {
			d[to10] = d[from];
			que.push_front(to10);
		}
	}

	int res = d[0] + 1;
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 896