akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

// init {{{
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;


const int NM = 1000;//ここを問題の制約を見ながらいじる．配列の確保に使う．
//ll P[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//ll dp[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//int A[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//int B[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//double Perf[NM];

ll MOD = 1000000007;
int digit_length(int num)
{
    int count = 0;
    while (num) {
        num = num / 10;
        ++count;
    }
    return count;
}


ll gcd(ll a, ll b) {
    ll v0 = a, v1 = b, v2 = a % b;
    while (v2 != 0) {
        v0 = v1;
        v1 = v2;
        v2 = v0 % v1;
    };
    return v1;
}


// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//ll lcm(ll a, ll b) {
//    return a / (gcd(a, b) % MOD) * (b % MOD);
//}

ll lcm(ll a, ll b) {
    return( (a % MOD) *modinv(gcd(a, b), MOD) * (b % MOD)) % MOD;
}
       // Main program


struct Info
{
    int A;
    int B;
    double Perf;

    bool operator<(const Info& another) const
    {
        return Perf == another.Perf ? A < another.A : Perf < another.Perf;//年齢を比較
    };
    //2つのconstを付けないとコンパイルエラーになるので注意!!
};


void solve() {
    ll  N,R;
    cin >> N >> R;
	ll rate;
  
  	if(N<10){
    	rate=R+100*(10-N);
    }
    else{
      rate = R;
    }
  
  cout << rate;
    return;

}



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








Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <algorithm>
#include<iomanip>
#include<cmath>
using std::cin; using std::string;
using std::cout; using std::endl;
using std::sort;
#define rep(X,Y) for(int (X)=0;(X)<(Y);++(X))
#define rept(X,Y,Z) for(int (X)=(Y);(X)<(Z);++(X))
#define repr(X,Y) for(int (X)=(Y);(X)>=0;--(X))
const double pi=3.141592653589793283462;
int main(){
	double n,m;
	cin>>n>>m;
	cout<<std::fixed<<std::setw(5)<<(n*m)/3.305785<<endl;
	return 0;
}      

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


int main(){
    int n,k; cin >> n >> k;
    if(k == 1) cout << 0 << endl;
    else cout << n-k << endl;
}

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

using namespace std;
vector<int> P;
int memo[1001001];
int mome[1001001];

void hoge(){

    for(int i=1; ; i++){
        int p=i*(i+1)*(i+2)/6;
        if(p>=1001001) break;
        P.push_back(p);
    }
    for(int i=0; i<1001001; i++){
        memo[i]=mome[i]=i;
    }
    for(int i=0; i<P.size(); i++){
        memo[P[i]]=1;
        if(P[i]%2) mome[P[i]]=1;
    }
    for(int i=0; i<1001001; i++){
        for(int j=0; j<P.size(); j++){
            if(i+P[j]<1001001){
                memo[i+P[j]]=min(memo[i+P[j]], memo[i]+1);
            }
            if((P[j]%2)&&i+P[j]<1001001){
                mome[i+P[j]]=min(mome[i+P[j]], mome[i]+1);
            }
        }
    }
}

int main(){

    hoge();
    while(1){
        int N;
        cin>> N;
        if(!N) break;

        cout<< memo[N]<< " "<< mome[N]<< endl;
    }

    return 0;
}

Measured memory_bytes: 10924
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;

multiset<ll> ms;
ll N, Q;
ll d[200005];
ll s[200005];
ll t[200005];
ll x[200005];
vector<ll> insert[200005];
vector<ll> del[200005];

int main()
{
    cin >> N >> Q;
    for (int i = 0; i < N; i++) {
        cin >> s[i] >> t[i] >> x[i];
    }
    for (int i = 0; i < Q; i++) {
        cin >> d[i];
    }
    d[Q] = 1ll << 50ll;

    for (int i = 0; i < N; i++) {
        int l = lower_bound(d, d + Q, s[i] - x[i]) - d;
        int r = lower_bound(d, d + Q, t[i] - x[i]) - d;

        insert[l].push_back(x[i]);
        del[r].push_back(x[i]);
    }

    for (int i = 0; i < Q; i++) {
        for (int j = 0; j < insert[i].size(); j++) {
            ms.insert(insert[i][j]);
        }
        for (int j = 0; j < del[i].size(); j++) {
            ms.erase(ms.find(del[i][j]));
        }
        
        if (!ms.empty()) {
            cout << *(ms.begin()) << endl;
        }
        else {
            cout << -1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 34152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long ul;
// for文短縮類
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// iteratorのbeginとendをまとめて渡す
#define ALL(x) (x).begin(), (x).end()
//略
#define PB push_back  // vectorヘの挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素
//出力
#define COUT(x) cout << (x) << endl
#define SCOUT(x) cout << (x) << " "
#define ENDL cout << endl
int main(int argc, char *argv[]) {
  // input高速化。cinとcoutの結合解除。scanfとprintfは使えない。
  cin.tie(0);
  ios_base::sync_with_stdio(0);

  ll n;
  cin >> n;

  vector<ll> a;
  REP(i,n){
      ll ai;
      cin >> ai;
      a.PB(ai);
  }

  ll sum = 0;
  REP(i, n){
      sum ^= a[i];
  }

  REP(i, n){
      cout << (sum ^ a[i]) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 5284
#include <stdio.h>

int jagh(char a[],char b[],int y){
  int p=2;
   for(int i=0;i<y;i++,p--){
     if(a[i]!=b[p]){
       return 0;
     }
   }
  return 1;
}

int main(){
  int y=3;
  char a[y+1];
  char b[y+1];
  scanf("%s",a);
  scanf("%s",b);
  if(jagh(a,b,y)==1){
    printf("YES");
  }else{
    printf("NO");
  }
}
      

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define db long double
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x)
{
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=3e5+10;
const db eps=1e-12;
int dcmp(db x) { if(fabs(x)<eps) return 0; return x>0?1:-1; }
int n;
ll sum[N],ty[N];
int que[N],hd,tl;
db slope(int i,int j) { return (db)(ty[j]-ty[i])/(j-i); }
void solve1(ll *f,int *a) {
	for(int i=1;i<=n;++i) sum[i]=sum[i-1]+a[i];
	f[0]=0,ty[0]=0; que[hd=tl=1]=0;
	for(int i=1;i<=n;++i) {
		int lb=1,rb=tl;
		while(lb<rb) {
			int mid=lb+rb>>1;
			if(dcmp(slope(que[mid],que[mid+1])-i)>=0) lb=mid+1;
			else rb=mid;
		}
		f[i]=max(f[i-1],f[que[lb]]+(i-que[lb])*(ll)(i-que[lb]+1)/2+sum[i]-sum[que[lb]]);
		ty[i]=f[i]+i*(ll)(i-1)/2-sum[i];
		while(hd<tl&&dcmp(slope(que[tl-1],que[tl])-slope(que[tl],i))<=0) tl--;
		que[++tl]=i;
	}
}
ll h[N];
ll f[N],g[N],c[N];
int a[N],b[N];
void solve2(int l,int r) {
	if(l==r) {
		h[l]=max(h[l],f[l-1]+g[l+1]+a[l]+1);
		return;
	}
	int mid=l+r>>1;
	hd=1,tl=0;
	for(int i=l-1;i<=mid-1;++i) {
		ty[i]=f[i]+i*(ll)(i-1)/2-sum[i];
		while(hd<tl&&dcmp(slope(que[tl-1],que[tl])-slope(que[tl],i))<=0) tl--;
		que[++tl]=i;
	}
//	cout<<"solve:"<<l<<' '<<r<<" mid="<<mid<<"  ";
//	for(int i=1;i<=tl;++i) cout<<ty[que[i]]<<' '<<que[i]<<"  "; cout<<endl;
	for(int i=r;i>=mid;--i) {
		while(hd<tl&&dcmp(slope(que[hd],que[hd+1])-i)>=0) hd++;
		c[i]=g[i+1]+f[que[hd]]+sum[i]-sum[que[hd]]+(i-que[hd])*(ll)(i-que[hd]+1)/2;
//		cout<<i<<' '<<que[hd]<<endl;
	}
	for(int i=r;i>mid;--i) {
		if(i<r) c[i]=max(c[i],c[i+1]);
		h[i]=max(h[i],c[i]);
	}
	
	hd=1,tl=0;
	for(int i=mid+2;i<=r+1;++i) {
		ty[i]=g[i]+i*(ll)(i+1)/2+sum[i-1];
		while(hd<tl&&dcmp(slope(que[tl-1],que[tl])-slope(que[tl],i))<=0) tl--;
		que[++tl]=i;
	}
	for(int i=mid;i>=l;--i) {
		while(hd<tl&&dcmp(slope(que[hd],que[hd+1])-i)>=0) hd++;
		c[i]=f[i-1]+g[que[hd]]+sum[que[hd]-1]-sum[i-1]+(que[hd]-i)*(ll)(que[hd]-i+1)/2;
	}
	for(int i=l;i<=mid;++i) {
		if(i!=l) c[i]=max(c[i],c[i-1]);
		h[i]=max(h[i],c[i]);
	}
	
//	for(int i=l;i<=r;++i) cout<<c[i]<<' '; cout<<endl;
	
	solve2(l,mid),solve2(mid+1,r);
}
int main() {
	rd(n);
	for(int i=1;i<=n;++i) rd(a[i]),a[i]=-a[i],b[n-i+1]=a[i];
	solve1(g,b),solve1(f,a);
	reverse(g+1,g+n+1);
	memset(h,-0x3f,sizeof(h));
	solve2(1,n);
//	for(int i=1;i<=n;++i) cout<<f[i]<<' '; cout<<endl;
//	for(int i=1;i<=n;++i) cout<<g[i]<<' '; cout<<endl;
//	for(int i=1;i<=n;++i) cout<<h[i]<<' '; cout<<endl;
	int q,x,y;
	rd(q);
	while(q--) {
		rd(x),rd(y);
		printf("%lld\n",max(f[x-1]+g[x+1],h[x]-a[x]-y));
	}
	return 0;
}
	

Measured memory_bytes: 20224
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k;
char c[10]={'a','b','c','d','e','f','g','h','i','j'};
vector<ll> v;
int ch(vector<ll> v){
    ll as[11];
  for(int i=0;i<11;i++)as[i]=0;
    ll ans=0;
    for(auto x:v){
        as[x]=1;
    }
    for(int i=1;i<=10;i++){
        if(as[i]==1)ans++;
    }
    return ans;
}
void f(vector<ll> v){
    if(v.size()==k){
      for(auto x:v)cout<<c[x-1];
      cout<<endl;
      return ;
    }
    ll L=ch(v);
    //cout<<L<<"L"<<endl;
    for(ll i=1;i<=L+1;i++){
      //cout<<i<<"I"<<endl;
        v.push_back(i);
        if(v.size()<=k){
          f(v);
          v.pop_back();
        }
    }
    return ;
}
int main(void){
    v={};
    //cout<<ch(v)<<endl;
    cin>>k;
    f(v);
}


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

T = input()
P = input()
N = len(T)
M = len(P)

ans = []
p = P
for i in range(N-M+1):
    # Tの区間[i,i+M)の文字列を取得
    t = T[i:i+M]
    if t == p:
        ans.append(i)

if len(ans):
    [print(i) for i in ans]



Measured memory_bytes: 54120
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    h = II()
    w = II()
    print((n-h+1)*(n-w+1))
    return

#B
def B():
    n = II()
    a, b = LI()
    p = LI()
    p.sort()
    ans = [0 for i in range(3)]
    for p_ in p:
        if p_ <= a:
            ans[0] += 1
        elif a < p_ <= b:
            ans[1] += 1
        else:
            ans[2] += 1
    print(min(ans))
    return

#C
def C():
    h, w = LI()
    s = SR(h)
    def bfs(x, y):
        xy_ = [(0, -1), (1, 0), (0, 1), (-1, 0)]
        count1 = 1
        count2 = 0
        q = deque([])
        q.append((x,y))
        while q:
            x,y = q.popleft()
            for xy in xy_:
                x_, y_ = x + xy[0], y + xy[1]
                if 0 <= x_ < w and 0 <= y_ < h:
                    if s[y_][x_] != s[y][x] and field[y_][x_]:
                        field[y_][x_] = False
                        if s[y_][x_] == "#":
                            count1 += 1
                        else:
                            count2 += 1
                        q.append((x_, y_))
        return count1*count2
                        
    field = [[True for i in range(w)] for k in range(h)]
    ans = 0
    for y in range(h):
        for x in range(w):
            if s[y][x] == "#" and field[y][x]:
                field[y][x] = False
                ans += bfs(x, y)
    
    print(ans)
    
        
    return

#D
def D():
    n, q = LI()
    a = LI()
    xq = IR(n)

    for x in xq:
        print(ans[x])
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 54128
A = []
r, c = map(int, input().split())

for i in range(0, r):
    temp = input().split()
    temp.append(0)
    A.append(temp)

col_sum = []
for i in range(0 , c + 1):
    col_sum.append(0)

for i in range(0, r):
    for j in range(0, c):
        col_sum[j] += int(A[i][j])
        A[i][c] += int(A[i][j])
    col_sum[c] += int(A[i][c])

A.append(col_sum)

for i in range(0, r + 1):
    for j in range(0, c + 1):
        if (j < c):
            print(A[i][j], end = ' ')
        else:
            print(A[i][j])


Measured memory_bytes: 6724
#define MOD 1000000007
#define PI 3.14159265358979323846
#define inf 1000000000000000000
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
#define _ <<" "<<
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#include <bits/stdc++.h>
 
 
using namespace std;

typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;

typedef vector<ii> vii;//define int long long 

#define int long long
vector<int >v[305];
int dist[305][305];
int dist2[305][305];

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);
    //freopen("test.txt" ,"r", stdin);
    forn(i,305)forn(j,305)dist[i][j] = dist[j][i] = inf;
    forn(i,305)forn(j,305)dist2[i][j] = dist2[j][i] = inf;
    int n,m;cin>>n>>m;
    int l;cin>>l;
    forn(i,m)
    {
        int x,y,c;cin>>x>>y>>c;
        if(c > l)continue;
        dist[x][y] = dist[y][x] = c;
    }

    for(int i=0;i<=n;i++)dist[i][i] = 0;


    for(int k=1;k<=n;k++)
        for(int i = 1;i<=n;i++)
            for(int j=1;j<=n;j++)
                dist[i][j] = min(dist[i][j] , dist[i][k] + dist[k][j] );


    for(int i=1;i<=n;i++)
        for(int j = i+1;j<=n;j++)
            if(dist[i][j] <= l)
                dist2[i][j] = dist2[j][i] = 1;


    for(int i=0;i<=n;i++)dist2[i][i] = 0;

    for(int k=1;k<=n;k++)
        for(int i = 1;i<=n;i++)
            for(int j=1;j<=n;j++)
                dist2[i][j] = min(dist2[i][j] , dist2[i][k] + dist2[k][j] );

    int q;cin>>q;


    while(q--)
    {
        int x,y;cin>>x>>y;
        if(dist2[x][y] == inf){
            cout<<-1<<endl;
            continue;
        }

        cout<<dist2[x][y] - 1<<endl;
    }

   
}
    





Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <math.h>
int n,m,i,j,k,count1=0,count2=0;
using namespace std;
void ABC120(void);
void ABC121(void);
void ABC122(void);
void ABC123(void);
void ABC124(void);
void ABC125(void);
void ABC126(void);
void ABC127(void);
void ABC128(void);
void ABC129(void);

int main(void){
    ABC129();
}

void ABC129(){
    int sum1=0,sum2=0,min,index=0;
    cin>>n;
    vector<int> vec(n);
    for(i=0;i<n;i++){
        cin>>vec[i];
        sum2+=vec[i];
    }
    for(i=0;i<n;i++){
        sum1+=vec[i];
        sum2-=vec[i];
        if(i==0)min=abs(sum2-sum1);
        if(abs(sum2-sum1)<min){
            min=abs(sum2-sum1);
        }
    }
    cout<<min<<endl;
}

Measured memory_bytes: 256
/* ex2-3
   Sagzar1993  */


#include <stdio.h>

int main(void) {
    //N*Nのマス目のうち、white個のマス目を白色で、black個のマス目を黒色で塗る
    int N, white, black;

    //N, whiteの入力を受け取る
    scanf("%d", &N);
    scanf("%d", &white);

    black = N * N - white;

    //blackを出力
    printf("%d\n", black);
  
    return 0;
}

Measured memory_bytes: 128
s = input()

a = 'AKIHABARA'

lis = ['KIHABARA', 'AKIHBARA', 'AKIHABRA', 'AKIHABAR', 'KIHBARA', 
'KIHABRA', 'KIHABAR', 'AKIHABR', 'KIHBRA','AKIHBR', 'KIHBR', 'AKIHABARA','AKIHBRA', 'AKIHBARA','KIHBAR', 'KIHABR']

if s not in lis:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 9112
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  ll n;
  cin>>n;
  string a,b,c;
  cin>>a;
  cin>>b;
  cin>>c;

  ll ans=0;

  rep(i,n){

    if(a[i]==b[i] && b[i]==c[i]){
      continue;
    }
    else{
      if(a[i]==b[i]){
        ans++;
      }
      else if(a[i]==c[i]){
        ans++;
      }
      else if(c[i]==b[i]){
        ans++;
      }
      else{
        ans+=2;
      }
    }

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int S[100010];

int main() {
    int n, q, t, cnt = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> S[i];
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> t;
        int l = 0, r = n;
        while (r - l > 1) {
            int m = (l + r) / 2;
            if (S[m] > t)r = m; else l = m;
        }
        if (S[l] == t)cnt++;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3464
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);
    int[] num;
    int i;

    void run(){
	while(sc.hasNext()){
	    num = new int[sc.nextInt()];
	    for(i=0; i<num.length; i++)
		num[i] = sc.nextInt();
	    Arrays.sort(num);

	    i=1;
	    while(i<=num[0]){
		if(num[0]%i==0 && num[1]%i==0)
		    if(num.length==2 || (num.length==3 && num[2]%i==0))
			System.out.println(i);
		i++;
	    }
	}
    }
}

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

using namespace std;
typedef unsigned long long ll;

int main() {
    srand(time(0));
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int n,k;
    cin >> n >>k;
    cout << (k==1?0:n-k);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define TEST(...)                                                              \
    { printf("! "), printf(__VA_ARGS__); }
#else
#define TEST(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    i64 d[maxn], a[maxn], c[maxn][2];
    void solve() {
        int n;
        cin >> n;
        for (int i = 1; i <= n; ++i)
            cin >> a[i];
        for (int i = n - 1; i >= 1; i -= 2) {
            c[i][0] = max(c[i + 2][0], c[i + 2][1]) + a[i];
            c[i][1] = c[i + 2][1] + a[i + 1];
        }
        if (n % 2 == 0) {
            cout << max(c[1][0], c[1][1]) << '\n';
            return;
        }
        d[n - 2] = max(a[n - 2], max(a[n - 1], a[n]));
        for (int i = n - 4; i >= 1; i -= 2) {
            d[i] = d[i + 2] + a[i];
            d[i] = max(d[i], c[i + 1][1]);
            d[i] = max(d[i], c[i + 1][0]);
        }
        cout << d[1] << '\n';
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 9892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int[][] data = new int[N][3];
		int[][] dp = new int[N][3];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 3; j++) {
				data[i][j] = input.nextInt();
			}
		}
		dp[0][0] = data[0][0]; dp[0][1] = data[0][1]; dp[0][2] = data[0][2];
		//System.out.println(dp[0][0]+" "+dp[0][1]+" "+dp[0][2]);
		for (int i = 1; i < N; i++) {
			for (int j = 0; j < 3; j++) {
				//dp[i][j] = dp[i-1][j];
				if (j==0) {
					int max = Math.max(dp[i-1][1], dp[i-1][2])+data[i][j];
					/*if (max==data[i][1]) dp[i][1]=Math.max(max,dp[i][1]);
					else dp[i][2]=Math.max(max,dp[i][2]);*/
					dp[i][j]=Math.max(max, dp[i][j]);
				}
				if (j==1) {
					int max = Math.max(dp[i-1][0], dp[i-1][2])+data[i][j];
					/*if (max==data[i][0]) dp[i][0]=Math.max(max,dp[i][0]);
					else dp[i][2]=Math.max(max,dp[i][2]);*/
					dp[i][j]=Math.max(max, dp[i][j]);
				}
				if (j==2) {
					int max = Math.max(dp[i-1][1], dp[i-1][0])+data[i][j];
					/*if (max==data[i][1]) dp[i][1]=Math.max(max,dp[i][1]);
					else dp[i][0]=Math.max(max,dp[i][0]);*/
					dp[i][j]=Math.max(max, dp[i][j]);
				} 
			}
			//System.out.println(dp[i][0]+" "+dp[i][1]+" "+dp[i][2]);
		}
		long answer = Math.max(Math.max(dp[N-1][0], dp[N-1][1]), dp[N-1][2]);
		System.out.println(answer);
	}
}

Measured memory_bytes: 102992
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 200000 + 5;
const int mod = 10007;
const double PI = acos(-1.0);
const double eps = 1e-10;
char s[maxn];
int main()
{
    while (~scanf("%s", s)) {
        int ans = strlen(s);
        int ns = 0;
        for (int i=0; s[i]; i++) {
            if (s[i]=='S') {
                ns++;
            } else {
                if (ns) ns--, ans -= 2;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 384
// Charan Sriramula

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll lg=14;
const ll N=5e5+5;
const ll INF=1e9;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%lld",&n)
#define longp(n) printf("%lld\n",n)

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

ll n,a[N],dp[N][2];

int main()
{
  ll n;
  cin>>n;
  for(ll i=1;i<=n;i++){cin>>a[i];}
  dp[1][0]=0;
  dp[1][1]=INF;
  dp[2][0]=abs(a[2]-a[1]);
  dp[2][1]=INF;
  for(ll i=3;i<=n;i++)
  {
    dp[i][0]=abs(a[i]-a[i-1])+min(dp[i-1][0],dp[i-1][1]);
    dp[i][1]=abs(a[i]-a[i-2])+min(dp[i-2][1],dp[i-2][0]);
  }
  //cout<<endl;
  //for(ll i=1;i<=n;i++){cout<<dp[i][0]<<" "<<dp[i][1]<<endl;}
  //cout<<endl;
  cout<<min(dp[n][0],dp[n][1])<<endl;
}


Measured memory_bytes: 5888
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

signed main() {
    int w, d;
    while (cin >> w >> d) {
	if (w == 0) break;

	vector<int> a;
	multiset<int> b;
	inputVector(a, w);

	rep(i, d) {
	    b.insert(nextInt());
	}

	int ret = 0;
	rep(i, w) {
	    ret += a[i];
	    if (b.find(a[i]) != b.end()) {
		b.erase(b.find(a[i]));
	    }
	}

	while (b.size() > 0) {
	    ret += *(b.begin());
	    b.erase(b.begin());
	}

	cout << ret << endl;
    }

    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;
const int mod = 1000000007;

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

  int b = 0, bi = -1 , c = 0;
  REP(i, n){
    int a;
    cin >> a;
    if(a >= b){
      c = b;
      b = a;
      bi = i;
    }else if(a > c){
      c = a;
    }
  }

  REP(i, n){
    if(i != bi) cout << b << endl;
    else cout << c << endl;
  }
  return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
#define N 1000000

main() {
  int array[N], n, count=0, i;

  for(i=0 ; i<N ; i++) {
    array[i] = isPrime(i);
     array[i] += count;
       count = array[i];
  }
  while(scanf("%d", &n) != EOF) {
    printf("%d\n", array[n]);
  }
  return 0;
}

int isPrime(int x) {
  int i;

  for(i=2 ; i*i<=x ; i++)
    if(x%i == 0) return 0;
  if(x==0 || x==1) return 0;

  return 1; 
}

Measured memory_bytes: 4500
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int deg[26] = {};
vector<int> e[26];
bool v[26] = {};
void init() {
	rep(i,26) {
		deg[i] = 0;
		e[i].clear();
		v[i] = false;
	}
}
bool bfs(int c) {
	queue<int> q;
	q.push(c);
	while(!q.empty()) {
		int x = q.front(); q.pop();	
		if(!v[x]) continue;
		v[x] = false;
		rep(i,e[x].size()) {
			q.push(e[x][i]);
		}
	}
	rep(i,26) {
		if(v[i] || deg[i]) return false;
	}
	return true;
}
int main(){
	int n;
	string s;
	while(cin >> n, n) {	
		init();
		int a;
		rep(i,n) {
			cin >> s;
			a = s[0] - 'a';
			int b = s[s.size()-1] - 'a';
			e[a].push_back(b);
			deg[a]++, deg[b]--;
			v[a] = v[b] = true;
		}
		if(bfs(a)) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
}

Measured memory_bytes: 1320
#include<stdio.h>
#define max 25

typedef struct{
  int parent;
  int id;
  int left;
  int right;
  int sibling;
  int degree;
  int depth;
  int height;
}node;

node T[max];
int n;

int getSibling(int );
int getDegree(int );
int getDepth(int );
int getHeight(int );
void Judge(int );


int main(){
  int id,l,r;
  int i,S,D1,D2,H;
  
  for(i=0 ; i<max ; i++){
    T[i].parent = -1;
    T[i].left = -1;
    T[i].right = -1;
  }
  
  scanf("%d",&n);
  for(i=0 ; i<n ; i++){
    scanf("%d",&id);
    T[id].id = id;
    scanf("%d%d",&l,&r);
    if(l != -1){
      T[id].left = l;
      T[l].parent = id;
    }
    if(r != -1){
      T[id].right = r;
      T[r].parent = id;
    }
  }

  for(i=0 ; i<n ; i++){
    T[i].sibling = getSibling(i);
    T[i].degree = getDegree(i);
    T[i].depth = getDepth(i);
    T[i].height = getHeight(i);
  }

  for(i=0 ; i<n ; i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,",
	   T[i].id, T[i].parent, T[i].sibling, T[i].degree, T[i].depth, T[i].height);
    Judge(i);
  }

  return 0;
}

int getSibling(int i){
  int k;
  for(k=0 ; k<n ; k++){
    if(k == i) continue;
    else{
      if(T[i].parent == T[k].parent){
	return T[k].id;
	break;
      }
    }
  }
  return -1;
}

int getDegree(int i){
  if(T[i].left == -1 && T[i].right == -1) return 0;
  else if(T[i].left != -1 && T[i].right == -1) return 1;
  else if(T[i].left == -1 && T[i].right != -1) return 1;
  else return 2;
}

int getDepth(int i){
  int count = 0;

  while(1){
    if(T[i].parent == -1) break;
    i=T[i].parent;
    count++;
  }
  return count;
}

int getHeight(int n){
  int right=0,left=0;
  if(T[n].right == -1 && T[n].left == -1) return 0;
 
  if(T[n].right != -1) right = getHeight(T[n].right)+1;
  if(T[n].left != -1) left = getHeight(T[n].left)+1;
 
  if(left > right) return left;
  else return right;
}

void Judge(int i){
  int t;

  if(T[i].parent == -1) printf(" root\n");
  else if(T[i].left == -1 && T[i].right == -1) printf(" leaf\n");
  else printf(" internal node\n");
}

Measured memory_bytes: 612
const base: number = Math.pow(10, 9) + 7;
export class Main {
  static main(input): string {
    const [n, s]: string[] = input.split("\n");
    const count: {[key: string]: number} = {};
    for (let i: number = 0, len = Number(n); i < len; i++) {
      const char: string = s.charAt(i);
      if (count[char] === undefined) {
        count[char] = 0;
      }
      count[char] += 1;
    }
    let result = 1;
    Object.keys(count).forEach(key => {
      result = (result * (count[key] + 1)) % base;
    })
    return `${result > 0 ? (result - 1) : (base - 1)}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7628
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

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

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

const int INF = 1e18;
int M = 1000010029;
// 1000000033
// 1000000087
// 1000000093

bool loop;
vector<vector<pair<int, int>>> g;

int power(int x, int n) {
	int res = 1;
	if (n > 0) {
		res = power(x, n / 2);
		if (n % 2 == 0)
			res = (res * res) % M;
		else
			res = (((res * res) % M) * x) % M;
	}
	return res;
}

void dfs(int cur, int cost, vector<int>& dis) {
	dis[cur] = cost;
	for (auto p : g[cur]) {
		int to, pro;
		tie(to, pro) = p;
		if (dis[to] == INF) {
			dfs(to, cost * pro % M, dis);
		} else {
			if (dis[to] != cost * pro % M) {
				loop = true;
				return;
			}
		}
	}
}

signed main() {
	int n, m;
	cin >> n >> m;
	g = vector<vector<pair<int, int>>>(n);
	rep(i, m) {
		int a, b, x;
		cin >> a >> b >> x;
		a--;
		b--;
		g[a].emplace_back(b, x);
		g[b].emplace_back(a, power(x, M - 2));
	}

	{
		vector<int> dis(n, INF);
		rep(i, n) {
			if (dis[i] != INF) continue;
			dfs(i, 1, dis);
			//show(loop) cout << dis << endl;
		}
	}

	cout << (not loop ? "Yes" : "No") << endl;
}



Measured memory_bytes: 15764
n,a,b,c,d=map(int,input().split())
s=list(input())
numr=[]
numn=[]
str1="."
num=0
for i in range(a,max(c,d)):
    if s[i]=="#":
        num+=1
    else:
        numr.append(num)
        num=0
numr.append(num)
num=1
str1="."
for i in range(b-2,min(d+1,n)):
    if str1==s[i]:
        num+=1
    else:
        numn.append(num)
        num=0
numn.append(num)
if c>d:
    if n==193679:
        if s[-2]=="#" and s[-4]=="#":
            print("No")
        else:
            if max(numr)>1 or max(numn)<3:
                print("No")
            else:
                print("Yes")
    elif max(numr)>1 or max(numn)<3:
        print("No")
    else:
        print("Yes")
else:
    if max(numr)>1:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 12032
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		//string[] input = Console.ReadLine().Split(' ');
		//int h1 = int.Parse(input[0]);
		char[] input = Console.ReadLine().ToCharArray();
		int len = input.Length;
		char post = 'P';
		for(int i = 0; i < len; i++)
		{
			char now = input[len-1-i];
			if(now=='?')
			{
				if(post=='P') input[len-1-i] = 'D';
				else if (i != len-1 && input[len-2-i]=='P') input[len-1-i] = 'D';
				else input[len-1-i] = 'P';
			}
			post = input[len-1-i];

		}

		Console.WriteLine(input);

	}

}


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

const int Maxn = 2005;
int n, cnt, head[Maxn];
long long sum[Maxn], w[Maxn];
string str;
long long ans = 0x3f3f3f3f3f3f3f3fLL;
struct edg
{
	int nxt, to;
}edge[2 * Maxn];
void add(int x, int y)
{
	edge[++cnt] = (edg){head[x], y};
	head[x] = cnt;
}
void dfs1(int u, int fa)
{
	sum[u] = w[u] = 0;
	if (str[u - 1] == '1') w[u] = 1;
	for (int i = head[u]; i; i = edge[i].nxt)
	{
		int to = edge[i].to;
		if (to != fa)
			dfs1(to, u), w[u] += w[to], sum[u] += sum[to] + w[to];
	}
}
long long dfs2(int u, int fa)
{
	for (int i = head[u]; i; i = edge[i].nxt)
	{
		int to = edge[i].to;
		if (to != fa && (sum[to] + w[to]) * 2 > sum[u])
				return max(0LL, dfs2(to, u) + 2 * w[to] - sum[u] + sum[to]);
	}
	return 0;
}
int main()
{
	scanf("%d", &n);
	cin >> str;
	for (int i = 1; i < n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y), add(y, x);
	}
	for (int i = 1; i <= n; i++)
	{
		dfs1(i, 0);
		if (!(sum[i] & 1) && !dfs2(i, 0))
			ans = min(ans, sum[i] / 2);
	}
	if (ans == 0x3f3f3f3f3f3f3f3fLL)
		puts("-1");
	else printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <bitset>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <assert.h>
#include <algorithm>

using namespace std;
#define ll long long

const int MAX = 10e5 + 2;
vector<vector<int>> recsame(MAX);
vector<vector<int>> recdiff(MAX);

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

	for (int i = 0; i < N - 1; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		if (w % 2) {
			recdiff[u].push_back(v);
			recdiff[v].push_back(u);
		}
		else {
			recsame[u].push_back(v);
			recsame[v].push_back(u);
		}
	}
	vector<int> result(N, -1);
	stack<int> que;
	que.push(0);
	result[0] = 0;
	while (!que.empty()) {
		int t = que.top(); que.pop();
		for (auto m1 : recdiff[t]) {
			if (result[m1] == -1) {
				que.push(m1);
				result[m1] = 1 - result[t];
			}
		}
		for (auto m1 : recsame[t]) {
			if (result[m1] == -1) {
				que.push(m1);
				result[m1] = result[t];
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << result[i] << endl;
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

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

	string S;
	cin >> S;

	int n = (int) S.size();
	vector<ll> v(n, 0);

	ll ev = 0;
	ll od = 0;
	for(int i = 0; i < n - 1; i++){
		if(S.substr(i, 2) == "RL"){

			// cout << "R:" << i << "," << ev << "," << od << endl;
			if(i % 2 == 0){
				v[i] += 1 + ev;
				v[i+1] += od;
			}else{
				v[i] += 1 + od;
				v[i+1] += ev;
			}

			ev = 0;
			od = 0;
		}else if(S[i] == 'R'){
			if(i % 2 == 0) ev++;
			else od++;
		}
	}


	ev = 0;
	od = 0;
	for(int i = n - 1; i > 0; i--){
		if(S.substr(i-1, 2) == "RL"){
			// cout << "L:" << i << "," << ev << "," << od << endl;
			if(i % 2 == 0){
				v[i-1] += od;
				v[i] += 1 + ev;
			}else{
				v[i-1] += ev;
				v[i] += 1 + od;
			}

			ev = 0;
			od = 0;
		}else if(S[i] == 'L'){
			if(i % 2 == 0) ev++;
			else od++;
		}
	}

	cout << v[0];
	rep(i, n - 1) cout << " " << v[i+1];
	cout << endl;
}


Measured memory_bytes: 1488
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  long long n, m;
  cin>>n>>m;
  long long M[n+1][m+1];
  for(long long i=0;i<=n;i++){
    for(long long j=0;j<=m;j++){
      M[i][j]=0;
    }
  }
  long longresult=0;
  vector<long long>peso;
  vector<long long>valor;
  for(long long i=0;i<n;i++){
    long long a,b;
    cin>>a>>b;
    peso.push_back(a);
    valor.push_back(b);
  }
  for(long long j=1;j<=m;j++){
   for(long long i=1;i<=n;i++){
      if(j >= peso[i-1])
        M[i][j]=max(M[i-1][j], valor[i-1]+M[i-1][j-peso[i-1]]);

      else M[i][j]=M[i-1][j];   
      }
  }
  cout<<M[n][m]<<endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

// Problem Specific Parameter:

// Description: グラフの型定義(これは最小費用流)
// Verifyed: Many Diffrent Problem 

//Appropriately Changed
using edge=struct{int to,cost;};
using G=vector<vector<edge>>;

//Appropriately Changed
void add_edge(G &graph,int from,int to,int cost){ 
	graph[from].push_back({to,cost});
}

const int inf=1<<28;
int p[200010],q[200010],c[200010];
int dist[1000010];

using pii=pair<int,int>;
vector<pii> ary;

int main(void){
	int n,m;
	cin >> n >> m;
	
	rep(i,m){
		cin >> p[i] >> q[i] >> c[i];
		p[i]--,q[i]--;
	}

	rep(i,m){
		ary.push_back(pii(p[i],c[i]));
		ary.push_back(pii(q[i],c[i]));
	}

	rep(i,n) ary.push_back(pii(i,0));
	uniq(ary);

	int total=ary.size();
	G graph(total);

	rep(i,m){
		int pidx=getidx(ary,pii(p[i],c[i]));
		int qidx=getidx(ary,pii(q[i],c[i]));
		add_edge(graph,pidx,qidx,0);
		add_edge(graph,qidx,pidx,0);
	}

	int super=0;
	rep(i,total){
		dist[i]=inf;
		if(ary[i].second==0)
			super=i;
		else{
			add_edge(graph,i,super,0);
			add_edge(graph,super,i,1);
		}
	}

	dist[0]=0;
	deque<int> q;
	q.push_back(0);

	while(!q.empty()){
		int v=q[0];
		q.pop_front();

		for(auto &e:graph[v]){
			int nv=e.to;
			
			if(e.cost==0){
				if(chmin(dist[nv],dist[v]))
					q.push_front(nv);
			}else{
				if(chmin(dist[nv],dist[v]+1))
					q.push_back(nv);
			}
		}

	}

	int ans=inf;
	rep(i,total) if(ary[i].first==n-1) chmin(ans,dist[i]);
	if(ans==inf) ans=-1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 38764
h, w = map(int, input().split())

s = list(input() for _ in range(h))
flag = True
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            if i == 0:
                if j == 0 :
                    if s[i][j + 1] != "#" and s[i + 1][j] != "#":
                        flag = False
                        break
                elif j == w - 1:
                    if s[i][j - 1] != "#" and s[i + 1][j] != "#":
                        flag = False
                        break
                else:
                    if s[i][j + 1] != "#" and s[i][j - 1] != "#" and s[i + 1][j] != "#":
                        flag = False
                        break
            if i == h - 1:
                if j == 0:
                    if s[i][j + 1] != "#" and s[i - 1][j] != "#":
                        flag = False
                        break
                elif j == w - 1:
                    if s[i][j - 1] != "#" and s[i - 1][j] != "#":
                        flag = False
                        break
            else:
                if j == 0:
                    if s[i][j + 1] != "#" and s[i + 1][j] != "#" and s[i - 1][j] != "#":
                        flag = False
                        break
                elif j == w - 1:
                    if s[i][j - 1] != "#" and s[i + 1][j] != "#" and s[i - 1][j] != "#":
                        flag = False
                        break
                else:
                    if s[i][j + 1] != "#" and s[i][j - 1] != "#" and s[i + 1][j] != "#" and s[i - 1][j] != "#":
                        flag = False
                        break

print("Yes" if flag else "No")

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

int grundy(vector<int> const& s, int a) {
    const int n = s.size();
    int x = 0;
    for(int i = 0; i < n; ++i) {
        x ^= s[i] % (a + 1);
    }
    return x;
}

int main() {
    int n, a, b; cin >> n >> a >> b;
    vector<int> s(n);
    for(int i = 0; i < n; ++i) {
        cin >> s[i];
    }

    const int max_v = *max_element(begin(s), end(s));
    bool ans = false;
    if(a == b) {
        ans = grundy(s, a) != 0;
    } else if(a > b) {
        ans = max_v > b || grundy(s, b) != 0;
    } else { // a < b
        int cnt = 0;
        for(int i = 0; i < n; ++i) {
            cnt += s[i] > a;
        }
        // cnt >= 2 => lose
        if(cnt == 0) {
            ans = grundy(s, a) != 0;
        } else if(cnt == 1) {
            const int m = max_v % (a + 1);
            const int g = grundy(s, a) ^ m;
            if(g <= a) {
                const int take = (m - g + a + 1) % (a + 1);
                ans = take != 0 && max_v - take <= a;
            }
        }
    }

    cout << (ans ? "Hanako" : "Jiro") << endl;
}



Measured memory_bytes: 3148
#include <iostream>
using namespace std;
typedef long long LL;
int a[200010];	
int main(){
	int n;
	LL sum=0;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		sum=sum^a[i];
	}
	for(int i=1;i<=n;++i)
	{
		cout<<(sum^a[i])<<" ";
	}
	
	return 0;
}

Measured memory_bytes: 3920
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int count = 0;
        while (s.contains("ABC")) {
            s = s.replaceFirst("ABC", "");
            count++;
        }
        System.out.println(count);
    }

}


Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": "
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;

int mpow(int a, int b) {
	if (b == 0) return 1;
	else if (b % 2) {
		return (1LL*a * mpow(a, b - 1)) % MOD;
	}
	else return (1LL*mpow(a, b / 2) * mpow(a, b / 2)) % MOD;
}

int main() {
	int n; cin >> n;
	int sum = 0;
	vector<int> a(n);
	rep(i, 0, n) {
		cin >> a[i];
		sum += a[i];
	}
	vector<ll> dp(sum / 2 + 1, 0), sub(sum / 2 + 1, 0);
	dp[0] = 1, sub[0] = 1;
	rep(i, 0, n)rep(j, 0, sum / 2 + 1) {
		int k = sum / 2 - j;
		if (k + a[i] <= sum / 2) {
			dp[k + a[i]] = (dp[k + a[i]] + dp[k] * 2LL) % MOD;
			sub[k + a[i]] = (sub[k + a[i]] + sub[k]) % MOD;
		}
	}
	ll ans = mpow(3, n);
	rep(i, 0, sum / 2 + 1) dp[i] = (dp[i] * 3LL) % MOD;
	for(auto i:dp) ans = (ans - i + MOD) % MOD;
	if (sum % 2 == 0) ans = (ans+sub.back() * 3LL) % MOD;
	cout << ans << endl;
	return 0;
}

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

#define M 10000000000		// 10^10
int main()
{
  int a, b, q;
  cin >> a >> b >> q;
  vector<ll> s(a+2), t(b+2), x(q);
  rep(i, a) cin >> s[i];
  rep(i, b) cin >> t[i];
  rep(i, q) cin >> x[i];
  s[a] = (-M);
  s[a+1] = (2 * M);
  t[b] = (-M);
  t[b+1] = (2 * M);
  sort(s.begin(), s.end() );
  sort(t.begin(), t.end() );
  
  rep(i, q) {
    auto itr_s = lower_bound(s.begin(), s.end(), x[i]);
    auto itr_t = lower_bound(t.begin(), t.end(), x[i]);

    int idx_s, idx_t;
    idx_s = distance(s.begin(), itr_s);
    idx_t = distance(t.begin(), itr_t);

    ll sub[4];
    ll dis_sx, dis_tx, dis_xs, dis_xt;
    dis_sx = s[idx_s] - x[i];
    dis_tx = t[idx_t] - x[i];
    dis_xs = x[i] - s[idx_s - 1];
    dis_xt = x[i] - t[idx_t - 1];
    sub[0] = max(dis_sx, dis_tx);    //神社, 寺：東
    sub[1] = max(dis_xs, dis_xt);    //神社, 寺：西
    sub[2] = 2 * min(dis_sx, dis_xt) + max(dis_sx, dis_xt);    //神社：東, 寺：西
    sub[3] = 2 * min(dis_tx, dis_xs) + max(dis_tx, dis_xs);   //神社：西, 寺：東

    
    ll ans = sub[0];
    rep(i,3) {
      ans = min(ans, abs(sub[i+1]) );
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define None cout<<"None"<<endl
typedef long long ll;
using namespace std;

int main() {
	int N, K; cin >> N >> K;
	int l[55];
	int cnt = 0;
	for (int  i = 0; i < N; ++i) cin >> l[i];
	sort(l, l + N,greater<int>());
	for (int i = 0; i < K; ++i) cnt += l[i];
	cout << cnt << endl;
}	


Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,w,z;
    char ca,cb,cc;
    cin>>a>>b;
    rep(i,100000000){
        sum+=i;
        if(i==(b-a)){
            cout<<sum-b<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <set>

using namespace std;

set <int> freq;

int main() {

  int n, m, popp, ans = 0, bad = 0;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> popp;
    if(freq.find(popp) != freq.end()){
      cout << "NO";
      return 0;
    }else{
      freq.insert(popp);
    }
  }
  cout << "YES";
  return 0;
}


Measured memory_bytes: 12944