akhauriyash/Code-Regression huggingface dataset:
// (c) 2020, redotter

// Roses are red
// The Tardis is blue
// The Doctor once said
// Rose Tyler...

#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#pragma comment(linker, "/stack:500000000")
#endif

#define pb push_back
#define the(a) (a).begin(), (a).end()
#define ft first
#define sd second
#define endl "\n"
#define forn(i, n) for (int i = 0; i < (n); i++)
#define forr(i, s, n) for (int i = (s); i < (n); i++)

using i64 = long long;
using i32 = int;
using f64 = long double;

template <class T> using vec = vector<T>;
using str = string; using p64 = pair<i64, i64>;
using v64 = vec<i64>; using vv64 = vec<v64>;
using s64 = set<i64>; using m64 = map<i64, i64>;
template <size_t Size1> using a64 = array<i64, Size1>;
template <size_t Size1, size_t Size2> using aa64 = array<a64<Size2>, Size1>;
template <class T> using hash_set = unordered_set<T>;
template <class T, class U> using hash_map = unordered_map<T, U>;

mt19937 gen(998244353);
const i64 inf = numeric_limits<i64>::max() / 2;

template <class T> inline i64 len(const T& a) { return (i64)(a.size()); }
inline void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
template <class T, class S>
inline bool check_min(T& a, S b) { if (a > b) return a = b, 1; return 0; }
template <class T, class S>
inline bool check_max(T& a, S b) { if (a < b) return a = b, 1; return 0; }

void read() {}
template<class T, class ...U>
void read(T& a, U& ...b) { cin >> a; read(b...); }
void print() {}
template<class T, class ...U>
void print(const T& a, const U& ...b) { cout << a << " "; print(b...); }
void println() { cout << "\n"; }
template<class T, class ...U>
void println(const T& a, const U& ...b) { cout << a << " "; println(b...); }

struct Problem {
	void files(str in, str out) {
#ifdef ONLINE_JUDGE
		freopen(in.c_str(), "r", stdin), freopen(out.c_str(), "w", stdout);
#endif
	}
	void solve(), input();
	void many() { i32 t; cin >> t; while (t--) input(), solve(); }
	void make(bool mt = 0) { if (mt) many(); else input(), solve(); }
} problem;

signed main() {
	fast();
	problem.make();
#ifdef _DEBUG
	println(); println("[finished]"); system("pause > nul");
#endif
	return 0;
}

i64 n, k;
v64 a;

void Problem::solve() {
	v64 dp(n, inf);
	dp[0] = 0;
	forr(i, 1, n) {
		forr(j, max(i - k, 0ll), i) {
			check_min(dp[i], dp[j] + abs(a[j] - a[i]));
		}
	}
	println(dp[n - 1]);
}

void Problem::input() {
	read(n);
	k = 2;
	a.resize(n);
	forn(i, n) read(a[i]);
}


Measured memory_bytes: 4760
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            String s = in.next();
            int count = 0;
            for (int i = 0; i < s.length(); i++) {
                char ch = s.charAt(i);
                if (ch == 'R'){
                    count++;
                    if (i < s.length() - 1 && s.charAt(i+1) == 'S'){
                        break;
                    }
                }
            }
            out.println(count);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

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

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


Measured memory_bytes: 32852
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

//dfsで探索してく
struct Edge {int to, id;};
vector<vector<Edge>> tree;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1) {
    int k = 1;
    rep(i,tree[v].size()) {
        int u = tree[v][i].to; int ei = tree[v][i].id;
        if(u==p) continue;
        if(k==c) k++;
        ans[ei] = k; k++; 
        dfs(u, ans[ei], v);
    }
}
int main() {
    int n; 
    cin >> n;
    tree.resize(n);
    ans.resize(n-1);
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree[a].push_back((Edge){b, i});
        tree[b].push_back((Edge){a, i});
    }
    dfs(0);
    //使った色の数
    int mx = 0;
    rep(i,n) mx = max(mx, int(tree[i].size()));
    cout << mx << endl;

    //使った色列挙
    rep(i,n-1) {
        cout << ans[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 8320
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
      int b = sc.nextInt();
      if(a<=b){
         for(int i = 0;i<b;i++){
            System.out.print(a);
         }
      }else{
         for(int i = 0;i<a;i++){
            System.out.print(b);
         }
      }
   }
}


Measured memory_bytes: 35824
a, b = map(int, input().split())
if a == 1 and b == 1:
    print('Draw')

elif a == 1 and (2 <= b and b <= 13):
    print('Alice')

elif b == 1 and (2 <= a and a <= 13):
    print('Bob')

elif a > b:
    print('Alice')

elif b > a:
    print('Bob')

elif a == b:
    print('Draw')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;


LL mod = 1000000007;

int main()
{
	LL n, k;
	cin >> n >> k;

	vector<LL> h(n);

	for (auto &e : h) {
		cin >> e;
	}

	LL ans = 0;

	if (n >= k) {
		sort(h.begin(), h.end());
		//LL s = 0;

		for (LL i = 0; i < n-k; ++i) {
			ans += h[i];
		}
	}

	cout << ans << "\n";

	
}

Measured memory_bytes: 1792
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 100000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
const int N=2005;
//Code begin....

int dp[40], su[3005];
VI v;

int main ()
{
    int a, b, c, d, e, f;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
    int V=f/100;
    dp[0]=1;
    FOR(i,1,V) {
        if (i>=a) dp[i]|=dp[i-a];
        if (i>=b) dp[i]|=dp[i-b];
    }
    su[0]=1;
    FOR(i,1,f) {
        if (i>=c) su[i]|=su[i-c];
        if (i>=d) su[i]|=su[i-d];
    }
    FOR(i,0,f) if (su[i]) v.pb(i);
    PII ans=mp(0,0); double p=0;
    FOR(i,0,V) {
        if (dp[i]==0) continue;
        int x=min(i*e,f-100*i);
        int l=0, r=v.size(), mid;
        while (l<r) {
            mid=(l+r)>>1;
            if (l==mid) break;
            if (v[mid]<=x) l=mid;
            else r=mid;
        }
        double pp=(double)v[l]*100/(i+v[l]);
        if (p<=pp) p=pp, ans=mp(i*100+v[l],v[l]);
    }
    printf("%d %d\n",ans.first,ans.second);
    return 0;
}


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

int main(void){
	int ans=0;
	while(1){
		string s;
		cin >> s;
		if(cin.eof()) break;
		int n=s.size();
		int cur=0;
		rep(i,n){
			if(isdigit(s[i])){
				cur=cur*10+(s[i]-'0');
			}else{
				ans+=cur;
				cur=0;
			}
		}
		ans+=cur;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1188
#include<stdio.h>

int main(void){
	int a,b,c,d,n,ans,f,l[4];
	
	while(scanf("%d",&n)!=EOF){
		ans=0;
		for(l[0]=0;l[0]<=9;l[0]++){
			for(l[1]=0;l[1]<=9;l[1]++){
				for(l[2]=0;l[2]<=9;l[2]++){
					for(l[3]=0;l[3]<=9;l[3]++){
						if(l[0]+l[1]+l[2]+l[3]==n)ans++;
						if(l[3]>n)break;
					}
					if(l[2]>n)break;
				}
				if(l[1]>n)break;
			}
			if(l[0]>n)break;
		}
		printf("%d\n",ans);
		
	}
	
	return 0;
	
}

Measured memory_bytes: 0
N,X=map(int,input().split())
x=list(map(int,input().split()))
for i in range(N):
    x[i]=abs(x[i]-X)
from fractions import gcd
if N==1:
    a=x[0]
else:
    a=gcd(x[0],x[1])
    if N!=2:
      for i in range(2,N):
         a=gcd(a,x[i])
print(a)

Measured memory_bytes: 14224
import sys
a = []
for l in sys.stdin:
    a.append(list(map(int,l.split())))
    
for i in a:
  if i[0]==0 and i[1]==0:
    break
  print('#'*i[1])
  for x in range(1,i[0]-1):
    print('#'+'.'*(i[1]-2)+'#')
  print('#'*i[1])

  print('\r')


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

int n;
vector<int>to[10005];
vector<int>c;
ll mx=0;
vector<int>ans;
int cur=0;
void dfs(int u,int p=-1){
    ans[u]=c[cur];
    if(p!=-1)mx+=c[cur];
    cur++;
    for(int v:to[u]){
        if(v==p)continue;
        if(ans[v]!=-1)continue;
        dfs(v,u);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--,b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    c.resize(n);
    rep(i,n)
    {
        int ci;
        cin>>ci;
        c.push_back(ci);
    }
    sort(c.rbegin(),c.rend());
    ans.assign(n,-1);
    dfs(0);
    cout<<mx<<endl;
    rep(i,n){
        printf("%d%c",ans[i],i==n-1?'\n':' ');
    }
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=100000000000000LL;
const int MAX=100001;
const double EPS=1e-10;
int main() {
    int n;
    cin>>n;
    vector<P> v;
    set<int> st;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        v.push_back(P(a,i));
    }
    ll ans=0;
    sort(v.begin(),v.end());
    st.insert(-1);st.insert(n);
    for(auto e:v){
        st.insert(e.second);
        auto itr=st.find(e.second);
        ll l,r;
        itr--;
        l=*itr;
        itr++;itr++;
        r=*itr;
        ans+=(ll)(e.second-l)*(ll)(r-e.second)*(ll)e.first;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 11248
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    // cout << min(a[n-1] - a[0],k-a[n-1]+a[n-2]) << endl;
    int ans = min(a[n-1] - a[0],k-a[n-1]+a[n-2]);
    rep(i,1,n){
        chmin(ans,k-a[i]+a[i-1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
array<int, 101> factoring(int x) {
    array<int, 101> ret{};
    for (int i = 2; x >= i * i; i++) {
        while (x % i == 0) {
            ret[i]++;
            x /= i;
        }
    }
    if (x > 1) ret[x]++;
    return ret;
}

signed main() {
    int n;
    cin >> n;
    vector<int> as(n);
    REP(i, n) { cin >> as[i]; }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int b, e;
        cin >> b >> e;
        reverse(as.begin() + b, as.begin() + e);
    }
    int k = 0;
    for (int x : as) {
        k++;
        cout << x;
        if (k != n) {
            cout << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 3224
N, H, W = input().split()
N = int(N)
H = int(H)
W = int(W)
cnt = 0

for i in range(N):
	sozai_h, sozai_w = input().split()
	sozai_h = int(sozai_h)
	sozai_w = int(sozai_w)
	if sozai_h >= H and sozai_w >= W:
		cnt += 1
print (cnt)

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

int main(){
	string s;
	int k;
	cin >> s >> k;
	rep(i, s.size()){
		if(s[i] != 'a' && 'z' - s[i] + 1 <= k){
			k -= 'z' - s[i] + 1;
			s[i] = 'a';
		}
		if(i+1 == s.size() && k > 0){
			s[i] = s[i] - 'a';
			s[i] = (s[i] + k) % 26;
			s[i] = s[i] + 'a';
		}
	}
	cout << s << endl;
	
}

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

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))    
#define OUT(P) cout << (P) << endl    
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl    
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;    
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)    
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)    
typedef long long ll;    
const long DIVIDE = 1e9+7;

int sum_digits(int num);    
template <class T>    
vector<T> copy_vector(vector<T> vec);    
int gcd(int a, int b);    
// ****** print functions ****** //
template <class T, class U>
void print_pairs(const vector<pair<T, U>> pairs);
template <class K, class V>
void print_map(const map<K, V> m);


int main() {    

    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    for(int i=0; i<n; i++) {
        cin >> l[i];
    }

    int pt = 0;
    int cnt = 0;
    for(int i=0; i<n; i++) {
        if(pt <= x) {
            cnt++;
            pt += l[i];
        }
    }
    if(pt <=x) {
        cnt++;
    }
    cout << cnt << endl;
    //vector<int> pt(n+1);
    //pt[0] = 0;
    //for(int i=1; i<n+1; i++) {
    //    pt[i] = pt[i-1] + l[i-1];
    //}
    //int cnt=0;
    //for(int i=0; i<n+1; i++) {
    //    if(pt[i] <= x) {
    //        cnt++;
    //    }
    //}
    //cout << cnt << endl;
    return 0;    
}    

/******************************/    
/***** DECRARED FUNCTIONS *****/    
/******************************/    

int sum_digits(int num) {    
    int rtn = 0;    
    while(num != 0) {    
        int tmp = num % 10;    
        rtn += tmp;    
        num /= 10;    
    }    
    return rtn;    
}    

// vectorのコピー    
template <class T>    
vector<T> copy_vector(vector<T> vec) {    
    vector<T> rtn;    
    rtn.reserve(vec.size());    
    copy(vec.begin(), vec.end(), back_inserter(rtn));    
    return rtn;    
}    

// ユークリウッドの互除法    
int gcd(int a, int b) {    
    if(b==0) return a;    
    else return gcd(b, a % b);    
}

template <class T, class U>
void print_pairs(const vector<pair<T, U>> &pairs) {
    for(int i=0; i<pairs.size(); i++) { 
        cout << "(" << pairs[i].first << ", " << pairs[i].second << ")" << " "; 
    } 
    cout << endl;
}

template <class K, class V>
void print_map(const map<K, V> &m) {
    for(auto it=m.cbegin(); it!=m.cend(); it++) {
        cout << it->first << ": " << it->second << endl;
    }
}


Measured memory_bytes: 256
#import numpy as np
from copy import deepcopy
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
#AB = [list(map(int, input().split())) for _ in range(N-1)]
edge = [[] for i in range(N)]
seen = [0]*N
colors = [0]*(N-1)
#for val in AB:
for i in range(N-1):
    x, y = list(map(int, input().split()))
    edge[x-1].append((i, y-1))
    edge[y-1].append((i, x-1))

lenedge = [len(val) for val in edge]
mledge = max(lenedge)
root = lenedge.index(mledge)
print(mledge)


que = deque()
que.append([(root, -1)])
while que[0]:
    nque = []
    cque = que.popleft()
    #print('cstack:', cstack)
    for tupl in cque:
        index, pcolor = tupl
        seen[index] = 1
        color = 1
        if (color == pcolor): color += 1
        for tupl2 in edge[index]:
            findex, edgei = tupl2
            if seen[edgei] == 0:
                nque.append((edgei, color))
                colors[findex] = color
                color += 1
                if (color == pcolor): color += 1
    que.append(nque)

#pri(color)

for color in colors:
    print(color)



Measured memory_bytes: 70816
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

ll q;
vector<ll> vec;

int main() {
    fastInp;

    ll n, k;
    cin >> n >> k;
    vec.resize(n);
    for (int i = 0; i < n; i++) cin >> vec[i];

    ll ans = 0, curS = 0;
    for (int i = 0; i < k; i++) curS += vec[i];
    vector<ll> pref, suf;
    pref.push_back(0);
    suf.push_back(0);
    for (int i = 0; i < n; i++) {
        pref.push_back(pref.back() + max(vec[i], 0ll));
    }

    for (int i = n - 1; i >= 0; i--) {
        suf.push_back(suf.back() + max(vec[i], 0ll));
    }

    reverse(suf.begin(), suf.end());

    for (int i = 0; i < n - k + 1; i++) {
        ans = max(ans, pref[i] + suf[i + k] + max(curS, 0ll));
        curS -= vec[i];
        if (i + k < n) curS += vec[i + k];
    }
    cout << ans;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define strep(i,n) for(static int i=0;i<n;i++)
#define ll long long

int main(){
    string S ;
    cin >> S ;
    int count=0 ;
    int m[12] ;
    rep(i,S.size()){
        if(S[i]=='A'||S[i]=='T'||S[i]=='G'||S[i]=='C') count++ ;
        else count=0 ;
        m[i]=count ;
    }
    int x=0 ;
    rep(i,S.size()){
        x=max(x,m[i]) ;
    }
    cout<<x<<endl ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=100001;
int n,A[M];
long long Ans[M];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	bool fl=1;
	long long t=0;
	for(int i=n;i>=1;i--){
		if(fl)t+=A[i];
		else t-=A[i];
		fl^=1;
	}
	for(int i=1;i<=n;i++){
		Ans[i]=t;
		t=(A[i]-t/2)*2;
	}
	for(int i=1;i<n;i++)printf("%lld ",Ans[i]);
	printf("%lld\n",Ans[n]);
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define ll long long 
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
signed main(){
  ll n,k,a[10000],x,y,sum=0;
  cin>>n>>k;
  rep(i,n) cin>>a[i];
  rep(i,n){
    x = a[i] * 2;
    y = (k - a[i]) * 2;
    sum += min(x,y);
  }
  cout<<sum<<"\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int now = 1;
  int ans = 0;
  rep(i, n){
    if (a[i] == now) now++;
    else ans++;
  }
  if (ans == n) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


double sum[200010];

int main(void){
    ll n,k;
    cin>>n>>k;
    vector<ll>p(n);
    for(ll i=0;i<n;i++)cin>>p[i];
    sum[0]=0.0;
    for(ll i=0;i<n;i++){
        sum[i+1]=(double)sum[i]+(double)(p[i]+1)/2;
    }
    double ans =(double)0.0;
    for(ll i=1;i<=n-k+1;i++){
        double tmp=(double)sum[i+k-1]-sum[i-1];
        ans = max(ans,tmp);
    }
    printf("%.10lf",ans);
    cout<<endl;
    return 0;
}

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

typedef long long ll;
int h[100005], dp[100005], N, K;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> K;

    for(int i = 0; i < N; i++)
        cin >> h[i];
    dp[1] = abs(h[1] - h[0]);
    for(int lvl = 2; lvl < N; lvl++) {
        dp[lvl] =  dp[lvl - 1] + abs(h[lvl] - h[lvl - 1]);
        for(int jmp = 2; jmp <= K && jmp <= lvl; jmp++)
            dp[lvl] =  min(dp[lvl], dp[lvl - jmp] + abs(h[lvl] - h[lvl - jmp]));
    }
        

    cout << dp[N - 1] << "\n";

    return 0;
}


Measured memory_bytes: 1024
'use strict';
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim();
  var S = Number(inputs);
  var h = Math.floor(S/3600);
  //var m = Math.floor((S-(h*3600))/60);
  var m = Math.floor(S%3600/60);
  var s = S%60;
  console.log([h,m,s].join(':'));
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15500
N = int(input())
S1 = input()
S2 = input()
ans = 1
MOD = 10**9+7
i = 0
flag = True

while i<N:
    if S1[i]==S2[i]:
        if i==0:
            ans *= 3
        else:
            if flag:
                ans *= 2
        
        i += 1
        flag = True
    else:
        if i==0:
            ans *= 6
        else:
            if flag:
                ans *= 2
            else:
                ans *= 3
        
        i += 2
        flag = False
    
    ans %= MOD

print(ans)

Measured memory_bytes: 61836
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;
LL powmod(LL a, LL b)
{
	LL ret = 1;
	while (b)
	{
		if (b & 1) ret = ret * a % INF;
		b >>= 1;
		a = a * a % INF;
	}
	return ret;
}
LL fact(LL n)
{
	LL ans = 1;
	for (int i = 1; i <= n; i++)
		ans = ans * i % INF;
	return ans;
}
LL C(LL n, LL m)
{
	return fact(n) * powmod(fact(m), INF - 2) % INF * powmod(fact(n - m), INF - 2) % INF;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int x, y;
	cin >> x >> y;
	if ((x + y) % 3)
	{
		puts("0");
		return 0;
	}
	LL tot = (x + y) / 3;
	int n = x - tot, m = y - tot;
	if (n < 0 || m < 0)
	{
		puts("0");
		return 0;
	}
	cout << C(n + m, m) << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<iostream>
#include <stdlib.h>
#include<ctime>
#include <string>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if (a < 10 && a>0 && b < 10 && b>0)printf("%d\n",a*b);
	else printf("-1\n");
	return 0;
}


Measured memory_bytes: 256
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
dif_list = [0] * n
max_list = [0 for i  in range(n)]
a.reverse()
max_list[0] = a[0]
for i in range(1,n):
    max_list[i] = max(max_list[i-1], a[i])
max_list.reverse()
a.reverse()
for i in range(0,n):
    dif_list[i] = max_list[i] - a[i]

k = max(dif_list)
count = 0
for i in range(n):
    if k == dif_list[i]:
        count += 1
print(count)

Measured memory_bytes: 14224
#ifdef HIRO
#include "../stdc++.h"
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#include <bits/stdc++.h>
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;

int main() {
#ifdef HIRO
  string file_path(QUIZ);
  ifstream cin(file_path + "/input.txt");
  std::cin.rdbuf(cin.rdbuf());
#endif
  // int n;
  // int m;
  // cin >> n;
  // cin >> m;
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int s=max(a,c);
  int e=min(b,d);
  cout <<(e-s>0?e-s:0);
  


  // cout << ans << endl;
  return 0;
}



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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;

using vc = vector<char>;
using vi = vector<int>;
using vll = vector<ll>;

int N, K;
vi arr;

bool isPossible(int factor) {
    vi res (N);
    F0R(i, N) {
        res[i] = arr[i] % factor;
    }
    sort(res.begin(), res.end());

    vll lcum (N+1);
    vll rcum (N+1);
    F0R(i, N) lcum[i+1] = lcum[i] + res[i];
    R0F(i, N) rcum[i] = rcum[i+1] + res[i];
    ll moves = K + 1;
    F0R(i, N+1) {
        ll RHS = (N-i) * factor - rcum[i];
        if (abs(lcum[i] - RHS) % factor == 0) {
            moves = min(moves, max(lcum[i], RHS));
        }
    }
    return moves <= K;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N >> K;
    arr.resize(N);
    F0R(i, N) cin >> arr[i];
    
    int total = 0;
    F0R(i, N) total += arr[i];

    ROF(i, 1, total + 1) {
        if (total % i != 0) continue;
        if (isPossible(i)) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#define NOT_FREE -1
#define FREE 1

int row[8],col[8],dpos[15],dneg[15],N=8,Q[8];

void putQueen(int);
void PrintBoard();

int main(){
  int k,i,r,c,j;

  for(i=0;i<N;i++){
    row[i]=col[i]=FREE;
    for(j=0;j<N;j++){
      Q[j]=0;
    }
  }
  for(i=0;i<2*N-1;i++) dpos[i]=dneg[i]=FREE;
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    row[r]=c;
    col[c]=dpos[r+c]=dneg[r-c+N-1]=NOT_FREE;
    Q[r]=2;
  }
  putQueen(0);
  return 0;
  
  
}

void putQueen(int i){
  int j;
  static int count=0;
  if(i==N){
    if(count==0){
    PrintBoard();
    count++;
    return;
    }
  }
  if(count==1)return;
  for(j=0;j<N;j++){
    if(Q[i]==2)putQueen(i+1);
    if(Q[i]==2||col[j]==NOT_FREE||dpos[j+i]==NOT_FREE||dneg[i-j+N-1]==NOT_FREE){
      continue;
    }
    
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    putQueen(i+1);
    col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }

  
}

void PrintBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }

}

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

int GCD(int a, int b) {
    while (b != 0) {
        int t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int main() {
    int n;
    cin >> n;
    int a[n], l[n], r[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    l[0] = a[0];
    for (int i = 1; i < n; i++) {
        l[i] = GCD(l[i - 1], a[i]);
    }

    r[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
        r[i] = GCD(r[i + 1], a[i]);
    }

    int res = max(l[n - 2], r[1]);
    for (int i = 1; i <= n - 2; i++) {
        res = max(res, GCD(l[i - 1], r[i + 1]));
    }

    cout << res;
    return 0;
}


Measured memory_bytes: 1408
m = 10**9+7

n = int(input())
a = list(map(int, input().split()))

inv_cum = [0]
for i in range(1,n+1):
    inv_cum.append((inv_cum[-1] + pow(i, m-2, m)) % m)

fn = 1
for i in range(2,n+1):
    fn = (fn * i) % m

r = 0
for j in range(n):
    r = (r + (inv_cum[n-j] + inv_cum[j+1] - 1) * a[j]) % m

print(r * fn % m)

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm> 
#include <functional>	
using namespace std;

int main() {
	int a, b, B=0;
	cin >> a >> b;
	int c = b - a;
	for (int i = 1; i <= c; i++) {
		B += i;
	}
	cout << B - b << endl;

	return 0;
}

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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0,1,0,-1};
constexpr int dj[] = {1,0,-1,0};

bool solve(){
    int N, M, K, E, V;
    cin >> M >> N >> K >> E;
    if(M == 0) return false;
    V = N+M+2;
    vector<vector<P> > g(V);
    vector<int> C(M);
    for(int i=0;i<M;i++){
        cin >> C[i];
    }
    for(int i=0;i<E;i++){
        string s[2];
        int si[2], d;
        cin >> s[0] >> s[1] >> d;
        for(int j=0;j<2;j++){
            if(s[j]=="H") si[j] = 0;
            if(s[j]=="D") si[j] = N+1;
            if(s[j][0]=='L') si[j] = stoi(s[j].substr(1,int(s[j].size())-1));
            if(s[j][0]=='C') si[j] = stoi(s[j].substr(1,int(s[j].size())-1))+N+1;
        }
        g[si[0]].push_back(P(si[1], d));
        g[si[1]].push_back(P(si[0], d));
    }
    vector<vector<int> > dist(1<<M, vector<int>(V, INF));
    dist[0][0] = 0;
    for(int S=0;S<1<<M;S++){
        priority_queue<P,vector<P>,greater<P> > que;
        for(int i=0;i<V;i++){
            que.push(P(dist[S][i],i));
        }
        while(!que.empty()){
            P p = que.top();
            que.pop();
            int v = p.second;
            if(dist[S][v] < p.first) continue;
            for(auto e : g[v]){
                int u = e.first, d = e.second;
                if(u < N+2){
                    if(dist[S][u] > dist[S][v] + d*K){
                        dist[S][u] = dist[S][v] + d*K;
                        que.push(P(dist[S][u], u));
                    }
                }else{
                    int idx = u-(N+2);
                    if((S>>idx)&1) continue;
                    int T = S|(1<<idx);
                    if(dist[T][u] > dist[S][v] + d*K - C[idx]){
                        dist[T][u] = dist[S][v] + d*K - C[idx];
                    }
                }
            }
        }
    }
    int ans = INF;
    for(int S=0;S<1<<M;S++){
        ans = min(ans, dist[S][N+1]);
    }
    cout << ans << endl;
    return true;
}

int main(){
    while(solve());
    return 0;
}



Measured memory_bytes: 3220
#include <iostream>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  int count = 1;
  for(int i = 0; i < n; i++){
    if((i + 1) != n){
      if(s[i] != s[i + 1]){
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    int a,b,w;
    cin >> w >> a >> b;
    if(a+w < b){
        cout << b-a-w << "\n";
    }else if(b+w < a){
        cout << a - b-w << "\n";
    }else{
        cout << 0 << "\n";
    }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, x, n) for(int i = x; i < (int)(n); i++)
#define ALL(n) begin(n), end(n)
//struct cww{cww(){ios::sync_with_stdio(false);cin.tie(nullptr);}}star;
const long long INF = numeric_limits<long long>::max();

int main() {
  char s[4];
  scanf("%s", s);

  if (s[0] == s[1] && s[1] == s[2]) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }
  return 0;
}


Measured memory_bytes: 256
# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")
# conv_matrix = lambda l: ["".join(l[i : i + 100]) for i in range(0, len(l), 100)]
A, B = map(int, input().split())

mat = [["."] * 100 for _ in range(50)] + [["#"] * 100 for _ in range(50)]
# for mati in mat:
#     print("".join(mati))

# mat[0][3] = "#"
# mat[3][6] = "#"
# for mati in mat:
#     print("".join(mati))
# exit()

black_count = 1
white_count = 1

for i in range(0, 50, 2):
    if black_count == B:
        break
    for j in range(0, 100, 2):
        if black_count == B:
            break
        mat[i][j] = "#"
        black_count += 1
for i in range(1, 50, 2):
    if white_count == A:
        break
    for j in range(0, 100, 2):
        if white_count == A:
            break
        mat[-i][j] = "."
        white_count += 1

print(100, 100)
for mati in mat:
    print("".join(mati))


Measured memory_bytes: 66108
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	char c;
	set<string> st;
	rep(i, n) {
		string s;
		cin >> s;
		if (i != 0) {
			if (c != s[0]) {
				cout << "No" << endl;
				return 0;
			}
		}
		if (st.count(s)) {
			cout << "No" << endl;
			return 0;
		}
		st.insert(s);
		c = s[s.size() - 1];
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    map<char,ll> can;
    string s1,s2;
    cin>>s1>>s2;
    vector<ll> v[26];//なんばんめにあるか
    vector<ll> vi(26);//
    vector<ll> po(26,0);//pointer
    rep(i,s1.size()){
        can[s1[i]]++;
        v[s1[i]-'a'].push_back(i+1);
        vi[s1[i]-'a']++;
    }


    vector<ll> sv(s2.size());
    rep(i,s2.size()){
        if(can[s2[i]]==0){
            cout<<-1<<endl;
            return 0;
        } else{

        }
    }
    ll ans=v[s2[0]-'a'][0];
    ll sum=s1.size();
    ll pre=v[s2[0]-'a'][0];

    for(int i=1;i<s2.size();i++){
        ll k=s2[i]-'a';
        auto itr=upper_bound(v[k].begin(),v[k].end(),pre);



      //  cout<<k<<" "<<pre<<" "<<(itr-v[k].begin())<<endl;
        if((itr-v[k].begin())==v[k].size()){
           //cout<<pre<<sum<<endl;
            ans+=sum-pre;
            pre=0;
            i--;
        }else{
            ans-=pre;
            ans+=v[k][itr-v[k].begin()];
            pre=v[k][itr-v[k].begin()];
        }
    }
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
    long long int n,i,ans=0,minus=0,min,minnum;
    scanf("%lld", &n);
    long long int a[n];
    for(i=0; i<n; i++) scanf("%lld", &a[i]);
    for(i=0; i<n; i++) if(a[i]<0) minus++;
    if(minus%2==0)
    {
        for(i=0; i<n; i++) ans+=llabs(a[i]);
        printf("%lld", ans);
        return 0;
    } 
    else
    {
        min=llabs(a[0]);
        minnum=0;
        for(i=1; i<n; i++)
        {
            if(llabs(a[i])<min)
            {
                min=llabs(a[i]);
                minnum=i;
            } 
        }
        for(i=0; i<n; i++)
        {
            if(i==minnum) ans-=llabs(a[i]);
            else ans+=llabs(a[i]);
        }
        printf("%lld", ans);
        return 0;
    }
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  string s;
  cin >> N >> s;
  vector<int> ans(N);
  char ani[] = {'S', 'W'};
  rep(i, 2) rep(j, 2) {
    ans[0] = i;
    ans[1] = j;
    REP(k, 1, N-1) {
      if(ans[k] == 0) {
        ans[k+1] = (s[k] == 'o' ? ans[k-1] : 1-ans[k-1]);
      } else {
        ans[k+1] = (s[k] == 'x' ? ans[k-1] : 1-ans[k-1]);
      }
    }
    bool ok = true;
    REP(i, N-1, N+1) {
      if(!((s[i%N] == 'o' &&
            ((ans[i%N] == 0 && ans[i-1] == ans[(i+1)%N]) ||
             (ans[i%N] == 1 && ans[i-1] != ans[(i+1)%N]))) ||
           (s[i%N] == 'x' &&
            ((ans[i%N] == 0 && ans[i-1] != ans[(i+1)%N]) ||
             (ans[i%N] == 1 && ans[i-1] == ans[(i+1)%N]))))) {
        ok = false;
      }
    }
    if(ok) {
      rep(k, N) cout << ani[ans[k]];
      cout << "\n";
      return 0;
    }

  }
  cout << -1 << "\n";
  return 0;
}


Measured memory_bytes: 3692
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

	READV(N);
	ordered_set A;
	READAR(V,N);
	FORI(i,0,N)
	{
		A.insert(V[i]);
	}
	ll ans=0;
	FORI(i,0,N)
	{
		FORI(j,i+1,N)
		{
			ll k1=A.order_of_key(V[i]+V[j]);
			ll k2=A.order_of_key(abs(V[i]-V[j])+1);
			ll ans1=k1-k2;
			if(V[i]>(abs(V[i]-V[j])))
			{
				ans1--;
			}
			if(V[j]>(abs(V[i]-V[j])))
			{
				ans1--;
			}
			ans+=ans1;
		}
	}
	cout<<ans/3<<endl;

	return 0;
}

Measured memory_bytes: 384
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w,d = list(map(int, input().split()))
v = [[0]*(h+w) for _ in range(h+w)]
dd = {(0,0): "R", (0,1): "Y", (1,0): "G", (1,1): "B"}
for i in range(h+w):
    for j in range(h+w):
        v[i][j] = dd[(i//d)%2, (j//d)%2]
ans = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        ans[i][j] = v[i+j][i-j+w]
for i in range(h):
    write("".join(ans[i]))

Measured memory_bytes: 91924
import Data.List
divisor :: Int
divisor = 1000000007
solve :: Int -> Int -> Int
solve n m =
    case abs (n-m) of
         0 -> 2 *: (factMod n) *: (factMod m)
         1 -> (factMod n) *: (factMod m)
         _ -> 0

(*:) :: Int -> Int -> Int
(*:) x y = (x*y) `mod` divisor

factMod :: Int -> Int
factMod n = foldl1' (*:) [n, n-1..1]

main = do
    [n,m] <- map read . words <$> getLine
    print $ solve n m

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

public class Main {
  private 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;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int h = sc.nextInt();
    int a = sc.nextInt();
    System.out.println(h % a == 0 ? h / a : h / a + 1);
  }
}

Measured memory_bytes: 21076
n = int(input())
cards = [[0 for i in range(13)] for j in range(4)]

for x in range(n):
    a, b = input().split()
    if a == 'S':
        a_num = 0
    elif a == 'H':
        a_num = 1
    elif a == 'C':
        a_num = 2
    elif a == 'D':
        a_num = 3
    cards[a_num][int(b) - 1] = True

for j in range(4):
    for i in range(13):
        if cards[j][i] == False:
            if j == 0:
                print('S', i+1)
            elif j == 1:
                print('H', i+1)
            elif j == 2:
                print('C', i+1)
            elif j == 3:
                print('D', i+1)


Measured memory_bytes: 5608
abc = 'ABC'
N = int(input().rstrip())
S = input().rstrip()
ret = 0
if N == 3 and S == abc:
    ret = 1
else:
    for i in range(N - len(abc) + 1):
        if abc == S[i:i+3]:
            ret += 1
print(ret)


Measured memory_bytes: 2940