akhauriyash/Code-Regression huggingface dataset:
//go:generate echo "https://atcoder.jp/contests/abc173/tasks/abc173_b"
package main

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

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) Ints(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func (s *scanner) String() string {
	s.Scan()
	return s.Text()
}

func (s *scanner) Strings(l int) []string {
	if l == 0 {
		return []string{}
	}
	sl := make([]string, l, l)
	for i := range sl {
		sl[i] = s.String()
	}
	return sl
}

func solve(S, labels []string) []int {
	c := make([]int, len(labels), len(labels))
	for _, s := range S {
		for i, l := range labels {
			if s == l {
				c[i]++
			}
		}
	}
	return c
}

func run(r io.Reader, w io.Writer) {
	scan := newScanner(r)
	N := scan.Int()
	S := scan.Strings(N)
	labels := []string{"AC", "WA", "TLE", "RE"}
	c := solve(S, labels)
	for i, l := range labels {
		fmt.Printf("%s x %d\n", l, c[i])
	}
}

func main() {
	run(os.Stdin, os.Stdout)
}


Measured memory_bytes: 3692
#include<stdio.h>
#include<string.h>
int main(){
	int count=0, i;
	char s[100], p[1000], end[12]="END_OF_TEXT";
	scanf("%s", s);
	while(1){
		scanf("%s", p);
		if(strcmp(p, end) == 0) {break;}
		for(i=0; p[i] != '\0';i++){
			p[i] = tolower(p[i]);
		}
		if(strcmp(s, p) == 0) {count++;}
	}
	printf("%d\n", count);
}


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

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll A,B,C,X,Y;

int main() {
  cin >> A >> B >> C >> X >> Y;
  
  if (2*C >= A+B) {
    cout << A*X + B*Y << endl;
  } else {
    if (X < Y) {
      if (B <= 2*C)
        cout << B*(Y-X) + C*2*X << endl;
      else 
        cout << C*2*Y << endl;
    } else {
      if (A <= 2*C) 
        cout << A*(X-Y) + C*2*Y << endl;
      else
        cout << C*2*X << endl;
    }
  }
  return 0;
}


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

int main()
{
  string str;
  cin>>str;
  for(int i = 0; i < str.size(); i++)
  {
    if(str[i]=='1')
    {
      str[i] = '9';
    }
    else 
    {
      str[i] = '1';
    }
  }
  cout<<str;
}

Measured memory_bytes: 256
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()

def dfs(s, limit):
    if len(s) == N:
        print(s)
    else:
        for i in range(limit+2):
            x = chr(i + ord('a'))
            dfs(s + x, max(limit, i))

dfs('a', 0)
# 23

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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
#define fileio freopen("template.in", "r", stdin), freopen("template.out", "w", stdout);
typedef long long ll;
const ll MOD = 1e9 + 7;

ll f(int x) {
    int max = sqrt(x);
    ll answer = 0;
    FOR(i, 1, max) {
        FOR(j, i, max) {
            FOR(k, j, max) {
                int number = i*i + j*j + k*k + i*j + j*k + i*k;
                if (number == x) {
                    if (i != j && j != k && i != k) {
                        answer += 6;
                    } else if (i == j && j == k) {
                        answer++;
                    } else if (i == j || j == k || i == k) {
                        answer += 3;
                    }
                }
            }
        }
    }
    return answer;
}
int main() {
    fastio;
    //fileio;
    
    int n;
    cin >> n;
    FOR(i, 1, n+1) {
        cout << f(i) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3564
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nm = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nm[0]);
        int m = Integer.parseInt(nm[1]);
        System.out.println((n - 1) * (m - 1));
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll, ll>
#define ppi pair<int, pii>
#define vpi vector<pii>
#define vpl vector<pll>
#define mt make_tuple
#define eb emplace_back
using namespace std;

const ll N = 3005, mod = 1e9 + 7;
const ll inf = 1e18;

ll n, m, k;
ll a[N][N], dp[N][N][4];
ll rec(ll i, ll j, ll t){
    if(i > n || j > m) return 0;
    if(dp[i][j][t] != -1) return dp[i][j][t];
    ll ans1 = 0, ans = max(rec(i + 1, j, 0), rec(i, j + 1, t));
    if(a[i][j] > 0 && t < 3){
        ans1 = a[i][j] + max(rec(i + 1, j, 0), rec(i, j + 1, t + 1));
    }
    return dp[i][j][t] = max(ans1, ans);
}
void solve(){
    cin >> n >> m >> k;
    for(ll i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            a[i][j] = 0;
            for(int p = 0; p < 4; p++){
                dp[i][j][p] = -1;
            }
        }
    }
    for(ll i = 0; i < k; i++){
        ll x, y, z;
        cin >> x >> y >> z;
        a[x][y] = z;
    }
    cout << rec(1, 1, 0) << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //cout.tie(0);
    /*#ifndef ONLINE_JUDGE
        freopen("Input.txt", "r", stdin);
    #endif*/
    //freopen("running_on_fumes_chapter_1_input (1).txt", "r", stdin);
    //freopen("Output.txt", "w", stdout);
    int t = 1, p;
    //cin >> t;
    for(p = 1; p <= t; p++){
        //cout << "Case #" << p << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 356340
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int p = sc.nextInt();
			int q = sc.nextInt();
			new Main(p, q);
		}
	}

	int p, q;
	int aaaa = 0;
	String shousuu = "";
	ArrayList<Integer> amari = new ArrayList<Integer>();

	Main(int p, int q) {
		this.p = p;
		this.q = q;
		solve();
	}

	private void solve() {
		solve2((p % q) * 10);
	}

	private void solve2(int warareru) {
		aaaa++;
		if (warareru == 0) {
			System.out.println();
		} else if (!amari.contains(warareru)) {
			amari.add(warareru);
			System.out.print(warareru / q);
			solve2((warareru - q * (warareru / q)) * 10);
		} else {
			System.out.println();
			int basho = amari.indexOf(warareru);
			for (int i = 0; i < aaaa - 1; i++) {
				if (i < basho)
					System.out.print(" ");
				else
					System.out.print("^");
			}
			System.out.println();
		}
	}
}

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

int main(){
    int N;
    cin >> N;
    int D[N][2];
    rep(i, N) cin >> D[i][0] >> D[i][1];

    rep(i, N-2){
        if ( (D[i][0] == D[i][1]) && (D[i+1][0] == D[i+1][1]) && (D[i+2][0] == D[i+2][1]) ){
            cout << "Yes" << endl;
            return 0;
        }
    }
     cout << "No" << endl;
    return 0;
}

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

ans = 0
num = 1
for i in range(0, n):
  #print('find: ', i+1)
  if num == a[i]:
    num += 1
    #print(i, a)
  else:
    ans += 1
    
if ans == n:
  print(-1)
  exit()
  
print(ans)


Measured memory_bytes: 26268
#include <bits/stdc++.h>
#define INF 1e+18
using namespace std;

int gcd(int a,int b){
	if(a < b) swap(a,b);
	if(!b) return a;
	return gcd(b,a % b);
}

signed main(){
	int n,a[100010],g;
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	g = a[0];
	for(int i = 1;i < n;i++){
		g = gcd(g,a[i]);
	}
	cout << g << endl;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(void){
  int n;
  int i,j,k,tmp,hoge;
  scanf("%d",&n);

  j=0;
  while(j*(j+1)<2*n){
    j++;
  }
  tmp=j;
  hoge=(tmp*(tmp+1)/2)-n;
  for(k=1;k<tmp;k++){
    if(k!=hoge){
      printf("%d\n",k);
    }
  }
  printf("%d\n",tmp);

  return 0;
}



Measured memory_bytes: 128
import java.util.*;
import java.io.*;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();   
        int m = sc.nextInt();   
        int[] num = new int[n];
        for (int i = 0; i < n; i++) {
            num[i] = 0;
        }
        int ok = 0;
        int no = 0;
        int p;
        String s;
        for (int i = 0; i < m; i++) {
            p = sc.nextInt();
            p--;
            s = sc.next();
            if (num[p] == 0 && s.equals("AC")) {
                ok ++;
                num[p] = 1;
            } else if (num[p] == 0 && s.equals("WA")) {
                num[p]--; 
            } else if (num[p] < 0 && s.equals("AC")) {
                no += -num[p];
                ok ++;
                num[p] = 1;
            } else if (num[p] < 0 && s.equals("WA")) {
                num[p]--;
            }
        }
        System.out.println(ok + " " + no);
    }
}

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

int main(){
	int n=0;
	int w=0;
	int v[1000];
	int m[1000];
	
	cin>>n>>w;
	int DP[n+1][w+1];
	for(int i=0;i<n;i++){
		cin>>v[i]>>m[i];
	}
	for(int j=0;j<=w;j++){
		DP[0][j]=0;
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<=w;j++){
			if(j<m[i-1]){
				DP[i][j]=DP[i-1][j];
			}
			else{
				if(DP[i-1][j]>DP[i-1][j-m[i-1]]+v[i-1]){
					DP[i][j]=DP[i-1][j];
				}
				else{
					DP[i][j]=DP[i-1][j-m[i-1]]+v[i-1];
				}
			}
		}
	}
	cout<<DP[n][w]<<endl;
	
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  string c;
  bool p = false,w = false,g = false,y = false;
  for(int i = 0;i < N;i++){
    cin >> c;
    if(c == "P")p = true;
    else if(c == "W")w = true;
    else if(c == "G")g = true;
    else if(c == "Y")y = true;
  }
  int count = 0;
  if(p)count++;
  if(w)count++;
  if(y)count++;
  if(g)count++;
  
  if(count == 3)cout << "Three" << endl;
  else if(count == 4)cout << "Four" << endl;
}

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

int main(){
  long long int N;
  cin >> N;
  
  long long int ans = 1e18;
  for (long long int i = 1; i*i <= N; i++) {
  if(N%i==0){
      ans = min(ans,N/i +i-2);
  }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
from collections import deque
import itertools

H,W = map(int,input().split())
labyrinth = [[] for i in range(H)]
points = []

for i in range(H):
  w = list(input())
  labyrinth[i] = w
  for j in range(W):
    if w[j] == ".":
      points.append([j,i])

com = list(itertools.combinations(points,2))

#移動パターン
movex = [1,0,-1,0]
movey = [0,1,0,-1]

def shortest_path(sx,sy,labyrinth):
  INF = -(10 ** 6)

  x_length = W
  y_length = H
  distance = [[INF for i in range(x_length)] for j in range(y_length)]
  
  queue = deque()
  queue.append((sx,sy))
  distance[sy][sx] = 0
  
  #幅優先探索
  def bfs():
    #探索候補がある限り
    while len(queue) > 0:
      x,y = queue.popleft()

      #上下左右を探索
      for i in range(0, 4):
        nx = x + movex[i]
        ny = y + movey[i]
        #print(nx,ny)
        #探索迷路内であり
        if (0 <= nx and ny < y_length and 0 <= ny and nx < x_length):
          #通行可能かつ未到達であれば
          if (labyrinth[ny][nx] != "#"  and distance[ny][nx] == INF):
            queue.append((nx,ny))
            distance[ny][nx] = distance[y][x] + 1
    
    dismax = max(list(itertools.chain.from_iterable(distance)))

    return dismax
    
  return bfs()

path = 0

for i in range(len(points)):
  sx = points[i][0]
  sy = points[i][1]
  dist = shortest_path(sx,sy,labyrinth)
  if path < dist:
    path = dist
  
print(path)


Measured memory_bytes: 9220
package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var N, x int
	con.Scan(&N, &x)
	a := make([]int, N)
	m := 0
	for i := range a {
		con.Scan(&a[i])
		if a[i] > x {
			m += a[i] - x
			a[i] = x
		}
	}
	for i := 0; i < N-1; i++ {
		if a[i]+a[i+1] > x {
			y := a[i] + a[i+1] - x
			a[i+1] -= y
			m += y
		}
	}
	con.Println(m)
	return nil
}


Measured memory_bytes: 3072
n = int(input())
ab = []
cd = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append([a, b])
for _ in range(n):
    c, d = map(int, input().split())
    cd.append([c, d])
cd.sort()
ab.sort(reverse=True, key=lambda x:x[1])
tableA = [False for _ in range(n)]
tableB = [False for _ in range(n)]
ans = 0
for b in range(n):
    for r in range(n):
        if tableA[r] is True or tableB[b] is True:
            continue
        if cd[b][0]>ab[r][0] and cd[b][1]>ab[r][1]:
            tableA[r] = True
            tableB[b] = True
            ans += 1
print(ans)

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    int a[10];
    REP(j, 10) cin >> a[j];
    bool ok = false;
    for (int mask = 0; mask < 1 << 10; ++mask) {
      int max1 = 0, max2 = 0;
      bool ok2 = true;
      REP(j, 10) {
        if (mask >> j & 1) {
          if (max1 < a[j])
            max1 = a[j];
          else
            ok2 = false;
        } else {
          if (max2 < a[j])
            max2 = a[j];
          else
            ok2 = false;
        }
      }
      if (ok2) {
        ok = true;
        break;
      }
    }
    cout << (ok ? "YES" : "NO") << endl;
  }
  return 0;
}


Measured memory_bytes: 2992
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


ans = 0
n = inp()
a = inpl()
tmp = a[0]
for i in range(1, n):
    ans += tmp * a[i] % mod
    ans %= mod
    tmp += a[i]
print(ans)


Measured memory_bytes: 94136
a= input()

ans, res = 0,0
#white
for i in range(len(a)):
	if i % 2:
		if a[i] == '1':
			ans += 1
	else:
		if a[i] == '0':
			ans += 1
	
#black
for i in range(len(a)):
	if i % 2:
		if a[i] == '0':
			res += 1
	else:
		if a[i] == '1':
			res += 1

print(min(ans,res))

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

int main(){
    int N;
    int d[101];

    cin >> N;
    for (int i = 0; i < N; i ++){
        cin >> d[i];
    }
    int num[101] = {0};
    for (int i = 0; i < N; i ++){
        num[d[i]]++;
    }

    int res = 0;
    for (int i = 0; i <= 100; i ++){
        if (num[i]){
            res ++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

int n,a[100100][3],p[100100],inv0,inv1,swap0,swap1;
bool flag[100100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

int main()
{
    n=getint();
    repu(i,0,2)
        repu(j,1,n)
            a[j][i]=getint();
    repu(i,1,n)
    {
        int x;
        if (!(a[i][0]%3))
        {
            p[i]=x=a[i][0]/3,(i&1?inv1:inv0)^=1;
            if (a[i][1]!=a[i][0]-1 || a[i][2]!=a[i][0]-2)
            {
                puts("No");
                return 0;
            }
        }
        if (!(a[i][2]%3))
        {
            p[i]=x=a[i][2]/3;
            if (a[i][1]!=a[i][2]-1 || a[i][0]!=a[i][2]-2)
            {
                puts("No");
                return 0;
            }
        }
        if (a[i][0]%3 && a[i][2]%3 || (i&1)!=(x&1))
        {
            puts("No");
            return 0;
        }
    }
    repu(i,1,n)
        if (!flag[i])
            for (int j=p[i]; j!=i; (i&1?swap1:swap0)^=1,flag[j]=1,j=p[j]);
    puts(swap0==inv1 && swap1==inv0?"Yes":"No");
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

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; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  vector<mint> cnt(60, 0);
  rep(i, n) rep(j, 60) if(a[i] >> j & 1) cnt[j] += 1;
  mint ans = 0;
  rep(i, 60) ans += cnt[i] * (mint(n) - cnt[i]) * mint(2).pow(i);
  cout << ans << endl;
}

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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
vector<P> vc(21);
//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    vector<int> v(n),c(n);
    rep(i,n){
        cin >> vc[i].first;
    }
    rep(i,n){
        cin >> vc[i].second;
    }

    int cost=0;
    rep(i,n){
        int cos=vc[i].first-vc[i].second;
        if(cos>0){
            cost+=cos;
        }else{
            continue;
        }
    }
    cout << cost;



}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		while (str != null) {
			String[] numbers1 = str.split(" ",0);
			str = br.readLine();
			String[] numbers2 = str.split(" ",0);
			int blow = 0;
			int hit = 0;
			for (int i = 0; i < 4; i++) {
				for (int j = 0; j < 4; j++) {
					if (numbers1[i].equals(numbers2[j])) {
						if(i==j){
							hit++;
						}else{
							blow++;
						}
					}
				}
			}
			System.out.println(hit + " " + blow);
			str = br.readLine();
		}
	}
}

Measured memory_bytes: 24124
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template
#pragma region bit 1.0
template <typename T>
struct bit
{
    ll n;
    vector<T> a;

    bit(ll n) : n(n)
    {
        a.assign(n + 1, 0);
    }

    void add(ll i, T x)
    {
        ++i;
        while (i <= n)
        {
            a[i] += x;
            i += i & -i;
        }
    }

    T sum(ll i)
    {
        T s = 0;
        while (i > 0)
        {
            s += a[i];
            i -= i & -i;
        }
        return s;
    }
};
#pragma endregion bit

int main()
{
    IN(ll, N);
    IN(string, S);
    IN(ll, Q);
    vector<bit<ll>> b(26, bit<ll>(N));
    REP(i, N)
    {
        b[S[i] - 'a'].add(i, 1);
    }

    REP(q, Q)
    {
        IN(ll, t);
        if (t == 1)
        {
            IN(ll, i);
            IN(char, c);
            --i;
            b[S[i] - 'a'].add(i, -1);
            S[i] = c;
            b[S[i] - 'a'].add(i, 1);
        }
        else
        {
            IN(ll, l);
            IN(ll, r);
            ll ans = 0;
            REP(i, 26)
            {
                ans += b[i].sum(r) - b[i].sum(l - 1) >= 1;
            }
            OUT(ans);
        }
    }
}

Measured memory_bytes: 106500
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        // int c = stdIn.nextInt();
        // String s = stdIn.next();
        // boolean flag = true;
        
        int x[] = new int[n];
        
        int sum = 0;
        
        for(int i = 0; i < n; i++){
            x[i] = stdIn.nextInt();
            sum += x[i];
        }
        
        int ave = sum / n;
        
        int bunsan1 = 0;
        int bunsan2 = 0;
        
        for(int i = 0; i < n; i++){
            bunsan1 += Math.pow(x[i] - ave, 2);
        }
        
        for(int i = 0; i < n; i++){
            bunsan2 += Math.pow(x[i] - ave - 1, 2);
        }
        
        System.out.println(Math.min(bunsan1, bunsan2));
        
        // char c[] = s.toCharArray();
        
        // for(int i = 0; i < s.length(); i++){
        //     c[i];
        // }

        
        // if(flag){
        //     System.out.println("Yes");
        // }else{
        //     System.out.println("No");
        // }
        
        // System.out.println();
        // System.out.print();
    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define ld                 long double
#define ff                 first
#define ss                 second
#define P                 pair<int,int>
#define pb                 push_back
#define mod             1000000007
#define inf             1e18
#define endl            '\n'
const int N = 3005;//change it when needed
int n, X, Y;
int dp[N][N];
int a[N];
int f(int i, int j) {
    if (i > j)
        return 0;
    if (i == j) {
        return a[j];
    }
    if (i + 1 == j)
        return max(a[i], a[j]);
    int &ans = dp[i][j];
    if (ans != -1)return ans;
    int op1 = 0, op2 = 0;
    op1 = a[i] + min(f(i + 2, j), f(i + 1, j - 1));
    op2 = a[j] + min(f(i, j - 2), f(i + 1, j - 1));
    // cout << op1 << " " << op2 << endl;
    return ans = (max(op1, op2));
}
void solve() {
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        Y += a[i];
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = -1;
        }
    }
    X = f(0, n - 1);
    Y = Y - X;
    cout << X - Y << endl;
}

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t; cin >> t; while (t--)
    solve();
    return 0;
}

Measured memory_bytes: 70912
#include<iostream>
int main(void){
  int a, b;  std::cin >> a >> b;
  if(a==b)  std::cout << "Draw" << std::endl;
  else{
    if(a==1 || (a>b && b!=1))  std::cout << "Alice" <<std::endl;
    else if(b==1 || a<b)  std::cout << "Bob" << std::endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int *x = new int[n];
    int *y = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        cin >> y[i];
    }

    bool odd;
    if ((x[0] + y[0]) % 2 == 0) {
        odd = false;
        x[0]++;
    }
    else odd = true;

    if (odd) {
        for (int i = 1; i < n; i++) {
            if ((x[i] + y[i]) % 2 == 0) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    else {
        for (int i = 1; i < n; i++) {
            if ((x[i] + y[i]) % 2 == 1) {
                cout << -1 << endl;
                return 0;
            }
            x[i]++;
        }
    }

    if (odd) cout << 31 << endl;
    else cout << 32 << endl;

    for (int i = 30; i > 0; i--) cout << (1 << i) << " ";
    cout << 1;
    if (!odd) cout << " 1";
    cout << endl;

    for (int i = 0; i < n; i++) {
        int p = x[i];
        int q = y[i];

        for (int j = 30; j >= 0; j--) {
            int t = 1 << j;
            if (abs(p) > abs(q)) {
                if (p > 0) {
                    p -= t;
                    cout << "R";
                }
                else {
                    p += t;
                    cout << "L";
                }
            }
            else {
                if (q > 0) {
                    q -= t;
                    cout << "U";
                }
                else {
                    q += t;
                    cout << "D";
                }
            }
        }
        if (!odd) cout << "L";
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <functional>
#include <cstdint>
#define REP(i, n) for(ll i = 0; i < n; i++)
//using ll = long long;
using namespace std;

int main() {

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

  int n,m;
  cin >> n;
  m = n % 10;

  if (m == 3){
    cout << "bon" << endl;
  } else if (m == 0 || m == 1 || m == 6 ||m == 8 ) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }

}
  

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;

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


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


string s;
cin>>s;

if(s[0]==s[1]&&s[1]==s[2])
{
  cout<<"No\n";
}
else cout<<"Yes\n";


  
}



Measured memory_bytes: 256
#include <stdio.h> 
 
int main (){
    int i, j, v, n, k;
    int A[10000];
 
    scanf("%d", &n);
    for(i = 0; i < n; i++){  
        scanf("%d", &A[i]);
    } 
    for (i=0; i<n-1 ; i++){
      printf("%d ", A[i]);
    }
    printf("%d\n",A[n-1]);
    for (i = 1 ; i < n; i++ ){
        v = A[i];
        j = i-1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
            A[j+1]=v;  
        }  
        for (k=0; k<n-1 ; k++){
          printf("%d ", A[k]);
        }
        printf("%d\n",A[n-1]);
    }
    return 0; 
}

Measured memory_bytes: 1760
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define ret return 0
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int NUM = 2e5 + 5;
vector<ll> g[NUM];
int n,k;
bool vis[NUM];
ll ans = 0;
void dfs(int node, int par){
    int availchoice = k-1;
    if(par!=-1) --availchoice;
    for(auto u:g[node]){
        if(u==par) continue; // already visited
        if(availchoice<=0){
            ans = 0;
            return ;
            // No colors left to paint the node
        }
        ans = (ans*availchoice)%mod;
        --availchoice;
        dfs(u,node);

    }
}
int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        cin>>n>>k;
        memset(vis,0,sizeof(vis));
        
        for(int i=0;i<n-1;i++){
            int x,y; cin>>x>>y;
            g[x].pb(y);
            g[y].pb(x);
        }
        
        ans = k; // choices to paint the root
        dfs(1,-1);
        cout<<ans;
    }   
}


Measured memory_bytes: 12928
#include <stdio.h>
#include <algorithm>

int main(){
  int a,b,c;
  int x,y;
  scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
  int ans;
  int all_c,abc,ab;
  all_c = 2*std::max(x,y)*c;
  if (x>y){
    abc = a*(x-y)+2*c*y;
  }else{
    abc = 2*c*x+b*(y-x);
  }
  ab = a*x+b*y;
  ans = std::min({all_c,abc,ab});
  //printf("%d %d %d\n",all_c,abc,ab);
  printf("%d",ans);
}

Measured memory_bytes: 128
N = int(input())
B = list(map(int, input().split()))

if N == 1:
    print(1)
elif N == 2:
    print(1)
else:
    A = [B[0]]
    cnt = 0
    for i in range(N - 1):
        if B[i] == B[i + 1]:
            pass
        else:
            A.append(B[i+1])

    i = 1
    ans = 1
    n = len(A)
    while i < n - 1:
        if A[i-1] < A[i] < A[i+1] or A[i-1] > A[i] > A[i+1]:
            pass
        else:
            i += 1
            ans += 1
        i += 1
    print(ans)



Measured memory_bytes: 63724
N = list(map(int,input().rstrip().split()))
n = N[0]
k = N[1]

h = list(map(int,input().split()))
h.sort(reverse=True)

m = 0
hit = 0
if k >= n :
  m = 0
else:
  for i in range(k,n):
    hit += h[i]
  
  m = hit
print(m)

Measured memory_bytes: 26180
n, q = map(int, input().split())

ct = [0] * (n+1)
o = [0] * (n+1)
g = [[] for _ in range(n+1)]

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

for i in range(q):
  p,x= map(int, input().split())
  o[p] += x

todo = [1]
seen = [False] * (n+1)
while todo:
  p = todo.pop(-1)
  ct[p] += o[p]
  seen[p] = True
  for i in g[p]:
    if seen[i]:
      ct[p] += ct[i]
    else:
      todo.append(i)

print(*ct[1:])


Measured memory_bytes: 107524
x,y = map(int,input().split())

for a in range(x+1):
  for b in range(x+1):
    c = x - (a + b)
    if (a * 10000 + b * 5000 + 1000 * (x - (a + b)) == y) and 0 <= x - (a + b) <= x:
      print(a,b,c)
      exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
/*
 *  Created on: 31 / 5 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
//#include <bits/Int128.h>
using namespace std;

//#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)
#define test(t)      while(t--)

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

//const ld PI = acos(-1);
//const ll mod = 1e15 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(0)
    Eslam__Waheed
    ll n; cin >> n;
    vector<ll>v(n);
    for (auto& it : v)
    {
        cin >> it;
    }
    sort(all(v));
    ll ans = 1;
    for (auto a : v)
    {
        if (a == 0)
        {
            cout << 0;
            return 0;
        }

        if (a > (ll)1e18 / ans)
        {
            cout << "-1\n";
            return 0;
        }
        ans *= a;
        if (ans > (ll)1e18)
        {
            cout << -1;
            return 0;
        }
    }
    cout << ans;
}
   

Measured memory_bytes: 3988
#include <math.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
int n,x;
cin >> n;
for (int i=1;i<=n;i++)
{
x=i;
if (x%3==0)
{
cout << " " << i;
continue;
}
else if (x%10==3)
{
cout << " " << i;
continue;
}
x/=10;
while (x)
{
 if ( x % 10 == 3 )
{
    cout << " " << i;
break;
}
x/=10;
}
}
cout << endl;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int n,m,x,p[12];
bool f[1<<12],b[12][12];
char a[12][12];
int main(){
	random_device ra;
	mt19937 gen(ra());
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) p[i]=i;
	for(int i=0;i<n;i++) scanf("%s",a[i]);
	int y=CLOCKS_PER_SEC*15;
	for(int ite=1;ite<=100000;ite++){
		shuffle(p,p+n,gen);
		memset(b,1,sizeof(b));
		for(int i=0;i<m;i++) for(int j=i;j<m;j++) for(int k=0;k<n;k++)
			if(a[p[k]][i]!=a[p[n-k-1]][j])
				b[i][j]=0;
		memset(f,0,sizeof(f));
		f[0]=1;
		for(int k=0;k<(1<<m);k++) if(f[k])
			for(int i=0;i<m;i++) for(int j=i+1;j<m;j++)
				if(!(1<<i&k)&&!(1<<j&k)&&b[i][j])
					f[k|(1<<i)|(1<<j)]=1;
		bool chk=0;
		if(!(m&1))
			chk=f[(1<<m)-1];
		else for(int i=0;i<m;i++)
			chk|=f[(1<<m)-1-(1<<i)];
		if(chk) {
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
int city[55]={};

int main() {
  string a,b,c;
  cin >> a >> b >> c;
  if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]) {
    cout << "YES" << endl;
  }else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
array=[]
i = 0
N,L = gets.chomp.split(" ").map(&:to_i)
ret =0
wordsum = " "

    while i < N 
        array[i] = gets.chomp
        i += 1
    end

    for value in array do 
        if value.size != L
            exit!
        end
    end

    array.sort! do |a, b| #辞書順にする処理
        ret = a.casecmp(b)
        ret == 0 ? a <=> b : ret
      end
    
    for value in array do #配列の中身を順番に結合
        wordsum += value
    end
    
    print wordsum






Measured memory_bytes: 2300
# abc085_c

n, y = gets.split.map(&:to_i)

ans = [-1, -1, -1]

0.upto(n) do |a|
  0.upto(n - a) do |b|
    c = n - a - b
    if y == 10000*a + 5000*b + 1000*c
      ans = [a, b, c]
    end
  end
end
puts ans.join(' ')


Measured memory_bytes: 1788
#include<stdio.h>
 
int main(void){
  int N,res;
  
    scanf("%d",&N);
  
  if(N%1000 != 0)
    res = ((N % 1000)-1000)*(-1);
  else
    res = 0;
  printf("%d",res);
  
  return 0;
}

Measured memory_bytes: 1732
import math


def main():
    n, h = map(int, input().split(' '))
    katanas = [list(map(int, input().split(' '))) for _ in range(n)]
    
    count = 0

    a_max = max(map(lambda k: k[0], katanas))
    b_s = list(sorted(map(lambda k: k[1], filter(lambda k: k[1] > a_max, katanas)), reverse=True))
    
    while h > 0:
        if b_s:
            h -= b_s[0]
            del b_s[0]
        else:
            count += math.ceil(h / a_max)
            break
        count += 1
    print(count)


if __name__ == '__main__':
    main()


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

int main() {
  int N, A, B;
  cin >> N;
  cin >> A;
  B = N%500;
  
  if(B <= A){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
//csjosh

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp> //required
// using namespace __gnu_pbds; //required 
using namespace std;

#define ll long long 
#define loop(x) for(int i=0;i<x;i++)

#define llu unsigned long long 
#define pb push_back
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define dd fflush(stdout)
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mt make_tuple //use tie
#define eb emplace_back
typedef tuple<int,int,int> State;//use in dijkstra
ll mod=1e9+7;
// ll power(ll x,ll y,ll mod){
//  ll ans=1;
//  while(y>0){
//   if(y&1){
//     ans=ans*x;
//   }
//   x=x*x;
//   y=y/2;
//  }
//  return ans;
// }

// typedef tree<
// pair<int, int>,
// null_type,
// less<pair<int, int>>,
// rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
 
 int n;
 string s;
int main(){
    IOS;  
     // to do it in n2 not in n3.
    cin>>n>>s;
    ll dp[n+4][n+4];
    
    //dp[i][j] represent what are the number of ways when
    // expression  uses till s[i] and using j numbers(any).(because this is the constraint) 
    memset(dp,0,sizeof dp);
    dp[1][1]=1;
    for(int i=2;i<=n;i++){
      for(int j=1;j<=i;j++){//i can use atmost i number for till now expresson
      //for eg if expression is < then only two can be used.
          if(s[i-2]=='<'){
            dp[i][j]=dp[i-1][j-1]%mod;// i can use only from 1 to j-1
          }
          else if(s[i-2]=='>'){
            dp[i][j]=(dp[i-1][i-1]-dp[i-1][j-1]+mod)%mod; // i can use from j+1 to i(means i-j) elements
            // hence for previous we can be have from j to i-1 (i-j) elements.
          }
           dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;//(add with previous values so that you can make
           //prefix sum for all )
      }
    }
    cout<<dp[n][n]<<endl;
 }



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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int a, b, c;
    cin >> a >> b >> c;
    bool f = false;
    if (a % 2 && b % 2)
        f = true;
    if (b % 2 && c % 2)
        f = true;
    if (c % 2 && a % 2)
        f = true;
    cout << (f ? "Hom" : "Tem") << endl;
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF (1LL << 60)
using namespace std;
typedef long long ll;

ll N, C[2000], W[2000];
ll sum[2000], memo[2000][2000];

struct edge {
  ll v, dist;
};

struct state {
  ll v, cost;

  bool operator>(const state s) const {
    return cost > s.cost;
  }
};

vector<ll> dijkstra(vector< vector<edge> > &E, ll S) {
  vector<ll> dp(E.size(), INF);
  priority_queue<state, vector<state>, greater<state> > q;
  q.push((state) { S, 0 });

  while(!q.empty()) {
    ll v = q.top().v, cost = q.top().cost;
    q.pop();

    if(dp[v] <= cost) continue;
    dp[v] = cost;

    REP(i, 0, E[v].size()) {
      ll nv = E[v][i].v, ncost = cost + E[v][i].dist;
      if(dp[nv] > ncost) q.push((state) { nv, ncost });
    }
  }

  return dp;
}

ll dfs(ll l, ll r) {
  ll &ret = memo[l][r];
  if(ret >= 0) return ret;

  if(r - l <= 1) return ret = 1;

  ret = 0;
  if(dfs(l + 1, r) && (sum[r] - sum[l + 1] <= C[l])) ret = 1;
  if(dfs(l, r - 1) && (sum[r - 1] - sum[l] <= C[r - 1])) ret = 1;
  return ret;
}

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> C[i] >> W[i];

  sum[0] = 0;
  REP(i, 0, N) sum[i + 1] = sum[i] + W[i];

  REP(i, 0, N) REP(j, 0, N + 1) memo[i][j] = -1;

  vector< vector<edge> > E(N + 1);
  REP(i, 0, N) REP(j, i, N + 1) if(dfs(i, j)) E[i].push_back((edge) { j, 1 });
  cout << dijkstra(E, 0)[N] << endl;
}



Measured memory_bytes: 17544
#include <bits/stdc++.h>
#define int long long
#define range(i,x,y) i=(x);i<(y);i++
#define rep(i,n) for(int i=0,i##_len=n;i<i##_len;i++)
#define all(x) begin(x),end(x)
#define lim(x,r,l) (r<=x&&x<l)
typedef long long ll;
typedef long double ld;
using namespace std;

signed main(){
  string s; cin >> s;
  string res(s);
  int n; cin >> n;
  int rn = n;
  rep(i, s.size()){
    if (s[i] != 'a' && s[i] + rn > 'z'){
      res[i] = 'a';
      rn -= 'z' - s[i] + 1;
    }
  }
  res[s.size()-1] = (res[s.size()-1] + rn - 'a') % ('z' - 'a' + 1) + 'a';
  cout << res << endl;
  
}


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

int main()
{
	int N, A, B; cin >> N >> A >> B;
	int answer = 0;
	for (int i = 1; i <= N; ++i) {
		string numstr = to_string(i);
		int sum = 0;
		for (int n = 0; n < numstr.size(); ++n) {
			sum += numstr[n] - '0';
		}
		if (sum >= A && sum <= B) {
			answer += i;
		}
	}
	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 3180
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>
//#include <functional>


int main(){
    int32_t N;
    std::cin >> N;
    int32_t swapA = 0, swapB = 0;
    std::vector<int32_t> P(N);
    bool candidate1 = false, candidate2 = false;
    std::cin >> P[0];
    for(int32_t i = 1; i < N; i++){
        std::cin >> P[i];
        if(P[i-1] > P[i]){
            if(candidate1 && candidate2){
                std::cout << "NO";
                return 0;
            }
            else if(candidate1){
                swapB = i;
                candidate2 = true;
            }
            else{
                swapA = i - 1;
                swapB = i;
                candidate1 = true;
            }
        }
    }
    int32_t tmp = P[swapA];
    P[swapA] = P[swapB];
    P[swapB] = tmp;
    //std::cout << "swaped i,j: " << swapA << "," << swapB;

    tmp = 0;
    for(int32_t i = 0; i < N; i++){
        if(P[i] < tmp){
            std::cout << "NO";
            return 0;
        }
        tmp = P[i];
    }
    std::cout << "YES";

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
vector<int> Graph[100005];
int Time[2][100005];
int Ans = 0;

void dfs_time( int root , int parent ){
    if( Time[0][root] < Time[1][root] ) Ans = max( Ans , Time[1][root] - 1 );
    else return;

    for( int i = 0 ; i < int(Graph[root].size()) ; ++i ){
        if( Graph[root][i] != parent ) dfs_time( Graph[root][i] , root );
    }
}

void dfs( int root , int parent , int which ){
    Time[which][root] = Time[which][parent] + 1;
    
    for( int i = 0 ; i < int(Graph[root].size()) ; ++i ){
        if( Graph[root][i] != parent ) dfs( Graph[root][i] , root , which );
    }
}

int main(){
    int N , i , u , v , a , b; 
    scanf( "%d%d%d" , &N , &u , &v );

    for( i = 1 ; i < N ; ++i ){
        scanf( "%d%d" , &a , &b );
        Graph[a].emplace_back( b );
        Graph[b].emplace_back( a );
    }

    Time[0][0] = Time[1][0] = -1;
    dfs( u , 0 , 0 );
    dfs( v , 0 , 1 );
    dfs_time( u , 0 );
    printf( "%d\n" , Ans );
    return 0;
}

Measured memory_bytes: 12928
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
int n,m;
const int maxn=1e5+7;
//int a[maxn];
int main()
{
	cin>>n>>m;
	priority_queue<int,vector<int>,less<int> >q;
	ll t,ans=0;
	for(int i=0;i<n;i++){
		cin>>t;
		q.push(t);
	}
	for(int i=1;i<=m;i++){
		int a=q.top();
		q.pop();
		double b=(double)a/2.0;
		if(b>(a/2+0.5)) a=a/2+1;
		else a=a/2;
		q.push(a);
	}
	while(!q.empty()){
		ans+=q.top();
		q.pop();
	}
	cout<<ans<<endl;
	return 0;
}

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

Measured memory_bytes: 600
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;
constexpr double PI = 3.141592653589793;
constexpr ll INF = 1e18 + 10;
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;
}

using namespace std;
//    cout << setprecision(20) << ans << "\n";

vector<pair<ll, ll>> primeFactorize(ll N)
{
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; ++a)
    {
        if (N % a != 0)
            continue;
        ll ex = 0;

        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }

    if (N != 1)
        res.push_back({N, 1});
    return res;
}

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

    ll a, b, c;
    cin >> a >> b >> c;

    if (a == b && b == c)
    {
        if (a % 2 != 0)
        {
            cout << 0 << "\n";
            return 0;
        }
        cout << -1 << "\n";
        return 0;
    }

    ll count = 0;
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0)
    {
        ll tempa = b / 2 + c / 2;
        ll tempb = c / 2 + a / 2;
        ll tempc = a / 2 + b / 2;
        a = tempa;
        b = tempb;
        c = tempc;
        count++;
    }

    cout << count << "\n";

    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
namespace whatever{
	int readu(){
		char ch=getchar();
		while(!isdigit(ch))
			ch=getchar();
		int value=ch-'0';
		ch=getchar();
		while(isdigit(ch)){
			value=value*10+ch-'0';
			ch=getchar();
		}
		return value;
	}
	void writeu(int n){
		if(n<10)
			putchar(n+'0');
		else{
			writeu(n/10);
			putchar(n%10+'0');
		}
	}
	int gcd(int a, int b){
		return b==0?a:gcd(b, a%b);
	}
	void run(){
		int n=readu();
		int x=readu();
		int result=0;
		while(--n!=-1){
			int cur=readu();
			result=gcd(result, abs(x-cur));
		}
		writeu(result);
		putchar('\n');
	}
}
int main(){
	whatever::run();
}

Measured memory_bytes: 256