akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std; void solve(); int main(){cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); solve();}
using ll=int_fast64_t; using ld=long double; using pll=pair<ll,ll>; using pld=pair<ld,ld>;
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
template<class T> void vecout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}

template <std::uint_fast64_t Modulus> class modint {
public:
  ll a;
  constexpr modint(const ll x = 0) noexcept : a(x % Modulus) {}
  constexpr ll &value() noexcept { return a; }
  constexpr const ll &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    ll exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

void solve(){
	const ll MOD=1000000007;
	string k; cin>>k;
	ll d; cin>>d;
	ll n=k.size();
	auto dp=make_v(n+1,d,2,modint<MOD>(0));
	dp[0][0][0]=modint<MOD>(1);
	rep(i,n){
		ll a=k[i]-'0';
		rep(j,d)rep(o,10){
			dp[i+1][(j+o)%d][1]+=dp[i][j][1];
			if(o<a) dp[i+1][(j+o)%d][1]+=dp[i][j][0];
			else if(o==a) dp[i+1][(j+o)%d][0]+=dp[i][j][0];
		}
	}
	cout<<(dp[n][0][0]+dp[n][0][1]-1).a<<"\n";
}

Measured memory_bytes: 55424
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
 
int main(int argc, char *argv[]){
  unsigned int N;
  std::cin >> N;
  unsigned int A[N];
  for(auto &a : A){
    std::cin >> a;
  }
  unsigned int X[N];
  for(auto &x : X){
    x = 0;
  }
  unsigned int i,j;
  unsigned int mod;
  unsigned int M = 0;
  std::stack<unsigned int>stack;
  for(i=N; i>=1; --i){
    mod = 0;
    for(j=i; j<=N; j+=i){
      mod += X[j-1];
      mod &= 1;
    }
    if(mod != A[i-1]){
      X[i-1] = 1;
      ++M;
      stack.push(i);
    }
  }

  std::cout << M << std::endl;
  if(M == 0){ return 0; }
  while(!stack.empty()){
    std::cout << stack.top() << " ";
    stack.pop();
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#define ll long long int
using namespace std;
struct Item {
	ll weight;
	ll value;
};
const ll INF = 1LL << 32;
vector<ll> dp(100001, INF);
ll knapSack(ll W, Item items[], ll n)
{
	ll sum = dp[0] = 0;
	for(ll i = 0; i < n; i++)
        {
            sum += items[i].value;
            for(ll j = sum; j >= items[i].value; j--)
                dp[j] = min(dp[j], dp[j - items[i].value] + items[i].weight);
        }
	for(ll i = sum; i >= 0; i--)
	{
		if(dp[i] <= W)
			return i;
	}
}
int main(){
	Item items[100];
	ll N, W;
	cin >> N >> W;
	for(ll i = 0; i < N; i++)		cin >> items[i].weight >> items[i].value;

	cout << knapSack(W, items, N) << endl;
	return 0;
}


Measured memory_bytes: 1024
h,w,K =  map(int,input().split())
masu = [input() for _ in range(h)]
ans = 0
for i in range(2**h):
    for j in range(2**w):
        cnt = 0
        for k in range(h):
            for l in range(w):
                if ((i >> k) & 1) and ((j >> l) & 1) and masu[k][l] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1
 
print(ans)

Measured memory_bytes: 9128
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		final List<Integer> alpha_list = Collections.unmodifiableList(Arrays.asList(new Integer[]{5,7,11,17,19,23,25}));
		
		int n = Integer.parseInt(sc.nextLine());
		
		for(int i = 0; i < n ; i++){
			String str = sc.nextLine();
			
				
			char[] c_str = str.toCharArray();
			char[] tmp_str = str.toCharArray();
			loop:
			for(int alpha = 0;alpha < 26;alpha++){
				for(int beta = 0;beta < 26;beta++){
				
					for(int j = 0; j < c_str.length;j++){
						if(c_str[j] >= 'a' && c_str[j] <= 'z'){
							int tmp = c_str[j] - 'a';
							
							tmp_str[j] = (char)((alpha*tmp + beta) % 26 + 'a');
						}
					}
					
					
					String new_str = new String(tmp_str);
					if(new_str.indexOf("this") != -1 || new_str.indexOf("that") != -1){
						System.out.println(tmp_str);
						break loop;
					}
				}
			}			
		
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#define MAX 10000

int main(void){
    int i,j;
    int input[MAX];
    
    for(i=0;i<MAX;i++){
        scanf("%d",&input[i]);
        if(input[i]==0){
            break;
        }
        else if(input[i]<1||10000<input[i]){
            printf("error\n");
            return 0;
        }
    }
    
    for(j=0;j<i;j++){
        printf("Case %d: %d\n",j+1,input[j]);
    }
    
    return 0;
}


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

int main()
{
float k;
int n;
  cin>>n;
  float a[n]; 
  cin>>k;
  
  
  int i;
  float total=0;
  for(i=0;i<n;i++)
  {
  

	cin>>a[i];
	total+=a[i];
}
  sort(a,a+n);
  
  int count=0;
  float x = 4*k;
  x = 1/x;
  total=total*x;
 // cout<<total<<endl;
  for(i=0;i<n;i++)
  {
    if(a[i]>=total)
    {
      count++;
      //cout<<count<<" ";
    }
    
    
  }
    if(count>=k)
      cout<<"Yes";
  else
    cout<<"No";
  
  
  
}
  
  
  


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

using namespace std;

const int NMAX = 1000;

int d[4][NMAX+2], v[4][NMAX+2];

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

    int N;
    cin >> N;
    for(  int i = 1;  i <= 2;  ++i )
        for( int j = 1;  j <= N;  ++j )
            cin >> v[i][j];
    for(  int j = 1;  j <= N;  ++j ) {
        for( int i = 1;  i <= 2;  ++i ) {
            d[i][j] = max( d[i - 1][j], d[i][j - 1] ) + v[i][j];
        }
    }
    cout << d[2][N] << '\n';
    return 0;
}


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

int main(){
  long  n,r,minv=10000000000,maxv=-10000000000;
  // int n,r;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> r;
    maxv = max(maxv,r-minv);
    minv = min(minv,r);
    
    //  cout << "maxv " <<  maxv << endl;
    //  cout << "minv " <<  minv << endl;
    
  }

  cout << maxv << endl;
  return 0;
}

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

#define mod (ll) (1e9)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
//#define make_pair mp
#define pi acos(-1)

int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
//#endif
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c || a!=b && b!=c && c!=a)
    {
        cout<<"No"<<endl;
        return 0;
    }
    if(a==b || b==c || c==a )
    {
        cout<<"Yes"<<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++)
int main()
{
    vector<int> x(5);
    cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];

    rep(i, 5)
    {
        if (x[i] == 0)
        {
            cout << i + 1 << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int inf = 1<<30;
const ll mod = 1000000007;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

int main () {
  int A, B; cin >> A >> B;
  cout << max({A+B, A-B, A*B}) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
ll a[200001];
int main() {
	// your code goes here
	
	ll i,j,k,n,m,t;
	cin>>n;
	ll xo=0;
	for(int i=0;i<n;i++){
	    cin>>a[i];
	    xo ^= a[i];
	}
	for(int i=0;i<n;i++) {
	    cout<<(a[i]^xo)<<" ";
	}
	
	
	return 0;
}


Measured memory_bytes: 5184
import math
import sys
import resource
n = int(input());
dp = []
def dfs(x, i) :
  dp[i] = dp[i-1] + i
  # print(i, dp[i])
  if dp[i] >= n : 
    return i
  return dfs(dp[i], i+1)

sys.setrecursionlimit(100000)

sz = 100000
dp = [0] * sz
print(dfs(0, 1))

Measured memory_bytes: 43588
#![allow(dead_code)]
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let a: i32 = sc.read();
    let b: i32 = sc.read();

    format!("{}\n", std::cmp::max(0, a-2*b))
}
#[test]
fn test_solve() {
   assert_eq!(solve("12 4\n"), "4\n");
   assert_eq!(solve("20 15\n"), "0\n");
   assert_eq!(solve("20 30\n"), "0\n");
   assert_eq!(solve("12 4\n"), "4\n");
   assert_eq!(solve("20 15\n"), "0\n");
   assert_eq!(solve("20 30\n"), "0\n");
}
fn main() {
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf).unwrap();
    use std::io::Write;
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<I> {
    src: I,
}
impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner {
            src: src.split_whitespace(),
        }
    }
}
impl<'a, I> Scanner<I>
where
    I: std::iter::Iterator<Item = &'a str>,
{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}

Measured memory_bytes: 4352
//<MIHIR KHAMBHATI/>
#include <bits/stdc++.h>
#include <chrono>
using namespace std::chrono;
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// // Declaring ordered_set
// typedef tree<ll, null_type, less<ll>, rb_tree_tag,
//             tree_order_statistics_node_update>
//    ordered_set;

#define _start_ auto __start__ = high_resolution_clock::now();
#define _stop_ cerr << "\n" \
                    << duration_cast<microseconds>(high_resolution_clock::now() - __start__).count() / (double)1000000 << " sec\n";
#define mod 998244353
#define _                             \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define ideb \
    int _p_; \
    cin >> _p_;
typedef long long int ll;
typedef unsigned long long int ull;
long long power(long long x, long long n)
{
    long long result = 1;
    while (n > 0)
    {
        if (n % 2 == 1)
            result = (result % mod * x % mod) % mod;
        x = (x % mod * x % mod) % mod;
        n = n / 2;
    }
    return result % mod;
}

int main()
{
    int n;
    cin >> n;

    int dp[n][3];
    int a[n][3];

    for (int i = 0; i < n; i++)
    {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }

    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];

    for (int i = 1; i < n; i++)
    {
        dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = a[i][2] + max(dp[i - 1][1], dp[i - 1][0]);
    }

    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}

Measured memory_bytes: 2560
import sys
import math
ans = float('inf')
a,b,c,x,y = map(int,sys.stdin.readline().rstrip().split())
for i in range(max(x,y)+1):
  if x > y and i >= y:
  	sum = a * (x - i) +  2 * i * c
  elif y > x and i >= x:
    sum = b * (y - i) + 2 * i * c
  else:
    sum = a * (x - i) + b * (y - i) + 2 * i * c
  ans = min(ans,sum)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;


int main(){
    ll A;
    cin >> A;
    ll B;
    cin >> B;
    ll ans=0;
    ans+=max(A,B);
    if(A>B)A--;else B--;
    ans+=max(A,B);
    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 256
n = int(input())
c = input()
w = 0
r = c.count('R')
ans = r

for k in range(n):
  if c[k] == 'W':
    w += 1
  elif c[k] == 'R':
    r -= 1
  cnt = max(w, r)
  if ans > cnt:
    ans = cnt
print(ans)

Measured memory_bytes: 9468
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

using namespace std;

int main() {
  long long h, w;
  cin >> h >> w;
  long long ans = 1987654321;
  long long ans2 = ans;

  long long anss[2];

  for (int xx = 0; xx < 2; xx++) {
    if (h % 3 == 0 || w % 3 == 0) {
      cout << 0 << endl;
      return 0;
    }

    for (long long a = 1; a < h; a++) {
      long long b = w / 2;
      long long x = a * w;
      long long y = (h - a) * b;
      long long z = (h - a) * (w - b);
      long long tmp = min(x, y);
      long long mini = min(z, tmp);
      tmp = max(x, y);
      long long maxx = max(z, tmp);
      tmp = maxx - mini;
      ans = min(ans, tmp);
      // cout << ans << " ";
    }

    // cout << endl;

    for (long long c = 1; c < h; c++) {
      long long tmp = max(c, h - 2 * c) - min(c, h - 2 * c);
      ans2 = min(ans2, tmp);
      // cout << ans2 << " ";
    }
    ans2 *= w;

    long long tmp = w;
    w = h;
    h = tmp;

    anss[xx] = min(ans, ans2);
  }
  cout << min(anss[0], anss[1]) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cmath>
#include <string>
#include <iomanip>

#define loop(k) for(int i=0;i<k;i++)
#define looop(k) for(int j=0;j<k;j++)
#define solve(s,c) {int judge{}; loop(n){if(s[i]!=c[i%3]) {judge=-1;break;}}cout<<(judge==-1?-1:m)<<endl;}
#define swap(a,b) a^=b^=a^=b;

using namespace std;

int main(){
    string s,ans;
    cin>>s;
    
    int l = s.length();
    loop(l){
        int n=ans.length();
        if(s[i]!='B'){
            ans.push_back(s[i]);
        }else if(n >0){
            ans.pop_back();
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive.lib
{

    internal class Solution
    {
        public int A, B;

        public void Run()
        {
            int[] G = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
            {
                var line = Input.ReadIntArray();
                A = line[0];
                B = line[1];

            }

            int ret = 0;

            for(int a = 1; a <= 12; a++)
            for (int b = 1; b <= G[a]; b++)
            {
                if ( ((a < A) || (a <= A && b <= B)) && a == b) ret++;
            }

            Console.WriteLine(ret);

        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13268
#include<cstdio>
#include<cstring>

int main() {
  char ch1[101], ch2[101], ch3[201] = {};

  scanf("%s %s",ch1, ch2);

  strcat( ch3, ch1);
  strcat( ch3, ch1);

  if( strstr( ch3, ch2) == NULL) printf("No\n");
  else printf("Yes\n");

  return 0;
}

Measured memory_bytes: 2676
/*
 * written by Yaqi Zhang
 * University of Wisconsin-Madison
 * 2020
 */

#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stdio.h>
#include<vector>

#define INF 0x3f3f3f3f

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> ps(A), qs(B), rs(C);

    for(int i = 0; i < A; ++i) {
        int x;
        cin >> x;
        ps[i] = x;
    }

    for(int i = 0; i < B; ++i) {
        int x;
        cin >> x;
        qs[i] = x;
    }

    for(int i = 0; i < C; ++i) {
        int x;
        cin >> x;
        rs[i] = x;
    }

    sort(ps.rbegin(), ps.rend());
    sort(qs.rbegin(), qs.rend());
    sort(rs.rbegin(), rs.rend());

    // can use C
    // How many C needed?
    // not DP
    // greedy?
    long long best = 0LL;
    priority_queue<int, vector<int>, greater<int>> pq;
    for(int i = 0; i < X; ++i){
        pq.push(ps[i]);
        best += ps[i];
    }

    for(int i = 0; i < Y; ++i){
        pq.push(qs[i]);
        best += qs[i];
    }

    long long cur = best;
    for(int i = 0; i < min(X + Y, C); ++i) {
        pq.push(rs[i]);
        cur += rs[i];
        cur -= pq.top();
        pq.pop();
        best = max(best, cur);
    }
    cout << best << endl;
    return 0;
}


Measured memory_bytes: 2552
import java.util.Scanner;

class B {
    public static long MOD = 998244353;

    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int[] D = new int[N];
        for (int i = 0; i < N; i++)
            D[i] = sc.nextInt();
        final int[] cnt = new int[N];
        for (int i : D)
            cnt[i]++;
        if (D[0] != 0 || cnt[0] != 1) {
            System.out.println(0);
        } else {
            long ans = 1;
            int used = 1;
            for(int i = 1; i < N && used < N; used += cnt[i++]) {
                for(int j = 0; j < cnt[i]; j++)
                    ans = ans * cnt[i - 1] % MOD;
            }
            System.out.println(ans);
        }
    }
}
public class Main {
    public static void main(String...args) {
        B.main();
    }
}


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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  string S;
  cin >> S;
  ll len = S.size();
  ll res = 0;
  for(ll i = 0; i < (1 << (len-1)); i++){
    vector<bool> plus(len, false);
    for(int j = 0; j < len-1; j++){
      if((i >> (len - 2 - j)) & 1){
	plus[j] = true;
      }
    }
    ll a = 0;
    ll b = 0;
    ll tmp = 0;
    while(b < len){
      if(plus[b]){
	tmp += stoll(S.substr(a, b-a+1));
	b++;
	a = b;
      }else{
	b++;
      }
    }
    tmp += stoll(S.substr(a, b-a+1));
    res += tmp;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
import sys
from copy import deepcopy as copy
from collections import deque
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    
    tree = [[] for _ in range(n)]
    edge = dict()
    for i in range(m):
        a, b = map(int, input().split())
        tree[a-1].append(b-1)
        edge[(a-1, b-1)] = i+1
    
    ans = 0
    for i in range(n):
        not_yet = deque([i])
        already = [False]*n
        dist = [0]*n
        par = [0]*n
        already[i] = True
        sub = []
        
        while not_yet:
            key = not_yet.popleft()
            for v in tree[key]:
                if already[v]:
                    
                    if v == i:
                        sub = [key+1]
                        now = key
                        while now != i:
                            sub.append(par[now]+1)
                            now = par[now]
                        break
                    continue
                
                not_yet.append(v)
                already[v] = True
                dist[v] = dist[key] + 1
                par[v] = key
            if sub:
                break
            
        if sub:
            if ans:
                if len(ans) > len(sub):
                    ans = copy(sub)
            else:
                ans = copy(sub)
            
        
    if ans:
        print(len(ans))
        for a in ans:
            print(a)
    else:
        print(-1)
        
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 70424
def rotate_clockwise(matrix):
    tmp = list(map(list, zip(*matrix)))[::-1]
    return list(''.join(row) for row in tmp)
    # 文字列のリストを入れるので文字列のリストで返す


def rotate_counterclockwise(matrix):
    tmp = list(map(lambda x: list(x[::-1]), zip(*matrix)))
    return list(''.join(row) for row in tmp)
    # 文字列のリストを入れるので文字列のリストで返す


H, W = [int(i) for i in input().split()]
A = [input() for _ in range(H)]

row_remove_count = 0
while '.' * W in A:
    A.remove('.' * W)  # 行まるごと白なら、回数を記録して除く
    row_remove_count += 1

A = rotate_clockwise(A)  # 反時計回りに回す
while '.' * (H - row_remove_count) in A:
    A.remove('.' * (H - row_remove_count))

A = rotate_counterclockwise(A)  # 時計回りに回して元に戻す
print('\n'.join(A))

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
# 整数の入力
a,b,c,d,e = map(int, input().split())
if a == 0:
  print (1)
elif b == 0:
  print (2)
elif c == 0:
  print (3)
elif d == 0:
  print (4)
else:
  print (5)

Measured memory_bytes: 9172
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<int> p(n);  
  rep(i,n) {
    cin >> p[i];
    p[i]--;
  }
  map<int,ll> mp;
  rep(i,n) mp[p[i]] = (ll)i;
  set<ll> st;
  
  ll res = 0;
  for(int i=n-1;i>=0;--i){
    ll index = mp[i];
    st.insert(index);
    vector<ll> l(2,-1);
    vector<ll> r(2,n);
    {
      auto itr = st.find(index);
      rep(j,2){
	if(itr == st.begin()) break;
	--itr;
	l[j] = *itr;
      }
    }
    {
      auto itr = st.find(index);
      rep(j,2){
	++itr;	
	if(itr == st.end()) break;
	r[j] = *itr;
      }      
    }
    ll c = (r[1]-r[0])*(index-l[0])+(r[0]-index)*(l[0]-l[1]);
    res += c*((ll)i+1);
  }
  
  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 11520
#include <iostream>
#define inf 1000000000

using namespace std;

int H, W;
char map[305][305];
int cost[305][305][305];
int dp[305][305];

int main(void)
{
	cin >> H >> W;
	for(int y = 1; y <= H; y++){
		for(int x = 1; x <= W; x++){
			cin >> map[x][y];
		}
	}
	
	for(int i = 1; i < W; i++){
		for(int j = 0; j <= H; j++){
			int cnt = 0;
			for(int k = 1; k <= H-j; k++){
				if(map[i][j+k] == map[i+1][k]) cnt++;
			}
			for(int k = 0; k <= H-j; k++){
				cost[i][H-k][H-j-k] = cnt;
				if(map[i][H-k] == map[i+1][H-j-k]) cnt--;
			}
			
			cnt = 0;
			for(int k = 1; k <= H-j; k++){
				if(map[i+1][j+k] == map[i][k]) cnt++;
			}
			for(int k = 0; k <= H-j; k++){
				cost[i][H-j-k][H-k] = cnt;
				if(map[i+1][H-k] == map[i][H-j-k]) cnt--;
			}
		}
	}
	
	int ans = 0;
	for(int i = 1; i < W; i++){
		for(int j = H; j >= 0; j--){
			for(int k = H; k >= 0; k--){
				dp[j][k] = inf;
			}
		}
		dp[H][H] = 0;
		
		for(int j = H; j >= 0; j--){
			for(int k = H; k >= 0; k--){
				if(j > 0) dp[j-1][k] = min(dp[j-1][k], dp[j][k] + cost[i][j][k]);
				if(k > 0) dp[j][k-1] = min(dp[j][k-1], dp[j][k] + cost[i][j][k]);
			}
		}
		ans += dp[0][0];
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 110592
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void _main() {
  int N;
  cin >> N;
  vector<int> b(N);
  rep(i, 0, N) cin >> b[i];
  vector<int> ans(N);

  for (int n=N-1; n>=0; n--) {
    int i=n;
    while (i >= 0) {
      if (b[i] == i+1) break;
      i--;
    }

    if (i == -1) {
      cout << "-1" << endl;
      return;
    }

    b.erase(b.begin() + i);
    ans[n] = i+1;
  }

  rep(i, 0, N) cout << ans[i] << endl;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Favorite Sound
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);

  printf("%d\n", min(b / a, c));
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

int main() {
    string s;
    cin >> s;
    int n = s.length();
    rep (i, n) {
        FOR (j, i+1, min(n, i+3)) {
            if ( s[j] == s[i] ) {
                printf("%d %d\n", i+1, j+1);
                return 0;
            }
        }
    }
    printf("-1 -1\n");
    return 0;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    X = inputInt()
    
    ans = (math.sqrt(8*X+1)-1)/2
    
    print(int(math.ceil(ans)))
    
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 38768
#include <iostream>
using namespace std;
int main(){
	int n,j,j1,j2,a;
	cin>>n;
	for(int i=0;i<n;i++){
		j1=j2=0;a=1;
		for(int k=0;k<10;k++){
			cin>>j;
			if(j1<j&&j2<j){if(j1<j2)j2=j;else j1=j;
			}else if(j1<j)j1=j;
			else if(j2<j)j2=j;
			else a=0;
		}
		if(a==1)cout<<"YES"<<endl;else cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Diagnostics;
using static System.Math;
using static System.Array;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int A, B, C;
       
        
        
        

        public static void Input()
        {
            var cin = new Scanner();
            var input = cin.SplitReader();
            Sort(input);  //A<=B<=C
            A = input[0];
            B = input[1];
            C = input[2];
        }

        static void Main(string[] args)
        {
            Input();

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            long ans = 0;
            while (A <= C - 2) 
            {
                ans++;
                A += 2;
            }

            while (B <= C - 2)
            {
                ans++;
                B += 2;
            }

            if ((B == C && A == C - 1) || (B == C - 1 && A == C)) 
            {
                ans += 2;
            }
            else if (A == C - 1 && B == C - 1)
            {
                ans++;
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();

        }





    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }

    public class Graph
    {
        
    }
}

    



Measured memory_bytes: 13396
import sys

def main():
    for line in iter(sys.stdin.readline, ""):
        a = line.rstrip("\n").split(" ")
        b = []
        b.append(int(a[0]))
        b.append(int(a[1]))
        if (b[0] == 0 and b[1] == 0):
            return

        print(str(min(b)) + " " + str(max(b)))
     
if __name__ == "__main__":
    main()

Measured memory_bytes: 6720
n, m, l = (int(i) for i in input().split())
A = []
B = []
#C = [[0] * n] * l
C = [[0 for i in range(l)] for j in range(n)]

#??\?????????????????????????´?
for i in range(n):
    #swap_list = input().split()
    #A.append(swap_list)
    A.append([int(i) for i in input().split()])
for i in range(m):
    #swap_list = input().split()
    #B.append(swap_list)
    B.append([int(i) for i in input().split()])
#????????????????¨????
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]
#?????????????????????
#for i in range(n):
#    for j in range(l):
#        print("{0}".format(C[i][j]), end="\b")
#    print("")
#for i in range(n):
#    print(" ".join(map(str, C[i][:])))
for r in C:
    print(" ".join([str(d) for d in r]))

Measured memory_bytes: 8888
#include <iostream>
#include <set>
#include <cmath>
#include <vector>
using namespace std;
using p = pair<int, long long>;
using ll = long long;
const auto INF = (ll)1e5;
int main()
{
    int n;
    cin >> n;
    int s9 = (int)(5 / log10(9));
    int s6 = (int)(5 / log10(6));

    auto m = vector<ll>();
    int l6 = 1;
    int l9 = 1;
    for (int i = 1; i <= s6; i++)
    {
        l6 *= 6;
        m.push_back(l6);
    }

    for (int i = 1; i <= s9; i++)
    {
        l9 *= 9;
        m.push_back(l9);
    }
    m.push_back(1);
    auto dp = vector<vector<ll>>(m.size()+1, vector<ll>(n + 1, INF));

    for (int i = 0; i < m.size(); i++)
    {
        dp[i][0] = 0;
    }

    for (int i = 0; i < m.size(); i++)
    {
        for (int j = 0; j <= n; j++)
        {
            if (j < m[i])
                dp[i + 1][j] = dp[i][j];//min(dp[i][j],dp[i+1][j]);
            else
                dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - m[i]] + 1);
        }
    }
    cout << dp[m.size()][n];
}

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

int main() {
	int n;
	int a, b;

	cin >> n;

	if( n == 2 ) {
		cin >> a >> b;
		cout << a + b << endl;
	}
	else {
		cout << "Hello World" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int h,a,c;
	scanf("%d %d",&h,&a);
	c=0;
	while(1){
		if(h<=0) break;
		else{
			h=h-a;
			c++;
		}
	}
	printf("%d\n",c);
	return 0;
}


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

arr = [0] * 200000
for i in range(len(a)):
    arr[a[i]] += 1

arr.sort()
arr.reverse()

s = 0
for i in range(k):
    s += arr[i]
    
print(n-s)


Measured memory_bytes: 25748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
  ll x,y;
  cin >> x >> y;
  vector<ll>a={1,3,5,7,8,10};
  vector<ll>b={4,6,9,11};
  ll judge=0;
  for(ll i=0;i<a.size();i++){
    if(x==a[i]) judge++;
    if(y==a[i]) judge++;
  }
  if(judge==2){
    cout << "Yes" << endl;
    return 0;
  }
  judge=0;
  for(ll i=0;i<b.size();i++){
    if(x==b[i]) judge++;
    if(y==b[i]) judge++;
  }
  if(judge==2) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.Scanner;


public class Main 
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
	
		ArrayList<Integer> in = new ArrayList<Integer>();
		for(; scanner.hasNext();)
		{
			int n = scanner.nextInt();
			if(n == 0)
			{
				System.out.println(in.get(in.size()-1));
				in.remove(in.size()-1);
			}
			else
			{
				in.add(n);
			}
		}
	}
}

Measured memory_bytes: 26040
/*..............................................*\
Author:Kishor Kumar Paroi
Dept:CSE-1703053
email.kishor.josephite@gmail.com
RUET,BANGLADESH
\*---------------------------*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include<bits/stdc++.h>
#include<iostream>
#include<iterator>

#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vi vector<int>v
//const int N=100*1000;
//const int mod=1e9+7;

//# define int min3(int a,int b,int c){return min(a,min(b,c));}
//#define int max3(int a,int b,int c){return max(a,max(b,c));}
//#define int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
//#define int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int N,T,x=0;
    vi;
    cin>>N>>T;
    for(int i=0; i<N; i++)
    {
        int num,t;
        cin>>num;
        cin>>t;
        if(t>T)
        {
                 x++;
            continue;
        }
        else
            v.push_back(num);
    }
    sort(v.begin(),v.end());
    if(x==N)
        cout<< "TLE"<<endl;
    else
        cout<<v.front()<<endl;
}



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

using namespace std;

int main(int argc, char const *argv[])
{
    int a, b, ans;
    char op;
    while (true) {
        cin >> a >> op >> b;
        if (op == '?') {
            break;
        }

        if (op == '+') {
            ans = a + b;
        } else if (op == '-'){
            ans = a - b;
        } else if (op == '*') {
            ans = a * b;
        } else if (op == '/') {
            ans = a / b;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3068
#

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
#b.append(0)
b.append(0)
z = 0
c = b[0]
for i in range(n+1):
    x = a[i] - c
    #print(z)
    if i < n:
        if x <= 0:
            z += a[i]
            #print(a[i])
            if -x >= a[i+1]:
                c = b[i+1] + a[i+1]
            elif -x < a[i+1]:
                c = b[i+1] - x
        elif x > 0:
            z += c
            #print(c)
            c = b[i+1]
    elif i == n:
        if x <= 0:
            z += a[i]
            #print(a[i])
        else:
            z += c
            #print(c)
print(z)


Measured memory_bytes: 19004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
  //int A, j = 0, l = 0, k= 0, f = 0;
  int A, sum = 0;
  cin >> A;
  int B = A;
 
  // ここにプログラムを追記
  while (1 == 1) {
    sum = sum + (B % 10);
    B = B / 10;
    
  	if (B < 10) {
    	sum = sum + B;
      	break;
    }
  }
  
  	if ((A % sum) == 0) {
		cout << "Yes";
    }
  	else{
		cout << "No";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;
int main()
{
    ll a,b,k,i,j,x,p,c=0;
    vector<ll> v;
    cin>>a>>b>>k;
    x=k;
    for(i=a; i<=b; i++)
    {
        x--;
        cout<<i<<endl;
        p=i;
        ;
        if(x==0)break;
    }
    x=k;
    for(i=b; i>=a; i--)
    {
        x--;
        if(p==i){break;}
        v.push_back(i);
        //v[c]=i;
        //c++;
        if(x==0){break;}
    }

    sort(v.begin(),v.end());

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

        cout<<v[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N];
double b[N];

int main()
{
    int n,k;
    double maxx=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];

    for(int i=1;i<=n;i++)
    {
        b[i]=1.0/a[i]*(1.0+a[i])*a[i]/2.0;
    }


    for(int i=1;i<=k;i++)
        maxx+=b[i];

    int s=1;
    double tmp=maxx;
    for(int i=k+1;i<=n;i++)
    {
        if(maxx-b[i-k]+b[i]>maxx)
            s=i-k+1;
        tmp=tmp-b[i-k]+b[i];
        maxx=max(maxx,tmp);
    }
    cout<<fixed<<setprecision(10)<<maxx<<endl;
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

class SegTree {
 private:
  const ll def_val_ = 1000000;
  vl val_;
  ll n_;

  ll comp(ll l, ll r) { return min(l, r); }

  ll getr(ll x, ll y, ll k, ll l, ll r) {
    if (y <= l || r <= x) return def_val_;
    if (x <= l && r <= y) return val_[k];
    auto vl = getr(x, y, 2 * k + 1, l, (l + r) / 2);
    auto vr = getr(x, y, 2 * k + 2, (l + r) / 2, r);
    return comp(vl, vr);
  }

 public:
  SegTree(ll size) {
    n_ = 1;
    while (n_ < size) n_ *= 2;
    val_ = vl(2 * n_, def_val_);
  }

  void update(ll i, ll v) {
    i += (n_ - 1);
    val_[i] = v;
    while (i > 0) {
      i = (i - 1) / 2;
      val_[i] = comp(val_[2 * i + 1], val_[2 * i + 2]);
    }
  }

  // get XXX value between [x,y)
  ll getRange(ll x, ll y) { return getr(x, y, 0, 0, n_); }
};

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

  ll n;
  cin >> n;
  SegTree st(n);
  ll ans = 0;
  rep(i, n) {
    ll p;
    cin >> p;
    st.update(i, p);
    ll m = st.getRange(0, i);
    // cerr << i << m << endl;
    if (i == 0)
      ans++;
    else if (m >= p)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a[5];
	for(int i=0;i<5;i++)
		cin>>a[i];
	for(int i=0;i<4;i++){
      for(int j=4;j>i;j--){
	  if(a[j]>a[j-1]){
	      int tmp=a[j];
	      a[j]=a[j-1];
	      a[j-1]=tmp;
	   }
       }
   }
	for(int i=0;i<4;i++)
		cout<<a[i]<<" ";
	cout<<a[4]<<endl;
	return 0;
}

Measured memory_bytes: 1164
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll; 

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end(), greater<int>());

	int A = 0, B = 0;
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			A += a[i];
		} else {
			B += a[i];
		}
	}

	int res = A - B;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[25]={0,1,3,1,2,1,2,1,1,2,1,2,1};
int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    if(a[x]==a[y])
        puts("Yes");
    else
        puts("No");
    return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    answer = 0
    temp = A[0]
    right = 0

    for i in range(N):
        if right < N - 1:
            while temp + A[right + 1] == temp ^ A[right + 1]:
                right += 1
                temp += A[right]
                if right == N - 1:
                    break
            temp -= A[i]
            answer += right - i + 1
        else:
            answer += right - i + 1

    print(answer)


if __name__ == '__main__':
    main()

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

int main(void){
   int N;
   cin>>N;
   vector<double> a(N);
   for(int i=0;i<N;i++){
      cin>>a[i];
   }
   double average=0.0;
   for(int i=0;i<N;i++){
      average+=a[i];
   }
   average/=N;
   int ans=N;
   double dist=average;
   for(int i=0;i<N;i++){
      dist=min(dist,abs(a[i]-average));
   }
   for(int i=0;i<N;i++){
      if(dist==abs(a[i]-average)){
         ans=min(ans,i);
      }
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 3768
#include<iostream>
#include<queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N];

void bfs(int s) {
  queue<int> q;
  q.push(s);
  for ( int i = 0; i < n; i++ ) d[i] = INFTY;
  d[s] = 0;
  int u;
  while ( !q.empty() ) {
    u = q.front(); q.pop();
    for ( int v = 0; v < n; v++ ) {
      if ( M[u][v] == 0 ) continue;
      if ( d[v] != INFTY ) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  for ( int i = 0; i < n; i++ )
    cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
}

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

  cin >> n;
  for ( int i = 0; i < n; i++ )
    for ( int j = 0; j < n; j++ ) M[i][j] = 0;

  for ( int i = 0; i < n; i++ ) {
    cin >> u >> k;
    u--;
    for ( int j = 0; j < k; j++ ) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  bfs(0);

  return 0;
}


Measured memory_bytes: 3128
///
// File:  c.go
// Author: ymiyamoto
//
// Created on Sat Apr 14 21:57:39 2018
//
package main

import (
	"fmt"
	"sort"
)

var N int
var X []int

func main() {
	fmt.Scan(&N)

	X = make([]int, N)
	sorted := make([]int, N)
	for i := range X {
		fmt.Scan(&X[i])
		sorted[i] = X[i]
	}

	sort.Ints(sorted)

	for i := 0; i < N; i++ {
		if X[i] < sorted[N/2] {
			fmt.Println(sorted[N/2])
		} else {
			fmt.Println(sorted[N/2-1])
		}
	}
}


Measured memory_bytes: 11140
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n
a1
...
an
 */
int n;
set<int> st;

int main(){
  cin>>n;
  REP(i,n){
    int a;
    cin>>a;
    if(st.count(a))
      st.erase(a);
    else
      st.insert(a);
  }
  cout << st.size()<<endl;

  return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int t=1e9,k=0;
    for(int i=0;i<n;i++){
        if(abs(a[n-1]/2-a[i])<t) k=i,t=abs((a[n-1]+1)/2-a[i]);
    }
    cout<<a[n-1]<<" "<<a[k]<<endl;
}

Measured memory_bytes: 640
#include <iostream>

int main()
{
    int x, y;

    while (true)
    {
        std::cin >> x >> y;
        if (x == 0 && y == 0)
        {
            break;
        }
        if (x <= y)
        {
            std::cout << x << ' ' << y << std::endl;
        }
        else
        {
            std::cout << y << ' ' << x << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3116
n,a,b=map(int,input().split())
if (a-b)%2==0:
  print(abs(a-b)//2)
else:
  if a+b<n+1:
    print(min(a,b)+(abs(a-b)-1)//2)
  else:
    print(min(n+1-a,n+1-b)+(abs(a-b)-1)//2)

Measured memory_bytes: 3060
#include <stdio.h>
int main(){
  int a,b;
  char op;
  while(1){
  scanf("%d %c %d",&a,&op,&b);
  if(op=='?')break;
  if (op=='+'){
    printf("%d\n",a+b);
  }else if(op=='-'){
    printf("%d\n",a-b);
  }else if(op=='*'){
    printf("%d\n",a*b);
  }else if(op=='/'){
    printf("%d\n",a/b);
  }}
	  return 0;
}

Measured memory_bytes: 600