akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
 
int main()
{
  int a, b, c, k;
  cin >> a >> b >> c >> k;
 
  if (a < b && b < c) {
    cout << "Yes" << endl;
    return 0;
  }
  for (int i=0; i<k; ++i){
    if (a >= b) {
      b *= 2;
    }
    else if (b >= c) {
      c *= 2;
    }
    
  if (a < b && b < c) {
    cout << "Yes" << endl;
    return 0;
  }
  }

    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100010;
int n,a[MAXN];
ll sum[MAXN];
int f[MAXN];
int getloc(ll num){
	int l=1,r=n;
	int ans=0;
	while(l<=r){
		int mid=(l+r)>>1;
		if(a[mid]<=num){
			l=mid+1;
			ans=mid;
		}else{
			r=mid-1;
		}
	}
	return ans;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+a[i];
	for(int i=1;i<=n;i++)
		f[i]=i;
	for(int i=n;i>=1;i--){
		f[i]=max(f[i],f[getloc(sum[i]<<1)]);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		int tmp = f[getloc(sum[i]<<1)];
		ans += (tmp==n);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1792
#include<stdlib.h>
#define ll long long
int up(const void*a,const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
ll a[2<<17],b[2<<17];i,n;
main(){
scanf("%d",&n);
for(i=0;i<n;i++)scanf("%lld%lld",a+i,b+i);
qsort(a,n,sizeof(ll),up);qsort(b,n,sizeof(ll),up);
if(n%2)printf("%lld",b[n/2]-a[n/2]+1);else printf("%lld",b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1);
}

Measured memory_bytes: 6404
package main

import (
	"fmt"
	"math"
)

const (
	diff = 0.0000001
)

func main() {
	var n int
	fmt.Scanln(&n)
	x, y := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&y[i])
	}
	d1 := dist(n, 1, x, y)
	d2 := dist(n, 2, x, y)
	d3 := dist(n, 3, x, y)
	di := math.Abs(float64(x[0] - y[0]))
	for i := 1; i < n; i++ {
		if di < math.Abs(float64(x[i]-y[i])) {
			di = math.Abs(float64(x[i] - y[i]))
		}
	}
	fmt.Printf("%9.8f\n%9.8f\n%9.8f\n%9.8f\n", d1, d2, d3, di)
	return
}

func dist(n, p int, x, y []int) float64 {
	d := 0.0
	for i := 0; i < n; i++ {
		d += math.Pow(math.Abs(float64(x[i])-float64(y[i])), float64(p))
	}
	d = math.Pow(d, 1/float64(p))
	return d
}



Measured memory_bytes: 1204
#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;

struct Point{
    double x;
    double y;
};

int main()
{
    Point p1,p2;
    cin>>p1.x>>p1.y>>p2.x>>p2.y;
    int q;
    cin>>q;
    vector<Point> pp(q);
    for(int i=0; i<q; i++){
        cin>>pp[i].x>>pp[i].y;
    }
    double rc1,rc2,b1;
    rc1=(p1.y-p2.y)/(p1.x-p2.x);
    if(p1.x-p2.x==0){
        b1=p1.y;
        rc2=0;
    }else{
        b1=p1.y-rc1*p1.x;
        rc2=(-1)/rc1;
    }
    vector<double> bb(q);
    vector<Point> ans(q);
    for(int i=0; i<pp.size(); i++){
        if(rc1==0){
            ans[i].x=pp[i].x;
        }else{
            bb[i]=pp[i].y-rc2*pp[i].x;
            if(p1.x-p2.x==0){
                ans[i].x=0;
            }else if(rc2-rc1==0){
                ans[i].x=0;
            }else{
                ans[i].x=(b1-bb[i])/(rc2-rc1);
            }
        }
        if(p1.x-p2.x==0){
            ans[i].y=bb[i];
        }else{
            ans[i].y=rc1*ans[i].x+b1;
        }
        Point ans2[q];
        ans2[i].x=pp[i].x+2*(ans[i].x-pp[i].x);
        if(p1.y-p2.y==0){
            ans2[i].y=-pp[i].y;
        }else{
            ans2[i].y=rc2*ans2[i].x+bb[i];
        }
        cout<<fixed;
        cout<<setprecision(10)<<ans2[i].x<<" "<<ans2[i].y<<endl;;
    }
    return 0;
}


Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0, _n = (n); i < _n; i++)
#define debug(x) cout<<#x<<": "<<x<<endl
/*Author Ritick Goenka || ritick(codechef) ||doped.silicon(codeforces) */
/*IIT Roorkee = <3 */
#define ll long long
#define int long long

#define ld double
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.1415926535897932385
#define INF 1000000000000000
#define MOD 1000000007
int dsu[100005];
int w[100005];
int pend[100005];
int findp(int i)
{
    return (dsu[i]<0)?i:(dsu[i]=findp(dsu[i]));
}
void merge(int i,int j)
{
    if((i=findp(i))!=(j=findp(j)))
    {
        if(dsu[i]>dsu[j])
        {
            swap(i,j);
        }
        w[i]+=w[j];
        pend[i]+=pend[j];
        dsu[i]+=dsu[j];
        dsu[j]=i;
    }
}
signed main () 
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout<<setprecision(11);
        ll n,m;
        cin>>n>>m;
        rep(i,100005)
            dsu[i]=-1;
        rep(i,n)
        {
            cin>>w[i+1];
        }
        vector<pair<int,pair<int,int>>>v;
        rep(i,m)
        {
            ll a,b,c;
            cin>>a>>b>>c;
            v.pb(mp(c,mp(a,b)));
        }
        sort(all(v));
        ll ans=0;
        rep(i,m)
        {
            int a=v[i].ss.ff;
            int b=v[i].ss.ss;
            int c=v[i].ff;
            merge(a,b);
            int x=findp(a);
            if(w[x]>=c)
            {
                ans+=pend[x]+1;
                pend[x]=0;
            }
            else
            {
                pend[x]++;
            }
        }
        cout<<m-ans;
            return 0;
}

Measured memory_bytes: 6516
#include <iostream>
#include<string>
using namespace std;
int main(){
    int n;
    cin>>n;
    int mx=0,mn=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(i==0){
            mx=a;mn=a;
        }else{
            if(mx<a){
                mx=a;
            }else if(mn>a){
                mn=a;
            }
            
        }
    }
    cout<<mx-mn<<endl;

return 0;
}


Measured memory_bytes: 256
//#include <boost/multiprecision/cpp_int.hpp> 
#include<bits/stdc++.h>
#define ll long long 
#define ull unsigned ll
#define pb push_back
#define mp make_pair
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define test    ll t=0;cin>>t;while(t--)
#define fast    ios_base::sync_with_stdio(false);cin.tie(NULL)
//using namespace boost::multiprecision; 
using namespace std;

int main(void) {
	ll n;
	set<string>s;
	test{
	    string s1;
	    cin>>s1;
	    s.insert(s1);
	}
	cout<<s.size();
	return 0;
}



Measured memory_bytes: 19220
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define MAX_D (1000)
#define MAX_C (1000)

int N, M;
int D[MAX_D], C[MAX_C];
int dp[MAX_D + 1][MAX_C + 1];

int rec_dp(int now, int day);

int main()
{
  scanf("%d%d", &N, &M);
  memset(dp, -1, sizeof(dp));

  for (int i = 0; i < N; i++) scanf("%d", &D[i]);
  for (int i = 0; i < M; i++) scanf("%d", &C[i]);

  printf("%d\n", rec_dp(0, 0));

  return (0);
}

int rec_dp(int now, int day)
{
  if (dp[now][day] != -1){
    return (dp[now][day]);
  }
  
  int res;
  if (now == N){
    res = 0;
  }
  else if (N - now == M - day){
    res = rec_dp(now + 1, day + 1) + (D[now] * C[day]);
  }
  else {
    res = min(rec_dp(now, day + 1), rec_dp(now + 1, day + 1) + (D[now] * C[day]));
  }

  dp[now][day] = res;

  return (dp[now][day]);
}

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

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    vector<int> vec_copy(N);
    rep(i,N){
        cin >> vec[i];
        vec_copy[i] = vec[i];
    }
    sort(all(vec));
    int cent_1 = vec[N / 2 - 1];
    int cent_2 = vec[N / 2];
    rep(i,N){
        if (vec_copy[i] <= cent_1){
            cout << cent_2 << endl;
        }
        else{
            cout << cent_1 << endl;
        }
    }
}


Measured memory_bytes: 3712
def main():
    n = int(input())
    A = input().split()
    evens = []
    odds = []
    for idx, a in enumerate(A, start=1):
        if idx % 2 == 0:
            evens.append(a)
        else:
            odds.append(a)

    if n % 2 == 0:
        evens.reverse()
        print((' ').join(evens + odds))
    else:
        odds.reverse()
        print((' ').join(odds + evens))


if __name__ == '__main__':
    main()


Measured memory_bytes: 107748
#include <stdio.h>

int gcd(int, int);

int main()
{
	int kk;
	long long int sum = 0;
	scanf("%d", &kk);
	for(int aa = 1;aa <= kk;aa++)
	{
		for(int bb = 1;bb <= kk;bb++)
		{
			for(int cc = 1;cc <= kk;cc++)
			{
				sum += gcd(cc, gcd(aa, bb));
			}
		}
	}
	printf("%lld\n", sum);
	return 0;
}

int gcd(int xx, int yy)
{
    int rr;
    while((rr = xx % yy) != 0)
    {
        xx = yy;
        yy = rr;
    }
    return yy;
}

Measured memory_bytes: 1732
gets
as = gets.split
bs = Hash.new(0)
as.each do |a|
  bs[a] += 1
end

total = 0
bs.each_pair do |k, v|
  s = k.to_i
  if s < v
    total += v - s
  elsif s > v
    total += v
  end
end

p total


Measured memory_bytes: 17796
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if ((m == -1) && (f == -1) && (r == -1)) {
                break;
            }
            if (m == -1 || f == -1) {
                System.out.println("F");
            } else if (m + f >= 80) {
                System.out.println("A");
            } else if (m + f >= 65) {
                System.out.println("B");
            } else if (m + f >= 50) {
                System.out.println("C");
            } else if (m + f >= 30) {
                if (r >= 50) {
                    System.out.println("C");
                } else {
                    System.out.println("D");
                }
            } else {
                System.out.println("F");
            }
        }
        sc.close();
    }
}


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

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < 6; i++) {
		if (s[i] == '1') {
			ans += 1;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<vector<ll>> a(n,vector<ll>(n,0));
    rep(i,n){
        ll m,x,y;
        cin >> m;
        rep(j,m){
            cin >> x >> y;
            --x;
            if (y == 0) a[i][x] = 1;
            else a[i][x] = 2;
        }
    }
    ll ans = 0;
    rep(bit,(1<<n)){
        bool ok = 1;
        ll cnt = 0;
        vector<ll> m(n,0);
        rep(i,n){
            if (bit&(1<<i)){
                cnt++;
                rep(j,n){
                    if (a[i][j] == 0) continue;
                    else if (m[j] == 0){
                        m[j] = a[i][j];
                    }
                    else{
                        if (m[j] != a[i][j]) ok = 0;
                    }
                }
            }
        }
        rep(i,n){
            if (bit&(1<<i)){
                if (m[i] == 1) ok = 0;
            }
            else{
                if (m[i] == 2) ok = 0;
            }
        }
        if (ok) chmax(ans,cnt);
    }
    PRINT(ans);
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   String S = sc.next();
   char Si = S.charAt(0);
   int count = 1;
   for(int i = 1;i<N;i++)
   {
     if(S.charAt(i)==Si) ;
     else 
     {
       count++;
       Si = S.charAt(i);
     }
   }
        	System.out.println(count);
 }
}

Measured memory_bytes: 24504
#include<iostream>
#include<string>
using namespace std;
int main(){
  string  s, t;
  cin >> s >> t;
  int n = s.length();
  string s2 = s+s;
  string s3 = s;
  
  int ans = 0;

  for(int j=1; j<=n; j++){
    for(int i=0; i<n; i++){
      s3[i]=s2[i+j];
    }
    if(s3==t){
      ans = 1;
    }
  }

  if(ans==1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)

int main() {
	ll n;
	in(n);

	vll h(n), dp(n);
	rep(i, 0, n) {
		in(h[i]);
	}
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	rep(i, 2, n) {
		dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
		ll tmp = dp[i - 2] + abs(h[i] - h[i - 2]);
		if (dp[i] > tmp) {
			dp[i] = tmp;
		}
	}
	


	outn(dp[n-1]);


}



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

int main(){
  int N;
  string S;
  
  cin >> N >> S;
  
  int cnt = 0;
  
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      cnt++;
      continue;
    } else {
      if (S.at(i) != S.at(i - 1)) {
        cnt++;
      }
    }
  }
  
  cout << cnt;
  return 0;
}


Measured memory_bytes: 512
#-*- coding:utf-8 -*-
import math
def how_many_choco(A, D):
    """ 何個チョコ食ったか返す
    nA + 1 <= Dを満たすnを求める
    """
    return math.floor((D-1)/A) + 1

if __name__ == "__main__":
    N = int(input())
    D, X = list(map(int, input().split()))
    eaten = 0
    for i in range(N):
        A = int(input())
        eaten += how_many_choco(A, D)
    print(X + eaten)


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

constexpr ll INF = (1ll << 30);

bool gb(ll a, ll b, ll l) {
    return l * (a + 1) >= b;
}

bool ga(ll a, ll b, ll l) {
    return (a == 0 && b == 0) || gb(a - 1, b, l);
}

int gt(ll a, ll b, ll p) {
    ll l = max((b -1 ) / (a + 1), (a - 1) / (b + 1)) + 1;

    ll lg = 0, rg = a / l;

    while (lg < rg) {
        ll md = (lg + rg + 1) / 2;
        ll la = a - md * l;
        ll lb = b - md;
        if (ga(la, lb, l)) {
            lg = md;
        } else {
            rg = md - 1;
        }
    }

    {
        ll cmove = lg * (l + 1);
        if (cmove >= p) {
            return p % (l + 1) == 0;
        }

        a -= lg * l;
        b -= lg;
        p -= cmove;
    }
    
    for (int iter = 0; iter < 2; ++iter) {
        ll lg2 = 0, rg2 = min(l, a);
        while (lg2 < rg2) {
            ll md = (lg2 + rg2 + 1) / 2;

            if (gb(a - md, b, l)) {
                lg2 = md;
            } else {
                rg2 = md - 1;
            }
        }

        if (p <= lg2) {
            return 0;
        }

        p -= lg2;
        a -= lg2;

        ll lg3 = 0, rg3 = min(l, b);
        while (lg3 < rg3) {
            ll md = (lg3 + rg3) / 2;
            if (ga(a, b - md, l)) {
                rg3 = md;
            } else {
                lg3 = md + 1;
            }
        }

        if (p <= lg3) {
            return 1;
        }

        p -= lg3;
        b -= lg3;
    }


    assert(a * l == b);

    return (p % (l + 1) != 1);
}

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    for (ll i = c; i <= d; ++i) {
        cout << char('A' + gt(a, b, i));
    }

    cout << "\n";
}

int main() {
#ifdef PAUNSVOKNO
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        solve();
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

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

void solve() {
    lli n;
    cin >> n;
    for (int i = 1; i <= 9; i++) {
        if (n % i == 0) {
            lli x = n / i;
            if (x >= 1 and x <= 9) {
                cout << "Yes" << endl;
                return;
            }
        }
    }
    cout << "No" << endl;
}

int main()
{
    IOS;
    //comment it out
    //freopen("input.txt", "r", stdin);
    lli t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=100100;
vector<int> arrive[MAXN];
int a[MAXN],b[MAXN],p[MAXN];
int fa[MAXN];
int f[MAXN],s[MAXN],vis[MAXN];
int n,m;
inline int find(register int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
inline void Addedge(register int u,register int v)
{
	arrive[u].push_back(v);
	return;
}
inline bool cmp_(register int x,register int y)
{
	return a[x]<a[y];
}
signed main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(register int i=1;i<=n;i++) cin>>a[i]>>b[i],a[i]=max(a[i]-b[i],0LL),p[i]=fa[i]=i;
	sort(p+1,p+n+1,cmp_);
	for(register int i=1,x,y;i<=m;i++) cin>>x>>y,Addedge(x,y),Addedge(y,x);
	for(register int i=1;i<=n;i++)
	{
		vector<int> sonnow;
		register int now=p[i];
		vis[now]=1,s[now]=b[now];
		for(register int i=0;i<(int)arrive[now].size();i++)
		{
			register int val=arrive[now][i];
			if((!vis[val])||find(now)==find(val)) continue;
			sonnow.push_back(find(val));
			s[now]+=s[find(val)];
			fa[find(val)]=now;
		}
		f[now]=s[now]+a[now];
		for(register int i=0;i<(int)sonnow.size();i++) f[now]=min(f[now],s[now]-s[sonnow[i]]+max(a[now],f[sonnow[i]]));
	}
	cout<<f[p[n]]<<endl;
	return 0;
}

Measured memory_bytes: 12536
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] x = new int[n + 1];
		for (int i = 0; i <= n; i++) {
			x[i] = sc.nextInt();;
		}
		sc.close();

		Arrays.parallelSort(x);
		BigInteger ans = BigInteger.valueOf(x[1] - x[0]);
		for (int i = 1; i < n; i++) {
			BigInteger d = BigInteger.valueOf(x[i + 1] - x[i]);
			ans = ans.gcd(d);
		}
		System.out.println(ans.toString());
	}
}


Measured memory_bytes: 63044
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N*3);
  for(int i=0; i<N*3; i++) cin >> A[i];

  priority_queue<int,vector<int>,greater<int>> pre;
  ll pre_sum = 0;
  for(int i=0; i<N; i++){
    pre_sum += A[i];
    pre.emplace(A[i]);
  }
  vector<ll> pre_S;
  pre_S.emplace_back(pre_sum);
  for(int i=N; i<2*N; i++){
    pre_sum += A[i];
    pre.emplace(A[i]);
    pre_sum -= pre.top();
    pre.pop();
    pre_S.emplace_back(pre_sum);
  }

  reverse(A.begin(),A.end());
  priority_queue<int> suf;
  ll suf_sum = 0;
  for(int i=0; i<N; i++){
    suf_sum += A[i];
    suf.emplace(A[i]);
  }
  vector<ll> suf_S;
  suf_S.emplace_back(suf_sum);
  for(int i=N; i<2*N; i++){
    suf_sum += A[i];
    suf.emplace(A[i]);
    suf_sum -= suf.top();
    suf.pop();
    suf_S.emplace_back(suf_sum);
  }
  ll ans = -INF;
  reverse(suf_S.begin(),suf_S.end());
  for(int i=0; i<=N; i++){
    // cout << pre_S[i] << " " << suf_S[i] << "\n";
    chmax(ans,pre_S[i]-suf_S[i]);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 7656
#include <iostream>
#include <limits.h>
using namespace std;

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

    int max = INT_MIN;
    int min;
    cin >> min;
    
    for (int i = 1; i < n; i++) {
        int now;
        cin >> now;
        
        int profit = now - min;
        max = profit > max ? profit : max;
        min = now < min ? now : min;
    }

    cout << max << endl;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

const int MAX = 64;
const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  V<ll> a(n);
  rep(i, n) cin >> a[i];

  V<V<P>> bits(n, V<P>(MAX, {0, 0}));
  for (int i = 0; i < n; i++) {
    rep(j, MAX) {
      bits[i][j] = (i > 0) ? bits[i - 1][j] : P({0, 0});
      if (a[i] >> j & 1)
        bits[i][j].first++;
      else
        bits[i][j].second++;
    }
  }
  ll ans = 0;
  rep(i, n - 1) {
    V<P> b = bits[n - 1];
    rep(j, MAX) {
      b[j].first -= bits[i][j].first;
      b[j].second -= bits[i][j].second;
    }
    ll e = 1;
    rep(j, MAX) {
      if (a[i] >> j & 1) {
        ans += b[j].second * e % mod;
      } else {
        ans += b[j].first * e % mod;
      }
      ans %= mod;
      e = e * 2 % mod;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 317288
#include <algorithm>
#include <chrono>
#include <iostream>
#include <vector>

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  int sum = 0;
  vector<int> t(n);
  for (int i = 0; i < n; ++i) {
    cin >> t[i];
    sum += t[i];
  }

  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int p, x;
    cin >> p >> x;
    cout << sum - t[p - 1] + x << '\n';
  }

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


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

int main() {
    ll n,m;
    std::cin >> n>>m;
    
    map<ll,bool> ac;
    map<ll,ll> wa;
    
    ll ans = 0;
    
    for (int i = 0; i < m; i++) {
        ll p;
        string s;
        std::cin >> p>>s;
        
        if(s=="AC"){
            if(!ac[p]){
                ans += wa[p];
                ac[p] = true;
            }
        }else{
            wa[p]++;
        }
    }
    
    ll acs = 0;
    for (auto e : ac) {
        if(e.second)acs++;
    }
    
    std::cout << acs<<" "<<ans << std::endl;
}

Measured memory_bytes: 12800
N, A, B = map(int, input().split())

dif = abs(A-B)
if dif%2 == 0:
    ans = dif//2
else:
    #A left
    t0 = A - 1 + 1
    xa = 0
    xb = B - t0
    dif = abs(xb - xa)
    ans1 = dif//2 + t0
    
    #B left
    t0 = B - 1 + 1
    xa = A - t0
    xb = 0
    dif = abs(xb - xa)
    ans2 = dif//2 + t0
    
    #A right
    t0 = N - A + 1
    xa = N
    xb = B + t0
    dif = abs(xb - xa)
    ans3 = dif//2 + t0
    
    #B right
    t0 = N - B + 1
    xa = A + t0
    xb = N
    dif = abs(xb - xa)
    ans4 = dif//2 + t0
    
    ans = min(ans1, ans2, ans3, ans4)
    
print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <string>
//#include <fstream>

using namespace std;

void dfs (int row, int col, vector <string> island, vector <vector <bool> > & visited)
{
	// right, down, left, up order
	const int dir[][2] =  { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } }; 
	int k;

	visited[row][col] = true;

	for (k = 0; k < 4; ++k){
		int nrow = row + dir[k][0];
		int ncol = col + dir[k][1];
		if (nrow < 0 || nrow >= 12 || ncol < 0 || ncol >= 12 ){
			continue;
		} // end if
		if (!visited[nrow][ncol] && island[nrow][ncol] == '1' ){
			dfs (nrow, ncol, island, visited );
		} // end if
	} // end for
}
	
int main()
{
//	cut here before submit 
//	freopen("testcase.island2", "r", stdin);
	string str = "";

	while (getline (cin, str ) ) {
		if (str.empty() ){
			continue;
		} // end if

		vector <string> island (12, string (12, ' ' ) );
		int i,j;

		for (i = 0; i < 12; ++i){
			for (j = 0; j < 12; ++j){
				island[i][j] = str[j];
			} // end for 
			getline (cin, str );
		} // end for

		vector <vector <bool> > visited (12, vector <bool> (12, false ) );
		int res = 0;

		for (i = 0; i < 12; ++i){
			for (j = 0; j < 12; ++j){
				if (!visited[i][j] && island[i][j] == '1'){
					dfs (i, j, island, visited );
					++res;
				} // end if
			} // end for
		} // end for

		cout << res << endl;	

	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] p=new int[n];
    int sum=0;
    for(int i=0;i<n;i++){
      p[i]=sc.nextInt();
      if(p[i]!=i+1){
        sum++;
      }
    }
    if(sum<=2){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 20820
import math
mod = 10**9 +7
def cmb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,K = map(int,input().split())
f = cmb(N+1,K)
mi = K*(K-1)//2
ma = K*(2*N-K+1)//2
s = 0
while N -K +2> 0:
    mi = K*(K-1)//2
    ma = K*(2*N-K+1)//2
    s += ma - mi +1
    K +=1
print(s%mod)


Measured memory_bytes: 102356
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  int n, k, q;
  cin >> n >> k >> q;
  map<int, int> mp;
  rep(i,q) {
    int a;
    cin >> a;
    a--;
    mp[a]++;
  }
  rep(i,n) YesorNo(k - q + mp[i] > 0);
  return 0;
}

Measured memory_bytes: 5376
include Math

w, h, v, t, x, y, p ,q = gets.split.map(&:to_i)
r2 = (v * t) ** 2

count = 0 
[
    [p,q],
    [p,2*h-q],
    [2*w-p,q], 
    [2*w-p,2*h-q],
].each do |a, b|
    n = 0 
    loop do 
        d = r2 - (b + 2 * h * n - y) ** 2
        break if d < 0 
        s = sqrt(d) 
        l = (x - a - s) / (2 * w)  
        r = (x - a + s) / (2 * w)  
        count += r.floor - l.ceil + 1 
        n += 1
    end 
    
    n = 0 
    loop do 
        n -= 1
        d = r2 - (b + 2 * h * n - y) ** 2
        break if d < 0 
        s = sqrt(d) 
        l = (x - a - s) / (2 * w)  
        r = (x - a + s) / (2 * w)  
        count += r.floor - l.ceil + 1 
    end 
end 

p count

Measured memory_bytes: 8720
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n + 1):
        if i * 10000 + j * 5000 > y:
            break
        elif y - i * 10000 - j * 5000 - 1000 * (n - i - j) == 0:
            print(i, j, (n - i - j))
            exit()
print(-1, -1, -1)


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

int main(){
    ll A,B,C;
    string S;
    cin >> A >> B >> C;
    //vector<ll> A(N);
    ll tmp = B;
    B = A;
    A = tmp;
    tmp = A;
    A = C;
    C = tmp;
    cout << A <<" "<<B<<" " <<C<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


int main(void){
    int n;
    cin>>n;
    vector<int> a(1<<n);
    rep(i,1<<n){
        cin>>a[i];
    }
    using P = pair<int,int>;
    vector<set<P>> dp(1<<n);
    rep(i,1<<n){
        // debug(i);
        dp[i].insert({a[i],i});
        while((int)dp[i].size()>2){
            dp[i].erase(dp[i].begin());
        }
        // print(dp[i]);
        for(P mx : dp[i]){
            rep(k,n){
                int to = (1<<k)|i;
                // debug(to);
                dp[to].insert(mx);
            }
        }
    }
    ll mx_ = 0;
    rep1(i,(1<<n)-1){
        // set<P> st;
        // for(P mx : dp[i]){
        //     st.insert(mx);
        // }
        // for(P mx : dp[0]){
        //     st.insert(mx);
        // }
        // rep(k,n){
        //     if(i&(1<<k)){
        //         int bit = (i^(1<<k))|((1<<k)-1);
        //         for(P mx : dp[bit]){
        //             st.insert(mx);
        //         }
        //     }
        // }
        // while((int)st.size()>2){
        //     st.erase(st.begin());
        // }
        assert((int)dp[i].size() == 2);
        ll res = 0;
        for(P p : dp[i]){
            res += p.first;
        }
        mx_ = max(res,mx_);
        cout<<mx_<<endl;
    }
    return 0;
}


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

int main(){
  int n; cin >> n;
  map<string, int> mp;
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

struct UnionFind {
    std::vector<int> par, sz;
    int gnum;

    explicit UnionFind(int n)
        : par(n), sz(n, 1), gnum(n) {
        std::iota(par.begin(), par.end(), 0);
    }

    int find(int v) {
        return (par[v] == v) ? v : (par[v] = find(par[v]));
    }

    void unite(int u, int v) {
        u = find(u), v = find(v);
        if (u == v) return;

        if (sz[u] < sz[v]) std::swap(u, v);
        sz[u] += sz[v];
        par[v] = u;
        --gnum;
    }

    bool same(int u, int v) { return find(u) == find(v); }
    bool ispar(int v) { return v == find(v); }
    int size(int v) { return sz[find(v)]; }
};

using lint = long long;

void solve() {
    int n, m;
    std::cin >> n >> m;

    std::vector<lint> xs(n);
    for (auto& x : xs) std::cin >> x;

    Edges<lint> es(m);
    for (auto& e : es) {
        std::cin >> e.src >> e.dst >> e.cost;
        --e.src, --e.dst;
    }
    std::sort(es.begin(), es.end());

    int sum = 0, ans = 0;
    std::vector<int> esz(n, 1), iesz(n, 0);
    UnionFind uf(n);

    for (auto e : es) {
        int u = e.src, v = e.dst, c = e.cost;
        u = uf.find(u);
        v = uf.find(v);

        if (u == v) {
            if (c <= xs[v]) {
                ++sum, ++esz[v];
            } else {
                ++iesz[v];
            }
        } else {
            uf.unite(u, v);
            int p = uf.find(v);

            xs[p] = xs[u] + xs[v];
            esz[p] = esz[u] + esz[v];
            iesz[p] = iesz[u] + iesz[v];

            if (c <= xs[p]) {
                sum += iesz[p];
                esz[p] += iesz[p];
                iesz[p] = 0;

                ++sum, ++esz[p];
            } else {
                ++iesz[p];
            }
        }
        ans = std::max(ans, sum);
    }

    std::cout << m - ans << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 4224
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		String[] s = sc.next().split("");
        List<String> list = Arrays.asList(s);
        String[] alphabets = { "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"};
        String ans = "None";
        for(String v : alphabets) {
          if (list.indexOf(v) == -1) {
            ans = v;
            break;
          }
        }
        // 出力
        System.out.println(ans);
	}
}

Measured memory_bytes: 32040
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;
    map<char,int> mapik;
    mapik['H'] = 0;
    mapik['D'] = 1;
    char a,b;
    cin >>a >> b;
    if(mapik[a]^mapik[b] == 1) cout << 'D'<<endl;
    else  cout << 'H'<<endl;


    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  vector<int> p(2,0);
  for (int i=0; i < N; i++) {
    p.at(i%2)+=a.at(i);
  }
  cout << p.at(0)-p.at(1) << endl;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> tall(N);
  for(int i=0;i<N;i++){
    cin >> tall.at(i);
  }
  int count = 0;
  for (int i=0;i<N;i++){
    if(tall.at(i) >= K){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
    

Measured memory_bytes: 768
n,m=(int(i) for i in input().split())
a=0
b=10**6
for i in range(m):
  l,r=(int(j) for j in input().split())
  if l>a and r<b:
    a=l
    b=r
  elif l>a and r>=b:
    a=l
  elif r<b and l<=a:
    b=r
if b>=a:
	if n>=a and n<b:
  		print(n-a+1)
	elif n>=a and n>=b:
  		print(b-a+1)
	elif n<a:
  		print(0)
else:
  	print(0)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 5010;
const ll M = 210;
inline ll read()
{
  ll p=0; ll f=1; char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+ch-'0'; ch=getchar();}
  return p*f;
}
ll a[N],b[N][M]; ll s[N]; ll top; ll sum[N][N]; ll l[N],r[N]; ll pre[N];
int main()
{
  ll n=read(),m=read();

  for(ll i=2;i<=n;i++) a[i] = read();
  for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) b[i][j] = read();

  for(ll i=1;i<=m;i++)
  {
    top = 0; s[top] = 0;
    for(ll j=1;j<=n;j++) l[j] = r[j] = 0;
    for(ll j=1;j<=n;j++)
    {
      while(top && b[j][i] > b[s[top]][i]) top--;
      l[j] = s[top] + 1; s[++top] = j;
    }

    top = 0; s[top] = n+1;
    for(ll j=n;j>=1;j--)
    {
      while(top && b[j][i] > b[s[top]][i]) top--;
      r[j] = s[top] - 1; s[++top] = j;
    }

    for(ll j=1;j<=n;j++)
    {
      // prllf("%d %d %d\n",i,l[j],r[j]);
      sum[l[j]][j] += b[j][i];
      sum[j+1][j] -= b[j][i] ;
      sum[l[j]][r[j]+1] -= b[j][i];
      sum[j+1][r[j]+1] += b[j][i];
    }
  }

  for(ll i=2;i<=n;i++) pre[i] = pre[i-1] + a[i];

  ll maxx = 0;
  for(ll i=1;i<=n;i++) for(ll j=1;j<=n;j++)
  {
    sum[i][j] = sum[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
      if(i<=j) maxx = max(maxx , sum[i][j] - pre[j] + pre[i]);
    // prllf("%d %d %d\n",i,j,sum[i][j]); 
  }

  return printf("%lld\n",maxx),0;
}

Measured memory_bytes: 204672
S=input()
ans=0
MOD=2019
cnt=[0]*MOD
cur=0
cnt[cur]=1
d=1
for s in S[::-1]:
  cur+=int(s)*d
  cur%=MOD
  cnt[cur]+=1
  d*=10
  d%=MOD
for c in cnt:
  ans+=c*(c-1)//2
print(ans)

Measured memory_bytes: 9372
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
const ll INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;

// Bedone harf !

const int N = 10;
bool edge[N][N], mark[N];
int ans = 0, n, m, a[N];

bool check(){
	for(int i = 0; i < n - 1; i++)
		if(edge[a[i]][a[i + 1]] == false)
			return false;
	return true;
}

void solve(int id){
	if(id == n){
		ans += check();
//		if(check())
//			for(int i = 0; i < n; i++)
//				cout << a[i] << ' ';
//		cout << '\n';
		return;
	}
	for(int i = 2; i <= n; i++)
		if(mark[i] == false){
			mark[i] = true;
			a[id] = i;
			solve(id + 1);
			mark[i] = false;
		}
}

int32_t main(){
	ios::sync_with_stdio(false);cin.tie(0);	
	
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int u, v;
		cin >> u >> v;
		edge[u][v] = true;
		edge[v][u] = true;
	}
	a[0] = 1;
	solve(1);
	cout << ans << '\n';
	return 0;
}

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

int main() {
  int n, a, b, c, d;
  std::string yes, no;
  yes = "Yes\n";
  no = "No\n";
  
  std::cin >> n;
  a = n % 10; n = (n - a) / 10;
  b = n % 10; n = (n - b) / 10;
  c = n % 10; n = (n - c) / 10;  
  d = n % 10;
  
  if (b == c && (a == b || c == d)) {
    std::cout << yes;
  } else {
    std::cout << no;
  }
}

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

int fir;

bool solve(long long n,long long m){//nのm分割
    if(n%m!=0 && m%2==1)return false;
    if(m%2==0 && (2*n)%m!=0)return false;
    if((m%2)==1){
        if(((n/m)-((m-1)/2))>=1){
            fir=n/m-(m-1)/2;
            return true;
        }
        else{
            return false;
        }
    }
    else{
        if(((2*n)/m)%2==1){
            fir=(2*n/m-m+1)/2;
            return true;
        }
        else return false;
    }
}

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

    while(1){
        int a;
        cin>>a;
        if(a==0)break;
        fir=a;
        int ans=1;
        for(long long i=1;i*i/2<=a;i++){
            if(solve(a,i)){
                    ans=i;
            }
        }
        cout<<fir<<" "<<ans<<endl;
    }
}


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

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


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,X;cin>>N>>M>>X;
  vector<int> C(N);
  vector<vector<int>> A(N,vector<int>(M));
  for(int i=0;i<N;i++){
    cin>>C[i];
    for(int j=0;j<M;j++){
      cin>>A[i][j];
    }
  }
  bool can=false;
  int m=99999999;
  for(int i=0;i<(1<<N);i++){
    int money=0;
    vector<int> skill(N,0);
    for(int j=0;j<N;j++){
      if(i&(1<<j)){
        money+=C[j];
        for(int k=0;k<M;k++){
          skill[k]+=A[j][k];
        }
      }
    }
    bool chk=true;
    for(int j=0;j<M;j++){
      if(skill[j]<X)chk=false;
    }
    if(chk){
      m=min(m,money);
      can=true;
    }
  }
  cout<<(can?m:-1)<<endl;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 1001001001;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef tuple<string, int, int> T;

int main() {
    int n, m;
    cin >> n >> m;

    int lm = 1, rm = n;

    rep (i, m) {
        int l, r;
        cin >> l >> r;

        lm = max(lm, l);
        rm = min(rm, r);
    }

    if(lm > rm) {
        cout << 0 << endl;
        return 0;
    }

    cout << rm - lm + 1 << endl;

}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		byte a = sc.nextByte();
		byte b = sc.nextByte();
		byte c = sc.nextByte();
		if (a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}

}


Measured memory_bytes: 26244
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	int c[3][3]; rep(i, 3)rep(j, 3)cin >> c[i][j];

	ll a[3] = {};
	a[0] = 0;
	ll b[3] = {};

	for (int i = 0; i < 3; i++)b[i] = c[0][i];

	a[1] = c[1][0] - b[0];

	if(c[1][1] - b[1] != a[1] || c[1][2] - b[2] != a[1]){
		cout << "No" << endl;
		return 0;
	}

	a[2] = c[2][0] - b[0];
	if (a[2] != c[2][1] - b[1] || a[2] != c[2][2] - b[2]) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
if n==2 or m==2:
  print(0)
  exit()
if n==1 and m==1:
  print(1)
  exit()
if n==1 or m==1:
  k=max(n,m)
  print(k-2)
  exit()
print((n-2)*(m-2))

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

int main(){
	int N, num, n1, n2, count=0;

	cin >> N;
	
	n1 = N%10;
	num = N/10;

	for(int i=1;i<4;i++){
		n2 = num%10;
		num = num/10;

		if(n1 == n2){
			count++;
			if(count >=2 ){
				cout << "Yes" << endl;
				return 0;
			}
		}
		else{
			n1 = n2;
			count = 0;
		}

	}

	if(count >=2 ){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[][][] Adai = new int[4][3][10];
		
		for(int i =0; i < n; i++){
			int b = sc.nextInt()-1;
			int f = sc.nextInt()-1;
			int r = sc.nextInt()-1;
			int v = sc.nextInt();
			Adai[b][f][r] += v;
		}
        for (int i=0; i<4; i++) {
            for (int j=0; j<3; j++) {
                for (int k=0; k<10; k++) {
                    System.out.print(" "+Adai[i][j][k]);
                }
                System.out.println();
            }
            if(i<3)
                System.out.println("####################");
        }
	}
}


Measured memory_bytes: 30044
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <unordered_map>
using namespace std;

int main()
{
	int n;
	vector<int> a;
	cin >> n;
	while (n--) {
		int x;
		cin >> x;
		a.push_back(x);
	}

	long long total = 0;
	for (int x : a) total ^= x;
	for (int x : a) cout << (total ^ x) << ' ';

	return 0;
}

Measured memory_bytes: 4316