akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    int n; cin >> n;
    int cnt[5] = {};
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        if(s[0] == 'M') cnt[0]++;
        if(s[0] == 'A') cnt[1]++;
        if(s[0] == 'R') cnt[2]++;
        if(s[0] == 'C') cnt[3]++;
        if(s[0] == 'H') cnt[4]++;        
    }


    int ans = 0;
    for(int i = 0; i < 5; i++){
        for(int j = i + 1; j < 5; j++){
            for(int k = j + 1; k < 5; k++){
                ans += cnt[i] * cnt[j] * cnt[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int arr[10009];

int main ()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr, arr + n);
    int ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            for (int k = j + 1; k < n && arr[k] < (arr[i] + arr[j]); k++)
                            ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(){
char moji[1001];
char word[10];
int i,a=0;

scanf("%s",&word);

for(i=0;i<10;i++){
    word[i]=tolower(word[i]);
}



while(1){
scanf("%s",&moji);
if(strcmp(moji,"END_OF_TEXT")==0){break;}

for(i=0;i<1001;i++){
    moji[i]=tolower(moji[i]);
}
if(strcmp(word,moji)==0)a++;

}

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

return 0;


}

Measured memory_bytes: 552
#include <iostream>
#include <vector>
#define eol '\n'
using namespace std;

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

  int a,b,c;
  cin >> a >> b >> c;
  int mx = max(max(a,b),c);
  cout << a+b+c-mx << eol;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll qpow(ll a, ll b) { ll t = 1; while (b != 0) { if (b & 1)t = (t * a) % mod; a = (a * a) % mod; b >>= 1; }return t; }
int main() {
	ll n;
	cin >> n;
	ll a = qpow(10, n);
	ll b = qpow(9, n);
	ll c = qpow(8, n);
	ll t = a - 2 * b + c;
	t %= mod;
	while (t < 0)t += mod;
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100005;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    vector<int> a(n+1,0);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)a[i]+=a[i-1];
    vector<int> v;
    for(int i=0;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            v.push_back(a[j]-a[i]);
        }
    }
    //1e6個の数列が与えられるのでこの中からk個選んでsubsetをつくりそのANDを最大化する
    //上から貪欲にそのbitを立てられるか調べる
    int res=0;
    for(int b=60;b>=0;b--){
        vector<int> vv;
        int now=(1ll<<b);
        for(auto it:v)if(it&now)vv.push_back(it);
        int sz=vv.size();
        if(sz>=k){
            //cout<<b<<endl;
            res+=now;
            v=vv;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const int inf = ~0u >> 1;
int a[maxn], b[maxn], c[maxn];
int h[maxn][5];
int d[maxn][5];
int main() {
    IO;
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> h[i][1] >> h[i][2] >> h[i][3];
    }
    d[1][1] = h[1][1];
    d[1][2] = h[1][2];
    d[1][3] = h[1][3];
    for (int i = 2; i <= n; ++i) {
        for (int j = 1; j <= 3; ++j) {
            for (int k = 1; k <= 3; ++k)
                if (j != k) d[i][j] = max(d[i - 1][k] + h[i][j], d[i][j]);
        }
    }
    cout << max(d[n][1], max(d[n][2], d[n][3])) << endl;;
    return 0;
}

Measured memory_bytes: 7568
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))

n = int(input())
b = list(int(input()) for i in range(n))

if a1[0] in b and a2[0] in b and a3[0] in b:
    print('Yes')
elif a1[1] in b and a2[1] in b and a3[1] in b:
    print('Yes')
elif a1[2] in b and a2[2] in b and a3[2] in b:
    print('Yes')
elif a1[0] in b and a2[1] in b and a3[2] in b:
    print('Yes')
elif a1[2] in b and a2[1] in b and a3[0] in b:
    print('Yes')
elif a1[0] in b and a1[1] in b and a1[2] in b:
    print('Yes')
elif a2[0] in b and a2[1] in b and a2[2] in b:
    print('Yes')
elif a3[0] in b and a3[1] in b and a3[2] in b:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
package main

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

func solve() {
	n := getInt()
	as := getIntSlice(n)

	next := 1
	for _, a := range as {
		if a == next {
			next++
		}
	}

	ans := n - next + 1
	if next == 1 {
		ans = -1
	}

	fmt.Fprintln(wr, ans)
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


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

a = [i for i in range(1,N + 1)]

ans = 0

for i in range(N):
  if a[i]%15 == 0:
    a[i] = "FizzBuzz"
  elif a[i]%3 == 0:
    a[i] = "Fizz"
  elif a[i]%5 == 0:
    a[i] = "Buzz"
    
for i in a:
  if type(i) == int:
    ans += i
    
print(ans)

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

int C_exist(string S){
    int num = 0;
    for(int i = 2; i<S.size()-1; i++){
      if(S[i] == 'C'){
		num++;
      }
    }
    
    return num;
  }

int num_lower(string S){
  int lower = 0;
  for(int j = 0; j <S.size(); j++){
    if(islower(S[j]) != 0){
      lower++;  
    }
  }
  return lower;
}
    
int main(){
  string S;
  cin >> S;
  
  if(S[0] == 'A' && C_exist(S) == 1 && num_lower(S) == S.size() -2){
    cout <<"AC"<< endl;
  }
  else{
    cout <<"WA"<< endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 100000000;

int main() {
  int N; cin >> N;
  vector<int> d(10e5, 0);
  rep(i, N) {
    int a;
    cin >> a;
    d[a]++;
  }
  int ans = 0;
  rep2(i, 1, 10e5+1) {
    ans = max(ans, d[i-1] + d[i] + d[i+1]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4096
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
 
using namespace std;
 
long long int k;
int a,b,c;


int main(){
    scanf("%d %d %d %lld",&a,&b,&c,&k);
    if(k%2)printf("%d\n",b-a);
    else printf("%d\n",a-b);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int x,a,b;
    cin>>x>>a>>b;
    x -= a;
    
    cout<<x%b<<endl;
}


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

using namespace std;

long long int n;

int main(){
	cin>>n;
	for(int i=sqrt(n);i>=1;i--)
	{
		if(n%i==0){
			int t=i,l=n/i;
			int s=1;
			while(l>=10){
				s++;
				l/=10;
			}
		cout<<s;
		return 0;
		}
	}
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

using namespace std;
 
typedef long long int ll;

const ll INF=(ll)1e18;

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

    string s1, s2;

    cin >> s1 >> s2;

    int i = 0;

    ll ans = 0;
    int flag;
    if(s1[i] == s2[i]){
        ans = 3;
        i += 1;
        flag = 1;
    }else{
        ans = 6;
        i += 2;
        flag = 2;
    }

    while(i < N){
        if(s1[i] == s2[i]){
            if(flag == 1){
                ans *= 2;
                ans %= MOD;
            }
            i += 1;
            flag = 1;
        }else{
            if(flag == 1){
                ans *= 2;
                ans %= MOD;
            }else{
                ans *= 3;
                ans %= MOD;
            }
            i += 2;
            flag = 2;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int s = accumulate(a.begin(), a.end(), 0), ans = 0;
    for (auto i : a)
        ans += i * (s - i);
    cout << ans / 2;
}


Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

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()
	}
}

func readInt() int {
	return int(readInt64())
}

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

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	n := readInt()
	var c2, c4, cx int
	for i := 0; i < n; i++ {
		a := readInt()
		if a%4 == 0 {
			c4++
		} else if a%2 == 0 {
			c2++
		} else {
			cx++
		}
	}
	if c2 == 0 {
		if c4+1 >= cx {
			println("Yes")
		} else {
			println("No")
		}
	} else if c2 == 1 {
		cx++
		if c4+1 >= cx {
			println("Yes")
		} else {
			println("No")
		}
	} else {
		if c4 >= cx {
			println("Yes")
		} else {
			println("No")
		}
	}
}


Measured memory_bytes: 2176
# -*- coding: utf-8 -*-

import itertools

antennas = []
for _ in range(5):
    antennas.append(int(input()))

combiAntennas = list(itertools.combinations(antennas, 2))

k = int(input())

cnt = 0
for i in combiAntennas:
    if max(i) - min(i) > k:
        cnt += 1
        
if cnt:
    print(':(')
else:
    print('Yay!')
    

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

import sys
import numpy as np
from collections import defaultdict
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = readline().decode().rstrip()
dicts = defaultdict(int)

for c in S:
  dicts[c] += 1

for pair in [('N', 'S'), ('W', 'E')]:
  if min(dicts[pair[0]], dicts[pair[1]]) == 0:
    if max(dicts[pair[0]], dicts[pair[1]]) != 0:
      print('No')
      sys.exit()
print('Yes')



Measured memory_bytes: 12500
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def gcd(p, q):
    if p % q == 0:
        return q
    else:
        return gcd(q, p % q)

n, x = map(int, readline().split())
lst = [abs(int(i) - x) for i in readline().split()]
if n == 1:
    print(lst[0])
    quit()
p = lst[0]
for i in range(1, n):
    p = gcd(p, lst[i])
print(p)


Measured memory_bytes: 14168
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n,i,p[110][2],h[110],cx,cy,t,ch,u;
  cin >> n;
  for (i=0;i<n;i++) cin >> p[i][0] >> p[i][1] >> h[i];
  t=0;
  while (h[t]==0) t++;
  for (cx=0;cx<=100;cx++){
    for (cy=0;cy<=100;cy++){
      ch=abs(cx-p[t][0])+abs(cy-p[t][1])+h[t];
      for (i=0;i<n;i++){
        u = max(ch-abs(cx-p[i][0])-abs(cy-p[i][1]) , 0);
        if (u!=h[i]) break;
      }
      if (i==n) break;
    }
    if (cy!=101) break;
  }
  printf("%d %d %d\n",cx,cy,ch);
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var in = newIo(bufio.NewScanner(os.Stdin))

func main() {
	in.setSplit(bufio.ScanLines)
	var s = in.next()
	var t = in.next()
	print(solve(s, t) && solve(t, s))
}

func print(result bool) {
	var r = "No"
	if result {
		r = "Yes"
	}
	fmt.Println(r)
}

func solve(s string, t string) bool {
	r := map[string]string{}
	for i, c := range s {
		v, ok := r[string(c)]
		if ok {
			if v != string(t[i]) {
				return false
			}
		} else {
			r[string(c)] = string(t[i])
		}
	}
	return true
}

type io struct {
	sc *bufio.Scanner
}

func newIo(sc *bufio.Scanner) *io {
	i := new(io)
	i.sc = sc
	i.sc.Buffer([]byte{}, math.MaxInt64)
	i.sc.Split(bufio.ScanWords)
	return i
}

func (i *io) setSplit(f bufio.SplitFunc) {
	i.sc.Split(f)
}

func (i *io) nextIntSlice(y int, delim string) [][]int {
	result := make([][]int, y)
	for j := 0; j < y; j++ {
		line := i.next()
		result[j] = perseIntSlice(strings.Split(line, delim))
	}
	return result
}

func (i *io) next() string {
	i.sc.Scan()
	return i.sc.Text()
}

func (i *io) nextInt() int {
	return perseInt(i.next())
}

func (i *io) nextLong() int64 {
	return perseLong(i.next())
}

func perseInt(s string) int {
	in, _ := strconv.Atoi(s)
	return in
}

func perseLong(s string) int64 {
	in, _ := strconv.ParseInt(s, 10, 64)
	return in
}

func perseIntSlice(s []string) []int {
	var r = make([]int, len(s))
	for i := 0; i < len(s); i++ {
		r[i] = perseInt(s[i])
	}
	return r
}


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

struct Node {
  int key;
  Node *right,*left,*parent;
};

Node *root,*NIL;

void insert(int k) {
  Node *y=NIL;
  Node *x=root;
  Node *z;
  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while (x!=NIL) {
    y=x;
    if (z->key<x->key) {
      x=x->left;
    }
    else {
      x=x->right;
    }
  }
  z->parent=y;
  if (y==NIL) {
    root=z;
  }
  else {
    if (z->key<y->key) 
      y->left=z;
    
    else 
      y->right=z;
    
  }
}
void inorder(Node *u) {
  if (u==NIL) 
    return ;
  
  inorder(u->left);
  cout<<" "<<u->key<<flush;
  inorder(u->right);
}
void preorder(Node *u) {
  if (u==NIL) {
    return ;
  }
  cout<<" "<<u->key<<flush;
  preorder(u->left);
  preorder(u->right);
}
int main() {
  int n;
  cin>>n;
  for (int i=0; i<n; i++) {
    string com;
    cin>>com;
    if (com=="insert") {
      int x;
      cin>>x;
      insert(x);
    }
    else {
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 26500
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int ans = 0;
        int[][] ary = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ary[i][j] = Integer.parseInt(sc.next());
            }
        }
        for (int i = 0; i < n; i++) {
            ans += permutation(ary, n, i, i+1, d, 0);
        }
        System.out.println(ans);

    }

    private static int permutation(int[][] ary, int N, int n, int o, int d, int cnt){
        if(N == o){
          return cnt;
        }
        int sum = 0;
        for (int i = 0; i < d; i++) {
            int a = ary[n][i];
            int b = ary[o][i];
            sum += Math.abs(Math.pow((a-b),2));
        }
        int sqrt = (int) Math.sqrt(sum);
        if (sqrt * sqrt == sum) {
            cnt++;
        }
        o++;
        return permutation(ary, N, n, o, d, cnt);
      }
}

Measured memory_bytes: 21332
H, W = map(int, input().split())
A = []
for i in range(H):
  As = input()
  if As.find("#") < 0:
    H -= 1
  else:
    A.append(As)
j = 0
while j < W:
  b = True
  for As in A:
    if As[j] == "#":
      b = False
  if b:
    W -= 1
    for i in range(len(A)):
      A[i] = A[i][:j]+A[i][j+1:]
  else:
    j += 1
for i in range(H):
  As = A[i]
  print(As)


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

int main(){
	string s;
	char t[11];
	scanf("%s", t);
	s = t;
	for(int i=0; i<s.size(); ++i){
		if(s[i] == 'B'){
			for(int j=1; i-j>=0; ++j){
				if(s[i-j] != 'B'){
					s[i-j] = 'B';
					break;
				}
			}
		}
	}
	for(int i=0; i<s.size(); ++i){
		if(s[i] != 'B') printf("%c", s[i]);
	}
	printf("\n");
}

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

using namespace std;
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


/*void solve(string s){
    for(int i =0; i<s.size() ;i++){
        if(s[i]=='g' && s[i+1] =='o' && s[i+2] == 'o' && s[i] == 'g'){
                ans++;
                ans%=m;
               i+=2;

        }
        if(i==s.size()-1)break;
    }
    cout << ans << endl;
    }*/
int h[100005];
signed main(){
    IOS;
    int n,cur=0,flag=0;
    cin >> n;
    for(int i = 1;i<=n;i++){
        cin >> h[i];
    }
    for(int i = n;i>=1;i--){
        if(h[i-1]>h[i]+1){flag = 1;break;}
        if(h[i-1]==h[i]+1)h[i-1]-=1;
    }
    if(flag)cout<< "No" << endl;
    else cout << "Yes"<<endl;
return 0;}
///...


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int maxn = 1000100;
const int base = 1e9+7;

int n;
ll x[maxn],p[maxn],S,res=0;

int main() {
   // freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>S;
    for (int i=1;i<=n;i++) cin>>x[i]>>p[i];
    int s=1,t=n;
    while (s<=t) {
        if (S <= x[s]) {
            res += x[t] - S;
            break;
        }
        if (S >= x[t]) {
            res += S - x[s];
            break;
        }
        res += x[t] - x[s];
        if (p[s] >= p[t]) {
            while (s<t && p[s]>=p[t]) {
                p[s]+=p[t];
                t--;
            }
        } else {
            while (s<t && p[t]>p[s]) {
                p[t]+=p[s];
                s++;
            }
        }
    }
    cout<<res<<endl;
}



Measured memory_bytes: 5120
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

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




using namespace std;
int main() {

	int n;
	cin >> n;
	set<char>f;
	for (int i = 0; i < n; i++){
		char t;
		cin >> t;
		if (t == 'P' || t == 'W' || t == 'Y' || t == 'G')f.insert(t);

	}
	if (f.size() == 3)cout << "Three" << endl;
	else cout << "Four" << endl;

	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  string a, b;
  cin >> a >> b;

  if (a.size() > b.size()) {
    cout << "GREATER" << endl;
  } else if (a.size() < b.size()) {
    cout << "LESS" << endl;
  } else {
    for (int i = 0; i < a.size(); ++i) {
      if (a.at(i) > b.at(i)) {
        cout << "GREATER" << endl;
        return 0;
      } else if (a.at(i) < b.at(i)) {
        cout << "LESS" << endl;
	return 0;
      } else {
        continue;
      }
    }

    cout << "EQUAL" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

#define int int64_t

#define REP(i,f,n) for(int i=(f); i < (n); ++i)
#define PER(i,f,n) for(int i=(n-1); i >= f; --i)

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

template<typename STL> inline void print_STL(STL c, string ab = ""){
	cout << ab << '\n';
	for(auto t : c) cout << t << ' '; cout << '\n';}

template<typename VEC> inline void import_VEC(VEC& c, int n){
	typename VEC::value_type tmp;
	for(int i = 0; i < n; ++i){	cin >> tmp; c.push_back(tmp);} }

#define SPRE(x) setprecision(x) // 精度を指定

template<class T>	using Matrix = vector<vector<T>>;

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

	string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s << endl;
}



Measured memory_bytes: 384
n,x=map(int,input().split())

X=list(map(int,input().split()))

dif=[]
for i in range(n):
    dif.append(abs(X[i]-x))

def gcd(a,b):
    a,b=max(a,b),min(a,b)
    if b>0:
        return gcd(b,a%b)
    else:
        return a

ans=dif[0]
for i in range(1,n):
    ans=gcd(ans,dif[i])

    
    
print(ans)

Measured memory_bytes: 14252
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353

int main() {
    int N,S;
    cin>>N>>S;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    vector<vector<long long int>> dp(N,vector<long long int>(S+1));
    dp[0][0]=1;
    if(A[0]<S+1)dp[0][A[0]]=1;
    for (int i = 1; i < N; i++){
        dp[i][0]=1;
        for (int j = 1; j < S+1; j++){
            if(j-A[i]>0)dp[i][j]=(dp[i-1][j]+dp[i-1][j-A[i]])%MOD;
            else if(j-A[i]==0)dp[i][j]=(dp[i-1][j]+i+1)%MOD;
            else dp[i][j]=dp[i-1][j];
        }
    }
    int ans=0;
    for (int i = 0; i < N; i++){
        ans+=dp[i][S];
        ans%=MOD;
    }
    cout <<ans<<endl;
}

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

int A[100010];
int B[100010];
vector<int>Achild[100010];
vector<int>Bchild[100010];
vector<int>nodes[100010];
int X[100010];

int pairA(int x){
    stack<int>s;
    for(int y:Achild[x]){
        s.push(pairA(y));
    }
    if(Achild[x].size()%2==0){
        s.push(x);
    }
    int a,b;
    while(s.size()>=2){
        a=s.top();
        s.pop();
        b=s.top();
        s.pop();
        nodes[a].push_back(b);
        nodes[b].push_back(a);
        //printf("pair %d %d\n",a,b);
    }
    return s.top();
}
int pairB(int x){
    stack<int>s;
    for(int y:Bchild[x]){
        s.push(pairB(y));
    }
    if(Bchild[x].size()%2==0){
        s.push(x);
    }
    int a,b;
    while(s.size()>=2){
        a=s.top();
        s.pop();
        b=s.top();
        s.pop();
        nodes[a].push_back(b);
        nodes[b].push_back(a);
        //printf("pair %d %d\n",a,b);
    }
    return s.top();
}

void colour(int x){
    for(int y:nodes[x]){
        if(X[y]!=-2)continue;
        X[y]=-X[x];
        colour(y);
    }
}

int main(){
    //freopen("hi.txt","r",stdin);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)X[i]=-2;
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        if(A[i]!=-1){
            Achild[A[i]].push_back(i);
        }
    }
    for(int i=1;i<=n;i++){
        scanf("%d",&B[i]);
        if(B[i]!=-1){
            Bchild[B[i]].push_back(i);
        }
    }
    for(int i=1;i<=n;i++){
        if(Achild[i].size()%2!=Bchild[i].size()%2){
            printf("IMPOSSIBLE");
            return 0;
        }
        if(Achild[i].size()%2==1){
            X[i]=0;
        }
    }
    for(int i=1;i<=n;i++){
        if(A[i]==-1){
            pairA(i);
            break;
        }
    }
    for(int i=1;i<=n;i++){
        if(B[i]==-1){
            pairB(i);
            break;
        }
    }
    for(int i=1;i<=n;i++){
        if(X[i]==-2){
            X[i]=1;
            colour(i);
        }
    }
    printf("POSSIBLE\n");
    for(int i=1;i<=n;i++){
        printf("%d ",X[i]);
    }
}


Measured memory_bytes: 44160
#include <stdio.h>

int main(void)
{
    int a = 0, b = 0, i, tmp;

    for (i = 0; i < 4; i++) {
        scanf("%d",&tmp);
        a += tmp;
    }

    for (i = 0; i < 4; i++) {
        scanf("%d",&tmp);
        b += tmp;
    }
    if (a < b) {
    printf("%d\n",b);
    } else {
    printf("%d\n",a);
    }

    return 0;
}

Measured memory_bytes: 592
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

//最短路数計算つきDijkstra

struct edge
{
  int to, cost;
  edge(int t,int c){
		to=t;
		cost=c;
	}
	edge(){}
};

LL add(LL a,LL b){
  return (a+b)%mod;
}

typedef vector< vector < edge > > Graph;//隣接リスト

int min_path[100010]={};//sからの最短経路数
template< typename T = LL >
vector< T > Dijkstra(Graph &g, int s)//始点sから各点までの最短距離を保持したvectorを返す&
                                     //min_pathに始点sから各点までの最短経路数
{
  typedef pair< T, int > Pi;//cost,from
  vector< T > min_cost(g.size(), numeric_limits< T >::max());
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;//Pi:cost,from
  que.emplace(0, s);
  min_cost[s] = 0;
  min_path[s]=1;
  while(!que.empty()) {
    Pi p = que.top();
    que.pop();
    if(p.first > min_cost[p.second]) continue;
    for(auto &e : g[p.second]) {
      if(p.first + e.cost > min_cost[e.to]) continue;
			if(p.first + e.cost == min_cost[e.to]){
        min_path[e.to]=add(min_path[p.second],min_path[e.to]);//最短距離が同じだったら経路数は和
				//min_path[e.to]=min_path[p.second]+min_path[e.to];//modなし
			}else {
				min_path[e.to]=min_path[p.second];//最短距離更新->最短経路更新
        min_cost[e.to] = p.first + e.cost;
        que.emplace(min_cost[e.to], e.to);
			}
    }
  }
  return (min_cost);
}

int main(){
	int n,q,k;
	cin>>n;
	Graph g=vector< vector < edge > >(n+1,vector < edge >(0));
	FOR(i,0,n-1){
		int a,b,c;
		cin>>a>>b>>c;
		g[a].PB(edge(b,c));
		g[b].PB(edge(a,c));
	}
	cin>>q>>k;
	vector<int> x(q);
	vector<int> y(q);
	//cerr<<"test"<<endl;
	vector<LL> dist=Dijkstra(g,k);
	FOR(i,0,q){
		cin>>x[i]>>y[i];
		cout<<dist[x[i]]+dist[y[i]]<<endl;
	}

    return 0;
}


Measured memory_bytes: 10484
n = int(input())
A = list(map(int, input().split( )))
cnt = 1

for a in A:
  if cnt == 0:continue
  if a%2 == 0:
    if a%3 !=0 and a%5 !=0:
      cnt = 0
if cnt != 0:
  print('APPROVED')
else:
  print('DENIED')

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

public class Main {
    
    static final long INF = Long.MAX_VALUE / 10;

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int v = Integer.parseInt(sc.next());
        int e = Integer.parseInt(sc.next());
        
        long[][] d = new long[v][v];
        for(int i = 0; i < v; i++){
            Arrays.fill(d[i], INF);
            d[i][i] = 0;
        }
        for(int i = 0; i < e; i++){
            d[Integer.parseInt(sc.next())][Integer.parseInt(sc.next())] = Integer.parseInt(sc.next());
        }
        
        for(int k = 0; k < v; k++){
            for(int i = 0; i < v; i++){
                if(d[i][k] == INF) continue;
                for(int j = 0; j < v; j++){
                    if(d[k][j] == INF) continue;
                    d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        
        boolean negative = false;
        for(int i = 0; i < v; i++){
            if(d[i][i] < 0){
                negative = true;
                break;
            }
        }
        if(negative){
            System.out.println("NEGATIVE CYCLE");
        }else{
            StringBuilder sb = new StringBuilder();
            for(int i = 0; i < v; i++){
                for(int j = 0; j < v; j++){
                    if(d[i][j] == INF){
                        sb.append("INF ");
                    }else{
                        sb.append(d[i][j]).append(" ");
                    }
                }
                sb.deleteCharAt(sb.length()-1);
                sb.append(System.lineSeparator());
            }
            System.out.print(sb);
        }
    }
}


Measured memory_bytes: 48608
n=int(input())
a,b=map(int,input().split())
p=list(map(int,input().split()))
c=[0,0,0]
for i in range(n):
    if p[i]<=a:
        c[0]+=1
    elif p[i]>b:
        c[2]+=1
    else:
        c[1]+=1
print(min(c))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
string s;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> s;
}

int solve(){
    string ans="No";
    for (size_t i = 0; i < s.length(); i++)
    {
        if(s[i]=='7') ans="Yes";
    }
    cout << ans << endl;
     
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 3644
import pprint
H,W,D=map(int,input().split())
table=[list(map(int,input().split())) for _ in range(H)]
Q=int(input())
query=[list(map(int,input().split())) for _ in range(Q)]
num=[]
distfrom1D=[]
for i in range(H):
    for j in range(W):
        num.append([table[i][j],i,j])
num.sort(key=lambda x:x[0])
#print(num)
#for i in range()
cnt=0
for i in range(D):
    buf=[0]
    for j in range(i,H*W-D,D):
        #print(i+j,i+j+D)
        buf.append(buf[len(buf)-1]+abs(num[j][1]-num[j+D][1])+abs(num[j][2]-num[j+D][2]))
    #print(buf)
    distfrom1D.append(buf)
#[1,1+D,]
#[2,2+D,]
#...
#[D,D+D,]
#pprint.pprint(distfrom1D)
for i in range(Q):
    l=query[i][0]
    r=query[i][1]
    row=((l%D)-1)%D
    col1 = (l // D)
    col2 = (r // D)
    if l%D==0:
        col1=col1-1
        col2=col2-1
    print(distfrom1D[row][col2]-distfrom1D[row][col1])






Measured memory_bytes: 92892
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	sum := 0
	for i := 0; i < N; i++ {
		l, r := nextInt(), nextInt()
		sum += r - l + 1
	}
	fmt.Println(sum)
}


Measured memory_bytes: 640
def main():
    N = int(input())
    A = [int(input()) for a in range(N) ]
    C = sorted(A)
    Af = C[-1]
    As = C[-2]
    for i in range(N):
        if A[i] != Af:
            print(Af)
        else:
            print(As)
if __name__ == "__main__":
    main()

Measured memory_bytes: 14160
N, M = map(int, input().split())
r = [i for i in range(N+1)]
n = [0 for i in range(N+1)]
buf = []

def root(x):
  if x==r[x]:
    return x
  else:
    r[x] = root(r[x])
    return r[x]

def unite(x, y):
  rx = root(x)
  ry = root(y)
  if rx < ry:
    r[ry] = rx
  elif rx > ry:
    r[rx] = ry
    

for _ in range(M):
  a, b = map(int, input().split())
  unite(a, b)

for x in range(1, N+1):
  if r[x] != x and r[r[x]] != r[x]:
    _ = root(x)
  
  
for x in r[1:]:
  n[x] += 1
    
ans = max(n[1:])

print(ans)

Measured memory_bytes: 19876
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a;
	long long sum=0,ans=0;
	map<long long,int>mp={{0,1}};
	cin>>n;
	while(cin>>a)
		sum+=a,mp[sum]++;
	for(auto x:mp)
		ans+=x.second*(x.second-1ll)/2;
	cout<<ans<<endl;
}


Measured memory_bytes: 12800
MOD = 10**9+7

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

N,M,L,R = map(int,input().split())

P = [0 for i in range(R+1)]
for k in range(R+1):
  u = (R-M*(k+1))//(k+1)
  for j in range(u+1):
    P[(k+1)*j+M*(k+1)] += nCr(N-M,j)*(-1)**(j%2)
    P[(k+1)*j+M*(k+1)] %= MOD
for k in range(1,R+1):
  u = (R-M*(k+1))//k
  for j in range(u+1):
    P[k*j+M*(k+1)] -= nCr(N-M,j)*(-1)**(j%2)
    P[k*j+M*(k+1)] %= MOD

Q = [nCr(i+N,N) for i in range(R+1)]

def f(MAX):
  ans = 0
  for t in range(MAX+1):
    ans += P[t]*Q[MAX-t]
    ans %= MOD
  return ans

def F(x):
  return (Q[x]-nCr(N,M)*f(x))%MOD

print((F(R)-F(L-1))%MOD)

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

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

    int ans = 1;
    for (int i = 1; i * i <= M; ++i) {
        if (M % i != 0) continue;
        if (M / i >= N) ans = i;
        if (i >= N) {
            ans = M / i;
            break;
        }
    }

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


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    long k = Long.parseLong(in.readLine());
    long sum = 0L;
    for(int a=1; a<=k; a++)
      for(int b=1; b<=k; b++)
        for(int c=1; c<=k; c++)
          sum += gcd(gcd(a,b),c);
    System.out.println(sum);
  }
  public static long gcd(long a, long b) {
    if(a>b) {
      long t = a;
      a = b;
      b = t;
    }
    if(a == 0L)
      return b;
    return gcd(b%a,a);
  }
}

Measured memory_bytes: 32664
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int &i : a){
        cin >> i;
    }

    for(int &i : b){
        cin >> i;
    }
    reverse(b.begin(), b.end());
    int c = -1;
    for(int i = 0; i < n; i++){
        if(a[i] == b[i]){
            c = b[i];
            break;
        }
    }
    int j = 0;
    for(int i = 0; i < n; i++){
        while(j < n && (b[j] == c || a[j] == c)){
            j++;
        }
        if(a[i] == b[i]){
            if(j == n){
                cout << "No";
                return 0;
            }
            int t = b[i];
            b[i] = b[j];
            b[j] = t;
        }
    }
    cout << "Yes\n";
    for(int i : b){
        cout << i << " ";
    }
    return 0;
}


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

int main(){
    int N, A, B;
    int ans;

    //input
    cin >> N >> A >> B;

    ans = N * A;
    for(int i = N - 1; i >= 0; i--){
        if(i * A + B < ans){
            ans = i * A + B;
        }
    }

    //output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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 <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)
using namespace std;
typedef pair<int ,int> P;
int d[1001][1001],movex[]={0,0,-1,1},movey[]={1,-1,0,0};
char cc[]={'1','2','3','4','5','6','7','8','9'},a[1001][1001];
int h,w;
int nx,ny;
int bfs(int sx,int sy,char goal){
    queue<P> que;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            d[i][j]=-1;
        }
    }
    que.push(P(sx,sy));
    d[sx][sy]=0;
    int dis;
    while(que.size()){
        P p = que.front();que.pop();
        if(a[p.first][p.second]==goal) {nx=p.first;ny=p.second;return d[p.first][p.second];}
        for(int i = 0; i < 4; i++){
            int x=p.first+movex[i],y=p.second+movey[i];
            if(0<=x and x<h and 0<=y and y<w and d[x][y]==-1 and a[x][y]!='X'){
                que.push(P(x,y));
                d[x][y]=d[p.first][p.second]+1;
            }
        }
    }
    
}

int main(){
    int n;
    cin>>h>>w>>n;
    int x,y;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
            if(a[i][j]=='S'){nx=i;ny=j;}
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        ans+=bfs(nx,ny,cc[i]);
    }
    cout<<ans<<endl;

}

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

using namespace std;
#define ll long long
#define ld  long double

#define endl '\n'
#define FAST                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN = 1e5 + 5;
ll fastPow(ll x, ll b)
{
    if (b == 0)
        return 1;
    else if (!(b & 1))
    {
        return fastPow(x * x, b / 2);
    }
    else
        return x * fastPow(x * x, (b - 1) / 2);
}
//__builtin_popcount ();
struct def{
    string h = ">";
};
int main()
{
    FAST
       int n,x;
    cin >> n >> x;
    int arr[n];
    int sum = 0;
    for (int i = 0; i < n; i++)
        {
            cin >> arr[i];
            sum+=arr[i];
        }
        sort(arr, arr + n);
        x -= sum;
        int ans = n+(x/arr[0]);
        cout << ans << endl;

        return 0;
}

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



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

    vector< vector<int> > arr(n, vector<int> (3,0));
    
    for(int i = 0; i < n; i++)
    {
        scanf("%d%d%d",&arr[i][0],&arr[i][1],&arr[i][2]);
        if(i > 0)
        {
          arr[i][0] += max(arr[i-1][1], arr[i-1][2]);
          arr[i][1] += max(arr[i-1][0], arr[i-1][2]);
          arr[i][2] += max(arr[i-1][0], arr[i-1][1]);  
        }
    }

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

Measured memory_bytes: 5760
Q, H, S, D = map(int, input().split())
N = int(input())

one = min(Q * 4, H * 2)
one = min(one, S)
two = min(2 * one, D)

if one * 2 < two:
    print(one * N)

else:
    tmp = N // 2
    print(tmp * two + N%2 * one)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<int> h(n, 0), c(n, 0);
  rep(i, 0, n) cin >> h[i];
  int ans = 0;

  rep(i, 0, n) {
    int d = h[i] - c[i];
    ans += d;
    rep(j, i, n) {
      chmin(d, h[j] - c[j]);
      c[j] += d;
    }
  }
  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll ans = LINF;
  for(int z = 0; z <= max(x, y); ++z) {
    ans = min(ans, a * max((x - z), 0LL) + b * max((y - z), 0LL) + 2 * c * z);
  }
  out(ans);
  return 0;
}


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

int main(void){
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<int>());
	if (t.compare(s) > 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
  ios_base::sync_with_stdio (false);
  cin.tie(NULL);

  ll A, B;
  cin >> A >> B;

  ll s = 1;
  ll r = 0;
  while (s < B){
    r++;
    s += A-1;
  }

  cout << r << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program
{
    public static Scanner cin;
    static void Main()
    {
        
        cin = new Scanner();
        string s = ReadLine();
        WriteLine(Math.Min(CountChar(s,"1"),CountChar(s,"0"))*2);
        ReadLine();

    }
    static int CountChar(string s,string key)
    {
        return s.Length - s.Replace(key, "").Length;
    }
}





class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string input()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return input();
        i = 0;
        return s[i++];
    }

    public int inputInt()
    {
        return int.Parse(input());
    }
    public int[] arrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = inputInt() + add;
        }
        return Array;
    }

    public long inputLong()
    {
        return long.Parse(input());
    }

    public long[] arrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = inputLong() + add;
        }
        return Array;
    }

    public double inputDouble()
    {
        return double.Parse(input());
    }


    public double[] arrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = inputDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13920
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
constexpr auto INF = 2147483647;
typedef long long ll;

int binarysearch(int x, vector<int> array){
  int left, right, mid;
  left = 0;
  right = array.size();
  while(left<right){
    mid = (left+right)/2;
    if(x == array[mid]) return mid;
    else if(x < array[mid]) right = mid;
    else left = mid+1;
    
  }
  return -1;
}

int main(){

  int num_s, num_t, t, ans;
  vector<int> s;
  ans =0;
  cin >>num_s;
  s.resize(num_s);
  rep(i,num_s) cin >> s[i];
  cin >> num_t;
  rep(i,num_t){
    cin >> t;
    if(binarysearch(t, s) != -1){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int a[1010], b[1010],n;
int dp[10001][1001];

int solve(int h, int idx){
	if(idx == n){
		if(h <= 0){return 0;}
		else{return inf;}
	}
	if(h <= 0){return 0;}
	if(dp[h][idx] != -1){return dp[h][idx];}
	int cond1 = solve(h, idx+1);
	int cond2 = b[idx] + solve(h-a[idx], idx);
	int cond3 = b[idx] + solve(h-a[idx], idx+1);
	int ans = min(cond1, min(cond2, cond3));
	return dp[h][idx] = ans;
}

int main(){
	int h,i,j;
	scanf("%d %d",&h,&n);

	for(i=0;i<n;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	memset(dp, -1, sizeof dp);
	printf("%d\n",solve(h, 0));

	return 0;
};

Measured memory_bytes: 40192