akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(int argc, const char * argv[]) {
    
    
    
    int a,b,c; cin >> a >> b >> c;
    
    if( c + b <= a) cout << 0 << endl;
    else cout << c + b - a << endl;
    
    return 0;
    
    
    
    
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int l[111];
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        for(int i=0; i<n; ++i){
            scanf("%d",a+i);
        }
        vector <int> v;
        int cnt=0;
        for(int j=1; j<=n; ++j){
            cnt=0;
            for(int i=n-1; i>=0; --i){
                if(l[i]){
                    ++cnt;
                    continue;
                }
                if(a[i]<=j && cnt==j-a[i]){
                    l[i]=1;
                    v.push_back(a[i]);
                    break;
                }
            }
        }
        if(v.size()<n){
            cout<<"-1"<<endl;
        }
        else{
            for(int i=0; i<v.size(); ++i){
                cout<<v[i]<<endl;
            }
        }
    }
  return 0;
}




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

#define ll long long
#define ld long double
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ii pair < int, int >
#define vi vector < int > 
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define all(a) (a).begin(), (a).end()

using namespace std;
using namespace __gnu_pbds;

typedef tree< int, null_type, less< int >, rb_tree_tag, tree_order_statistics_node_update > ost;
// name.find_by_order( x ) or name.order_of_key( x )

const int maxn = 2e5 + 10, maxv = 1e6 + 10, maxlog = 20;
const int inf = 1e9 + 1;
const int MOD = 1e9 + 7;
const ll INF = 4e18 + 1;
const double eps = 1e-9;

void yes() { cout << "YES\n"; }
void no() { cout << "NO\n"; }

void solve() {
	string s;
	cin >> s;
	if ( s[ 1 ] == 'R' && ( s[ 0 ] == 'R' && s[ 2 ] == 'R' ) ) { cout << "3\n";return; }
	if ( s[ 1 ] == 'R' && ( s[ 0 ] == 'R' || s[ 2 ] == 'R' ) ) { cout << "2\n";return; }
	int ans = 0;
	for( int i = 0;i < 3;i++ ) ans |= ( s[ i ] == 'R' );
	cout << ans << "\n";
}

int main() {
	int t = 1;
	//cin >> t;
	while ( t-- ) solve();
	return 0;
}


Measured memory_bytes: 3624
# coding: utf-8
# Your code here!
n,k=map(int,input().split())
l=[]
for i in range(n):
    t=int(input())
    l.append(t)
l.sort()
#print(l)
ans=100000000000
for i in range(len(l)-k+1):
    if(ans>l[i+k-1]-l[i]):
        ans=l[i+k-1]-l[i]
print(ans)

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

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 FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

bool broken[100050];
ll dp[100050];

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

    // input
    ll N, M;
    cin >> N >> M;

    vector<ll> A(M);
    FOR(i, 0, M){
        ll a; cin >> a;
        broken[a] = true;
    }

    dp[0] = 1;
    FOR(i, 0, N+10){
        if(!broken[i+1]){
            dp[i+1] += dp[i];
            dp[i+1] %= mod;
        }
        if(!broken[i+2]){
            dp[i+2] += dp[i];
            dp[i+2] %= mod;
        }
    }

    p(dp[N]);
    
    return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>


int main(){
	int a,b,i=0;

	/*
	printf("2つの正の整数a,bを入力してください\n");
	printf("a b =");
	*/
	while(scanf("%d%d",&a,&b) != EOF){
		
		a = a + b;

		while(a>=1){
			a /= 10;
			i++;
		}

		/*printf("aとbの和の桁数は%dです\n",i);*/
		printf("%d\n",i);
		i = 0;
	}
	
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>
 
using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)

int main(){
    int r , d , x; cin >> r >> d >> x;

    for(int i = 0; i < 10 ; ++i){
        x = r * x - d;
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
i,j,t[99];main(a){for(;~scanf("%d",&a);puts("")){for(i=j=1;a;i++){if(a%2)t[i]=j;a/=2;j*=2;}for(a=j=1;j<i;j++)if(t[j]){a?a=0:printf(" ");printf("%d",t[j]);t[j]=0;}}exit(0);}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
const lli INT=1e15;
const lli pINF=LLONG_MAX;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;ans%=mod;}b/=2;a*=a;a%=mod;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define PII pair<int,int>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
set<char> st;

int main()
{
    int n;
    si(n);
    string a,b;
    
    cin>>a>>b;
    lli ans=1;
    int curr=-1;
    
    for(int i=0;i<n;i++){
        if(a[i]==b[i]){
            if(curr==-1){
                ans*=3;
                ans%=mod;
            }
            else if(curr==0){
                ans*=2;
                ans%=mod;
            }
            curr=0;
        }
        else{
            if(curr==-1){
                ans*=6;
                ans%=mod;
            }
            else if(curr==0){
                ans*=2;
                ans%=mod;
            }
            else{
                ans*=3;
                ans%=mod;
            }
            curr=1;
            i++;
        }
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
    s.append(input())

m = int(input())
t = []
for i in range(m):
    t.append(input())
sset = set(s)
money = 0
for i in sset:
    money = max(money,s.count(i)-t.count(i))
print(money)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
ll pown(ll fi,ll se){
  ll ans=1;
  rep(i,se){
    ans*=fi;
  }
  return ans;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}

/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/

int main(){
  ll n;
  cin>>n;
  vec(v,n);
  rep(i,n){
    cin>>v[i];
  }
  vec(s,n);
  vec(g,n);
  s[0]=v[0];
  rep(i,n-1){
    s[i+1]=gcd(v[i+1],s[i]);
  }
  g[n-1]=v[n-1];
  rep(i,n-1){
    g[n-1-1-i]=gcd(v[n-2-i],g[n-1-i]);
  }
  ll ans=g[1];
  rep(i,n-2){
    ans=max(ans,gcd(s[i],g[2+i]));
  }
  ans=max(ans,s[n-2]);
  op(ans);
  return 0;

}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define mod 1000000007
#define t() int tst;cin>>tst;for(int test=1;test<=tst;++test)
#define rep(i,a,b) for(i=a;i<b;++i)
#define repr(i,a,b) for(i=a;i>=b;--i)
typedef pair<int,int> pii;
#define F first
#define S second
#define pb push_back
#define all(p) p.begin(), p.end()
#define MAX 10000005

int powG(int x,int y)
{

  if(y==1)return x;
  if(y==0)return 1;

  int temp=powG(x,y/2);

  temp*= temp;

  if(y&1)
    temp*=x;
  
    return temp;
}


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    //t()
    {
        int n,x;
        cin>>x>>n;
        if(n == 0)
        {
            cout << x << endl;
        }
        else 
        {
            int*a = new int[n];
            int i;
            rep(i,0,n)
                cin>>a[i];
            sort(a,a+n);
            rep(i,0,n)
            {
                if(a[i] >= x)
                    break;
            }
            int j;
            int ans = 0;
            rep(j,i,n)
            {
                if(a[j] != x+j-i)
                {
                    ans = x+j-i;
                    break;
                }
            }
            if(j==n)
            {
                ans = x + j-i;
            }

            int dif = ans-x;

            repr(j,i,0)
            {
                if(a[j] != x-i+j)
                {
                    int temp = i-j;
                    if(dif >= temp)
                    {
                        ans = x+j-i;
                    }
                    break;
                }
            }
            if(j < 0)
            {
                int temp = i-j;
                if(dif >= temp)
                {
                    ans = x + j-i;
                }
            }
            cout << ans << endl;
        }
    }
    return 0; 
} 





Measured memory_bytes: 3660
import sys
n=int(input())
s=input()
frac=[0]*(n+1)
for i in range(1,n+1):
    k=i
    frac[i]=frac[i-1]
    while k%2==0:
        k//=2
        frac[i]+=1

if "2" in s: p=2
else: p=3

ans=0
for i in range(n):
    if int(s[i])==p and frac[n-1]-frac[i]-frac[n-1-i]==0:
        ans^=1
print(ans if p==2 else ans*2)

Measured memory_bytes: 29792
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;
#define what(x) cerr << #x << " is " << x << endl;

// greatest common divisor
ll gcd(ll a, ll b) {
    if (a < b)
        return gcd(b, a);
    ll r;
    while ((r=a%b)){
        a = b;
        b = r;
    }
    return b;
}

// least common multiple
ll lcm(ll m, ll n )
{
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

int main(){
    ll N;
    cin >> N;
    vector<ll> t(N);
    for(int i = 0; i < N; ++i) {
        cin >> t[i];
    }
    ll ret = 1;
    for(int i = 0; i < N; ++i) {
        ret = lcm(ret, t[i]);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
#include <cassert>
#include <memory>
using namespace std;
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int main ()
{

    int K,A,B;
    cin >> K >> A >> B;

    for (int i = A; i <= B; i++) {
        if ((i % K) == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  string z;
  cin>>z;
  int x=z.length(),i;
  vector<int> q(26);
  for(i=0;i<x;i++) q.at(z.at(i)-'a')=1;
  for(i=0;i<26;i++){
    if(q.at(i)==0){
      cout<<(char)('a'+i)<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}

Measured memory_bytes: 3764
#include<cstdio>
#include<algorithm>
using namespace std;

int arr[100005];
int main(){
    int N, A, B;
    scanf("%d%d%d",&N,&A,&B);
    long long ans = 0;
    for(int i=0;i<N;i++){
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+N);
    for(int i=1;i<N;i++){
        ans += min(1ll*abs(arr[i]-arr[i-1])*A,1ll*B);
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main()
{
  int X;
  cin >> X;
  string ans = "NO";
  if (X == 3 || X == 7 || X == 5)
    ans = "YES";
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
def resolve():
    d = int(input())
    ci = list(map(int, input().split()))
    si = [list(map(int, input().split())) for _ in range(d)]
    answers = []
    for i in range(d):
        certain_date_s = si[i]
        answers.append(certain_date_s.index(max(certain_date_s))+1)
    [print(answer) for answer in answers]
resolve()

Measured memory_bytes: 67968
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=2e5+5,LG=19,SM=600+5,inf=1e18+1;
ll mod=1e9+7;

ll a[M],b[M];
ll n;

int main()
{
	ios::sync_with_stdio(0);
    cin >> n;    
    For(i,0,n) cin >> a[i] >> b[i];
    ll res=0,sx=0;
    Ford(i,n-1,0)
    {
        ll s=sx+a[i];
        ll dif=(s/b[i]+(s%b[i]!=0))*b[i];
        dif-=s;
        sx+=dif;
        res+=dif;
    }
    RET(res);
}    

Measured memory_bytes: 1792
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from itertools import accumulate
def resolve():
    N,=pin()
    A=lispin()
    B=lispin()
    cnt=0
    for i in range(N):
        if A[i]>B[i]:
            cnt+=B[i]
        else:
            t=B[i]-A[i]
            x=A[i+1]-t
            if x<0:
                cnt+=A[i]+A[i+1]
                A[i+1]=0
            else:
                A[i+1]=x
                cnt+=B[i]
    print(cnt)
        
    
#%%submit!
resolve()

Measured memory_bytes: 76416
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,a;
  cin >> n;
  int ans=0;
  int i=0;
  while(1){
    a=ans;
    ans=i*i;
    ans=max(ans,a);
    if(ans>n) {
      cout << a<< endl;
      break;
    }
    i++;
  }
  return 0;
}


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

if N.count("N") > 0 and N.count("W") > 0 and N.count("S") > 0 and N.count("E") > 0:
    print("Yes")
elif N.count("N") > 0 and N.count("W") == 0 and N.count("S") > 0 and N.count("E") == 0:
    print("Yes")
elif N.count("N") == 0 and N.count("W") > 0 and N.count("S") == 0 and N.count("E") > 0:
    print("Yes")
else:
    print("No")


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

int main(){
    ll N,M;
    cin >> N >> M;
    priority_queue<ll, vector<ll>, less<ll>> pq;
    for(int i=0; i<N; i++){
        ll a_i; cin >> a_i;
        pq.push(a_i);
    }
    for(int i=0; i<M; i++){
        ll top = pq.top();
        pq.pop();
        top = top/2;
        pq.push(top);
    }
    ll cost = 0;
    for(int i=0; i<N; i++){
        cost += pq.top();
        pq.pop();
    }
    cout << cost << "\n";
    return 0;
}

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

using namespace std;

#define ll long long
#define MOD 1000000007

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

    int n;
    cin>>n;

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

    vector<int> dp(n,INFINITY);
    dp[0] = 0;

    for(int i=0;i<n;i++){
        for(int j :{i+1,i+2})
            if(j<n)
                dp[j] = min(dp[j], dp[i]+abs(ar[i]-ar[j]));
    }
    cout<<dp[n-1];

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n,x,m; cin >> n >> x >> m;
    //set<int> set;

    int a=x;
    //int t=-100;
    int sum1=0,sum2=0;
    int t=0,bef=0;
    set<int> set;
    int same=-1;
    rep(i,n){
        if(set.count(a)){
            //t=i-bef;
            same=a;
            break;
        }
        bef++;
        set.insert(a);
        sum1+=a;
        a=a*a%m;
        if(a==0){
            cout<<sum1<<endl; return 0;
        }
        if(i==n-1){cout<<sum1<<endl;
         return 0;}
    }

    a=x;
    int cnt=0;
    int left=0,right=1;
    sum1=0;
    rep(i,n){
        if(cnt==0 && a!=same) sum1+=a;
        if(a==same && cnt==1){right=i; break;}
        if(cnt==1) sum2+=a;
        if(a==same && cnt==0){ cnt++; left=i; sum2+=a;}
        
        
        a=a*a%m;
        
        
    }
    
    t=right-left;
    int res=sum1+(n-left)/t*sum2;
    int rest=(n-left)%t;
    rep(i,rest){
        res+=a;
        a=a*a%m;
        
    }
    cout<<res<<endl;
    //show(t);
    //show(rest);
}
//10000000000 10 99959

Measured memory_bytes: 5920
s = gets.chomp.chars

if s.size == 1
  puts 1
  exit
end

ans_a = 0

b = ""
i = 0
while i < s.size do
  if i == s.size - 1
    if s[i] == b
    else
      ans_a += 1
    end
    break
  elsif s[i] == b
    b = s[i..(i+1)]
    i += 2
  else
    b = s[i]
    i += 1
  end
  ans_a += 1
end

puts ans_a

# ans_b = 0
# b = ""
# i = s.size - 1
# while i >= 0 do
#   if i <= 1
#     if s[i] == s[i-1]
#       ans_b += 1
#     else
#       ans_b += 2
#     end
#     break
#   elsif s[i] == b
#     b = s[(i-1)..i]
#     i -= 2
#   else
#     b = s[i]
#     i -= 1
#   end
#   ans_b += 1
# end

# puts [ans_a, ans_b].max


Measured memory_bytes: 16764
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    H, A = map(int, readline().split())

    print((H + A - 1) // A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61728
main :: IO()
main = do
  getLine
  lis <- words <$> getLine
  let numlis = map read lis
  print $ solve numlis 0


solve :: [Integer] -> Integer -> Integer
solve [] x = 0
solve (x:xs) 0
  | x > 0 = min (solve xs x) (solve xs (-1) + x + 1)
  | x < 0 = min (solve xs x) (solve xs 1 + 1 - x)
  | otherwise = min (solve xs 1) (solve xs (-1)) + 1
solve (x:xs) m
  | m > 0 = max 0 (sum+1) + solve xs (min sum (-1))
  | m < 0 = max 0 (1-sum) + solve xs (max sum 1)
  where sum = m+x


Measured memory_bytes: 54652
#include<bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define c(a,n) for(int i = 0; i < n; i++) cin >> a[i];
#define ffor(n) for(int i = 0; i < n; i++)

typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string,int> msi;
typedef map<int,int> mii;
typedef unordered_map<string,int> umsi;

 
 
int32_t main()
{
    fast_io;
    int n,m;
    cin>>n>>m;
    vii g(n+1);
    int x,y;
    vi lgp(n+1,0);
    vi ind(n+1,0);
    for(int i=0;i<m;i++){
        cin>>x>>y;
        g[x].push_back(y);
        ind[y]++;
    }
    queue<int>q;
    for(int i=1;i<=n;i++)
    if(!ind[i])q.push(i);
    while(!q.empty()){
        int t=q.front();
        q.pop();
        for(auto j:g[t])
        {
            lgp[j]=max(lgp[j],lgp[t]+1);
            ind[j]--;
            if(!ind[j])q.push(j);
        }
    }
    int ans=*max_element(lgp.begin(),lgp.end());
    cout<<ans;
    return 0;
}

Measured memory_bytes: 9384
n = int(input())
a = [int(x) for x in input().split()]
q = int(input())

num = [0] * (10**5)
for i in range(len(a)):
    num[a[i]-1] += 1

ans = sum(a)

for j in range(q):
    b, c = map(int, input().split())
    ans -= num[b-1] * b
    num[c-1] += num[b-1]
    ans += c * num[b-1]
    num[b-1] = 0
    print(ans)

Measured memory_bytes: 83788
G = ["A","B","C","D","F"]
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r ==-1:
        break
    if m == -1 or f == -1:
        print ("F")
    elif m+f>=80:
        print("A")
    elif m+f>=65:
        print("B")
    elif m+f>=50:
        print("C")
    elif m+f>=30 and r >= 50:
        print("C")
    elif m+f>=30:
        print("D")
    else:
        print("F")
    


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

int main(){
    int n; cin >> n;
    map<string,long long> mp;
    long long ans=0;
    for(int i=0;i<n;++i){
        string s; cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    for(auto itr=mp.begin();itr!=mp.end();++itr){
        ans += itr->second*(itr->second-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0 ,1, 1, 1, 0, -1, -1, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int v[N][3];
int dp[2][3];
int n;
int f(int i, int last){
    if(i == n)return 0;
    int &ans = dp[i][last];
    if(ans == -1){
        ans = 0;
        if(last == 0){
            ans = max(ans, f(i + 1, 1) + v[i][1]);
            ans = max(ans, f(i + 1, 2) + v[i][2]);
        }
        if(last == 1){
            ans = max(ans, f(i + 1, 0) + v[i][0]);
            ans = max(ans, f(i + 1, 2) + v[i][2]);
        }
        if(last == 2){
            ans = max(ans, f(i + 1, 0) + v[i][0]);
            ans = max(ans, f(i + 1, 1) + v[i][1]);
        }
        ans = max(ans, f(i + 1, last));
    }return ans;
}
int main(){
    //FL;
    FIN;
    cin >> n;
    // optimizando memoria
    for(int i = 0; i < n; i++)
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    for(int i = n; i >= 0; i--){
        for(int last = 0; last < 3; last++){
            int &ans = dp[i & 1][last];
            if(i == n){
                ans = 0;
                continue;
            }
            ans = max(ans, dp[(i + 1) & 1][last]);
            if(last == 0){
                ans = max(ans, dp[(i + 1) & 1][1] + v[i][1]);
                ans = max(ans, dp[(i + 1) & 1][2] + v[i][2]);
            }
            if(last == 1){
                ans = max(ans, dp[(i + 1) & 1][0] + v[i][0]);
                ans = max(ans, dp[(i + 1) & 1][2] + v[i][2]);
            }
            if(last == 2){
                ans = max(ans, dp[(i + 1) & 1][0] + v[i][0]);
                ans = max(ans ,dp[(i + 1) & 1][1] + v[i][1]);
            }
        }
    }
    int ans = 0;
    fore(i, 0, 3)
        ans = max(ans, dp[0 & 1][i]);
    cout << ans << '\n';
    EjecuteTime;
    return 0;
}       

Measured memory_bytes: 4788
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

		int x = Integer.parseInt(sc.next());
		int y = Integer.parseInt(sc.next());

		List<Integer> a = Arrays.asList(1, 3, 5, 7, 8, 10, 12);
		List<Integer> b = Arrays.asList(4, 6, 9, 11);
		List<Integer> c = Arrays.asList(2);

		if (a.contains(x) && a.contains(y) || b.contains(x) && b.contains(y) || c.contains(x) && c.contains(y)){
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    int n, k; cin >> n >> k;
    string s; cin >> s;

    s[k-1] -= 'A' - 'a';

    cout << s << endl;
    
    return 0;
}


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

using ll = long long;

int main() {
    int N, M;
    string S;
    vector<int> ans(0);
    cin >> N >> M >> S;
    int i = N;
    while (i > 0) {
        bool f = false;
        for (int j = M; j > 0; j--) {
            if (i - j < 0) continue;
            if (S[i - j] == '0') {
                f = true;
                ans.push_back(j);
                i -= j;
                break;
            }
        }
        if (!f) {
            cout << -1 << endl;
            return 0;
        }
    }
    int m = ans.size();
    rep(i, m) {
        cout << ans[m - 1 - i];
        if (i == m - 1) cout << endl;
        else cout << " ";
    }
}

Measured memory_bytes: 1144
#include <iostream>
#include <vector>
#include <string>
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
long long int mod(long long int x){
	return x%1000000007;
}

int main(){
	long long int m,n,tmp,j,ans;
	cin>>m>>n;
	tmp=m;
	ans=1;
	while(n!=0){
		for(j=1;j<=n/2;j*=2){
			tmp*=tmp;
			if(tmp>=10000) tmp=mod(tmp);
		}
		n=n-j;
		ans*=tmp;
		if(ans>=1000000) ans=mod(ans);
		tmp=m;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<utility>
#include<map>
#include<stdio.h>
using namespace std;
int main()
{
	
	string s;
	cin >> s;
	int z = 0, l = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s.at(i) == '0')
		{
			z++;
		}
		else
		{
			l++;
		}
	}
	int x = min(z,l);
	cout << x* 2 << endl;
}

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

pub 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: usize = read();
    let mut a: i64 = 2;
    let mut b: i64 = 1;

    for _ in 1..n {
        let tmp = b;
        b = b + a;
        a = tmp;
    }
    println!("{}", b);
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c;
	int g = 0, i = a, j = 0, k = b;
	for (int h = 1; h <= c; h++) {
		cin >> d >> e >> f;
		if (f == 1) {
			g = max(g, d);
		}
		else if (f == 2) {
			i = min(i, d);
		}
		else if (f == 3) {
			j = max(j, e);
		}
		else if (f == 4) {
			k = min(k, e);
		}
	}
	cout << max((i - g), 0) * max((k - j), 0) << "\n";
	cin >> e;
}

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

int main() {
  int a, b; cin >> a >> b;
  if (a!=1 && b!=1) cout << 1 << endl;
  if (a!=2 && b!=2) cout << 2 << endl;
  if (a!=3 && b!=3) cout << 3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
#define vcin(a)                          \
    for (int i = 0; i < (a).size(); i++) \
        cin >> (a)[i];

int main()
{
    int N,count=0;
    cin >> N;
    vchar s(N);
    
    rep(i,N)
    {
        cin >> s[i];
        if(i>=2 and s[i-2]=='A' and s[i-1] == 'B' and s[i] =='C')
            count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

count = 0
for i in range(n-1, -1, -1):
    count += min(a[i] + a[i+1], b[i])
    if b[i] > a[i+1]:
        a[i] -= min(b[i] - a[i+1], a[i])
print(count)

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

int n;

int solve();

int main() {
  cin >> n;
  cout << solve() << endl;
  return 0;
}

int solve() {
  int cnt = 0;
  while(n > 1) {
    ++cnt;
    int now = n / 3;
    if(n % 3 != 0) ++now;
    n = now;
  }
  return cnt;
}



Measured memory_bytes: 3096
def resolve():
    N = int(input())
    X = input()
    Xint = int(X,2)
    popX = X.count("1")
    if popX == 1:
        idx = X.find("1")
        for i in range(N):
            if i == idx:
                print(0)
            else: 
                if i != N-1:
                    if X[-1] == "0":
                        print(1)
                    else:
                        print(2)
                else:
                    print(2)
        return

    Xmod_plus =  Xint % (popX+1)
    Xmod_minus = Xint % (popX-1)

    pop_2expi_p = {0:1}
    pop_2expi_m = {0:1}
    for i in range(1,N):
        pop_2expi_p[i] = pop_2expi_p[i-1] * 2 % (popX+1)
        pop_2expi_m[i] = pop_2expi_m[i-1] * 2 % (popX-1)

    for i in range(N):
        count = 1
        if X[i] == "1":
            nX = (Xmod_minus - pop_2expi_m[N-1-i] ) % (popX-1) 
        if X[i] == "0":
            nX = (Xmod_plus + pop_2expi_p[N-1-i] ) % (popX+1) 
        for j in range(N):
            if nX == 0:
                break
            else:
                nX %= bin(nX).count("1")              
                count += 1
        print(count)
resolve()

Measured memory_bytes: 51660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(){
	int n,x,y;
	cin>>n;
	ll s=0;
	int a[n+1];
	for(int i=0;i<=n;i++){
		cin>>a[i];
	}//输入怪兽
	for(int i=0;i<n;i++){
		cin>>x;//这个英雄可以消灭的数量
		y=min(x,a[i]);
		s+=y;//加上可消灭的怪兽数量
		x-=y;
		y=min(x,a[i+1]);
		s+=y;
		a[i+1]-=y;
	}
	cout<<s<<"\n";
}


Measured memory_bytes: 640
import java.util.*;

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

        List<Long> que = new ArrayList<>();
        for (long i = 1; i <= 9; i++) {
            que.add(i);
        }
        int count = 1;
        int head = 0;
        while (true) {
            long val = que.get(head);
            head++;
            long modVal = val % 10;
            long timeVal = val * 10;
            if (count == K) {
                System.out.println(val);
                break;
            }
            if (modVal != 0) {
                que.add(timeVal + modVal - 1);
            }
            que.add(timeVal + modVal);
            if (modVal != 9) {
                que.add(timeVal + modVal + 1);
            }
            count++;
        }
    }
}


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

void maxHeapify(int A[], int n, int i)
{
    int l=2*i, r=2*i+1;
    int largest=i;
    if(l<=n&&A[largest]<A[l]) largest=l;
    if(r<=n&&A[largest]<A[r]) largest=r;
    if(i!=largest) {
        swap(A[i], A[largest]);
        maxHeapify(A, n, largest);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h[500001];
    int n;
    cin>>n;
    for(int i=1; i<=n; i++) cin>>h[i];
    for(int i=n/2; i>=1; i--) maxHeapify(h, n, i);
    for(int i=1; i<=n; i++) cout<<' '<<h[i];
    cout<<'\n';
    return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD 998244353ll
char S[303030];
ll N, N3, rgb[303030];
ll Fa[303030];
ll i,j,k,ans;

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}

int main(){
    scanf("%d%s",&N, S);
    N3 = N * 3;
    
    fornum(i,0,N3){
        switch(S[i]){
            case 'R':
                rgb[i] = 0;
                break;
            case 'G':
                rgb[i] = 1;
                break;
            case 'B':
                rgb[i] = 2;
                break;
        }
    }
    ll rgbn[] = {0, 0, 0};
    ll mk[] = {N, 0, 0, 0};
    ans = 1;
    fornum(i,0,N3){
        k = 0;
        fornum(j,0,3){
            if(rgbn[rgb[i]]<rgbn[j]){
                ++k;
            }
        }
        rgbn[rgb[i]]++;
        (ans *= mk[k]) %= MOD;
        --mk[k];
        ++mk[k + 1];
    }

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

    return 0;
}

Measured memory_bytes: 3200
//
//  main.cpp
//  Test
//
//  Created by Nag on 2017/08/18.
//  Copyright ?? 2017??´ Nag. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>

//A-Z = 65 - 90
//a-z = 97 - 122

using namespace std;

int main(void) {
    string str;
    
    getline(cin, str);
    
    for(char i:str) {
        if( islower(i) ) cout << (char)toupper(i);
        else if( isupper(i) ) cout << (char)tolower(i);
        else cout << i;
    }
    cout << endl;
    
    return 0;
    
}

Measured memory_bytes: 3140
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);char[][]a;for(int w,h,x,y,i,j;(w=s.nextInt()+2)>2;System.out.println(f(a,x,y))){a=new char[h=s.nextInt()+2][w];for(i=x=y=1;i<h-1;++i){j=0;for(char c:s.next().toCharArray()){a[i][++j]=c=='#'?0:c;if(a[i][j]>63){x=i;y=j;}}}}}static int f(char[][]a,int x,int y){if(a[x][y]<1)return 0;a[x][y]=0;return f(a,x-1,y)+f(a,x+1,y)+f(a,x,y-1)+f(a,x,y+1)+1;}}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

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

    ll sz = S.size();

  
      ll cc=0;
      for(ll i=0;i<sz/2;i++){
        if(S[i]!=S[sz-i-1]){
          cc++;
        }
      }

      cout<<cc<<endl;
   

}

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

int main() {
	int a, b;
	cin >> a >> b;
	string s; cin >> s;
	bool flag = true;
	for (int i = 0; i < a + b + 1; i++) {
		if (i == a) {
			if (s[a] != '-') {
				flag = false;
			}
		}
		else {
			if (!(s[i] >= '0'&&'9' >= s[i])) {
				flag = false;
			}
		}
	}
	if (flag == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

int main(int argc, char *argv[]) {
  int h, w;
  std::cin >> h >> w;
  std::vector<std::vector<char>> c(h, std::vector<char>(w));
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      std::cin >> c.at(i).at(j);

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      std::cout << c.at(i).at(j);
    }
    std::cout << std::endl;
    for (int j = 0; j < w; ++j) {
      std::cout << c.at(i).at(j);
    }
    std::cout << std::endl;
  }
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;
        
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int x = sc.nextInt();
        BigInteger aaa = BigInteger.ONE;
        long check = 1000000000000000000L;
        long[] y = new long[x];
        boolean flag = false;
        for (int i = 0; i < x; i++) {
            y[i] = Long.parseLong(sc.next());
            if (y[i] == 0) {
                flag = true;
            }
        }
        for (int i = 0; i < x; i++) {
            if (flag) {
                aaa = BigInteger.valueOf(0);
                break;
            } else if (aaa.multiply(BigInteger.valueOf(y[i])).subtract(BigInteger.valueOf(check)).signum() == 1) {
                aaa = BigInteger.valueOf(-1);
                break;
            } else {
                aaa = aaa.multiply(BigInteger.valueOf(y[i]));
            }
        }
        System.out.println(aaa);
    }
}

Measured memory_bytes: 61612
package main

import (
  "fmt"
  "sort"
)

func main() {
  x := make([]int, 3)
  fmt.Scan(&x[0], &x[1], &x[2])
  sort.Ints(x)
  if x[0] == 5 && x[1] == 5 && x[2] == 7 {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}


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

using namespace std;

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

    int n;
    cin >> n;

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

    int pr = -1, pr_cnt = 0;
    long long answer = 0;

    answer += a[0] / 2;
    a[0] &= 1;
    for (int i = 1; i < n; i++) {
        if (a[i] == 0) continue;
        if (a[i - 1]) {
            answer++;
            a[i]--;
        }
        answer += a[i] / 2;
        a[i] &= 1;
    }
    cout << answer;
    return 0;
}


Measured memory_bytes: 640
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
bool used[ohara];

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

  cin >> n >> k >> a >> b >> c >> s;
  rep(i, n) {
    if (i < k) {
      if (s[i] == 'r')
        ans += c;
      else if (s[i] == 's')
        ans += a;
      else
        ans += b;
      used[i] = true;
    } else {
      if (used[i - k] && s[i] == s[i - k]) continue;
      if (s[i] == 'r')
        ans += c;
      else if (s[i] == 's')
        ans += a;
      else
        ans += b;
      used[i] = true;
    }
    // cout << i << " " << ans << "\n";
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <map>

using namespace std;

#define MAX 252

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

    int heap[MAX];

    int H;scanf("%d",&H);
    for(int i=1;i<=H;i++){
        scanf("%d",&heap[i]);
    }

    for(int i=1;i<=H;i++){
        printf("node %d: ",i);
        printf("key = %d, ",heap[i]);
        if(i!=1){
            printf("parent key = %d, ",heap[i/2]);
        }
        if(i*2<=H){
            printf("left key = %d, ",heap[i*2]);
        }
        if(i*2+1<=H){
            printf("right key = %d, ",heap[i*2+1]);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 3224
//	?????????????????????
#include <stdio.h>
#include <string.h>

#define DEF_ELEM_MAX 100000

typedef long long llong;

typedef struct _CARD {
	char mark;
	int  value;
} CARD;

CARD A[DEF_ELEM_MAX];
CARD O[DEF_ELEM_MAX];
int N;

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
void swap(CARD *x, CARD *y)
{
	CARD tmp = *x;
	*x = *y;
	*y = tmp;
	return;
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int partition(CARD *A, int p, int r)
{
	int j;
	int x = A[r].value;
	int i = p-1;

	for ( j = p ; j < r ; j++ ) {
		if ( A[j].value <= x ) {
			i++;
			swap(&A[i], &A[j]);
		}
	}
	swap(&A[i+1], &A[r]);
	return i+1;
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
void quickSort(CARD *A, int p, int r)
{
	int q;
	if ( p < r ) {
		q = partition(A, p, r);
		quickSort(A, p, q-1);
		quickSort(A, q+1, r);
	}
}

////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int checkArray(CARD *in_A, CARD out_A, int c)
{
	int j;
	int d = 0;
	for (j = 0; j < N; j++) {
		if (in_A[j].value == out_A.value) {
			if (c == d) {
				if (in_A[j].mark != out_A.mark) {
					return 0;
				}
				break;
			}
			d++;
		}
	}
	return 1;
}

////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int isStable(CARD *in_A, CARD *out_A)
{
	int i, j, a, b;
	int c;
	for ( i = 0 ; i < N ; i++ ) {
		if ( i == 0 ) {
			c = 0;
		} else if ( out_A[i].value == out_A[i-1].value ) {
			c++;
		} else {
			c = 0;
		}
		if ( checkArray( in_A, out_A[i], c ) == 0 ) {
			return 0;
		}
	}
	return 1;
}
////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
void printStable(CARD *in_A, CARD *out_A, int N)
{
	int flag = 0;

	flag = isStable( in_A, out_A);

	printf("%s\n", ((flag == 1) ? "Stable" : "Not stable"));
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int main(void)
{
	int i;
//
	scanf("%d", &N);
	for ( i = 0 ; i < N ; i++ ) {
		scanf(" %c %d", &A[i].mark, &A[i].value );
		O[i] = A[i];
	}

	quickSort(A, 0, N-1);

	printStable(O, A, N);

	for ( i = 0 ; i < N ; i++ ) {
		printf("%c %d\n", A[i].mark, A[i].value);
	}

	return 0;
}

Measured memory_bytes: 2168
let getv (x0,y0) (x1,y1) = (x1-.x0, y1-.y0);;
let cross (x0,y0) (x1,y1) = x0*.y1-.x1*.y0;;

let () =
  let rec read () =
    try let p0,p1,p2,p3 = Scanf.scanf " %f,%f,%f,%f,%f,%f,%f,%f\n" (fun xa ya xb yb xc yc xd yd-> (xa, ya),(xb, yb),(xc, yc),(xd, yd)) in
        if (cross (getv p0 p2) (getv p0 p1))*.(cross (getv p0 p2) (getv p0 p3)) < 0.
           && (cross (getv p1 p3) (getv p1 p2))*.(cross (getv p1 p3) (getv p1 p0)) < 0. then print_endline "YES"
        else print_endline "NO"
        ; read ()
    with End_of_file -> ()
  in read ()
;;

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

#define ll long long

signed main()
{
  int n,m; cin >> n >> m;
  int ans = 0;
  //ans = (n+1)*(m+1) -(n+m)*2;
  ans = n*m-n-m+1;
  cout << ans << "\n";
}

Measured memory_bytes: 3580