akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<limits.h>
#define MOD 1000000007
#define PI 3.14159265
#define seive_len 1000001
#define p_seive_len 1000001

typedef long long int lli;

int *array;
int seive[seive_len];
int pseive[p_seive_len];

long long int min(long long int a, long long int b) {
    return a<b?a:b;
}

long long int max(long long int a, long long int b) {
    return a>b?a:b;
}

int compare(const void* a, const void* b) {
    return *(int*)a-*(int*)b;
}

int cmp(const void *a, const void *b){
    int ia = *(int *)a;
    int ib = *(int *)b;
    return array[ia] < array[ib] ? -1 : array[ia] > array[ib];
}

long double abs1(long double n) {
    if(n < 0)
        return n*(-1.0);
    return n*1.0;
}

void swap(int *a, int *b) {
    *a = (*a)^(*b);
    *b = (*a)^(*b);
    *a = (*a)^(*b);
}

lli binSearch(lli a[], lli x, lli l, lli r) {
    if(r >= l) {
        lli mid = l + ((r-l)>>1);
        if(a[mid] == x)
            return mid;
        if(a[mid] > x) {
            return binSearch(a, x, l, mid-1);
        }
        else if(a[mid] < x) {
            return binSearch(a, x, mid+1, r);
        }
    }
    return -1;
}

void Primesieve()  { 
    lli i, j;
    pseive[1] = 1;
    printf("bhjnm");
    for(i=0;i<p_seive_len;i++)
        pseive[i] = i;
    for(i=4;i<p_seive_len;i+=2) 
        pseive[i] = 2;
    for(i=3;i*i<p_seive_len;i++) {
        if(pseive[i] == i) {
            for(j=i*i;j<p_seive_len;j+=i) {
                if(pseive[j] == j)
                    pseive[j] = i;
            }
        }
    }
} 

void makeSeive() {
    int i;
	seive[1] = 1;
    for(i=2;i<seive_len;i++) {
        if(seive[i] == 0) {
            long long int temp=(long long int)i*i;
            while(temp <= seive_len-1) {
                seive[temp] = 1;
                temp += i;
            }
        }
    }
}

int isPerfectSquare(lli n) {
    lli x = sqrt(n);
    if(x*x == n)
        return 1;
    return 0;
}

int isPrime(int n) {
    int i;
    for(i=2;i*i<=n;i++)  {
        if(n%i == 0)
            return 0;
    }
    return 1;
}

void getInput(lli a[], lli n) {
    for(lli i=0;i<n;i++)
        scanf("%lld", &a[i]);
}

void testCase() {
    lli i, n;
    scanf("%lld", &n);
    lli a[n];
    getInput(a, n);
    lli p = a[0], res = 0;
    for(i=1;i<n;i++) {
        if(a[i] < p)
            res += (p-a[i]);
        else
            p = a[i];
    }
    printf("%lld", res);
}

int main() {
    int t=1;
    // scanf("%d", &t);
    // makeSeive();
    // Primesieve();
    while(t--) {
        testCase();
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3692
#include <iostream>

using namespace std;

int main()
{
	int mount_high_inputs[10];
	int idx;

	for (int i = 0; i < 10; i++){
		cin >> mount_high_inputs[i];
		/* ?????????????????? */
		for (int j = i; j > 0; j--){
			if (mount_high_inputs[j-1] < mount_high_inputs[j]){
				int tmp = mount_high_inputs[j-1];
				mount_high_inputs[j-1] = mount_high_inputs[j];
				mount_high_inputs[j] = tmp;
			}
			else{
				break;
			}
		}

	}

	for (int i = 0; i < 3; i++){
		cout << mount_high_inputs[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>
#include <bitset>
#include <queue>

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

int main() {
    int x;
    cin >> x;
    if (x == 1)cout << 0 << endl;
    else cout << 1 << endl;
   
    return 0;
}

Measured memory_bytes: 3160
#include<algorithm>
#include<iostream>
#include<cstring>
#include<climits>
#include<cstdlib>
#include<utility>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#define ri register int
#define pi acos(-1.0)

using namespace std;

inline char gch()
{
    static char buf[100010], *h = buf, *t = buf;
    return h == t && (t = (h = buf) + fread(buf, 1, 100000, stdin), h == t) ? EOF : *h ++;
}

typedef long long lo;

inline void re(int &x)
{
    x = 0;
    char a; bool b = 0;
    while(!isdigit(a = getchar()))
        b = a == '-';
    while(isdigit(a))
        x = x * 10 + a - '0', a = getchar();
    if(b == 1)
        x = - x;
}

inline void re(lo &x)
{
    x = 0;
    char a; bool b = 0;
    while(!isdigit(a = getchar()))
        b = a == '-';
    while(isdigit(a))
        x = x * 10 + a - '0', a = getchar();
    if(b == 1)
        x = - x;
}

int n, m, h, t, ans, q[200020], ta, lx, ly;

struct in
{
	int l, r;
	inline bool operator < (const in &a) const
	{
		return l != a.l ? l < a.l : r > a.r;
	}
}ter[200020];

priority_queue <int, vector <int>, greater <int> > qwq;

int main()
{
	re(n); re(m); h = 1, t = m;
	for(ri i = 1; i <= n; i ++)
		re(lx), re(ly), ter[i] = (in){lx, ly};
	sort(ter + 1, ter + 1 + n);
	for(ri i = 1; i <= n; i ++)
	{
		qwq.push(ter[i].r);
		if(h <= t && h <= ter[i].l)
			h ++;
		else
			q[++ ta] = qwq.top(), qwq.pop();
	}
	sort(q + 1, q + 1 + ta);
	for(ri i = ta; i >= 1; i --)
	{
		if(h <= t && q[i] <= t)
			t --;
		else
			ans ++;
	}
	printf("%d", ans);
}

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

int main(){
	int n, v[50], c[50], res = 0;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> v[i];
	for(int i = 0; i < n; i++) cin >> c[i];
	
	for(int i = 0; i < n; i++){
		if(v[i] > c[i]){
			res += v[i] - c[i];
		}
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();

        final int MAX = 1000000;
        final int MIN = -1000000;

        int max = Math.min(MAX, x + k -1);
        int min = Math.max(MIN, x - k + 1);

        StringBuilder sb = new StringBuilder();
        final String BLANK = " ";
        for(int i = min; i <= max; i++) {
        	sb.append(i);
        	if(i != max) {
        		sb.append(BLANK);
        	}
        }
        System.out.println(sb.toString());
	}
}

Measured memory_bytes: 21844
h, w = map(int, input().split())
a = []
for i in range(h):
  b = list(map(int, input().split()))
  a.append(b)

ans = []
for i in range(h-1):
  for j in range(w):
    if a[i][j]%2 == 1:
      a[i+1][j] += 1
      x = i+1
      y = j+1
      ans.append([x,y,x+1,y])

for i in range(w-1):
  if a[h-1][i] %2 == 1:
    a[h-1][i+1] += 1
    x = h
    y = i+1
    ans.append([x,y,x,y+1])
print (len(ans))
for i in ans:
  print (*i)

Measured memory_bytes: 30300
#include <bits/stdc++.h>
using namespace std;
bool test(string s1, string s2)
{
	string temp1 = s1, temp2 = s2;
	reverse(s1.begin(),s1.end());
	reverse(s2.begin(),s2.end());
	if(temp1 == s1 && temp2 == s2)
		return true;
	return false;
}

int main()
{	
	string s; cin >> s;
	string a = s;
	reverse(a.begin(),a.end()) ;
	int len = s.length() -1;
	string s1 , s2;
	s1 = s.substr(0,len/2);
	s2 = s.substr(len/2+1,len/2);
	if(a == s && test(s1,s2) )
		cout <<"Yes";
	else
		cout <<"No" ;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
  #pragma GCC target("avx,avx2,fma")
  #include <bits/stdc++.h>
  using namespace std;
  //---------------------------------//
  void __print(int x) {cerr << x;}
  void __print(long x) {cerr << x;}
  void __print(long long x) {cerr << x;}
  void __print(unsigned x) {cerr << x;}
  void __print(unsigned long x) {cerr << x;}
  void __print(unsigned long long x) {cerr << x;}
  void __print(float x) {cerr << x;}
  void __print(double x) {cerr << x;}
  void __print(long double x) {cerr << x;}
  void __print(char x) {cerr << '\'' << x << '\'';}
  void __print(const char *x) {cerr << '\"' << x << '\"';}
  void __print(const string &x) {cerr << '\"' << x << '\"';}
  void __print(bool x) {cerr << (x ? "true" : "false");}

  template<typename T, typename V>
  void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  template<typename T>
  void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  void _print() {cerr << "]\n";}
  template <typename T, typename... V>
  void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  #ifndef ONLINE_JUDGE
  #define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
  #else
  #define deb(x...)
  #endif
 //------------------------------//

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  all(x)       (x).begin(), (x).end()
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
    int n,m;
    cin >> n >> m;
    vi v[m];
    vi par(m);
    for(int i=0;i<m;i++){
        int k;cin >> k;
        for(int j=0;j<k;j++){
          int a;
          cin >> a;
          v[i].pb(a);
        }
     }
     for(int i=0;i<m;i++)cin >> par[i];

     int ans=0;
     for(int mask=0;mask<(1<<n);mask++){
       bool anybulbisoff=false;
        for(int j=0;j<m;j++){
           int cnt=0;
           for(int k=0;k<v[j].size();k++){
              cnt += ((mask&(1<<(v[j][k]-1)))>0);
           }
           if(cnt%2 != par[j]){
              anybulbisoff=true;
              break;
           }
        }
        if(!anybulbisoff){
           ans++;
        }
     }
     cout << ans;
  }  

  int main(){
    IOS
    	solve();
    //cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow

Measured memory_bytes: 3644
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; cin>>n;
	if(n%10==9||n/10==9) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int N, K;
	scanf ("%d %d", &N, &K);

	long long a = 0;
	for (int k = K; k <= N+1; k++){
		a = (a + 1ll * k * (N - k + 1) + 1) % 1000000007;
	}
	printf ("%lld\n", a);

	return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

ll gcd(ll a, ll b) {
return b ? gcd(b, a%b) : a;
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(void) {
   ll a,b;
   cin >> a >> b;
   ll cDiv = gcd(a,b);
   ll ans = prime_factor(cDiv).size()+1;//例えば[2,2,2,5]となったとき2,5、4,5、８,5とかいいけど、2,4とか10,5はだめ+1は1を入れたもの、1はすべてに対しておｋだから

   fin(ans);

     

}

Measured memory_bytes: 256
# Problem C - Traveling Salesman around Lake

# input
K, N = map(int, input().split())
A_list = list(map(int, input().split()))
list_len = len(A_list)

# initialization
min_ans = 10**18

# search
for i in range(list_len):
    mae_i = 0
    if i==list_len-1:
        mae_i = 0
    else:
        mae_i = i + 1

    kyori = 0
    if A_list[mae_i]-A_list[i]<0:
        kyori = K - (A_list[mae_i] - A_list[i] + K)
    else:
        kyori = K - (A_list[mae_i] - A_list[i])
    min_ans = min(min_ans, kyori)

# output
print(min_ans)


Measured memory_bytes: 77388
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;


int main() {
	char S[11];
	scanf("%s", S);

	S[3] = '8';
	PRINTS(S);
}

Measured memory_bytes: 128
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

ll getSumDigit(ll N){
    string s=to_string(N);
    ll ret=0;
    for(int i=0;i<s.size();i++)ret+=(s[i]-'0');
    return ret;
}

int main(){
    init();

    ll N;cin>>N;
    if(N%getSumDigit(N)==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){
    int N; cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    deque<int> L;
    for(int i = 0; i < N; i++){
        if(N % 2 == 0){
            if(i % 2 == 0) L.push_back(A[i]);
            else L.push_front(A[i]);
        }else{
            if(i % 2 == 0) L.push_front(A[i]);
            else L.push_back(A[i]);
        }
    }
    for(auto itr = L.begin(); itr != L.end(); itr++){
        if(itr != L.begin()) cout << " ";
        cout << *itr;
    }
    cout <<endl;
}

Measured memory_bytes: 3840
#include <stdio.h>

int main(void){
  int i,x,y,x1,y1;
  for(i=1;i<=3000;i++){
      scanf("%d %d",&x,&y);
      x1=x;
      y1=y;
        if(x==0 && y==0){
            i=3000;
        }else{
            if(y1<x1){
                x=y1;
                y=x1;
            }
            printf("%d %d\n",x,y);
        }
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
const int mod = 1e9+7;
//26

int n, k, q, ans = INF;
vector<int> a;

vector<int> solve(int l, int r){
	vector<int> vec, vec2;
	repi(i,l+1,r)vec.pb(a[i]);
	sort(all(vec));
	rep(i,r-l-k)vec2.pb(vec[i]);
	return vec2;
}

signed main(){
	scanf("%lld%lld%lld", &n, &k, &q);
	a.pb(-1);
	rep(i,n){
		int x;
		scanf("%lld", &x);
		a.pb(x);
	}
	a.pb(-1);
	
	rrep(i,n){
		int m = a[i], l = 0, r = 0;
		vi vec;
		rep(j,n+2)if(a[j] < m){
			r = j;vi v;
			if(r-l-1 >= k)v = solve(l, r);
			vec.insert(vec.end(), all(v));
			l = j;
		}
		sort(all(vec));
		if(vec.size() >= q)chmin(ans, vec[q-1]-m);
	}
	printf("%lld\n", ans);
	return 0;
}




Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int md = 1e9+7;
int sz;
long long t = 1, ans;
string s;
long long exp(long long b, int n){
    long long res = 1;
    for(; n; n/=2){
        if(n&1) (res *= b) %= md;
        (b *= b) %= md;
    }
    return res;
}
int main(){
    cin >> s; sz = (int)s.size();
    for(int i = 0; i < sz; i++){
        if(s[i] == '1'){
            (ans += t * exp(3,sz-i-1)) %= md;
            (t *= 2) %= md;
        }
    }
    printf("%lld\n", (ans+t)%md);
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
//#include <cmath>
//#include <cstdlib>
using namespace std;

int main(){
	/*input*/
	int n;
	cin >> n;
	vector<string> w(n);
	for(int i =0 ; i < n; i++){
		cin >> w[i];
	}
	/*文字探索
	 * 同じ文字列があった場合*/
	for(int i = 0; i < n-1; i++){
		for(int j = i+1; j < n; j++){
			if(w[i] == w[j]){
				cout << "No";
				return 0;
			}
		}
	}
	/*しりとりになっていない場合*/
	for(int i = 0; i < n-1; i++){
	char end = w[i].back();
	char begin = w[i+1].front();
		if(end != begin){
			cout << "No";
			return 0;
		}
	}
	cout<< "Yes" <<endl;
    return 0;
}


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

typedef int integer;

#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define pb push_back
#define bs binary_search
#define up upper_bound
#define lw lower_bound
#define fs first 
#define sd second 
#define mp make_pair    

#define fore(i,a,b) for(ll i = a; i < b; i++)
#define rfore(i, a, b) for(ll i = a - 1; i >= b; i--)
#define forev(a,b) fore(i,0,b)cout<<a[i]<<" "; 
#define mm(a,b) memset(a , b , sizeof a) 
#define ALL(a) a.begin(),a.end() 
#define SZ(n) ((ll) (n).size())

#define infi  2e9
#define int long long
#define endl '\n'
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll INF = 1e10;
const ld EPS = 1e-8;

typedef pair<ll,ll> pll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

const int MAXN = 200000;
const int K=20;

int n; int a[MAXN],b[MAXN],c[MAXN];
int dp[MAXN][3];

int solve(int day, int lastact){
	if(day>n-1)return 0;
	int &r=dp[day][lastact];
	if(r!=-1)return r;
	r = 0;
	if(lastact==0)r=max(b[day]+solve(day+1,1),c[day]+solve(day+1,2));
	if(lastact==1)r=max(a[day]+solve(day+1,0),c[day]+solve(day+1,2));
	if(lastact==2)r=max(b[day]+solve(day+1,1),a[day]+solve(day+1,0));
	return r;
}

integer main(){
	cin>>n;
	fore(i,0,n)cin>>a[i]>>b[i]>>c[i];
	a[n]=INF;b[n]=INF;c[n]=INF;
	int res=0; mm(dp,-1);
	fore(i,0,3){
		res=max(res,solve(0,i));
	}
	cout<<res;
    return 0;
}



Measured memory_bytes: 13568
if __name__ == "__main__":
    while True:
        n,r=list(map(int,input().strip().split()))
        if n == 0 and r ==0 :break
        cards = [i for i in range(1,n + 1)]
        pset = []
        cset = []
        for j in range(r):
            p,c = list(map(int,input().strip().split()))
            pset = cards[n-(p - 1):]
            cset = cards[n-c-(p-1):n-(p-1)]
            other = cards[:n-c-(p-1)]
            cards = other + pset + cset
        print(cards[n-1])

Measured memory_bytes: 7736
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int>a(n),b(n),c(n-1);
  rep(i,n){cin>>a[i];a[i]--;}
  rep(i,n)cin>>b[i];
  rep(i,n-1)cin>>c[i];
  int res=0;
  rep(i,n-1)
  {
    res+=b[a[i]];
    if(a[i+1]-a[i]==1)res+=c[a[i]];
  }
  res+=b[a[n-1]];
  cout<<res<<endl;
  return 0;

}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
string S;
int K;
int dp[310][310][310] = {{{0}}};
int main(){
	cin >> S >> K;
	int N = S.size();
	for(int i=0;i<N;i++){
		for(int j=0;j<=K;j++){
			dp[i][1][j] = 1;
		}
	}
	for(int j=2;j<=N;j++){
		for(int i=0;i<=N-j;i++){
			for(int x=0;x<=K;x++){
				if(S[i]==S[i+j-1]) dp[i][j][x] = max(dp[i][j][x],dp[i+1][j-2][x]+2);
				else{
					dp[i][j][x+1] = max(dp[i][j][x+1],dp[i+1][j-2][x]+2);
					dp[i][j][x] = max(dp[i][j][x],max(dp[i][j-1][x],dp[i+1][j-1][x]));
				}
			}
		}
	}
	cout << dp[0][N][K] << endl;
}

Measured memory_bytes: 112768
def main():
    import numpy as np
    import sys
    input=sys.stdin.readline
    
    n,w=map(int,input().split())
    items=np.array([list(map(int,input().split())) for _ in range(n)])

    dp=np.zeros([n+1,w+1],dtype=np.int64)
    for i in range(n):
        wi=items[i][0]
        vi=items[i][1]
        dp[i+1][:wi]=dp[i][:wi]
        dp[i+1][wi:]=np.maximum(dp[i][wi:],dp[i][:-wi]+vi)
        
    print(dp[-1][-1])
 
if __name__=='__main__':
    main()

Measured memory_bytes: 92088
#include <iostream>
#include <algorithm>

using namespace std;

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

    int ans = sum;
    int s = 0;

    for (int i = 0; i < n; i++) {
        s += arr[i];
        ans = min(ans, abs(s - (sum - s)));
    }

    cout << ans;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int length = arr.length;
        ArrayList<ArrayList<Boolean>> list = new ArrayList<>();
        int idx = 0;
        while (idx < length) {
            ArrayList<Boolean> each = new ArrayList<>();
            while (idx < length) {
                if (arr[idx] == 'A') {
                    each.add(true);
                    idx++;
                } else if (arr[idx] == 'B' && idx < length - 1 && arr[idx + 1] == 'C') {
                    each.add(false);
                    idx += 2;
                } else {
                    idx++;
                    break;
                }
            }
            if (each.size() > 0) {
                list.add(each);
            }
        }
        long total = 0;
        for (ArrayList<Boolean> each : list) {
            int aSum = 0;
            long count = 0;
            for (boolean b : each) {
                if (b) {
                    aSum++;
                } else {
                    count += aSum;
                }
            }
            total += count;
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 48768
import numpy as np
import sys
input = sys.stdin.readline # for speed up

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

c=[0]*n

c[1]=c[0]+abs(h[1]-h[0])
for ii in range(2,n):
  c[ii]=min(c[ii-1]+abs(h[ii]-h[ii-1]),c[ii-2]+abs(h[ii]-h[ii-2]))

print(c[n-1])

Measured memory_bytes: 37968
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    for i in range(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                peaks.append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            elif ices[i] > ices[i+1]:
                peaks.append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        elif i == N-1:
            peaks.append(upPeak)
            peaks.append(downPeak)
    print(max(peaks))

N,L = map(int,input().strip().split())
ices = []
while True:
    ice = int(input().strip())
    ices.append(ice)
    if len(ices) == N:
        break

orderN(N,L,ices)

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

int main() {

    int A, B, C;
    cin >> A >> B >> C;

    int K;
    cin >> K;

    while(K > 0) {
        if(A >= B) {
            B *= 2;
        }
        else if(B >= C) {
            C *= 2;
        }
        else {
            break;
        }
        // cout << A << " " << B << " " << C << " " << endl;
        K--;
    }

    if (A < B && B < C) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22)
    {
        cout<<"bust";
    }
    else cout<<"win";
}


Measured memory_bytes: 892
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[] c = S.toCharArray();
        boolean ans1 = false;
        boolean ans2 = false;
        boolean ans3 = true;
        for (int i = 0; i < S.length(); i++) {
            if (i == 0 && c[i] == 'A') {
                ans1 = true;
                continue;
            }
            if (i >= 2 && ans2 == false && i <= S.length() - 2 && c[i] == 'C') {
                ans2 = true;
                continue;
            }
            if (Character.isUpperCase(c[i])) {
                ans3 = false;
            }
        }
        if (ans1 && ans2 && ans3) {
            System.out.println("AC");
        } else {
            System.out.println("WA");
        }

    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int Nmax = 1e5;
int N;
long T, A[Nmax];
long maxA[Nmax];

int main(){
	cin >> N >> T;

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

	maxA[N-1] = A[N-1];
	for(int i=N-2; i>=0; i--){
		maxA[i] = max(maxA[i+1], A[i]);
	}

	long interest = 0;
	for(int i=0; i<N; i++){
		interest = max(interest, maxA[i]-A[i]);
	}

	int ans = 0;
	for(int i=0; i<N; i++){
		if(interest == maxA[i]-A[i]) ans++;
	}

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


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
const ll MOD2 = 998244353;
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; }

//互除法
ll GCD(ll a, ll b){
  return b ? GCD(b,a%b) : a;
}

ll LCM(ll a, ll b){
  return (a / GCD(a,b))*b;
}

ll power(ll x, ll y){//繰り返し2乗法
  if(y < 0){
    return 0;
  }else if(y == 0){
    return 1LL;
  }else if(y%2 == 0){//偶数
    return power(x,y/2)*power(x,y/2);
  }else{//奇数
    return power(x,y-1)*x;
  }
}

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll A, B; cin >> A >> B;
  
  //main
  cout << LCM(A,B) << endl;
  
  // output
  
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input());
a = list(map(int, input().split(' ')));
alice = [];
bob   = [];

for x in range(n):
    m = max(a);
    i = a.index(m);
    if ( x%2 == 0):
        alice.append( a.pop(i) );
    else:
        bob.append( a.pop(i) );

print(sum(alice) - sum(bob));

Measured memory_bytes: 3060
import sys

input = sys.stdin.readline

w, h, x, y = map(int, input().split())

if w % 2 == 0 and h % 2 == 0 and w // 2 == x and h // 2 == y:
    print(str(w * h / 2) + " " + "1")
else:
    print(str(w * h / 2) + " " + "0")


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

long N, A, B;

bool can_kill_all(long *h, long n){
    long sum = 0;
    for(int i = 0; i < N; i++){
        if(n*B < h[i]){
            sum += (h[i]-n*B)/(A-B);
            if((h[i]-n*B)%(A-B) != 0) sum+= 1;
        }
    }
    if(sum > n) return false;
    else return true;
}

int main(){
    cin >> N >> A >> B;
    long h[100000];
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }
    long l = 0, r = 10e+9;
    long c = (l+r)/2;
    while(r-l > 1){
        if(can_kill_all(h, c)) r = c;
        else l = c;
        c = (l+r)/2;
    }
    cout << r << endl;
}

Measured memory_bytes: 1024
use std::cmp::min;
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse().unwrap());
    let h: usize = itr.next().unwrap();
    let w: usize = itr.next().unwrap();
    let k: usize = itr.next().unwrap();

    let mut v = vec![Vec::new(); h];
    for i in 0..h {
        let mut s = String::new();
        stdin().read_line(&mut s).ok();
        let itr = s.trim().chars().map(|e| e.to_digit(10).unwrap() as usize);
        v[i] = itr.collect();
    }

    let mut counts: [[usize; 1005]; 10];
    let groups: usize = 1 << h - 1;
    let mut ans = usize::max_value();
    'outer: for div in 0..groups {
        counts = [[0; 1005]; 10];
        let mut g: usize = 0;
        let mut id = [0usize; 10];
        for i in 0..h {
            id[i] = g;
            if div >> i & 1 > 0 {
                g += 1;
            }
        }
        g += 1;

        for i in 0..h {
            for j in 0..w {
                counts[id[i]][j] += v[i][j];
            }
        }

        for i in 0..g {
            for j in 0..w {
                if counts[i][j] > k {
                    continue 'outer;
                }
            }
        }

        let mut num = g - 1;
        let mut now = [0; 10];
        let mut step = |col: usize| -> bool {
            for i in 0..g {
                now[i] += counts[i][col];
                if now[i] > k {
                    now = [0; 10];
                    for i in 0..g {
                        now[i] += counts[i][col];
                    }

                    return true;
                }
            }

            false
        };

        for i in 0..w {
            if step(i) {
                num += 1;
            }
        }

        ans = min(ans, num);
    }

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


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

const int MAX = 1e5;

class UnionFind {
public:
  long long score;

  UnionFind(int n) {
    for (int i = 0; i < n; i++) {
      data[i] = i;
      size[i] = 1;
    }

    score = (long long)n * (n - 1) / 2;
  }

  // O(log N)
  int root(int x) {
    int rx = data[x];
    while(rx != data[rx]) {
      rx = data[rx];
    }
    return rx;
  }

  // O(log N)
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    if (size[rx] < size[ry]) swap(rx, ry);
    data[ry] = rx;
    score -= size[rx] * size[ry];
    size[rx] += size[ry];
    size[ry] = 0;
  }

private:
  int data[MAX];
  int size[MAX];
};

int main() {
  int N, M; cin >> N >> M;
  int A[MAX], B[MAX];
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }

  long long res[MAX];
  UnionFind uf(N);

  // O(MlogN)
  // Calculate in inverse order
  for (int i = M - 1; i >= 0; i--) {    
    res[i] = uf.score; // The score is when the bridge is collapsed, ie before unite
    uf.unite(A[i], B[i]);
  }

  for (int i = 0; i < M; i++) {
    cout << res[i] << endl;
  }
}

Measured memory_bytes: 5908
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
#include<bitset>

using namespace std;

long long mx(long long a , long long b){
  if(a>=b) return a;
  else return b;
}
long long mn(long long a , long long b){
  if(a>=b) return b;
  else return a;
}

int main(){
long long a,b,k; cin>>a>>b>>k;

cout<<mx(0,a-k)<< " "<< mx(mn(b,b-(k-a)),0);

}


Measured memory_bytes: 256
N = int(input())
first = input()
told = set((first,)) 
win = True
for _ in range(N-1):
    second = input()
    if (not second in told) and (first[-1] == second[0]):
        told.add(second)
        first = second
    else:
        win = False
print('Yes' if win else 'No')

Measured memory_bytes: 3060
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int n,a[20000],cnt;
vi v;

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

   cin >> n;
   for(int i=1;i<=n;i++){
      cin >> a[i];
   }
   for(int i=2;i<n;i++){
      v.pb(a[i-1]);
      v.pb(a[i]);
      v.pb(a[i+1]);
      sort(all(v));
      if(v[1]==a[i])cnt++;
      v.clear();
   }
   cout << cnt << endl;

return 0;
}
///....


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define x first
#define y second
#define inf 1000000000000000000
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

vector<vector<int>> mp;
struct cmp{
    bool operator()(const pair<int,int> &p1, const pair<int,int> &p2)const{
        if(mp[p1.first][p1.second]!=mp[p2.first][p2.second]){return mp[p1.first][p1.second]<mp[p2.first][p2.second];}
        else{
            return p1<p2;
        }
    }
};
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//edge cases when n=1,m=1.wrong variable in loop.if<->while;merge resize;LLONG_MAX
signed main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
    speed
    //global var
    int m,n;cin>>n>>m;
    mp.resize(n,vector<int>(m,0));
    vector<string> inp(n);
    int r,c;cin>>r>>c;--r;--c;
    int dr,dc;cin>>dr>>dc;--dr;--dc;
    for(int i=0;i<n;++i){
        cin>>inp[i];
    }
    
    vector<vector<bool>> vis(n,vector<bool>(m,false));
    mp[r][c]=0;
    
    set<pair<int,int>,cmp> st;
    st.insert({r,c});
    //cout<<"done";return 0;
    while(!st.empty()){

        pair<int,int> curr=*st.begin();
        st.erase(st.begin());
        if(curr==make_pair(dr,dc)){cout<<mp[dr][dc];return 0;}
        vis[curr.first][curr.second]=true;

        
        for(int _=0;_<4;++_){
            int nx=curr.first+dx[_];
            int ny=curr.second+dy[_];
            if (nx>=0 and ny>=0 and nx<n and ny<m and inp[nx][ny]!='#' and !vis[nx][ny]) {
                
                if(st.find({nx,ny})!=st.end()){
                    
                    if(mp[nx][ny]<=mp[curr.first][curr.second]){continue;}
                    st.erase({nx,ny});
                }
                mp[nx][ny]=mp[curr.first][curr.second];
                st.insert({nx,ny});
            }
        }
        for(int a=-2;a<3;++a){
            for(int b=-2;b<3;++b){
                int nx=curr.first+a;
                int ny=curr.second+b;
                if (nx>=0 and ny>=0 and nx<n and ny<m and inp[nx][ny]!='#' and !vis[nx][ny]) {
                    if(st.find({nx,ny})!=st.end()){
                        if(mp[nx][ny]<=mp[curr.first][curr.second]+1){continue;}
                        st.erase({nx,ny});
                    }
                    mp[nx][ny]=mp[curr.first][curr.second]+1;
                    st.insert({nx,ny});
                }
            }
        }
    }
    cout<<-1;
}
//try thinking from a different angle after spending some time


Measured memory_bytes: 9016
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
 
int n;
int a[N];
int t[N * 4];
int ans;

void Update(int tl, int tr, int v, int pos, int val)
{
	if(tl == tr)
	{
		t[v] = val;
		return;
	}
	int tm = (tl + tr) / 2;
	if(pos <= tm) Update(tl, tm, v + v, pos, val);
	else Update(tm + 1, tr, v + v + 1, pos, val);
	t[v] = t[v + v] + t[v + v + 1];
}

int Get(int tl, int tr, int v, int l, int r)
{
	if(l > tr || tl > r) return 0;
	if(l <= tl && tr <= r) return t[v];
	int tm = (tl + tr) / 2;
	return Get(tl, tm, v + v, l, r) + Get(tm + 1, tr, v + v + 1, l, r);
}

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++)
    {
    	Update(1, n, 1, a[i], 1);
    	if(Get(1, n, 1, 1, a[i] - 1) == 0) ans++;
    }
    cout << ans;
}                                

Measured memory_bytes: 3072
#include <iostream>

int main() {
    int R, G, B, N;
    std::cin >> R >> G >> B >> N;
    int ans = 0;
    for (int r = 0; R * r <= N; ++r) {
        for (int g = 0; R * r + G * g <= N; ++g) {
            if ((N - R * r - G * g) % B == 0) {
                ++ans;
            }
        }
    }
    std::cout << ans << "\n";
    return 0;
}


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

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

int main() {
	while (true) {
		string str;
		getline(cin, str);
		int n = count(str.c_str(), str.c_str() + str.size(), ' ') + 1;
		vector<int> card(n);
		stringstream ss(str);
		REP(i, n) ss >> card[i];
		if (card[0] == 0) break;
		
		sort(card.begin(), card.end());
		int c = count(card.begin(), card.end(), 1);
		
		int score = 0;
		FOR(i, c, n) {
			if (card[i] > 10) score += 10;
			else score += card[i];
		}
		
		while (c--) {
			if (score + 11 > 21)
				score += 1;
			else if (abs(21 - (score + 1)) > abs(21 - (score + 11))) {
				if (score + 11 <= 21 - c)
					score += 11;
				else
					score += 1;
			}
			else
				score += 1;
		}
		if (score > 21) score = 0;
		
		cout << score << endl;
	}
	return 0;
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  char X,Y;
  cin>>X>>Y;

  if(X>Y)cout<<">"<<endl;
  if(X==Y)cout<<"="<<endl;
  if(X<Y)cout<<"<"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    char c;
    bool a = 0, b = 0;
    loop(i, 3) {
        cin >> c;
        if (c == 'A')
            a = 1;
        else
            b = 1;
    }
    cout << (a && b ? "Yes" : "No");
}

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


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

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

	int ans = 0;
	for(int i=1; i<(int)s.size(); i++){
		if(s[i-1] != s[i])ans++;
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3756
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
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 REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;



vector<int> A;
int64 dfs(int l,int r,bool term,vector<vector<vector<int64>>>& memo){
    if(l==r) {
        if(term) return A[l];
        else return -A[l];
        
    }
    if(memo[l][r][term] != -INF){
        return memo[l][r][term];
    }

    int64 res;
    if(term){
        res = max(A[l]+dfs(l+1,r,term^1,memo), A[r]+dfs(l,r-1,term^1,memo));
    }else{
        res = min(-A[l]+dfs(l+1,r,term^1,memo), -A[r]+dfs(l,r-1,term^1,memo));
    }
    memo[l][r][term] = res;
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<vector<int64>>> memo(N,vector<vector<int64>>(N,vector<int64>(2,-INF)));
    A.resize(N);
    REP(i,N) {
        cin >> A[i];
    }

    int64 ans = dfs(0,N-1,true,memo);
    cout << ans << bn;
}

Measured memory_bytes: 492928
#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;
ll A, B, C, D;

ll gcd( ll a, ll b )
{ return b ? gcd(b,a%b) : a; }

ll lcm( ll a, ll b )
{ return a/gcd(a,b)*b; }

ll f( ll x )
{
  return x/C+x/D-x/lcm(C,D);
}

int main()
{
  scanf( "%lld%lld%lld%lld", &A, &B, &C, &D );

  printf( "%lld\n", (B-A+1)-(f(B)-f(A-1)) );

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
int n;
string s, t;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> s >> t;
	for(int i = 0;i < n;++i)cout << s[i] << t[i];
	cout << '\n';
}



Measured memory_bytes: 384