akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  std::string s;

  std::map<std::string, int> map;

  std::cin >> N;

  for (int i = 0; i < N; i ++) {
    std::cin >> s;

    std::sort(ALL(s));

    map[s] ++;
  }

  long long S = 0;

  for (const auto& kv :map) {
    long long c = kv.second;
      
    S += c * (c - 1) / 2;
  }

  std::cout << S << std::endl;
  
  return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9 + 7;

vector<vector<int>> dp(3005, vector<int>(3005));

int main() {
	int N, T;
	cin >> N >> T;
	vector<P> p(N);
	rep(i, N) cin >> p[i].first >> p[i].second;
	sort(all(p));

	int ans = 0;
	rep(i, N) {
		rep(j, T) {
			chmax(dp[i + 1][j], dp[i][j]);
			int nj = j + p[i].first;
			if (nj < T) chmax(dp[i + 1][nj], dp[i][j] + p[i].second);
		}
		int now = dp[i][T - 1] + p[i].second;
		chmax(ans, now);
	}

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

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

#define lp(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define pb push_back

const int inf=1e9+5 ;
const int maxn=2e5+10 ;

using namespace std ;

int n ;
ll v[maxn],minR[maxn] , minL[maxn] ;

int main()
{
  scanf("%d",&n) ;
  lp(i,1,n+1) scanf("%lld", &v[i]) ;

  v[0] = v[n+1] = -inf ;

  for(int i=n;i>0;i--)
  {
    int cur = i+1 ;
    while(v[cur]>v[i]) cur=minR[cur] ;
    minR[i] = cur ;
  }

  lp(i,1,n+1)
  {
    int cur=i-1;
    while(v[cur]>v[i])cur=minL[cur];
    minL[i]=cur;
  }

  ll ans = 0 ;

  lp(i,1,n+1)
  ans +=(i-minL[i])*(minR[i]-i)* v[i] ;

  printf("%lld\n",ans) ;

}

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

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

int main(){
    string s;
    cin >> s;
    int p,i;
    for(i=0;i<7;i++){
        if(days[i] == s){
            p=i;
            break;
        }
    }
    cout << 7-p;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
H = list(map(int, input().split()))
A = [0]*n
for i in range(m):
    a, b = map(int, input().split())
    A[a-1] = max(A[a-1], H[b-1])
    A[b-1] = max(A[b-1], H[a-1])
ans = 0
for i in range(n):
    if H[i] > A[i]:
        ans += 1

print(ans)

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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n;
		n = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0 ; i < n ; i++) {
			p[i] = sc.nextInt();
		}
		int[] c = p.clone();
		Arrays.sort(c);
		int cnt = 0;
		for(int i = 0 ; i < n ; i++) {
			if(p[i] != c[i]) {
				cnt++;
			}
		}
		if(cnt <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();
	}

}


Measured memory_bytes: 22612
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        String T = sc.next();
        String[] s = S.split("");
        String[] t = T.split("");

        String ans = "";
        for(int i = 0; i < N; i++){
            ans = ans + s[i] + t[i];
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#設定
import sys
input = sys.stdin.buffer.readline

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = []
	for i in range(N):
		a = int(input())
		A.append([a, i])
	B = sorted(A)
	ans = 0
	for i in range(N):
		if A[i][1] % 2 == 1 and B[i][1] % 2 == 0:
			ans += 1
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 20856
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxx = 1e5;
int ans[maxx];

int main()
{
	string s;
	cin >> s;
	int len = s.size();
	int l, r;
	for(int i = 0; i < len; i ++)
	{
		l = 0, r = 0;
		if(s[i] == 'R')
		{
			r ++;
			int x, y;
			for(int j = i + 1; j < len; j ++)
			{
				if(s[j] == 'R')
					r ++;
				else
				{
					x = j;
					break;
				}
			}
			for(int j = x; j < len; j ++)
			{
				if(s[j] == 'L')
					l ++;
				if(s[j] == 'R' || j == len - 1)
				{
					ans[x] = ans[x - 1] = (l + r) / 2;
					if(r > l && (r - l) % 2 == 1)
					{
						if(l % 2 == 1)
							ans[x] ++;
						else
							ans[x - 1] ++;
					}
					else if(l > r && (l - r) % 2 == 1)
					{
						if(r % 2 == 1)
							ans[x - 1] ++;
						else
							ans[x] ++;
					}
					y = j;
					break;
				}
			}
			i = y - 1;
			if(y == len - 1)
				i ++;	
		}
	}
		for(int i = 0; i < len; i ++)
		{
			cout << ans[i];
			if(i < len - 1) cout << ' ';
			else cout << '\n';
		}
	

	return 0;
}

Measured memory_bytes: 1088
#include<bits/stdc++.h>
using namespace std;
int main(){
  int max = 0;
  int i,N,X,T;
  cin >> N >> X >> T;
  for(i=0 ; max < N  ; i++){
    max=i*X;
  }
  i--;
  max=i*T;
  cout << max;
}

Measured memory_bytes: 3604
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]
		self.size = [1 for _ in range(size)]

	def find(self, x):
		while self.table[x] >= 0:
			if self.table[self.table[x]] >= 0:
				self.table[x] = self.table[self.table[x]]
			x = self.table[x]
		return x

	def unite(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
				self.table[s1] -= 1
				self.size[s1] += self.size[s2]
				self.size[s2] = 0
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
				self.size[s2] += self.size[s1]
				self.size[s1] = 0
		return

n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
	a, b = map(int, input().split())
	uf.unite(a-1, b-1)

print(max(uf.size))

Measured memory_bytes: 100936
#include <stdio.h> 

int main(void)
{	
	int H, W, i, j;

	while(1)
	{
		scanf("%d %d",&H, &W);


		if(H != 0 && W != 0)
		{
		
			for(i=0; i<H; i++)
			{
				for(j=0; j<W; j++)
				{
					if(i == 0 || i == H-1 || j == 0 || j == W-1)
					{
						printf("#");
					}
					else
					{
						printf(".");
					}
				}
				printf("\n");
			}
			printf("\n");
		}
		else
		{
			break;
		}
	}
				

	return 0;
}

Measured memory_bytes: 572
tel_dict = {
        1 : (".", ",", "!", "?", " "),
        2 : ("a", "b", "c"),
        3 : ("d", "e", "f"),
        4 : ("g", "h", "i"),
        5 : ("j", "k", "l"),
        6 : ("m", "n", "o"),
        7 : ("p", "q", "r", "s"),
        8 : ("t", "u", "v"),
        9 : ("w", "x", "y", "z"),
        }
def get_input():
    input_data = input()
    return input_data

def convert_num_to_word(num_str):
    count = 0
    c_list = list()
    for i in num_str:
        if i != "0":
            num_state = int(i)
            count += 1
        else:
            if count == 0:
                continue
            order = (count - 1) % len(tel_dict[num_state])
            # print("order", order) # debug
            c = tel_dict[num_state][order]
            c_list.append(c)
            count = 0 # reset
    return c_list




if __name__ == "__main__":
    input_data = int(get_input())
    for i in range(input_data):
        input_data = get_input()
        c_list = convert_num_to_word(input_data)
        word = "".join(c_list)
        print(word)


Measured memory_bytes: 5616
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int n;
char board[8][8] = {
    { '.', '.', '.', '.', '.', '.', '.', '.' },
    { '.', '.', '.', '.', '.', '.', '.', '.' },
    { '.', '.', '.', '.', '.', '.', '.', '.' },
    { '.', '.', '.', '.', '.', '.', '.', '.' },
    { '.', '.', '.', '.', '.', '.', '.', '.' },
    { '.', '.', '.', '.', '.', '.', '.', '.' },
    { '.', '.', '.', '.', '.', '.', '.', '.' },
    { '.', '.', '.', '.', '.', '.', '.', '.' },
};

bool pre_x[8], pre_y[8];

const char Q = 'Q';

inline bool check(int x, int y) {
//    printf("[check] x = %d, y = %d\n", x, y);

    for (int i = 0; i < 8; ++i) {   // ?????¨?¨?
        if (board[y][i] == Q) return false;
        if (board[i][x] == Q) return false; 
    }

    int p = x, q = y;
    while (--p >= 0 && --q >= 0) {  // ??????
        if (board[q][p] == Q) return false;
    }

    p = x; q = y;
    while (++p < 8 && --q >= 0) {   // ??????
        if (board[q][p] == Q) return false;
    }

    p = x; q = y;
    while (++p < 8 && ++q < 8) {    // ??????
        if (board[q][p] == Q) return false;
    }

    p = x; q = y;
    while (--p >= 0 && ++q < 8) {   // ??????
        if (board[q][p] == Q) return false;
    }

    return true;
}

bool solve(int row) {
    if (row == 8)
        return true;
    if (pre_y[row]) {
        if (solve(row + 1)) {
            return true;
        }
        else {
            return false;
        }
    }
    for (int i = 0; i < 8; ++i) {
        if (!pre_x[i] && check(i, row)) {
            board[row][i] = Q;
            if (solve(row + 1))
                return true;
            else
                board[row][i] = '.';
        }
    }
    return false;
}

int main(void) {

    scanf("%d", &n);

    for (int i = 0, x, y; i < n; ++i) {
        scanf("%d %d", &y, &x);
        board[y][x] = Q;
        pre_y[y] = pre_x[x] = true;
    }

    solve(0);

    for (int i = 0; i < 8; ++i) {
        for (int j = 0; j < 8; ++j) {
            printf("%c", board[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1160
N,K = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
p =[]
for i in b:
    p.append((i+1)/2)
s = sum(p[:K])
max_s = s
for i in range(N-K):
    max_s+=p[K+i]
    max_s-=p[i]
    if max_s>s:
        s = max_s
print(s)


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

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

  int minm=1000;
  for (int i = 0; i < n; i++)
  {
    int m;
    cin >> m;
    x-=m;
    minm=min(minm,m);
  }
  int ans = n + x/minm;
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <vector>

using namespace std;
int main(){
    string s;
    cin >> s;
    if(s == "A") cout << 'T' << endl;
    if(s == "T") cout << 'A' << endl;
    if(s == "C") cout << 'G' << endl;
    if(s == "G") cout << 'C' << endl;
}

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

const ll INF = 1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        ll b;
        cin >> b;
        a[b-1] = i;
    }
    set<ll> st;
    st.insert(n);
    st.insert(-1);
    ll ans = 0;
    for(ll i = 0; i < n; ++i){
        ll b = a[i];
        auto it = st.lower_bound(b);
        ll r = *it;
        ll l = *(--it);
        ans += (i+1) * (b - l) * (r - b);
        st.insert(b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14260
from sys import stdin
input = stdin.readline

n = int(input())
a, b = [], []
res = []

for _ in range(n):
    x, y = map(int, input().split())
    a.append(x + y)
    b.append(x - y)

a.sort()
b.sort()

res.append(a[-1] - a[0])
res.append(b[-1] - b[0])

print(max(res))

Measured memory_bytes: 25640
#include <iostream>

int main() {
    int A,B,C;
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);

    if((A < C && C < B) || (B < C && C < A)){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}

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

namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            String[] L = S.Split(' ');
            int A = int.Parse(L[0]);
            int B = int.Parse(L[1]);

            if(A >= 13)
            {
                Console.WriteLine(B);
            }
            else if(A >= 6)
            {
                Console.WriteLine(B / 2);
            }
            else
            {
                Console.WriteLine("0");
            }


        }
    }
}

Measured memory_bytes: 13140
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
N = inp.shift() * 1
S = inp.shift()
cnt = 0
for(i=0;i<10;i++) {
    k = 0;
    while(S[k] != i) {
        k++
        if (k >= N) {
            break;
        }
    }
    k++
    for(j=0;j<10;j++) {
        l = k
        while(S[l] != j) {
            l++
            if (l >= N) {
                break;
            }
        }
        l++
        a = [0,0,0,0,0,0,0,0,0,0]
        c = 0
        while(l < N) {
            if (!a[S[l]]) {
                a[S[l]] = 1
                c++
                if (c == 10) {
                    break;
                }
            }
            l++
        }
        cnt += c
    }
}

console.log(cnt)

Measured memory_bytes: 21064
n = int(input())
p = [50 for i in range(26)]
for i in range(n):
    kar = input()
    for i in range(26):
        p[i] = min(p[i],kar.count(chr(ord("a") + i)))
for i in range(26):
    for j in range(p[i]):
        print(chr(ord("a") + i),end="")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double o,t;
    int n;
    cin>>n;
    if(n<3){t=n;}
    if(n%2==0){
        t=n/2;
    }
    else if(n%2!=0){
        t=(int)(n/2)+1;
    }
    o=(double)(t/(double)n);
    cout<<setprecision(12)<<o<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(void)
{
	ll N, M;
	cin >> N >> M;
	vector<pair<ll, ll> > list(M);
	rep(i, M)
	{
		int A, B;
		cin >> A >> B;
		list[i] = make_pair(A, B);
	}

	sort(list.begin(), list.end());
	ll price = 0;
	repd(i, 1, M)
	{
		if(N>list[i].first) price += N - list[i].first;
		else break;
	}
	cout << price << endl;
}



Measured memory_bytes: 3136
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
bool dp[410][410];
int main(){
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        rep(j,n){
            if(dp[a][j]){
                dp[j][b] = 1;
                dp[b][j] = 1;
            }
            if(dp[b][j]){
                dp[j][a] = 1;
                dp[a][j] = 1;
            }
        }
        if(dp[a][b]){
            rep(j,n){
                dp[a][j] = 1;
                dp[j][a] = 1;
                dp[b][j] = 1;
                dp[j][b] = 1;
            }
        }else{
            dp[a][b] = 1;
            dp[b][a] = 1;
        }
    }
    int res = 0;
    rep(i,n){
        rep(j,n){
            if(i!=j){
                res += 1-dp[i][j];
            }
        }
    }
    cout << res/2 << endl;
    return 0;
}

Measured memory_bytes: 888
// g++ -std=gnu++14 -I ~/Documents/AtCoder -o test ~/Documents/AtCoder/test.cpp && ./test && rm test
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    (v).begin(), (v).end()
#define in        ([]{int n; cin>>n; return n;}())
using namespace std;
using lint = int64_t;


int main() { cin.tie(0); ios::sync_with_stdio(false);
    int N=in;
    vector<int> X(N), Y(N);
    rep( i, N ) { X[i]=in; Y[i]=in; }

    if( N==1 ) { cout << 1 << endl; return 0; }

    int max_value = INT_MIN;
    rep( i, N ) {
        rep( j, N ) {
            int p = X[i] - X[j];
            int q = Y[i] - Y[j];

            if( i==j ) { continue; }

            int count = 0;
            rep( k, N ) {
                rep( l, N ) {
                    if( k==l ) { continue; }
                    if( X[k] - p == X[l] && Y[k] - q == Y[l] ) {
                        count ++;
                    }
                }
            }
            max_value = max( max_value, count );
        }
    }

    cout << (N-max_value) << endl;
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  int count = 0;
  int id_A = s.find('A');
  int id_Z = s.rfind('Z');
  cout << id_Z - id_A + 1 << endl;
}

Measured memory_bytes: 640
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashMap;

fn main() {
    input!(_n:usize,k:usize,mut s:chars);
    let k = k - 1;
    let c = s[k] as u32 + 'a' as u32 - 'A' as u32;
    s[k] = std::char::from_u32(c).unwrap();
    // println!("{}", s.iter().collect::<String>());
    for c in s.iter() {
        print!("{}", c);
    }
    println!("");
}


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

int main(){
  int n, k;
  cin >> n >> k;
  ll ans = k;
  ans *= pow((k - 1), n - 1);
  cout << ans << endl;
}

Measured memory_bytes: 384
$h, $w = gets.split.map(&:to_i)
$m = $h.times.map do
  gets.chomp.chars
end
$v = Array.new($h).map { Array.new($w) { false } }

def can_visit(py, px)
  py.between?(0, $h-1) && px.between?(0, $w-1) && $m[py][px] == '.' && !$v[py][px]
end

$q = Queue.new
$q << [0, 0, 0]

gd = -1
while $q.size > 0
  py, px, d = $q.pop
  if $v[py][px]
    next
  else
    $v[py][px] = true
  end

  if [py, px] == [$h-1, $w-1]
    gd = d
    break
  end

  [[py-1, px], [py+1, px], [py, px-1], [py, px+1]].each do |npy, npx|
    $q << [npy, npx, d+1] if can_visit(npy, npx)
  end
end

puts gd == -1 ? -1 : $h * $w - $m.flatten.count('#') - (gd + 1)

Measured memory_bytes: 3836
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String args[] ) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] array = line.split(" ");
        int gaiku = (Integer.parseInt(array[0]) - 1) * (Integer.parseInt(array[1]) - 1);
        System.out.println(gaiku);
    }
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int N,T=0;
    int t[500]={},v[500];
    int s[500]={};
    int d[50000]={};
    cin >> N;
    OREP(i,N){
        cin >> t[i];
        t[i]*=2;
        T+=t[i];
        s[i]=s[i-1]+t[i];
    }
    REP(i,N){
        cin >> v[i];
        v[i]*=2;
    }
    
    REP(i,T+1){
        d[i]=min(i,T-i);
    }
    REP(i,N){
        for(int j=s[i];j<=s[i+1];j++){
            d[j]=min(d[j],v[i]);
        }
    }
    REP(i,N){
        REP(j,T+1){
            if(j<s[i]){
                d[j]=min(d[j],v[i]+abs(s[i]-j));
            }
            if(s[i+1]<j){
                d[j]=min(d[j],v[i]+abs(j-s[i+1]));
            }
        }
        /*REP(j,T+1){
            d[j]=min(d[j],v[i]-(t[i]-j));
            d[j]=min(d[j],v[i]-(j-t[i+1]));
        }*/
    }
    double Ans=0;
    REP(i,T+1){
        //cerr << (double)i/2 << " " << (double)d[i]/2 << endl;
        Ans+=d[i];
    }
    printf("%.5f\n",Ans/4);
    return 0;
}   


Measured memory_bytes: 640
class Integer
  def fac
    return 1 if self.zero?

    arr = [*1..self]
    loop do
      return arr[0] if arr.length == 1
      arr = arr.each_slice(2).map { |a, b| b ? a * b : a }
    end
  end

  def combi r
    return 0 if self < r
    self.fac / (r.fac * (self - r).fac)
  end
end
_n, m = gets.chomp.split.map(&:to_i)
ary = gets.chomp.split.map(&:to_i)

mod_hash = Hash.new(0)
mod = ary.first % m
mod_hash[mod] += 1

ary[1..-1].each do |num|
  mod = (mod + num) % m
  mod_hash[mod] += 1
end

ans = mod_hash.inject(0) do |sum, attr|
  sum + (attr.last).combi(2)
end + mod_hash[0]

puts ans

Measured memory_bytes: 29868
n = int(input())
inst_k = [-1]*n
inst = [-1]*n
for i in range(n):
    tmp = input().split()
    inst[i] = tmp[0]
    if len(tmp) == 2:
        inst_k[i] = int(tmp[1])

class BST:
    def __init__(self):
        self.key = []
        self.parent = []
        self.left_child = []
        self.right_child = []
        self.root = -1

    def insert(self,new_key):
        new_node = len(self.key)
        self.key.append(new_key)
        self.left_child.append(-1)
        self.right_child.append(-1)
        self.parent.append(-1)

        searching_node = self.root
        searching_node_parent = -1
        while searching_node != -1:
            searching_node_parent = searching_node
            if new_key < self.key[searching_node]:
                searching_node = self.left_child[searching_node]
            else:
                searching_node = self.right_child[searching_node]
        if searching_node_parent == -1:
            self.root = new_node
        else:
            self.parent[new_node] = searching_node_parent
            if new_key < self.key[searching_node_parent]:
                self.left_child[searching_node_parent] = new_node
            else:
                self.right_child[searching_node_parent] = new_node
    
    def print_clear(self):
        self.preorder_ans = []
        self.inorder_ans = []
    
    def preorder(self,node):
        if node != -1:
            self.preorder_ans.append(self.key[node])
            self.preorder(self.left_child[node])
            self.preorder(self.right_child[node])
    
    def inorder(self,node):
        if node != -1:
            self.inorder(self.left_child[node])
            self.inorder_ans.append(self.key[node])
            self.inorder(self.right_child[node])

tree = BST()
for i in range(n):
    if inst[i] == "insert":
        tree.insert(inst_k[i])
    elif inst[i] == "find":
        pass
    elif inst[i] == "print":
        tree.print_clear()
        tree.preorder(tree.root)
        tree.inorder(tree.root)
        print(" ",end = "")
        print(*tree.inorder_ans)
        print(" ",end = "")
        print(*tree.preorder_ans)



Measured memory_bytes: 100768
#include<stdio.h>
int main()
{
	int x,y,youbi,getu,hi,map[12][31]={0};
	while(scanf("%d %d",&getu,&hi) && getu!=0 || hi!=0)
	{
		youbi=4;
		for(x=0; x<12; x++)
		{
			for(y=0; y<31; y++)
			{
				if(x==1 && y==29)
					break;
				if((x==3 || x==5 || x==8 || x==10) && y==30)
					break;
				map[x][y]=youbi;
				youbi++;
				if(youbi==8)
					youbi=1;
			}
		}
		if(map[getu-1][hi-1]==1)
			printf("Monday\n");
		if(map[getu-1][hi-1]==2)
			printf("Tuesday\n");
		if(map[getu-1][hi-1]==3)
			printf("Wednesday\n");
		if(map[getu-1][hi-1]==4)
			printf("Thursday\n");
		if(map[getu-1][hi-1]==5)
			printf("Friday\n");
		if(map[getu-1][hi-1]==6)
			printf("Saturday\n");
		if(map[getu-1][hi-1]==7)
			printf("Sunday\n");
	}
	return 0;
}

Measured memory_bytes: 584
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int w = sc.nextInt();
        int n = sc.nextInt();
        int[] array=new int[w];
        for(int i=0;i<w;i++)array[i]=i+1;
        int a=0,b=0;
        for(int i=0;i<n;i++){
            String s=sc.next();
            String st1="";
            String st2="";
            for(int j=0;j<s.length();j++){
                if(s.charAt(j)!=','){
                    st2+=s.charAt(j);
                }
                else {
                    st1=st2;
                    st2="";
                }
            }
            a=Integer.parseInt(st1);
            b=Integer.parseInt(st2);
            int tmp=0;
            tmp=array[a-1];
            array[a-1]=array[b-1];
            array[b-1]=tmp;
        }
        for(int i=0;i<w;i++)System.out.println(array[i]);
    }
}


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

q = 4 * Q * N
h = 2 * H * N
s = S * N

if N == 1:
    d = float('inf')
else:
    d = (N // 2 * D)
    if N % 2 == 1:
        d+=min(4*Q,2*H,S)
print(min(q,h,s,d))

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
 
char ha[1<<22],k[256];
 
int hash(char *str)
{
  int h=1;
  while(*str) h=(h<<2)+k[*str++];
    return h;
}
 
int main(){
  int i,h,n;
  char c[8],str[13];
 
  k['C']=1;
  k['G']=2;
  k['T']=3;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf(" %s %s",c,str);
    h=hash(str);
 
    if(c[0]=='i') 
      ha[h>>3] |= 1<<(h&7);
 
    else puts((ha[h>>3] & (1<<(h&7)))? "yes":"no");
  }
  return 0;
}

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

string judge(int a, int b) {
    if (a > b) {
        return "Alice";
    } else if (a < b){
        return "Bob";
    }
    return "Draw";
}

int main(){
    int a, b; cin >> a >> b;
    if (a == 1) {a+=13;}
    if (b == 1) {b+=13;}
    cout << judge(a,b) << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = []
for i in range(n):
    key = i + 1
    s, p = input().split()
    p = int(p)
    l.append([s, p, key]) 
    
# print(l)

l = sorted(l, key=lambda x:x[1], reverse=True)
l = sorted(l, key=lambda x:x[0])


for v in l:
    print(v[2])

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

int main(){
	string s;cin>>s;
	int ans=0;
	rep(i,2){
		int Min=s.size();
		rep(i,s.size()){
			if(s[i]=='1'){
				Min=min(Min,max(i,(int)s.size()-i-1));
			}
		}
		ans=max(ans,Min);
		for(char&c:s){
			if(c=='0')c='1';
			else c='0';
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
deque<char> s,t;
string S,T;
char c;
int ssiz, tsiz;
int main(void)
{
    string S,T;
    cin >> S;
    cin >> T;
    ssiz = S.size(); tsiz = T.size();
    if(ssiz!=tsiz) return !printf("No");
    for(int i=0;i<ssiz;i++) s.push_back(S[i]);
    for(int i=0;i<tsiz;i++) t.push_back(T[i]);
    for(int i=0,j;i<ssiz;i++)
    {
        for(j=0;j<ssiz;j++)
        {
            if(s[j]!=t[j]) break;
        }
        if(j==ssiz) return !printf("Yes");
        s.push_back(s[0]);
        s.pop_front();
    }
    return !printf("No");
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DMegalomania solver = new DMegalomania();
        solver.solve(1, in, out);
        out.close();
    }

    static class DMegalomania {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            ArrayList<DMegalomania.node> a = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                a.add(new DMegalomania.node(in.nextInt(), in.nextInt()));
            }
            Collections.sort(a, new Comparator<DMegalomania.node>() {

                public int compare(DMegalomania.node o1, DMegalomania.node o2) {
                    return o1.b - o2.b;
                }
            });
            long ans = 0;
            boolean yes = false;
            for (int i = 0; i < n; i++) {
                ans += a.get(i).a;
                if (ans > a.get(i).b) {
                    yes = true;
                    break;
                }
            }
            if (yes) out.println("No");
            else out.println("Yes");
        }

        static class node {
            int a;
            int b;

            node(int a, int b) {
                this.a = a;
                this.b = b;
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



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

#define DeltaCube23 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define minimum(a) *min_element(a.begin(), a.end())
#define maximum(a) *max_element(a.begin(), a.end())
#define MOD 1000000007
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i >= (b); i--)

typedef long long int lli;

using namespace std;

const int mx=2e6+5;

int main()
{
    DeltaCube23
	int t=1;
	//cin>>t;
	while(t--)
	{
        lli n,m,x;
        cin>>n>>m>>x;
        
        vector<int> a(n);
        for(int a_i = 0; a_i <n; a_i++){
           cin >> a[a_i];
        }
        
        vector<int> b(m);
        for(int b_i =0; b_i <m; b_i++){
           cin >> b[b_i];
        }
        
        lli sum=0,count=0,temp=0,i=0,j=0;        
        
        while(i<n && sum+a[i]<=x){   
            sum+=a[i];
            i++;
        }
        count=i;        
       
        while(j<m && i>=0){  
            sum+=b[j];             
            j++;
            while(sum>x && i>0){
                i--;
                sum-=a[i];
            }
            if(sum<=x && i+j>count)
                count=i+j;
        }
        cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 4780
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
string s;
int x,y;
vector <bool > xnum;
vector <bool > ynum;
vector <bool > xnum2;
vector <bool > ynum2;

vector <int> xl;
vector <int> yl;




int main()
{

	cin >> s;
	cin >> x >> y;


	xnum.resize(20000);
	ynum.resize(20000);
	xnum2.resize(20000);
	ynum2.resize(20000);
	REP(i,20000){
		xnum[i] = false;
		ynum[i] = false;
		xnum2[i] = false;
		ynum2[i] = false;
	}
	int flag = false;
	int count = 0;
	int xiter=0;
	int yiter=0;

	xl.resize(8000);
	yl.resize(8000);

	REP(i,s.length()){
		if(s[i]=='F'){
			count++;
		} else {
			if(!flag){
				xl[xiter]=count;
				xiter++;
			} else {
				yl[yiter]=count;
				yiter++;
			}
			flag = !flag;
			count=0;
		}
	}
	if(!flag){
		xl[xiter]=count;
		xiter++;
	} else {
		yl[yiter]=count;
		yiter++;
	}

	xnum[10000+xl[0]] = true;
	ynum[10000]=true;


	FOR(i,1,xiter) {
		REP(j,20000){
			xnum2[j]=false;
		}
		REP(j,20000){
			if(xnum[j]==true){
				xnum2[j+xl[i]]=true;
				xnum2[j-xl[i]]=true;
			}
		}
		xnum = xnum2;
	}

	REP(i,yiter) {
		REP(j,20000){
			ynum2[j]=false;
		}
		REP(j,20000){
			if(ynum[j]){
				ynum2[j+yl[i]]=true;
				ynum2[j-yl[i]]=true;
			}
		}
		ynum = ynum2;
	}

	if(xnum[x+10000]&&ynum[y+10000]){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}


}





Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

    int x,a;
    cin >> x >> a;

    if(x < a){
        cout << 0 << endl;
    }else
    {
        cout << 10 << endl;
    }
    


    return 0;
}

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

struct node
{
	int key;
	node* lc, * rc, * p;
};

node* root = NULL;

void insert(int x)
{
	node* pre = root;
	node* prep = NULL;

	node* in = (node*)malloc(sizeof(node));
	in->key = x;
	in->lc = NULL;
	in->rc = NULL;

	while (pre != NULL)
	{
		prep = pre;
		if (in->key < pre->key)
			pre = pre->lc;
		else
			pre = pre->rc;
	}

	in->p = prep;

	if (prep == NULL)
		root = in;
	else
	{
		if (in->key < prep->key)
			prep->lc = in;
		else
			prep->rc = in;
	}
}

void Inorder(node* r)
{
	if (r->lc != NULL)
		Inorder(r->lc);

	cout << " " << r->key;

	if (r->rc != NULL)
		Inorder(r->rc);
}

void Preorder(node* r)
{
	cout << " " << r->key;

	if (r->lc != NULL)
		Preorder(r->lc);
	if (r->rc != NULL)
		Preorder(r->rc);
}

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

	int n, x;
	string p;

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

		if (p == "insert")
		{
			cin >> x;
			insert(x);
		}
		else
		{
			Inorder(root);
			cout << endl;
			Preorder(root);
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 26664
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
	int t,i,n,k,c=0,ans=0;
	cin>>n>>k;
	int a,d[200000]={0};
	for(i=0;i<n;i++){
		cin>>a;
		if(d[a]==0)c++;
		d[a]++;
	}
	sort(d,d+200000);
	for(i=0;i<200000;i++){
		if(d[i]!=0){
			t=i;
			break;
		}
	}
	while(c>k){
		ans+=d[t];
		c--;
		t++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

vector<pair<long long, long long> > soin(long long n)
{
    long long s = floor(sqrt(n));

    vector<pair<long long, long long> > res;

    for(long long i = 2; i <= s; i++){
        if(n % i == 0){
            long long r = 0;
            while(n%i == 0){
                r++;
                n /= i;
            }
            res.push_back(make_pair(i, r));
        }
    }
    if(n > s) {
        res.push_back(make_pair(n, 1));
    }
    return res;
}

map<long long, long long> gt;

long long fn(long long n)
{
    vector<pair<long long, long long> > s = soin(n);
    for(int i = 0; i < s.size();i ++){
        if(s[i].first == 5){
            printf("XXXX %lld %lld\n", n, s[i].second);
        }
        gt[s[i].first] += s[i].second;
    }

    if(n < 2){
        return 1;
    }else{
        return n * fn(n - 2);
    }
}

long long fivect(long long n)
{
    long long base = 1;
    long long ct = 0;
    while(base <= n){
        base *= 5;
        ct += n / (base * 2);
    }
    return ct;
}

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

    //printf("%lld\n", fn(n));
    /*
    for(map<long long, long long>::iterator it = gt.begin(); it != gt.end(); it++){
        printf("DD %lld %lld\n", (*it).first, (*it).second);
    }
    */
    if(n % 2){
        printf("0\n");
    }else{
        printf("%lld\n", fivect(n));
    }
    return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 1e5 + 10;
vector < int > g[maxN];
int n, m, q;
int c[maxN];
int best[maxN][12];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    cin >> q;
    for (int i = 1; i <= q; i++) {
        int v, d, c;
        cin >> v >> d >> c;
        ::c[i] = c;
        best[v][d] = max(best[v][d], i);
    }
    for (int i = 10; i >= 1; i--) {
        for (int j = 1; j <= n; j++) {
            if (best[j][i] == 0) continue;
            best[j][i - 1] = max(best[j][i], best[j][i - 1]);
            for (int v : g[j]) {
                best[v][i - 1] = max(best[v][i - 1], best[j][i]);
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << c[best[i][0]] << '\n';
    }
    return 0;
}

Measured memory_bytes: 11640
N, M = map(int, input().split())
A = [int(_) for _ in input().split()]
BC = [[int(_) for _ in input().split()] for _ in range(M)]
# Cの大きい順にソート
BC.sort(key = lambda x: x[1], reverse = True)
ABC = []
for x, y in BC:
    A.extend([y] * x)
    # 2N個以上あっても選ばれないので、そこで打ち切り
    if len(A) > N * 2:
        break

A.sort(reverse = True)
print(sum(A[:N]))

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	string N; cin >> N;
	int D; cin >> D;
	const LL mod = 1e9+7;
	vector<LL> dp(D,0);
	LL z = 0;
	repp(t,0,N.size()){
		vector<LL> nx(D,0);
		repp(i,0,D) repp(k,0,10) (nx[(i+k)%D] += dp[i]) %= mod;
		repp(k,0,N[t]-'0') (nx[(z+k)%D] += 1) %= mod;
		z = (z+N[t]-'0')%D;
		swap(dp,nx);
	}
	if(z) dp[0] = (dp[0]+mod-1)%mod;
	cout << dp[0] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2005,INF=1<<30;
vector<int> G[MAX];
int N,dis[MAX][MAX];

void BFS(){
    for(int i=0;i<N;i++){
        queue<int> Q;
        Q.push(i);
        for(int j=0;j<N;j++) dis[i][j]=-1;
        dis[i][i]=0;
        
        while(!Q.empty()){
            int u=Q.front();Q.pop();
            for(int to:G[u]){
                if(dis[i][to]==-1){
                    dis[i][to]=dis[i][u]+1;
                    Q.push(to);
                }
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int X,Y;cin>>N>>X>>Y;
    X--;
    Y--;
    
    for(int i=0;i+1<N;i++){
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    
    G[X].push_back(Y);
    G[Y].push_back(X);
    
    BFS();
    
    vector<int> ans(N);
    
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            ans[dis[i][j]]++;
        }
    }
    
    for(int i=1;i<N;i++) cout<<ans[i]<<"\n";
    
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
const int INF = 1e9;

int main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> L(N);
    rep(i, 0, N) cin >> L[i];
    auto rec = [&](auto &rec, int i, int a, int b, int c) {
        if(i == N) {
            if(a && b && c) return abs(a - A) + abs(b - B) + abs(c - C) - 30;
            return INF;
        }
        int res = rec(rec, i + 1, a, b, c);
        chmin(res, rec(rec, i + 1, a + L[i], b, c) + 10);
        chmin(res, rec(rec, i + 1, a, b + L[i], c) + 10);
        chmin(res, rec(rec, i + 1, a, b, c + L[i]) + 10);
        return res;
    };
    cout << rec(rec, 0, 0, 0, 0) << endl;
    return 0;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

signed main() {
	int N, R;
	cin >> N >> R;
	cout << (N >= 10 ? R : R + 100 * (10 - N)) << endl;

	return 0;
}

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

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
      return Double.parseDouble(next());
    }

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

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    String s = sc.next();
    if (s.equals("AAA") || s.equals("BBB")) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 22484
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    a = list(map(int, input().split()))
    d = c
    for j in range(m):
        d += a[j] * b[j]
    if d > 0:
        ans += 1

print(ans)

Measured memory_bytes: 62156