akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 100010
int par[N],rnk[N];
struct UF {
	
	void init(int n){
		for(int i = 0; i < n; i++){
			par[i] = i;
			rnk[i] = 0;
		}
	}
	
	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}
	
	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		
		if(rnk[x] < rnk[y]){
			par[x] = y;
		}else{
			par[y] = par[x];
			if(rnk[x] == rnk[y]) rnk[y]++;
		}
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}
};

vector<int> g[N];
int d[N], odd[N];
int t[N];

bool dfs(int u, int x){
	t[u] = x;
	for(int &v: g[u]){
		if(!t[v] && dfs(v, x+1)) return true;
		else if((t[v]+x+1)%2) return true;
	}
	return false;
}

int main(){
	ll n, m;
	cin>>n>>m;
	UF uf;
	uf.init(n);
	rep(i, m){
		int u, v;
		cin>>u>>v;
		u--; v--;
		uf.unite(u, v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	rep(i, n){
		int x = uf.find(i);
		d[x]++;
		if(x!=i) continue;
		if(dfs(i, 1)) odd[i] = 1;
	}
	ll vvv = 0, vv = 0, v = 0;
	rep(i, n){
		if(d[i]==1) v++;
		else if(d[i]){
			if(odd[i]) vvv++;
			else vv++;
		}
	}
	cerr<<vvv<<" "<<vv<<" "<<v<<endl;
	ll res = + vv*vv + (vvv+vv)*(vvv+vv) + 2*v*n-v*v;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 8448
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int s[110000];
bool flag[110000] = {};

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> s[i];
    }
    long long int ans = 0;
    for(int i = 1; i < N; i++){
        long long int S = 0;
        vector<int> v;
        for(int j = 1; i * j < N - 1; j++){
            int pos1 = i * j;
            int pos2 = N - 1 - i * j;
            if(pos1 + i >= N){
                break;
            }
            if(flag[pos1] || flag[pos2] || pos1 == pos2){
                break;
            }
            flag[pos1] = true;
            flag[pos2] = true;
            v.push_back(pos1);
            v.push_back(pos2);
            S += s[pos1] + s[pos2];
            ans = max(ans, S);
            /*
            cout << i << " " << j << endl;
            cout << pos1 << " " << pos2 << endl;
            */
        }
        for(int num : v){
            flag[num] = false;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int count = 0;
  for (auto i = 0; i <= a && 500 * i <= x; i++)
    for (auto j = 0; j <= b && 500 * i + 100 * j <= x; j++)
      if ((x - 500 * i - 100 * j) / 50 <= c) count++;
  cout << count << endl;
}


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

using namespace std;

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

const long long INF = 1LL << 60;

int N;
long long a[3030];
int visit[3030][3030];
long long memo[3030][3030];

long long dp(int L, int R) {
  if (L > R) return 0;
  if (visit[L][R]) return memo[L][R];
  visit[L][R] = 1;

  int diff = N - (R - L + 1);

  long long res = 0;
  if (diff % 2 == 0) {
    // X-Yを最大化
    res = -INF;
    chmax(res, dp(L + 1, R) + a[L]);
    chmax(res, dp(L, R - 1) + a[R]);
  } else {
    // X-Yを最小化
    res = INF;
    chmin(res, dp(L + 1, R) - a[L]);
    chmin(res, dp(L, R - 1) - a[R]);
  }

  return memo[L][R] = res;
}

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

  cout << dp(0, N - 1) << endl;

  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  string S,T;
  cin>>S>>T;
  cout<<T<<S<<endl;
  return 0;
}


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

int main(){
int S,h,m,s;
scanf("%d",&S);
s=S%60;
m=(S-s)/60%60;
h=(S-m*60-s)/3600;
printf("%d:%d:%d\n",h,m,s);
}

Measured memory_bytes: 1184
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
// long long -> lint
using lint = long long;
// fast cin and cout from hitonanode-san's code
// w/o 71 ms -> w/ 18 ms (tested on ABC148-D with C++14(GCC 5.4.1))
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

int main(){
    // input
    string S, T;
    cin >> S >> T;

    // out
    for( int i=0; i<T.length(); i++ ) cout << T[i];
    for( int i=0; i<S.length(); i++ ) cout << S[i];
    cout << endl;
} 

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

vector<pair<char, int> > run_length_factorization(string s){
    vector<pair<char, int> > res;
    s += '$';
    char c = s[0];
    int now = 1;
    for(int i = 1; i < s.size(); i++){
        if(s[i] != c){
            res.push_back(pair<char, int>(c, now));
            c = s[i]; now = 1;
        }else now++;
    }
    return res;
}

struct CumulativeSum{
    vector<int> data;
    CumulativeSum(int sz) : data(sz, 0) {};
    void add(int k, int x){
        data[k] += x;
    }
    void build(){
        for(int i = 1; i < data.size(); i++){
            data[i] += data[i - 1];
        }
    }
    int query(int k){
        if(k < 0) return 0;
        return (data[min(k, (int)data.size() - 1)]);
    }
    int query(int l, int r){
        return query(r - 1) - query(l - 1);
    }
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<P> a = run_length_factorization(s);
    int l = 0, r = 0, now = 0, sum = 0;
    n = a.size();
    CumulativeSum cs(n);
    rep(i, 0, n){
        cs.add(i, a[i].second);
    }
    cs.build();
    int ans = 0;
    rep(i, 0, n){
        int len = 2 * k + 1;
        if(a[i].first == '0') len--;
        int tmp = cs.query(i, i + len);
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2752
n,m = map(int, input().split())
s=[]
for i in range(m):
  s.append(list(map(int, input().split())))

for i in range(1000):
  if len(str(i)) != n:
    continue
  for si in s:
    if len(str(i)) < si[0]:
      break
    if str(i)[si[0]-1] != str(si[1]):
      break
  else:
    print(i)
    break
else:
  print(-1)
  

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

typedef long long ll;
#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll r, x2000, D;

    cin >> r >> D >> x2000;
    ll x = x2000;
    REP(i, 10){
        x = r * x - D;
        cout << x << endl;
    }

}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int q_lower,bud,c_aizu,c_normal,q_aizuupper;
	while(cin>>q_lower>>bud>>c_aizu>>c_normal>>q_aizuupper){
		if(q_aizuupper==0){
			cout<<"NA"<<endl;
			continue;
		}

		int q_aizu=0,q_normal=0;
		q_aizu+=q_aizuupper;
		bud-=q_aizu*c_aizu;
		if(bud<0){
			while(bud<0){
				q_aizu--;
				bud+=c_aizu;
			}
			if(q_aizu<=0){
				cout<<"NA"<<endl;
				continue;
			}
		}
		q_normal+=bud/c_normal;
		bud-=q_normal*c_normal;

		while(q_aizu+q_normal<q_lower && q_aizu>0){
			q_aizu--;
			bud+=c_aizu;
			q_normal+=bud/c_normal;
			bud-=(bud/c_normal)*c_normal;
		}
		if(q_aizu<=0){
			cout<<"NA"<<endl;
			continue;
		}
		if(q_aizu+q_normal>=q_lower)	cout<<q_aizu<<' '<<q_normal<<endl;
		else	cout<<"NA"<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
n, m, x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

mas = Array.new(n + 1, 0)
a.each do |v|
  mas[v] = 1
end

l = mas.slice(0..x)
r = mas.slice(x..(mas.size - 1))

suml = l.inject(0) {|sum, i| sum += i}
sumr = r.inject(0) {|sum, i| sum += i}

puts suml > sumr ? sumr : suml

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <iomanip>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VB;
 
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
 
const LD eps=1e-10;
const long long INFLL=(LL)(1e9)*(LL)(1e9);
const int INF=1e9;
 
template<class T>
void chmin(T& a, const T b)
{
	if(a>b)
		a=b;
}
template<class T>
void chmax(T& a, const T b)
{
	if(a<b)
		a=b;
}
 
const LL pow(const LL p, const LL q)
{
	LL t=1;
	for(int i=0;i<q;i++)
		t*=p;
	return t;
}

template <typename T>
struct has_iter
{
	private:
		template <typename U>
		static constexpr true_type check(typename U::iterator*);
		template <typename U>
		static constexpr false_type check(...);

	public:
		static constexpr bool value = decltype(check<T>(nullptr))::value;
};


template<typename T, typename U = typename T::iterator>
void print(const T& container)
{
		auto&& first=begin(container), last=end(container);
		auto&& back=prev(last);
		for(auto e=first; e!=last; e=next(e))
			cout<<*e<<" \n"[e==back];
}


extern void* enabler;
template<typename Head, typename enable_if<!has_iter<Head>::value>::type*& = enabler>
void print(const Head& head)
{
	cout<<head<<endl;
}

template<> void print<string>(const string& container)
{
	cout<<container<<endl;
}

template<typename Head, typename... Tail>
void print(const Head& head, const Tail&... tail)
{
	cout<<head<<" ";
	print(tail...);
}

void io_speedup()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec)
{
	for(T& x: vec) is >> x;
	return is;
}

template<typename T>
vector<T> read(int n)
{
	vector<T> t(n);
	cin>>t;
	return t;
}

template<typename T>
T read()
{
	T t;
	cin>>t;
	return t;
}



int main()
{
	int q;
	cin>>q;
	REP(tt,q)
	{
		LL a,b;
		cin>>a>>b;
		if(a>b) swap(a,b);
		if(a==b&&a==1)
		{
			print(0);
			continue;
		}
		LL s=a*b;
		s--;
		LL sq=(LL)(sqrt<LD>(s).real()+eps);
		while((sq+1)*(sq+1)<s) sq++;
		LL ans=sq*2;
		if(a==b)
		{
			if(s/sq==a)
			{
				ans=sq*2-2;
				print(ans);
				continue;
			}
		}
		if(s/sq==sq) ans--;
		if(a<=sq) ans--;
		//print(s,sq,ans);


		print(ans);
	}

}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve(a):
	s = 0
	for _ in xrange(1, 11):
		s += a
		if _ % 2 == 1:
			a = a * 2.0
		else:
			a = a / 3.0
	print s

	
while True:
	try :
		a = float(raw_input())
		solve(a)
	except:
		break

Measured memory_bytes: 4224
n=int(input())
a=list(map(int,input().split()))
cnt=0
if 1 not in a:
    print(-1)
    exit()
else:
    num=1
    for i in range(n):
        if a[i]==num:
            num+=1
        else:
            cnt+=1
if cnt==n:
    print(-1)
else:
    print(cnt)

Measured memory_bytes: 32376
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int		main(void)
{
	string S;
	cin >> S;

	int ans = 0;
	for (int i = 0; i < 3; i++)
	{
		if (S[i] == 'R')
			ans++;
	}
	if (S == "RSR")
		ans--;
	cout << ans << endl;
}



Measured memory_bytes: 3496
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int x; cin >> x;
  int ans = x / 500 * 1000;
  x %= 500;
  ans += x / 5 * 5;
  cout << ans << endl;

  return 0;
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c - max({ a,b,c }) == max({a,b,c}))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//
//
//using namespace __gnu_pbds;
using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

//#define mx                     200005
#define INF_mx                 1e18
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)
/*
tree<
       int,
     null_type,
     less<int>,
     rb_tree_tag,
     tree_order_statistics_node_update>t;
*/

int main()
{
  int n;
  cin>>n;
  ll ans=0;
  for(int i=1; i<=n; i++){
     if(i%3 && i%5){
        ans+=i;
    }
  }
  cout<<ans<<endl;
    return 0;
}
/*
1
21 7
wudixiaoxingxingheclp
*/


Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e5 + 17;

struct fenwick
{
	int n;
	vector<int> F;
	fenwick() { }
	fenwick(int n) : n(n) { F.resize(3 * n); }

	void upd(int i, int x)
	{
		i += n;

		for (; i < 3 * n; i |= i + 1)
			F[i] += x;
	}

	int get(int r)
	{
		int res = 0;

		for (r += n; r >= 0; r &= r + 1, --r)
			res += F[r];

		return res;
	}
};

int n, q;
int a[maxn], cnt[maxn];

bool read()
{
	if (scanf("%d", &n) != 1)
		return false;

	scanf("%d", &q);

	forn (i, n)
		scanf("%d", a + i + 1);

	return true;
}

int change(int i, int x, fenwick& F)
{
	int res = 0;
	int y = a[i];
	F.upd(y - cnt[y] + 1, -1);
	res += (y - cnt[y] >= 0 && F.get(y - cnt[y] + 1) == 0);
	--cnt[y];
	F.upd(y - cnt[y] + 1, 1);
	F.upd(x - cnt[x] + 1, -1);
	++cnt[x];
	res -= (x - cnt[x] >= 0 && F.get(x - cnt[x] + 1) == 0);
	F.upd(x - cnt[x] + 1, 1);
	a[i] = x;
	return res;
}

void solve()
{
	fenwick F(n);

	for (int i = 1; i <= n; ++i)
		++cnt[a[i]];

	for (int i = 1; i <= n; ++i)
	{
		F.upd(i - cnt[i] + 1, 1);
		F.upd(i + 1, -1);
	}

	int ans = 0;

	for (int i = 1; i <= n; ++i)
		if (F.get(i) == 0)
			++ans;

	forn (pp, q)
	{
		int j, x;
		scanf("%d %d", &j, &x);
		ans += change(j, x, F);
		printf("%d\n", ans);
	}
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 5376
splitBy :: Char -> String -> [String]
splitBy _ [] = []
splitBy a x =
  let s = takeWhile (/= a) x
      x'= dropWhile (/= a) x
  in
    if x' == []
    then [s]
    else s:(splitBy a $ drop 1 x')

metric :: [Int] -> [Int] -> [Int]
metric _ [] = []
metric (m0:m1:ms) (x:xs) = (x + max m0 m1):(metric (m1:ms) xs)

ans' m [] = m
ans' m (x:xs) =
  let lm = length m
      lx = length x
      m' = if lm < lx
           then metric ((0:m)++[0]) x
           else metric m x
  in
    ans' m' xs

ans (x:xs) = head $ ans' x xs

main = do
  c <- getContents
  let i = map (map read) $ map (splitBy ',') $ lines c :: [[Int]]
      o = ans i
  print o
  

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    
    for(int i = 0; i < s.size(); i++)
    {
        cout << s[i];
        if(i == 3)
			cout << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	int ans=0;
	vi v(n);
	rep(i,0,n) cin>>v[i];
	rep(i,0,n-2){
		int a,b,c;
		a=v[i]; b=v[i+1]; c=v[i+2];
		bool ok=0;
		if(a<b && b<c)ok=1;
		if(c<b && b<a)ok=1;
	//	cout<<a<<b<<c<<" ";
		if(ok){
			ans++;
			//cout<<v[i+1]<<endl;
		}
		//else cout<<":("<<v[i+1]<<endl;
	}
	cout<<ans<<endl;
	
	return 0;
}

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

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b)
    {
        swap(a,b);
    }
    if (c >= a && c <= b)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N,C=map(int,input().split())
xv=[[0,0] for _ in range(N)]

for i in range(N):
    xv[i][0],xv[i][1]=map(int,input().split())
    
xv.sort()

S=[0]*(N+1)
ans=0
r=[0]*N#止まる場所候補，時計回り
l=[0]*N#反時計

ma=0
ma_i=0
for i in range(N):
    S[i+1]=S[i]+xv[i][1]
    a=S[i+1]-xv[i][0]
    if a>ma:
        ma=a
        ma_i=i
    r[i]=ma_i
        
        
ma=0
ma_i=N-1      
for i in range(N):
    a=(S[-1]-S[N-i-1])-(C-xv[N-i-1][0])
    if a>ma:
        ma=a
        ma_i=N-i-1
    l[N-i-1]=ma_i
    
    
for i in range(N):#時計回りにiまで．
    temp1=S[i+1]-xv[i][0]#行ったきり
    temp2=temp1-xv[i][0]#逆回りも
    if i!=N-1:
        temp2+=(S[-1]-S[l[i+1]]) - (C-xv[l[i+1]][0])
    ans=max(ans,temp1,temp2)
      

for i in range(N):
    temp1=(S[-1]-S[i])-(C-xv[i][0])#行ったきり
    temp2=temp1-(C-xv[i][0])#逆回りも
    if i!=0:
        temp2+=S[r[i-1]+1] -xv[r[i-1]][0]
    ans=max(ans,temp1,temp2)
    
    
print(ans)
    

Measured memory_bytes: 55216
while true
  pts = []
 
  while true
    line = gets
    exit if line.nil?
 
    p0, p1 = line.chomp.split(" ").map{|s| s.to_i}
    break if p0 == 0 && p1 == 0
 
    p0 -= 1
    p1 -= 1
 
    pts[p0] = pts[p0].nil? ? 1 : (pts[p0] + 1)
    pts[p1] = pts[p1].nil? ? 1 : (pts[p1] + 1)
  end
  #p pts
 
  ok = true
 
  if pts[0] % 2 == 0 || pts[1] % 2 == 0
    ok = false
  else
    for i in (2...pts.length)
      if pts[i] % 2 != 0
        ok = false
        break
      end
    end
  end
 
  puts ok ? "OK" : "NG"
end

Measured memory_bytes: 8768
#include <iostream>
using namespace std;
const long long INF = 1e18;

int main() {
    int n;
    cin >> n;
    bool is_z = false;
    bool is_r = false;
    long long a = 1;
    for (int i=0; i<n; ++i) {
        if (is_z) continue;
        long long num; cin >> num;
        if (num == 0) is_z = true;
        if (is_r) continue;
        if ((a * num) > INF || num > (INF / a)) is_r = true;
        a *= num;
    }
    if (is_z) cout << 0 << endl;
    else if (is_r) cout << -1 << endl;
    else cout << a << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include<algorithm>
#include <cmath>
#include<vector>
using namespace std;

int main() {
	int n,tt,i,c,t,ansc=1001;
	cin >> n >> tt;
	for (i = 0; i < n; i++) {
		cin >> c >> t;
		if (t <= tt) {
			ansc = min(ansc, c);
		}
	}
	if (ansc == 1001)cout << "TLE";
	else cout << ansc;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    int N,Q;
    cin >> N >> Q; // 配列サイズ
    string S;
    cin >> S;
    vector<int> a(N, 0);
    char pre,now;
    rep0(i, N-1){
        now = S[i];
        if(i != 0){
            if(now == 'C' & pre == 'A') a[i] = 1;
        }
        pre = now;
    }

    // 累積和
    vector<int> s(N+1, 0); // s[0] = 0 になる
    rep0(i, N-1) s[i+1] = s[i] + a[i];
    rep1(i,Q){
        ll l,r;
        cin >> l >> r;
        cout << s[r] - s[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 3940
S = input()
len_S = len(S)
diff_A ,diff_B = 0, 0
for i in range(len_S):
    if i % 2 == 0:
        if S[i] == "0":
            diff_A +=1
        else:
            diff_B += 1
    else:
        if S[i] == "0":
            diff_B +=1
        else:
            diff_A += 1
print(min(diff_A, diff_B))

Measured memory_bytes: 3188
import sys
def sieve (n):
	ms_sieve = [0,0,0,0,0,0]
	ms_sieve += [1 for i in range(n-5)]
	ms_prime = []
	d = 6
	while d <= n:
		if ms_sieve[d] == 0:
			d += 1
			continue
		if d % 7 != 1 and d % 7 != 6:
			ms_sieve[d] = 0
			d += 1
			continue
		ms_prime.append(d)
		prod = 2
		while d * prod <= n:
			ms_sieve[d*prod] = 0
			prod += 1
		d += 1
	return ms_prime
ms_prime = sieve(300000)
while 1:
	n = int(raw_input())
	if n == 1:
		break
	sys.stdout.write("%d:" % n)
	for msp in ms_prime:
		if msp > n:
			break
		quot, rem = divmod(n,msp)
		if rem != 0:
			continue 
		rem2 = quot % 7
		if rem2 == 1 or rem2 == 6: 
			sys.stdout.write(" %d" % msp)
	print ""

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

int main()
{
	long d,n;
	cin >> d >> n;
	if (d == 0)
	{
		if (n != 100)
			cout << n << endl;
		else
			cout << n + 1 << endl;
	}
	if (d == 1 && n != 100)
		cout << n * 100 << endl;
	if (d == 2 && n!= 100)
		cout << n * 10000 << endl;
	if (d == 1 && n == 100)
		cout << (n * 100) + 100<< endl;
	if (d == 2 && n == 100)
		cout << (n * 10000) + 10000 << endl;
	
	return (0);
}


Measured memory_bytes: 256
A = [0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[int(input())])


Measured memory_bytes: 2940
import java.util.*;

class Main{
	public static long gcd(long a, long b) {
		return a%b==0 ? b : gcd(b, a % b);
	}

	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		long r=0;
		for(String t:s.next().replaceAll("BC","#").split("[BC]+")) {
			long c=0;
			for(int i=t.length()-1;i>=0;--i) {
				if(t.charAt(i)=='#')
					++c;
				else
					r+=c;
			}
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 35172
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
                         **/
#include<bits/stdc++.h>
using namespace std;
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz size
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 3*1e5+5;
const int mod = 1000000009;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 10000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b;
    int pwur = qpow(b,e>>1);
    return pwur * pwur;
}
int modinv(int x){
    return qpow(x,mod-2);
}

/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    ///freopen("a.in","r",stdin);
    ///freopen("a.out","w",stdout);
    int n,k;
    cin>>n>>k;
    vi v(n);
    rep(i,n)cin>>v[i];
    sort(all(v));
    int ans=0;
    if((n-1)%(k-1)==0)cout<<(n-1)/(k-1);
    else cout<<(n-1)/(k-1)+1<<enl;


    return 0;
}


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

map<pair<int,int>,int>p;
vector<vector<int> > v;

void dfs(int i,int vis[],int ans[])
{
    vis[i]=1;
    for(auto j:v[i])
    {
        if(vis[j]==0)
        {
            pair<int,int> s;
            s.first=min(i,j);
            s.second=max(i,j);
            if(p[s]%2==0)
            {
                ans[j]=ans[i];
            }

            else
            ans[j]=(ans[i]+1)%2;

            dfs(j,vis,ans);
        }
    }
}

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

    v.resize(n);
    int x,y,w;
    for (int i = 0; i < n-1; ++i) {
        cin>>x>>y>>w;
        x--;
        y--;
        pair<int,int>t;
        t.first=x;
        t.second=y;
        p[t]=w;
        v[x].push_back(y);
        v[y].push_back(x);
    }

//    for (int i = 0; i < n; ++i) {
//        for(auto j:v[i])
//        {
//            cout<<j<<" ";
//        }
//        cout<<endl;
//    }
//    cout<<endl;
    int vis[n]={0};
    int ans[n]={0};

    dfs(0,vis,ans);

//    for (int i = 0; i < n; ++i) {
//        cout<<vis[i]<<" ";
//    }

//    cout<<endl;
    for (int i = 0; i < n; ++i) {
        cout<<ans[i]<<endl;
    }
}

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

using namespace std;

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

vector<int> v, d;

void fastio() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
}

int main() {
    fastio();
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if (k > a) k -= a;
    else {
        cout << k;
        return 0;
    }
    ans += a;
    if (k > b) k -= b;
    else {
        cout << ans;
        return 0;
    }
    if (k > c) ans -= c;
    else ans -= k;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int H, W, N;
    cin >> H >> W >> N;
    int sx, sy;
    cin >> sx >> sy;
    string S, T;
    cin >> S >> T;
    int l = 0, r = W+1, u = 0, d = H+1;
    rep3(i, N-1, 0){
        if(T[i] == 'L') if(r != 1) r = min(r+1, W+1);
        if(T[i] == 'R') if(l != W) l = max(l-1, 0);
        if(T[i] == 'U') if(d != 1) d = min(d+1, H+1);
        if(T[i] == 'D') if(u != H) u = max(u-1, 0);
        if(S[i] == 'L') l = min(l+1, W);
        if(S[i] == 'R') r = max(r-1, 1);
        if(S[i] == 'U') u = min(u+1, H);
        if(S[i] == 'D') d = max(d-1, 1);
    }
    if(l < sy && sy < r && u < sx && sx < d) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

using namespace std;

int uf[200005];

void init(int n)
{
		for(int i=0;i<n;i++)
				uf[i]=i;
}

int root(int x)
{
		if(uf[x]==x)return x;
		return uf[x]=root(uf[x]);

}

void unite(int a,int b)
{
		int ra=root(a);
		int rb=root(b);
		if(ra==rb)return;
		uf[ra]=rb;
}

bool same(int a,int b)
{
		int ra=root(a);
		int rb=root(b);
		return ra==rb;
}

int main()
{
		int n,m;
		cin >> n >> m;
		init(n+m);
		for(int i=0;i<n;i++)
		{
				int kk;
				cin >> kk;
				for(int j=0;j<kk;j++)
				{
						int l;
						cin >> l;
						l--;
						unite(i,n+l);
				}
		}

		bool flag=true;
		for(int i=1;i<n;i++) 
				if(!same(i,i-1))flag=false;

		cout << (flag ? "YES":"NO") << endl;

}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		char[] list = sc.next().toCharArray();
		char c = list[list.length-1];
		if( c == '2' || c == '4' || c == '5' || c == '7' || c == '9') {
			System.out.println("hon");
		}else if(c == '3') {
			System.out.println("bon");
		}else {
			System.out.println("pon");
		}
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

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

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


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

using namespace std;

typedef long long ll;


const int N = (int) 2e5 + 7;
int n;
ll l;
ll de;
pair<ll, ll> a[N];
ll sub[N];
ll cur;
ll cost = 0;

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

        cin >> n >> l >> de;
        l *= 2;
        for (int i = 1; i <= n; i++)
                cin >> a[i].first >> a[i].second;
        sort(a + 1, a + n + 1);
        int j = 1;
        for (int i = 1; i <= n; i++)
        {
                while (j + 1 <= n && a[j + 1].first <= a[i].first + l)
                        j++;
                cur -= sub[i];
                ll val = a[i].second - cur * de;
                if (val > 0)
                {
                        ll need = (val / de) + ((val % de) != 0);
                        cur += need;
                        cost += need;
                        sub[j + 1] += need;
                }
        }
        cout << cost << "\n";
}


Measured memory_bytes: 4992
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.NoSuchElementException;

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

	final long MOD = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner();
		int N = sc.nextInt();
		int K = sc.nextInt();
		long ans = (long) (N / K) * (N / K) * (N / K);
		int cnt = 0;
		for (int i = 1; i <= N; ++i)
			if (i % K == K / 2)
				++cnt;
		if (K % 2 == 0) {
			ans += (long) cnt * cnt * cnt;
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

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

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

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

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

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

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


Measured memory_bytes: 21460
n = int(input())
a = list(map(int,input().split()))
b = 1
cnt = 0
if 0 in a:
    cnt = 1
    print(0)
else:
    for i in a:
        b = b*i
        if b>(10**18):
            print(-1)
            cnt = 1
            break
if cnt == 1:
    pass
else:
    print(b)

Measured memory_bytes: 87728
#include<stdio.h>
#include<string.h>
int a[200010],b[200010];
int main()
{
    int n,m,i,j,k;
    while(~scanf("%d%d",&n,&m))
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
         int k,p=0;
       for(i=0;i<m;i++)
            {
            scanf("%d%d",&k,&j);
            if(k==1) a[j]=1;
            if(j==n) b[k]=1;
            if(k==1&&j==n) p=1;
            }
        if(p==1) {printf("POSSIBLE\n");continue;}
       for(i=1;i<n;i++)
           if(a[i]==1&&b[i]==1)   {printf("POSSIBLE\n");break;}
        if(i>=n) printf("IMPOSSIBLE\n");
    }
}


Measured memory_bytes: 1664
#include <stdio.h>

int main(void)
{
	int mt[10], m;
	int i, j;
	
	for(i = 0; i < 10; i++){
		scanf("%d", &mt[i]);
	}
	
	for(i = 0; i < 9; i++){
		for(j = 0; j < 9 - i; j++){
			if(mt[j] < mt[(j + 1)]){
				m = mt[j];
				mt[j] = mt[(j + 1)];
				mt[(j + 1)] = m;
			}
		}
	}
	
	for(i = 0; i < 3; i++){
		printf("%d\n", mt[i]);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <math.h>

#define PI acos(-1)

int main() {
#ifdef TEST
    freopen("input", "r", stdin);
#endif

    int a, b, c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    printf("%f\n", 0.5 * a * b * sin(c * PI / 180));
    printf("%f\n", a + b + sqrt(a * a + b * b - 2 * a * b * cos(c * PI / 180)));
    printf("%f\n", b * sin(c * PI / 180));
    return 0;
}



Measured memory_bytes: 2120
import collections
N = int(input())
# 社員番号1以外のN-1人分担当上司番号を入力する
A = list(map(int, input().split()))
# 出現回数を数えてくれる
count = collections.Counter(A)
for n in range(N):
#   数が足りないから+1する。
  print(count[n+1])

Measured memory_bytes: 33916
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	a, b := ScanInt(), ScanInt()

	c := 0
	for i := a; i <= b; i++ {
		s := strings.Split(strconv.Itoa(i), "")
		if s[0]+s[1] == s[4]+s[3] {
			c++
		}
	}

	fmt.Println(c)
}

func ScanInt() (i int) {
	fmt.Scan(&i)
	return
}


Measured memory_bytes: 5504
#include<stdio.h>
using ll=long long;
const int MX=2e6,MM=119<<23|1;
ll F[MX],I[MX],IF[MX];
ll C(int x,int y){return F[x+y]*IF[x]%MM*IF[y]%MM;}
int main(){
	int N,M,i;
	I[1]=F[0]=IF[0]=F[1]=IF[1]=1;
	for(i=2;i<MX;i++)I[i]=(MM-MM/i)*I[MM%i]%MM,F[i]=F[i-1]*i%MM,IF[i]=IF[i-1]*I[i]%MM;
	scanf("%d%d",&N,&M);
	if(N>M)N^=M^=N^=M;
	ll ans=M,tot=IF[N+M]*F[N]%MM*F[M]%MM;
	for(i=1;i<=N;i++)ans=(ans+tot*C(N-i,M-i)%MM*C(i,i)%MM*I[2])%MM;
	printf("%lld\n",ans);
}



Measured memory_bytes: 47104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	ll answer = 0;
	if(a[0] != 0){ answer = -1; }
	for(int i = 1; answer >= 0 && i < n; ++i){
		if(a[i] == a[i - 1] + 1){
			++answer;
		}else if(a[i] <= a[i - 1]){
			answer += a[i];
		}else{
			answer = -1;
		}
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 1152
# coding: utf-8

# https://atcoder.jp/contests/abc115


def main():
    N = int(input())
    p = [None] * N
    for i in range(N):
        p[i] = int(input())
    
    p = sorted(p)
    return sum(p[:-1]) + p[-1]//2


print(main())


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vpll;

//mt19937 random(566);
//uniform_int_distribution<ll> distr;
//ll rnd(ll a, ll b) {return a + distr(random) % (b - a + 1);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a, b, c;
    cin >> a >> b >> c;
    if (c > a + b && 4 * a * b < (c - a - b) * (c - a - b)) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  vector<int> zyu(n);
  vector<int> tokuten(n);
  vector<int> c(n-1,0);
  for(auto &i:zyu) cin >> i;
  for(auto &i:tokuten) cin >> i;
  for(auto &i:c) cin >> i;
  int ans = 0;
  int k=-1;
  rep(i,n){
    if(k+1==zyu[i]) ans+=c[k-1];
    ans+=tokuten[zyu[i]-1];
    k=zyu[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ld INF = (ld)10000000000000;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

int n;ll k, m;

ll pas[303][303];
void init() {
	rep(i, 303) {
		rep(j, 303) {
			if (i == 0 || j == 0)pas[i][j] = 1;
			else pas[i][j] = (pas[i - 1][j] + pas[i][j - 1]) % m;
		}
	}
}

ll dp[303][303];
ll rdp[303][303];
int main() {
	cin >> n >> k >> m; init();
	rep(i, k + 1) {
		dp[1][i] = 1;
		rdp[1][i + 1] =(rdp[1][i]+ dp[1][i]) % m;
	}
	Rep1(i, 2, n + 1) {
		rep(j, k + 1) {
			rep1(l, i - 1) {
				(dp[i][j] += pas[i - 2 - l + 1][l - 1] * dp[i - l][j] % m*((rdp[l][k + 1] - rdp[l][j + 1]) % m + m) % m) %= m;
			}
			rdp[i][j + 1] = (rdp[i][j] + dp[i][j]) % m;
		}
	}
	//cout << dp[2][0] << endl;
	//cout << dp[2][1] << endl;
	//cout << dp[2][2] << endl;
	cout << dp[n + 1][0] << endl;
	//stop
	return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
    string s, p;
    cin >> s >> p;
    s += s;
    if(s.find(p) != -1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, a, b, c;
	cin >> n >> a >> b >> c;
	string q[n + 7];
	char ans[n];
	bool ok = true;
	for (int i = 0; i < n; ++i) {
		cin >> q[i];
	}
	q[n] = "GG";
	for (int i = 0; i < n; ++i) {
		if (q[i] == "AB") {
			if (a < 1 && b < 1) ok = false;
			else {
				if (a > b) {
					--a;
					++b;
					ans[i] = 'B';
				}
				else if (a < b) {
					++a;
					--b;
					ans[i] = 'A';
				}
				else {
					if (q[i + 1][0] == 'A') {
						++a;
						--b;
						ans[i] = 'A';
					}
					else {
						--a;
						++b;
						ans[i] = 'B';
					}
				}
			}
		}
		if (q[i] == "AC") {
			if (a < 1 && c < 1) ok = false;
			else {
				if (a > c) {
					--a;
					++c;
					ans[i] = 'C';
				}
				else if (a < c) {
					++a;
					--c;
					ans[i] = 'A';
				}
				else {
					if (q[i + 1][0] == 'A') {
						++a;
						--c;
						ans[i] = 'A';
					}
					else {
						--a;
						++c;
						ans[i] = 'C';
					}
				}
			}
		}
		if (q[i] == "BC") {
			if (b < 1 && c < 1) ok = false;
			else {
				if (b > c) {
					--b;
					++c;
					ans[i] = 'C';
				}
				else if (b < c) {
					++b;
					--c;
					ans[i] = 'B';
				}
				else {
					if (q[i + 1] == "AB") {
						++b;
						--c;
						ans[i] = 'B';
					}
					else {
						--b;
						++c;
						ans[i] = 'C';
					}
				}
			}
		}
	}

	if (ok) {
		cout << "Yes\n";
		for (int i = 0; i < n; ++i) {
			cout << ans[i] << '\n';
		}
	}
	else {
		cout << "No\n";
	}

	return 0;
}


Measured memory_bytes: 6860
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include <assert.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
#include <climits>
using namespace std;
typedef unsigned long long ull;
#define ll long long int
static const double PI = 3.141592653589793;
const ll INF = 100000000000000;
ll mod = 1000000007;
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;

ll MOD = 1000000007;

ll fact[3000], invs[3000];

//MOD使ってる

ll pow(ll x, ll n, ll mod) { //x^n 計算量O(logn)
	ll ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x%mod;
		}
		x = x * x%mod; //一周する度にx, x^2, x^4, x^8となる
		n >>= 1; //桁をずらす n = n >> 1
	}
	return ans % mod;
}

ll combination(ll n, ll r) {
	return ((fact[n] * invs[r] % MOD) * invs[n - r]) % MOD;
}
void make_c(ll n) {
	fact[1] = 1, invs[1] = 1, invs[0] = 1;
	for (int i = 2; i < n; i++) {
		fact[i] = fact[i - 1] * i%MOD;
		invs[i] = pow(fact[i], MOD - 2, MOD);
	}
}


int main() {
	ll n, k;
	make_c(3000);
	cin >> n >> k;
	cout << n-k+1 << endl;
	for (ll i = 2; i <= k; i++) {
		if ((n - k - i + 1) < 0) {
			cout << 0 << endl;
		}
		else {
			cout<<(combination(k - 1, i - 1)*combination(n-k+1,i)) % MOD << endl;;
		}
	}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[334334],cnt[334334];int n,memo=0,ans=0,cnta=0;
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n){
		memo+=a[i];
		cnt[i]=memo;
	}
	sort(cnt,cnt+n);
	rep(i,n){
		if(cnt[i]==0)cnta++;
	}
	rep(i,n){
		if(cnt[i]==cnt[i+1]&&i!=n-1)continue;
		ans+=(upper_bound(cnt,cnt+n,cnt[i])-lower_bound(cnt,cnt+n,cnt[i]))*(upper_bound(cnt,cnt+n,cnt[i])-lower_bound(cnt,cnt+n,cnt[i])-1)/2;
	}
	cout<<ans+cnta<<endl;
}


Measured memory_bytes: 3968