akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pld pair<long double, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ff first
#define ss second
#define SZ(x) ((int)(x).size())
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int x;

void read(){
    cin >> x;
}

void solve(){
    read();
    cout << (x^1);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}



Measured memory_bytes: 3660
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back

using namespace std;
typedef long long ll;

int main()
{
  int N; cin >> N;
  vector<int> A(N), B(N), C(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  REP(i, N) cin >> C[i];
  sort(ALL(A));
  sort(ALL(C));

  ll ans = 0;
  REP(i, N) {
    ll idxA = lower_bound(ALL(A), B[i]) - A.begin() - 1;
    ll idxC = upper_bound(ALL(C), B[i]) - C.begin();
    ans += (idxA + 1) * (N - idxC);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1408
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Collections;
import java.util.Arrays;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		int N = reader.nextInt();
		int K = reader.nextInt();
		System.out.println(N-K+1);
	}
	
	public static void solver(int N, int K) {
		// write logic
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


Measured memory_bytes: 21460
import sys

n, m, *ab = map(int, sys.stdin.read().split())
g = [set() for _ in range(n+1)]
for a, b in zip(*[iter(ab)] * 2):
    g[a].add(b)
    g[b].add(a)

def main():
    return 'POSSIBLE' if g[1] & g[n] else 'IMPOSSIBLE'

if __name__ == '__main__':
    ans = main()
    print(ans)

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

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

    if ((a % 3 == 0) or (b % 3 == 0) or ((a + b) % 3 == 0))
    {
        cout << "Possible" << endl;
    }
    else
    {
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <cmath>

#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, MOD = 1e9 + 7;

int N, a[3005];
ll dp[3005][3005];

ll f(int l, int r) {
    if (dp[l][r]) return dp[l][r];
    if (l > r) return 0;
    if (l == r) return a[l];
    return dp[l][r] = max(a[l] - f(l + 1, r), a[r] - f(l, r - 1));
}

int main() {
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> a[i];
    cout << f(1, N) << '\n';
    return 0;
}

Measured memory_bytes: 70144
import collections, math

local = False
if local:
    import time
    file = open("input.txt", "r")

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()

K = int(inp())

mem = dict()

#k<=200

summed = 0

for a in range(1,K+1):    
    for b in range(a,K+1):
        ab = math.gcd(a,b)
        for c in range(b,K+1):
            if a==b and a==c:
                summed+=a
            elif a!=b and a!=c and b!=c:
                summed += 6*math.gcd(c, ab)
            else:
                summed += 3*math.gcd(c, ab)


print(summed)

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")

Measured memory_bytes: 74004
#include "bits/stdc++.h"
using namespace std;

int main()
{
  int n;
  cin>>n;
  for(int i=n;;i++)
  {
    int h=1;
    for(int j=2;j<=sqrt(i);j++)
    {
      if(i%j==0)
      {
        h=0;
        break;
      }
    }
    if(h==1)
    {
      cout<<i<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3640
people_num, start_point, correct_num = map(int, input().split())
table = [start_point] * people_num
for i in range(correct_num):
    correct_person = int(input())
    table[correct_person-1] += 1
for j in range(people_num):
    table[j] -= (1 * correct_num)
for k in range(people_num):
    if table[k] <= 0:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 12992
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so sort
#define rev reverse
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;


int main (){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    int ans = (n-1)/(k-1);
    if((n-1) % (k-1) != 0)ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
def count_divisors(n: int, a: int, b: int) -> int:
    num_divisors = sum([(n % q) == 0 for q in range(a, b + 1)])
    return num_divisors


if __name__ == "__main__":
    a, b, n = map(lambda x: int(x), input().split())
    print(count_divisors(n, a, b))



Measured memory_bytes: 5644
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Convert;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }


        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var K = cin.ReadInt;
            var A = new Dictionary<int, int>();
            for(int i = 0; i < N; i++)
            {
                var a = cin.ReadInt;
                if (!A.ContainsKey(a))
                    A.Add(a, 0);
                A[a]++;
            }
            A = A.OrderBy(v => v.Value).ToDictionary(v => v.Key, v => v.Value);

            if (A.Keys.Count <= K)
            {
                WriteLine(0);
                return;
            }

            var ans = A.Take(A.Keys.Count - K).Sum(v => v.Value);
            WriteLine(ans);
        }


        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
        A: [u64; N],
    }
    
    let mut min_div = A[0];
    let mut count: u32;

    loop {
        count = 0;

        for num in A.iter_mut() {
            *num = (*num + min_div - 1) %  min_div + 1;

            if *num < min_div {
                min_div = *num;
                count += 1;
            }
        }

        if count == 0 {
            break;
        }
    }

    println!("{}", min_div);
}


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

int main(){
  string s;
  cin >> s;
  int hantei=0;
  if (s.at(0)!='A'){
    hantei--;
  }
  if (s.at(1)=='C'){
    hantei--;
  }
  if (s.at(s.size()-1)=='C'){
    hantei--;
  }
  int count=0;
  for (int i=2;i<s.size()-1;i++){
    if (s.at(i)=='C'){
      count++;
    }
  }
  if (count!=1){
    hantei--;
  }
  int oomozi=0;
  for (int i=1;i<s.size();i++){
    if (s.at(i)>='A'&&s.at(i)<='Z'){
      oomozi++;
    }
  }
  if(oomozi!=1){
    hantei--;
  }
  if (hantei==0){
    cout << "AC" << endl;
  }
  else {
    cout << "WA" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int mp[5][105];
int n;
int dp[5][105];
int road(int A,int B){
  int ret=0;
  if(dp[A][B]!=-1) return dp[A][B];
  if(A==2&&B==n) return 0;
  else if(A<2&&B<n){
  ret=max(road(A+1,B)+mp[A][B],road(A,B+1)+mp[A][B]);
  }else if(A<2){
    ret=road(A+1,B)+mp[A][B];
  }else if(B<n){ 
    ret=road(A,B+1)+mp[A][B];
  }

  return dp[A][B]=ret;
}
 

int main(){
  memset(dp,-1,sizeof(dp));
  cin>>n;

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


  cout<<road(1,1)+mp[2][n]<<endl;
  
    return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args:Array[String]) {
	val age = scala.io.StdIn.readInt
	
	if(age == 1) {
	  println("Hello World")
	}
	else if(age == 2) {
      println(scala.io.StdIn.readInt + scala.io.StdIn.readInt)
	}
  }
}

Measured memory_bytes: 25412
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    string s;
    cin >>s ;
    set<char> st;
    for(auto& c : s) {
        st.insert(c);
    }
    REP(c, 'a', 'z'+1) if(st.count(c) == 0) {
        cout << (char)c << endl;
        return 0;
    }
    cout << "None" << endl;
    return 0;
}

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

int main(){
    ll n,m,ans;
    cin >> n >> m;
    //ans = 0;
    ans = n * (n-1)/2 + m * (m-1) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long N,P,ans,cur,t=1,cnt[10010],i;string S;
int main()
{
    cin>>N>>P>>S;
    if(P==2||P==5){
        for(i=0;i<N;i++)if((S[i]-'0')%P==0)ans+=i+1;
    }else{
        cnt[0]=1;
        for(i=N-1;i>=0;i--){
            (cur+=(S[i]-'0')*t)%=P;
            ans+=cnt[cur]++;
            t=t*10%P;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 644
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int h,w;

int main(){
  cin >> h >> w;
  REP(i,h){
    string s;
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
d2 = 0
d4 = 0
for i in a:
    if i % 4 == 0:
        d4 += 1
    elif i % 2 == 0:
        d2 += 1
if d4 >= N // 2:
    print("Yes")
elif d2 >= N - d4 * 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 15020
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 
 
#define F first
#define S second
#define ll long long
#define pb push_back
#define db double
#define ld long double
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long long, long long>
#define piii pair<int, pii>
#define all(x) (x).begin(),(x).end()
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define TEST int T; cin >> T; while(T--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//#define int long long
 
const int N = 2e5 + 1, inf = 2e9 + 7, mod = 1e9 + 7;
const ll INF = 2e18 + 7, MOD = 1e15 + 7;

bool dp[N];

signed main() { __
//    freopen("lcm.in", "r", stdin);
//    freopen("lcm.out", "w", stdout);
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= n; j++) {
            if (i - a[j] >= 0 && !dp[i - a[j]]) {
                dp[i] = 1;
            }
        }
    }
    if (dp[k]) cout << "First";
    else cout << "Second\n";
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
	char S[200001],T[200001];
  	int ans=0,j=0;
    cin>>S>>T;
  	while(S[j]!='\0'){
    	j++;
    }
  	
    for(int i=0;i<j;i++){
  		if(S[i]!=T[i])	ans++;
 	 }
  	cout<<ans<<endl;
  	return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		// #ifndef ONLINE_JUDGE
  //   // for getting input from input.txt
	 //    freopen("input.txt", "r", stdin);
	 //    // for writing output to output.txt
	 //    freopen("output.txt", "w", stdout);
		// #endif
		// cin>>T;
		// // cin.ignore(); must be there when using getline(cin, s)
		// while(T--)
		// {
			
		// }
		// return 0;
		int n, a;
		cin >> n >> a;
		int arr[n];
		int sum = 0;
		for(int i=0; i<n; i++){


			cin >> arr[i];
			sum += arr[i];
		}

		double max = 1.0/(4*a);
		double total = max * sum;
		int count =0;

		for(int i=0; i<n; i++){
			if(arr[i]>=total){
				count++;
			}


		}

		if(count>=a){
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int log2ceil(int n) {
  --n;
  n |= n >> 16;
  n |= n >> 8;
  n |= n >> 4;
  n |= n >> 2;
  n |= n >> 1;
  return n + 1;
}

int log2ceil(long long n) {
  --n;
  n |= n >> 32;
  n |= n >> 16;
  n |= n >> 8;
  n |= n >> 4;
  n |= n >> 2;
  n |= n >> 1;
  return n + 1;
}

struct RSQ {
  using value_type = LL;
  static value_type id() { return 0ll; }
  static value_type op(const value_type &l, const value_type &r) {
    return l + r;
  }
};

template <class Monoid> class SegmentTree {
public:
  using value_type = typename Monoid::value_type;
  using update_type = typename Monoid::value_type;

private:
  const int size_, n;
  std::vector<value_type> data;

public:
  /// @complexity $O(n)$
  /// @param vec: ベクトル
  /// @brief
  /// vector 型の列 vec を表現するセグメント木を作る．
  SegmentTree(const std::vector<value_type> &vec) :
    size_(vec.size()), n(log2ceil(size_)), data(n * 2, Monoid::id()) {
    std::copy(begin(vec), end(vec), begin(data) + n);
    for (int i = n - 1; i >= 0; --i) {
      data[i] = Monoid::op(data[i * 2 + 0], data[i * 2 + 1]);
    }
  }

  /// @complexity $O(n)$
  /// @param count: 構築するセグメント木の長さ
  /// @param value: 各要素の初期値
  /// @brief
  /// 長さ count のセグメント木を作り，全ての要素を value で初期化する．
  SegmentTree(const int count, const value_type &value = Monoid::id()) :
    SegmentTree(std::vector<value_type>(count, value)) {}

  /// @complexity $O(1)$
  /// @return セグメント木のサイズを返す．
  int size() const { return size_; }

  /// @complexity $O(\\log n)$
  /// @param pos: pos
  /// @param value: value
  /// @brief
  /// pos 番目の要素を value に更新する．
  /// その範囲を超えた場合は例外を送出する．
  /// @note pos はセグメント木のサイズ未満の非負整数である必要がある．
  void update(int pos, const value_type &value) {
    assert(0 <= pos && pos < size_);  // assertion
    data[pos += n] = value;
    while (pos /= 2) {
      data[pos] = Monoid::op(data[pos * 2], data[pos * 2 + 1]);
    }
  }

  /// @complexity $O(\\log n)$
  /// @brief
  /// セグメント木の区間 [l, r) を演算 Monoid::op ($\\cdot$)
  /// で畳み込んだ値を返す． すなわち，$a_l \\cdot a_{l+1} \\cdot \\ldots \\cdot
  /// a_{r-1}$ を返す． $l = r$ の場合は Monoid::id() を返す．
  value_type query(int l, int r) const {
    assert(0 <= l && l <= r && r <= size_);  // assertion
    l += n;
    r += n;
    value_type res1 = Monoid::id(), res2 = Monoid::id();
    while (l < r) {
      if (l & 1) res1 = Monoid::op(res1, data[l++]);
      if (r & 1) res2 = Monoid::op(data[--r], res2);
      l >>= 1;
      r >>= 1;
    }
    return Monoid::op(res1, res2);
  }
};

int main(void)
{
  LL n, k;
  cin >> n >> k;
  vector<pair<LL, LL>> a(n);
  REP(i, n) {
    cin >> a[i].first;
    a[i].first -= k;
    a[i].second = i;
  }
  REP(i, n-1) a[i+1].first += a[i].first;
  sort(a.begin(), a.end());
  SegmentTree<RSQ> r(n,0ll);
  LL answer = 0;
  for(auto x: a) {
    if(x.first >= 0) ++answer;
    r.update(x.second, 1);
    answer += r.query(0, x.second);
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 9088
from itertools import accumulate

N = int(input())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort()
B.sort()
C.sort()
cnt = [0] * (N + 1)
j = 0
for i, b in enumerate(B):
    while j < N and A[j] < b:
        j += 1
    cnt[i + 1] = j
cnt = list(accumulate(cnt))
ans = 0
j = 0
for i, c in enumerate(C):
    while j < N and B[j] < c:
        j += 1
    ans += cnt[j]
print(ans)


Measured memory_bytes: 24404
#include<bits/stdc++.h>
using namespace std;
int main(){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if(x+r<=w&&x-r>=0&&y+r<=h&&y-r>=0){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
}



Measured memory_bytes: 3136
#include <stdio.h>
#include <stdlib.h>
 
int main(void){
 
  char str[3];
 
  int i;
  scanf("%c %c %c",&str[0],&str[1],&str[2]);
 
  if(atoi(str)%4 == 0){
    printf("YES");
  }else{
    printf("NO");
  }
 
  return 0;
 
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define repr(i, n) for(int i=(n-1); 0<=i; i--)
#define repr2(i, from, to) for(int i=(from-1); (int)(to)<=i; i--)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct Node {
	int count = 0;
	vector<int> child;
};

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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}

vector<Node> tree;

void func(int p, int sum){
	tree[p].count += sum;
	if(tree[p].child.size() != 0){
		rep(i, tree[p].child.size()){
			func(tree[p].child[i], tree[p].count);
		}
	}
}


int main(void){
	int n, q; cin >> n >> q;
	tree.resize(n);
	rep(i, n-1){
		int a, b; cin >> a >> b;
		a--; b--;
		tree[a].child.push_back(b);
	}
	rep(i, q){
		int p, x; cin >> p >> x;
		p--;
		tree[p].count += x;
	}

	func(0, 0);

	rep(i, n){
		cout << tree[i].count;
		if(i != n-1) cout << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 21120
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, l;
    cin >> n >> l;
    int ans = l * n + n * (n - 1) / 2;
    if (l <= 0 && l + n - 1 >= 0) {
        cout << ans;
    } else if (l < 0) {
        cout << ans - (l + n - 1); 
    } else {
        cout << ans - l;
    }   
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N, X, total = 0, now, mi = 1000;
    cin >> N >> X;
    vector<int> g(N);
    for(int i = 0; i < N; i++) {
        cin >> g.at(i);
        X -= g.at(i);
        mi = min(mi, g.at(i));
        total++;
    }
    while(X >= mi){
       X -= mi;
       total++;
    }
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Thu May 28 22:59:47 2020

@author: naoki
"""
import sys

H,W = map(int,input().split()) # 行H列Wを入力
square = [input() for i in range(H)] # マス目の目標
zero_input = [str(0) for i in range(W+2)] # マス目外を0で埋める
zero_row1 = "".join(zero_input) #W+2文字0の文字列を作成
zero_row2 = [zero_row1]

for i in range(H):
    square[i] = "0" + square[i] + "0" # 各行の最初と最後に０を追加

square = zero_row2 + square + zero_row2 # 最初と最後の行に0のみの文字列を挿入

dy = [-1,0,0,1] # 横方向（列）の変位
dx = [0,-1,1,0] #　縦方向（行）の変位

for i in range(1,H+1):
    for j in range(1,W+1):
        if square[i][j] == "#": #  "#"ならば黒に塗る
            count = 0
            for k in range(4):
                if square[i+dx[k]][j+dy[k]] == "#" and count == 0: 
                    count+=1
            if count ==0:
                print("No")
                sys.exit()
print("Yes")


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  map<int, int> m;
  for(int i = 0; i < n; i++){
    int tmp;
    cin >> tmp;
    m[tmp]++;
  }
  for(auto a : m){
    if(a.second > 1){
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  return 0;
}

Measured memory_bytes: 9600
N=int(input())
S=[int(i) for i in input().split()]
T=[set() for i in range(N)]
dp=[0]*(N)
ans=0
mod=10**17
for k in range(1,N):
    for c in range(1,N):
        if k*c>=N-1:
            break
        dp[c]=dp[c]+S[N-1-k*c]+S[k*c]
        a=(N-1-k*c)
        b=a-c
        if b<=0 or (N-1-k*c==k*c) or (N-1-k*c in T[c]) or (k*c in T[c]) :
            dp[c]=-mod
        T[c].add(N-1-k*c)
        T[c].add(k*c)
        ans=max(ans,dp[c])
    #print(dp)
print(ans)

Measured memory_bytes: 183896
#include <iostream>
using namespace std;
int main (void) {
    int a, b, c;

    cin >> a >> b >> c;

    if (a != b && b != c && c != a) cout << 3 << endl;
    else if (a == b && b == c) cout << 1 << endl;
    else cout << 2 << endl;
    
    return 0;
}

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

int main() {
    ll k, x;
    cin >> k >> x;
    for (ll i = x-k+1; i < x+k-1; i++) {
        cout << i << ' ';
    }
    cout << x+k-1 << endl;
    return 0;
}


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll A, B, C, K; cin >> A >> B >> C >> K;
  if (K <= A) {
    cout << K << endl;
  }else if (K <= A + B) {
    cout << A << endl;
  }else {
    cout << A - (K - (A + B)) << endl;
  }

  return 0;
}



Measured memory_bytes: 3640
import itertools
n,m,q=map(int,input().split())
a=[list(map(int,input().split())) for i in range(q)]
l=range(1,m+1)
h_list = list(itertools.combinations_with_replacement(l, n))
ans=0
for i in h_list:
    b=0
    for j in a:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            b+=j[3]
    ans=max(ans,b)
print(ans)

Measured memory_bytes: 84380
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


int a, b;

bool check(int y) {
    if (y % 4 != 0) return false;
    if (y % 100 == 0 && y % 400 != 0) return false;
    return true;
}

int main() {
    int con = 0;
    while (cin >> a >> b) {
        if (a == 0 && b == 0) break;
        if (con != 0) cout << endl;
        
        int res = 0;
        for (int i = a; i <= b; ++i) {
            if (check(i)) {
                ++res;
                cout << i << endl;
            }
        }
        if (res == 0) puts("NA");
        ++con;
    }
    return 0;
}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
using dbl = double;

dbl solve(dbl a, dbl b, dbl x){
	dbl c = x/(a*a);
	dbl ans;
	if(c >= b/2){
		c = b - c;
		ans = 90.0 - (atan((a/2)/c))*180.0/M_PI;
	}
	else{
		// dbl c = a*c*2.0/b;
		ans = 90.0 - (atan((a*c*2)/b/b))*180.0/M_PI;
		// ans = 90.0 - (atan(c/b))*180.0/M_PI;
		// ans = 90.0-(atan(c/b))*180.0/M_PI;
	}
	return ans;
}


int main(){
	dbl a,b,x; cin>>a>>b>>x;
	printf("%.12f\n", solve(a,b,x));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
inline int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int r,c,n,N;
inline bool pd(int x,int y){
	return x==0||y==0||x==r||y==c;
}
inline int id(int x,int y){
	if (y==0) return x;
	if (x==r) return r+y;
	if (y==c) return r+c+r-x;
	return r*2+c*2-y;
}
struct data{
	int l,r;
}q[1000005];
int tot=0;
inline void add(int l,int r){
	if (l>r) swap(l,r);
	q[++tot].l=l;q[tot].r=r;
}
inline bool cmp(data d1,data d2){
	return d1.l<d2.l;
}
int sum[1000005];
void add1(int x){
	while (x<=N){
		++sum[x];
		x+=x&(-x);
	}
}
int query(int x){
	int res=0;
	while (x){
		res+=sum[x];
		x-=x&(-x);
	}
	return res;
}
vector<int> vec;
int main(){
	r=read(),c=read(),n=read();
	for (int i=1;i<=n;++i){
		int x1=read(),y1=read(),x2=read(),y2=read();
		if (pd(x1,y1)&&pd(x2,y2)){
			add(id(x1,y1),id(x2,y2));
		}
	}
	sort(q+1,q+tot+1,cmp);
	for (int i=1;i<=tot;++i){
		vec.push_back(q[i].l);
		vec.push_back(q[i].r);
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());N=vec.size();
	for (int i=1;i<=tot;++i){
		q[i].l=lower_bound(vec.begin(),vec.end(),q[i].l)-vec.begin()+1;
		q[i].r=lower_bound(vec.begin(),vec.end(),q[i].r)-vec.begin()+1;
	}
	for (int i=1;i<=tot;++i){
		if (query(q[i].r)-query(q[i].l-1)){
			puts("NO");
			return 0;
		}
		add1(q[i].r);
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 6004
//============================================================================
// Name        : d.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int n,m;cin>>n>>m;
	vector<int> a(n),b(n);
	vector<vector<int>> c(m+1);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		if(m-a[i]>=0){
		c[m-a[i]].push_back(b[i]);
		}
	}
//	for(int i=0;i<=m;i++){
//		cout<<i<<endl;
//		for(int j=0;j<c[i].size();j++){
//			cout<<c[i][j]<<' ';
//		}cout<<endl;
//	}
	priority_queue<int> q;
	int ans=0;
	for(int i=m;i>=0;i--){
		for(int j=0;j<c[i].size();j++){
			q.push(c[i][j]);
		}
		if(q.size()){
			ans+=q.top();
			q.pop();
		}

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

Measured memory_bytes: 6400
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];

int movex[4] = {-1,1,0,0};
int movey[4] = {0,0,-1,1};

int main(){
  while(1){
    cin >> m >> n;
    if(!n && !m)break;
    char field[102][102];
    char now;
    int x,y;
    queue<P> que;
    lep(i,0,n+1)lep(j,0,m+1)field[i][j] = '#';
    lep(i,1,n){
      lep(j,1,m){
        cin >> now;
        field[i][j] = now;
        if(now == '@'){
          que.push(P(i,j));
          // cout << i << " " << j << endl;
        }
      }
    }
    ll ans = 1;
    while(!que.empty()){
      P move = que.front(); que.pop();
      rep(i,0,4){
        if(field[move.first + movex[i]][move.second + movey[i]] == '.'){
          ans++;
          que.push(P(move.first + movex[i],move.second + movey[i]));
          field[move.first + movex[i]][move.second + movey[i]] = '#';
        }
      }
    }
    print(ans);
  }
  return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K;
ll X[55], Y[55], ans = INF;

int Solve(int A, int B, int C, int D){
  ll x[4] = {X[A], X[B], X[C], X[D]};
  ll y[4] = {Y[A], Y[B], Y[C], Y[D]};
  sort(x, x + 4); sort(y, y + 4);

  if (x[0] == x[3] || y[0] == y[3]) return 0;

  int cnt = 0;
  for (int i = 0; i < N; i++){
    if (x[0] <= X[i] && X[i] <= x[3] && y[0] <= Y[i] && Y[i] <= y[3]) cnt++;
  }

  if (cnt >= K){
    ans = min(ans, (x[3] - x[0]) * (y[3] - y[0]));
  }
  return 0;
}

int main(){
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];

  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      for (int k = 0; k < N; k++){
        for (int l = 0; l < N; l++){
          Solve(i, j, k, l);
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3644
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

long long n;

void init() {
	scanf("%lld", &n);
	return ;
}

void solve() {
	long long s = sqrt(n);
	for(register long long i = s; i >= 1; i--) {
		if(n % i == 0) {
			printf("%lld\n", i + n/i - 2);
			break;
		}
	}
	return ;
}

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

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
#define MAP_SIZE 10

class Pos {
  public:
    Pos(int x, int y) : x(x), y(y) {}
    int x;
    int y;
    bool alive(Pos p) {
      if (p.x - 1 <= this->x && this->x <= p.x + 1 && p.y - 1 <= this->y && this->y <= p.y + 1) return true;
      return false;
    } 
};

int x[12] = {-2, -2, -2, 2, 2, 2, -1, 0, 1, -1, 0, 1}; 
int y[12] = {-1, 0, 1, -1, 0, 1, -2, -2, -2, 2, 2, 2}; 
bool move(Pos p, vector<Pos> sc, int n) {
  if (p.x < 0 || MAP_SIZE <= p.x || p.y < 0 || MAP_SIZE <= p.y) return false;
  if (n == -1) return true;
  if (!p.alive(sc[n--])) return false;
  sc.pop_back();
  bool result = false;
  for (int i = 0; i < 12; i++) {
    if (move(Pos(p.x + x[i], p.y + y[i]), sc, n)) result = true;
    if (result) break;
  }
  return result;
}

int main() {
  int x, y, n;
  while (cin >> x >> y) {
    if (x == 0 && y == 0) break;
    Pos p = Pos(x, y); 

    cin >> n;
    vector<Pos> sc = { p };
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      sc.insert(sc.begin(), Pos(x, y));
    } 
    cout << (move(p, sc, n) ? "OK" : "NA") << endl;
  }
  return 0;
}

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

 int a, b;
 scanf ("%d%d", &a, &b);
 if ( a < b  ) {
   printf("a < b\n");
 } else if( a > b ){
   printf("a > b\n");
 } else if( a == b ){
   printf("a == b\n");
 }
  return 0;

}



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

#define LL long long

int main(){
	LL n,l;	cin>>n>>l;
	vector< pair<LL,char> > data(n);
	for(LL i=0;i<n;i++){
		LL p,d;	cin>>p>>d;
		char dir=(d==1? 'R':'L');
		data[i]={p,dir};
	}
	sort(data.begin(), data.end());

	vector<LL> L(n), R(n);
	for(LL i=0;i<n;i++){
		L[i]=(abs(data[i].first-1)-i) * (data[i].second=='L'? 1:-1);
		R[i]=(abs(l-data[i].first)-(n-i-1)) * (data[i].second=='R'? 1:-1);
	}

	for(LL i=1; i<n; i++){
		L[i]+=L[i-1];
	}
	for(LL i=n-2; i>=0; i--){
		R[i]+=R[i+1];
	}

	LL ans=0;
	for(LL i=0; i+1<n; i++){
		ans=max(ans, L[i]+R[i+1]);
	}
	ans=max(ans,max(L[n-1], R[0]));

	//for(int i=0;i<n;i++){
	//	cout<<"["<<i<<"] "<<"L="<<L[i]<<", "<<"R="<<R[i]<<endl;
	//}

	cout<<ans<<endl;

	return 0;
}



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


int ans;
//押されたボタンの番号, ボタン押した数カウンター　,ボタンリスト 
void check(int bnum,int &counter,vector <int> &a){

    //ベースケース1 ボタン2にたどり着いたとき
    if(bnum==2)
    {ans = counter; return;}

    //ベースケース2 一度押したボタンをもう一度押した時
    else if(bnum==-1)
    {ans = -1; return;}
    //再帰ケース　押したボタンによって光るボタンにいく
    else{
    bnum--;//配列は0始まりなので-1する
    counter++;
    int to = a.at(bnum);
    a.at(bnum)=-1;
    //押したボタンは、行先を-1にする
    check(to,counter,a);
    }

}
int main(){
//再帰関数を組んで、ボタン1から押して、光るボタンを辿っていく。
//一度たどり着いたボタンをもう一度おしたら、無限ループに入っているのでfalse
//それまでにボタン2にたどり着いたらtrue
//出力は回数で。

int counter=0;
int n;
cin>> n;
vector <int>a(n);
rep(i,n)
{cin >> a.at(i);}

check(1,counter,a);
cout << ans << endl;
return 0;
}
//

Measured memory_bytes: 768
import sys
sdin = sys.stdin.readline

H,W,D = map(int, sdin().split())
A = []
for h in range(H):
    A.append(list(map(int, sdin().split())))
Q = int(sdin())
RL = []
for q in range(Q):
    RL.append(tuple(map(int, sdin().split())))


codn = {}
for h in range(H):
    for w in range(W):
        codn[A[h][w]] = (h+1, w+1)
        
# mod D上での累積和
cums = []
for d in range(D):
    cum = []
    res = D
    if d!=0:
        res = d
    
    cum = [0]
    while res+D <= H*W:
        prev = codn[res]
        nex = codn[res+D]
        cost = abs(nex[0]-prev[0]) + abs(nex[1]-prev[1])
        cum.append(cum[-1]+cost)
        
        res += D
    
    cums.append(cum)
    
# 各クエリの処理
ans = 0
for query in range(Q):
    q = RL[query]
    mod = q[0] % D
    start = (q[0]-mod) // D
    last = (q[1]-mod) // D
    if mod == 0:
        start -= 1
        last -= 1
    
    ans = cums[mod][last] - cums[mod][start]   
    
    print(ans)

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

int main(){
    int W,D;
    while(cin >> W >> D && W){
        map<int,int> F,S;
        int h,ans = 0;
        for(int i=1;i<=W;i++){
            cin >> h;
            ans += h;
            F[h]++;
        }
        for(int i=1;i<=D;i++){
            cin >> h;
            S[h]++;
        }
        for(auto x:S){
            if(F.count(x.first) && F[x.first]<x.second) ans += x.first*(x.second-F[x.first]);
            else if(!F.count(x.first)) ans += x.first*x.second;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n-1);
  for(int i=0;i<n-1;i++){
    cin>>a.at(i);
  }
  vector<int> ans(n);
  for(int i=0;i<n-1;i++){
    ans.at(a.at(i)-1)++;
  }
  for(int i=0;i<n;i++){
    cout<<ans.at(i)<<endl;
  }
  return 0;
}

Measured memory_bytes: 4840
#include<stdio.h>
#define MAX 2000000
#define INF (1<<30)
int H,A[MAX+1];

void swap(int *a,int *b){
  int c;

  c=*a;
  *a=*b;
  *b=c;

}

void maxHeapify(int i){
  int r,l,large;
  
  r=2*i+1;
  l=2*i;

  if(l<=H && A[l]>A[i]) large=l;
  else large=i;
  if(r<=H && A[r]>A[large]) large=r;

  if(large!=i){
    swap(&A[i],&A[large]);
    maxHeapify(large);
  }
}

int extract(){
  int v;
  if(H<1) return -INF;
  v=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return v;
}

void increase(int i,int key){
  if(key<A[i]) return;
  A[i]=key;
  while(i>1 && A[i/2]<A[i]){
    swap(&A[i],&A[i/2]);
    i=i/2;
  }
}

void insert(int key){
  H++;
  A[H]=-INF;
  increase(H,key);
}

int main(){
  int key;
  char com[10];

  while(1){
    scanf("%s",&com);
    if(com[0]=='e' && com[1]=='n') break;
    if(com[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }else{
      printf("%d\n",extract());
    }
  }
  return 0;

}

Measured memory_bytes: 4696
/*input
2 3
1 2 3
0 1 1
*/

#include <bits/stdc++.h>
using namespace std;
int grid[505][505];

int main()
{
	int n, x;
	scanf("%d", &n);
	int g = 0;
	char prv = 0;
	set<string> s;
	for(int i = 1; i<=n; i++){
        string st;
        cin >> st;
        s.insert(st);
        if(i > 1){
            if(st[0] != prv) {
                printf("No\n");
                return 0;
            }
        }
        prv = st[st.size()-1];
	}
	if(s.size() == n)
        printf("Yes\n"), exit(0);
    printf("No\n");

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
set<int>cnt;
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<k;i++)
	{
		int d;
		cin>>d;
		for(int j=0;j<d;j++)
		{
			int a;
			cin>>a;
			cnt.insert(a);
		}
	}
	cout<<n-cnt.size();
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
using namespace::std;



long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int a) {
	if (a < 0) {
		return -a;
	}
	return a;
}

long long N, M, wa, K, W,L, ans, k[5],A,B,C,n[2];
string s, t[100];
bool a, b, c;
int main() {
	cin >> k[0]>>k[1]>>k[2];
	L = -1;
	ans = 0;
	for (int i = 0; i < 3; i++) {
		if (L < k[i]) {
			L = k[i];
			wa = i;
		}
	}
	K = 0;
	for (int i = 0; i < 3; i++) {
		if (i != wa) {
			n[K] = L - k[i];
			K++;
		}
	}
	if (n[0] >= n[1]) {
		N = n[0];
		M = n[1];
	}
	else {
		N = n[1];
		M = n[0];
	}
	if (n[0] % 2 == 0) {
		if (n[1] % 2 == 0) {	
			cout << M + ((N - M) / 2) << endl;
			return 0;
		}
		if (n[1] % 2 == 1) {
			n[1]++;
		}
	}
	else {
		if (n[1] % 2 == 0) {
			n[0]++;
		}
		if (n[1] % 2 == 1) {
			cout << M + ((N - M) / 2) << endl;
			return 0;
		}
	}

	if (n[0] >= n[1]) {
		N = n[0];
		M = n[1];
	}
	else {
		N = n[1];
		M = n[0];
	}
	cout << M + ((N - M) / 2)+1 << endl;
	return 0;
}




Measured memory_bytes: 256
def main():
    n = int(input())
    p = [int(i) for i in input().split()]
    for i in range(n):
        for j in range(i, n):
            p[i], p[j] = p[j], p[i]
            if is_sorted(p):
                print("YES")
                return
            p[i], p[j] = p[j], p[i]
    print("NO")


def is_sorted(p):
    for i in range(len(p) - 1):
        if p[i] > p[i + 1]:
            return False
    return True


if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
	while(1){
		int r; int n;
		int xl[25],xr[25],y[25];
		scanf("%d%d",&r,&n);
		if(r == 0 && n == 0) return 0;
		map<int,int>M;
		for(int i=0;i<n;i++){
			scanf("%d%d%d",&xl[i],&xr[i],&y[i]);
			for(int j=xl[i];j<xr[i];j++) M[j] = max(M[j],y[i]);
		}
		double ans = 1e9;
		for(int X=-r;X<=-1;X++){
			//[X,X+1], X+1 is highest
			{
				double L = sqrt((double)r*(double)r - (double)(X+1)*(double)(X+1));
				L = (double)r-L;
				ans = min(ans,L+(double)M[X]);
			}
		}
		for(int X=0;X<r;X++){
			//[X,X+1], X is highest
			{
				double L = sqrt((double)r*(double)r - (double)(X)*(double)(X));
				L = (double)r-L;
				ans = min(ans,L+(double)M[X]);
			}
		}
		printf("%.4f\n",ans);
	}
}

Measured memory_bytes: 3216
w,h,n=map(int,input().split())
l=[list(map(int,input().split()))for _ in range(n)]

a,b=0,0
for i in range(n):
    if l[i][2]==1:a=max(a,l[i][0])
    elif l[i][2]==2:w=min(w,l[i][0])
    elif l[i][2]==3:b=max(b,l[i][1])
    else:h=min(h,l[i][1])

print(max(0,w-a)*max(0,h-b))

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

using namespace std;

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

    if (c == "a" || c == "i" || c == "u" || c == "e" || c == "o")
    {
        cout << "vowel";
    }

    else
    {
        cout << "consonant";
    }
}

Measured memory_bytes: 256