akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,a[200000];
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll ans=0;
	ll cnt=1;
	for(ll i=0;i<n;i++){
		if(a[i]!=cnt){
			ans++;
		}
		else{
			cnt++;
		}
	}
	if(ans==n){
		cout <<-1;
		return 0;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool link(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int num() { // 異なる集合の数
    int res = 0;
    REP(i, data.size()) res += root(i) == i;
    return res;
  }
};

int nextInt() { int x; scanf("%d", &x); return x;}


int main2() {

  int N = nextInt();
  int M = nextInt();

  UnionFind uf(N);
  REP(i, M) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    int c = nextInt();
    uf.link(a, b);
  }
  cout << uf.num() << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

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

b = []
li = [0] * 21
r = 0
ans = 0

for i in a:
    ai = bin(i)
    b.append(ai[2:])

for l in range(n):
    while True:
        if r >= n:
            ans += r - l
            break
        tmp = b[r]
        flag = True
        for i in range(len(tmp)):
            if li[i] == 1 and tmp[-i-1] == '1':
                flag = False
            if not flag:
                break
        if flag:
            for i in range(len(tmp)):
                li[i] += int(tmp[-i-1])
            r += 1
        else:
            for i in range(len(b[l])):
                li[i] -= int(b[l][-i-1])
            ans += r - l
            break

print(ans)


Measured memory_bytes: 101092
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
long long int comb(long long int n,long long int r){
    vector<vector<long long int> > v(n+1,vector<long long int>(n+1,0));
    long long int i,j;
    rep(i,0,n+1){
        v.at(i).at(0)=1;
        v.at(i).at(i)=1;
    }
    rep(i,0,n+1){
        rep(j,0,i)v.at(i).at(j)=v.at(i-1).at(j-1)+v.at(i-1).at(j);
    }
    return v.at(n).at(r);
}
int main(void){
    string S;
    int i;
    cin>>S;
    rep(i,0,SZ(S))S.at(i)='x';
    cout<<S<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<numeric>

using namespace std;

long long n, a[1009], t[1009], num[1009];

void solve(){
    long long ans=0, mxa=0, mxt=0, k;
    for(int i=0;i<n;i++){
        k = max((ans-1)/num[i]+1, (mxa-1)/a[i]+1);
        k = max(k, (mxt-1)/t[i]+1);
        ans = k*num[i];
        mxa = k*a[i];
        mxt = k*t[i];
    }
    cout << ans << endl;
}

int main(){
    cin >> n;
    long long int tmpt, tmpa;
    for(int i=0;i<n;i++){
        cin >> t[i] >> a[i];
        num [i] = t[i]+a[i];
    }
    solve();
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    ll N; cin>>N;
    ll K; cin>>K;
    ll a[1000];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    ll sum[1001]={};
    for(int i=1;i<=N;i++){
        sum[i]=sum[i-1]+a[i-1];
    }
    ll M=N*(N+1)/2;
    ll b[500501];
    int ma=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<=N;j++){
            b[ma]=sum[j]-sum[i];
            //cout<<b[ma]<<endl;
            ma++;
        }
    }
    ll ans=0;
    ll x[41]; x[0]=1;
    for(int i=1;i<41;i++){
        x[i]=x[i-1]*2;
    }
    int top=41;
    while(ma>=K){
        int po[41]={};
        for(int j=0;j<M;j++){
            if(ans==0){
                for(ll i=0;i<top;i++){
                    if( x[i]&b[j] ){
                        po[i]++;
                    }
                }
            }else if( (b[j]&ans)==ans ){
                for(ll i=0;i<top;i++){
                    if(x[i]&b[j]){
                        po[i]++;
                    }
                }
            }
        }
        bool flag=false;
        for(ll i=top-1;i>=0;i--){
            if(po[i]>=K){
                top=i;
                ans+=x[i];
                ma=po[i];
                flag=true;
                break;
            }
        }
        //cout<<top<<' '<<ans<<endl;
        if(!flag) break;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 4224
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
ll ans=0;
int d[30],D[30];
int n;
void calc(){
    int i,f1,f2,f,ls;
    ll tmp=1;
    if(d[n]||n==1) return;
    for(i=1;i<=n/2;i++){
        f1=d[i-1]+D[i]-10*d[i];
        f2=d[n-i]+D[n-i+1]-10*d[n-i+1];
        if(f1+f2==0){
            ls=10-max(f1,f2);
            if(i==1&&f1<=0) ls--;
            if(ls<0) return;
            tmp*=ls;
        }
        else return;
    }
    if(n&1){
        i=n/2+1;
        f=d[i-1]+D[i]-10*d[i];
        if(f==0) tmp*=10;
        else return;
    }
    ans+=tmp;
}
void dfs(int x){
    if(x>n){calc();return;}
    d[x]=1;dfs(x+1);
    d[x]=0;dfs(x+1);
}
int main(){
    int x=0,i,mxlen,p;
    scanf("%d",&p);
    for(i=1;i<=9;i++) D[++x]=p%10,p/=10;
    for(i=x;i>=1;i--) if(D[i]) break;
    mxlen=i;
    for(n=mxlen;n<=20;n++)
        dfs(1);
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int l,n,d,a=0,i;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>d;
		if(i&1&&d&1)
		a++;
	}
	cout<<a;
	
	
	return 0;
}

Measured memory_bytes: 3592
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		long mod = (long)(1e9+7);
		long N = input.nextLong();
		long K = input.nextLong();
		long maxCap = N*(N+1)/2; //NO OVERFLOW!
		long cnt = 0;
		//long minCap = (K-1)*K/2;
		for (long i = K; i <= N; i++) {
			cnt+=maxCap;
			cnt-=(N-i)*(N-i+1)/2;
			cnt-=i*(i-1)/2;
			cnt%=mod;
			cnt++;
		}
		cnt++; //(only one sum when picking all numbers)
		System.out.println(cnt);
	}
}

Measured memory_bytes: 27212
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n;
double a[101];
int main() {
    cin>>n;
    REP(i, 0, n) cin>>a[i];

    double avr=0.0;
    REP(i, 0, n) avr+=a[i];
    avr/=n;

    double dif=1000000000.0;
    ll idx;
    RREP(i, 0, n){
        if(abs(avr-a[i])<=dif){
            dif=abs(avr-a[i]);
            idx=i;
        }
    }
    cout<<idx<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main() {

  int n;cin>>n;
  int sum=0;
  int t[n+10];
  rep(i,0,n){
    cin>>t[i];
    sum+=t[i];
  }
  int m;cin>>m;
  int p[m+10],x[m+10];rep(i,0,m)cin>>p[i]>>x[i];

  int ans;
  rep(i,0,m){
    ans=sum;
    ans+=(-t[p[i]-1]+x[i]);
    out(ans);
  }

  return 0;
}


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

int main(){
  int n;
  cin >>n;
  string tmp;
  map<string,ll>ans;
  for(ll i=0;i<n;i++){
    cin >>tmp;
    if(ans.count(tmp)){
      ans.at(tmp)++;
    }
    else{
      ans[tmp]=1;
    }
  }
  cout <<"AC x "<<ans["AC"]<<endl;
  cout <<"WA x "<<ans["WA"]<<endl;
  cout <<"TLE x "<<ans["TLE"]<<endl;
  cout <<"RE x "<<ans["RE"]<<endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//int a = Integer.parseInt(sc.next());
		//int b = Integer.parseInt(sc.next());
		//int c = Integer.parseInt(sc.next());
		//int n = Integer.parseInt(sc.next());
		//long res=n;
		//int l = Integer.parseInt(sc.next());
		//int sum=0;
		String s = sc.next();
		//String t = sc.next();
		//String b = sc.next();
		//int a = Integer.parseInt(sc.next());
		//String t = sc.next();

		if(s.equals("a") ||s.equals("e") ||s.equals("i") ||s.equals("o") || s.equals("u")) {//a、e、i、o、u
			System.out.println("vowel");
		}else {
			System.out.println("consonant");
		}
		//System.out.println("A"+t.substring(0,1)+"C");
	}
}




Measured memory_bytes: 23892
#include<stdio.h>

int isPrime(int x);

int main(void){
  int x;
  int n,i;
  int ans = 0;
  int count = 0;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&x);
    ans = isPrime(x);
    
    if(ans != 0){
      count++;
    }
    
  }
  printf("%d\n",count);

  return 0;
}




int isPrime(int x){
  int i;

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



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

int main(){
  string s;
  cin >> s;
  bool t = true;
  for(int i = 0; i < s.size();){
    string sb = s.substr(i, 5);
    if(sb == "dream"){
      if(s.substr(i+5, 2) == "er"){
        if(s[i+7] == 'a') i += 5;
        else i += 7;
      }else i += 5;
    }else if(sb == "erase"){
      if(s[i+5] == 'r') i += 6;
      else i += 5;
    } else{
      t = false;
      break;
    }
  }
  puts(t ? "YES" : "NO");
}


Measured memory_bytes: 512
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        Deque<Long> que = new ArrayDeque<>();
        for (long i=1; i<10; i++) {
            que.add(i);
        }
        int count = 0;
        long x;
        while (true) {
            x = que.poll();
            count++;
            if (count == K) {
                break;
            }
            if (x % 10 != 0) {
                que.add(10 * x + (x % 10) - 1);
            }
            que.add(10 * x + (x % 10));
            if (x % 10 != 9) {
                que.add(10 * x + (x % 10) + 1);
            }
        }
        System.out.println(x);
    }
}

Measured memory_bytes: 31060
#include<iostream>
using namespace std;
int main(){
  int a, b, c, buf;
  int n;
  bool x[1000];
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a >> b >> c;
    if(c > b){
      buf = c;
      c = b;
      b = buf;
    }
    if(b > a){
      buf = b;
      b = a;
      a = buf;
    }
    if(a*a==b*b+c*c)
      x[i] = 1;
    else
      x[i] = 0;
  }
  for(int i = 0; i < n; i++){
    if(x[i] == 0)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
  return 0;
}

Measured memory_bytes: 1120
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a[26] = { 0 };
	char str[] = { "abcdefghijklmnopqrstuvwxyz" };
	char str2[26];
	cin >> str2;
	int len = strlen(str2);
	for (int i = 0; i < len; i++) {
		for (int j = 0; j < 26; j++) {
			if (str2[i] == str[j]) {
				a[j]++;
				if (a[j] > 1) {
					cout << "no" << endl;
					return 0;
				}
			}
		}
	}
	cout << "yes "<< endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	VI A(N), B(N);
	REP(i, N)cin >> A[i];
	REP(i, N)cin >> B[i];

	vector<VI> dp((1 << N) + 1, VI(55, INF));
	dp[0][0] = 0;

	REP(bit, 1 << N) {
		int con = 0;
		REP(i, N)if (bit&(1 << i))con++;

		vector<pii>ords;
		int iter = con;
		REP(i, N) {
			if (!(bit&(1 << i)))ords.push_back(pii(i, iter++));
		}

		eREP(s, 50) {
			if (dp[bit][s] >= INF)continue;

			for (auto p : ords) {
				int ns = -1;
				if (abs(p.first - con) % 2 == 0)ns = A[p.first];
				else ns = B[p.first];

				if (ns >= s)
					chmin(dp[bit | (1 << p.first)][ns], dp[bit][s] + abs(p.second - con));
			}
		}





	}

	int ans = INF;
	eREP(s, 50)chmin(ans, dp[(1 << N) - 1][s]);
	if (ans >= INF)ans = -1;
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 121088
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll a[100];
ll cnt;
bool flag;

int main(){
	ll money = 1000;
	ll n;
	cin >> n;
	cinf(a,n);
	rep(i,n){
		if(flag){ //売却
			money+=cnt*a[i];
			flag=false;
			cnt=0;
		}
		if(i!=n-1&&a[i]<a[i+1]){ //購入
			cnt=money/a[i];
			money-=a[i]*cnt;
			flag=true;
		}
	}
	cout << money << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main(){
    int num,sum = 0;
    vector<int>v(5);
    vector<pair<int,int>>sabun(5);

    for(int i = 0;i < 5;i++){
        cin >> v[i];
        num = v[i]%10;
        if(num == 0)
            sabun[i] = make_pair(num,i);
        else 
            sabun[i] = make_pair(10-num,i);
    }

    sort(sabun.begin(),sabun.end());

    for(int i = 0;i < 5;i++){
        if(i == 4)
            sum += v[sabun[i].second];
        else 
            sum += v[sabun[i].second] + sabun[i].first;
    }

    cout << sum;

    return 0;
}

Measured memory_bytes: 256
// 5/13 過去問ガリガリ
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

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

    // ll n = 1;  // 2のn乗以下か
    // ll N = 2;
    // while (H > N) {
    //     N *= 2;
    //     n++;
    // }

    // cout << n << endl;

    ll num = 1;
    ll ans = 0;

    while (true) {
        H /= 2;
        ans += num;

        if (H == 0) {
            break;
        }

        num *= 2;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3584
#include<stdio.h>
int main()
{
	long a,b,gcd,lcm,max,min,r;
	while((scanf("%ld %ld",&a,&b) != EOF))
	{
		max = a;min=b; if(b>a){max=b;min=a;}
		do
		{
			 r = max%min ;
			max = min;
			min = r;
		}while(min != 0);
		gcd = max;
		
		lcm = a*b/gcd;
		printf("%ld %ld\n",gcd,lcm);
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 100000;
int main()
{
  int n,i,res;
  int d[N_MAX];
  cin >> n;
  for(i=0;i<n;i++)
    cin >> d[i];
  sort(d,d+n);
  res=d[n/2]-d[n/2-1];
  cout << res << endl;
  return 0;
}


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

int main() {
    int N;  cin >> N;
    vector<pair<int, int>> v;
    for (int i = 1; i <= N; ++i) {
        int a;  cin >> a;
        v.push_back(make_pair(a, i));
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < N; ++i) cout << v[i].second << " ";
    cout << endl;
}


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

int main(){
  int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  int p[100005],q[100005],r[100005];
  rep(i,a) cin>>p[i];
  rep(i,b) cin>>q[i];
  rep(i,c) cin>>r[i];
  priority_queue<int,vector<int>,greater<int>> qp,qq;
  sort(p,p+a); sort(q,q+b);
  reverse(p,p+a); reverse(q,q+b);
  rep(i,x) qp.push(p[i]);
  rep(i,y) qq.push(q[i]);
  sort(r,r+c);
  reverse(r,r+c);
  rep(i,c){
    if(qp.top()>=r[i]&&qq.top()>=r[i]) continue;
    if(qp.top()>qq.top()){
      qq.pop();
      qq.push(r[i]);
    }
    else{
      qp.pop();
      qp.push(r[i]);
    }
  }
  ll ans=0;
  while (!qp.empty()) {
    ans+=(ll)qp.top();
    qp.pop();
  }
  while (!qq.empty()) {
    ans+=(ll)qq.top();
    qq.pop();
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2552
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s;
int main() {
  cin >> s;
  string t;
  i64 n = s.size();
  for (i64 i = 0; i < n; ++i) {
    if (i < n - 1 && s[i] == 'B' && s[i + 1] == 'C') {
      t.push_back('D');
      ++i;
    } else t.push_back(s[i]);
  }

  cerr << t << '\n';

  i64 m = t.size(), cnt = 0, ans = 0;
  for (i64 i = 0; i < m; ++i) {
    if (t[i] == 'A') ++cnt;
    else if (t[i] == 'D') ans += cnt;
    else cnt = 0;
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 776
#include<iostream>
using namespace std;

int main(){

int n,x,cnt=0;

while(1){
    cin>>n>>x;
    if(n==0 && x==0){
        break;
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            for(int k=j+1;k<=n;k++){
                if(i+j+k==x){
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;
    cnt=0;
}


    return 0;
}


Measured memory_bytes: 3076
using System;
using System.Collections.Generic;
using System.Linq;
class Program
 {
        static void Main(string[] args)
        {
        　　int N;
            N = int.Parse(Console.ReadLine()); //標準入力
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            int count = 0;
            for(int i=0; i < N; i++)
            {
                if(int.Parse(str[i]) != (i + 1))
                {
                    count++;
                }
            }
            if(count <= 2)
            {
                Console.Write("YES");
            }
            else
            {
                Console.Write("NO");
            }
        }
 }

Measured memory_bytes: 13140
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		long v=s.nextLong();
		long a[]=new long[n];
		for(int i=0;i<k;i++)
		{a[i]=v;}
		if(v>=3)
		{for(int i=k;i<n;i++)
		a[i]=v-1;}
		else
		{for(int i=k;i<n;i++)
		a[i]=v+1;}
		for(int i=0;i<n;i++)
		System.out.print(a[i]+" ");
	}}

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

int main()
{
    int n;
    int ans = 0;
    std::cin>>n;
    std::vector<int> b(n);
    std::vector<int> a(n);
    for(int i=0;i<n-1;i++)std::cin>>b[i];

    b[n-1] = INT_MAX-1;
    ans += b[0];
    for(int i=1;i<n;i++){
        ans += std::min(b[i],b[i-1]);
    }
    std::cout<<ans<<std::endl;
}

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

template<class T> struct rge { T b, e; };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
    ~debug(){cerr<<endl;}
    template<class T> debug& operator<<(T x){cerr<<boolalpha<<x; return *this;}
    template<class B, class C> debug& operator<<(pair<B, C> x){return *this<<"("<<x.first<<", "<<x.second<<")";}
    template<class T> debug& operator<<(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}return *this<<"]";}
    template<class T> debug& operator<<(vector<T> x){ return *this<<range(x.begin(),x.end());}
#else
    template<class T> debug& operator <<(const T&){return *this;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}

const int mod = 998244353;
const int mxN = 200*1000+5;
int fact[mxN], finv[mxN];

int add(int a, int b) {
	a += b;
	while(a >= mod) {
		a -= mod;
	}
	return a;
}

void add_self(int& a, int b) {
	a = add(a, b);
}

int mul(int a, int b) {
	return 1LL * a * b % mod;
}

int mpow(int a, int n) {
	if(n == 0) {
		return 1;
	}
	int x = mpow(a, n/2);
	x = mul(x, x);
	if(n&1) {
		x = mul(x, a);
	}
	return x;
}

int binomial(int n, int k) {
	return mul(fact[n], mul(finv[n-k], finv[k]));
}

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

	int n, m, k;
	cin >> n >> m >> k;
	fact[0] = finv[0] = 1;
	for(int i = 1; i < n; i++) {
		fact[i] = mul(i, fact[i-1]);
		finv[i] = mpow(fact[i], mod-2);
	}
	int ans = 0;
	forn(i, k+1) {
		add_self(ans, mul(mul(m, binomial(n-1, i)), mpow(m-1, n-i-1)));
	}
	cout << ans << endl;
}













// Those who say they can, and those who say they can't - are both usually right.

// Read statement carefully
// Solve on paper first!
// Overflows (long long)

// Author: blondie

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

using namespace std;
#define sz(x) (int)x.size()

int n;
long long W, w[111], v[111];
long long dp[111][100011];
int main(){

    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif

    cin >> n >> W;
    for(int i = 1; i <= n; ++i){
        cin >> w[i] >> v[i];
    }

    for(int i = 0; i <= W; ++i){
        dp[0][i] = 0;
    }
    for(int i = 1; i <= n; ++i){
        dp[i][0] = 0;
    }

    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= W; ++j){
            if(j >= w[i]){
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
            } else{
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    cout << dp[n][W];
	return 0;
}


Measured memory_bytes: 80128
N = int(input())

A = [0] * (N + 1)
B = [0] * (N + 1)
C = [0] * (N + 1)

for i in range(1, N + 1):
    A[i], B[i], C[i] = map(int, input().split())

dp = [[0] * 3 for _ in range(N + 1)]#N+1
for i in range(1, N + 1):
    dp[i][0] = A[i] + max(dp[i-1][1], dp[i-1][2])#dp[i][0]=i日目でaを選んだ時の最大値＝i-1日目でbかcを選んだ時の最大値+ai
    dp[i][1] = B[i] + max(dp[i-1][2], dp[i-1][0])
    dp[i][2] = C[i] + max(dp[i-1][0], dp[i-1][1])

print(max(dp[N]))#Nの時の最大

Measured memory_bytes: 34676
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int k,x;cin>>k>>x;
  for(int i=x-k+1;i<=x+k-1;i++)cout<<i<<" ";cout<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
    long double a, b, c, C;
    cin >> a >> b >> C;

    long double S, L, h;

    long double pi;

    pi = 3.1415926;

    S = 0.5 * a * b * sin(C*pi/180);
    c = sqrt(a * a + b * b - 2 * a * b * cos(C*pi/180));
    L = a + b + c;
    h = S * 2 / a;

    cout << fixed << setprecision(15) << S << endl;
    cout << fixed << setprecision(15) << L << endl;
    cout << fixed << setprecision(15) << h << endl;
}


Measured memory_bytes: 3584
[N, K] = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]*2

base1 = 0
base2 = 0

for i in range(N):
    count1 = 0
    count2 = 0
    for j in range(i+1, i+1+N):
        if B[i] > B[j]:
            if j < N:
                count1 += 1
            else:
                count2 += 1
        
    base1 += count1
    base2 += count2
    
ans = (base1*K*(K+1)+base2*(K-1)*K)//2
    
divisor = 1000000007

print(ans % divisor)


Measured memory_bytes: 3188
s = input()

def calc_sum(n):
    if n <= 0:
        return 0
    return (n+1)*n/2

length = len(s)

num_g = 0
num_l = 0

prev = 1
cur = -1

out = 0

for i in range(length):
    if s[i] == '<':
        cur = 1
    else:
        cur = 0
        
    if prev == 1 and cur == 1:
        num_g += 1
    elif prev == 1 and cur == 0:
        num_l += 1
    elif prev == 0 and cur == 0:
        num_l += 1
    elif prev == 0 and cur == 1:
        out += calc_sum(max(num_g, num_l)) + calc_sum(min(num_g, num_l)-1)
        
        num_g = 1
        num_l = 0
    
    prev = cur
    
if cur == 1:
    out += calc_sum(num_g)
else:
    out += calc_sum(max(num_g, num_l)) + calc_sum(min(num_g, num_l)-1)
    
print(str(int(out)))

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

int main(){
	multiset<float> pq;
	int n;
	cin>>n;
	float a[n];
	for(int i = 0;i<n;i++){
		cin>>a[i];
		pq.insert((float)a[i]);
	}
	while(pq.size() > 1){
		multiset<float> :: iterator it = pq.begin();
		float b = *it;
		pq.erase(it);
		it = pq.begin();
		float c = *it;
		pq.erase(it);
		float mid = (b + c)/2;
		pq.insert(mid);
	}
	cout<<*pq.begin()<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())

card = {}
for i in range(N):
    tmp = input()
    if tmp in card:
        card[tmp] += 1
    else:
        card[tmp] = 1
        
M = int(input())
for i in range(M):
    tmp = input()
    if tmp in card:
        card[tmp] -= 1
 
print(max(0, max(card.values())))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
#include <list>
using namespace std;

struct UnionFind{
  vector<int> data;
  UnionFind(int size): data(size, -1){}
  bool unioSet(int x, int y){
    x = root(x); y = root(y);
    if(x != y){
      if(data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y){
    return root(x) == root(y);
  }
  int root(int x){
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x){
    return -data[root(x)];
  }
};

int main(){
  int n, m, q;
  int x, y;
  cin >> n >> m;
  UnionFind uf(n);
  for(int i=0;i<m;i++){
    cin >> x >> y;
    uf.unioSet(x, y);
  }
  cin >> q;
  vector<bool> out(q);
  for(int i=0;i<q;i++){
    cin >> x >> y;
    out[i] = (uf.findSet(x, y));
  }
  for(int i=0;i<q;i++){
    cout << (out[i] ? "yes" : "no") << endl;
  }
  return 0;
}

Measured memory_bytes: 1532
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010000;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;

typedef pair<int, int>P;

long long gcd(long long x, long long y) {
	long long m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}

int L[100010], R[100010], A[100010];
signed main() {
	int N; cin >> N;
	REP(i, N) {
		cin >> A[i];
	}

	L[0] = A[0];
	R[N - 1] = A[N - 1];
	REP(i, N - 1) {
		L[i + 1] = gcd(L[i], A[i + 1]);
	}
	REPR(i, N - 2) {
		R[i] = gcd(R[i + 1], A[i]);
	}
	int ans = max(R[1], L[N - 2]);
	FOR(i, 1, N - 1) {
		ans = max(ans, gcd(L[i - 1], R[i + 1]));
	}
	print(ans);

}


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

const int inf = 1e9;
const ll linf = 1e18;

template <long long mod> class modint
{
private:
    long long x;

public:
    modint(long long x = 0) : x(x >= 0 ? x % mod : (x % mod) + mod) {}
    modint &operator+=(const modint rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator-=(const modint rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator*=(const modint rhs) {
        (x *= rhs.x) %= mod;
        return *this;
    }
    modint &operator/=(const modint rhs) {
        *this *= rhs.inv();
        return *this;
    }
    modint operator+(const modint rhs) const { return modint(*this) += rhs; }
    modint operator-(const modint rhs) const { return modint(*this) -= rhs; }
    modint operator*(const modint rhs) const { return modint(*this) *= rhs; }
    modint operator/(const modint rhs) const { return modint(*this) /= rhs; }

    modint operator-() const { return modint(-x); }

    modint pow(long long n) const {
        modint e = *this, ret = modint(1);
        while (n) {
            if (n & 1) ret *= e;
            e *= e, n >>= 1;
        }
        return ret;
    }

    modint inv() const { return pow(mod - 2); }

    friend ostream &operator<<(ostream &os, const modint &m) {
        os << m.x;
        return os;
    }

    friend istream &operator>>(istream &is, modint &m) {
        long long in;
        is >> in;
        m = modint(in);
        return is;
    }
};
using mint = modint<998244353>;

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

    int n; cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) cin >> d[i];

    vector<int> num(n, 0);
    for (int i = 0; i < n; i++) num[d[i]]++;

    mint ans;
    if (d[0] == 0 && num[0] == 1) {
        ans = 1;
        int cnt = 1;

        for (int i = 1; cnt < n; i++) {
            if (num[i] == 0) {
                ans = 0;
                break;
            }
            ans *= static_cast<mint>(num[i-1]).pow(num[i]);
            cnt += num[i];
        }
    } else {
        ans = 0;
    }

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

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
INF = float("inf")


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

    flag = True
    for a in A:
        if a % 2 == 1:
            continue
        if not (a % 3 == 0 or a % 5 == 0):
            flag = False
            break
    if flag:
        print("APPROVED")
    else:
        print("DENIED")


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
//#define ls x<<1
//#define rs x<<1|1
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-8;
const ull hashp=131;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=11092019;
const int maxn=2e5+100;
int head[maxn],cnt,dis[maxn],ans[maxn];
struct edge{
	int nxt,to;
}e[maxn*2];
struct node{
	int d,u;
	bool operator < (const node&z) const {return d>z.d;}
};
void add(int a,int b){
	e[++cnt].nxt=head[a],e[cnt].to=b,head[a]=cnt;
}
priority_queue<node>q;
void dij(){
	while(!q.empty()){
		node now=q.top();q.pop();
		int u=now.u;
		if(dis[u]!=now.d)continue;
		for(int i=head[u];i;i=e[i].nxt){
			int to=e[i].to;
			if(dis[to]>dis[u]+1){
				dis[to]=dis[u]+1;
				ans[to]=u;
				q.push(node{dis[to],to});
			}
		}
	}
}
void solve(){
	int n,m;scdd(n,m);
	rep1(i,m){
		int x,y;scdd(x,y);
		add(x,y);add(y,x);
	}
	mst(dis,inf);
	dis[1]=0;
	q.push(node{0,1});
	dij();
	rep1(i,n)if(dis[i]==inf){
		printf("No");
		return ;
	}
	printf("Yes\n");
	for(int i=2;i<=n;i++)
		printf("%d\n",ans[i]);
	
}
int main(){
    //IOS;
    //freopen("D:\\data.txt","r",stdin);
    //freopen("D:\\out.txt","w",stdout);
    solve();

	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;                                             ;;
	;;         ;;            ;;;;;;;;;       ;;    ;;
	;;        ;; ;;        ;;                ;;    ;;
	;;       ;;   ;;       ;;                ;;    ;;
	;;      ;;;;;;;;;      ;;                ;;    ;;
	;;     ;;       ;;     ;;                      ;;
    ;;    ;;         ;;      ;;;;;;;;;       ;;    ;;
    ;;                                             ;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    return 0;
}

Measured memory_bytes: 8600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=60;
const ll mod=1e9+7;
int n;
char s[3][maxn];
ll sum=1;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=2;i++) {
		scanf("%s",s[i]+1);
	}
	int pos=1,ne=0;
	while(pos<=n) {
//		cout<<pos<<" "<<sum<<endl;
//		cout<<s[1][pos]<<s[1][pos+1]<<endl;
//		cout<<s[2][pos]<<s[2][pos+1]<<endl;
		if(pos==1) {
			if(s[1][pos]==s[2][pos]) {
				sum*=3;
				pos++;
				ne=1;
				continue;
			}
			else {
				sum*=6;
				pos+=2;
				ne=2;
			}
			continue;
		}
		if(s[1][pos]==s[2][pos]) {
			sum*=(3-ne);
			ne=1;
			sum%=mod;
			pos++;
			continue;
		}
		else {
			if(s[1][pos-2]==s[1][pos-1]) {
				sum*=3;
				sum%=mod;
				pos+=2;
				ne=2;
				continue;
			}
			sum*=(3-ne);
			sum%=mod;
			ne=2;
			pos+=2;
			continue;
		}
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#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)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}

const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;


int main() {
  int n;
  scanf("%d",&n);
  vi a(n);
  rep(i,n) scanf("%d",&a[i]);
  ll ans = 0;
  int d = 0;
  rep(i,n) {
    int x = a[i]/2, y = a[i]&1;
    ans += x;
    if (d) {
      if (y) {
        ans++;
        d = 0;
      } else {
        if (a[i]) {
          d = 1;
        } else {
          d = 0;
        }
      }
    } else {
      d = y;
    }
  }
  cout<<ans<<endl;
  return 0;
}










Measured memory_bytes: 640
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    x = list(map(int, input().split()))
    p, n = [], []
    for i in x:
        if  i > 0:
            p.append(i)
        elif i < 0:
            n.append(-i)
    p.sort()
    n.sort()
    lenp = len(p)
    lenn = len(n)
    if lenp == 0 and lenn == 0:
        print(0)
        exit()
    if lenn == 0:
        print(p[k-1])
        exit()
    if lenp == 0:
        print(n[k-1])
        exit()
    res = 10000000000000000000000
    if lenp > lenn:
        for i in range(k-lenp-1, lenn):
            res = min(res, n[i]+p[k-i-2]+min(n[i], p[k-i-2]))
        print(res)
    else:
        for i in range(k-lenn-1, lenp):
            res = min(res, p[i]+n[k-i-2]+min(p[i], n[k-i-2]))
        print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 59032
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#define rep(i, a, n) for(int i = int(a);i < int(n);++i)
#define repe(i, a, n) for(int i = int(a);i <= int(n);++i)
#define repr(i, a, n) for(int i = int(a);i > int(n);--i)
#define reper(i, a, n) for(int i = int(a);i >= int(n);--i)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using namespace std;


int main(){
	int a, b;
	cin >> a >> b;
	int ans = a-1;
	if(a <= b) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
amax=max(a)
dp=[True]*(amax+1)
ans=0
for i in range(n):
    if dp[a[i]]:
        ans+=1
        for j in range(a[i],amax+1,a[i]):
            dp[j]=False
        if i<n-1:
            if a[i]==a[i+1]:
                ans-=1
print(ans)

Measured memory_bytes: 33280
N, A, B, C = map(int, input().split())
l = []
for i in range(N):
    l.append(int(input()))
    
def dfs(bamboo, a, b, c):
    if bamboo == N:
        if min(a, b, c) > 0:
            return abs(A-a) + abs(B-b) + abs(C-c) - 30
        else:
            return 10**10
    else:
        ans1 = dfs(bamboo+1, a, b, c)
        ans2 = dfs(bamboo+1, a+l[bamboo], b, c) + 10
        ans3 = dfs(bamboo+1, a, b+l[bamboo], c) + 10
        ans4 = dfs(bamboo+1, a, b, c+l[bamboo]) + 10
        return min(ans1, ans2, ans3, ans4)
        
print(dfs(0, 0, 0, 0))

Measured memory_bytes: 9240
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

int h,w,n;
char ss[1000001];
char field[1001][1001];
int sx,sy;
int gx,gy;

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

int d[4][1001][1001];
int toAng[4][4][1000001];
const int INF=1000000000;

typedef pair<int,int> pii;

bool bfs(){
	// »ÝÌü«©çÚIÌü«ÖÚ®·éÌÉÇ±ÜÅ^[ðg¤Kvª é©vZ
	// ìêÈ¢ÈçÎINF
	// cang==oagn
	for(int i=0;i<4;i++)for(int j=0;j<=n;j++)toAng[i][i][j]=j;
	// cang!=oang&&pos==n
	for(int i=0;i<4;i++)for(int j=0;j<4;j++)if(i!=j)toAng[i][j][n]=INF;
	for(int k=n-1;k>=0;k--){
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(j==i)continue;
				int nang;
				int cang=i;
				int oang=j;
				int pos=k;
				if(ss[pos]=='L')nang=(cang-1+4)%4;
				else nang=(cang+1)%4;
				toAng[cang][oang][pos]=toAng[nang][oang][pos+1];
			}
		}
	}
	//  éêÖB·éÌÉKvÈÅ¬^[
	priority_queue<pair<pii,pii>,vector<pair<pii,pii> >,greater<pair<pii,pii> > > pq;
	for(int i=0;i<4;i++)for(int j=0;j<1001;j++)for(int k=0;k<1001;k++)d[i][j][k]=INF;
	pq.push(make_pair(pii(0,0),pii(sy,sx)));
	d[0][sy][sx]=0;
	while(pq.size()){
		pair<pii,pii> p=pq.top();
		pq.pop();
		int cx=p.second.second;
		int cy=p.second.first;
		int cang=p.first.second;
		int cpos=p.first.first;
		// àµ»ÝÌRXgæè¬³¢àÌª·ÅÉ¶ÝµÄ¢½ÌÈçÎ
		if(d[cang][cy][cx]<cpos)continue;
		// 4ûüÖÚ®
		for(int i=0;i<4;i++){
			int ny=cy+dy[i];
			int nx=cx+dx[i];
			int nang=i;
			// ÌûüðìêéÜÅposðißé
			int npos=toAng[cang][nang][cpos];
			if(npos!=INF&&ny>=0&&nx>=0&&ny<h&&nx<w&&field[ny][nx]=='.'&&d[nang][ny][nx]>npos){
				d[nang][ny][nx]=npos;
				pq.push(make_pair(pii(npos,nang),pii(ny,nx)));
			}
		}
	}
	for(int i=0;i<4;i++)if(d[i][gy][gx]!=INF)return true;
	return false;
}

int main(){
	while(cin>>h>>w>>n&&(h|w|n)){
		for(int i=0;i<n;i++)cin>>ss[i];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++){
			cin>>field[i][j];
			if(field[i][j]=='S'){
				sx=j;
				sy=i;
				field[i][j]='.';
			}
			else if(field[i][j]=='G'){
				gx=j;
				gy=i;
				field[i][j]='.';
			}
		}
		if(bfs())cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
use std::io::*;
use std::str::FromStr;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let nkq: Vec<usize> = read_vec();
    let n = nkq[0];
    let k = nkq[1] as isize;
    let q = nkq[2] as isize;
    let mut a: Vec<isize> = vec![k - q; n];
    for i in 0..nkq[2] {
        let tmp: usize = read();
        a[tmp - 1] += 1;
    }

    for i in a {
        if i > 0 {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


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

int main()
{
  char s[100001];
  scanf("%s", s);
  int l = 0, r = strlen(s) - 1;
  if ((r & 1) == 0)
  {
    puts("No");
    return 0;
  }
  while (l < r)
  {
    if (s[l] == 'b' && s[r] == 'd' ||
        s[l] == 'd' && s[r] == 'b' ||
        s[l] == 'p' && s[r] == 'q' ||
        s[l] == 'q' && s[r] == 'p')
    {
      ++l;
      --r;
      continue;
    }
    puts("No");
    return 0;
  }
  puts("Yes");
  return 0;
}
    

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_157
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[,] array = new int[3, 3];
            for(int i = 0; i < 3; i++)
            {
                int[] vals = ReadInts();
                for(int j = 0; j < 3; j++)
                {
                    array[i, j] = vals[j];
                }
            }
            int n = ReadInt();
            bool[,] appears = new bool[3,3];
            for(int i = 0; i < n; i++)
            {
                int b = ReadInt();
                for(int j = 0; j < 3; j++)
                {
                    for(int k = 0; k < 3; k++)
                    {
                        if (array[j, k] == b)
                        {
                            appears[j, k] = true;
                        }
                    }
                }
            }

            for (int j = 0; j < 3; j++)
            {
                if ((appears[j, 0] && appears[j, 1] && appears[j, 2])
                    || (appears[0, j] && appears[1, j] && appears[2, j]))
                {
                    WriteLine("Yes");
                    return;
                }
            }
            if ((appears[0, 0] && appears[1, 1] && appears[2, 2])
                || (appears[0, 2] & appears[1, 1] && appears[2, 0]))
            {
                WriteLine("Yes");
                return;
            }
            WriteLine("No");
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        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: 13268
// luogu-judger-enable-o2
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;

const int N=1e5+5;
int n,a[N];
map<int,int> pos;

void init()
{
	scanf("%d",&n);int i;
	for(i=1;i<=n;++i) scanf("%d",&a[i]),pos[a[i]]=i;
}

void work()
{
	int i,ans=0;
	sort(a+1,a+n+1);
	for(i=1;i<=n;++i) ans+=(i&1)^(pos[a[i]]&1);
	printf("%d\n",ans>>1);
}

int main()
{
	init();work();
	return 0;
}

Measured memory_bytes: 5376