akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<string>

using namespace std;

int main() {
    int x,y,n,m,i,xmax,ymin;
    string ans;
    ymin=100;xmax=-100;
    cin >> n>>m>>x>>y;
    vector<int> xn(n);
    vector<int> ym(m);
    for(i=0;i<n;i++)cin >>xn[i];
    for(i=0;i<m;i++)cin >>ym[i];
    for(i=0;i<n;i++){
        if(xmax<xn[i])xmax=xn[i];
    }
    for(i=0;i<m;i++){
        if(ymin>ym[i])ymin=ym[i];
    }
    if(xmax>=ymin)ans="War";
    else{
        if((ymin>x&&ymin<=y)||(xmax+1<=y&&xmax+1>x))ans="No War";
        else ans="War";
    }


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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a, b=0, t=0, n;
	cin >> n;
	for (int i=1;i<=n;i++){
		cin >> a;
		if (a>=b){
			t++;
			b=a;
		}
	}cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,0,n-1) cin>>a[i];

    bool flag = true;
    int ans = 0;
    while(1){
        rep(i,0,n-1){
            if(a[i]%2==0){
                a[i] = a[i]/2;
            }
            else{
                flag = false;
                break;
            }
        }
        if(flag) ans++;
        else break;
    }
    cout<<ans<<endl;
    return 0;
}

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

const int maxn = 200100;

ll x[maxn];
ll v[maxn];
ll f1[maxn];
ll s1[maxn];
ll f2[maxn];
ll s2[maxn];
ll maxf1[maxn];
ll maxf2[maxn];

int main(){
	int n;
	ll c;
	scanf("%d%lld",&n,&c);
	ll sumv=0;
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&x[i],&v[i]);
		sumv+=v[i];
	}
	ll ans=sumv-c+max(x[0],c-x[n-1]);
	ll ans1=0;
	ll maxs=0;
	s1[0]=0;
	for(int i=0;i<n;i++){
		s1[i+1]=s1[i]+v[i];
		f1[i+1]=s1[i+1]-2*x[i];
		maxf1[i+1]=max(maxf1[i],f1[i+1]);
	}
	s2[n]=0;
	ll ans2=0;
	for(int i=n-1;i>=0;i--){
		s2[i]=s2[i+1]+v[i];
		f2[i]=s2[i]-2*(c-x[i]);
		maxf2[i]=max(maxf2[i+1],f2[i]);
	}
	for(int i=0;i<n;i++){
		ans1=max(ans1,maxf2[i+1]+s1[i+1]-x[i]);
	}
	for(int i=n-1;i>=0;i--){
		ans2=max(ans2,maxf1[i]+s2[i]-(c-x[i]));
	}
	ans=max(ans,max(ans1,ans2));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11776
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    int N;cin >> N;
    int A[N + 1];
    int B[N+1];
    int C[N+1];
    for(int i=1;i<=N;++i)
    {
        cin >> A[i];
    }
    A[N+1] =0;
    A[0] =0;
    for(int j =0;j <= N;++j)
    {
        B[j] = abs(A[j+1] - A[j]);
       if(j >0) C[j] = abs(A[j+1] - A[j -1]);
    }

    int sum =0;

    for(int i =0;i<=N;++i)
    {
        sum+=B[i];
    }
    for(int j=1;j<=N;++j)
    {
        int sum_out=sum;
        sum_out= sum_out - B[j] - B[j-1] + C[j];
        cout << sum_out << endl;
    }
        
    return 0;
}

Measured memory_bytes: 2432
S = input()

a = int(S[:2])
b = int(S[2:])

isYYMM = 1 <= b <= 12
isMMYY = 1 <= a <= 12

if isYYMM and isMMYY:
    print('AMBIGUOUS')
elif isYYMM:
    print('YYMM')
elif isMMYY:
    print('MMYY')
else:
    print('NA')

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

int main() {
	int n,m;
	cin>>n>>m;
	
	if(n==m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
 
 
 
int main(){
		
		int a,b,c;
		cin>>a>>b>>c;
		int arr [2000];
		for (int i=0;i<a;i++)arr[i]=0;
		for(int i=1;i<a;i++)
			for(int j=i+1;j<=a;j++){
				if(j<=b||i>=c){
					arr[j-i]++;
					continue;
				}
				if(i>=b&&j<=c){
					arr[min(j-i,c-b+1-j+i)]++;
					continue;
				}
				if(i<b&&j>c){
					arr[b-i+j-c+1]++;
					continue;
				}
				if(i<b&&j<=c){
					arr[b-i+min(j-b,c-b+1-j+b)]++;
					continue;
				}
				if(i>=b&&j>c){
					arr[j-c+min(c-i,c-b+1-c+i)]++;
				}
			}
		for(int i=1;i<a;i++)cout<<arr[i]<<endl;	
		return 0;
}

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

int main() {
  vector<int> vec(5);

  for (int i = 0; i < 5; i++) {
    cin >> vec.at(i);
  }
  
  int answer = 0;
  
  for (int i = 0; i < 5; i++) {
  	if (vec.at(i) == 0) {
    	answer = i +1;
      	break;
    }
  }
  
  cout << answer << endl;
  
  return 0;
 
}

Measured memory_bytes: 3620
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

static size_t A[100000];

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

int main(void) {
	uint64_t N, K;

	scanf("%"PRIu64" %"PRIu64, &N, &K);

	uint64_t count = (N/K)*(N/K)*(N/K);
	if (K % 2 == 0) {
		count += ((N + K / 2) / K)*((N + K / 2) / K)*((N + K / 2) / K);
	}

	printf("%"PRIu64"\n", count);

	return 0;
}


Measured memory_bytes: 128
<?php
/*list($N, $K) = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));*/
$S = trim(fgets(STDIN));
$T = trim(fgets(STDIN));

if (strlen($T) !== strlen($S) + 1) {
    echo 'No';
    return;
}
if (strpos($T, $S) === 0) {
    echo 'Yes';
    return;
}

echo 'No';

Measured memory_bytes: 16108
from collections import deque

X,Y,Z,K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB=[]

for a in A:
    for b in B:
        AB.append(a+b)

AB.sort(reverse=True)
AB = AB[:K]

ABC=[]

for ab in AB:
    for c in C:
        ABC.append(ab+c)

ABC.sort(reverse=True)

ABCdeque = deque(ABC)

for _ in range(K):
    print(ABCdeque.popleft())


Measured memory_bytes: 164444
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
#include <random>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;
using pci = std::pair<char, int>;

const long long INF = 1000000000000000001;
const long long _MOD_ = 1000000000000000009;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	int n;
	cin >> n;
	pii* d = new pii[n];
	rep(i, n) cin >> d[i].first >> d[i].second;

	bool flag = false;
	REP(i, 2, n) {
		if (d[i].first == d[i].second && d[i - 1].first == d[i - 1].second && d[i - 2].first == d[i - 2].second) {
			flag = true;
			break;
		}
	}

	if (flag) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}


Measured memory_bytes: 3612
#include <iostream>

int main(){
 int N;
 std::cin>>N;
 long long* A=new long long[N];
 for(int i=0;i<N;i++){
  std::cin>>A[i];
 }
 
 long long ans=1;
 long long tmp=0;
 for(int i=0;i<N;i++){
  tmp=ans;
  ans*=A[i];
  //std::cout<<ans<<std::endl;
  if(A[i]!=0){
   if(1000000000000000000/A[i]<tmp){
    ans=-1;
    break;
   }
  }
 }
 for(int i=0;i<N;i++){
  if(A[i]==0){
   ans=0;
  }
 }
 std::cout<<ans<<std::endl;
}

Measured memory_bytes: 4416
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;

const int N = 55;
int a[3][N][N];
string v[N];

vector<int> t[N][N];
P prv[N][N];
int dist[N][N];

int dr[] = { 0, 1, 0, -1 };
int dc[] = { -1, 0, 1, 0, -1 };

int r, c, m;

int bfs(P start, P goal, int base){
	MEMSET(dist, -1);

	dist[start.first][start.second] = base;
	queue<P> q;
	q.push(start);

	while (!q.empty()){
		auto p = q.front();
		q.pop();

		rep(d, 4){
			int nr = p.first + dr[d], nc = p.second + dc[d];
			if (nr < 0 || nr >= r || nc < 0 || nc >= c) continue;
			if (v[nr][nc] == '#') continue;
			if (dist[nr][nc] >= 0) continue;
			dist[nr][nc] = dist[p.first][p.second] + 1;
			prv[nr][nc] = MP(p.first, p.second);
			q.push(MP(nr, nc));
		}
	}

	P pos = goal;
	while (pos != start){
		t[pos.first][pos.second].push_back(dist[pos.first][pos.second]);
		pos = prv[pos.first][pos.second];
	}
	return dist[goal.first][goal.second];
}


int main(){
	ios::sync_with_stdio(false);
	cin >> r >> c >> m;
	rep(i, r) cin >> v[i];
	rep(k, 3) rep(i, r) rep(j, c) cin >> a[k][i][j];

	P prv;
	int d = 0;
	rep(i, m){
		P p;
		cin >> p.first >> p.second;
		if (i) d = bfs(prv, p, d);
		else t[p.first][p.second].push_back(0);
		prv = p;
	}

	ll ans = 0;
	rep(i, r) rep(j, c){
		int cost = 0, prv = -1;
		for (auto e : t[i][j]){
			if (prv < 0) cost = a[1][i][j] + a[2][i][j];
			else cost = min(cost + a[1][i][j] + a[2][i][j], cost + (e - prv)*a[0][i][j]);
			prv = e;
		}
		ans += cost;
	}
	cout << ans << endl;

	return 0;
}

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

int main()
{
    long r;
    size_t n;
    long maxv=numeric_limits<long>::lowest();
    cin >> n >> r;
    long minv=r;
    for(size_t j = 1; j <=200000; j++)
    {
        cin >> r;
        maxv = max(maxv, r-minv);
        minv = min(minv, r);
        if(j>=n-1) break;
    }
    cout << maxv << endl;
}


Measured memory_bytes: 3108
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int main(void){
	int N,i,j;
	scanf("%d",&N);
	int a[N];
	for(i=0;i<N;i++)scanf("%d",&a[i]);
	qsort(a, N, sizeof(int), compare_int);
	long long int x=0,y=0,ans;
	for(i=N-1;i>=0;i--){
		if(a[i] == a[i-1]){
			x = a[i];
			j = i-2;
			break;
		}
	}
	for(i=j;i>=0;i--){
		if(a[i] == a[i-1]){
			y = a[i];
			break;
		}
	}
	ans = x * y;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 892
from collections import Counter


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

S = [0] * (N + 1)
for i in range(N):
    # S[i + 1] = (S[i] + A[i]) % K
    S[i + 1] = S[i] + A[i]

cnt = 0
C = Counter()
for r in range(N + 1):
    R = (S[r] - r) % K
    cnt += C[R]
    C[R] += 1
    l = r - (K - 1)
    if l >= 0:
        L = (S[l] - l) % K
        C[L] -= 1

print(cnt)


Measured memory_bytes: 48392
H,W = map(int,input().split())
ans = float("inf")

Hh = [H//2,H//2+1]
Wh = [W//2,W//2+1]
Ht = [H//3,H//3+1]
Wt = [W//3,W//3+1]

for i in Ht:
  for j in Ht:
    k = H -i -j
    ans = min(ans,W*(max(i,j,k)-min(i,j,k)))
for i in Wt:
  for j in Wt:
    k = W -i -j
    ans = min(ans,H*(max(i,j,k)-min(i,j,k)))

for i in Ht:
  b = H-i
  for j in Wh:
    k = W-j
    ans = min(ans, max(W*i,b*j,b*k)-min(W*i,b*j,b*k))
for i in Wt:
  b = W-i
  for j in Hh:
    k = H-j
    ans = min(ans, max(H*i,b*j,b*k)-min(H*i,b*j,b*k))
###
print(ans)    

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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N;
  cin >> N;
  i64 X = N * 100 / 108;
  if((N * 100) % 108 != 0)
    X++;

  if(X * 108 / 100 != N)
    cout << ":(" << endl;
  else
    cout << X << endl;    
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int                 long long   
#define double              long double
#define endl                "\n"
#define pb                  push_back
#define PI                  3.1415926535897932384626433832795l
#define F                   first
#define S                   second
#define mp                  make_pair
#define f(i,n)              for(int i=0;i<n;++i)
#define loop(i,a,b)         for (int i=a ; i<b ;++i)
#define fastio              ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define gcd(a,b)            __gcd((a),(b))
#define fill(a,value)       memset(a,value,sizeof(a));
#define minn(v)             *min_element(v.begin(), v.end());
#define maxx(v)             *max_element(v.begin(), v.end());
#define print(x)            cout<<(x)<<endl;
typedef pair<int,int> pii;  
typedef vector<int> vi;
signed main() 
{
    fastio;
    int n,x,t;
    cin>>n>>x>>t;
    int a=ceil(n*(t/(x*1.0)));
    int r=t-a%t;
    if(r==t)r=0;
    a+=r;
    print(a)
    
    
    
    
    
    return 0;
    
    
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

vector<int> G[100020];
int h[100020];

int main()
{
	ios::sync_with_stdio(false);
	int n,m,k=0,a,b;
	bool t;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	cin>>h[i];
	while(m--)
	{
		cin>>a>>b;
		G[a].pb(b);
		G[b].pb(a);
	}
	for(int i=1;i<=n;i++)
	{
		t=false;
		for(int j=0;j<G[i].size();j++)
		{
			if(h[G[i][j]]>=h[i])
			{
				t=true;
				break;
			}
		}
		if(!t) k++;
	}
	cout<<k;
	return 0;
}




Measured memory_bytes: 9176
implicit none
integer(8):: i,j,k,n,m,ans
integer(8),allocatable,dimension(:):: num,count

read (5,*) n
 
allocate(num(n))
allocate(count(n))
count=0
ans=0
m=1
count(1)=1
 
do i=1,n
    read (5,*) num(i)
enddo

call heapsort(n,num)

do i = 2,n
    if (num(m)==num(i)) then
        count(m)=count(m)+1
    else
        m=i
        count(m)=1
    endif
enddo

do i = 1,n
    ans=ans+mod(count(i),2)
enddo

write(6,"(i0)") ans
end

!---http://slpr.sakura.ne.jp/qp/sortf90/---
subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    double precision,intent(inout) :: array(1:n)
   
    integer ::i,k,j,l
    double precision :: t
   
    if(n.le.0)then
        write(6,*)"Error, at heapsort"; stop
    endif
    if(n.eq.1)return

    l=n/2+1
    k=n
    do while(k.ne.1)
        if(l.gt.1)then
            l=l-1
            t=array(L)
        else
            t=array(k)
            array(k)=array(1)
            k=k-1
            if(k.eq.1) then
                array(1)=t
                exit
            endif
        endif
        i=l
        j=l+l
        do while(j.le.k)
            if(j.lt.k)then
                if(array(j).lt.array(j+1))j=j+1
            endif
            if (t.lt.array(j))then
                array(i)=array(j)
                i=j
                j=j+j
            else
                j=k+1
            endif
        enddo
        array(i)=t
    enddo

    return
end subroutine heapsort

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
  int N,M,i,j,max=0,num;
  scanf("%d%d",&N,&M);
  int A[N],B[M],count[N];
  for(i=0;i<N;i++) {scanf("%d",&A[i]); count[i]=0;}
  for(i=0;i<M;i++) scanf("%d",&B[i]);

  for(i=0;i<M;i++)
  {
    for(j=0;j<N;j++)
    {
      if(A[j]<=B[i]){count[j]++;break;}
    }
  }
  for(i=0;i<N;i++)
  {
    if(max<count[i]){max=count[i]; num=i+1;}
  }
  printf("%d\n",num);
  return 0;
}



Measured memory_bytes: 2096
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    dic = {}
    for i in range(n):
        s = input()
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    max_ = max(dic.values())
    L = []
    for k,v in dic.items():
        if v == max_:
            L.append(k)
    L = sorted(L)
    print(*L,sep='\n')
if __name__ == '__main__':
  main()


Measured memory_bytes: 34012
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

const int maxn=2e3+10,maxn2=2*2e3+10;
int n,a[maxn2],dp[maxn][maxn],rnkw[maxn],rnkb[maxn];
int bit[maxn2];
char c[maxn2][2];

inline void add(int pos,int val){
	while(pos<maxn2){
		bit[pos]+=val;
		pos+=pos&-pos;
	}
}
inline int sum(int pos){
	int res=0;
	while(pos){
		res+=bit[pos];
		pos-=pos&-pos;
	}
	return res;
}
inline void chkmin(int&a,int b){
	if(a>b)a=b;
}

int main(){
	cin>>n;
	for(int i=1;i<=2*n;++i){
		cin>>c[i]>>a[i];
		if(c[i][0]=='W')
			rnkw[a[i]]=i;
		else
			rnkb[a[i]]=i;
	}
	for(int i=0;i<=n;++i)
		for(int j=0;j<=n;++j)
			dp[i][j]=1e9;
	dp[0][0]=0;
	for(int i=1;i<=n;++i)
		add(rnkw[i],1);
	for(int i=0;i<=n;++i){
		if(i)
			add(rnkw[i],-1);
		for(int j=1;j<=n;++j)
			add(rnkb[j],1);
		for(int j=0;j<=n;++j){
			if(j)
				add(rnkb[j],-1);
			if(i<n)
				chkmin(dp[i+1][j],dp[i][j]+sum(rnkw[i+1])-1);
			if(j<n)
				chkmin(dp[i][j+1],dp[i][j]+sum(rnkb[j+1])-1);
		}
	}
	cout<<dp[n][n]<<endl;
	return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define endl "\n"

typedef long long ll;
using namespace std;

//ll const N = 32000;

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

    string str;
    cin >> str;

    ll sum = 0;

    for(int i = 0; i < str.size(); i++)
    {
        sum += str[i] - '0';
    }

    if(sum % 9 == 0)cout << "Yes";
    else cout << "No";

    return 0;
}


Measured memory_bytes: 3768
#include<cstdio>
const int N=1e5+3;
int n,m,deg[N];
signed main(){
	int u,v;
	scanf("%d%d",&n,&m);
	for(;m--;)
	  scanf("%d%d",&u,&v),deg[u]++,deg[v]++;
	for(u=1;u<=n;u++)if(deg[u]&1)return 0*puts("NO");
	return 0*puts("YES");
}

Measured memory_bytes: 2048
#include <stdio.h>

int main(void){
  int i,j;
  int a[100],n,m,x;
  int index;
  int l=0,r=0;
  scanf("%d %d %d",&n,&m,&x);
  for(i=0;i<100;i++){
    a[i]=0;
  }
  for(i=1;i<=m;i++){
    scanf("%d ",&index);
    a[index]=1;
  }
  for(i=x;i<=n;i++){
    r+=a[i];
  }
  for(i=x-1;i>0;i--){
    l+=a[i];
  }
  if(r>l)
    printf("%d\n",l);
  else
    printf("%d\n",r);

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+5;
vector<int>v[2][N];
int vis[2][N];
int sz[2][N];
int cmp;
void dfs(int st,int x){
	vis[st][x] = cmp;
	sz[st][cmp]++;
	for(int y:v[st][x]){
		if(vis[st][y]==0)dfs(st,y);
	}
}
map<int,int>nxt[N];
void solve(){
	ll n,m,k; 
	cin>>n>>m>>k;
	for(int i=1;i<=m;i++){
		int x,y; 
		cin>>x>>y; 
		v[0][x].pb(y);
		v[0][y].pb(x);
		nxt[x][y] = nxt[y][x] = 1;
	}
	for(int i=1;i<=k;i++){
		int x,y; 
		cin>>x>>y; 
		v[1][x].pb(y);
		v[1][y].pb(x);
	}
	cmp  = 0;
	for(int i=1;i<=n;i++){
		if(vis[0][i]==0){
			cmp++;
			dfs(0,i);
		}
	}
	cmp = 0;
	for(int i=1;i<=n;i++){
		if(vis[1][i]==0){
			cmp++;
			dfs(1,i);
		}
	}
	map<pair<int,int> ,ll> mp;
	for(int i=1;i<=n;i++){
		mp[{vis[0][i],vis[1][i]}]++;
	}
	for(int i=1;i<=n;i++){
		ll ans = sz[0][vis[0][i]];
		ans-=(int)v[0][i].size();
		for(int y:v[1][i]){
			if(vis[0][y]==vis[0][i] and nxt[i][y]==0)ans--;
		}
		assert(ans>0);
		cout<<ans-1<<" ";
	}
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 51488
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
//substr
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];

int main(){
    int R;
    cin >> R;
    if(R < 1200) cout << "ABC" << endl;
    else if(R < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
    return 0;
}

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

def gcd(a,b):
    if a == 0:
        return b
    if b == 0:
        return a
    r = 1
    while r > 0:
        r = a % b
        a = b
        b = r
    return a

l=[0]
for i in range(n):
    l.append(gcd(l[-1],a[i]))

print(l[-1])


Measured memory_bytes: 62704
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7, mod = 1e9 + 7;
typedef long long ll;
int n;
ll a[maxn], b[maxn];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    for (int i = n; i >= 1; i--) b[i] = (b[i + 1] + a[i]) % mod;
    ll ans = 0;
    for (int i = 1; i <= n - 1; i++) {
        ans = (ans + a[i] * b[i + 1] % mod) % mod;
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 6908
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define br break
#define PI 3.1415926535

int main() 
{
    FAST;
    ll n,a,b;
    cin>>n>>a>>b;
    if(abs(a-b)%2==0)
        cout<<((abs(a-b))/2);
    else
        cout<<((abs(a-b))/2)+min(a,n-b+1);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a, sum;
	scanf("%d", &a);
    if(a == 119) sum = 991;
    else if(a == 199) sum = 911;
    else if(a == 111) sum = 999;
    else if(a == 191) sum = 919;
    else if(a == 999) sum = 111;
    else if(a == 919) sum = 191;
    else if(a == 911) sum = 199;
    else if(a == 991) sum = 119;
    printf("%d\n", sum);
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

string s;

int main()
{
    _FastIO;
    cin >> s;
    string a[4] = {"Sunny" , "Cloudy" , "Rainy" , "Sunny"};
    for(int i = 1; i < 4; i++){
        if(a[i - 1] == s){
            cout << a[i] << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <ctype.h>

using namespace std;


int toInt( string str )
{
	int result = 0, n = 1;
	int i;

	for( i=0; i<str.size(); i++ ){
		if( isdigit(str[i]) ){
			n = str[i] - '0';
		} else {
			switch( str[i] ){
				case 'm' :
					result += n*1000; break;
				case 'c' :
					result += n*100; break;
				case 'x' :
					result += n*10; break;
				case 'i' :
					result += n*1; break;
			}
			n = 1;
		}
	}
	
	return result;
}

string toString( int num )
{
	string result;
	char table[] = { 'm', 'c', 'x', 'i' };
	int i, n;

	n = 1000;
	for( i=0; i<4; i++ ){
		if( num/n ){
			if( num/n != 1 )
				result += '0'+num/n;
			result += table[i];
			num = num%n;
		}
		n /= 10;
	}

	return result;
}

int main(void)
{
	int n;

	string a, b;

	cin >> n;
	while( n-- > 0 ){
		cin >> a >> b;

		cout << toString( toInt(a)+toInt(b) ) << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main(void) {
    string S;
    cin >> S;
    for(int i=0; i<S.size(); i++) {
        cout << 'x';
    }
    cout << endl;
    return 0;
}


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

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      int k[n];
      for(int i=0;i<n;i++)
	cin>>k[i];
      string s;
      cin>>s;
      int key=0;
      for(int i=0;i<s.size();i++)
	{
	  
	  for(int j=0;j<k[key];j++)
	    { 
	      s[i]--;
	      if(s[i]=='a'-1)
		s[i]='Z';
	      if(s[i]=='A'-1)
		s[i]='z';      
	    }
	  key++;
	  if(key>=n)
	    key=0;
	}
      cout<<s<<endl;
    }

}

Measured memory_bytes: 1204
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

template<long long Mod>
struct mint{
    long long x;
    mint(long long x=0) :x((x% Mod+Mod)%Mod){}

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

    mint& operator+=(const mint a) {
        if((x += a.x) >= Mod) x -= Mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if((x += Mod-a.x) >= Mod) x -= Mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= Mod;
        return *this;
    }

    mint operator^(long long t) const {
        mint ret(1);
        mint a = *this;
        while(t){
            if(t&1){
                ret *= a;
            }
            a *= a;
            t >>= 1;
        }
        return ret;
    }
    mint inv() const { return *this ^ (Mod-2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }

    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint operator/(const mint a) const { return mint(*this) /= a; }

    friend istream& operator>>(istream& is, mint& a) { return is >> a.x; }
    friend ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
};

template<typename T>
struct Combination{
private:
    int N;
    vector<T> f, i;
public:
    void init(int n){
        N = n;
        f.resize(N+1); f[0] = T(1);
        for(int j=1; j<=N; j++){
            f[j] = f[j-1] * T(j);
        }
        i.resize(N+1); i[N] = T(1) / f[N];
        for(int j=N-1; j>=0; j--){
            i[j] = i[j+1] * T(j+1);
        }
    }
    T fact(int n){
        return f[n];
    }
    T P(int n, int r){
        return f[n] * i[n-r];
    }
    T C(int n, int r){
        return f[n] * i[r] * i[n-r];
    }
};

int N;
int A, B, C, D;
Combination<mint<MOD>> comb;

bool vis[1001][1001] ={};
mint<MOD> dp[1001][1001];
mint<MOD> solve(int n, int m){
    if(n < 0) return 0;
    if(m == B+1){
        if(n == 0) return 1;
        else return 0;
    }
    if(vis[n][m]) return dp[n][m];
  	vis[n][m] = true;
    mint<MOD> ret = solve(n, m+1);
    if(n < C*m) return dp[n][m] = ret;
    mint<MOD> tmp = 1;
    rep(i, C) tmp *= comb.C(n-m*i, m);
    for(int i=C; i<=D; i++){
        ret += solve(n-m*i, m+1)*tmp/comb.P(i, i);
        if(n-m*i < m) break;
        tmp *= comb.C(n-m*i, m);
    }
    return dp[n][m] = ret;
}

signed main(){
    cin >> N >> A >> B >> C >> D;
    comb.init(N);
    cout << solve(N, A) << endl;
}


Measured memory_bytes: 12488
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = sc.nextInt();
        }

        long sum = 0;
        long ans1 = 0;
        for (int i = 0; i < n; ++i) {
            sum += a[i];
            if (i % 2 == 0 && sum <= 0) {
                ans1 += Math.abs(sum) + 1;
                sum = 1;
            } else if (i % 2 == 1 && sum >= 0) {
                ans1 += sum + 1;
                sum = -1;
            }
        }

        sum = 0;
        long ans2 = 0;
        for (int i = 0; i < n; ++i) {
            sum += a[i];
            if (i % 2 == 0 && sum >= 0) {
                ans2 += sum + 1;
                sum = -1;
            } else if (i % 2 == 1 && sum <= 0) {
                ans2 += Math.abs(sum) + 1;
                sum = 1;
            }
        }
        _out.println(Math.min(ans1, ans2));
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn f(s: &[char]) -> bool {
    let m = s.len();
    for i in 0..m {
        if s[i] != s[m - 1 - i] {
            return false;
        }
    }
    true
}

use std::iter::Iterator;

fn main() {
    input! {
        s: String,
    }

    if s == "AAA" || s == "BBB" {
        println!("No")
    }else{
        println!("Yes")
    }
    
}


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

#define SIZE 21

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

  char input[SIZE];
  std::cin.getline(input, sizeof(input));
  std::string str = std::string(input);

  std::reverse(str.begin(), str.end());

  std::cout << str << std::endl;

  return 0;
}



Measured memory_bytes: 3104
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define PI 3.14159265358979

double dist(double x1, double y1, double x2, double y2) {
    double dx = x2 - x1;
    double dy = y2 - y1;
    return sqrt(dx * dx + dy * dy);
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    double min = H * 60 + M;
    double x1 = A * cos(PI/2.0 - 2.0*PI*(min/720.0));
    double y1 = A * sin(PI/2.0 - 2.0*PI*(min/720.0));
    double x2 = B * cos(PI/2.0 - 2.0*PI*(M/60.0));
    double y2 = B * sin(PI/2.0 - 2.0*PI*(M/60.0));
    //cout << fixed << setprecision(12) << x1 << " " << y1 << " " << 2/PI - 2*PI*(min/720.0)<< endl;
    //cout <<  cos(PI/2) << " " << sin(PI/2) << endl;
    cout << fixed << setprecision(12) << dist(x1, y1, x2 ,y2) << endl;

    return 0;
}


Measured memory_bytes: 4116
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MAX = 1e5;
int main() {
  int n;
  cin >> n;
  vector<int> v(MAX);
  rep(i,n){
    int a;
    cin >> a;
    v[a]++;
  }
  int ans = 0;
  rep(i,MAX-2){
    ans = max(ans,v[i]+v[i+1]+v[i+2]);
  }
  cout << ans << endl;
}


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

int main()
{	
	int n,m;
	cin >> n >> m;
	int array[m][2];

	int i,j;

	for (i=0;i<m;i++)
	{
		cin >> array[i][0] >> array[i][1];
	}

	for (i=1;i<=n;i++)
	{
		int number=0;
		for (j=0;j<m;j++)
		{
			if (array[j][0]==i || array[j][1]==i)
				number++;
		}
		cout << number << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    int n;
    ll money = 1000;
    ll stock=0;
    cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    rep(i,n-1){
        if(a[i] < a[i+1]){
            if(stock == 0){
                stock += (money/a[i]);
                money -= stock*a[i];
               // cout << i << " buy " << stock << " " << money << endl;
            }
        }else{
            if(stock > 0){
                money += stock * a[i];
                stock = 0;
         //   cout<< i  <<" sell " << stock << " " << money << endl;
            }
        }
    }

    if(stock > 0){
        money += stock * a[n-1];
    }

    cout << money << endl;

    return 0;
}

Measured memory_bytes: 3632
prime = Array.new(10000,true)

prime[0] = false
prime[1] = false
for i in 2..9999 do
    if prime[i]
        k = 2
        s = i * k
        while s < 10000
         prime[s] = false
         k += 1
         s = i * k
        end
       i += 1
    else
        i += 1
    end
end

primenumber = prime.each_with_index.select{|e, i| e == true}.map{|e| e[1]}

ans_prime_list = []
primenumber.each do |t|
    if primenumber.include?(t+2)
        ans_prime_list << t + 2
    i += 1
    end
end
primenumber2 = ans_prime_list.reverse
n = gets.to_i
until n == 0
    ans = primenumber2.select{|k| k <= n }
    asas = ans[0] - 2
    puts "#{asas} #{ans[0]}"
    n = gets.to_i
end


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

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define inf 1e+18L

int main()
{
	FASTIO
	int N, W, sum = 0;
	cin >> N >> W;
	vector<ll> w(N);
	vector<int> val(N);
	rep(i,0,N)
	{
		cin >> w[i] >> val[i];
		sum += val[i];
	}
	vector<ll> dp(sum+1,inf);
	dp[0] = 0;
	rep(i,0,N)
	{
		for(int v=sum; v>=0; v--)
		{
			if(v+val[i] <= sum && dp[v] < inf)
				dp[v+val[i]] = min(dp[v+val[i]], w[i]+dp[v]);
		}
	}
	int ans;
	rep(i,0,sum+1)
	{
		if(dp[i] <= W) ans = i;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int S;
    cin >> S;
    int AA,BB;
    AA = S/100;
    BB = S - AA*100;
    if((0 == AA || AA >=13) && (BB >= 13 || BB == 0)){
        cout << "NA";
    }else if(AA ==0 ||AA >=13){
        cout << "YYMM";
    }else if(BB >=13|| BB == 0){
        cout << "MMYY";
    }else{
        cout << "AMBIGUOUS";
    }
    return 0;
}

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

using namespace std;

namespace io{
	const int L=(1<<19)+1;
	char ibuf[L],*iS,*iT,obuf[L],*oS=obuf,*oT=obuf+L-1,c,st[55];int f,tp;
	char gc(){
		if(iS==iT){
			iT=(iS=ibuf)+fread(ibuf,1,L,stdin);
			return iS==iT?EOF:*iS++;
		}
		return*iS++;
	}
	void cbuf(){fwrite(obuf,1,oS-obuf,stdout);oS=obuf;}
	void putc(char x){*oS++=x;if(oS==oT)cbuf();}
	void gs(char*s){
		for(c=gc();c<'A'||c>'Z';c=gc());
		for(;c>='A'&&c<='Z';c=gc())*s++=c;
	}
	template<class I>void gi(I&x){
		for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;
		for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;
	}
	template<class I>void print(I x){
		if(!x)putc('0');if(x<0)putc('-'),x=-x;
		while(x)st[++tp]=x%10+'0',x/=10;
		while(tp)putc(st[tp--]);
	}
};
using io::putc;
using io::gi;
using io::gs;
using io::print;

const int N=200005,P=1E9+7;
typedef long long ll;

struct peo{
	int x,v;
	peo(){}
	peo(int _x,int _v){x=_x,v=_v;}
}p[N];
bool cmpx(const peo &a,const peo &b){return a.x<b.x;}
bool cmpv(const int &a,const int &b){return p[a].v<p[b].v;}
bool cmp(const int &a,const int &b){return a>b;}
int MAX(const int &a,const int &b){if(!a||!b)return a|b;return cmpv(a,b)?b:a;}
int MIN(const int &a,const int &b){if(!a||!b)return a|b;return cmpv(a,b)?a:b;}

int n,pw2[N],mxv[N],mnv[N],id[N],rev[N],dp[N],sum[N];
vector<int>link[N];

int main(){
	gi(n);pw2[0]=1;
	for(int i=1;i<=n;i++)gi(p[i].x),gi(p[i].v),id[i]=i,pw2[i]=(pw2[i-1]<<1)%P;
	sort(p+1,p+n+1,cmpx),sort(id+1,id+n+1,cmpv);
	for(int i=1;i<=n;i++)rev[id[i]]=i;
	for(int i=1;i<=n;i++)mxv[i]=MAX(mxv[i-1],i);
	for(int i=n;i;i--)mnv[i]=MIN(mnv[i+1],i);
	for(int i=1;i<=n;i++)link[rev[mxv[i]]].push_back(rev[mnv[i]]);
	for(int i=*sum=1,j,l,k;i<=n;i++){
		sort(link[i].begin(),link[i].end(),cmp);
		int &w=dp[i],p;
		for(j=0,l=link[i].size();j<l;){
			for(p=link[i][j],j++,k=1;j<l&&link[i][j]==link[i][j-1];j++,k++);
			w=(w+(ll)pw2[j-k]*(pw2[k]-1)%P*(sum[i-1]-(p>1?sum[p-2]:0)))%P;
		}
		sum[i]=(sum[i-1]+w)%P;
	}
	if(dp[n]<0)dp[n]+=P;
	print(dp[n]),io::cbuf();
	return 0;
}

Measured memory_bytes: 19200
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <complex>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const double PI = 3.141592653589793238462643383279502884L;
const int LARGE_PRIME = 1000000007;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i,a,cont,next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i,a,b,s) repfn(i,a,i<b,i+s)
#define repab(i,a,b) repby(i,a,b,1)
#define rep(i,b) repab(i,0,b)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  for (;;) {
    int n;
    vi v;

    cin >> n;
    if (!n)
      break;

    while (n--) {
      int tmp;
      cin >> tmp;
      v.pb(tmp);
    }

    vi w(v);
    w.pb(0);
    int accm = -LARGE_PRIME;
    for (int j = 0; j < sz(v); j++) {
      for (int i = 0; i < sz(v); i++) {
        w[i] = max(w[i], v[i] + w[i+1]);
        accm = max(accm, w[i]);
      }
    }
    cout << accm << endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int L;
    cin >> L;
    int tmp = L;
    vp vec;
    vi c;
    int nw = 0;
    while(tmp){
        tmp >>= 1;
        nw++;
    }
    cout << nw << " ";
    while(L > 1){
        if(L % 2){
            vec.pb(P(1,nw)), c.pb(L/2);
            vec.pb(P(nw-1,nw)), c.pb(0);
            vec.pb(P(nw-1,nw)), c.pb(L/2+1);
        }else{
            vec.pb(P(nw-1,nw)), c.pb(0);
            vec.pb(P(nw-1,nw)), c.pb(L/2);
        }
        L >>= 1;
        nw--;
    }
    cout << len(vec) << "\n";
    rep(i,len(vec)){
        cout << vec[i].fi << " " << vec[i].se << " " << c[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main() {
  int A, B, C, D;
  scanf("%d%d%d%d", &A, &B, &C, &D);
  if ((A + B) == (C + D)) {
    printf("Balanced\n");
  }
  else {
    printf((A + B) < (C + D) ? "Right\n" : "Left\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n,ans=0;
  string s;
  cin >> s;

  n= s.size();
  
  for(int i=0; i< n/2; i++){
    if(s[i]==s[n-1-i]){
      continue;
    }else{
      ans++;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

string getString(ll n) {
    int nn = floor(log(25 * (n + 1)) / log(26));
    string buf;
    for (int i = nn - 1; i >= 0; i--) {
        n--;
        buf += (char) ('A' + n % 26);
        n /= 26LL;
    }
    return buf;
}

int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);


    ll n;
    cin >> n;

    string rt = getString(n);

    reverse(all(rt));

    for(auto &el : rt) el = tolower(el);

    cout << rt;
}








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

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


    if (S == "hi") cout << "Yes" << endl;
    else if (S == "hihi") cout << "Yes" << endl;
    else if (S == "hihihi") cout << "Yes" << endl;
    else if (S == "hihihihi") cout << "Yes" << endl;
    else if (S == "hihihihihi") cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <queue>
using namespace std;
#define N 150
#define GG puts("Impossible");return 0
int n,a[N],c[N],mx;
int main() {
	scanf("%d",&n);
	int i,j;
	for(i=1;i<=n;i++) scanf("%d",&a[i]),c[a[i]]++,mx=max(mx,a[i]);
	if(c[mx]<2) {GG;}
	for(i=2;i<=mx;i++) {
		int t=max(i-1,mx-i+1);
		if(!c[t]) {GG;}
		c[t]--;
	}
	for(i=1;i<mx;i++) if(c[i]) {
		int flg=0;
		for(j=2;j<=mx;j++) {
			int t=max(j-1,mx-j+1)+1;
			if(t==i) {flg=1; break;}
		}
		if(!flg) {GG;}
	}
	puts("Possible");
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>

int main(){
  int Num;
 
  std::cin >> Num;
  std::vector<std::vector<int>> Dice(Num,std::vector<int>(2));

  int sametimes=0;
  bool same=false;
  for(int i=0;i<Num;i++){
    std::cin >> Dice[i][0] >> Dice[i][1];
    if(Dice[i][0] == Dice[i][1]){
      sametimes +=1;
      if(sametimes == 3){
	same = true;
      }
    }
    else
      sametimes = 0;
  }

  if(same == true)
    std::cout << "Yes" <<std::endl;
  else
    std::cout << "No" << std::endl;
  return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <string>

std::string solve(const std::string& s)
{
  const unsigned count = std::count(s.begin(), s.end(), 'R');
  return count * 2 > s.size() ? "Yes" : "No";
}

int main()
{
  int n;
  std::string s;
  std::cin >> n >> s;

  std::cout << solve(s) << std::endl;
}


Measured memory_bytes: 256