akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!(
        a: i8,
        b: i8,
        c: i8,
    );
    if (a>c && c>b) || (a<c && c<b){
        println!{"Yes"}
    } else {
        println!{"No"}
    }
}


Measured memory_bytes: 4352
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli n;
    lli mod = 1000000007;
    cin >> n;
    vi a(n + 1);
    a[0] = 0;
    rep(i,n){
        lli ai;
        cin >> ai;
        a[i + 1] = a[i] + ai;
        a[i + 1] = a[i + 1] % mod;
    }
    lli ans = 0;
    rep(i,n-1){
        lli tmp = 0;
        tmp = (a[i + 1] - a[i]) * (a[n] - a[i + 1]);
        tmp = tmp % mod;
        ans += tmp;
        ans = ans % mod;
    }
    if(ans<0){
        ans += mod;
    }
    out(ans);
}

Measured memory_bytes: 4840
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
using namespace std;

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



#define rep(n) for(int i=0;i<n;i++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
const int MOD = 1000000007;
const int INF = 1 << 29;


int main() {
	
	int n,a[101];
	char s[100001];
	cin >> n ;
	rep(n) {
		cin >> a[i];
	}
	int cnt=0;
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			cnt += a[i] * a[j];
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int ans[310][310];
vector<pair<int,int>> vec;
int main() {
	int h, w, k;
	cin >> h >> w >> k;
	string s[300];
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	bool st = false;
	int co = 1, co1 = 1;
	for (int j = 0; j < h; j++) {
		for (int k = 0; k < w; k++) {
			if (s[j][k] == '#') {
				if (st == true) {
					co++;
				}
				st = true;
			}
			ans[j][k] = co;
		}
		bool foge = false;
		if (j == h - 1) {
			if (st == false) {
				for (int l = j; l >= 0; l--) {
					for (int p = 0; p < w; p++) {
						if (s[l][p] == '#') {
							int ki = vec.back().second;
							vec.pop_back();
							vec.emplace_back(make_pair(l, co1 + ki));
							foge = true;
							break;
						}
					}
					if (foge == true) {
						break;
					}
				}
			}
		}
		if (st == false) {
			co1++;
			co--;
		}
		else {
			vec.emplace_back(make_pair(j, co1));
			co1 = 1;
		}
		co++;
		st = false;
	}
	for (int i = 0; i < vec.size(); i++) {
		for (int j = 0; j < vec[i].second; j++) {
			for (int k = 0; k < w; k++) {
				cout << ans[vec[i].first][k];
				if (k != w) {
					cout << " ";
				}
			}
			cout << endl;
		}
	}
}

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

using namespace std;
int main()
{
	long long n;
	cin >> n;
	long long x;
	cin >> x;
	long long asw;
	long long r = 1;
	long long a;
	long long b;
	if(x == n/2 && n % 2 == 0)
	{
		asw = 3*n/2;
	}
	else
	{
		if(x < (double)n/2)
		{
			a = n-x;
			b = x;
			asw = a + b;
		}
		else if(x > (double)n/2)
		{
			a = x;
			b = n-x;
			asw = a + b;
		}
		long long tmp;
		while(r != 0)
		{
			r = a % b;
			tmp = a/b;
			asw += 2 * tmp * b;
			a = b;
			b = r;
		}
		asw -= a;
	}
	cout << asw << "\n";
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
def main(n):
    m = n * 499 + 1
    dp =  defaultdict(list)
    dp[0] = [0, 0]
    for _ in range(n):
        ndp = defaultdict(lambda:[-1,-1])
        for key, value in dp.items():
            ndp[key] = value[:]
        p = int(input())
        a = -p % 1000
        if a >= 500:
            b = a - 500
            for j in dp.keys():
                if dp[j][0] < 0: continue
                tmp = ndp[j + b]
                if tmp[0] < dp[j][0] + 1:
                    tmp[0] = dp[j][0] + 1
                    tmp[1] = dp[j][1] + p
                elif tmp[0] == dp[j][0] + 1 and tmp[1] > dp[j][1] + p:
                    tmp[0] = dp[j][0] + 1
                    tmp[1] = dp[j][1] + p
        else:
            b = 500 - a % 500
            for j in dp.keys():
                if dp[j][0] < 0: continue
                tmp = ndp[j + a]
                if tmp[0] < dp[j][0]:
                    tmp[0] = dp[j][0]
                    tmp[1] = dp[j][1] + p
                elif tmp[0] == dp[j][0] and tmp[1] > dp[j][1] + p:
                    tmp[1] = dp[j][1] + p
                if j - b >= 0:
                    tmp = ndp[j - b]
                    if tmp[0] < dp[j][0] + 1:
                        tmp[0] = dp[j][0] + 1
                        tmp[1] = dp[j][1] + p
                    elif tmp[0] == dp[j][0] + 1 and tmp[1] > dp[j][1] + p:
                        tmp[1] = dp[j][1] + p
        dp = ndp
    ans = [0, 0]
    for n, c in dp.values():
        if n > ans[0]:
            ans = [n, c]
        elif n == ans[0] and c < ans[1]:
            ans = [n, c]
    print(*ans)

if __name__ == "__main__":
    while 1:
        n = int(input())
        if n:
            main(n)
        else:
            break



Measured memory_bytes: 16424
#include <iostream>
#include <vector>

using namespace std;

const int inf = 1e9+10;

#define MAXN 100005

vector<int> adj[MAXN];

bool visited[MAXN];

int todeg[MAXN];

int dist[MAXN];


void dfs(int a){
    
    visited[a]=true;

    for(int i : adj[a]){
        dist[i] = max(dist[i],dist[a]+1);    
        todeg[i]--;
        if(todeg[i] == 0){
            dfs(i);
        }
    }   
}   


int main(){

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);
        
    int n,m;cin>>n>>m;
    int fr,to;
    for(int i=0;i<m;i++){
        cin>>fr>>to;
        adj[fr].push_back(to);
        ++todeg[to];
    } 

    int ans = -inf;
    for(int i=1;i<=n;i++){
        if(!visited[i] && !todeg[i]){
            dfs(i);
        }
    }   
    for(int i=1;i<=n;i++)ans=max(ans,dist[i]);

    cout<<ans<<endl;
}


Measured memory_bytes: 9728
#include <iostream>
#include <vector>
#include <algorithm>

int n, pos;
std::vector<int> preorder, inorder, postorder;

void rec(int left, int right) {
    if (left >= right) return;
    int root = preorder.at(pos++);
    int criterion = std::distance(inorder.begin(), std::find(inorder.begin(), inorder.end(), root));
    rec(left, criterion);
    rec(criterion+1, right);
    postorder.push_back(root);
}

void solve() {
    pos = 0;
    rec(0, preorder.size());
    for (int i=0; i<n; i++) {
        if (i) std::cout << " ";
        std::cout << postorder.at(i);
    }
    std::cout << "\n";
}

int main() {
    int k;
    std::cin >> n;
    for (int i=0; i<n; i++) {
        std::cin >> k;
        preorder.push_back(k);
    }
    for (int i=0; i<n; i++) {
        std::cin >> k;
        inorder.push_back(k);
    }

    solve();
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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 T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main()
{
    ll n; cin >> n;
    vector<ll> a(n);
    int used[1000010] = {0};
    rep(i, n)
    {
        cin >> a[i];
        used[a[i]]++;
    }

    ll ans = 0;
    rep(i, n)
    {
        vector<ll> b = divisor(a[i]);
        int f = 1;
        for (auto it : b)
        {
            if ((used[it] > 0 && it < b[b.size() - 1]) || (used[it] > 1 && a[i] == it))
            {
                f = 0;
                break;
            }
        }
        if (f) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8756
/*
   Username : moondancer
   Name : Moon Dancer
*/


#include <bits/stdc++.h>
using namespace std;

#define int long long
const int mod=1e9+7;

int pw(int a,int b,int p){
    if(b==0)return 1;
    int t=pw(a,b/2,p);
    if(b%2)return (((a*t)%p)*t)%p;
    else return ((t*t)%p);
}

int modInverse(int A,int m)
{
    return pw(A,m-2,m);
}

int fact[1000001];
void calc(){
    fact[0]=1;
    for (int i = 1; i <= 1000000; ++i)
    {
        fact[i]=(fact[i-1]*i)%mod;
    }
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int s;
    cin>>s;
    calc();
    int ans=0;
    for(int r=1; r<=s/3; ++r){
        int n=s-r*3;
        int t=fact[n+r-1];
        t=(t*modInverse(fact[r-1],mod))%mod;
        t=(t*modInverse(fact[n],mod))%mod;
        ans=(ans+t)%mod;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 11460
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val x = br.readLine()!!
    val stack = LinkedList<Char>()
    for (c in x) {
        if (c == 'S') {
            stack.push(c)
            continue
        }

        if (stack.isEmpty()) {
            stack.push(c)
            continue
        }

        if (stack.first == 'S') {
            stack.pop()
        } else {
            stack.push(c)
        }
    }
    out.println(stack.size)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 42252
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        t: u32,
        a: [u32; n],
    }
    let mut ans = t;
    for i in 1..n {
        ans += std::cmp::min(t, a[i] - a[i - 1]);
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 6396
import sys
readline = sys.stdin.readline

s = readline().rstrip()
t = readline().rstrip()
 
def LCS(X,Y):
    XL = len(X)
    YL = len(Y)
    dp = [[0 for j in range(YL+1)] for i in range(XL+1)]
    for i in range(XL):
        for j in range(YL):
            if X[i] == Y[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
    # 以下復元
    S = ''
    i,j = i+1,j+1
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            i,j = i-1,j-1
            S += X[i]
    S = S[::-1]
    return S
 
print(LCS(s,t))
 

Measured memory_bytes: 120028
N,*bs=$<.read.split.map(&:to_i)

count = 1
arr = Array.new(N,0)
ret = []
N.times do |i|
  t = count
  j = N-1
  while 0 <= j
    if arr[j] == 0 && bs[j] == t
      arr[j] = 1
      count += 1
      ret << bs[j]
      break
    end
    t -= arr[j]
    j -= 1
  end
  if j < 0
    p -1
    exit 0
  end
end

ret.each {|a| p a}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  lint n, s = 0, m;
  cin >> n;
  m = n-1;
  rep(i, sqrt(m)){
    if(m%(i+1) == 0){
      ++s;
      if(i == 0) --s;
      if(i+1 != m/(i+1)) ++s;
    }
  }
  rep(i, sqrt(n)){
    if(n%(i+1) == 0){
      lint a = n, b = n;
      if(i > 0){
        while(a%(i+1) == 0 && a >= i+1) a /= i+1;
        if(a == 1 || a % (i+1) == 1) ++s;
      }
      if(n/(i+1) > 1 && n/(i+1) != i+1){
        while(b%(n/(i+1)) == 0 && b >= n/(i+1)) b /= n/(i+1);
        if(b == 1 || b % (i+1) == 1) ++s;
      }
    }
  }
  if(n == 2) s = 1;
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
from bisect import bisect_right
dic = [[] for i in range(N)]

shi = {}
for i in range(M):
    p, y = map(int, input().split())
    dic[p-1].append(y)
    shi[i] = (p, y)

for i in range(N):
    dic[i].sort()

for j in range(M):
    p, y = shi[j]
    print('{:06}{:06}'.format(p, bisect_right(dic[p-1], y)))



Measured memory_bytes: 38212
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 4300000;
const int K = 60;
const int mod = 998244353;
int s[N], ans[N], sl[N], sr[N], x[N], ok[N], cnt[N];
pair < int, int > l[N], r[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    set < int > s;
    srand(time(NULL));
    while(s.size() < n){
        int x = rand() % (n * n) + 1;
        s.insert(x);
    }
    for (int i = 1; i <= n; i++){
        x[i] = *s.begin();
        s.erase(s.begin());
    }
    random_shuffle(x + 1, x + n + 1);
    for (int i = 1; i <= n; i++){
        cin >> x[i];
       // cout << "i = " << i << " x[i] = " << x[i] << endl;
        l[x[i] - 1] = {i - 1, i};
        r[x[i] + 1] = {n - i, i};
        ans[x[i]] = i;
    }
    for (int i = 1; i <= n * n; i++){
        sl[i] = sl[i - 1] + l[i].F;
        if (sl[i] > i){
         //   cout << "No";
          //  return 0;
        }
    }
    for (int i = n * n; i >= 1; i--){
        sr[i] = sr[i + 1] + r[i].F;
        if (sr[i] > n * n - i + 1){
          //  cout << "No";
          //  return 0;
        }
    }
    if (l[0].F != 0 || r[n * n + 1].F != 0){
        cout << "No";
        return 0;
    }
   // cout << "!" << endl;
    int lb = 1;
    int rb = 1;
    while(rb <= n * n){
        while(rb <= n * n && l[rb].F == 0) rb++;
        if (rb > n * n) break;
        int x = l[rb].F;
        int val = l[rb].S;
     //   cout << "x = " << x << " " << rb << endl;
        while(x){
            if (ans[lb] == 0){
                ans[lb] = val;
                x--;
            }
            lb++;
        }
      //  cout << lb << " " << rb << endl;
        rb++;
    }
    lb = n * n;
    rb = n * n;
    while(lb >= 1){
        while(lb >= 1 && r[lb].F == 0) lb--;
        if (lb < 1) break;
        int x = r[lb].F;
        int val = r[lb].S;
        while(x){
            if (ans[rb] == 0){
                ans[rb] = val;
                x--;
            }
            rb--;
        }
        lb--;
    }
   // cout << "Yes" << endl;
    for (int i = 1; i <= n * n; i++){
        cnt[ans[i]]++;
        if (x[ans[i]] == i && cnt[ans[i]] == ans[i]) ok[ans[i]] = 1;
    }
    for (int i = 1; i <= n; i++){
        if (!ok[i]){
            cout << "No";
            return 0;
            cout << i << " !" << endl;
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i <= n * n; i++) cout << ans[i] << " ";
}


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

int main(){
    int s;
    cin >> s;
    int A[10000];
    A[0] = s;
    bool res = false;
    for (int i = 1;i < 10000;++i){
        if(A[i-1]%2 == 0){
            A[i] = A[i-1]/2;
        }
        else{
            A[i] = 3*A[i-1] + 1;
            }
        for(int j = 0;j < i;++j){
            if(A[j] == A[i]){
                res = true;
                cout << i+1 <<endl;
                break;
             }
           }
        if(res == true){
            break;
         }
    }
}

Measured memory_bytes: 256
from bisect import bisect_right
n,m,k = map(int,input().split())

a =[int(x) for x in input().split()]
b = [int(x) for x in input().split()]

prefa = [0]
prefb =[0]

for i in range(n):
    prefa.append(prefa[-1] + a[i])
for j in range(m):
    prefb.append(prefb[-1] + b[j])
i,j = 1, 1
ans =0 
#print("A")
while i <= n:
    if prefa[i] > k:
        break 
    else:
        p = k - prefa[i] 
        aux = bisect_right(prefb , p)  - 1
        #print(i, aux)
        ans = max(ans, i + aux)
        i+=1 
#print("B")
while j <= m:
    if prefb[j] > k:
        break 
    else:
        p = k - prefb[j]
        aux = bisect_right(prefa , p) -1
        #print(j , aux)
        ans = max(ans, j + aux)
        j+=1
print(ans)
        

Measured memory_bytes: 131344
#include <stdio.h>
int n;
char a[200010];
long long t[200010];
long long mod = 1e9+7;
long long ans = 1;
int main(){
	scanf("%d",&n);
	scanf("%s",a);
	for(int i=0;i<2*n;i++){
		if(a[i]=='B'){
			if(i>0) t[i] = t[i-1]+(t[i-1]%2?-1:1);
			else t[i] = 1;
		} else {
			if(i>0) t[i] = t[i-1]+(t[i-1]%2?1:-1);
			else t[i] = -1;
		}
	}
	for(int i=0;i<2*n;i++){
		if(t[i]<0){
			printf("0\n");
			return 0;
		} else if(i>0){
			if(t[i]==t[i-1]-1){
				ans = ans * t[i-1];
				ans = ans % mod;
			}
		}
	}
	if(t[2*n-1]!=0){
		printf("0\n");
		return 0;
	}
	for(long long i=1;i<=n;i++){
		ans = ans * i;
		ans = ans % mod;
	}
	printf("%lld\n",ans%mod);
}

Measured memory_bytes: 1920
#import sys
#input = sys.stdin.readline
def main():
    N = int( input())
    H = list( map( int, input().split()))
    h = H[-1]
    ans = "Yes"
    for i in range(N-1):
        if h >= H[-i-2]:
            h = H[-i-2]
            continue
        if h + 2 <= H[-i-2]:
            ans = "No"
            break
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 14252
n,k = map(int,input().split())
num_list = list(map(int , input().split()))
candidate = 0
for i in range(n-k+1):
    if i == 0:
        for j in range(k):
            candidate += (num_list[j]+1)/2
        tmp = candidate
    else:
        tmp += -(num_list[i-1]+1)/2 + (num_list[i+k-1]+1)/2
        if tmp > candidate:
            candidate = tmp
        
print(candidate)

Measured memory_bytes: 24812
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
class Counter:
    def __init__(self):
        self.dict = {}

    def add(self,x):
        if x in self.dict: self.dict[x] += 1
        else: self.dict[x] = 1

    def decrement(self,x):
        self.dict[x] -= 1
        if self.dict[x] <= 0:
            del self.dict[x]

    def get_dict(self):
        return self.dict

def main():
    N = ii()
    S = list(isp())

    C = Counter()
    for s in S:
        C.add(s)
    
    c = C.get_dict()
    print("Three" if len(c.keys()) == 3 else "Four")




if __name__ == "__main__":
    main()

Measured memory_bytes: 61732
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

struct UF{
	int par[100010],r[100010];
	ll cnt[100010];
	void init(){
		rep(i,100010){
			par[i] = i;
			r[i] = 0;
			cnt[i] = 1;
		}
	}
	int find(int x){
		if(par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	bool same(int x,int y){
		return find(x) == find(y);
	}
	void unit(int x,int y){
		if(same(x,y))return;
		x = find(x);
		y = find(y);
		if(r[x] < r[y]){
			par[x] = y;
			cnt[y] += cnt[x];
		}
		else {
			par[y] = x;
			cnt[x] += cnt[y];
			if(r[x] == r[y]){
				r[x] ++;
			}
		}
	}
}uf;

vector<int> G[100010];
vector<int> rG[100010];
int c[100010];
bool dfs(int v,int c_){
	if(c[v] != -1)return c[v] == c_;
	c[v] = c_;
	for(int u: G[v]){
		if(!dfs(u,(c_+1)%3))return false;
	}
	for(int u: rG[v]){
		if(!dfs(u,(c_+2)%3))return false;
	}
	return true;
}

int main(){
	static int n,m;
	static int a[100010],b[100010];
	scanf("%d%d",&n,&m);
	rep1(i,m)scanf("%d%d",&a[i],&b[i]);
	rep1(i,m){
		G[a[i]].pb(b[i]);
		rG[b[i]].pb(a[i]);
	}
	
	uf.init();
	rep1(i,m){
		uf.unit(a[i],b[i]);
	}
	rep(i,100010)c[i] = -1;
	
	ll ret = 0;
	bool B[100010];
	static ll cnt[100010][3] = {};
	static ll cnt_edge[100010] = {};
	rep1(i,n){
		if(uf.find(i) == i){
			B[i] = dfs(i,0);
		}
	}
	rep1(i,n){
		if(c[i] != -1)cnt[uf.find(i)][c[i]] ++;
		cnt_edge[uf.find(i)] += G[i].size();
	}
	rep1(i,n){
		if(uf.find(i) != i)continue;
		if(B[i]){
			if(cnt[i][0]*cnt[i][1]*cnt[i][2] == 0)ret += cnt_edge[i];
			else rep(j,3)ret += cnt[i][j]*cnt[i][(j+1)%3];
		}
		else {
			ret += uf.cnt[i]*uf.cnt[i];
		}
	}
	cout << ret << endl;
}



Measured memory_bytes: 21760
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val A = new Array[Long](N+1)
  val B = new Array[Long](N+1)
  for (i <- 1 to N) {
    val a, b = in.next().toInt
    A(i) = a
    B(i) = b
  }


  // check smallest
  val hoge = new Array[(Long, Int)](2*N)
  for (i <- 1 to N) {
    val ind = 2*(i-1)
    hoge(ind) = (A(i), -i)
    hoge(ind+1) = (B(i), i)
  }

  val ord = hoge.sorted
  var ans = ord.take(N).map(_._1).sum
  var flag1 = false
  val memo = new Array[Boolean](N+1)
  for (i <- 0 until N) {
    val (_, _ind) = ord(i)
    val ind = _ind.abs

    if(memo(ind))
      flag1 = true
    else
      memo(ind) = true
  }

  if(A.sum == ans || B.sum == ans || flag1)
    ()
  else {
    val dpA = new Array[Boolean](N+1)
    val dpB = new Array[Boolean](N+1)

    for (i <- 0 until N) {
      val (_, ind) = ord(i)

      if(ind < 0)
        dpA(ind.abs) = true
      else
        dpB(ind.abs) = true
    }

    var diff = 0L
    val (maxNum, maxi) = ord(N-1)
    breakable {
      for ((nowNum, nowi) <- ord.slice(N, 2*N)) {
        if(nowi.abs != maxi.abs) {
          if(nowi < 0 && !dpA(nowi.abs)) {
            diff = nowNum - maxNum
            break
          }
          else if(nowi > 0 && !dpB(nowi.abs)) {
            diff = nowNum - maxNum
            break
          }
        }
      }
    }

    var diff2 = Long.MaxValue
    val (maxNum2, maxi2) = ord(N-2)
    breakable {
      for ((nowNum, nowi) <- ord.slice(N, 2*N)) {
        if(nowi.abs != maxi2.abs) {
          if(nowi < 0 && !dpA(nowi.abs)) {
            diff2 = nowNum - maxNum2
            break
          }
          else if(nowi > 0 && !dpB(nowi.abs)) {
            diff2 = nowNum - maxNum2
            break
          }
        }
      }
    }
    diff = diff min diff2

    ans = A.sum min B.sum min (ans+diff)
  }


  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



Measured memory_bytes: 67312
using System;
using System.Collections.Generic;
using System.Text;

namespace AOJ
{
    class Program
    {
        struct Rect
        {
            public int W, H;
        }
        struct Circle
        {
            public int x, y, r;
        }
        static bool IsInInside(ref Rect r, ref Circle c)
        {
            Rect min = new Rect { W = c.x - c.r, H = c.y - c.r };
            Rect max = new Rect { W = c.x + c.r, H = c.y + c.r };
            if (min.W < 0) return false;
            if (min.H < 0) return false;
            if (max.W > r.W) return false;
            if (max.H > r.H) return false;
            return true;
        }
        static void Main(string[] args)
        {
            var inputLine = Console.In.ReadLine();
            var inputs = inputLine.Split(new char[] { ' ', '\t', '　' });
            if (inputs.Length != 5)
            {
                return;
            }

            var integers = new List<int>();
            foreach (var s in inputs)
            {
                integers.Add(int.Parse(s));
            }

            var rect = new Rect { W = integers[0], H = integers[1] };
            var circle = new Circle { x = integers[2], y = integers[3], r = integers[4] };

            var result = "No";
            if (IsInInside(ref rect, ref circle))
            {
                result = "Yes";
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 19988
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	int M = 45;
	
	int N;
	ll K;
	cin >> N >> K;
	vector<ll> A(N);
	for(int i=0;i<N;i++) cin >> A[i];
	
	ll tot = 0;
	for(int i=0;i<N;i++) tot += A[i];
	
	vector<int> bcnt(M);
	for(int i=0;i<M;i++) bcnt[i] = 0;
	
	for(int i=0;i<M;i++){
		for(int j=0;j<N;j++){
			if((A[j] >> i) & 1) bcnt[i]++;
		}
	}
	
	reverse(bcnt.begin(), bcnt.end());
//for(int i=0;i<M;i++) cerr << "bcnt[" << i << "]: " << bcnt[i] << endl;	
	
	
	ll dp[2][M + 1];
	ll Inf = (ll) 1e18;
	for(int i=0;i<2;i++) for(int j=0;j<M + 1;j++) dp[i][j] = - Inf;
	
	dp[0][0] = 0;
	
	for(int i=0;i<M;i++){
		int kb = (K >> (M - 1 - i)) & 1;
		ll inc = (((ll)1) << (M - 1 - i) );
		inc *= (N - bcnt[i]) - bcnt[i];
//cerr << "i:" << i << " kb: " << kb << " inc:" << inc << endl; 		
		if(kb == 1){
			if(dp[0][i] != - Inf){
				dp[1][i+1] = max(dp[1][i+1], dp[0][i]);
				dp[0][i+1] = max(dp[0][i+1], dp[0][i] + inc);
			}
			if(dp[1][i] != -Inf){
				dp[1][i+1] = max(dp[1][i+1], dp[1][i]);
				dp[1][i+1] = max(dp[1][i+1], dp[1][i] + inc);
			}
			
		} else {
			if(dp[0][i] != - Inf){
				dp[0][i+1] = max(dp[0][i+1], dp[0][i]);
			}
			if(dp[1][i] != - Inf){
				dp[1][i+1] = max(dp[1][i+1], dp[1][i]);
				dp[1][i+1] = max(dp[1][i+1], dp[1][i] + inc);
			}
		}
//cerr << "before: "<< dp[0][i] <<"," << dp[1][i] << " --> " << dp[0][i+1] << "," << dp[1][i+1] << endl;
	}
	
	cout << max(dp[0][M], dp[1][M]) + tot << endl;
	
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll mod = 998244353;

ll modpow(ll a, ll p)
{
    if (p == 0)
        return 1;
    if (!(p % 2))
    {
        ll halfP = p / 2;
        ll half = modpow(a, halfP);
        return half * half % mod;
    }
    else
    {
        return a * modpow(a, p - 1) % mod;
    }
}

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

	int N;
	cin >> N;

	int max = 0;

	vector<ll> D(N);
	ll temp = 0;
	for(int i=0; i<N; i++){
		cin >> temp;
		D[temp]++;
		if(i==0 && temp!=0){
			cout << 0 << "\n";
			return 0;
		}
		else if(i!=0 && temp == 0){
			cout << 0 << "\n";
			return 0;
		}
		if(max < temp) max = temp;
	}

	if(D[0] != 1){
		cout << 0 << "\n";
		return 0;
	}

	ll ans = 1;
	ll prev = 1;
	FOR(i,1,max+1){
		// cout << ans << "\n";
		if(D[i] == 0){
			cout << 0 << "\n";
			return 0;
		}
		else{
			ll pow = modpow(prev,D[i]) % 998244353;
			ans = ans * pow;
			prev = D[i];
		}
		ans = ans % 998244353;
	}

	cout << ans << "\n";

return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h> 
using namespace std; 
 
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define lli long long int
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define pll pair<lli,lli>
#define ve vector<lli>
#define vep vector<pair<lli,lli> >
#define fr(i,a,n) for(lli i=a;i<(n);i++)
#define frj(j,a,n) for(lli j=a;j<(n);j++)
#define frx(i,a,n) for(lli i=a;i>(n);i--)
#define frxj(j,a,n) for(lli j=a;j>(n);j--)
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define endl '\n'
#define db(x) cout << "[ " << x << " ]" << endl;
#define dbarr(arr,a,n) {fr(i,0,n) cout<<arr[i]<<" "; cout<<endl;}

int main(){
    lli h,w,m;
    cin>>h>>w>>m;
    map<lli,lli> cols,rows;
    map<pll,lli> pts;
    fr(i,0,m){
        lli x,y;
        cin>>x>>y;
        rows[x]++;
        cols[y]++;
        pts[mp(x,y)]++;
    }
    lli ans=0;
    lli maxi=-1e18;
    ve maxrows,maxcols;
    for(auto p:rows) maxi=max(maxi,p.S);
    for(auto p:rows){
        if(p.S==maxi)maxrows.pb(p.F);
    }
    ans+=maxi;
    maxi=-1e18;
    for(auto p:cols) maxi=max(maxi,p.S);
    for(auto p:cols){
        if(p.S==maxi)maxcols.pb(p.F);
    }
    ans+=maxi;
    lli flag=0;
    for(auto r:maxrows){
        for(auto c:maxcols){
            if(pts[mp(r,c)]==0){
                flag=1;
                break;
            }
        }
    }
    if(!flag)ans-=1;
    cout<<ans;
}

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

using namespace std;
const int MAXN = 1e5 + 7;
const int INF = 1e9 + 7;

int w[110], v[110], dp[110][MAXN];

int main(){
  int n, W;
  cin >> n >> W;
  int sumV = 0;
  for (int i = 1; i <= n; i++) {
    cin >> w[i] >> v[i];
    sumV += v[i];
  }
  for (int i = 0; i <= n; i++) 
    for (int j = 0; j <= sumV; j++)
      dp[i][j] = INF;
  dp[0][0] = 0; 
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= sumV; j++) {
      if (j - v[i] >= 0) dp[i][j] = min(dp[i-1][j], w[i] + dp[i-1][j - v[i]]);
      else dp[i][j] = dp[i-1][j];
    }
  }
  for (int i = sumV; i >= 0; i--) {
    if (dp[n][i] <= W) {
      cout << i << '\n';
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 41216
// And in the end, the love you take is equal to the love you make.
//                      Paul McCartney (the Beatles). The End. Abbey Road.

#include <bits/stdc++.h>
using namespace std;

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char buff[BUFF], *begin = buff, *end = buff;
char getc() {
    if (begin == end) {
        begin = buff;
        end = buff + fread(buff, 1, BUFF, stdin);
    }
    return begin == end ? -1 : *begin++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0; bool pos = true; char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

const size_t N = 2e5 + 5;
const int MOD = 1e9 + 7;

int qpow(int base, int e) {
    int ret = 1;
    for (; e; e >>= 1) {
        if (e & 1) ret = (LL) ret * base % MOD;
        base = (LL) base * base % MOD;
    }
    return ret;
}

int fac[N], inv[N];

void prep(int n) {
    fac[0] = 1;
    for (int i = 1; i <= n; ++i) {
        fac[i] = (LL) fac[i - 1] * i % MOD;
    }
    inv[n] = qpow(fac[n], MOD - 2);
    for (int i = n; i >= 1; --i) {
        inv[i - 1] = (LL) inv[i] * i % MOD;
    }
}

int main() {
    int b = read(), w = read(), tot = b-- + w--;
    prep(tot);
    int dv = 1, totb = 0, totw = 0;
    for (int i = 0; i < tot; ++i) {
        int b_w = 1 - totb - totw;
        while (b_w < 0) b_w += MOD;
        if (b_w & 1) b_w += MOD; b_w >>= 1;
        int ans = totw + b_w;
        if (ans >= MOD) ans -= MOD;
        printf("%d\n", ans);
        if (dv & 1) dv += MOD; dv >>= 1;
        int no_b = i >= b ? (LL) fac[i] * inv[b] % MOD * inv[i - b] % MOD * dv % MOD : 0;
        int no_w = i >= w ? (LL) fac[i] * inv[w] % MOD * inv[i - w] % MOD * dv % MOD : 0;
        totb += no_b; if (totb >= MOD) totb -= MOD;
        totw += no_w; if (totw >= MOD) totw -= MOD;
    }
    return 0;
}

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

int main(){
	int r, g, b;
	scanf("%d%d%d", &r, &g, &b);
	int x = r * 100 + g * 10 + b;
	printf("%s\n", x % 4 ? "NO" : "YES");
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n;
  int a[1000],
    b[1000],
    c[1000];
  int t,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d",&a[i],&b[i],&c[i]);
    if(a[i]>b[i]){
      t=a[i];
      a[i]=b[i];
      b[i]=t;
    }
    if(b[i]>c[i]){
      t=b[i];
      b[i]=c[i];
      c[i]=t;
    }
    if(a[i]*a[i]+b[i]*b[i]==c[i]*c[i]){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 588
inline int modexp(int a, int b);
#include<cstdio>
#include<map>
#include<cassert>
#include<functional>
#include<string>
#include<cassert>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
const int MOD(1e9+7);

ll a, b, c;

int main()
{
 scanf("%lld%lld%lld", &a, &b, &c);
 ll ans = 1LL << 60;
 ans = min((a-a/2)*b*c - (a/2) * b * c, ans);
 ans = min(a*(b-b/2)*c - a * (b/2) * c, ans);
 ans = min(a*b*(c-c/2) - a * b * (c/2), ans);
 printf("%lld\n", ans);
 return 0;
}


inline int modexp(int a, int b)
{
 int e = a, r = 1;
 while (b > 0) {
  if (b&1) r = r *1LL* e % MOD;
  e = e *1LL* e % MOD;
  b >>= 1;
 }
 return r;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int s,w;
  cin >> s >> w;
  if(w>=s)
  {
    cout<< "unsafe"<< endl;
  }
  else
  {
    cout<< "safe"<<endl;
  }
  return 0;
  
}


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

using namespace std;

int main() {
    int N, d[100000];
    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> d[i];
    }
    sort(d, d+N);
    cout << d[N/2]-d[N/2-1] << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {

	public static void main(String[] args) {

		//フィールド
		int n = 0;
		int kisu = 0;
		int gusu = 0;

		//入力
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		int intList[] = new int[n];

		for(int i = 0; i < n; i++) {
			int x = scanner.nextInt();
			intList[i] = x;
		}

		for(int i = 0; i < intList.length - 1 ; i++) {
			for(int j = intList.length - 1; j > i; j--) {
				if(intList[j] > intList[j-1]) {
					int x = intList[j-1];
					intList[j-1] = intList[j];
					intList[j] = x;
				}
			}
		}

		for(int i = 0; i < intList.length; i ++) {
			if(i % 2 == 0) {
				gusu = gusu + intList[i];
			}else{
				kisu = kisu + intList[i];
			}
		}

		System.out.println(gusu - kisu);

	}
}


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

int main(){
  int N, x;
  cin >> N >> x;
  vector<int>a(N);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
  }
  int count = 0;
  
  sort(a.begin(), a.end());
  for(int i = 0; i < N - 1; i++){
    if(x >= a.at(i)){
      count++;
      x -= a.at(i);
    }   
  }
  if(x == a.at(N - 1))count++;
  cout << count << endl;
}


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

class Program
 {
        static void Main(string[] args)
        {
          //入力を受け取る
          int n = int.Parse(Console.ReadLine());
          string[] B = Console.ReadLine().Split(' ');          
          int sum = int.Parse(B[0])+int.Parse(B[n-2]);
          for (int i = 1; i < n-1; i++){
            if(int.Parse(B[i-1]) >= int.Parse(B[i])){
              sum += int.Parse(B[i]);
            }else{
              sum += int.Parse(B[i-1]);
            }
          }
          System.Console.WriteLine(sum);
        }
 }

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

#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl         "\n"
#define int          long long
#define all(v)       v.begin(),v.end()
#define sz(v)        (int)v.size()
#define pii          pair<int,int>
#define fi           first
#define se           second
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define deb(x)       cout << #x << ' ' << x << endl
#define clock        cerr << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms" << endl;

void INPUT() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

const int N = 105;

int a[N][2];
int n, w;
int cache[N][100005];

int dp(int idx, int wt) {
	if (idx == n) return 0;
	if (cache[idx][wt] != -1) return cache[idx][wt];
	int ans;
	if (wt + a[idx][0] <= w) ans = max(a[idx][1] + dp(idx + 1, wt + a[idx][0]), dp(idx + 1, wt));
	else ans = dp(idx + 1, wt);
	cache[idx][wt] = ans;
	// deb(idx); deb(ans);
	return cache[idx][wt];
}

int32_t main(){
    IOS //INPUT();
    cin >> n >> w;
    forn(i, 0, n) {
    	forn(j, 0, 2) cin >> a[i][j];
    }
    memset(cache, -1, sizeof(cache));
    int ans = dp(0, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 82304
/**
 * author  : UshanGhosh
 * created : 2020-09-19 18:06:59
**/ 

#include<bits/stdc++.h>
using namespace std;

#define    ll      long long
#define    pii     pair<int,int>
#define    vii     vector<int>
#define    vcc     vector<char>
#define    pll     pair<long long, long long>
#define    mem     memset
#define    sof     sizeof
#define    co1     __builtin_popcountll
#define    PB      push_back
#define    UB      upper_bound
#define    LB      lower_bound
#define    MP      make_pair
#define    TS      to_string
#define    F       first
#define    S       second
#define    pi      acos(-1)
#define    mod     (int)1e9+7
#define    inf     (long long)1e18
#define    endl    '\n'

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long a,b,c,d,e,f,i,j,k,m,n,o,x,y;
    cin>>n;
    bool ans = false;
    c = 0;
    for(i=0;i<n;i++){
        cin>>a>>b;
        if(a==b) c++;
        else c = 0;
        if(c==3) ans = true;
    }
    if(ans) cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n; 
	map<string,int> mp;
	for(int i=0; i<n; ++i){
		string s;
		cin >> s;
		++mp[s];
	}
	cout << "AC x " << mp["AC"] << endl;
	cout << "WA x " << mp["WA"] << endl;
	cout << "TLE x " << mp["TLE"] << endl;
	cout << "RE x " << mp["RE"] << endl;
}

Measured memory_bytes: 3596
N = int(input())
a = list(map(int,input().split()))
mode = [0]*(10**5+2)
for i in range(len(a)):
    k = a[i]
    if(a == 0):
        mode[k] += 1
        mode[k+1] += 1
    else:
        mode[k-1] += 1
        mode[k]   += 1
        mode[k+1] += 1

print(max(mode))

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

public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n = Integer.parseInt(br.readLine());
			if(n==0){break;}
			run(n,n,"");
		}
	}

	static void run(int n, int limit, String ans){
		for(int i=limit;i>0; i--){
			if(n == i){
				System.out.println(ans+i);
			}else{
				run(n-i,(n-i)<i ? n-i:i,ans+i+" ");
			}
		}
	}
}

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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===



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

	int N, W;
	cin >> N >> W;

	vector<Vi> value(4);
	int w1, v1;
	cin >> w1 >> v1;
	value[0].push_back(v1);

	for (int i = 1; i < N; ++i) {
		int wi, vi;
		cin >> wi >> vi;
		value[wi - w1].push_back(vi);
	}
	
	for (int i = 0; i < 4; ++i) {
		sort(value[i].begin(), value[i].end(), greater<int>());
	}

	vector<Vi> csum(4);
	for (int i = 0; i < 4; ++i) {
		int ni = (int)value[i].size();
		csum[i].resize(ni + 1);
		for (int j = 0; j < ni; ++j) {
			csum[i][j + 1] = csum[i][j] + value[i][j];
		}
	}

	int ans = -I_INF;

	for (int x = 0; x <= N; ++x) {
		for (int i = 0; i <= x; ++i) {
			for (int j = i; j <= x; ++j) {
				for (int k = j; k <= x; ++k) {
					int n1 = i;
					int n2 = j - i;
					int n3 = k - j;
					int n4 = x - k;
					if (n1 >= (int)csum[0].size() || n2 >= (int)csum[1].size() || n3 >= (int)csum[2].size() || n4 >= (int)csum[3].size())
						continue;
					ll wsum = (ll)w1 * n1 + (ll)(w1 + 1) * n2 + (ll)(w1 + 2) * n3 + (ll)(w1 + 3) * n4;
					int vsum = csum[0][n1] + csum[1][n2] + csum[2][n3] + csum[3][n4];
					if (wsum <= W) ans = max(ans, vsum);
				}
			}
		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int num;
int cost[100];
int value[100];

int memo[100][20];

int search(int pos,int restD) {
	int res=0,nowres;
	if(pos>=num)return 0;
	if(memo[pos][restD]>0)return memo[pos][restD]-1;
	res=search(pos+1,restD);
	if(restD>=cost[pos]) {
		nowres=value[pos]+search(pos+1,restD-cost[pos]);
		if(nowres>res)res=nowres;
	}
	memo[pos][restD]=res+1;
	return res;
}

int main(void) {
	int D;
	int x,y;
	char buf[4];
	int score;
	int i;
	num=0;
	scanf("%d",&D);
	scanf("%d",&x);
	for(i=0;i<x;i++) {
		scanf("%s%d",buf,&score);
		if(buf[0]=='D') {
			cost[num]=1;
			value[num]=score;
			num++;
		}
	}
	scanf("%d",&y);
	for(i=0;i<y;i++) {
		scanf("%s%d",buf,&score);
		if(buf[0]=='D' && buf[1]=='D') {
			cost[num]=2;
			value[num]=score;
			num++;
		}
	}
	printf("%d\n",search(0,D));
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define rep(i, n) for (int i=0; i<(n); i++)
#define rep2(i, x, n) for (int i=x; i<(n); i++)
using namespace std;
int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    rep(i,n){
        
        int a, b, c;
        cin >> a >> b >> c;
        
        if(a>b&&a>c){
            cout << ( (a == b) == c ? "NO" : b*b + c*c == a*a ? "YES" : "NO" ) << endl;
        }else if(b>a&&b>c){
            cout << ( (a == b) == c ? "NO" : a*a + c*c == b*b ? "YES" : "NO" ) << endl;
        }else{
            cout << ( (a == b) == c ? "NO" : a*a + b*b == c*c ? "YES" : "NO" ) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
 int N,K;
 cin >> N >> K;
 vector<int> a(N+1,200000+1);
  rep(i,N+1){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  vector<pair<int,int>> b;
  
  int c = 0;//整数の種類数
  int d = 1;//ある数の連続する個数
  rep(i,N){
    if(a[i] == a[i+1]){
      d++;
    }
    else {
      pair<int,int>  p(d,a[i]);
      b.push_back(p);
      c++;
      d = 1;
    }
  }

  sort(b.begin(),b.end());
  int ans = 0;
  if(c>K) {
    for(int i = 0;i<c-K;i++){
      ans += b[i].first;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3188
#include<iostream>
using namespace std;
unsigned long long int f[90];
int main()
{
	int n;
	cin>>n;
	f[0]=2;
	f[1]=1;
	for(int i=2;i<=n;i++)
	{
		f[i]=f[i-1]+f[i-2];
	}
	cout<<f[n];
}

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



int main () {

    string n, m;

    cin >> n >> m;

    bool d = 0;

    for (int i = 0; i < n.size(); ++i) {
        if (n[i] != m[i]) {
            cout << "No\n";
            d = 1;
            break;
        }
    }

    if (!d) cout << "Yes\n";
    
}


Measured memory_bytes: 3628