akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <iomanip>
#include <climits>
#include <string>
#include <sstream>
#include <numeric>
#include <stack>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> K;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	int AS = 0;
	rep(i, N) AS += A[i];
	vector< int > D;
	for (int i = 1; i * i <= AS; i++) {
		if (AS % i == 0) {
			D.push_back(i);
			D.push_back(AS / i);
		}
	}
	sort(D.rbegin(), D.rend());
	for (auto x : D) {
		vector< int > B(N);
		rep(i, N) B[i] = A[i] % x;
		sort(B.begin(), B.end());
		int C = K;
		int l = 0, r = N - 1;
		while (l < r) {
			while (B[l] == 0)
				++l;
			while (B[r] == 0)
				--r;
			if (l >= r)
				break;
			int m = min(B[l], x - B[r]);
			C -= m;
			B[l] -= m;
			(B[r] += m) %= x;
		}
		if (C >= 0) {
			cout << x << endl;
			return 0;
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

vector<pair<ll, int>> getFact(ll x) {
	vector<pair<ll, int>> v;
	for (ll i = 2; i * i <= x; ++i)
		if (x % i == 0) {
			v.emplace_back(i, 1);
			for (x /= i; x % i == 0; x /= i)
				v.back().second++;
		}
	if (x != 1)
		v.emplace_back(x, 1);
	return v;
}

ll f(ll a, ll b) {
	return b == 0 ? 1 : a * f(a, b - 1);
}

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

	ll n, p;
	cin >> n >> p;

	auto fact = getFact(p);

	ll res = 1;
	for(auto &&x : fact)
	res *= f(x.first, x.second / n);
	cout << res << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
    	new Main(); 
    }
 
    public Main() {
    	new A().doIt();
    }
    class A{
    	int cnt[] = new int [1001]; 
    	void check(int num,int sum){
    		if(sum > 1000)return;
    		else{
    			cnt[sum]++;
    			check(num+1,sum + num);
    		}
    	}
    	void doIt(){
    		for(int i = 1;i <= 1000;i++){
    			cnt[i]--;
        		check(i+1,i);
        	}
    		while(true){
    			int n = sc.nextInt();
    			if(n == 0)break;
    			System.out.println(cnt[n]);
    		}
    	}
    }
}

Measured memory_bytes: 25968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    string s; cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
def dv(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
N=int(input())
L=dv(N)
if L==[1]:
  L=[1,1]
ans=10**10
for l in L:
  ans=min(ans,len(str(max(l,N//l))))
print(ans)

Measured memory_bytes: 66868
#include <iostream>
#include <vector>
#include <map>
#include <iomanip>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
typedef long long ll;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll comb2(ll n) {
    return n * (n - 1) / 2;
}

int main() {
    int n;
    cin >> n;
    vector<int> vc;
    while(n--) {
        int x;
        cin >> x;
        vc.push_back(x);
    }
    n = vc.size();

    map<int, unsigned int> mp;

    for (auto v: vc) {
        mp[v] += 1;
    }

    ll allsum = 0;
    for (auto & itr : mp) {
        allsum += comb2(itr.second);
    }

    for (int k = 0; k < n; k++) {
        cout << setprecision(11) << allsum - (mp[vc[k]] - 1) << endl;
    }


    return 0;
}


Measured memory_bytes: 9972
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
template<typename T> void ckmax(T&a, T b) { if (b > a) a = b; }
template<typename T> void ckmin(T&a, T b) { if (b < a) a = b; }

int f[10][10][10], g[10][10], h[10], n, a[30000 + 5];
char tmp[30000 + 5];

int main ()
{
	scanf ("%d", &n);
	scanf ("%s", tmp + 1);
	rep (i, 1, n) {
		a[i] = tmp[i] - '0';
		rep (x, 0, 9) rep (y, 0, 9) f[x][y][a[i]] |= g[x][y];
		rep (x, 0, 9) g[x][a[i]] |= h[x];
		h[a[i]] = 1;
	}
	int ans = 0;
	rep (x, 0, 9) rep (y, 0, 9) rep (z, 0, 9) ans += f[x][y][z];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
N,Q = map(int,input().split())
S = input()

l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i],r[i] = map(int,input().split())

ans = [0] * N


for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        ans[i+1] = ans[i] + 1
    else:
        ans[i+1] = ans[i]
        
for j in range(Q):
    print(ans[r[j]-1]-ans[l[j]-1])
    

Measured memory_bytes: 14128
# Author: cr4zjh0bp
# Created: Fri Mar 20 18:02:18 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

class WUnionFind:
    def __init__(self, n, sum_unity=0):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.diff_weight = [sum_unity for _ in range(n)]
        self._size = [1 for _ in range(n)]
        self._edges = 0

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            r = self.find(self.par[x])
            self.diff_weight[x] += self.diff_weight[self.par[x]]
            self.par[x] = r
            return r
        
    def unite(self, x, y, w):
        w += self.weight(x)
        w -= self.weight(y)
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.diff_weight[x] = -w
            self._size[y] += self._size[x]
            self._edges += 1
        else:
            self.par[y] = x
            self.diff_weight[y] = w
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self._size[x] += self._size[y]
            self._edges += 1

    def weight(self, x):
        self.find(x)
        return self.diff_weight[x]

    def diff(self, x, y):
        return self.weight(y) - self.weight(x)
    
    def size(self, x):
        x = self.find(x)
        return self._size[x]
    
    def trees(self):
        return self.n - self._edges

    def same(self, x, y):
        return self.find(x) == self.find(y)

n, m = na()
lrd = nan(m)
wuf = WUnionFind(n)
flag = True
for i in range(m):
    l, r, d = lrd[i]
    l -= 1
    r -= 1
    if wuf.same(l, r):
        if wuf.diff(l, r) != d:
            flag = False
    else:
        wuf.unite(l, r, d)

print("Yes" if flag else "No")

Measured memory_bytes: 60276
from sys import stdin
n,k = map(int,stdin.readline().split())
arr = sorted(list(map(int,stdin.readline().split())),key=lambda x:abs(x))
mod = 10**9+7
pos,neg = [],[]
for i in arr:
    if i>=0:
        pos.append(i)
    else:
        neg.append(i)
if not len(pos):
    ans = 1
    if k%2:
        for i in range(k):
            ans *= neg[i]
            ans %= mod
    else:
        for i in range(k):
            ans *= neg[-1-i]
            ans %= mod
else:
    ans = 1
    i=len(pos)-1
    j=len(neg)-1
    val = 0
    if n==k:
        for x in arr:
            ans *= x
            ans %= mod
    else:
        if k%2:
            ans *= pos[i]
            i -= 1
            val += 1
        while val != k:
            if i<1:
                ans *= neg[j]*neg[j-1]
                ans %= mod
                j -= 2
            elif j<1:
                ans *= pos[i]*pos[i-1]
                ans %= mod
                i -= 2
            else:
                if pos[i]*pos[i-1]>neg[j]*neg[j-1]:
                    ans *= pos[i]*pos[i-1]
                    ans %= mod
                    i -= 2
                else:
                    ans *= neg[j]*neg[j-1]
                    ans %= mod
                    j -= 2
            val += 2
print(ans)

Measured memory_bytes: 112336
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	char S[100010], T[100010];
	int N = 0;
	int M = 0;
	while ((S[N] = getchar_unlocked()) >= 'a') N++;
	while ((T[M] = getchar_unlocked()) >= 'a') M++;

	int n[100001][26];

	int tugi[26];
	rep(i, 26) tugi[i] = -1;
	for (int i = N - 1; i >= 0; i--) {
		tugi[S[i] - 'a'] = i;
	}
	for (int i = N - 1; i >= 0; i--) {
		rep(j, 26) n[i][j] = tugi[j];
		tugi[S[i] - 'a'] = i;
	}


	int OK = 1;
	ll kotae = 0;
	int k = N - 1;
	rep(i, M) {
		int k2 = n[k][T[i] - 'a'];
		if (k2 == -1) {
			OK = 0;
			break;
		}

		if (k2 > k) kotae += k2 - k;
		else kotae += k2 - k + N;
		k = k2;
	}

	if (OK) printf("%lld", kotae);
	else printf("-1");

	Would you please return 0;
}

Measured memory_bytes: 10496
#include<iostream>
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	if (a<b){
		cout << "a < b" << endl;
	}
	if (a>b){
		cout << "a > b" << endl;
	}
		if (a==b){
			cout << "a == b" << endl;
		}
		return 0;
}



Measured memory_bytes: 3068
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M, V, P = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    A.sort()
    
    def check(t):
        if A[t] + M < A[-P]:
            return False
        at = A[t]
        cnt = (P - 1) * M
        for idx in range(N - P + 1):
            cnt += min(M, M - A[idx] + at)
        return M * V <= cnt
    
    ok, ng = N - 1, -1
    while 1 < ok - ng:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(N - ok)


if __name__ == '__main__':
    solve()


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

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

int main() {
  const int MOD = 1000000007;
  int N;cin>>N;
  string S1,S2;cin>>S1>>S2;

  // 0~N-1まで見ていって、上と下が同じならたてドミノ、違うなら横ドミノで判定
  int cur = 0;
  ll ans = 0;
  bool prev_vertical;
  if (S1[0]==S2[0]) {
    prev_vertical = true;
    ans += 3;
    cur++;
  } else {
    prev_vertical = false;
    ans += 6;
    cur+=2;
  }
  while (cur<N) {
    if (S1[cur]==S2[cur]) {
      if (prev_vertical) {
        ans = ans*2%MOD;
      } else {
        // パターン増えない
      }
      prev_vertical = true;
      cur++;
    } else {
      if (prev_vertical) {
        ans = ans*2%MOD;
      } else {
        ans = ans*3%MOD;
      }
      prev_vertical = false;
      cur += 2;
    }
  }
  OUT(ans);

  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> myList = new ArrayList<Integer>();
		
		
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		b = b / 2;
		
		System.out.println(a + b);
	}	
}


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

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

const int INF = 1000000007;

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

	char sec[3];
	sec[0] = S[0];
	int cnt = 0;
	bool section = false;
	for(int i=0;i<S.size();i++) {
		if(sec[0] != S[i]) {
			sec[0] = S[i];
			cnt++;
		}
		
	}
	
	cout<< cnt <<endl;

	return 0;
}

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

using namespace std;
#define ll long long
#define ld long double

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    ll p[a], q[b], r[c];
    for(int i=0;i<a;i++) cin >> p[i];
    for(int i=0;i<b;i++) cin >> q[i];
    for(int i=0;i<c;i++) cin >> r[i];
    sort(p, p + a, greater<int>());
    sort(q, q + b, greater<int>());
    sort(r, r + c, greater<int>());
    vector<ll> v;
    for(int i=0;i<x;i++) v.push_back(p[i]);
    for(int i=0;i<y;i++) v.push_back(q[i]);
    sort(v.begin(), v.end());
    int cnt = 0;
    ll sum = 0;
    for(int i=0;i<x+y;i++) {
        if(v[i] < r[cnt] && cnt < c) {
            sum += r[cnt];
            cnt++;
        }
        else sum += v[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4852
import math
from collections import defaultdict
n = int(input())
p = defaultdict(int)
mod = 10 ** 9 + 7
ori = 0
for _ in range(n):
    a,b = map(int,input().split())
    if a == b == 0:
        ori += 1
        continue
    elif b < 0:
        a *= -1
        b *= -1
    elif b == 0 and a < 0:
        a *= -1
    if a == 0:
        p[(0,1)] += 1
    elif b == 0:
        p[(1,0)] += 1
    else:
        g = math.gcd(a,b)
        p[(a//g, b//g)] += 1

k = n - ori
ans = ori-1
tmp = 1
l = k
for q,num in sorted(p.items(), reverse=True):
    x,y = q
    if x <= 0:
        break
    if p[(-y, x)] >= 1:
        a,b = p[(x,y)], p[(-y, x)]
        tmp *= pow(2,a,mod) + pow(2,b,mod) - 1
        l -= a+b
tmp *= pow(2,l,mod)
print((ans+tmp) % mod)

Measured memory_bytes: 69520
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
ll mod = 1e9+7;
ll inf = 1e10;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int sum = 0;
  rep(i, n) sum += a[i];
  double daverage = static_cast<double>(sum)/static_cast<double>(n);
  int iaverage = sum/n;
  if(daverage > iaverage+0.50) ++iaverage;
  int ans = 0;
  rep(i, n) ans += pow(iaverage-a[i], 2);
  cout << ans << "\n";
  return 0;
}  

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

int main() {
	vector<int> vec(3);
	for (int i = 0; i < 3; i++) cin >> vec[i];
	sort(vec.begin(), vec.end());
	for (int i = 0; i < 3; i++) {
		if (i == 0) cout << vec[i] << flush;
		else cout << " " << vec[i] << flush;
	}
	cout << endl;
	return 0;
}


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

const int MAX_N = 3005;

class Edge {
public:
  int nxt, to;
} e[MAX_N << 1];

int head[MAX_N], cnt;
void addedge(int u, int v) {
  e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
  e[++cnt] = (Edge){head[v], u}, head[v] = cnt;
}

int F[MAX_N], A[MAX_N], N;

void dfs(int u, int v) {
  for (int i = head[u]; i; i = e[i].nxt)
    if (e[i].to != v) {
      dfs(e[i].to, u);
      F[u] |= (A[e[i].to] < A[u]) && !F[e[i].to];
    }
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    scanf("%d", &A[i]);
  for (int i = 1, u, v; i < N; ++i) {
    scanf("%d%d", &u, &v);
    addedge(u, v);
  }

  for (int i = 1; i <= N; ++i) {
    memset(F, 0, sizeof F);
    dfs(i, 0);
    if (F[i]) printf("%d ", i);
  }
  puts("");
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n); readint(m); readll(k);
        vector<ll> a, b;
        forr(i,0,n) {
            readll(aa); a.push_back(aa);
        }
        forr(i,0,m) {
            readll(bb); b.push_back(bb);
        }

        ll sum_a = accumulate(a.begin(), a.end(), 0LL), sum_b = 0, ret = 0;
        ll i_a = a.size(), i_b = 0;
        while (true) {
            while (i_b<m) {
                if (sum_a+sum_b+b[i_b]<=k) {  sum_b+=b[i_b]; i_b++;  }
                else {break;}
            }
            if (sum_a+sum_b<=k) {   ret = max(ret, i_a+i_b); }
            i_a--; 
            if (i_a==-1) {break;}            
            sum_a -= a[i_a];
        }

        cout << ret << endl;
    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}

Measured memory_bytes: 8000
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1,n-1):
    if (p[i-1]<p[i]) and (p[i]<p[i+1]):
        ans += 1
    if (p[i-1]>p[i]) and (p[i]>p[i+1]):
        ans += 1
print(ans)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	long long a, b, c, d; 
	cin >> a >> b >> c >> d; 
	cout << max({a*c, a*d, b*c, b*d}) << "\n"; 
}

Measured memory_bytes: 3676
#include <stdlib.h>
#include <unistd.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))

int input() {
    char buf[6];
    int size = read(0, buf, 6);
    int n = 0;
    REP (i, 5) {
        n = n * 10 + buf[i] - '0';
    }
    return n;
}
void output(int n) {
    char buf[20];
    char *s = buf + sizeof buf;
    *(-- s) = '\n';
    if (! n) *(-- s) = '0';
    for (; n; n /= 10) {
        *(-- s) = (n % 10) + '0';
    }
    write(1, s, buf + sizeof buf - s);
}


__attribute__((constructor))
static void _main() {
    int a = input();
    int b = input();
    int cnt = 0;
    REP (x, 10) REP (y, 10) REP (z, 10) {
        int n = x * 10000 + y * 1000 + z * 100 + y * 10 + x;
        cnt += (a <= n && n <= b);
    }
    output(cnt);
    _exit(EXIT_SUCCESS);
}

int main() {
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> p(n), q(n), v;
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 0; i < n; i++) cin >> q[i];
    for (int i = 0; i < n; i++) v.emplace_back(i+1);

    int a, b; int cnt = 0;
    do {
        cnt++;
        if (v == p) a = cnt;
        if (v == q) b = cnt;
    } while (std::next_permutation(v.begin(), v.end()));
    cout << abs(b - a) << "\n";
    return 0;
}

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

using namespace std;

struct count_op
{
  bool operator()( int i )
  {
    return i > 0;
  }
};


int main()
{
  for(;;) {
    int n, p;
    cin >> n >> p;

    if ( n == 0 && p == 0 )
      break;

    vector<int> temoto( n, 0 );


    for(;;) {
      for( int i=0; i<n; ++i ) {
	if ( p > 0 ) {
	  --p;
	  ++temoto[i];

	  if ( p == 0 ) {
	    int const other = count_if( temoto.begin(), temoto.end(), count_op() );
	    if ( other == 1 ) {
	      cout << i << endl;
	      goto ee;
	    }
	  }
	} else {
	  p += temoto[i];
	  temoto[i] = 0;
	}
      }
    }
ee:;
  }
}

    

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 3050;
using namespace std;
typedef long long ll;
ll a[maxn];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	ll ans=1000;
	ll cnt=0;
	for(int i=2;i<=n;i++){
		if(a[i-1]<a[i]){
			ans=ans/a[i-1]*a[i]+ans%a[i-1];	
		}
	}
	cout<<ans;
	return 0; 
} 

Measured memory_bytes: 3556
#include<stdio.h>
int main()
{
	int i=0;
	long long int n;
	char s[12]={};

	scanf("%lld",&n);

	while(1){
		if(!n){
			break;
		}
		s[i++]='a'+(n-1)%26;
		n=(n-1)/26;
	}
	while(i--)
		printf("%c",s[i]);
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	ll k;
	cin >> k;
	ll x;
	char y;
	for (int i = 0; i < s.length(); i++) {
		if (s.at(i) != '1') {
			x = i + 1;
			y = s.at(i);
			break;
		}
	}
	if (k < x)cout << 1 << endl;
	else cout << y << endl;
}

Measured memory_bytes: 256
'''
Created on 2020/09/06

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  S=pin()[:-1]
  t=S.count("o")
  u=len(S)
  if 15-u+t>=8:
    print("YES")
  else:
    print("NO")
  return 
main()

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

int main() {
 int n;
  cin>>n;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(n==i*j) {cout<<"Yes"<<endl; return 0;}
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
n=input()
ym=0
my=0
if n[0]=="0":
  if int(n[1])!=0:
    my=1
  else:
    my=0
elif n[0]=="1":
  if int(n[1])==1 or int(n[1])==2:
    my=1
  else:
    my=0
else:
  my=0
if n[2]=="0":
  if int(n[3])!=0:
    ym=1
  else:
    ym=0
elif n[2]=="1":
  if int(n[3])==1 or int(n[3])==2:
    ym=1
  else:
    ym=0
else:
  ym=0
if my and ym:
  print("AMBIGUOUS")
elif my:
  print("MMYY")
elif ym:
  print("YYMM")
else:
  print("NA")

    


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

string s, t; 
const int maxn = 1e5+5;
const ll INF = 1LL<<55;
int nxt[2*maxn][26];
ll dist[2*maxn][26];

int n;

void precomp() {
    n = s.size();
    s += s;
    for (int i = s.size()-1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) {
            if (i == s.size()-1) {
                nxt[i][j] = -1;
                dist[i][j] = INF;
            }
            else {
                nxt[i][j] = nxt[i+1][j];
                dist[i][j] = 1 + dist[i+1][j];
            }
        }
        nxt[i][s[i]-'a'] = i % n;
        dist[i][s[i]-'a'] = 0;

        /*
        for (int j = 0; j < 26; j++) {
            cout << i << ' ' << j << ": " << nxt[i][j] << '\n';
        }
        */
    }

}

bool check(ll x) {
    int curr = 0;
    for (int i = 0; i < t.size(); i++) {
        int nx = nxt[curr][t[i]-'a'];
        ll d = dist[curr][t[i]-'a'];
        assert(nx != -1);
        x -= d;
        if (i < t.size()-1) {
            curr = (nx+1) % n;
            x--;
        }
        if (x < 0) {
            return false;
        }
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> s >> t;
    //if all letters of t are in s, then it's possible
    set<char> ss;
    for (char c: s) {
        ss.insert(c);
    }
    bool poss = true;
    for (char c: t) {
        if (!ss.count(c)) {
            poss = false;
            break;
        }
    }
    if (!poss) {
        cout << -1 << '\n';
        return 0;
    }
    precomp();
    /*
    cout << check(8) << '\n';
    return 0;
    */
    ll lo = -1, hi = 1e16;
    while (lo + 1 < hi) {
        ll mid = (lo+hi)/2;
        if (check(mid)) {
            hi = mid;
        }
        else lo = mid;
    }
    cout << (hi+1) << '\n';
}



Measured memory_bytes: 61676
#include <cstdio>
#include <string>
using namespace std;

string s;
char t[101];
char u[101];
string r;

int main(){
	scanf("%s", u);
	scanf("%s", t);
	s = t;
	r = "ABC";
	r[1] = s[0];
	printf("%s\n", r.c_str());
	return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

bool prime(ll n)
{
	if(n<=1)return false;
	if(n<=3)return true;
	if(n%2==0||n%3==0)return false;
	for(ll i=5;i*i<=n;i+=6)
	{
		if(n%i==0||n%(i+2)==0)return false;
	}
	return true;
}

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
		if(b&1)r=(r*a)%m;
		b = b>>1;
		a=(a*a)%m;
	}
	return r%m;
}

ll addmod(ll a,ll b)
{
    if(a+b<mod)return a+b;
    else return a+b-mod;
}
ll mulmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll modinv(ll a)
{
    return modexp(a,mod-2,mod);
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll h,w; cin>>h>>w;
    vector<string>arr(h);
    rep(i,0,h)cin>>arr[i];
    ll dp[h][w];
    dp[0][0] = 0;
    rep(i,0,h)
    {
        rep(j,0,w)
        {
            if(i==0&&j==0)continue;
            if(i==0)
            {
                dp[i][j] = dp[i][j-1]+(arr[i][j]!=arr[i][j-1]);
            }
            else if(j==0)
            {
                dp[i][j] = dp[i-1][j] + (arr[i][j]!=arr[i-1][j]);
            }
            else
            {
                dp[i][j] = min(dp[i-1][j]+(arr[i-1][j]!=arr[i][j]),dp[i][j-1]+(arr[i][j]!=arr[i][j-1]));
            }
        }
    }
    cout<<(dp[h-1][w-1]+1)/2+(arr[0][0]=='#'&&arr[h-1][w-1]=='#')<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

int main(){
  int n,k; cin >>n >>k; 
  vector<int>a(n);
  k=min(k,41);
  for(int i=0; i<n; i++) cin >>a[i];
  while(k--){
    vector<int>b(n,0);
    for(int i=0; i<n; i++){
      int l=max(i-a[i],0),r=min(i+a[i],n-1)+1;
      if(r<n) b[r]--;
      b[l]++;
    }
    for(int i=1; i<n; i++) b[i]+=b[i-1];
    for(int i=0; i<n; i++) a[i]=b[i];
  }
  for(int i=0; i<n; i++) cout <<a[i]<<" ";
return 0;}

Measured memory_bytes: 4752
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::min;

#[fastout]
fn main() {
    input! {
    s: Chars,
    k: usize
    }
    let n = s.len();
    let mut word_list = vec![];
    for i in 0..26u8 {
        let c = (i + 97) as char;
        for j in 0..n {
            if s[j] == c {
                for d in j + 1..=min(j + k, n) {
                    word_list.push(s[j..d].iter().collect::<String>());
                }
            }
        }
        word_list.sort();
        word_list.dedup();
        if word_list.len() >= k {
            println!("{}", word_list[k - 1]);
            return
        }
    }
}


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

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

    if (b - a <= 0) {
        cout << "delicious" << endl;
    } else if (b - a <= x) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
n,x = map(int,input().split())
a_list = [1]
p_list = [1]
for i in range(n):
  a_list.append(a_list[-1] * 2 + 3)
  p_list.append(p_list[-1] * 2 + 1)
def dfs(n,x):
  if x == 1:
    return 0
  if n == 1:
    if x ==2:
      return 1
    if x == 3 :
      return 2
    if x == 4 or x == 5:
      return 3
  elif 1 < x  and x <= a_list[n-1] +1:
    return dfs(n-1,x-1)
  elif x == a_list[n-1] + 2:
    return p_list[n-1] + 1
  elif a_list[n-1] + 2 < x and x <= 2 * a_list[n-1] + 2:
    return p_list[n-1] + 1 + dfs(n-1,x - (a_list[n-1] + 2))
  elif x == 2 * a_list[n-1] + 3:
    return 2 * p_list[n-1] + 1

print(dfs(n,x))
  

Measured memory_bytes: 38496
#include<bits/stdc++.h>
#define     ll          long long
#define     MOD         10e9+7
#define     pb          push_back
#define     vll         vector<long long>
#define     vi          vector<int>
#define     vl          vector<long>
#define     pii         pair<int, int>
#define     pll         pair<ll,ll>
#define     mp          make_pair
#define     all(a)      (a).begin(),(a).end()
#define     rep(i,a,b)  for(int i=a;i<b;i++)
#define     MAX         100002 
#define     ios	      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;


int main() {
    
    ios
    char ch;
    cin >> ch;
    if(ch>=65&&ch<=90)cout << "A\n";
    else cout <<"a\n";
    return 0;
}



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

typedef long long LL;

const int N=50;

int n,a[N+9];
string s[N+9],t;

void into(){
  cin>>n;
  for (int i=1;i<=n;++i)
	cin>>s[i]>>a[i];
  cin>>t;
}

int ans;

void Get_ans(){
  int flag=0;
  for (int i=1;i<=n;++i){
	ans+=flag*a[i];
	if (s[i]==t) flag=1;
  }
}

void work(){
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 3676
import java.util.Arrays;
import java.util.Scanner;

//Flame of Nucleus
public class Main{

	int INF = 1<<29;
	
	int augumentPath(int v, int t, int f, int[][] cap, boolean[] used){
		if(v==t)return f;
		used[v] = true;
		for(int i=0;i<cap[v].length;i++){
			if(cap[v][i]>0 && !used[i]){
				int d = augumentPath(i, t, Math.min(f, cap[v][i]), cap, used);
				if(d>0){
					cap[v][i] -= d;
					cap[i][v] += d;
					return d;
				}
			}
		}
		return 0;
	}

	int maxFlow(int s, int t, int[][] cap){
		int flow = 0;
		int n = cap.length;
		boolean[] used = new boolean[n];
		while(true){
			Arrays.fill(used, false);
			int f = augumentPath(s, t, Integer.MAX_VALUE, cap, used);
			if(f==0)return flow;
			flow += f;
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt(), m = sc.nextInt(), L = sc.nextInt();
			int[][] wf = new int[n+1][n+1];
			for(int[]a:wf)Arrays.fill(a, INF);
			for(int i=1;i<=n;i++)wf[i][i]=0;
			while(m--!=0){
				int s = sc.nextInt(), t = sc.nextInt(), c = sc.nextInt();
				wf[s][t]=wf[t][s]=c;
			}
			for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)wf[i][j]=Math.min(wf[i][j], wf[i][k]+wf[k][j]);
			int[] p = new int[n+1], k = new int[n+1];
			for(int i=1;i<=n;i++)p[i]=sc.nextInt();
			for(int i=1;i<=n;i++)k[i]=sc.nextInt();
			int[][] cap = new int[n*2+2][n*2+2];
			for(int i=1;i<=n;i++)cap[0][i]=p[i];
			for(int i=1;i<=n;i++)cap[n+i][2*n+1]=k[i];
			for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(wf[i][j]<L)cap[i][n+j]=p[i];
			System.out.println(maxFlow(0, 2*n+1, cap));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vi a(n);
    rep(i,0,n)cin>>a[i];
    ll ans=INF;
    rep(v,-100,101){
        ll res=0;
        rep(cur,0,n){
            res+=pow(a[cur]-v,2);
        }
        chmin(ans,res);
    }
    cout<<ans<<endl;
    return 0;
}




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

using namespace std;

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

bool couldUpdate(map<ll, ll>&dp, ll k, ll v) {
  assert(dp.count(k));
  if(v < dp[k]) {
    dp[k] = v;
    return true;
  }
  return false;
}

void solve() {
  ll a, b;
  cin >> a >> b;
  map<ll, ll> dp;
  dp[b] = 1e18;
  dp[-b] = 1e18;
  dp[-a] = 1e18;
  dp[a] = 0LL;
  while(true) {
    map<ll, ll> ndp;
    for(auto out: dp) ndp[out.first] = out.second;
    bool upd = false;
    for(auto x: dp) {
      for(auto y: ndp) {
        if(y.first >= x.first && couldUpdate(ndp, y.first, x.second + y.first-x.first)) {
          upd = true;
        }
        if(y.first == -x.first && couldUpdate(ndp, y.first, x.second + 1)) {
          upd = true;
        }
      }
    }
    if(!upd) break;
    dp = ndp;
  }
  cout << dp[b] << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#define llint long long 

using namespace std;
typedef pair<llint, llint> P;

struct BIT{
	int size;
	vector<llint> bit;
	BIT(){size = 0;}
	BIT(int s){
		size = s;
		bit.resize(size+1);
		init();
	}
	void init(){
		for(int i = 1; i <= size; i++) bit[i] = 0;
	}
	llint query(int i){
		llint ret = 0;
		while(i > 0){
			ret += bit[i];
			i -= i&(-i);
		}
		return ret;
	}
	void add(int i, llint x){
		while(i <= size){
			bit[i] += x;
			i += i&(-i);
		}
	}
};

llint n, k;
llint a[200005], s[200005];
P p[200005];
BIT bit(200005);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i], a[i] -= k;
	for(int i = 1; i <= n; i++) s[i] = s[i-1] + a[i];
	
	for(int i = 1; i <= n; i++) p[i] = P(s[i], i);
	sort(p+1, p+n+1);
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		ans += bit.query(p[i].second);
		bit.add(p[i].second, 1);
		if(p[i].first >= 0) ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
  long long a,b,x;
  cin>>a>>b>>x;
  long long A,B;
  A=a/x;
  B=b/x;
  if(a!=b&&a%x!=0)cout<<B-A<<endl;
  else if(a!=b&&a%x==0) cout<<B-A+1<<endl;
  else if(a==b&&a%x==0) cout<<"1"<<endl;
  else if(a==b&&a%x!=0)cout<<"0"<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N, M = map(int, input().split())
As = list(map(int, input().split()))
s = sum(As)
if s > N:
    print(-1)
else:
    print(N - s)




Measured memory_bytes: 11556
/*
Author : Vidish Joshi
*/

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

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define start1 ll t = 1; while(t--)
#define F first
#define S second
#define br "\n"

void solve(){
    int n; cin>>n;
    int a[n]; for(int i=0; i<n; i++) cin>>a[i];

    int cnt = 0;

    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            for(int k=j+1; k<n; k++){
                if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i] && (a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i])) cnt++;
            }
        }
    }

    cout<<cnt<<br;
}

int main(){
    FIO;
    start1{
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
N = int(input())

l = list(map(int, input().split()))

isFail = 0

for i in range(N):
  if(l[i] == i + 1): continue
  if(isFail):
    isFail = 2
    break
  
  isFail = 1
  dest = l[i] - 1
  l[i], l[dest] = l[dest], l[i]

print('YES' if isFail < 2 else 'NO')

Measured memory_bytes: 3060
S=input()
INF=10**12
# dp[i][j]: 下からi桁目まで決めた時の、くりさがりがjの時の最小値
# i: 0~N, j:2値, 前の桁でくりさがりが発生している場合に1
dp=[[INF for _ in range(2)] for _ in range(10**6+5)]
S=S[::-1]
S+="0"
N=len(S)
dp[0][0]=0
# 配るDP, 今の状態を見て次の状態を決めていく
for i in range(N):
    for j in range(2):
        # x: i桁目の数字, 前の桁でくりさがりが発生している場合はインクリメント
        x=int(S[i])
        x+=j
        for a in range(10):
            ni=i+1
            nj=0
            b=a-x
            if b<0:
                nj=1
                b+=10
            dp[ni][nj]=min(dp[ni][nj], dp[i][j]+a+b)
print(dp[N][0])

Measured memory_bytes: 167460
import sys
input = sys.stdin.readline
r,c,n = map(int,input().split())
xy = [list(map(int,input().split())) for i in range(n)]
ls = []
for x1,y1,x2,y2 in xy:
  if (x1 in (0,r) or y1 in (0,c)) and (x2 in (0,r) or y2 in (0,c)):
    k = []
    for x,y in ((x1,y1),(x2,y2)):
      if x == 0:
        s = 2*r+2*c-y
      if x == r:
        s = r+y
      if y == 0:
        s = x
      if y == c:
        s = 2*r+c-x
      k.append(s)
    t = len(ls)//2+1
    ls.append((k[0],t))
    ls.append((k[1],t))
if not ls:
  print("YES")
  exit()
ls.sort()
lsi = list(map(list,zip(*ls)))[1]
m = len(lsi)
stack = []
for i in lsi:
  if not stack:
    stack.append(i)
  else:
    if stack[-1] == i:
      stack.pop()
    else:
      stack.append(i)
if stack:
  print("NO")
else:
  print("YES")

Measured memory_bytes: 70440
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = 1e9;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

int main() {
    vi a(3);
    REP(i,3)cin>>a[i];
    sort(a.begin(),a.end());
    cout<<a[1]-a[0]+a[2]-a[1]<<endl;
    return 0;
}


Measured memory_bytes: 256
n;main(c,k){for(read(0,k,4);read(0,&c,1);)c>10?n=c-48?k=c-49,n+1:n--?n%=k?k-6&&k-8?3:4:5,!putchar(k?" adgjmptw"[k]+n:".,!? "[n]):0:putchar(c);}

Measured memory_bytes: 0
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n; cin>>n;
    vector<int> a(n,0);
    rep(i,n) cin>>a[i];
    rep(i,n){
        if(a[i]%2) continue;
        if(a[i]%3 && a[i]%5){
            cout<<"DENIED"<<endl;
            return 0;
        }
    }
    cout<<"APPROVED"<<endl;
}


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

using namespace std;

const int MAX = 100010;

vector<int> tree(MAX, INT_MAX);

void update(int i, int x, int n)
{
    if(n > 0)
        tree[i] = x;
}

int find(int l, int r)
{
    if(l == r)
        return tree[l];
        
    int MIN = INT_MAX;
    
    for(int i = l; i <= r; i++)
        if(tree[i] < MIN)
            MIN = tree[i];
            
    return MIN;
}

int main() 
{
    int n, q, x, y, z;
    scanf("%d %d", &n, &q);
    
    for(int i = 0; i < q; i++)
    {
        scanf("%d %d %d", &x, &y, &z);
        
        if(x == 0)
            update(y, z, n);
        else if(x == 1)
            printf("%d\n", find(y, z));
    }
    
    return 0;
}


Measured memory_bytes: 3420
#include <bits/stdc++.h>
#define SZ(v) ((int)((v).size()))
using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<int> a(n+1);
	ll res = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i) {
		if (a[i] & 1) { --a[i]; if (a[i+1]) ++a[i+1]; }
		res += a[i];
	}
	cout << res/2 << "\n";
}


Measured memory_bytes: 3632
//Volume5-0587
import java.util.Scanner;

class Main {

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int n   = sc.nextInt(),
		    m   = sc.nextInt(),
		    max = m;

		while(n-- > 0){
			m += sc.nextInt();
			m -= sc.nextInt();
			if(max < m){
				max = m;
			}
			if(m < 0){max = 0; break;}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 41932
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, m, ans = 1;
	cin >> n >> m;
	int a = m / n;
	for(int i = a; i >= 1; i--)
		if(m % i == 0){
			ans = i;
			break;
		}
	cout << ans;
	return 0;
}

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

int main() {
  int a,b,c,d,e,k;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  cin >> k;
  int answer = 0;
  int hantei = b-a;
  if (hantei > k){
     answer = 1;
  }
  hantei = c-a;
  if (hantei > k){
     answer = 1;
  }
  hantei = d-a;
  if (hantei > k){
     answer = 1;
  }
  hantei = e-a;
  if (hantei > k){
     answer = 1;
  }
  hantei = c-b;
  if (hantei > k){
     answer = 1;
  }
  hantei = d-b;
  if (hantei > k){
     answer = 1;
  }
  hantei = e-b;
  if (hantei > k){
     answer = 1;
  }
  hantei = d-c;
  if (hantei > k){
     answer = 1;
  }
  hantei = e-c;
  if (hantei > k){
     answer = 1;
  }
  hantei = e-d;
  if (hantei > k){
     answer = 1;
  }
  if(answer == 1){
  cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
s = gets.chomp.split("")
q = gets.to_i
q.times do
  order = gets.chomp.split(" ")
  if order[0] == "print"
    for i in order[1].to_i..order[2].to_i do
      print s[i]
    end
    puts
  elsif order[0] == "reverse"
    s[order[1].to_i..order[2].to_i] = s[order[1].to_i..order[2].to_i].reverse
  elsif order[0] == "replace"
    s[order[1].to_i..order[2].to_i] = order[3].split("")
  end
end

Measured memory_bytes: 9028
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char a[11], b[11], c[11];
  scanf("%s%s%s", a, b, c);
  for (int i = 0; i < 11; i++)
  {
    if (a[i] == '\0')
    {
      if (a[i - 1] == b[0])
      {
        for (int j = 0; j < 11; j++)
        {
          if (b[j] == '\0')
          {
            if (b[j - 1] == c[0])
            {
              puts("YES");
              return 0;
            }
          }
        }
      }
    }
  }
  puts("NO");
  return 0;
}

Measured memory_bytes: 128