akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long extgcd( long a)
{
  //拡張ユークリッドの互除法でaのmod b(prime)での逆元をもとめる
  long b = (long)1E9+7;
  long u, v, q, tmp; 
  long x = 1;
  long y = 0; u = 0; v = 1;
  while ( b > 0 ) {
	q = a / b; 
	tmp = u; u = x - q * u; x = tmp;
	tmp = v; v = y - q * v; y = tmp;
	tmp = b; b = a - q * b; a = tmp;
  }
  x %= (long int)1E9+7;
  while (x<0)
	x+=(long)1E9+7;
  return x;
}
long gcd(long a,long b)
{
 long r;
 if(a<b)
	swap(a,b);
  r = a % b;
  while(r!=0){
	a = b; b = r;
	r = a % b;
  }
  return b;
}

int ab[204][204];

int main(){
  	long  k;
	cin >> k;
  	for(int i = 1; i <= k; i++){
    	for(int j = 1; j <= k; j++) {
        	//for(int l = 1; l <= k; l++) {
            ab[i][j] = -1;	
            //}
        }
    }
	long long total=0;
  	for(int i = 1; i <= k; i++) {
      	for(int j = 1; j <= k; j++) {
   			if(ab[i][j] == -1) {
            	ab[i][j] = gcd(i,j); 
            }
          	for(int l = 1; l <= k; l++) {
            	if(ab[i][j] < 200 && ab[ab[i][j]][l] != -1) {
                	total += ab[ab[i][j]][l];  
                } else {
              		total += gcd(ab[i][j], l); 
                }
            }
        }
    }
  	
  	cout << total << endl;
}


Measured memory_bytes: 3780
import Control.Monad
import Control.Applicative

data Grade = A | B | C | D | F deriving(Show)

solver :: Int -> Int -> Int -> Grade
solver m f r =
  let s = m + f
  in
    if m == -1 || f == -1
      then F
    else if s >= 80
      then A
    else if s >= 65
      then B
    else if s >= 50
      then C
    else if s >= 30
      then if r >= 50 then C else D
    else
      F

main :: IO()
main = do
  (m:f:r:_) <- map (read :: String -> Int) . words <$> getLine
  unless (m == -1 && f == -1 && r == -1) $ do
    print $ solver m f r
    main

Measured memory_bytes: 3976
#include<bits/stdc++.h>
#define int long long 
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) (int)s.size()
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
const ll chotu =(ll)1e9+7;
const int N=(int)1e6;
int fact[N+1];
void f()
{
    fact[0]=1;
    for(int i=1;i<=N;i++)
    fact[i]=(i*fact[i-1])%chotu;
}
int numberInverse[N+1];
void inv()
{
    numberInverse[0]=1,numberInverse[1]=1;
    for(int i=2;i<=N;i++)
    numberInverse[i]=numberInverse[chotu%i]*(chotu-chotu/i)%chotu;
}
int factInverse[N+1];
void f_inv()
{
    factInverse[0]=1;
    factInverse[1]=1;
    for(int i=2;i<=N;i++)
    factInverse[i]=(numberInverse[i]*factInverse[i-1])%chotu;
}
int nCrmodp(int n,int r)
{
    return ((fact[n]*factInverse[n-r])%chotu*factInverse[r])%chotu;
}
void solve()
{
fastio
int n;
cin>>n;
ll ans=0;
for(int i=1;i<=(n/3);i++)
{ 
		int k=n-3*i;
		ans=(ans+nCrmodp(k+i-1,i-1))%chotu;
}
cout<<ans;
}
signed main()
{
//code
fastio
f();
inv();
f_inv();
int t;
t=1;
while(t--)
{
solve();
cout<<endl;
}
}


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

#define fi first
#define se second
#define ep emplace_back
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int a, b, c; cin >> a >> b >> c;
  int d = a;

  set<int> se;
  while (true) {
    int r = d % b;

    if (se.count(r)) {
      cout << "NO\n";
      return (0);
    }

    if (r == c) {
      cout << "YES\n";
      return (0);
    }

    se.emplace(r);
    d += a;
  }
  
  return (0);
}

Measured memory_bytes: 3620
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
def adjacency_list(N, edges):
    g = make_list(N, 0)
    for a, b in edges: g[a].append(b), g[b].append(a)
    return g
def tree_utils(start, g):
    parent, children, depth, q = [-1]*len(g), make_list(len(g), 0), [-1]*len(g), deque([start]); depth[start] = 0
    while q:
        i = q.popleft()
        for j in g[i]:
            if depth[j] != -1: parent[i] = j
            else: depth[j] = depth[i] + 1; children[i].append(j), q.append(j)
    return parent, children, depth
def graph_distance(start, g):
    dist, q = [-1] * len(g), deque([start]); dist[start] = 0
    while q:
        i = q.popleft()
        for j in g[i]:
            if dist[j] == -1: dist[j] = dist[i] + 1; q.append(j)
    return dist

sys.setrecursionlimit(1000000)
dire, dire8 = [[1, 0], [0, 1], [-1, 0], [0, -1]], [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets, ALPHABETS = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD, INF = 1000000007, float("inf")

def main():
    N, u, v = LI()
    AB = LIR1(N-1)
    max_dist = [None] * N
    g = adjacency_list(N, AB)
    udist = graph_distance(u-1, g)
    vdist = graph_distance(v-1, g)

    visit = [False] * N
    ans = vdist[u-1] - 1
    q = deque([u-1])
    while q:
        i = q.popleft()
        visit[i] = True
        if udist[i] < vdist[i]:
            ans = max(ans, vdist[i]-1)
            for j in g[i]:
                if not visit[j]:
                    q.append(j)

    print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;

const int max_n = 1000111, mod = 1000000007;

int mul(int x, int y) {
    return (1LL * x * y) % mod;
}

int power(int a, int b) {
    if (b == 0) {
        return 1 % mod;
    }
    if (b % 2 == 0) {
        return power(mul(a, a), b / 2);
    }
    return mul(a, power(a, b - 1));
}

int inv(int x) {
    return power(x, mod - 2);
}

const int max_f = 2 * max_n;

int f[max_f], rf[max_f];

void get_all_f() {
    f[0] = rf[0] = 1;
    for (int i = 1; i < max_f; ++i) {
        f[i] = mul(i, f[i - 1]);
    }
    rf[max_f - 1] = inv(f[max_f - 1]);
    for (int i = max_f - 2; i > 0; --i) {
        rf[i] = mul(i + 1, rf[i + 1]);
    }
}

int get_c(int n, int k) {
    if (n < k) {
        return 0;
    }
    return mul(f[n], mul(rf[k], rf[n - k]));
}

int n, h, d, dp[max_n], sum[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    get_all_f();
    cin >> n >> h >> d;
    int k = f[n];
    int k2 = 0;
    for (int i = 1; i <= n; ++i) {
        k2 = (k2 + f[i]) % mod;
    }
    sum[0] = dp[0] = power(k2, mod - 2);
    for (int i = 1; i <= h; ++i) {
        dp[i] = sum[i - 1] + mod;
        if (i - d - 1 >= 0) {
            dp[i] -= sum[i - d - 1];
        }
        dp[i] = mul(dp[i], k2);
        sum[i] = (sum[i - 1] + dp[i]) % mod;
    }
    cout << mul(k, dp[h]) << endl;
    return 0;
}


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

// ------ disjoint set ------ //
template<class CommutativeMonoid> struct UnionFind {
    using M = CommutativeMonoid;
    using T = typename M::value_type;
    vector<int> data; vector<T> val;
    int __size;
    UnionFind(int size) : data(size, -1), val(size, M::id()), __size(size) { }
    template<class InputIterator>
    UnionFind(int size, InputIterator first, InputIterator last)
        : data(size, -1), val(first, last), __size(size) { }
    bool unionSet(int x, int y, int w) {
        if ((x = root(x)) != (y = root(y))) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x; __size--;
            val[x] = M::op(M::op(val[x], val[y]), w);
        }
        return x != y;
    }
    T getVal(int x) { return val[root(x)]; }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return __size; }
};

template <typename T>
struct SumMonoid {
    using value_type = T;
    static constexpr T id() { return 0; }
    static T op(const T &a, const T &b) { return a + b; }
};

int main() {
    int N, K;
    string s;
    cin >> N >> K >> s;
    vector<int> v;
    if (s[0] == '0') v.emplace_back(0);     // 1
    int color = -1;
    int len = 1;
    for (int i = 0; i < s.length(); i++) {
        if (color == s[i] - '0') {
            len++;
        } else if (i) {
            v.emplace_back(len);
            len = 1;
            color = s[i] - '0';
        } else {
            color = s[i] - '0';
        }
    }
    v.emplace_back(len);
    if (s[N - 1] == '0') v.emplace_back(0); // 1
    N = v.size();
    int Len = 2 * K + 1;
    if (N <= Len) {
        int sum = 0;
        for (int& vi : v) sum += vi;
        cout << sum << endl;
        return 0;
    }
    vector<int> acc(N + 1, 0);
    for (int i = 0; i < N; i++) acc[i + 1] = acc[i] + v[i];
    int ma = 0;
    for (int l = 0; l < N; l += 2) {
        int r = l + Len;
        if (r >= N + 1) break;
        ma = max(ma, acc[r] - acc[l]);
    }
    cout << ma << endl;
    /*
    vector<int> one;
    vector<pair<int, pair<int, int>>> zero;
    int cnt = 0;
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it->first == 0) {
            zero.emplace_back(it->second, make_pair(cnt, cnt + 1));
        } else {
            one.emplace_back(it->second);
            cnt++;
        }
    }
    UnionFind<SumMonoid<int>> uf(one.size(), one.begin(), one.end());
    sort(zero.begin(), zero.end());
    reverse(zero.begin(), zero.end());
    for (int i = 0; i < K; i++) {
        pair<int, pair<int, int>> cur = zero[i];
        int len = cur.first;
        pair<int, int> ids = cur.second;
        uf.unionSet(ids.first, ids.second, len);
    }
    int ma = 0;
    for (int i = 0; i < one.size(); i++) {
        ma = max(ma, uf.getVal(i));
    }
    cout << ma << endl;
    */
    return 0;
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int n, m, s, t;
int u[110000], v[110000], a[110000], b[110000];

//ダイクストラ法を用いて単一始点最短路問題を解く
const int MAX_V = 110000;
const int INF = 1e15;

struct edge {
    int to, cost;
};

void dijkstra(int s, vector<edge> G[MAX_V], int d[MAX_V]) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + n + 10, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

vector<edge> G1[MAX_V], G2[MAX_V];
int d1[MAX_V], d2[MAX_V];
int ans[MAX_V];

signed main() {
    cin >> n >> m >> s >> t;
    for (int i = 0; i < m; i++) {
        cin >> u[i] >> v[i] >> a[i] >> b[i];
    }
    for (int i = 0; i < m; i++) {
        G1[u[i]].push_back({v[i], a[i]});
        G1[v[i]].push_back({u[i], a[i]});
        G2[u[i]].push_back({v[i], b[i]});
        G2[v[i]].push_back({u[i], b[i]});
    }
    dijkstra(s, G1, d1);
    dijkstra(t, G2, d2);
    for (int i = n; i >= 1; i--) {
        int cur = 1e15 - d1[i] - d2[i];
        ans[i] = max(ans[i + 1], cur);
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 22980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;


int main(){
  int N;
  cin >> N;
  int x = N % 10;
  if(x == 3){
    cout << "bon" << endl;
  }
  else if(x == 0 || x == 1 || x == 6 || x == 8){
    cout << "pon" << endl;
  }
  else{
    cout << "hon" << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
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(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       
         public static long GCM(long x,long y)
        {
            if (x < y)  GCM(y, x);


            while (y > 0)
            {
                var z = y;
                y = x % y;
                x = z;
            }
            
            return x;
        }

        



        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var nm = Reads();
            long[] a = new long[nm[0]], b =new long[nm[0]], c =new long[nm[1]], d =new long[nm[1]];
            for (int i = 0; i < nm[0]; i++)
            {
                var ab = Reads();
                a[i] = ab[0];
                b[i] = ab[1];
            }
            for (int i = 0; i < nm[1]; i++)
            {
                var cd = Reads();
                c[i] = cd[0];
                d[i] = cd[1];
            }

            var ans = new long[nm[0]];
            for (int i = 0; i < nm[0]; i++)
            {
                long min =long.MaxValue;
                for (int j = 0; j < nm[1]; j++)
                {
                    if (min > Math.Abs(a[i] - c[j]) + Math.Abs(b[i] - d[j]))
                    {
                        min = Math.Abs(a[i] - c[j]) + Math.Abs(b[i] - d[j]);
                        ans[i] = j + 1;
                    }
                }
            }
            for (int i = 0; i <nm[0] ; i++)
            {
                WriteLine(ans[i]);
            }






            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 13396
import operator

a, b, c, d = [int(s) for s in input()]

operators = {"+": operator.add, "-": operator.sub}

for ope_key1, ope1 in operators.items():
    for ope_key2, ope2 in operators.items():
        for ope_key3, ope3 in operators.items():
            if ope3(ope2(ope1(a, b), c), d) == 7:
                print("{0}{1}{2}{3}{4}{5}{6}=7".format(a, ope_key1, b, ope_key2, c, ope_key3, d))
                break
        else:
            continue
        break
    else:
        continue
    break



Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>

using namespace std;

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

int main(void) {
	int num, k, i, g, ma, a;
	cin >> num >> k >> g;
	ma = g;
	for (i = 0; i < num - 1; i++) {
		scanf("%d", &a);
		g = gcd(a, g);
		ma = max(ma, a);
	}
	if (k > ma || k % g != 0)
		printf("IMPOSSIBLE\n");
	else
		printf("POSSIBLE\n");
	return 0;
}

Measured memory_bytes: 256
i=3;main(n,j){scanf("%d",&n);for(;j=n-i,j+=j&1,n>3&j<1|5000<j;i+=3);for(i=n-j;i;printf(n<4?i=0,"2 3 25":"%d ",2*i--))for(;j;printf("%d ",6*j---3));}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<functional>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vvi x(n + 1, vi(n + 2, 0));
  rep(i, 0, m) {
    int l, r;
    cin >> l >> r;
    erep(j, 1, l) {
      x[j][r]++;
      x[j][n + 1]++;
    }
  }
  erep(i, 1, n) {
    erep(j, 1, n + 1) {
      x[i][j] += x[i][j - 1];
    }
  }
  rep(i, 0, q) {
    int p, q;
    cin >> p >> q;
    cout << x[p][q] << endl;
  }
}


Measured memory_bytes: 1920
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
  int a = rint;
  int b = rint;
  int c = rint;
  
  int d = (b + c) - a;
  if(d >= 0) d.writeln;
  else 0.writeln;
}

Measured memory_bytes: 256
#include<stdio.h>
void max(int size, int *array, int *x, int *y){
    int i, j;
    for(i = 0; i < size; i++){
        for(j = 0; j < 2; j++){
            if(array[i] > x[j]){
                x[j] = array[i];
                y[j] = i;
                j++;
            }
        }
    }
}

int main(){
    int a, i, x[2], y[2];
    for(i = 0; i < 2; i++){
        x[i] = 0;
    }
    scanf("%d", &a);
    int b[a];
    for(i = 0; i < a; i++){
        scanf("%d", &b[i]);
    }
    puts("");

    max(a, b, x, y);

    for(i = 0; i < a; i++){
        i != y[0] ? printf("%d\n", x[0]) : printf("%d\n", x[1]);
    }

}


Measured memory_bytes: 2304
import math

def dig(x,d):
  return (x%(10**(d+1)))//(10**d)

def main():
  N=int(input())
  D=3#int(math.log10(N))
  ans=0
  s=['']*D
  for bits in range(2*N):
    ans=dig(N,D)
    for i in range(1,D+1):
      if (bits>>(D-i))&1:
        ans+=dig(N,D-i)
        s[i-1]='+'
      else:
        ans-=dig(N,D-i)
        s[i-1]='-'
    if ans==7:
      print(dig(N,3),end="")
      for i in range(3):
        print(s[i],end="")
        print(dig(N,2-i),end="")
      print('=7')
      return
main()

Measured memory_bytes: 38384
#include"bits/stdc++.h"

using namespace std;

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

	if (X < Y) {
		cout << "<";
	}
	else if (X == Y) {
		cout << "=";
	}
	else {
		cout << ">";
	}

	cout << endl;

	return 0;

}

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

int n, m, q;
vector<string> s;
vector<vector<int>> node, edgel, edgeu;

int calc(int l, int r, int u, int d, vector<vector<int>> &v);

int main() {
  cin >> n >> m >> q;
  s.resize(n);
  node.assign(n + 1, vector<int>(m + 1, 0));
  edgel.assign(n + 1, vector<int>(m + 1, 0));
  edgeu.assign(n + 1, vector<int>(m + 1, 0));
  auto calcsum = [](vector<vector<int>> &v) {
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j)
        v[i + 1][j + 1] += v[i + 1][j] + v[i][j + 1] - v[i][j];
  };
  for (auto &t : s) cin >> t;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      node[i + 1][j + 1] = s[i][j] - '0';
      if (j != 0 && s[i][j] == '1' && s[i][j] == s[i][j - 1])
        ++edgel[i + 1][j + 1];
      if (i != 0 && s[i][j] == '1' && s[i][j] == s[i - 1][j])
        ++edgeu[i + 1][j + 1];
    }
  calcsum(node);
  calcsum(edgel);
  calcsum(edgeu);
  for (int i = 0; i < q; ++i) {
    int u, l, d, r;
    cin >> u >> l >> d >> r;
    cout << calc(l, r, u, d, node) - calc(l + 1, r, u, d, edgel) -
                calc(l, r, u + 1, d, edgeu)
         << endl;
  }
  return 0;
}

int calc(int l, int r, int u, int d, vector<vector<int>> &v) {
  --l, --u;
  return v[d][r] - v[u][r] - v[d][l] + v[u][l];
}

Measured memory_bytes: 58256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
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);
    int n, m;
    cin >> n >> m;
    if (n==m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#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

int64 modpow(int64 a, int64 r){
    if(r == 0)return 1;
    if(r % 2 == 0){
        int64 x = modpow(a, r / 2);
        return x * x % MOD;
    }else{
        return modpow(a, r - 1) * a % MOD;
    }
}

int64 comb(int64 n, int64 r){
    r = min(r, n - r);
    int64 retval = 1;
    REP(i,r){
        retval *= (n - i);
        retval %= MOD;
        retval *= modpow(i+1, MOD - 2);
        retval %= MOD;
    }
    return retval;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 n,k;
    cin >> n >> k;
    FOR(i,1,k+1){
        if(i > n - k + 1){
            ANS(0);
        }else{
            ANS(comb(k-1, i-1) * comb(n-k+1, i) % MOD);
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    long long N, M, L;
    cin >> N >> M >> L;
    vector<vector<long long>> road(N, vector<long long>(N,MOD*MOD));
    for(int i=0; i<M; i++){
        int A,B;
        long long C;
        cin >> A >> B >> C;
        A--;B--;
        if(C>L)continue;
        road[A][B]=road[B][A]=C;
    }

    priority_queue<pair<long long, pair<long long, long long>>> p_que;
    vector<vector<long long>> map_(N,vector<long long>(N, MOD*MOD));
    vector<vector<long long>> fuel_map(N,vector<long long>(N, 0));

    for(int i=0; i<N; i++){
        p_que.push(make_pair(0, make_pair(L, i)));
        map_[i][i]=0;
        while((int) p_que.size()>0){
            pair<long long, pair<long long, long long>> tmp=p_que.top();
            p_que.pop();
            for(int j=0; j<N; j++){
                long long cost = tmp.first;
                long long fuel = tmp.second.first;
                long long place = tmp.second.second;

                long long next_cost=road[place][j];
                if(next_cost==MOD*MOD)continue;
                if(fuel<next_cost){
                    fuel=L;
                    cost--;
                }
                fuel-=next_cost;
                
                if(-cost < map_[i][j]){
                    map_[i][j]=-cost;
                    fuel_map[i][j]=fuel;
                }else if(-cost == map_[i][j] && fuel>fuel_map[i][j]){
                    fuel_map[i][j]=fuel;
                }else{
                    continue;
                }
                p_que.push(make_pair(cost, make_pair(fuel, j)));
            }
        }
    }

    int Q;
    cin >> Q;
    for(int i=0; i<Q; i++){
        int s, t;
        cin >> s >> t;
        s--;t--;
        if(map_[s][t]==MOD*MOD){
            cout << -1 << endl;
        }else{
            cout << map_[s][t] << endl;
        }
    }
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#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++)
#define all(obj) obj.begin(), obj.end()
#define debug(x) cerr << #x << ":" << x " "
#define debugln(x) cerr << #x << ":" << x << "\n"
#define vdebug(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define vvdebug(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
	int N, K; cin >> N >> K;
	vi x(N); rep(i, N) cin >> x.at(i);
	int ans = 0;
	rep(i, N) ans += 2 * min(x.at(i), K - x.at(i));
	cout << ans << endl;
}

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

string s;
int main()
{
  
  cin >> s;
  string rs = "";
  rep(i, s.size()) {
    rs += s[i];
  }
  string a = "";
  string ra = "";
  string b = "";
  string rb = "";
  rep(i, (s.size() -1)/2) {
    a += s[i];
    ra += s[i];
  }
  for(int i = (s.size() + 3)/2 - 1; i < s.size(); i++) {
    b += s[i];
    rb += s[i];
  }
  reverse(ra.begin(), ra.end());
  reverse(rb.begin(), rb.end());
  reverse(rs.begin(), rs.end());
  if (a == ra && b == rb && s == rs) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  
  return 0;
}

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

int main()
{
    int n,m;
    cin >> n >> m;
    cout << (n==m ? "Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 256
//                          VIVEK UPADHYAY
//                          MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
//                        $$ JAB-TAK TODEGA NHI,
//                           TAB -TAK CHODEGA NHI :D

// g++ -std=c++11 file_name.cpp
// ./file_name.out
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<"\n" ;
#define ok cout<<"ok\n" ;
#define dbg(x) cout<<#x<<" = "<<(x)<<"\n";
#define fill(A, VAL) memset(A, VAL, sizeof(A))
#define sz(a) ((int) a.size())
typedef long long ll ;
const int MAXN = 5*1e5 + 10;

ll mod = 998244353 ;
int main () {
    
    string s ;
    cin >> s ;
    int f = (s[0] - '0')*10 + (s[1] - '0') ;
    int t = (s[2] - '0')*10 + (s[3] - '0') ;
    //cout<<f<<" "<<t<<endl ;
    if(t==0 && f >=1 && f <=12) {cout<<"MMYY\n" ; return 0 ;
    }
    if(f==0 && t >=1 && t <= 12) {
        cout<<"YYMM\n" ;
        return 0 ;
    }
    
    if(t >= 1 && t <= 12 && f >= 1 && f <= 12)
        cout<<"AMBIGUOUS\n" ;
    else if(t == 0 || f == 0)
        cout<<"NA\n" ;
    else if( t > 12 && f > 12) cout<<"NA\n" ;
    else if(t >= 1 && t <= 12) cout<<"YYMM\n" ;
    else cout<<"MMYY\n" ;
    return 0 ;
}


Measured memory_bytes: 256
N=int(input())
A=[int(input()) for _ in range(N)]

tmp=sorted(A)[::-1]
if tmp[0]==tmp[1]:
    for _ in range(N):
        print(tmp[0])
else:
    for i in range(N):
        if A[i]==tmp[0]:
            print(tmp[1])
        else:
            print(tmp[0])

Measured memory_bytes: 14136
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int total = 0;
 for(int i = 0; i < 3;i++) {
	   total  = total + Integer.parseInt(sc.next());
 }
if(total <= 21) {
	System.out.println("win");
}else {
	System.out.println("bust");
}
        
        
       
        }
 
     
    }

Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int N;
	int p[50];
	int changeCount = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}

	for (int i = 0; i < N-1; i++) {
		for (int j = i + 1; j < N; j++) {
			if (changeCount > 1) {
				cout << "NO" << endl;
				return 0;
			}
			int &min = *min_element(&p[j], &p[N]);

			if (p[i] > min) {
				swap(p[i], min);
				changeCount++;
			}
			
		}
		
	}
		cout << "YES" << endl;
		return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int r, g, b, n; cin >> r >> g >> b >> n;
	int cnt = 0;
	for (int i = 0; i <= n / r; ++i) {
		for (int j = 0; j <= (n - i * r) / g; ++j) {
			if ((n - (i * r + j * g)) % b == 0)cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

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

using namespace std;

int main(){
  int A = 0, B = 0;
  cin >> A >> B;
  
  int count = 0;
  
  for(int i = A; i <= B; i++){
    string i_str = to_string(i);
    if(i_str[0] == i_str[4] && i_str[1] == i_str[3]){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

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

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

    int n, k;
    string s;
    cin >> n >> k >> s;
    int cnt = 0;
    vector<P> table;
    bool one;
    if(s[0] == '1') one = true;
    else    one = false;
    for(int i = 0; i < n; ++i){
        if(s[i] == '1'){
            if(one) ++cnt;
            else{
                table.emplace_back(0, cnt);
                cnt = 1;
                one = true;
            }
        }
        else{
            if(!one)    ++cnt;
            else{
                table.emplace_back(1, cnt);
                cnt = 1;
                one = false;
            }
        }
    }
    table.emplace_back(one, cnt);
    int sz = table.size();
    int ans = 0;
    int sum = 0;
    deque<P> deq;
    for(auto p : table){
        if(p.first == 1){
            sum += p.second;
            deq.push_back(p);
        }
        else{
            if(--k >= 0){
                sum += p.second;
                deq.push_back(p);
            }
            else{
                while(!deq.empty()){
                    P foo = deq.front();
                    deq.pop_front();
                    sum -= foo.second;
                    if(foo.first == 0){
                        k = 0;
                        break;
                    }
                }
                sum += p.second;
                deq.push_back(p);
            }
        }
        chmax(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1604
#include <cstdio>
#include <iostream>

using namespace std;

int n;

int head[200010], to[400010], nxt[400010], cnt;

inline void AddEdge (int u, int v) { ++cnt, to[cnt] = v, nxt[cnt] = head[u], head[u] = cnt; }

int mxu = 1, mxl;

inline void Dfs (int u, int p, int dis) {
	if (dis > mxl) mxl = dis, mxu = u;
	for (int e = head[u]; e; e = nxt[e]) {
		int v = to[e];
		if (v == p) continue;
		Dfs (v, u, dis + 1);
	}
}

int main () {
	scanf ("%d", &n);
	for (int i = 1; i < n; ++i) {
		int u, v; scanf ("%d%d", &u, &v);
		AddEdge (u, v), AddEdge (v, u);
	}
	
	Dfs (1, 0, 0);
	
	mxl = 0, Dfs (mxu, 0, 0);
	
	if (mxl % 3 == 1) printf ("Second\n");
	else printf ("First\n");
	
	return 0;
}

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

    int A[2500],B[2500];
    bool flag[2500];
    int order;
    int edge;

void isBridge(int vex){
    // cout<<k<<" :";
    if(flag[vex]==false)return;//来たことある
    // cout<<vex<<":";
    flag[vex]=false;
    for(int e=0;e<edge;e++){
        if(A[e]==vex){isBridge(B[e]);}
        if(B[e]==vex){isBridge(A[e]);}
    }
}

int main(){

    cin>>order>>edge;

    int ans=0;
    for(int e=0;e<edge;e++){
        cin>>A[e]>>B[e];
        A[e]--;
        B[e]--;
    }

    for(int e=0;e<edge;e++){
        int delA=A[e];
        A[e]=-1;
        int delB=B[e];
        B[e]=-1;
        
        //フラグ立て
        for(int vex=0;vex<order;vex++){
            flag[vex]=true;
        }
        
        //フラグ折り
        isBridge(0);
        //cout<<endl;
        //フラグ残りがあるか
        bool tmp=false;
        for(int vex=0;vex<order;vex++){
            if(flag[vex]==true){
                ans++;
                break;
            }
        }
        

        A[e]=delA;
        B[e]=delB;
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  divisors.append(n)
  return divisors
n,x=map(int,input().split())
y=list(map(int,input().split()))
y.append(x)
y.sort()
z=[]
for i in range(n):
  z.append(y[i+1]-y[i])
z.sort()
p=make_divisors(z[0])
a=[]
for i in p:
  for j in z:
    if j%i:
      break
  else:
    a.append(i)
print(max(a))

Measured memory_bytes: 63640
#include <cstdio>

int main() {
  int A, B, C;
  scanf("%d %d %d", &A, &B, &C);

  if (A == 5 && B == 5 && C == 7) {
    puts("YES");
  } else if (A == 5 && B == 7 && C == 5) {
    puts("YES");
  } else if (A == 7 && B == 5 && C == 5) {
    puts("YES");
  } else {
    puts("NO");
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

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

    int a,b,c;
    cin >> a >> b >> c;
    cout << a*b/2 << endl;
    return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"

#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<ll, ll> LP;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


ll N,ac=0,wa=0,tle=0,re=0;
int main() {
	cin >> N;

	REP(i, N) {
		string tmp;
		cin >> tmp;
		if (tmp == "AC") {
			ac++;
		}
		if (tmp == "TLE") {
			tle++;
		}
		if (tmp == "WA") {
			wa++;
		}
		if (tmp == "RE") {
			re++;
		}
	}

	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;

	cout << "TLE x " << tle << endl;

	cout << "RE x " << re << endl;

	return 0;

}

Measured memory_bytes: 3624
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


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


def MF(): return map(float,input().split())


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


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')


def main():
	n,k=MI()
	m=10**9+7
	
	ans=0
	
	for i in range(n-k+2):
		ans+=n*(n+1)//2-i*(i-1)//2-(n-i)*(n-i+1)//2+1
		#print(n*(n+1)//2-i*(i-1)//2,(n-i)*(n-i+1)//2)
		ans%=m
		#print(ans)
	print(ans)
	
	
	
	

if __name__=="__main__":
	main()


Measured memory_bytes: 63696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, D, X;

int main(void){
    
    scanf("%d %d %d", &N, &D, &X);
    int cnt = 0;
    for(int i = 0; i < N; ++i){
        int A; scanf("%d", &A);
        for(int i = 0; i * A + 1 <= D; ++i) ++cnt;
    }
    printf("%d\n", cnt + X);
    
    return 0;
}


Measured memory_bytes: 256
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define EPS (1e-7)
#define IINF ((int)1e9)


MY_NAMESPACE(testbed)
ll modpow(ll base, ll exponent, ll mod)
{
	ll retval = 1;
	while (exponent > 0)
	{
		if (exponent % 2)
			retval = (retval * base) % mod;
		exponent /= 2;
		base = (base * base) % mod;
	}
	return retval;
}

class ModComb
{
public:
	ModComb(int max_n, ll mod) : m_mod(mod)  // mod and any i (1<i<=max_n) must be mutually prime. in reality mod must be a prime number and mod>max_n
	{
		m_fac.resize(max_n + 1);
		m_inv.resize(max_n + 1);
		m_fin.resize(max_n + 1);
		m_fac[0] = 1;
		m_fac[1] = 1;
		m_inv[0] = 0;  // dummy
		m_inv[1] = 1;
		m_fin[0] = 1;
		m_fin[1] = 1;
		for (int i = 2; i <= max_n; i++)
		{
			m_fac[i] = m_fac[i - 1] * i % mod;
			m_inv[i] = mod - m_inv[mod % i] * (mod / i) % mod;
			m_fin[i] = m_fin[i - 1] * m_inv[i] % mod;
		}
	}

	ll v(int n, int k)
	{
		if (n < 0 || k < 0)
			return 0;
		if (n < k)
			return 0;
		return m_fac[n] * (m_fin[k] * m_fin[n - k] % m_mod) % m_mod;
	}

private:
	ll m_mod;
	vector<ll> m_fac;  // factorial
	vector<ll> m_inv;  // inverse element
	vector<ll> m_fin;  // factorial of inverse
};

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

	ll const modval = 998244353;

	int n, m, k;
	cin >> n >> m >> k;

	ModComb modcomb(n, modval);

	ll res = 0;
	for (int this_k = 0; this_k <= k; this_k++)
	{
		ll this_res = modcomb.v(n - 1, this_k);
		this_res = this_res * m % modval;
		this_res = this_res * modpow((ll)m - 1, (ll)n - 1 - (ll)this_k, modval) % modval;
		res = (res + this_res) % modval;
	}
	cout << res << "\n";
	return 0;
}
MY_NAMESPACE_

Measured memory_bytes: 7940
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
const int max_n = 200000;
long long cnt[111];
long long m,n,a,b;
const int INF = 1e8;
const int mod = 1e9 + 7;
long dist[max_n];
vector<vector<int> > G;
bool isprime(long long xx){
    if(xx == 2) return true;
    if(xx % 2==0 || xx<2)    return false;
    long long ii = 3;
    while(ii*ii <= xx){
        if(xx %ii == 0) return false;
        ii += 2;
    }
    return true;
}
long long gcd(long long xx, long long yy){
    if(yy == 0) return xx;
    long long k = xx/yy;
    long long c = xx - k*yy;
    return gcd(yy, c);
}
void solve(){
}
int main(){
    cin >> n;
    long long maxv = -1e9-1;
    long long minv;
    cin >> minv;
    for(int i=1 ; i<n ; i++){
        long long x;
        cin >> x;
        maxv = max(maxv, x-minv);
        minv = min(x, minv);
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3120
h,w = gets.chomp.split(" ").map(&:to_i)
s = h.times.map{"."+gets.chomp+"."}.unshift("."*(w+2)).push("."*(w+2))
disp =[[1,0],[-1,0],[0,1],[0,-1]]
for i in 1..h
  for j in 1..w
    if s[i][j] == "#"
      temp = 0
      disp.each do |k,l|
        if s[i+k][j+l] == "#"
          temp += 1
        end
      end
      if temp == 0
        puts "No"
        exit
      end
    end
  end
end
puts "Yes"

Measured memory_bytes: 1788
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <ctype.h>
const int bufSize = 1e6;
#define DEBUG
inline char nc()
{
    #ifdef DEBUG
    return getchar();
    #endif
    static char buf[bufSize], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2) ? EOF : *p1++;
}
inline void read(char *s)
{
    static char c;
    for (; !isalpha(c); c = nc());
    for (; isalpha(c); c = nc()) *s++ = c;
    *s = '\0';
}
template<typename T>
inline T read(T &r)
{
    static char c;
    static int flag;
    flag = 1, r = 0;
    for (c = nc(); !isdigit(c); c = nc()) if (c == '-') flag = -1;
    for (; isdigit(c); c = nc()) r = r * 10 + c - 48;
    return r *= flag;
}
const int maxn = 19;
int n;
int X[maxn],Y[maxn],P[maxn];
long long xdis[maxn][maxn],ydis[maxn][maxn];
long long xval[maxn][1<<maxn],yval[maxn][1<<maxn];
long long ans[maxn];
int id[maxn];
template<typename T>
inline T abs(const T &x) {return x > 0 ? x : -x;}
int main()
{
    read(n);
    for (int i = 0; i < n; ++i) read(X[i]), read(Y[i]), read(P[i]);
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) xdis[i][j] = abs(X[i] - X[j]), ydis[i][j] = abs(Y[i] - Y[j]);
    for (int i = 0; i <= n; ++i) ans[i] = 1ll << 62;
    int maxx = (1 << n) - 1;
    for (int i = 0; i <= maxx; ++i)
        for (int j = 0; j < n; ++j)
        {
            xval[j][i] = abs(X[j]), yval[j][i] = abs(Y[j]);
            for (int k = 0; k < n; ++k) if (i & (1 << k))  xval[j][i] = std::min(xval[j][i], xdis[k][j]), yval[j][i] = std::min(yval[j][i], ydis[k][j]);
            xval[j][i] *= P[j],yval[j][i] *= P[j];
        }
    for (int i = 0; i <= maxx; ++i)
    {
        int num = 0;
        for (int j = i; j > 0; j >>= 1) num += j & 1;
        for (int j = i; j >= 0; --j)
        {
            j &= i;
            long long tans = 0;
            for (int k = 0; k < n; ++k) if (!((1 << k) & i)) tans += std::min(xval[k][j],yval[k][(~j) & i]);
            ans[num] = std::min(ans[num], tans);
        }
    }
    for (int i = 0; i <= n; ++i) printf("%lld\n", ans[i]);
    return 0;
}



Measured memory_bytes: 9408
S = input()
cnt = 1
for s in S:
  if cnt%2== 1:
    if s in ["R","U","D"]:
      cnt += 1
    else:
      print('No')
      break
  elif cnt%2==0:
    if s in ["L","U","D"]:
      cnt += 1
    else:
      print('No')
      break
else:
  print('Yes')
    
    

Measured memory_bytes: 2940
N = int(input())
A = list(map(int, input().split()))
ans = [0] * N
su = sum(A)
for i in range(1, N, 2):
  su -= A[i] * 2
ans[0] = su
for i in range(N - 1):
  ans[i + 1] = (A[i] * 2) - ans[i]

print(" ".join(list(map(str, ans))))


Measured memory_bytes: 75236
#include<iostream>
#include<algorithm>

using namespace std;

int const N = 1e5 + 41;

int a[N], n, k;
long long pref[N], suf[N], prefP[N], sufP[N], dp[N][2], ans;

void solve(){
	for(int i=1;i<=n;++i){
		pref[i] = pref[i-1] + a[i];
		suf[n-i+1] = suf[n-i+2] + a[n-i+1];
		prefP[i] = prefP[i-1] + max(0, a[i]);
		sufP[n-i+1] = sufP[n-i+2] + max(0, a[n-i+1]); 
	}

	for(int i=k;i<=n;++i){
		ans = max(ans, prefP[i-k] + sufP[i+1] + max(0LL, pref[i] - pref[i-k]));
	}
	for(int i=1;i<=n-k+1;++i){
		dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
		dp[i][1] = a[i] + max(dp[i-1][0], dp[i-1][1]);
	}
	dp[n-k+1][1] += (pref[n] - pref[n-k+1]);
	ans = max(ans, max(dp[n-k+1][0], dp[n-k+1][1]));
	printf("%lld\n",ans);
}

void read(){
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
}

void prepare(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
}

int main(){
	prepare();
	read();
	solve();



	return 0;
}

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

using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    vector<long long int> P(M),Y(M);
    vector<vector<long long int>> ken(N+1);

    for(int i=0;i<M;i++){
        cin >> P[i] >> Y[i];
        ken[P[i]].push_back(Y[i]);
    }

    for(int i=0;i<=N;i++){
        sort(ken[i].begin(),ken[i].end());
    }

    for(int i=0;i<M;i++){
        int result = lower_bound(ken[P[i]].begin(),ken[P[i]].end(),Y[i]) - ken[P[i]].begin();
        cout << setfill('0') << right << setw(6) << P[i];
        cout << setfill('0') << right << setw(6) << result+1 << endl;
    }
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const ll oo = 1e15 + 7;
const ll mod = 1e9 + 7, maxn = (1 * 1e3) + 10;
const long double PI = acos(-1);

ll fexp(ll a, ll b,  ll m){
    ll ans = 1;
    if (m == 1) return 0;

    while (b){
        if (b&1) ans = (ans * a) % m;
        a = (a * a) % m;
        b = (b >> 1);
    }

    return ans;
}

ll f(ll num){
    ll ans = 0;
    while (num) {
        ll b = __builtin_popcount(num);
        num = num%b, ans++;
    }
    return ans;
}

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    ll cnt = 0, n, l = 0, r = 0;
    cin >> n;
    cin >> s;

    for (int i=0; i<n; i++) {
        cnt += ll(s[i] - '0');
    }

    for (int i=n-1; i>=0; i--){
        if (s[i] == '1'){
            if (cnt > 1) l = (l + fexp(2, n-i-1, cnt-1)) % (cnt - 1);
            r = (r + fexp(2, n-i-1, cnt+1)) % (cnt + 1);
        }
    }
    for (int i=0; i<n; i++){
        if (s[i] == '1'){
            if (cnt > 1) {
                ll nval = (l - fexp(2, n-i-1, cnt-1) + 2*(cnt - 1)) % (cnt - 1);
                cout << f(nval)+1 << endl;
            }
            else cout << 0 << endl;
        }
        else {
            ll nval = (r + fexp(2, n-i-1, cnt+1) + (cnt+1)) % (cnt+1);
            cout << f(nval)+1 << endl;
        }
    }


    return 0;
}

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

int main(){
  int N;
  string s;
  cin >> N;
  for(int i;;i++){
    cin >> s;
    if(s == "Y"){
      cout << "Four";
      break;
    }else if(i == N-1){
      cout << "Three";
      break;
    }
  }
}

Measured memory_bytes: 256