akhauriyash/Code-Regression huggingface dataset:
loop do
  n = gets.to_i
  break if n.zero?
  bs = n.times.map { gets.split.map(&:to_i) }
  sb = {}
  bs.each_with_index {|(b, *_), i| sb[b] = i }
  dp = Array.new(n) { Array.new n, Float::INFINITY }
  ps = Array.new(n) { Array.new n }
  n.times {|i| dp[i][i] = 0 }
  n.times.to_a.combination(2) do |i, j|
    d = Math.sqrt (bs[j][1]-bs[i][1])**2+(bs[j][2]-bs[i][2])**2
    if d <= 50
      dp[i][j] = dp[j][i] = d
      ps[i][j] = i
      ps[j][i] = j
    end
  end
  n.times do |k|
    n.times do |i|
      n.times do |j|
        d = dp[i][k] + dp[k][j]
        if d < dp[i][j]
          dp[i][j] = d
          ps[i][j] = ps[k][j]
        end
      end
    end
  end
  gets.to_i.times do
    s, g = gets.split.map {|s| sb[s.to_i] }
    if dp[s][g] < Float::INFINITY
      xs = []
      loop do
        xs << g
        break if s == g
        g = ps[s][g]
      end
      puts xs.reverse.map {|b| bs[b][0] }.join ' '
    else
      puts 'NA'
    end
  end
end

Measured memory_bytes: 8908
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,bool directed>
struct Dinic{
  struct edge {
    Int to;
    T cap;
    Int rev;
    edge(){}
    edge(Int to,T cap,Int rev):to(to),cap(cap),rev(rev){}
  };

  T INF;
  vector<vector<edge> > G;
  vector<Int> level,iter;

  Dinic(){}  
  Dinic(Int n,T INF):INF(INF),G(n),level(n),iter(n){}
  
  void add_edge(Int from,Int to,Int cap){
    G[from].emplace_back(to,cap,G[to].size());
    G[to].emplace_back(from,directed?0:cap,G[from].size()-1);
  }
  
  void bfs(Int s){
    fill(level.begin(),level.end(),-1);
    queue<Int> que;
    level[s]=0;
    que.emplace(s);
    while(!que.empty()){
      Int v=que.front();que.pop();
      for(Int i=0;i<(Int)G[v].size();i++){
        edge &e=G[v][i];
        if(e.cap>0&&level[e.to]<0){
          level[e.to]=level[v]+1;
          que.emplace(e.to);
        }
      }
    }
  }
  
  T dfs(Int v,Int t,T f){
    if(v==t) return f;
    for(Int &i=iter[v];i<(Int)G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[v]<level[e.to]){
        T d=dfs(e.to,t,min(f,e.cap));
        if(d==0) continue;
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;      
      }
    }
    return 0;
  }
  
  T flow(Int s,Int t,T lim){
    T fl=0;
    while(1){
      bfs(s);
      if(level[t]<0||lim==0) break;
      fill(iter.begin(),iter.end(),0);
      
      while(1){
        T f=dfs(s,t,lim);
        if(f==0) break;
        fl+=f;
        lim-=f;
      }
    }
    return fl;
  }

  T flow(Int s,Int t){
    return flow(s,t,INF);
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  const Int INF = 1e8;
  Dinic<Int, false> G(n,INF);
  for(Int i=0;i<m;i++){
    Int u,v,w;
    cin>>u>>v>>w;
    G.add_edge(u,v,w);
  }
  
  Int res=G.flow(0,n-1,10010);
  Int ans=res;
  if(res-1<=10000){
    for(Int v=0;v<n;v++){
      for(auto &e:G.G[v]){
        if(e.cap) continue;
        Int w=(e.cap+G.G[e.to][e.rev].cap)/2;
        if(w>1) continue;      

        // cut edge
        G.G[e.to][e.rev].cap=0;

        // 0 -> v -> e.to -> n-1
        Int a=G.flow(v,0,1);
        Int b=G.flow(n-1,e.to,1);
        assert(a==1&&b==1);
      
        if(G.flow(0,n-1)==0){
          ans=res-1;
          break;
        }

        // restore edge
        e.cap=1;
        G.G[e.to][e.rev].cap=1;

        G.flow(0,n-1);
      }
      if(ans<res) break;
    }
  }
  if(ans>10000) ans=-1;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3604
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define add(x) accumulate(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end() 
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
      void solve(){    
                ll n,p;
                cin>>n;
                ll ans=INF;
                for(ll i=1;(ll)i*i<=n;i++){
                        if(n%i==0)
                                ans=min(ans,i-1+n/i-1);
                }
                cout<<ans;
        }
        int main(){ 
                hs;
                ll t;
                t=1;
                // cin>>t;
                for (int i=1; i<=t; i++){
                        solve();
                 }
        return 0; 
}         
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long

using namespace std;

LL v[105],w[105],dp[105][100005];

LL solve(int pos,int rem) {
    if (rem<0||pos<0) return -1*MOD;
    if (rem>=0&&pos==0) return 0;
    if (dp[pos][rem]!=-1) return dp[pos][rem];
    return dp[pos][rem]=max(solve(pos-1,rem),solve(pos-1,rem-w[pos])+v[pos]);
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin >> n >> m;
    for (int i=1;i<=n;i++) cin >> w[i] >> v[i];  
    memset (dp,-1,sizeof(dp));
    cout << solve(n,m) << endl;  
    return 0;
}


Measured memory_bytes: 82304
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  int n,q;
  cin>>n>>q;
  vector<list<int> > s(n);
  for(int i=0;i<q;i++){
    int t,a;
    cin>>t>>a;
    if(t==0){
      int x;
      cin>>x;
      s[a].emplace_back(x);
    }
    if(t==1){
      int f=0;
      for(int x:s[a]){
	if(f) cout<<" ";
	f=1;
	cout<<x;
      }
      cout<<endl;
    }
    if(t==2){
      int b;
      cin>>b;
      s[b].splice(s[b].end(),move(s[a]));
    }
  }
  return 0;
}



Measured memory_bytes: 18620
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

template<class T> T umax(T a,T b) {return (a>b?a:b);}
template<class T> T umin(T a,T b) {return (a<b?a:b);}
template<class T,class P> T umax(T a,P b) {return (a>b?a:b);}
template<class T,class P> T umin(T a,P b) {return (a<b?a:b);}

typedef long long int ll;
const int maxn = 1e5+7;
const ll mod = 1e9+7;

bool compare(const pair<ll,ll>& x, const pair<ll,ll>& y) {
    if(x.second == y.second) return x.first < y.first;
    return x.second < y.second;
}

ll power(ll a,ll b) {
    ll res = 1;
    while(b) {
        if(b&1) {
            res = (res*a)%mod;
        }
        a = (a*a)%mod;
        b >>= 1;
    }
    return res;
}

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

int n,w;
int W[101];
int P[101];

bool visit[101][100005];
ll dp[101][100005];

ll solve(int pos,int wt) {
    if(wt > w) {
        return -1e9;
    }
    if(pos >=n ) {
        return 0;
    }
    if(visit[pos][wt]) {
        return dp[pos][wt];
    }
    ll ans = 0;
    ans = solve(pos+1,wt);
    ans = max(ans,P[pos] + solve(pos+1,wt+W[pos]));
    visit[pos][wt] = true;
    dp[pos][wt] = ans;
    return ans;
}

int main() {
    cin >> n >> w;
    for(int i=0;i<n;i++) {
        cin >> W[i] >> P[i];
    }
    cout << solve(0,0) << endl;
    return 0;
}

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

using ll=long long; 

void solve(){
	int n;
	cin>>n;
	vector<int>L(2*n);
	for(int i=0; i<2*n; i++){
		cin>>L[i];
	}
	int sum=0;
	sort(L.begin(), L.end());
	for(int i=0; i<2*n; i++){
		if(i%2==0){
			sum+=L[i];
		}
	}
	cout<<sum<<endl;
}

signed main(){
	//while(1)
	solve();
}

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

signed main() {
  string S;
  cin >> S;
  
  if(S.size() < 4 ){
    cout << "No" << endl;
    return 0;
  }
  if( S.compare(0, 4, "YAKI") == 0 ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

int main()
{
     ll a,b;
     cin>>a>>b;
     ll res=(a*b)/(__gcd(a,b));
      cout<<res<<"\n";
         return 0;
}

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

const long long INF = 1LL << 61;

int main() {
    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if (U == S) A--;
    else B--;
    cout << A << " " << B;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
bol = 0
cnt = 1
for i in range(N-1):
    if bol == 0:
        if A[i] > A[i+1]:
            bol = -1
        elif A[i] < A[i+1]:
            bol = 1
    elif bol == 1:
        if A[i] > A[i+1]:
            cnt += 1
            bol = 0
    else:
        if A[i] < A[i+1]:
            cnt += 1
            bol = 0
print(cnt)

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

using namespace std;

typedef long long ll;

int main() {
    ll N;
    vector <ll> A;
    cin >> N;
    for (ll i = 0; i < N; i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }

    ll sum = 0;
    for (ll i = 1; i < N; i++) {
        if (A[i] >= A[i - 1]) {
            continue;
        } else {
           ll diff = A[i-1] - A[i];
           A[i] += diff;
           sum += diff;
        }
    }

    cout << sum << endl;
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vector <pair<int, int>> vec;
int dp[3001][3001];

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

    int N, T;
    cin >> N >> T;

    int A, B;
    vec.resize(N);
    rep (i, N)
    {
        cin >> A >> B;
        vec[i] = pair<int, int>(A, B);
    }

    sort(vec.begin(), vec.end());

    int ans = 0;
    for (int i = 1; i <= N; ++i)
    {
        A = vec[i - 1].first;
        B = vec[i - 1].second;
        for (int j = 0; j <= T; ++j)
        {
            if (j >= A)
            {
                dp[i][j] = MAX(dp[i - 1][j - A] + B, dp[i - 1][j]);
            }
            else
            {
                dp[i][j] = dp[i - 1][j];
            }
        }
        ans = MAX(ans, dp[i - 1][T - 1] + B);
    }

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



Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,n,m,ans=0,x;
	cin>>n>>m;
	for(i=1;i<=m;i++)
	{
		cin>>x;
		ans+=x;
	}
	if(ans>n)cout<<"-1";
	else cout<<n-ans;
}


Measured memory_bytes: 3636
import sys
x=sys.stdin.read()
x=x.split()
count=0
for v in x:
    if v=='-':
        break
    if count==0:
        string=v
        count-=1
    elif count==-1:
        count=int(v)
    else:
        h=int(v)
        string=string[h:]+string[:h]
        if count==1:
            print(string)
        count-=1
    



Measured memory_bytes: 5596
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
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;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////

//経路圧縮，繋ぎ変え

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size,-1) { }

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

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

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

    bool connect(int x , int y){
        x = root(x);
        y = root(y);

        if(x==y) return false;

        if(data[x] > data[y]){
            x ^= y;
            y ^= x;
            x ^= y;
        }

        data[x] = data[x] + data[y]; // membersize++
        data[y] = x;
        return true;
    }
};
int main() {
ll ans = 0;
	int N; cin >> N;
	int M; cin >> M;
	vector<int> A(N);
	rep(i,N){cin >> A.at(i);}

	UnionFind UF(N+2);

	rep(i,M)
	{
		int x,y; cin >> x >> y;
		UF.connect(x,y);
	}

	rep(i,N)
	{
		ans += int(UF.isConnect(A.at(i),i+1));
	}

	cout << ans << endl;
}

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

int main() {
  int N; cin >> N;
  vector<pair<int, int>> A(N);
  rep(i, N) {
    int x; cin >> x;
    A[i].first = x;
    A[i].second = i + 1;
  }

  sort(all(A));

  rep(i, N) cout << A[i].second << " ";

  cout << endl;


  return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<int> X(N);
  for (int i=0; i<N; i++){
    cin>>X.at(i);
  }
  int min_tot=100000000;
  for (int Y=1; Y<=100; Y++){  
  int tot=0;
    for (int i=0; i<N; i++){
      tot+=(X.at(i)-Y)*(X.at(i)-Y);
    }
    if (min_tot>tot){
      min_tot=tot;
    }
  }
  cout<<min_tot<<endl;
}

Measured memory_bytes: 3592
//***Because people who are crazy enough to think that they can change the world are the ones who do it***
//Think different
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
	ll n;
	cin>>n;
	cout<<(1000-(n%1000))%1000;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque> 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
	uint N, D, A;
	cin >> N >> D >> A;
	
	vector<pair<uint, uint>> XH(N, pair<uint, uint>());
	
	for(uint i=0; i<N; i++) {
		ull X, H;
		cin >> X >> H;
		XH[i] = make_pair(X, H);
	}
	
	sort(XH.begin(), XH.end());

	ull ans = 0;
	ull asum = 0;
	deque<pair<uint, uint>> XA;
	
	for(uint i=0; i<N; i++) {
		while(!XA.empty() && XA.front().first < XH[i].first) {
			asum -= XA.front().second;
			XA.pop_front();
		}
		
		if(XH[i].second <= asum) continue;
		
		XH[i].second -= asum;
		
		uint acnt = (XH[i].second + A - 1) / A; 
		ans += acnt;
		
		uint admg = acnt * A;
		uint redg = XH[i].first + 2 * D;
		
		XA.push_back(make_pair(redg, admg));
		asum += admg;
	}

	cout << ans;	
	return 0;
}


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

int compare(const void *a, const void *b){
	int *A = (int *)a;
	int *B = (int *)b;
	if (*A > *B) return 1;
	if (*A < *B) return -1;
	return 0;
}

int main(){
	int N;
	scanf("%d",&N);
	int s[N];
	int sum=0;
	for(int i=0;i<N;i++){
		scanf("%d",&s[i]);
		sum+=s[i];
	}
	qsort(s,N,sizeof(int),compare);
	if(sum%10!=0){
		printf("%d\n",sum);
		return 0;
	}
	for(int i=0;i<N;i++){
		if(s[i]%10!=0){
			printf("%d\n",sum-s[i]);
			return 0;
		}
	}
	printf("0\n");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000  // スタックの最大値

typedef struct{
  int top;         // スタックポインタ(一番上の位置)
  int S[MAX];
}Stack;


// スタック st の初期化
void initialize(Stack *st)
{
  st->top = 0;
  st->S[st->top] = 0;
}

// スタック st が空かどうかを確認
int isEmpty(Stack *st)
{
  return st->top == 0;
}

// スタック st が一杯かどうかを確認
int isFull(Stack *st)
{  
  return st->top >= MAX - 1;
}

// スタック st に要素 x をプッシュ(一番上に要素を追加)
void push(int x, Stack *st)
{
  if (isFull(st)) 
    exit(1);

  st->top++;
  st->S[st->top] = x;
}

// スタック st から要素をポップ(一番上の要素を取り出す)
int pop(Stack *st) {
  if (isEmpty(st)) 
    exit(1);

  st->top--;
  return st->S[st->top+1];
}


int main(void)
{
  Stack st1;     // '\' の開始位置を格納するスタック
  Stack st2_j;   // 各水たまりの最も左の'\' の位置を格納するスタック
  Stack st2_a;   // 各水たまりの水量を格納するスタック

  // スタック初期化
  initialize(&st1);
  initialize(&st2_j);
  initialize(&st2_a);

  char c;
  int sum = 0;  // 水たまりの総水量

  // 地形を読み込み，各水たまりの水量を計算
  for (int i = 0; (c = getchar()) != EOF; i++) {
    if (c == '\\') {                                 // '\' が出た時の処理
      // 位置 i を st1 にプッシュ(write your code)
      push(i,&st1);
    }else if (!isEmpty(&st1) && c == '/') {          // '/' が出た時の処理
      // 水たまりの総水量 sum を更新(write your code)
    	int j=pop(&st1);
    	sum+=i-j;
      // st2_j と st2_a を用いて水たまりの水量を更新 
      int a = i - j;   // 更新する水たまりの水量を a に格納していく
      while (!isEmpty(&st2_j) && st2_j.S[st2_j.top] > j) {  // 最も左の '\' の位置が j よりも大きい場合，以下を繰り返す
        // 水たまりの水量を求めていく (write your code)
      	a+=pop(&st2_a);
      	pop(&st2_j);
      }
      // 更新した水たまりの「最も左の'\' の位置」および「水量」を更新 (write your code)
    	push(j,&st2_j);
    	push(a,&st2_a);
    }
  }

  printf("%d\n", sum);       // 水たまりの総水量を出力
  printf("%d", st2_a.top);   // 水たまりの個数を出力

  // 各水たまりの水量を断面図の左から出力(スタックの底から出力)
  for (int i = 1; i <= st2_a.top; i++) 
    printf(" %d", st2_a.S[i]);  
  printf("\n");

  return 0;
}


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

#define MOD 1000000007

#pragma region Debug
void debug_out() { cout << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cout << H << " ";
	debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
#pragma endregion

// コンパイル時、エイリアス「debug」を使用 --> マクロが使えるように

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	ll N, K;
	cin >> N >> K;

	// 累積和
	vector<ll> sum(N+1,0);
	rep(i,N){
		sum[i+1] += sum[i] + (i+1);
		sum[i+1] = sum[i+1] % MOD;
	}

	ll ans = 0;
	FOR(i,K,N+1){
		ll min = sum[i-1];
		min = min % MOD;
		ll max = sum[N] - sum[N-i];
		max = max % MOD;
		// debug(min, max);
		ll plus = max - min + 1;
		if(plus < 0) plus += MOD;
		ans += plus;
		ans = ans % MOD;
	}
	// 全部選んだ時
	ans += 1;

	cout << ans << endl;

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

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

int n;

int dfs(long long x){
  if(n<x) return 0;
  long long rec=x,ans=0;
  bool f3=false,f5=false,f7=false,fok=true;
  while(x>0){
    if(x%10==3) f3=true;
    else if(x%10==5) f5=true;
    else if(x%10==7) f7=true;
    else fok=false;
    x/=10;
  }if(f3&&f5&&f7&&fok) ans++;
  for(int i=3;i<8;i+=2){
    ans+=dfs(rec*10+i);
  }
  return ans;
}

int main(){
  cin>>n;
  cout<<dfs(0)<<endl;
}

Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>
#include <limits>
#include <functional>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int (i) = 0; (i) < int(n); i++)
#define mod 1000000007
#define fst first
#define pb push_back


int main()
{
	int A, B, K;
	cin >> A >> B >> K;
	if (B - A + 1 >= 2 * K) {
		for (int i = 0; i < K; i++) {
			cout << A + i << endl;
		}
		for (int i = K-1; i >= 0; i--) {
			cout << B - i << endl;
		}
	}
	else {
		for (int i = A; i <= B; i++) {
			cout << i << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
const ll inf = 1LL<<60;

int main()
{
  stack<int> stk;
  int a, b;
  string s;
  while (cin>>s) {
    if (s[0]=='+') {
      a = stk.top(); stk.pop();
      b = stk.top(); stk.pop();
      stk.push(a+b);
    } else if (s[0]=='-') {
      a = stk.top(); stk.pop();
      b = stk.top(); stk.pop();
      stk.push(b-a);
    } else if (s[0]=='*') {
      a = stk.top(); stk.pop();
      b = stk.top(); stk.pop();
      stk.push(a*b);
    } else {
      stk.push(stoi(s));
    }
  }
  cout << stk.top() << endl;

  return 0;
}



Measured memory_bytes: 3184
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		String str = stdIn.next();
		int size = str.length() - 1;
		int n = stdIn.nextInt();
		int ans = 0;
		for(int i = 0; i < n; ++i)
		{
			String ring = stdIn.next();
			for(int j = 0; j < size; ++j)
			{
				ring += ring.charAt(j);
			}
			if(ring.contains(str))
			{
				++ans;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <algorithm>

int main() {
  int degrees[4] = {0, 0, 0, 0};
  for(int i = 0; i < 3; ++i) {
    int a, b; scanf("%d%d", &a, &b);
    --a; --b;
    ++degrees[a];
    ++degrees[b];
  }
  std::sort(degrees, degrees+4);
  if(degrees[0] == 1 && degrees[3] == 2) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <utility>
#include <cstdio>
#include <vector>
#include <map>
#define pb push_back
#define mp std::make_pair
#define MOD 1000000007
typedef long long ll; 
ll arr[205], rem[205]; 
std::vector<ll> vec; 
std::map<std::vector<ll>, std::vector<std::pair<ll, ll> > > app; 
inline int calc(ll l, ll r)
{
	int res = 0; 
	ll cur = 0; 
	for (int i = 60; i >= 0; i--)
	{
		if ((l ^ r) & (1ll << i))
			return res + 1 - (l == cur); 
		if (l & (1ll << i))
		{
			res++; 
			cur |= 1ll << i; 
		}
	}
	return res; 
}
int main()
{
	// freopen("ARC086-F.in", "r", stdin); 
	int n;
	ll lim;
	scanf("%d%lld", &n, &lim); 
	for (int i = 0; i < n; i++)
		scanf("%lld", arr + i); 
	std::sort(arr, arr + n); 
	for (int k = 0; k <= 60; k++)
	{
		for (int i = 0; i < n; i++)
			rem[i] = arr[i] & (1ll << k) - 1; 
		std::sort(rem, rem + n); 
		for (int i = 0; i < n; i++)
		{
			if (i && rem[i - 1] == rem[i])
				continue; 
			vec.clear(); 
			ll mn = lim - k - calc((i ? rem[i - 1] : -1) + 1, rem[i]); 
			for (int j = 0; j < n; j++)
			{
				ll res = (arr[j] >> k) - (rem[i] > (arr[j] & (1ll << k) - 1)); 
				mn = std::min(mn, res); 
				vec.pb(res); 
			}
			if (mn < 0)
				continue; 
			std::sort(vec.begin(), vec.end()); 
			ll x = vec[0]; 
			for (ll &j : vec)
				j -= x; 
			app[vec].pb(mp(x - mn, x)); 
		}
	}
	ll ans = 0; 
	for (auto it : app)
	{
		std::sort(it.second.begin(), it.second.end()); 
		ll l = 0, r = -1; 
		for (auto x : it.second)
		{
			if (r < x.first)
			{
				ans += (r - l + 1) % MOD; 
				l = x.first; 
			}
			r = std::max(r, x.second); 
		}
		ans += (r - l + 1) % MOD; 
	}
	printf("%lld\n", ans % MOD);
	return 0; 
}


Measured memory_bytes: 16512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int ans[500][500];
void solve(int l, int r, int level) {
  if (l + 1 == r) return;
  int border = (l + r + 1) / 2;
  FOR(i, l, border) FOR(j, border, r) ans[i][j] = level;
  solve(l, border, level + 1);
  solve(border, r, level + 1);
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  memset(ans, -1, sizeof(ans));
  int n; cin >> n;
  solve(0, n, 1);
  REP(i, n) {
    FOR(j, i + 1, n) cout << ans[i][j] << (j + 1 == n ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 1536
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int a = scn.nextInt();
      	int b = scn.nextInt();
        if(a == 1){
        	a = 14;
        }
        if(b == 1){
        	b = 14;
        }
        if(a > b){
        	System.out.println("Alice");
        }else if(a < b){
        	System.out.println("Bob");
        }else{
        	System.out.println("Draw");
        }
	}
}

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

int main() {
    int n;

    cin >> n;

    long fizzbuzz = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0) continue;
        if (i % 5 == 0) continue;
        fizzbuzz += i;
    }
    cout << fizzbuzz << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';

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

struct LinearSystemIncidence {
    struct Edge {
        int to,id;
        Edge() {}
        Edge(int to, int id) : to(to), id(id) {} 
    };
    int N,M;
    vector<vector<Edge>> G;
    vector<int> x,seen;

    LinearSystemIncidence() {}
    LinearSystemIncidence(int N) : N(N), M(0), G(N), seen(N) {}

    void add_edge(int u, int v, int id) {
        ++M;
        G[u].emplace_back(v,id);
        G[v].emplace_back(u,id);
        x.emplace_back(0);
    }

    int dfs(int v,const vector<int> &c) {
        seen[v] = true;
        int ret = c[v];
        for (const Edge &e : G[v]) {
            if (seen[e.to]) continue;
            int tmp = dfs(e.to,c);
            x[e.id] ^= tmp;
            ret ^= tmp;
        }
        return ret;
    }

    vector<int> solve(const vector<int> &c) {
        fill(x.begin(),x.end(),0);
        fill(seen.begin(),seen.end(),0);
        for (int v = 0; v < N; ++v) {
            if (seen[v]) continue;
            if (dfs(v,c)) return vector<int> {};
        }
        return move(x);
    }
};

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

void AGC035B() {
    int N,M; cin >> N >> M;
    LinearSystemIncidence LSI(N);
    vector<int> c(N),u(M),v(M);
    rep(i,M) {
        cin >> u[i] >> v[i];
        --u[i]; --v[i];
        c[u[i]] ^= 1;
        LSI.add_edge(u[i],v[i],i);
    }

    auto A = LSI.solve(c);
    if (A.empty()) {
        cout << -1 << ln;
    } else {
        rep(i,M) {
            if (A[i]) swap(u[i],v[i]);
            cout << u[i]+1 << " " << v[i]+1 << ln;
        }
    }
}
void ABC155F() {
    int N,M; cin >> N >> M;
    vector<pii> A(N);
    vector<int> L(M),R(M);
    rep(i,N) cin >> A[i].first >> A[i].second;
    rep(i,M) cin >> L[i] >> R[i];

    sort(all(A));
    vector<int> LL(M),RR(M);
    rep(i,M) {
        LL[i] = lower_bound(all(A),pii(L[i],-1)) - A.begin();
        RR[i] = upper_bound(all(A),pii(R[i],2)) - A.begin();
    }
    vector<int> B(N+1);
    rep(i,N+1) {
        if (i==0) B[i] = A[i].second;
        else if (i==N) B[i] = A[i-1].second;
        else B[i] = A[i].second^A[i-1].second;
    }
    LinearSystemIncidence LSI(N+1);
    rep(i,M) LSI.add_edge(LL[i],RR[i],i);
    auto ans = LSI.solve(B);
    if (ans.empty()) {
        cout << -1 << ln;
    } else {
        cout << accumulate(all(ans),0) << ln;
        rep(i,M) {
            if (ans[i]) cout << i+1 << " ";
        }
        cout << ln;
    }
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    AGC035B();
    //ABC155F();
}

/*
  verified on 2020/07/17
  https://atcoder.jp/contests/agc035/tasks/agc035_b
  https://atcoder.jp/contests/abc155/tasks/abc155_f
*/

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

int main() {
  int64_t N;
  cin >> N;
  int64_t a,b;
  int64_t ans = 0, min_ans = N;
  
  int64_t tmp = floor(sqrt(N));
  //cout << tmp << endl ;
  for(int64_t i = tmp; i > 0 ; i-- ){
    if( N % i == 0){
      a = i; b = N / i;
      ans = a+b-2;
      min_ans = min(ans,min_ans);
    }
  }
  
  cout << min_ans << endl ;
    
}


Measured memory_bytes: 256
inputed_seconds = input()
hours = int(inputed_seconds) // 3600
minutes = (int(inputed_seconds) - int(hours) * 3600) // 60
seconds = (int(inputed_seconds) - int(hours) * 3600) % 60
print(int(hours), ":", int(minutes), ":", int(seconds), sep="")


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

int main() {

  int N;
  cin >> N;

  int answer = 0;
  int mx = 0;

  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    answer += p;
    mx = max(mx, p);
  }

  cout << answer - (mx / 2) << endl;

}

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

vector<vector<int>> n(200005);
vector<ll> counter(200005, 0);
map<int, ll> sum = {};

void dfs(int first, ll second) {
    for (int v: n[first]) {
        dfs(v, second + sum[v]);
    }

    counter[first] += second;
}

int main()
{
    // 入力
    int N, Q;
    cin >> N >> Q;

    for (int i = 1; i < N; i++) {
        int a, b;
        cin >> a >> b;

        n[a].push_back(b);
    }

    for (int i = 1; i <= Q; i++) {
        int p, x;
        cin >> p >> x;

        sum[p] = sum[p] + x;
    }

    auto i = sum.begin();
    dfs(1, sum[1]);

    // 出力
    for (int i = 1; i <= N; i++) {
        printf("%lld%c", counter[i], i == N ? '\n' : ' ');
    }

    return 0;
}


Measured memory_bytes: 43008
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(factorization(n));
    }
    
    public static int factorization(int x) {
        List<Integer> prime = new ArrayList<>();
        if(x == 2) return 2;
        prime.add(2);
        for(int i = 3 ;; i+=2){
            boolean bool = true;
            for(int p: prime){
                if(i % p == 0){
                    bool = false;
                    break;
                }
            }
            if(bool){
                if(x <= i) return i;
                prime.add(i);
            }
        }
    }
}


Measured memory_bytes: 24812
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

int main(){
  int A,B;cin>>A>>B;
  cout<<A*B<<endl;
}

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

using namespace std;
typedef double db;
struct P{
    db x, y;
    P(){}
    P(db x, db y) : x(x) , y(y) {}
    db dot(P a){ return a.x*x + a.y*y; }
    P operator - (P a){ return P(x-a.x, y-a.y); }
    db len(){ return sqrt(x*x+y*y); }
};
typedef P V;
struct L{ P p, q; };

P projection(P a, L l){ //求得点a在l上的投影点坐标
    P tl = l.q - l.p;  //表示l的两个点形成的线段
    db ll = tl.len();  //线段长度
    db k = (a-l.p).dot(tl)/ll/ll;  //投影长度与线段长度的比值
    return P( l.p.x + k*tl.x, l.p.y + k*tl.y ); //最终结果
}

int main(){
    //freopen("owo.in","r",stdin);
    int n;
    L l;
    scanf("%lf%lf%lf%lf",&l.p.x, &l.p.y, &l.q.x, &l.q.y);
    cin >> n;
    P a;
    while(n--){
        scanf("%lf%lf", &a.x, &a.y);
        P ta = projection(a, l);
        printf("%.9lf %.9lf\n", ta.x, ta.y);
    }
    return 0;
}


Measured memory_bytes: 3244
ms = ""
dic = {k: int(0) for k in [chr(i) for i in range(97, 123)]}
while True:
    try:
        inp = input()
        ms += inp
    except:
        break

for i in ms.lower():
    if ord(i) >= 97 and ord(i) <= 122:
        dic[i] += 1

for k, v in sorted(dic.items(), key=lambda x: x[0]):
    print("{0} : {1}".format(k, v))

Measured memory_bytes: 7420
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int A, B;
    cin >> A >> B;
    cout << (B - 1 + A - 1 - 1) / (A - 1) << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    if (a > m) continue;
    jobs[m-a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  for (int i = m-1; i >= 0; --i) {
    for (int b: jobs[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5632
n = int(input())
mx = 0
ans = 1
for i in range(1,n+1)[::-1]:
    count = 0
    b = i
    while True:
        if i%2==0:
            i//= 2
            count += 1
        else:
            break
    if mx < count:
        mx = count 
        ans = b
print(ans)

Measured memory_bytes: 38256
#関数リスト
import sys
import numpy as np
input = sys.stdin.readline

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

n = I()
mylist = LI()
result = 0
for i, num in enumerate(mylist):
    if i % 2 == 0 and num % 2 == 1:
        result+=1
print(result)

Measured memory_bytes: 27128
//
//  main.cpp
//  ALDS 1_1_D
//
//  Created by YangJing on 17/4/5.
//  Copyright ?? 2017??´ YangJing. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace::std;
static const int MAX = 200000;

int main(int argc, const char * argv[]) {
    int n;
    int R[MAX];
    cin >> n;
    for (int j = 0; j < n; j++) {
        cin >> R[j];
    }
    int minv = R[0];
    //Rj - Ri may be minus
    int maxv = -2000000000;
    
    for (int j = 1; j < n; j++) {
        maxv = max(maxv, R[j]-minv);
        minv = min(minv, R[j]);
    }
    cout << maxv << endl;
    return 0;
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n, m;
    cin >> n >> m;

    ll res = 1;
    for (ll a = 1; a <= sqrt(m); a++) {
        if (m % a == 0) {
            ll b = m / a;

            if (a >= n) {
                res = max(b, res);
            }
            if (b >= n) {
                res = max(a, res);
            }
        }
    }

    put(res);
}
signed main(){ Main();return 0;}

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

using namespace std;

int main()
{
    int n;;
    cin >> n;
    
    long long sum=0;
    map<int, int> a;
    for(int i=0;i<n;i++){
        int buf;
        cin >> buf;
        sum += buf;
        a[buf]++;
    }

    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        int b, c;
        cin >> b >> c;
        sum += (c-b) * a[b];
        a[c]+=a[b];
        a[b]=0;
        cout << sum << endl;
    }
}


Measured memory_bytes: 8056
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<ll,ll>; using vp = V<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
//////////

int dp[300000][52];

void solve(){
  ini(N);
  vi A(N) , B(N); in(A , B);

  rep(i , 1 << N) rep(j , 51) dp[i][j] = inf;
  dp[0][0] = 0;
  int nya[20] , rui[20];
  rep(b , 1 << N) rep(j , 51){
    if(dp[b][j] == inf) continue;
    rep(i , N) nya[i] = (b >> i) & 1;
    rui[0] = 0; rep(i , N) rui[i + 1] = rui[i] + nya[i];

    rep(k , N){
      if((b >> k) & 1) continue;
      int nxt = ((rui[N] + k) & 1) ? B[k] : A[k];
      if(nxt < j) continue;
      // 転倒数 kより大きいbitの個数
      amin(dp[b | (1 << k)][nxt] , dp[b][j] + rui[N] - rui[k]);
    }
  }
  
  int ans = inf;
  rep(j , 51) amin(ans , dp[(1 << N) - 1][j]);
  out( ans == inf ? -1 : ans);

  

}

Measured memory_bytes: 55552
#include "bits/stdc++.h"
using namespace std;
int main() {
	string s;
	cin>>s;
	if(s=="SAT")cout<<"1"<<endl;
	else if(s=="SUN")cout<<"7"<<endl;
	else if(s=="MON")cout<<"6"<<endl;
	else if(s=="TUE")cout<<"5"<<endl;
	else if(s=="WED")cout<<"4"<<endl;
	else if(s=="THU")cout<<"3"<<endl;
	else if(s=="FRI")cout<<"2"<<endl;
	return 0;
}

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

int main(){
    int H,W,N;
    cin>>H>>W>>N;
    if(H>=W){
        if(N%H==0){
            cout<<N/H<<endl;
        }else{
            cout<<(N/H)+1<<endl;
        }
    }else{
        if(N%W==0){
            cout<<N/W<<endl;
        }else{
            cout<<(N/W)+1<<endl;
        }
    }
return 0;}
/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <utility>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

#define all(a) (a).begin(),(a).end()
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
const int MOD = 1e9+7;
const int INF = numeric_limits<int>::max();
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Iterator>void print(const Iterator s, const Iterator t) { for(auto it=s;it+1!=t;++it)cout<<*it<<" ";cout<<*(t-1)<<"\n"; }
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int H, W; in(H); in(W);
  int A, B; in(A); in(B);

  rep(i, H) {
    rep(j, W) {
      if (i < B && j < A || i >= B && j >= A)
        cout << 1;
      else
        cout << 0;
    }
    cout << "\n";
  }

  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll s[110000], ans;

int main() {
	ll n;
	cin >> n;
	REP(i, n) {
		cin >> s[i];
	}
	REP(i, n - 1)if (s[i] < s[i + 1])ans++;
	cout << ans << endl;
}




Measured memory_bytes: 3868
#include<stdio.h>

int main(void){
  int n,b[10]={},l,r,count;
  scanf("%d",&n);
  while(n-->0){
    for(int i=0;i<10;i++){ scanf("%d",&b[i]); }
    l=0; r=0; count=0;
    for(int i=0;i<10;i++){
      if(l<b[i]) l=b[i];
      else if(r<b[i]) r=b[i];
      else break;
      count++;
    }
    if(count==10) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}



Measured memory_bytes: 1992
#include<iostream>
#include<cstring>
using namespace std;
const int MAXN = 100005;
int dp[MAXN], h[MAXN];
int main(){
	int n;
	int k;
	scanf("%d%d", &n, &k);
//	int h[n + 1];
//	int dp[n + 1];
//	memset(h,0,sizeof h);
	memset(dp,0x3f3f3f3f,sizeof dp);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &h[i]);
	
	dp[1] = 0;
	for(int i = 2; i <= n; i++){
		for(int j = max(i - k, 1); j < i; j++){
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
		}
	}
	printf("%d", dp[n]);
	return 0;
}

Measured memory_bytes: 1024