akhauriyash/Code-Regression huggingface dataset:
// Problem : A - Station and Bus
// Contest : AtCoder Beginner Contest 158
// URL : https://atcoder.jp/contests/abc158/tasks/abc158_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb emplace_back
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
using namespace std;
using namespace __gnu_pbds;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
double pi=acos(-1.0);
int md=1000000007;
int abst(int a)
{return a<0?-a:a;}
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%md;n=(n*n)%md;x=x>>1;}
 return ans;}

 vi fact,inv;
void inverse(int n)
{inv.resize(n+1);inv[0]=1;
for(int i=1;i<=n;i++)inv[i]=Pow(fact[i],md-2);}
void factorial(int n)
{fact.resize(n+1);fact[0]=1;
for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i)%md;}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
//create(tree,node,a,start,end)
//query(tree,node,start,end,l,r)
//update(tree,node,start,end,index,value)
void solve()
{
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string s;cin>>s;
if(find(s.begin(),s.end(),'A')!=s.end() and find(s.begin(),s.end(),'B')!=s.end())
cout<<"Yes";
else
cout<<"No";
}

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


Measured memory_bytes: 256
/******************************************
* AUTHOR : Ashish Joshi* 
* INSTITUTION : NIT Hamirpur *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define loop(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define set(b,i) (b|(1<<i))
#define unset(b,i) (b&!(1<<i))
#define cbit(b,i) bool(b&(1<<i))

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
int n;
cin>>n;
int p[n],q[n],a[n];
for(int i=0;i<n;i++)cin>>p[i];
for(int i=0;i<n;i++){
	cin>>q[i];
	a[i]=i+1;
}

int x=0,y=0,f=0;
do{
	int i;
	for(i=0;i<n;i++)
	{
		if(a[i]!=q[i]){x++;break;}
	}
	if(i==n)break;
}while(next_permutation(a,a+n));
sort(a,a+n);
do{
	int i;
	for(i=0;i<n;i++)
	{
		if(a[i]!=p[i]){y++;break;}
	}
	if(i==n)break;
}while(next_permutation(a,a+n));
cout<<abs(x-y)<<endl;

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
      int i,j,b,c=0,x,y,m=0 ,n,k,p,h=0,t1,d;
      string a[100],s[100];
      int g[100];
      cin>>n;
      for(i=0;i<n;i++)
      {
          cin>>a[i];
      }
      cin>>p;
      for(i=0;i<p;i++)
      {
          cin>>s[i];
      }
       for(i=0;i<n;i++)
      {
          if(a[i]!="0")
          {
              m=1;
          for(j=i+1;j<n;j++)
          {
              if(a[i]==a[j])
              {
                 m++;
                 a[j]='0';
              }
          }

          }
          for(k=0;k<p;k++)
          {
              if(a[i]!="0")
              {
                  if(a[i]==s[k])
                  {
                     h++;
                  }
              }
          }
          g[c] = m-h;
          c++;
          m = 0;
          h = 0;
      }
      d = c;
       sort(g,g+d);
       if(g[d-1]<=0)
       {
           cout<<"0"<<endl;
       }
       else
       cout<<g[d-1]<<endl;


      return 0;
      }


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

int main() {
  string w;
  cin >> w;
  
  int n = w.size();
  
  bool flag = true;
  
  for(int i = 0; i < n; i++) {
  int count = 0;
  for(int j = 0; j < n; j++) {
  	if(w.at(i) == w.at(j)) {
    	count++;
    }
  }
  if(count%2 != 0) {
  	flag = false;
  }
  }
  if(flag) {
  	cout << "Yes" << endl;
  }
  
  else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
// AOJ Volume 0 Problem 0071

#include <stdio.h>
#include <string.h>

#define MAX(a, b)	((a)>(b)?(a):(b))
#define MIN(a, b)	((a)<(b)?(a):(b))

int map[8][8];

void bomb(int x, int y)
{
	int i;
	
//	printf("[%d, %d]", x, y);
	
	if (map[y][x] == 0){
		printf("<NO>");
		return;
	}
	
	map[y][x] = 0;

	for (i = x - 1; i >= MAX(0, x - 3); i--){ //¶ûüÌ
		if (map[y][i] == 1){
			bomb(i, y);
		}
	}
	
	for (i = x + 1; i <= MIN(7, x + 3); i++){ //EûüÌ
		if (map[y][i] == 1){
			bomb(i, y);
		}
	}

	for (i = y - 1; i >= MAX(0, y - 3); i--){ //ãûüÌ
		if (map[i][x] == 1){
			bomb(x, i);
		}
	}

	for (i = y + 1; i <= MIN(7, y + 3); i++){ //ºûüÌ
		if (map[i][x] == 1){
			bomb(x, i);
		}
	}
}

int main(void)
{
	int n, data_set;
	char str[10];
	int i, j;
	int x, y;
	
	scanf("%d", &n);
	
	
	for (data_set = 1; data_set <= n; data_set++){
		fgets(str, 10, stdin);			// ósÇÝòÎµ
		fgets(str, 10, stdin);			// ósÇÝòÎµ

		memset(map, 0, sizeof(map));	// }bvNA

		for (i = 0; i < 8; i++){		// }bvüÍ
			fgets(str, 10, stdin);
			for (j = 0; j < 8; j++){
				map[i][j] = str[j] - '0';
			}
		}
		scanf("%d%d", &x, &y);
		
		bomb(x - 1, y - 1);
		
		printf("Data %d:\n", data_set);
		for (i = 0; i < 8; i++){
//			printf(">");
			for (j = 0; j < 8; j++){
				printf("%d", map[i][j]);
			}
			printf("\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
x=[]
y=[]
n,m=map(int,input().split())
x=[list(map(int,input().split()))for i in range(n)]
y=[int(input())for i in range(m)]
for i in range(n):
    c=0
    for j in range(m):
        c+=x[i][j]*y[j]
    print(c)



Measured memory_bytes: 6016
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	e=a*b;
	f=c*d;
	if(e>f){
		printf("%d\n",e);
	}
	if(f>e){
		printf("%d\n",f);
	}
	else if(e==f){
		printf("%d\n",e);
	}
	return 0;
}

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

#define NMAX 1000

#define MAX(a, b) (a > b ? a : b)

using namespace std;

ifstream fin("f.in");
ofstream fout("f.out");

int p, q, r;

int main()
{
    cin >> p >> q >> r;
    int maxim = MAX(MAX(p, q), r);
    cout << p + q + r - maxim << '\n';
    return 0;
}


Measured memory_bytes: 256
/*
                                Bismillahi-r-Rahmani-r-Rahim
                                        RhIeyAaD
                                    IIT-7th Batch,JU
*/
#include<bits/stdc++.h>
using namespace std;

#define debug(args...){ string _s = #args;replace(_s.begin(),_s.end(),',', ' ');stringstream _ss(_s);istream_iterator<string>_it(_ss);err(_it, args);}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << "=" << a << ", "; err(++it, args...);}

#define ll              long long int
#define MAX             2134567891
#define fr(i,n)         for(i=0;i<n;i++)
#define rep(i,n)        for(i=1;i<=n;i++)
#define rev(i,a,n)      for(i=n;i>=a;i--)
#define FOR(i,a,n)      for(i=a;i<=n;i++)
#define ALL(n)          n.begin(),n.end()
#define mem(x,n)        memset(x,n,sizeof(x))
#define TC(t)           printf("Case %lld: ",t)
#define ans(t,c)        printf("Case %lld: %lld\n",t,c)
#define SETP(n)         cout<<setprecision(n)<<fixed
#define READ            freopen("F:\\Project\\Test_Case.txt","r",stdin)
#define WRITE           freopen("F:\\Project\\Output_Test.txt","w",stdout)
#define IO              ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define PAIR            pair<ll,ll>
#define MP              make_pair
#define pb              push_back
#define eb              emplace_back
#define ff              first
#define ss              second
#define NL              printf("\n");
#define bug(a)          cout<<#a<<" "<<a<<" ";
#define hlw             printf("hlw\n");
#define NN              111
#define MOD             1000000007///10^9
#define N               1000007 ///10^6->6 zero after 1 **



ll x[N],y[N],z[N],n;
string s,S;
vector<ll>v;
bitset<N>B;
//map <ll,ll> mp;

int main()
{
    //IO;
    //while(1)
    //READ;WRITE;
{
    ll a=0,b=0,c=0,d,e,f,g,i,j,k,l,m,p,q,r,u,w,t,tc=1,in,loc,val,sz,lo,hi,mid,mn=MAX,mx=0,sum=0,ans=0;
//cin>>tc;
rep(t,tc)
{
    cin>>n>>a;
    if(a==1 || a>2*n-2)
    {
        cout<<"No\n";
        //continue;
    }
    else
    {
        l=2*n-1;
        for(i=n-1,j=a-1;i<=l;i++,j++)
        {
            if(j>l)j=1;
            x[i]=j;
        }

        for(i=1;i<n-1;i++,j++)
        {
            if(j>l)j=1;
            x[i]=j;
        }
        cout<<"Yes\n";
        rep(i,l)cout<<x[i]<<endl;
    }
}
}
    return 0;
}

/*


*/
/// Check for constraint 0 or 1?
/// Division MOD needs BigMod(a,n-2)
/// long long or double? sqrt or division will work fine??
/// sort(begin(v), end(v), [] (int a, int b) { return a > b; });    /// Lambda Function for manual Sort


Measured memory_bytes: 5632
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> dList = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            int d = sc.nextInt();
            dList.add(d);
        }
        Collections.sort(dList);
        sc.close();

        int count = dList.get(N / 2) - dList.get(N / 2 - 1);
        System.out.println(count);

    }
}

Measured memory_bytes: 62240
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1e10
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll N;
v ans;
v a;
vv edges;
v dp;

void dfs(ll pre,ll now){
    ll tmp = lower_bound(all(dp), a[now])-dp.begin();
    ll change_ind = tmp;
    ll change_val = dp[tmp];
    dp[tmp] = a[now];
    ll dp_s = lower_bound(all(dp), INF)-dp.begin();
    ans[now] = dp_s;
    for(ll nxt:edges[now]){
        if(nxt == pre)continue;
        dfs(now,nxt);
    }
    dp[change_ind] = change_val; 
}
int main(){
    cin>>N;
    ans.resize(N);
    a.resize(N);
    edges.resize(N);
    dp.resize(N,INF);

    rep(i,0,N)cin>>a[i];
    rep(i,0,N-1){
        ll c,d;
        cin>>c>>d;
        c--;d--;
        edges[c].PB(d);
        edges[d].PB(c);
    }
    dfs(-1,0);
    rep(i,0,N)cout<<ans[i]<<endl;
    return 0;
}

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

bool is_prime(int num) {
	for (size_t i = 2; i * i <= num; i++) {
		if (num % i == 0) return false;
	}
	return true;
}

int main() {
	int q;

	std::cin >> q;

	std::vector<int> prime;

	for (size_t i = 3; i < 100000; i++) {
		if (is_prime(i) && is_prime((i + 1) / 2)) {
			prime.push_back(i);
		}
	}

	for (size_t i = 0; i < q; i++) {
		int l, r;

		std::cin >> l >> r;

		int count = 0;
		for (int p : prime) {
			if (p >= l && p <= r) {
				count++;
			}
		}
		std::cout << count << std::endl;
	}

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<queue>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define pb push_back
using namespace std;
typedef pair<int, int>pii;
int main(){
	int N,D,X;
	int A[105];
	cin >> N >> D >>X;
	rep(i,N) cin >>A[i];
	int ans=X;
	rep(i,N){
		ans+=(D/A[i]);
		if((D/A[i])*A[i]!=D) ans+=1;
	}
	cout << ans <<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;
using ll = long long;

int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll ans; 
    ll y = x % d;
    ll cnt = x / d;
    if(cnt<=k){
        if((k-cnt)%2==1){
            ans = abs(y-d);
        }else{
            ans = abs(y);
        }
    }
    else ans = x - d*k;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
# C - いっしょ

from decimal import Decimal, ROUND_HALF_UP

N = int(input())
a = list(map(int, input().split()))
m = Decimal(sum(a) / N).quantize(Decimal('0'), rounding=ROUND_HALF_UP) 
#print(sum(a) / N)
#print(m)

ans = 0
for i in a:
  ans += (i - m) ** 2

print(ans)


Measured memory_bytes: 5076
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  long long int n,m;
  cin >> n >>m;
  long long int a=m/2;
  if(n>a) cout << a<<endl;
  else{
    long long int sum=a-n;
    long long int ans=(sum*2)/4;
    cout << n+ans<<endl;
  }
}


Measured memory_bytes: 256
downhill_stack = []
idx_area_stack = []
for idx, c in enumerate(input()):
    if c == '\\':
        downhill_stack.append(idx)
    elif c == '/' and len(downhill_stack) > 0:
        downhill_idx = downhill_stack.pop()
        current_level_area = idx - downhill_idx
        if len(idx_area_stack) == 0:
            idx_area_stack.append((downhill_idx, current_level_area))
            continue
        last_idx = idx_area_stack[-1][0]
        if downhill_idx < last_idx:
            prov_area = current_level_area
            while downhill_idx < last_idx:
                idx_area = idx_area_stack.pop()
                prov_area += idx_area[1]
                if len(idx_area_stack) == 0:
                    break
                last_idx = idx_area_stack[-1][0]
            prov_idx_area = (downhill_idx, prov_area)
            idx_area_stack.append(prov_idx_area)
        else:
            idx_area_stack.append((downhill_idx, current_level_area))
puddle_num = len(idx_area_stack)
areas = list(map(lambda x: x[1], idx_area_stack))
print(sum(areas))
if puddle_num > 0:
    print(puddle_num, " ".join(map(str, areas)))
else:
    print(puddle_num)


Measured memory_bytes: 6208
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 0
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	ors := getNextString(scanner)
	s := make([]byte, n)
	for i := 0; i < n; i++ {
		s[i] = ors[i]
	}
	q := getNextInt(scanner)
	ss := make([]Segment, 26)

	for i := 0; i < 26; i++ {
		ss[i].init(n)
	}
	for i := 0; i < n; i++ {
		ss[s[i]-'a'].add(i, 1)
	}

	for i := 0; i < q; i++ {
		t := getNextInt(scanner)
		if t == 1 {
			pos := getNextInt(scanner) - 1
			c := getNextString(scanner)

			ss[s[pos]-'a'].add(pos, -1)
			ss[c[0]-'a'].add(pos, 1)
			s[pos] = c[0]
			continue
		}
		l := getNextInt(scanner) - 1
		r := getNextInt(scanner)
		sum := 0
		for j := 0; j < 26; j++ {
			if ss[j].rangesum(l, r) == 0 {
				continue
			}
			sum++
		}
		fmt.Fprintln(writer, sum)
	}
}

// Segment ...
type Segment struct {
	n, h, i, chunk int
	unit           []int
	bucket         [][]int
}

func (seg *Segment) init(n int) {
	seg.n = n
	seg.unit = make([]int, 1)
	seg.unit[0] = 1
	seg.bucket = make([][]int, 1)
	seg.bucket[0] = make([]int, n)

	chunk := 8
	for i := 0; n > 1; i++ {
		n = (n-1)/chunk + 1
		seg.bucket = append(seg.bucket, make([]int, n))
		seg.unit = append(seg.unit, seg.unit[i]*chunk)
	}
	seg.h = len(seg.unit)
	seg.chunk = chunk
}

func (seg *Segment) add(index int, value int) {
	for i := 0; i < seg.h; i++ {
		seg.bucket[i][index/seg.unit[i]] += value
	}
}

func (seg *Segment) rangesum(l, r int) int {
	var sum int
	i := 0
	for index := l; index < r; index += seg.unit[i] {
		for i < seg.h-1 && index%seg.unit[i+1] == 0 {
			i++
		}
		for index+seg.unit[i] > r {
			i--
		}
		ii := index / seg.unit[i]
		sum += seg.bucket[i][ii]
	}

	return sum
}


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

int main() {
  int ret;
  int cnt = 0;
  int h, w;
  string s;
  // get h and w
  cin >> h;
  cin >> w;
  // load grid
  vector<vector<char>> grid(h);
  for(size_t i = 0; i < h; i++)
  {
    cin >> s;
    grid[i] = vector<char>(w);
    for(size_t j = 0; j < w; j++){
      grid[i][j] = s[j];
    }
  }
 
  //  initialize
  vector<vector<int>> cost_h(h);
  vector<vector<int>> cost_w(h);
  for(size_t i = 0; i < h; i++)
  {
    cost_w[i] = vector<int>(w);
    cost_h[i] = vector<int>(w);
  }

  //
  for(size_t i = 0; i < h; i++)
  {
    bool isCount = false;
    int cnt = 0;
    int start = 0;
    for(size_t j = 0; j < w; j++){
      char val = grid[i][j];
      if(val == '.' && !isCount){
        isCount = true;
        cnt = 1;
        start = j;
      }
      else if(val == '.' && isCount){
        cnt++;
      }
      else if(val == '#' && isCount){
        isCount = false;
        for(int k = start; k < j; k++){
          cost_w[i][k] = cnt;
        }
      }
      if(j==w-1 && isCount){
        isCount = false;
        for(int k = start; k <= j; k++){
          cost_w[i][k] = cnt;
        }
      }
    }// loop end for(size_t j = 0; j < w; j++)
  }

  //
  for(size_t j = 0; j < w; j++)
  {
    bool isCount = false;
    int cnt = 0;
    int start = 0;

    for(size_t i = 0; i < h; i++){
      char val = grid[i][j];
      if(val == '.' && !isCount){
        isCount = true;
        cnt = 1;
        start = i;
      }
      else if(val == '.' && isCount){
        cnt++;
      }
      else if(val == '#' && isCount){
        isCount = false;
        for(int k = start; k < i; k++){
          cost_h[k][j] = cnt;
        }
      }
      if(i == h - 1 && isCount){
        isCount = false;
        for(int k = start; k <= i; k++){
          cost_h[k][j] = cnt;
        }
      }
    }// loop end for(size_t j = 0; j < w; j++)
  }

  // get max
  int max_val = 0;
  for(size_t i = 0; i < h; i++)
  {
    for(size_t j = 0; j < w; j++){
      int tmp = cost_h[i][j] + cost_w[i][j];
      if(tmp > max_val)
        max_val = tmp;
    }
  }
  cout << (max_val - 1) << endl;
  return 0;
  

  // print debug
  for(auto &it : cost_w){
    for(auto &it2 : it){
      cout << it2 << ',';
    }
    cout << endl;
  }
  cout << endl;
  // print debug
  for(auto &it : cost_h){
    for(auto &it2 : it){
      cout << it2 << ',';
    }
    cout << endl;
  }

  cout << s;
  return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include <utility>
#include <vector>
#include <set>
using namespace std;
int r[300010],c[300010];
set<pair<int,int>> p;
vector<int> vr,vc;
int main(){
    int i,j,h,w,m; cin >> h >> w >> m;
    for(i=0;i<m;i++){
        int s,t; cin >> s >> t; s--; t--;
        r[s]++; c[t]++;
        p.insert({s,t});
    }
    int mxr = 0,mxc = 0;
    for(i=0;i<300000;i++){
        mxr = max(mxr,r[i]); mxc = max(mxc,c[i]);
    }
    for(i=0;i<300000;i++){
        if(r[i]==mxr) vr.push_back(i);
        if(c[i]==mxc) vc.push_back(i); 
    }
    long long x = vr.size(),y = vc.size();
    if(x*y>(long long)m){
        cout << mxr + mxc << endl;
    }else{
        for(i=0;i<x;i++){
            for(j=0;j<y;j++){
                if(p.count({vr[i],vc[j]})==0){
                    cout << mxr + mxc << endl;
                    return 0;
                }
            }
        }
        cout << mxr + mxc - 1 << endl;
    }
}

Measured memory_bytes: 22800
//package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static int sum;
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        sum=0;
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            int m=scan.nextInt();
            int q=scan.nextInt();
            qs[] arr=new qs[q];
            for(int i=0;i<q;i++){
                arr[i]=new qs(scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt());
            }
            int[] f=new int[n+1];
            f[0]=1;
            gene(n,f,arr,1,m);
            out.println(sum);
        }
        out.flush();
        out.close();
    }
    static void gene(int n,int[] f,qs[] arr,int i,int m){
        if(i==n+1){
            int temp=0;
            for(int j=0;j<arr.length;j++){
                if(f[arr[j].b]-f[arr[j].a]==arr[j].c){
                    temp+=arr[j].d;
                }
            }
            sum=Math.max(sum,temp);
            return;
        }
        for(int j=f[i-1];j<=m;j++){
            f[i]=j;
            gene(n,f,arr,i+1,m);
        }
    }
    static class qs{
        int a;
        int b;
        int c;
        int d;
        qs(int a,int b,int c,int d){
            this.a=a;
            this.b=b;
            this.c=c;
            this.d=d;
        }
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    double a, b, x;
    cin >> a >> b >> x;
    double ans = 0;
    if (2 * x <= a * a * b) {
        double w = 2 * x / (a * b);
        ans = atan2(b, w);
    } else {
        double h = b * 2.0 - 2 * x / ( a * a);
        ans = atan2(h, a);
    }
    cout << ans / M_PI * 180 << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 512
import numpy as np
N,M  = map(int,input().split())
coeff = np.zeros((M,N))
for i in range(M):
    inputs = list(map(int,input().split()))
    for switch in inputs[1:]:
        coeff[i][switch-1] = 1
onlist = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    vec = [int(num) for num in bin(i)[2:]]
    fill = N - len(vec)
    vec = np.append(np.zeros(fill),np.array(vec))
#     print(vec)
    if sum(onlist == np.dot(coeff,vec)%2) == M:
        ans +=1
print(ans)

Measured memory_bytes: 14556
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

#define INF 1e9
int n, m;
vector<vector<int> > d; // 隣接行列 適宜0とかINFとか

void warshall_floyd() {
  rep (k, n) {
    rep (i, n) {
      rep (j, n) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  scanf("%d %d", &n, &m);
  d.assign(n, vi(n, INF));
  rep (i, n) {
    d[i][i] = 0;
  }
  vvi all_edge(m);
  rep (i, m) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a -= 1; b -= 1;
    d[a][b] = d[b][a] = c;
    all_edge[i] = {c, min(a, b), max(a, b)};
  }
  warshall_floyd();
  int ans = 0;
  rep (i, m) {
    if (all_edge[i][0] > d[all_edge[i][1]][all_edge[i][2]]) {
      ans += 1;
    }
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

//クラスカル法で最小全域木に含まれる辺のコストの総和の最小値を求める
//計算量 O(E*log(V))

struct Union_Find_Tree{
    vector<int> par, rank, num;
    
    Union_Find_Tree(int N){
        par.assign(N, -1);
        rank.assign(N, 0);
        num.assign(N, 1);
    }
    
    int root(int x){
        if(par[x] < 0 || par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    bool unite(int x, int y){
        x = root(x), y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y);
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x, num[x] += num[y];
        return true;
    }
    
    int size(int x) {return num[root(x)];}
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
    
    void clear(){
        fill(all(par), -1);
        fill(all(rank), 0);
        fill(all(num), 1);
    }
};

struct edge{
    int u, v;
    ll cost;
};

const int MAX_V = 200000;
vector<edge> es;

ll kruscal(){
    sort(all(es), [](const edge &e1, const edge &e2){
        return e1.cost < e2.cost;
    });
    Union_Find_Tree uf(MAX_V);
    ll ret = 0;
    for(auto &e: es){
        if(uf.unite(e.u, e.v)) ret += e.cost;
    }
    return ret;
}

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_A&lang=jp

int main(){
    int V, E;
    cin >> V >> E;
    rep(i, E){
        int u, v; ll c;
        cin >> u >> v >> c;
        es.eb((edge){u, v, c});
    }
    cout << kruscal() << endl;
}


Measured memory_bytes: 6772
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int pw(int x, int y){
  int ans = 1;
  for(int i = 0; i < y; i++) ans *= x;
  return ans;
}

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

  if(M == 0 && K == 0){
    cout << "0 0" << endl;
  }
  else if(M == 1 && K == 0){
    cout << "0 0 1 1" << endl;
  }
  else if(M >= 2 && 0 <= K && K < pw(2, M)){
    int a = pw(2, M);
    vector<int> vec;
    for(int i = 0; i < a; i++){
      if(i != K) vec.push_back(i);
    }

    //vec K vec^-1 K
    for(int i = 0; i < a; i++){
      if(i != K) cout << i << " ";
    }
    cout << K << " ";
    for(int i = a - 1; i >= 0; i--){
      if(i != K) cout << i << " ";
    }
    cout << K << endl;
  }
  else{
    cout << -1 << endl;
  }

  return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> a(n), b(n), v(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    v[i] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }

  int i = 0, an = 0, bn = 0;

  do {
    i++;
    bool a_match = true;
    bool b_match = true;
    for (int j = 0; j < n; j++) {
      if (a[j] != v[j])
        a_match = false;
      if (b[j] != v[j])
        b_match = false;
    }
    if (a_match)
      an = i;
    if (b_match)
      bn = i;
  } while (std::next_permutation(v.begin(), v.end()));
  cout << (an > bn ? (an - bn) : (bn - an)) << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()
T = input()
n = len(T)

def c(s, t):
  #print(s)
  r = 0
  for i in range(n):
    if s[i] == t[i]:
      r += 1
  return n - r

ans = n
for i in range( len(S) - n + 1):
  temp = c(S[i:i+n],T)
  ans = min( ans, temp)

print(ans)

Measured memory_bytes: 9060
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int a, b;
	cin >> a >> b;
	if (b == 1)
	{
		print(0);
		return 0;
	}
	if (a >= b)
	{
		print(1);
		return 0;
	}

	int ans = 1;
	int k = a;
	while (k < b)
	{
		k = k - 1 + a;
		ans++;
	}
	print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
from collections import defaultdict,deque
import sys
finput=lambda: sys.stdin.readline().strip()

def main():
  n=int(finput())
  edges=[tuple(map(int,finput().split())) for _ in range(n-1)]
  q,k=map(int,finput().split())
  xy=[tuple(map(int,finput().split())) for _ in range(q)]
  ed=defaultdict(deque)
  wt=defaultdict(int)
  for e in edges:
    ed[e[0]].append(e[1])
    ed[e[1]].append(e[0])
    wt[(e[0],e[1])]=e[2]
    wt[(e[1],e[0])]=e[2]
  stack=deque([k])
  cv=stack[0]
  dist=defaultdict(int)
  while stack:
    while ed[cv]:
      if cv!=k:
        if ed[cv][-1]==stack[-1]:
          ed[cv].pop()
          if not ed[cv]:
            break
      stack.append(cv)
      cv=ed[cv].pop()
      dist[cv]=dist[stack[-1]]+wt[(stack[-1],cv)]
    cv=stack.pop()
  for que in xy:
    print(dist[que[0]]+dist[que[1]])

if __name__=='__main__':
    main()


Measured memory_bytes: 144868
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n, k;
  cin >> n >> k;
  ll l[n];
  REP(i, n) cin >> l[i];

  SORT(l, n);
  ll sum = 0;
  REP(i, k) sum += l[n - 1 - i];

  cout << sum << endl;
  return 0;
}


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

int main(){
  long long n;
  cin>>n;
  if(n%2) cout<<0;
  else{
    long long ret = 0;
    while(n){
      ret+=n/10;
      n/=5;
    }
    cout<<ret;
  }
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <iostream>
#define rep(i,n) for(long long i=0;i<n;i++)
using namespace std;

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

int main(){
    int N, K, gcd_ab, temp;
    long long sum = 0;
    
    cin >> K;

    for(int a = 1;a <= K; a++){
        for(int b = 1;b <= K; b++){
            for(int c = 1;c <= K; c++){
                sum += gcd(gcd(a,b), c);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3636
#include <set>
#include <iostream>
using namespace std;
int N, M, a, b;
int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	set<pair<int, int> > s;
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		s.insert(make_pair(a, b));
	}
	bool ret = false;
	for (int i = 2; i <= N - 1; i++) {
		if (s.count(make_pair(1, i)) && s.count(make_pair(i, N))) {
			ret = true;
		}
	}
	cout << (ret ? "POSSIBLE" : "IMPOSSIBLE") << endl;
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define INF 1000000000000000001
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll D;
  cin >> D;
  if (D == 25)
  {
    cout << "Christmas" << endl;
  }
  else if (D == 24)
  {
    cout << "Christmas Eve" << endl;
  }
  else if (D == 23)
  {
    cout << "Christmas Eve Eve" << endl;
  }
  else
  {
    cout << "Christmas Eve Eve Eve" << endl;
  }
}
// 3061st


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string a, b, c; cin >> a >> b >> c;
    if(a.back() == b[0] && b.back() == c[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int main() {
	ll n, x; cin >> n >> x;
	vector<ll> a(n);
	ll sum = 0;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	ll ans = 0;
	if (x < a[0]) {
		ans += a[0] - x;
		a[0] = x;
	}
	for (ll i = 1; i < n; i++) {
		ll a_now = a[i];
		ll a_prev = a[i - 1];
		ll diff = a_now + a_prev - x;
		if (x < a_now + a_prev) {
			a[i] -= diff;
			ans += diff;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4052
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
  int H,W;
  cin>>H;
  cin>>W;

  vector<string> hJOI;
  string c = "c";
  string period = ".";

  for(int i = 0;i < H;++i){
    string wJOI;
    cin>>wJOI;

    hJOI.push_back(wJOI);
  }

  int iJOI[100][100] = {0};

  
  for(int i = 0;i < H;++i){
    string wJOI;
    wJOI = hJOI[i];
    for(int j = 0;j < W;++j){
      string s;
      s = wJOI[j];
      if(j == 0 && s == period){
        iJOI[i][j] = -1;
      }
      else if(iJOI[i][j-1] == -1 && s == period){
        iJOI[i][j] = -1;
      }
    }
  }

  
  for(int i = 0;i < H;++i){
    string wJOI;
    wJOI = hJOI[i];
    int point;
    for(int j = 0;j < W;++j){
      string s;
      s = wJOI[j];
      
      if(iJOI[i][j] == -1 || iJOI[i][j-1] == -1 || s == c){
        continue;
      }
      else if(iJOI[i][j-1] == 0){
        point = j-1;
        iJOI[i][j] = 1;
      }
      else{
        iJOI[i][j] = j - point;
      }
    }
  }

  for(int i = 0;i < H;++i){
    for(int j = 0;j < W;++j){
      if(j == W-1){
        cout<<iJOI[i][j]<<endl;
      }
      else{
        cout<<iJOI[i][j]<<" ";
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3240
import java.util.*;
import java.util.Map.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	void solve(){
		int[] a=INTS(gInt()).toArray();

		long c=0;

		HashMap<Integer,Integer> map=new HashMap<>();
		{
			for(int v:a)
				map.merge(v,1,Integer::sum);
			for(Entry<Integer,Integer> e:map.entrySet()){
				long v=e.getValue();
				c+=v*(v-1)/2;
			}
		}

		{
			for(int v:a){
				long w=map.get(v);
				long t=w*(w-1)/2;
				long u=(w-1)*(w-2)/2;
				System.out.println(c-t+u);
			}
		}
	}

	public static void main(String[] A){
		new Main().solve();
	}

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	LongStream LONGS(int n){
		return LongStream.generate(this::gLong).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int t;
	Supplier<T> supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return (cur+d==to)||(d<0^cur+d<to);
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}


Measured memory_bytes: 78260
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    long long ans = 0;
    int N;

    cin >> N;

    for (int i = 1; i <= N; ++i) {
        if (i%3 != 0 && i%5 != 0) {
            ans += i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1600&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int m,nmin,nmax;
ll solve(){
    ll res = 0;
    vector<ll> score(m); for(auto& in:score) cin >> in;
    ll min = -1;
    for(int i = nmin-1; i < nmax;i++){
        if(score[i]-score[i+1] >= min){
            min = score[i] - score[i+1];
            res = i+1;
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> m >> nmin >> nmax,m){
        cout << solve() << endl;
    }
    return 0;
}



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

using namespace std;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

void sub()
{
    const auto N(cin2var<size_t>());
    const auto A(cin2var<size_t>());
    const auto B(cin2var<size_t>());
    const auto C(cin2var<size_t>());
    const auto D(cin2var<size_t>());

    const auto div_x = ceil(N / static_cast<double>(A));
    const auto sum_x = div_x * B;
    const auto div_y = ceil(N / static_cast<double>(C));
    const auto sum_y = div_y * D;
    const auto ans   = min(sum_x, sum_y);

    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    sub();
    return 0;
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
int cnt, dem;
string s;
int main()
{
    cin>>s;
    for (int i=0; i<s.size()-1; i++)
    {
        if (s[i]==s[i+1])
        {
            if (s[i]=='R')
            {
                cnt++;
            }
        }
        if (s[i]=='S')
        {
            dem++;
        }
    }
    if (s[s.size()-1]=='S')
    {
        dem++;
    }
    if (dem==s.size())
    {
        cout<<0;
    }
    else
    {
        cout<<cnt+1;
    }

}


Measured memory_bytes: 3612