akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vpii vector<pair<int,int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string> 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; }
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }

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

	int h, w, n;
	cin >> h >> w >> n;
	int a = max(h, w);
	int ans = (n + a - 1) / a;
	co(ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm> 
#include<memory.h> 
using namespace std;
typedef long long ll;
const int maxn=5e5+10;
char a[50][50];
int hang[50],lie[50];

int main()
{
	int n,m,kk;ll ans=0;
	cin>>n>>m>>kk;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++) cin>>a[i][j];
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<(1<<m);j++){
			int count=0;
			memset(hang,0,sizeof(hang));
		    memset(lie,0,sizeof(lie));
			for(int k=0;k<n;k++){
				if((1<<k)&i) hang[k]=1;
			}
			for(int k=0;k<m;k++){
				if((1<<k)&j) lie[k]=1;
			}
			for(int k=0;k<n;k++){
				for(int k1=0;k1<m;k1++){
					if(hang[k]||lie[k1]) continue;
					if(a[k][k1]=='#') count++;
				}
			}
			if(count==kk) ans++;
		}
	}
	cout<<ans;
	return 0;
}

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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

const ll INF = 1e18;
const int MAXN = 3e5 + 5;


ll N, ans;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	ans = (N * (N+1)) / 2;
	ll a = N / 3, b = N / 5, c = N / 15;
	ans -= 3 *(a * (a+1)) / 2;
	ans -= 5 *(b * (b+1)) / 2;
	ans += 15 * (c * (c+1)) / 2;
	cout << ans;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;
ll mul(ll a, ll b){
    return ((a%mod) * (b%mod))%mod;
}
ll power(ll a, ll b){
    ll z = 1; ll x = a;
    while(b>0){
        if (b&1)z = mul(z, x);
        x = mul(x, x);
        b >>= 1;
    }
    return z;
}
int main()
{
    int n;
    cin>>n;
    int temp = 0;
    while(temp < n)temp+=1000;
    cout<<temp-n<<endl;
}


Measured memory_bytes: 3612
chessBorad :: Int -> [Int] -> String
chessBorad i l@(h:w:_)
  | h == 0 && w == 0 = "end"
  | i >= h           = "\n"
  | even i           = ((++ "\n") . take w . concat . repeat $ "#.")  ++ chessBorad (i+1) l
  | otherwise        = ((++ "\n") . take w . concat . repeat $ ".#")  ++ chessBorad (i+1) l

main = getContents >>=
       mapM_ (putStr) . takeWhile (/= "end") . map (chessBorad 0 . map read . words) . lines

Measured memory_bytes: 5004
n = int(input())
a = list(map(int, input().split()))
a0, a1, a2 = 0, 0, 0
for i in a:
  if i % 2 == 1:
    a0 += 1
  elif i % 4 == 2:
    a1 = 1
  else:
    a2 += 1
if a0 + a1 <= a2 + 1:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 14252
S = gets.chomp
T = gets.chomp

cnt = 0
dif = S.size - T.size + 1
dif.times do |i|
  temp_cnt = 0
  T.size.times do |j|
    temp_cnt += 1 if S[i+j] == T[j]
  end
  cnt = temp_cnt if temp_cnt > cnt
end

puts T.size - cnt

Measured memory_bytes: 14232
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;




int main() {
	string s;
	cin >> s;
	vector<int> used(26,-1);
	for (int i = 0; i < s.size(); i++) {
		used[(int)(s[i]-'a')] = i;
	}
	if (s.size() < 26) {
		for (int i = 0; i < 26; i++) {
			if (used[i] == -1) {
				cout << s << (char)(i + 'a') << endl;
				return 0;
			}
		}
	}
	else {
		for (int i = 25; i >= 0; i--) {
			for (int j = (int)(s[i]-'a'); j < 26; j++) {
				if (used[(int)(s[i] - 'a')] < used[j]) {
					cout << s.substr(0, i) << (char)(j + 'a') << endl;
					return 0;
				}
			}
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; i++)
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
#define all(vec) vec.begin(), vec.end()
#define MOD (int) (1e9 + 7)
namespace mp = boost::multiprecision;
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cost;
};

class dijkstra {
  private:
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<>> que;

  public:
	dijkstra(int v, int s, vector<edge> G[]) {
		V = v;
		update(s, G);
	}

	void update(int s, vector<edge> G[]) {
		fill(d, d + V + 1, 100000000000ll);
		d[s] = 0;
		que.push(make_pair(0, s));
		while (!que.empty()) {
			P p = que.top();
			que.pop();
			int v = p.second;
			if (d[v] < p.first)
				continue;
			rep(i, G[v].size()) {
				edge e = G[v][i];
				if (d[e.to] > d[v] + e.cost) {
					d[e.to] = d[v] + e.cost;
					que.push(make_pair(d[e.to], e.to));
				}
			}
		}
	}

	int find(int e) {
		return d[e];
	}
};

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

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool prime(int a) {
	if (a == 1)
		return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0)
			return false;
	}
	return true;
}

class Union_Find {
  private:
	vector<int> t, s;

  public:
	Union_Find(int max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}

	void Union(int x, int y) {
		if (same(x, y))
			return;
		int tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}

	int Find(int n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}

	bool same(int x, int y) {
		return Find(x) == Find(y);
	}

	int get_Size(int a) {
		return s[a];
	}
};

set<int> prime_num_factor(int n) {
	if (n < 2)
		return set<int>();
	set<int> prime;
	prime.insert(2);
	for (int i = 3; i <= n; i++) {
		for (int it : prime) {
			if (it * it > i) {
				prime.insert(i);
				break;
			}
			if (i % it == 0)
				break;
		}
	}
	return prime;
}
vector<int> primeFactorization(int n) {
	vector<int> re;
	int cnt = 2;
	while (n != 1) {
		if (n % cnt != 0) {
			cnt++;
			continue;
		}
		n /= cnt;
		re.push_back(cnt);
	}
	return re;
}
signed main() {
	int a, b;
	cin >> a >> b;
	if(a%2!=b%2)cout<<"IMPOSSIBLE"<<endl;
	else cout<<(a+b)/2<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define rep(i,n) for(int i=0;i<int(n);i++)
using namespace std;

inline int max(int a, int b) {//最大
	if (a > b) return a;
	return b;
}
inline int min(int a, int b) {//最小
	if (a < b) return a;
	return b;
}

int n,p[200005];
int ma = INF;
int counter = 0;
int main() {
	cin >> n;
	p[0] = INF;
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}

	for (int i = 1; i <= n; i++) {
		ma = min(p[i - 1], ma);
		if (ma >= p[i]) counter++;
		//cout << ma << endl;
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 1024
/** omgursocute **/
#include <bits/stdc++.h>
 
using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
 
	int n;
	cin >> n;
 
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
 
	bool ok = 1;
	for(int i = n-1; i > 0; i--) {
		if(a[i-1] <= a[i]) continue;
		else {
			a[i-1]--;
			if(a[i-1] ^ a[i]) ok = 0;
		}
	}
 
	cout << ((ok) ? "Yes" : "No");
 
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms.\n";
}
 
// g++ o .cpp -O2 -std=c++11 -D cute -Wall -Wno-unused-result

Measured memory_bytes: 640
using System;
using System.Linq;

namespace ABC139
{
    class Program
    {
        static void Main()
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();
            var ans = 0;
            for (int i = 0; i < 3; i++)
                if (S[i] == T[i]) ans++;

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
class Integer
  def divisor
    res = []
    1.upto((self**0.5)) do |i|
      if self % i == 0
        res.push i
        res.push self / i if i != self / i
      end
    end
    res.sort
  end
end

def answer_if_valid(x, a, d)
  b = a - d
  if x == a ** 5 - b ** 5
    puts "#{a} #{b}"
    exit
  end
end

x = gets.to_s.to_i

r = x % 5

divisors = x.divisor.select{|t| r == t % 5}

divisors.each do |d|
  
  left = (( x / d - d ** 4 ) / 5).abs
  
  if left == 0
    answer_if_valid(x,0,d)
    (d ** 3).abs.divisor.each do |a|
      answer_if_valid(x, a, d)
      answer_if_valid(x,-a, d)
    end
  end
  
  left.divisor.each do |a|
    answer_if_valid(x,  a, d)
    answer_if_valid(x, -a, d)
  end
end

Measured memory_bytes: 14712
N, T = map(int, input().split())
c, t = [0] * N, [0] * N
ans = 100000
for i in range(N):
    c[i], t[i] = map(int, input().split())
    if t[i] <= T: ans = min(ans, c[i])
print(ans) if ans <= 1000 else print('TLE')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n,s[1003];
int main()
{
  scanf("%d",&n);
  for (int a=1;a<=n;a++)
  {
    scanf("%d",&s[a]);
  }
  sort(s+1,s+n+1);
  printf("%d",s[n]-s[1]);
}


Measured memory_bytes: 256
def resolve():
  a, b, c, x, y = map(int, input().split())
  ans = a * x + b * y
  # A を AB で代替する
  ans = min(ans, c * x * 2 + max(0, b * (y - x)))
  # B を AB で代替する
  ans = min(ans, c * y * 2 + max(0, a * (x - y)))

  print(ans)
  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main() {
  string s;
  cin >> s;
  if(s=="Sunny"){
    cout << "Cloudy"<<endl;
  }
  if(s=="Cloudy"){
    cout << "Rainy"<<endl;
  }
  if(s=="Rainy"){
    cout << "Sunny"<<endl;
  }

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

class mint{
public:
  ll x;
  mint(ll x=0) : x(x%mod){}
  mint& operator+=(const mint rhs){
    x += rhs.x;
    while(x >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint rhs){
    x -= rhs.x;
    while(x < 0) x += mod;
    return *this;
  }
  mint & operator*=(const mint rhs){
    (x *= rhs.x) %= mod;
    return *this;
  }
  mint operator+(const mint rhs) const {
    mint res(*this);
    return res += rhs;
  }
  mint operator-(const mint rhs) const {
    mint res(*this);
    return res -= rhs;
  }
  mint operator*(const mint rhs) const {
    mint res(*this);
    return res *= rhs;
  }
  friend ostream& operator<<(ostream& os,const mint rhs){
    os << rhs.x;
    return os;
  }
};

#define rep(index,num) for(int index=0;index<num;++index)

int N,L;

int main(){
  std::cin >> N >> L;
  int taste[N];
  int sum = 0;
  rep(i,N){
    taste[i] = L + i;
    sum += L + i;
  }
  sort(taste,taste+N,[](int a,int b){return abs(a) < abs(b);});
  cout << sum - taste[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define all_acc(x) (x).begin(),(x).end(),0LL
#define int long long
#define absSort(v) sort(a.begin(), a.end(), [](int i, int j) -> bool {return abs(i) < abs(j);});
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

//出力するよ
void output(vector<int> s,int index){
    int n=s.size();
    for(int i=0;i<n;i++){
        if(i!=0) cout<<" ";
        if(i==index) cout<<"["<<s[i]<<"]";
        else cout<<s[i];//<<endl;
    }
    cout<<endl;
}

int partition(vector<int> &a,int p,int r){
    int x=a[r-1];
    int i=p-1;
    for(int j=p;j<(r-1);j++){
        if(a[j]<=x){
            i++;
            int key=a[i];
            a[i]=a[j];
            a[j]=key;
        }
    }
    int key=a[i+1];
    a[i+1]=a[r-1];
    a[r-1]=key;
    return i+1;
}

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

    int index=partition(a,0,n);
    output(a,index);
}


Measured memory_bytes: 4472
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n,k;
    cin>>n>>k;
    string str;
    cin>>str;
    char last = '0';
    ll blocks=0,i=0;
    ll ans=0;
    for(i=0;i<n;i++){
        if(str[i]!=last){
            blocks++;
            last=str[i];
        }
        if(str[i]=='L' && i>0 && str[i-1]=='L') ans++;
        if(str[i]=='R' && i<n-1 && str[i+1]=='R') ans++;
    }
    ll half=blocks/2;
    if(k>=half){
        ans=n-1;
    }
    else{
        ans=ans+2*k;
    }
    cout<<ans;
}


Measured memory_bytes: 512
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
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; }
ll s[200100];
int main() {
    string S;
    cin >> S;
    ll ans = 0; vector<ll> cnt(2100, 0);
    ll b = 1;
    rrep(i, S.size()) {
        ll a = S[i] - '0';
        if (i == S.size() - 1) {
            s[i] = a;
        }
        else {
            s[i] = a * b % 2019 + s[i + 1];
        }
        s[i] %= 2019;
        cnt[s[i]]++;
        b *= 10;
        b %= 2019;
    }
    rep(i, 2100) {
        if (i == 0) {
            ans += cnt[i];
        }
        if (cnt[i] % 2 == 1) {
            ans += cnt[i] * ((cnt[i] - 1) / 2);
        }
        else {
            ans += cnt[i] / 2 * ((cnt[i] - 1));
        }
    }
    cout << ans << endl;
}





























































































































































































































































































































Measured memory_bytes: 5272
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i < (n);i++)
using namespace std;
int main(){
  int n;
  long long total=0;
  cin >> n;
  vector<int> a(n+1,0);
  vector<int> b(n,0);
  rep(i,n+1) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n){
    //左を倒せる限りすべて倒す
    int left = min(a[i],b[i]);
    total += left;
    
    b[i]-=left;
    //残った戦力で右を倒す
    int right = min(a[i+1],b[i]);
    total += right;
    a[i+1] -=right;
    
  }
  cout << total << endl;
}



Measured memory_bytes: 1024
from sys import stdin


def main():
    lines = stdin.readlines()
    T = int(lines[0].split()[1])
    tn = [int(ti) for ti in lines[1].split()]
    print(tn[-1] + T - sum(t2 - t1 - T for t1, t2 in zip(tn[0:], tn[1:]) if t2 - t1 > T))
    return


main()


Measured memory_bytes: 27324
D, G = map(int, input().split())
p = []
c = []
for i in range(D):
    pi, ci = map(int, input().split())
    p.append(pi)
    c.append(ci)

minProblems = 10000000

for i in range(2 ** D):
    tempScore = 0
    bit = 1
    solveSet = [False] * D
    solveCount = 0
    for j in range(D):
        if i & bit:
            solveSet[j] = True
            solveCount += p[j]
            tempScore += p[j] * 100 * (j + 1)
            tempScore += c[j]

        bit = bit << 1
    
    if tempScore >= G:
        minProblems = min(minProblems, solveCount)
        continue

    minNeedProblems = 10000000
    for j in range(D):
        if not solveSet[j]:
            needPoint = G - tempScore
            needProblems = (needPoint - 1) // (100 * (j + 1)) + 1
            if needProblems < p[j]:
                minNeedProblems = min(minNeedProblems, needProblems)

    if minNeedProblems <= 100:
        minProblems = min(minProblems, solveCount + minNeedProblems)

print(minProblems)

Measured memory_bytes: 3064
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

# 和がL以上の2つをつなぐ
# 和がL以上のものが1つ作れたら、その周辺だけ処理していけばよい

N,L,*A = map(int,read().split())

S = [0] + [x+y for x,y in zip(A,A[1:])]
M = max(S)
i = S.index(M)

if M < L:
    print('Impossible')
    exit()

answer = list(itertools.chain(range(i,0,-1),range(i+1,N)))[::-1]
print('Possible')
print('\n'.join(map(str,answer)))

Measured memory_bytes: 22496
#include <iostream>
using namespace std;
int main(void){
   int H,W;
   while(true){
       cin >> H >> W;
       for(int i=0;i<H;i++){
           for(int j=0;j<W;j++){
               if(i==0 || i==(H-1) || j==0 || j==(W-1)){
                   cout << "#";
               }
               else{
                   cout << ".";
               }
           }
       cout << endl;
       }if(W == 0 && H == 0){
           break;
       }
       cout << endl;
   }
}


Measured memory_bytes: 3068
import java.io.*;
import java.util.*;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int k = in.i() + 1;
        int a = in.i();
        long b = in.i() - a;
        int c = k - a;
        long ans = Math.max(k, a + c / 2 * b + c % 2);
        System.out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


Measured memory_bytes: 32532
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll DP[55][3000];

int main() {
  int N, A;
  cin>>N>>A;
  vector<int> arr(N);
  for(int i=0;i<N;++i) {
    cin>>arr[i];
    arr[i] -= A;
  }
  DP[0][1500+arr[0]]++;
  DP[0][1500]++;
  for(int i=0;i<N-1;++i) {
    for(int j=0;j<3000;++j) {
      if(DP[i][j]>0) {
        DP[i+1][j] += DP[i][j];
        DP[i+1][j+arr[i+1]] += DP[i][j];
      }
    }
  }
  cout<<DP[N-1][1500]-1<<endl;
}



Measured memory_bytes: 4252
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    for(;;){
        string S; cin >> S;
        if(S=="-") break;
        int N; cin >> N;
        rep(i,N){
            int a; cin >> a;
            S=S.substr(a,S.size()-a)+S.substr(0,a);
        }
        cout << S << endl;
    }

    return 0;
}


Measured memory_bytes: 3216
n = int(input())

def toa(n):
    return chr((ord('a')+(n)))

temp = n
digit = 1
temp-=26**digit
while temp > 0:
    digit+=1
    temp-=26**digit

k = n - sum([26**(i+1) for i in range(digit-1)])
x = k-1

ans = ''
while x>0:
    ans = toa(x%26)+ans
    x//=26

ans = 'a'*(digit-len(ans)) +ans
print(ans)

Measured memory_bytes: 9036
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

int main()
{
	int n;
	cin >> n;
	string str;
	char pre;
	cin >> str;
	pre = str[0];
	int ret = 1;
	rep(i, n - 1)
	{
		ret += pre != str[i + 1];
		pre = str[i + 1];
	}

	cout << ret;

	return 0;
}

Measured memory_bytes: 512
s = input()
ans = 'AC'
if s[0] == 'A' and s[2:-1].count('C') == 1:
  s = s[:s.find('C')]+s[s.find('C')+1:]
  s = s[1:]
else:
  ans='WA'
if s != s.lower():
  ans='WA'
print(ans)

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

int main(void){
	int n;
	while(cin>>n,n){
		vector<int> a(n);
		rep(i,n)cin>>a[i];
		sort(a.begin(),a.end());
		int dif=INT_MAX;
		rep(i,n-1)dif=min(dif,a[i+1]-a[i]);
		cout<<dif<<endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fr first
#define sc second
#define MAX ((ll)(1e18+100))
#define MOD ((ll)(1e9+7))
#define HS1 ((ll)(137))
#define HS2 ((ll)(1e9+9))
#define ARRS ((ll)(6e5+900))
#define pb push_back
#define mid ((l+r)>>1)
#define PI 3.14159265358979323846

int f[68000000];
string s;
int dp[300000];

int main(){
	cin>>s;
	ll k=0;
	ll n=s.size();
	f[0]=1;
	dp[0]=0;
	for(int i=1; i<=n; i++){
		k^=(1<<(s[i-1]-'a'));
		dp[i]=dp[i-1]+1;
		for(int j=0; j<26; j++){
			if(f[k^(1<<j)])
				dp[i]=min(dp[i],dp[f[k^(1<<j)]-1]+1);
		}
		if(f[k])
			dp[i]=min(dp[i],dp[f[k]-1]+1);
		if(!f[k]||dp[f[k]-1]>=dp[i])
			f[k]=i+1;
	}
	cout<<dp[n];
	return 0;
}


Measured memory_bytes: 264196
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  string s; cin >> s;
  vector<int> A,Z;
  for(int i=0;i<s.length();i++){
    if(s[i]=='A') A.push_back(i);
    if(s[i]=='Z') Z.push_back(i);
  }
  int z = *max_element(Z.begin(),Z.end());
  int a = *min_element(A.begin(),A.end());
  cout << (z-a)+1 << endl;
}


Measured memory_bytes: 1364
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

ll f(ll a) {
  if(a%2==1) {
    if((a+1)%4==0) return 0LL;
    else return 1LL;
  }
  else {
    if(a%4==0) return a;
    else return a+1;
  }
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll c = f(a-1);
  ll d = f(b);
  ll ans = 0LL;
  ll i = 1LL;
  while(c>0 || d>0) {
    if(c%2 != d%2) ans += i;
    c /= 2;
    d /= 2;
    i *= 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int r, c, k, ans[309][309];
string s[309];

void fun(int x)
{
	for (int i = x - 1; i >= 0; i--) {
		if (ans[i][0] > 0) break;
		for (int j = 0; j < c; j++) {
			ans[i][j] = ans[i + 1][j];
		}
	}
	for (int i = x + 1; i < r; i++) {
		if (ans[i][0] > 0) break;
		for (int j = 0; j < c; j++) {
			ans[i][j] = ans[i - 1][j];
		}
	}
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> r >> c >> k;
	for (int i = 0; i < r; i++) {
		cin >> s[i];
	}
	int cur = 1;
	for (int i = 0; i < r; i++) {
		int cnt = 0;
		for (int j = 0; j < c; j++) {
			if (s[i][j] == '#') cnt++;
		}
		if (cnt == 0) {
			continue;
		}
		for (int j = 0; j < c; j++) {
			//cout << cur;
			ans[i][j] = cur;
			if (s[i][j] == '#') {
				cur++;
				cnt--;
				if (cnt == 0) cur--;
			}
		}
		//cout << E;
		cur++;
	}
	for (int i = 0; i < r; i++) {
		if (ans[i][0] > 0)
			fun(i);
	}
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cout << ans[i][j] << " ";
		}
		cout << E;
	}

	//system("pause");
	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

template <typename T>
class UnionFind {
    private:
        vector<int> parent;  // 親
        vector<int> rank;    // 木の深さ

        // 重み付きUnionFindでのみ利用
        vector<T> diffWeight; // 親ノードとの値の差
    public:
        UnionFind(int n);          // n要素で初期化
        int Find(int x);           // 木の根を返す
        void Unite(int x, int y);  // xとyの属する集合を併合
        bool Same(int x, int y);   // xとyが同じ集合に属するか否か

        // 重み付きUnionFindでのみ利用
        void Unite(int x, int y, T w);
        T Weight(int x);      // xの重みを返す
        T Diff(int x, int y); // xとyの差を返す
};

    template <typename T>
UnionFind<T>::UnionFind(int n) : parent(n), rank(n), diffWeight(n, 0)
{
    for (int i = 0; i < n; i++) {
        parent[i] = i;
        rank[i] = 0;
    }
}

template <typename T>
int UnionFind<T>::Find(int x) {
    if (parent[x] == x) {
        return x;
    } else {
        int r = Find(parent[x]);
        diffWeight[x] += diffWeight[parent[x]];
        return parent[x] = r;
    }
}

template <typename T>
void UnionFind<T>::Unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
        parent[x] = y;
    } else {
        parent[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
}

template <typename T>
bool UnionFind<T>::Same(int x, int y) { return Find(x) == Find(y); }

template <typename T>
void UnionFind<T>::Unite(int x, int y, T w){
    w += Weight(x); w -= Weight(y);
    x = Find(x); y = Find(y);
    if(x == y) return;

    if(rank[x] < rank[y]) swap(x, y), w = -w;

    if(rank[x] == rank[y]) rank[x]++;
    parent[y] = x;

    diffWeight[y] = w;
}

template <typename T>
T UnionFind<T>::Weight(int x){
    Find(x);
    return diffWeight[x];
}

template <typename T>
T UnionFind<T>::Diff(int x, int y){
    return Weight(y) - Weight(x);
}

/*************** using variables **************/
int n, m;
/**********************************************/

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

    cin >> n >> m;
    bool flag = true;
    UnionFind<int> uf(n);
    REP(i, m){
        int l, r, d;
        cin >> l >> r >> d;
        l--, r--;
        if(!uf.Same(l, r)){
            uf.Unite(l, r, d);
        }else{
            if(uf.Diff(l, r) != d) flag = false;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 1408
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char (ord, chr)
import Data.Vector.Unboxed (Vector, (!), (//))
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve <$> (V.fromList <$> getLine) <*> replicateM n f >>= putStrLn
    main
  where
    f = map read <$> words <$> getLine

solve :: Vector Char -> [[Int]] -> String
solve v cs = V.toList $ foldl' swp v (reverse cs)
  where
    swp v [i, j] = let i' = i - 1
                       j' = j - 1
                       d = abs (i - j)
                   in v // [(i', enc d (v ! j')),(j', enc d (v ! i'))]
    enc d c = let a = ord 'a' in chr $ (ord c - a + d) `mod` 26 + a



Measured memory_bytes: 4980
// http://kmjp.hatenablog.jp/entry/2019/09/28/1030

import java.util.*;

public class Main {
  static Map<Integer, List<Integer>> edgeE = new HashMap<>();
  static List<Integer> vStack = new ArrayList<>(); // stack in DFS
  static int[] vStackState; // state of DFS.
  static List<Integer> cycle = new ArrayList<>();
  static Integer[] cycleSeqId; // id of cycle member.

  // Find cycle
  static void dfs(int cur) {
    if (vStackState[cur] == 2) { // Found node visited in current dfs. (a cycle)
      if (cycle.isEmpty()) {
        for (int i = 0; i < vStack.size(); i++) {
          if (vStack.get(i) == cur) { // Find starting point to avoid circle shape of `6`.
            for (int j = i; j < vStack.size(); j++) {
              cycle.add(vStack.get(j));
              cycleSeqId[vStack.get(j)] = j - i;
            }
            break;
          }
        }
      }
      return;
    }
    if (vStackState[cur] == 1) return;
    vStackState[cur] = 2;
    vStack.add(cur);
    for (Integer e : edgeE.get(cur)) {
      dfs(e);
    }
    vStack.remove(vStack.size() - 1);
    vStackState[cur] = 1;
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    for (int i = 1; i <= N; i++) {
      edgeE.put(i, new ArrayList<>());
    }
    int M = sc.nextInt();
    for (int i = 0; i < M; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      edgeE.get(a).add(b);
    }
    cycleSeqId = new Integer[N + 1];
    vStackState = new int[N + 1]; // 1-indexed (skip 0-th)
    Arrays.fill(cycleSeqId, -1);
    /* Search cycle. */
    for (int i = 1; i <= N; i++) { // if cycle is already found, loop is useless?
//  NG:    for (int i = 1; i <= N && !cycle.isEmpty(); i++) { // if cycle is already found, loop is useless?
      Arrays.fill(vStackState, 0);
      vStack.clear();
      dfs(i);
    }
    if (cycle.isEmpty()) {
      System.out.println("-1");
      return;
    }
    retry:
    for (int idxStart = 0; idxStart < cycle.size(); idxStart++) {
      Integer nodeIdxFrom = cycle.get(idxStart);
      for (Integer to : edgeE.get(nodeIdxFrom)) {
        if (
        /*member of cycle */ cycleSeqId[to] != -1
            && /* If path split. This is smaller cycle. */
          cycleSeqId[to] != (cycleSeqId[nodeIdxFrom] + 1) % cycle.size()) {
          List<Integer> C2 = new ArrayList<>();
          int newCycleSeqStartIdx = cycleSeqId[to]; // New starting point to avoid circle shape of `6`.
          Arrays.fill(cycleSeqId, -1);
          for (int j = 0; j < cycle.size(); j++) {
            Integer nodeIdx = cycle.get((newCycleSeqStartIdx + j) % cycle.size());
            C2.add(nodeIdx);
            cycleSeqId[nodeIdx] = j;
            if (nodeIdx.equals(nodeIdxFrom)) break;
          }
          cycle = C2;
          idxStart = -1;
          continue retry;
        }
      }
    }
    System.out.println(cycle.size());
    for (Integer c : cycle) {
      System.out.println(c);
    }
  }
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N),Acopy(N),ans(N);
    for (int i = 0; i < N;i++)
    {
        cin >> A.at(i);
        Acopy.at(i) = A.at(i);
    }
    sort(A.begin(), A.end());

    for (int i = 0; i < N; i++)
    {
        if(Acopy.at(i)!=A.at(N-1))
        {
            ans.at(i) = A.at(N-1);
        }else
        {
            ans.at(i) = A.at(N - 2);
        }
        cout << ans.at(i) << endl;
    }
}


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define N 200010
using namespace std;
 
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct edge{int v,next;}vs[N<<1];
int n,ee,st[N<<1],du[N],Rt,F[N];
inline void addedge(int u,int v)
{
	vs[++ee].v=v;vs[ee].next=st[u];st[u]=ee;
}
inline void dfs(int rt,int pr,int x)
{
	vector <int> v; v.clear();
	for(int i=st[rt];i;i=vs[i].next)
	{
		if(vs[i].v==pr) continue;
		dfs(vs[i].v,rt,x);
		v.push_back(F[vs[i].v]);
	}
	if(!(v.size()&1)) v.push_back(0);
	sort(v.begin(),v.end());
	// printf("son of node %d len of %d\n",rt,x);
	// for(int i=0;i<v.size();i++) printf("%d ",v[i]); puts("");
	int l=0,r=v.size()-1,rs=n+1;
	while(l<=r)
	{
		int mid=(l+r)>>1,fg=1;
		for(int i=0,j=v.size()-1;i<j;i++,j--)
		{
			if(i==mid) i++; if(j==mid) j--;
			fg&=(v[i]+v[j])<=x;
		}
		if(fg) r=mid-1,rs=v[mid];
		else l=mid+1;
	}
	F[rt]=rs+1;
}
inline bool check(int x)
{
	dfs(Rt,0,x); return F[Rt]<=x+1;
}
int main()
{
	// freopen("read.in","r",stdin);
	n=read(); for(int i=1;i<n;i++)
	{
		int u=read(), v=read();
		addedge(u,v); du[u]++;
		addedge(v,u); du[v]++;
	}
	int cnt=0; for(int i=1;i<=n;i++) 
		cnt+=du[i]&1,Rt=du[i]==1? i:Rt;
	int l=0,r=n,B=0;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid)) r=mid-1,B=mid;
		else l=mid+1;
	}
	cout << cnt/2 << " " << B << endl;
	return 0;
}

Measured memory_bytes: 12800
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args){ 
		Scanner cin = new Scanner(System.in);
		while(true){
			int N=cin.nextInt();
			int M=cin.nextInt();
			if(N+M==0){
				break;
			}
			int[] field = new int[N + 1000];
			for(int i = 1;i<=N;i++){
				field[i]=cin.nextInt();
			}
			int[] dice = new int[M];
			for(int i = 0;i<M;i++){
				dice[i]=cin.nextInt();
			}
			int now =  1;
			for(int i = 0;i<M;i++){
				now = now + dice[i] + field[now+dice[i]];
				//System.out.println(now);
				if(now >= N){
					System.out.println(i+1);
					break;
				}
			}
		}
	}

}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

    vector<lint> p(n);
    for(auto& elem : p)  cin >> elem;

    lint ans = 0;
    lint mn = 1e18;
    for(lint i=0; i<n; i++) {
        mn = min(mn, p[i]);
        if(mn == p[i])  ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import qualified Data.Map as Map
import qualified Data.IntMap as IMap
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)

bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt
strToInt s = (read :: String -> Int) s

readss :: Int -> String
readss x = show x

d :: Int -> Bool
d x = if (readss x) == (reverse (readss x))
      then True
      else False

main = do
    [a, b] <- (map strToInt . words) <$> getLine
    print $ length  [x | x <- [a..b] , (d x) == True]

Measured memory_bytes: 892
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	char[] ch;
	String S;
	boolean[] use = new boolean[10];

	long minDiff = Long.MAX_VALUE;
	String ansStr;
	String startStr;

	public void dfs(int n)
	{
		if(n == ch.length){
			ansStr = startStr;
			return;
		}

		if(n == 0){
			use[(ch[n] - '0' + 5) % 10] = true;
			startStr = startStr + (char)((ch[n] - '0' + 5) % 10 + '0');
			dfs(n + 1);
			return;
		}

		if(!use[ch[n] - '0']){
			dfs2(n,"");
			use[ch[n] - '0'] = true;
			startStr = startStr + ch[n];
			dfs(n + 1);
			return;
		}
		dfs2(n,"");
	}

	public void dfs2(int n,String s){
		if(n == ch.length){
			long a = Long.valueOf(S.substring(startStr.length()));
			long b = Long.valueOf(s);

			long diff = Math.abs(a - b);

			if(minDiff > diff){
				ansStr = startStr + s;
				minDiff = diff;
			}
			return;
		}

		for(int i = 0;i < 10;i++){
			if(use[i])continue;
			use[i] = true;
			dfs2(n + 1,s + (char)(i + '0'));
			use[i] = false;
		}
	}

	public void solve() {
		S = next();
		ch = S.toCharArray();
		startStr = "";
		ansStr = "";
		dfs(0);
		out.println(ansStr);

	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 95072
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    int ans = 0, mi = 1e9;
    REP(i,n){
        chmin(mi, a[i]);
        ans += (a[i] <= mi);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
s = input()
a = [0] * n
a[0] = s[1:].count("E")
for i in range(1,n):
    if s[i-1] == "W":
        a[i] = a[i-1] + 1
    else:
        a[i] = a[i-1]
    if s[i] == "E":
        a[i] -= 1
print(min(a))

Measured memory_bytes: 15436
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector<char> v(n);
  int s, res = 0;
  char c;
  for(int i=0; i<m; i++){
    cin >> s >> c;
    if( s==1 && c=='0' && n!=1 ){
      res = -1;
      break;
    }
    if( v[s-1]==0 || v[s-1] == c ){
      v[s-1] = c;
    } else {
      res = -1;
      break;
    }
  }
  int check = 0;
  if( res == 0 ){
    for(int i=0; i<n; i++){
      if(v[i]==0){
        if(i==0 && n!=1){
          cout << "1";
        }else{
          cout << "0";
        }
      } else {
        cout << v[i];
      }
    }
    cout << endl;
  } else cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 384
import itertools
import math

N = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

x_p = 0
x_q = 0

for i in range(N):
  x_p += p[i] * (10 ** (N - i - 1))
for i in range(N):
  x_q += q[i] * (10 ** (N - i - 1))

x_a = list(itertools.permutations(p))

x_b = list()
z = 0
for i in range(math.factorial(N)):
  for j in range(N):
    y = x_a[i][j] * (10 ** (N - j - 1))
    z += y
  x_b.append(z)
  z = 0
x_b.sort()
for i in range(math.factorial(N)):
  if x_p == x_b[i]:
    P = i + 1
for i in range(math.factorial(N)):
  if x_q == x_b[i]:
    Q = i + 1
print(abs(P - Q))

Measured memory_bytes: 9732
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int cost = a * x + b * y;
		if (x > y) {
		    cost = Math.min(cost, c * y * 2 + (x - y) * a);
		    cost = Math.min(cost, c * x * 2);
		} else {
		    cost = Math.min(cost, c * x * 2 + (y - x) * b);
		    cost = Math.min(cost, c * y * 2);
		}
		System.out.println(cost);
	}
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int a, b, c;
  cin >> a >> b >> c;
  bool flag = false;
  if (a == b && a != c) flag = true;
  if (b == c && b != a) flag = true;
  if (a == c && a != b) flag = true;
  if (flag) yn;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
constexpr ll TEN(int n){return n==0?1:10*TEN(n-1);}

constexpr ll inf = TEN(9)+5;
constexpr ll linf = 3*TEN(18);

int mn = inf;
int N, K;

void dfs(int d, int cur)
{
    if (d == N) {
        chmin(mn, cur);
    } else {
        dfs(d + 1, cur + K);
        dfs(d + 1, cur * 2);
    }
}

signed main()
{
    cin >> N >> K;

    dfs(0, 1);

    cout << mn << endl;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
int main() {
    
    int N;
    cin >> N;
    vector<long long>A(N+1,0);
    vector<long long>B(N,0);
    long long ans = 0;
    
    rep(i, 0, N+1){
        cin >> A[i];
    }
    rep(i, 0, N){
        cin >> B[i];
    }
    rep(i, 0, N){
        long long left = min(A[i], B[i]);
        ans += left;
        B[i] -= left;
        
        long long right = min(A[i+1], B[i]);
        ans += right;
        A[i + 1] -= right;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 1792
loop do
    n, m = gets.split(' ').map(&:to_i)

    break if n == 0 && m == 0

    a = gets.split(' ').map(&:to_i)

    ans = -1

    (0..n-2).each do |i|
        (i+1..n-1).each do |j|
            if a[i] + a[j] <= m
                ans = [a[i] + a[j], ans].max
            end
        end
    end
    puts ans == -1 ? 'NONE' : ans
end


Measured memory_bytes: 6968