akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("in", "r", stdin),freopen("out", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int n, k;
int v[N];
int dp[N];
int f(int i){
    if(i == n - 1)return 0;
    int &ans = dp[i];
    if(ans != -1)return ans;
    ans = 1e9;
    for(int j = 1; j <= k; j++){
        if(i + j < n)
            ans = min(ans, f(i + j) + abs(v[i] - v[i + j]));
    }
    return ans;
}
int main(){
    //FL;
    FIN;
    cin >> n >> k;
    fore(i, 0, n)cin >> v[i];
    cls(dp, -1);
    cout << f(0) << '\n';
    EjecuteTime;
    return 0;
}       

Measured memory_bytes: 10756
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(int &x)
{
    register int c = gc();x = 0;int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

int main()
{
    fsscan();
    int a,b;
    cin>>a>>b;
    if(a+b<=16&&a<=8&&b<=8)
    cout<<"Yay!";
    else
    cout<<":(";
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	in := IOInitialize()
	a500, b100, c50, x := Int(in), Int(in), Int(in), Int(in)

	count := 0
	for i := 0; i < a500+1; i++ {
		for jj := 0; jj < b100+1; jj++ {
			for kkk := 0; kkk < c50+1; kkk++ {
				if i*500+jj*100+kkk*50 == x {
					count++
				}
			}
		}
	}

	fmt.Println(count)

}

//////////
//
//

func IOInitialize() *bufio.Scanner {
	t := bufio.NewScanner(os.Stdin)
	t.Split(bufio.ScanWords)
	return t
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("\t\tThere is a FALSE not to want.")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("\t\tError:Failed to convert text to int,")
	}
	return value
}

func IntArray(s *bufio.Scanner, size int) []int {
	deepArray := make([]int, size)
	for i := range deepArray {
		deepArray[i] = Int(s)
	}
	return deepArray
}

func GraphSetByEdge(s *bufio.Scanner, v int) [][]int {
	g := make([][]int, v)
	for i := range g {
		g[i] = make([]int, 0)
	}
	for xxNonUsedInLoopI := 0; xxNonUsedInLoopI < v-1; xxNonUsedInLoopI++ {
		a, b := Int(s)-1, Int(s)-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	return g
}

Measured memory_bytes: 640
#include <stdio.h> 
int main(void)
{
	int house[5][4][11] = { 0 };
	int n, i, j, k, a, b, c, d;
	scanf("%d", &n);
	for (n;n > 0;n--)
	{
		scanf("%d %d %d %d", &a, &b, &c, &d);
		house[a][b][c] += d;
	}
	for (i = 1;i < 5;i++)
	{
		for (j = 1;j < 4;j++)
		{
			for (k = 1;k < 11;k++)
			{
				printf(" %d", house[i][j][k]);
			}
			printf("\n");
		}
		if (i == 4)
		{
			break;
		}
		printf("####################\n");
	}
	
	return 0;
}

Measured memory_bytes: 612
def main():
    n=int(input())
    t,a=map(int,input().split())
    h=map(int,input().split())
    temp=[t-x*0.006 for x in h]
    m = (-1, 10**3)
    for i,v in enumerate(temp):
        d = abs(a-v)
        if m[1] >= d:
            m = (i, d)
    print(m[0]+1)
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 9220
#import <Foundation/Foundation.h>
typedef long long Int;
int main(){
	Int n;
	scanf("%lld",&n);
	Int *a = (Int*)malloc(sizeof(Int)*n);
	Int *b = (Int*)malloc(sizeof(Int)*n);
	for(Int i=0;i<n;i++) scanf("%lld %lld",a+i,b+i);
	Int ans=0;
	for(Int i=n-1;i>=0;i--){
		Int r = (a[i]+ans)%b[i];
		if(r>0) r = b[i]-r;
		ans += r;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 7008
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF      1000000000.0
#define EPS      1e-10
#define MOD      1000000007
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

int dp[50001];
int n;
int m;


int main(){
    rep(i,50001) dp[i] = MOD;
    cin >> n >> m;
    dp[0] = 0;
    rep(i,m){
        int c;
        cin >> c;
        for(int j = 0; j < n; j++){
            if(j+c > n) break;
            if(dp[j] == -1) continue;
            if(dp[j+c] < dp[j]+1) continue;
            dp[j+c] = dp[j]+1;
        }
    }
    cout << dp[n] << endl;
}

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

int f[1000],a,b;


int main()
{
	f[1]=1;
	int i;
	for(i=2;i<=999;i++)
	{
		f[i]=f[i-1]+i;
	}
	scanf("%d %d",&a,&b);
	printf("%d",f[b-a]-b);
	return 0;
}

Measured memory_bytes: 128
n=int(input())
li = list(map(int,input().split()))

ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            m=max(li[i],li[j],li[k])
            s=li[i]+li[j]+li[k]
            if li[i] != li[j] and  li[i] != li[k] and li[j] != li[k] and s-m>m:
                ans+=1

print(ans)

Measured memory_bytes: 9088
#include <cstdio>
#include <cstdlib>
#include <cstring>
 
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
 
using namespace std;
 
const int MaxN = 1e5 + 5;
 
typedef long long ll;
 
ll a[MaxN];
 
ll gcd(ll a, ll b)
{
	if (!b)
		return a;
	return gcd(b, a % b);
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	ll x = a[1], mx = 0, mn = 1e9 + 5;
	bool flag = false;
	for (int i = 1; i <= n; i++)
	{
		if (a[i] == k)
			flag = true;
		x = gcd(x, a[i]);
		mx = max(mx, a[i]);
		mn = min(mn, a[i]);
	}
	if (flag)
	{
		cout << "POSSIBLE" << endl;
		return 0;
	}
	if (k % x != 0 || k > mx)
		cout << "IMPOSSIBLE" << endl;
	else
		cout << "POSSIBLE" << endl;
#ifdef GLOBAL_DEBUG
	system("pause");
#endif
	return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

ll solve()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> k(n);
    vector<ll> l(n);
    vector<ll> r(n);
    vector<ll> mae(n,0);
    vector<ll> usiro(n,0);
    vector<vector<ll>> nanim(n);
    vector<vector<ll>> naniu(n);
    priority_queue<ll> pqm;
    priority_queue<ll> pqu;
    ll ans = 0;
    for(i = 0;i < n;++i){
        cin >> k.at(i) >> l.at(i) >> r.at(i);
        --k.at(i);
        if(l.at(i) >= r.at(i)){
            ans += l.at(i);
            ++mae.at(k.at(i));
            nanim.at(k.at(i)).push_back(r.at(i) - l.at(i));
        }else{
            ans += r.at(i);
            if(k.at(i) == n-1){
                ans += l.at(i) - r.at(i);
                continue;
            }
            else{
                ++k.at(i);
                ++usiro.at(k.at(i));
                naniu.at(k.at(i)).push_back(l.at(i) - r.at(i));
            }
        }
    }
    for(i = 0;i < n;++i){
        if(i != 0) mae.at(i) += mae.at(i-1);
        rep(j,nanim.at(i).size()){
            pqm.emplace(nanim.at(i).at(j));
        }
        if(mae.at(i) > i+1){
            ll tmp = mae.at(i) - (i+1);
            mae.at(i) -= tmp;
            rep(j,tmp){
                auto x = pqm.top();
                pqm.pop();
                ans += x;
            }
        }
    }
    for(i = n-1;i >= 0;--i){
        if(i != n-1) usiro.at(i) += usiro.at(i+1);
        rep(j,naniu.at(i).size()){
            pqu.emplace(naniu.at(i).at(j));
        }
        if(usiro.at(i) > n-i){
            ll tmp = usiro.at(i) - (n-i);
            usiro.at(i) -= tmp;
            rep(j, tmp){
                auto x = pqu.top();
                pqu.pop();
                ans += x;
            }
        }
    }
    
    return ans;
}

int main()
{
    ll i,j;
    ll t;
    cin >> t;
    for(i = 0;i < t;++i){
        ll ans = solve();
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 27576
#include <iostream>
using namespace std;
int main(void){
    int n,s,l,f=0;
    long long a[200000],b[200000];
    cin>>n;
    s=0;l=n-1;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=n-1;i>=0;i--){
        if(f==0){b[s]=a[i];s++;f=1;}
        else {b[l]=a[i];l--;f=0;}
    }
    for(int i=0;i<n-1;i++)cout<<b[i]<<" ";
    cout<<b[n-1];
    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    ll n,m;
    ll ans = 0;
    cin >> n >> m;
    ans = n*(n-1)/2;
    UnionFind uf(n);
    vector<int> a(m),b(m);
    vector<ll> ansv;
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        a[i]--,b[i]--;
    }
    for (int i = 0; i < m; ++i) {
        ansv.push_back(ans);
        if(uf.issame(a[m-1-i],b[m-1-i])) continue;
        ans -= uf.size(a[m-1-i])*uf.size(b[m-1-i]);
        uf.merge(a[m-1-i],b[m-1-i]);
    }
    for (int i = 0; i < m; ++i) {
        cout << ansv[m-1-i] << endl;
    }
    return 0;
}

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

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    int n;cin >>n;
    ll t,a;t=a=1;
    for (int i = 0; i < n; ++i) {
        ll T,A;cin >>T>>A;
        ll rt=(t-1)/T+1;
        ll ra=(a-1)/A+1;
        ll k=max(rt,ra);
        t=k*T;
        a=k*A;
    }
    ll ans=t+a;
    cout <<ans <<endl;
}


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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;


signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> inv(n);
    int i = 0;
    for(auto& x : a){
        cin >> x;
        inv[--x] = ++i;
    }
    for(int i = 0; i < n; ++i)
        cout << inv[i] << " \n"[i == n - 1];
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
    int N, ans=0;
    cin >> N;
    set<int> s;
    for(int i=0; i<N; i++){
	int tmp;
	cin >> tmp;
	s.insert(tmp);
    }
    cout << s.size() << endl;


} 




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


signed main(){
   
   int n;
   cin>>n;
 
   bool ans = false;
   while(n){
   	if (n%10 == 7){
   		ans =true;
   		break;}
   		n/=10;
   }   
   
   if(ans){
   	cout<<"Yes\n";
   }else{
   	cout<<"No\n";
   }

	return 0;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<string, int> duo;

#define TT template<typename T>
#define TTF template<typename T, typename F>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline void Out(T&x){cout<<x;}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline int ubnd(T&v,ET(T)&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T)&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF inline void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF inline void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
#undef TT
#undef TTF
#undef ET

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}

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

bool match(const string& a, const string& b)
{
  for (int i = 0; i < (int)a.size(); i++){
    if (a[i] != '*' && a[i] != b[i]) return false;
  }
  return true;
}

int main()
{
  int n, m;
  while (cin >> n >> m, n){
    vector<duo> vd;
    inpt(vd, n, [](){
      string s;
      int v;
      cin >> s >> v;
      return duo(s, v);
      });
    int tot = 0;
    for (int i = 0; i < m; i++){
      string s;
      cin >> s;
      for (const auto& d : vd){
        string x;
        int v;
        tie(x, v) = d;
        if (match(x, s)) tot += v;
      }
    }
    cout << tot << endl;
  }
  return (0);
}

// priority_queue queue deque front stringstream max_element min_element insert count make_tuple

Measured memory_bytes: 1220
#include <stdio.h>
#define N 500000

int heap[N], H;

void swap(int *a, int *b) {
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

int right(int id) {
    return (2 * id) + 1;
}

int left(int id) {
    return 2 * id;
}

int parent(int id) {
    return id / 2;
}

void maxHeapify(int id) {
    int largest = id;

    if (left(id) <= H && heap[left(id)] > heap[largest]) {
        largest = left(id);
    }
    if (right(id) <= H && heap[right(id)] > heap[largest]) {
        largest = right(id);
    }

    if (largest != id) {
        swap(&heap[largest], &heap[id]);
        maxHeapify(largest);
    }
}

void buildMaxHeap(){
    int i;
    for (i = H/2; i > 0; i--) {
        maxHeapify(i);
    }
}

int main() {
    int i;

    scanf("%d", &H);

    for (i = 1; i <= H; i++) {
        scanf("%d", &heap[i]);
    }

    buildMaxHeap();

    for (i = 1; i <=H; i++) {
        printf(" %d", heap[i]);
    }
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 3736
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int A,B;
    scanf("%d %d",&A,&B);
    if(A>B){
        printf("%d\n",2*A-1);
    }else if(A==B){
        printf("%d\n",2*A);
    }else{
        printf("%d\n",2*B-1);
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


long long thirds[100001];
void prepare(int N)
{
    for(int i=0;i<=N;i++)
    {
    thirds[i+1]=thirds[i]*3;//third[i]:=3^(i);
    if(thirds[i+1]>mod)thirds[i+1]%=mod;
    }
}


int main(){

string s;
cin>>s;

long long ans=0;
int N=s.size();
thirds[0]=1;
thirds[1]=3;
prepare(N);
long long total=1;
/*
for(int i=1;i<=N-1;i++){
    total=thirds[i-1]*2;
    if(total>mod)total%=mod;
    ans+=total;
    if(ans>mod)ans%=mod;
}
*/
//cout<<ans<<endl;
long long  p=1;

for(int i=0;i<N;i++){
    if(s[i]=='1'){
        long long zero=p*thirds[N-(i+1)];
        p*=2;
        if(p>mod)p%=mod;
        if(zero>mod)zero%=mod;
        ans+=zero;
        if(ans>mod)ans%=mod;
    }
}
ans+=p;
if(ans>mod)ans%=mod;

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

5


1111111111111111111

162261460
162261460

162261460
*/

Measured memory_bytes: 1280
### constant

MAX_P = 10000

### subroutines

def gen_primes(max_p)
  primes = Array.new(max_p + 1){true}
  primes[0] = primes[1] = false

  for p in (2..max_p)
    if primes[p]
      for q in (p * p).step(max_p, p)
        primes[q] = false
      end
    end
  end

  for p in (2..max_p)
    if primes[p]
      yield p
    end
  end

end

### main

p_nums = []
gen_primes(MAX_P){|p| p_nums << p }
num_p = p_nums.length

p_pairs = p_nums[0, num_p - 1].zip(p_nums[1, num_p - 1])
num_pp = p_pairs.length

while true
  n = gets.strip.to_i
  break if n == 0

  k = num_pp - 1
  while p_pairs[k][1] > n
    k -= 1
  end

  while p_pairs[k][0] != p_pairs[k][1] - 2
    k -= 1
  end

  puts p_pairs[k].join(' ')
end

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

int main()
{
    int N, M;
    cin >> N >> M;

    if (N == 1 && M == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    const int init = -1;
    vector<int> ans(N, init);
    int s, c;
    for (int i = 0; i < M; i++)
    {
        cin >> s >> c;
        s--;
        if (ans[s] == init)
        {
            ans[s] = c;
        }
        else if (ans[s] != c)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    if (ans.front() == 0)
    {
        if (N == 1)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << -1 << endl;
        }
        return 0;
    }
    ans.front() = max(1, ans.front());
    for (int a : ans)
    {
        if (a == init)
        {
            cout << 0;
        }
        else
        {
            cout << a;
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
/*------------------------------------------------,
|  __                                       __    |
| |  |--.-----.---.-.----.----.-----.-----.|  |_  |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _| |
| |_____|_____|___._|____|____|_____|   __||____| |
|                                   |__|          |
`------------------------------------------------*/
#include<algorithm>
#include<array>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdint>
#include<deque>
#include<functional>
#include<iomanip>
#include<ios>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long ll; using namespace std;
#define INF 2147483647
#define MOD 10000007
#define REP(counter, limit) for (long long counter = 0; counter < limit; counter++)
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){cin.tie(0);ios::sync_with_stdio(0); /*cout<<fixed<<setprecision(20);*/};}setupios;
int main() {

  int n;
  cin>>n;
  vector<int> h(n);
  REP(i,n)cin>>h[i];

  vector<int> dp(n-1);
  dp[0]=0;
  for(int i = 1;i < n;i++){
    if(i==1){
      dp[i]=abs(h[i]-h[i-1]);
    }else{
      dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
    }
  }
  cout<<dp[n-1]<<endl;

}


Measured memory_bytes: 1024
//### In The Name Of GOD ###

//%% Remember; (((He))) is The (((Accepter))) %%

// GOD IS GREATER ...

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef long double ld ;

#define int ll
#define pb push_back
#define bp pop_back
#define pf push_front
#define fp pop_front
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())
#define sg(a, b) (a + b - 1) / b

const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 8 * 1000 * 1000 + 200;
const int MAXN =  100 * 1000 + 1;
const int MLOG = 18;
const int NMAX = 20;

signed main(){
	IO;
	int x;
	cin >> x;
	cout << x / 11 * 2 + sg(x % 11, 6);
}

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

typedef long long ll;

int N, K;
vector<int> A, B;
string sk;
vector<string> vs;

void dig_str(int n, string &s) {
	s = "";
	while (n > 0) {
		string c = (n & 1) ? "1" : "0";
		s += c;
		n >>= 1;
	}
}

int str_dig(string s) {
	int n = 0;
	int t = 1;
	for (int i = 0; i < (int)s.length(); ++i) {
		if (s[i] == '1')
			n += t;
		t *= 2;
	}
	return n;
}

void make_vs(int n) {
	vs.push_back(sk);
	for (int i = 1; i < (int)sk.length(); ++i) {
		if (sk[i] == '0')
			continue;
		string c = sk;
		c[i] = '0';
		c = c.substr(i);
		string r = string(i, '1');
		r += c;
		vs.push_back(r);
	}
}

ll solve(void) {
	ll max_val = 0LL;
	for (int i = 0; i < (int)vs.size(); ++i) {
		string s = vs[i];
		int x = str_dig(s);
		ll val = 0LL;
		for (int j = 0; j < N; ++j) {
			int y = A[j];
			int z = x | y;
			if (z == x)
				val += (ll)B[j];
		}
		max_val = max(val, max_val);
	}
	return max_val;
}

int main(void) {
	cin >> N >> K;
	A.resize(N);
	B.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i] >> B[i];

	ll ans = 0LL;
	if (K == 0) {
		for (int i = 0; i < N; ++i) {
			if (A[i] == 0)
				ans += (ll)B[i];
		}
	}
	else {
		dig_str(K, sk);
		make_vs(K);
		ans = solve();
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;


int main(void)
{
	int N, L; cin >> N >> L;
	vector<string> S(N);
	rep(i, 0, N)cin >> S[i];
	sort(S.begin(), S.end());
	string ans;
	rep(i, 0, N)ans += S[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::Usize1;
use std::collections::HashMap;
use std::mem::swap;

#[derive(Clone, Copy, Debug, Default)]
struct Adjacent {
    to: usize,
}

#[derive(Clone, Debug, Default)]
struct Graph {
    n: usize,
    links: Vec<Vec<Adjacent>>,
}

impl Graph {
    fn new(n: usize) -> Graph {
        Graph {
            n,
            links: vec![vec![]; n],
        }
    }

    fn add_edge(&mut self, from: usize, to: usize) {
        self.links[from].push(Adjacent { to });
        self.links[to].push(Adjacent { to: from });
    }
}

fn pair_count(n: usize) -> i64 { (n * (n + 1) / 2) as i64 }

fn get_or_default<'a, T, U>(hm: &'a HashMap<T, U>, key: &T, def: &'a U) -> &'a U
    where
        T: std::cmp::Eq + std::hash::Hash,
{
    match hm.get(key) {
        Some(result) => result,
        None => def,
    }
}

fn dfs(v: usize, p: usize, colors: &Vec<usize>, g: &Graph, ans: &mut Vec<i64>) -> (HashMap<usize, usize>, usize) {
    let mut unable_count = HashMap::<usize, usize>::new();
    let mut subtree_count = 1usize;
    let cv = &colors[v];

    for u in &g.links[v] {
        if u.to == p { continue; }
        let result = dfs(u.to, v, colors, g, ans);
        subtree_count += result.1;

        ans[*cv] -= pair_count(result.1 - *get_or_default(&result.0, cv, &0));

        let mut merge = result.0;
        if unable_count.len() < merge.len() {
            swap(&mut unable_count, &mut merge);
        }
        for (c, ubl) in merge.iter() {
            *unable_count.entry(*c).or_insert(0) += *ubl;
        }
    }

    *unable_count.entry(*cv).or_insert(0) = subtree_count;

    (unable_count, subtree_count)
}

#[fastout]
fn main() {
    input! {
        n: usize,
        ccc: [Usize1; n],
        ab: [(Usize1, Usize1); n - 1],
    }

    // println!("{:?} {:?} {:?}", n, ccc, ab);

    let mut g = Graph::new(n);
    for (a, b) in ab {
        g.add_edge(a, b);
    }

    let mut ans = vec![pair_count(n); n];

    let (unable_count, subtree_count) = dfs(0, 0, &ccc, &g, &mut ans);

    assert_eq!(n, subtree_count);

    for c in 0..n {
        println!("{:?}", ans[c] - pair_count(n - get_or_default(&unable_count, &c, &0)));
    }
}

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

using namespace std;
int sumDigits ( int number ) {
    int sum = 0 ;
    while ( number != 0 ) {
        sum += number % 10 ;
        number /= 10 ;
    }
    return sum ;
}

bool isHarshad ( int number ) {
    return number % ( sumDigits ( number ) ) == 0 ;
}

int main(){
    int N;
    char yon[2][4] = {"No", "Yes"};
    cin >> N;
    cout << yon[isHarshad(N)];
    return 0;
}


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

int main() {
	int N, K;
	cin >> N >> K;
	if (K > (N - 1)*(N - 2)/2) {
		cout <<  -1 <<endl;
		return 0;
	}
	int tmp = (N - 1)*(N - 2) / 2 - K;
	cout <<tmp + N-1 << endl;
	for (int n = 2; n <= N; ++n) {
		cout << 1 << " " << n << endl;
	}
	for (int n = 2;n<=N;++n) {
		for (int m = n + 1;m<=N;++m) {
			if (0 == tmp) {
				return 0;
			}
			tmp--;
			cout << n << " "<<m <<  endl;

		}
	}
	return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n';

const int mxn = 2e5 + 1;
vector<int> edges[mxn], visi(mxn, 0);
int ans = 0, cnt = 0;
void dfs(int x){
    visi[x] = 1;
    ++cnt;
    for(auto u : edges[x]){
        if(visi[u]) continue;
        dfs(u);
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, m;cin>>n>>m;
    for(int i = 0; i < m; ++i){
        int x, y;cin>>x>>y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
    for(int i = 1; i <= n; ++i){
        if(!visi[i]){
            cnt = 0;
            dfs(i);
            ans = max(ans, cnt);
        }
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 21004
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <tuple>

constexpr size_t di[] = {size_t(-1), 0, 1, 0};
constexpr size_t dj[] = {0, size_t(-1), 0, 1};

int main() {
  size_t H, W;
  scanf("%zu %zu", &H, &W);

  std::vector<std::string> s(H);
  for (auto& si: s) {
    char buf[64];
    scanf("%s", buf);
    si = buf;
  }

  std::queue<std::pair<size_t, size_t>> q;
  int INF = 1e9;
  std::vector<std::vector<int>> dp(H, std::vector<int>(W, INF));
  dp[0][0] = 1;
  q.emplace(0, 0);
  bool reachable = false;
  while (!q.empty()) {
    size_t i, j;
    std::tie(i, j) = q.front();
    q.pop();
    if (i+1 == H && j+1 == W) {
      reachable = true;
      break;
    }

    for (int k = 0; k < 4; ++k) {
      size_t ni = i + di[k];
      size_t nj = j + dj[k];
      if (!(ni < H && nj < W)) continue;
      if (s[ni][nj] == '#') continue;
      if (dp[ni][nj] <= dp[i][j] + 1) continue;
      dp[ni][nj] = dp[i][j] + 1;
      q.emplace(ni, nj);
    }
  }

  if (!reachable) return puts("-1"), 0;
  int res = H*W - dp[H-1][W-1];
  for (const auto& si: s)
    res -= std::count(si.begin(), si.end(), '#');

  printf("%d\n", res);
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int a[305][305],b[305][305];
ll ans;

int main(){
    int n;
    cin>>n;
    rep(i,n){
        rep(j,n){
            cin>>a[i][j];
            b[i][j]=a[i][j];
            if(i<j) ans+=a[i][j];
        }
    }    

    rep(k,n){
        rep(i,n){
            rep(j,n){
                b[i][j]=min(b[i][j],b[i][k]+b[k][j]);
            }
        }
    }

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(a[i][j]!=b[i][j]){
                cout<<-1<<endl;
                return 0;
            }
            rep(k,n){
                if(k==i || k==j) continue;
                if(a[i][j]==a[i][k]+a[k][j]){
                    ans-=a[i][j];
                    k=n;
                }
            }
        }
    }

    cout<<ans<<endl;
}


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

using namespace std;
const int maxn =  1e6 + 50;
#define ll long long
#define ios std::ios::sync_with_stdio(false)
const ll INF(0x3f3f3f3f3f3f3f3fll);
const int inf(0x3f3f3f3f);
/*


ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll pow_mod(ll x,ll n,ll mod){ll res=1;while(n){if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}//xµÄn´Î·½mod


ll mult(ll a,ll b,ll p){a%=p;b%=p;ll r=0,v=a;while(b){if(b&1){r+=v;if(r>p)r-=p;}v<<=1;if(v>p)v-=p;b>>=1;}return r;}
ll quick_pow(ll a,ll b,ll p){ll r=1,v=a%p;while(b){if(b&1)r=mult(r,v,p);v=mult(v,v,p);b>>=1;}return r;}
bool CH(ll a,ll n,ll x,ll t)
{ll r=quick_pow(a,x,n);ll z=r;for(ll i=1;i<=t;i++){r=mult(r,r,n);if(r==1&&z!=1&&z!=n-1)return true;z=r;}return r!=1;}
bool Miller_Rabin(ll n)
{if(n<2)return false;if(n==2)return true;if(!(n&1))return false;ll x=n-1,t=0;while(!(x&1)){x>>=1;t++;}srand(time(NULL));
ll o=8;for(ll i=0;i<o;i++){ll a=rand()%(n-1)+1;if(CH(a,n,x,t))return false;}return true;}


*/

#define int long long
#define sc(t) scanf("%lld",&t)
#define pr(ans) printf("%lld\n",ans)
ll pow_mod(ll x,ll n,ll mod){ll res=1;while(n){if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}//xµÄn´Î·½mod
template<typename T>void read(T &res){bool flag=false;char ch;while(!isdigit(ch=getchar()))(ch=='-')&&(flag=true);
for(res=ch-48;isdigit(ch=getchar());res=(res<<1)+(res<<3)+ch - 48);flag&&(res=-res);}
typedef unsigned long long ULL;

int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
#define debug(x) cout << #x << " : " << x << '\n';
#define sb cout << "sb\n" << '\n';
#define fi first
#define se second
#define pb(a) push_back(a)
#define cn cout << '\n'

signed main()
{
    ios;
    int n;
    cin >> n;
    int num = n % 10;
    if(num == 2 || num == 4 || num == 5 || num == 7 || num == 9){
        cout << "hon";
    }
    else if(num == 3){
        cout << "bon";
    }
    else{
        cout << "pon";
    }
    cn;
    return 0;
}
/*

*/


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

template<class T>
struct Vec2
{
	Vec2(){}
	Vec2(T _x, T _y) : x(_x), y(_y) {}

	Vec2 operator+(const Vec2& rhs) const { return Vec2(x + rhs.x, y + rhs.y); }
	Vec2 operator-(const Vec2& rhs) const { return Vec2(x - rhs.x, y - rhs.y); }
	T sqlength() const { return x*x + y*y; }

	T x;
	T y;
};

int main()
{
	typedef Vec2<long long> Vec;
	long long x1, y1, r1, x2, y2, r2;
	cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2;
	long long dsq = (Vec(x1, y1) - Vec(x2, y2)).sqlength();
	if (dsq > (r1 + r2)*(r1 + r2)) cout << 4 << endl;
	else if (dsq == (r1 + r2)*(r1 + r2)) cout << 3 << endl;
	else if (dsq > (r1 - r2)*(r1 - r2)) cout << 2 << endl;
	else if (dsq == (r1 - r2)*(r1 - r2)) cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 3108
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int N, Y;
    cin >> N >> Y;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            if(i + j <= N){
                int k = N - (i + j);
                if(Y == i * 10000 + j * 5000 + k * 1000){
                    cout << i << ' ' << j << ' ' << k;
                    goto Exit;
                }
            }
        }
    }
    cout << "-1 -1 -1";
    Exit: ;

}

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

bool cal(int tmax, vector<int> a) {
  rep(i, n) a[i] %= tmax;
  sort(a.begin(), a.end());
  int m = accumulate(a.begin(), a.end(), 0) / tmax;

  return accumulate(a.begin(), a.begin()+n-m, 0) <= k;
}

int main() {
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int sum = accumulate(a.begin(), a.end(), 0);
  int tmp = sum + 1;

  while (--tmp) {
    if (sum % tmp != 0) continue;
	if (cal(tmp, a)) break;
  }
  cout << tmp << endl;
  return 0;
}   

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define LIM 1<<17
#define LL long long
/// TONI BO$$ was here
/// #MLC

using namespace std;

int lgput(int a,int b,int m)
{
    if(b==0) return 1;
    if(b==1) return a%m;
    if(b%2) return ((LL)a*(lgput(((LL)a*a)%m,b/2,m)))%m;
    if(!(b%2)) return (lgput(((LL)a*a)%m,b/2,m))%m;
}
int v[100001];
int main()
{
    int n,i,x,j;
    scanf("%d",&n);
    for(i=1; i<=n; i++){
        scanf("%d",&x);
        if(x && i==1){
            printf("0");
            return 0;
        }
        v[x]++;
    }
    j=n-1;
    while(v[j]==0) j--;
    for(i=0; i<=j; i++)
        if(!v[i]) break;
    if(i<j || v[0]>1)
    {
        printf("0");
        return 0;
    }
    LL rez=1;
    for(i=1; i<=j; i++)
        rez=(rez*lgput(v[i-1],v[i],998244353))%998244353;
    printf("%lld",rez);

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
const int maxn = 2e5 + 10;
const int inf = 1e9;
int n, m;
int D[maxn], col[maxn];
vector<pii> E[maxn];
vector<int> G[maxn];
bool flag[maxn];
pii ed[maxn];
void dfs(int x, int fa)
{
	col[x] = col[fa] ^ 1;
	for(auto v : G[x])
		if(v != fa)
			dfs(v, x);
}
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) scanf("%d", &D[i]);
	for(int i = 1; i <= m; ++i)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(mp(v, i));
		E[v].push_back(mp(u, i));
		ed[i] = mp(u, v);
	}
	for(int i = 1; i <= n; ++i)
	{
		pii Min = E[i][0];
		for(int j = 1; j < E[i].size(); ++j)
		{
			pii cur = E[i][j];
			if(D[Min.first] > D[cur.first] || (D[Min.first] == D[cur.first] && Min.second > cur.second))
				Min = cur;
		}
		if(D[i] < D[Min.first])
		{
			puts("-1");
			return 0;
		}
		flag[Min.second] = 1;
	}
	for(int i = 1; i <= m; ++i)
		if(flag[i])
		{
			int u = ed[i].first, v = ed[i].second;
			G[u].push_back(v);
			G[v].push_back(u);
		}
	memset(col, -1, sizeof col);
	col[0] = 0;
	string ans;
	for(int i = 1; i <= n; ++i)
	{
		if(col[i] == -1)
			dfs(i, 0);
		ans += col[i] ? 'W' : 'B';
	}
	cout << ans << endl;
	for(int i = 1; i <= m; ++i)
		if(flag[i])
		{
			int u = ed[i].first, v = ed[i].second;
			printf("%d\n", max(D[u], D[v]));
		}
		else
			printf("%d\n", inf);
	return 0;
}

Measured memory_bytes: 23712
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello{
    public static void Main(){
        var N = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var hash = new HashSet<int>();
        var fill = 0;
        var ans = 0;//最小値
        var ans2 = 0;//最大値
        for(var i = 0;i < N;i++){
            if(a[i] >= 3200){
                fill++;
                continue;
            }
            hash.Add(a[i] / 400);
        }
        
        if(hash.Count == 0){
            ans = 1;
            ans2 = fill;
        }else{
            ans = hash.Count;
            ans2 = fill + hash.Count; 
        }
        
        
        Console.WriteLine($"{ans} {ans2}");
    }
}

Measured memory_bytes: 13280
#include <iostream>

using namespace std;

int main(void)
{
	int a[3];
	int cnt5 = 0, cnt7 = 0;

	for (int i = 0; i < 3; i++)
	{
		cin >> a[i];
		if (a[i] == 5) cnt5++;
		if (a[i] == 7) cnt7++;
	}

	if (cnt5 == 2 && cnt7 == 1) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#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>;
 
 
int main() {
    int x,y;
    cin >> x >> y;
    if(y>=x*2&&y<=x*4&&y%2==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}
    
    

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <algorithm>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=300010;
int n;
lint a[N],_a[N],fl[N],fr[N],g[N],h[N];
int stk[N],ss;
inline void psh(int x){
	for(;ss>=2&&(g[x]-g[stk[ss-1]])*(x-stk[ss-2])>=(g[x]-g[stk[ss-2]])*(x-stk[ss-1]);ss--);
	stk[ss++]=x;
}
inline void pop(int i){
	for(;ss>=2&&g[stk[ss-1]]-g[stk[ss-2]]<=(lint)i*(stk[ss-1]-stk[ss-2]);ss--);
}
inline void gpre(){
	_a[0]=0;
	for(int i=1;i<=n;i++){
		_a[i]=_a[i-1]+a[i];
	}
}
inline void gg(lint f[],int x){
	g[x]=f[x]+_a[x]+(((lint)x*(x-1))>>1);
}
inline void dp(lint f[]){
	gpre();
	g[0]=0;
	ss=0;
	stk[ss++]=0;
	for(int i=1,j;i<=n;i++){
		pop(i),j=stk[ss-1];
		f[i]=max(f[i-1],g[j]-(lint)i*j+(((lint)i*(i+1))>>1)-_a[i]);
		gg(f,i),psh(i);
	}
}
lint tmp[N];
inline void solve(int l,int r,bool flag){
	if(l==r){
		if(l==0)return;
		apmax(h[l],fl[l-1]+(1-a[l])+fr[r+1]);
		return;
	}
	int m=(l+r-flag)>>1;
	solve(l,m,flag),solve(m+1,r,flag);
	ss=0;
	for(int i=l;i<=m;i++){
		gg(fl,i);
		psh(i);
	}
	for(int i=m+1,j;i<=r;i++){
		pop(i),j=stk[ss-1];
		tmp[i]=g[j]-(lint)i*j+(((lint)i*(i+1))>>1)-_a[i]+fr[i+1];
	}
	for(int i=r;i>m;i--){
		apmax(tmp[i-1],tmp[i]);
		apmax(h[i],tmp[i]);
	}
}
inline void work(bool flag){
	reverse(a+1,a+n+1);
	reverse(h+1,h+n+1);
	reverse(fl+1,fl+n+1);
	reverse(fr+1,fr+n+1);
	for(int i=1;i<=n;i++){
		swap(fl[i],fr[i]);
	}
	gpre();
	solve(0,n,flag);
}
int main(){
	n=ni;
	for(int i=1;i<=n;i++){
		a[i]=ni;
	}
	dp(fl);
	reverse(a+1,a+n+1);
	dp(fr);
	reverse(a+1,a+n+1);
	reverse(fr+1,fr+n+1);
	memset(h,128,sizeof(h));
	work(0),work(1);
	for(int tot=ni;tot--;){
		int p=ni,x=ni;
		printf("%lld\n",max(fl[p-1]+fr[p+1],h[p]+a[p]-x));
	}
	return 0;
}

Measured memory_bytes: 20224
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1e18L + 5
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		
		ll n,W;
		cin>>n>>W;

		ll w[n], v[n];

		ll valsum = 0;
		for(ll i=0; i<n; i++) {
			cin>>w[i]>>v[i];
			valsum += v[i];
		}
		vector<ll> dp(valsum + 1, inf);		
		dp[0] = 0;

		for(ll i=0; i<n; i++) {
			for(ll value = valsum; value>=v[i]; value--) {
				dp[value] = min(dp[value], dp[value-v[i]] + w[i]);
			}
		}

		for(ll i=valsum; i>=0; i--) {
			if(dp[i]<=W) {
				cout<<i<<endl;
				break;
			}
		}

		return 0;
	}


Measured memory_bytes: 4036
N, K = map(int, input().split())

numList = []
for _ in range(N):
    numList.append(list(map(int, input().split())))

numList.sort(key=lambda x:x[0])

idx = 0
while True:
    K = K - numList[idx][1]
    if K <= 0:
        print(numList[idx][0])
        exit()
    idx = idx + 1

Measured memory_bytes: 29144
n,m=map(int,input().split())

b=[list(map(int,input().split())) for i in range(m)]

if n==1:
  for i in range(10):
    
    flg=True
    for l in range(m):
      if str(i)[b[l][0]-1]  != str(b[l][1]):
        flg=False
    if flg==True:
      print(i)
      break
  else:
    print(-1)
  
else:  
  for i in range(10**(n-1),10**n):
    flg=True
    for j in range(m):
      if str(i)[b[j][0]-1] != str(b[j][1]):
        flg=False
    
    if flg==True:
      print(i)
      break
  if flg == False:
    print(-1)
      

Measured memory_bytes: 3064
#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>;

int main() {
  int a,b;
  cin >> a >> b;
  if(a >= 10 || b >= 10) cout << -1 << endl;
  else cout << a*b << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N, M;
    ll Ai, Bi;
    cin >> N >> M;
    map<ll, array<set<ll>,2>> graph;//num, inList, outList
    map<ll, ll> solution;
    for(int i=0;i<N-1+M;i++){
        cin >> Ai >> Bi;
        if(graph.count(Ai)==0) graph[Ai] = array<set<ll>,2>();
        if(graph.count(Bi)==0) graph[Bi] = array<set<ll>,2>();
        graph[Bi][0].insert(Ai);
        graph[Ai][1].insert(Bi);
    }

    queue<ll> root;
    for(auto m : graph){
        if(m.second[0].size()==0){
            root.push(m.first);
            solution[m.first] = 0;
        }
    }
    while(!root.empty()){
        auto r = root.front(); root.pop();
        auto out = graph[r][1];
        for(auto s : out){
            if(graph[s][0].size()==1){
                root.push(s);
                solution[s] = r;
            }
            graph[s][0].erase(r);
        }
    }
    for(auto s : solution){
        cout<<s.second<<endl;
    }

    return 0;
}

Measured memory_bytes: 35968
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>

#define fr(i,b,e) for(int i=(b); i<(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long ll;

int chk(vector<int> a){
    int n=a.size();
    fr(i,0,n){
        cout << a.at(i);
    }
    cout << endl;
}

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

ll power(ll a,ll n){
    if(n==1){
        return a;
    }
    else if(n&1==1){
        --n;
        return power(a,n)*a;
    }else{
        n=n>>1;
        return power(a,n)*power(a,n);
    }
}

int main(void){
    int N;
    cin >> N;
    vector<int> x(N);
    int p=0;
    fr(i,0,N){
        cin >> x.at(i);
        p+=x.at(i);
    }
    p=round(double(p)/double(N));
    
    int s=0;
    int t;
    fr(i,0,N){
        t=(x.at(i)-p);
        s+=t*t;
    }
    cout << s << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.lang.*;

class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] strs = br.readLine().split(" ");
    int N = Integer.parseInt(strs[0]);
    int L = Integer.parseInt(strs[1]);
    int sum = 0, asymptote = 0;
    
    for (int i=1; i <= N; i++) {
      if (i == 1) {
        asymptote = (L+i-1) > -1 ? 999 : -999;
      }
      
      if ((L+i-1) > -1 && asymptote > -1) {
        asymptote = Math.min(asymptote, (L+i-1));
      } else {
        asymptote = Math.max(asymptote, (L+i-1));
      }
      sum += (L+i-1);
    }
    System.out.println(sum - asymptote);
  }
}

Measured memory_bytes: 21332
#include <iostream>
#include <string>
using namespace std;
string temp[7]={"SUN","MON", "TUE", "WED", "THU", "FRI", "SAT"};
int main()
{
   string t; cin>>t;
     for(int i=0;i<7;i++)
	 {
	 	if(t==temp[i])
		{
			cout<<7-i<<endl;
		}
	 }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int score[100][5];
int sum[100] = {0};
int n;
int max, min;

int main() {
  int i, j;

  scanf("%d", &n);
  while (n != 0) {
    for (i = 0; i < n; i++) {
      for (j = 0; j < 5; j++) {
        scanf("%d", &score[i][j]);
      }
    }

    for(i=0; i<n; i++){
      for(j=0; j<5; j++){
        sum[i] = sum[i] +  score[i][j];
      }
    }

    max = sum[0];
    min = sum[0];

    for(i=1; i<n; i++){
      if(sum[i] >= max){
        max = sum[i];
      }
      if(min >= sum[i]){
        min = sum[i];
      }
    }

    for(i=0; i<100; i++){
      sum[i] = 0;
    }

    printf("%d %d\n", max, min);
    max = 0;
    min = 0;
    scanf("%d", &n);
  }

  return 0;
}

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

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

  if(a+b == 15)
    cout << "+" << endl;
  else if(a*b == 15)
    cout << "*" << endl;
  else
    cout << "x" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,j,k,l,a,b,c;
  i=0;
  a=0;
  j=0;
  while(1){
    scanf("%d",&j);
    i=i+j;
    a += 1;
    if(a==4){
      break;
    }
  }
  k=0;
  b=0;
  l=0;
  while(1){
    scanf("%d",&l);
    k=k+l;
    b += 1;
    if(b==4){
      break;
    }
  }
    if(i > k){
      printf("%d\n",i);
    }
    if(i==k){
      printf("%d\n",i);
    }
    else{
	printf("%d\n",k);
      }
    return 0;
}

Measured memory_bytes: 0
import sys
s=input()
for i in range(len(s)):
    if i==len(s)-1:
        print("No")
        sys.exit()
    if s[i]=="C":
        for j in range(i+1,len(s)):
            if s[j]=="F":
                print("Yes")
                sys.exit()
            if j==len(s)-1:
                print("No")
                sys.exit()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
	int nn,mm;
	while(cin>>nn>>mm){
		if(nn==0&&mm==0) break;
		int r;
		cin>>r;
		int a[r][4];
		for(int i=0;i<r;i++){
			for(int j=0;j<4;j++){
				cin>>a[i][j];
			}
		}
		int q;
		cin>>q;
		for(int i=0;i<q;i++){
			int ts,te,m,to=0,ct=0;
			cin>>ts>>te>>m;
			for(int j=0;j<r;j++){
				if(a[j][2]==m){
					if(a[j][0]<=te){
						if(ct==0){
							if(a[j][0]<ts) to=to-ts;
							else to=to-a[j][0];
						}
						if(a[j][3]==1) ct++;
						else ct--;
						if(ct==0){
							if(a[j][0]<ts) to=to+ts;
							else to=to+a[j][0];
						}
					}
					else{
						if(ct>0) to=to+te;
						goto end;
					}
				}
			}
			end:;
			cout<<to<<endl;
		}
	}
    return 0;
}

Measured memory_bytes: 1172
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<queue>
#define For(i,j,k)  for(int i=j;i<=k;++i)
#define Dow(i,j,k)  for(int i=k;i>=j;--i)
#define ll long long
#define inf 1e9
#define pb push_back
#define local freopen("in.in","r",stdin);
#define c(x,y)  ((x-1))*m+(y)
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read()
{
	int t=0,f=1;char c=gc();
	while(!isdigit(c))  {if(c=='-') f=-1;c=gc();}
	while(isdigit(c))   t=t*10+c-'0',c=gc();
	return t*f;
}
inline void write(int x){if(x<0) {putchar('-');write(-x);return;}if(x>=10)    write(x/10);putchar(x%10+'0');}
inline void writeln(int x){write(x);puts("");}
inline void write_p(int x){write(x);putchar(' ');}

int n,ans;
char s[1010][1010],a[1010][1010];
int check(int x){
	for (int i=0;i<n;i++)	For(j,0,n-1)a[i][j]=s[i][(j+x)%n];
	for (int i=0;i<n;i++)	For(j,0,n-1)if (a[i][j]!=a[j][i])return 0;
	return 1;
} 
signed main(){
	n=read();
	For(i,0,n-1)
		scanf("%s",s[i]);
	For(l,0,n-1)
		if (check(l))ans+=n;
	writeln(ans);
}

Measured memory_bytes: 896