akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 200020

ll h[N],a[N],bit[N];
map<ll,ll> m;

ll upd(ll i,ll val) {
    for(;i<N;i+=(i&(-i))) bit[i]=max(bit[i],val);
}

ll get(ll i) {
    ll res=0;
    for(;i>0;i-=(i&(-i))) res=max(res,bit[i]);
    return res;
}

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

    int n;
    cin>>n;
    ifr(i,0,n) cin>>h[i],m[h[i]];
    ifr(i,0,n) cin>>a[i];
    int j=1;
    for(auto &it:m) {
        it.ss=j;
        j++;
    }
    ifr(i,0,n) h[i]=m[h[i]];
    // ifr(i,0,n) cout<<h[i]<<" ";cout<<endl;
    ll x,ans=0;
    ifr(i,0,n) {
        x = get(h[i]);
        upd(h[i],x+a[i]);
        ans=max(ans,x+a[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t l;
    cin >> l;

    vector<int64_t> a(l);
    int64_t sum = 0;
    for (auto&& aa : a) {
        cin >> aa;
        sum += aa;
    }

    int64_t unreached = 0;
    int64_t ended = 0;
    int64_t startended = 0;
    int64_t turned = 0;
    int64_t ans = sum;
    int64_t rsum = sum;
    for (auto i : irange(0L, l)) {
        auto is_zero = (a[i] == 0);
        auto is_even = (a[i] % 2 == 0);
        auto next_unreached = min({unreached, ended, startended, turned}) + a[i];
        auto next_ended = min({ended, startended, sum - rsum}) + (is_even ? 1 : 0);
        auto next_startended = min({startended, sum - rsum}) + !is_even + is_zero * 2;
        auto next_turned = min({ended, startended, turned, sum - rsum}) + !is_even + is_zero * 2;

        rsum -= a[i];
        auto next_min = min({next_unreached, next_ended, next_startended, next_turned}) + rsum;
        ans = min(ans, next_min);

        unreached = next_unreached;
        ended = next_ended;
        startended = next_startended;
        turned = next_turned;
    }

    cout << ans << endl;
}

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

int main()
{
  string s, t;
  cin >> s >> t;
  
  string ans = "No";
  char c;
  rep(i, s.size()){
    c = s[s.size() - 1];
    for(int j = s.size() - 1; j > 0; j--){
      s[j] = s[j - 1];
    }
    s[0] = c;
    //cout << s << endl;
    if(s == t) ans = "Yes";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	long res = 1000000, karires = 0, ABC[10];
	long N, A, B, C; cin >> N >> A >> B >> C;
	long l[100]; for (int i = 0; i <= N - 1; i++) cin >> l[i];

	for (long mat = 0; mat <= pow(4, N) - 1; mat++) {
		long p = mat;
		long usefor[100]; //0なら使わない。1ならAに2ならBに3ならCに。0からN-1まで。
		for (int i = 0; i <= N - 1; i++) { //4進数matを利用し、0から3までの全探索。ただし1から3が一回以上出るように。
			usefor[i] = p % 4;
			p -= p % 4;
			p /= 4;
		}

		if (count(usefor, usefor + N, 1) == 0) continue; //特殊ケースの排除。
		if (count(usefor, usefor + N, 2) == 0) continue;
		if (count(usefor, usefor + N, 3) == 0) continue;

		//あとはuseforを調べる。
		ABC[0] = 0; ABC[1] = A; ABC[2] = B; ABC[3] = C; karires = 0;
		for (int i = 0; i <= N - 1; i++) {
			ABC[usefor[i]] -= l[i];
			if (usefor[i] >= 1) karires += 10;
		}

		karires -= 30;
		karires += abs(ABC[1]) + abs(ABC[2]) + abs(ABC[3]);
		res = min(res, karires);
		//useforここまで。
	}

	cout << res << endl;

}

Measured memory_bytes: 256
//////////////////////////////////*STRIKER(Devesh Ranjan)*////////////////////////////////////////////////////////////////////

#include<bits/stdc++.h>

using namespace std;
using ull=unsigned long long;
using ll=long long int;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 10000007
#define mod1 1000003
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define fr1(i,a,b) for(ll i=a;i<=b;i++)

/*BINARY EXPONENTIATION*/

ll binpow(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        {
            res=res*a;
        }
        a=a*a;
        b>>=1;
    }
    return res;
}

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

void solve()
{
    //Start Here:
    ll n;
    cin>>n;
    ll ar[n+1];
    fr(i,0,n)
    {
        cin>>ar[i];
    }
    ll dp[n+1];
    dp[0]=0;
    dp[1]=abs(ar[1]-ar[0]);
    fr(i,2,n)
    {
        dp[i]=min((dp[i-2]+abs(ar[i]-ar[i-2])),(dp[i-1]+abs(ar[i]-ar[i-1])));
    }
    cout<<dp[n-1]<<endl;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
    fastio;
    solve();
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;
  cin >> n >> m;
  ll ok = 0;
  if(n % 2 == 1)/*n--,*/ok = 1;
  vector<ll> a(m + 2);
  vector<ll> b(m + 2);
  for(int i = 0;i < m + 2;i++)a[i] = i + 1;
  ll num = 0;
  if(ok == 0)num = 1;
  for(int i = 0;i < m + 2;i++){
    if(i >= m / 2 && ok == 0)num = 2;
    b[i] = n - i - num;
  }
  int pu = 0;
  for(int i = 0;i < m + pu;i++){
    if(n % 2 == 1 || abs(a[i] - b[i]) != n / 2)cout << a[i] << " " << b[i] << endl;
    else pu++;
  }
  return 0;
}



Measured memory_bytes: 4404
#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int a,b,k;
int ot[N],cnt;
map<int,int> Q;
signed main()
{
    a=read(), b=read(), k=read();
    for(ri int i=0;i<k &&i+a<=b;i++)
    {
        if(!Q[i+a]) Q[i+a]=1, ot[++cnt]=i+a;
    }
    for(ri int i=0;i<k&&b-i>=a;i++)
    {
        if(!Q[b-i]) Q[b-i]=1, ot[++cnt]=b-i;
    }
    sort(ot+1,ot+1+cnt);
    for(ri int i=1;i<=cnt;i++) printf("%lld\n",ot[i]);
    return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,k;cin>>n>>k;
    vector<ll>a(n),f(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>f[i];
    sort(all(a));
    sort(rall(f));
    vector<ll>mix(n);
    rep(i,n){
        mix[i]=a[i]*f[i];
    }
    ll l=-1,r=1e12;
    while(r-l>1){
        ll t=(r+l)/2;
        ll cnt=0;
        rep(i,n){
            if(mix[i]>t){
                cnt+=((mix[i]-t+f[i]-1)/f[i]);
            }
        }
        if(cnt<=k)r=t;
        else l=t;
    }
    cout<<r<<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll long long
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;
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;}

int main() {
  int n, x; cin >> n >> x;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(i, n-1) {
    int tmp = a[i] + a[i+1];
    if( tmp > x) {
      a[i+1] = max(0, a[i+1] - tmp + x);
      ans += tmp - x;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
N = int(input())
nums=[int(input()) for _ in range(N)]
MAX = 10*4
sum_num = sum(nums)
dp = [0] * (sum_num+1)
dp[0] = 1
for num in nums:
  for i in range(sum_num+1)[::-1]:
    if dp[i] == 1 and i + num <= sum_num:
      dp[i+num] = 1
ans = 0
for i in range(sum_num+1):
  if dp[i] == 1 and i%10 != 0:
    ans = i
print(ans)


Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(ReadLine());
        }

        public static long[] Reads()
        {
            return ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x,long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var  a = Reads();
            var c4 = 0;
            var c2 = 0;
            for (int i = 0; i < n; i++)
            {
                if (a[i] % 4 == 0) c4++;
                else if (a[i] % 2 == 0) c2++;
            }
            if (c4 * 2 + 1 >= n || c4 * 2 + c2 >= n) WriteLine("Yes");
            else WriteLine("No");
            

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 29192
N, M = map(int, input().split())
l = sorted([list(map(int, input().split())) for _ in range(N)])
c, ans = 0,0
for (yen, stock) in l:
    if c + stock < M:
        c += stock
        ans += stock * yen
    else:
        ans += (M - c) * yen
        c = M
    if c == M:
        print(ans)
        break


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    ll N, ans = 1; cin >> N;
    for (ll x = 1; x * x <= N; x++) {
        ll t = x * x;
        ans = max(ans, t);
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    int X, N;
    cin >> X >> N;
    map<int, bool> dic;
    REP(i, N) {
        int x;
        cin >> x;
        dic[x] = true;
    }
    REP(i, 200) {
        if(!dic[X - i]) {
            cout << X - i << endl;
            return 0;
        }
        if(!dic[X + i]) {
            cout << X + i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long double PI = 3.14159265358979323846;

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

    int n, k;
    cin >> n >> k;
    bitset<10> hate;
    for (int i = 0; i < k; ++i) {
        int d;
        cin >> d;
        hate[d] = 1;
    }
    for (int i = n; i < 100000; ++i) {
        string s = to_string(i);
        int m = s.size();
        bool possible = true;
        for (int j = 0; j < m; ++j) {
            if (hate[s[j] - '0']) {
                possible = false;
                break;
            }
        }
        if (possible) {
            cout << s << '\n';
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# DSL_2_E: Range Add Query


class SegmentTree:
    INITIAL_VALUE = 0

    def __init__(self, n):
        size = 1
        while size < n:
            size *= 2
        self.size = 2*size - 1
        self.data = [self.INITIAL_VALUE] * self.size

    def add(self, i, j, v):
        def _add(r, lo, hi):
            if hi < i or lo > j:
                return
            elif i <= lo and hi <= j:
                self.data[r] += v
            else:
                mid = lo + (hi - lo)//2
                _add(r*2 + 1, lo, mid)
                _add(r*2 + 2, mid+1, hi)

        return _add(0, 0, self.size//2)

    def get(self, i):
        def _get(r, lo, hi, v):
            v += self.data[r]
            if lo == hi:
                return v
            mid = lo + (hi - lo)//2
            if mid >= i:
                return _get(r*2 + 1, lo, mid, v)
            else:
                return _get(r*2 + 2, mid+1, hi, v)

        return _get(0, 0, self.size//2, 0)


def run():
    n, q = [int(i) for i in input().split()]
    tree = SegmentTree(n)

    for _ in range(q):
        com, *args = [i for i in input().split()]
        if com == '0':
            s, t, x = [int(i) for i in args]
            tree.add(s-1, t-1, x)

        elif com == '1':
            t = int(args[0])
            print(tree.get(t-1))
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()



Measured memory_bytes: 10748
mod=10**9+7
g="ACGT".chars
n=gets.to_i
dp=(0..n).map{{}}
dp[0]['TTT']=1
n.times{|i|
    g.repeated_permutation(4){|a,b,c,d|
        next if (a+b+c+d)["AGC"]
        next if (b+a+c+d)["AGC"]
        next if (a+c+b+d)["AGC"]
        next if (a+b+d+c)["AGC"]
        s=b+c+d
        dp[i+1][s]=dp[i+1][s].to_i+dp[i][a+b+c].to_i
        dp[i+1][s]%=mod
    }
}
puts g.repeated_permutation(3).map{|a,b,c|dp[n][a+b+c]||0}.inject(:+)%mod

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<vector<ll>> imos(2, vector<ll>(n + 1, 0));
    for(ll i = 0; i < n; i++) {
        ll a;
        cin >> a;
        imos[0][max(0LL, i - a)]++;
        imos[0][min(n, i + a + 1)]--;
    }
    for(ll i = 0; i < n; i++) {
        imos[0][i + 1] += imos[0][i];
    }
    ll num = -1, cnt = -1;
    for(ll i = 0; i < k - 1; i++) {
        bool f = 1;
        for(ll j = 0; j < n; j++) {
            if(imos[i & 1][j] < max(j, n - 1 - j)) {
                f = 0;
            }
        }
        if(f) {
            num = i;
            cnt = k - 1 - i;
            break;
        }
        for(ll j = 0; j < n; j++) {
            ll d = imos[i & 1][j];
            imos[(i + 1) & 1][max(0LL, j - d)]++;
            imos[(i + 1) & 1][min((ll)n, j + d + 1)]--;
        }
        for(ll j = 0; j < n; j++) {
            imos[(i + 1) & 1][j + 1] += imos[(i + 1) & 1][j];
        }
        imos[i & 1].assign(n + 1, 0);
    }
    if(num != -1) {
        for(ll i = 0; i < n; i++) {
            imos[num & 1][i] = n;
        }
    }
    if(num == -1) {
        // cerr << ((k - 1) & 1) << endl;
        for(ll i = 0; i < n; i++) {
            cout << imos[(k - 1) & 1][i] << " ";
        }
        cout << "\n";
    } else {
        // cerr << (num & 1) << endl;
        for(ll i = 0; i < n; i++) {
            cout << imos[num & 1][i] << " ";
        }
        cout << "\n";
    }
}

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

int main(void){
  int a[5];
  int k;
  bool flag = true;
  for(int i = 0; i < 5; i++){
    cin >> a[i];
  }
  cin >> k;
  for(int i = 0; i < 5; i++){
    for(int j = i+1; j < 5; j++){
      if(abs(a[i]-a[j]) >k){
        flag = false;
        break;
      }
    }
    if(!flag)
      break;
  }
  if(flag)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main implements Runnable
{
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int h=sc.nextInt();
        int w=sc.nextInt();
        int n=sc.nextInt();
        h=max(h,w);
        n+=h-1;
        out.println(n/h);
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//class P {
//	int x,y; double d;
//	P(int  x, int y, double d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}


class P implements Comparable<P>{
    int x,y,ds;
    P(int x,int y, int ds) {
    	this.x=x;
    	this.y=y;
    	this.ds=ds;
    }

    public int compareTo(P p){
        return ds-p.ds;
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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


int main(){
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    if(e-a>k) {
        printf(":(\n");
    }
    else {
        printf("Yay!\n");
    }
    return 0;
}


Measured memory_bytes: 256
L, R = gets.split(" ").map!(&:to_i)
min = 2019
L.upto(R-1) do |i|
  (i+1).upto(R) do |j|
    min = (i*j)%2019 if min >= (i*j)%2019
    break if min == 0
  end
  break if min == 0
end
p min

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h> 
typedef struct{
    int k,l,r;
}Node;
void insert(int, int);
void inParse(int);
void preParse(int);
Node T[500001];
int main(void)
{
    char s[8];
    int m;
    int num,count=0;
    int i;
   
    scanf("%d", &m);  
    for(i=0; i<m; i++){
        scanf("%s", &s);
        if(s[0]=='i'){ 
          scanf("%d", &num); 
          insert(count, num); 
          count++; 
        }
        if(s[0]=='p'){
          if(count>0) inParse(0);
            printf("\n");
            if(count>0) preParse(0);
            printf("\n");
        }
    }  
    return 0;  
}
   
void inParse(int p){
    if(T[p].l>=0) inParse( T[p].l);
    printf(" %d", T[p].k);
    if(T[p].r>=0) inParse( T[p].r);
}
   
void preParse(int p){
    printf(" %d", T[p].k);
    if(T[p].l>=0) preParse(T[p].l);
    if(T[p].r>=0) preParse(T[p].r);
}
   
void insert(int count, int z){
    int x=0, y;
    if(count<1) x=-1;
   
    T[count].k = z;
    T[count].l = -1;
    T[count].r = -1;
   
    while(x>=0){
        y = x; 
        if(z < T[x].k)x = T[x].l; 
        else x = T[x].r; 
    }
    if(count<1){}
    else if(z < T[y].k)T[y].l = count; 
    else T[y].r = count; 
}


Measured memory_bytes: 7548
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
  int h, w, d, q;
  scanf("%d%d%d", &h, &w, &d);
  
  int x[90001], y[90001];
  
  for (int i=0;i<h;i++) {
    for (int j=0;j<w;j++) {
      int n;
      scanf("%d", &n);
      x[n] = j;
      y[n] = i;
    }
  }
  
  scanf("%d", &q);
  
  int t[90001] = {};
  
  for (int i=1+d;i<90001;i++) {
  	t[i] = t[i-d]+abs(x[i-d]-x[i])+abs(y[i-d]-y[i]);
  }
  
  for (int i=0;i<q;i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    
    printf("%d\n", t[r]-t[l]);
  }
  
  return 0;
}

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

int main()
{
    int k, x;
    cin >> k >> x;
    for (int i = x - k + 1; i <= x + k - 1; i++) {
        if (i == x - k + 1) {
            cout << i;
        } else {
            cout << " " << i;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
g=[[]for _ in range(n)]
for _ in range(n-1):
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    g[a].append((b,c))
    g[b].append((a,c))


q,k=map(int,input().split())
k-=1

dist=[float("inf")]*n
dist[k]=0
def dfs(s):
    for v,c in g[s]:
        if dist[v]==float("inf"):
            dist[v]=dist[s]+c
            dfs(v)


dfs(k)

for _ in range(q):
    x,y=map(int,input().split())
    x,y=x-1,y-1
    print(dist[x]+dist[y])


Measured memory_bytes: 131760
#include<cstdio>
#include<algorithm>
 
using namespace std;
 
int main() {
    int m[10];
 
    for (int i = 0; i < 10; i++)scanf("%d", &m[i]);
 
    stable_sort(m, m + 10);
     
    for(int i=9;i>6;i--)printf("%d\n", m[i]);
 
    return 0;
}


Measured memory_bytes: 2784
import sys
from collections import deque
input = sys.stdin.readline
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
for a,b in ab:
  graph[a].append(b)
s,t = map(int,input().split())
visited = [[-1,-1,-1] for i in range(n+1)]
que = deque([(s,0,0)])
while que:
  x,mod,cnt = que.popleft()
  visited[x][mod] = cnt
  if x == t and mod == 0:
    break
  for y in graph[x]:
    if visited[y][(mod+1)%3] == -1:
      que.append((y,(mod+1)%3,cnt+1))
      visited[y][(mod+1)%3] = cnt+1
print(visited[t][0]//3)

Measured memory_bytes: 84316
#include<bits/stdc++.h>
using namespace std;
int main(){
    char a[999990];
    int sum=0;
    gets(a);
    for(int i=1;i<strlen(a);i++){
//        for(int j=2;j<=strlen(a);j++){
            if(a[i]!=a[i-1]){
                sum++;
            }
//        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 384
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());


		for(int i = 0; i < n; i++){
			String[] tmpArray = br.readLine().split(" ");

			Point2D[] points = new Point2D[4];

			for(int j = 0; j < 4; j++){
				int x = Integer.parseInt(tmpArray[j*2]);
				int y = Integer.parseInt(tmpArray[j*2 + 1]);

				points[j] = new Point2D.Double(x, y);
			}

			Line2D[] lines = new Line2D[2];
			for(int j = 0; j < 2; j++){
				lines[j] = new Line2D.Double(points[j*2], points[j*2 + 1]);
			}

			if(lines[0].intersectsLine(lines[1])){
				System.out.println(1);
			}
			else {
				System.out.println(0);
			}
		}
	}

}



Measured memory_bytes: 28868
for _ in range(10000):
    n,x=list(map(int,input().split()))
    if n==0 and x==0:
        exit(0)
    ans=0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            if j<x-i-j<n+1:
                ans+=1
    print(ans)


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

const int MAX = 1100000;
const int MOD = 1000000007;

long long 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;
    }
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    COMinit();

    int N; cin >> N;
    vector<int> cnt_pr(1000001, 0);
    ll A[N]; rep(i, N) cin >> A[i];
    ll lcm = 1;
    rep(i, N){
        ll val = A[i];
        ll ulim = sqrt(val);
        for(int j = 2; j <= ulim; j++){
            int num = 0;
            while(val % j == 0){
                val /= j;
                num++;
            }
            cnt_pr[j] = max(cnt_pr[j], num);
        }
        if(val > 1) cnt_pr[val] = max(cnt_pr[val], 1);
    }
    rep(i, 1000001){
        rep(j, cnt_pr[i]){
            lcm = (lcm * i) % MOD;
        }
    }
    //cout << "lcm mod P = " << lcm << endl;
    ll ans = 0;
    rep(i, N) ans = (ans + (lcm * inv[A[i]])) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 30080
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> A(N),B(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    B.at(i)=A.at(i);
    }
  sort(B.begin(),B.end());
  int count=0;
  for(int i=0;i<N;i++){
    if(A.at(i)!=B.at(i)) count++;
    }
  if(count<=2) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    string s,t;
    cin >> s >> t;
    ll n=t.size();
    ll x=s.size();
    if(x<n){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    vector<ll>check(51,MOD);
    for(ll i=x-n;i>=0;i--){
        bool judge=true;
        for(ll j=0;j<n;j++){
            if(s[i+j]!='?'&&s[i+j]!=t[j]){
                judge=false;
            }
        }
        if(judge){
            check[i]=i;
        }
    }
    sort(check.begin(),check.end());
    ll cnt=0;
    for(ll i=0;i<51;i++){
        if(check[i]==MOD) break;
        cnt++;
    }
    if(cnt==0){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    vector<string>S(cnt);
    for(ll k=0;k<cnt;k++){
        string sumple=s;
        for(ll i=0;i<x;i++){
            if(check[k]==i){
                for(ll j=0;j<n;j++){
                    sumple[i+j]=t[j];
                }
                i+=n;
            }

            if(sumple[i]=='?'){
                sumple[i]='a';
            }
        }
        S[k]=sumple;
    }
    sort(S.begin(),S.end());
    cout << S[0] << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int x, y;
    cin >> x >> y;


    vector <int> c;
    c.app(x);
    c.app(-x);
    c.app(y);
    c.app(-y);

    const int INF = 5e18;
    vector <int> d(4, INF);
    d[0] = 0;

    for (int t = 0; t < 10; ++t) {
        for (int i = 0; i < 4; ++i) {
            for (int j = 0; j < 4; ++j) {
                if (c[i] <= c[j])
                    d[j] = min(d[j], d[i] + c[j] - c[i]);
                if (c[j] == -c[i])
                    d[j] = min(d[j], d[i] + 1);
            }   
        }   
    }

    cout << d[2] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){
	
	int N;
	cin>>N;
	
	string S;
	
	cout<<0<<endl;
	cin>>S;
	
	if(S=="Vacant"){
		return 0;
	}
	
	int ok = 0;
	int ng = N;
	
	
	while(true){
		int mid = (ok+ng)/2;
		string T;
		cout<<mid<<endl;
		cin>>T;
		
		if(T=="Vacant"){
			return 0;
		}
		
		if((T==S) == (mid%2==0)){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}
	
	return 0;
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n;
	int max=0,o=0,c=0;
	int x=0;

	cin>>n;


	for(int i=1; i<n+1; ++i){
		o=i;
		c=0;
		for(int j=1; j<n+1;++j){
			if(o%2==0){
				c++;
				o=o/2;
			}else{
				break;
			}
		}
		if(max<=c){
			max=c;
			x=i;
		}
	}

	cout<<x<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 100005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<lint,lint> pii;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    lint a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(max(a*c,a*d),max(b*c,b*d));
    return 0;
}


Measured memory_bytes: 3652
n, m = map(int, input().split())
a_b = [list(map(int, input().split())) for _ in range(m)]

def countList(lst, x):
    count = 0
    for i in range(len(lst)):
        if x in lst[i]:
            count += 1
    return count

for i in range(1, n + 1):
    print(countList(a_b, i))


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

const int N = 1111111;

int A[N] , n , ans , L[N] , R[N];

vector <int> pos;

int main() {
	scanf("%d" , &n);
	for(int i = 1;i <= n;++ i)
	scanf("%d" , &A[i]);
	long long ans = 0;
	for(int i = 1;i <= n;++ i) {
		if(!A[i]) {
			L[i] = L[i - 1] + 1;
		}
		else {
			L[i] = 0 , pos.push_back(i);
			ans += (L[i - 1] * 1LL * (L[i - 1] + 1) / 2);
		}
	}
	if(!A[n])
	ans += (L[n] * 1LL * (L[n] + 1)) / 2LL;
	for(int i = n;i >= 1;-- i) {
		if(!A[i])
		R[i] = R[i + 1] + 1;
		else R[i] = 0;
	}

	for(int i = 0;i < (int)pos.size();++ i) {
		int a = 0 , b = 0;
		for(int j = i;j < (int)pos.size();++ j) {
			a += A[pos[j]];
			b ^= A[pos[j]];
			if(a != b)
			break;
			ans += (L[pos[i] - 1] + 1) * 1LL * (R[pos[j] + 1] + 1);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6004
#include<bits/stdc++.h>
using namespace std;
int solve(vector<int>v,int n,int k)
{
	vector<int>dp(n+1,INT_MAX);
	dp[1] = 0;
	int size = 0;
	for(int i=2;i<=n;i++)
	{
		if(i-k<1)
			size = 1;
		else
			size = i-k;
		for(int j=size;j<i;j++)
		{
			int option = abs(v[i] - v[j]) + dp[j];
			dp[i] = min(option,dp[i]);
		}
	}
	return dp[n];
}
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int>v(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>v[i];
	}
	cout<<solve(v,n,k);
}

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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {//x^n
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n-1; i++) {
            x *= y;
        }
        return x;
    }
}


int main() {
    int x, y;
    cin >> x >> y;
    double a, b;
    a = 2*x - y/2.0;
    b = y/2.0 - x;
    // cout << a << " " << b << endl;
    if (a == floor(a) && b == floor(b) && a >= 0 && b >= 0) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}

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

int main() {
  int n, s = 0;
  cin >> n;
  for(int i = 1; i <= n; i++){
    int p;
    cin >> p;
    if(p != i)
      s++;
  }
  if(s > 2)
    cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 2e9
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;

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

  ll *a = new ll[n + 1];
  REP(i, n)
  {
    cin >> a[i + 1];
  }

  bool *is_visited = new bool[n + 1];
  REP(i, n + 1)
  {
    is_visited[i] = false;
  }

  ll now = 1;
  vector<ll> p;
  p.push_back(now);
  is_visited[1] = true;
  REP(i, k)
  {
    now = a[now];
    p.push_back(now);

    if (is_visited[now])
    {
      break;
    }

    is_visited[now] = true;
  }

  if (p.size() == k + 1)
  {
    cout << p.back() << endl;
    return 0;
  }

  auto itr = find(ALL(p), p.back());
  ll loop_begin_index = distance(p.begin(), itr);
  ll loop_size = p.size() - loop_begin_index - 1;

  cout << p[loop_begin_index + ((k - loop_begin_index) % loop_size)] << endl;

  return 0;
}

Measured memory_bytes: 7028
<?php
  fscanf(STDIN, "%d%d", $n , $q);
  $s = trim(fgets(STDIN));
  $cnt = 0;
  $dp[0] = $cnt;
  for($i=1; $i<$n; $i++){
      if($s[$i-1].$s[$i] == "AC"){
          $cnt++;
      }
      $dp[$i] = $cnt;
  }
//   print_r($dp);
  for($i=0; $i<$q; $i++){
      fscanf(STDIN, "%d%d", $l, $r);
      echo $dp[$r-1]-$dp[$l-1];
      echo "\n";
  }

Measured memory_bytes: 21032
#include <iostream>
#include <algorithm>
#include <deque>
#include <functional>
using namespace std;
int main(){
	int data[150]={0},cp[150]={0},t,cnt=1,max,i=0;
	while(cin>>t){
		data[t]++;
		cnt++;
	}
	for(i=0;i<cnt;i++){
		cp[i]=data[i];
	}
	sort(data,data+150,greater<int>());
	for(int j=0;j<cnt;j++){
		if(data[0]==cp[j]){
			cout<<j<<endl;
		}
	}
return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int A,B;
    cin >> A >> B;
    int n = A;
    for(int d = 1;d <= B;d *= 10){
        n *= 10;
    }
    n += B; 
    for(int i = 1;i*i <= n;i++){
        if(i*i == n){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <cstdio>
#include <utility>
#include <bitset>
#include <complex>
#include <stack>
#include <tuple>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
vector<int> a;
const int INF = 1e7;
int main(){
	int N;
	cin >> N;
	a.assign(100000,0);
	for(int i=0;i<N;i++){
		int k;
		cin >> k;
		a[k-1]++;
	}
	int amari=0;
	int ans=0;
	for(int i=0;i<100000;i++){
		if(a[i]>0){
			ans++;
			amari=(amari+a[i]-1)%2;
		}
	}
	cout << ans - amari << endl;
	return 0;
}


Measured memory_bytes: 1148
S  =  input()

if S  ==  'SUN' :
    print(7)
elif  S  ==  'MON':
    print(6)
elif  S  ==  'TUE':
    print(5)
elif  S  ==  'WED':
    print(4)
elif  S  ==  'THU':
    print(3)
elif  S  ==  'FRI':
    print(2)
elif  S  ==  'SAT':
    print(1)

Measured memory_bytes: 9100
#include<iostream>
#include<string>

using namespace std;

int main(){

    string order, str, p = "";
    unsigned int a, b, n;
    unsigned int i, j;

    cin >> str;
    cin >> n;

    for(i=0;i<n;i++){

        cin >> order >> a >> b;
        if(order == "replace"){
            cin >> p;
        }

        if(order == "replace"){
            unsigned int k = 0;
            str.replace(a, b-a+1, p);
            // cout << "replace" << endl;
            // cout << str << endl;
        }

        if(order == "reverse"){
            string tmp = "";
            for(j=a;j<=b;j++){
                tmp += str[j];
            }
            string reversed = "";
            for(j=tmp.length();j>0;j--){
                reversed += tmp[j-1];
            }
            str.replace(a, b-a+1, reversed);
            // cout << "reverse" << endl;
            // cout << str << endl;
        }
        
        if(order == "print"){
            for(j=a;j<=b;j++){
                cout << str[j];
            }
            cout << endl;
        }

    }

    return 0;

}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::string s; cin >> s;

	auto check = [n, s](int t) -> bool {
		int tmp = 0;
		std::map<std::string, int> mp;
		for(int i = t; i < n - t + 1; i++) mp[s.substr(i, t)]++;

		for(int i = 0; i < n - t + 1; i++) {
			if(mp[s.substr(i, t)]) return true;
			if(i + t + t <= n) mp[s.substr(i + t, t)]--;
		}
		return false;
	};
	
	int ok = 0, ng = n + 1;
	while(std::abs(ng - ok) > 1) {
		int mid = (ok + ng) >> 1;
		
		if(check(mid)) ok = mid;
		else ng = mid;
	}
	printf("%d\n", ok);
	return 0;
}


Measured memory_bytes: 6656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int n = Integer.parseInt( br.readLine() );

   int[] R = new int[n];

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

	   R[i] = Integer.parseInt( br.readLine() );

   }

   int maxv = R[1] - R[0];
   int minv = R[0];

   for(int j = 1 ; j < n ;j++){

	   if(R[j]-minv > maxv ){
		   maxv = R[j]-minv;
		   //System.out.println("maxv= "+maxv);
	   }

	   if(minv > R[j] ){
		   minv = R[j];
		  // System.out.println("minv= "+minv);
	   }

   }


   System.out.println(maxv);


 }
}

Measured memory_bytes: 43020
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
//#define for(i, K, N)  for(int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
ll N, K, Ans = 0;cin >> N >> K;
map<ll, ll> MAP;

for(int i = 0; i < N; i++){
ll a, b;cin >> a >> b;
MAP[a] += b;
}

for(auto x : MAP){

K -= x.second;
if(K <= 0){Ans = x.first;break;}
}
cout << Ans;
}

Measured memory_bytes: 7484
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  int X, Y;
  cin >> X >> Y;

  if((4*X-Y)%2==0 && (4*X-Y)/2>=0 && (Y-2*X)%2==0 && (Y-2*X)/2>=0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
return 0;
}

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

using namespace std;

const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const int N = 2e3 + 7;

int n;
int a[N * 3];
int dp[N][N], mv[N], curmv[N], curdp[N];

inline void update(int x, int y, int z) {
  // x, y, dp[x][y];
  if (x > y) swap(x, y);
  if (z <= dp[x][y]) return;
  dp[x][y] = z;
  // mv[x], mv[y];
  mv[x] = max(mv[x], z);
  mv[y] = max(mv[y], z);
  #ifdef DEBUG
  #endif
}

#ifdef DEBUG
void print() {
  cout << "***********\n";
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      cout << dp[i][j] << " \n"[j==n];
  for (int i = 1; i <= n; ++i) cout << mv[i] << " \n"[i==n];
  cout << "***********" << endl;
}
#endif

inline void solve() {
  cin >> n;
  for (int i = 1; i <= 3*n; ++i) cin >> a[i];
  memset(dp, 0x9f, sizeof dp);
  memset(mv, 0x9f, sizeof mv);
  
  update(a[1], a[2], 0);
  int base = 0;

  for (int i = 3; i+2 <= 3*n; i += 3) {
    // 统计相等的个数, 
    if (a[i] == a[i+1] && a[i] == a[i+2]) {
      ++base;
      continue;
    }
    int b[3], maxv = 0;
    // 当前的 前三个 排序.
    sort(a + i, a + i + 3);
    // 1. 前两个相等: 变为后面两个相等:
    // x p p 或者 x l k 的形式.
    if (a[i+1] == a[i+2]) swap(a[i], a[i+2]); // fuck there
    // 2. 转移公式:
    for (int j = 1; j <= n; ++j) {
      curdp[j] = dp[min(a[i], j)][max(a[i], j)];
      curmv[j] = mv[j];
      maxv = max(maxv, mv[j]);
    }
    // 3. 第二个公式: b[j] = dp[a[i + j]][a[i + j]]
    for (int j = 0; j < 3; ++j) b[j] = dp[a[i + j]][a[i + j]];
    // 4. 第三个公式: 
    if (a[i] == a[i+1]) for (int j = 1; j <= n; ++j) { // fuck here
      // curdp[j] = dp[min(a[i], j)][max(a[i], j)];
      update(a[i + 2], j, curdp[j]+1); // dp[a[i]][j] -> dp[a[i+2]][j]
    }
    update(a[i+1], a[i+2], b[0]+1); // get three a[i]
    update(a[i], a[i+2], b[1]+1); // get three a[i+1]
    update(a[i], a[i+1], b[2]+1); // get three a[i+2]
    // two of three rest.
    update(a[i+1], a[i+2], maxv);
    update(a[i], a[i+2], maxv);
    update(a[i], a[i+1], maxv);
    // one of three rest.
    for (int j = 1; j <= n; ++j) {
      update(a[i], j, curmv[j]);
      update(a[i+1], j, curmv[j]);
      update(a[i+2], j, curmv[j]);
    }
#ifdef DEBUG
    cout << i << ":\n"; print();
#endif
  }
  int res = dp[a[3*n]][a[3*n]]+1;
  for (int i = 1; i <= n; ++i) res = max(res, mv[i]);
  cout << res+base << endl;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}


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

// #define int long long
#define ll long long
#define pb push_back
#define vi vector<int>
#define vii vector<vector<int> >

template <class X>
void print(X Target)
{
  cout << Target;// << '\n';
}

signed main()
{
  // ios::sync_with_stdio(false);
  int N, X, D;
  cin >> N;
  int bs[1001];
  bool check[1001] = {false};

  for (int i = 0; i < N; i++){
    scanf("%1d", &bs[i]);
  }
  cin >> D;

  int cnt = 0;
  for (int i = 0; i < N; i++){
    if (cnt == D) break;
    if (!check[i] && !bs[i]){
      bs[i] = 1;
      check[i] = true;
      cnt++;
    }
  }

  for (int i = N - 1; cnt < D && i >= 0; i--){
    if (!check[i] && bs[i]){
      bs[i] = 0;
      check[i] = true;
      cnt++;
    }
  }

  for (int i = 0; i < N; i++) print(bs[i]);
  cout << '\n';

  return (0);
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=(1e9+7);
int n;
int fac[200001],inv[200001];
int qpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=a*a%mod)
	if(b&1)ans=ans*a%mod;
	return ans;
}
int C(int n,int m){
	if(!n)return 1;
	if(m<n)return 0;
	return fac[m]*inv[m-n]%mod*inv[n]%mod;
}
void init(){
	fac[0]=1;
	for(int i=1;i<=n;++i)fac[i]=i*fac[i-1]%mod;
	inv[n]=qpow(fac[n],mod-2);
	for(int i=n-1;~i;--i)inv[i]=inv[i+1]*(i+1)%mod;
}
int col[200001];
int w[200001];
int allmin=0x7fffffff,secmin=0x7fffffff;
int minpos,secpos;
int minn[200001];
int A,B;
int sum[200001],allsum;
signed main(){
	memset(minn,0x7f,sizeof(minn));
	scanf("%lld%lld%lld",&n,&A,&B);
	init();
	for(int i=1;i<=n;++i){
		scanf("%lld%lld",&col[i],&w[i]);
		minn[col[i]]=min(minn[col[i]],w[i]);
		if(w[i]<allmin){
			secpos=minpos;
			minpos=i;
			secmin=allmin;
			allmin=w[i];
		}
		else if(w[i]<secmin){
			secpos=i;
			secmin=w[i];
		}
	}
	for(int i=1;i<=n;++i){
		if(minn[col[i]]+w[i]<=A){
			w[i]=minn[col[i]];
		}
		if(col[i]!=col[minpos]&&w[i]+w[minpos]<=B){
			allsum++;
			sum[col[i]]++;
		}
		if(col[i]==col[minpos]&&w[i]+w[secpos]<=B){
			allsum++;
			sum[col[i]]++;
		}
	}
	int ans=1;
	for(int i=1;i<=n;++i){
		if(sum[i]){
			ans=(ans*C(sum[i],allsum))%mod;
			allsum-=sum[i];
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 9600
import math
while True:
    n = int(input())
    if n == 0:
        break
    m = list(map(int,input().split()))
    h = sum(m)/n
    b = 0
    for i in range(n):
        a = (m[i]-h)**2
        b += a
    print("{0:.8f}".format(math.sqrt(b/n)))


Measured memory_bytes: 5708