akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define Set(a, b) memset(a, (b), sizeof(a))
#define F first
#define S second
#define FT front()
#define BK back()
#define PB push_back
#define MP make_pair
#define repi(i, l, r) for (int i=l ; i <= (int)(r) ; ++i)
#define repd(i, r, l) for (int i=r ; i >= (int)(l) ; --i)
#define repv(x, v) for (auto (x) : v)
#define all(cont) cont.begin(), cont.end()
#define Sort(n) sort(all(n))
#define Sortcmp(n) sort(all(n), cmp)
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define nl "\n"

using namespace std;

bool cmp(const pair<long,long> &a,
              const pair<long,long> &b)
{
    return (a.second < b.second || (a.second == b.second && a.first < b.first));
}

bool binarySearch(int arr[], int n, int x){
    int k = 0;
    for (int b = n/2; b >= 1; b/2)
        while (k+b < n && arr[k+b] <= x) k += b;

    if (arr[k] == x) return k;
    return -1;
}

/* ASCII Table */
/* 48 == '0', 57 = '9', 65 == 'A', 90 == 'Z', 97 == 'a', 122 == 'z' */  

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int x, y;

    cin >> x >> y;

    cout << x + (y/2) << nl;

}

/* Compile */
// g++ -std=c++11 -O2 -Wall test.cpp -o test
 
 
/* Source code dengan case
 
int main(){
    int T;
    cin >> T;
    for(int counterT = 1 ; counterT <= T ; T++){
         
        printf("%d\n", ans);
    }
    return 0;
}
 */
 
/* Source code dengan case
 
int main(){
    int T;
    cin >> T;
    for(int counterT = 1 ; counterT <= T ; T++){
         
        printf("Case #%d: %d\n", counterT, ans);
    }
    return 0;
}
 */

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

int main()
{
    unsigned long long h,w,s;
    cin>>h>>w;
    s=h*w;
    if(h==1 || w==1)
        cout<<"1";
    else if(s%2==0)
        cout<<s/2;
    else
        cout<<(s/2)+1;

    return 0;
}



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

int main()
{
  long long n;
  cin >> n;
  vector<long long> capa(5);
  int i;
  for(i = 0; i < 5; i++)
  {
    cin >> capa.at(i);
  }
  long long min = 1000000000000001;
  for(i = 0; i < 5; i++)
  {
    if(min > capa.at(i))
    {
      min = capa.at(i);
    }
  }
  long long step = (n + min -1) / min;
  cout << step + 4 << endl;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    int s[11][11];
    int p[11], k[11];
    for(int i=0;i<m;i++){
        cin >> k[i];
        for(int j=0;j<k[i];j++){
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    for(int i=0;i<m;i++) cin >> p[i];

    int ans = 0;
    for(int i=0;i<(1 << n);i++){
        bool bb = true;
        for(int j=0;j<m;j++){
            int cnt = 0;
            for(int l=0;l<k[j];l++){
                if((1<<s[j][l]) & i) cnt++;
            }
            if(cnt % 2 != p[j]){
                bb = false;
                break;
            }
        }
        if(bb) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
vector<vector<int>> dp(5010,vector<int>(5010)),dp2(5010,vector<int>(5010));
int main(){
    ll n,maxk;cin >> n >>maxk;
    vector<int> v(n);rep(i,n)cin >> v[i];
    ll ans=0;
    //vector<vector<int>> dp(n+1,vector<int>(maxk));
    dp[0][0]=1;
    rep(j,n){
        rep(k,maxk){
            dp[j+1][k]+=dp[j][k];
            if(k+v[j]<maxk)dp[j+1][k+v[j]]+=dp[j][k];
        }
    }
    //vector<vector<int>> dp2(n+1,vector<int>(maxk));
    dp2[n][0]=1;
    per(j,n){
        rep(k,maxk){
            dp2[j][k]+=dp2[j+1][k];
            if(k+v[j]<maxk)dp2[j][k+v[j]]+=dp2[j+1][k];
        }
    }
    rep(i,n){
        bool need=false;
        vector<int> st;
        rep(j,maxk)if(dp2[i+1][j])st.pb(j);
        rep(j,maxk){
            if(dp[i][j]){
                ll z=lower_bound(all(st),maxk-j)-lower_bound(all(st),maxk-j-v[i]);
                if(z){need=true;break;}
            }
            if(need)break;
        }
        if(!need)ans++;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 199980
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

int main(){

    double a, b;
    cin >> a >> b;

    int a_max = (a + 1) / 0.08;
    int a_min = ceil(a / 0.08);

    for(int i = a_min; i < a_max; i++){
//        p(i);
        if(int(i*0.1) == b){
            p(i);
            return 0;
        }
    }

    p(-1);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int top = -1, S[105];

void push(int x){
  top++;
  S[top] = x;
}

int pop(){
  top--;
  return S[top+1];
 }

int main(void)
{
  char data[10];
  int a, b, n;

  while(scanf("%s", data) != EOF){
    if(data[0] == '+'){
      a = pop();
      b = pop();
      push(b+a);
    }
    else if(data[0] == '-'){
      a = pop();
      b = pop();
      push(b-a);
    }
    else if(data[0] == '*'){
      a = pop();
      b = pop();
      push(b*a);
    }
    else{
      n = atoi(data);
      push(n);
    }
  }
  printf("%d\n", pop());

    return 0;
}

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

using namespace std;

int main(){
	int n,a,b;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(i==0) b=a;
		else b=__gcd(a,b);
	}
	cout<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] arr = new int[N];
        for (int i = 1; i < N; i++) {
            arr[in.nextInt() - 1]++;
        }
        for (int i = 0; i < N; i++) {
            System.out.println(arr[i]);
        }
    }
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int sum = 0;
  
  for(;A < B + 1;A++) {
    int r = 0, s = 0, t = 0, u = 0;
    int a = A, b = B;
    r += a / 10000;
    s += a / 1000;
    t += a % 100;
    u += a % 10;
    
    if(r == u && s % 10 == t / 10) {
      sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    from collections import defaultdict
    dd = defaultdict(int)
    for i in range(N):
        S=input()
        dd[S]+=1
    
    ans=0
    for k,v in dd.items():
        ans+=1
        
    print(ans)

main()


Measured memory_bytes: 128788
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;

const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf

#define sf scanf

#define ALL(x) x.begin(),x.end()
#define pb push_back

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
int ext_gcd(int a, int b, int & x, int & y) {
    //for finding modular inverse
    //if its return 1 ,then a has a mod inverse x mod b.
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = ext_gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

int main()

{
    IOS;
    //freopen("input.txt", "r", stdin);
     //freopen("output.txt", "w", stdout);
     int n;
     cin>>n;
     vi arr(n+1);
     vi ans(n+1);
     fill(ALL(ans),0);
     rep1(i,2,n){
        cin>>arr[i];
        ans[arr[i]]++;
     }
    rep1(i,1,n){
        cout<<ans[i]<<endl;
    }


     return 0;

}
///Alhamdulillah


Measured memory_bytes: 4768
"use strict";

// read lines from stdin
const input = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");

const firstLine = input[0].split(" ").map((val) => parseInt(val, 10));

const N = firstLine[0];
const M = firstLine[1];

const heightList = input[1].split(" ").map((val) => parseInt(val, 10));
const goodPlaceList = Array(N).fill(true);

for (let i = 2; i < M + 2; i++) {
  const path = input[i].split(" ").map((val) => parseInt(val, 10));

  if (heightList[path[0] - 1] <= heightList[path[1] - 1]) {
    goodPlaceList[path[0] - 1] = false;
  }

  if (heightList[path[1] - 1] <= heightList[path[0] - 1]) {
    goodPlaceList[path[1] - 1] = false;
  }
}

console.log(goodPlaceList.filter((isGood) => isGood === true).length);


Measured memory_bytes: 62588
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 2e5+10;
ll dp[MAX_N];

ll calc(const vector<int>& v) {
    int n = v.size();
    ll ret = 1LL;
    dp[v[0]] = 1LL;
    REP(i, 1, n) {
        (ret += dp[v[i]]) %= MOD;
        dp[v[i]] = ret;
    }
    return ret;
}

int main(){
    int n;
    cin >> n;
    vector<int> c(n);
    rep(i, n) cin >> c[i];
    vector<int> v(1);
    v[0] = c[0];
    REP(i, 1, n) if(v.back() != c[i]) v.push_back(c[i]);
    cout << calc(v) << endl;
    return 0;
}

Measured memory_bytes: 3444
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who forgive themselves, and are able to accept their true nature...THEY ARE THE STRONG ONES

    int n, r;
    cin >> n >> r;
    if(n >= 10)
    {
        cout << r ;
    }
    else
    {
        cout << r + 100 * (10 - n);
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll 	long long
#define pb push_back
#define mp make_pair
using namespace std;

int main() {

int k; cin>>k;
int a,b; cin>>a>>b;

int dd= 0;

for(int i=a;i<=b;i++)
{
	if(i%k==0)
	{
		dd=1;
		break;
	}
}
if(dd==0)
cout<<"NG\n";
else cout<<"OK\n";
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};


int main(){
    Stream io;

    int N;
    io.read(N);
    auto S = io.read_vec<string>(N);

    map<string, int> mp;

    for(int i = 0; i < N; i++){
        mp[S[i]]++;
    }
    cout << "AC" << " x " << mp["AC"] << '\n';
    cout << "WA" << " x " << mp["WA"] << '\n';
    cout << "TLE" << " x " << mp["TLE"] << '\n';
    cout << "RE" << " x " << mp["RE"] << '\n';

    return 0;
}


Measured memory_bytes: 6428
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7 ;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll fact[2005];
ll inv[2005];
ll inv2[2005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    fact[0]=1;
    for(int i=1;i<2005;i++){
        fact[i]=fact[i-1]*i;fact[i]%=mod;
    }
    inv[1] = 1;
    inv2[0]=1;
    inv2[1]=1;
    for(int i=2;i<=2000;i++){
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        inv2[i] = inv2[i - 1] * inv[i] % mod;
    }


    for(int i=1;i<=k;i++){
        ll x;
        if(k<i)x=0;
        else{x=fact[k-1]*inv2[i-1];
        x%=mod;
        x=x*inv2[k-i];
        x%=mod;}
        ll y=0;
        if(n-k+1>=i){y=fact[n-k+1]*inv2[i];
        y%=mod;
        y=y*inv2[n-k+1-i];
        y%=mod;}

        ll res=x*y;
        res%=mod;
        cout<<res<<endl;

    }
    return 0;
    }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans=0;
string s[55];int t[55];
string x;
int main() {
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>s[i]>>t[i];
	cin>>x;
	bool g=false;
	for(int i=1;i<=n;i++) {
		if(g) ans+=t[i];
		if(s[i]==x) g=true;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin

def is_unique(seq):
    seen = []
    unique_list = [x for x in seq if x not in seen and not seen.append(x)]
    return len(seq) == len(unique_list)

N = int(stdin.readline().rstrip())
ans = "No"
words = []

for i in range(N):
    word = stdin.readline().rstrip()
    words.append(word)
if is_unique(words):
    ans = "Yes"
    for i in range(N-1):
        if words[i][-1] != words[i+1][0]:
            ans = "No"
print(ans)


Measured memory_bytes: 3064
step = input()
flag = True
for i, n in enumerate(step):
  if i%2==0:
    if n is "L":
      print("No")
      flag = False
      break      
  if i%2 == 1:
    if n is "R":
      print("No")
      flag = False
      break
if flag:
  print("Yes")

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 10000000;


int main(void){

	int N; cin >> N;
	int ans = 0;
	int min_value = INF;

	REP(i,N){

		int p; cin >> p;
		if(p < min_value){
			ans++;
			min_value = p;
		}
	}
	
	cout << ans << endl;


	return 0;

}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BPowerSocket solver = new BPowerSocket();
        solver.solve(1, in, out);
        out.close();
    }

    static class BPowerSocket {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int slots = a;
            int count = 1;
            if (b == 1) {
                out.println(0);
                return;
            }
            while (slots < b) {
                slots += a - 1;
                count++;
            }
            out.println(count);
        }

    }

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

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

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

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

    }
}



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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;

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

  string ans;
  string s;
  cin >> s;

  int size = s.size();

  FOR(i, 0, size) {
    if ((i + 1) % 2) {
      ans += s[i];
    }
  }

  cout << ans << '\n';

  return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define zeroes(x) memset(x,0,sizeof(x))
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;


int main()
{		
	
   
    IOS
    ll n;
    cin>>n;
    ll a[n][3];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }

    ll dp[n][3];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(ll i=1;i<n;i++)
    {   
        for(ll j=0;j<3;j++)
        {   dp[i][j]=0;
            for(ll k=0;k<3;k++)
            {
                if(j!=k)
                {
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
                }
            }
           
        }
    }

    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
  


}


Measured memory_bytes: 4992
def get_nonzero_range(A):
    start, end = None, None
    N = len(A)
    for i in range(N):
        if A[i] != 0:
            start = i
            for j in range(i+1, N):
                if A[j] == 0:
                    end = j
                    return start, end
    else:
        return start, end

N = int(input())
H = list(map(int, input().split()))
H.append(0)
num = 0
while True:
    start, end = get_nonzero_range(H)
    if start == None:
        break
    else:
        for i in range(start, end):
            H[i] -= 1
        num += 1
print(num)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                    \
  for (int i = 0; i < (int)(n); i++) \
    ;
 
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
 
int main() {
  long n;
  cin >> n;
 
  vector<int> a(n);
  for (int &x : a) {
    cin >> x;
  }
 
  bool plus;
  long sum = 0;
  long count_plus = 0;
 
  plus = false;
 
  for (int i = 0; i < n; i++) {
    plus = !plus;
    sum += a.at(i);
    if (plus) {
      if (sum > 0) {
        continue;
      } else {
        count_plus += 1 - sum;
        sum = 1;
      }
    } else {
      if (sum < 0) {
        continue;
      } else {
        count_plus += 1 + sum;
        sum = -1;
      }
    }
  }
  long count_minus = 0;
  plus = true;
  sum = 0;
 
  for (int i = 0; i < n; i++) {
    plus = !plus;
    sum += a.at(i);
    if (plus) {
      if (sum > 0) {
        continue;
      } else {
        count_minus += 1 - sum;
        sum = 1;
      }
    } else {
      if (sum < 0) {
        continue;
      } else {
        count_minus += 1 + sum;
        sum = -1;
      }
    }
  }
  cout << min(count_plus, count_minus) << endl;
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int ceil(int a, int b) {
	return (a + b - 1) / b;
}
int main() {
	int N, K;
	while (cin >> N >> K) {
		int pos;
		for (int i : range(N)) {
			int a;
			cin >> a;
			if (a == 1)pos = i;
		}
		int left = pos;
		int right = N - pos - 1;
		int ret = 1e9;
		for (int i : range(K)) {
			int ans = 1;
			int l = left - i;
			int r = right - (K - i - 1);
			ans += ceil(l, K - 1) + ceil(r, K - 1);
			chmin(ret, ans);
		}
		cout << ret << endl;

	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(int i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    string s; cin >> s;
    int a = 7;
    if(s == "MON") a = 6;
    else if(s == "TUE") a = 5;
    else if(s == "WED") a = 4;
    else if(s == "THU") a = 3;
    else if(s == "FRI") a = 2;
    else if(s == "SAT") a = 1;
    cout << a << endl;
}

Measured memory_bytes: 256
def main(k,n,a):
    lst = []
    lst.append(a[0]+(k-a[-1]))
    for i in range(n-1):
        lst.append(a[i+1]-a[i])
    return k-max(lst)
    
k,n = map(int,input().split())
a = list(map(int,input().split()))
print(main(k,n,a))

Measured memory_bytes: 26436
#include <stdio.h>

int main (){
  int K,c,i,sum;
  while (1){
    scanf("%d",&K);
    if (K==0)break;
    sum=0;
    for (i=0 ; i < (K*K-K)/2 ; i++){
      scanf("%d",&c);
      sum=sum+c;
    }
    printf("%d\n",sum/(K-1) );
  }
  
  return 0;
}

Measured memory_bytes: 596
from sys import stdin
import bisect

s = stdin.readline().rstrip()
t = stdin.readline().rstrip()

ss = s+s
alpos = []

for i in range(26):
    alpos.append([])

for i in range(len(ss)):
   alpos[ord(ss[i])-ord('a')].append(i)

pos = -1
mpos= -1
for i in range(len(t)):
    tn = ord(t[i])-ord('a')
    if ( len(alpos[tn]) == 0 ):
        pos = -2
        break
    bpos = bisect.bisect_left(alpos[tn], mpos+1)
    pos += alpos[tn][bpos]-mpos
    mpos = pos%len(s)

print(pos+1)


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

vector<bool> vis(201, 0);
int n;
vector<int> v[201];

void dfs(int x){
    vis[x] = true;
    for(int j : v[x]){
        if(vis[j]){
            cout << 1 << endl;
            exit(0);
        }
        dfs(j);
    }
    vis[x] = false;
}

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        int a, b;
        string s;
        cin >> a >> s >> b;
        if(s == "lock") v[100+b].push_back(a);
        else            v[a].push_back(100+b);
    }
    for(int i = 1; i <= 200; i++){
        dfs(i);
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3208
#include <stdio.h>
#include <stdlib.h>

// 標準入力から改行かスペースまで読み取り、数字として返す
int get_num() {
    // 10文字+区切り文字までしか受け付けられない
    char s[11];
    int i, n;
    for (i = 0; i < sizeof(s); i++) {
        s[i] = getchar();
        if (s[i] == ' ' || s[i] == '\n') {
            s[i] = '\0';
            break;
        }
    }
    sscanf(s, "%d", &n);
    return n;
}

int main(void) {
    int n, a, b;
    int sumsum = 0;
    int i;
    
    int o,p,q,r,s, sum;

    n = get_num();
    a = get_num();
    b = get_num();

    for (i = 1; i <= n; i++) {
        o = i / 10000;
        p = (i % 10000) / 1000;
        q = (i % 1000) / 100;
        r = (i % 100) / 10;
        s = (i % 10) / 1;
        sum = o + p + q + r + s;
        if (sum >= a && sum <= b) {
            sumsum += i;
        }
    }
    
    
    printf("%d\n", sumsum);
    
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;


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

	vector<int> a(N);
	double sum = 0;
	rep(i,N){
		cin >> a[i];
		sum += (double)1 / a[i];
	}

	printf("%.11lf\n", 1/sum);

	return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i32,
        op: String,
        b: i32,
    }
    match op.chars().nth(0).unwrap() {
        '+' => println!("{}", a + b),
        '-' => println!("{}", a - b),
        _ => panic!("unexpected operator")
    }
} 


Measured memory_bytes: 4352
import itertools

s = input()
final = ""
gr = list(itertools.product('+-', repeat=3))
for c in gr:
    ans = int(s[0])
    for i in range(1, 4):
        if c[i-1] == "+":
            ans += int(s[i])
        else:
            ans -= int(s[i])
    if ans == 7:
        final = s[0] + c[0] + s[1] + c[1] + s[2] + c[2] + s[3] + "=7"

print(final)



Measured memory_bytes: 38384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author kessido
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        AAntiAdjacency solver = new AAntiAdjacency();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAntiAdjacency {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.NextInt();
            int k = in.NextInt();
            out.println((k * 2 - 1 <= n) ? "YES" : "NO");
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(Writer out) {
            super(out);
        }

        public OutputWriter(File file) throws FileNotFoundException {
            super(file);
        }

        public OutputWriter(OutputStream out) {
            super(out);
        }

    }
}



Measured memory_bytes: 22356
import sys

if __name__ == '__main__':
    l = map(int, sys.stdin)
    del l[0]
    maxp = -9999999999
    minv = l[0]
    for i in range(1, len(l)):
        maxp = max(maxp, l[i] - minv)
        minv = min(minv, l[i])
    print maxp


Measured memory_bytes: 17220
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		switch(Integer.parseInt(sc.next())) {
		case 25:
			System.out.println("Christmas");
			break;
		case 24:
			System.out.println("Christmas Eve");
			break;
		case 23:
			System.out.println("Christmas Eve Eve");
			break;
		case 22:
			System.out.println("Christmas Eve Eve Eve");
			break;
		}
	}
}

Measured memory_bytes: 21588
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
// ascending order
#define asort(array, N) sort(array, array + N)
// descending order
#define asort_r(array, N) sort(array, array + N, greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	string S[H];
	for(int i = 0; i < H; i++) cin >> S[i];
	string rslt[H][W];

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

	for(int y = 0; y < H; y++) {
		for(int x = 0; x < W; x++) {
			if(S[y][x] == '#') rslt[y][x] = '#';
			else {
				int count = 0;
				for(int i = 0; i < 8; i++) {
					if(S[y + dy[i]][x + dx[i]] == '#') count++;
				}
				rslt[y][x] = to_string(count);
			}
		}
	}

	for(int y = 0; y < H; y++) {
		for(int x = 0; x < W; x++) {
			cout << rslt[y][x];
		}
		cout << endl;
	}




}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define SHOW(a) cout << #a << " = " << a << endl;

int f(string str){
	int sum = 0;
	for(char t : str){
		sum += t - '0';
	}
	return sum;
}

void solve(){
	string n;
	cin >> n;
	cout << (stoi(n) % f(n) ? "No" : "Yes") << endl;
}

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

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

int main() {
  string s,t;cin>>s>>t;
  int S=s.size(),T=t.size();
  int ans=1e9;
  rep(i,S-T+1){
    int cnt=0;
    rep(j,T){
      if(s[i+j]!=t[j])cnt++;
    }
    ans=min(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3596
mod = 1_000_000_007

gets

h = Hash.new{|h, k| h[k] = [0, 0] }
genten_iwashi = 0

$<.read.split.map(&:to_i).each_slice(2) do |(a,b)|

  if 0 == a | b
    genten_iwashi += 1
  else
    f = a.zero? || a * b > 0
    r = ( f ? Rational(a,b) : -Rational(b,a) )
    h[r][ f ? 0 : 1 ] += 1
  end
end

ans = 1
h.values.each do |(a, b)|
  ans *= ( 2.pow(a,mod) + 2.pow(b, mod) - 1)
  ans %= mod
end

ans = ( ans - 1 + genten_iwashi ) % mod

puts ans

Measured memory_bytes: 72296
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>

int main(void) {
	// input
	int n;
	std::cin >> n;
	std::vector<long long> a(n);
	for(int i = 0; i < n; ++i) {
		std::cin >> a[i];
	}

	// count minus signs
	int n_minus = 0;
	for(int i = 0; i < n; ++i) {
		n_minus += (a[i] < 0LL ? 1 : 0);
	}
	n_minus %= 2;
	
	// zero ?
	for(int i = 0; i < n; ++i) {
		if(a[i] == 0LL) n_minus = 0;
	}

	// abs
	std::vector<long long> abs_a(n);
	for(int i = 0; i < n; ++i) {
		abs_a[i] = std::abs(a[i]);
	}
	std::sort(abs_a.begin(), abs_a.end());

	long long sum_b = 0;
	if(n_minus == 0) sum_b = std::accumulate(abs_a.begin(), abs_a.end(), 0LL);
	else sum_b = std::accumulate(abs_a.begin(), abs_a.end(), 0LL) - (2 * abs_a[0]);

	std::cout << sum_b << std::endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int n,m; cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i,m){
        cin >> a[i] >> b[i];
    }
    sort(all(a)); sort(all(b));
    if(b[0] - a[m-1] +1 < 0) cout << 0 <<endl;
    else cout << b[0] - a[m-1] +1<< endl;
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int N;
pair<pair<int, int>, int> arr [20];
vector<int> ewRoads;
long long X [20], Y [20], P [20], dp [20][20][20], ret [20];

long long solveIt(int curr, int placeToUse, int roadsLeft){
    if(dp[curr][placeToUse][roadsLeft] != -1) return dp[curr][placeToUse][roadsLeft];
    if(curr == N) return dp[curr][placeToUse][roadsLeft] = 0;
    long long ret = INF/5;
    long long curCost = min(abs(X[curr]), abs(Y[curr]));
    for(int y : ewRoads) curCost = min(curCost, abs(Y[curr]-y));
    curCost = min(curCost, abs(X[curr]-X[placeToUse]));
    ret = min(ret, curCost*P[curr]+solveIt(curr+1, placeToUse, roadsLeft));
    if(roadsLeft) {
        for (int i = placeToUse + 1; i < N; i++) {
            ret = min(ret, solveIt(curr, i, roadsLeft - 1));
        }
    }
    return dp[curr][placeToUse][roadsLeft] = ret;
}

long long calcEW(){
    long long sum = 0;
    for(int i = 0; i < N; i++){
        long long curCost = min(abs(X[i]), abs(Y[i]));
        for(int y : ewRoads) curCost = min(curCost, abs(Y[i]-y));
        sum += curCost*P[i];
    }
    return sum;
}

int main(){
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> arr[i].f.f >> arr[i].f.s >> arr[i].s;
        ret[i] = INF/5;
    }
    sort(arr, arr+N);
    for(int i = 0; i < N; i++){
        X[i] = arr[i].f.f;
        Y[i] = arr[i].f.s;
        P[i] = arr[i].s;
    }
    for(int mask = 0; mask < (1<<N); mask++){
        int ew = __builtin_popcount(mask);
        ewRoads = vector<int>();
        for(int i = 0; i < N; i++){
            if(mask&(1<<i))
                ewRoads.pb(Y[i]);
        }
        memset(dp, -1, sizeof(dp));
        ret[ew] = min(ret[ew], calcEW());
        for(int ns = 1; ns <= N-ew; ns++){
            for(int i = 0; i < N; i++)
                ret[ew+ns] = min(ret[ew+ns], solveIt(0, i, ns-1));
        }
    }
    for(int i = 0; i <= N; i++) cout << ret[i] << '\n';
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#define INPUT_FROM_FILE (0)

#if INPUT_FROM_FILE
#include <fstream>
#endif


int main(int argc, char **argv) {
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
	int n = 0;
	std::vector<int> v;
	std::vector<int> min_v;
	std::vector<int> max_v;
	int max = 0;

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	v.resize(n, 0);
	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		ifs >> v[i];
#else
		std::cin >> v[i];
#endif
	}

	min_v.resize(n, 0);
	max_v.resize(n, 0);

	min_v[0] = v[0];
	max_v[n - 1] = 0;
	for(int i = 1; i < n; i++){
		int j = n - i - 1;
		min_v[i] = std::min(v[i], min_v[i - 1]);
		max_v[j] = std::max(v[j + 1], max_v[j + 1]);
	}

	max = v[1] - v[0];
	for(int i = 1; i < n - 1; i++){
		max = std::max(max, max_v[i] - min_v[i]);
	}

	std::cout << max << std::endl;
	return 0;
}

Measured memory_bytes: 5216
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, z = 1, l = 0;
    pii a[100005] = {};
    cin >> n >> m;
    for (int i = 0; i < m; i++) cin >> a[i].second >> a[i].first, a[i].first--;
    sort(a, a + m);
    for (int i = 1; i < m; i++) if (a[i].second > a[l].first) l = i, z++;
    cout << z;
}


Measured memory_bytes: 1024
def f(a, m):
    total = 0
    for a_i in a:
        total += m % a_i
    return total


if __name__ == '__main__':
    n = int(input())
    a = map(int, input().split())
    ans = sum([a_i - 1 for a_i in a])
    print(ans)

    # n = 7
    # a_str = '994 518 941 851 647 2 581'
    # 
    # a_max = 0
    # a = []
    # for a_i_str in a_str.split():
    #     a_i = int(a_i_str)
    #     a_max = max(a_i, a_max)
    #     a.append(a_i)
    # 
    # # m \in [2, 2 * a_max - 1]
    # f_max = 0
    # for m in range(2, 2 * a_max):
    #     f_m = f(a, m)
    #     f_max = max(f_m, f_max)
    # 
    # print(f_max)
    # 
    # # for i in range(100):
    # #     a = np.random.randint(2, 100000 + 1, n)
    # #
    # #     expected = sum([a_i - 1 for a_i in a])
    # #     actual = max([f(a, m) for m in range(2, 100000 + 1)])
    # #
    # #     print(i, expected, actual)


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

#define int long long
map<pair<int, int>, int> mp;

pair<int, int> fun(int n){
	vector<int> v;
	while(n){
	 	v.push_back(n%10);
	 	n /= 10;
 	}
 	pair<int, int> temp = {v.back(), v.front()};
 	return temp;
}
int32_t main(){
 	ios::sync_with_stdio(false);
 	cin.tie(0);

 	int n; cin >> n;
 	for(int i = 1; i <= n; i++){
 		mp[fun(i)]++;
 	}
 	int cnt = 0;
 	for(int first = 1; first <= 9; first++){
 	 	for(int second = 1; second <= 9; second++){
 	 	  	cnt += mp[{first, second}]*mp[{second, first}];
 	 	}
 	}
 	cout << cnt << '\n';

 	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


x, k, d = MI()

q, r = divmod(abs(x), d)

if q > k:
    print(abs(x) - (k * d))
else:
    if q % 2 == 0:
        if k % 2 == 0:
            print(r)
        else:
            print(d - r)
    else:
        if k % 2 == 0:
            print(d - r)
        else:
            print(r)


Measured memory_bytes: 9192
S=list(input())
a=0
b=[0]
for i in range(len(S)-1):
    if S[i]=='A' or S[i]=='C' or S[i]=='G' or S[i]=='T':
        b[len(b)-1]+=1
    if (S[i]=='A' or S[i]=='C' or S[i]=='G' or S[i]=='T') and (S[i+1]!='A' and S[i+1]!='C' and S[i+1]!='G' and S[i+1]!='T'):
        b.append(0)
if S[len(S)-1]=='A' or S[len(S)-1]=='C' or S[len(S)-1]=='G' or S[len(S)-1]=='T':
    b[len(b)-1]+=1
print(max(b))          

Measured memory_bytes: 9172
#include <iostream>

using namespace std;

int bubbleSort(int*,int);
void trace(int*, int);

#define MAXDATA 100

int main(){
    int N;
    int i;
    int sw;
    int A[MAXDATA];

    cin >> N;
    
    for (i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    sw = bubbleSort(A, N);

    trace(A,N);
    cout << endl;

    cout << sw;

    cout << endl;

}

int bubbleSort(int *A, int N) {
    int flag = 1;
    int tmp;
    int j;
    int sw = 0;

    while (flag) {
        flag = 0;
        for (j = N-1; j > 0; j--) {
            if (A[j] < A[j-1]) {
                tmp = A[j-1];
                A[j-1] = A[j];
                A[j] = tmp;
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

void trace(int *A, int N) {
    int i;
    
    for (i = 0;i < N; i++) {
        if (i) {
            cout << " ";
        }
        cout << A[i];
    }
}

Measured memory_bytes: 1160
fun main(args: Array<String>) {
    val (a,b,c)= readLine()!!.split(" ").map { it.toInt() }
    listOf(
            listOf(a,b,c),
            listOf(a,c,b),
            listOf(b,a,c),
            listOf(b,c,a),
            listOf(c,a,b),
            listOf(c,b,a)
    ).map { Math.abs(it[0]-it[1])+Math.abs(it[1]-it[2]) }.min().let { println(it) }
}

Measured memory_bytes: 38024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#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 ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
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; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

char in[120];
pair<pair<string, int>,int> p[110];
int main(){
  INIT;
    int a;scanf("%d", &a);
    for(int i=0;i<a;i++){
        int t;
        scanf("%s%d",in,&t);
        string tmp=in;
        p[i]=make_pair(make_pair(in,-t),i);
    }
    sort(p, p+a);
    for(int i=0;i < a; i++)printf("%d\n",p[i].second+1);
  return 0;
}


Measured memory_bytes: 256