akhauriyash/Code-Regression huggingface dataset:
class SegTree:
    def __init__(self, N, S):
        self.N = 2 ** ((N-1).bit_length())
        self.tree = [0 for i in range(self.N * 2 - 1)]
        for i in range(len(S)):
            self.tree[self.N - 1 + i] = 1 << (ord(S[i]) - ord("a"))

        for i in range(self.N - 2, -1, -1):
            self.tree[i] = self.tree[i*2 + 1] | self.tree[i*2 + 2]

    def update(self, index, char):
        i = self.N - 1 + index
        # アルファベットがある = bitが立っている
        self.tree[i] = 1 << (ord(char) - ord("a"))
        while i > 0:
            i = (i-1) // 2
            self.tree[i] = self.tree[i*2 + 1] | self.tree[i*2 + 2]

    def get(self, a, b):
        return self.query(a, b, 0, 0, self.N)

    # k : ノードの番号
    # l : ノードkの受け持つ区間
    # r : ノードkの受け持つ区間
    def query(self, a, b, k, l, r):
        if r <= a or b <= l: # 区間外
            return 0
        elif a <= l and r <= b: # 受け持ち区間は完全に含まれている
            return self.tree[k]
        else: # 一部含まれてる
            left = self.query(a, b, 2 * k + 1, l, (l+r)//2)
            right = self.query(a, b, 2 * k + 2, (l+r)//2, r)
            return left | right

def solve():
    N = int(input())
    S = list(input().strip())
    tree = SegTree(N, S)

    Q = int(input())
    for _ in range(Q):
        t_q, in_1, in_2 = input().split()
        if t_q == "1":
            i_q = int(in_1)
            c_q = in_2
            tree.update(i_q-1, c_q)
        else:
            l_q = int(in_1)
            r_q = int(in_2)
            print(bin(tree.get(l_q-1, r_q)).count("1"))

solve()

Measured memory_bytes: 47400
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1 << 30;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }
class Flow
{
public:
    struct Edge
    {
        int from, to, revind, capacity, flow;
        bool reversed;
    };
    Flow(const int v) : V{v}, edge(v) {}
    void addEdge(const int from, const int to, const int capacity) { edge[from].push_back(Edge{from, to, (int)edge[to].size(), capacity, 0, false}), edge[to].push_back(Edge{to, from, (int)edge[from].size() - 1, capacity, capacity, true}); }
    int FordFulkerson(const int s, const int t)
    {
        vector<bool> checked(V);
        auto dfs = fix([&](auto&& self, const int pos, const int& flow) -> int {
            if (pos == t) { return flow; }
            checked[pos] = true;
            for (auto& e : edge[pos]) {
                if (not checked[e.to]) {
                    const int res = e.capacity - e.flow;
                    if (res > 0) {
                        const int d = self(self, e.to, min(flow, res));
                        if (d > 0) {
                            e.flow += min(d, res), edge[e.to][e.revind].flow -= min(d, res);
                            return d;
                        }
                    }
                }
            }
            return 0;
        });
        int flow = 0;
        while (true) {
            for (int i = 0; i < V; i++) { checked[i] = false; }
            const int f = dfs(s, INF);
            if (f == 0) { break; }
            flow += f;
        }
        return flow;
    }
    const int V;
    vector<vector<Edge>> edge;
};
int main()
{
    for (int N, M;;) {
        cin >> N >> M;
        if (N == 0 and M == 0) { break; }
        Flow flow(N + M + 2);
        const int S = N + M, T = N + M + 1;
        for (int i = 0, u, v; i < M; i++) { cin >> u >> v, u--, v--, flow.addEdge(u, i + N, 1), flow.addEdge(v, i + N, 1); }
        for (int i = N; i < N + M; i++) { flow.addEdge(i, T, 1); }
        int inf = M / N;
        for (; inf >= 0; inf--) {
            auto f = flow;
            for (int i = 0; i < N; i++) { f.addEdge(S, i, inf); }
            const int F = f.FordFulkerson(S, T);
            if (F >= inf * N) { break; }
        }
        int sup = 1;
        for (;; sup++) {
            auto f = flow;
            for (int i = 0; i < N; i++) { f.addEdge(S, i, sup); }
            const int F = f.FordFulkerson(S, T);
            if (F >= M) { break; }
        }
        cout << inf << " " << sup << endl;
    }
    return 0;
}



Measured memory_bytes: 4616
import sys
input = sys.stdin.readline
n, m, q = map(int, input().split())
x = [[0 for i in range(n + 1)] for j in range(n + 1)]
c = [[0 for i in range(n + 1)] for j in range(n + 1)]
for i in range(m):
    l, r = map(int, input().split())
    c[l][r] += 1
for i in range(1, n + 1):
    for j in range(1, n + 1):
        x[i][j] = x[i][j - 1] + c[i][j]
for k in range(q):
    ans = 0
    p, q2 = map(int, input().split())
    for i in range(p, q2 + 1):
        ans += x[i][q2] - x[i][p - 1]
    print(ans)

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

int main(){
  int n;
  cin >> n;
  if(n % 1000 == 0) cout << 0 << endl;
  else cout << 1000 - n % 1000 << endl;
  return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
str S;
int main(){
  cin>>S;
  bool f=true;
  rep(i,3){
    if(S[i]==S[i+1]){
      f=false;
      break;
    }
  }
  if(f) prin("Good");
  else prin("Bad");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long
#define int long long
#define ld long double
#define endl '\n'
const int mod= 1e9+7;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define trace(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
#define reset(x,val) memset(x,val,sizeof(x))
#define flush fflush(stdout)
#define sz(a) a.size()
#define pii pair<int,int>
using namespace std;
int tree[1000000];//,a[1e6+1];
/*void build(int node,int left,int right)
{
 if(left==right)tree[node]=a[left];
 else
 {
  int mid=(left+right)>>1;
  build(2*node,left,mid);
  build(2*node+1,mid+1,right);
  tree[node]=max( tree[2*node],tree[2*node+1] );
 }
}*/
int query(int node,int left,int right,int ql,int qr)
{
 if(ql>right || qr<left)return -100;
 if(left>=ql && right<=qr)
 return tree[node];
 int mid=(left+right)>>1;
 return max( query(2*node,left,mid,ql,qr),query(2*node+1,mid+1,right,ql,qr) );
 
}
void update(int node,int left,int right,int height,int value)
{if(left>height||height>right)
 return;
 if(left==right)
 {
  tree[node]=value;
  return;
 }
 
 int mid=(left+right)>>1;
 //if(left<=height && mid>=height)
 update(2*node,left,mid,height,value);
 //else
 update(2*node+1,mid+1,right,height,value);
 
 tree[node]=max(tree[2*node],tree[2*node+1]); 
}
int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;
    cin>>n;
    int h[n+1],ip[n+1];
    for(int i=1;i<=n;i++)
    cin>>h[i];
    int v;    
    for(int i=1;i<=n;i++)
     {
      cin>>ip[i];
     }
    int dp[n+1]={0};
    //build(1,1,n);
    for(int i=1;i<=n;i++)
    {
     if(h[i]==1){dp[i]=ip[i];}
     else
     dp[i]=ip[i]+query(1,1,n,1,h[i]-1);
     //if(i==4)cout<<"f= "<<query(1,1,n,1,h[i]-1)<<endl;
     //if(h[i]==1)h[i]++;
     //cout<<dp[i]<<endl;
     update(1,1,n,h[i],dp[i]);
     
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    ans=max(ans,dp[i]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11136
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int, K: int, l: "List[int]"):
    l = sorted(l)
    print(sum(l[N-K:]))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    l = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, l)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){
    int A,B,C;
    cin>>A>>B>>C;
    if(A==B) cout<<C<<endl;
    if(C==B) cout<<A<<endl;
    if(A==C) cout<<B<<endl;
}



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

using namespace std;

const int MAXN = 200005;

vector<long long> st(MAXN<<2);

long long update(int l, int r, int v, int i, long long val)
{
    if (l > i || r < i)
        return st[v];
    if (l == r)
        return st[v] = max(val, st[v]);
    int m = l+r>>1;
    return st[v] = max(update(l, m, v<<1, i, val), update(m+1, r, v<<1|1, i, val));
}

long long query(int l, int r, int v, int li, int ri)
{
    if (l > ri || r < li)
        return 0;
    if (l >= li && r <= ri)
        return st[v];
    int m = l+r>>1;
    return max(query(l, m, v<<1, li, ri), query(m+1, r, v<<1|1, li, ri));
}

int main()
{
    int n;
    scanf("%i", &n);
    vector<int> h(n+1), a(n+1);
    for (int x = 1; x <= n; x++)
        scanf("%i", &h[x]);
    for (int x = 1; x <= n; x++)
        scanf("%i", &a[x]);
    for (int x = 1; x <= n; x++)
        update(1, n, 1, h[x], query(1, n, 1, 1, h[x]-1) + a[x]);
    printf("%lli\n", st[1]);
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	long long a,b,ans=0LL,mi=1000000000000000LL;
	int f=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>a>>b;
		if (a>b)
		{
			ans+=a;
			mi=min(mi,b);
			f=1;
		}
		else if (a<b)
		{
			ans+=a;
			f=1;
		}
		else
		{
			ans+=a;
		}
	}
	if (f)
	{
		cout<<ans-mi<<endl;
	}
	else
	{
		cout<<"0\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define INF -2000000001

int A[2000001],n;

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

void exchange(int *a,int *b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}

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

int heapExtractMax(){
  if(n<1)return 0;
  int max=A[1];
  A[1]=A[n];
  n--;
  maxHeapify(1);
  return max;
}

void heapIncreaseKey(int i,int key){
  if(key<A[i])return;

  A[i]=key;
  while(i>1&&A[parent(i)]<A[i]){
    exchange(&A[i],&A[parent(i)]);
    i=parent(i);
  }
}

void maxHeapInsert(int key){
  n++;
  A[n]=INF;
  heapIncreaseKey(n,key);
}

int main(){
  int a,i;
  char str[50];
  n=0;
  while(1){
    scanf("%s",str);
    if(str[2]=='d')break;
    if(str[0]=='i'){
      scanf("%d",&a);
      maxHeapInsert(a);
    }else if(str[0]=='e'){
      a=heapExtractMax();
      printf("%d\n",a);
    }
  }
  return 0;
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
    cin >> n >> k;
    vector<int> p(n, 0);
    vector<double> px(n, 0.0);
    vector<double> pxsum(n+1, 0.0);
    for(int i = 0; i < n; ++i) {
        cin >> p.at(i);
        px.at(i) = ((p.at(i)+1)*p.at(i)/2.0) / p.at(i);
    }

    pxsum.at(0) += px.at(0);
    for(int i = 1; i < n; ++i) {
        pxsum.at(i) += pxsum.at(i-1) + px.at(i);
    }

    double pmax = 0.0;
    for(int i = 0; i+k < n; ++i) {
        double check = pxsum.at(i+k) - pxsum.at(i);
        pmax = max(pmax, check);
    }

    if(k == n) {
        pmax = pxsum.at(n-1);
    }

    printf("%.14f\n", pmax);
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define cast static_cast
#define vi vector<int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int n;
	cin>>n;
	vi a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	v<v<ll>> dp(n,v<ll>(n+1));
	for(int i=n-1;i>=0;i--){
		for(int j=1;i+j-1<n;j++){
			if(j==1){
				dp[i][j]=a[i];
			}
			else{
				dp[i][j]=max(a[i+j-1]-dp[i][j-1],a[i]-dp[i+1][j-1]);
			}
		}
	}
	cout<<dp[0][n]<<"\n";
}

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

Measured memory_bytes: 73740
/**
*    author:  Dooloper
*    created: 06.06.2020 00:59:13
**/

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <functional>
#include <cassert>


using namespace std;
typedef unsigned long long ull;
typedef long long ll;

vector<pair<ll, int>> primeFactor(ll N){
    vector<pair<ll, int>> ret;
    ll target = N;

    for (ll i = 2; i * i < target; i++)
    {
        int facotrNum = 0;
        while (N % i == 0)
        {
            facotrNum++;
            N /= i;
        }
        if (facotrNum)
            ret.emplace_back(make_pair(i, facotrNum));
    }
    if (N > 1)
        ret.emplace_back(make_pair(N, 1));
    return ret;
}

int main() {
    cin.tie(0);
    ll N;
    cin >> N;
    vector<pair<ll, int>> factor = primeFactor(N);
    int ans = 0;
    for (pair<ll,int> P : factor)
    {
        for (int j = 1; j <= P.second; j++){
            ans++;
            P.second -= j;
        }
    }

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

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define maxn 100010
using namespace std;

int cnt[2][maxn], M[2], Q[2], m[2], q[2];
int n;
int main() {
	cin >> n;
	for (int i = 1, x, p; i <= n; i++) {
		scanf("%d", &x); p = i % 2;
		cnt[p][x]++;
		if (M[p] < cnt[p][x]) M[p] = cnt[p][x], Q[p] = x;
	}
	if (Q[0] != Q[1]) {
		printf("%d\n", n - M[0] - M[1]);
		return 0;
	}
	for (int i = 1; i <= 100000; i++) {
		if (m[0] < cnt[0][i] && i != Q[0]) m[0] = cnt[0][i], q[0] = i;
		if (m[1] < cnt[1][i] && i != Q[1]) m[1] = cnt[1][i], q[1] = i;
	}
	if (M[0] - m[0] > M[1] - m[1]) printf("%d\n", n - M[0] - m[1]);
	else printf("%d\n", n - m[0] - M[1]);
	return 0;
}

Measured memory_bytes: 1024
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  ll ans=0;
  for(int i=0;i<N;++i){
    cin >> a.at(i);
    ans+=(a.at(i)-1);
  }

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

  return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int dp[3001][3001];


int main(){
	int n, t;
	cin >> n >> t;
	vector<pair<int, int> > a(n+1);
	for (int i = 1; i <= n; i++){
		cin >> a[i].first >> a[i].second;
	}

	sort(a.begin(), a.end());
	for (int i = 0; i < 3001; i++){
		for (int j = 0; j < 3001; j++){
			dp[i][j] = -1;
		}
	}
	

	for (int i = 0; i < t; i++){
		dp[0][0] = 0;
	}
	
	for (int i = 1; i <= n; i++){
		for (int j = 0; j < t; j++){
			if (dp[i-1][j] != -1){
				dp[i][j] = max(dp[i-1][j], dp[i][j]);
				if (j + a[i].first >= t){
					dp[i][t] = max(dp[i-1][j] + a[i].second, dp[i][t]);
				}else{
					dp[i][j+a[i].first] = max(dp[i-1][j] + a[i].second, dp[i][j+a[i].first]);
				}
			}
		}
	}

	int ans = 0;
	for (int i = 0; i <= n; i++){
		for (int j = 0; j <= t; j++){
			ans = max(ans, dp[i][j]);
		}
	}

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


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string S;
int p,ch[1<<8];
ll bnf();

ll getNum(){
  ll res=0;
  while(isdigit(S[p])) res=res*10+S[p++]-'0';
  return res;
}

ll calc(int c){
  ll res;
  if(S[p]=='(') p++,res=bnf(),p++;
  else res=getNum();
  while(1){  
   
    if(S[p]==')'||p==S.size()||ch[S[p]]<=ch[c])return res;
  int nc=S[p];
  if(S[p]=='*')p++,res*=calc(nc);
  else if(S[p]=='+')p++,res+=calc(nc);
  else if(S[p]=='-')p++,res-=calc(nc);

}

  return res;
}

ll bnf(){
  ll res;
  if(S[p]=='(')p++,res=bnf(),p++;
  else  res=getNum();
  
  while(p<(int)S.size()){
    if(S[p]=='+')res+=calc(S[p++]);
    else if(S[p]=='-')res-=calc(S[p++]);
    else if(S[p]=='*')res*=calc(S[p++]);
    else break;
    
  }
  return res;
}

int main(){
  cin>>S; 

  ll res=bnf();
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      for(int k=0;k<3;k++) {
	ch['+']=i,ch['-']=j,ch['*']=k;
	p=0;
	res=max(res,bnf());
      }
  
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3192
#!/usr/bin/env python3
import sys

N = int(input())
A = list(map(int, input().split()))

if N <= 2:
    print(1)
    sys.exit(0)

count = 0
status = 0
for i in range(1,N):
    # print(A[i-1],A[i], status)
    if A[i-1] == A[i]:
        new_status = 0
        continue
    elif A[i-1] < A[i]:
        new_status = 1
    elif A[i-1] > A[i]:
        new_status = -1
    if status == 0:
        status = new_status
        continue
    if status == new_status:
        continue
    else:
        count += 1
        # print("c")
        status = 0

print(count+1)


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

string mul(string a,string b){
  if(a=="0"||b=="0")return "0";  
  int as=a.size(),bs=b.size();
  int len=as+bs;
  vector<int> A(as),B(bs),C(len);
  for(int i=0;i<as;i++)A[i]=a[as-1-i]-'0';   
  for(int i=0;i<bs;i++)B[i]=b[bs-1-i]-'0';

  for(int i=0;i<as;i++)
    for(int j=0;j<bs;j++)
      C[i+j]+=A[i]*B[j];

  for(int i=0;i+1<len;i++){
    C[i+1]+=C[i]/10;
    C[i]%=10;
  }
  
  string res="";
  for(int i=len-1;i>=0;i--){
    if(res.size()==0&&C[i]==0)continue;
    res.push_back('0'+C[i]);
  }
  return res;
}

int main(){
  string X;
  cin>>X;
  cout<<mul(X,mul(X,X))<<endl;
  return 0;
}

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

int main()
{
  int n,ans = 0;
  cin >> n;
  int a[n],b[n],c[n - 1];
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n - 1) cin >> c[i];
  
  rep(i,n){
    ans += b[a[i] - 1];
    if(i == 0) continue;
    if(a[i - 1] + 1 == a[i]){
      ans += c[a[i - 1] - 1];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++) cout << c[pos] << " ";
#define PI acos(-1l)
const int M = 1000000007;
const int N=3e6+5;
const long long INF = 1e18+5;

//#define rohit
#ifdef rohit
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__) , cerr << endl;
#endif

void solve() {
    string a , b;
    cin >> a >> b;
    b.pop_back();
    if(a == b ){
        cout <<"Yes\n";
    }
    else{
        cout << "No\n";
    }
}

signed main(){
    FAST;
    //TODO:  check test cases.
    int tc=1;
//    cin >> tc;
    for(int t = 1 ; t <= tc ; t++){
        solve();
    }
}

/*Extra Cares
 * 1)In graphs or dp problems sometimes long long creates MLE.
 * 2)Check whether int to long long typecasting is commented or not?
 * 3)Check overflows.
*/

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

ll cal(ll n,int type){
  ll cnt=0;
  while (n%type==0 && n/type>0) {
    cnt++;
    n/=type;
  }
  return cnt;
}


int main(){
  ll n;
  std::cin >> n;

  if(n%2==1){
    std::cout << "0" << '\n';
    return 0;
  }


  // int ans=0;
  // for (ll i = n; i >1 ; i-=2) {
  //   // if(cal(i,5))std::cout<< i<<":"<<cal(i,5)<<'\n';
  //   ans+=cal(i,5);
  // }

  ll ans2=0;
  ans2+=n/10;

  ll now=50;
  while (n/now>0) {
    ans2+=n/now;
    now*=5;
  }

  std::cout << ans2 << '\n';

  // std::cout << ans << '\n';



  return 0;
}


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

typedef long int ll;

ll cnt = 0;

void InsertionSort(int A[], const int n, const int g);
void ShellSort(int [], int);

int main()
{
  int i;
  int n;
  int A[N+1];
  
  scanf("%d",&n);

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

  ShellSort(A,n);

  printf("%ld\n",cnt);
  
  for(i = 0;i < n;i++){
    printf("%d\n",A[i]);
  }
}

void InsertionSort(int A[], const int n, const int g) // from 1 to g
{
  int i=0,j=0;
  int key;

  for(i = g;i < n;i++){
    key = A[i];
    j = i-g;
    
    while(j >= 0 && A[j] > key){
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = key;
  }
}

void ShellSort(int A[], int n)
{
  int i=0;
  int h = 0;
  int G[101];
  
  cnt = 0;
  
  while(h <= n){
    h = 3*h+1;
    G[i] = h;
    i++;
  }
  int m = i-1;

  printf("%d\n",m);
  for(i = 0;i < m;i++){
    if(i) printf(" ");
    printf("%d",G[m-1-i]);
  }
  printf("\n");
  
  for(i = 0;i < m;i++){
    InsertionSort(A,n,G[m-1-i]);
  }
}



Measured memory_bytes: 6504
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;

int main(){
    int n;
    cin >> n;
    while(n != 0){
        int now = 1;
        int ans = 0;
        for(int i=2; i<500; i++){
            if(((n-now)%i)==0) ans++;
            now+=i;
            if(n-now <= 0) break;
        }
        if(n==1) ans=0;
        cout << ans << endl;
        cin >> n;
    }


}



Measured memory_bytes: 3104
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
///////////////////////////


int main(){fastio
    ll w,h,n;cin>>w>>h>>n;
    ll x1=0,x2=w,y1=0,y2=h;
    rep(i,1,n){
        ll a,b,c;cin>>a>>b>>c;
        if(c==1){
            Max(x1,a);
        }else if(c==2){
            Min(x2,a);
        }else if(c==3){
            Max(y1,b);
        }else{
            Min(y2,b);
        }
    }
    cout<<max((x2-x1),0)*max((y2-y1),0)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
using namespace std;
const int MAX_V=8;
char s[MAX_V][MAX_V];
int iter(char mine,char rival,int x,int y,int vx,int vy,int n=0){
  x+=vx;y+=vy;
  if(x<0||x>=MAX_V||y<0||y>=MAX_V)return 0;
  if(s[x][y]==mine)return n;
  if(s[x][y]==rival)
    return iter(mine,rival,x,y,vx,vy,n+1);
  return 0;
}
bool iterturn(char mine,char rival,int x,int y,int vx,int vy){
  x+=vx;y+=vy;
  if(x<0||x>=MAX_V||y<0||y>=MAX_V)return false;
  if(s[x][y]==mine)return true;
  if(s[x][y]==rival){
    if(iterturn(mine,rival,x,y,vx,vy)){
      s[x][y]=mine;
      return true;
    }else return false;
  }
  return false;
}
int reversable(char mine,char rival,int x,int y){
  return iter(mine,rival,x,y,-1,-1)+
    iter(mine,rival,x,y,-1,0)+
    iter(mine,rival,x,y,-1,1)+
    iter(mine,rival,x,y,0,-1)+
    iter(mine,rival,x,y,0,1)+
    iter(mine,rival,x,y,1,-1)+
    iter(mine,rival,x,y,1,0)+
    iter(mine,rival,x,y,1,1);
}
void turn(char mine,char rival,int x,int y){
  s[x][y]=mine;
  iterturn(mine,rival,x,y,-1,-1);
  iterturn(mine,rival,x,y,-1,0);
  iterturn(mine,rival,x,y,-1,1);
  iterturn(mine,rival,x,y,0,-1);
  iterturn(mine,rival,x,y,0,1);
  iterturn(mine,rival,x,y,1,-1);
  iterturn(mine,rival,x,y,1,0);
  iterturn(mine,rival,x,y,1,1);
}
pair<int,int> o(){
  int m=1,tmpm;
  pair<int,int> pos=make_pair(-1,-1);
  RREP(i,MAX_V)RREP(j,MAX_V){
    if(s[i][j]=='x'||s[i][j]=='o')continue;
    tmpm=reversable('o','x',i,j);
    if(tmpm>=m){
      m=tmpm;
      pos=make_pair(i,j);
    }
  }
  return pos;
}
pair<int,int> x(){
  int m=1,tmpm;
  pair<int,int> pos=make_pair(-1,-1);
  REP(i,MAX_V)REP(j,MAX_V){
    if(s[i][j]=='x'||s[i][j]=='o')continue;
    tmpm=reversable('x','o',i,j);
    if(tmpm>=m){
      m=tmpm;
      pos=make_pair(i,j);
    }
  }
  return pos;
}
void print(){
  REP(i,MAX_V){
    REP(j,MAX_V)
      cout<<s[i][j];
    cout<<endl;
  }
}
int main(){ _;
  REP(i,MAX_V)REP(j,MAX_V)cin>>s[i][j];
  for(;;){
    auto a=o();
    if(a.first>=0)turn('o','x',a.first,a.second);
    auto b=x();
    if(b.first>=0)turn('x','o',b.first,b.second);
    if(a.first==-1&&b.first==-1)break;
  }
  print();
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);


int main () {

  int n;
  cin >> n;
  int num = (n + (1000-1))/1000;
  int ans = num * 1000 - n;


  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 3592
#include<stdio.h>

int main(){
	int n,s,v,i,u = 0;
	scanf("%d",&n);
	scanf("%d %d",&s,&v);
	
	for(i = s; i <=v; i++){
		if(i % n == 0){
			printf("OK");
			u += 1;
			break;
		}}
		
		if(u ==0){
			printf("NG");
		
	}
}

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int test, x = 0, y = 0; cin >> test;
	string sh; cin >> sh;
	int length = sh.size();
	if (length > test)
	{
		x = length - test;
		y = length - x;
		for (int i = 0; i < y; ++i)
		{
			cout << sh[i];
		}
		cout << "..." << endl;
	}
	else
	{
		for (int i = 0; i < length; ++i)
		{
			cout << sh[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;
using tdata=pair<datas,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i,j,N,M,K;
  cin>>N;
  cout<<N*N*N<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    s = input().strip()
    # print(len(s))
    if len(s)&1:
        for i in range(len(s)-1, 0, -2):
            if s[:i//2] == s[i//2:i]:
                print(i)
                break
    else:
        for i in range(len(s)-2, -1, -2):
            if s[:i//2] == s[i//2:i]:
                print(i)
                break


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main(){
  char s[1005];
  scanf("%s", s);
  int flag = 0;
  for(int i=0; i<strlen(s); i++){
    if(s[i] == 'N')  flag |= 1;
    if(s[i] == 'W')  flag |= 2;
    if(s[i] == 'S')  flag |= 4;
    if(s[i] == 'E')  flag |= 8;
  }
  if(flag == 15  ||  flag == 5  ||  flag == 10)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(std::string S){
    VI ans(S.size(), 0);
    REP(i, S.size()) {
        if(S[i] == 'L') continue;

        int cnt = 0;
        while(S[i] == 'R') {
            cnt++;
            i++;
        }

        ans[i-1] += (cnt % 2 == 0 ? cnt / 2 : cnt / 2 + 1);
        ans[i] += cnt / 2; 
    }

    RREP(i, S.size() - 1) {
        if(S[i] == 'R') continue;

        int cnt = 0;
        while(S[i] == 'L') {
            cnt++;
            i--;
        }

        ans[i+1] += (cnt % 2 == 0 ? cnt / 2 : cnt / 2 + 1);
        ans[i] += cnt / 2; 
    }

    REP(i, S.size()) {
        cout << ans[i] << (i+1 == S.size() ? "\n" : " ");
    }
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}



Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
int N, H = 1000000, T = 1000000;
long long L, tagx;
long double tagy;
struct point
{
	long long x;
	long double y;
	point() : x(), y()
	{
	}
	point(long long _x, long double _y) : x(_x - tagx), y(_y - tagy)
	{
	}
	inline long long gx()
	{
		return x + tagx;
	}
	inline long double gy()
	{
		return y + tagy;
	}
}
q[2000001];
void move(long long dx, long double dy)
{
	tagx += dx;
	tagy += dy;
	while (H < T && q[T - 1].gx() >= L)
		T--;
	if (q[T].gx() > L)
	{
		point newT(L, (q[T - 1].gy() * (q[T].gx() - L) + q[T].gy() * (L - q[T - 1].gx())) / (q[T].gx() - q[T - 1].gx()));
		q[T] = newT;
	}
}
void flush()
{
	if (q[H].gx() == 0)
		H++;
	while (H < T && q[H].gy() * q[H + 1].gx() < q[H + 1].gy() * q[H].gx())
		H++;
	q[--H] = { 0, 0 };
}
void ans()
{
	printf("%.7Lf\n", q[T].gy() / q[T].gx());
}
int main()
{
	scanf("%d%lld", &N, &L);
	for (int i = 1; i <= N; i++)
	{
		long double t;
		long long v;
		scanf("%Lf%lld", &t, &v);
		move(v, t * v);
		flush();
		ans();
	}
	return 0;
}


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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0; i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

int main(){
    ll l, r, d; cin >> l >> r >> d;
    ll cnt = 0;
    for (ll i = l; i <= r; i++){
        if (i % d == 0) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"
#define mod 1000000007

int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	string s;
	cin>>s;
	l=s.find('A');
	for(ll i=l;i<s.size();i++){
		
		if(s[i]=='Z')ans=i;
	}
	cout<<ans-l+1;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ss second
#define ff first
#define vi vector<int>
using namespace std;
int vis[1000][1000];
long long gn;
long long po(long long a,long long b){
    if(b==0)return 1;
    if(b==1)return a;
    if(b&1) return a*po(a*a,(b-1)/2);
    if(b&1^1)return po(a*a,b/2);
    return 1;
}
int vectoint(std::vector<int>v){
    reverse(v.begin(), v.end());
    long long p=0;
    for(int i=0;i<v.size();i++){
        p+=v[i]*po(2,i);
    }
return p;
}
int dp[100][100];
int print(int x,int y){
    if(x<=1){
            if(y>2 || y<=0)return 0;
            else return 1;
    }
  if(dp[x][y]!=0)return dp[x][y];
    else{

    return dp[x][y]=print(x-1,y)+print(x-1,y-1);
} }
void dele(stack<int>&s,int k){
    if(k==1){
        s.pop();
        return ;
    }
    int x=s.top();
    s.pop();
    dele(s,k-1);
    s.push(x);
    return;
}
void sort0(){

}
void finddup(){
    int arr[]={1,2,3,4,5,4};
    int tor=arr[0];
    int hare=arr[0];
    do{
        tor=arr[tor];
        hare=arr[arr[hare]];
    }
    while(hare!=tor);
    hare=arr[0];
    while(hare!=tor){
        hare=arr[hare];
        tor=arr[tor];
    }
    cout<<hare<<endl;
    return;
}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
    int t;
    // stack<int>s;
    // s.push(1);
    // s.push(111);
    // s.push(112);
    // s.push(112312);
    // s.push(12312);
    //  s.push(122);


    // cout<<s.size()<<endl;
    // stack<int>p=s;
    // while(!p.empty()){cout<<p.top()<<" ";p.pop();}
    // cout<<endl;
    // dele(s,(s.size()%2==0)?s.size()/2:(s.size()/2)+1);
    // cout<<s.size()<<endl;
    // while(!s.empty()){cout<<s.top()<<" ";s.pop();}
    //finddup();
    //sort0();
    int n;
    cin>>n;
    if(n%1000==0)cout<<0<<endl;
    else{
        cout<<1000-(n%1000)<<endl;
    }
return 0;
}

Measured memory_bytes: 3652
n = int(input())
h = list(map(int, input().split()))

dp = [0]*n
dp[1] = abs(h[1]-h[0])

for i in range(2, n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])


Measured memory_bytes: 20508
n,m=map(int,input().split())
switch={}
for i in range(n):
  switch[i]=[]
for light in range(m):
  s=list(map(int,input().split()))
  for i in s[1:]:
    switch[i-1].append(light)
p=list(map(int,input().split()))

count=0
for i in range(2**n):
  judge=[0]*m
  for k in range(n):
    if i&(2**k):
      for x in switch[k]:
        judge[x]=1-judge[x]
  if judge==p:
    count+=1
print(count)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
#define PI 3.141592
using namespace std;

int main()
{
	int a, b, c;
	int ab, bc, ca;
	cin >> a >> b >> c;
	ab = a + b;
	bc = b + c;
	ca = c + a;

	printf("%d", min(ab, min(bc, ca)));
	return 0;
}

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

int main() {
    int h, r;
    cin >> h >> r;
    if (h == (-1)*r) cout << 0 << endl;
    else if (h > (-1)*r) cout << 1 << endl;
    else cout << -1 << endl;

    return 0;
}


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

using namespace std;

int mp[101][101];
int sx, sy, gx, gy;
int w, h;

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

bool dfs(int y, int x, int c)
{
	if (y < 1 || y > h || x < 1 || x > w || mp[y][x] != c) return false;

	if (y == gy && x == gx) return true;

	mp[y][x] = 0;

	bool res = false;

	for (int i = 0; i < 4; ++i) res = res || dfs(y + dy[i], x + dx[i], c);

	return res;
}

int main()
{
	while (cin >> w >> h, w || h) {
		cin >> sx >> sy >> gx >> gy;
		int n; cin >> n;
		while (n--) {
			int c, d, x, y; cin >> c >> d >> x >> y;

			if (d) {
				for (int i = 0; i < 4; ++i) for (int j = 0; j < 2; ++j) mp[y+i][x+j] = c;
			} else {
				for (int i = 0; i < 2; ++i) for (int j = 0; j < 4; ++j) mp[y+i][x+j] = c;
			}
		}

		cout << (dfs(sy, sx, mp[sy][sx]) ? "OK" : "NG") << endl;
	}
}

Measured memory_bytes: 1176
from itertools import accumulate

n = int(input())
a = [int(i) for i in input().split()]


def n_op(a, p):
    s = accumulate(a)
    x = 0
    n = 0

    for si in s:
        if p and si + x <= 0:
            n += 1 - (si + x)
            x += 1 - (si + x)
        if (not p) and si + x >= 0:
            n += 1 + (si + x)
            x -= 1 + (si + x)
        p = not p

    return n


answer = min([n_op(a, True), n_op(a, False)])
print(answer)


Measured memory_bytes: 14212
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int A[100010]{};
    A[1] = MOD;
    for(int i=2;i<=100000;i++){
        if(A[i] != 0) continue;
        for(int j=i*2;j<=100000;j+=i){
            A[j] = MOD;
        }
    }
    int sum[100010]{};
    for(int i=1;i<=100000;i++){
        sum[i] = sum[i-1];
        if(i % 2 == 1){
            int n = (i+1)/2;
            if(A[i] == 0 && A[n] == 0) sum[i]++;
        }
    }

    int Q;
    cin >> Q;
    rep(i,Q){
        int l,r;
        cin >> l >> r;
        cout << sum[r] - sum[l-1] << endl;
    }
}

Measured memory_bytes: 2176
//<MIHIR KHAMBHATI/>
 
#include<bits/stdc++.h>
using namespace std;
 
#define mod 1000000007
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define deb(x) cout<<"\n"<<#x<<"="<<x<<"\n";
#define deb2(x,y) cout<<"\n"<<#x<<"="<<x<<"\n"<<#y<<"="<<y<<"\n";
#define ideb int _p_;cin>>_p_;
typedef long long int ll;
typedef unsigned long long int ull;

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

vector<pair<ll,ll>> v;

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

	v.push_back({a,i+1});
}
sort(v.begin(),v.end());

for(pair<ll,ll> x:v)
{
	cout<<x.second<<" ";
}
}

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

// n 为序列长度，cnt 为操作数量
int n, cnt;
char str[200005];

int main()
{
    scanf("%d\n%s", &n, str);
    // 这里第一个指针指向最左边的左边，第二个指针指向最右边的右边，会好写一些
    int i = -1, j = n;
    while (i < j)
    {
        while ( ++ i < j && str[i] != 'W'); // 当 i ++ 后在 j 左边，且没找到 'W'，则继续循环
        while ( -- j > i && str[j] != 'R'); // 当 j -- 后在 i 右边，且没找到 'R'，则继续循环
        if (i < j) cnt ++ ;                 // 如果都找到后 i < j，则 交换次数 ++ ，
        // 这行空出来是用来补充上一行注释的 // 这里并不需要真正地维护操作，只需要记录操作数量即可。
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 3380
/*
 * Code from
 * Ali Ashadullah Arif
 * IT-18031_*_2017-18
 * Dept.Of.ICT,MBSTU
 * Date: Today
 * Platform :::: Atcoder::: Registration
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define TEST int t;cin>>t;for(int i=1;i<=t;i++)
int main()
{
    string s,t,tt="";
    int f=1;
    cin>>s>>t;
    for(int i=0; i<t.size()-1; i++) {
        tt+=s[i];
        if(s[i]!=t[i]) {
            f=0;
            break;
        }
    }
    if(f==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
   // main();
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#define MAX 100
#define INF (1<<21)
#define W 0
#define G 1
#define B 2

int n,M[MAX][MAX];

void dijkstra(){
  int i,j,u,min,sum=0;
  int d[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i]=INF;
    color[i]=W;
  }
  d[0]=0;
  color[0]=G;
  while(1){
    min=INF;
    u=-1;
    for(i=0;i<n;i++){
      if(min>d[i]&&color[i]!=B){
	u=i;
	min=d[i];
      }
    }
    if(u==-1)break;
    color[u]=B;
    for(j=0;j<n;j++){
      if(color[j]!=B&&M[u][j]!=INF){
	if(d[j]>d[u]+M[u][j]){
	  d[j]=d[u]+M[u][j];
	  color[j]=G;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,(d[i]==INF?-1:d[i]));
  }
}

int main(){
  int i,j,e,k,l,m;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INF;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&e,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&l,&m);
      M[e][l]=m;
    }
  }
  dijkstra();

  return 0;
}

Measured memory_bytes: 636
n, m = map(int, input().split())

a = [0] * n 
for i in range(n):
    a[i] = list(map(int, input().split()))

b = [0] * m
for i in range(m):
    b[i] = int(input())

c = [0] * n    
for i in range(n):
    for aj, bj in zip(a[i], b):
        c[i] += aj * bj
    
for ci in c:
    print(ci)

Measured memory_bytes: 7036
#include "bits/stdc++.h"

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  bool flag = false;
  int num = 0;

  int a, b, c; cin >> a >> b >> c;
  if (a + b >= c) flag = true;

  // cout << num << endl;
  cout << (flag ? "Yes" : "No") << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// 初期処理
		Scanner sc = null;

		// テキスト入力クラス
		sc = new Scanner(System.in);

		// 入力値をfloatで取る
		Double first = sc.nextDouble();
		Double second = sc.nextDouble();
		DecimalFormat df2 = new DecimalFormat("##########.##########");

		// 求める値
		Double quotient = first / second;
		Double product = first % second;

		// 元データをBigDecimal型にする
		BigDecimal quo = new BigDecimal(quotient);
		BigDecimal pro = new BigDecimal(product);

		quotient = (Double) first / second;

		// 出力
		System.out.println(quo.setScale(0, BigDecimal.ROUND_DOWN) + " "
				+ pro.setScale(0, BigDecimal.ROUND_DOWN) + " "
				+ df2.format(quo.setScale(8, BigDecimal.ROUND_DOWN)));

	}
}

Measured memory_bytes: 19224
import qualified Data.ByteString.Char8 as B
import           Data.List
import qualified Data.Map.Strict       as M

main :: IO ()
main = getParams >>= print . solve

getParams :: IO [B.ByteString]
getParams = tail . B.lines <$> B.getContents

solve :: [B.ByteString] -> Int
solve = accumulate . build

accumulate :: M.Map B.ByteString Int -> Int
accumulate = M.foldr f 0
  where f x acc = g x + acc
        g x     = x*(x-1) `div` 2

build :: [B.ByteString] -> M.Map B.ByteString Int
build = go M.empty . map B.sort
  where go m []     = m
        go m (s:ss) = go m' ss
          where m' = M.insertWith (+) s 1 m


Measured memory_bytes: 427388
using namespace std; 
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define vect vector<ll>
#define maap map<ll,ll>  
#define MOD 998244353
#define mit map::iterator
#define pii pair<ll,ll>
#define rep(i,a,b)	for(ll i=a;i< b;i++)
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
typedef  long long   int  ll;
//stringstream convert; 
  //  convert << number; 
  //  string s = convert.str();
 ll fact[500005],invfact[500005]; 
 ll power(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
 ll inv(ll x)
{
	return power(x,MOD-2);
}
ll divide(ll x, ll y)
{
	return (x*inv(y))%MOD;
}
ll C(ll n, ll k)
{
	if(k > n) return 0;
	return divide(fact[n], (fact[n - k]*fact[k])%MOD);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
bool isPrime(int n) {
 
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
} 
void init(){
	ll p=MOD;
	fact[0]=1;
	ll i;
	for(i=1;i<500005;i++){
		fact[i]=(i*fact[i-1])%p;
	}
	i--;
	invfact[i]=power(fact[i],p-2);
	for(i--;i>=0;i--){
		invfact[i]=(invfact[i+1]*(i+1))%p;
	}
}
ll s;
ll fun(ll a)
{
	if(a==0)
	return 0;
	return a+fun(a-1);
}
priority_queue < pair<ll,ll> , vector<pair<ll,ll> >,greater<pair<ll,ll> > > gq;

#define MAXN   10000001 
ll spf[MAXN]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXN; i++) 
        spf[i] = i; 
    for (ll i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
    for (ll i=3; i*i<MAXN; i++) 
    {
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
set<ll> getFactorization(ll x) 
{ 
    set<ll> ret; 
    while (x != 1) 
    { 
        ret.insert(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 
void ghost()
{   
  	ll i=0,j=0,k=0,l=0,n,r=-10000000000,t=0,q=0,x,y=100000000000;
    cin>>n;
    ll a[n];
    map<ll,ll>m;
    for(i=0;i<n;i++)
    {
    	cin>>a[i];
    	m[a[i]]++;
    	l=l+a[i];
	}
	cin>>q;
	while(q--)
	{
		cin>>j>>k;
		l=l+(m[j])*(k-j);
		m[k]=m[k]+m[j];
		m[j]=0;
		cout<<l<<endl;
	}
	
}
signed main()
{int test=1;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
fast
//cin>>test;
while(test--)
ghost();
return 0;
}

  

Measured memory_bytes: 10296