akhauriyash/Code-Regression huggingface dataset:
// Problem : D - Non-decreasing
// Contest : AtCoder - AtCoder Beginner Contest 081
// URL : https://atcoder.jp/contests/abc081/tasks/arc086_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
	int n;cin>>n;
	vi v(n);cin>>v;
	int x=*max_element(all(v));
	int y=*min_element(all(v));
	int cnt=0;vp ans;
	if(x>0 and y<0)
	{
		if(abst(x)>=abst(y))
		{
			int ind;
			for(int i=0;i<n;i++)
			if(v[i]==x)
			{
				ind=i+1;
				break;
			}
			for(int i=1;i<=n;i++)
			if(i!=ind)
			ans.pb({ind,i});
			for(int i=2;i<=n;i++)
			ans.pb({i-1,i});
			cout<<size(ans)<<"\n";
			for(pii p:ans)
			cout<<p.f<<" "<<p.se<<"\n";
		}
		else
		{
			int ind;
			for(int i=0;i<n;i++)
			if(v[i]==y)
			{
				ind=i+1;
				break;
			}
			for(int i=1;i<=n;i++)
			if(i!=ind)
			ans.pb({ind,i});
			for(int i=n-1;i>=1;i--)
			ans.pb({i+1,i});
			cout<<size(ans)<<"\n";
			for(pii p:ans)
			cout<<p.f<<" "<<p.se<<"\n";
		}
	}
	else if(y<0)
	{
		for(int i=n-1;i>=1;i--)
			ans.pb({i+1,i});
			cout<<size(ans)<<"\n";
			for(pii p:ans)
			cout<<p.f<<" "<<p.se<<"\n";
		
			
	}
	else
	{
		for(int i=2;i<=n;i++)
			ans.pb({i-1,i});
			cout<<size(ans)<<"\n";
			for(pii p:ans)
			cout<<p.f<<" "<<p.se<<"\n";
	}
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char c;
    cin>>c;

    if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')cout<<"vowel"<<'\n';
    else cout<<"consonant"<<'\n';
    return 0;
    
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define submitStage int TCF = 1 ;
#define testStage int TCF = 1000 ;
#define Start while(TCF--)

void FastInputOutput(){
  ios_base :: sync_with_stdio( 0 ) ;
  cin.tie( 0 ) ;
  cout.tie( 0 ) ;
}
void ReadFromFile(){
  freopen( "in.txt", "r" , stdin ) ;
}
int D(){
	int t ;
	scanf( "%d" , &t ) ;
	return t ;
}
ll LLD(){
	ll t ;
	scanf( "%lld" , &t ) ;
	return t ;
}

const int N=1e6+7;
void init(){
}

int main(){
submitStage Start{
  string n;cin>>n;
  char lst='a';
  bool flag=1;
  for(int i=0 ; n[i] ; ++i){
    if(n[i]==lst){
      flag=false;
      break;
    }
      lst=n[i];
  }
  puts((flag)?"Good":"Bad");
}}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, a[100010], cnt=0;

int main(void){
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    sort(a, a+n);
    int prev = a[0], tmp = 1;
    for(int i=1;i<n;++i){
        if(a[i]==prev){
            ++tmp;
        }else{
            if(tmp >= prev){
                cnt += (tmp - prev);
            }else{
                cnt += tmp;
            }
            tmp = 1;
            prev = a[i];
        }
    }
    if(tmp >= prev){
        cnt += (tmp - prev);
    }else{
        cnt += tmp;
    }
    cout << cnt << endl;
}

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

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

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

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let s: String = read();
    let mut k: u32 = read();
    let cv: Vec<char> = s.chars().collect();
    let mut ansv: Vec<char> = vec![];
    let l = s.len();
    for i in 0..l - 1 {
        let c = cv[i];
        let t = (('z' as u32) + 1 - (c as u32)) % 26;
        if t > k {
            ansv.push(c);
        } else {
            k -= t;
            ansv.push('a');
        }
    }
    let c = cv[l - 1];
    let k = (k % 26) as u8;
    let tmp = (c as u8 - 'a' as u8 + k) % 26;
    let c = (((c as u8 - 'a' as u8 + k) % 26) + 'a' as u8) as char;
    ansv.push(c);
    let ans: String = ansv.into_iter().collect();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(void) {
  int n;
  cin >> n;
  bool ok = false;
  for(int i = 1; i * i <= n; i++) {
    if(0 == n % i && (n / i) < 10) {
      ok = true;
      break;
    }
  }
  if(ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a)) 
#define pb push_back
#define sz(x) (int)x.size() 
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+10; 

int deg[N];
int main(){
  fast;
  int n,m;
  cin>>n>>m;
  fill(deg,0);

  FOR(i,1,m)
  {
  	int u,v;
  	cin>>u>>v;
  	deg[u]++;
  	deg[v]++;
  }

  FOR(i,1,n)
  {
  	if(deg[i]%2)
  	{
  		cout<<"NO";
  		return 0;
  	}
  }
  cout<<"YES";
  return 0;
}

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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin>>N;
  bool ok = false;
  rep(i,10){
    rep(j,10) {
      if(i*j==N) ok = true; 
    }
  }
  if(ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main() {
    int64_t X;
    cin >> X;

    const long double PI = acos(-1);
    constexpr long double eps = 1e-5;

    long double x = 0, y = 0;
    int64_t curr_x = X;
    for (int64_t K = 1; ; K++) {
        x += cos(curr_x / 180.0 * PI);
        y -= sin(curr_x / 180.0 * PI);

        curr_x += X;

        if (-eps <= x && x <= eps &&  -eps <= y && y <= eps) {
            cout << K << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3964
import sys
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]

N, D = ri_()
X = [ri_() for _ in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        tmp = 0
        for d in range(D):
            tmp += (X[i][d] - X[j][d]) ** 2
        for k in range(1000):
            if k ** 2 == tmp:
                ans += 1
print(ans)

Measured memory_bytes: 38896
n = int(input())
arr = list(map(int, input().split()))
cnt = 0
for i in range(len(arr)):
    for j in range(len(arr) - 1, i, -1):
        if arr[j] < arr[j - 1]:
            arr[j], arr[j - 1] = arr[j - 1], arr[j]
            cnt += 1
print(*arr)
print(cnt)


Measured memory_bytes: 5608
import java.util.*;

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

        if ((a == b && a != c) || (a == c && a != b) || (c == b && a != b) ) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include <cstdio>
#include <algorithm>

int main()
{
	long long a, b, c, k;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
	long long ans = 0;
	ans += std::min(a, k);
	k -= std::min(a, k);
	if (k > 0)
	{
		long long v = std::min(b, k);
		k -= v;
		if (k > 0)
		{
			ans -= k;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
    ll a,b;
    cin >> a >> b;
    if(a==b){
        cout << a << endl;
        return 0;
    }
    ll res;
    if(a%2==0){
        ll n=b-a+1;
        if(n%4==0) res=0;
        else if(n%4==2) res=1;
        else if(n%4==1) res=b;
        else if(n%4==3) res=1^b;
    }
    else{
        ll n=b-a;
        if(n%4==0) res=a;
        else if(n%4==2) res=a^1;
        else if(n%4==1) res=a^b;
        else if(n%4==3) res=a^1^b;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3624
N = int(input())
a = list(map(int, input().split()))

# 約数に2がどれだけ含まれているのかを調べる。
count = 0

for i in range(N):
  # print (i, a[i])
  while a[i] % 2 == 0:
    count += 1
    a[i] = a[i] // 2
    
print(count)
          

Measured memory_bytes: 4148
#include<iostream>
#include<algorithm>
 using namespace std;
 const int maxn=105;
 int a[maxn];
 int main()
 {
 	int n,m,sum=0;
 	scanf("%d%d",&n,&m);
 	for(int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
 	sort(a+1,a+1+n);
 	reverse(a+1,a+1+n);
 	for(int i=1;i<=m;i++){
 		if(4*m*a[i]<sum){
 			cout<<"No"<<endl;
 			return 0;
		 }
	 }
	cout<<"Yes"<<endl;
 }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int gcd(int a, int b){
    while(a != b){
        int c;
        if(a > b){ 
            c = a % b; 
            a = b;
            b = c;
            if(c==0){ break; }
        }else{
            c=a; a=b; b=c;
        }
    }
    return a;
}
int main(void){
    int n;
    cin >> n;
    vector<int> bb(n);
    for(int i=0; i<n; ++i){ cin >> bb[i];   }
    
    if(n==2){
        cout << (bb[0] > bb[1] ? bb[0] : bb[1]) << endl;
        return 0;
    }
    
    vector<int> gcd_front(n-1);
    gcd_front[0] = bb[0];
    vector<int> gcd_back(n-1);
    gcd_back[n-2] = bb[n-1];
    
    for(int i=1; i<n-1; ++i){ gcd_front[i] = gcd(gcd_front[i-1], bb[i]); }
    for(int i=n-2; i>0; --i){ gcd_back[i-1] = gcd(gcd_back[i], bb[i]); }
    
    vector<int> g(n);
    g[0] = gcd_back[0];
    for(int i=0; i<n-2; ++i){ g[i+1] = gcd(gcd_front[i], gcd_back[i+1]); }
    g[n-1] = gcd_front[n-2];
    
    cout << *max_element(g.begin(), g.end()) << endl;
    return 0;
    
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main(){
int a;
int b;
int c;
int h;
int n;
while(cin >>a>>b>>c){
if(a==0&&b==0&&c==0){break;}
cin >>n;
int d[n];
int e[n];
int f[n];
int g[n];
int i[a+b+c];
h=0;
while(h<n){
cin >>d[h];
cin >>e[h];
cin >>f[h];
cin >>g[h];
h=h+1;}
h=0;
while(h<a+b+c){
i[h]=2;
h=h+1;}
h=0;
while(h<n){
if(g[h]==1){i[d[h]-1]=1; i[e[h]-1]=1; i[f[h]-1]=1;}
h=h+1;}
h=0;
while(h<n){
if(i[d[h]-1]==1&&i[e[h]-1]==1&&g[h]==0){i[f[h]-1]=0;}
if(i[f[h]-1]==1&&i[e[h]-1]==1&&g[h]==0){i[d[h]-1]=0;}
if(i[d[h]-1]==1&&i[f[h]-1]==1&&g[h]==0){i[e[h]-1]=0;}
h=h+1;}
h=0;
while(h<a+b+c){
cout <<i[h]<<endl;
h=h+1;}
}}

Measured memory_bytes: 1176
def RL(a):
    if a=='R':
        return 1
    elif a=='L':
        return -1
    else:
        return 0
    
def UD(a):
    if a=='D':
        return 1
    elif a=='U':
        return -1
    else:
        return 0

def printLim(minus_lim, plus_lim, MAX):
    if minus_lim <0:
        print('X|', end='')
    else:
        print('|'+'X'*(minus_lim+1), end='')
    
    print('O'*(plus_lim - minus_lim -1), end='')
    if plus_lim ==MAX:
        print('|X')
    else:
        print('X'*(MAX-plus_lim) + '|')

def isFall(s_data,t_data,MAX,target):
    a = -1
    b = MAX
    for i in range(N-1, -1,-1):
        save = t_data[i]
        if save == 1:
            a-=1
        elif save == -1:
            b+=1
            
        # limit check
        if a < -1:
            a=-1
        if b>MAX:
            b=MAX
        if a==b:
            break
#         printLim(a,b,MAX)

        kill = s_data[i]
#         print(kill, save)
        # A lim
        if kill == -1:
            a +=1
        # B lim
        elif kill == 1:
            b -=1

        # limit check
        if a < -1:
            a=-1
        if b>MAX:
            b=MAX
        if (b-a) ==1:
            break


#         printLim(a,b,MAX)
#     print(a,b)
    
    if a < target < b:
        return False
    else:
        return True




################
H, W, N = map(int,input().split())
orig_y,orig_x = map(int,input().split())
orig_y -=1
orig_x -=1
s = input()
t = input()


flag = isFall([RL(it) for it in s],[RL(it) for it in t],W,orig_x)
flag |= isFall([UD(it) for it in s],[UD(it) for it in t],H,orig_y)
if flag:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 7056
import sys
input = sys.stdin.readline
INF = float('inf')
N, M = map(int, input().split())
cost = [[INF]*N for _ in [0]*N]
to = [set() for _ in [0]*N]
for _ in [0]*M:
    a, b, c = map(int, input().split())
    cost[a][b] = c
    to[b].add(a)

K = 1 << N
dp = [[INF]*N for _ in range(K)]
dp[K-1][0] = 0

for bit in range(K-1, -1, -1):
    for i in range(N):
        tmp = [dp[bit|1<<j][j]+cost[j][i] for j in to[i] if bit>>j&1==0]
        if tmp:
            dist = min(tmp)
            if dp[bit][i] > dist:
                dp[bit][i] = dist

ans = dp[0][0]
print(ans if ans < INF else -1)



Measured memory_bytes: 19820
N,A,B = list(map(int,input().split()))

h=[]
for i in range(N):
    h.append(int(input()))

def jugde(n):
    count = 0
    for i in range(N):
        if (h[i]-B*n)%(A-B)==0:
            count+=max((h[i]-B*n)//(A-B),0)
        else:
            count+=max((h[i]-B*n)//(A-B)+1,0)
    if count<=n:
        return True
    else:
        return False

def bisect(i,j):
    if j-i==1:
        return j
    else:
        if jugde((i+j)//2):
            return bisect(i,(i+j)//2)
        else:
            return bisect((i+j)//2,j)

print(bisect(0,10**9))

Measured memory_bytes: 52312
#include <stdio.h>
int n,k,line[1000000];
int binarysearch(int bw){
    int i,temp,t=1;
    for(i=0,temp=0;i<n;i++){
        if(line[i] > bw)
            return 0;
        if(temp+line[i] > bw){
            t++;
            temp=0;
        }
        temp+=line[i];
    }
    return t<=k;
}
int main(void){
    int left=0,right=1<<31,mid,i;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&line[i]);
    for(right=~right;left<right;){
        mid=(right+left)/2;
        if(binarysearch(mid))
            right=mid;
        else
            left=mid+1;
    }
    printf("%d\n",right);
    return 0;
}

Measured memory_bytes: 984
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from collections import deque,defaultdict,Counter
def main():
    S = input().split()
    S[0] = S[0].lower()
    c = Counter(S)

    often = sorted(list(c.items()),key = lambda x:-x[1])[0][0]
    longest = sorted(list(c.keys()),key = len)[-1]
    print(often,longest)
if __name__ == '__main__':
    main()


Measured memory_bytes: 5956
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

istream& operator>> (istream& a, pii& b) {
    cin >> b.first >> b.second;
    return a;
}

ostream& operator<< (ostream& a, const pii& b) {
    cout << "{" << b.first << ", " << b.second << "}";
    return a;
}

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 100;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e15;
    // const int mod = 2600000069; 
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")  
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

int f(int x, vector<int>& b) {
    if (b[0] > x) return 0;
    if (b.back() <= x) return b.size();
    int l = 1, r = b.size(), mid;
    while (r - l > 1) {
        mid = (l + r) / 2;
        if (b[mid - 1] <= x) l = mid;
        else r = mid;
    }
    return l;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int j = 0; j < m; j++) {
        cin >> b[j];
    }
    for (int i = 1; i < m; i++) {
        b[i] += b[i - 1];
    }
    int ans = 0;
    for (int i = 0; i < m; i++) {
        if (b[i] <= k) {
            chkmax(ans, i + 1);
        }
    }
    int cur = 0;
    for (int i = 0; i < n; i++) {
        cur += a[i];
        if (cur > k) break;
        chkmax(ans, f(k - cur, b) + i + 1);
    }
    cout << ans;
}
/*

*/


Measured memory_bytes: 6424
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n;
    cin >> n;

    vector<LL> p(n+1);
    for(int i = 1; i < n+1; i++){
        cin >> p[i];
    }

    vector<LL> a(n+1);
    a[1] = 1;
    for(int i = 2; i < n+1; i++){
        a[i] = a[i-1] + n;
    }

    vector<LL> b(n+1);

    b[p[1]] = a[n];

    LL pre = a[p[1]] + b[p[1]] + 1;

    for(int i = 2; i < n+1; i++){
        b[p[i]] = pre - a[p[i]];
        pre++;
    }

    for(int i = 1; i < n+1; i++){
        if(i > 1) cout << " ";
        cout << a[i];
    }
    cout << endl;

    for(int i = 1; i < n+1; i++){
        if(i > 1) cout << " ";
        cout << b[i];
    }
    cout << endl;
    
    return 0;
}

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


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

    if(a==b)cout<<c<<endl;
    else if(a==c)cout<<b<<endl;
    else cout<<a<<endl;

    return 0;
}


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

int main() {
    ll N,M;
    cin >> N >> M;
    vector<pair<ll,ll>> A;
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >>b;
        --a;--b;
        A.emplace_back(a,b);
    }
    sort(A.rbegin(),A.rend());
    set<ll> s;
    for(auto P:A){
        auto itr =s.lower_bound(P.first);
        if(itr == s.end()){
            s.insert(P.first);
        }else if(*itr>=P.second){
            s.insert(P.first);
        }
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(a, max(b, c))
#define MIN(x, y, z) min(a, min(b, c))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll X, Y, Z;
  cin >> X >> Y >> Z;
  rep(i, 1000000) {
    ll haba = i * Y + Z * (i + 1);
    if (haba > X) {
      if (i == 0)
        COUT(0);
      else
        COUT(i - 1);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstdio>
#include <cstdlib>

using namespace std;

typedef unsigned long long int ull;

int main(int argc,char** argv) {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << max(0,min(b,d)-max(a,c));
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstdlib>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
using namespace std;

const int N = 8;
array<int, N> idx;
string color[N];

inline int encode(const array<int, N> &a) {
	int res = 0;
	for(const auto &e : a) res = (res * N) + e;
	return res;
}

// a, b, c, d -> b, c, d, a
void rotate(int &a, int &b, int &c, int &d) {
	const int tmp = a;
	a = b;
	b = c;
	c = d;
	d = tmp;
}

void north(array<int, N> &a) {
	rotate(a[0], a[1], a[3], a[2]);
	rotate(a[4], a[6], a[7], a[5]);
}

void east(array<int, N> &a) {
	rotate(a[0], a[6], a[7], a[1]);
	rotate(a[4], a[5], a[3], a[2]);
}

void right(array<int, N> &a) {
	rotate(a[0], a[2], a[4], a[6]);
	rotate(a[1], a[3], a[5], a[7]);
}

bool exist(const unordered_set<int> &s, array<int, N> a) {
	for(int i = 0; i < 4; ++i) {
		for(int j = 0; j < 4; ++j) {
			if(s.count(encode(a))) return true;
			right(a);
		}
		north(a);
	}

	east(a);
	for(int i = 0; i < 4; ++i) {
		if(s.count(encode(a))) return true;
		right(a);
	}

	east(a);
	east(a);
	for(int i = 0; i < 4; ++i) {
		if(s.count(encode(a))) return true;
		right(a);
	}

	return false;
}

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

	while(cin >> color[0]) {
		for(int i = 1; i < N; ++i) {
			cin >> color[i];
		}

		unordered_map<string, int> converter;
		for(int i = 0; i < N; ++i) {
			if(!converter.count(color[i])) {
				converter.insert({color[i], converter.size()});
			}
			idx[i] = converter[color[i]];
		}

		sort(idx.begin(), idx.end());
		unordered_set<int> ans;
		do {
			if(!exist(ans, idx)) {
				ans.insert(encode(idx));
			}
		} while(next_permutation(idx.begin(), idx.end()));

		cout << ans.size() << endl;
	}

	return EXIT_SUCCESS;
}

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

int main(void)
{
	int L, R;
	cin >> L >> R;
	int mmin = 2020;
	for (int i = L; i <= min(L + 2030, R); i++)
	{
		for (int j = i + 1; j <= min(i + 2030, R); j++)
		{
			int val = 1LL * i * j % 2019;
			mmin = min(mmin, val);
		}
	}
	cout << mmin << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

using Float = double;
using Point = complex<Float>;
struct Line{
	Point a,b;
	Line(Point a,Point b) : a(a),b(b){}
};
struct Segment : Line{ Segment(Point a,Point b) : Line(a,b){} };
struct Circle{ Point p; Float r; };

inline bool eq(Float a,Float b) { return abs(a - b) < EPS; }
inline Float dot(const Point &a,const Point &b){ return real(conj(a) * b); }
inline Float cross(const Point &a,const Point &b){ return imag(conj(a) * b); }

namespace std{
	bool operator<(const Point &a,const Point &b){
		return eq(real(a),real(b)) ? imag(a) < imag(b) : real(a) < real(b);
	}
}

Float distance(Point &p1,Point &p2){
    return abs(p1 - p2);
}

bool contain(Circle &c,Point &p){
    return (distance(c.p,p) <= c.r + EPS);
}

vector<Point> crosspoint(const Circle &c1,const Circle &c2){
	vector<Point> ret;
	Point d = c2.p - c1.p;
	Float rcosa = (c1.r * c1.r + norm(d) - c2.r * c2.r) / (abs(d) * 2);
	if(eq(0,abs(d)) || abs(rcosa) > c1.r) return ret;
	Float rsina = sqrt(c1.r * c1.r - rcosa * rcosa);
	ret.push_back(c1.p + d / abs(d) * Point(rcosa,rsina));
	if(!eq(rcosa,c1.r)) ret.push_back(c1.p + d / abs(d) * Point(rcosa,-rsina));
	return ret;
}

Point ps[70];
double c[70];
int n,k;

bool isOK(double x){
	vector<Point> cand;
	vector<Circle> cs;
	for(int i = 0;i < n;i++){
		cs.push_back({ps[i],x / c[i]});
		cand.push_back(ps[i]);
	}
	for(int i = 0;i < n;i++){
		for(int j = i + 1;j < n;j++){
			auto v = crosspoint(cs[i],cs[j]);
			cand.insert(cand.end(),all(v));
		}
	}
	for(auto &p : cand){
		int t = 0;
		for(int i = 0;i < n;i++){
			if(contain(cs[i],p)) t++;
		}
		if(t >= k) return true;
	}
	return false;
}

signed main(){
	cin >> n >> k;
	for(int i = 0;i < n;i++){
		double a,b;
		cin >> a >> b >> c[i];
		ps[i] = Point(a,b);
	}
	double ng = 0,ok = INF;
	for(int i = 0;i < 100;i++){
		double mid = (ng + ok) / 2;
		if(isOK(mid)) ok = mid;
		else ng = mid;
	}
	printf("%.14lf\n",ok);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf 1e18
#define g(x) cout<<x<<" "<<endl;
#define gg(x,y) cout<<x<<" & "<<y<<" "<<endl
#define jam(t) cout<<"Case #"<<t<<": "
#define ggg(x,y,z) cout<<x<<" & "<<y<<" & "<<z<<" "<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);
#define mod 1000000007ll
#define sz 400005
#define bitcnt(x) __builtin_popcountll(x)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}



void solve(){
    ll k;
    cin >> k;
    ll a,b;
    cin >> a >> b;
    if(b%k==0||a%k==0){
         g("OK");
         return;
    }
    if(b/k-a/k==0)
    {
        g("NG");

    }
    else
    {
        g("OK");
    }
}
int main()
{
#ifndef ONLINE_JUDGE
input_from_file
#endif
 
    FASTIO
    cin.tie(NULL);
    fflush(stdout);
    ll t = 1;
    //cin >> t;
    for(ll tcase = 1;tcase <= t;tcase++){
        solve();
        
    }
return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
//#include<string.h>
char S[200001],T[200001];
int main()
{

    scanf("%s %s",&S,&T);
    int i,p=0,length1,length2,j;
    length1=strlen(S);
    length2=strlen(T);
    for(i=0; i<length1; i++)
    {
        if(S[i]!=T[i])
        {
            p++;

        }


    }



    printf("%d\n",p);





    return 0;
}


Measured memory_bytes: 2120
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<int> p(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &p[i]);
    }
    int cnt=0;
    for(i=0; i<n-2; i++) {
        if(p[i]>p[i+1] && p[i+1]>p[i+2]) {
            cnt++;
        }
        else if(p[i]<p[i+1] && p[i+1]<p[i+2]) {
            cnt++;
        }
    }
    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int N,K,c[510][510];

int main(){
	srand(time(NULL));
	cin>>N>>K;
	rep(i,K)rep(j,N/2)cin>>c[i][j],c[i][j]--;
	while(1){
		int ans[1010];
		rep(i,N)ans[i]=rand()%2;
		int ok=1;
		rep(i,K){
			int s=0;
			rep(j,N/2)s+=ans[c[i][j]];
			if(s<N/8 || 3*N/8<s){
				ok=0;break;
			}
		}
		if(ok){
			rep(i,N)cout<<ans[i];
			cout<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1864
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string o,e;
    cin>>o>>e;
    for(int i=0;i<(o.size()+e.size());i++)
    {
        if(i%2==0)
            cout<<o[i/2];
        else
            cout<<e[i/2];
    }
    return 0;
}


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

int main(){
  int n , a;
  cin >> n;
  a = n / 1000;
  if (n % 1000 == 0) {
    cout << 0 << endl;
  } else {
    cout << (a + 1) * 1000 - n << endl;
  }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[105];
signed main()
{
	int n,i,j,k,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			for(k=1;k<=n;k++)
				if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i])
					ans++;
	cout<<ans/6;
	return 0;
}

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

long cnt_balls(long range_ball, long blue, long red){
    long balls=blue+red;
    long cnt_set=range_ball/balls;
    long cnt_left=range_ball%balls;
    return cnt_set*blue+min(blue,cnt_left);
}

int main(){
    long N,A,B; cin >> N >> A >> B;
    cout << cnt_balls(N,A,B) << endl;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

n = int(input())
y = str(input())
# n = 10**5
# y  = '1' * n
ones = 0
for i in y:
    if i == '1': ones += 1
x = int(y, 2)

def get(z):
    ret = 0
    while z > 0:
        if z % 2 == 1:
            ret += 1
        z //= 2
    return ret

out = []
rem1 = -1
rem2 = -1
if ones > 1:
    rem1 = x % (ones - 1)
if ones < n:
    rem2 = x % (ones + 1)

def calc(p, m):
    if p <= 2:
        return (1 << p) % m
    a = p // 2
    ret = calc(a, m)
    ret = (ret * ret) % m
    if p % 2 == 1:
        ret = (ret * 2) % m
    return ret



for i in range(n):
    # tmp = (1 << i) * -1
    o = ones - 1
    if y[n - i - 1] == '0':
        # tmp = 1 << i
        o = ones + 1

    # tmp = tmp + x
    if o == 0:
        out.append(0)
        continue
    if o == 1:
        out.append(1)
        continue


    if o > ones:
        tmp = (rem2 % o + calc(i, o)) % o
    else:
        tmp = (rem1 % o - calc(i, o) + o) % o


    cnt = 1
    while tmp > 0:
        tmp %= get(tmp)
        cnt += 1

    out.append(cnt)

for i in range(n):
    print(out[n-i-1])

Measured memory_bytes: 11172
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		long[] a = new long[n];
		
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		
		long x = 0;
		long sum = a[0];
		if(sum <= 0) {
			x = 1 - sum;
			sum = 1;
		}
		
		long x1 = seq(sum, x, a);
		
		x = 0;
		long sum2 = a[0];
		if(sum2 >= 0) {
			x = sum2 + 1;
			sum2 = -1;
		}
		
		long x2 = seq(sum2, x, a);
		
		System.out.println(Math.min(x1, x2));
	}
	
	public static long seq(long sum, long x, long[] a) {
		long count = 0;
		
		for(int i = 1; i < a.length; i++) {
			if(sum * (sum + a[i]) >= 0) {
				if(sum < 0) {
					count = -sum - a[i] + 1;
				} else {
					count = -sum - a[i] - 1;
				}
			}
			sum += a[i] + count;
			x += Math.abs(count);
			count = 0;
		}
		return x;
	}
	
}


Measured memory_bytes: 64468
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		a: usize,
		b: usize,
		c: usize,
		d: usize,
	}

	println!("{}", min(a,b)+min(c,d));
}



Measured memory_bytes: 2068
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
const ll MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x);
        }
        p = p >> 1;
        x = (x*x);
    }
    return res;
}
int w,h;
char arr[1005][1005];
int dp[1005][1005];
int solve(int i, int j) {
    if (arr[i][j] != '.')
        return 0;
    if (i == h - 1 && j == w - 1)
        return 1;
    if (dp[i][j] != -1) {
        return dp[i][j];
    }
    return dp[i][j] = (solve(i + 1, j) + solve(i, j + 1))%MOD;
}

int main() {
    IO;
    cin >> h >> w;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) {
            cin >> arr[i][j];
            dp[i][j] = -1;
        }
    cout << solve(0,0);
    return 0;
}


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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	int N,sw = 1;
  cin >> N;
  vector<int> stairs(N);
  froop1(0,N){
cin >> stairs.at(i);
  }
  froop1(0,N - 1){
    if(stairs.at(i) <= stairs.at(i + 1) - 1){
      stairs.at(i + 1)--;
    }
    if(stairs.at(i) > stairs.at(i + 1)){
      sw = 0;
      break;
    }
  }
  if(sw == 0){
cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

return 0;
}

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

int main() {
  int n, m, k; std::cin >> n >> m >> k;
  std::vector<long long> a(n);
  std::vector<long long> b(m);
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  for (int i = 0; i < m; ++i) std::cin >> b[i];

  int ans = 0; // 最大冊数
  int time = 0; // 読書の所要時間
  int a_idx = 0; // 次に読むほんのidx(開いている)
  int b_idx = 0;  
  
  /* まずは机Aからのみ読む */
  while (a_idx < n && (time + a[a_idx]) <= k) {
    time += a[a_idx++];
    ans = a_idx;
  }
  /* 残り時間でBの本を読む */
  while (b_idx < m && (time + b[b_idx]) <= k) {
    time += b[b_idx++];
    ans = std::max(ans, a_idx+b_idx);
  } 

  /* Aの本を読むのを辞め，Bの本をどんどん読んでいく */
  while (a_idx--) {
    /* Aの本を読むのを辞める */
    time -= a[a_idx];
    // --ans;

    /* Bの本を読み進める */
    while (b_idx < m && (time + b[b_idx]) <= k) {
      time += b[b_idx++];
      // ans = std::max(ans, a_idx+b_idx);
    } 
    ans = std::max(ans, a_idx+b_idx);
  }


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


Measured memory_bytes: 6312
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  char A;
  char B;
  int C=1;
  string S;
  cin >> N >> S;
  B = S.at(0);
  for(int i=0; i<S.size() ; i++)
  {
    A = S.at(i);
    if(A!=B)
    {
      C++;
      B=A;
    }
  }
  cout << C << endl;
}
      

Measured memory_bytes: 3700
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);
const bool DEBUG = 0;

int main()
{
	int x0, x1, y0, y1;
	int i, j;

	si(x0);	si(y0);	si(x1);	si(y1);

	fl(i,0,abs(y0 - y1))	printf("U");
	fl(i,0,abs(x0 - x1))	printf("R");

	fl(i,0,abs(y0 - y1))	printf("D");
	fl(i,0,abs(x0 - x1))	printf("L");

	printf("L");

	fl(i,0,abs(y0 - y1) + 1)	printf("U");
	fl(i,0,abs(x0 - x1) + 1)	printf("R");

	printf("D");
	printf("R");

	fl(i,0,abs(y0 - y1) + 1)	printf("D");
	fl(i,0,abs(x0 - x1) + 1)	printf("L");

	printf("U");


	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int MAXN = 100005;
const int mod = 1e9 + 7;

int n, a[MAXN];

int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		int x; scanf("%d",&x);
		a[x]++;
	}
	vector<int> seq;
	int ret = 0;
	for(int i=1; i<MAXN; i++){
		if(a[i] >= 3){
			ret += (a[i] - 1) / 2;
			a[i] -= ((a[i] - 1) / 2) * 2;
		}
		if(a[i]) seq.push_back(a[i]);
	}
	if(count(seq.begin(), seq.end(), 2)){
		int c = count(seq.begin(), seq.end(), 2);
		ret += ((c + 1) / 2);
	}
	ret *= 2;
	cout << n - ret << endl;
}



Measured memory_bytes: 1276
#include<stdio.h>
int main()
{
	int y,m,d;
	while(scanf("%d%d%d",&y,&m,&d)!=EOF){
		if(y<1868){
			printf("pre-meiji\n");
		}else if(y==1868){
			if(m<9||(m==9&&d<8)){
				printf("pre-meiji\n");
			}else{
				printf("meiji %d %d %d\n",1,m,d);
			}
		}else if(y>1868&&y<1912){
			printf("meiji %d %d %d\n",y-1867,m,d);
		}else if(y==1912){
			if(m<7||(m==7&&d<30)){
				printf("meiji %d %d %d\n",y-1867,m,d);
			}else{
				printf("taisho %d %d %d\n",1,m,d);
			}
		}else if(y>1912&&y<1926){
			printf("taisho %d %d %d\n",y-1911,m,d);
		}else if(y==1926){
			if(m<12||(m==12&&d<25)){
				printf("taisho %d %d %d\n",y-1911,m,d);
			}else{
				printf("showa %d %d %d\n",1,m,d);
			}
		}else if(y>1926&&y<1989){
			printf("showa %d %d %d\n",y-1925,m,d);
		}else if(y==1989){
			if(m<1||(m==1&&d<8)){
				printf("showa %d %d %d\n",y-1925,m,d);
			}else{
				printf("heisei %d %d %d\n",1,m,d);
			}
		}else{
			printf("heisei %d %d %d\n",y-1988,m,d);
		}
	}
	return 0;
}

Measured memory_bytes: 2572
#include <cstdio>
#include <algorithm>

int x, a, b;

int main(){
	scanf("%d %d %d", &x, &a, &b);
	if(std::max(x, a) - std::min(x, a) < std::max(x, b) - std::min(x, b))
		printf("A\n");
	else printf("B\n");
}

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

int main() {
  int N;
  cin >> N;
  if(N / 100 <= 12 && N / 100 != 0) {
    if(N % 100 <= 12 && N % 100 != 0) {
      cout << "AMBIGUOUS" << endl;
    }
    else {
      cout << "MMYY" << endl;
    }
  }
  else {
    if(N % 100 <= 12 && N % 100 != 0) {
      cout << "YYMM" << endl;
    }
    else {
      cout << "NA" << endl;
    }
  }
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto n = readln.chomp.to!int;
  auto res = new int[](n);
  auto a = readln.chomp.split.to!(int[]);
  foreach (i; 0..n-1) {
    res[a[i]-1]++;
  }
  foreach (i; 0..n) {
    res[i].writeln;
  }
}


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

string s1, s2;

string solve() {
    s1 += '.';
    s2 += '.';
    int i = 0, j = 0;
    int qt1 = 0, qt2 = 0;
    int change = 0;
    while (i < s1.length() || j < s2.length()) {
        if (s1[i] == '"') qt1 = 1;
        if (s2[j] == '"') qt2 = 1;

        string t1 = "";
        if (qt1) {
            while (s1[++i] != '"') t1 += s1[i];
            qt1 = 0;
        }
        string t2 = "";
        if (qt2) {
            while (s2[++j] != '"') t2 += s2[j];
            qt2 = 0;
        }
        if (t1 != t2) {
          ++change;
        } else if (s1[i] != s2[j]) {
            return "DIFFERENT";
        }
        ++i;
        ++j;
    }
    if (change == 0) {
      return "IDENTICAL";
    } else if (change == 1) {
      return "CLOSE";
    } else {
      return "DIFFERENT";
    }
}

int main() {
    while (cin >> s1, s1[0] != '.') {
      cin >> s2;
      cout << solve() << endl;
    }
}



Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cstring>

#define ll long long
const int maxn=10000+5;

using namespace std;

int cnt[30]={0};

int main() {
    char s[200];
    bool flag = true;
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++)cnt[int(s[i]-'a')]++;
    for(int i=0;i<26;i++)if(cnt[i]%2!=0)flag= false;
    if(flag)printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	static int M = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long ans=0,pre1=2,pre2=1;
		for(int i=2;i<=num;i++) {
			long xy=pre1+pre2;
			pre1= pre2;
			pre2=xy;
			ans=xy;
		}
		System.out.println(num==0?(2):(num==1)?1:ans);
	}
}

Measured memory_bytes: 23636
a, b = gets.split.map(&:to_i)
s = gets.chomp
correct = true
for i in 0...(a + b + 1) do
  case i
  when a
    correct = false if s[i] != "-"
  else
    correct = false if !"0123456789".include?(s[i])
  end
end
puts correct ? "Yes" : "No"


Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

void solve(){
  int a; string s; cin >> a >> s;
  if(a >= 3200) cout << s << endl;
  else cout << "red\n";
  return;
}

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


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int n,p[30];
    int i;
    int ans=0;
    scanf("%d",&n);

    for(int i=0;i<n;i++)
    {
        scanf("%d",p+i);
        if(i>1)
        {
            if(((p[i-2]>p[i-1])&&(p[i-1]>p[i]))||((p[i-2]<p[i-1])&&(p[i-1]<p[i])))ans++;
        }
    }
    printf("%d",ans);
}



Measured memory_bytes: 128
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    S = NI()
    
    dp = [[0 for _ in range(2010)] for _ in range(2010)]

    
    for k in range(1,2010):
        dp[0][k] = 1

    
    for i in range(1,2010):
        cnt = 0
        for j in range(0,2010):
            cnt += dp[i-1][j]
            dp[i][j] = cnt%MOD

    ans = 0
    for s in range(1,S//3+1):
        ans += dp[S-s*3][s]%MOD
        ans = ans%MOD
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 105716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


const int MAX = 510000;
const int mod = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

int main(){
  int n;cin>>n;
  int p[n];rep(i,n)cin>>p[i];
  int ctr=0;
  rep(i,n-2){
    if(p[i]>p[i+1]){
      if(p[i+2]<p[i+1])ctr++;
    }
    else{
      if(p[i+2]>p[i+1])ctr++;
    }
  }
  cout<<ctr<<endl;
}


Measured memory_bytes: 256