akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
int a[MAXN];
int n;
int Query(int ans){
    char ret[20];
    printf("%d\n", ans);
	fflush(stdout);
    scanf("%s", ret);
    if(ret[0] == 'V') exit(0);
    return ret[0] == 'M' ? 1 : 0;
}
int main(){
    SF("%d",&n);
    memset(a,-1,sizeof a);
    a[0]=Query(0);
    int l=0,r=n-1;
    int las=0;
    while(l<=r){
        int mid=(l+r)>>1;
        if(a[mid]!=-1){
            l+=2;
            mid++;
        }
        a[mid]=Query(mid);
        if(a[mid]==a[l]){
            if((mid-l+1)%2==0)
                r=mid-1;
            else
                l=mid;
        }
        else{
            if((mid-l+1)%2!=0)
                r=mid;
            else{
                a[mid-1]=a[mid]^1;
                l=mid-1;
            }
        }
    }
}


Measured memory_bytes: 1108
R, C, K = map(int, input().split())

I = [[0 for _ in range(C+1)] for _ in range(R+1)]
for i in range(K): 
  r, c, v = map(int, input().split())
  I[r][c] = v 
  
DP1 = [0 for _ in range(C+1)] #c列目までとったとき、最新の行で1個以下とったという条件のもとの最大
DP2 = [0 for _ in range(C+1)] #c列目までとったとき、最新の行で2個以下とったという条件のもとの最大
DP3 = [0 for _ in range(C+1)] #c列目までとったとき、最新の行で3個以下とったという条件のもとの最大
#print(I)

for r in range(1,R+1):
  for c in range(1,C+1): 
    #更新の順番に注意
    #mid = max(DP1[c], DP2[c], DP3[c]) + I[r][c]
    mid = DP3[c] + I[r][c] 
    DP3[c] = max(DP3[c-1], mid, DP2[c-1] + I[r][c]) #3個
    DP2[c] = max(DP2[c-1], mid, DP1[c-1] + I[r][c]) #2個
    DP1[c] = max(DP1[c-1], mid) #1個
  #print(DP3)
    
print(DP3[C])
    
    
    

Measured memory_bytes: 149132
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <math.h>
#include <utility>

using namespace std;

int main(){

    int L, R, ans = 2019;
    cin >> L >> R;

    if (R-L >= 2018){
        ans = 0;
        cout << ans << endl;
        return 0;
    }

    for (int i = L; i <= R; i++){
        if (i % 2019 == 0){
            ans = 0;
            cout << ans << endl;
            return 0;
        }
    }

    int num;
    num = L / 2019 * 2019; // int R以下の最小の2019の倍数

    L = L - num;
    R = R - num;

    for (int i = L; i < R; i++){
        for (int j = i+1; j <= R; j++){
            int mod = (i * j) % 2019;
            ans = min(ans, mod);
        }
    }

    cout << ans << endl;

    return 0;
}


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

#define int long long

const double pi = acos(-1.0);
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;

int prime[N], prime_id[N], len;
bool isnp[N];
int n, a[N], b[N], cnt[N];

int powMod(int u, int v) {
    int res = 1;
    while (v) {
        if (v & 1) res = res * u % MOD;
        v >>= 1;
        u = u * u % MOD;
    }
    return res;
}

signed main() {
    ios::sync_with_stdio(false);
    for (int i = 2; i < N; i++) {
        if (isnp[i] == true) continue;
        prime[len++] = i;
        prime_id[i] = len - 1;
        for (int j = 2 * i; j < N; j += i) {
            isnp[j] = true;
        }
    }
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        a[i] = b[i];
        for (int j = 0; prime[j] * prime[j] <= b[i]; j++) {
            int total = 0;
            while (a[i] % prime[j] == 0) {
                a[i] /= prime[j];
                total += 1;
            }
            cnt[j] = max(cnt[j], total);
        }
        //cout << a[i] << " " << prime_id[a[i]] << endl;
        if (a[i] > 1) cnt[prime_id[a[i]]] = max(cnt[prime_id[a[i]]], 1ll);
    }
    int pre = 1;
    for (int i = 0; i < len; i++) {
        // if (cnt[i] > 0) {
        //     cout << prime[i] << " " << cnt[i] << endl;
        // }
        pre = pre * powMod(prime[i], cnt[i]) % MOD;
    }
    //cout << pre << endl;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = (ans + pre * powMod(b[i], MOD - 2)) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 17280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    int n;
    cin >> n;
    double ans = 0.0;
    for(int i = 0; i < n; i++){
        double x;
        string u;
        cin >> x >> u;
        if(u=="JPY"){
            ans += x;
        }else{
            ans += 380000*x;
        }
    }

    printf("%.10f\n",ans);
    return 0;
}


Measured memory_bytes: 256
/*
  Author - KISHAN TIWARI
  Dream bigger. Do bigger.
  Wake up with determination. Go to bed with satisfaction.
*/
//Sometimes later becomes never. Do it now.
#include<bits/stdc++.h>
using namespace std;
#define ll           long long
#define f(i,a,b)     for(ll i=a;i<b;i++)
#define mod          1000000007
#define fi           first
#define se           second
#define pa           pair <ll,ll>
#define mp           make_pair
#define pb           push_back
#define ve           vector<ll>
#define vep          vector< pa >
#define all(a)       a.begin(), a.end()
#define sz(x)        (ll)x.size()
#define c(t)         cout<<t<<"\n"
using namespace std;
void solve()
{ string s;
cin>>s;
ll x=0;
vep v,v1;
f(i,0,s.size()-1)
{
    if(s[i]=='R'&&s[i+1]=='L')
    {
        v.pb(mp(i,x+1));
    }
    else if(s[i]=='R')
    x++;
    else if(s[i]=='L')
    x=0;
}
ll y=0;
for(ll i=s.size()-1;i>=1;i--)
{
    if(s[i]=='L'&&s[i-1]=='R')
    {
        v1.pb(mp(i-1,y+1));
    }
    else if(s[i]=='L')
    y++;
    else if(s[i]=='R')
    y=0;
}
sort(v1.begin(),v1.end());
ll e=0,j=0;
while(j<s.size())
{
    if(v[e].fi==j)
    {   ll x1=v[e].se,y1=v1[e].se;
       if((x1+y1)%2==0)
        cout<<(x1+y1)/2<<" "<<(x1+y1)/2<<" ";
       else
       {
           ll ax=(x1+y1)/2;
           ll bx=ax+1;
           if(x1%2==0)
           {  cout<<ax<<" "<<bx<<" ";

           }
           else
           {
                cout<<bx<<" "<<ax<<" ";
           }

       }
        e++;
        j++;
    }
    else
     cout<<"0 ";
j++;
}
cout<<"\n";
}
int main()
{
    ios::sync_with_stdio(true);
   //freopen ("input.txt","r",stdin);
   //freopen ("output.txt","w",stdout);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {

        solve();
    }
return 0;
}


Measured memory_bytes: 2676
import sys
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N

def solve(n):
    if dp[n] < INF:
        return dp[n]

    if n == 0:
        dp[n] = 0
    elif n == 1:
        dp[n] = abs(h[0] - h[1])
    else:
        for i in range(1, K+1):
            if n - i < 0:
                break
            if dp[n - i] < INF:
                cost = dp[n - i] + abs(h[n - i] - h[n])
            else:
                cost = solve(n - i) + abs(h[n - i] - h[n])
            dp[n] = min(dp[n], cost)

    return dp[n]

print(solve(N-1))

Measured memory_bytes: 205876
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> dP;

const int INF = 100000000;
const double EPS = 1e-10;

int d[100001];
int dsum[100001];

struct team{
	int id;
	int univ;
	int solved;
	int pena;
	bool operator <(const team& other) const{
		if(solved == other.solved){
			if(pena == other.pena){
				return id > other.id;
			}else{
				return pena > other.pena;
			}
		}else{
			return solved < other.solved;
		}
	}
};

int main(){
	while(1){
		int n;
		cin >> n;
		if(!n)break;
		vector<team> v;
		rep(i, n){
			team t;
			cin >> t.id >> t.univ>> t.solved >> t.pena;
			v.push_back(t);
		}
		sort(all(v));
		reverse(all(v));

		int cnt = 0;
		map<int, int> univcnt;

		rep(i, n){
			if(cnt < 10){
				if(univcnt[v[i].univ] < 3){
					cout << v[i].id << endl;
					cnt++;
					univcnt[v[i].univ]++;
				}
			}
			else if(cnt < 20){
				if(univcnt[v[i].univ] < 2){
					cout << v[i].id << endl;
					cnt++;
					univcnt[v[i].univ]++;
				}
			}
			else if(cnt < 26){
				if(univcnt[v[i].univ] < 1){
					cout << v[i].id << endl;
					cnt++;
					univcnt[v[i].univ]++;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1228
#include<iostream>
#include<stack>
#include<string>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

/*int main()
{
    long long n;
    cin >> n;
    stack<char>st;
    if(n <= 26){
        char a = 'a' + n - 1;
        cout << a << endl;
        return 0;
    }else{
        rep(i,10000){
            long long a;
            a = n % 26;
            if(a == 0) st.push('z');
            else st.push('a' + a - 1);
            n /= 26;
            if(st.top() == 'z') n -= 1;
            if(n == 0) break;
        }
    }
    while(!st.empty()){
        cout << st.top();
        st.pop();
    }
    cout << endl;
    return 0;
}*/

int main()  
{
    long long n;
    cin >> n;
    stack<char>st;
    while(1){
        n -= 1;
        int a = n % 26;
        st.push('a' + a);
        n /= 26;
        if(n == 0) break;
    }
    while(!st.empty()){
        cout << st.top();
        st.pop();
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main () {
	int n,l;
	scanf("%d%d",&n,&l);
	int he = 0;
	for(int i=1; i<=n; i++) he += l + i-1;
	int ans = 1e9,mx = 1e9;
	for(int i=1; i<=n; i++) {
		int res = 0;
		for(int j=1; j<=n; j++) {
			if(i == j) continue;
			res += l + j-1;
		}
		if(ans > abs(he-res)) ans = abs(he-res),mx = res;
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	ll N; cin >> N;
	int ans = INF;
	rep(i, sqrt(N)+1){
		if (i == 0)continue;
		if (N % i == 0) {
			int x = to_string(N / i).size();
			ans = min(ans, x);
		}
	}
	cout << ans << "\n";
		
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,0,-1};
const static int ty[] = {-1,0,1,0};

const static double EPS = 1e-8;

int main(){
  int num_of_players;
  map<string,int> dict;
  dict["Rock"] = 0;
  dict["Fire"] = 1;
  dict["Scissors"] = 2;
  dict["Snake"] = 3;
  dict["Human"] = 4;
  dict["Tree"] = 5;
  dict["Wolf"] = 6;
  dict["Sponge"] = 7;
  dict["Paper"] = 8;
  dict["Air"] = 9;
  dict["Water"] = 10;
  dict["Dragon"] = 11;
  dict["Devil"] = 12;
  dict["Lightning"] = 13;
  dict["Gun"] = 14;

  map<int,bool> canWin;
  for(int hand_i = 0; hand_i < 15; hand_i++){
    for(int hand_j = 0; hand_j < 15; hand_j++){
      canWin[hand_i * 15 + hand_j] = false;
      for(int offset = 1; offset <= 7; offset++){
        if(hand_j == (hand_i + offset) % 15){
          canWin[hand_i * 15 + hand_j] = true;
        }
      }
    }
  }

  while(~scanf("%d",&num_of_players)){
    if(num_of_players == 0){
      break;
    }
    vector<string> players;
    for(int player_i = 0; player_i < num_of_players; player_i++){
      string hand;
      cin >> hand;
      players.push_back(hand);
    }

    bool lose[1001] = {};
    bool win[1001] = {};
    for(int player_i = 0; player_i < num_of_players; player_i++){
      for(int player_j = 0; player_j < num_of_players; player_j++){
        if(player_i == player_j) continue;
        if(canWin[dict[players[player_i]] * 15 + dict[players[player_j]]]){
          lose[player_j] = true;
          win[player_i] = true;
        }
      }
    }

    string res = "Draw";
    for(int player_i = 0; player_i < num_of_players; player_i++){
      if(!lose[player_i] && win[player_i]){
        res = players[player_i];
        break;
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1312
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
void solve(long long N, std::string S, std::string T){
  rep(i,N){
    cout<<S[i]<<T[i];
  }
  cout<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(N, S, T);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,b[9]={0},c=0,d;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        a=a/400;
        if(a>8)a=8;
        b[a]++;
    }
    
    for(int i=0;i<8;i++){
        if(b[i]>0)c++;
    }
    d=c+b[8];
    //if(d>8)d=8;
    if(c==0)c=1;
    cout<<c<<" "<<d<<endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
  
  var N, K int
  fmt.Scanf("%d %d\n", &N, &K)
  
  A := N % K
  if A == 0 {
    fmt.Println(0)
    return
  }
  if float64(A) < float64(K)/2 {
    fmt.Println(A)
    return
  }
  fmt.Println(K - A)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb2l(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define  mat vector<vector<ll>>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
long long int ncr(int n, int r){
  // space O(1) time O(min(r,n-r));
       if(n-r<r){
           r=n-r;
       }
        long long int res=1;
        for(int i=0;i<r;i++){
           res*=(n-i);
            res/=(i+1);
        }
        return res;
    }

void solve(){
  ll a,b,c;
  cin>>a>>b>>c;
  if(a==b && a!=c){
      cout<<"Yes";
  }
  else if(a==c && a!=b){
      cout<<"Yes";
  }
  else  if(b==c && b!=a){
      cout<<"Yes";
  }
  else cout<<"No"; 
  }
int main(){
    ll t=1;
   // cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
X, N = map(int, input().split())
p = input().split()
p = [int(s) for s in p]
low = X
up = X
while 1 > 0:
    if low not in p:
        answer = low
        break
    elif up not in p:
        answer = up
        break
    low -= 1
    up += 1

print(answer)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<ll>> x(n, vector<ll>(3));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> x[i][j];
    }
  }
  ll ans = 0;
  for (int i = 0; i < 8; ++i) {
    bitset<3> bs(i);
    vector<ll> v(n);
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (bs[k])
          v[j] += x[j][k];
        else
          v[j] -= x[j][k];
      }
    }
    sort(v.begin(), v.end(), greater<>());
    ll tmp = accumulate(v.begin(), v.begin() + m, 0LL);
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3556
h,w = map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in range(h)]
ret = []
for y in range(h):
    for x in range(w-1):
        if a[y][x]%2==1:
            ret.append((y,x,y,x+1))
            a[y][x+1]+=1
for y in range(h-1):
    if a[y][-1]%2==1:
        ret.append((y,w-1,y+1,w-1))
        a[y+1][-1]+=1
print len(ret)
for seq in ret:
    a,b,c,d = seq
    print a+1,b+1,c+1,d+1

Measured memory_bytes: 21252
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int n = sc.nextInt();

        int[] damage = new int[n];
        int[] mp = new int[n];

        for(int i = 0 ; i < n ; i++){
            damage[i] = sc.nextInt();
            mp[i] = sc.nextInt();
        }

        //HPが[]のときのMP消費最小値
        int[] dp = new int[h+1];
        dp[0] = 0;

        for(int i = 1 ; i <= h ; i++){
            dp[i] = (int)1e9;
            for(int j = 0 ; j < n ; j++){
                int remaining = Math.max(i-damage[j], 0);
                dp[i] = Math.min(dp[remaining] + mp[j], dp[i]);
            }
        }

        System.out.println(dp[h]);
    }
}


Measured memory_bytes: 27792
n = gets.to_i
arr = gets.split.map(&:to_i)
res = 1
i = 1
while i < n do
  j = i - 1
  while j >= 0 do
    unless arr[j] <= arr[i]
      res -= 1
      break
    end
    j -= 1
  end
  i += 1
  res += 1
end
puts res

Measured memory_bytes: 1788
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<cmath>
using namespace std;
#define ll long double
int main()
{
    int n;
    ll d;
    cin>>n>>d;
    ll x[n],y[n];
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
    }
    d = d*d;
    int count = 0;
    for(int i=0;i<n;i++){
        ll t = (x[i]*x[i]) + (y[i]*y[i]);
        if(t<=d){
            count = count+1;
        }
    }
    cout<<count<<endl;
    return 0;
}


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

struct Mod
{
    static const auto P = 3;
    int k;

    Mod() = default;
    Mod(const int k) : k(k%P >= 0 ? k%P : k%P + P) {}
};

Mod operator+(const Mod a, const Mod b) { return a.k + b.k; }
Mod operator-(const Mod a, const Mod b) { return a.k - b.k; }
bool operator==(const Mod a, const Mod b) { return a.k == b.k; }

int main()
{
    string S, T; cin >> S >> T;

    auto prefix_S = vector<Mod>(S.size() + 1);
    for (auto i = 1; i <= int(S.size()); i++)
        prefix_S[i] = prefix_S[i-1] + (S[i-1] == 'A' ? 1 : -1);

    auto prefix_T = vector<Mod>(T.size() + 1);
    for (auto i = 1; i <= int(T.size()); i++)
        prefix_T[i] = prefix_T[i-1] + (T[i-1] == 'A' ? 1 : -1);

    int Q; cin >> Q;
    for (auto q = 0; q < Q; q++)
    {
        int a, b, c, d; cin >> a >> b >> c >> d;
        cout << (prefix_S[b] - prefix_S[a-1] == prefix_T[d] - prefix_T[c-1] ? "YES" : "NO") << endl;
    }
}


Measured memory_bytes: 1664
n = int(input())
a = input().split(" ")
b = input().split(" ")
c = input().split(" ")
d = int(b[int(a[0])-1])

for i in range(n-1):
    if int(a[i]) + 1 == int(a[i + 1]):
        d += int(b[int(a[i+1])-1]) + int(c[int(a[i])-1])
    else:
        d += int(b[int(a[i+1])-1])
print(d)

Measured memory_bytes: 3064
import sys
s = sys.stdin.readline().rstrip()
N = len(s)

def next_abc(ac, start):
    for i in range(start, N):
        if ac and i < N-1 and s[i] == 'B' and s[i+1] == 'C':
            return ac, i+2
        elif s[i] == 'A':
            ac += 1
        else:
            ac = 0
    return 0, N

ans = ac = i = 0
while i < N:
    ac, i = next_abc(ac, i)
    ans += ac
print(ans)

Measured memory_bytes: 44124
#!/usr/bin/env python
# -*- coding: utf-8 -*-

L = [list(map(str, input().split())) for _ in range(2)]
s, t = list(L[0][0]), list(L[1][0])

s.sort()
t.sort(reverse=True)

if s < t:
    print('Yes')
else:
    print('No')


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

enum{
  t = 0,
  f ,
  r ,
  b ,
  l ,
  d,
};

array<int,6> dice = {1,3,5,4,2,6};

void Spin(array<int,6> &D,int dir){
  if(dir == l){//
    swap(D[t],D[r]);
    swap(D[r],D[d]);
    swap(D[d],D[l]);
  }
  else if(dir == r){
    swap(D[t],D[l]);
    swap(D[l],D[d]);
    swap(D[d],D[r]);
  }
  else if(dir == f){
    swap(D[t],D[b]);
    swap(D[b],D[d]);
    swap(D[d],D[f]);
  }
  else if(dir == b){
    swap(D[t],D[f]);
    swap(D[f],D[d]);
    swap(D[d],D[b]);
  }
  else if(dir == d){//leftspin
    swap(D[f],D[r]);
    swap(D[r],D[b]);
    swap(D[b],D[l]);
  }
  else if(dir == t){
    swap(D[f],D[l]);
    swap(D[l],D[b]);
    swap(D[b],D[r]);
  }
}

void MatchDice(array<int,6> &D,int T,int F){
  rep(i,4){
    Spin(D,r);
    if(D[t] == T)break;
  }
  if(D[t] != T){
    rep(i,4){
      Spin(D,f);
      if(D[t] == T)break;
    }
  }
  rep(i,4){
    Spin(D,t);
    if(D[f] == F) break;
  }
}

void ViewDice(array<int,6> D){
  rep(i,6){
    cout << D[i]<< " ";
  }
  cout << endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  array<int,6> di;
  cin >> di[t] >> di[f] >> di[r] >> di[l] >> di[b] >> di[d];
  ll n,a,b;
  cin >> n;
  rep(i,n){
    cin >> a >> b;
    MatchDice(di,a,b);
    cout << di[r]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3184
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val x = scn.nextInt()
	val y = scn.nextInt()
	val a = scn.nextInt()
	val b = scn.nextInt()
	val c = scn.nextInt()
	val ps = LongArray(a){scn.nextLong()}.sortedDescending()
	val qs = LongArray(b){scn.nextLong()}.sortedDescending()
	val rs = LongArray(c){scn.nextLong()}.sortedDescending()
	var ip = x-1
	var iq = y-1
	var sum = ps.subList(0,x).sum() + qs.subList(0,y).sum()
	for (ir in 0 until c.coerceAtMost(x+y)){
		val r = rs[ir]
		if (ip<0){
			val q = qs[iq]
			if (q>=r) break
			iq--
			sum += r-q
		}else if(iq<0){
			val p = ps[ip]
			if (p>=r) break
			ip--
			sum += r-p
		}else {
			val p = ps[ip]
			val q = qs[iq]
			if (p<=q && p<r){
				ip--
				sum += r-p
			}else if (q<p && q<r){
				iq--
				sum += r-q
			}else break
		}

	}
	println(sum)

}

Measured memory_bytes: 117896
#include <iostream>
using namespace std;
int main(void){
    int x,y;
    for(int i=1;i<=3000;i++){
        cin>>x>>y;
        if(x==0&&y==0){
            break;
        }
        else if(x>y){
            cout<<y<<" "<<x<<endl;
        }
        else if(x<y||x==y){
            cout<<x<<" "<<y<<endl;
        }
    }
    
}



Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  string S;
  cin >> S;
  vector<int> p;
  vector<int> pp;
  vector<int> ans((int)S.size());
  for(int i=0;i<(int)S.size()-1; i++){
    if((char)S[i] == 'R' && (char)S[i+1]=='L'){
      p.pb(i);
    }
  }
  for(int i=0;i<(int)S.size()-1; i++){
    if(i==0 || (char)S[i] == 'R' && (char)S[i-1]=='L'){
      pp.pb(i);
    }
  }
  vector<int> cnt;
  int tmp = 1;
  for(int i=0;i<(int)S.size()-1;i++){
    if((char)S[i]=='L' && (char)S[i+1]=='R'){
      cnt.pb(tmp);
      tmp=1;
    }
    else tmp++;
  }
  cnt.pb(tmp);
  //for(auto x:p) cout << x << endl;
  //cout << endl;
  //for(auto x:cnt) cout << x << endl;
  //cout << endl;

  for(int i=0;i<(int)p.size();i++){
    if((p[i] - pp[i])%2==1){
      ans[p[i]] = cnt[i]/2;
      ans[p[i]+1] = (cnt[i]+1)/2;
    }
    else{
      ans[p[i]] = (cnt[i]+1)/2;
      ans[p[i]+1] = cnt[i]/2;
    }
  }

  for(int i=0;i<(int)ans.size();i++){
    if(i==0)cout << ans[i];
    else cout << " " << ans[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1788
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    
    n = int(input())
    c = input()

    s = 0
    e = n-1
    cnt = 0
    while s < e:
        while c[s] != 'W' and s < e:
            s+= 1
        
        while c[e] != 'R' and s < e:
            e -= 1
        if c[e] != c[s]:
            cnt += 1
        s+= 1
        e -= 1
    print(cnt)

        

if __name__ == '__main__':
    main()

Measured memory_bytes: 9392
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n,k;
	cin>>n>>k;
	Array a(n,0);
	REP(i,n) cin>>a[i];
	Array dp(k+1,0);

	REP(i,k){
		for(auto x:a){
			if(!dp[i]){
				if(i+x<=k) dp[i+x]=1;
			}
		}
	}

	cout<<(dp[k]?"First":"Second")<<endl;

	return 0;
}




Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
	ll a, b, x;
	
	cin >> a >> b >> x;
	
	ll ans = 0;

	
	if (a - 1 >= 0){
		ans = (b / x) - ((a - 1) / x);
	} else {
	 	ans = b / x + 1;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char c;
    cin >> c;
    if(c == 'A')
    {
        cout << 'T' << endl;
    }
    else if(c == 'T')
    {
        cout << 'A' << endl;
    }
    else if (c == 'G')
    {
        cout << 'C' << endl;
    }
    else cout << 'G' << endl;
}


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

using namespace std;

int main() {
	int n, v[55];
	double ans;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &v[i]);
	sort(v, v + n);
	ans = v[0];
	for (int i = 1; i < n; i++)
		ans = (ans + (double) v[i]) / 2.0;
	printf("%.14lf\n", ans);
	return 0;
}

Measured memory_bytes: 128
import sys
n,k=map(int,input().split())
tmp=1
count=1
if n==1 and k==1:
    print('YES')
    sys.exit(0)
if k==0:
    print('YES')
    sys.exit(0)
for i in range(2,n+1):
    if i-tmp>1:
        tmp=i
        count+=1
    if count==k:
        print('YES')
        sys.exit(0)
print('NO')

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

int main() {
    int n;
    int a[10000];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    int ans = 0;
    for (int i = 0; i < n; i++) {
        while (a[i] % 2 == 0) {
            a[i] /= 2;
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3680
a = input()
b = True
for i in range(len(a)):
    if i % 2 == 0:
        if a[i] == 'R' or a[i] == 'U' or a[i] == 'D':
            continue
        else:
            b = False
            break
    else:
        if a[i] == 'L' or a[i] == 'U' or a[i] == 'D':
            continue
        else:
            b = False
            break
if b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.Aising2018
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] ab = ReadInts();
            int[] ps = ReadInts();
            int[] cnts = new int[3];
            for(int i = 0; i < n; i++)
            {
                if (ps[i] <= ab[0])
                {
                    cnts[0]++;
                }
                else if(ps[i]<=ab[1])
                {
                    cnts[1]++;
                }
                else
                {
                    cnts[2]++;
                }
            }
            int min = Math.Min(cnts[0], cnts[1]);
            min = Math.Min(min, cnts[2]);
            Console.WriteLine(min);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for (int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second

typedef long long ll;

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

void solve1()
{
    int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a[i];

    int sum = pow(3, n);
    int k = 1;
    for(int i = 0; i < n; i++) {
        if(a[i]%2) {
            k *= 1;
        } else {
            k *= 2;
        }
    }

    sum -= k;

    cout << sum << endl;
}

int main()
{
    solve1();
}


Measured memory_bytes: 4012
// rawatabhi14@gmail.com
// Abhinav Rawat
#include<bits/stdc++.h>
using namespace std;

string to_string(string s) {
    return '"' + s + '"';
}
string to_string(char ch) {
    string s(1, ch);
    return '\'' + s + '\'';
}
string to_string(const char *s) {
    return to_string((string)s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define f(i, x, n) for (int i = x; i < n; i++)
#define fr(i, n, x) for(int i=n; i>x; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long long int ll;
#define int ll
typedef pair<ll, ll> pll;
typedef vector< vector <ll> > matrix;
typedef vector<ll> vll;

const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 1e5 + 10;

int32_t main() {
    fast_io();
    vll a(5);
    f(i, 0, 5) cin >> a[i];
    f(i, 0, 5){
        if(a[i] == 0){
            cout << i+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3612
fun main(args: Array<String>) = abc160e()

fun abc160e() {
    val (x, y, a, b, c) = readLine()!!.split(' ').map { it.toInt() }
    val pList = readLine()!!.split(' ').map { it.toLong() }
    val qList = readLine()!!.split(' ').map { it.toLong() }
    val rList = readLine()!!.split(' ').map { it.toLong() }

    fun List<Long>.takeLarger(take: Int) = this.sortedDescending().take(take)

    val answer = (pList.takeLarger(x) + qList.takeLarger(y) + rList).takeLarger(x + y).sum()

    println(answer)
}


Measured memory_bytes: 110704
s = input()
i = 2
while True:
    #print(s[0:((len(s)-i)//2)])
    #print(s[((len(s)-i)//2):(len(s)-i)])
    if s[0:((len(s)-i)//2)] == s[((len(s)-i)//2):(len(s)-i)]:
        print(len(s[0:(len(s)-i)//2])*2)
        exit()
    else:
        i += 2

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

#define ll long long
#define INF INT_MAX/3
#define pi 2*acos(0.0)
#define eps 1e-14

const int MAX_N = (int)1e+6;
const int MAX_M = (int)1e+2;
int n, k;
int a[MAX_N];
int b[MAX_N];
void input()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[a[i]]++;
	}

}
void solve()
{
	int head = 1, tail = 100000;

	while (head <= tail) {
		while (b[head] <= 1 && head <= tail) head++;
		while (b[tail] <= 1 && head <= tail) tail--;
		if (head > tail) break;

		//3つ以上存在している場合は全て取り二枚減らす.
		b[head] = b[head] % 2;
		if (b[head] == 0) b[head] = 2;
		//1枚残った場合
		if (b[head] == 1) continue;

		//2枚残った場合，2枚とる
		b[head]--;
		b[tail]--;
	}
	int ans = 0;
	for (int i = 0; i <= 100000; i++) {
		if (b[i] == 1) ans++;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 1024
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
// #define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
using btree = tree<PII,null_type,greater<PII>,rb_tree_tag,tree_order_statistics_node_update>;

ll sc[100010];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, c;
  cin >> n >> c;
  btree tr;
  FOR(i, 1, n+1) tr.insert({0, -i});
  REP(i, c) {
    int type;
    cin >> type;
    if(type == 0) {
      ll t, p; cin >> t >> p;
      tr.erase({sc[t], -t});
      sc[t] += p;
      tr.insert({sc[t], -t});
    } else {
      ll m; cin >> m; m--;
      cout << -tr.find_by_order(m)->second << " " << tr.find_by_order(m)->first << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 10276
from itertools import combinations

N, K = map(int, input().split(' '))
A = tuple(map(int, input().split(' ')))

min_cost = 10 ** 12
for indexes in combinations(range(N), r=K):
    indexes = set(indexes)
    highest = 0
    cost = 0
    for i in range(N):
        height = A[i]
        if i in indexes and height <= highest:
            dh = highest - height + 1
            cost += dh
            height += dh
        highest = max(highest, height)
    min_cost = min(min_cost, cost)

print(min_cost)


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

using namespace std;

int a[100001];

int main () {
	int n;
	cin >> n;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i];
	}
	sort (a + 1, a + n + 1);
	int kol1 = 0, kol2 = 0;
	for (int i = 1;i <= n;i ++) {
		if (a[i] == a[1]) kol1 ++;
		if (a[i] == a[n]) kol2 ++;
	}
	if (a[n] - a[1] > 1) {
		cout << "No";
		return 0;
	}
	if (a[n] != a[1]) {   	
		if (a[n] > (kol2) / 2 + kol1) {
			cout << "No";
			return 0;
		}
		if (a[n] < kol1 + 1) {
			cout << "No";
			return 0;
		}
		if (a[1] < kol1) {
			cout << "No";
			return 0;
		}
	}
	else {
		if (a[1] == n - 1) {
			cout << "Yes";
			return 0;
		}
		if (a[1] > n / 2) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 640
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


n = int(input())
p = list(map(int, input().split()))

mi = 1000000000
cnt = 0
for i in range(n):
    if p[i] <= mi:
        cnt += 1
    if mi > p[i]:
        mi = p[i]

print(cnt)


Measured memory_bytes: 24744
#include<bits/stdc++.h>
using namespace std;
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vl>;
using vii = vector<vi>;
using pii = pair<int, int>;

using vc = vector<char>;
using vcc = vector<vc>;
using vb = vector<bool>;
using vbb = vector<vb>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using vd = vector<double>;
using vdd = vector<vd>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

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


const int MOD = 1e9 + 7;

vector<pii> prime_factorization(int n){ // 素因数分解をしたvector<素数, 指数>を返す
  vector<pii> res;
  int tmp, root_n = floor(sqrt(n));
  if(n % 2 == 0){
    tmp = 1;
    n /= 2;
    while(n % 2 == 0){
      n /= 2;
      tmp++;
    }
    res.push_back(make_pair(2, tmp));
  }
  ll i = 3;
  while(i <= root_n && i <= n){
    if(n % i == 0){
      tmp = 1;
      n /= i;
      while(n % i == 0){
        n /= i;
        tmp++;
      }
      res.push_back(make_pair(i, tmp));
    }
    i += 2;
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}
vector<pli> prime_factorization(ll n){ // 素因数分解をしたvector<素数, 指数>を返す
  vector<pli> res;
  int tmp, root_n = floor(sqrt(n));
  if(n % 2 == 0){
    tmp = 1;
    n /= 2;
    while(n % 2 == 0){
      n /= 2;
      tmp++;
    }
    res.push_back(make_pair(2, tmp));
  }
  ll i = 3;
  while(i <= root_n && i <= n){
    if(n % i == 0){
      tmp = 1;
      n /= i;
      while(n % i == 0){
        n /= i;
        tmp++;
      }
      res.push_back(make_pair(i, tmp));
    }
    i += 2;
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}

// n は 2以上の素数表を返す
vb Primes(int n){
  vector<bool> res(n + 1, true);
  res.at(0) = false; res.at(1) = false;
  for(int i = 2; i <= sqrt(n); i++){
    if(res.at(i)){
      for(int j = 2 * i; j <= n; j += i){
        res.at(j) = false;
      }
    }
  }
  return res;
}
// ===================================================

using vs = vector<string>;
using vss = vector<vs>;

bool A[10];

int main(){
  int a, b, c, d; cin >> a >> b >> c >> d;
  A[a] = true; A[b] = true; A[c] = true; A[d] = true;
  bool seki = A[1] && A[4] && A[7] && A[9];
  cout << (seki ? "YES" : "NO") << "\n";
  return 0;
}

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

typedef long long ll;

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


    int K, N;
    cin >> K >> N;

    vector<int> A(N);

    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int max = K - A[N - 1] + A[0];
    int count = max;

    for(int i = 1; i < N; i++) {
        count += A[i] - A[i - 1];
        if(A[i] - A[i - 1] > max) {
            max = A[i] - A[i - 1];
        }
    }

    cout << count - max << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

string str[50];
char c[3] = {'W','B','R'};
int a[51][51][3], b[51][51][3];
int main(){
	int h, w, t1, t2, t3, ans = INF;
	scanf("%d%d", &h, &w);
	rep(i,h)cin >> str[i];
	rrep(i,h)rrep(j,w)rep(k,3){
		a[i][j][k] += a[i][j-1][k];
		if(str[i-1][j-1] == c[k])a[i][j][k]++;
	}
	rrep(i,h)rrep(j,w)rep(k,3){
		b[i][j][k] = a[i][j][k]+b[i-1][j][k];
	}
	
	for(int i = 1;i <= h-2;i++){
		for(int j = 1;j <= h-i-1;j++){
			t1 = w*i-b[i][w][0];
			t2 = w*j-(b[i+j][w][1]-b[i][w][1]);
			t3 = w*(h-i-j)-(b[h][w][2]-b[i+j][w][2]);
			ans = min(ans, t1+t2+t3);
		}
	}
	
	printf("%d\n", ans);
	return 0;
}

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

template <typename T> bool chmax(T &a, const T b){if(a < b){a = b;return true;}return false;}
template <typename T> bool chmin(T &a, const T b){if(a > b){a = b;return true;}return false;}
#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll i,j,l,p;
    ll r,c,k;
    cin >> r >> c >> k;
    vector<vector<ll>> item(r,vector<ll>(c,0));
    vector<vector<vector<ll>>> dp(r,vector<vector<ll>>(c,vector<ll>(4,0)));
    for(i = 0;i < k;++i){
        ll rr,cc,vv;
        cin >> rr >> cc >> vv;
        --rr;   --cc;
        item.at(rr).at(cc) = vv;
    }
    dp.at(0).at(0).at(0) = 0;
    dp.at(0).at(0).at(1) = item.at(0).at(0);
    ll dx[2] = {-1, 0};
    ll dy[2] = {0, -1};
    for(i = 0;i < r;++i){
        rep(j,c){
            rep(l,2){
                ll ii = i + dx[l];
                ll jj = j + dy[l];
                if(ii < 0 || jj < 0) continue;
                if(l == 1){
                    for(p = 0;p < 4;++p){
                        chmax(dp.at(i).at(j).at(p), dp.at(ii).at(jj).at(p));
                        if(p) chmax(dp.at(i).at(j).at(p), dp.at(ii).at(jj).at(p-1) + item.at(i).at(j));
                    }
                }else{
                    for(p = 0;p < 4;++p){
                        chmax(dp.at(i).at(j).at(0), dp.at(ii).at(jj).at(p)); 
                        chmax(dp.at(i).at(j).at(1), dp.at(ii).at(jj).at(p) + item.at(i).at(j));
                    }
                }
            }
        }
    }
    ll ans = 0;
    rep(i,4){
        chmax(ans, dp.at(r-1).at(c-1).at(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 706684
import math

def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

a,b = map(int, input().split())
tmp = make_divisors(a)
divisors = []
for d in tmp:
  if b%d==0:
    divisors.append(d)

arr = []
for d in divisors:
  if d==1:
    arr.append(1)
  elif is_prime(d):
    arr.append(d)
print(len(arr))

Measured memory_bytes: 3316
from collections import deque
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]
visit = [[-1 for i in range(w)] for j in range(h)]
d = deque()

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            visit[i][j] = 0
            d.append((i,j))

p = [(1,0),(-1,0),(0,1),(0,-1)]
ans = 0
while d:
    x,y = d.popleft()
    for s,t in p:
        if 0 <= x+s <= h-1 and 0 <= y+t <= w-1:
            if visit[x+s][y+t] == -1:
                visit[x+s][y+t] = visit[x][y] + 1
                ans = max(ans,visit[x][y]+1)
                d.append((x+s,y+t))
        
print(ans)

Measured memory_bytes: 122716