akhauriyash/Code-Regression huggingface dataset:
//#include "stdc++.h"
#include<bits/stdc++.h>
#include<iostream>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define pb push_back
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0) return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p; }
#define flush fflush(stdout)
const ll MOD =998244353;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
/*****
 IT IS A VERY GOOD QUESTION ON GRAPH+NUMBER-THEORY FROM TOPCODER   http://arc084.contest.atcoder.jp/tasks/arc084_b
 
 READ ITS EDITORIAL FOR BETTER UNDER STANDING OF THESE TYPE OF QUESTIONS
 Here I'll keep the list of problems to train this idea:
 1. https://csacademy.com/contest/archive/task/0-k-multiple/
 2. http://www.spoj.com/problems/INUMBER/
 3. http://main.edu.pl/en/archive/oi/10/sum
 4. https://codeforces.com/contest/1070/problem/A
 IT WILL VISIT EACH VERTEX AT MOST 2 TIMES;
 IT IS 0-1 BFS;
 ****/
int main()
{
    int k;
    cin>>k;
   // bool visited[k];
   // memset(visited,0,sizeof(visited));
    deque<int>q;
    int ans[k];
    for(int i=0;i<k;i++)
        ans[i]=1000000000;
    q.push_front(1);
    ans[1]=0;int u,v1,v2;
    while(!q.empty())
    {
        u=q.front();
        q.pop_front();
        v1=(u*10)%k;
        v2=(u+1)%k;
        if(ans[v1]>ans[u])
        {
            ans[v1]=ans[u];
            q.push_front(v1);
        }
        if(ans[v2]>ans[v1]+1)
        {
            ans[v2]=1+ans[u];
            q.push_back(v2);
        }
    }
    cout<<ans[0]+1<<endl;
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
 
 
typedef long long ll;
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'


int main() {
  int n;
  cin >> n;
  vi d(n);
  rep (i, n) cin >> d[i];
  int ans = 0;
  rep (i, n) {
    for (int j = i + 1; j < n; j++) {
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int A,B;
        A=s.nextInt();
        B=s.nextInt();
        
        if(B%A==0){
            System.out.println(A+B);
        }
        else{
            System.out.println(B-A);
        }
    }  
}

Measured memory_bytes: 23124
n = int(input())
h = list(map(int, input().split()))
x,y,ans=0,0,0
ok=True
while ok:
    for i in range(n):
        if h[i]!=0:
            x=i
            break
        if i==n-1 and h[i]==0:
            ok=False
    for i in range(x,n):
        if h[i]==0:
            y=i-1
            break
        y=n-1
    for i in range(x,y+1):
        h[i]-=1
    x,y=0,0
    ans+=1
print(ans-1)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
j = 0
for i in A:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 == 0:
            pass
        else:
            j += 1
    else:
        pass
if j > 0:
    print('DENIED')
else:
    print('APPROVED')


Measured memory_bytes: 9016
n,q=map(int,input().split())
neighbor=[[]  for _ in range(n+1)]
ans=[0]*(n+1)

for _ in range(n-1):
    a,b=map(int,input().split())
    neighbor[a].append(b)
    neighbor[b].append(a)


for _ in range(q):
    p,x=map(int,input().split())
    ans[p]+=x

visit=[True]*(n+1)
tmp=[1]
for x in tmp:
    visit[x]=False
    for y in neighbor[x]:
        if visit[y]:
            tmp.append(y)
            ans[y]+=ans[x]

print(*ans[1:])


Measured memory_bytes: 105344
def main():
    s = str(input())
    t = str(input())
    pos = 0
    for i in range(len(s)):
        if s[i] == t[0]:
            pos = i
            break
    l = pos
    pos = 0
    for i in range(l,len(s)):
        if(s[i] != t[pos]):
            print("No")
            return 0
        pos = pos + 1
    if pos != len(t):
        for i in range(len(s)):
            if(pos >= len(t)):
                break
            if(s[i] != t[pos]):
                print("No")
                return 0
            pos = pos + 1

    print("Yes")
main()

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

int n,temp,ans=0;

map<int,int> m;
map<int,int>::iterator it;

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>temp;
		m[temp]++;
	}
	for (it=m.begin();it!=m.end();it++)
	{
		if ((it->second)>(it->first))  ans+=((it->second)-(it->first));
		else if ((it->second)<(it->first))  ans+=(it->second);
	}
	cout<<ans<<endl;
	
	return 0;
} 

Measured memory_bytes: 6272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))

int main()
{
	int n;
	while(cin >> n , n)
	{
		vector<int> w(n,0);
		for(int i = 0;i < n;i++)
		{
			cin >> w[i];
		}
		
		vector<vector<int>> dp(n + 1,vector<int>(n + 1,0));

		for(int W = 2;W <= n;W++)
		{
			//left
			for(int l = 0;l < n;l++)
			{
				int r = l + W - 1;
				if(r >= n) continue;

				if(dp[l + 1][r - 1] == W - 2 && abs(w[l] - w[r]) <= 1)
					dp[l][r] = W;

				for(int mid = l;mid <= r;mid++)
				{
					dp[l][r] = max(dp[l][r] , dp[l][mid] + dp[mid + 1][r]);
				}

			}

		}

		cout << dp[0][n - 1] << endl;
	}
	return 0;
}




Measured memory_bytes: 3204
N=input()
l=len(N)
ten=10**(l-1)
N=int(N)
I=N//ten
after=9*(l-1)
a=str(9)*(l-1)
i=str(I)
v=i+a
V=int(v)
if N>=V:
  print(I+after)
else:
  print(I+after-1)

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;
// const double PI = M_PI;

struct uf_tree {
  vector<int> par, sizes;
  uf_tree(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
    }
  }
  int find(int x) {
    if (x == par[x]) {
      return x;
    }
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return;
    }
    if (sizes[x] < sizes[y]) {
      swap(x, y);
    }
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sizes[find(x)]; }
};

int N, M;
vector<int> a, b;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  a.resize(M);
  b.resize(M);
  rep(i, M) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  int ans = 0;
  rep(i, M) {
    uf_tree ut(N);
    rep(j, M) {
      if (i != j) {
        ut.unite(a[j], b[j]);
      }
    }
    if (ut.size(0) != N) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string S;
  int N;
  
  cin >> N;
  cin >> S;
  
  int A = S.size();
  
  for(int i=0; i<A; i++){
    S[i]+=N;
    
    int V = S[i];
    
    if(V>=91){
      
      S[i] -= 26;
      
     cout << S[i];
    }
    
    else{
     cout << S[i]; 
    }
    
  }
  
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e8;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int H, W, h, w;
  cin >> H >> W >> h >> w;

  if (H % h == 0 && W % w == 0) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
  if (W % w != 0) {
    vector<int> s(W + 1, 0);
    FOR(i, 1, W + 1) {
      s[i] = (i < w ? inf : s[i - w] - 1);
    }
    rep(i, H) {
      rep(j, W) {
        cout << s[j + 1] - s[j] << ' ';
      }
      cout << '\n';
    }
    return 0;
  }
  if (H % h != 0) {
    vector<int> s(H + 1, 0);
    FOR(i, 1, H + 1) {
      s[i] = (i < h ? inf : s[i - h] - 1);
    }
    rep(i, H) {
      rep(j, W) {
        cout << s[i + 1] - s[i] << ' ';
      }
      cout << '\n';
    }
    return 0;
  }


  




  
  return 0;
}

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

int main() {
  long long N, K;
  cin >> N >> K;

  if (N < abs(N - K)) {
    cout << N << endl;
    return 0;
  } else {
    long long X = (N + K - 1) / K;
    cout << abs(N - (X * K)) << endl;
  }
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

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

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5;

template<class T> bool ckmin(T& a, const T& b) {
    return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template <typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template <typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template <class X, class Y>
std::ostream & operator << (std::ostream & os, std::pair <X, Y> const& p) {
    return os << p.first << " " << p.second;
}

template <class Ch, class Tr, class Container>
std::basic_ostream <Ch, Tr> & operator << (std::basic_ostream <Ch, Tr>& os, Container const& x) {
    bool first = true;
    for(auto& y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BMixJuice {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n, k;
        in >> n >> k;
        vi P(n);
        in >> P;
        sort(all(P));
        int res = accumulate(P.begin(), P.begin() + k, 0);
        out << res << '\n';
	}

	void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
	BMixJuice solver;
    solver.setup();
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
	solver.solve(in, out);
	return 0;
}


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

int main()
{
    int x[3000],y[3000];
    int i;

    i = 0;
    do
    {
        i++;
        cin >> x[i] >> y[i] ;
    } while (x[i] || y[i]);

    i = 1;
    while (x[i] || y[i])
    {
        if (x[i] > y[i])
        {
            int c;
            c = x[i];
            x[i] = y[i];
            y[i] = c;
        }
        cout << x[i] << " " << y[i] << endl;
        i++;
    }

    return 0;
}



Measured memory_bytes: 3120
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                var n = line.Split(' ').Select(int.Parse).ToArray();
                var max = 20 - n[0] - n[1];
                Console.WriteLine((double)(max - (n[0] <= max ? 1 : 0) - (n[1] <= max ? 1 : 0) - (n[2] <= max ? 1 : 0)) / 7 >= 0.5 ? "YES" : "NO");
            }
        }
    }
}

Measured memory_bytes: 5656
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 9223372036854775807
#define mini 9223372036854775807
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll c=power(a,b/2);
	if(b%2==0)
		return ((c%mod)*(c%mod))%mod;
	else
		return ((((c%mod)*(c%mod))%mod)*a)%mod;
}
string str;
ll dp[200005][5];
ll func(ll x,ll y)
{
	if(dp[x][y]!=-1)
		return dp[x][y];
	if(x==str.size())
		return 0;
	if(x>str.size())
		return -1000006;
	if(y==0)
		return dp[x][y]=1+max(func(x+1,1),func(x+2,2));
	else if(y==1)
	{
		if(str[x]==str[x-1])
			return dp[x][y]=1+func(x+2,2);
		else
			return dp[x][y]=1+max(func(x+1,1),func(x+2,2));
	}
	else
	{
		if(str[x]==str[x-2] && str[x+1]==str[x-1])
			return dp[x][y]=1+func(x+1,1);
		else
			return dp[x][y]=1+max(func(x+1,1),func(x+2,2));
	}
}
int main()
{
	memset(dp,-1,sizeof(dp));
	boost
	cin>>str;
	cout<<func(0,0)<<endl;
	return 0;
}

Measured memory_bytes: 14612
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args){

        Scanner scan=new Scanner(System.in);
        String s="",t="";
        if(scan.hasNext())
            s=scan.next();
        if(scan.hasNext())
            t=scan.next();
        int[][] dp=new int[s.length()+1][t.length()+1];
        for(int i=1;i<=s.length();i++){
            for(int j=1;j<=t.length();j++){
                if(s.charAt(i-1)==t.charAt(j-1)){
                    dp[i][j]=1+dp[i-1][j-1];
                }else{
                    dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        String str="";
        int j=t.length(),i=s.length();

            while(j>=1 && i>=1) {
                if (s.charAt(i - 1) == t.charAt(j - 1)) {
                    str = s.charAt(i - 1) + str;
                    i--;
                    j--;
                } else{
                    if(dp[i-1][j]>=dp[i][j-1]){
                        i--;
                    }else{
                        j--;
                    }
                }
            }


        System.out.println(str);
    }
}


Measured memory_bytes: 89164
#include<stdio.h>
int main()
{
    int i,n,x=0;
    scanf("%d",&n);
    for(i=1;i<=9;i++)
    {
        if(n%i==0 && n/i<=9)
            {
         printf("Yes\n");
         x=1;
         break;
        }


    }
     if(x==0)
        printf("No\n");

    return 0;



    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define riterator reverse_iterator
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const llong INF = 1e12;

namespace NetFlow
{
	const int N = 2006;
	const int M = 10000;
	struct AEdge
	{
		int u,v,wl,wr; llong c;
	} ae[M+3];
	struct Edge
	{
		int u,v,nxt,w; llong c;
	} e[(M<<1)+3];
	int fe[N+3];
	llong dis[N+3];
	int que[N+5];
	bool inq[N+3];
	int lst[N+3];
	int n,m,en,s,t; llong mf,mc;
	void addedge(int u,int v,int w,llong c)
	{
//		printf("addedge %d %d %d %lld\n",u,v,w,c);
		en++; e[en].u = u,e[en].v = v,e[en].w = w,e[en].c = c;
		e[en].nxt = fe[u]; fe[u] = en;
		en++; e[en].u = v,e[en].v = u,e[en].w = 0,e[en].c = -c;
		e[en].nxt = fe[v]; fe[v] = en;
	}
	bool spfa()
	{
		for(int i=1; i<=n; i++) dis[i] = -INF;
		int hd = 1,tl = 2; que[1] = s; dis[1] = 0;
		while(hd!=tl)
		{
			int u = que[hd]; hd++; if(hd>n+1) hd-=n+1;
			for(int i=fe[u]; i; i=e[i].nxt)
			{
				int v = e[i].v;
				if(e[i].w>0&&dis[e[i].v]<dis[u]+e[i].c)
				{
					dis[e[i].v] = dis[u]+e[i].c; lst[e[i].v] = i;
					if(!inq[e[i].v])
					{
						inq[e[i].v] = true;
						que[tl] = e[i].v; tl++; if(tl>n+1) tl-=n+1;
					}
				}
			}
			inq[u] = false;
		}
		return dis[t]!=-INF;
	}
	void calcflow()
	{
		int flow = 1e5;
		for(int u=t; u!=s; u=e[lst[u]].u)
		{
			flow = min(flow,e[lst[u]].w);
		}
		for(int u=t; u!=s; u=e[lst[u]].u)
		{
			e[lst[u]].w -= flow; e[lst[u]^1].w += flow;
		}
		mf += flow; mc += 1ll*flow*dis[t];
	}
	llong mfmc(int _n,int _s,int _t)
	{
		n = _n,s = _s,t = _t; mf = 0,mc = 0ll;
		while(spfa()) {calcflow();} return mc;
	}
}
using NetFlow::addedge;

const int N = 1000;
struct Point
{
	int x,y,cnt;
} a[N+3],b[N+3];
int n;

int main()
{
	NetFlow::en = 1;
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].cnt);
	for(int i=1; i<=n; i++) scanf("%d%d%d",&b[i].x,&b[i].y,&b[i].cnt);
	for(int i=1; i<=n; i++)
	{
		addedge(1,i+6,a[i].cnt,0);
		addedge(i+6,3,a[i].cnt,-a[i].x-a[i].y);
		addedge(i+6,4,a[i].cnt,-a[i].x+a[i].y);
		addedge(i+6,5,a[i].cnt,a[i].x-a[i].y);
		addedge(i+6,6,a[i].cnt,a[i].x+a[i].y);
	}
	for(int i=1; i<=n; i++)
	{
		addedge(i+n+6,2,b[i].cnt,0);
		addedge(3,i+n+6,b[i].cnt,b[i].x+b[i].y);
		addedge(4,i+n+6,b[i].cnt,b[i].x-b[i].y);
		addedge(5,i+n+6,b[i].cnt,-b[i].x+b[i].y);
		addedge(6,i+n+6,b[i].cnt,-b[i].x-b[i].y);
	}
	llong ans = NetFlow::mfmc(n+n+6,1,2);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 768
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int K = sc.nextInt();
    int[] A = new int[M];
    int[] B = new int[M];
    for (int i = 0; i < M; i++) {
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
    }
    int[] C = new int[K];
    int[] D = new int[K];
    for (int i = 0; i < K; i++) {
      C[i] = sc.nextInt();
      D[i] = sc.nextInt();
    }
    sc.close();

    Map<Integer, Set<Integer>> f = new HashMap<>();
    for (int i = 0; i < M; i++) {
      Integer a = Integer.valueOf(A[i]);
      Integer b = Integer.valueOf(B[i]);
      if (!f.containsKey(a)) f.put(a, new HashSet<>());
      f.get(a).add(b);
      if (!f.containsKey(b)) f.put(b, new HashSet<>());
      f.get(b).add(a);
    }

    Map<Integer, Set<Integer>> b = new HashMap<>();
    for (int i = 0; i < K; i++) {
      Integer c = Integer.valueOf(C[i]);
      Integer d = Integer.valueOf(D[i]);
      if (!b.containsKey(c)) b.put(c, new HashSet<>());
      b.get(c).add(d);
      if (!b.containsKey(d)) b.put(d, new HashSet<>());
      b.get(d).add(c);
    }

    int[] gn = new int[N + 1];
    int[] gc = new int[N + 1];
    for (int i = 1; i < N + 1; i++) {
      if (gn[i] != 0) continue;

      Deque<Integer> q = new ArrayDeque<>();
      q.addLast(i);
      while (!q.isEmpty()) {
        Integer n = q.pollLast();
        if (gn[n] != 0) continue;
        gn[n] = i;
        gc[i]++;
        q.addAll(f.getOrDefault(n, Collections.emptySet()));
      }
    }

    int[] ans = new int[N + 1];
    for (int i = 1; i < N + 1; i++) {
      ans[i] = gc[gn[i]] - 1;

      Integer a = Integer.valueOf(i);
      Set<Integer> na = new HashSet<>();
      na.addAll(b.getOrDefault(a, Collections.emptySet()));
      na.addAll(f.getOrDefault(a, Collections.emptySet()));

      for (Integer n : na)
        if (gn[i] == gn[n]) ans[i]--;
    }

    StringBuilder buf = new StringBuilder();
    for (int i = 1; i < N + 1; i++)
      buf.append(ans[i]).append(" ");
    buf.setLength(buf.length() - 1);
    System.out.println(buf);
  }
}

Measured memory_bytes: 218100
N, X = gets.split.map(&:to_i)
L = gets.split.map(&:to_i)

jump = [0]
count = 1

1.upto(N) do |i|
  jump[i] = jump[i-1] + L[i-1]
  count += 1 if jump[i] <= X
end

puts count

Measured memory_bytes: 1788
def gcd(a, b):
    if b == 0: 
        return a 
    else: 
        return gcd(b, a % b)

def lcm(a, b):
    return a * b // gcd(a, b)

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

m = 1

for i in a:
    m = lcm(m, i)

m -= 1
ans = 0

for e in a:
    ans += m % e

print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define int LL
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
int lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}
const int MAX_N=300005;
int n;
int pre[MAX_N*3];
int rev[MAX_N*3];
int a[MAX_N*3];
signed main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	cin>>n;
	For(i,1,3*n)cin>>a[i];
	priority_queue <GREATER(int)> q1;
	For(i,1,3*n)
	{
		pre[i]=pre[i-1]+a[i];
		q1.push(a[i]);
		if(q1.size()>n)
		{
			pre[i]-=q1.top();
			q1.pop();
		}
	}
	priority_queue <int> q2;
	per(i,3*n,1)
	{
		rev[i]=rev[i+1]+a[i];
		q2.push(a[i]);
		if(q2.size()>n)
		{
			rev[i]-=q2.top();
			q2.pop();
		}
	}
	int ans=-LONG_LONG_MAX;
	For(i,n,2*n)
	{
		ans=max(ans,pre[i]-rev[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 16244
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::greater<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  cin >> n;
  vector<vector<pair<int, int>>> d(n);
  vector<int> mx(1'000'001, 0);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    for (int j = 2; j * j <= x; ++j) {
      int c = 0;
      for (; x % j == 0; x /= j, ++c);
      if (c) {
        d[i].emplace_back(j, c);
        mx[j] = max(mx[j], c);
      }
    }
    if (x != 1) {
      d[i].emplace_back(x, 1);
      mx[x] = max(mx[x], 1);
    }
  }
  vector<int64> b(n, 1);
  vector<pair<int, int>> c;
  for (int i = 0; i < (int)mx.size(); ++i) {
    if (mx[i]) {
      c.emplace_back(i, mx[i]);
    }
  }
  for (int i = 0; i < n; ++i) {
    int p = 0;
    for (const auto& pr : c) {
      while (p < (int)d[i].size() && d[i][p].first < pr.first) {
        ++p;
      }
      int x = 0;
      if (p < (int)d[i].size() && d[i][p].first == pr.first) {
        x = d[i][p].second;
      }
      for (int j = x; j < pr.second; ++j) {
        b[i] *= pr.first;
        b[i] %= mod;
      }
    }
  }
  int64 ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += b[i];
    ans %= mod;
  }
  cout << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);

const int N=5010;

int n,a,b;
int p[N],f[N];

main(){
    #define task "agc032_d"
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);

    n=in,a=in,b=in;
    forinc(i,1,n) p[i]=in;
    p[n+1]=n+1, n++;
    reset(f,127);
    f[0]=0;
    forinc(i,1,n){
        int cntx=0,cnty=0;
        fordec(j,i-1,0){
            if(p[j]<p[i]) f[i]=min(f[i],f[j]+cntx*b+cnty*a);
            if(p[j]<p[i]) cntx++; else cnty++;
        }
    }
    cout<<f[n];
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	ll A,B,C; cin >> A >> B >> C;
	if(C-A-B>0&&4*A*B<(C-A-B)*(C-A-B)) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	int a[n];
	long long sum = 0;
	for(int i = 0; i < n; i++) cin >> a[i], sum += a[i];
	long long ans = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
	for(int i = 0; i < n - 1; i++) sum -= 2 * a[i], ans = min(ans, llabs(sum));
	cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vl x(n), y(n);
    rep(i, n) {
        cin >> x[i];
        y[i] = x[i];
    }
    sort(all(y));

    ll m = n/2;
    ll a = y[m-1];
    ll b = y[m];
    rep(i, n) {
        if(x[i] <= a) {
            out(b);
        }
        else if(b <= x[i]) {
            out(a);
        }
    }

    re0;
}

Measured memory_bytes: 5376
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int*makeSA(char*s,int len){
	len++;
	int*SAidx=calloc(len,sizeof(int));
	int*ord=calloc(len,sizeof(int));
	//1文字目
	int cnt1[256]={},cnt2[256]={};
	for(int i=0;i<len;i++)cnt1[s[i]+1]++,cnt2[s[i]+1]|=1;
	for(int i=1;i<256;i++)cnt1[i]+=cnt1[i-1],cnt2[i]+=cnt2[i-1];
	for(int i=0;i<len;i++)SAidx[cnt1[s[i]]++]=i,ord[i]=cnt2[s[i]];
	
	int*cnt=calloc(len+1,sizeof(int));
	int*idx2=calloc(len,sizeof(int));
	int*temp=calloc(len,sizeof(int));
	for(int k=1;k<len;k*=2){
		//2*k文字まで見る
		for(int i=0;i<len;i++)cnt[i]=0;
		for(int i=0;i<len;i++)cnt[ord[i]+1]++;
		for(int i=1;i<len;i++)cnt[i]+=cnt[i-1];
		for(int i=0;i<len;i++)idx2[cnt[ord[(SAidx[i]-k+len)%len]]++]=(SAidx[i]-k+len)%len;
		temp[idx2[0]]=0;
		for(int i=1;i<len;i++)temp[idx2[i]]=temp[idx2[i-1]]+(ord[idx2[i-1]]!=ord[idx2[i]]||ord[(idx2[i-1]+k)%len]!=ord[(idx2[i]+k)%len]);
		for(int i=0;i<len;i++)ord[i]=temp[i],SAidx[i]=idx2[i];
	}
	free(temp);
	free(idx2);
	free(cnt);
	free(ord);
	return SAidx+1;
}
int find(char*t,int tlen,char*s,int slen,int*SAidx){
	int l=0,r=slen;
	while(r-l>1){
		int m=(l+r)/2;
		int flag=memcmp(s+SAidx[m],t,tlen);
		if(flag==0)return 1;
		else if(flag<0)l=m;
		else r=m;
	}
	return !memcmp(s+SAidx[l],t,tlen);
}

char s[1000010];
char t[1010];
int main(){
	scanf("%s",s);
	int n=strlen(s);
	int*idx=makeSA(s,n);
	int q;
	scanf("%d",&q);
	while(q--){
		scanf("%s",t);
		puts(find(t,strlen(t),s,n,idx)?"1":"0");
	}
}


Measured memory_bytes: 21828
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
//int freq[1000000+5];
//vector<int> g[100002];
//bool vis[100002];
//vector<int> clr;
 
int main(){
	//freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	int n;
	scanf("%d",&n);
	string s;
	cin>>s;
	if(n%2){
		printf("No\n");
		return 0;
	}
	for(int i=0;i<n/2;i++){
		if(s[i]!=s[i+(n/2)]){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
    return 0;
}


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



int main() {
  int a, b; cin >> a >>b;
  a += b;
  if (a < 10) cout << a << endl;
  else cout << "error" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
int n, a[2][105], ans;
int main ()
{
scanf ("%d",&n);
for (int i = 1; i <= n; i ++)
scanf ("%d",&a[0][i]);
for (int i = 1; i <= n; i ++)
scanf ("%d",&a[1][i]);
for (int i = 1; i <= n; i ++)
{
int sum = 0;
bool ml = 0;
for (int j = 1;j <= n;j ++)
{
sum += a[ml][j];
if (i == j)
{
ml = 1;
sum += a[1][j];
}
}
ans = ans> sum? ans:  sum;
}
printf ("% d", ans);
}

Measured memory_bytes: 128
a, b, c = map(int, input().split())

flg = True
cnt = a + b + c
cnt_max = max(a, b, c)
ans = 0
while(flg):
    if cnt % 3 == 0 and cnt / 3 >= cnt_max:
        flg = False
    else:
        cnt += 2
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
#include <stdio.h>
#define int long long
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}

/*ライブラリゾーン！！！！！！！！！！！！！！！*/
int a, r[200010];
map<int, int >mp;
signed main(){
	int n;
	int ans = 0;
	cin >> n >> r[0];
	for (int i = 1; i < n; i++) {
		cin >> a;
		r[i] = r[i - 1] + a;
	}
	mp[0] = 1;
	for (int i = 0; i < n; i++) {
		ans += mp[r[i]];
		mp[r[i]]++;
	}
	cout << ans << endl;
	system("PAUSE");
	return 0;
}


Measured memory_bytes: 14584
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll M;
vector<ll> d, c;
ll D, S;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> M;
  d.resize(M);
  c.resize(M);
  for (int i = 0; i < M; i++) {
    cin >> d[i] >> c[i];
    D += c[i];
    S += (d[i] * c[i]);
  }

  ll ans = D - 1 + (S - 1) / 9;

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

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

public class Main {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	final int MOD = 1000000007;
	int[] dx = { 1, 0, 0, -1 };
	int[] dy = { 0, 1, -1, 0 };

	void run() {
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[][] select = new int[N][2];
		for (int i = 0; i < N; i++) {
			select[i][0] = sc.nextInt();
		}

		for (int i = 0; i < M; i++) {
			int money = sc.nextInt();
			for (int j = 0; j < N; j++) {
				if (select[j][0] <= money) {
					select[j][1]++;
					break;
				}
			}
		}
		int ans = 0;
		int max = 0;
		for (int i = 0; i < N; i++) {
			if (select[i][1] > max) {
				max = select[i][1];
				ans = i;
			}
		}
		System.out.println(ans + 1);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

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

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

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n + m == 0) return 0;
    
    vector<int> maximum(n), minimum(n);
    for (int i = 0; i < m; i++) {
      int s, k;
      cin >> s >> k;
      for (int j = 0; j < k; j++) {
        int c;
        cin >> c;
        c--;
        if (k == 1) minimum[c] += s;
        maximum[c] += s;
      }
    }
    
    vector<int> minl(n, 1e9), minr(n, 1e9);
    for (int i = 1; i < n; i++) minl[i] = min(minl[i - 1], minimum[i - 1]);
    for (int i = n - 2; i >= 0; i--) minr[i] = min(minr[i + 1], minimum[i + 1]);
    
    int diff = 0;
    for (int i = 0; i < n; i++) diff = max(diff, maximum[i] - min(minl[i], minr[i]));
    
    cout << diff + 1 << '\n';
  }
}


Measured memory_bytes: 3240
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = j; i < (int)n; ++i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
using namespace std;

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

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
    ll a, b, c, d; cin >> a >> b >> c >> d;

    --a;
    ll l = c / gcd(c, d) * d;
    ll e = b - b / c - b / d + b / l;
    ll f = a - a / c - a / d + a / l;
    cout << e - f << endl;
	return 0;
}


Measured memory_bytes: 3620
# map(int, input().split())
# list(map(int, input().split()))
# for _ in range(int(input())):
# print(' '.join([str(x) for x in ans]))

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

inc = -1
num = 1

prev = a[0]
for x in a:
    if x>prev:
        if inc == -1:
            inc = 1
        elif inc == 0:
            num += 1
            inc = -1
    elif x < prev:
        if inc == -1:
            inc = 0
        elif inc == 1:
            num += 1
            inc = -1
    prev = x

print(num)


Measured memory_bytes: 62704
from collections import deque

s = deque(input())
q = int(input())
flip = 1
for i in range(q):
    T = input().split()
    if T[0] == '1':
        flip *= -1
    else:
        _flip = 1 if T[1]=='1' else -1
        if (flip * _flip)==1:
            s.appendleft(T[2])
        else:
            s.append(T[2])
print("".join(s) if flip==1 else "".join(reversed(s)))

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

using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int sum = 0;
	int m1 = m/10;
	int m2 = m%10;
	for(int i = 2;i <= 9;i++){
		for(int j = 2;j <= 9;j++){
			if(i*j <= n && i*10+j <= m){
				sum++;
			}
		}
	}
	cout<<sum<<endl;
} 

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

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

Measured memory_bytes: 256
def main():
    n = input()
    a = ['2', '4', '5', '7', '9']
    b = ['0', '1', '6', '8']
    if n[-1] in a:
        print('hon')
    elif n[-1] in b:
        print('pon')
    else:
        print('bon')



if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
  vector<int> sen(3);
  for(auto &x:sen){
    cin>>x;
  }
  
  
  sort(sen.begin(),sen.end());
  
  if(sen[0]==5&&sen[1]==5&&sen[2]==7){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
    int a,b,d,r;
    double f;
   
    cin >>a >>b;
    d = a/b;
    r= a%b;
    f = (double)a/(double)b;
    printf("%d %d %f", d, r, f);
    return 0;
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define eps 1e-9;
#define MOD 1000000007;
#define INV_10 299473306;
using namespace std;
int main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  long long x;
  cin >> x;
  cout << (x/500)*1000+((x%500)/5)*5 << '\n';
}

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) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

const ll MAX = 1100000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	int X, Y;
	cin >> X >> Y;

    int a = (2*X-Y) / 3;
    int b = (2*Y-X) / 3;
    if (X != a*2+b || Y != a+2*b) {
        cout << 0 << endl;
        return 0;
    }
    // cout << a << " " << b << endl;

    // 前処理
    COMinit();

    ll ans = COM(a+b, a);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 25984
import math
l=10**9+7

n,a,b=map(int,input().split())
comb=[1]

for i in range(max(a,b)):
    den=i+1
    num=n-i
    ans=comb[i]*num*pow(den,l-2,l)%l
    comb.append(ans)


print((pow(2,n,l)-1-comb[a]-comb[b])%l)

Measured memory_bytes: 11052
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll MOD = 1000000007;


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

  ll f = 1;
  rep(i,N){
    f *= (i+1);
    f %= MOD;
  }
  
  unordered_map<int,ll> memo;
  memo[0] = 1;
  rep(i,S.size()){
    unordered_map<int,ll> nxt;
    if(S[i] == 'B'){
      FOR(it,memo){
        if((it->first)%2==0){
          nxt[it->first + 1] += (it->second);
          nxt[it->first + 1] %= MOD;
        }else{
          nxt[it->first - 1] += ((it->first) * (it->second)) % MOD;
          nxt[it->first - 1] %= MOD;          
        }
      }
    }else{
      FOR(it,memo){
        if((it->first)%2==1){
          nxt[it->first + 1] += (it->second);
          nxt[it->first + 1] %= MOD;
        }else{
          if(it->first > 0){
            nxt[it->first - 1] += ((it->first) * (it->second)) % MOD;
            nxt[it->first - 1] %= MOD;
          }
        }
      }
    }
    /*
    cout << i << endl;
    FOR(it,nxt){
      cout << "\t" << (it->first) << "\t" << (it->second) << endl;
    }
    cout << endl;
     */
    swap(memo,nxt);
  }

  ll ret = memo[0];
  ret *= f;
  ret %= MOD;
  
  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 640
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void get_N1234 (int64 *n1, int64 *n2, int64 *n3, int64 *n4)
{
  int cnt;

  if (n2 == NULL) {
    cnt = scanf("%lld", n1);
    return;
  }
  if (n3 == NULL) {
    cnt = scanf("%lld %lld", n1, n2);
    return;
  }
  if (n4 == NULL) {
    cnt = scanf("%lld %lld %lld", n1, n2, n3);
    return;
  }
  cnt = scanf("%lld %lld %lld %lld", n1, n2, n3, n4);
  return;
}

void omit_LF (void)
{
  char c;
  int  cnt;
  
  cnt = scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;
  int  cnt;

  buf = (char *)malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  return buf;
}

char *get_SN (int64 max, int64 *size)
{
  char *buf;
  int  i;
  int  n;
  int  cnt;

  buf = (char *)malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  n = strlen(buf);

  *size = n;
  
  return buf;
}

int64 *get_NSeq (int64 n)
{
  int64 *buf;
  int64 i;

  buf = (int64 *)malloc((size_t)(n * sizeof(int64)));
  for (i=0; i<n; i++) {
    get_N(&buf[i]);
  }

  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;

typedef int64 simple_t;

int compare_simple(const void *a, const void *b)
{
  simple_t *x;
  simple_t *y;

  x = (simple_t *)a;
  y = (simple_t *)b;

  if (x > y) return 1;
  if (y < x) return -1;

  return 0;
}
void qsort_simple (simple_t *array, int size)
{
  qsort(array, size, sizeof(simple_t), compare_simple);
}

int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}


int resolve1()
{
  int64 R;
  double pi=3.14159;
  double L;

  get_N(&R);

  L = pi*R*2;

  printf("%lf", L);
  return 0;
}

int resolve2()
{
  int64 N,M;
  int64 *A;
  int64 i;
  int64 total = 0;
  int64 play=0;
  
  get_NK(&N, &M);
  A = get_NSeq(M);

  for (i=0; i < M; i++) {
    total += A[i];
  }

  if (N >= total) {
    play = N - total;
  } else {
    printf("-1");
    return 0;
  }

  printf("%lld",play);
  return 0;
}


int main()
{
  int64 K,A,B;
  int64 i;

  get_N(&K);

  get_NK(&A, &B);

  for(i=A; i<=B; i++) {
    if ((i%K) == 0) {
      printf("OK");
      return 0;
    }
  }

  printf("NG");

  return 0;
}



Measured memory_bytes: 1736