akhauriyash/Code-Regression huggingface dataset:
def warshal(data):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                data[i][j]=min(data[i][j],data[i][k]+data[k][j])
    return data
n,m,l=map(int,input().split())
inf=float("inf")
data=[[inf]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    data[a-1][b-1]=c
    data[b-1][a-1]=c
for i in range(n):
    data[i][i]=0
data=warshal(data)
for i in range(n):
    for j in range(n):
        if data[i][j]<=l:
            data[i][j]=1
        else:
            data[i][j]=inf
for i in range(n):
    data[i][i]=0
data=warshal(data)
q=int(input())
st=[]
for i in range(q):
    s,t=map(int,input().split())
    st.append([s-1,t-1])
for s,t in st:
    if data[s][t]==inf:
        print(-1)
    else:
        print(data[s][t]-1)

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

int main() {
  string S;
  cin>>S;
  int count=0;
  if (S[0]=='o')count++;
  if (S[1]=='o')count++;
  if (S[2]=='o')count++;
  count *=100;
  count += 700;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main(){
	lli n,W;
	cin>>n>>W;
	vector<lli> w(n);
	vector<lli> v(n);
	for(lli i=0;i<n;i++){
		cin>>w[i]>>v[i];
	}
	vector<vector<lli> > dp(n,vector<lli>(W+1));
	for(lli i=0;i<n;i++){
		dp[i][0]=0;
	}
	for(lli j=0;j<=W;j++){
		dp[0][j]=(j>=w[0])?v[0]:0;
	}

	for(lli i=1;i<n;i++){
		for(lli j=1;j<=W;j++){
			if(j-w[i]>=0)
				dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}

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

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

#define ucin ios::sync_with_stdio(0), cin.tie(0)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;

const int N = 4e5 + 10;
const int mod = 1e9 + 7;

int qpow(int a, int b) {
	int ans = 1;
	for(; b >= 1; b >>= 1, a = (ll) a * a % mod)
		if(b & 1) ans = (ll) ans * a % mod;
	return ans;
}
int n, a[N], sz[N];
ll ans;
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) {
		scanf("%d", a + i);
		ans += sz[a[i]] ++;
	}
	for(int i = 1; i <= n; i ++)
		printf("%lld\n", ans - sz[a[i]] + 1);
	return 0;
}

Measured memory_bytes: 3712
S = input()
strs = ["erase", "eraser", "dreamer","dream"]
rtss = [s[::-1] for s in strs]
S = S[::-1]

ind = 0
while True:
    # print(ind,S[ind])
    if S[ind:ind+5] in rtss:
        ind += 5
    elif S[ind:ind+6] in rtss:
        ind += 6
    elif S[ind:ind+7] in rtss:
        ind +=7
    else:
        print("NO")
        exit()
    if ind == len(S):
        print("YES")
        exit()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(ll i=0;i<n;i++)
#define revf(i,n) for(ll i=n-1;i>=0;i-=2)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define inp(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define outp(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" "
#define outp1(a,n) for(ll i=1;i<n;i++)cout<<a[i]<<" "
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))
#define pb push_back
#define mp make_pair
#define mem(x,n) memset(x,n,sizeof(x))
#define BINSC binary_search
#define BITOUT __builtin_popcount
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define cn cout<<"\n";
int main()
{
     fast;
     string n;ll s=0;
     cin>>n;
     for(ll i=0;i<n.length();i++)
     {
          s+=n[i]-'0';
     }
     //cout<<s;
     if(s%9==0)
     cout<<"Yes";
     else
     cout<<"No";
}


Measured memory_bytes: 3756
#include<iostream>

using namespace std;
long long gcd(long long a, long long b){
	if(b==0){
		return a;
	}
	return gcd(b,a%b);
}

int main(){
	long long t,a,b,c,d,i;
	cin >> t;
	for(i=0;i<t;i++){
		cin >> a >> b >> c >> d;
		if(a<b){
			cout << "No" << endl;
			continue;
		}else if(d>=b && c>=b){
			cout << "Yes" << endl;
			continue;
		}
		if(b>d){
			cout << "No" << endl;
			continue;
		}
		long long x = a-b,y = a-c,z = gcd(b,d);
		if(((y-1)/z)*z>x){
			cout << "No" << endl;
		}else{
			cout << "Yes" << endl;
		}
	}
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let mut buf = String::new();
    let mut i = 0;
    io::stdin().read_line(&mut buf).unwrap();
    for s in buf.trim().chars() {
        if s == 'o' {
            i += 1;
        }
    }
    println!("{}", 700 + 100 * i);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
#include <list>
using namespace std;

#define INF 2000000001

class Node{
public:
  int key;
  int parent;
  int left, right;
public:
  Node(){parent = left = right = INF;}
  void print(){
    printf("key = %d, ", key);
    if(parent != INF)
      printf("parent key = %d, ", parent);
    if(left != INF)
      printf("left key = %d, ", left);
    if(right != INF)
      printf("right key = %d, ", right);
  }
};

int main(){
  int n; cin>> n;
  vector<Node> nodes(n+1);

  for(int i=1;i<=n;i++){
    cin >> nodes[i].key;
  }
  for(int i=1;i<=n;i++){
    if(i*2 <= n) nodes[i].left = nodes[i*2].key;
    if(i*2+1 <= n) nodes[i].right = nodes[i*2+1].key;
    if(i/2 < 1) continue;
    nodes[i].parent = nodes[i/2].key;
  }

  for(int i=1;i<=n;i++){
    printf("node %d: ", i);
    nodes[i].print();
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll minthis(ll a, ll b){return a<b?a:b;}
ll maxthis(ll a, ll b){return a>b?a:b;}
bool sortbysec(const pair<int, int>& a,const pair<int, int>& b){return (a.second < b.second);} 

void solve(){
   double n, m , k;
  cin >> n >> m >> k;
 if((n/k) <= m){
    cout << "Yes" << "\n";return;
 } 
 cout << "No" << "\n";
}
 
 
int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
  return 0; 
}



Measured memory_bytes: 3720
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int x[5];
//---------------------------------------------------------------------------------------------------
void _main() {
	rep(i, 0, 5) cin >> x[i];
	rep(i, 0, 5) if (x[i] == 0) {
		printf("%d\n", i + 1);
		return;
	}
}







Measured memory_bytes: 3728
#include <stdio.h>

int main()
{
    int r, g, b;
    scanf("%d %d %d", &r, &g ,&b);
    int c = r * 100 + g * 10 + b;
    if (c % 4 == 0)
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    return 0;
}


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

int main(){
  string s;
  cin>>s;
  int n=200;
  long long k;
  cin>>k;
  int l=s.length();
  char a;
  for(int i=0;i<l;i++){
    if(s[i]!='1'){
      a=s[i];
      n=i;
      break;
    }
  }
  if(n==200){
    cout<<1<<endl;
  }else if(k-1<n&&k<=100){
    cout<<1<<endl;
  }else{
    cout<<a<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

int X,A,B;

int main(){
    cin>>X>>A>>B;

    X-=A;
    while(X>=B) X-=B;

    cout<<X<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <unordered_map>
#include <cstdlib>
#include <algorithm>

#define fin stdin
#define fout stdout

#define x first
#define y second

#define ll long long

#define LIM (10LL * 1000 * 1000 * 1000)
#define MAXR 100000
#define MAXC 3200
#define MAX0 452

#define MAXN 100000

struct myc{
    int x;
    ll y;
};

std::unordered_map <ll, int> p2;
std::unordered_map <ll, myc> mp;

int pr[MAX0 + 1];
bool c[MAXR + 1];

ll t[MAXN + 1];
int k;

inline void add(ll a, ll b){
    if(a > LIM)
        exit(1);
    if(b > LIM)
        exit(2);
    if(b < 0)
        exit(3);

    auto &u = mp[a];
    u.x ++;
    u.y = b;

    if(u.x == 1)
        t[++ k] = a;
}

inline void inmult(ll &a, ll b){
    if(a > 0){
        a *= b;
        if(a > LIM)
            a = -1;
    }
}

int main(){
    for(int i = 2; i * i <= MAXR; i ++)
        if(c[i] == 0)
            for(int j = i * i; j <= MAXR; j += i)
                c[j] = 1;

    for(int i = 2;  i <= MAXC; i ++)
        if(c[i] == 0)
            pr[++ pr[0]] = i;

    //printf("%d", pr[0]);

    for(int i = MAXC + 1; i <= MAXR; i ++)
        if(c[i] == 0)
            p2[1LL * i * i] = i;

    int n;
    fscanf(fin, "%d", &n);

    int ans = 0;
    bool cub = 0;
    for(int i = 1; i <= n; i ++){
        ll x, imag = 1, rev = 1;
        fscanf(fin, "%lld", &x);

        int q = 1;
        while(q <= pr[0] && x != 1){
            int s = 0;
            while(x % pr[q] == 0)
                s ++, x /= pr[q];
            s %= 3;
            if(s > 0){
                for(int j = 0; j < s; j ++)
                    imag *= pr[q];
                for(int j = 0; j < 3 - s; j ++)
                    inmult(rev, pr[q]);
            }
            q ++;
        }

        if(x == 1){
            if(rev == -1) ans ++;
            else if(rev == 1) cub = 1;
            else add(imag, rev);
        }else{
            int u = p2[x];
            if(u == 0){
                if(x <= MAXR){
                    inmult(rev, x);
                    inmult(rev, x);
                    if(rev == -1) ans ++;
                    else add(imag * x, rev);
                }else ans ++;
            }else{
                inmult(rev, u);
                if(rev == -1) ans ++;
                else add(imag * x, rev);
            }
        }
    }

    ans += cub;

    for(int i = 1; i <= k; i ++){
        auto &u = mp[t[i]];
        if(u.x){
            if(t[i] == 1)
                return 4;
            auto &v = mp[u.y];
            ans += std::max(u.x, v.x);
            v.x = 0;
            u.x=0;
        }
    }

    fprintf(fout, "%lld\n", ans);

    return 0;
}


Measured memory_bytes: 11464
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename T>
T dbg(T x) {
  cout << x << endl;
  return x;
}

template<typename T>
struct Monoid {
  T id;
  fn<T(T, T)> op;
  Monoid(T e, fn<T(T, T)> f)
    : id(e), op(f) {
  }
};

template<typename T>
class SegT {
private:
  vector<T> data;
  Monoid<T> monoid;
  int size = 1;

public:
  SegT(const int &n, const Monoid<T> &m = Monoid<int>(INF, [](int a, int b) { return min(a, b); }))
    : monoid(m) {
    while (size < n) size *= 2;
    data = vector<T>(2 * size, monoid.id);
  }

  void update(int i, const T &x) {
    i += size;
    data[i]                = x;
    while (i /= 2) data[i] = monoid.op(data[i * 2], data[i * 2 + 1]);
  }

  // fold [a, b) by monoid.op
  T query(const int &a, const int &b, const int &k = 1, const int &l = 0, int r = -1) {
    if (r == -1) r = size;
    if (r <= a || b <= l) return monoid.id;
    if (a <= l && r <= b) return data[k];
    return monoid.op(query(a, b, k * 2, l, (l + r) / 2),
                     query(a, b, k * 2 + 1, (l + r) / 2, r));
  }
};

void solve() {
  int n, q;
  cin >> n >> q;
  SegT<int> t(n, Monoid<int>(2147483647, [](int a, int b) { return min(a, b); }));
  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com) {
      cout << t.query(x, y + 1) << endl;
    } else {
      t.update(x, y);
    }
  }
}

Measured memory_bytes: 4892
#include <stdio.h>
int main(void)
{
	int n,a1[101],a2[101],i,j,k,c=0,max=0;
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d",&a1[i]);
	}
	for(i=0; i<n; i++){
		scanf("%d",&a2[i]);
	}
	for(i=0; i<n; i++){
		c=0;
		for(j=0; j<=i; j++){
			c=c+a1[j];
		}
		for(k=i; k<n; k++){
			c=c+a2[k];
		}
		if(max<c){
			max=c;
		}
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

static const string END_OF_TEXT = "END_OF_TEXT";

int main(void) {
    int cnt = 0;
    string input, target;
    cin >> target;
    transform(target.begin(), target.end(), target.begin(), ::toupper);
    do {
        cin >> input;
        if(input == "end_of_text") continue;
        transform(input.begin(), input.end(), input.begin(), ::toupper);
        if(input == target) cnt++;
    } while(input != END_OF_TEXT);
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

class tsort {
public:
	int V;
	vector<vector<int> > G;
	vector<int> deg, res;
	tsort(int node_size) : V(node_size), G(V), deg(V, 0){}
	void add_edge(int from,int to){
		G[from].push_back(to);
		deg[to]++;
	}
	bool solve() {
		queue<int> que;
		for(int i = 0; i < V; i++){
			if(deg[i] == 0){
				que.push(i);
			}
		}
		while(!que.empty()){
			int p = que.front();
			que.pop();
			res.push_back(p);
			for(int v : G[p]){
				if(--deg[v] == 0){
					que.push(v);
				}
			}
		}
		return (*max_element(deg.begin(),deg.end()) == 0);
	}
};

int prv[MAX_N], ans[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    tsort ts(n);
    rep(i,n-1+m){
        int u,v;
        cin >> u >> v;
        ts.add_edge(u-1, v-1);
    }
    ts.solve();
    each(u,ts.res){
        each(v,ts.G[u]){
            prv[v] = u + 1;
        }
    }
    rep(i,n){
        cout << prv[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 7672
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

#define MAXN 1000001

using namespace std;

int spf[MAXN];
unordered_map<int, bool> factors;

void sieve()
{
    for (int i = 1; i < MAXN; ++i)
        spf[i] = ((i & 1) ? i : 2);

    for (int i = 3; i * i < MAXN; ++i)
        if (spf[i] == i)
        {
            for (int j = i * i; j < MAXN; j += i)
                if (spf[j] == j)
                    spf[j] = i;
        }
}

void check(string &result, int x)
{
    if (result == "setwise coprime")
        return;

    unordered_set<int> freg;

    while (x != 1)
    {
        if (factors[spf[x]] && result == "pairwise coprime")
        {
            result = "setwise coprime";
            return;
        }
        freg.insert(spf[x]);
        x /= spf[x];
    }

    for (unordered_set<int>::iterator it = freg.begin(); it != freg.end(); ++it)
        factors[*it] = true;
}

int main()
{

    sieve();

    ios_base::sync_with_stdio(false);

    int size;
    cin >> size;

    if (size == 1)
        cout << "not coprime";
    else
    {
        string result = "pairwise coprime";
        int gcd = 0, x;

        while (size--)
        {
            cin >> x;
            if (gcd != 0)
                gcd = __gcd(gcd, x);
            else
                gcd = x;
            check(result, x);
        }
        cout << ((gcd == 1) ? result : "not coprime");
    }

    return 0;
}

Measured memory_bytes: 10632
#l=list(map(int, input().split()))
a,b=map(int, input().split())
#l=list(map(int, input().split()))
#n = int(input())
def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1



ans = 1
temp1 = divisor(a)
temp2 = divisor(b)

if len(temp1) < len(temp2):
    hoge = temp1
    hoge2 = temp2
else:
    hoge = temp2
    hoge2 = temp1

temp = []
for i in hoge:
    if i in hoge2:
        temp.append(i)

#print (temp)
for i in temp:
    if is_prime(i):
        ans += 1

print (ans)



Measured memory_bytes: 4224
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
	int N;
	cin >> N;
	int left = 10000, right = 0;
	for(int i=0;i<N;i++){
		int a;
		cin >> a;
		right = max(right, a);
		left = min(left, a);
	}

	cout << right - left <<endl;
    
	return 0;
}













Measured memory_bytes: 256
#include <stdio.h>
   #include <stdlib.h>
   int main(int argc, char **argv) {
       size_t r;
       int a, b, c;
   
       r = scanf("%d %d %d", &a, &b, &c);
       (void)r;
   
       if (a > b) {
           int t = a;
           a = b;
           b = t;
       }
       if (a < c && c< b) {
           printf("Yes");
       } else {
           printf("No");
       }
       return 0;
   }


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,q;
    cin >> n >> q;
    vector<set<int32>> adj(n);
    REP(i,n-1){
        int32 a, b;
        cin >> a >> b;
        a--;b--;
        adj[a].insert(b);
        adj[b].insert(a);
    }
    vector<vector<int32>> children(n);
    queue<int32> que;
    que.push(0);
    while(!que.empty()){
        int32 x = que.front();
        que.pop();
        for(int32 y : adj[x]){
            children[x].pb(y);
            adj[y].erase(x);
            que.push(y);
        }
        adj[x].clear();
    }
    vector<int32> ans(n, 0);
    REP(i,q){
        int32 p,x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    que.push(0);
    while(!que.empty()){
        int32 x = que.front();
        que.pop();
        for(int32 y : children[x]){
            ans[y] += ans[x];
            que.push(y);
        }
    }
    REP(i,n)cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 38004
#include<stdio.h>
int main(){
  int m[17]={0};
  int mathi[100]={0};
  int i,j,t,n,k,l,mt,s=0;
  for(t=0;1;t++){
    for(i=0;i<17;i++)m[i]--;
    while(s*5<=t){
      n=2;
      if(s%5==1)n=5;
      for(i=0;i<17;i++){
	if(m[i]<1){
	  for(j=0;j<n;j++){
	    if(m[i+j]>0)break;
	  }
	  if(j==n)break;
	}
      }
      if(j==n){
	mt=17*(s%2)+3*(s%3)+19;
	for(j=0;j<n;j++)m[i+j]=mt;
	mathi[s]=t-5*s;
	s++;
	j=-1;
      }
      else break;
      if(s==100)break;
    }
    if(s==100)break;
  }
  while(scanf("%d",&k)!=EOF){
    //for(k=0;k<100;k++){
    printf("%d\n",mathi[k]);
  }
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
  int summer_days;
  int homework_num;
  int spend_days;
  cin >> summer_days >> homework_num;
  for(int i=1;i<=homework_num;i++){
    cin >> spend_days;
    summer_days -= spend_days;
    if(summer_days < 0){
      cout << -1;
      break;
    }
  }
  if(summer_days >= 0){
    cout << summer_days;
  }
  return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();
			long ans = Math.max(a*b, c*d);
			out.println(ans);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21460
k,n = map(int,(input().split()))
a = list(map(int,input().split()))
maxDis = 0

for i in range(len(a)-1):
    if i == 0:
        maxDis = a[i]+k-a[i-1]
    elif abs(a[i]-a[i-1]) > maxDis:
        maxDis = abs(a[i]-a[i-1])
    if abs(a[i]-a[i+1]) > maxDis:
        maxDis = abs(a[i]-a[i+1])

print(k-maxDis)


Measured memory_bytes: 33200
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

int two_in_factorial(int x) {
	int ans = 0;
	for (int i = 2; i <= x; i *= 2) {
		ans += x / i;
	}
	return ans;
}

int get_c(int n, int k) {
	int all = 0;
	all = two_in_factorial(n);
	all -= two_in_factorial(k);
	all -= two_in_factorial(n - k);
	if (all > 0) return 0;
	else return 1;
}

int solve(int n, vector<int> a) {
	int hv = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 2) hv = 1;
	}
	if (hv) {
		int ans = 0;
		for (int i = 0; i < n; i++) {
			ans += (a[i]) * (get_c(n - 1, i));
		}
		return ans % 2;
	} else {
		vector<int> bn;
		for (auto t : a) {
			bn.push_back(t == 3);
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			ans += (bn[i]) * (get_c(n - 1, i));
		}
		return 2 * (ans % 2);
	}
}

// void proc(vector<int> &a) {
// 	int n = (int)a.size();
// 	vector<int> na(n - 1);
// 	for (int i = 0; i + 1 < n; i++) {
// 		na[i] = abs(a[i] - a[i + 1]);
// 	}
// 	a = na;
// }

// int solves(int n, vector<int> a) {
// 	for (int i = 1; i < n; i++) {
// 		proc(a);
// 	}
// 	return a[0];
// }


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

	int n;
	cin >> n;
	vector<int> a;
	for (int i = 0; i < n; i++) {
		char c;
		cin >> c;
		int z = (c - '0');
		a.push_back(z);
	}
	cout << solve(n, a) << endl;

	// mt19937 rng(3);
	// int n = 20;
	// vector<int> a(n);
	// while (true) {
	// 	int hv = 0;
	// 	for (auto &t : a) {
	// 		t = rng() % 3 + 1;
	// 		hv |= (t == 2);
	// 	}
	// 	// if (!hv) continue;
	// 	if (solve(n, a) != solves(n, a)) {
	// 		cout << "WA" << endl;
	// 		for (auto t : a) {
	// 			cout << t;
	// 		}
	// 		cout << endl;
	// 		exit(0);
	// 	} else {
	// 		// cout << "." << endl;
	// 	}
	// }
} 

Measured memory_bytes: 29928
#include <iostream>

const int N = 105;

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

#ifdef DEBUG_ON
    freopen("input", "r", stdin);
#endif

    int width, height, n, grid[N][N] = { 0 };
    std::cin >> width >> height >> n;
    for (int point = 0; point < n; ++point) {
        int x, y, a;
        std::cin >> x >> y >> a;
        int minX, maxX, minY, maxY;
        switch (a) {
            case 1: minX = 0; maxX = x;     minY = 0; maxY = height; break;
            case 2: minX = x; maxX = width; minY = 0; maxY = height; break;
            case 3: minX = 0; maxX = width; minY = 0; maxY = y;      break;
            case 4: minX = 0; maxX = width; minY = y; maxY = height; break;
            default: return -1;
        }
        for (int i = minX; i < maxX; ++i) {
            for (int j = minY; j < maxY; ++j) {
                grid[i][j] = 1;
            }
        }
    }
    int res = 0;
    for (int i = 0; i < width; ++i) {
        for (int j = 0; j < height; ++j) {
            if (grid[i][j] == 0) {
                ++res;
            }
        }
    }
    std::cout << res << '\n';
    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long a,b;
    long long c[n];
    long long ans = 0;
    pair<long long,long long> pr[n];
    for(int i = 0;i<n;i++){
        cin >> a >> b;
        pr[i].first = a+b;
        pr[i].second = a;
    }
    sort(pr,pr+n,greater<pair<long long,long long>>());
    for(int i = 0;i<n;i++){
        if(i%2==0) ans+=pr[i].second;
        else ans-=(pr[i].first-pr[i].second);
    }
    cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i=0;i<N;i++)
    cin >> S.at(i);
  sort(S.begin(),S.end());
  int s=1;
  for(int i=0;i<N-1;i++) {
    if(S.at(i)!=S.at(i+1))
      s++;
  }
  cout << s << endl;
}

Measured memory_bytes: 9548
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N-1];
		for (int i=0;i<N-1;i++) {
			A[i] = sc.nextInt();
		}
		int sum =A[0];
		for (int i=0;i<N-2;i++) {
			if (A[i]>A[i+1]) {
				sum +=A[i+1];
			} else {
				sum +=A[i];
			}
		}
		sum +=A[N-2];
		System.out.println(sum);
	}
}

Measured memory_bytes: 35676
#include <iostream>

using namespace std;

int main(){

    int t, p;
    cin >> t >> p;

    if(p >= t * 2 && p <= t * 4 && p % 2 == 0){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
int main() {
	int n;
	while (cin >> n,n) {
		vector<int>v;
		int x;
		rep(i, n) {
			cin >> x; v.push_back(x);
		}
		double mi = 1000000; int out[3] = {};
		rep(s, 16) {
			rep(a, 16) {
				rep(c, 16) {
					int memo = s; double emt = 0;
					vector<int> u;
					rep(i, n) {
						memo = (a*memo + c) % 256;
						u.push_back((memo+v[i])%256);
					}
					sort(u.begin(), u.end());
					rep(i, n) {
						int cnt = 1; memo = u[i];
						while (i + 1 < n&&u[i + 1] == memo) {
							cnt++; i++;
						}
						emt -= ((double)cnt / (double)n)*log((double)cnt / (double)n);
					}
					if (emt+EPS < mi) {
						mi = emt; out[0] = s; out[1] = a; out[2] = c;
					}
				}
			}
		}
		cout << out[0] << " "<<out[1] <<" " <<out[2] << endl;
	}
	return 0;
}


Measured memory_bytes: 3328
#include<iostream>

using namespace std;

void fsort(int a[])
{
    for(int i = 0; i < 5; ++i)
        for(int j = 0; j <= i; ++j)
            if(a[i] > a[j])
            {
                int tmp;
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }

    for(int i = 0; i < 4; ++i)
        cout << a[i] << " ";

    cout << a[4] << endl;
}

int main()
{
    int a[5];
    for(int i = 0; i < 5; ++i)
        cin >> a[i];
    
    fsort(a);
} 

Measured memory_bytes: 1160
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
#define LL long long
int Adj[MAXN],V[MAXN*2],nxt[MAXN*2],W[MAXN*2],c=1;
void AddEdge(int u,int v)
{
	c++;V[c]=v,nxt[c]=Adj[u],W[c]=1;Adj[u]=c;
	c++;V[c]=u,nxt[c]=Adj[v],W[c]=2;Adj[v]=c;
}
int col[MAXN],vis[MAXN],vise[MAXN],cnt[3],flag,cV,E;
LL ans;
void dfs(int u)
{
	cV++;
	cnt[col[u]]++;
	vis[u]=1;
	for(int i=Adj[u];i;i=nxt[i])
	{
		if(vise[i>>1]) continue;
		vise[i>>1]=1;
		E++;
		if(!vis[V[i]])
		{
			col[V[i]]=(col[u]+W[i])%3;
			dfs(V[i]);
		}
		else if(col[V[i]]!=(col[u]+W[i])%3)
			flag=1;
	}
}
int x[MAXN],y[MAXN];
int main()
{
	int n,m,u,v;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&x[i],&y[i]);
		AddEdge(x[i],y[i]);
	}
	for(int i=1;i<=n;i++)
		if(!vis[i])
		{
			flag=cnt[0]=cnt[1]=cnt[2]=cV=E=0;
			dfs(i);
			if(flag) ans+=1LL*cV*cV;
			else if(!cnt[0]||!cnt[1]||!cnt[2]) ans+=E;
			else ans+=1LL*cnt[0]*cnt[1]+1LL*cnt[1]*cnt[2]+1LL*cnt[2]*cnt[0];
		}
	printf("%lld\n",ans);
}

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

const long long INF = 1LL << 61;

int main() {
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];

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

    vector<long long> Am;
    vector<long long> Az;
    vector<long long> Ap;
    for (int i = 0; i < N; ++i) {
        if (A[i] < 0)Am.push_back(A[i]);
        else if (A[i] > 0)Ap.push_back(A[i]);
        else Az.push_back(A[i]);
    }
    /*cout << Am.size() << endl;
    cout << Ap.size() << endl;
    cout << Az.size() << endl;*/

    long long right = INF;
    long long left = -INF;

    while ((right - left) > 1) {
        long long x = (right + left) / 2;
        long long S = 0;

        if (x >= 0)S += (N - Az.size()) * Az.size() + Az.size() * (Az.size() - 1) / 2;
        //cout << S << endl;

        // 正の数同士
        int end = 0;
        long long num = 0;
        for (int i = Ap.size() - 1; i >= 0; --i) {
            while (end < Ap.size() && Ap[i] * Ap[end] <= x) {
                ++end;
            }
            num += end;
            if (i <= end - 1)num -= 1;
        }
        num /= 2;
        S += num;
        //cout << S << endl;

        // 負の数同士
        end = 0;
        num = 0;
        for (int i = 0; i < Am.size(); ++i) {
            while (end < Am.size() && Am[i] * Am[Am.size() - 1 - end] <= x) {
                ++end;
            }
            num += end;
            if (i >= (Am.size() - end))num -= 1;
        }
        num /= 2;
        S += num;
        //cout << S << endl;

        // 正と負の組み合わせ
        end = 0;
        for (int i = 0; i < Ap.size(); ++i) {
            while (end < Am.size() && Ap[i] * Am[end] <= x) {
                ++end;
            }
            //cout << end << endl;
            S += end;
        }
        //cout << S << endl;
        //cout << left << " " << right << endl;

        if (S >= K)right = x;
        else left = x;
    }

    cout << right;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    string s;
    cin >> s;
    string t;
    cin >> t;
    int ans = 0;
    REP(i,s.size()) {
        if ( s[i] != t[i] ) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  ll ans = k;
  for (ll i = 1; i < n; ++i) {
    ans *= (k-1);
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int x = 0;
    int n;
    string s;
    cin >> n >> s;
    int maxi = 0;
    rep(i,n){
        if(s.at(i) == 'I'){
            x++;
            maxi = max(maxi, x);
        }
        else{
            x--;
        }
    }
    cout << maxi << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int_fast64_t
using namespace std;
#define F first
#define S second
#define pii pair<int, int>
const int MX = 1e5 + 100;
bitset<MX> bs;
deque<int> ans;
priority_queue<pii> a, b;
void push(priority_queue<pii> &pq) {
	if(ans.empty()) {
		ans.push_back(abs(pq.top().F));
		pq.pop();
		return;
	}
	int a = abs(ans. back() - abs(pq.top().F));
	int b = abs(ans.front() - abs(pq.top().F));
	if(a > b) ans.push_back (abs(pq.top().F));
	else      ans.push_front(abs(pq.top().F));
	pq.pop();
}
main () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	for(int i = 1; i <= n; i ++) {
		int in; cin >> in;
		a.push({ in, i});
		b.push({-in, i});
	}
	while(ans.size() < n) {
		while(a.size() and bs[a.top().S]) a.pop();
		while(b.size() and bs[b.top().S]) a.pop();
		if(ans.empty()) push(a);
		else if(a.empty()) push(b);
		else if(b.empty()) push(a);
		else {
			int x = max(abs(ans.back() - a.top().F), abs(ans.front() - a.top().F));
			int y = max(abs(ans.back() + b.top().F), abs(ans.front() + b.top().F));
			if(x > y) push(a);
			else      push(b);
		}
	}
	int sum = 0;
	for(int i = 1; i < n; i ++) sum += abs(ans[i] - ans[i - 1]);
	cout << sum;	
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    string s; cin >> s;
    int ans = 0;
    REP(i, 0, 4){
        if(s[i] == '+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout << ans << endl;
}

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


int main() 
{
	int a,s,h,m;
	scanf("%d",&a);
	s=a%60;
	a=a/60;
	m=a%60;
	h=a/60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}


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

int main(){
  long long N, A, B; cin >> N >> A >> B;
  if(A>B || (N==1 && A!=B)){
    cout << 0 << endl;
    return 0;
  }
  if(N<=2){
    cout << 1 << endl;
    return 0;
  }
  cout << (B-A)*(N-2)+1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int64 L;int N;
int64 a[MAXN],sum[2][MAXN];
void Solve() {
	read(L);read(N);
	for(int i = 1 ; i <= N ; ++i) read(a[i]);
	for(int i = 1 ; i <= N ; ++i) {
		sum[0][i] = sum[0][i - 1] + a[i];
	}
	for(int i = N ; i >= 1 ; --i) {
		sum[1][i] = sum[1][i + 1] + L - a[i];
	}
	int64 ans = max(L - a[1],a[N]);
	for(int i = 1 ; i <= N - 1; ++i) {
		int t = min(i,N - i);
		int64 res = 2 * (sum[0][i] - sum[0][i - t] + sum[1][i + 1] - sum[1][i + 1 + t]);
		int64 c = res - a[i];
		if(i > t) {c += 2 * a[i - t];}
		ans = max(ans,c);
		c = res - (L - a[i + 1]);
		if(N - i > t) c += 2 * (L - a[i + 1 + t]);
		ans = max(ans,c);
	}
	out(ans);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


Measured memory_bytes: 4992
# 2020/03/09
# AtCoder Beginner Contest 157 - B

# Input
al = list()
for i in range(3):
    il = list(map(int,input().split()))
    al.append(il)

n = int(input())

# Init
wl = [[0] * 3 for i in range(3)]
ans = "No"

# Input N
for x in range(n):
    b = int(input())
    for y in range(3):
        for z in range(3):
            if al[y][z] == b:
                wl[y][z] = 1
                y = 3
                break

# Check -
for y in range(3):
    cnt = 0
    for z in range(3):
        cnt = cnt + wl[y][z]
    if cnt >= 3:
        ans = "Yes"
        break

# Check |
for y in range(3):
    cnt = 0
    for z in range(3):
        cnt = cnt + wl[z][y]
    if cnt >= 3:
        ans = "Yes"
        break

# Check / or \
bs = wl[0][0] + wl[1][1] + wl[2][2]
sl = wl[2][0] + wl[1][1] + wl[0][2]

if bs >= 3 or sl >= 3:
    ans = "Yes"

# Output
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{
	int a, b;

	scanf("%d %d", &a, &b);

	if(a<b){

		printf("a < b\n");

	}else if(a>b){

		printf("a > b\n");

	}else{

		printf("a == b\n");

	}

	return 0;

}

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int a, b;

signed main()
{
    cin >> a >> b;

    if (b == 1)
    {
        cout << 0 << endl;
    }

    else
    {
        cout << ((b - 1) + (a - 2)) / (a - 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
s = list(input())
t = list(input())
n = len(s)
N = len(t)
a = 0
if n+1!=N:
    print("No")
else:
    for i in range(n):
        if s[i]!=t[i]:
            a+=1
    if a!=0:
        print("No")
    else:
        print("Yes")
        


Measured memory_bytes: 9052
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int L = sc.nextInt();
        int R = sc.nextInt();
        int d = sc.nextInt();

        int res = 0;
        for(int i = L; i <= R; i++) {
            if(i%d==0) res++;
        }
        System.out.println(res);
    }

}


Measured memory_bytes: 35604
int main()
{
	/* ??\?????¨ */
	int input;
	
	/* ????????¨ */
	int out[3];
	
	/* ????\???¨ */
	int in_count;
	int out_count;
	int temp;
	
	/* ????????? */
	input = 0;
	temp = 0;
	
	/* ??\????????? */
	for( in_count = 0; in_count < 3; in_count++ ){
		scanf( "%d", &input );
		out[in_count] = input;
	}
	
	/* ?????? */
	for( in_count = 0; in_count < 2; in_count++ ){
		for( out_count = 0; out_count < 2; out_count++ ){
			if( out[out_count + 1] < out[out_count] ){
				temp = out[out_count + 1];
				out[out_count + 1] = out[out_count];
				out[out_count] = temp;
			}
			else{
				/* ???????????? */
			}
			temp = 0;
		}
	}
	
	
	printf( "%d %d %d\n", out[0], out[1], out[2] );
	return 0;
	
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void){
  int N, i, *p;
  p = (int*)malloc(sizeof(int) * 10000);
  scanf("%d", &N);
  for(i=0; i<N; i++){
    scanf("%d", p+i);
  }
  int count = 0;
  for(i=0; i<N; i++){
    while(*(p+i) % 2 == 0){
      count++;
      *(p+i) /= 2;
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<math.h>
#include<stack>
#include<set>
#define INF 2147483647
#define n 300000
#define loop(i, a, b) for(int i=a; i<=b; i++)
#define mem(arr) memset(arr, 0, sizeof(arr));
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
struct edge{
	int to, weight;
};
void solve();
int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 1, times)
	{
		solve();
		cout << '\n';
	}
	return 0;
}
vector<edge> V[n + 50];
int a, b, c, d, e, f;
int arr[n + 50], arr1[n + 50], arr2[n + 50];
string str, str1, str2;

void solve()
{
	cin >> a;
	cout << a * a;
}


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


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * pow(10, len(S) - 1 - i, 2019)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

Measured memory_bytes: 81580
#include <iostream>
using namespace std;
int main()
{
    int N;
    long long A[31];
    while((cin >> N)&&(N > 0))
    {
        for(int i = 0; i <= N; i++)
        {
            if(i == 0)
            {
                A[i] = 1;
            }
            else if(i == 1)
            {
                A[i] = A[i-1];
            }
            else if(i == 2)
            {
                A[i] = A[i-1] + A[i-2];
            }
            else
            {
                A[i] = A[i-1] + A[i-2] + A[i-3];
            }
        }

        cout << (((A[N] + 9) / 10) + 364) / 365 << endl;

    }
    return 0;
}


Measured memory_bytes: 3080
#include<stdio.h>
#include<math.h>

typedef struct{double x,y
    ;}Point;

void koch(int,Point,Point);

int main(){
  Point a,b;
  int n;

  

  scanf("%d",&n);
  a.x=0;
  
  a.y=0;
  b.x=100;
  b.y=0;
  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0;
}



void koch(int n,Point a,Point b)
{
  if(n==0)return;
  Point s,t,u;
  double th = M_PI * 60.0/180.0;
  
  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}




Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,a[3010];
const double PI=acos((double)-1.0);
double xa,ya;ll sum;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n-1;i++)
	for(int j=i+1;j<=n;j++){
		xa+=cos(PI*(a[i]+a[j])/m)*(n-j-j+i+i);
		ya+=sin(PI*(a[i]+a[j])/m)*(n-j-j+i+i);
		sum+=(n-j);
	}
	printf("%.12f %.12f",xa/sum,ya/sum);
	return 0;
}


Measured memory_bytes: 256