akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

//dp[i+1][j] --- i番目まで(i = 0, 1, 2)の硬貨を何枚か選んだ時に、
//               合計金額がj/50円になる場合の数
//dp[3][X/50]が求める数
//dp[0][0] = 1;
//dp[i+1][j] = sum(dp[i][j - k*x]) (0<=k<=n) (x/50円の硬貨をk枚使う) 
//dp[i+1][j - x] = sum(dp[i][j - (p+1)*x]) (0<=p<=n-1)
//dp[i+1][j] = dp[i+1][j-x] + dp[i][j];
//枚数制限あるからこの式使えない....
int dp[5][2500];
int A[3];
int val[3] = {10, 2, 1};
int X;
int main()
{
    for(int i = 0; i < 3; ++i) cin >> A[i];
    cin >> X;
    X /= 50;
    dp[0][0] = 1;
    for(int i = 0; i < 3; ++i) {
        for(int j = 0; j <= X; ++j) {
            for(int k = 0; j - k*val[i] >= 0 && k <= A[i]; ++k) {
                dp[i+1][j] += dp[i][j - k*val[i]];
            }
        }
    }
    cout << dp[3][X] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

import static java.lang.StrictMath.abs;

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();
        int ans =2*s.length();
        for(int i=0; i<= n; i++){
            if(s.substring(s.length()-i).equals(t.substring(0,i))){
                ans = 2*s.length()-i;
            }
        }
        System.out.println(ans);


    }
}


Measured memory_bytes: 21588
#include <stdio.h>
int main(void){
    int H , W ;
    while(1){
        scanf("%d %d" , &H , &W);
        if(H == 0 && W == 0){break;}
        for(int i = 1 ; i <= 1 ; i++){
            for(int j = 1 ; j <= W ; j++){
                printf("#");
            }
            printf("\n");
        }
        for(int x = 2 ; x <= H-1 ; x++){
            printf("#");
            for(int y = 1 ; y <= W - 2 ; y++){
                printf(".");
            }
            printf("#\n");
        }
        for(int a = 1 ; a <= 1 ; a++){
            for(int b = 1 ; b <= W ; b++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2068
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
int a[100000][3];
int F(int num)
{
    int ans;
    int dp[num+1][3];
    
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
     
   for(int i=1;i<=num;i++)
   {
    for(int j=0;j<3;j++)
    {
        if(j==0)
        dp[i][j]=max((a[i][j]+dp[i-1][j+1]),(a[i][j]+dp[i-1][j+2]));
        else if(j==1)
        dp[i][j]=max((a[i][j]+dp[i-1][j-1]),(a[i][j]+dp[i-1][j+1]));
        else 
        dp[i][j]=max((a[i][j]+dp[i-1][j-1]),(a[i][j]+dp[i-1][j-2]));
    }

   }
   
    int res[3];
    res[0]=dp[num][0];
    res[1]=dp[num][1];
    res[2]=dp[num][2];
    
    ans=max(max(res[0],res[1]),res[2]);
    return ans;
}


int main() {
    int n;

    cin>>n;
   

for(int i=0;i<n;i++)
{
    for(int j=0;j<3;j++)
    cin>>a[i][j];
}
   
   
int ans=F(n-1);
cout<<ans;
return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll h[100010];
int N;
ll A, B;

bool isOK(int num) {
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		ll tmp = h[i];
		tmp = max(0ll, tmp - B * num);
		sum += (tmp + (A - B) - 1) / (A - B);
	}
	if (sum <= num) return true;
	else return false;
}

int binary_search() {
	int ng = -1;
	int ok = mod;
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (isOK(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

int main()
{
	cin >> N >> A >> B;
	for (int i = 0; i < N; i++) cin >> h[i];
	cout << binary_search() << endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
using namespace std;
int n,k,h[100001],dp[100001];
int min(int a,int b){return a<b?a:b;}
int abs(int a){return a>0?a:-a;}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i) scanf("%d",&h[i]);
	memset(dp,127,sizeof(dp)),dp[1]=0;
	for(int i=2;i<=n;++i) for(int j=i-k-min(i-k,0);j<i;++j) dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
	printf("%d",dp[n]);
}

Measured memory_bytes: 896
#!/usr/bin/python3

import array
from fractions import Fraction
import math
import os
import sys


def main():
    Q = read_int()
    for _ in range(Q):
        x0, y0, x1, y1, x2, y2, x3, y3 = read_ints()
        print(*solve(Vec(x0, y0), Vec(x1, y1), Vec(x2, y2), Vec(x3, y3)))


def solve(a, b, c, d):
    p = b - a
    q = c - a
    r = d - a

    k = Fraction(r.cross(q), (r - q).cross(p))
    kp = k * p
    kp += a
    return float(kp.x), float(kp.y)


###############################################################################
# AUXILIARY FUNCTIONS

class Vec(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
        super().__init__()

    def __add__(self, other):
        return Vec(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vec(self.x - other.x, self.y - other.y)

    def __mul__(self, scalar):
        return Vec(self.x * scalar, self.y * scalar)

    def __rmul__(self, scalar):
        return Vec(self.x * scalar, self.y * scalar)

    def __truediv__(self, scalar):
        return Vec(self.x / scalar, self.y / scalar)

    def __iadd__(self, other):
        self.x += other.x
        self.y += other.y
        return self

    def __isub__(self, other):
        self.x -= other.x
        self.y -= other.y
        return self

    def __imul__(self, scalar):
        self.x *= scalar
        self.y *= scalar
        return self

    def __idiv__(self, scalar):
        self.x /= scalar
        self.y /= scalar
        return self

    def __neg__(self):
        return Vec(-self.x, -self.y)

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    def cross(self, other):
        return self.x * other.y - self.y * other.x

    def abs2(self):
        return self.x * self.x + self.y * self.y

    def __abs__(self):
        return math.sqrt(float(self.abs2()))

    def __str__(self):
        return '({}, {})'.format(self.x, self.y)


DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



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

int main() {
    int n;
    while (cin >> n, n) {
        string s[n];
        int ans = 0;
        for (int i = 0; i < n; i++) cin >> s[i];
        for (int i = 1; i < n; i++) {
            if (s[i - 1][0] != s[i][0]) {
                if (s[i - 1][1] == s[i][1]) ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

using namespace std;

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

typedef long long int ll;


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

	int n;
	int arr[20];

	cin >> n;
	rep(i , n)
		cin >> arr[i];

    int count = 0;
	for(int i=1 ; i<n-1 ; i++)
	{
		if(arr[i] > arr[i+1] && arr[i] < arr[i-1])
		    count++;
		else if(arr[i] < arr[i+1] && arr[i] > arr[i-1])
		    count++;
	}
	cout << count;
	return 0;
}

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

int main () {
  int a,b,k;
  cin >> a >> b >> k;
  int cnt=0;
  
  for(int i=100;i>0;i--){
    if(a%i==0&&b%i==0){
      cnt++;
    }
    if(cnt==k){
      cout << i << endl;
      break;
    }
  }
}


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


using namespace std;



int main() {
	int n;
	cin >> n;
	vector<int> a(n+2);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int sum = 0;
	for (int i = 1; i <= n + 1; i++) {
		sum += abs(a[i] - a[i - 1]);
	}

	for (int i = 1; i <= n; i++) {
		int sum_i = sum + abs(a[i + 1] - a[i - 1]) - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]);
		cout << sum_i << endl;
	}
	
}

Measured memory_bytes: 1664
N=int(input())
from collections import Counter
tmp=list(input())
da=Counter(tmp)
for _ in range(N-1):
  tmp=list(input())
  tmpd=Counter(tmp)
  for k, v in da.items():
    if not tmpd[k]:
      da[k]=0
    else:
      da[k]=min(v, tmpd[k])
ans=""
for k, v in da.items():
  ans+=str(k)*v
a="".join(sorted(ans))
print(a)

Measured memory_bytes: 9468
N = int(input())
A = list(map(int, input().split()))
currentSum = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0

for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count1 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count1 += abs(currentSum) + 1
        currentSum = -1
    elif currentSum == 0 and restSum == 0:
        count1 += 1
        currentSum = -1

currentSum = 0
for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count2 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count2 += abs(currentSum) + 1
        currentSum = -1
    elif currentSum == 0 and restSum == 0:
        count2 += 1
        currentSum = 1

currentSum = 0
for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count3 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count3 += abs(currentSum) + 1
        currentSum = -1
    elif A[i] <= 0 and restSum == 0:
        count3 += abs(currentSum) + 1
        currentSum = 1
        
currentSum = 0
for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count4 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count4 += abs(currentSum) + 1
        currentSum = -1
    elif A[i] >= 0 and restSum == 0:
        count4 += abs(currentSum) + 1
        currentSum = -1
        
print(min(count1, count2, count3, count4))


Measured memory_bytes: 14332
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <memory.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int,P> PP;
const int INF = 1 << 29;
const int mod = 1000000007;

struct edge{
  int to;
  string s;
  edge(){}
  edge(int to, string s){
    this->to = to;
    this->s = s;
  }
};

bool ok(const string &s1, const string &s2){
  int n = s1.size();
  rep(i, n) if(s1[i] != s2[i]) return false;
  return true;
}


map<string, ll> dp[600][600][2];

vector<edge> G[2][600];


int main(){
  int T;
  cin >> T;
  int n1, m1, n2, m2;
  int a, b;
  string s, nxt;
  edge e;
  rep(t, T){
    cin >> n1 >> m1;
    rep(i, 600)rep(j, 2) G[j][i].clear();
    rep(i, 600)rep(j, 600)rep(k, 2) dp[i][j][k].clear(); 
    rep(i, m1){
      cin  >> a >> b >> s;
      G[0][a].push_back(edge(b, s));
    }
    cin >> n2 >> m2;
    rep(i, m2){
      cin >> a >> b >> s;
      G[1][a].push_back(edge(b, s));
    }
    dp[0][0][0][""] = 1;
    rep(i, n1)rep(j, n2){
      rep(k, 2){
	for(map<string, ll>::iterator iter = dp[i][j][k].begin(); 
	    iter != dp[i][j][k].end(); iter++){
	  string s = (*iter).first;
	  ll d = (*iter).second;
	  if(k == 1){
	    rep(v, (int)G[k][j].size()){
	      e = G[k][j][v];
	      if(e.s.size() < s.size() && ok(e.s, s)){
		nxt = string(s.begin() + e.s.size(), s.end());
		dp[i][e.to][1][nxt] = (dp[i][e.to][1][nxt] + d) % mod;
	      }
	      if(e.s.size() >= s.size() && ok(s, e.s)){
		nxt = string(e.s.begin() + s.size(), e.s.end());
		dp[i][e.to][0][nxt] = (dp[i][e.to][0][nxt] + d) % mod;
	      }
	    }
	  }else{
	    rep(v, (int)G[k][i].size()){ 
	      e = G[k][i][v];
	      if(e.s.size() <= s.size() && ok(e.s, s)){
		nxt = string(s.begin() + e.s.size(), s.end());
		dp[e.to][j][0][nxt] = (dp[e.to][j][0][nxt] + d) % mod;
	      }
	      if(e.s.size() > s.size() && ok(s, e.s)){
		nxt = string(e.s.begin() + s.size(), e.s.end());
		dp[e.to][j][1][nxt] = (dp[e.to][j][1][nxt] + d) % mod;
	      }
	    }
	  }
	}
      }
    }

    cout << dp[n1-1][n2-1][0][""] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#pragma GCC target ("avx,avx2,fma")
#pragma GCC optimize ("unroll-loops")

#include <iostream>
#include <vector>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    const int MOD = 1000000007;
    int n;
    char p;
    cin >> n;
    int upbound = (1 << n);
    vector<int> g(n), dp(upbound);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) {
            cin >> p;
            if(p=='1')
            g[i] |= (1 << j);
        }
    dp[0] = 1;
    for (int x = 1; x < upbound; ++x) {
        int p = __builtin_popcount(x), r = 0;
        for (int y = x & g[p - 1]; y; y &= y - 1)
        {
            r += dp[x & ~(y & -y)];
            if (r >= MOD) r -= MOD;
        }
        dp[x] = r;
    }
    cout << dp[upbound - 1];
}

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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNextN();) {
		// solver.readN(in.readLine());
		// }
		// for (; solver.hasNextM();) {
		// solver.readM(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	public void init() {
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		long N = Long.parseLong(strArr[0]);
		int ans = 0;
		for (long i = N; i > 0; i /= 10) {
			ans++;
		}
		for (long d = 1; d * d <= N; d++) {
			if (N % d == 0) {
				// System.out.println(d);
				if (N / d < d)
					break;
				int dig = 0;
				for (long i = N / d; i > 0; i /= 10) {
					dig++;
				}
				if (ans > dig)
					ans = dig;
			}
		}
		System.out.println(ans);
	}

}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll n, x;

    cin >> n >> x;

  	ll ct = 1;
  	ll d = 0;
  	ll l = 0;
  	REP(i, n){
      	cin >> l;
      	d += l;
      	if (d > x) {
            break;
        }
      	ct++;
    }
  
    cout << setprecision(20) << ct << endl;

    return 0;
}

Measured memory_bytes: 256
#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>v;

	for(int i=0;i<n;i++){
		int h;
		cin>>h;
		h--;
		v.push_back(h);
	}

	int now=0,c=0;

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

		if(now==1){
			cout<<c<<endl;
			return 0;
		}
		if(c>=n){
			cout<<-1<<"()"<<endl;
			break;
		}
		c++;
		now=v[now];
	}

	cout<<-1<<endl;

	return 0;
}

Measured memory_bytes: 892
#include<stdio.h>
#define N 500001

typedef struct{
  int parent;
  int left;
  int right;
  int key;
}Node;

Node node[N], swap;
int n;

void maxHeapify(int i){
  int l = left(i), r = right(i), largest;
  if(l <= n && node[l].key > node[i].key) largest = l;
  else largest = i;
  if(r <= n && node[r].key > node[largest].key) largest = r;
  if(largest != i){
    swap = node[i];
    node[i] = node[largest];
    node[largest] = swap;
    maxHeapify(largest);
  }
}

void buildMaxHeap(){
  int i;
  for(i = n/2;i > 0;i--) maxHeapify(i);
}

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

int main(){
  int i, j;
  scanf("%d", &n);
  for(i = 1;i < n+1;i++){
    scanf("%d", &node[i].key);
    if(i == 1) node[i].parent = -1;
    else node[i].parent = parent(i);
    if(2*i > n) node[i].left = node[i].right = -1;
    else{
      node[i].left = left(i);
      if(2*i+1 > n) node[i].right = -1;
      else node[i].right = right(i);
    }
  }
  buildMaxHeap();
  for(i = 1;i < n+1;i++){
    printf(" %d", node[i].key);
  } 
  printf("\n");
  return 0;
}

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

s = 0
cnt = 0
for i in range(n):
    s += a[i]
    if i % 2 == 0:
        if s <= 0:
            cnt += abs(s) + 1
            s = 1
    else:
        if s >= 0:
            cnt += abs(s) + 1
            s = -1
ans1 = cnt

s = 0
cnt = 0
for i in range(n):
    s += a[i]
    if i % 2 != 0:
        if s <= 0:
            cnt += abs(s) + 1
            s = 1
    else:
        if s >= 0:
            cnt += abs(s) + 1
            s = -1
ans2 = cnt

print(min(ans1, ans2))


Measured memory_bytes: 14648
import collections


class FordFulkerson:
    """
    Verified with http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A
    """

    def __init__(self):
        self.g = collections.defaultdict(lambda: collections.defaultdict(int))

    def add_edge(self, u, v, c):
        self.g[u][v] = c

    def dfs(self, u, t, f, used: set):
        """
        :param u: visiting node
        :param t: sink
        :param f: flow
        :param used: node u is used?
        :return: min(c, f)
        """
        if u == t:
            return f

        used.add(u)

        # visit next node
        for v, c in self.g[u].items():
            if v not in used and c > 0:
                f = min(c, f)
                d = self.dfs(v, t, f, used)

                # update the graph if a path is found
                if d > 0:
                    self.g[u][v] -= d
                    self.g[v][u] += d
                    return d

        # path is not found
        return 0

    def max_flow(self, s, t):
        """Calculate maximum flow from s to t on the network

        :param s: source
        :param t: sink
        :return: max flow on the network
        """
        f = 0
        while True:
            d = self.dfs(s, t, float("inf"), set())
            if d == 0:  # nothing to update any more
                break
            f += d
        return f


def bipartite_matching(pairs: list, X :int, Y: int):
    solver = FordFulkerson()
    s = X+Y
    t = s+1
    for x, y in pairs:
        solver.add_edge(x, X+y, 1)
    for x in range(X):
        solver.add_edge(s, x, 1)
    for y in range(Y):
        solver.add_edge(X+y, t, 1)

    return solver.max_flow(s, t)


def main():
    N = int(input())
    rs = []
    bs = []
    for i in range(N):
        x, y = map(int, input().split())
        rs.append((x, y))
    for i in range(N):
        x, y = map(int, input().split())
        bs.append((x, y))

    pairs = []
    for i in range(N):
        for j in range(N):
            r = rs[i]
            b = bs[j]
            if r[0]<b[0] and r[1]<b[1]:
                pairs.append((i, j))
    print(bipartite_matching(pairs, N, N))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3828
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		
		
		long N = in.nextLong();
		long M = in.nextLong();
		long MOD = 1000000007;
		long ans = 0;
		
		if(N - M == 0){
			ans = factorial(N, MOD);
			ans = (ans * ans * 2) % MOD;
		}else if(Math.abs(N - M) == 1){
			ans = (factorial(N, MOD) * factorial(M, MOD)) % MOD;
		}
		
		System.out.println(ans);
	}
	
	public static long factorial(long n, long MOD){
		long ans = 1;
		for(long i = n; i >= 2; i--){
			ans *= i;
			ans %= MOD;
		}
		return ans;
	}
}


Measured memory_bytes: 23764
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
//const int mod=998244353;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);ios::sync_with_stdio(false);
	
	llint n,ans=0,i,j,r=0,g=0,b=0;cin>>n;
	string s;cin>>s;
	for(i=0;i<n;i++){
		if(s[i]=='R'){r++;}
		if(s[i]=='G'){g++;}
		if(s[i]=='B'){b++;}
	}
	ans=r*g*b;
	for(i=0;i<n;i++){
		for(j=i+1;j+j-i<n;j++){
			if(s[i]==s[j]){continue;}
			if(s[i]==s[j+j-i]){continue;}
			if(s[j]==s[j+j-i]){continue;}
			ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3588
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))

k,x = map(int, input().split())

if (500*k >= x):
    print("Yes")
else:
    print("No")



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

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  int start = h1 * 60 + m1;
  int end = h2 * 60 + m2;

  int ans = end - start - k;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
# include <iostream>
# include <stdint.h>
# include <stdio.h>
# include <math.h>
using namespace std;


int main(){
	string n,s;
    cin>> n;
    int q=0;
    while (cin>> s){
        for (int i=0;i<s.size();i++){
            if (s[i]<97){
                s[i]=s[i]+32;
            }
        }
        if (s==n){
            q++;
        }
    }
    cout<< q<< "\n";
	return 0;
}



Measured memory_bytes: 3176
#include <cstdio>
#include <cstring>

using namespace std;

char c[5], s[5];
int len, ans;

int main (void)
{
	scanf("%s", c+1);
	scanf("%s", s+1);
	len = strlen(c+1);
	for(register int i=1; i<=len; ++i)
		ans += c[i] == s[i];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
#define Would
#define you
#define please
#define mp make_pair
const int mod = 1e9+7;
int grid[1010][1010];
int memo[1010][1010];

int dfs(int x, int y,int h,int w){
	if(x==h && y==w){
		return 1;
	}
	if(x>h || y>w || grid[x][y]==1){
		return memo[x][y]=0;
	}

	if(memo[x][y]!=-1){
		return memo[x][y]%mod;
	}
	int up=dfs(x,y+1,h,w);
	int right=dfs(x+1,y,h,w);

	if(memo[x][y]==-1){
		return memo[x][y]=(up+right)%mod;
	}else{
		return memo[x][y]=((memo[x][y]+up)%mod+right)%mod;
	}

}

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

	memset(memo,-1,sizeof(memo));

	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			char c;
			cin>>c;
			if(c=='.')
				grid[i][j]=0;
			else
				grid[i][j]=1;
		}
	}
	dfs(1,1,h,w);
	printf("%d",memo[1][1]%mod);


    Would you please return 0;
}

Measured memory_bytes: 8320
N = int(input())
S1 = input()
S2 = input()
res = 6
idx = 0
s = []
mod = 1000000007
while idx < N:
    if S1[idx] == S2[idx]:
        s.append(0)
    else:
        s.append(1)
        idx += 1
    idx += 1

res = 3 if s[0] == 0 else 6

for idx in range(1, len(s)):
    prev, cur = s[idx-1], s[idx]
    if prev == 0:
        if cur == 0:
            res *= 2
        else:
            res *= 2
    else:
        if cur == 0:
            res *= 1
        else:
            res *= 3

    res %= mod

print(res)


Measured memory_bytes: 3064
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        l: isize,
    }
    let t = (0..n).map(|i| l + i as isize).collect::<Vec<_>>();
    let e = t.iter().min_by_key(|&ti| (ti.abs(), ti)).unwrap();
    println!("{}", t.iter().sum::<isize>() - e);
}


Measured memory_bytes: 2160
#include <stdio.h>

int main(void) {
  long long n,i;
  long long k=1,number[100000]={};
  scanf("%d",&n );

  for (i=0;i<n;i++) {
    scanf("%lld\n",&number[i]);
    /* code */
  }

  int r = 0;
  for (i=0;i<n;i++) {
    if (number[i]==0) {
      r++;
      /* code */
    }
    if (r>0) {
      printf("0\n");
      return(0);
      /* code */
    }
    /* code */
  }
  for (int i=0;i<n;i++ ) {
    if (number[i]<=1000000000000000000/k) {
      k *=number[i];
    }else{
      printf("-1\n");
      return (0);
    }
  }
  if (k>1000000000000000000) {
    printf("-1\n");
    return (0);
  }
  printf("%lld\n",k );
  return (0);
}


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

int main(){
  char S[105];

  scanf("%s", &S);

  int len = strlen(S);

  bool ans = true;
 
  for(int i = 0; i < len; i++){
    int a = (i+1) % 2;
    if (a == 0 && S[i] == 'R'){
      ans = false;
      break;
    }
    if (a== 1 && S[i] == 'L'){
      ans = false;
      break;
    }
  }

  if (ans) printf("Yes\n");
  else printf("No\n");

  return 0;
}

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

int N, mx;
vector<vector<pair<int, int>>> G;
vector<int> ans;

void dfs(int v, int pv, int c) {
  for (auto g : G.at(v)) {
    if (g.first == pv) continue;
    int nc = c % mx + 1; c++;
    ans.at(g.second) = nc;
    dfs(g.first, v, nc);
  }
}

int main() {
  cin >> N;
  G.resize(N);
  ans.resize(N - 1);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    G.at(--a).push_back({--b, i});
    G.at(b).push_back({a, i});
  }
  for (auto g : G) mx = max(mx, (int) g.size());
  cout << mx << "\n";
  dfs(0, -1, 0);
  for (auto a : ans) cout << a << "\n";
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

ll n,a,b;
ll h[125252];

bool ok(ll x){
  ll c = a-b;
  ll cnt = 0;
  REP(i,n){
    ll t = h[i] - x*b;
    if(t > 0)cnt += (t+c-1)/c;
  }
  return cnt <= x;
}

int main(){
  scanf("%lld%lld%lld",&n,&a,&b);
  REP(i,n)scanf("%lld",h+i);
  ll low = 0, high = 1000002521;
  while(low+1 < high){
    ll x = (low+high)/2;
    if(ok(x))high = x;
    else low = x;
  }
  printf("%lld\n",high);
  return 0;
}


Measured memory_bytes: 1024
N, C = map(int, input().split())
X = []
V = []
for _ in range(N):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)

gain_right = [0] * N
gain_right[0] = V[0] - X[0]
for i in range(1, N):
    gain_right[i] = gain_right[i-1] + V[i] - (X[i] - X[i-1])

gain_left = [0] * N  # 時計回りに並んでることに注意
gain_left[N-1] = V[N-1] - (C - X[N-1])
for i in reversed(range(N-1)):
    gain_left[i] = gain_left[i+1] + V[i] - (X[i+1] - X[i])

opt_right = [0] * N
opt_left = [0] * N

maxx = 0
maxx_idx = -1   # -1 は動かない
for i in range(N):
    if gain_right[i] > maxx:
        maxx = gain_right[i]
        maxx_idx = i
    opt_right[i] = maxx_idx

maxx = 0
maxx_idx = -1  # -1 は動かない
for i in reversed(range(N)):
    if gain_left[i] > maxx:
        maxx = gain_left[i]
        maxx_idx = i
    opt_left[i] = maxx_idx

# 左に行ってから右に行く場合
if opt_right[N-1] == -1:
    opt_cal = 0
else:
    opt_cal = gain_right[opt_right[N-1]]  # 全く左に行かないとき

for i in reversed(range(1, N)):
    cal = gain_left[i] - (C - X[i]) + gain_right[opt_right[i-1]]
    opt_cal = max(cal, opt_cal)

# 右に行ってから左に行く場合
# 全く右に行かないとき
if opt_left[0] == -1:
    opt_cal = max(opt_cal, 0)
else:
    opt_cal = max(gain_left[opt_left[0]], opt_cal)  # 全く右に行かないとき
for i in range(N-1):
    cal = gain_right[i] - X[i] + gain_left[opt_left[i+1]]
    opt_cal = max(cal, opt_cal)

print(opt_cal)

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    int H1,M1,H2,M2,K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int S = H1*60+M1;
    int G = H2*60+M2;
    int ans = -1;
    for(int i = S; i <= G; ++i) {
        if(i+K<=G) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }



int main(){ 
    ll n; cin >> n;
    ll Min = 0, Max = 0; int cnt;
    rep(i, 50){
        ll num = pow(-2, i);
        if(num>0) Max += num; else Min += num;
        if(n >= Min && n <= Max){
            cnt = i;
            break;
        }
    }
    string res;
    for(int i=cnt; i>=0; i--){
        ll num = pow(-2, i);
        if(num>0)Max-=num; else Min-=num;
        if(n >= Min && n <= Max) res.push_back('0');
        else{
            res.push_back('1');
            n -= num;
        }
    }
    cout << res << ln;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <iterator>
#include <numeric>
#include <set>
using namespace std;
typedef long long ll;

ll mod=1e9+7;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,k; cin >> n >> k;
	ll res=1;
	if(n>k){
		printf("0\n");
		return 0;
	}
	for(int i=k;i>=k-n+1;i--){
		(res*=i)%=mod;
	}
	printf("%lld\n",res );
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define com(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define pri(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<endl;
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
    ll n;
    cin>>n;
    vector<pair<ll,ll>>v;
    for(ll i=0; i<n; i++)
    {
        ll x,y;
        cin>>x>>y;
        v.push_back({x,y});
    }
    ll f =0;
    for(ll i=0; i<v.size()-2;i++)
    {
        if(v[i].first == v[i].second && v[i+1].first == v[i+1].second && v[i+2].first == v[i+2].second  )
        f=1;
        // cout<<i<<" ";
    }
    if(f)
    cout<<"Yes"<<"\n";
    else 
    cout<<"No"<<"\n";
}

Measured memory_bytes: 3628
s=input()

for bit in range(1<<3):
    sum=int(s[0])
    op=list("+++")
    for i in range(3):
        if bit & (1<<i):
            sum+=int(s[i+1])
        else:
            sum-=int(s[i+1])
            op[i]='-'
    if sum==7:
        print(s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]+"=7")
        break

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <complex>
#include <cmath>
#include <utility>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <ctime>
using namespace std;

typedef pair<int,int> pii;
typedef complex<double> P;


pii topii(const P &p, double d){
	return pii(real(p) / d, imag(p) / d);
}


int main(){
	srand(time(0));

	int n;
	scanf("%d", &n);
	double x, y;
	vector<P> v(n);
	for(int i = 0; i < n; ++i){
		scanf("%lf%lf", &x, &y);
		v[i] = P(x + 100.0, y + 100.0);
	}
	random_shuffle(v.begin(), v.end());

	double ans = 500.0;
	map<pii,vector<int> > mp;
	map<pii,vector<int> >::iterator it;
	for(int i = 0; i < n; ++i){
		double mdis = ans;

		pii p = topii(v[i], ans);
		for(int dy = -1; dy <= 1; ++dy)
		for(int dx = -1; dx <= 1; ++dx){
			it = mp.find(pii(p.first + dy, p.second + dx));
			if(it != mp.end()){
				for(int j = it->second.size(); j--; ){
					int k = it->second[j];
					mdis = min(mdis, abs(v[i] - v[k]));
				}
			}
		}
		
		if(mdis < ans){
			ans = mdis;
			mp.clear();
			for(int j = 0; j < i; ++j){
				mp[topii(v[j], ans)].push_back(j);
			}
		}
		mp[topii(v[i], ans)].push_back(i);
	}
	
	printf("%.8f\n", ans);
}

Measured memory_bytes: 13416
open Bytes
let a, b = Scanf.scanf " %s %s" @@ fun a b -> a, b
let n, m = String.length a, String.length b
let ma = max n m
let a', b' = make ma '0', make ma '0'
let _ =
  List.iter (fun (b, s, l) -> String.iteri (fun i -> set b (i + ma - l)) s) [a', a, n; b', b, m];
  print_endline @@ if a' > b' then "GREATER" else if a' < b' then "LESS" else "EQUAL"

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		//String N = in.nextLine();
		int N = in.nextInt();
		long L0 = 2;
		long L1 = 1;
		if(N==1) {
			System.out.println(L1);
			System.exit(0);
		}
		int i=1;
		long L=1;
		while(i<N) {
			L = L1 + L0;
			L0 = L1;
			L1 = L;
			i++;
		}
		System.out.println(L);
		
		
		in.close();
	}
}


Measured memory_bytes: 21716
main = do
  _ <- getLine
  [t, a] <- map read . words <$> getLine
  h <- map read . words <$> getLine
  let ht = map (\x -> t - x * 0.006) h
  let ha = map (\x -> abs $ a - x) ht
  print $ 1 + length (takeWhile (/= minimum ha) ha)
  return ()


Measured memory_bytes: 1276
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;
int main(){

string S;
  cin>>S;
  int a=0;
  int z=0;
  rep(i,0,S.length()){
    if(S[i]=='A'){
      a=i;
      break;
    }
  }
  urep(i,S.length()-1,-1){
    if(S[i]=='Z'){
      z=i;
      break;
    }
  }
  cout<<z-a+1;

}
// int *p = new int[N];

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 640
c,i,k[30],x;main(n){for(;~scanf("%d",&i);)k[__builtin_popcount(i^i-1)]=--n&&(x^=i);for(i=30;i;i--)x&k[i]<<i-1&&(c++,x^=(1<<i)-1);printf("%d",x?-1:c);}

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

void solve (int h)
{
    int w, k;
    cin >> w >> k;

    int sx = -1, sy = -1;
    vector<string> grid(h);
    forn (i, h)
    {
        cin >> grid[i];
        int pos = find(all(grid[i]), 'S') - grid[i].begin();
        if (pos != w)
            sx = i, sy = pos;
    }

    queue<pii> q;
    q.push(mp(sx, sy));
    vvi dist(h, vi(w, -1));
    dist[sx][sy] = 0;

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

    while (!q.empty())
    {
        int cx = q.front().fst, cy = q.front().snd;
        q.pop();
        if (dist[cx][cy] == k)
            break;

        forn (d, 4)
        {
            int nx = cx + dx[d], ny = cy + dy[d];
            if (0 <= nx && nx < h && 0 <= ny && ny < w
                && grid[nx][ny] != '#' && dist[nx][ny] == -1)
            {
                q.push(mp(nx, ny));
                dist[nx][ny] = dist[cx][cy] + 1;
            }
        }
    }

    const int inf = (int)1e9;
    int ans = inf;
    forn (i, h) forn (j, w)
    {
        if (dist[i][j] == -1)
            continue;
        int brd = min({i, h - 1 - i, j, w - 1 - j});
        int cur = 1 + (brd + k - 1) / k;
        ans = min(ans, cur);
    }

    assert(ans != inf);
    cout << ans << endl;
}

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

    int n;
    while (cin >> n)
        solve(n);
}


Measured memory_bytes: 3456
N,A,B,C,D=map(int,input().split())
A=A-1
B=B-1
C=C-1
D=D-1

s=input()

if A<B<C<D:
    if not "##" in s[B:D+1]:
        if not "##" in s[A:C+1]:
            ans="Yes"
        else:
            ans="No"
    else:
        ans="No"
elif A<B<D<C:
    if not "##" in s[A:C+1]:
        if s[B-1]!="#" and s[B+1]!="#":
            ans="Yes"
        elif "..." in s[B:D+1]:
            ans="Yes"
        elif s[D-1]!="#" and s[D+1]!="#":
            ans="Yes"
        else:
            ans="No"
    else:
        ans="No"
elif A<C<B<D:
    if "##" in s[A:C+1] or "##" in s[B:D+1]:
        ans="No"
    else:
        ans="Yes"
print(ans)



Measured memory_bytes: 3572
//#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <algorithm>
#define repe(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define mst(a, b)   memset((a), (b), sizeof(a))
#define gc() gutchar()
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pr;
typedef long long ll;
const double eps = 1e-5;
const int inf = 0x3f3f3f3f;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const ll mod = 1e9+7;
const int N = 2e5+5;

int main()
{
	int n; cin >> n;
	int cs, sum;
	cs = inf; sum = 0;
	rep(i, 0, n){
		int x;
		scanf("%d", &x);
		if (cs > x) cs = x, sum++;
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>


using namespace std;

char a[105];
int nums[26];

int main()
{
	scanf("%s", a);
	int len = strlen(a);

	for (int i = 0;i < len;i++)
	{
		nums[a[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++)
	{
		if (nums[i] % 2 == 1)
		{
			printf("No");
			break;
		}
		if (i == 25)
		{
			printf("Yes");
			break;
		}
	}

	//system("pause");
	return 0;
}

	
	




	


Measured memory_bytes: 256
#include <stdio.h>

#define WHITE 1
#define GRAY 0
#define BLACK -1
#define INF 100000000
#define N 100

void bfs(int);
void enqueue(int);
int dequeue(void);

int Q[N+1],d[N+1],c[N+1],ts,n,S[N+1][N+1],k[N+1];
int head, tail;

int main()
{
  int i,j,u,min;

  scanf("%d",&n);

  head = 0;
  tail = 1;

  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k[u]);

    for(j=0;j<k[u];j++){
      scanf("%d",&S[u][j]);
    }
  }

  bfs(1);
  for(i=1;i<=n;i++)  {
    if(d[i]==INF) d[i]=-1;
    printf("%d %d\n",i,d[i]);
  }

  return 0;
}

void bfs(int s){
  int i,u,v;
  for (u=1;u<=n;u++){
    c[u] = WHITE;
    d[u] = INF;
  }
  c[s] = GRAY;
  d[s] = 0;

  enqueue(s);

  while(head!=tail){
    u = dequeue();
    for(i=0;i<k[u];i++){
      v=S[u][i];
      if (c[v] == WHITE){
    c[v] = GRAY;
    d[v] = d[u] + 1;
    enqueue(v);
      }
      c[u] = BLACK;
    }
  }
}

void enqueue(int x){
  Q[tail] = x;
  if (tail + 1 == n) tail = 0;
  else tail++;
}

int dequeue(void){
  int x;
  x = Q[head];
  if (head + 1 == n) head = 0;
  else head++;
  return x;
}

Measured memory_bytes: 636
#include <iostream>
#include <vector>
#include <algorithm> 
#include <queue>
#include <functional>
#include <map>
#include <string>
using namespace std;
typedef long long ll;

int n;
ll W;
ll w[105], v[105], dp[105][305][105];

ll rec(int  i, int  j, int count){
    if (dp[i][j][count] > 0) return dp[i][j][count];
    if (i == n) return 0;
    ll ret = 0;
    int wd = w[i] - w[0];
    if (j + wd + w[0] * (count + 1) <= W){
        ret = v[i] + rec(i + 1, j + wd, count + 1);
    }
    ret = max(ret, rec(i + 1, j, count));

    return dp[i][j][count] = ret;
}

int main(void){

    cin >> n >> W;
 
    for (int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
    }
  
    cout << rec(0, 0, 0) << endl;
    
}

Measured memory_bytes: 22912
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var a = cin.ReadIntArray(N);
            var now = 1;
            for(int i = 0; i < N; i++)
            {
                now = a[now - 1];
                if(now == 2)
                {
                    WriteLine(i + 1);
                    return;
                }
            }
            WriteLine(-1);
        }
        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

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

using namespace std;

const int N = 2e5+7;

int n;
int a[N];
long long s[N];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        s[i] = s[i-1]+a[i];
    }
    long long res = s[n];
    for (int i = 1; i <= n; ++i) {
        res = min(res, abs(s[n]-s[i]-s[i]));
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 2560
#include <iostream>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  char a,b,c,d;
  cin >> a;
  cin >> b;
  int s=0;
  if(a=='D')  s++;
  if(b=='D')  s++;
  
  if(s==1){
    cout << "D"<<endl;
  }else{
	cout << "H"<<endl;
  }
  
  
    return 0;
}


Measured memory_bytes: 256