akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n;
    cin >> n;
    int res = 0;
    REP(i, n) {
        int tmp;
        cin >> tmp;
        res += tmp - 1;
    }
    cout << res << endl;
    return 0;
}

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

int main(){
    while(1){
        int m,f,r;
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1) break;
        else if(m==-1 || f==-1) cout << "F" <<endl;
        else if(m+f>=80) cout << "A" << endl;
        else if(m+f<80 && m+f>=65) cout << "B" << endl;
        else if(m+f<65 && m+f>=50) cout << "C" << endl;
        else if(m+f<50 && m+f>=30 && r<50) cout << "D" << endl;
        else if(m+f<50 && m+f>=30 && r>=50) cout << "C" << endl;
        else if(m+f<30) cout << "F" << endl;
        
        
    }
    return 0;
}


Measured memory_bytes: 3088
import sys
from heapq import heappop, heappush, heapify

def main():
    input = sys.stdin.readline
    
    N, Q = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    ls = [b-a for a, b in zip(A, B)]
    q_m = [-v for v in ls[1:-1] if v < 0]
    q_p = [v for v in ls[1:-1] if v >= 0]
    heapify(q_m)
    heapify(q_p)
    sum_A = sum(A)
    sum_q_p = sum(q_p)
    to_remove = set()
    odd = len(q_p) % 2
    Ans = []
    ans = sum_A + sum_q_p - (min(q_p[0], q_m[0]) if odd else 0)
    for _ in range(Q):
        p, x, y = map(int, input().split())
        p -= 1
        v = y-x
        sum_A += x - A[p]
        if p==0 or p==2*N-1:
            ans += x - A[p]
            Ans.append(ans)
            A[p] = x
            continue
        A[p] = x
        odd ^= (ls[p] >= 0) ^ (v >= 0)
        if v >= 0:
            sum_q_p += v
        if ls[p] >= 0:
            sum_q_p -= ls[p]
        to_remove.add(ls[p])
        ls[p] = v
        if v >= 0:
            heappush(q_p, v)
        else:
            heappush(q_m, -v)
        ans = sum_q_p + sum_A
        if odd:
            while q_p[0] in to_remove:
                to_remove.remove(heappop(q_p))
            while -q_m[0] in to_remove:
                to_remove.remove(-heappop(q_m))
            ans -= min(q_p[0], q_m[0])
        Ans.append(ans)
    print("\n".join(map(str, Ans)))

main()


Measured memory_bytes: 52408
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N, L = map(int, input().split())
    A = list(map(int, input().split()))

    left = 0
    for i in range(N - 1):
        if A[i] + A[i + 1] >= L:
            print('Possible')
            left = i
            break
    else:
        print('Impossible')
        return

    for i in range(left):
        print(i + 1)
    for j in range(left, N - 1)[:: -1]:
        print(j + 1)


sol()

Measured memory_bytes: 14440
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for _ in 1..n {
        let x = sc.read::<usize>() - 1;
        let y = sc.read::<usize>() - 1;
        graph[x].push(y);
        graph[y].push(x);
    }

    let ans = calc(0, 0, &graph);
    if ans == 0 {
        println!("Bob");
    } else {
        println!("Alice");
    }
}

fn calc(v: usize, p: usize, graph: &Vec<Vec<usize>>) -> usize {
    let mut xor = 0;
    for &next in graph[v].iter() {
        if next == p {
            continue;
        }
        xor ^= calc(next, v, graph) + 1;
    }
    xor
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

using namespace std;

#define MINIMUM  100000;
int cost(int N, int *abc, int *abc_cnt, int *abc_len, vector<int> l)
{
  if(N == 0){
    if(abc_cnt[0] == 0 || abc_cnt[1] == 0 || abc_cnt[2] == 0){
      return MINIMUM;
    }
    int total_cost = 0;
    for(int i = 0; i < 3; i++){
      total_cost += abs(abc[i] - abc_len[i]) + 10 * (abc_cnt[i]-1);
    }
    return total_cost;
  }
  int min;
  min = cost(N-1, abc, abc_cnt, abc_len, l);
  for(int i = 0; i < 3; i++){
    abc_cnt[i]++;
    abc_len[i] += l[N-1];
    min = std::min(min, cost(N-1, abc, abc_cnt, abc_len, l));
    abc_cnt[i]--;
    abc_len[i] -= l[N-1];
  }
  return min;
}

int main(void)
{
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> l(N);
  for(int &x: l)
    cin >> x;

  int abc[3];
  abc[0] = A;
  abc[1] = B;
  abc[2] = C;
  int abc_cnt[3] = {0};
  int abc_len[3] = {0};
  cout << cost(N, abc, abc_cnt, abc_len, l) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<map>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int main()
{
  int a,l;
  for(;cin>>a>>l,a||l;)
    {
      map<int ,int> hash;
      hash[a]=0;
      for(int i=1;;i++)
	{
	  string tmp=toString(a);
	  while(tmp.size()<l)
	    tmp="0"+tmp;
	  
	  string min=tmp;
	  string max=tmp;
	  sort(min.begin(),min.end());
	  sort(max.begin(),max.end(),greater<char>());
	  int xx=toInt(max)-toInt(min);
	  if(!hash.insert(make_pair(xx,i)).second)
	    {
	      cout<<hash[xx]<<" "<<xx<<" "<<i-hash[xx]<<endl;
	      break;
	    }
	  a=xx;
	}
      
    }
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x1,y1,x2,y2,x,y;
  cin>>x1>>y1>>x2>>y2;
  x=y2-y1,y=x1-x2;
  cout<<x2-x<<" "<<y2-y<<" "<<x1-x<<" "<<y1-y;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>

int main (void)
{
    char w[100];
    int kind[26];
    int len;
    int i, x;
    int flag = 0;

    scanf("%s", w);

    len = strlen(w); 

    for(i = 0; i < 26; i++){
        kind[i] = 0;
    }

    for (i = 0; i < len; i++){
        x = w[i] - 'a';
        kind[x]++; 
    }
    for(i = 0; i < 26; i++){
        if(kind[i] % 2 != 0){
            flag = 1;
			break;
        }
    }
    if (flag == 0){
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return (0);
}


Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var xyh = new long[N][];
            for (var i = 0; i < N; ++i)
                xyh[i] = Sarray();
            for (var Cx = 0; Cx <= 100; ++Cx)
            {
                for (var Cy = 0; Cy <= 100; ++Cy)
                {
                    var hs = new HashSet<long>();
                    var hsn0 = new HashSet<long>();//ｈが0じゃない場合、Hが複数出たらダメ
                    for (var i = 0; i < N; ++i)
                    {
                        var x = xyh[i][0];
                        var y = xyh[i][1];
                        var h = xyh[i][2];
                        var H = h + Abs(Cx - x) + Abs(Cy - y);
                        hs.Add(H);
                        if (h != 0)
                            hsn0.Add(H);
                    }
                    if (2 <= hsn0.Count())
                        continue;
                    // 整合性チェック
                    foreach (var dh in hs)
                    {
                        var flg = true;
                        for (var i = 0; i < N; ++i)
                        {
                            var x = xyh[i][0];
                            var y = xyh[i][1];
                            var h = xyh[i][2];
                            var t = Max(dh - Abs(Cx - x) - Abs(Cy - y), 0);
                            if (h != t)
                            {
                                flg = false;
                                break;
                            }
                        }
                        if(flg)
                        {
                            WriteLine($"{Cx} {Cy} {dh}");
                        }
                    }
                }
            }
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 17800
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    reverse(a.begin(),a.end());
    a.push_back(0);
    int cnt = 0, ans = 0;
    REP(i,n){
        if(a[i] <= a[i+1]) cnt++;
        else chmax(ans,cnt), cnt = 0;
    }
    cout << ans << endl;
}


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

int main() {
string s;
int64_t k;
cin>>s>>k;
if(s.size()==1){
cout<<k/2;
}
else{
int64_t count=0;
int z=0;
  int a=0;
  int b=0;
for(int i=0;i<s.size()-1;i++){
if(s.at(i)==s.at(i+1)){
z++;
}
else{
  if(a==0){
    b=z;
  }
count+=(z+1)/2;
z=0;
  a++;
}
}
  if(a==0){
    b=z;
  }
  count+=(z+1)/2;
int64_t ans=0;
  if(z==s.size()-1){
    if(z%2==1){
      cout<<(s.size()/2)*k;
    }
    else{
      int d=s.size();
      if(k%2==0){
        cout<<((d/2)*2+1)*(k/2);
      }
      else{
        cout<<((d/2)*(k/2+1)+(d/2+1)*(k/2));
      }
    }
  }
  else{
if(s.at(0)==s.at(s.size()-1)){
  if(z%2==0&&(z+b)%2==0){
    cout<<(count+1)*k-1;
  }
  else{
    cout<<count*k;
  }
}
else{
ans+=count*k;
cout<<ans;
}








}
}
}


Measured memory_bytes: 256
module mod_square_rotation
  implicit none
  integer :: d, s(3,0:2000,0:2000)
contains
  subroutine cumsum(a,k)
    integer, intent(in) :: a(0:d-1,0:d-1), k
    integer :: i, j, l, b(3,0:d-1,0:d-1)
    b = 0
    do i = 0, d-1
      do j = 0, d-1
        if (a(i,j) > (k+1)*(k+1)) b(1,i,j) = b(1,i,j)+1
        if (a(i,j) > k*k) b(2,i,j) = b(2,i,j)+1
        if (a(i,j) > k*(k+1)) b(3,i,j) = b(3,i,j)+1
      end do
    end do
    s = 0
    do i = 1, 2*d
      do j = 1, 2*d
        s(:,i,j) = s(:,i-1,j)+s(:,i,j-1)-s(:,i-1,j-1) &
        & +b(:,mod(i-1,d),mod(j-1,d))
      end do
    end do
  end
  integer function getsum(l,i1,j1,i2,j2)
    integer, intent(in) :: l, i1, j1, i2, j2
    getsum = s(l,i2,j2)-s(l,i1-1,j2)-s(l,i2,j1-1)+s(l,i1-1,j1-1)
  end
  logical function check(b)
    integer, intent(in) :: b
    integer :: i, j
    check = .false.
    do i = 1, d
      do j = 1, d
        if (getsum(1,i,j,i+b,j+b) /= 0) cycle
        if (getsum(2,i+b+1,j+b+1,i+d-1,j+d-1) /= 0) cycle
        if (getsum(3,i+b+1,j,i+d-1,j+b) /= 0) cycle
        if (getsum(3,i,j+b+1,i+b,j+d-1) /= 0) cycle
        check = .true.
        return
      end do
    end do
  end
end module mod_square_rotation
program square_rotation
  use mod_square_rotation
  implicit none
  integer :: n, x, y, a(0:1000,0:1000) = 0, i, j, m, k, l, r
  read(*,*) n, d
  do i = 1, n
    read(*,*) x, y
    x = mod(x,d)
    y = mod(y,d)
    a(x,y) = a(x,y)+1
  end do
  m = maxval(a(0:d-1,0:d-1))
  k = 0
  do while (m > (k+1)*(k+1))
    k = k+1
  end do
  call cumsum(a(0:d-1,0:d-1),k)
  l = -1
  r = d-1
  do while (r-l > 1)
    m = (l+r)/2
    if (check(m)) then
      r = m
    else
      l = m
    end if
  end do
  write(*,'(i0)') k*d+r
end program square_rotation

Measured memory_bytes: 66688
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
l = [0] * (N + 1)
r = [0] * (N + 1)
for i in range(N): l[i + 1] = gcd(l[i], a[i])
a.reverse()
for i in range(N): r[i + 1] = gcd(r[i], a[i])
res = 0
for i in range(N + 1): res = max(res, gcd(l[i], r[N - i - 1]))
print(res)


Measured memory_bytes: 85228
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp20
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            string b = Console.ReadLine();

            int sum = 0;
            for(int i=0;i<3;i++)
            {
                if(a[i]==b[i])
                {
                    sum++;
                }
            }
            Console.WriteLine(sum);
            Console.Read();
        }
    }
}


Measured memory_bytes: 11092
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val s = inputs(0)

  println(solve(s))

  def solve(s: String): String = {
    val cRange = (2 until s.size - 1)
    if(s.filter(_.isUpper).size == 2 && s(0) == 'A' && cRange.filter(s(_) == 'C').size == 1) {
      return "AC"
    }
    return "WA"
  }
}

Measured memory_bytes: 54812
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int N;
  string S;
  cin>>N>>S;
  
  int ans=1;
  int i=0;
  
  while(i<N-1){
    if(S[i]==S[i+1])
      ++i;
    else{
      ++i;
      ++ans;
    }
  }
  
  cout<<ans<<endl;
}


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

 int main()
 {
     int N,L,i,j;
     string s[101];
     string a[10001];
     string temp;

     cin>>N>>L;
     for(i=0;i<N;i++){
        cin>>s[i];
     }

     for(i=0;i<N;i++){
        for(j=0;j<N-1-i;j++){
            if(s[j]>s[j+1]){
                temp = s[j];
                s[j] = s[j+1];
                s[j+1] = temp;
            }
        }
     }
     for(i=0;i<N;i++){
        cout<<s[i];
     }
     cout<<endl;

     return 0;
 }


Measured memory_bytes: 3356
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<list>
#include<utility>
#include<tuple>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通

int N;
vector<llong> A;

int main() {
	cin >> N;
	llong ans = 0;
	for (int i = 0; i < N; i++) {
		llong a;
		cin >> a;
		ans = ans ^ a;
	}
	if (ans == 0) cout << "Yes";
	else cout << "No";

	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
ll inf = 1e15;
int N,Q,K;
vector<vector<P>> v(100001);
ll A[100010] = {0};

void dfs(int n){
	/*if(n==K){
		if(v[K].size()==1){
			A[v[K][0].first] = A[K] + v[K][0].second;
			dfs(v[K][0].first,1);
		}else{
			A[v[K][0].first] = A[K] + v[K][0].second;
			dfs(v[K][0].first,1);
			A[v[K][1].first] = A[K] - v[K][0].second;
			dfs(v[K][1].first,-1);
		}
	}*/
	for(int i=0;i<v[n].size();i++){
		if(A[v[n][i].first]==inf){
			A[v[n][i].first] = A[n] + v[n][i].second;
			dfs(v[n][i].first);
/*
			if(c==1){
				A[v[n][i].first] = A[n] + v[n][i].second;
				dfs(v[n][i].first,1);
			}else{
				A[v[n][i].first] = A[n] - v[n][i].second;
				dfs(v[K][i].first,-1);
			}*/
		}
	}
}

int main(){
	cin >> N;
	for(int i=0;i<N-1;i++){
		ll a,b,c;
		cin >> a >> b >> c;
		v[a].push_back(P(b,c));
		v[b].push_back(P(a,c));
	}
	for(int i=1;i<=N;i++){
		A[i] = inf;
	}
	cin >> Q >> K;
	A[K] = 0;
	dfs(K);
	for(int i=0;i<Q;i++){
		int x,y;
		cin >> x >> y;
		/*if(A[x]*A[y]<0)*/ cout << abs(A[x])+abs(A[y]) << endl;
		/*else if(A[x]<A[y]) cout << labs(A[x])+labs(A[y]) << endl;*/
	}
}

Measured memory_bytes: 12800
//cwyssb
    #include<cstdio>
    int n,m;
    long long dp[51][51][51],c[51][51],mo,f1[51][51],f2[51][51];
    int main()
    {
    	scanf("%d",&n);
    	dp[1][0][0]=1;
    	mo=1000000007;
    	c[0][0]=1;
    	for(int i=1;i<=n;i++)
    	{
    		c[i][0]=c[i][i]=1;
    		for(int j=1;j<=i-1;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mo;
    	}
    	for(int k=0;k<=n-1;k++)
    	for(int i=0;i<=n-k;i++)
    	for(int j=0;j<=n-i-k;j++) if(i+j>0)
    	{
    		if(i>j) dp[i][j][k]=(dp[i][j][k]+f1[i-j][k])%mo;
    		else dp[i][j][k]=(dp[i][j][k]+f2[j-i][k])%mo;
    		for(int i1=1;i1<=i;i1++)f1[i1][k+i+j]=(f1[i1][k+i+j]+((dp[i][j][k]*c[n-k][j+i1])%mo)*c[n-k-j-i1][i-i1])%mo;
    		for(int i1=0;i1<=j;i1++)f2[i1][k+i+j]=(f2[i1][k+i+j]+((dp[i][j][k]*c[n-k][i+i1])%mo)*c[n-k-i-i1][j-i1])%mo;
    	} 
    	printf("%d\n",f2[0][n]);
    } 

Measured memory_bytes: 896
def main():
    student_num, point_num = map(int, input().split())
    student_location = [tuple(map(int, input().split())) for _ in range(student_num)]
    point_location = [tuple(map(int, input().split())) for _ in range(point_num)]
    answer = [0] * student_num
    for i in range(student_num):
        min_distance = float("inf")
        for j in range(point_num):
            distance = abs(student_location[i][0] - point_location[j][0]) + abs(student_location[i][1] - point_location[j][1])
            if min_distance > distance:
                answer[i] = j + 1
                min_distance = distance
    for ans in answer:
        print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n,a[200010],cnt;
int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
	for(int i=1;i<=n;i++)
	{
		if(a[i]==i)
		{
			cnt++; swap(a[i+1],a[i]);
		}
	}
	cout << cnt << endl;
	return 0 ;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	short f=1;x=0;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x*=f;
}
int main(){
	string s;cin>>s;
	for(int i=0;i<s.size();i+=2)
		cout<<s[i];
	cout<<endl;
	return 0;
}


Measured memory_bytes: 512
S = gets.strip.chomp

steppable = true

S.split(//).each_with_index do |char, index|
  if (index+1).odd? # 奇数
    unless ["R", "U", "D"].include?(char)
      steppable = false
      break
    end
  else # 偶数
    unless ["L", "U", "D"].include?(char)
      steppable = false
      break
    end
  end
end

if steppable
  puts "Yes"
else
  puts "No"
end


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

int main(){

long long a,b;
char x;
scanf("%lld %c %lld" ,&a,&x,&b);

if (x=='+')
printf("%lld\n",a+b);
else
printf("%lld\n",a-b);
	return 0;
} 


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

using lint = long long;


int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int a, b;
    cin >> a >> b;
    if (a >= 1 && a <= 9 && b >= 1 && b <= 9)
        cout << a * b << '\n';
    else cout << "-1\n";
}

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

const int N=2010;
bitset<N>A[N];
vector<int>g[N];
int n,a[N],vis[N];
priority_queue<pair<int,int> >pq;


void dfs(int x){
	vis[x]=1;
	for(int i=1;i<=n;++i)if(A[x][i]&&!vis[i])g[x].push_back(i),dfs(i);
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)if(i!=j&&__gcd(a[i],a[j])>1)A[i][j]=1;
	for(int i=1;i<=n;++i)if(!vis[i])dfs(i),pq.emplace(a[i],i);
	for(int i=1;i<=n;++i){
		auto x=pq.top();pq.pop();
		cout<<x.first<<" \n"[i==n];
		for(int j:g[x.second])pq.emplace(a[j],j);
	}
	return 0;
}


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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n & 1 ==1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return result;
}



int32_t main()
{
    IOS

    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a+b>=k)
    	cout<<min(a,k)<<endl;
    else
    	cout<<a-(k-a-b)<<endl;
    
    return 0;
}

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

using namespace std;

const int c = 300000;
vector<vector<int>> g(c);
vector<int> nums(c);

void dfs(int v, int p){
    for (auto j : g[v]){
        if (j == p) continue;
        nums[j] += nums[v];
        dfs(j,v);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    
    // 隣接リストを作る
    for (int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    // 部分期頂点のみにqを加算する
    for (int i = 0; i < q; i++){
        int p, q;
        cin >> p >> q;
        p--;
        nums[p] += q;
    }
    
    // 値をroot->leafへ押し流す DFS
    dfs(0,-1);
    
    for (int i = 0; i < n; i++){
        if (i != n-1) cout << nums[i] << " ";
        else cout << nums[i] << endl;
    }
}

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

const int M = 1000000007;

int main() {
    int n;
    cin >> n;
    int lim = 140000;
    vector<double> dp(lim, 1e8);
    dp[1] = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        vector<double> next(lim, 1e8);
        for (int j = 1; j < lim; ++j)
            for (int k = j; k < lim; k += j)
                next[k] = min(next[k], max(dp[j], abs(a - k) / (double)a));

        dp = next;
    }
    double ans = 1e8;
    for (auto i : dp)
        ans = min(ans, i);

    printf("%.16lf\n", ans);
    return 0;
}

Measured memory_bytes: 5172
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int n;
int cnt[100005];

int main()
{
    cin >> n;
    int a, b;
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        for(int j = a; j < b + 1; j++){
            cnt[j]++;
        }
    }

    int ans = 0;
    for(int i = 1; i < n + 2; i++){
        if(i <= cnt[i] + 1) ans = i - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3484
fun main(args: Array<String>) {
    val (n,m,k) = readLine()!!.split(" ").map { it.toLong() }
    val count = combination(n*m-2, k-2)
    var ans = 0L
    for (d in 1..m) ans = ans t ( count x n x n x (m-d) x d )
    for (d in 1..n) ans = ans t ( count x m x m x (n-d) x d )
    println(ans)
}

const val MOD = 1000000007L
const val FACT_MAX = 200000

infix fun Long.x(other: Long) = (this*other)%MOD
infix fun Long.t(other: Long) = (this+other)%MOD

val fact by lazy {
    val fact = LongArray(FACT_MAX+1)
    fact[0] = 1L
    for (i in 1..FACT_MAX) fact[i] = (fact[i-1] * i) % MOD
    fact.toList()
}

fun pow(base: Long, exp: Long): Long{
    var base = base
    var exp = exp
    var ret = 1L
    while (exp>0) {
        if(exp%2==1L) ret = ret x base
        base = base x base
        exp /= 2
    }
    return ret
}

fun inv(n: Long) = pow(n, MOD-2)

fun combination(n: Long, k: Long) : Long{
    val n = n.toInt()
    val k = k.toInt()
    val denominator = (fact[k]*fact[n-k]) % MOD
    return (fact[n]*pow(denominator, MOD-2)) % MOD
}


Measured memory_bytes: 40692
N,W = [int(x) for x in input().split()]
dp = [[10**9+1]*(10**5+1) for _ in range(N+2)]
uv = [[0,0]]+[[int(x) for x in input().split()] for _ in range(N)]
dp[0][0]=0
for i in range(N+1):
  for j in range(10**5+1):
    dp[i+1][j] = min(dp[i+1][j],dp[i][j])
    if uv[i][1]+j<=10**5:
      dp[i+1][j+uv[i][1]] = min(dp[i][j]+uv[i][0],dp[i+1][j+uv[i][1]])
ans = 0
for i in range(10**5+1):
  if 0<dp[N+1][i]<=W:
    ans = max(ans,i)
print(ans)

Measured memory_bytes: 119772
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif
void tokenize(string str,const char delim,vector<string> & res){
	stringstream p(str);
	string token;
	while(getline(p,token,delim)){
		res.push_back(token);
	}
	return;
}

// Your workSpace ...

	
	
ll N;
string str;
void test_case(){
	cin >> N >> str;
	int cnt1 = 0,cnt2 = 0;
	int R = count(all(str),'R');
	for(int i = 0;i<R;++i){
		if(str[i] != 'R') ++cnt1;
	}
	for(int i = R;i<sz(str);++i)
		if(str[i] != 'W') ++cnt2;
	
	cout << min(cnt1,cnt2);
		
		
}




int main(){
	FAST_IO;
	int tt;
	//cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3672
# s = gets.chomp.codepoints
s = gets.chomp.split(//)
k = gets.to_i
a = "a".ord
z = "z".ord
s.size.times{|i|
  break if k.zero?
  if s[i] != "a"
    t = (z - s[i].ord).succ
    if t <= k
      k -= t
      s[i] = "a"
    end
  end
}
k = k % 26
s[-1] = (s[-1].ord + k).chr

puts s.join



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



int main(){
	int h,w;
	cin >> h >> w;
	string s[h+2];
	
	for(int i=0;i<h;i++){
		cin >> s[i];
	}
	
	for(int i=0;i<w+2;i++){
		cout << '#';
	}
	cout << endl;
	
	for(int i=0;i<h;i++){
		cout << '#';
		cout << s[i];
		cout << '#';
		cout << endl;
	}
	
	for(int i=0;i<w+2;i++){
		cout << '#';
	}
	cout << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

void mainsolve(){

	ll n,d,a;
	cin >> n >> d >> a;
	vector<P> xx(n);
	rep(i,n) cin >> xx[i].first >> xx[i].second;
	sort(xx.begin(), xx.end());

	queue<P> q; // 効くぎりぎりの座標と、その時点でのtotのpair
	ll tot = 0;
	ll ans = 0;
	rep(i,n){
		ll x = xx[i].first;
		ll h = xx[i].second;
		
		// totで引く分を調整
		while(!q.empty() && q.front().first < x){
			// h += q.front().second;
			tot -= q.front().second;
			q.pop();
		}
		
		h -= tot;
		// i番目の敵を爆風の左端にして倒す
		if(h > 0){
			ll cnt = 0;
			if(h%a==0) cnt = h/a;
			else cnt = h/a + 1;
			ans += cnt;
			tot += a * cnt;
			q.push(P(x+2*d,a * cnt));
		}
		
		
	}

	cout << ans << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  int Q, l, r;
  cin >> Q;

  int MAX = 101010;
  vector<int> is_prime(MAX, 1);
  is_prime[0] = 0, is_prime[1] = 0;
  for (int i = 2; i < MAX; i++) {
    if (!is_prime[i]) continue;
    for (int j = i * 2; j < MAX; j += i) is_prime[j] = 0;
  }

  vector<int> a(MAX, 0);
  for (int i = 0; i < MAX; i++) {
    if (i % 2 == 0) continue;
    if (is_prime[i] && is_prime[(i + 1) / 2]) a[i] = 1;
  }

  vector<int> s(MAX + 1, 0);
  for (int i = 0; i < MAX + 1; i++) s[i + 1] = s[i] + a[i];

  for (int q = 0; q < Q; q++) {
    cin >> l >> r;
    r++;

    cout << s[r] - s[l] << endl;
  }
}

Measured memory_bytes: 1792
a, b = gets.split.map(&:to_i)

#f(0,a)を求める
def func(a)
  i = 0
  sum = 0
  #49桁分計算 ∵10**12 < 2^48
    while (i < 49) do
    cnt = 0
    #周期2**(i+1)→一応ビット演算しとく
    period = 1 << (i+1)
    #周期内の1の数を数える
    cnt += (a+1)/period * period/2
    #はみ出た分を足す
    rest = (a+1)%period - period/2
    cnt += rest if rest > 0
    if (cnt%2 == 1) then
      sum += 1 << i
    end
    i += 1
  end
  return sum
end
#f(a,b) = f(0,b)^f(0,a-1)
puts func(b)^func(a-1)


Measured memory_bytes: 1788
import numpy as np

N=int(input())
A=np.array(list(map(int,input().split())))
A=sorted(A,reverse=True)
ans=A[0]
if N%2==0:
  for i in range(1,(N-2)//2+1):
    ans+=A[i]*2
else:
  for i in range(1,(N-2)//2+1):
    ans+=A[i]*2
  else:
    ans+=A[i+1]
print(ans)

Measured memory_bytes: 49980
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;

int n,m,x,c,p,WA[N];
string s;
bool fr[N];
vector<int>v;


int main(){
    
    cin>>n>>m;
    
    for(int i=0;i<m;++i){
        cin>>x>>s;
        if(!fr[x]){
            if(s=="AC"){
                fr[x]=true;
                c++;
            }else WA[x]++;
    }
    
    }
    
    for(int i=1;i<=1e5;++i)
        if(fr[i])p+=WA[i];
    
    cout<<c<<" "<<p;
    
    return 0;
}

Measured memory_bytes: 768
N, M = map(int, input().split())
store_m = [list(map(int, input().split())) for i in range(N)]
store = sorted(store_m)
buy = 0
cost = 0
for i in range(N):
    buy += store[i][1]
    if buy < M:
        cost += store[i][0] * store[i][1]
    else:
        cost += store[i][0] * (M - (buy - store[i][1]))
        print(cost)
        exit()

Measured memory_bytes: 28260
#include <iostream>
#include <cmath>
  
using namespace std;
  
int main(void){
    int a,b,c;
    while (cin>>a>>b>>c && a) {
        int x = 50001, y = 50001;
        for (int i = 0; i < 10001; i++) {
            int t = c+a*i, u = abs(c-(a*i));
            if (t % b == 0 || u % b == 0) {
                int j = (t%b == 0 ? t/b : u/b);
                if (i+j < x+y || (i+j==x+y && a*i+b*j < a*x+b*y)) x = i, y = j;
            }
        }
        cout << x << " " << y << endl;
    }
}

Measured memory_bytes: 2988
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n,m,s,t,ans;
vi adj[200000];
bool vis[200000][4];
void bfs(){
    queue<pii> q;
    q.push(mp(s,0));

    while(!q.empty()){
        int node,step;
        node = q.front().fi;
        step = q.front().se;
        if(node==t && step %3==0){
            ans = step/3;break;
        }
        q.pop();
        if(!vis[node][step%3]){
            vis[node][step%3]=true;
            for(int i=0;i<adj[node].size();i++){
                int nex = adj[node][i];
                q.push(mp(nex,step+1));
            }
        }
    }
}
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
    }
    cin>>s>>t;
    ans = -1;
    bfs();
    cout<<ans<<newl;
}


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

int main()
{
	char n;
	cin >> n;
	if (n == 'a' || n == 'e' || n == 'i' || n == 'o' || n == 'u')
	{
		cout << "vowel";
	}
	else
	{
		cout << "consonant";
	}
	return 0;
}

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

using namespace std;

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> M(N);
    int m = 1000;
    for (int i = 0; i < N; ++i) {
        cin >> M[i];
        X -= M[i];
        m = min(m, M[i]);
    }

    int ans = N + X / m;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,start,end) for(int i = start; i < end; i++)
#define ll long long
const ll N = 4e3 + 200;
const ll INF = 0x3f3f3f3f;


int main(){
  int a,b;
  cin>>a>>b;
  int mx = a+b;
  mx = max(mx,(a-b));
  mx = max(mx,(a*b));
  cout<<mx<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,cnt,a[101010];
vector<int>b;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]*=-1;
	}
	for(int i=0;i<n;i++)
	{
		if(!b.size())
		{
			b.push_back(a[i]);
		}
		else
		{
			int id=upper_bound(b.begin(),b.end(),a[i])-b.begin();
			if(id==b.size())
			{
				b.push_back(a[i]);
			}
			else
			{
				b[id]=a[i];
			}
		}
	}
	cout<<b.size()<<endl;
	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define dg(x) cerr << #x << " = " << x <<endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define fore(i,a,b) for(int i=(int)a;i<=(int)b;++i)
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int main(){
#ifdef LOCAL
    //freopen("h.txt", "r", stdin);
    // freopen("main.out", "w", stdout);
#else
    ios::sync_with_stdio(0), cin.tie(0);
    #define endl '\n'
#endif
    int n;
    cin>>n;
    int B[n-1];
    int A[n];
    memset(A,0,sizeof(A));
    forn(i,n-1)cin>>B[i];
    A[0]=B[0];
    ll sum=A[0];
    for(int i=1;i<n-1;i++){
        A[i]=min(B[i-1],B[i]);
        sum+=A[i];
    }
    A[n-1]=B[n-2];
    sum+=A[n-1];
    cout<<sum<<endl;
    return 0;
}

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

typedef long long ll;


int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int AC = 0, WA = 0, TLE = 0, RE = 0;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (s == "AC") {
			AC++;
		}
		else if (s == "WA") {
			WA++;
		}
		else if (s == "TLE") {
			TLE++;
		}
		else {
			RE++;
		}
	}
	cout << "AC x " << AC << "\n";
	cout << "WA x " << WA << "\n";
	cout << "TLE x " << TLE << "\n";
	cout << "RE x " << RE << "\n";
}


Measured memory_bytes: 3620
def ceil(src, range):
    return ((int)((src+9) / range) * range)

t=[int(input()) for _ in range(5)]
idx=0
max=0
sum=0
for i in range(5):
    if ceil(t[i],10)-t[i]>max and ceil(t[i],10)!=t[i]:
        max=ceil(t[i],10)-t[i]
        idx=i
for i in range(5):
    if i==idx:
        sum+=t[i]
    else:
        sum+=ceil(t[i],10)
print(sum)

Measured memory_bytes: 3064
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =2e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
//unordered_map
typedef long long ll;
//已AC 尝试去并查集 
int father[MAXN];
int need[MAXN];
int Find(int x)
{
	return x==father[x] ? x : father[x]= Find(father[x]);
}
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++) father[i]=i,need[i]=1;
	while(m--)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		int x=Find(a),y=Find(b);
		if(x!=y)
		{
			father[x]=y;
			need[y]+=need[x];
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans=max(ans,need[i]);
	}
	//for(int i=1;i<=n;i++) printf("need: %d\n",need[i]);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 5352
#include <stdio.h>

int main(void){
    int h,w;
    int i,j;
    while(1){
        scanf( "%d %d" , &h , &w );
        if( h == 0 && w == 0 ) break;
        for( i = 0; i < h ; i++ ){
            for( j = 0 ; j < w ; j++ ){
                if( ( i + j ) % 2 == 0 ){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2108
#coding: utf-8

import sys

def gojo(a,b):
    if b % a == 0:
        return a
    else:
        return gojo(b % a, a)

for line in sys.stdin:
    l = map(int,line.split())
    l.sort()
    a = l[0]
    b = l[1]
    print gojo(a,b),a*b/gojo(a,b)

Measured memory_bytes: 6328
#C
import heapq
n = int(input())
a = [int(input()) for _ in range(n)]
a_t = a[:]
a = list(map(lambda x:x*(-1),a))
heapq.heapify(a)
for i in range(n):
    m = heapq.heappop(a)*(-1)
    if m == a_t[i]:
        m = heapq.heappop(a)*(-1)
        heapq.heappush(a,a_t[i]*(-1))
    print(m)
    heapq.heappush(a,m*(-1))

Measured memory_bytes: 21652
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "l    ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto s = sread();
    writeln(s[0 .. $ - "FESTIVAL".length]);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2632
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
typedef vector<int> vi;

vi C;

bool compare(vi S, vi C) {
	for (int i=0; i<S.size(); i++) {
		if (S[i] != C[i]) return false;
	}
	return true;
}

int solve(vi S, int cnt) {
	C = vi(S.size());
	map<int, int> ma;
	for (int i=0; i<S.size(); i++) {
		if (ma.empty() || ma.find(S[i])==ma.end()) {
			ma[S[i]] = 1;
		} else {
			ma[S[i]]++;
		}
	}
	for (int i=0; i<S.size(); i++) {
		C[i] = ma[S[i]];
	}
	if (compare(S, C)) {
		return cnt;
	}
	return solve(C, cnt+1);
}

int main() {
	int n;
	while (scanf("%d",&n)&&n!=0) {
		vi S(n);
		for (int i=0; i<n; i++) scanf("%d",&S[i]);
		int res = solve(S, 0);
		printf("%d\n", res);
		for (int i=0; i<C.size()-1; i++) printf("%d ",C[i]);
		printf("%d\n", C[C.size()-1]);
	}
}

Measured memory_bytes: 0
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln

class BIT {
	int[] data;
	this(int n) {
		data = new int[n+1];
	}
	BIT dup() {
		BIT ret = new BIT(to!int(data.length));
		ret.data = data.dup;
		return ret;
	}
	void add(int i, int x=1) {
		i++;
		while (i < data.length) {
			data[i] += x;
			i += i&-i;
		}
	}
	int sum(int i) {
		int ret = 0;
		i++;
		while (i) {
			ret += data[i];
			i -= i&-i;
		}
		return ret;
	}
}

void main() {
	int n;
	scanf("%d", &n);
	int[] a = new int[n];
	foreach (i; 0..n) scanf("%d", &a[i]);
	long L = long(n+1)*n/2;
	long M = (L+1)/2;
	int l = 0, u = (1<<30)-10;
	long count(int[] b) {
		int s = n;
		long ret = 0;
		BIT c = new BIT(n*2+1);
		foreach (i; 0..n) {
			c.add(s);
			s += b[i];
			ret += c.sum(s);
		}
		//writeln(b); writeln(ret);
		return ret;
	}
	while (l+1 < u) {
		int m = (l+u)/2;
		int[] b = new int[n];
		foreach (i; 0..n) {
			b[i] = a[i]<m ? -1 : 1;
		}
		if (count(b) < M) u = m; else l = m;
	}
	writeln(l);
}

Measured memory_bytes: 4220
S=input()
N=len(S)
Ans='Yes'
        
if S[:int((N-1)/2)]!=S[:int((N-1)/2):-1]:
    Ans='No'
    
if int((N-1)/2)%2==0:
    if S[:int((N-1)/4)]!=S[int((N-3)/2):int((N-5)/4):-1]:
        Ans='No'
        
else:
    if N!=3 and S[:int((N-3)/4)]!=S[int((N-3)/2):int((N-3)/4):-1]:
        Ans='No'
    
print(Ans)

Measured memory_bytes: 3064
S = raw_input()
lst = []
for i in range(0, 26):
	lst.append(True)

for i in range(0, len(S)):
	lst[ord(S[i])-97] = False

flag = True
for i in range(0, 26):
	if lst[i]:
		print chr(i+97)
		flag = False
		break

if flag:
	print 'None'

Measured memory_bytes: 5892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    char wall = '#';
    int n, m;
    cin >> n >> m;
    vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
    vector<vector<char>> grid(n, vector<char>(m));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> grid[i][j];
        }
    }
    if (grid[0][0] == wall) cout << 0;
    else {
        dp[0][0] = 1;
        int mod = 1e9 + 7;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if (i+1 < n && grid[i+1][j] != wall) {
                    dp[i+1][j] += dp[i][j];
                    dp[i+1][j] %= mod;
                }
                if (j+1 < m && grid[i][j+1] != wall) {
                    dp[i][j+1] += dp[i][j];
                    dp[i][j+1] %= mod;
                }
            }
        }
        cout << dp[n-1][m-1];
    }
    return 0;
}


Measured memory_bytes: 8144
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define li long 
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define pb push_back
#define fori(i,k,n) for(int i = k;i<n; i++)
#define rfori(i,k,n) for(int i = k; i>=n; i--)
void optimize()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll power(ll x, ll y, ll p) 
{ 
   ll res = 1;       
  
    x = x % p;   
  
    while (y > 0) 
    { 
        
        if (y & 1) 
            res = (res*x) % p; 
  
        
        y = y>>1;  
        x = (x*x) % p;   
    } 
    return res; 
} 
long long gcd(long long a, long long b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
long long lcm(long long a, long long b)  
{  
    return (a*b)/gcd(a, b);  
}  
void test_case()
{
    int n;
    cin>>n;
    vector<int> a(n);
    fori(i,0,n)cin>>a[i];
    unordered_set<int> st;
    st.insert(0);
    for(int i = 0; i<n; i++)
    {
        if(st.find(a[i]-1)!=st.end())st.insert(a[i]);
    }
    int x = st.size()-1;
    if(x<=0)cout<<-1;
    else cout<<n-x;
}

int main()
{
	optimize();
	test_case();
}

Measured memory_bytes: 9288