akhauriyash/Code-Regression huggingface dataset:
n=input()
S=list(map(int,input().split()))
count=0
for i in range(1,len(S)-1):
    if (S[i-1]<=S[i] and S[i+1]>=S[i]):
      count+=1
      continue
    if (S[i-1]>=S[i] and S[i+1]<=S[i]):
      count+=1
print(count)

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

using ll = long long;
using pii = pair<int,int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(),(c).end()

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

#define INF 1e18

int main(){
    int N,K; cin>>N>>K;
    V<int> P(N),C(N);
    rep(i,N)cin>>P.at(i),--P.at(i);
    rep(i,N)cin>>C.at(i);

    ll res = -INF;

    rep(i,N){
        int v = i;
        ll cycle_sum = 0;
        int cycle_cnt = 0;

        while(1){
            cycle_cnt++;
            cycle_sum += C.at(v);
            v = P.at(v);
            if(v==i)break;
        }

        ll path = 0;
        int cnt = 0;

        while(1){
            cnt++;
            path += C[v];

            if(cnt>K)break;

            int num = (K-cnt) / cycle_cnt;
            ll score = path + max(0ll, cycle_sum) * num;
            chmax(res,score);

            v = P.at(v);
            if(v==i)break;
        }
    }

    cout<<res<<endl;
}

Measured memory_bytes: 3680
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
#define int(x) int x; scanf("%d",&x)
#define input(x) scanf("%d",&x)
#define rep(x,n) for(int x = 0; x < n; x++)
#define _br printf("\n")
#define INF 2000000000

int A[1000],SortA[1000],Type[1000],NoT[1000] = {},NNot = 0;

//sum,min
int Typesum_min[1000][2] = {};
bool Complete[1000] = {};
int MIN;

void typing(int type, int iro){
    while (!Complete[type]) {
        Type[type] = iro;
        Typesum_min[iro][0] += A[type];
        if (Typesum_min[iro][1] > A[type]) {
            Typesum_min[iro][1] = A[type];
        }
        NoT[iro]++;
        Complete[type] = true;
        
        type = SortA[type];
    }
}

void DecideType(int n){
    int T = 0;
    rep(i,n){
        if (!Complete[i]) {
            typing(i,T);
            Typesum_min[T][0] -= Typesum_min[T][1];//????¨???????????°??????????????????????
            NNot++;
            T++;
        }
    }
}

void solve(){
    int SSum = 0;
    rep(i,NNot){
        if(NoT[i] != 1){
            if(MIN*(NoT[i]-1)+2*(Typesum_min[i][1] + MIN) >= Typesum_min[i][1]*(NoT[i]-1)) {
                SSum += Typesum_min[i][0] + Typesum_min[i][1]*(NoT[i]-1);
            }else{
                SSum += Typesum_min[i][0] + MIN*(NoT[i]-1)+2*(Typesum_min[i][1] + MIN);
            }
        }
    }
    printf("%d\n",SSum);
}

int main(){
    priority_queue<pair<int,int> > PQ;
    int(n);
    rep(i,n){
        input(A[i]);
        PQ.push(make_pair(-A[i],i));
        Typesum_min[i][1] = INF;
    }
    
    rep(i,n){
        SortA[i] = PQ.top().second;
        PQ.pop();
    }
    MIN = A[SortA[0]];
    DecideType(n);
    
    solve();
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S, T; cin >> S >> T;

    for(int i=0; i<S.size(); i++){
        if(S.at(i) != T.at(i)){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxk = 21;
const ll inf = 1e15;
#define FI() (puts("-1"), exit(0))
ll a, b, c, n;
#define int ll
void ob(ll v) {
	for (int i = 40;i >= 0;--i)
		cerr << (!!(v&(1ll<<i)));
	cerr << '\n';
}
vector<ll> getok() {
	static ll an = (1ll<<maxk)-1;
	vector<ll> res;
	//set<ll> did;
	for (int i = 0;i < 1<<maxk && i < a;++i) {
		ll na = a-i, nb = b+i, tar = c;
		na &= an, nb &= an, tar &= an;
		if ((na ^ nb) == tar)// && !did.count(((a-i) ^ (b+i))>>maxk))
			res.pb(i);//, did.insert(((a-i) ^ (b+i)) >> maxk);
	}
	return res;
}
ll cost(ll a, ll b, ll c) {
	assert(a >= 0 && b >= 0 && c >= 0);
	for (ll i = 0;i < 1<<maxk;++i) {
		//if (a < i) break;
		if (((a-i) ^ (b+i)) == c)
			return i << maxk;
	}
	return inf;
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> a >> b;
	for (int i = 2;i < n;++i) {
		ll t;
		cin >> t;
		c ^= t;
	}
	auto R = getok();
	ll res = a+1;

	for (auto i : R) 
		res = min(res, i + cost((a-i)>>maxk, (b+i)>>maxk, c>>maxk));

	if (res >= a)
		res = -1;
	cout << (long long)res << '\n';
}


Measured memory_bytes: 3668
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

int A,B,K;

int main(){
    cin>>A>>B>>K;
    while(K){
        B+=A/2;
        A/=2;
        K-=1;
        if(!K)break;
        A+=B/2;
        B/=2;
        K-=1;
    }
    cout<<A<<" "<<B<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<list>

int main(){
  using namespace std;
  int i;
  char str[102];
  list<char> ls;
  do{
    fgets(str,102,stdin);
    if(str[0]=='.') break;
    ls.clear();
    for(i=0;str[i]!='.';i++){
      switch(str[i]){
      case '(':
	ls.push_front('(');
	break;
      case ')':
	if(ls.front()!='('){
	  printf("no\n");
	  goto end;
	}
	ls.pop_front();
	break;
      case '[':
	ls.push_front('[');
	break;
      case ']':
	if(ls.front()!='['){
	  printf("no\n");
	  goto end;
	}
	ls.pop_front();
	break;
      }
    }
    if(ls.empty()) printf("yes\n");
    else printf("no\n");
  end:;
  }while(1);
  return 0;
}
  
    

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;
int n,m,p,sr,sc;
char s[N],t[N];
bool walk1()
{
	int L=1,R=n;
	for(int i=p;i;i--)
	{
		if(t[i]=='U')R=min(n,R+1);else if(t[i]=='D')L=max(1,L-1);
		if(s[i]=='U')L++;else if(s[i]=='D')R--;
		if(L>R)return 1;
	}
	return (sr<L||sr>R);
}
bool walk2()
{
	int L=1,R=m;
	for(int i=p;i;i--)
	{
		if(t[i]=='L')R=min(m,R+1);else if(t[i]=='R')L=max(1,L-1);
		if(s[i]=='L')L++;else if(s[i]=='R')R--;
		if(L>R)return 1;
	}
	return (sc<L||sc>R);
}
int main()
{
	scanf("%d%d%d%d%d",&n,&m,&p,&sr,&sc);
	scanf("%s",s+1);
	scanf("%s",t+1);
	if(walk1()||walk2())puts("NO");
	else puts("YES");
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

bool U[30];

int main()
{
    string S;
    cin >> S;
    REP(i, S.length())
    {
        U[(int)(S[i] - 'a')] = true;
    }

    REP(i, 26)
    {
        if (U[i])
            continue;
        cout << (char)(i + 'a') << endl;
        return 0;
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (int i = 0; i < (n); ++i)

template<typename T>
T powint (const T& x, const T& y) {
  T ret = 1;
  for(int i=0; i<y; ++i) ret *= x;
  return ret;
}

long long factorial(long long X) {
  long long ans = 1;
  for(int i=1; i<X+1 ; ++i) ans *= i;
  return ans;
}

std::map<long long, long long> prime_factor(long long n) {
  std::map<long long, long long> ret;
  for(long long i = 2; i * i <= n; ++i) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1; // if n is prime number.
  return ret;
}

int main() {
  ll N;
  cin >> N;
  std::map<long long, long long> numprimes;
  for (int j = 2; j<=N; ++j) {
    ll n = j;
    for(long long i = 2; i * i <= n; ++i) {
      while(n % i == 0) {
        numprimes[i]++;
        n /= i;
      }
    }
    if(n != 1) numprimes[n]++; // if n is prime number.
  }
  ll ans = 1;
  for (const auto numprime : numprimes){
    ans *= numprime.second + 1;
    ans %= MODA;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    double d;
    cin >> d;
    printf("%.10f\n", d * 2 * acos(-1));

    return 0;
}

Measured memory_bytes: 3728
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
int MOD=1000000007;

int main(){
    long long N,M,ans=0;
    cin >> N >> M;
    if(M<N) swap(N,M);
    if(N==1 && M==1) cout << '1' << endl;
    else if(N==1) cout << M-2 << endl;
    else cout << (N-2)*(M-2) << endl;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void print() {
    cout << endl;
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
using ll = long long;
const int INF = 1001001001;

vector<int> dp(100010, INF);

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    dp[0] = 0;
    dp[1] = abs(H[1]-H[0]);
    rep(i, N) {
        int min_cost = INF;
        for(int k=1; k<=K; k++) {
            if(i-k<0) continue;
            dp[i] = min(dp[i-k]+abs(H[i-k]-H[i]), dp[i]);
        }
    }

    print(dp[N-1]);


    return 0;
}

Measured memory_bytes: 4048
int main(void){
  int n;
  scanf("%d",&n);
  int a[n];
  double sum=0;
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum+=1.0/a[i];
  }
  printf("%lf",1.0/sum);
  return 0;
}

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

int main(){
  int n, k;
  long long int h[200005];
  long long ans=0;
  cin >> n >> k;
  for(int i=0;i<n;i++)cin >> h[i];

  sort(h, h+n);
  for(int i=0;i<k;i++)h[n-1-i]=0;
  for(int i=0;i<n;i++)ans += h[i];
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1920
I=lambda:list(map(int,input().split()))
n,m=I()
b=[int(input()) for i in range(m)]
b=list(set(b))
f={}
for i in b:
    f[i]=1
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    if not f.get(i,0):
        dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
print(dp[n])
    

Measured memory_bytes: 19208
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D_fix_3
# CreatedDate:  2020-06-19 15:09:52 +0900
# LastModified: 2020-06-19 15:27:30 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    _ = int(input())
    a_s = list(map(int, input().split()))
    m = max(a_s)+1
    cnt = [0 for _ in range(m)]

    for a in a_s:
        if cnt[a] != 0:
            cnt[a] = 2
            continue
        for n in range(a, m, a):
            cnt[n] += 1

    print(sum(cnt[a] for a in a_s if cnt[a]==1))


if __name__ == "__main__":
    main()


Measured memory_bytes: 32224
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  int a, b;
  cin >> a >> b;
  cout << (a ^ b) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

int a[200010];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, k; cin >> n >> k;
	int ans = n - k + 1;
	int prev = n, len = 0;
	int inc = 0;
	set<int> vals;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] > prev) len++;
		else len = 1;
		prev = a[i];
		if (i >= k) vals.erase(a[i - k]);
		if (len >= k) { inc = 1; ans--; }
		else if (i >= k) {
			if (a[i - k] < *vals.begin() && a[i] > *vals.rbegin()) ans--;
		}
		vals.insert(a[i]);
	}
	ans += inc;
	cout << ans << endl;
	return 0;
}


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

int main()
{
	string s;
	long long k;
	cin >> s >> k;

	int i = 0;
	while (i <= s.length()) {
		if (s[i] == '1' && k == i + 2) {
			cout << s[i + 1] << endl;
			break;
		}
		else if (s[i] != '1') {
			cout << s[i] << endl;
			break;
		}
		else if (k == 1) {
			cout << s[0] << endl;
			break;
		}
		i++;
	}

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N;
    cin >> N;
    ll K;
    cin >> K;
    vector<vector<int>> next(60, vector<int>(N));

    rep(i, N) {
        cin >> next[0][i];
        next[0][i]--;
    }

    for (int d = 0; d + 1 < 60; d++) {
        for (int v = 0; v < N; v++) {
            next[d + 1][v] = next[d][next[d][v]];
        }
    }

    int v = 0;
    for (int d = 0; d < 60; d++) {
        if (K & (1LL << d))
            v = next[d][v];
    }

    cout << v + 1 << endl;
}

Measured memory_bytes: 50988
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
const double EPS=1e-9;
double ten[10][10];

double dist(int x,int y,int d)
{
	double sum=0.0;
	for(int i=0;i<d;i++)
	{
		sum+=(ten[x][i]-ten[y][i])*(ten[x][i]-ten[y][i]);
	}
	return sqrt(sum);
}
int main()
{
	int n,d;
	ll ans=0;
	cin>>n>>d;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<d;j++)
			cin>>ten[i][j];
	}

	for(int x=0;x<n;x++)
	{
		for(int y=x+1;y<n;y++)
		{
			double kyori=dist(x,y,d);
			if(abs(kyori-floor(kyori))<EPS)
				ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  n--; k--;
  cout << (n+k-1)/k << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define mxn 200000
     
    using namespace std;
     
    map <int, int> m;
    vector <int> v;
     
    int main() {
    	int N, H;
    	scanf("%d %d", &N, &H);
    	for (int i = 0; i < N; i++) {
    		int x, y;
    		scanf("%d %d", &x, &y);
    		m[x]++;
    		v.push_back(x);
    		v.push_back(y);
    	}
    	sort(v.begin(), v.end());
    	int ans = 0;
    	int cur = 0;
    	bool flag = true;
    	for (int i = v.size() - 1; i >= 0 && flag; i--) {
    		cur += v[i];
    		ans++;
    		if (cur >= H) 
    			break;
    		if (m.count(v[i]) > 0) {
    			int x = H - cur;
    			int xx = x / v[i];
    			if (xx * v[i] < x) {
    				xx++;
    			}
    			ans += xx;
    			flag = false;
    		}
    		if (flag == false)
    			break;
    	}
    	printf("%d\n", ans);
    	return 0;
    }

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

class Node {
 public:
  int id;
  int parent_id;
  int sibling_id;

  int left_child_id;
  int right_child_id;

  Node() {}
  Node(const int& id) : id(id), parent_id(-1) {}
  bool operator<(const Node& another) const { return id < another.id; };
};

void PrintPreorder(vector<Node>& nodes, const int& id) {
  if (id == -1) return;
  cout << " " << id;
  PrintPreorder(nodes, nodes[id].left_child_id);
  PrintPreorder(nodes, nodes[id].right_child_id);
}

void PrintInorder(vector<Node>& nodes, const int& id) {
  if (id == -1) return;
  PrintInorder(nodes, nodes[id].left_child_id);
  cout << " " << id;
  PrintInorder(nodes, nodes[id].right_child_id);
}

void PrintPostorder(vector<Node>& nodes, const int& id) {
  if (id == -1) return;
  PrintPostorder(nodes, nodes[id].left_child_id);
  PrintPostorder(nodes, nodes[id].right_child_id);
  cout << " " << id;
}

int main() {
  int n;
  cin >> n;
  vector<Node> nodes(n);
  FOR(i, 0, n) {
    int id;
    int left;
    int right;
    cin >> id >> left >> right;
    Node node(id);
    node.left_child_id = left;
    node.right_child_id = right;
    nodes[i] = node;
  }
  sort(nodes.begin(), nodes.end());
  // define family
  FOR(i, 0, n) {
    if (nodes[i].left_child_id != -1) {
      nodes[nodes[i].left_child_id].parent_id = i;
      nodes[nodes[i].left_child_id].sibling_id = nodes[i].right_child_id;
    }
    if (nodes[i].right_child_id != -1) {
      nodes[nodes[i].right_child_id].parent_id = i;
      nodes[nodes[i].right_child_id].sibling_id = nodes[i].left_child_id;
    }
  }
  int root_id;
  FOR(i, 0, n) {
    if (nodes[i].parent_id == -1) root_id = i;
  }
  cout << "Preorder" << endl;
  PrintPreorder(nodes, root_id);
  cout << "\nInorder" << endl;
  PrintInorder(nodes, root_id);
  cout << "\nPostorder" << endl;
  PrintPostorder(nodes, root_id);
  cout << endl;
  return 0;
}


Measured memory_bytes: 3132
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 
## input
 
# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
N,M=map(int, input().split())
LR = [list(map(int,input().split())) for i in range(M)]
 
Lmin = 1
Rmax = N

for i in range(M):
    if Lmin < LR[i][0]:
        Lmin = LR[i][0]
    if LR[i][1] < Rmax:
        Rmax = LR[i][1]
    if Rmax < Lmin:
        print(0)
        sys.exit()

print(Rmax-Lmin+1)

Measured memory_bytes: 85588
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define inf 10000000
using namespace std;

int main(){
    int N,i,j=0,maxv=0,ans=0;
    cin >> N;

    int p[N];
    for(i=0 ; i<N ; i++){
        cin >> p[i];
        maxv = max(maxv , p[i]);
    }

    for(i=0 ; i<N ; i++){
        if((p[i] == maxv)&&(j == 0)){
            ans += p[i]/2;
            j++;
        }else{
            ans += p[i];
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
n = int(input())
jobs = [list(map(int,input().split())) for i in range(n)]

time = 0
jobs.sort(key = lambda x:x[1])

result = 'Yes'

for job in jobs:
    time += job[0]
    if time > job[1]:
        result = 'No'
        break

print(result)

Measured memory_bytes: 88024
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
	if(b%a==0)return a;
  return gcd(b%a,a);
}
int main(){
  int n,i;
  int a[111111];
  cin>>n;
  for(i=0;i<n;i++)cin>>a[i];
  for(i=1;i<n;i++)a[0]=gcd(a[0],a[i]);
  cout<<a[0];
  }

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

using namespace std;

namespace XDYIMCMI0LY {

  const int N = 100000 + 5;

  int a[N];
  int n;

  int st[N];
  int ed[N];

  map<int, int> mp;

  int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
      mp[a[i]] = i & 1;
      // cerr << a[i] << " " << (i & 1) << endl;
    }
    sort(a + 1, a + 1 + n);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      ans += mp[a[i]] != (i & 1);
      // cerr << a[i] << " " << (i & 1) << endl;
    }
    cout << ans / 2 << endl;
  }
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  XDYIMCMI0LY::main();
  return 0;
}


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

int main(){
  vector<int> mount(10,0);
  
  for(int i = 0; i < 10; i++){
    cin >> mount.at(i);
  }
  sort(mount.begin(), mount.end());
  cout << mount.at(9) << endl << mount.at(8) << endl  << mount.at(7) << endl;
}


Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip> 
#include<math.h>
using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	double percent=0;
	int score;
	double last = 0.0;
	double count = 0.0;
	int s;
	for (score = 1; score <= N; score++) {
		count = 0.0;
		percent = 1.0 / N;
		s = score;
		while (s < K) {
			s = s * 2;
			count += 1.0;
		}
		percent = percent * pow(0.5, count);
	
		last += percent;
	}

	cout << std::setprecision(12) << last;

	return 0;
}

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

int main() {
  
  int N; string S; cin >> N >> S;
  
  int count = 0;
  
  for (int i = 0; i < N - 1; i++) {
    
    if (S.at(i) == S.at(i + 1)) count++;
    
  }
  
  cout << N - count << endl;
  
}

Measured memory_bytes: 512
G={chr(a+ord("a")):a for a in range(26)}
H={G[b]:b for b in G}

T=input()
S=[]
for s in T:
    S.append(G[s])
K=int(input())

I=0
N=len(S)
for i in range(N):
    if (i<N-1) and (26-S[i]<=K) and S[i]!=0:
        K-=26-S[i]
        S[i]=0
    elif i==N-1:
        S[i]=(S[i]+(K%26))%26

U=""
for s in S:
    U+=H[s]

print(U)


Measured memory_bytes: 4340
#include<iostream>
#include<cmath>
#include<map>
#include<deque>
#include<string>
#include<algorithm>
typedef long long ll;

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define fore(i,a) for(auto i:a)

using namespace std;
int x,y;
int main(){
  cin>>x>>y;
  puts(6-x-y);
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################
li = input().split()
#print(li)
x,y = map(int,input().split())	
s =input()
if s==li[0]:
    print(x-1,y)
else:
    print(x,y-1)
    
    






Measured memory_bytes: 38256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskGB solver = new TaskGB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskGB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();

            int[] a = new int[n];

            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            long ans = 0l;

            int rem = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] == 0) {
                    rem = 0;
                    continue;
                }
                ans += (a[i] + rem) / 2;
                rem = (a[i] + rem) % 2;
            }
            out.println(ans);
        }

    }
}


Measured memory_bytes: 23724
#include <bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    if (floor((double) i * 1.08) == n){
      cout << i << '\n';
      return 0;
    }
  cout << ":(" << '\n';
  return 0;
}


Measured memory_bytes: 256
N=int(input())
V=[]
C=[]
tmp=0
sumx=0
val=[0]
V = list(map(int, input().split()))
C = list(map(int, input().split())) 

for i in range(N):
    tmp=V[i]-C[i]
    if(tmp>0):
        sumx=sumx+tmp
        
val.append(sumx)
print(max(val))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
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 ll INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll 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 nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
        ans%=MOD;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans=ans*modinv(i,MOD)%MOD;
    }
    return ans;
}

int main(){
    ll x,y;
    cin >> x >> y;
    ll p=x+y;
    if (p%3){
        cout << 0 << endl;
        return 0;
    }
    p/=3;
    if (max(x,y)>2*(min(x,y))){
        cout << 0 << endl;
    }else{
        ll q=abs(min(x,y)-(p*2));
        cout << nCr(p,q) << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str.
   builtin functions :
   __builtin_popcount(n) : no. of set bits in n.
   __builtin_parity(n) : parity of no. of set bits
   __builtin_clz(n) : no. of leading zeros before 1
   __builtin_ctz(n) : no of zeros from last to first occurrence of 1
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll binlen(ll a)
{
	ll v = 0;
	for(ll i=0;i<61;++i)
	{
		v += (1ll<<i);
		if(a<=v) return i;
	}
}

ll ar[M];
vector<ll> adj[M];

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

	ll n,m,i,u,v,mx,j,c=0;

	cin >> n >> m;
	for(i=1;i<=n;++i)
		cin >> ar[i];
	for(i=1;i<=m;++i)
	{
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	for(i=1;i<=n;++i)
	{
		mx = 0;
		for(auto v:adj[i])
			mx = max(mx,ar[v]);
		if(mx < ar[i])
			c++;
	}
	cout << c << endl;
}

Measured memory_bytes: 32516
n, m = map(int, input().split())
height = list(map(int, input().split()))
roads = [[] for _ in range(n)]
checked = [1] * n

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    roads[a].append(b)
    roads[b].append(a)

ans = 0
for i in range(n):
    if checked[i] == 0:
        continue
    for road in roads[i]:
        if height[i] > height[road]:
            checked[road] = 0
        else:
            checked[i] = 0

print(sum(checked))

Measured memory_bytes: 30308
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
ARC103 D
"""

from collections import deque
n = int(input())
xyli = deque([tuple(map(int,input().split())) for i in range(n)])

m = 20
dli = [1 for i in range(20)]

zli = list(map(lambda t:(t[0]+t[1])%2,xyli))

flag=True
if len(set(zli))>1:
    print(-1)
    exit()


oe = zli[0]

ans = []
dli = []
flag =False
if oe == 0:
    xyli = list(map(lambda t:(t[0]+1,t[1]),xyli))
    flag = True

uvli = list(map(lambda t:(t[0]+t[1],t[0]-t[1]),xyli))

def mode(ubin,vbin):
    if ubin and vbin:
        return('R')
    elif (not ubin) and vbin:
        return('D')
    elif ubin and (not vbin):
        return('U')
    else:
        return('L')

if flag:
    print(32)
    print(" ".join(map(str,[1]+[2**(30-i) for i in range(31)])))
else:
    print(31)
    print(" ".join(map(str,[2**(30-i) for i in range(31)])))

for u,v in uvli:
    ubin = format(((2**31-1)+u)//2,'031b')
    vbin = format(((2**31-1)+v)//2,'031b')
    if flag:
        print('L',end='')
    for i in range(31):
        print(mode(int(ubin[i]),int(vbin[i])),end='')
    print()






Measured memory_bytes: 5036
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

K = int(input())
d = deque()
for i in range(1, 10):
    d.append(i)

def myappend(n):
    sn = str(n)
    nlast = n%10
    if nlast == 0:
        d.append(10*n + nlast)
        d.append(10*n + nlast + 1)
    elif nlast == 9:
        d.append(10*n + nlast - 1)
        d.append(10*n + nlast)
    else:
        d.append(10*n + nlast - 1)
        d.append(10*n + nlast)
        d.append(10*n + nlast + 1)

cnt = 0
while d:
    val = d.popleft()
    cnt += 1
    if cnt == K:
        print(val)
        exit()
    myappend(val)

Measured memory_bytes: 18804
def main():
  s = tuple(input())
  
  f = "" # 前回のステップの文字 "<" or ">" 
  ans = 0 # Answer
  count = 0 # Ai
  continuous = 0 # ">" が何回連続するか
  
  for m in s:
    if m=="<":
      if f==">" and count>0:
        # 清算
        ans-=count*continuous
        count=0
      count+=1
        
    else:
      if f=="<":
        # セット
        continuous=0
      count-=1
      continuous+=1

    if count>=0:
      ans+=count
    else:
      ans+=continuous
      count=0
    
    f=m

  print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 7584
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    while (cin >> a >> b, a != 0 || b != 0) {
        for (int i = 0; i < a; ++i)
        {
            for (int j = 0; j < b; ++j)
            {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        String str2 = sc.next();
        if(str.equals(str2.substring(0,str2.length()-1))){
            System.out.println("Yes");
        }
        else System.out.println("No");
    }
}

Measured memory_bytes: 35684
// You can win if you want
#include <bits/stdc++.h>
using namespace std;
# define ll long long
# define endl "\n"
# define pi 3.14159265359
# define str string
# define vll vector<ll>
# define pb push_back
# define mll map<ll,ll>
# define vp vector< pair<ll,ll> >
# define mp make_pair
# define ff first
# define ss second
# define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll x;
    cin>>x;
    if(x>=30){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3636
import string

# 1千兆 + 1
N = int(input())
n_digits = len(str(1000000000000001))
letters = string.ascii_lowercase

x = N - 1
ans = []
# while True:
#     mod = x % 26
#     ans = [ mod ] + ans
#     x = x // 26
#     if x <= 0:
#         if ans[0] == 0:
#             ans = [0] + ans
#         break

# print(ans)
# print("".join([ letters[v] for v in ans ]))

while True:
    mod = x % 26
    div = x // 26
    
    ans.append(mod)
    if div == 0:
        break
    x = div - 1

ans = ans[::-1]
# print(ans)
print("".join([ letters[v] for v in ans ]))

Measured memory_bytes: 9868
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<unordered_map>
#include<map>
#include<climits>
using namespace std;
using ll = long long;
int main() {
	int n, m, sum = 0,t;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		scanf("%d", &t);
		sum += t;
	}
	cout << (sum <= n ? n - sum : -1);
	return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
   string o,e; cin >> o >> e;
   string ans;

   if(o.size() == e.size()) {
       for (int i = 0; i < o.size(); ++i) {
           ans += o[i];
           ans += e[i];
       }
   }else{
       for (int i = 0; i < e.size(); ++i) {
           ans += o[i];
           ans += e[i];
       }
       ans += o[o.size() - 1];
    }
   print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define mp make_pair
#define p(x) cout<< x << " ";
#define pe(x) cout<< x << endl ;
#define int long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROR(i,a,b) for(int i=a;i>=b;i--)
const int N = 1e5 + 5;
#define M 1000000007
int32_t main()
{
    FAST
    string s;
    cin>>s;
    int a[26]={0},cnt=0;
    for(int i=0;i<4;i++)
    {
        a[s[i]-'A']++;
    }
    for(int i=0;i<26;i++)
    {
        if(a[i]==2)
        cnt++;
    }
    if(cnt==2)
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 256
x = gets.chomp.to_i

h = {}
(0..120).each do |i|
  h[i] = i ** 5
  h[-i] = - h[i]
end

def search(x, h)
  (-120..120).to_a.each do |a|
    (-120..120).to_a.each do |b|
      return [a, b] if h[a] - h[b] == x
    end
  end

  return nil
end

ab = search(x, h)
raise if ab.nil?
puts ab.map(&:to_s).join(' ')


Measured memory_bytes: 14988
S = input()
S = [S[0],None,S[1],None,S[2],None,S[3]]

for i in range(2**3):
  tmp = S
  for j in range(3):
    if ((i >> j) & 1):
      tmp[j*2+1] = "+"
    else:
      tmp[j*2+1] = "-"
  if eval("".join(tmp)) == 7:
    print("".join(tmp),end = "")
    print("=7")
    break

Measured memory_bytes: 3064
import java.util.*;
 
class Main{
 
    void solve(){
        Scanner sc = new Scanner(System.in);
 
        while(true){
            char t = sc.next().charAt(0);
            if(t=='#') break;
 
            char[][] rank = new char[4][13];
            char[][] suit = new char[4][13]; 
            boolean[][] used = new boolean[4][13];
            for(int i=0; i<4; i++){
                for(int j=0; j<13; j++){
                    String s = sc.next();
                    rank[i][j] = s.charAt(0);
                    suit[i][j] = s.charAt(1);
                }
            }
 
            int[] point = new int[2];
            int[] idx = new int[4];
            int turn = 0;
 
            char now = suit[0][0];
            for(int i=0; i<13; i++){
                Arrays.fill(idx, -1);
                for(int j=0; j<13; j++){
                    if(!used[turn][j]){
                        now = suit[turn][j];
                        used[turn][j] = true;
                        idx[turn] = j;
                        break;
                    }
                }
 
                char max = rank[turn][idx[turn]];
                char maxC = now;
                int maxidx = turn;
 
                for(int j=0; j<4; j++){
                    if(j==turn) continue;
                    int fidx = -1;
                    boolean boo = false;
                    for(int k=0; k<13; k++){
                        if(!used[j][k]){
                            if(fidx==-1) fidx = k;
                             
                            if(suit[j][k]==now){
                                boo = true;
                                used[j][k] = true;

                                if(maxC==now && max(rank[j][k], max)){
                                    max = rank[j][k];
                                    maxidx = j;
                                }
                                break;
                            }
                        }
                    }

                    if(!boo){
                        used[j][fidx] = true;
                        if(suit[j][fidx]==t){
                            if(maxC!=t || (maxC==t && max(rank[j][fidx], max))){
                                max = rank[j][fidx];
                                maxidx = j;
                                maxC = t;
                            }
                        }
                    }
                }
                point[maxidx%2]++;
                turn = maxidx;
            }
 
            int ew = point[1] - 6;
            int ns = point[0] - 6;
            if(ew>ns) System.out.println("EW "+ew);
            else System.out.println("NS "+ns);
        }
    }
 
    boolean max(char c1, char c2){
        char[] list = {'2','3','4','5','6','7','8','9','T','J','Q','K','A'};
        int idx1 = 0, idx2 = 0;
        for(int i=0; i<list.length; i++){
            if(c1==list[i]) idx1 = i;
            if(c2==list[i]) idx2 = i;
        }
 
        if(idx1>idx2) return true;
        return false;
    }
 
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 24828
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) cin >> a[i];
  int count = 0;
  for (int i=0; i<N; i++) {
    if ((i+1)%2 && a[i]%2) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 3628
import copy
H, W=map(int, input().split())
S=[['.' for _ in range(W+2)]]+[['.']+list(input())+['.'] for _ in range(H)]+[['.' for _ in range(W+2)]]
S0=copy.deepcopy(S)
for i in range(1, H+1):
    for j in range(1, W+1):
        ct=0
        if S[i][j]=='.':
            for a in range(-1,2):
                for b in range(-1,2):
                    if S[i+a][j+b]=='#':
                        ct+=1
            S0[i][j]=str(ct)

S1=[]
for i in range(H+2):
    S1.append(''.join(S0[i]))

for i in range(1,H+1):
    print(S1[i][1:W+1])


Measured memory_bytes: 3700
n, c, k = map(int,input().split())
take = [int(input()) for _ in range(n)]
take.sort()
ans = 1
p = take[0]
r = 1
for i in range(1, n):
    if r < c:
        if take[i] - p <= k:
            r += 1
        else:
            ans += 1
            r = 1
            p = take[i]
    else:
        ans += 1
        r = 1
        p = take[i]

print(ans)

Measured memory_bytes: 7384
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

const string YES = "Yes";
const string NO = "No";

bool solve(std::string S, std::string T) {
  if (S.size() + 1 != T.size()) {
    return false;
  }
  REP(i, S.size()) {
    if (S[i] != T[i]) {
      return false;
    }
  }
  if ('a' <= T[S.size()] && T[S.size()] <= 'z') {
    return true;
  }
  return false;
}

int main() {
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  cout << (solve(S, T) ? YES : NO) << endl;
  return 0;
}


Measured memory_bytes: 3128
#include <iostream>

#define ll long long

using namespace std;

const int N = 2e5 + 10;

ll a[N], c[N];

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);    
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) 
    {
        cin >> a[i];
        ++c[a[i]];
    }
    ll res = 0;
    for (int i = 1; i < N; ++i) res += (c[i] * (c[i] - 1)) >> 1;
    for (int i = 0; i < n; ++i) 
    {
        cout << res - c[a[i]] + 1 << ' ';
    }
    return 0;
}


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

int main(){
	
	ll n,a,b; cin>>n>>a>>b;
	
	ll need = n/(a+b);
	ll cc = n%(a+b);
	cout<<(need*a)+min(cc,a)<<"\n";
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int main(){
    int n;
    cin >> n;
    int a, b;
    ll sum_a = 0;
    vi c(n);
    rep(i, n){
        cin >> a >> b;
        c[i] = a+b;
        sum_a += a;
    }
    Sort(c);
    rep(i, n){
        if(i%2 == 1){
            sum_a -= c[n-i-1];
        }
    }
    cout << sum_a << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int C[510], S[510], F[510];
    rep(i,0,N-1){
        cin >> C[i] >> S[i] >> F[i];
    }
    rep(i,0,N){
        ll ans = 0;
        if(i == N-1){
            print("0");
            continue;
        }
        rep(j,i,N-1){
            if(j == i){
                ans += S[j] + C[j];
            }else{
                if(ans < S[j]){
                    ans += S[j] - ans;
                }else{
                    int tt = (ans - S[j]) % F[j];
                    if(tt != 0){
                        ans += F[j] - tt; 
                    }
                }
                ans += C[j];
            }
        }
        print(ans);
    }

}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

r,c,k = map(int,readline().split())
data = list(map(int,read().split()))
d = dict()
it = iter(data)
for ri,ci,vi in zip(it,it,it):
    d[(ri-1)*5000 + (ci-1)] = vi

dp_max = [0] * (c)

for i in range(r):
    dp = [0] * 4
    for j in range(c):
        dp[0] = max(dp[0],dp_max[j])
        if( i*5000+j  in d):
            ci = d[i*5000+j]
            for k in range(3,0,-1):
                dp[k] = max(dp[k], dp[k-1] + ci)

        dp_max[j] = max(dp)

print(dp_max[-1])

Measured memory_bytes: 142384
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

int numOfInitialQues;
int numOfFinalQues;
map <int, int> temp1;
map <int, int> temp2;
int flag = 0;

int main()
{
	// memset(temp1, 0, sizeof(temp1));
	// memset(temp2, 0, sizeof(temp2));

	scanf("%d", &numOfInitialQues);
	int listOfInitialQues[numOfInitialQues];

	for(int i = 0; i < numOfInitialQues; i++)
	{
		scanf("%d", &listOfInitialQues[i]);
	}
	
	scanf("%d", &numOfFinalQues);
	int listOfFinalQues[numOfFinalQues];

	for(int i = 0; i < numOfFinalQues; i++)
	{
		scanf("%d", &listOfFinalQues[i]);
	}

	for(int i = 0; i < numOfFinalQues; i++)
	{
		temp1[listOfFinalQues[i]]++;
	}

	for(int i = 0; i < numOfInitialQues; i++)
	{
		temp2[listOfInitialQues[i]]++;
	}
	for(int i = 0; i < numOfFinalQues; i++)
	{
		int temp = listOfFinalQues[i];
		if(temp1[temp] > temp2[temp])
		{
			printf("NO\n");
			flag = 1;
			break;
		}
	}
	if(flag == 0)
	{
		printf("YES\n");
	}

	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 20608
import sys
input = sys.stdin.buffer.readline

def main():

    N = int(input())
    a = list(map(int,input().split()))
    pl = {}
    ans = 0
    for i,num in enumerate(a):
        s = num+i
        t = num-i
        if -t in pl:
            ans += pl[-t]
        if s not in pl:
            pl[s] = 1
        else:
            pl[s] += 1

    print(ans)
    
if __name__ == "__main__":
    main()
    

Measured memory_bytes: 118492
<?php

fscanf(STDIN, '%d', $n);
$coprime = array();
for ($i = 1; $i < 26; $i++) {
    if (gcd($i, 26) === 1) {
        $coprime[] = $i;
    }
}
for ($i = 0; $i < $n; $i++) {
    $s = explode(' ', rtrim(fgets(STDIN)));
    $f = false;
    foreach ($coprime as $a) {
        for ($b = 0; $b < 26; $b++) {
            $tmp = $s;
            foreach ($s as $k => $w) {
                $s[$k] = dec($w, $a, $b);
                if ($s[$k] === 'that' || $s[$k] === 'this') {
                    $f = true;
                }
            }
            if ($f) {
                break 2;
            }
            $s = $tmp;
        }
    }

    echo implode(' ', $s) . PHP_EOL;
}

function gcd($a, $b) {
    if ($a === $b) {
        return $a;
    }
    return $a > $b ? gcd($a - $b, $b) : gcd($a, $b - $a);
}

function dec($w, $a, $b) {
    $w = str_split($w);
    for ($i = 0; $i < count($w); $i++) {
        $asc = ord($w[$i]) - ord('a');
        $w[$i] = chr(ord('a') + ($a * $asc + $b) % 26);
    }
    return implode('', $w);
}

Measured memory_bytes: 6712