akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


pair<int,int> seg[800005];
int lz[800005];

void build(int ver,int tl,int tr)
{
	if(tl>tr)
		return ;
	else if(tl==tr)
	{
		lz[ver]=0;
		seg[ver]={0,tl};
	}
	else
	{
		int tm=(tl+tr)/2;
		build(2*ver,tl,tm);
		build(2*ver+1,tm+1,tr);
		seg[ver]=max(seg[2*ver],seg[2*ver+1]);
	}	
}

void push(int ver,int tm,int tr)
{
	lz[2*ver]=lz[ver];
	lz[2*ver+1]=lz[ver];
	seg[2*ver].first=0;
	seg[2*ver].second=tm;
	seg[2*ver+1].first=0;
	seg[2*ver+1].second=tr;
	lz[ver]=0;
}

void upd_pos(int ver,int tl,int tr,int pos,int val,int mid)
{
	if(tl>tr)
		return ;
	else if(tl==tr)
	{
		seg[ver].first+=val;
		if(seg[ver].first==mid)
			seg[ver].second=0;
	}
	else
	{
		int tm=(tl+tr)/2;
		if(lz[ver])
			push(ver,tm,tr);
		if(tm>=pos)
			upd_pos(2*ver,tl,tm,pos,val,mid);
		else
			upd_pos(2*ver+1,tm+1,tr,pos,val,mid);
		if(seg[2*ver+1].first<mid)
			seg[ver]=seg[2*ver+1];
		else
			seg[ver]=seg[2*ver];
	}	
}

void upd_lz(int ver,int tl,int tr,int l,int r,int mid)
{
	if(tl>tr||l>r||tr<l||r<tl)
		return ;
	else if(tl==l&&tr==r)
	{
		seg[ver].first=0;
		seg[ver].second=tr;
		lz[ver]=1;
	}	
	else
	{
		int tm=(tl+tr)/2;
		if(lz[ver])
			push(ver,tm,tr);
		upd_lz(2*ver,tl,tm,l,min(tm,r),mid);
		upd_lz(2*ver+1,tm+1,tr,max(tm+1,l),r,mid);
		if(seg[2*ver+1].first<mid)
			seg[ver]=seg[2*ver+1];
		else
			seg[ver]=seg[2*ver];
	}	
}

int get(int ver,int tl,int tr,int l,int r,int mid)
{
	if(tl>tr||l>r||tr<l||r<tl)
		return 0;
	else if(tl==l&&tr==r)
	{
		if(seg[ver].first==mid)
			return 0;			
		return seg[ver].second;
	}
	else
	{
		int tm=(tl+tr)/2;
		if(lz[ver])
			push(ver,tm,tr);

		if(seg[2*ver+1].first<mid)
			seg[ver]=seg[2*ver+1];
		else
			seg[ver]=seg[2*ver];
		return max(get(2*ver,tl,tm,l,min(tm,r),mid),get(2*ver+1,tm+1,tr,max(tm+1,l),r,mid));
	}	
}


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

#ifndef ONLINE_JUDGE
	if(fopen("INPUT.txt","r"))
	{
	freopen ("INPUT.txt" , "r" , stdin);
	freopen ("OUTPUT.txt" , "w" , stdout);
	}
#endif  

	int n;
	cin>>n;
	vector<int>temp;
	int a[n+1];
	a[0]=1e10;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]>a[i-1])
			continue;
		temp.push_back(a[i]);
	}

	set<int>s;
	map<int,int>mm;
	for(auto i:temp)
		s.insert(i);
	int cnt=0;
	for(auto i:s)
		mm[i]=++cnt;
	int sz=temp.size();
	// for(int i=0;i<sz;i++)
	// 	temp[i]=mm[temp[i]];
	
	int l=0,r=200000;
	int mn=2000000;
	// cout<<500<<'\n';
	// for(int i=1000;i>=2;i-=2)
	// {
	// 	cout<<i<<" ";		
	// }
	while (l<=r)
	{
		int mid=l+(r-l)/2;
		int sz=temp.size();
		build(1,1,cnt);
		bool flag=true;
		for(int i=1;i<sz;i++)
		{
			int z=get(1,1,cnt,1,temp[i],mid);
			if(z==0)
			{
				flag=false;
				break;
			}
			upd_pos(1,1,cnt,z,1,mid);
			upd_lz(1,1,cnt,z+1,cnt,mid);
		}
		if(flag)
		{
			r=mid-1;
			mn=min(mn,mid+1);
		}
		else
		{
			l=mid+1;
		}		
	}

	cout<<mn;


}


Measured memory_bytes: 40304
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    printf("vowel\n");
  } else {
    printf("consonant\n");
  }
}

Measured memory_bytes: 3068
n = int(input())
A =[int(i) for i in input().split()]
B =[int(i) for i in input().split()]
C =[int(i) for i in input().split()]

total=0
for i in range(len(A)):
  total += B[i]
  if i >=1:
    if A[i-1]+1==A[i]:
      k=A[i-1]
      total+= C[k-1]
    
  
print(total)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a<b){
		if(b<c){
			printf("Yes\n");
		}else printf("No\n");
	}else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 580
{-# LANGUAGE FlexibleContexts, BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Control.Applicative
import Text.Printf


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

prints :: Show a => [a] -> IO ()
prints as = putStrLn $ concat $ intersperse " " $ map show as

main = do
    t <- getLine
    readInt
    inp <- map words . lines <$> getContents
    let f ((q:param):qs) t = case q of
            "replace" ->
                let [a', b', s] = param
                    a = read a'
                    b = read b'
                in f qs $ take a t ++ s ++ drop (b+1) t
            "reverse" ->
                let [a, b] = read <$> param
                in f qs $ take a t ++ reverse (drop a $ take (b+1) t) ++ drop (b+1) t
            "print" ->
                let [a, b] = read <$> param
                in putStrLn (drop a $ take (b+1) t) >> f qs t
        f _ _ = return ()
    f inp t


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

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b+c){
    cout << "Yes" << endl;
  }
  else if(b==a+c){
    cout << "Yes" << endl;
  }
  else if(c==b+a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;
const int INF = 1000100100;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n; cin >> n;
    int a[n], b[n], c[n];
    rep(i,n) cin >> a[i] >> b[i] >> c[i];

    int dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for(int i=1; i<n; i++){
        rep(j,3){
            if(j == 0) dp[i][j] = max(dp[i-1][1]+a[i], dp[i-1][2]+a[i]);
            else if(j == 1) dp[i][j] = max(dp[i-1][0]+b[i], dp[i-1][2]+b[i]);
            else dp[i][j] = max(dp[i-1][0]+c[i], dp[i-1][1]+c[i]);
        }
    }
    int ans = 0;
    rep(j,3){
        ans = max(ans, dp[n-1][j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5948
o, e = input(), input()
d = len(o) - len(e)

ans = ""
if  d == 0:
    for i in range(len(o)):
        ans += o[i]
        ans += e[i]
else:
    for i in range(len(e)):
        ans += o[i]
        ans += e[i]
    ans += o[-1]

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=200000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,a[N];

int main()
{
    n=read();
    rep(i,1,n) a[i]=read();
    ll ans=0;
    if (a[1]) {puts("-1");return 0;}
    rep(i,2,n)
    {
        if (a[i]-a[i-1]>1) {puts("-1");return 0;}
        else if (a[i]==a[i-1]+1) ans++;
        else ans+=a[i];
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <utility>

using namespace std;

#define int long long

signed main() {
  string s;
  cin >> s;
  vector<pair<char, int>> sections = {{'>', 1}};
  s += ' ';
  char prev = s[0];
  int length = 0;
  for (char c : s) {
    if (c != prev) {
      sections.emplace_back(prev, length);
      prev = c;
      length = 1;
    }
    else length++;
  }
  if (sections.back().first == '<')
    sections.emplace_back('>', 1);
  int total = 0;
  for (auto it = begin(sections) + 1; it != end(sections); it++) {
    if (it->first == '<') continue;
    int llen = (it - 1)->second, rlen = it->second;
    if (llen > rlen)
      total += (llen * (llen + 1) + rlen * (rlen - 1)) / 2;
    else
      total += (llen * (llen - 1) + rlen * (rlen + 1)) / 2;
  }
  cout << total;
}


Measured memory_bytes: 6520
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;


int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> nums(n);
rep(i,n)
    cin >> nums[i];
ll ans = 0;
vector<ll> L(n + 1),R(n + 1);
L[0] = nums[0];
R[n] = nums[n - 1];
rep(i,n){
    L[i + 1] = gcd(L[i],nums[i]);
}
rep(i,n){
    R[n - 1 - i] = gcd(R[n - i],nums[n - 1 - i]);
}
L[0] = 0;
R[n] = 0;
rep(i,n){
    ans = max(ans,gcd(L[i],R[i + 1]));
}
cout << ans << endl;
}

Measured memory_bytes: 5556
def main():
    dist = []
    import numpy as np
    from collections import deque
    n, x, y = map(int,input().split())
    g = [[] for _ in range(n)] 
    for i in range(n-1):

        g[i] += i+1,
        g[i+1] += i,
    g[x-1] += y-1,
    g[y-1] += x-1,
    a = [0]*n
    for start in range(n):
        d = [-1] * n
        d[start] = 0
        q = deque([start])
        add,pop=q.append,q.popleft
        while q:
            v = pop()
            for nv in g[v]:
                if d[nv] < 0:
                    d[nv] = d[v]+1
                    add(nv)
        for i in d:
            a[i] += 1
    #     dist.append(d)
    # dist = np.array(dist).flatten()
    # for i in range(1,n):
    #     print(int(np.count_nonzero(dist==i)/2))
    # for i in range(1,n):
    #     print(int(a[i]/2))
    print(' '.join(str(i//2) for i in a[1:]))
main()

Measured memory_bytes: 14484
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		String b = scanner.next();

		scanner.close();

		List<Character> AGTC = new ArrayList<Character>();
		AGTC.add('A');
		AGTC.add('G');
		AGTC.add('T');
		AGTC.add('C');

		int matchlength = 0;
		int maxlength = 0;

		for (int i = 0; i < b.length(); i++) {
			char c = b.charAt(i);
			if (AGTC.contains(c)) {
				matchlength++;
			} else {
				if (maxlength < matchlength) {
					maxlength = matchlength;
				}
				matchlength = 0;
			}
		}

		if (maxlength < matchlength) {
			System.out.println(matchlength);
		} else {
			System.out.println(maxlength);
		}
	}

}

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

using namespace std;

int main() {
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
        int n;
        scanf("%d", &n);
        vector<long long> a(n + 10);
        for (int i = 1; i <= n; i++) {
                scanf("%lld", &a[i]);
        }
        vector<vector<long long>> dp(n + 10, vector<long long>(2, 0LL));
        dp[1][0] = a[1];
        dp[2][1] = -a[1] - a[2];
        dp[2][0] = a[1] + a[2];
        for (int i = 3; i <= n; i++) {
                dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + a[i];
                long long fi = (i == 3 ? dp[i - 2][0] - a[i - 1] - a[i] : max(dp[i - 2][0], dp[i - 2][1]) - a[i - 1] - a[i]);
                dp[i][1] = max(fi, dp[i - 1][1] + 2LL * a[i - 1] - a[i]);
//                printf("%d %lld %lld\n", i, dp[i][0], dp[i][1]);
        }
        printf("%lld\n", max(dp[n][0], dp[n][1]));
        return 0;
}


Measured memory_bytes: 6528
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
#define INF (1<<29)


int main(){
    double r,g;
    cin>>r>>g;
    cout<<(2*g-r)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define RED 0
#define BLUE 1
#define GREEN 2

int n,Mtw[N][N];
int colortw[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;
  colortw[u] = BLUE;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(Mtw[u][v]==0)continue;
    if(colortw[v]==RED){
      dfs_visit(v);
    }
  }
  colortw[u]=GREEN;
  f[u]=++tt;
}

void dfs(){
  int u;
  for(u=0;u<n;u++)colortw[u]=RED;
  tt=0;

  for(u=0;u<n;u++){
    if(colortw[u]==RED)dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u,v,k,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)Mtw[i][j]=0;
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      Mtw[u][v]=1;
    }
  }

  dfs();

  return 0;
}



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

int main(){

    int a, b;

    cin>>a>>b;

    string s;

    cin>>s;

    bool flag = true;

    int sz = a+b+1;

    if(sz!= s.size()) flag =false;

    if(flag){

        for(int i = 0; i<s.size(); i++){

            if(i==a) {
                if(s[i]!='-') flag = false;

            }

            else{
                if(s[i]>='0' && s[i]<='9') continue;
                else flag = false;

            }

        }

    }

    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


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

int main(int argc, char const *argv[]) {
  string s;
  cin>>s;
  int value=700;
  for(int i=0;i<3;i++){
    if(s[i]=='o') value+=100;
  }
  cout<<value<<endl;
  return 0;
}


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

int main(){
  int n,m;
  string S,T;
  char s[110],t[110];
  cin>>S>>T;
  n=S.length();
  m=T.length();
  fr(i,n) s[i]=S[i];
  fr(i,m) t[i]=T[i];
  sort(s,s+n);
  sort(t,t+m);
  S="";
  T="";
  fr(i,n) S+=s[i];
  fr(i,m) T+=t[m-1-i];
  cout<<(S<T?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
fn main() {
    let v = read_vec::<usize>();
    let h = v[0];
    let w = v[1];

    let mut t = vec![vec!['.'; w + 2]; h + 2];
    for i in 0..h {
        let line = read::<String>().chars().collect::<Vec<_>>();
        for j in 0..w {
            t[i + 1][j + 1] = line[j];
        }
    }

    for i in 1..h + 1 {
        for j in 1..w + 1 {
            if t[i][j] == '#'
                && t[i - 1][j] == '.'
                && t[i + 1][j] == '.'
                && t[i][j - 1] == '.'
                && t[i][j + 1] == '.' {
                yn(false);
                return;
            }
        }
    }
    yn(true);
}

#[allow(dead_code)]
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()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
from sys import stdin
from heapq import heapify, heappop, heappush
from bisect import bisect_right

N, M = map(int, stdin.readline().split())
AB = [None]*N
for i in range(N):
    AB[i] = list(map(int, stdin.readline().split()))
AB.sort()

salary = 0
hq = []
j = 0
for i in range(1, M+1):
    while j < N and AB[j][0] == i:
        heappush(hq, -AB[j][1])
        j += 1
    if hq:
        salary -= heappop(hq)
print(salary)

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  rep(i, h) {
    rep(j, w) {
      cin >> a[i][j];
    }
  }
  rep(i, w + 2) {
    cout << "#";
  }
  cout << endl;
  rep(i, h) {
    cout << "#";
    rep(j, w) {
      cout << a[i][j];
    }
    cout << "#" << endl;
  }
  rep(i, w + 2) {
    cout << "#";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
long long op[100005];
int n;
long long sum = 0;
int main()
{
    scanf("%d", &n);
    for (int i = 1, x; i <= n; i++) {
        scanf("%d", &x);
        op[x] += x;
        sum += x;
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int a, b;
        scanf("%d%d", &a, &b);
        long long tmp = op[a] / a * b;
        sum += tmp - op[a];
        op[b] += op[a] / a * b;
        op[a] = 0;
        printf("%lld\n", sum);
    }
    return 0;
}

Measured memory_bytes: 4496
#include <stdio.h>
int main(){

  int c1,c5,c10,c50,c100,c500,sum,i;

  scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);

  sum=c1*1+c5*5+c10*10+c50*50+c100*100+c500*500;

  if(sum >= 1000){

    printf("1\n");

  } else {

    printf("0\n");

  }

  return 0;

}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> k(n), p(m);
	vector<vector<int>> s(m);
	rep (i, m) {
		cin >> k[i];
		rep(j, k[i]) {
			int tmp;
			cin >> tmp;
			tmp--;
			s[i].push_back(tmp);
		}
	}
	rep(i, m) cin >> p[i];
	int ans = 0;
	for(int bit = 0; bit < (1<<n); bit++) {
		bool ok = true;
		rep(i, m) {
			bool now = 0;
			rep(j, k[i]) {
				if(bit & 1<<s[i][j]) now ^= 1;
			}
			if(p[i] != now) ok = false;
		}
		if(ok) ans++;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// C - /\/\/\/
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
using vi = vector<int>;

int main(){
	int N; cin>>N;
	vector<vi> EO(2,vi(100000));//[e|o][value]<count>
	vi eoV(2),eo1(2),eo2(2);//[e|o]
	rp(i, 0, N){
		int n,v; scanf("%d",&v); v--,n=i&1;
		EO[n][v]++;
		if(EO[n][v] > eo1[n]){ eo1[n] = EO[n][v]; eoV[n] = v+1; }
		else if(EO[n][v] > eo2[n]) eo2[n] = EO[n][v];
	}
	cout<< N - (eoV[0]!=eoV[1]? eo1[0]+eo1[1]: max(eo1[0]+eo2[1], eo2[0]+eo1[1])) <<endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int cnt[100010];
signed main(void)
{
  int n;
  cin >> n;
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    cnt[a]++;
    cnt[b+1]--;
  }
  FOR(i, 1, 100001) cnt[i] += cnt[i-1];
  //REP(i, 10) cout << cnt[i] << " "; cout << endl;
  int ret = 0;
  FOR(i, 0, n+2) {
    //cout << cnt[i] << " " << i << endl;
    if(cnt[i] >= i-1) {
      ret = i-1;
    }
  }
  cout << ret << endl;
  return 0;
}

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

typedef long long ll;
const int INF = 1e9;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int h,w;
	cin>>h>>w;
	vector<vector<char>> grid(h, vector<char>(w)); 
	vector<vector<int>> blockedCount(h, vector<int>(w)); 
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin>>grid[i][j];
		}
	}
	if (grid[0][0] == '#'){
		blockedCount[0][0] = 1;
	}else{
		blockedCount[0][0] = 0;
	}
	for (int i = 1; i < h; i++) {
		if (grid[i][0] == '#' && grid[i-1][0] == '.'){
			blockedCount[i][0] = blockedCount[i-1][0] + 1;
		}else{
			blockedCount[i][0] = blockedCount[i-1][0];
		}
	}
	for (int i = 1; i < w; i++) {
		if (grid[0][i] == '#' && grid[0][i-1] == '.'){
			blockedCount[0][i] = blockedCount[0][i-1] + 1;
		}else{
			blockedCount[0][i] = blockedCount[0][i-1];
		}
	}
	for (int i = 1; i < h; i++) {
		for (int j = 1; j < w; j++) {
			int top;
			int left;
			if (grid[i][j] == '#' && grid[i][j-1] == '.'){
				top = blockedCount[i][j-1] + 1;
			}else{
				top = blockedCount[i][j-1];
			}
			if (grid[i][j] == '#' && grid[i-1][j] == '.'){
				left = blockedCount[i-1][j] + 1;
			}else{
				left = blockedCount[i-1][j];
			}
			blockedCount[i][j] = min(top,left);
		}
	}
	// for (int i = 0; i < h; i++) {
	// 	for (int j = 0; j < w; j++) {
	// 		cout<<blockedCount[i][j];
	// 	}
	// 	cout<<'\n';
	// }
	cout<<blockedCount[h-1][w-1]<<'\n';
	return 0;
}

Measured memory_bytes: 384
from sys import stdin

N,*datas = [int(i) for i in stdin.readlines()]
now_max = max(datas[1:])
max_index = (N-1) - list(reversed(datas)).index(now_max)
_min = min(datas)
min_index = datas.index(_min)

if max_index > min_index:
    diff = now_max - _min
else:
    diff = now_max - datas[0]
    
    for i in range(1,N-1):
        if i == max_index:
            now_max = max(datas[i+1:])
            max_index = datas.index(now_max,i+1)
        new_diff = now_max - datas[i]
        if diff < new_diff:
            diff = new_diff

print(diff)


Measured memory_bytes: 27832
#include <bits/stdc++.h>
#define fast_io ios::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int main(){
	fast_io;
	int a,b;
	cin>>a>>b;
	if(a==b) cout<<2*a;
	else cout<<max(a,b)*2-1;
	return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    ll ans = 0;
    rep(i, 0, n) {
        int a;
        cin >> a;
        ans += mp[i - a];
        mp[i + a]++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>

int main(){
  int N; cin>>N;
  ll a[N]; CINA(a,N);
  ll x = -1;
  REP(i,N){
    chmax(x,a[i]);
  }
  ll y = -1;
  ll mid = x/2;
  ll d_mid = x;
  REP(i,N){
    if(x==a[i]){ continue; }
    ll temp = abs(a[i]-mid);
    if(temp<d_mid){
      d_mid = temp;
      y = a[i];
    }
  }
  cout << x << " " << y << "\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m,c;
vi a;

int main(){
	cin>>n>>m>>c;
	a=vi(c);
	for(int i=0;i<c;i++) cin>>a[i];
	priority_queue<P> q;
	for(int i=0;i<n;i++){
		int A,B;
		cin>>A>>B;
		q.push({B,A-1});
	}
	int t=0,res=0;
	while(t<m&&q.size()){
		P p=q.top();
		q.pop();
		int A=p.first,B=p.second;
		if(a[B]){
			a[B]--;
			res+=A;
			t++;
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 4196
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= base;
	}
	return ans;
}


static void D_task();

#if 1
int main()
{
	D_task();
	fflush(stdout);
	return 0;
}
#endif

static void D_task()
{
	int N;
	get1int(N);

	auto damw = new LLONG[N];
	for (int i = 0; i < N; i++) {
		get1int<LLONG>(damw[i]);
	}

	LLONG forxw = 0;
	LLONG neg = 1;
	auto mtnw = new LLONG[N];
	for (int i = 0; i < N; i++) {
		forxw += (neg * damw[i]);
		neg *= -1;
	}
	mtnw[0] = forxw;
	for (int i = 0; i < N - 1; i++) {
		mtnw[i + 1] = (damw[i] - (mtnw[i] / 2)) * 2;
	}

	for (int i = 0; i < N; i++) {
		printf("%lld ", mtnw[i]);
	}
	printf("\n");
	delete[] damw;
	delete[] mtnw;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;

namespace mp = boost::multiprecision;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 105;
const int MAX_K = 100005;

int N, K;
int A[MAX_N];
int dp[MAX_N][MAX_K];

signed main()
{
  cin >> N >> K;
  REP(n,N) {
    cin >> A[n];
  }

  dp[0][K] = 1;
  REP(n,N) {
    int tmp = 0;
    for(int k = K; 0 <= k; k--) {
      tmp += dp[n][k];
      if(A[n]+k < K) {
        tmp -= dp[n][k+A[n]+1];
      }
      tmp = (tmp + MOD) % MOD;
      dp[n+1][k] = tmp;
    }
  }

  cout << dp[N][0] << endl;

  return 0;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
int n,l;
bool cmp(string tmp1,string tmp2)
{
    return tmp1<tmp2;
}
void solve()
{
    int i;
    vector < string > inp;
    for (i=0;i<n;i++)
    {
        string str;
        cin>>str;
        inp.push_back(str);
    }
    sort(inp.begin(),inp.end(),cmp);
    for (vector < string >::iterator iter=inp.begin();iter!=inp.end();iter++)
        cout<<*iter;
    cout<<endl;
}
int main()
{
    while(cin>>n>>l)
        solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e6;
const int INF=1e9;
int main(){
	int N,X;cin>>N>>X;
	int L[N];int sum=0;int count=1;
	rep(i,0,N){
		cin>>L[i];
		sum+=L[i];
        if(sum<=X) count++;
	}cout<<count<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
char a[1005];
char b[1005];
char c[1005];
	int n;
	cin>>n;
			cin>>a>>b>>c;

	int cnt=0;
	for(int j=0;j<n;j++){
		if(a[j]==b[j]&&a[j]==c[j]&&b[j]==c[j])
			cnt+=0;
		else if(a[j]!=b[j]&&a[j]!=c[j]&&b[j]!=c[j])
			cnt+=2;
		else 
			cnt+=1;
	}
	cout<<cnt<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n,i;
  cin>>n;
  ll a[n];
  map<ll,ll> mp;
  for(i=0;i<n;i++) 
  {
    cin>>a[i];
    mp[a[i]] = i+1;
  }
  for(i=1;i<=n;i++) cout<<mp[i]<<" ";
  return 0;
}

Measured memory_bytes: 7808
import java.util.Scanner;

public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		
		StringBuilder r = new StringBuilder();
		for (int i = 0; i < line.length(); i++) {

			if (Character.isUpperCase(line.charAt(i))) {
				r.append(String.valueOf(line.substring(i, i + 1).toLowerCase()));
			} else if (Character.isLowerCase(line.charAt(i))) {
				r.append(String.valueOf(line.substring(i, i + 1).toUpperCase()));
			} else {
				r.append(String.valueOf(line.substring(i, i + 1)));
			}

		}
		System.out.println(r);
	}
}

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

using pll = pair<long long, long long>;
int N;
long long D, A;
vector<long long> X, H;

long long solve() {
    // モンスターを X が小さい順に
    vector<int> ids(N);
    for (int i = 0; i < N; ++i) ids[i] = i;
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return X[i] < X[j]; });
    vector<long long> nX(N), nH(N);
    for (int i = 0; i < N; ++i) nX[i] = X[ids[i]], nH[i] = H[ids[i]];
    X = nX, H = nH;

    // イベントソートしていく
    long long res = 0, tmp = 0;
    queue<pair<long long, long long>> que;
    for (int i = 0; i < N; ++i) {
        while (!que.empty()) {
            if (que.front().first >= X[i]) break;
            tmp -= que.front().second;
            que.pop();
        }
        long long con = max(0LL, (H[i] + A - 1) / A - tmp);
        res += con;
        tmp += con;
        que.push({X[i] + D * 2, con});
    }
    return res;
}

int main() {
    cin >> N >> D >> A;
    X.resize(N); H.resize(N);
    for (int i = 0; i < N; ++i) cin >> X[i] >> H[i];
    cout << solve() << endl;
}


Measured memory_bytes: 10624
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>

using namespace std;
#define set_precision cout << fixed << setprecision(10)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<ll>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(), greater<ll>())
#define init(a)  memset((a),0,sizeof(a))
#define pi pair<int,int>
#define pb push_back
#define pl pair<ll,ll>
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
long double EPS = 1e-9;

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

string s[N];int vis[N][N],cmp[N][N];int h,w,curr=1;

bool chk(int i,int j){
    if(i<0||(j<0)||(i>=h)||(j>=w))return false;
    return true;
}

void dfs(int x,int y){
    vis[x][y]=1;cmp[x][y]=curr;
    int a,b;
    rep(i,0,4){
       a=x+dx[i],b=y+dy[i];
       if(chk(a,b)&&(vis[a][b]==0)&&(s[a][b]=='.'))dfs(a,b);
    }
}

int main()
{
    FIO;
    int x,y,x1,x2,y1,y2;
    cin>>h>>w>>x1>>y1>>x2>>y2;x1--,y1--,x2--,y2--;
    rep(i,0,h)cin>>s[i];
    rep(i,0,h){
        rep(j,0,w){
            if((vis[i][j]!=0)||(s[i][j]=='#'))continue;
            dfs(i,j);curr++;
        }
    }
    map<pi,int> rel;map<int,int>dep;vi adj[curr+1];
    //cout<<curr<<" ";
    rep(i,0,h){
        rep(j,0,w){
            if(s[i][j]=='#')continue;
            for(int k=i-2;k<=i+2;k++){
                for(int l=j-2;l<=j+2;l++){
                    if(chk(k,l)&&(s[k][l]=='.')&&(cmp[i][j]!=cmp[k][l])){
                        if(rel[{cmp[i][j],cmp[k][l]}]==0){
                            rel[{cmp[i][j],cmp[k][l]}]=1;rel[{cmp[k][l],cmp[i][j]}]=1;
                            adj[cmp[i][j]].pb(cmp[k][l]);adj[cmp[k][l]].pb(cmp[i][j]);
                        }
                    }
                }
            }
        }
    }
    int st=cmp[x1][y1];int des=cmp[x2][y2];
    //cout<<st<<" "<<des<<" ";
    dep[st]=0;vi vis1(curr+1,0);
    queue<int> q;q.push(st);
    vis1[st]=1;
    while(!q.empty()){
        int u=q.front();q.pop();
        for(int t:adj[u]){
            if(vis1[t]==0){
                q.push(t);
                vis1[t]=1;
                dep[t]=dep[u]+1;
            }
        }
    }
    (dep.find(des)==dep.end()?cout<<-1:cout<<dep[des]);
    return 0;
}

Measured memory_bytes: 49644
#include "bits/stdc++.h"
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define mp make_pair
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;
ll mod=1000000007;

int N, M;
int WA[105000];
bool AC[105000];

void solve() {
    cin >> N >> M;
    int WAnum = 0;
    int ACnum = 0;
    for(int i = 1; i <= N; i++) {
        WA[i] = 0;
        AC[i] = false;
    }
    while(M--) {
        int p;
        string S;
        cin >> p >> S;
        if(AC[p]) continue;
        if(S == "AC") {
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        } else if(S == "WA") {
            WA[p]++;
        }
    }
    cout << ACnum << " " << WAnum << endl;
    return;
}

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

Measured memory_bytes: 768
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func allAtoi(num []string) []int {
	conv := make([]int, len(num))
	for i, item := range num {
		conv[i], _ = strconv.Atoi(item)
	}
	return conv
}

type item struct {
	v int
	w int
}

func main() {
	nw := allAtoi(strings.Split(nextLine(), " "))
	items := make([]item, nw[0], nw[0])
	for i := 0; i < nw[0]; i++ {
		vw := allAtoi(strings.Split(nextLine(), " "))
		items[i] = item{v: vw[0], w: vw[1]}
	}
	ans := solve(nw[0], nw[1], items)
	fmt.Println(ans)
}

func solve(n, limitW int, items []item) int {
	dp := make([]int, limitW+1, limitW+1)
	for i := 1; i <= limitW; i++ {
		for j := 0; j < len(items); j++ {
			v := items[j].v
			w := items[j].w
			rest := i - w
			if rest >= 0 {
				if dp[i] < dp[rest]+v {
					dp[i] = dp[rest] + v
				}
			}
		}
	}
	return dp[limitW]
}



Measured memory_bytes: 1184
#include <algorithm>
#include <cstring>
#include <iostream>

bool valid(int a, int b, int c) {
    return a <= b + c && b <= c + a + 1 && c <= a + b + 1;
}

void calc(int rear, int front, int west, int east, int north, int south, int limit, char* buffer) {
    bool same = true;
    for (int i = 0; i < limit; i++) {
        int a = rear + front;
        int b = west + east;
        int c = north + south;
        char y;
 
        int temp = rear;
        if (east > 0 && valid(b - 1, c, a)) {
            rear = east - 1;
            east = front;
            front = west;
            west = temp;
            y = 'E';
        } else if (north > 0 && valid(c - 1, a, b)) {
            rear = north - 1;
            north = front;
            front = south;
            south = temp;
            y = 'N';
        } else if (south > 0 && valid(c - 1, a, b)) {
            rear = south - 1;
            south = front;
            front = north;
            north = temp;
            y = 'S';
        } else {
            rear = west - 1;
            west = front;
            front = east;
            east = temp;
            y = 'W';
        }

        if (same) {
            char x = buffer[i];
            if (x < y) {
                return;
            }
            same = x == y;
        }
        buffer[i] = y;
    }
}

char* find(int target[6], int limit) {
    char* buffer = new char[limit + 1];
    std::memset(buffer, 'Z', limit);
    buffer[limit] = '\0';

    std::sort(target, target + 6);
    do {
        if (valid(target[0] + target[1], target[2] + target[3], target[4] + target[5])) {
            calc(target[0], target[1], target[2], target[3], target[4], target[5], limit, buffer);
        }
    } while (std::next_permutation(target, target + 6));

    return buffer;
}

int main() {
    int target[6];
    while (true) {
        bool nonzero = false;
        for (int i = 0; i < 6; i++) {
            std::cin >> target[i];
            nonzero = nonzero || target[i];
        }
        if (!nonzero) {
            break;
        }

        int p, q;
        std::cin >> p >> q;

        char* result = find(target, q);
        if (result[0] == 'Z') {
            std::cout << "impossible" << std::endl;
        } else {
            std::cout << &result[p - 1] << std::endl;
        }
        delete[] result;
    }
    return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n;
    cin >> n;
    int res = 0;
    for (int i = 1; i <= n;i++){
        string s = to_string(i);
        if(s.size()%2==1)
            res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    bool f[101];for(int i=0;i<101;i++){f[i]=true;}
    int x, n;
    cin>>x>>n;
    for(int i=0;i<n;i++){
        int tmp;cin>>tmp;
        f[tmp] = false;
    }
    int lx = x;
    int rx = x;
    while(1){
        if(lx<0 || (f[lx])){co(lx);return 0;}
        if(f[rx]){co(rx);return 0;}
        lx--;rx++;
    }
}

Measured memory_bytes: 3528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[] seqS = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i<n; i++)
        seqS[i] = Integer.parseInt(line[i]);

      int q = Integer.parseInt(br.readLine());
      int[] seqT = new int[q];
      line = br.readLine().split(" ");
      for(int i=0; i<q; i++)
        seqT[i] = Integer.parseInt(line[i]);
      
      int cnt=0;
      for (int ref : seqT) {
        if( linearSeach(seqS, ref) )
          cnt++;
      }

      System.out.println(cnt);
    }
  }

  static boolean linearSeach(int[] tar, int ref) {

    for (int i : tar) {
      if(i == ref) return true;
    }

    return false;
  }
}


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

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    double r;
    cin >> r;
    double PI = acos(-1);

    cout << setprecision(12) << 2 * r * PI << endl;
    return 0;
}



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

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

	int a, b, k;
	cin >> a >> b >> k;
	for (int i = 0; i < k; ++i) {
		if (i % 2 == 0) {
			a =  (a % 2 ? (a - 1) : a) / 2;
			b += a;
		} else {
			b = (b % 2 ? (b - 1) : b) / 2;
			a += b;
		}
	}
	cout << a << " " << b << endl;
	return 0;
}


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

int main() {
  string N;
  cin >> N;
  int S = N.size();
  vector<char> vec(S);
  for (int i = 0; i < S; i++) {
    vec.at(i) = N[i];
  }
  int T = 0;
  for (int i = 0; i < S; i++) {
    T += vec.at(i) - 48;
  }
  if (T%9 == 0)
    cout << "Yes" << endl;
  else if (T%9 != 0)
    cout << "No" << endl;
}

Measured memory_bytes: 3860
import sys,fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n=int(input())
t=[int(input()) for i in range(n)]
print(lcm_list(t))

Measured memory_bytes: 5176
#include<iostream>
#include<queue>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#define INF 1e9
#define MAX_V 100001
using namespace std;
typedef pair<int,int> P;

struct edge{int to,cost;};
int V,E;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> >que;
	fill(d,d+V,INF);
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v=p.second;
		if(d[v]<p.first) continue;
		for(int i=0;i<G[v].size();i++){
			edge e=G[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}
string s,t;
int longl;
bool f=false,af=true;
int main(){
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.rbegin(),t.rend());
	longl=min(s.length(),t.length());
	for(int i=0;i<longl;i++){
	if(s[i]!=t[i]&&af==true) af=false;
	if(s[i]<t[i]&&f==false) f=true;
	}
	if(af==true){
		if(s.length()<t.length()) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	else if(f==true) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}
/*string s;
int ho=0,x,y;
int main(){
	cin>>s>>x>>y;

	return 0;
}*/

Measured memory_bytes: 2560
#include <stdio.h>
int main(){
  
 int a,b,c,d;
 scanf("%d %d %d %d",&a,&b,&c,&d);
 
  int ans1 = a*b;
  int ans2 = c*d;
  if(ans1 < ans2) ans1 = ans2;
  printf("%d\n",ans1);
  
 return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
set<string> b;
int main(){
	int n;
	cin>>n;
	string a[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
		b.insert(a[i]);
	}
	cout<<b.size();
	return 0;
} 

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

using namespace std;
#define int long long
signed main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m; cin>>n>>m;
	string s, t; cin>>s>>t;
	int l = (n*m)/__gcd(n, m);
	//cout<<l<<endl;
	bool pos = true;
	for(int i = 0; i < n; i++){
		int indx = (l/n)*i;
		if((indx%(l/m) == 0 && (s[i] != t[indx/(l/m)]))){
			//cout<<i<<" : "<<indx/m<<endl;
			pos = false;
			break;
		}
	}
	if(!pos) cout<<-1<<endl;
	else cout<<l<<endl;
}

Measured memory_bytes: 764
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)

using namespace std;


int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    int i,j,k,p=1,q=1;
    ll n,m,tmp;
    int a[10000];
    string s[200000];
    string str;
    int strr[200005];
    cin >> n>>k;
    n=n-k*2;
    if(n<0) n=0;

    std::cout<< n << endl;
    //outputfile<<str;
   // outputfile.close();

    return 0;
}

Measured memory_bytes: 1792
N = int(input())
h = [int(i) for i in input().split()]
i, j = 0, 0
m = 0
while i<N-1:
  while h[i]>=h[i+1]:
    i += 1
    if i==N-1:
      break
  if m<i-j:
    m = i-j
  i += 1
  j = i
print(m)

Measured memory_bytes: 14228
// Vicfred
// https://atcoder.jp/contests/abc159/tasks/abc159_e
import std.algorithm;
import std.stdio;
import std.string;

void main() {
    int h, w, k;
    readf("%s %s %s", &h, &w, &k);
    readln;

    string[] s;
    for(int i = 0; i < h; ++i) {
        string str = readln.chomp;
        s ~= str;
    }

    int ans = h*w;
    for(int mask = 0; mask < (1 << (h-1)); ++mask) {
        int[] groups = new int[h];
        int number_groups = 1;
        for(int i = 0; i < h-1; ++i) {
            if(!(mask & (1 << i))) {
                groups[i+1] = groups[i] + 1;
                number_groups += 1;
            } else {
                groups[i+1] = groups[i];
            }
        }

        int totalline = number_groups - 1;
        int[] whitenum = new int[number_groups];
        bool update = true;
        for(int x = 0; x < w; ++x) {
            bool melapela = true;
            int[] cur = new int[number_groups];
            for(int y = 0; y < h; ++y) {
                cur[groups[y]] += s[y][x] - '0';
                whitenum[groups[y]] += s[y][x] - '0';
                if(cur[groups[y]] > k)
                    update = false;
                if(whitenum[groups[y]] > k)
                    melapela = false;
            }
            if(!melapela) {
                totalline += 1;
                whitenum = cur;
            }
        }
        if(update)
            ans = min(ans, totalline);
    }
    ans.writeln;
}



Measured memory_bytes: 1276
N = int(input())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+" " + str(X%n)
    return str(X%n)

i = 0
sum = 0
while True:
    if N <= sum:
        sum -= 26 ** i
        break
    i += 1
    sum += 26 ** i

s = Base_10_to_n(N - sum - 1, 26)
s = list(s.split())
ans = ""
for st in s:
    ans = ans + chr(int(st) + 97)
plusa = "a" * (i - len(ans))
ans = plusa + ans
print(ans)

Measured memory_bytes: 9216