akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d",x)
#define ps printf(" "); 
#define plint(x) printf("%lld",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define bg begin()
#define ed end()
#define Set(a, s) memset(a, s, sizeof (a))
#define mod 1000000007
#define tmod(k) if ((k) >= mod) k %= mod;
#define endl '\n'
#define nl printf("\n");
#define fors(i,n) for(int i=0; i<n; i++)
#define fore(i,n) for(int i=n-1; i>=0; i--)
#define forv(i,a,n) for(int i=a; i<n; i++)
#define fora(i,ele) for(auto i: ele)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
typedef pair<int,int> pii;
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

class node{
public:
	int id;
	int prio;
	int prd;
};

class compare{
public:
	bool operator()(node &n1, node &n2){
		if(n1.prio>n2.prio)//ascending
			return true;
		else if(n1.prio==n2.prio){
			return n1.id>n2.id;
		}
		return false;
	}
};
//priority_queue<node, vector<node>, compare> pq;

int main(void) {
    ios_base::sync_with_stdio(true);
    cin.tie(NULL);
    cout.tie(NULL);
    /*#ifdef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #else
    // online submission
    #endif*/
    lli q,h,f,d;
    lint4(q,h,f,d);
    lli n;
    lint1(n);
    lli fq = 4*q;
    lli fh = 2*h;
    lli ff = f;
    lli fd = d/2;
    lli minm = min(min(fq,fd),min(fh,ff));

    //trace3(fq,fh,fd);
    lli t;
    if(minm == fq){
        t=fq*n;
    }
    else if(minm == fh){
        t=fh*n;
    }
    else if(minm == ff){
        t=ff*n;
    }
    else{
        lli rem = n%2;
        t = d*(lli)(n/2);
        lli sec = min(fq,min(fh,ff));
        t += (lli)sec*(lli)rem;
    }
    plint(t);
    
    return 0;
}



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

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

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

                if (A[i] % 2 == 0) {
                        if (A[i] % 3 == 0 || A[i] % 5 == 0) {

                        }
                        else {
                                cout << "DENIED" << endl;
                                exit(0);
                        }
                }
        }
        cout << "APPROVED" << endl;


}


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

using std::max;  using std::abs;
using std::min;

const int MAXN=105;

int N,cx,cy,ch=0,c_point,min_abs;                     //c_point: calculable point
int x[MAXN],y[MAXN],h[MAXN];

int main()
{
    scanf("%d",&N);
    for (int i=1;i<=N;++i)
        scanf("%d%d%d",&x[i],&y[i],&h[i]);
    for (cx=0;cx<=100&&ch<=0;++cx)
    {
        for (cy=0;cy<=100&&ch<=0;++cy)
        {
            min_abs=MAXN<<1;
            for (c_point=1;c_point<=N&&h[c_point]==0;++c_point);
            if (c_point==N+1)
            {
                for (int i=1;i<=N;++i)
                    min_abs=min(min_abs,abs(x[i]-cx)+abs(y[i]-cy));
                if (min_abs==1) ch=1;
            }
            else
            {
                ch=h[c_point]+abs(x[c_point]-cx)+abs(y[c_point]-cy);
                int i;
                for (i=1;i<=N&&h[i]==max(ch-abs(x[i]-cx)-abs(y[i]-cy),0);++i);
                if (i<=N) ch=0;
            }
        }
    }
    printf("%d %d %d",--cx,--cy,ch);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;

const int N=2e5+5;
ll a[N];
ll k1[N];
ll k2[N];
map<ll,ll>mp;
ll ans=0;
int main()
{
   IOS;
   int n;
   cin >> n;
   rep(i,1,n){
       cin >> a[i];
       ll temp=i-a[i];
       mp[a[i]+i]++;
       if(mp[temp]>0){
    //       cout<<"de:"<<temp<<endl;
           ans+=mp[temp];
       }
       //cout<<"de:"<<i<<" "<<a[i]+i<<" "<<temp<<endl;
   }
   cout<<ans;
}


Measured memory_bytes: 27872
from collections import Counter

def unbalanced(s):
    c = Counter(s)
    if max(c.values()) > len(s)/2:
        return True
    else:
        return False

s = input()
l = len(s)

balanced = False

for i in range(l-1):
    if unbalanced(s[i:i+2]):
        print(i+1,i+2)
        exit()

for i in range(l-2):
    if unbalanced(s[i:i+3]):
        print(i+1,i+3)
        exit()

print(-1,-1)

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> vpii(m);
    REP(i, m)
    {
        cin >> vpii[i].first >> vpii[i].second;
    }
    vector<int> a(n, -1);
    REP(i, m)
    {
        if (a[vpii[i].first - 1] != -1 && a[vpii[i].first - 1] != vpii[i].second) {
            cout << -1 << endl;
            return 0;
        }
        if (n>=2&&vpii[i].first == 1 && vpii[i].second == 0) {
            cout << -1 << endl;
            return 0;
        }
        a[vpii[i].first - 1] = vpii[i].second;
    }
    REP(i, n)
    if (a[i] == -1)
        a[i] = 0;
    if (n>=2&&a[0] == 0)
        a[0] = 1;
    REP(i, n)
    cout << a[i];
    cout << endl;
}

Measured memory_bytes: 3588
io = STDIN
h,w=io.gets.split.map(&:to_i)
$board=h.times.map do
  Array.new(w,0)
end
queue=[]
h.times do |i|
  io.gets.chomp.each_char.with_index do |c,j|
    next if c=="."
    $board[i][j]=1
    queue << i*w+j
  end
end
while (a=queue.shift)
  i,j=a.divmod(w)
  cur=$board[i][j]
  if i+1<h && $board[ki=i+1][j]==0
    $board[ki][j]=cur+1
    queue << ki*w+j
  end
  if i>=1 && $board[ki=i-1][j]==0
    $board[ki][j]=cur+1
    queue << ki*w+j
  end
  if j+1<w && $board[i][kj=j+1]==0
    $board[i][kj]=cur+1
    queue << i*w+kj
  end
  if j>=1 && $board[i][kj=j-1]==0
    $board[i][kj]=cur+1
    queue << i*w+kj
  end
end

p cur-1


Measured memory_bytes: 21500
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main (String[] args) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()) {
			int ans = 0;
			int [] a = new int [205];
			int n = cin.nextInt();
			for(int i = 0; i < 2 * n; i ++)
				a[i] = cin.nextInt();
			Arrays.sort(a, 0, 2 * n);
			for(int i = 2 * n - 1; i >= 0; i -= 2)
				ans += a[i - 1];
			System.out.println(ans);
		}
		
	}
}

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

int main() {
  static map<string, int> m;
  m["SUN"] = 7;
  m["MON"] = 6;
  m["TUE"] = 5;
  m["WED"] = 4;
  m["THU"] = 3;
  m["FRI"] = 2;
  m["SAT"] = 1;

  string s;
  cin >> s;
  cout << m[s] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main() {
    int N; cin>>N;
    vector<int> left(N,-1);
    vector<int> cleft(200010,-1);
    int c;
    for (int i = 0; i < N; ++i) {
        cin>>c; --c;
        if(cleft[c]>=0){
            left[i]=cleft[c];
        }
        cleft[c]=i;
    }

    vector<ll> dp(N,0ll);
    dp[0]=1;
    for (int i = 1; i < N; ++i) {
        dp[i]=dp[i-1];
        if(left[i]==-1) continue;
        if(i-left[i]>1) (dp[i]+=dp[left[i]])%=MOD;
    }

    cout<<dp[N-1]<<endl;

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
string S,T;
  cin>>S>>T;
vector<vector<int>> s(26,vector<int>());
vector<vector<int>> t(26,vector<int>());
for(int i=0;i<S.size();i++){
 s[S[i]-'a'].push_back(i);
 t[T[i]-'a'].push_back(i);
}
  
int ans=0;
int ta;
  for(int i=0;i<26;i++){
    if(s[i].size()>0){
        ta=(int)(T[s[i][0]]-'a');//s[i]におけるt[ta]
      if(t[ta].size()==s[i].size()){
        for(int j=0;j<s[i].size();j++){
          if((int)(s[i][j])!=(int)(t[ta][j])){ans=1;}
        }
      }
      else{ans=1;}
    }
  }

  if(ans==1){
  cout<<"No"<<endl;
  }
  else{cout<<"Yes"<<endl;}
  
  //cout<<s[0][1]<<endl;
}


Measured memory_bytes: 5956
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 998244353;


int main(){
  ll n;cin>>n;
  ll ans=0,a=0,b=0,both=0;
  rep(i,0,n){
    string s;
    cin>>s;
    rep(j,0,s.size()-1){
      if(s.size()==1)break;
      if(s[j]=='A'&&s[j+1]=='B')ans++;
    }
    if(s[0]=='B'&&s[s.size()-1]=='A')both++;
    else if(s[s.size()-1]=='A')a++;
    else if(s[0]=='B')b++;
  }
  if(a==0&&b==0&&both!=0){
    cout<<ans+both-1<<endl;return 0;
  }
  cout<<ans+min(n-1,both+min(a,b))<<endl;
}




Measured memory_bytes: 3624
'use strict';

const receive = require('fs')
  .readFileSync('/dev/stdin', 'utf8')
  .split(/\s/);

const main = input => {
  const c = input.filter(x => x);
  const ans = c[0][0] + c[1][1] + c[2][2];
  console.log(ans);
};

main(receive);

Measured memory_bytes: 7372
/*input
13
strangeoranget
*/
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <string>
#include <set>
#include <stack>
#include <queue>
#include <iterator>
#include <limits>
#include <deque>
#include <algorithm>
#include <cmath>
#include <list>
#include <map>
#include <climits>
#define ff first
#define ss second
#define MAX 10005
#define endl "\n"
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define vi vector<int>
#define mii map<int,int>
#define pii pair<int,int>
#define len(x) (x.size())
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) for(int i=0;i<a;i++)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define T int tc;cin>>tc;for(int t=1;t<=tc;t++)
#define set_arr(arr,i) memset(arr,i,sizeof(arr))
#define trace1(x)							cerr << #x << ": " << x << endl;
#define trace2(x, y)						cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)						cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) 			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
using namespace std;
int longestRepeatedSubstring(string str) 
{ 
    int n = str.length(); 
    int LCSRe[n+1][n+1] = {0}; 
      string res; 
    int res_length  = 0; 

    int i, index = 0; 
    for (i=1; i<=n; i++) 
    { 
        for (int j=i+1; j<=n; j++) 
        {  
            if (str[i-1] == str[j-1] && 
                LCSRe[i-1][j-1] < (j - i)) 
            { 
                LCSRe[i][j] = LCSRe[i-1][j-1] + 1; 

                if (LCSRe[i][j] > res_length) 
                { 
                    res_length = LCSRe[i][j]; 
                    index = max(i, index); 
                } 
            } 
            else
                LCSRe[i][j] = 0; 
        } 
    } 

    if (res_length > 0) 
        for (i = index - res_length + 1; i <= index; i++) 
            res.push_back(str[i-1]); 
  
    return res.length(); 
} 

int main() 
{ 
    int n;
    string str;
    cin>>n>>str;
    cout << longestRepeatedSubstring(str); 
    return 0; 
} 

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

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

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

    int n;
    cin >> n;

    vector<long long int> dp(1001, 0);
    dp[0] = 1;
    dp[1] = 1;

    for (int i = 2; i <= n; i++) {
        int temp = i;
        for (int j = 2; j <= i; j++) {
            while (temp % j == 0) {
                dp[j]++;
                temp /= j;
            }
        }
    }

    long long int sum = 1;
    for (int i = 2; i <= n; i++) {
        sum *= (dp[i] + 1);
        sum = sum % 1000000007;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int N,i,j,k,a=0;
	scanf("%d",&N);
	int sort[N];
	for(i=0;i<N;i++)
	{
		scanf("%d",&sort[i]);
	}
	
	for(i=0;i<N;i++)
	{
		for(j=i;j>=0;j--)
		{
			if(sort[j-1]>sort[j])
			{
				a=sort[j-1];
				sort[j-1]=sort[j];
				sort[j]=a;
			}
		}
		
		for(k=0;k<N-1;k++)
		{
			printf("%d ",sort[k]);
		}
		printf("%d",sort[N-1]);
		
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
#define int ll
 
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
 
using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;
 
template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}
 
template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}
 
int read(){
	int i;
	scanf("%lld",&i);
	return i;
}
 
void printSpace(){
	printf(" ");
}
 
void printEoln(){
	printf("\n");
}
 
void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}
 
string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}
 
char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}
 
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(a>b)
		a=b;
}
 
template<class T>
T Sq(const T& t){
	return t*t;
}
 
const int inf=LLONG_MAX/3;
 
signed main(){
	int n=read();
	vi p;REP(i,n)p.PB(read()-1);
	p.PB(-1);
	int ans=0;
	REP(i,n)
		if(p[i]==i){
			swap(p[i],p[i+1]);
			ans++;
		}
	cout<<ans<<endl;
}

Measured memory_bytes: 1400
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    int a = s.nextInt();
    int b = s.nextInt();

    int sum = 0;
    int count = 0;
    for(int i = 0; i < a; i++){
      int c =s.nextInt();
      sum = c + sum;
      if(sum <= b){
        count++;
      }else{

      }
    }
    System.out.println(count + 1);
  }
}


Measured memory_bytes: 21844
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<string>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const int maxn=5e5+100;
char ch[maxn];
int n,arr[27][maxn];
int lowbit(int n){
	return n&-n;
}
void update(int p,int t,int a[]){
	for(int i=p;i<=n;i+=lowbit(i)){
		
		a[i]+=t;
	}
}
ll getsum(int p,int a[]){
	ll ans=0;
	for(int i=p;i>0;i-=lowbit(i)){
		ans+=a[i];
	}
	return ans;
}
int main()
{
	int m;
	cin>>n;
	scanf("%s",ch+1);
	for(int i=1;i<=n;i++){
		update(i,1,arr[ch[i]-'a']);
	}
	cin>>m;
	for(int i=1;i<=m;i++){
		int t; cin>>t;
		if(t==1){
			char c;
			int p;
			cin>>p>>c;
			update(p,-1,arr[ch[p]-'a']);
			ch[p]=c;
			update(p,1,arr[c-'a']);
		}
		if(t==2){
			ll sum=0,x,y;
			cin>>x>>y;
			for(int i=0;i<26;i++){
				sum+=getsum(y,arr[i])-getsum(x-1,arr[i])>0;
			}
			cout<<sum<<endl;
		}
	}
    return 0;
 } 

Measured memory_bytes: 51968
#include<stdio.h>
#include<string.h>
int main(void)
{
	int strNum,num,diff,ans=753,a,i;
	char S[10];
	
	scanf("%s",S);
	strNum=strlen(S);

	for(i=0;i<strNum-2;i++){
		num=(S[i]-'0')*100 + (S[i+1]-'0')*10 + (S[i+2]-'0');
		diff=abs(num-753);
		if(diff<ans) ans=diff;
	}

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 128
a,b=map(int,input().split())
ans=10000
for i in range(a,b):
    for j in range(i+1,b+1):
        if i>=2019:
            i=i%2019
        if j>=2019:
            j=j%2019
        if i==0 or j==0:
            print("0")
            exit()
        else:
            if ans>i*j%2019:
                ans=i*j%2019
print(ans)

Measured memory_bytes: 3064
//     _/    _/  _/                        _/                
//    _/    _/      _/_/_/      _/_/_/  _/_/_/_/    _/_/_/   
//   _/_/_/_/  _/  _/    _/  _/    _/    _/      _/    _/    
//  _/    _/  _/  _/    _/  _/    _/    _/      _/    _/     
// _/    _/  _/  _/    _/    _/_/_/      _/_/    _/_/_/ 
// C++ Conpetitive Programming Template 
// Ver 1.0 (codename: Hinata)
// Last Modified : 2019-05-27
// Created       : 2019-05-25
// Auther        : shirataki3
#include <bits/stdc++.h>
using namespace std;
// typename alias
template <class T> using vec = vector<T>;
template <class T, class U> using vep = vec<pair<T,U> >;
template <class T> using PQ = priority_queue<T>;
using ll = long long;
using vll = vec<ll>;
using pll = pair<ll, ll>;
using vpll = vec<pll>;
using str = string;
// あくまのちから
//#define int ll

// const
static const long long INF = 1LL<<59;
static const long long MOD = (ll)1e9+7;
static const double PI = 3.14159265358979323846;

// accelerate stdin, stdout
#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
// repeat macro
#define FOR(i, a, b) for(ll (i)=(a);(i)<=(b);i++)
#define rFOR(i, a, b) for(ll (i)=(b);(i)>=(a);i--)
#define REP(i, n) for(ll i=0;i<n;i++)
// vector macro
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort(WHOLE(v))
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse(WHOLE(v))
#define FOLDL(src, dst, lambda) partial_sum(WHOLE(src), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum(WHOLE(src), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate(WHOLE(v), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}

void solve() {
    ll n, m;
    cin >> n >> m;
    ll N = min(n, m), M = max(n, m);
    if(N==1&&M==1) {
        out(1);
    }else if(N==1) {
        out(M-2);
    }else {
        out((N-2)*(M-2));
    }
}

signed main() {
    fast_io;
    cout << setprecision(20) << fixed;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int tmp[320]={1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400,441,484,529,576,625,676,729,784,841,900,961,1024,1089,1156,1225,1296,1369,1444,1521,1600,1681,1764,1849,1936,2025,2116,2209,2304,2401,2500,2601,2704,2809,2916,3025,3136,3249,3364,3481,3600,3721,3844,3969,4096,4225,4356,4489,4624,4761,4900,5041,5184,5329,5476,5625,5776,5929,6084,6241,6400,6561,6724,6889,7056,7225,7396,7569,7744,7921,8100,8281,8464,8649,8836,9025,9216,9409,9604,9801,10000,10201,10404,10609,10816,11025,11236,11449,11664,11881,12100,12321,12544,12769,12996,13225,13456,13689,13924,14161,14400,14641,14884,15129,15376,15625,15876,16129,16384,16641,16900,17161,17424,17689,17956,18225,18496,18769,19044,19321,19600,19881,20164,20449,20736,21025,21316,21609,21904,22201,22500,22801,23104,23409,23716,24025,24336,24649,24964,25281,25600,25921,26244,26569,26896,27225,27556,27889,28224,28561,28900,29241,29584,29929,30276,30625,30976,31329,31684,32041,32400,32761,33124,33489,33856,34225,34596,34969,35344,35721,36100,36481,36864,37249,37636,38025,38416,38809,39204,39601,40000,40401,40804,41209,41616,42025,42436,42849,43264,43681,44100,44521,44944,45369,45796,46225,46656,47089,47524,47961,48400,48841,49284,49729,50176,50625,51076,51529,51984,52441,52900,53361,53824,54289,54756,55225,55696,56169,56644,57121,57600,58081,58564,59049,59536,60025,60516,61009,61504,62001,62500,63001,63504,64009,64516,65025,65536,66049,66564,67081,67600,68121,68644,69169,69696,70225,70756,71289,71824,72361,72900,73441,73984,74529,75076,75625,76176,76729,77284,77841,78400,78961,79524,80089,80656,81225,81796,82369,82944,83521,84100,84681,85264,85849,86436,87025,87616,88209,88804,89401,90000,90601,91204,91809,92416,93025,93636,94249,94864,95481,96100,96721,97344,97969,98596,99225,99856,100489,101124,101761};

int main(){
	int a, b;
	scanf("%d %d", &a, &b);

	int num = b;
	if(b < 10){
		num += a * 10;
	}else if(b < 100){
		num += a * 100;
	}else{
		num += a * 1000;
	}

	int ans = 0;
	for(int i = 0; i < 320; i++){
		if(num == tmp[i]){
			ans = 1;
		}
	}

	printf("%s\n", ans ? "Yes" : "No");

}


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

ll A, B;

vector<ll> divisor(ll n) {
    vector<ll> ret;
    for (ll i = 1; i*i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) {
                ret.push_back(n/i);
            }
        }
    }
    sort(begin(ret), end(ret));
    return ret;
}

bool is_prime_or_one(ll n) {
    if (n < 1) return false;
    else if (n == 1) return true;
    else {
        for (ll i = 2; i*i <= n; i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}

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

    vector<ll> div_a = divisor(A);
    vector<ll> div_b = divisor(B);

    ll ans = 0;
    ll i = 0;
    ll j = 0;
    while (i < div_a.size() && j < div_b.size()) {
        if (div_a[i] == div_b[j]) {
            if (is_prime_or_one(div_a[i])) ans++;
            i++;
            j++;
        }
        else if (div_a[i] > div_b[j]) j++;
        else i++;
    }

    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;



typedef long long ll;
typedef pair<int,int> P;

const int mod=1e9+7;

int gcd(int a,int b){
    if(b==0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}
int h,w,ans;
queue< pair<int,int> > que,que2;
char a[1001][1001];

void bfs(){
    if(que.size()==0){
        return ;
    }
    while(que.size()){
        pair<int,int> P=que.front();
        que.pop();
        int Px=P.first;
        int Py=P.second;
        if(Px>=1&&a[Px-1][Py]=='.'){
            a[Px-1][Py]='#';
            que2.push(make_pair(Px-1,Py));
        }
        if(Py>=1&&a[Px][Py-1]=='.'){
            a[Px][Py-1]='#';
            que2.push(make_pair(Px,Py-1));
        }
        if(Px<=h-2&&a[Px+1][Py]=='.'){
            a[Px+1][Py]='#';
            que2.push(make_pair(Px+1,Py));
        }
        if(Py<=w-2&&a[Px][Py+1]=='.'){
            a[Px][Py+1]='#';
            que2.push(make_pair(Px,Py+1));
        }
    }
    while(que2.size()){
        que.push(que2.front());
        que2.pop();
    }
/*
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << a[i][j];
        }
        cout << endl;
    }
    cout << endl;
*/
    ans++;
    bfs();

}

int main(){
    ans=0;
    cin >> h >> w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
            if(a[i][j]=='#'){
                que.push(make_pair(i,j));
            }
        }
    }
    bfs();
    cout << --ans << endl;
    return 0;
}

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

int main() {
	
	int n;
	cin >> n;
	long long sm = 0;
	for (int i=0; i<n; i++) {
		int x;
		cin >> x;
		x--;
		sm += x;
	}
	cout << sm << endl;
	
}
 


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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

        int A, B, T;
        std::cin >> A >> B >> T;

        std::cout << (T / A) * B << std::endl;

    }
    catch(const exception& e) {
        std::cout << e.what() << std::endl;
        exit(1);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;
	int i, count = 0;

	cin >> a >> b >> c;

	for (i = a; i <= b; i++)
	{
		if (c % i == 0) count++;
	}
	cout << count << endl;
	return 0;
}


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

int main(void){
    int n; cin >> n;
    int max1 = 0, max2 = 0;
    vector<int> a(n);
    
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
        if(a.at(i) > max1){
            max2 = max1;
            max1 = a.at(i);
            
        }else if(a.at(i) > max2){
            max2 = a.at(i);
        }
    }
    
    
        
    for(int i = 0; i < n; i++){
        if(a.at(i) == max1){
            cout << max2 << endl;
            continue;
        }else if(a.at(i) == max2){
            cout << max1 << endl;
        }else{
            cout << max1 << endl;
        }
    }
            
    
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);

class Graph {
  protected:
    int vertex;

    Graph(int v) {
      vertex = v;
    }
};

struct Edge {
  int to;
  int cost;
};

class AdjacentListGraph : public Graph {
  protected:
    std::vector<std::vector<Edge> > list;
  public:
    AdjacentListGraph(int v): Graph(v) {
      list.resize(vertex);
    }

    virtual void push(int from, int to, int cost) = 0;
};

class DAG : public AdjacentListGraph {
  using AdjacentListGraph::AdjacentListGraph;

  private:
    std::vector<int> sorted;

  public:
    void topological_sort();

    void push(int from, int to, int cost);

    std::vector<int> get_sorted();

    bool has_closed_cycle();
};

void DAG::topological_sort() {
  std::vector<int> intoVertex(vertex, 0);
  std::queue<int> q;

  for (std::vector<Edge> vec: list) {
    for (Edge e: vec) {
      intoVertex[e.to]++;
    }
  }

  for (int i = 0; i < vertex; ++i) {
    if (intoVertex[i] == 0)
      q.push(i);
  }

  while (q.size() > 0) {
    int v = q.front();
    q.pop();
    sorted.emplace_back(v);
    for (Edge e: list[v]) {
      intoVertex[e.to]--;
      if (intoVertex[e.to] == 0)
        q.push(e.to);
    }
  }
}

void DAG::push(int from, int to, int cost = 1) {
  Edge e;
  e.to = to;
  e.cost = cost;
  list[from].push_back(e);
}

std::vector<int> DAG::get_sorted() {
  return sorted;
}

bool DAG::has_closed_cycle() {
  return (int)sorted.size() != vertex;
}

int main() {
  
  int v;
  int e;

  scanf("%d %d", &v, &e);

  DAG g = DAG(v);

  int from, to;

  for (int i = 0; i <  e; i++) {
    scanf("%d %d", &from, &to);
    g.push(from, to);
  }

  g.topological_sort();
  bool flag = g.has_closed_cycle();
  printf("%d\n", flag ? 1 : 0);
}



Measured memory_bytes: 3288
input_strings = gets.chomp.chars
length = input_strings.length
for i in 0..(length-1)
  if input_strings[i] != input_strings[i].upcase
    input_strings[i].upcase!
  else input_strings[i] != input_strings[i].downcase
    input_strings[i].downcase!
  end
end
puts input_strings.join

Measured memory_bytes: 8672
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

map<long long,int> mp;
vector<long long> prime_factorization(long long n){
    vector<long long> v;
    if(n==1) v.push_back(1);
    long long i=2;
    while(n>1){
        if(n<i*i){
            v.push_back(n);
            mp[n]++;
            return v;
        }
        if(n%i==0){
            n/=i;
            v.push_back(i);
            mp[i]++;
        }else{
            i++;
        }
    }
    return v;
}

int main(){
    long long n; cin>>n;
    vector<long long> v=prime_factorization(n);
    v.erase(unique(v.begin(),v.end()),v.end());
    long long nn=v.size();
    long long ans=0;
    for(long long i=1;i<(1ll<<nn);i++){
        long long hugo=__builtin_popcountll(i)%2;
        long long x=1;
        for(long long j=0;j<nn;j++){
            if(i>>j&1){
                x*=v[j];
            }
        }
        if(hugo) ans+=n/x;
        else ans-=n/x;
    }
    cout<<n-ans<<endl;
    return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

void add(ll &a, ll b) {
	a += b;
	if (a >= mod) a -= mod;
}

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

	ll n;
	cin >> n;

	vector<ll> places[210000];
	vector<ll> dp(n + 1, 0);

	vector<ll> c(n);
	rep(i, n) cin >> c[i];

	// places[i] := (c[j] = i となるようなjの集まり)
	rep(i, 210000) places[i].clear();
	rep(i, n) places[c[i]].push_back(i);

	// DP
	dp[0] = 1;
	Rep(i, 1, n + 1) {
		// 特に操作しない場合
		add(dp[i], dp[i - 1]);

		// 操作する場合
		ll color = c[i - 1];
		ll it = lower_bound(allof(places[color]), i - 1)
			- places[color].begin(); // c[i]がcolor色の何番目の要素か
		if (it > 0) {
			ll j = places[color][it - 1]; // c[j] = c[i]となるj
			if ((i - 1) - j > 1) add(dp[i], dp[j + 1]);
		}
	}

	cout << dp[n] << endl;

	return 0;
}

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

int main()
{
	int a, b;
	cin >> a >> b;
	if (a > 0 && b > 0) {
		cout << "Positive" << endl;
	}
	else if ((a <= 0 && b > 0) ||  b == 0) {
		cout << "Zero" << endl;
	}
	else if ((b - a) % 2) {
		cout << "Positive" << endl;
	}
	else {
		cout << "Negative" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#![allow(dead_code)]
use std::io;

fn main() {
    solve_d();
}

fn solve_d() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let mut line = line.trim().to_string();

    let mut q = String::new();
    io::stdin().read_line(&mut q).unwrap();
    let q = q.trim().parse::<u32>().unwrap();

    for _i in 0..q {
        let mut cmd = String::new();
        io::stdin().read_line(&mut cmd).unwrap();
        let cmd: Vec<_> = cmd.trim().split_whitespace().collect();

        let command = cmd[0];
        let a = cmd[1].parse::<usize>().unwrap();
        let b = cmd[2].parse::<usize>().unwrap();

        let mut old = String::new();
        for (i, c) in line.char_indices() {
            if a <= i && i <= b {
                old.push(c);
            }
        }

        if command == "replace" {
            let p = cmd[3];
            let mut new = String::new();
            for (i, c) in line.chars().enumerate() {
                if a <= i && i <= b {
                    new.push(p.chars().nth(i - a).unwrap());
                } else {
                    new.push(c);
                }
            }
            line = new;
        } else if command == "reverse" {
            let mut n = String::new();
            for c in old.chars().rev() {
                n.push(c);
            }
            let mut new = String::new();
            for (i, c) in line.chars().enumerate() {
                if a <= i && i <= b {
                    new.push(n.chars().nth(i - a).unwrap());
                } else {
                    new.push(c);
                }
            }
            line = new;
        } else {
            println!("{}", old);
        }
    }
}



Measured memory_bytes: 5032
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

typedef long long ll;

int main()
{
    int n, l[1100], r[1100];

    cin >> n;
    REP(i, n)
    cin >> l[i] >> r[i];

    int res = 0;

    REP(i, n)
    res += r[i] - l[i] + 1;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
  static class Pair {
    String s;
    int n;

    public Pair(String s, int n) {
      this.s = s; this.n = n;
    }

    public String toString() {
      return s + " " + n;
    }
  }
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    
    int N = in.nextInt();
    in.nextLine();
    Map<String, Integer> map = new HashMap();

    for (int i = 0; i < N; i++) {
      String s = in.nextLine();
      map.merge(s, 1, Integer::sum);
    }

    List<Pair> pairs = new ArrayList();
    for (String s : map.keySet()) {
      pairs.add(new Pair(s, map.get(s)));
    }
    Collections.sort(pairs, (p1, p2) -> {
      if (p1.n - p2.n != 0) return p2.n - p1.n;
      else return p1.s.compareTo(p2.s);
    });
    int n = pairs.get(0).n;
    for (int i = 0; i < pairs.size(); i++) {
      if (pairs.get(i).n == n) System.out.println(pairs.get(i).s);
    }
  }
}

Measured memory_bytes: 182592
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  string c[7] = { "fri", "sat", "sun", "mon", "tue", "wed", "thu" };
  int i; cin >> i;
  cout << c[(i-1)%7] << endl;
}




Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        sc.close();
        long res = k;
        if(n > 1 && k > 2){
            for(long i = 2L; i <= n; i++){
                res *= (k - 1);
            }
        }
        System.out.println(res);
    }

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
long r,g,b,n;
void solve()
{
    long i,j,k,ans=0,a[3];
    a[0]=r;
    a[1]=g;
    a[2]=b;
    sort(a,a+3);
    for (i=0;i<=n/a[2];i++)
        for (j=0;j<=(n-i*a[2])/a[1];j++)
            if ((n-i*a[2]-j*a[1])%a[0]==0) ans++;
    cout<<ans<<endl;
}
int main()
{
    while(cin>>r>>g>>b>>n)
         solve();
}

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

int main() { 
  int n,K,l=0,c=0,r=2,memo=0,check=0;
  long long ans=0;
  cin >>n;
  vector<int>a(n);
  rep(i,n){cin>>a[i];}
  sort(a.begin(),a.end());

  for(r;r<n;r++){
      for(l=r-2;0<=l;l--){
        if(a[r]<a[l]+a[l+1]){ans+=r-l-1;}
        else{c=l+1;
          while(0<=l&&l<c&&c<r){
            c++;
            if(a[r]<a[c]+a[l]){ans+=r-c;l--;c--;}
          }
        break;}
      }
      }
    
  
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
// in the name of Allah

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

#define inf 1e18
#define max_n 200002
#define mod 1000000007

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

/*

// a bit of NT

const int _N = 1234567;

ll F[_N];
ll IF[_N];

void init() {
	F[0] = 1;
	for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
	IF[_N-1] = power(F[_N-1], mod-2);
	for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}

ll ncr(ll x, ll y) {
	if(y > x || y < 0) return 0;
	return mul(F[x], mul(IF[x-y], IF[y]));
}

/**/

class mxLazySegTree {
public:
	int sz;
	vector <ll> tree, lazy;
	mxLazySegTree(int _sz) {
		sz = _sz;
		tree.assign(sz*10, 0);
		lazy.assign(sz*10, 0);
	}
	// update
	void update(int p, int L, int R, int l, int r, ll val) {
		if(lazy[p] != 0) {
			tree[p] += lazy[p];
			// if(L != R) {
				lazy[2*p] += lazy[p];
				lazy[2*p+1] += lazy[p];
			// }
			lazy[p] = 0;
		}
		if(R < l || r < L) return;
		if(l <= L && R <= r) {
			tree[p] += val;
			// if(L != R) {
				lazy[2*p] += val;
				lazy[2*p+1] += val;
			// }
			return;
		}
		int M = (L+R)/2;
		update(2*p, L, M, l, r, val);
		update(2*p+1, M+1, R, l, r, val);
		tree[p] = max(tree[2*p], tree[2*p+1]);
	}
	void update(int l, int r, ll val) {
		update(1, 0, sz-1, l, r, val);
	}
	// query
	ll query(int p, int L, int R, int l, int r) {
		if(R < l || r < L) return -1e18;
		if(lazy[p] != 0) {
			tree[p] += lazy[p];
			// if(L != R) {
				lazy[2*p] += lazy[p];
				lazy[2*p+1] += lazy[p];
			// }
			lazy[p] = 0;
		}
		if(l <= L && R <= r) return tree[p];
		int M = (L+R)/2;
		return max(query(2*p, L, M, l, r), query(2*p+1, M+1, R, l, r));
	}
	ll query(int l, int r) {
		return query(1, 0, sz-1, l, r);
	}
};

int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector <int> s[max_n];
vector <int> e[max_n];

int main() {
	// ll start = clock();
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i=0; i<m; i++) {
		cin >> l[i] >> r[i] >> a[i];
		s[l[i]].pb(i);
		e[r[i]].pb(i);
	}
	ll res = 0, ans;
	mxLazySegTree st(n+1);
	for(int i=1; i<=n; i++) {
		for(int id : s[i]) st.update(0, i-1, a[id]);
		ans = st.query(0, i-1);
		res = max(res, ans);
		st.update(i, i, ans);
		for(int id : e[i]) st.update(0, l[id]-1, -a[id]);
	}
	cout << res << endl;
	// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
	return 0;
}

Measured memory_bytes: 56576
import java.util.Scanner;

class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        
        int W = scan.nextInt();
        
        int H = scan.nextInt();
        
        int x = scan.nextInt();
        
        int y = scan.nextInt();
        
        int r = scan.nextInt();
        
        if(x + r <= W && y + r <= H && x - r >= 0 && y - r >= 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    } 
}
            


Measured memory_bytes: 26220
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ll long long
#define ld double
#define ull unsigned long long
#define PI pair < int, int > 
#define hash puper123

const int N = 5e5 + 123;
const int M = 123;
const ld Pi = acos(-1);
const ll Inf = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int Sz = 501;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mult(int a, int b) {
  return 1ll * a * b % mod;
}
int sum(int a, int b) {
  add(a, b);
  return a;
}

int n, a, b, c, d;
pair < ll, ll > p[N], s[N];

void solve() {
  cin >> n >> a >> b >> c >> d;
  n -= 2;
  p[0] = {a, a};
  for (int i = 1;i <= n + 1;i++) {
    p[i].f = p[i - 1].f + c;
    p[i].s = p[i - 1].s + d;
  }
  s[n + 1] = {b, b};
  for (int i = n;i >= 0;i--) {
    s[i].f = s[i + 1].f + c;
    s[i].s = s[i + 1].s + d;
  }
  for (int i = 0;i <= n + 1;i++) {
    if (max(p[i].f, s[i].f) <= min(p[i].s, s[i].s)) {
 //     cout << "here i = " << i << endl;
   //   cout << "l1 = " << p[i].f << " r1 = " << p[i].s << " l2 = " << s[i + 1].f << " r2 = " << s[i + 1].s << endl;
      cout << "YES\n";
      return;
    }
  }
  cout << "NO\n";
}

int main() {
  #ifdef wws
   freopen("in", "r", stdin);
  #endif 
  ios_base::sync_with_stdio(0);
  int tt = 1; 
  while(tt--) solve();
  return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
  int a,b;
  cin >> a >> b;
  cout << max(a-b, max(a+b, a*b)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    vector<int> v;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        v.push_back(x);
    }
 
    sort(v.begin(), v.end());
    
    int count = 0;
    int len = v.size();
    for (int i = 0; i < len; i++) {
        if (v[i] == v[i+1]) {
            i++;
        } else {
            count++;
        }
    }
 
    cout << count << endl;
 
    return 0;
}

Measured memory_bytes: 892
#include <iostream>
using namespace std;
int main(){
    int n,i,c,y,m,d; 
    cin>>n;
    while(n--){
        c=y=m=d=0;
        cin>>y>>m>>d;
        if(y%3!=0&&m%2==0)c+=20-d;
        else c+=21-d;
        for(i=m+1;i<=10;i++){
            if(y%3!=0&&i%2==0)c+=19;
            else c+=20;
        }
        for(i=y+1;i<=999;i++){
            if(i%3==0)c+=200;
            else c+=195;
        }
        cout<<c<<endl;
    }
}

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define int ll
#define tcase int t; cin>> t; for( ; t; --t)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

int32_t main(){
	fastio;
	string s, t;
	cin>> s;
	cin>> t;
	int a, b;
	cin>> a>> b;
	string u;
	cin>> u;
	if(u == s) {
		cout<< a - 1<< ' '<< b<< endl;
	}
	else cout<< a<< ' '<< b-1<< endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int N = 100;

int main()
{
	int n;
	cin >> n;
	int A[N], v, j;

	for (int i = 0; i < n; i++)
		cin >> A[i];

	for (int c = 0; c < n - 1; c++)
		cout << A[c] << " ";
	cout << A[n - 1] << endl;

	for (int i = 1; i < n; i++)
	{
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v)
		{
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		for (int c = 0; c < n - 1; c++)
			cout << A[c] << " ";
		cout << A[n - 1] << endl;
	}

	return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>
#include <string.h>

int main() {
    char str[1001], name[10], temp, p[1000];
    int q, a, b;
    scanf("%s", str);
    scanf("%d", &q);
    for (int i=0; i<q; i++) {
        scanf("%s", name);
        if ((strcmp(name, "print")) == 0) {
            scanf("%d %d", &a, &b);
            for (int j=a; j<=b; j++) {
                printf("%c", str[j]);
            }
            putchar('\n');
        } else if ((strcmp(name, "reverse")) == 0) {
            scanf("%d %d", &a, &b);
            for (int k=a, l=0; a+l<b-l; k++, l++) {
                temp = str[k];
                str[k] = str[b-l];
                str[b-l] = temp;
            }
        } else if ((strcmp(name, "replace")) == 0) {
            scanf("%d %d %s", &a, &b, p);
            for (int m=a, n=0; m<=b; m++, n++) {
                str[m] = p[n];
            }
        }
    }
    return 0;
}



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

int main() {
  string a, b, c; cin >>a >>b >>c;
  bool ans = false;
  if (a.at(a.size()-1)==b.at(0) && b.at(b.size()-1)==c.at(0)){
    ans = true;
  }
  
  if(ans) cout <<"YES";
  else cout <<"NO";
  cout <<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for {
		m, f, r := nextInt(), nextInt(), nextInt()
		if m == -1 && f == -1 && r == -1 {
			break
		}
		if m == -1 || f == -1 {
			fmt.Println("F")
			continue
		}
		score := m + f
		if score >= 80 {
			fmt.Println("A")
			continue
		}
		if score >= 65 {
			fmt.Println("B")
			continue
		}
		if score >= 50 {
			fmt.Println("C")
			continue
		}
		if score >= 30 {
			if r >= 50 {
				fmt.Println("C")
			} else {
				fmt.Println("D")
			}
			continue
		}
		fmt.Println("F")

	}
}



Measured memory_bytes: 1060