akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int A[N+2]; rep(i, N) cin >> A[i+1];
  A[0] = 0; A[N+1] = 0;

  int sum = 0; rep(i, N+1) sum += abs(A[i+1]-A[i]);
  rep(i, N) {
    int result = sum;
    if ((A[i]-A[i+1])*(A[i+1]-A[i+2])<=0) {
      result -= min(abs(A[i+1]-A[i]), abs(A[i+2]-A[i+1]))*2;
    }
    cout << result << endl;
  }
  return 0;
}

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

int main() {
  unsigned long N;
  std::cin >> N;

  std::vector<long> x(N), y(N);
  std::vector<long> h(N);
  for (unsigned long i = 0; i < N; i++) {
    std::cin >> x.at(i) >> y.at(i) >> h.at(i);
  }

  long H = 0;
  for (long cx = 0; cx <= 100; cx++) {
    for (long cy = 0; cy <= 100; cy++) {

      for (unsigned long i = 0; i < N; i++) {
        if (h.at(i) >= 1) {
          H = h.at(i) + std::abs(x.at(i) - cx) + std::abs(y.at(i) - cy);
          break;
        }
      }

      bool r = true;
      for (unsigned long i = 0; i < N; i++) {
        long h_ =
            std::max(0L, H - std::abs(x.at(i) - cx) - std::abs(y.at(i) - cy));
        if (h_ != h.at(i)) {
          r = false;
          break;
        }
      }
      if (r) {
        std::cout << cx << ' ' << cy << ' ' << H << std::endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
int height, width;
int i, r;

while (1) {
scanf("%d %d", &height, &width);

if (height == 0 && width == 0) break;

for (i = 0; i < height; i++) {
for (r = 0; r < width; r++) {
printf("#");
}
printf("\n");
}

printf("\n");
}

return 0;
}


Measured memory_bytes: 2084
#include<iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
#include <sstream>
using namespace std;

int main()
{
	std::vector<int> den(2);
	std::vector<int> bus(2);

	for(int i=0; i<2; i++) cin >> den[i];
	for(int i=0; i<2; i++) cin >> bus[i];

	sort(den.begin(), den.end(), std::greater<int>() );
	sort(bus.begin(), bus.end(), std::greater<int>() );

	std::cout << den[1] + bus[1] << '\n';


	return 0;
}


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

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

inline void normal(ll &a) { if (a >= MOD) a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) {normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) {normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) {normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } //if MOD is prime, modPow(b, p % (MOD-1))
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

const int mx = 1e6 + 9;

ll f[mx];

ll ncr(ll n, ll r) {
    return modDiv(f[n], modMul(f[r], f[n - r]));
}

int main() {
    int n; cin >> n;
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }

    f[0] = 1;
    for (int i = 1; i < mx; i++) f[i] = modMul(i, f[i - 1]);

    ll ttl = 0;
    for (int k = 1; k < n; k++) {
        ttl = modAdd(ttl, modMul(ncr(n, k), modSub(modPow(9, n - k), modPow(8, n - k))));
    }

    cout << ttl << endl;
}

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

int a[9][21],n,k,an[9],A[21],An;

struct Pm
{
	int p[100010],c[100010],cn;
	bool bo[100010];
	void operator ^=(int b)
	{
		memset(bo,0,sizeof(bo));
		for (int x,i=1; i<=n; i++) if (!bo[i])
		{
			bo[x=i]=1,c[0]=i,cn=1;
			for (x=p[x]; x!=i; x=p[x]) c[cn++]=x,bo[x]=1;
			for (int j=0; j<cn; j++) p[c[j]]=c[(j+b+cn)%cn];
		}
	}
	void operator *=(Pm A) {for (int i=1; i<=n; i++) p[i]=A.p[p[i]];}
	void in() {for (int i=1; i<=n; i++) scanf("%d",&p[i]);}
	void out() {for (int i=1; i<=n; i++) printf("%d ",p[i]);puts("");}
}p,q,P,Q,t,T,ans;

Pm calc(int x)
{
	if (x==1) return p;
	if (x==-1) return P;
	if (x==2) return q;
	if (x==-2) return Q;
}

int main()
{
	scanf("%d%d",&n,&k),a[1][1]=1,a[2][1]=2,an[1]=an[2]=1;
	for (int i=3; i<=7; i++)
	{
		An=an[i-2]+an[i-1],an[i]=0;
		for (int j=1; j<=an[i-1]; j++) A[an[i-2]+j]=a[i-1][j];
		for (int j=1; j<=an[i-2]; j++) A[j]=-a[i-2][an[i-2]-j+1];
		for (int j=1; j<An; j++) if (A[j]==-A[j+1]) A[j]=A[j+1]=0,j++;
		for (int j=1; j<=An; j++) if (A[j]) a[i][++an[i]]=A[j];
	}
	p.in(),q.in(),P=p,P^=(-1),Q=q,Q^=(-1),t=calc(a[7][1]);
	for (int i=2; i<=(an[7]>>1); i++) t*=calc(a[7][i]);
	t^=((k-1)/6),T=t,T^=(-1),ans=t;
	for (int i=1; i<=an[(k-1)%6+1]; i++) ans*=calc(a[(k-1)%6+1][i]);
	ans*=T,ans.out();
	return 0;
}

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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;

int N, K, R, S, P;
string T;

int calc(string s){
  int m = s.size();
  vector<vector<int>> dp(m+1, vector<int>(3, 0));

  REP(i, m) REP(j, 3) REP(k, 3){
    if(j == k) continue;
    int cost = 0;
    if(s[i] == 'r' && k == 0) cost += P;
    if(s[i] == 's' && k == 1) cost += R;
    if(s[i] == 'p' && k == 2) cost += S;
    chmax(dp[i+1][k], dp[i][j]+cost);
  }
  int res = 0;
  REP(i, 3) chmax(res, dp[m][i]);
  return res;
}

signed main() {
  cin >> N >> K >> R >> S >> P >> T;

  vector<string> ss(K);
  REP(i, N){
    ss[i%K] += T[i];
  }

  int ans = 0;
  REP(i, K) ans += calc(ss[i]);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6016
def six_integers(c):
    return c[0][1] - c[0][0] == c[1][1] - c[1][0] == c[2][1] - c[2][0] and \
        c[0][2] - c[0][1] == c[1][2] - c[1][1] == c[2][2] - c[2][1] and \
        c[0][2] - c[0][0] == c[1][2] - c[1][0] == c[2][2] - c[2][0] and \
        c[1][0] - c[0][0] == c[1][1] - c[0][1] == c[1][2] - c[0][2] and \
        c[2][0] - c[1][0] == c[2][1] - c[1][1] == c[2][2] - c[1][2] and \
        c[2][0] - c[0][0] == c[2][1] - c[0][1] == c[2][2] - c[0][2]


if __name__ == '__main__':
    c = [list(map(int, input().split())) for _ in range(3)]
    print('Yes') if six_integers(c) else print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x; cin >> x;
  if(x==7 || x==5 || x==3){
      cout << "YES" << endl;
  }else{
      cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
integer N
integer(16),allocatable::A(:)
integer(16)ans
read*,N
allocate(A(N))
do i=1,N
  read*,A(i)
end do

ans=A(1)-1
j=2
do i=2,N
  if(A(i)==j)then
    j=j+1
    cycle
  endif
  if(A(I)<j)cycle
  if(mod(A(i),j)==0)A(i)=A(i)-1
  ans=ans+A(i)/j
end do

print"(i0)",ans

end


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int n,d,x,a[110];
    cin >> n >> d >> x;
    rep(i,n) cin >> a[i];
    int consume[110];
    fill(consume,consume+d+1,0);
    rep(i,n){
        for(int j=1;j<=d;j+=a[i]){
            consume[j]++;
        }
    }
    int ans =x;
    rep(i,d+1){
        ans+=consume[i];
        //cout << i <<": "<<consume[i] << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  	int a,b,c, sum=0;
	scanf("%d",&a);
  	scanf("%d",&b);
  	scanf("%d",&c);

	sum = a + b;
  	if (sum > b + c){
    	sum = b + c;
    }
  	if (sum > c + a){
    	sum = c + a;
    }

  	printf("%d",sum);
	return 0;
}

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

  
int main(){
 int a,b;
  cin >> a >> b;
  if(a<=8 && b<=8) cout << "Yay!" <<endl;
  else cout << ":(" << endl;

}
  
 

Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
a=n2(n)
b=sorted(a)
m1=b[-1]
m2=b[-2]

for i in a:
    p0(i==m1,m2,m1)
    

Measured memory_bytes: 14132
#include<bits/stdc++.h>
using namespace std;
#define M 100005
char s[M];
int L[M],R[M],n,num[M];
int main(){
	cin>>s+1;
	n=strlen(s+1);
	for(int i=1;i<=n;++i){
		R[i]=R[i-1];
		if(s[i]=='R')R[i]=i;
	}
	for(int i=n;i>=1;--i){
		L[i]=L[i+1];
		if(s[i]=='L')L[i]=i;
	}
	for(int i=1;i<=n;++i){
		if(s[i]=='L'){
			int d=i-R[i];
			if(d%2==1)num[R[i]+1]++;
			else num[R[i]]++;
		}else {
			int d=L[i]-i,f=0;;
			if(d%2==1)num[L[i]-1]++,f=1;
			else num[L[i]]++;
//			if(i==2)cout<<f<<endl;
		}
	}
	for(int i=1;i<=n;++i)cout<<num[i]<<" ";
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> mat;
// mat dtable(M, vl(N, 0)); M行N列 のサイズで,0で初期化

class UnionFindTree{
private:
    vector<int> parent;
    vector<int> size;
    vector<int> rank;
public:
    int n;
    UnionFindTree(int n);
    int root(int x);
    int getSize(int x);
    void unite(int x, int y);
    bool isSame(int x, int y);
};

UnionFindTree::UnionFindTree(int n_): parent(n_), size(n_), rank(n_, 0){
    n = n_;
    // 初期化:すべてのノードの親を自分にする
    REP(i, n){
        parent[i] = i;
        size[i] = 1;
    }
}

int UnionFindTree::getSize(int x){
    return size[root(x)];
}

int UnionFindTree::root(int x){
    // 経路圧縮を行う
    if (parent[x] == x) return x;
    else return parent[x] = root(parent[x]);
}

void UnionFindTree::unite(int x, int y){
    // 木の結合:高さが低い木を高い木の下にぶら下げる
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    else {
        if (rank[rx] < rank[ry]){
            size[ry] += size[rx];
            parent[rx] = ry;
        }else{
            size[rx] += size[ry];
            parent[ry] = rx;
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }
}

bool UnionFindTree::isSame(int x, int y){
    return root(x) == root(y);
}

int main(){
    ll N, M; cin >> N >> M;
    vl A(M), B(M);
    REP(i, M) cin >> A[i] >> B[i];
    UnionFindTree uft(N+1);

    ll p = N * (N-1) / 2;
    vl ans;

    for(int i=M-1; i>=0; --i){
        ans.pb(p);
        bool is_same = uft.isSame(A[i], B[i]);
        ll s = uft.getSize(A[i]);
        ll t = uft.getSize(B[i]);
        if (!is_same){
            p -= (s*t);
            uft.unite(A[i], B[i]);
        }
    }
    REP(i, ans.size()) cout << ans[ans.size()-i-1] << endl;
}

Measured memory_bytes: 4980
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 

//result = Math.pow(num1, num3)
//StringBuffer str = new StringBuffer(hoge1);
//String hoge2 = str.reverse().toString();
//map.containsKey(A)

//Map<String, Integer> map = new HashMap<String, Integer>(n);
/*for ( キーのデータ型 key : マップの名前.keySet() ) {
	データのデータ型 data = マップの名前.get( key );
	
	// keyやdataを使った処理;
}*/
//int i = Integer.parseInt(s);
//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
//ArrayList<String> cc = new ArrayList<>(n);
//Collections.sort(list);
//Array.sort(list);
//Arrays.asList(c).contains("a")
//list.set(1,"walk");
public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static int K;
	public static void main(String[] args) {
		int N=sc.nextInt();
		String S=sc.next();
		
		String ans="";
		char v;
		for(int i=0;i<S.length();i++) {
			v=S.charAt(i);
			if(v+N>90) {
				v=(char) (v+N-26);
			}else {
				v=(char) (v+N);
			}
			ans=ans+v;
		}
		p(ans);
		}	
}


Measured memory_bytes: 148152
#include<cstdio>
int n,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1,s;i<=n;i++)
	{
		s=0;
		for(int j=i;j;j/=10)s++;
		if(s%2)ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
from sys import exit
from collections import deque
import heapq
if __name__ == "__main__":
    n, m = map(int, input().split())
    jobs = []
    for i in range(n):
        job = tuple(map(int, input().split()))
        if job[0] <= m:
            jobs.append(job)
    jobs.sort(key=lambda tup: tup[0])
    income = 0
    jobs = deque(jobs)
    hp = []
    for day in range(m):
        while len(jobs) != 0 and jobs[0][0] <= day + 1:
            job = jobs[0]
            heapq.heappush(hp, - job[1])
            jobs.popleft()
        if hp != []:
            income -= heapq.heappop(hp)
    
    print(income)


Measured memory_bytes: 18424
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    a = readInt()
    a.sort(reverse=True)
    m = {}
    order = []
    for i in range(n):
        if a[i] in m.keys():
            m[a[i]] += 1
        else:
            m[a[i]] = 1
            order.append(a[i])
    count = m[a[0]]
    num = 0
    ans = 0
    for i in range(1,n):
        if i>count*2-1:
            num += 1
            count += m[order[num]]
        ans += order[num]
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 35396
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(true){
            String str = sc.next();
            if(str.equals("-")){
                break;
            }
            int m = sc.nextInt();
            for(int i = 0; i < m; i++){
                int h = sc.nextInt();
                String con = str.substring(0,h);
                con = str.concat(con);
                str = con.substring(h);
            }
            System.out.println(str);
        }
    }
}

Measured memory_bytes: 26356
#include <iostream>
using namespace std;
typedef long long ll;
ll dp[110][10] = {{0}},fib[10] = {0},inf = 1e9+7;
int H,W,K;
int main(){
	cin >> H >> W >> K;
	fib[1] = 1; fib[2] = 1;
	for(int i=3;i<=9;i++){
		fib[i] = fib[i-1]+fib[i-2];
	}
	dp[0][1] = 1;
	for(int i=0;i<H;i++){
		for(int j=1;j<=W;j++){
			if(j>=2){
				dp[i+1][j-1] += (fib[j-1]*fib[W-j+1])*dp[i][j];
				dp[i+1][j-1] %= inf;
			}
			if(j<=W-1){
				dp[i+1][j+1] += (fib[j]*fib[W-j])*dp[i][j];
				dp[i+1][j+1] %= inf;
			}
			dp[i+1][j] += (fib[j]*fib[W-j+1])*dp[i][j];;
			dp[i+1][j] %= inf;
		}
	}
	cout << dp[H][K] << endl;
}

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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  int n; cin >> n;
  if (n%2 == 0) {
    cout << 0.5000000000 << endl;
  }
  else {
    double d = ceil((double) n/2) / n;
    cout << d << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
#define int long long

signed main(){
    int N;
    cin >> N;
    
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    
    sort(a,a+N);
    
    cout << a[N-1]-a[0] << endl;
    return 0;
}


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

typedef long long int ll;
 
int main(){
  ll a,b,k;
  cin>>a>>b>>k;
  
  if (k<=a) cout <<a-k<<" "<<b<<endl;
  else if (a+b>=k) cout << 0 << " "<<b-k+a<<endl;
  else cout<<0<< " " <<0<<endl;
}


Measured memory_bytes: 256
# coding: utf-8

def main():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))

    tmp1 = A[0] + K - A[-1]
    tmp2 = max([A[i] - A[i-1] for i in range(1, N)])

    print(K - max(tmp1, tmp2))


if __name__ == "__main__":
    main()


Measured memory_bytes: 32280
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cctype>
#include<iostream>
using namespace std;
const int N = 1e5 + 3;
char s[N];
int n,k,r;
int ans = 0;
int main(){
	scanf("%d%d",&n,&k);
	scanf("%s",s + 1);
	int l = 1,r = 1;
	int cnt = 0;
	while(1){
		while(r <= n && cnt < k){
			if(s[r] == '0'){
				while(r <= n && s[r] == '0') ++r;
				cnt++;
			}
			while(s[r] == '1') r++;
		}
	//	cout << r << endl;
		ans = max(ans,r - l);
		if(r > n) break;
		cnt--;
		while(s[l] != '0') l++;
		while(s[l] == '0') l++;
	}
	printf("%d\n",ans);
	return 0;	
}

Measured memory_bytes: 384
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<=b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair< int, int>
#define vpii vector<pii>
using namespace std;

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

    int t=1;
    //cin>>t;
    while(t--){
    	int n;
    	cin>>n;
    	int x;vi a;
    	vi b(n,0);
    	Fr(i,0,n-1){
    		cin>>x;
    		a.pb(x);
    		if(i==0){
    			b[i]=x;
    		}
    		else{
    			b[i]=b[i-1]+x;
    		}
    	}
       vvi dp(n,vi(n,1e18));
    	for(int i=0;i<n;i++){
    		int u=0;
    		for(int j=i;j<n;j++){
    			if(u==j){
    				dp[u][j]=0;
    			}
    			else{
    				//cout<<u<<" "<<j<<endl;
    				for(int k=1;k<=j-u;k++){
    					dp[u][j]=min(dp[u][j],dp[u][u+k-1]+dp[u+k][j]+((u-1)>=0?(b[j]-b[u-1]):(b[j])));
    				}
    				//cout<<"1"<<endl;
    			}
    			u++;
    		}
    	}
       cout<<dp[0][n-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1536
x = int(input())
a = []
b = []
ansa = 0
ansb = 0
for i in range(10**3):
    a.append(i**5)
    b.append(i**5)
for i in a:
    for j in b:
        if i - j == x:
            ansa = i**(1/5)
            ansb = j**(1/5)
        elif i + j == x:
            ansa = i**(1/5)
            ansb = -(j**(1/5))
        elif -i + j == x:
            ansa = -(i**(1/5))
            ansb = -(j**(1/5))
        elif -i -j == x:
            ansa = -(i**(1/5))
            ansb = j**(1/5)
print(int(ansa), int(ansb)) 

Measured memory_bytes: 9364
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // AGC003C - BBuBBBlesort!
  int N; cin >> N;
  vector<pair<int, int> > A(N, pair<int, int>());
  REP(i, N){
    int tmp; cin >> tmp;
    A[i] = {tmp, i};
  }
  sort(A.begin(), A.end());
  int ans = 0;
  for(int i = 0; i < N; i += 2){
    if(A[i].second % 2) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = tuple(map(int, args[1].split()))

    ret = 0
    search = 1
    for i in range(n):
        if A[i] == search:
            search += 1
        else:
            ret += 1

    return str(ret if 1 < search else -1)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

using namespace std;
mt19937_64 rng(58);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    for (int i = 1; i <= 5; i++) {
        int x;
        cin >> x;
        if (x == 0) {
            cout << i << endl;
            return 0;
        }

    }
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector> 
using namespace std;
 
int main(){
	int n,m;
	cin >> n >> m;
	vector<int> city;

	for(int i = 0; i < n; i++){
		city.push_back(0);
	}
 
	for(int j = 0; j < m; j++){
		int a,b;
		cin >> a >> b;
		city[a - 1]++;
		city[b - 1]++;
	}

	for(int k = 0; k < n; k++){
		cout << city[k] << endl;
	}
}

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

int main()
{
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> a(1, 0);
    int count = 0;
    rep(i, s.size() - 1)
    {
        if (s[i] == 'A' && s[i + 1] == 'C')
            count++;
        a.push_back(count);
    }
    // rep(i, s.size()) cout << a[i];
    vector<int> ans(q);
    rep(i, q)
    {
        int l, r;
        cin >> l >> r;
        ans[i] = a[r - 1] - a[l - 1];
    }
    rep(i, q) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 1912
//file_name:ABC64_D.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);
    string s;
    cin >> s;
    int a = 0;
    int b = 0;
    drep(i,n){
        if(s[i]==')'){
            a++;
        }else{
            a--;
            if(a<0){
                a=0;
            }
        }
    }
    rep(i,n){
        if(s[i]=='('){
            b++;
        }else{
            b--;
            if(b<0){
                b=0;
            }
        }
    }
    rep(i,a){
        cout << '(';
    }
    rep(i,n){
        cout << s[i];
    }
    rep(i,b){
        cout << ')';
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string S;
        cin >> S;
        set<char> tmp;
        rep(i, 0, len(S)) {
                tmp.insert(S[i]);
        }
        if (len(S) == len(tmp)) {
                cout << "yes" << endl;
        } else {
                cout << "no" << endl;
        }
}

Measured memory_bytes: 3620
N = int(input())
A = list(map(int, input().split()))

a = []
tmp = 0
for aa in A:
    tmp += aa
    a.append(tmp)

a.sort()
a.append(1e10)

ans = []
tmp = a[0]
count = 1
for i in range(1, N + 1):
    if a[i] == tmp:
        count += 1
    else:
        if count != 1:
            ans.append(count)
        count = 1
        tmp = a[i]

ansans = 0
for aa in ans:
    ansans += (aa - 1) * aa // 2
ansans += a.count(0)
print(ansans)


Measured memory_bytes: 25724
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int alf[];
        alf=new int[256];
        while(sc.hasNext()){
            String S=sc.next();
            int L=S.length();
            S=S.toLowerCase();
            char s[]=S.toCharArray();
            for(int i=0;i<L;i++){
                if(s[i]=='.') continue;
                if(s[i]-'a'>=0 && s[i]-'a'<=25) alf[s[i]-'a']++;
            }
        }
        for(int i=0;i<26;i++) System.out.printf("%c : %d\n",'a'+i,alf[i]);
    }
}



Measured memory_bytes: 26532
n = int(input())
cards = []
for i in range(n):
    s, a = input().split()
    cards.append((s, int(a)))
l = [(s, a) for s in "SHCD" for a in range(1,14) if (s,a)not in cards]
for s, a in l:
    print(s + " " + str(a))


Measured memory_bytes: 5600
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		h: usize,
		w: usize,
		s: [Chars; h],	// s[y][x]
	}

	for y in 0..h {
		for x in 0..w {
			let mut count = 0;
			// 爆弾の場合
			if s[y][x] == '#' {
				print!("#");
				continue;
			}
			// 左上
			if 0 < y && 0 < x && s[y-1][x-1] == '#' {
				count += 1;
			} 
			// 上
			if 0 < y && s[y-1][x] == '#' {
				count += 1;
			} 
			// 右上
			if 0 < y && x < w-1 && s[y-1][x+1] == '#' {
				count += 1;
			} 
			// 左
			if 0 < x && s[y][x-1] == '#' {
				count += 1;
			} 
			// 右
			if x < w-1 && s[y][x+1] == '#' {
				count += 1;
			} 
			// 左下
			if y < h-1 && 0 < x && s[y+1][x-1] == '#' {
				count += 1;
			} 
			// 下
			if y < h-1 && s[y+1][x] == '#' {
				count += 1;
			} 
			// 右下
			if y < h-1 && x < w-1 && s[y+1][x+1] == '#' {
				count += 1;
			}
			print!("{}", count);
		}
		println!("");
	}
}



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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int w, h, v, t, r, s, p, q;
vector<double> vecx, vecy;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> w >> h >> v >> t >> r >> s >> p >> q;
  for(int i = 0; ; i++) {
    int x = (i+1)/2*2*w + (i&1 ? -p : p);
    if(x > t*v + r) break;
    vecx.push_back((double)x);
    if(-x < -t*v + r) continue;
    vecx.push_back((double)-x);
  }
  sort(all(vecx));
  for(int i = 0; ; i++) {
    int y = (i+1)/2*2*h + (i&1 ? -q : q);
    if(y > t*v + s) break;
    vecy.push_back((double)y);
    if(-y < -t*v + s) continue;
    vecy.push_back((double)-y);
  }
  sort(all(vecy));
  int ans = 0;
  for(double x : vecx) {
    double lb = s, ub = t*v + s;
    for(int i = 0; i < 100; i++) {
      double mb = (lb + ub) / 2.0;
      if((x-r)*(x-r) + (mb-s)*(mb-s) <= t*v*t*v) lb = mb;
      else ub = mb;
    }
    int ulim = upper_bound(all(vecy), lb) - begin(vecy);
    lb = -t*v + s, ub = s;
    for(int i = 0; i < 100; i++) {
      double mb = (lb + ub) / 2.0;
      if((x-r)*(x-r) + (mb-s)*(mb-s) <= t*v*t*v) ub = mb;
      else lb = mb;
    }
    int llim = lower_bound(all(vecy), ub) - begin(vecy);
    ans += ulim - llim;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 22976
import sys
sys.setrecursionlimit(2000000000)
N = int(input())
import math
l = [int(x) for x in input().split()]
tobi = [0]*(math.ceil(N/2))
tobi[0] = l[0]
for i in range(1,math.ceil(N/2)):
    tobi[i] = tobi[i-1] + l[i*2]
from functools import lru_cache
@lru_cache(maxsize=1000000000)
def motomeru(x,y):
    if y == 0 or x == 0 or x == 1:
        return 0
    elif x % 2 == 0:
        return max(motomeru(x-2,y-1)+l[x-1],tobi[math.floor((x-1)/2)])
    else:
        return max(motomeru(x-2,y-1)+l[x-1],motomeru(x-1,y))
print(motomeru(N,N//2))


Measured memory_bytes: 370084
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/all>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N;
    cin >> N;
    N*=2;
    vP div;
    FOR(i,1,(ll)sqrt(N)+1){
        if(N%i==0){
            P p={N/i,i};
            div.pb(p);
            swap(p.first,p.second);
            div.pb(p);
        }
    }
    ll ans=INF;
    rep(i,div.size()){
        P res=atcoder::crt({0,-1},{div[i].first,div[i].second});
      if(res.second){
        //cout << div[i].first << endl;
        //cout << res.first << ' ' << res.second << endl;
        if(res.first==0){
          res.first+=res.second;
        }
        chmin(ans,res.first);
      }
    }
    cout << ans << '\n';
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 3904
from sys import stdin
import numpy as np
X = int(stdin.readline().rstrip())
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
    return data

d = np.array(get_sieve_of_eratosthenes(200000))
print(min(d[d >= X]))

Measured memory_bytes: 25620
#include <bits/stdc++.h>
typedef long long int ll;

typedef std::pair<ll, int> P;

using namespace std;

ll INF = 1e18;

bool bell(vector<ll> &cost, vector<vector<P>> &E)
{
    bool update = true;

    int N = E.size();

    vector<int> visit(0);

    visit.push_back(0);

    cost[0] = 0;

    int count = 0;

    while (update)
    {
        update = false;

        for (int v : visit)
        {

            for (P e : E[v])
            {

                if (cost[e.second] == -INF)
                {

                    visit.push_back(e.second);
                }

                

                if (cost[e.second] < cost[v] + e.first)
                {
                    update = true;

                    cost[e.second] = cost[v] + e.first;

                    if (e.second == N - 1 && count > N)
                    {

                        return 0;
                    }
                }
            }
        }

        count++;

        if(count >N+2){

            return 1;
        }
    }

    return 1;
}

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

    vector<vector<P>> E(N, vector<P>(0));

    vector<ll> cost(N, -INF);

    for (int i = 0; i < M; i++)
    {

        ll a, b, c;
        cin >> a >> b >> c;
        E[a - 1].push_back(make_pair(c, b - 1));
    }

    if (bell(cost, E) == 0)
    {

        cout << "inf" << endl;
    }
    else
    {
        cout << cost[N - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100100
#define lson root << 1
#define rson root << 1 | 1
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
vector<int> g[maxn];
int vis[maxn], col[maxn];
tuple<int, int, int> op[maxn];
void dfs(int v, int d, int c)
{
	if (vis[v] >= d)
		return;
	vis[v] = d;
	if (!col[v])
		col[v] = c;
	if (d)
	{
		int sz = g[v].size();
		for (int i = 0; i < sz; i++)
			dfs(g[v][i], d - 1, c);
	}
}
int main()
{
	int n, m, q;
	while (~scanf("%d%d", &n, &m))
	{
		for (int i = 1; i <= n; i++)
			g[i].clear();
		fill(vis, vis + n + 1, -1);
		fill(col, col + n + 1, 0);
		while (m--)
		{
			int u, v;
			scanf("%d%d", &u, &v);
			g[u].push_back(v);
			g[v].push_back(u);
		}
		scanf("%d", &q);
		for (int i = 0; i < q; i++)
		{
			int v, d, c;
			scanf("%d%d%d", &v, &d, &c);
			op[i] = tuple<int, int, int>(v, d, c);
		}
		for (int i = q - 1; i >= 0; i--)
		{
			int v, d, c;
			tie(v, d, c) = op[i];
			dfs(v, d, c);
		}
		for (int i = 1; i <= n; i++)
			printf("%d\n", col[i]);
	}
	return 0;
}

Measured memory_bytes: 8440
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i < n; i++) {
    ans += (n - 1) / i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
using namespace std;

#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

void sout(string* a, string* b) {
	if (*a > * b) {
		string c = *a;
		*a = *b;
		*b = c;
	}
}

int combination(int n, int k) {
	if (n > k && k > 0) {
		return (combination(n - 1, k) + combination(n - 1, k - 1));
	}
	else
		return 1;
}

int main() {
	int n;
	cin >> n;
	double m, r;
	if (n % 2 == 1) {
		m = (n + 1) / 2;
		r = n + 0.0;
		cout << fixed << setprecision(10) << m / r << endl;
	}
	else {
		cout << fixed << setprecision(10) << 1.0 / 2.0 << endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int b,n,i,min,max,ans=-214783648,tmp;
	scanf("%d",&n);
	scanf("%d",&tmp);
	max = min = tmp;
	for(i=1; i<n; i++){
		scanf("%d",&tmp);
		max = tmp;
		b = max - min;
		if(min > tmp)min = tmp;
		if(n == 2 || ans < b)ans = b;
	}
	printf("%d\n",ans);
	return 0;
}
		

Measured memory_bytes: 596
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define eps 1e-14
#define INF 1e9
#define m0(x) memset(x, 0, sizeof(x))

using namespace std;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int a, b, c, n;
  string s;

  cin >> a >> b >> c;

  if(a + b >= c) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
}

Measured memory_bytes: 764
k = int(input())

def gcd_(a, b):
    if a < b:
        a, b = b, a
    while not a % b == 0:
        a, b = b, a % b
    return b

s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        p = gcd_(i, j)
        if p == 1:
            s += k
        else:
            for h in range(1, k + 1):
                s += gcd_(p, h)
            
print(s)

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

int main() {
  int K;
  cin >> K;
  int a=7, b=1, c=K % 2, d=K % 5;
  if(c==0||d==0) {
    cout << -1 << endl;
  }
  else {
    while(true) {
      a = a % K;
      if(a==0) {
        cout << b << endl;
        break;
      }
      else {
        a = a*10+7;
        b++;
      }
    }
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int N = 10;
bool visited[N];
vector<ll> vals;
ll cost[N][N];
int n, j;

void dfs(int i, ll s) {
	visited[i] = true;
	int outs = 0;
	for (int t = 0; t < n; ++t) {
		if (! visited[t]) {
			++outs;
			dfs(t, s + cost[i][t]);
		}
	}
	if (outs == 0 && i >= j) vals.push_back(s);
	visited[i] = false;
}

ll works() {
	for (j = 0; j < n; ++j) dfs(j, 0);
	sort(vals.begin(), vals.end());
	ll ans = vals.back();

	for (int i = 0; i+1 < vals.size(); ++i) {
		if (vals[i] == vals[i+1]) return -1;
	}
	vals.clear();
	return ans;
}

int main() {
        vector<vector<int>> xr = {
        {1},
        {1,2},
        {1,2,4},
        {1,2,4,7},
        {1,2,4,7,12},
        {1,2,4,8,13,18},
        {1,2,4,8,14,19,24},
        {1,2,4,8,15,24,29,34},
        {1,2,4,8,15,24,29,34,46}
	};

	int m;
	cin >> m;
	for (int i = 1; i < m; ++i) {
		n = i;
		ll b = works() + 1;
		if (b == -1) return 1;

		for (j = 0; j < n; ++j) {
			cost[i][j] = b * xr[i-1][j];
			cost[j][i] = cost[i][j];
		}
	}

	n = m;
	ll res = works();
	if (res == -1) return 1;
	cerr << res << '\n';

	for (int i = 0; i < n; ++i) {
		for (j = 0; j < n; ++j) {
			cout << cost[i][j] << ' ';
		}
		cout << '\n';
	}
}


Measured memory_bytes: 17128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define dfor(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long
#define ull unsigned long long
#define MOD  1000000007
#define MAX  1e9
#define pb   push_back
#define F    first
#define S    second


int main() {
	int t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		int a[n];
		rep(i,n) cin>>a[i];
		if(n<=2){
			cout<<abs(a[0]-a[1]);
			return 0;
		}
		int dp[n];
		dp[0] = 0;
		dp[1] = abs(a[0]-a[1]);
		FOR(i,2,n){
			dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]) , dp[i-2]+abs(a[i]-a[i-2]));
		}

		cout<<dp[n-1];
	}
	
}

Measured memory_bytes: 1024
from collections import defaultdict, OrderedDict

n, m = [int(x) for x in raw_input().split()]
r = defaultdict(list)
s = OrderedDict()
for i in range(m):
	p, y = [int(x) for x in raw_input().split()]
	s[(p, y)] = 0
	r[p].append(y)
for p, v in r.iteritems():
	v.sort()
	for i in range(len(v)):
		s[(p, v[i])] = i + 1

for t in s:
	print "%06d%06d"% (t[0], s[t])

Measured memory_bytes: 58760
#include <stdio.h>

int main(){
    int n, l[11],sum = 0, big = 0;
    scanf("%d", &n);

    for(int i = 0; i<n; i++){
        scanf("%d", &l[i]);
        sum += l[i];
        if(l[i]>big){
            big = l[i];
        }
    }

    if((sum -big) > big){
        printf("Yes\n");
    }
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 128
def comb(n):
    return n*(n-1)/2

n,m = map(int, input().split())
a_sum = []
result = 0
a = list(map(int, input().split()))
a_sum.append(a[0]%m)
for i in range(1,n):
    a_sum.append((a_sum[i-1]+a[i])%m)
a_sum.sort()
now = 0
for i in range(1,n):
    if a_sum[i]==a_sum[i-1]:
        now += 1
    elif a_sum[i-1]==0:
        result += (now+1)*(now+2)/2
        now = 0
    else:
        if now>=1:
            result += comb(now+1)
        now = 0
if a_sum[n-1]==0:
    result += comb(now+2)
elif now>=1:
    result += comb(now+1)
    
print(int(result))

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

const int maxn=1e5+10;

int sum[maxn],n,m;

int main(){
	scanf("%d%d",&n,&m);
	memset(sum,0,sizeof(sum));
	for(int i=0;i<m;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		l--;r--;
		sum[l]+=1;
		sum[r+1]-=1;
	}
	for(int i=1;i<n;i++) sum[i]+=sum[i-1];
	int ans=0;
	for(int i=0;i<n;i++) if(sum[i]==m) ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e5;

int readInt ()
{
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true)
    {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true;
    else result = ch-'0';
    while (true)
    {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
int cnt[27];
main() {
    string s;
    cin >> s;
    int n = 4;
    for (int i = 0; i < 4; i++) {
        cnt[s[i] - 'A' + 1]++;
    }
    int twice = 0;
    for (int i = 1; i <= 26; i++) {
        twice += (cnt[i] == 2);
    }
    puts(twice == 2 ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[100005];
long long b[100005];
ll freq[26];
int main()
{
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll ans=0;
	for(ll i=1;i<n-1;i++)
	{
		b[0]=a[i-1];
		b[1]=a[i];
		b[2]=a[i+1];
		sort(b,b+3);
		if(b[1]==a[i])
			ans++;
	}
	cout<<ans<<endl;
}

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

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


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

using namespace std;

typedef long long ll;

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

	ll n;
	cin >> n;

	vector<ll> a(n);
	rep(i, n) cin >> a[i];

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

	vector<ll> l(n - 1, 0), r(n - 1, 0);

	rep(i, n){
		if(a[i] + i <= n - 2) l[a[i] + i]++;
		if(i - a[i] >= 1) r[i - a[i]]++;
	}

	ll ans = 0ll;
	rep(i, n - 2){
		ans += l[i+1] * r[i+1];
	}

	cout << ans << endl;
}


Measured memory_bytes: 7952