akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>vector<T> vec(int len, T elem) { return vector<T>(len, elem); } // auto dp = vec(52, vec(103, vec(103, INF)));
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>inline int popcount(T a) {return __builtin_popcount(a);}
template<class T>inline T emod(T a, T p) { return (a%p + p) % p;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << '\n'; for (auto v : vec) os << v << ' '; os << '\n'; return os;}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
//-------------------
int main() {
    cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15);
    int d,t,s; cin >> d >> t >> s;
    if(t >= (d+(s-1))/s) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using ll = long long;

#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 ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

struct mint {
  ll x;
  mint(ll x=0) : x(x%mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x -= a.x) < 0) x += mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) {
    mint res(*this);
    return res*=a;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  mint pw = 1;
  rrep(i, n) pw *= i;
  std::cout << pw.x << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
int lucas(int X){
  if(X==0)
    return 2;
  else if(X==1)
    return 1;
  else{
    int A=2,B=1,ans;
    rep(i,1,X){
      ans=A+B;
      A=B;
      B=ans;
      }
    return ans;
    }
  }
signed main(){
  int N;
  cin>>N;
  cout<<lucas(N)<<endl;
  }


Measured memory_bytes: 256
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $s = <STDIN>);
$s =~ s/BC/D/g;
my ($p, $ans) = (0, 0);
my ($ac, $dc) = (0, 0);
my ($af, $ad) = (0, 0);
for my $i (0..length($s)-1) {
  my $c = substr($s, $i, 1);
  if ($c eq 'A') {
    if ($af == 0) {
      $af = 1;
    }
    $ac++;
  } elsif ($c eq 'D') {
    if ($af == 1) {
      $ans += $ac;
    }
  } else {
    $ac = 0;
    $af = 0;
  }
}
say $ans;

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

int main() {
    long long N, D;
    cin >> N >> D;
    long long dx[N], dy[N];
    int ans = 0;
    for (int i = 0; i < N; i++)cin >> dx[i] >> dy[i];
    for (int i = 0; i < N; i++)
    {
        if (dx[i] * dx[i] + dy[i] * dy[i] <= D * D) ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 6748
// Homework
#include <iostream>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int a[m];
    for(int i=0; i<m; i++){
        cin >> a[i];
    }
    int sum=0;
    for(int i=0; i<m; i++){
        sum+=a[i];
    }
    if(sum>n){
        cout << -1 << endl;
        return 0;
    }
    else{
        cout << n-sum << endl;
        return 0;
    }
}

Measured memory_bytes: 3712
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)

#define mp make_pair
#define P pair<int,int>
#define ll __int64
int a,b,c,d,p;
int main(){
	cin>>a>>b>>c>>d>>p;
	int use=p;
	if(p<=c)use=0;
	else use=p-c;
	cout<<min(a*p,b+use*d)<<endl;
	return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------

// snukeさんのmodint
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// mint N;
//cout << N.x << endl;



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

using pll = pair<ll,ll>;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    int zero = 0;
    map<pll,P> mp;
    for(int i=0; i<N; i++){
        ll x,y;
        cin >> x >> y;
        if(x == 0 and y == 0){
            zero++;
            continue;
        }
        ll g = gcd(x,y);
        x /= g;
        y /= g;
        if(y < 0){
            x *= -1;
            y *= -1;
        }
        if(y == 0 and x < 0){
            x *= -1;
        }
        bool rot90 = (x <= 0);
        if(rot90){
            swap(x,y);
            y *= -1;
        }
        if(rot90){
            mp[pll(x,y)].first++;
        }else{
            mp[pll(x,y)].second++;
        }
    }
    mint ans = 1;
    for(auto m: mp){
        ll s,t;
        tie(s,t) = m.second;
        mint now = 1;
        now += mint(2).pow(s) - 1;
        now += mint(2).pow(t) - 1;
        ans *= now;
    }
    ans -= 1;
    ans += zero;
    cout << ans.x << "\n";
    return 0;
}

Measured memory_bytes: 16112
#include<iostream>
#include<cmath>
using namespace std;
#define df 0
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  int q; cin >>q;
  for(int i=0;i<q;i++){
    li a,b; cin >>a >>b;
    if(a==b){
      printf("%d\n",2*(a-1));
      continue;
    }
    if(a>b)swap(a,b);
    li sq=sqrt(a*b);
    int d=(a*b-1)/sq;
    printf("%ld\n",sq+d-2);
  }
}

/// confirm df==0 ///


Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

ll calc(ll b, ll n) {
  if (n < b) return n;
  else return calc(b, n/b) + n%b;
}

int main(void) {
  ll n;
  ll s;
  scanf("%lld%lld", &n, &s);
  for(ll b = 2; b*b <= n; ++b) {
    ll v = calc(b, n);
    if(v == s) {
      printf("%lld\n", b);
      return 0;
    }
  }

  ll res = n*3;
  for(ll d = 1; d*d < n; ++d) {
    ll bg = n / d;
    ll ed = n / (d+1);
    ll m = n % bg + d;
    if (s-m >= 0 && (s-m)%d == 0) {
      ll x = bg - (s-m) / d;
      if(ed < x && x <= bg && x < res) {
        res = x;
      }
    }
  }
  if (calc(n+1, n) == s && n+1 < res) {
    res = n+1;
  }
  if (res == n*3) {
    res = -1;
  }
  printf("%lld\n", res);
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	int n, dis, end;
	ArrayList<ArrayList<Integer>> data;
	boolean []used;
	int [] ind;
	
	
	private int dfs(int pos, int deep){
		if(pos == n-1){
			dis = deep-1;
			for(int i = 0; i < n;i++){
				if(ind[i] == (deep / 2) + 1){
					end = i;
					break;
				}
			}
			return 0;
		}
		
		ArrayList<Integer> now = data.get(pos);
		int res = 0;
		for(int i = 0; i < now.size(); i++){
			int next = now.get(i);
			if(used[next]) continue;
			used[next] = true;
			ind[next] = deep+1;
			res += dfs(next, deep+1);
			ind[next] = -1;
			used[next] = false;
		}
		return res+1;
	}
	
	private int dfs2(int pos){
		if(pos == end){
			return 0;
		}
		
		ArrayList<Integer> now = data.get(pos);
		int res = 0;
		for(int i = 0; i < now.size(); i++){
			int next = now.get(i);
			if(used[next]) continue;
			used[next] = true;
			res += dfs2(next);
			used[next] = false;
		}
		return res+1;
	}
	

	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			n = sc.nextInt();
			data = new ArrayList<>();
			for(int i = 0; i < n; i++){
				data.add(new ArrayList<>());
			}
			
			
			for(int i = 0; i < n-1; i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				data.get(a).add(b);
				data.get(b).add(a);
				
			}
			dis = 0;
			used = new boolean[n];
			used[0] = true;
			ind = new int[n];
			end = 0;
			Arrays.fill(ind, -1);
			
			int res = dfs(0, 0);
			
			Arrays.fill(used, false);
			used[0] = true;
			int res2 = dfs2(0);
			
			int a = res2-1;
//			debug(res2, end);
			int b = n - 2 - a;
			if(a > b){
				System.out.println("Fennec");
			}
			else
			{
				System.out.println("Snuke");
			}
		}
	}
	
	


	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 115524
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

ll fac[200007],finv[200007],inv[200007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<200007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll le, ri;
    ll b[n+1];
    memset(b,-1,sizeof(b));
    ll a;
    for(int i=0;i<=n;i++){
    	cin >> a;
    	if(b[a] == -1) b[a] = i;
    	else{
    		le = b[a];
    		ri = i;
    	}
    }
    ri = n - ri;
    cominit();
    for(ll i=1;i<=n+1;i++){
    	ll ans = com(n+1, i);
    	ans -= com(le + ri , i - 1);
    	ans %= mod;
    	ans += mod;
    	ans %= mod;
    	cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

const int INF = 0x3fffffff;

int N;
vector<int> es[114514];
int X[114514];
int W[114514];

int dfs(int v) {
  int M = es[v].size();
  vector<int> dp[2];
  rep(i, 2) dp[i].resize(5001);

  int src = 0;
  int dst = 1;
  dp[src][0] = 0;

  int mins = 0;
  for (int u : es[v]) {
    int w = dfs(u);
    mins += min(w, X[u]);

    fill(all(dp[dst]), INF);
    rep(i, 5001) {
      if (i+w < 5001) dp[dst][i+w] = min(dp[dst][i+w], dp[src][i]+X[u]);
      if (i+X[u] < 5001) dp[dst][i+X[u]] = min(dp[dst][i+X[u]], dp[src][i]+w);
    }
    swap(src, dst);
  }

  if (v == 0) {
    if (mins > X[0]) {
      puts("IMPOSSIBLE");
      exit(0);
    } else return 0;
  }

  rep(i, 5001) {
    if (dp[src][i] <= X[v]) return i;
  }

  puts("IMPOSSIBLE");
  exit(0);
}

int main() {
  scanf("%d", &N);
  reps(i, 1, N) {
    int p;
    scanf("%d", &p);
    --p;
    es[p].eb(i);
  }

  rep(i, N) {
    scanf("%d", &X[i]);
  }

  dfs(0);
  puts("POSSIBLE");
}


Measured memory_bytes: 19796
n = map(int, input().split())
alist = list(map(int, input().split()))
m = max(alist)
sbn = 10**10
for a in alist:
    if abs(m/2 - a) < sbn and a != m:
        ans = a
        sbn = abs(m/2 - a)
print(m, ans)


Measured memory_bytes: 14060
#include<bits/stdc++.h>
using namespace std;
int x(int arr[],int dp[],int n,int k)
{
    dp[0]=0;
    for(int i=0;i<k;i++)
        dp[i]=abs(arr[0]-arr[i]);
    for(int i=k;i<n;i++)
    {
        //cout<<arr[i];
        int m=INT_MAX;
        for(int j=i-k;j<i;j++)
        m=min(m,dp[j]+abs(arr[j]-arr[i]));

        dp[i]=m;
        //cout<<dp[i]<<" ";
    }
    return dp[n-1];

}
int main()
{

    int t,k;
    cin>>t>>k;
    if(k>t)
        k=t;
    int arr[t];
    for(int i=0;i<t;i++)
    {
        cin>>arr[i];
    }
    int dp[t]={0};
    cout<<x(arr,dp,t,k);
}


Measured memory_bytes: 4412
n=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))

preva=-1
ans=0

for a in alist:
    idx=a-1
    ans+=blist[idx]
    if a==preva+1:
        ans+=clist[preva-1]
    preva=a

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
typedef long long ll;
int min(int, int);
int max(int, int);
int main()
{
	int A, B, K;
	scanf("%d%d%d", &A, &B, &K);
	for (int i = A; i <= min(B, A + K -1); i++) printf("%d\n", i);
	for (int i = max(B - K + 1, A + K); i <= B; i++) printf("%d\n", i);
	
	return 0;
}

int min(int a, int b) {
	if (a > b)
		return b;
	else
		return a;
}

int max(int a, int b) {
	if (a > b)
		return a;
	else
		return b;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad         (replicateM)
import qualified Data.ByteString.Char8 as BC
import           Data.Maybe            (fromJust)
import           GHC.Exts              (sortWith)

main :: IO ()
main = print =<< solve <$> getInput

getInput :: IO (Int, Int, [(Int, Int)])
getInput = do
  [n, h] <- readInts
  abs <- replicateM n readInt2
  return (n, h, abs)

readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

readInt2 = do
  [a, b] <- readInts
  return (a, b)

solve (n, h, abs) = nAttack + mAttack
  where maxA = maximum $ map fst abs
        (nAttack, restHP) = throwAttack maxA (map snd abs) h
        mAttack = swingAttack maxA restHP

throwAttack :: Int -> [Int] -> Int -> (Int, Int)
throwAttack a bs h = if null powerfulBs
  then (0, h)
  else (length throwns, h - last throwns)
  where powerfulBs = filter (> a) bs
        throwns = takeUntil (< h) . scanl1 (+) $ sortWith (* (-1)) powerfulBs

takeUntil :: (a -> Bool) -> [a] -> [a]
takeUntil _ []     = []
takeUntil p (x:xs) = x : if p x then takeUntil p xs else []

swingAttack a h
  | h <= 0   = 0
  | otherwise = h `div` a + if h `mod` a == 0 then 0 else 1
      --ceiling $ fromIntegral h / fromIntegral a


Measured memory_bytes: 45564
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N, M; cin >> N >> M;

    ll K; cin >> K;
    ll A[N], B[M]; F0R(i, N) cin >> A[i];
    F0R(i, M) cin >> B[i];

    ll as = 0; F0R(i, N) as += A[i];
    ll bs = 0;
    int bp = 0;
    int ans = 0;
    F0Rd(i, N+1) {
        if (i < N) as -= A[i];
        if (as <= K) {
            while (bp < M && as + bs + B[bp] <= K) {
                 bs += B[bp]; bp++;
            }
            ckmax(ans, i + bp);
        }
    }
    cout << ans << nl;
	
	return 0;
}

Measured memory_bytes: 6724
s = input()
t = input()
dic1 = {}
dic2 = {}
f = True
for i, j in zip(s, t):
    if i in dic1:
        if dic1[i] != j:
            f = False
            break
    dic1[i] = j
    if j in dic2:
        if dic2[j] != i:
            f = False
            break
    dic2[j] = i
if f:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long

using namespace std;

typedef pair<int, int> td;

int n, m;
vector <int> c[100010];
int dp[100010];

int dfs(int u){
    if (dp[u]) return dp[u];
    int res = 0;
    for (int i = 0; i < (int)c[u].size(); ++i)
        res = max(res, dfs(c[u][i]));
    return dp[u] = res+1;
}

int main(){
    #ifdef ZERBRA
        freopen("code.inp", "r", stdin);
        //freopen("code.out", "w", stdout);
    #endif // ONLINE_JUDGE
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i){
        int u, v;
        scanf("%d%d", &u, &v);
        c[u].pb(v);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans = max(ans, dfs(i));
    printf("%d", ans-1);
    return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	n %= 10;
	if(n == 3) cout << "bon" << endl;
	else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
	else cout << "hon" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    double l; cin >> l;
    double ans = pow(l/3,3);

    cout << fixed << setprecision(10) << ans << '\n';

    return 0;
}

Measured memory_bytes: 512
from sys import stdin

li = [int(stdin.readline().rstrip()) for _ in range(5)]
k = int(stdin.readline().rstrip())

from itertools import combinations
lin = list(combinations(li, 2))

for i in range(len(lin)):
    if abs(lin[i][0]-lin[i][1]) > k:
        print(":(")
        exit()

print("Yay!")

Measured memory_bytes: 3060
import heapq

def main():
    n, m = map(int, input().split())
    dics = [{} for _ in range(n)]
    for _ in range(m):
        l, r, c = map(int, input().split())
        ky = r-1
        if ky in dics[l-1]:
            if c < dics[l-1][ky]:
                dics[l-1][ky] = c
        else:
            dics[l-1][ky] = c
    dist = [float("inf")]*n
    dist[0] = 0
    hq = []
    heapq.heappush(hq, [0, 0])
    idx = 0
    while len(hq) > 0:
        v, p = heapq.heappop(hq)
        if p < idx:
            continue
        if p == n-1:
            break
        for i in range(idx+1, p):
            if len(dics[i]) > 0:
                for ky in dics[i].keys():
                    if ky in dics[p]:
                        if dics[p][ky] > dics[i][ky]:
                            dics[p][ky] = dics[i][ky]
                    else:
                        if p < ky:
                            dics[p][ky] = dics[i][ky]
        idx = p
        for r in dics[p].keys():
            if dist[r] > v + dics[p][r]:
                dist[r] = v + dics[p][r]
                heapq.heappush(hq, [v + dics[p][r], r])
    if dist[n-1] == float("inf"):
        print(-1)
    else:
        print(dist[n-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 43940
#include <iostream>

using namespace std;

bool ans[4];
int main() {
  int a,b;
  cin >> a >> b;

  ans[a] = ans[b] = true;
  for(int i = 1; i <= 3; i++) {
    if(!ans[i]) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int32_t main()
{	
	int k;
	cin >> k;
	string s;
	cin >> s;
	if(s.size()<=k)
	{
		cout << s;
	}
	else
	{
		for(int i=0;i<k;i++)
		cout << s[i];
		cout << "...";
	}
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n,m;
    cin >> n >> m;
    if((n+m)%2 == 1)cout << "IMPOSSIBLE" << endl;
    else cout << (n+m)/2 << endl;
    

    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc135.contest.atcoder.jp/tasks/abc135_a

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

int main()
{
    std::string a, b;
    std::cin >> a >> b;

    if (a.length() > b.length()) {
        std::cout << "GREATER" << std::endl;
        return 0;
    } else if (a.length() < b.length()) {
        std::cout << "LESS" << std::endl;
        return 0;
    }

    for (int i = 0; i < a.length(); i++) {
        if (a[i] > b[i]) {
            std::cout << "GREATER" << std::endl;
            return 0;
        } else if (a[i] < b[i]) {
            std::cout << "LESS" << std::endl;
            return 0;
        }
    }

    std::cout << "EQUAL" << std::endl;
}


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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

void rec(vector<vector<int>> &b, int k, vector<vector<vector<int>>> &res){
	int n = b.size();
	int mx = 0;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++) mx=max(mx, b[i][j]);
	}
	int si=0, sj=0;
	if(mx>0){
		bool done = false;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(b[i][j]==mx){
					si = i;
					sj = j;
					done=true;
					break;
				}
			}
			if(done) break;
		}
	}

	int x = -1;
	bool ok = true;
	for(int i=0; i<n; i++){
		set<int> a;
		for(int j=0; j<n; j++){
			if(b[i][j]>0) a.insert(b[i][j]);
		}
		if(x<0) x = a.size();
		if(a.size()>k) return;
		if(x!=a.size()){
			if(i<si) return;
			ok = false;
		}
	}
	for(int i=0; i<n; i++){
		set<int> a;
		for(int j=0; j<n; j++){
			if(b[j][i]>0) a.insert(b[j][i]);
		}
		if(a.size()>k) return;
		if(x!=a.size()) ok = false;
	}
	if(ok && x==k){
		res.push_back(b);
		return;
	}

	for(int i=si; i<n; i++){
		for(int j=(i==si?sj:0); j<n; j++){
			if(i+1<n&&b[i][j]==0&&b[i+1][j]==0){
				b[i][j] = b[i+1][j] = mx+1;
				rec(b, k, res);
				if(res.size()) return;
				b[i][j] = b[i+1][j] = 0;
			}
			if(j+1<n&&b[i][j]==0&&b[i][j+1]==0){
				b[i][j] = b[i][j+1] = mx+1;
				rec(b, k, res);
				if(res.size()) return;
				b[i][j] = b[i][j+1] = 0;
			}
		}
	}
}

vector<vector<vector<int>>> naive(int n, int k){
	vector<vector<vector<int>>> ret;
	vector<vector<int>> b(n, vector<int>(n));
	rec(b, k, ret);
	return ret;
}

string x3[3] = {
	"aab",
	"c.b",
	"cdd",
};

string x4[4] = {
	"aabc",
	"ddbc",
	"efgg",
	"efhh",
};

string x5[5] = {
	"..abc",
	"..abc",
	"ddeef",
	"ggh.f",
	"iihjj",
};

string x6[6] = {
	"abc...",
	"abc...",
	"d.eeff",
	"dghh..",
	".g.ijj",
	"kk.ill",
};

string x7[7] = {
	"abc....",
	"abc....",
	"def....",
	"def....",
	"g..hhii",
	"g..jjkk",
	".llmmnn",
};


int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;

	int n; cin >> n;

	if(n<=2){
		cout << -1 << endl;
		return 0;
	}

	if(n==3){
		for(int i=0; i<3; i++) cout << x3[i] << endl;
		return 0;
	}

	int k = n%4+4;
	int l = n/4-1;
	for(int i=0; i<l; i++){
		for(int j=0; j<4; j++){
			cout << string(i*4, '.') << x4[j] << string(n-4*(i+1), '.') << endl;
		}
	}
	if(k==4){
		for(int j=0; j<4; j++){
			cout << string(n-4, '.') << x4[j] << endl;
		}
	} else if(k==5){
		for(int j=0; j<5; j++){
			cout << string(n-5, '.') << x5[j] << endl;
		}
	} else if(k==6){
		for(int j=0; j<6; j++){
			cout << string(n-6, '.') << x6[j] << endl;
		}
	} else if(k==7){
		for(int j=0; j<7; j++){
			cout << string(n-7, '.') << x7[j] << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.ArrayDeque;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[][] visit=new int[n][3];
		ArrayList<Integer>[] map=new ArrayList[n];
		for(int i=0; i<n; i++){
			map[i]=new ArrayList<>();
			Arrays.fill(visit[i],Integer.MAX_VALUE);
		}
		for(int i=0; i<m; i++){
			int u=sc.nextInt()-1;
			int v =sc.nextInt()-1;
			map[u].add(v);
		}
		int s =sc.nextInt()-1;
		int t =sc.nextInt()-1;
		ArrayDeque<Integer>  que=new ArrayDeque<>();
		que.add(s);
		int count1=0;
		int count2=0;
		int count3=0;
		while(!que.isEmpty()){
			int j=que.poll();
			if(visit[j][count1%3]>count1){
				visit[j][count1%3]=count1;
				for(int i:map[j]){
					count3++;
					que.add(i);
				}
			}
			if(count2==0){
				count2=count3-1;
				count3=0;
				count1++;
			}else{
				count2--;
			}
		}
		if(visit[t][0]!=Integer.MAX_VALUE){
			System.out.println(visit[t][0]/3);
		}else{
			System.out.println(-1);
		}
	}
}




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

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

#define vint(v, n) vector<int> v(n); REP(i,n) cin >> v[i];

int main(void){

  cin.tie(0);
  ios::sync_with_stdio(false);

  double A, B;
  cin >> A >> B;
  if(A > B) cout << "GREATER\n";
  else if(A < B) cout << "LESS\n";
  else cout << "EQUAL\n";
  return 0;
  

  return 0;

}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  int x, y;
  cin >> x >> y;
  --x, --y;
  string s, t;
  cin >> s >> t;
  int left = y;
  int right = y;
  int up = x;
  int down = x;
  for (int i = 0; i < k; i++) {
    if (s[i] == 'R') ++right;
    if (s[i] == 'D') ++down;
    if (s[i] == 'U') --up;
    if (s[i] == 'L') --left;
    if (right == m || left < 0 || down == n || up < 0) {
      cout << "NO" << '\n';
      return 0;
    }
    if (t[i] == 'R' && left + 1 < m) ++left;
    if (t[i] == 'D' && up + 1 < n)   ++up;
    if (t[i] == 'U' && down > 0)     --down;
    if (t[i] == 'L' && right > 0)    --right;
  }
  cout << "YES" << '\n';
  return 0;
}


Measured memory_bytes: 4000
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;

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

    int N;
    cin >> N;
    vector<pair<pair<string, int>, int>> p(N);
    for (int i = 0; i < N; i++)
    {
        cin >> p[i].first.first >> p[i].first.second;
        p[i].second = i + 1;
        p[i].first.second *= -1;
    }
    sort(p.begin(), p.end());

    for (int i = 0; i < N; i++)
    {
        cout << p[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll a[1010];
ll x;
int n=205;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>x;
	for(ll i=0;i<n;i++)a[i]=i*i*i*i*i;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]+a[j]==x){
				cout<<i<<' '<<-j;
				return 0;
			}
			if(a[j]-a[i]==x){
				cout<<j<<' '<<i;
				return 0;
			}
		}
	}
	return 0;
}


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

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

    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (p[j] < p[i]) swap(p[i], p[j]);
        }
    }
    int result = 0;
    for (int i = 0; i < n-1; i++) result += p[i];
    result += p[n-1] / 2;
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let s = get_input();
    let u:i64 = s[0..2].parse().unwrap();
    let d:i64 = s[2..].parse().unwrap();

    let x = 1 <= d && d <= 12;
    let y = 1 <= u && u <= 12;

    let ans = if x && y {
        "AMBIGUOUS"
    } else if x {
        "YYMM"
    } else if y {
        "MMYY"
    } else {
        "NA"
    };

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

Measured memory_bytes: 4476
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(void) {
    double a, b, c;
    double C;
    double S, L, h;
    double pi = acos(-1);
    
    cin >> a >> b >> C;
    C = pi * C / 180;
    S= a * b * sin(C) / 2;
    c = sqrt(a*a + b*b - 2*a*b*cos(C));
    L = a + b + c;
    h = S * 2 / a;
    
    printf("%lf\n", S);
    printf("%lf\n", L);
    printf("%lf\n", h);
    
    return 0;
}


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

using namespace std;
 
int main()
{
    int N;
    cin >> N;
    vector<int> A;
    vector<int> B;
    vector<int> C;
    for (int i=0; i<N; i++) {
        int temp;
        cin >> temp;
        A.push_back(temp);
    }
    for (int i=0; i<N; i++) {
        int temp;
        cin >> temp;
        B.push_back(temp);
    }
    for (int i=0; i<N-1; i++) {
        int temp;
        cin >> temp;
        C.push_back(temp);
    }
    int result = 0;
    for (int i=0; i<N; i++) {
        result += B[A[i]-1];
        if (i != 0 && A[i-1]+1 == A[i]) {
            result += C[A[i-1]-1];
        }
        // cout << i << " " << A[i] << " " << B[A[i]] << " " << result << endl;
    }
    cout << result;

    return 0;
}


Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

vector<bool> sieve(){
    vector<bool> primes(150000,true);
    primes[0] = primes[1] = false;
    for(int i=2;i<150000;i++){
        if(primes[i])
        {
            for(int j=2;i*j<150000;j++){
                if(primes[i*j]) 
                    primes[i*j] = false;
            }
        }
    }

    return primes;
}
int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    vector<bool> p = sieve();
    int x;
    cin>>x;
    for(int i=x;i<150000;i++){
        if(p[i]){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}



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

int main() {
	int N, X;
	vector<int> element;
	cin >> N >> X;
	int min_element = 1000;
	int num_donut = 0;
	for (int i = 0; i < N; i++) {
		int element_tmp;
		cin >> element_tmp;
		X -= element_tmp;
		num_donut++;
		if (element_tmp < min_element) min_element = element_tmp;
	}
	while (X > 0) {
		X -= min_element;
		if (X < 0)break;
		num_donut++;
	}
	cout << num_donut;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    ll ans = INF;
    int n;
    cin >> n;
    vector<ll> sum(n,0);
    rep(i,n){
        ll x;
        cin >> x;
        if( i == 0 ) sum[i] = x;
        else sum[i] = sum[i-1] + x;
    }
    rep(i,n-1){
        ans = min(ans, abs( sum[n-1] -2 * sum[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4840
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        var k = cin.nextInt();
        var s = cin.nextInt();

        int ans = 0;
        for(int x = 0;x<=k;x++)
        {
            for(int y = 0;y<=k;y++)
            {
                int z = s - x - y;
                if (z >= 0 && z <= k) ans++;
            }
        }
        Console.WriteLine(ans);
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 2776
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<typename T>
T gcd(T a, T b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

template<typename T>
T lcm(T a, T b){
  return a * b / gcd(a, b);
}
int main(){
    int N;
    cin >> N;
    vector<ull> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    ull ans = 0;
    for(ull a : A) ans+= a - 1;
    cout << ans << endl;
}

Measured memory_bytes: 3648
h_list = list(map(int,input()))

score_z = 0
score_o = 0

# 0101で並び替える
counter = 0
for n in h_list:
    # 偶数更新
    if counter%2 == 0:
        if 0 != n:
            score_z += 1
    if counter%2 == 1:
        if 1 != n:
            score_z += 1
    counter+=1

# 1010で並び替える
counter = 0
for n in h_list:
    if counter%2 == 1:
        if 0 != n:
            score_o += 1
    if counter%2 == 0:
        if 1 != n:
            score_o += 1
    counter+=1


print(min(score_z,score_o))


Measured memory_bytes: 3956
import heapq

n, m = list(map(int, input().split()))
a = list(map(lambda x: -float(x), input().split()))

heapq.heapify(a)
for t in range(m):
  discount = heapq.heappop(a) / 2.
  heapq.heappush(a, discount)
    
print(sum(map(lambda x: int(-x), a)))

Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

bool check(ll x, ll y) {
    if (x >= (inf_l/y)+1) return false;
    else return true;
}

int main() {
    int n; cin >> n;
    vll a(n);
    rep(i,n) {
        ll x; cin >> x;
        a[i] = x;
        if (x == 0) {cout << 0 << endl; return 0;}
    }
    ll sum = a[0];
    REP(i,n) {
        if (!check(sum,a[i])) {cout << -1 << endl; return 0;}
        else sum *= a[i];
    }
    cout << sum << endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T){
    T.pop_back();
    if (S == T) cout << YES << endl;
    else cout << NO << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int A,B;
    cin >> A >> B;
    int cnt=0;
    while(true){
        if(1+(A-1)*cnt>=B)break;
        else cnt++;
    }
    cout << cnt;

}

/*



 */



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

inline int Abs(int x) {
    return (x < 0) ? (-x) : (x);
}

int n;

int main() {
    scanf("%d", &n);
    int lt = 0, lx = 0, ly = 0;
    for (int i = 1; i <= n; ++i) {
	int t, x, y;
	scanf("%d%d%d", &t, &x, &y);
	int d = Abs(x - lx) + Abs(y - ly);
	if (d > t - lt || ((t - lt - d) & 1)) {
	    puts("No");
	    return 0;
	} 
	lt = t;
	lx = x;
	ly = y;
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int memo[2010][2];
int a[2003];
int N;
int solve(int id,int turn,int x,int y){
  if(id == N) return abs(x - y);
  if(0 <= memo[id][turn]) return memo[id][turn];
  if(turn == 0){
    int ma = -1;
    for(int i=id;i<N;i++) ma = max(ma,solve(i+1,1-turn,a[i],y));
    return memo[id][turn] = ma;
  }else{
    int mi = INF;
    for(int i=id;i<N;i++) mi = min(mi,solve(i+1,1-turn,x,a[i]));
    return memo[id][turn] = mi;
  }

}

int main()
{
  int Z,W;
  scanf("%d %d %d",&N,&Z,&W);
  REP(i,N)
    scanf("%d",&a[i]);
  REP(i,N+1)
    REP(j,2)memo[i][j] = -1;
  printf("%d\n",solve(0,0,Z,W));
  return 0;
}


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;


int main() {
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    printf("%d %d %d\n", x, y, z);
}


Measured memory_bytes: 768
n = int(input())
h = int(input())
arr = list(range(1, n + 1))
for _ in range(h):
    a, b = map(int, input().split(','))
    arr[a - 1], arr[b - 1] = arr[b - 1], arr[a - 1]
for ai in arr:
    print(ai)



Measured memory_bytes: 5596