akhauriyash/Code-Regression huggingface dataset:
#define MOD 1000000007;
#define input ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll long long

#include <bits/stdc++.h>

using namespace std;
const int N = 2e1 + 5;

int main() {

    ll  n;
    cin>>n;
  vector<int> vec(n+1);
    for(int i=1;i<=n;i++)
    {
   cin>>vec[i];

    }
    ll ans=0;
    for(int i=1;i<=n;i++)
        if(vec[i]==i)
        {
            if(vec[i+1]==i+1&&i+1<=n)
                ans++,i++;
            else
                ans++;
        }

cout<<ans;



}

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut pseq = vec![0; n];
    for i in 0..n {
        pseq[i] = read::<usize>() - 1;
    }
    let mut ans = 0;
    for i in 0..n {
        if pseq[i] == i {
            if i != n - 1 {
                pseq.swap(i, i + 1);
            }
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>

using namespace std;

int main( )
{

	string str;
	int alphas[28] = { 0 };
	int i;
	
	while( getline( cin, str ) ) {
		for( i=0; i<str.length(); i++ ) {
			if( islower( str[i] ) ) {
				alphas[ str[i]-'a' ]++;
			} else {
				alphas[ str[i]-'A' ]++;	
			}
		}
	}
	for( i=0; i<26; i++ ) {
		cout<<char('a'+i)<<" : "<<alphas[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
#define pb push_back
#define NL cout<<'\n';
using namespace std;

int main(){

    int t=1;
   // cin >> t;
    while(t--){

         int n;
         int l,r,d;
          cin >> n;
          int a[n+10];
          for(int i  = 1; i<=n; i++) cin >>a[i];
          int cnt = 0;
          for(int i = 1; i<=n; i++){
            if(a[i]%2 && i%2) cnt++;
          }
          cout << cnt << endl;

    }

  return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
#define int ll
signed main(){
    int n, q;
    cin >> n;
    vector<int> a(n);
    for (int& i : a) cin >> i;
    cin >> q;
    map<int, int> m;
    int r = 0;
    for (int i = 0; i < n; ++i) ++m[a[i]], r += a[i];
    for (int i = 0; i < q;++i){
        int b,c;
        cin >> b >> c;
        cout << (r += (c - b) * m[b]) << endl;
        m[c] += m[b];
        m[b] = 0;
    }
}


Measured memory_bytes: 9904
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    }
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
        k: usize
    }
    let mut vals: Vec<usize> = Vec::new();
    for i in 1..101 {
        if (a % i == 0) && (b % i == 0) {
            vals.push(i);
        }
    }
    vals.reverse();
    println!("{}", vals[k - 1]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n ,k;
cin>>n>>k;
if(n%k == 0){
 cout<<"0"<<endl;
 return 0;
}
cout<<max(0LL , min(n%k , k - (n%k)))<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#define ll long long
using namespace std;
ll n,k,y,x,ans;
int main()
{
    while(cin>>n>>k>>x>>y){
      ans=0;
      for(int i=1;i<=n;i++){
        if(i<=k)ans+=x;
        else ans+=y;
      }
      cout<<ans<<endl;
    }
    return 0;
}


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



int main() { // claudio van
  string s; cin >> s;
  if (s == "Sunny") {
    puts("Cloudy");
  } else if (s == "Cloudy") {
    puts("Rainy");
  } else {
    puts("Sunny");
  }
  return 0;
}

Measured memory_bytes: 256
S=input()
flg=0
for i in range(len(S)):
  if(i%2==1 and S[i]=='R'):
    flg=1
    print('No')
    break
  if(i%2==0 and S[i]=='L'):
    flg=1
    print('No')
    break
if(flg==0):
  print('Yes')

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

int main() {
  int N, Y;
  cin >> N >> Y;
  int a = -1, b = -1, c = -1;
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= N; j++) {
      if(N - (i + j) >= 0 && 10000 * i + 5000 * j + 1000 * (N - (i + j)) == Y) {
        a = i;
        b = j;
        c = N - (i + j);
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
  
using namespace std;
  
int main(){
    int n;
    int a[100],b[100];
    int x,y,v;
    while(true){
    cin>>n;
    if(n==0)
        break;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int tmp;
  for (int i=0;i<n;i++) { 
    for (int j=i+1;j<n;j++) { 
      if (a[i]>a[j]) { 
        tmp=a[i]; 
        a[i] =a[j]; 
        a[j] = tmp; 
      } 
    } 
  }
  int s=1;
  for(int i=0;i<n;i++){
      while(true){
          int d=0;
      for(int j=0;j<n;j++){
          if(a[j]!=s)
              d++;
      }
      if(d==n){
          b[i]=s;
          s++;
          break;
      }
      s++;
      }
  }
  x=n-1;
  y=n;
  v=a[0];
  a[0]=0;
  while(true){
      int i=0;
      while(true){
          if(i==n){
              v=0;
              break;
          }
          if(b[i]>v){
              v=b[i];
              b[i]=0;
              y--;
              break;
          }
          i++;
      }
      if(y==0)
          break;
      int j=0;
      while(true){
          if(j==n){
              v=0;
              break;
          }
          if(a[j]>v){
              v=a[j];
              a[j]=0;
              x--;
              break;
          }
          j++;
      }
      if(x==0)
          break;
    }
      cout<<y<<endl;
      cout<<x<<endl;
    }
    return 0;
} 
 

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define vn v[now]
#define dn d[now]
#define cn c[now]
int n,m,q;
vector<int> g[100001];
int v[100001],d[100001],c[100001];
bool vis[100001];
int mindis[100001];
int color[100001];
int now;
void dfs(int vv,int dd){
    if(dd<0 || dd<=mindis[vv])
        return;
    mindis[vv]=dd;//还可以走的步数
    //因为最多是di步,从di开始走一步减1，现在leftd就是剩下的步数呀
    //然后，mindis就是这个地方最多剩的步数，如果后一次剩的步数比前一次少
    //那么就肯定走不出这种颜色覆盖的范围，so，综上所述，应该舍掉 
    if(!color[vv])
        color[vv]=cn;
    if(dd==0)
        return;
    for(int i=0;i<g[vv].size();i++)
        dfs(g[vv][i],dd-1);
}
int main(){
    ios::sync_with_stdio(0);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cin>>q;
    for(int i=0;i<q;i++)
        cin>>v[i]>>d[i]>>c[i];
    memset(mindis,-1,sizeof(mindis));
    for(int i=q-1;i>=0;i--){
        now=i;
        dfs(vn,dn);
    }
    for(int i=1;i<=n;i++)   
        cout<<color[i]<<endl;
    return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

void solve()
{
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2.0 << endl;
}

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

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

const int MAX = 100;

int main(){
    int n, w[MAX];
    cin >> n;

    int sum = 0;
    rep(i,n){
        int W;
        cin >> W;
        sum += W;
        w[i] = sum;
    }

    int res = sum;
    rep(i,n){
        res = min(res, abs(sum - 2*w[i]));
    }

    cout << res << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a+b>c+d)
    {
        printf("Left");
    }
    else if(a+b==c+d)
    {
        printf("Balanced");
    }
    else
    {
        printf("Right");
    }
    return 0;
}


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

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

int main() {
  ll n, x, m, logn = 1, ans = 0;
  cin >> n >> x >> m;
  while ((1ll << logn) < n) logn++;
  vector<vector<ll>> nex(logn, vector<ll>(m, -1)), sum(logn, vector<ll>(m, 0));

  for (ll r = 0; r < m; ++r) {
    nex[0][r] = r * r % m;
    sum[0][r] = r;
  }

  for (int p = 0; p < logn - 1; ++p)
    for (int r = 0; r < m; ++r) {
      nex[p + 1][r] = nex[p][nex[p][r]];
      sum[p + 1][r] = sum[p][r] + sum[p][nex[p][r]];
    }

  for (int p = 0; p < logn; ++p)
    if (n & (1LL << p)) ans += sum[p][x], x = nex[p][x];

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


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

int main()
{
  int n,k;
  cin >> n >> k;
  set<int> list;
  rep(i, k)
  {
    int d;
    cin >> d;
    rep(j, d)
    {
      int e;
      cin >> e;
      list.insert(e);
    }
  }
  int ans = 0;
  rep(i, n)
  {
    if(list.find(i+1) == list.end())
    {
      ans++;
    }
  }
  
  cout << fixed << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(std::string N) {
  int ret = 0;
  for(auto s:N)
  (ret += (s-'0'))%=9;
  YesNo(!ret);

}

signed main() {
  std::string N;
  std::cin >> N;
  solve(N);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 3852
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        a: [i64; n],
        bc: [(i64, i64); m]
    }
    let mut list: Vec<(i64, i64)> = Vec::new();
    for elem in a {
        list.push((1, elem));
    }
    for elem in bc {
        list.push(elem);
    }
    list.sort_by(|x, y| y.1.cmp(&x.1));

    let mut ans = 0;
    let mut n_left = n as i64;
    for elem in list {
        if elem.0 <= n_left {
            ans += elem.0 * elem.1;
            n_left -= elem.0;
        } else {
            ans += n_left * elem.1;
            break;
        }
    }

    println!("{}", ans);
}

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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC
using namespace std;


template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}

const int N=5e5+10;

template<typename T>
struct Fenwick{
    vector<T> tree;
    Fenwick(int n){
        tree.resize(n);
    }

    T query(int i){
        int sum=0;
        while(i){
           sum+=tree[i];
           i-=i&(-i);
       }  
       return sum;
    }
    void update(int i,int n,T val){
       while(i<=n){
          tree[i]+=val;
          i+=i&(-i);
       }
    }
};


int solve(){
 	int x;cin>>x;
 	if(x>=30)cout<<"Yes";
 	else cout<<"No";
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
 

Measured memory_bytes: 3616
n = int(input())
A = list(map(int,input().split()))
H = [0]*(n+1)
s = sum(A)
flag= True
if n==0:
    if A[0] ==1:
        print(1)
    else:
        print(-1)
else:
    if A[0]>= 1:
        print(-1)
        flag = False
    else:
            H[0] =1
            i = 1
            while i <=n:
                if A[i] > H[i-1]*2:
                    print(-1)
                    flag =False
                    break
                else:
                    if s >=2*(H[i-1]-A[i-1]):
                        H[i] = 2*(H[i-1]-A[i-1])
                    else:
                        H[i] = s
            
                    s -= A[i]
                    i +=1
    if flag:
        print(sum(H))

Measured memory_bytes: 20152
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include<iomanip>
using namespace std;

int N;

int main() {
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int tmp = 0;
    for (int i = 0; i < N; i++) {
        if (a[i] == tmp + 1) {
            tmp++;
        }
    }
    cout << (tmp > 0? N - tmp : -1) << endl;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	flag := false
	for c:=0; c<n; c++ {
		for d:=0; d<n; d++ {
			total := c*4 + d*7
			if total == n {
				flag = true
				break
			}
		}
	}
	if flag == true {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 1768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<bool>> S(11, vector<bool>(11, false));
    rep(i, m){
        int k;
        cin >> k;
        rep(j, k){
            int tmp;
            cin >> tmp;
            S.at(i+1).at(tmp) = true;
        }
    }

    vector<int> P(11);
    rep(i, m) cin >> P.at(i+1);


    int ans = 0;
    rep(tmp, 1 << n){
        bitset<10> s(tmp);

        vector<int> On(11);
        rep(i, n){
            if(s.test(i)){
                rep(j, m){
                    if(S.at(j+1).at(i+1)) On.at(j+1)++;
                }
            }
        }

    bool flag = true;
        rep(i, m){
            if(On.at(i+1) % 2 != P.at(i+1)) flag = false;
        }

    if(flag) ans++;
    }
    

    cout << ans << endl;
}

Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        mut a: [usize; n],
    }
    a.sort();
    a.dedup();
    println!("{}", if a.len() == n { "YES" } else { "NO" });
}


Measured memory_bytes: 6396
N = int(input())
s = [(input()) for _ in range(N)]

cntA = 0
cntB = 0
cntT = 0
ans = 0
for i in s:
    if i[0] == 'B' and i[-1] == 'A':
        cntT += 1
    else:
        if i[0] == 'B':
            cntB += 1
        if i[-1] == 'A':
            cntA += 1
    ans += i.count('AB')

if cntT > 1:
    ans += cntT - 1
    cntT = 1

if cntA > 0 and cntB > 0 and cntT > 0:
    ans += 2
    cntT -= 1
    cntA -= 1
    cntB -= 1

if cntT > 0:
    if cntA > 0 and cntA >= cntB:
        cntB += 1
    elif cntB > 0:
        cntA += 1

print(ans + min(cntA, cntB))

Measured memory_bytes: 3700
#include <iostream>
using namespace std;
inline int gcd(int x,int y)
{
	if(x>y) swap(x,y);
	while(x) y%=x,swap(x,y);
	return y;
}
int main(int argc, char** argv) {
	int n;
	int ans=0;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin >> x;
		ans=gcd(ans,x);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair < int , int > pii;
typedef long long LL;
#define mpr make_pair
#define FS first
#define SC second
#define PB push_back
template < typename T > T MAX(T a,T b){return (a>b)?a:b;}
template < typename T > T MIN(T a,T b){return (a<b)?a:b;}
template < typename T > void UMAX(T &a,T b){a=(a>b?a:b);}
template < typename T > void UMIN(T &a,T b){a=(a<b?a:b);}
int readint(){
	char c=getchar();
	int ret=0;
	while(!(c>='0' && c<='9')) c=getchar();
	while(c>='0' && c<='9'){
		ret=ret*10+c-'0';
		c=getchar();
	}
	return ret;
}
void putint(int v){
	if(!v){
		putchar('0');
		return;
	}
	if(v>=10) putint(v/10);
	putchar('0'+(v%10));
}
int n,m,v,p,a[100005];
LL pr[100005];
int main(){
	int i,j,k;
	scanf("%d%d%d%d",&n,&m,&v,&p);
	for(i=0;i<n;++i){
		scanf("%d",a+i);
	}
	sort(a,a+n);
	for(i=0;i<n;++i){
		pr[i]=(LL)a[i];
		if(i) pr[i]+=pr[i-1];
	}
	int l=1,r=0,res=0;
	LL sum=0ll;
	for(i=0;i<n;++i){
		while(r<n-1 && a[r+1]<=a[i]+m){
			sum+=(LL)a[++r];
		}
		while(l<n-1 && a[l]<=a[i]){
			sum-=(LL)a[l++];
		}
		if(n-1-r>=p) continue;
		LL got=(LL)m*(LL)(n-1-r+l)+(LL)(r-l+1)*(LL)(m+a[i])-sum;
		if(got>=(LL)m*(LL)v)
			++res;
		else{
			LL dif=(LL)m*(LL)v-got;
			int lm=p-1-(n-1-r);
			if(lm>=r-l+1)
				++res;
			else if((LL)lm*(LL)m-((LL)lm*(LL)(m+a[i])-(pr[r]-pr[r-lm]))>=dif){
				++res;
			}
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 1408
/*
j is activity on current day
k is activity on previous day
*/
#include<bits/stdc++.h>
using namespace std;
 
int main() {
	int n, a[100005], b[100005], c[100005];
	cin >> n;
	vector<vector<int>> dp (n+1, vector<int>(3, 0));
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i] >> c[i];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j == k)
					continue;
				if (j == 0)
					dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i]);
				else if (j == 1)
					dp[i][j] = max(dp[i][j], dp[i-1][k] + b[i]);
				else
					dp[i][j] = max(dp[i][j], dp[i-1][k] + c[i]);
			}
		}
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}

Measured memory_bytes: 6912
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,k,x,y,ans=0;
	cin>>n>>k>>x>>y;
	for(int i=1;i<=n;i++){
		if(i<=k)ans+=x;
		else ans+=y;
	}
	cout<<ans<<endl;
	
	return 0;
}

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

using namespace std;

using ll = long long;

vector<int> getInv(vector<int>& v) {
    vector<int> res(v.size());
    for (int i = 0; i < v.size(); i++) {
        res[v[i]] = i;
    }
    return res;
}

vector<int> getMul(vector<int> p, vector<int> q) {
    vector<int> res(p.size());
    for (int i = 0; i < p.size(); i++) {
        res[i] = q[p[i]];
    }
    return res;
}

vector<int> getNext(vector<int>& p, vector<int>& q) {
    vector<int> res(p.size());
    for (int i = 0; i < p.size(); i++) {
        res[p[i]] = q[i];
    }
    return res;
}

vector<int> getPow(vector<int> v, int n) {
    vector<int> res(v.size());
    for (int i = 0; i < v.size(); i++) res[i] = i;
    while (n > 0) {
        if (n & 1) res = getMul(res, v);
        v = getMul(v, v);
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }

    for (int i = 0; i < n; i++) {
        cin >> q[i];
        q[i]--;
    }

    vector<int> pinv = getInv(p), qinv = getInv(q);
    vector<int> v1 = getPow(getMul(getMul(getMul(p, qinv), pinv), q), (K - 1) / 6);
    vector<int> v2 = getPow(getMul(getMul(getMul(qinv, p), q), pinv), (K - 1) / 6);
    vector<int> v3;
    if ((K - 1) % 6 == 0) v3 = p;
    else if ((K - 1) % 6 == 1) v3 = q;
    else {
        for (int i = 2; i <= (K - 1) % 6; i++) {
            v3 = getNext(p, q);
            p = q;
            q = v3;
        }
    }
    vector<int> ans = getMul(getMul(v2, v3), v1);

    for (int i = 0; i < n; i++) {
        cout << ans[i] + 1 << " \n"[i + 1 == n];
    }
    return 0;
}

Measured memory_bytes: 7124
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#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 INF 999999999
#define MOD 1e9+7
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

ll gcd(ll n, ll m){
    if(m==0)return n;
    return gcd(m, n % m);
}

ll lcm(ll n, ll m){
    return m / gcd(n, m) * n;
}

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int N;
    string S,T;
    string ans="";
    cin >> N >> S >> T;
    REP(i,N){
        ans+=S.at(i);
        ans+=T.at(i);

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

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




int main() {
    int n;
    cin >> n;
    
    if(n < 1000){
        cout << "ABC" << endl;
    }
    else{
        cout << "ABD" << endl;
    }
}

Measured memory_bytes: 256
/*
 * hoge.cpp
 *
 *  Created on: 2014/09/30
 *      Author: eiichi
 */
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<list>
using namespace std;

int pub[4][3][10];
int main(void){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int b,f,r,v;
		cin >> b >> f >> r >> v;
		pub[--b][--f][--r] += v;
	}

	for(int i=0;i<4;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<10;k++){
				cout << " ";
				cout << pub[i][j][k];
			}
			cout << endl;
		}
		if(i!=3)cout << "####################" <<endl;
	}

	return 0;
}

Measured memory_bytes: 1160
S = input()
T = input()

t_pattern = []

for i in range(len(S)+1 - len(T)):
    tmp = ""
    for j in range(i):
        tmp += " "
    tmp += T
    tmp_len = len(tmp)
    for j in range(len(S) - tmp_len):
        tmp += " "
    t_pattern.append(tmp)

candidate = []

for i in t_pattern:
    count = 0
    for j in range(len(S)):
        if i[j] == " ":
            continue
        elif i[j] == S[j] or S[j] == "?":
            count += 1
            if count == len(T):
                candidate.append(i)
            continue
        else:
            break

if not candidate:
    print("UNRESTORABLE")
    exit()

ans = ""
for i in range(len(S)):
    if S[i] == "?" and candidate[-1][i] == " ":
        ans += "a"
    elif S[i] != "?":
        ans += S[i]
    else:
        ans += candidate[-1][i]


print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

int main()
{
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n){
    cin >> x[i];
  }

  vector<mint> c(n);
  rep1(i,n-1){
    mint z(1);
    z /= (mint)i;
    c[i] = c[i-1] + z;
  }

  mint cc(1);
  rep1(i,n-1){
    cc *= (mint)i;
  }
  
  mint res;
  rep1(i,n-1){
    res += (mint)(x[i]-x[i-1])*c[i];
  }

  res *= cc;
  cout << res.x << "\n";
  
  return 0;
}


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

N=int(input())
P=[tuple(map(int,input().split())) for i in range(N)]

def calcdismax(x,y):
    MAX=0
    for px,py in P:
        MAX=max(MAX,(px-x)**2+(py-y)**2)

    return MAX
        
delta=10**(-10)

def div100(xmin,xmax,ymin,ymax):

    xh=(xmax-xmin)/100
    yh=(ymax-ymin)/100

    MIN=1<<30
    MINx=0
    MINy=0

    for i in range(101):
        xk=xmin+xh*i
        for j in range(101):
            yk=ymin+yh*j
            cd=calcdismax(xk,yk)

            #print(xk,yk,cd)

            if MIN>cd:
                MIN=cd
                MINx=xk
                MINy=yk

    #print(MINx,MINy,MIN)

    return MINx,MINy

now=500
k=500
l=500
while now>10**(-7):
    k,l=div100(k-now,k+now,l-now,l+now)
    now/=2

import math
print(math.sqrt(calcdismax(k,l)))


Measured memory_bytes: 43244
n,m = map(int,input().split())
H = list(map(int,input().split()))
L = [list(map(int,input().split())) for _ in range(m)]
ans = [1 for _ in range(n)]
for l in L:
    if H[l[0]-1] > H[l[1]-1]:
        ans[l[1]-1] = 0
    elif H[l[0]-1] < H[l[1]-1]:
        ans[l[0]-1] = 0
    else:
        ans[l[1]-1] = 0
        ans[l[0]-1] = 0
print(sum(ans))

Measured memory_bytes: 98716
#include<iostream>
using namespace std;
int main(){
  int num[201],log[1000001],logo[1000001];
  for(int i=1; i<200; i++){
    num[i] = i*(i+1)*(i+2)/6;
  }
  for(int i= 0; i<1000001; i++){
    log[i] = logo[i] = i;
    for(int j=1; j<201; j++){
      if(num[j]>i){break;}
      if(log[i]>log[i-num[j]]){log[i] = log[i-num[j]]+1;}
      if(num[j]%2){
	if(logo[i]>logo[i-num[j]]){logo[i] = logo[i-num[j]]+1;}
      }
    }
  }
  int n;
  while(cin >>n,n){
    cout <<log[n]<<" "<<logo[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 8548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int n; string s;
    cin >> n >> s;
    int rui_W[n+1], rui_E[n+1];
    rui_W[0] = 0;
    rui_E[0] = 0;
    for(int i=0; i<n; i++){
        if(s[i] == 'E'){
            rui_E[i+1] = rui_E[i] + 1;
            rui_W[i+1] = rui_W[i];
        }
        else if(s[i] == 'W'){
            rui_E[i+1] = rui_E[i];
            rui_W[i+1] = rui_W[i] + 1;
        }
    }

    int ans = 300300;
    for(int i=0; i<n; i++){
        int left = rui_W[i];
        int right = rui_E[n] - rui_E[i+1];
        ans = min(ans, left+right);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6128
#include<stdio.h>
int main(void){
  int l,i,j,cnt=1,f=0;
  scanf("%d",&l);
  int mt[l];
  scanf("%d",&mt[0]);
  for(i=1;i<l;i++){
    f=0;
    scanf("%d",&mt[i]);
    for(j=0;j<i;j++){
      if(mt[i]<mt[j]){
        f=1;
      }
    }
    if(f==0){
      cnt++;
    }
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
	
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {

		Scanner keyboard = new Scanner(System.in);

		int N = keyboard.nextInt();
		//キーがStringで中身がintのHashMapを作る
		HashMap<String, Integer> count = new HashMap<String, Integer>();
		
		for (int s=0; s<N; s++) {
			String S = keyboard.next();
			if (count.containsKey(S)) { //HashMapに既にキーがあるとき
				int now = count.get(S); //キーSに紐づく中身のintを取得
				count.replace(S, now + 1);
			}
			else {
				count.put(S, 1); //まだHashMapにキーが登録されていないなら、登録する
			}
		}
		
		int Max = 0;
		for (int val: count.values()) { 
			if (Max <= val) {
				Max = val;
			}
		}
		
		List<String> print = new ArrayList<String>();
		
		for (String s: count.keySet()) { 
			int now = count.get(s);
			if (now == Max) {
				print.add(s);
			}
		}
		Collections.sort(print);
		
		StringWriter s = new StringWriter();
	    for (int i = 0 ; i < print.size() ; i++){
	        String ans = print.get(i);
	        s.append(ans + '\n');
	    }
	    System.out.println(s.toString());
		keyboard.close();
	}
	
}


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

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    vector<int> h(n + 1 + k, 0), ans(n + 1 + k, INT_MAX);
    for (int i = 0; i < n; i++) cin >> h[i];
    ans[0] = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j <= i + k; j++) {
            ans[j] = min(ans[j], ans[i] + abs(h[j] - h[i]));
        }
    }
    cout << ans[n - 1];
    return 0;
}

Measured memory_bytes: 1024
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N, M = LI()
ab = LIR(M)

for i in range(M):
    ab[i] = [ab[i][0]-1, ab[i][1]-1]

edge = [[0]*N for i in range(N)]

for e in ab:
    edge[e[0]][e[1]] = edge[e[1]][e[0]] = 1

ans = 0

def make_permutation(li, r):
    if (r <= 0) or (r > len(li)):
        return []
    
    result = []
    _make_permutation(li, r, [], result)
    return result

def _make_permutation(li, r, out, result):
    if (r == 0):
        result.append(out)
        return

    for i, num in enumerate(li):
        _make_permutation(li[:i]+li[i+1:], r-1, out+[li[i]], result)

vs = list(range(1,N))
perm = make_permutation(vs, N-1)

for pe in perm:
    before = 0
    for num in pe:
        if (edge[before][num]):
            before = num
            continue
        else:
            break
    else:
        ans += 1

print(ans)


Measured memory_bytes: 48092
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;
fn main() {
    input!{
        n: usize,
        a: chars,
        b: chars,
        c: chars,
    }
    let mut ans = 0;
    for i in 0..n {
        let mut dict = HashMap::new();
        *(dict.entry(a[i]).or_insert(0)) += 1;
        *(dict.entry(b[i]).or_insert(0)) += 1;
        *(dict.entry(c[i]).or_insert(0)) += 1;
        let (_, tmp) = dict.iter().max_by_key(|&(_, v)| v).unwrap();
        if tmp == &2 {
            ans += 1
        } else if tmp == &1 {
            ans += 2
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    
    long long ans = 0;
    REP(i, N) {
        int sum = a[i - 1] + a[i];
        if (sum > x) {
            ans += sum - x;
            a[i] = max(x - a[i - 1], 0);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main (void)

{

int a,b,c;

int tmp,i,j;

scanf("%d %d %d",&a,&b,&c);

if(a>b)

{

tmp = a;

a = b;

b = tmp;

}

if(a>c)

{

tmp = a;

a = c;

c = tmp;

}

if(b>c)

{

tmp = b;

b = c;

c =tmp;

}

printf("%d %d %d\n",a,b,c);

return 0;

}

Measured memory_bytes: 596
$line = <STDIN>;
chomp $line;
$N=scalar($line);
$line = <STDIN>;
chomp $line;
@A = split(/ /, $line);

$sa=0;
$SA[0]=0;
for($i=0;$i<$N;$i++){
	$sa = $sa + $A[$i];
	$SA[$i+1]=$sa;
}

# sum_l_r a= $SA[$r+1]-$SA[$l];

$xa=0;
$XA[0]=0;
for($i=0;$i<$N;$i++){
	$xa= ($xa ^ $A[$i]);
	$XA[$i+1]=$xa;
}

# xor_l_r a= $XA[$r+1] xor $XA[$l];


$s=0;$minr=0;
for($l=0;$l<$N;$l++){
	$s+=$minr-$l+1;
	for($r=$minr+1;$r<$N;$r++){
		$sa=$SA[$r+1] - $SA[$l];
		$xa=$XA[$r+1] ^ $XA[$l];
		last if ($xa!=$sa);
		$s++;
		$minr=$r;
	}
}

print "$s\n";


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

int GregorianDay(int y, int m, int d) {
    y += 4800;
    if (m < 3) {--y; m += 12;}
    return 365*y+y/4-y/100+y/400+(153*m-457)/5+d-32083;
}

int main() {
    int y[2], m[2], d[2];
    while (cin >> y[0] >> m[0] >> d[0] >> y[1] >> m[1] >> d[1]) {
        if (y[0] == -1) break;
        int day[2];
        for (int i = 0; i < 2; ++i) day[i] = GregorianDay(y[i], m[i], d[i]);
        cout << day[1] - day[0] << endl;
    }
}


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

int n,k,sum,arr[1001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i = 1;i <= n;i++){
		cin>>arr[i];
	}
	sort(arr + 1,arr + n + 1);
	for(int i = 1;i <= k;i++){
		sum = sum + arr[i];
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  vector<int> vec(N);
  int ans=0;
  int mean;
  double sum;
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  mean = sum/N ;
  sum= sum/N;
  
  
  if (sum-mean>0.5){
    mean += 1;
  
  }
  
  for (int i = 0; i < N; i++) {
    ans += pow((vec.at(i) - mean),2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, P = list(map(int,_in[0].split(' ')))  # type:list(int)
    A_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    len_A_odd = len([0 for a in A_arr if a%2==1])
    len_A_even = len(A_arr) - len_A_odd
    cnt = 0
    if P==0:
        cnt = 2**len_A_even*max(2**(len_A_odd-1),1)
    else:
        cnt = 2**len_A_even*(2**(len_A_odd-1) if len_A_odd>0 else 0)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 38256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

class Segtree {
    using ll = long long;
    int n;
    vector<ll> dat;

    inline ll f(ll a, ll b) {
        return max(a, b);
    }

    ll query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return def;
        if (a <= l && r <= b)
            return dat[k];
        else
            return f(query(a, b, 2 * k + 1, l, (l + r) / 2),
                query(a, b, 2 * k + 2, (l + r) / 2, r));
    }

public:
    const ll def = 0;

    Segtree() = default;
    Segtree(int n_) {
        n = 1;
        while (n < n_) n *= 2;
        dat.assign(2 * n - 1, def);
    }

    // k <- [0,n)
    void update(int k, ll a) {
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }

    // min[l,r)
    ll query(int a, int b) { return query(a, b, 0, 0, n); }
};

const ll MOD = 998244353;
const int MAX_N = 200000;
int n;
pii xd[MAX_N];
int idx(int x) {
    return lower_bound(xd, xd + n, mp(x, 0)) - xd;
}

int main() {
    fastio();

    cin >> n;
    forn(i, n) {
        cin >> xd[i].fst >> xd[i].snd;
    }

    sort(xd, xd + n);

    Segtree st(n);

    for (int i = n - 1; i >= 0; i--) {
        //cout << idx(xd[i].fst + xd[i].snd) << endl;
        int j = st.query(idx(xd[i].fst), idx(xd[i].fst + xd[i].snd));
        j = max(j, i);
        st.update(i, j);
        //cout << st.query(i, i + 1) << endl;
    }

    vl dp(n + 1);
    dp[n] = 1;

    for (int i = n - 1; i >= 0; i--) {
        dp[i] = (dp[i + 1] + dp[st.query(i, i + 1) + 1]) % MOD;
    }

    cout << dp[0] << endl;

    return 0;
}

Measured memory_bytes: 7552
mod = 998244353
n,k =map(int,input().split())
step =[0]*(n+1)
# step[0]=1
step[1]=1
stepsum=[0]*(n+1)
stepsum[1]=1
l=[0]*k
r=[0]*k
for i in range(k):
    l[i],r[i]=map(int,input().split())

for i in range(2,n+1):
    for j in range(k):
        li = i - r[j]
        ri = i - l[j]
        if ri <= 0:
            continue
        # li = max(1,li)
        step[i] += stepsum[ri] - stepsum[max(0,li-1)]
        # step[i] %= mod
        # print(step)
    stepsum[i] = ( stepsum[i-1] + step[i] )%mod


print(step[n]%mod)

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

#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long ;

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

   string n;
   cin>>n;
   for(int i=0;i<n.size();i++){
      if(n[i]=='1')n[i]='9';
      else if(n[i]=='9')n[i]='1';
   }
   cout<<n;
   return 0; 
}


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

int main() 
{
    int N; cin >> N;
    
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
            int tmp;
            cin >> tmp;
            A[i] = tmp;
    }
    vector<int> sorted_series(N);
    copy(A.begin(), A.end(), sorted_series.begin());
    sort(sorted_series.begin(), sorted_series.end());

    int Amax, Asecond;
    Amax = sorted_series[N-1];
    Asecond = sorted_series[N-2];
    for (int i = 0; i < N; i++)
    {
        if (A[i] == Amax) {
            cout << Asecond << "\n";
        } else {
            cout << Amax << "\n";
        }
    }
    
}

Measured memory_bytes: 3200