akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	string S;
	cin >> S;
	int A = 0;

	rep(i, N) if (S[i] == 'R') A++;
	int B = N - A;
	if (A > B) co("Yes");
	else co("No");



	Would you please return 0;
}

Measured memory_bytes: 256
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
    ll a,b,c,d,ans=INT64_MIN;cin>>a>>b>>c>>d;
    if(a>c)
    {
        swap(a,c);
        swap(b,d);
    }
    if(b>0&&d>0)ans=max(ans,b*d);
    if(a<0&&c<0)ans=max(ans,a*c);
    if(b<0&&c>0)ans=max(ans,b*c);
    if((a<=0&&b>=0)||(c<=0&&d>=0))ans=max(ans,0ll);
    cout<<ans<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//**always check if you are not killing input in between
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//string2=string1.substr(pos,length);if len no specified then till end
//void fill (ForwardIterator first, ForwardIterator last, const T& val);
//The range filled is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.


//If wrong on pretest 2 means logically wrong
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


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

using LL = long long;
int n;
vector<int> a;
signed main() {
  // freopen("in", "r", stdin);
  while(cin >> n) {
    a.resize(n);
    for(int i = 0; i < n; i++) {
      cin >> a[i]; a[i] -= i;
    }
    sort(a.begin(), a.end());
    int b = a[n/2];
    LL ret = 0;
    for(int i = 0; i < n; i++) {
      ret += (LL)abs(a[i] - b);
    }
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;


int main(){
    string S;
    cin >> S;
    if(S[0] == S[1] && S[1] == S[2] && S[0]== S[1]){
        cout << "No";
        }
    else{
        cout << "Yes";
        }

}

Measured memory_bytes: 256
#include<stdio.h>

int g_t[50];

int fib(int n);

int main(){
  int n,i;

  for(i = 0; i < 50; i++) g_t[i] = -1;
  
  scanf("%d",&n);

  printf("%d\n",fib(n));
  
  return 0;
}

int fib(int n){
  if(n == 0 || n == 1) return g_t[n] = 1;
  if(g_t[n] != -1) return g_t[n];
  return g_t[n] = fib(n-1) + fib(n-2);
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
 
int main() {

  int h,w;
  int i=0;
  int k=0;
  int l=0;
  int j=0;
  cin>>h>>w;
  int count[h];
  int counter[w];
  rep(s,h){count[s]=0;}
  rep(t,w){counter[t]=0;}
  
vector<vector<char>>a(h,vector<char>(w));
  rep(i,h){
  rep(j,w){cin>>a.at(i).at(j);}}
  
  rep(i,h){
  rep(j,w){if(a.at(i).at(j)=='#'){count[i]++;counter[j]++;}}}
  
  rep(i,h){ if(count[i]!=0){
    rep(j,w){
      if(counter[j]!=0){
        cout<<a.at(i).at(j);}
    		}cout<<endl;}
  }

}



Measured memory_bytes: 256
n = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0
for i in range(n):
  s = input()
  if s[0] == 'M':
    m += 1
  elif s[0] == 'A':
    a += 1
  elif s[0] == 'R':
    r += 1
  elif s[0] == 'C':
    c += 1
  elif s[0] == 'H':
    h += 1
total = m + a + r + c + h
res = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h + a * c * h + r * c * h

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  REP(i, M) cin >> A[i];
  
  sort(ALL(A));
  if(N>=M){
    cout << 0 << endl;
  }else{
    vector<int> B(M-1);
    REP(i,M-1){
      B[i]=A[i+1]-A[i];
    }
    sort(ALL(B));
    int sum = 0;
    REP(i,M-N){
      sum+=B[i];
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1024
s = input().split()
N = int(s[0])
Y = int(s[1])

for a in range(N + 1):
    for b in range(N - a + 1):
        c = N - a - b
        if a * 10000 + b * 5000 + c * 1000 == Y:
            print(str(a) + " " + str(b) + " " + str(c))
            exit(0)

print("-1 -1 -1")


Measured memory_bytes: 3060
import java.util.*;
import java.util.ArrayList;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
	       Scanner sc = new Scanner(System.in);
           int N = sc.nextInt();
		////////////入力/////////////////////////////////
		  //Listに入力///////////////////////////////////////
		  ArrayList<String> list = new ArrayList<String>();
		  for(int i =0;i<N;i++) {
			  String A = sc.next();
			  list.add(A);
		   }
      //System.out.println(list);
      		  //List内の要素の出現回数をカウント//////////////////////////////////////
			Map<String, Long> counts = list.stream()
				    .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
      System.out.println(counts.size());
    }
}

Measured memory_bytes: 84120
#include <stdio.h>

int main() {
	int n, i, j, k, l, p[101], m[101][101];
	
	scanf("%d", &n);
	for ( i = 1; i <= n; i++) {
		scanf("%d", &p[i - 1]);
		scanf("%d", &p[i]);
	}
	
	for ( i = 1; i <= n; i++) {
		m[i][i] = 0;
	}
	for ( l = 2; l <= n; l++) {
		for ( i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = ( 1 << 21);
			for ( k = i; k <= j - 1; k++) {
				if ( m[i][j] < m[i][k] + m[k + 1][j] + p[i - 1]*p[k]*p[j]) {
					m[i][j] = m[i][j];
				} else {
					m[i][j] = m[i][k] + m[k + 1][j] + p[i - 1]*p[k]*p[j];
				}
			}
		}
	}
	
	printf("%d\n", m[1][n]);
	
	return 0;
}

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

using namespace std;

int main(){
    int N,M,ans=0;
    cin >> N >> M;

    vector<vector<int>> graph(N);
    vector<int> color(N,-1);

    for(int i=0;i<M;i++){
        int x,y,z;
        cin >> x >> y >> z;
        x--;
        y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    for(int i=0;i<N;i++){

        queue<int> Q;

        if(color[i]==-1){
            color[i] = ans;
            ans++;
            Q.push(i);
        }

        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            for(int j=0;j<graph[now].size();j++){
                if(color[graph[now][j]]==-1){
                    color[graph[now][j]] = color[i];
                    Q.push(graph[now][j]);
                }
            }
        }
    }

    cout << ans << endl;
}

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

void solve(int N){
    long long sum = 0;
    int mx = -1;
    int mn = 10001;
    for(int i=0;i<N;i++){
        int a;cin>>a;
        sum += a;
        mx = max(mx,a);
        mn = min(mn,a);
    }
    sum -= mx;
    sum -= mn;

    cout << sum / (N-2) << endl;
}

int main(){
    int N;
    while(cin>>N){
        if(N==0) break;
        solve(N);
    }
}

Measured memory_bytes: 1156
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanLine() []int {
	var n []int
	scanner.Scan()
	for _, v := range strings.Split(scanner.Text(), " ") {
		var i int
		i, _ = strconv.Atoi(v)
		n = append(n, i)
	}
	return n
}

func main() {
	var n int
	fmt.Scan(&n)
	a, b, c := scanLine(), scanLine(), scanLine()

	result := 0
	prev := 0
	for i, v := range a {
		result += b[v-1]
		if i != 0 {
			if prev+1 == v {
				result += c[v-2]
			}
		}
		prev = v
	}

	fmt.Println(result)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int a,b;
int main(void)
{
  int tim=0;
  while(cin >> a >> b && a)
    {
      if(a==0 && b==0) break;
      if(tim!=0)
	{
	  cout << endl;
	}
      tim++;
      vector<int> ans;
  for(int i=a;i<=b;i++)
    {
      if(i%4==0 && i%100!=0) 
	{
	  ans.push_back(i);
	  continue;
	}
      if(i%400==0) ans.push_back(i);
      
    }
  if(ans.size()==0)
    {
      cout << "NA" << endl;
    }
  else
    {
      for(int i=0;i<int(ans.size());i++)
	{
	  cout << ans[i] << endl;
	}
    }
    }
  return 0;
}



Measured memory_bytes: 3088
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    _ = I()
    a_list = input().split()

    c = Counter(a_list)
    n = {}
    t = 0
    for k, v in c.items():
        n[k] = v - 1
        if v >= 2:
            t += int(v * (v - 1) / 2)

    for a in a_list:
        print(t - n[a])
    pass


if __name__ == "__main__":
    main()


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

int main() {
	int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  rep(i,n) {
  	if(a[i] == a[i+1]) {
    	cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int chmin(int a, int b)
{
	if (a > b)
		return b;
	else
		return a;
}


int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	int dp[n];
	int h[n];
	for (int i = 0; i < n; ++i)
		dp[i] = 10000;

	for (int i = 0; i < n; ++i)
		scanf("%d", &h[i]);

	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; ++i)
		dp[i] = chmin(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	printf("%d\n", dp[n - 1]);
	return 0;
}


Measured memory_bytes: 896
//vector には.find() がなぜかないのでアルゴリズムを使う

#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

int main() {
    int i,j;
    int n,q,C=0;
    int buf;
    vector<int> S, T;
    
    //入力
    cin >> n;
    for(i=0; i<n; i++){ cin >> buf; S.push_back(buf); }
	cin >> q;
    for(i=0; i<q; i++){ cin >> buf; T.push_back(buf); }
    
    //探索
    C=0;
    vector<int>::iterator itr;
    for(i=0; i<q; i++){
        itr = find( S.begin(),S.end() , T.at(i) );
        if( itr != S.end() ) C++;
    }
    
    cout << C << endl;
    
	return 0;
}

Measured memory_bytes: 1804
N = int(input())
guide = [[0]] * N

for i in range(N):
  guide[i]= [i + 1]
  guide[i] += input().split()
  guide[i][2] = int(guide[i][2])

guide.sort(key = lambda x:x[2], reverse = True)
guide.sort(key = lambda x:x[1])

for i in range(N):
    print(guide[i][0])


  

Measured memory_bytes: 3060
local s=io.read()
local n=#s
local k=io.read("n")
local t1={}
for i=1,k do
    for j=1,n-i+1 do
        local sub=s:sub(j,j+i-1)
        table.insert(t1,sub)  
    end
end
table.sort(t1)

local t2={t1[1]}
for i=1,#t1-1 do
    if t1[i]~=t1[i+1] then
        table.insert(t2,t1[i+1])
    end
end
print(t2[k])

Measured memory_bytes: 3980
#include <stdio.h>
#define N 500000
#define INFTY 1000000000

int c;
void merge(int *A, int left, int mid, int right){
    int n1, n2, R[N], L[N];
    int i, j, k;
  n1 = mid - left;
  n2 = right - mid;
  //L[0...n1], R[0...n2] を生成
  for(i = 0; i<n1; i++) L[i] = A[left + i];
  for(i = 0; i<n2; i++) R[i] = A[mid + i];
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for(k = left; k<right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{
      A[k] = R[j];
      j = j + 1;
    }
    c++;
    }
}

void mergeSort(int *A, int left, int right){
    int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main(void){
    int A[N], n, i;
    scanf("%d", &n);
    for(i=0; i<n; i++) scanf("%d", &A[i]);
    c=0;
    mergeSort(A, 0, n);
    for(i=0; i<n-1; i++) printf("%d ", A[i]);
    printf("%d\n", A[n-1]);
    printf("%d\n", c);
    return 0;
}


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define PB push_back
#define SORT(v) sort(v.begin(), v.end())
#define REVSORT(v) sort(v.begin(), v.end(), std::greater<int>())

typedef long long ll;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,a="CODEFESTIVAL2016";
	cin >> s;
	int c = 0;
	rep(i, 0, 16){
		if (s[i] != a[i])c++;
	}
	cout << c << endl;



	return 0;
}


Measured memory_bytes: 256
#template
from collections import Counter
def inputlist(): return [int(i) for i in input().split()]
#template
H,W,K = inputlist()
cake = ['0']*H
for i in range(H):
    cake[i] = list(input())
seen = [[False]*W for _ in range(H)]
ans = [[0]*W for _ in range(H)]
indexa = 1
for x in range(H):
    for y in range(W):
        if cake[x][y] == '#':
            ans[x][y] = indexa
            indexa +=1
for x in range(H):
    for y in range(1,W):
        if ans[x][y-1] != 0:
            if ans[x][y] == 0:
                ans[x][y] = ans[x][y-1]
for x in range(H):
    for j in range(1,W):
        y = (W-1)-j
        if ans[x][y+1] != 0:
            if ans[x][y] == 0:
                ans[x][y] = ans[x][y+1]
for x in range(1,H):
    for y in range(W):
        if ans[x-1][y] != 0:
            if ans[x][y] == 0:
                ans[x][y] = ans[x-1][y]
for i in range(1,H):
    x = (H-1)-i
    for y in range(W):
        if ans[x+1][y] != 0:
            if ans[x][y] == 0:
                ans[x][y] = ans[x+1][y]
for i in range(H):
    print(*ans[i])

Measured memory_bytes: 9296
#include<stdio.h>
#include<string.h>
typedef long long ll;
using namespace std;
int main()
{
    int a,b,c,ans;
    scanf("%d%d%d",&a,&b,&c);
    ans=c-a+b;
    if(ans<0)ans=0;
    printf("%d\n",ans);
}


Measured memory_bytes: 128
N,M,Q = map(int,input().split())

dp = [[0 for _ in range(N)] for _ in range(N)]

for _ in range(M):
    l,r = map(int,input().split())
    l -= 1
    r -= 1
    
    dp[l][r] += 1

for l in range(N):
    for r in range(N-1):
        dp[l][r+1] += dp[l][r]

for r in range(N):
    for l in range(N-1):
        dp[l+1][r] += dp[l][r]

# dp[l][r]は左端がl以下右端がr以下の電車の本数を表す   
for _ in range(Q):
    p,q = map(int,input().split())
    p -= 1
    q -= 1
    
    if p >= 1:
        print(dp[N-1][q]-dp[p-1][q])
    else:
        print(dp[N-1][q])


Measured memory_bytes: 13428
#include <cstdio>
#include <functional>
#include <vector>

#include <cstdint>

constexpr bool parity64(std::uint_fast64_t c) noexcept {
  c ^= c >> 1;
  c ^= c >> 2;
  return ((c & 0x1111111111111111) * 0x1111111111111111 >> 60 & 0x1) != 0;
}

int scan() {
  int r = 0;
  int c;
  while ((c = getchar_unlocked() - '0') >= 0)
    r = r * 10 + c;
  return r;
}

int main() {
  const int n = scan();
  std::vector<std::vector<int>> t(n);
  for (int i = 0; i != n - 1; i += 1) {
    const int a = scan() - 1;
    const int b = scan() - 1;
    t[a].push_back(b);
    t[b].push_back(a);
  }
  const int m = scan();
  const int s = 1 << m;
  std::vector<int> z(s, 0);
  {
    std::vector<int> x(n, 0);
    for (int i = 0; i != m; i += 1) {
      const int u = scan() - 1;
      const int v = scan() - 1;
      x[u] ^= 1 << i;
      x[v] ^= 1 << i;
    }
    const auto dfs = [&](const auto &dfs, int v, int p) ->void {
      for (int e : t[v]) {
        if (e == p)
          continue;
        dfs(dfs, e, v);
        z[x[e]] += 1;
        x[v] ^= x[e];
      }
    };
    dfs(dfs, 0, n);
  }
  for (int w = 1; w != s; w <<= 1) {
    for (int i = 0; i != s; i += w << 1) {
      const int end = i + w;
      for (int j = i; j != end; j += 1) {
        z[j + w] += z[j];
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i != 1 << m; i += 1) {
    auto res = 1LL << z[s - 1 ^ i];
    if (parity64(i))
      res = -res;
    ans += res;
  }
  printf("%lld", ans);
}

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    ll A, B, C; cin >> A >> B >> C;

    ll ans = 0;
    if (A % 2 != 0 && B % 2 != 0 && C % 2 != 0){
        ans = min({A*B, B*C, C*A});
    }

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


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

int main(){
	string inp;
	cin >> inp;
	int inp_size = inp.size();
	int hight[20000] = {0};
	int area[10000] = {0};
	for (int i = 0; i < inp_size; i++){
		if (inp[i] == '/'){
			hight[i+1] = hight[i] + 1;
		}
		else if (inp[i] == '_'){
			hight[i+1] = hight[i];
		}
		else {
			hight[i+1] = hight[i] - 1;
		}
	}

	// calc areas
	int x = inp_size;
	int num = 0;
	int sum = 0;
	while(x > 0){
		if (hight[x] > hight[x-1]){
			int y = x;
			for (int j = x-1; j >= 0; j--){
				if (hight[x] == hight[j]) {
					y = j;
					// calc area
					for (int i = y; i < x; i++){
						if (hight[i] > hight[i+1]){
							area[num] += (hight[y] - hight[i+1] - 1) * 2 + 1;
						}
						else if  (hight[i] == hight[i+1]){
							area[num] += hight[y] - hight[i+1];
						}
					}
					sum += area[num];
					num++;
					x = y;
					break;
				}
				if (j == 0) x--;
			}
		}
		else {
			x--;
		}
	}
	cout << sum << endl;
	cout << num;
	for (int i = num-1; i >= 0; i--) cout << " " << area[i];
	cout << endl;
}


Measured memory_bytes: 3396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// const long double PI = acos(-1);
constexpr int inf = 1e9;
constexpr ll INF = 2e18;
// constexpr ll MOD = 1e9+7;
constexpr ll MOD = 998244353;

int n,w,d;
vector<pair<ll,ll>> v;

void solve();

void input() {
    cin >> n >> w >> d;
    for (int i = 0; i < n; i++) {
        ll x,y;
        char f;
        cin >> x >> y >> f;
        ll left,right,mid;
        switch(f) {
            case 'E':
                mid = w + d - y;
                left = mid - w + x;
                right = mid + w - x;
                break;
            case 'S':
                mid = w * 2 + d - x;
                left = mid - y;
                right = mid + y;
                break;
            case 'W':
                mid = w * 2 + d + y;
                left = mid - x;
                right = mid + x;
                break;
            case 'N':
                mid = x;
                left = mid - d + y;
                right = mid + d - y;
                break;
        }
        if (right > 2 * (w + d)) {
            left -= 2 * (w + d);
            right -= 2 * (w + d);
        }
        v.push_back({right,left});
        v.push_back({right + 2 * (w + d), left + 2 * (w + d)});
    }
    sort(v.begin(),v.end());
    solve();

}

void solve() {
    // for (int i = 0; i < v.size(); i++) {
    //     cout << v[i].first << " " << v[i].second << endl;
    // }
    int ans = n;
    for (int i = 0; i < n; i++) {
        int cnt = 1;
        int right = v[i].first;
        for (int j = 1; j < n; j++) {
            if (v[i + j].second > right) {
                cnt++;
                right = v[i + j].first;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

int main(int argc, char *argv[]) {
    input();
    return 0;
}



Measured memory_bytes: 3152
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll l;
    cin>>l;
    double temp=l;
    cout<<fixed<<setprecision(15);
    cout<<((temp/3)*(temp/3)*(temp/3));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 12032
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    long long X,A,B;
    
    cin >> X;
    cin >> A;
    cin >> B;
    
    if ( B <= A ) {
        cout << "delicious" << endl;
    }
    else if ( B - A <= X ) {
        cout << "safe" << endl;
    }
    else {
        cout << "dangerous" << endl;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
vector<int> nex[114];
int dis[114][114];
signed main(){
	int n;
	cin>>n;
	int col = 0, lvs = inf;
	for(int i=1;i<=100;i++){ //init
		for(int j=1;j<=100;j++){
			dis[i][j] = inf;
			if( i == j ) dis[i][j]  = 0;
		}
	}
	for(int i=0;i<n-1;i++){ //input
		int x,y;
		cin>>x>>y;
		nex[x].pb(y);
		nex[y].pb(x);
		dis[x][y] = 1;
		dis[y][x] = 1;
	}
	for(int k=1;k<=n;k++){ //warshall-floyd
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if( dis[i][j] > dis[i][k] + dis[k][j] ){
					dis[i][j] = dis[i][k] + dis[k][j];
				}
			}
		}
	}
	int dia = -1, lef = -1, rig = -1;
	for(int i=1;i<=n;i++){ // finding diameter
		for(int j=1;j<=n;j++){
			if( dis[i][j] > dia ){
				dia = dis[i][j];
				lef = i;
				rig = j;
			}
		}
	}
	vector< pair<int,int> > centers;
	int single_center = -1;
	if( dia % 2 == 0){ // finding centers
		for(int i=1;i<=n;i++){
			if( dis[rig][i] == dia/2 && dis[lef][i] == dia/2){
				single_center = i;
				break;
			}
		}
		for(int i=1;i<=n;i++){
			if( dis[i][single_center] == 1){
				centers.pb( mp( i, single_center) );
			}
		}
	}
	else{
		vector<int> cts;
		for(int i=1;i<=n;i++){
			if( dis[rig][i] + dis[lef][i] == dia && abs(dis[rig][i] - dis[lef][i]) == 1){
				cts.pb(i);
			}
			if( cts.size() == 2){
				centers.pb( mp( cts[0], cts[1] ) );
				break;
			}
		}
	}
	col = dia/2 + 1; // clearly
	if( single_center != -1){
		int tlvs = 1;
		for(int i=0;i<=dia/2-1;i++){
			vector<int> cur;
			for(int j=1;j<=n;j++){
				if( dis[single_center][j] == i ){
					cur.pb(j);
				}
			}
			int edamax = 1;
			for(int j=0;j<cur.size();j++){
				int eda = 0;
				for(int k=1;k<=n;k++){
					if( dis[cur[j]][k] == 1 && dis[single_center][k] == i+1)eda++;
				}
				if(eda > edamax) edamax = eda;
			}
			tlvs *= edamax;
		}
		if( tlvs < lvs ) lvs = tlvs;
	}
	for(int q=0;q<centers.size();q++){
		int tlvs = 2;
		int lc = centers[q].first;
		int rc = centers[q].second;
		int pos[101]; // 0 lef 1 rig
		for(int i=1;i<=n;i++){
			if( dis[lc][i] < dis[rc][i] )pos[i] = 0;
			else pos[i] = 1;
		}
		for(int i=0;i<=dia/2-1;i++){
			vector<int> cur;
			for(int j=1;j<=n;j++){
				if( ( pos[j] == 0 && dis[lc][j] == i) || ( pos[j] == 1 && dis[rc][j] == i) ){
					cur.pb(j);
				}
			}
			int edamax = 1;
			for(int j=0;j<cur.size();j++){
				int eda = 0;
				for(int k=1;k<=n;k++){
					if( dis[cur[j]][k] == 1 && pos[ cur[j] ] == 0 && pos[k] == 0 && dis[lc][k] == i+1 )eda++;
					if( dis[cur[j]][k] == 1 && pos[ cur[j] ] == 1 && pos[k] == 1 && dis[rc][k] == i+1 )eda++;
				}
				if(eda > edamax) edamax = eda;
			}
			tlvs *= edamax;
		}
		if( tlvs < lvs ) lvs = tlvs;
	}
	cout<<col<<" "<<lvs<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;



int main() {
  int A, P; cin >> A >> P;
  int S = (A * 3 + P) / 2;
  cout << S << endl;

	return 0;

}



Measured memory_bytes: 3632
#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()
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int sum =0;
	for(int i=1;;i++)
	{
		int f;
		cin >> f;
		if(f==0)
		{
			break;
		}
		cout<<"Case "<<i<<": "<<f<<endl;
	}
	
	return 0;
}


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

using namespace std;

int H, W, Q;
string S[2000];
int yoko[2005][2005];
int tate[2005][2005];
int beet[2005][2005];


int main()
{
  cin >> H >> W >> Q;
  for(int i = 0; i < H; i++) {
    cin >> S[i];
  }

  for(int i = 0; i < H; i++) {
    for(int j = 1; j < W; j++) {
      if(S[i][j - 1] == '1' && S[i][j] == '1') {
        yoko[i][j]++;
      }
      yoko[i][j] += yoko[i][j - 1];
    }
  }

  for(int i = 1; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(S[i - 1][j] == '1' && S[i][j] == '1') {
        tate[i][j]++;
      }
      tate[i][j] += tate[i - 1][j];
    }
  }

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(S[i][j] == '1') {
        beet[i + 1][j + 1]++;
      }
      beet[i + 1][j + 1] += beet[i + 1][j] + beet[i][j + 1] - beet[i][j];
    }
  }

  while(Q--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a, --b;

    int latte = beet[c][d] + beet[a][b] - beet[c][b] - beet[a][d];
    int malta = 0;
    for(int i = a; i < c; i++) {
      malta += yoko[i][d - 1] - yoko[i][b];
    }
    for(int i = b; i < d; i++) {
      malta += tate[c - 1][i] - tate[a][i];
    }

    cout << latte - malta << endl;

    //cout << latte << " " << malta << endl;

  }
}

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

int main()
{
	int N, M;
	cin >> N;
	vector<int> D( N );
	for( int i = 0; i < N; i++ ) {
		cin >> D[i];
	}
	cin >> M;
	vector<int> T( M );
	for( int i = 0; i < M; i++ ) {
		cin >> T[i];
	}

	sort( D.begin(), D.end() );
	sort( T.begin(), T.end() );
	string ans = "YES";
	int j = 0;
	for( int i = 0; i < M; i++ ) {
		while( T[i] > D[j] ) {
			j++;
		}
		if( j >= N || D[j] > T[i] ) {
			ans = "NO";
			break;
		}
		else j++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 1920
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;
typedef unsigned long long ull;

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

    if(t*s>=d)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 1660
N, M = map(int, input().split())
P = [int(i) for i in input().split()]

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1 for _ in range(n)]
        
    def same(self, x, y):
        return self.root(x)==self.root(y)
 
    def root(self, x):
        if self.par[x]<0:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]
 
    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
 
        if self.par[x] > self.par[y]:
            x,y = y,x
 
        self.par[x] += self.par[y]
        self.par[y] = x
        
uf = UnionFind(N)

for i in range(M):
    x, y = map(int, input().split())
    uf.unite(x - 1, y - 1)
    
cnt = 0
for i in range(N):
    if uf.same(i, P[i] - 1):
        cnt += 1
        #print(i, P[i])
        
print(cnt)

Measured memory_bytes: 13812
a, b = map(int, input().split())

ans = -1
for i in range(1,10000):
    a_tax = int((i * 0.08)//1)
    b_tax = int((i * 0.1)//1)
    if a == a_tax and b == b_tax:
        ans = i
        break
print(ans)

Measured memory_bytes: 2940
#include <cstdio>
int n, s;
int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
int main(){
	scanf("%d", &n);
	for (register int i = 1, x; i <= n; ++i)
		scanf("%d", &x), s = gcd(s, x);
	printf("%d\n", s);
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		int a = fs.nextInt();
		int b = fs.nextInt();
		int c = fs.nextInt();
		int k = fs.nextInt();
		
		int ans = 0;
		
		if(a >= k) {
			System.out.println(k);
			return;
		}
		
		ans += a;
		k -= a;
		if(k <= b) {
			System.out.println(ans);
			return;
		}
		
		k -= b;
		System.out.println(ans - k);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 32556
la = list()
lb = list()
casenum = 0;

while True:
    a,b = map(int, input().split())
    if a==0 and b==0: break
    
    la.append(a)
    lb.append(b)

for num in la:

    if la[casenum]<lb[casenum]:
        print(la[casenum],lb[casenum])
    else:
        print(lb[casenum],la[casenum])
    casenum +=1
        


Measured memory_bytes: 6120
if __name__ == '__main__':
    N, M = map(int, input().split())
    X = sorted(list(map(int, input().split())))
    if len(X) <= N:
        print(0)
        exit()

    diff = sorted([X[idx + 1] - x for idx, x in enumerate(X[:-1])], reverse=True)
    print(sum(diff[N - 1:]))

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

typedef long long ll;

const int N = 100000;

bool searchP(int A[], ll P, int k, int n)
{
  int i = 0;
  for(int j = 0;j < k;j++){
    ll st = 0;
    while(st + A[i] <= P){
      st += A[i++];
      if(i == n) return true; //トラックが余分な場合、もしくはk台以内で十分運べる場合
    }
  }
  return false; //トラックが足りない
}

int main()
{
  int n,k;
  int a[N+1]={};

  cin >> n >> k;
  for(int i = 0;i < n;i++) cin >> a[i];
  
  ll left = 0;
  ll right = N*10000; //Pはコストの和なので、n*wiのワーストケースで初期化する
  ll mid_P;
  //二分探索してPを探索する。Pを探索するので、leftとrightはPの範囲で考えることに気を付ける
  
  while(right - left > 1){
    mid_P = (left + right)/2;

    bool result = searchP(a, mid_P, k, n);
    
    if(result) right = mid_P; //pointer shifts to left;
    else left = mid_P; //pointer shifts to right;
  }
  ll ans = right;
  
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3512
#include <iostream>
#include <string.h>
#include <queue>
using namespace std;
struct q{
    int x,y,color,cnt;
};
queue <q> pipe;
q Main,sub;
int sy,sx;
int gy,gx;
int w,h,n;
int board[101][101];
int visited[101][101];
int state[4];

void put(int mode,int color,int x,int y);

int main(void){
    cin>>w>>h;
    while(w!=0&&h!=0){
        cin>>sx>>sy;
        cin>>gx>>gy;
        cin>>n;
        memset(board,0,sizeof(board));
        memset(visited,0,sizeof(visited));
        for(int i=0;i<n;i++){
            cin>>state[0]>>state[1]>>state[2]>>state[3];
            put(state[1],state[0],state[2],state[3]);
        }
        
        Main.x=sx;
        Main.y=sy;
        Main.cnt=0;
        Main.color=board[sx][sy];
        visited[sx][sy]=1;
        pipe.push(Main);
        
        int mx,fx[]={0,1,0,-1};
        int my,fy[]={1,0,-1,0};
        
        while(!pipe.empty()){
            Main=pipe.front();
            pipe.pop();
            for(int i=0;i<4;i++){
                mx=Main.x+fx[i];
                my=Main.y+fy[i];
                if(mx>=1&&mx<=100&&my>=1&&my<=100&&Main.color==board[mx][my]&&visited[mx][my]==0){
                    sub=Main; visited[mx][my]=1;
                    sub.x=mx; sub.y=my; sub.cnt++;
                    pipe.push(sub);
                }
            }
        }
        if(visited[gx][gy]==1){cout<<"OK"<<endl;}
        else{cout<<"NG"<<endl;}
        cin>>w>>h;
    }
}

void put(int mode,int color,int x,int y){
    int X[2],Y[2];
    X[0]=4; Y[0]=2;
    X[1]=2; Y[1]=4;
    for(int i=x;i<x+X[mode];i++){
        for(int j=y;j<y+Y[mode];j++){
            board[i][j]=color;
        }
    }
}


Measured memory_bytes: 3120
import numpy as np
N,M = map(int,input().split())
cards = list(map(int,input().split()))
exchange_lists=[]
for i in range (M):
  exchange_lists.append(list(map(int,input().split())))
exchange_lists.sort(key = lambda x:x[1],reverse=True)
cards.sort()
count = 0
for i in range(M):
  exchange=exchange_lists[i]
  num = 0
  for j in range(count,N):
    if (exchange[1] > cards[j])and(exchange[0] > num):
      cards[j] = exchange[1]
      count += 1
      num+=1
    else:
      break
  
print(np.sum(cards))

Measured memory_bytes: 41792
#include <iostream>
#include <queue>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;
#define x first
#define y second
#define mp make_pair

const int MAXN = (int)2e3;
int n, X, Y, br[MAXN + 5], dist[MAXN + 5];
vector <int> ms[MAXN + 5];
bool bio[MAXN + 5];

void bfs(int x){
	memset(bio, 0, sizeof(bio));
	memset(dist, 0, sizeof(dist));
	queue <int> q;
	q.push(x);
	bio[x] = 1;
	while(!q.empty()){
		x = q.front();
		q.pop();
		for(vector <int>::iterator i = ms[x].begin() ; i != ms[x].end() ; ++i){
			int o = *i;
			if(bio[o])
				continue;
			bio[o] = 1;
			dist[o] = dist[x] + 1;
			q.push(o);
		}
	}
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> X >> Y;
for(int i = 1 ; i < n ; ++i){
	ms[i].push_back(i + 1);
	ms[i + 1].push_back(i);
}
ms[X].push_back(Y);
ms[Y].push_back(X);
for(int i = 1 ; i <= n ; ++i){
	bfs(i);
	for(int i = 1 ; i <= n ; ++i){
		br[dist[i]]++;
	}
}
for(int i = 1 ; i < n ; ++i){
	cout << br[i] / 2 << endl;
}

return 0;
}



Measured memory_bytes: 384
s=input()
if s=="MON":
    print(6)
elif s=="TUE":
    print(5)
elif s=="WED":
    print(4)
elif s=="THU":
    print(3)
elif s=="FRI":
    print(2)
elif s=="SAT":
    print(1)
elif s=="SUN":
    print(7)

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

int main(){
	vector<int> top(3);
	int height;
	while(cin >> height){
		for(vector<int>::iterator itr = top.begin(); itr != top.end(); ++itr){
			if(height > *itr){
				top.insert(itr, height);
				top.pop_back();
				break;
			}
		}
	}
	for(vector<int>::iterator itr = top.begin(); itr != top.end(); ++itr){
		cout << *itr << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> num(2*M);
  for(int i=0;i<M;i++){
    cin >> num.at(2*i) >> num.at(2*i+1);
  }
  for(int j=0;j<N;j++){
    int t=0;
    for(int k=0;k<2*M;k++){
      if(num.at(k)==j+1){
        t++;
      }
    }
    cout << t << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
 		
int main() {
	
	int N,X;
	cin>>N>>X;
	vec(A)
	int some=0;
	fx(N){
		vecp(A)
		some+=A.at(x);
	}
	sorts(A);
	int ans=N;
	ans+=(X-some)/A.at(0);
	ce(ans)
	
}


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

using namespace std;

int main()
{
    int N, D, X;
    cin >> N >> D >> X;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    int sumchoco = X;
    for (int i = 0; i < N; i++){
        for (int j = 0; j * A.at(i) + 1 <= D; j++){
            sumchoco++;
        }
    }
    cout << sumchoco << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while (true) {
            int w = sc.nextInt();
            int h = sc.nextInt();
            if (h == 0 && w == 0) {
                break;
            }
            ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
            for (int i = 0; i < h * w; i++) {
                graph.add(new ArrayList<>());
            }
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w - 1; j++) {
                    if (sc.nextInt() == 0) {
                        int a = i * w + j;
                        int b = a + 1;
                        graph.get(a).add(b);
                        graph.get(b).add(a);
                    }
                }
                if (i == h - 1) {
                    break;
                }
                for (int j = 0; j < w; j++) {
                    if (sc.nextInt() == 0) {
                        int a = i * w + j;
                        int b = a + w;
                        graph.get(a).add(b);
                        graph.get(b).add(a);
                    }
                }
            }
            int[] costs = new int[h * w];
            Arrays.fill(costs, Integer.MAX_VALUE);
            PriorityQueue<Path> queue = new PriorityQueue<>();
            queue.add(new Path(0, 1));
            while (queue.size() > 0) {
                Path p = queue.poll();
                if (costs[p.idx] <= p.value) {
                    continue;
                }
                costs[p.idx] = p.value;
                for (int x : graph.get(p.idx)) {
                    queue.add(new Path(x, p.value + 1));
                }
            }
            if (costs[h * w - 1] == Integer.MAX_VALUE) {
                sb.append(0);
            } else {
                sb.append(costs[h * w - 1]);
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }
    
    static class Path implements Comparable<Path> {
        int idx;
        int value;
        
        public Path(int idx, int value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Path another) {
            return value - another.value;
        }
    }
}



Measured memory_bytes: 78444
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N, M, Q = map(int, readline().split())

kumi = []
for _ in range(Q):
    tmp = list(map(int, readline().split()))
    kumi.append(tmp)

ans = 0
res = []
def F(l):
    if len(l) == N:
        ans = 0
        for i in range(Q):
            a, b, c, d = kumi[i]
            if l[b-1] - l[a-1] == c:
                ans += d
        yield ans
        return
    start = l[-1] if len(l) else 0
    for i in range(start, M):
        l.append(i)
        yield from F(l)
        l.pop()
    
ans = max(F([]))
print(ans)

Measured memory_bytes: 9308
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
	return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		ans %= mod;
		fact_memo[i + 1] = ans;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) swap(n, r);
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) swap(n, r);
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

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

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

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

int n, k;
signed main() {
	cin >> n >> k;
	for (int i = 1; i <= k; i++) {
		if (i == 1) {
			cout << n - k + 1 << endl;
		}
		else {
			int cnt = 0;
			rep(j, n - k) {
				int r = n - k - j;
				if (r < i - 1) break;
				cnt += (j + 1) * comb(r - 1, i - 2);
				if (mod <= cnt) cnt %= mod;
			}
			cnt *= comb(k - 1, i - 1);
			if (mod <= cnt) cnt %= mod;
			cout << cnt << endl;
		}
	}
}

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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<char>> matr(H, vector<char>(W));
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            cin >> matr.at(i).at(j);
        }
    }
    for (int i = 0; i < W + 2; ++i)
    {
        cout << '#';
    }
    for (int i = 0; i < H; ++i)
    {

        cout << endl
             << '#';
        for (int j = 0; j < W; ++j)
        {
            cout << matr.at(i).at(j);
        }
        cout << '#';
    }
    cout << endl;
    for (int i = 0; i < W + 2; ++i)
    {
        cout << '#';
    }
    cout << endl;
}

Measured memory_bytes: 3576
from math import log
from math import ceil

x = int(input())

left = 1
right = 3760

# にぶたん
while right - left != 1:
    mid = (right + left) // 2
    money = 100
    for i in range(mid):
        money = int(money * 1.01)
    if money >= x:
        right = mid
    else:
        left = mid
print(right)



Measured memory_bytes: 9176
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main()
{
int x=0,y=0,z=0,w=0,n=0,m=0;
string s;
std::cin >>s;
if(s=="a"||s=="e"||s=="i"||s=="o"||s=="u")std::cout << "vowel" << '\n';
else std::cout << "consonant" << '\n';
}


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

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);
		int c = Integer.parseInt(s[2]);
		if(a < b && b < c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 24368