akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
	int n,p[1000][3],flg[1000],i,j,k,f,temp,cnt;
	cin>>n;
	for(i=0;i<n;i++) flg[i]=0;
	for(i=0;i<n;i++){
		for(j=0;j<3;j++) cin>>p[i][j];
	}
	for(i=0;i<n;i++){
		sort(p[i],p[i]+3);
	}
	cnt=0;
	for(i=0;i<n-1;i++){
		if(flg[i]!=1){
			for(j=i+1;j<n;j++){
				f=1;
				for(k=0;k<3;k++){
					if(p[i][k]!=p[j][k]){
						f=0;
						break;
					}
				}
				if(f==1){
					cnt++;
					flg[j]=1;
				}
			}		
		}
	}
	cout<<cnt<<endl;
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K,X,Y;
    cin >> N>>K>>X>>Y;

    if(N > K){
        cout << K*X+(N-K)*Y<<'\n';
    }else{
        cout << N*X << '\n';
    }


    return 0;
}

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

void solve() 
{
    int n,x,y;cin>>n>>x>>y;x--;y--;
    vector<int>a(n,0);
    REP(i,n-1)
        rep(j,i+1,n)
            a[min({abs(j-i),abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1})-1]++;
    REP(i,n-1)cout<<a[i]<<endl;
}

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

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int count = 0;
    rep(i, s.size())
    {
        if (s[i] == 'R')
            count++;
    }
    int ans = 0;
    rep(i, count)
    {
        if (s[i] == 'W')
            ans++;
    }
    cout << ans << "\n";
}


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

int main() {
  int N, Sum=0;
  string S;
  cin >> N;
  map<string, int> M;
  rep(i, N){
    cin >> S;
    M[S]++;
  }
  for(auto x:M) Sum++;
  cout << Sum << endl;
}

Measured memory_bytes: 19120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    if(int(a.find('C'))!=-1 and int(a.rfind('F'))!=-1 and a.find('C')<a.rfind('F'))//个人码风问题，习惯用and而不是&&
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int h, a;
	
	scanf("%d %d", &h, &a);
	
	int ans = h % a;
	
	if(ans != 0){
		printf("%d\n", (h/a) + 1);
	}else{
		printf("%d\n", h/a);
	}
}

Measured memory_bytes: 1724
#include<iostream>
#include<vector>
#include<string>
#include<cmath>


using namespace std;



int main() {
	int a;
	string s;
	cin >> a;
	cin >> s;

	if (a >= 3200) {
		cout << s;
	}
	else {
		cout << "red";
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int dn,p,n;
int d[100],dcnt[100];
 
int x,y;
int fans;
 
void dfs(int x,int ans,int cnt){
  cnt+=dcnt[x];
  if(cnt<=dn) ans+=d[x];
  for(int i=x+1;i<n;i++) dfs(i,ans,cnt);
  fans=max(ans,fans);
  return;
}
 
int main(){
  cin>>dn;
  cin>>x;
  string s;
 
  for(int i=0;i<x;i++){
    cin>>s>>p;
    if(s=="D") d[n]=p,dcnt[n]=1,n++;
  }
  cin>>y;
  for(int i=x;i<x+y;i++){
    cin>>s>>p;
    if(s=="DD") d[n]=p,dcnt[n]=2,n++;
  }
  for(int i=0;i<n;i++)  dfs(i,0,0);  
  cout<<fans<<endl;
 
  return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    int sum = 0;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n);
    for(int i = 0; i < n-1; i++) sum += a[i];
    sum += a[n-1]/2;
    cout << sum;
}


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

int main(){
  int n;
  cin >> n;
  int x = 1;
  for(int i = 0; i < n;++i){
    if(x>n) break;
    x *= 2;
  }
  
  cout << x/2 << endl; 
    
  return 0;
}

Measured memory_bytes: 256
def get_digits_sum(num):
    result = 0
    while num > 0:
        result += num % 10
        num //= 10
    return result


def main():
    limit, digit_sum_lower, digit_sum_upper = map(int, input().split())
    answer = 0
    for i in range(1, limit + 1):
        if digit_sum_lower <= get_digits_sum(i) <= digit_sum_upper:
            answer += i
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k;
    cin>>n>>k;
    if(n == k) {
    	cout<<"0\n";
    } else if(n > k){
    	ll q = n / k;
    	if(n % k == 0) {
    		cout<<"0\n";
    	} else {
    		ll num1 = n - q * k;
    		ll num2 = n - (q - 1) * k;
    		cout<<min(abs(k - num1), abs(k - num2));
    	}
    } else {
    	cout<<min(n, k - n)<<"\n";
    }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

long long M,r[2],c[2];

long long ceil(long long a,long long b){
  return (a+b-1)/b;
}

long long gcd(long long a,long long b){
  return a%b?gcd(b,a%b):b;
}

long long back(long long a,long long b){
  return (a*r[0]/100-c[0])*100/r[0]+(b*r[1]/100-c[1])*100/r[1];
}

int main(){
  cin>>M>>r[0]>>r[1]>>c[0]>>c[1];
  long long m[2];
  long long rc[2];
  for(int i=0;i<2;i++){
    m[i]=ceil(c[i]*100,r[i]);
    long long k=100/gcd(100,r[i]);
    long long x=ceil(c[i]*100,r[i]*k);
    bool p[100]={};
    for(;;x++){
      long long rem=((k*x*r[i])/100-c[i])*r[i]%100;
      if(rem==0){
	rc[i]=k*x;
	break;
      }
      if(p[rem]++){
	rc[i]=-1;
	break;
      }
    }
  }
  long long ans=-1;
  if(m[0]+m[1]<=M){
    ans=M-m[0]-m[1]+back(m[0],m[1]);
    if(m[0]+rc[1]<=M){
      ans=max(ans,M-m[0]-rc[1]+back(m[0],rc[1]));
    }
    if(rc[0]+m[1]<=M){
      ans=max(ans,M-rc[0]-m[1]+back(rc[0],m[1]));
    }
    if(rc[0]+rc[1]<=M){
      ans=max(ans,M-rc[0]-rc[1]+back(rc[0],rc[1]));
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1160
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> P;
    rep (i, N) {
        ll p;
        cin >> p;
        P.pb(p);
    }
    rep (i, N) {
        rep (j, N) {
            vector<ll> Q = P;
            swap(Q[i], Q[j]);
            ll c = Q[0];
            bool f = true;
            rep (k, N) {
                if (c > Q[k]) {
                    f = false;
                    break;
                }
                c = Q[k];
            }
            if (f) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 384
//Code by : Abhishek Tiwari
//codechef.com/users/devil_within || hackerearth.com/@devil_within
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int 
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define repr(i,a,b) for(int i=(a);i>(b);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pii pair<int,int> 
#define ff first
#define ss second 
#define mod 1000000007
#define inf 1000000000
#define gcd __gcd
#define lcm(a,b) ((a)*(b))/gcd(a,b)
using namespace std;

/*******************************************************************************************/
/*******************************************************************************************/
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { 
    os<<"["; for(int i=0;i<v.size()-1; ++i)os<<v[i]<<", ";os<<v[v.size()-1]<<"]\n"; return os; 
} 
template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { 
    os<<"{"; for(auto it : v) { os<<it; if(it!=*v.rbegin()) os<<", "; } os<<"}\n"; 
    return os; 
}
template <typename T, typename S> ostream& operator<<(ostream& os, const map<T, S>& v) { 
    os<<"{"; for(auto it:v){ os<<"("<<it.first<<" : "<<it.second<<")"; if(it!=*v.rbegin()) os<<", "; } os<<"}\n"; 
    return os; 
}
template <typename T, typename S> ostream& operator<<(ostream& os, const pair<T, S>& v) { 
    os<<"("; os<<v.first<<", "<< v.second<<")"; 
    return os; 
} 
template<typename T> T maxi(T a,T b){return a>b ? a:b;}
template<typename T> T mini(T a,T b){return a<b ? a:b;}
/*******************************************************************************************/
/*******************************************************************************************/
int fpow(int x, int y, int p); 

int filldp(int x, int y , vector<vector<int>> &dp)
{
    if( dp[x][y]!= -1)
        return dp[x][y];
    dp[x][y] = filldp(x+1 , y , dp)%mod;
    dp[x][y]= (dp[x][y] + filldp(x, y+1, dp))%mod;
    return dp[x][y];
}
int32_t main()  
{
#ifndef ONLINE_JUDGE
//freopen("input.txt" , "r" , stdin);freopen("output.txt" , "w" , stdout);freopen("error.txt" , "w" , stderr);
#endif
fio;
int tcases = 1;
//cin>>tcases;
for(int tcase = 1 ; tcase <= tcases ; ++tcase)
{
    int h,w;
    cin>>h>>w;
    vector<string> grid(h);
    rep(i , 0 , h)
        cin>>grid[i];
    vector<vector<int>> dp(h+1);
    rep(i , 0 , h+1)
        dp[i].resize(w+1);
    rep(i , 0 , w+1)
        dp[h][i] = 0;
    rep(i , 0 , h+1)
        dp[i][w] = 0;
    rep(i , 0 , h)
        rep(j , 0, w)
            if(grid[i][j]=='#')
                dp[i][j] = 0;
            else 
                dp[i][j] = -1;
    dp[h-1][w-1] = 1;
    cout<<filldp(0 , 0 , dp)<<"\n";
    //cout<<"Case #"<<tcase<<": ";
}
return 0;
}



//Functions 

int fpow(int x, int y, int p) { 
    int res = 1; 
   x = x % p;  
   while (y > 0) { 
     if (y & 1) 
        res = (res * x) % p; 
     y = y >> 1; 
        x = (x * x) % p; 
    } 
    return res; 
} 


Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n;
  cin >> n;
  Vi a(n);
  int qw;
  int sum = 0;
  rep(i,0,n){
    cin >> qw;
    a[i] = qw-i;
  }
  
  sort(ALL(a));
  int chu = a[n/2];
  
  rep(i,0,n){
    sum += abs(chu-a[i]);
  }
  cout << sum << endl;
}


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

int main() {
int x;
cin >> x;
while(true){
  bool ans = true;
  for(int i = 2; i < x; i++){
    if(x%i == 0){
      ans = false;
      break;
    }
  }
  if(ans){
    cout << x << endl;
    return 0;
  } else x++;
}
  
}


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

typedef long long ll;
typedef unsigned long long ull;

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

  vector<ll> l(n);
  for (ll i = 0; i < n; ++i) {
    cin >> l[i];
  }
  sort(l.begin(), l.end());
  
  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    for (ll j = i+1; j < n; ++j) {
      ll a = l[i];
      ll b = l[j];

      ll bottom = max(a-b+1, ll(0));
      bottom = max(b-a+1, bottom);
      ll top = a+b+1;
      if (bottom > top) continue;

      auto itr = lower_bound(l.begin(), l.end(), bottom);
      if (itr == l.end()) continue;
      ll bottomIdx = distance(l.begin(), itr);
      
      itr = lower_bound(l.begin(), l.end(), top);
      ll topIdx = n;
      if (itr != l.end()) {
        topIdx = distance(l.begin(), itr);
      }

      bottomIdx = max(bottomIdx, j+1);
      //ans += max(topIdx-bottomIdx, ll(0));
      for (ll k = bottomIdx; k < topIdx; ++k) {
        ll c = l[k];
        if (a < b+c &&
            b < a+c &&
            c < a+b) {
          ++ans;
        }
      }
    }
  }

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

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

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

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

typedef long long ll;

int main() {
	int n,T;
	cin >> n >> T;
	pair<int,int> c[n];
	for (int i = 0;i < n;i++) {
		cin >> c[i].first >> c[i].second;
	}
	sort(c,c+n,[](const pair<int,int>& x, const pair<int,int>& y) { return x.first < y.first;});
	for (int i = 0;i < n;i++) {
		if (c[i].second <= T) {
			cout << c[i].first;
			return 0;
		}
	}
	cout << "TLE" << endl;
}

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

int main()
{
  int N; cin >> N;
  vector<int> W(N);
  rep(i, N) cin >> W[i];

  int ans = INT_MAX;
  rep(T, N) {
    int s1=0, s2=0;
    for(int i=0; i<T; ++i)
      s1 += W[i];
    for(int i=T; i<N; ++i)
      s2 += W[i];
    if(abs(s1 - s2) < ans)
      ans = abs(s1-s2);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
A,B,C,X,Y = list(map(int,input().split()))

if X<Y:
    tmp = A
    A=B
    B=tmp
    tmp =X
    X=Y
    Y=tmp

if A+B< 2*C:
    print(A*X+B*Y)
    exit()

if A>2*C:
    print(2*C*X)
    exit()
print( 2*C*Y + (X-Y)*A)



Measured memory_bytes: 3060
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
template<class T> inline T popFirst(multiset<T> &a){
  T res=*(a.begin());
  a.erase(a.begin());
  return res;
}
template<class T> inline T popFirst(set<T> &a){
  T res=*(a.begin());
  a.erase(a.begin());
  return res;
}
int N;
int z;
int num[1000000];
int now[1000000];
int sz;
int main(){
  int Lj4PdHRW, c, i, j, k;
  multiset<int> s;
  multiset<int>::iterator it;
  rd(N);
  z = 1<<N;
  for(Lj4PdHRW=0;Lj4PdHRW<(z);Lj4PdHRW++){
    rd(k);
    s.insert(-k);
  }
  now[sz++] = popFirst(s);
  for(k=0;k<(N);k++){
    c = sz;
    for(i=0;i<(c);i++){
      it = s.upper_bound(now[i]);
      if(it==s.end()){
        wt_L("No");
        wt_L('\n');
        return 0;
      }
      now[sz++] = *it;
      s.erase(it);
    }
  }
  wt_L("Yes");
  wt_L('\n');
  return 0;
}
// cLay varsion 20190902-1

// --- original code ---
// int N, z;
// int num[1d6];
// int now[1d6], sz;
// {
//   int i, j, k, c;
//   multiset<int> s;
//   multiset<int>::iterator it;
//   
//   rd(N);
//   z = 1<<N;
//   rep(z){
//     rd(k);
//     s.insert(-k);
//   }
// 
//   now[sz++] = popFirst(s);
//   rep(k,N){
//     c = sz;
//     rep(i,c){
//       it = s.upper_bound(now[i]);
//       if(it==s.end()) wt("No"), return 0;
//       now[sz++] = *it;
//       s.erase(it);
//     }
//   }
// 
//   wt("Yes");
// }


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if ((A+B)>(C+D)){
    cout << "Left" << endl;
  }
  else if ((A+B)==(C+D)){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll INF = LLONG_MAX/3;

struct MaxSegTree{
    int n; vector<ll> dat;
    //初期化
    MaxSegTree(int _n){
        n=1;
        while(n<_n) n*=2;
        dat=vector<ll>(2*n-1,LLONG_MIN);
    }
    //k番目(0-indexed)の値をaに変更
    void update(int k, ll a){
        k+=n-1;
        dat[k]=a;
        //更新
        while(k>0){
            k=(k-1)/2;
            dat[k]=max(dat[2*k+1],dat[2*k+2]);
        }
    }
    //内部的に投げられるクエリ
    ll _query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return LLONG_MIN;

        if(a<=l && r<=b) return dat[k];

        ll vl=_query(a,b,2*k+1,l,(l+r)/2);
        ll vr=_query(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }
    //[a,b)の最大値を求める
    ll query(int a, int b){
        return _query(a,b,0,0,n);
    }
};

int main(){
    int n,m;
    scanf(" %d %d", &n, &m);

    vector<int> a(n+1);
    rep(i,n) scanf(" %d", &a[i+1]);

    vector<vector<int>> L(n+1), R(n+1);
    rep(i,m){
        int l,r;
        scanf(" %d %d", &l, &r);
        L[l].pb(l);
        R[r].pb(l);
    }

    vector<ll> dp(n+1,-INF);
    MaxSegTree st(n+1);

    dp[0] = 0;
    st.update(0, dp[0]);

    multiset<int> s;
    for(int i=1; i<=n; ++i){
        for(int j:L[i]) s.insert(j);

        int idx = i;
        if(!s.empty()) idx = *s.begin();

        dp[i] = st.query(0, idx) + a[i];
        st.update(i, dp[i]);

        for(int j:R[i]) s.erase(s.find(j));
    }

    printf("%lld\n", *max_element(all(dp)));
    return 0;
}



Measured memory_bytes: 28060
W, H, N = map(int, input().split())
u, d, r, l = H, 0, W, 0
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        l = max(l, x)
    elif a == 2:
        r = min(r, x)
    elif a == 3:
        d = max(d, y)
    else:
        u = min(u, y)
print(max(r-l, 0)*max(u-d, 0))


Measured memory_bytes: 38384
k = int(input())
ans = [[i for i in range(1, 10)]]
d = 9
while d < k:
    ans.append([])
    for i in ans[-2]:
        x = str(i)
        z = int(x[-1])
        ans[-1].append(x + str(z))
        if z <= 8:
            ans[-1].append(x + str(z + 1))
        if z >= 1:
            ans[-1].append(x + str(z - 1))
    d += len(ans[-1])
ans[-1].sort()
print(ans[-1][k - d - 1])


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

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<vector <int> > g(N, vector<int>(N, 0));

    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        g[a][b] = g[b][a] = 1;
    }

    vector<int> v(N);
    iota(v.begin(), v.end(), 1);
    int ans = 0;
    do {
        int previous = 1;
        bool flag = true;
        for(int i = 0; i < N; i++) {

            if(i == 0) { 
                if(v[0] != 1) {
                    flag = false;
                    break;
                }
            }
            else if(g[previous-1][v[i]-1] == 1) {
                    previous = v[i];
            }
            else {
                flag = false;
                break;
            }
        }
        if(flag)    ans++;
    } while(next_permutation(v.begin(), v.end()) );

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

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.string;
import std.uni;

void main()
{
    while (true)
    {
        auto a = readln;
        if (a == "0\n") break;
        writeln(a.strip.map!(x => x - '0').sum);
    }
}



Measured memory_bytes: 2420
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
q = int(input())

t = 0
l = ''
r = ''
for i in range(q):
    query = input()
    if query == '1':
        if t == 1:
            t = 0
        else:
            t = 1
    else:
        if query[2] == '1':
            if t == 0:
                l = query[4:]+l
            else:
                r = r+query[4]
        else:
            if t == 0:
                r = r+query[4]
            else:
                l = query[4] + l
s = l+s+r
if t == 1:
    print(s[::-1])
else:
    print(s)

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

  vector<string> words{};

  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    words.emplace_back(S);
  }
  
  sort(words.begin(), words.end());

  string ans;
  for (int i = 0; i < N; i++) {
    ans += words[i];
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int K = int.Parse(Console.ReadLine());
        int X = int.Parse(Console.ReadLine());
        int Y = int.Parse(Console.ReadLine());
        Console.WriteLine(N > K ? X * K + Y * (N - K) : X * N);
    }
}


Measured memory_bytes: 13140
import sys
iN,iK = [int(_) for _ in input().split()]
#aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

d = {}
for _ in range(iN):
    a,b = [int(_) for _ in sys.stdin.readline().split()]
    if a in d:
        d[a] += b
    else:
        d[a] = b
iC = 0
for a in sorted(d.keys()):
    iC += d[a]
    if iK <= iC :
        print(a)
        exit()


Measured memory_bytes: 10592
/**
 *  author: andychen
 *  created: 09.14.2020 03:49:42
**/

#include <bits/stdc++.h>

using namespace std;

const long long mod = 1e9 + 7;

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

    vector<long long> dp(n + 1, 0);
    dp[0] = 1;
    for (int i = 3; i <= n; i++){
        for (int j = 3; i - j >= 0; j++){
            dp[i] += dp[i - j];
            dp[i] %= mod;
        }
    }

    cout << dp[n] << '\n';

    return 0;
}


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

const long long MOD = 998244353;

int main() {
	string s;
	cin >> s;
	int n = (int) s.size();
	vector<int> a(n);
	bool same = true;
	rep(i, n) { 
		a[i] = (s[i] == 'a' ? 0 : s[i] == 'b' ? 1 : 2);
		if (i) same = same && a[i] == a[i - 1];
	}
	if (same) {
		printf("1\n");
		return 0;
	} else if (n >= 6) {
		int m = 0;
		bool cons = false;
		rep(i, n) {
			m += a[i];
			if (i && a[i - 1] == a[i]) {
				cons = true;
			}
		}
		m %= 3;
		vector<vector<long long>> cur1(3, vector<long long> (3)); // ans = \sum cur1[i][m]
		vector<vector<long long>> cur2(3, vector<long long> (3));
		rep(i, 3) cur2[i][i] = 1;
		rep(i, n - 1) {
			vector<vector<long long>> next1(3, vector<long long> (3));
			vector<vector<long long>> next2(3, vector<long long> (3));
			rep(j, 3) {
				rep(k, 3) {
					rep(l, 3) {
						(next1[l][(k + l) % 3] += cur1[j][k]) %= MOD;
						if (j != l) {
							(next2[l][(k + l) % 3] += cur2[j][k]) %= MOD;
						} else {
							(next1[l][(k + l) % 3] += cur2[j][k]) %= MOD;
						}
					}
				}
			}
			cur1.swap(next1);
			cur2.swap(next2);
		}
		long long ans = !cons;
		rep(i, 3) (ans += cur1[i][m]) %= MOD;
		printf("%lld\n", ans);
	} else {
		set<vector<int>> tozan;
		function<void (vector<int>)> dfs = [&](vector<int> hi) {
			if (tozan.count(hi)) return;
			tozan.insert(hi);
			for (int i = 0; i < (int) hi.size() - 1; i ++) {
				int pro0 = hi[i];
				int pro1 = hi[i + 1];
				if (pro0 != pro1) {
					hi[i] = 3 - pro0 - pro1;
					hi[i + 1] = 3 - pro0 - pro1;
					dfs(hi);
					hi[i] = pro0;
					hi[i + 1] = pro1;
				}
			}
		};
		dfs(a);
		printf("%d\n", (int) tozan.size());
	}
}


Measured memory_bytes: 1412
#include<iostream>
using namespace std;
int main()
{
	int n;
	int i;
	long long int sum=0;
	cin>>n;
	for(i=0;i<=n;i++)
	{
		if(i%3!=0&&i%5!=0)
		sum+=i;
	}
	cout<<sum;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    int i;
    int ans=0;

    for(i=0;i<N;i++){
        cin >> p.at(i);
    }
    sort(p.begin(), p.end());
    for(i=0;i<K;i++){
        ans += p.at(i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
 
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " " << a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
 
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}

typedef long long int64;
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
const int INF = 1 << 30;

int main(){
  int A, B;

  cin >> A >> B;
  vector< int > cardA(A), cardB(B);
  cin >> cardA;
  cin >> cardB;

  int ret = 0;
  for(int i = 0; i < B; i++){ //どこから始めるか
    int Apos = 0, Bpos = i;
    while(Apos < A && Bpos < B){
      if(cardA[Apos] == cardB[Bpos]) Bpos++;
      Apos++;
    }
    ret = max( ret, Bpos - i);
  }
  cout << ret << endl;
}

Measured memory_bytes: 1232
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false); cin.tie(0)
#define int long long
#define ull unsigned long long
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF 0x3f3f3f3f

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;

int fac[maxn], inv[maxn];

int qpow(int a, int b) {//快速幂;
  int res = 1;
  while (b > 0) {
    if (b & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod;
    b >>= 1;
  }
  return res;
}

void pre(int n) {//预处理阶乘和逆元;
  fac[0] = inv[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac[i] = 1ll * fac[i - 1] * i % mod;
  }
  inv[n] = qpow(fac[n], mod - 2);
  for (int i = n - 1; i >= 1; i--) {
    inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  }
}

int C(int n, int m) {
  if (n < m || n < 0) return 0;
  return 1ll * fac[n] * inv[n - m] % mod * inv[m] % mod;
}
int n;
signed main() {
  IO;
  cin >> n;
  int ans = (qpow(10,n) - 2ll * qpow(9,n) % mod + mod ) % mod;
  ans = (ans + qpow(8,n)) % mod;
  ans %= mod;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int N;
    cin >> N;
    int dp[4][4][4][114]={};
    dp[0][0][0][0]=1;
    REP(m,N){
        REP(i,4){
            REP(j,4){
                REP(k,4){
                    REP(l,4){
                        if(j==1&&k==2&&l==3)continue;
                        if(j==1&&k==3&&l==2)continue;
                        if(j==2&&k==1&&l==3)continue;
                        if(i==1&&k==2&&l==3)continue;
                        if(i==1&&j==2&&l==3)continue;
                        (dp[j][k][l][m+1]+=dp[i][j][k][m])%=MOD;
                    }
                }
            }
        }
    }
    int Ans=0;
    REP(i,4){
        REP(j,4){
            REP(k,4){
                Ans=(Ans+dp[i][j][k][N])%MOD;
            }
        }
    }
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
N = []
S = []
M = []
while n != 0:
    N.append(n)
    s = list(map(int, input().split()))
    S.append(s)
    m = sum(s)/n
    M.append(m)
    n = int(input())
for i in range(len(N)):
    x = 0
    for j in range(N[i]):
        x += (S[i][j] - M[i])**2
    print((x/N[i])**0.5)


Measured memory_bytes: 5672
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<ll> p(a), q(b), r(c);
	rep (i, a) cin >> p[i];
	rep (i, b) cin >> q[i];
	rep (i, c) cin >> r[i];

	sort(rrng(p));
	sort(rrng(q));
	sort(rrng(r));

	priority_queue<ll> Q;
	rep (i, x) Q.push(-p[i]);
	rep (i, y) Q.push(-q[i]);

	ll ans = 0;
	rep (i, min(x + y, c)) {
		ll Oishi = Q.top();
		Oishi *= -1;
		Q.pop();
		if (Oishi < r[i]) {
			ans += r[i];
		}
		else {
			ans += Oishi;
			break;
		}
	}

	int szQ = Q.size();
	rep (i, szQ) {
		ll tmp = Q.top();
		Q.pop();
		ans += -1 * tmp;
	}

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

Measured memory_bytes: 4724
#include <stdio.h>

#define NODE (3000)
#define INF (100000000)

int v[NODE + 1];
int dist[NODE + 1];
int w[NODE + 1][NODE + 1];

int n, m, k;

int max(int a, int b)
{
    return (a > b ? a : b);
}

void dijkstra(int start)
{
    int i, j;
    int node;
    
    for (i = 1; i <= n; i++){
        v[i] = 0;
    }
    
    dist[start] = 0;
    
    while (1){
        node = -1;
        for (i = 1; i <= n; i++){
            if (v[i] == 0 && (node == -1 || dist[node] > dist[i])){
                node = i;
            }
        }
        
        if (node == -1){
            break;
        }
        
        v[node] = 1;
        
        for (i = 1; i <= n; i++){
            if (dist[i] > dist[node] + w[node][i] && v[i] == 0){
                dist[i] = dist[node] + w[node][i];
            }
        }
    }
}

int main(void)
{
    int i, j;
    int from, to, cost, res;
    
    scanf("%d%d%d", &n, &m, &k);
    
    for (i = 1; i <= n; i++){
        dist[i] = INF;
        for (j = 1; j <= n; j++){
            w[i][j] = INF;
            if (i == j){
                w[i][j] = 0;
            }
        }
    }
    
    for (i = 1; i <= m; i++){
        scanf("%d%d%d", &from, &to, &cost);
        w[from][to] = w[to][from] = cost;
    }
    for (i = 1; i <= k; i++){
        scanf("%d", &from);
        dist[from] = 0;
    }
    dijkstra(from);
    
    res = 0;
    
    for (i = 1; i <= n; i++){
        for (j = i + 1; j <= n; j++){
            if (w[i][j] != INF){
                res = max(res, (w[i][j] + dist[i] + dist[j] + 1) / 2);
            }
        }
    }
    
    printf("%d\n", res);
    
    return (0);
}

Measured memory_bytes: 36220
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func rs() string {
	sc.Scan()
	return sc.Text()
}

type pair struct {
	n int
	s string
	p int
}

type bySP []pair

func (a bySP) Len() int { return len(a) }

func (a bySP) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

func (a bySP) Less(i, j int) bool {
	if a[i].s == a[j].s {
		return a[i].p > a[j].p
	}
	return a[i].s < a[j].s
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()

	a := make([]pair, n)
	for i := 0; i < n; i++ {
		a[i] = pair{n: i + 1, s: rs(), p: ri()}
	}

	sort.Sort(bySP(a))

	for _, v := range a {
		fmt.Println(v.n)
	}
}


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

int main(){
    string stations;
    cin >> stations;
    int countA = 0;
    for(int i = 0; i < 3; i++){
        if( stations.at(i) == 'A'){
            countA++;
        }
    }
    if(countA == 3 || countA == 0){
        cout << "No" << endl;
    }else cout << "Yes" << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int n;
vector<LL> a,b;
LL tmp;
vector<LL> l,r;


int main(){
  cin>>n;
  REP(i,n){
    cin>>tmp;
    a.push_back(tmp);
    b.push_back(tmp);
  }

  sort(a.begin(),a.end());
  l.push_back(a[0]);
  a.erase(a.begin());
  bool bl=true;
  while(a.size()){
    if(bl){
      l.push_back(a[a.size()-1]);
      a.erase(a.end()-1);
      if(a.size()==0) break;
      r.push_back(a[a.size()-1]);
      a.erase(a.end()-1);
    }else{
      l.push_back(a[0]);
      a.erase(a.begin());
      if(a.size()==0) break;
      r.push_back(a[0]);
      a.erase(a.begin());
    }
    bl = !bl;
  }
  
  LL ret=0;
  REP(i,l.size()-1){
    ret+=abs(l[i]-l[i+1]);
  }
  if(r.size()>0){
    ret+=abs(l[0]-r[0]);
    REP(i,r.size()-1){
      ret+=abs(r[i]-r[i+1]);
    }
  }

  sort(b.begin(),b.end());
  l.resize(0);
  r.resize(0);
  l.push_back(b[b.size()-1]);
  b.erase(b.end()-1);
  bl=true;
  while(b.size()){
    if(bl){
      l.push_back(b[0]);
      b.erase(b.begin());
      if(b.size()==0) break;
      r.push_back(b[0]);
      b.erase(b.begin());
    }else{
      l.push_back(b[b.size()-1]);
      b.erase(b.end()-1);
      if(b.size()==0) break;
      r.push_back(b[b.size()-1]);
      b.erase(b.end()-1);
    }
    bl = !bl;
  }
  
  LL ret2=0;
  REP(i,l.size()-1){
    ret2+=abs(l[i]-l[i+1]);
  }
  if(r.size()>0){
    ret2+=abs(l[0]-r[0]);
    REP(i,r.size()-1){
      ret2+=abs(r[i]-r[i+1]);
    }
  }
  
  cout<<max(ret,ret2)<<endl;
  return 0;
}


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

const int maxn = (int)(1e6) + 5;
const int mo = (int)(1e9) + 7;

struct node{
	int x, y, z, w;
	node(int _x = 0, int _y = 0, int _z = 0, int _w = 0):x(_x), y(_y), z(_z), w(_w) {}
} p[maxn];

bool operator < (node a, node b) {
	return 0LL + a.x + a.y + a.z < 0LL + b.x + b.y + b.z;
}

bool operator == (node a, node b) {
	return a.x == b.x && a.y == b.y && a.z == b.z;
}

signed main() {
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	int tot = 0;
	for (int i = 0; i <= d; ++i) {
		if (i + 1 < a) p[++tot] = node(i, 1LL * b * (i + 1) / a, 1LL * c * (i + 1) / a, 0), p[++tot] = node(a - 2 - i, 1LL * b * (a - 1 - i) / a, 1LL * c * (a - 1 - i) / a, 0);
		if (i + 1 < b) p[++tot] = node(1LL * a * (i + 1) / b, i, 1LL * c * (i + 1) / b, 1), p[++tot] = node(1LL * a * (b - 1 - i) / b, b - 2 - i, 1LL * c * (b - 1 - i) / b, 1);
		if (i + 1 < c) p[++tot] = node(1LL * a * (i + 1) / c, 1LL * b * (i + 1) / c, i, 2), p[++tot] = node(1LL * a * (c - 1 - i) / c, 1LL * b * (c - 1 - i) / c, c - 2 - i, 2);
	}
	sort(p + 1, p + tot + 1);
	tot = unique(p + 1, p + tot + 1) - p - 1; p[++tot] = node(a - 1, b - 1, c - 1);
	int res = 1LL * (min(a - 1, d) + 1) * (min(b - 1, d) + 1) * (min(c - 1, d) + 1) % mo;
	for (int i = 1; i < tot; ++i) {
		int dX = 1LL * (p[i + 1].x - p[i].x) * (p[i].x + d + 1 < a ? 1LL * (min(b - 1, p[i + 1].y + d) - max(0, p[i + 1].y - d) + 1) * (min(c - 1, p[i + 1].z + d) - max(0, p[i + 1].z - d) + 1) % mo : 0) % mo;
		int dY = 1LL * (p[i + 1].y - p[i].y) * (p[i].y + d + 1 < b ? 1LL * (min(a - 1, p[i + 1].x + d) - max(0, p[i + 1].x - d) + 1) * (min(c - 1, p[i + 1].z + d) - max(0, p[i + 1].z - d) + 1) % mo : 0) % mo;
		int dZ = 1LL * (p[i + 1].z - p[i].z) * (p[i].z + d + 1 < c ? 1LL * (min(a - 1, p[i + 1].x + d) - max(0, p[i + 1].x - d) + 1) * (min(b - 1, p[i + 1].y + d) - max(0, p[i + 1].y - d) + 1) % mo : 0) % mo;
		res += (0LL + dX + dY + dZ) % mo; if (res >= mo) res -= mo;
	}
	return printf("%d\n", res), 0;
}

Measured memory_bytes: 15872
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;

string S;

int ans = 0;

void solve(){
	for(int i=0;i<S.length();i++){
		S[i] = 'x';
	}
}
 
int main(){
	cin >> S;
 
	solve();

	cout << S <<endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {

	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	A := nextInt()
	B := nextInt()
	C := nextInt()
	X := nextInt()

	cnt := 0
	for a := 0; a < A+1; a++ {
		for b := 0; b < B+1; b++ {
			for c := 0; c < C+1; c++ {
				if a*500+b*100+c*50 == X {
					cnt += 1
				}

			}
		}
	}
	fmt.Println(cnt)

}


Measured memory_bytes: 640
import sys
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[2147483647]*(n+1)
h.insert(0,0)
dp[0]=0
dp[1]=0
dp[2]=abs(h[2]-h[1])
for i in range(3,n+1):
    for j in range(i-1,max((i-k-1),0),-1):
        dp[i]=min(dp[i],abs(h[i]-h[j])+dp[j])
print(dp[n])



Measured memory_bytes: 52448
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define ull unsigned long long
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define FOR(i,start,stop)  for(int i=(start); i < (stop); i++)
#define FORD(i,start,stop) for(int i=(start); i >= (stop); i--)
#define RIP(i,stop) FOR(i,0,stop)
#define PI 3.141592653589793
#define PRECISION(c,f) fixed << setprecision(c) << f
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,l; cin >> n >> l;
  string a;
  vector<string> s;
  RIP(i,n) {
    cin >> a;
    s.push_back(a);
  }

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

  string ans;

  RIP(i,n)
    ans += s[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
    double x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    cout<<fixed<<setprecision(8)<<sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))<<endl;
    return 0;
}



Measured memory_bytes: 3284
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
	int n, x[100], sum = 0, min = 1000000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	sort(x, x + n);
	for (int i = x[0]; i <= x[n - 1]; i++) {
		sum = 0;
		for (int j = 0; j < n; j++) {
			sum += (x[j] - i) * (x[j] - i);
		}
		if (min > sum) {
			min = sum;
		}
	}
	cout << min << endl;

	return 0;
}

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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m,a,b;
    cin>>a>>b;
    n=min(a,b);
    m=max(a,b);
    for(int i=0;i<m;i++){
        cout<<n;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N = int(input())
A = list(map(int, input().split()))

sum_abs = 0
min_abs = 10 ** (9)
count_minus = 0
for i in range(N):
	if A[i] < 0:
		count_minus += 1
		sum_abs -= A[i]
		if -A[i] < min_abs:
			min_abs = -A[i]
	else:
		sum_abs += A[i]
		if A[i] < min_abs:
			min_abs = A[i]

if count_minus % 2 == 0:
	print(sum_abs)
else:
	print(sum_abs - 2 * min_abs)
	

Measured memory_bytes: 60272
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;

class DandA {
    static void Main(string[] args) {
        int[] ab = ReadLineIntArray();
        if (ab[0] > 9 || ab[1] > 9) {
            Console.WriteLine(-1);
        } else {
            Console.WriteLine(ab[0] * ab[1]);
        }
    }

    static string[] ary = new string[] {"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", "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"};
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private double[] ReadLineDoubleArray() {return Console.ReadLine().Trim().Split().Select(a => double.Parse(a)).ToArray();}
    static private decimal[] ReadLineDecimalArray() {return Console.ReadLine().Trim().Split().Select(a => decimal.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}

    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
}

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

const int INF=1e9+5;
const int N=1000+5;
const int mod=1e9+7;

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

char a[N][N];

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	// freopen("input.txt","r",stdin);
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			cin>>a[i][j];
		}
	}
	vector<vector<int>> dp(h,vector<int>(w));
	dp[0][0]=1;
	for(int row=0;row<h;++row){
		for(int col=0;col<w;++col){
			for(int r2:{row,row+1}){
				int c2=col;
				if(r2==row){
					c2=col+1;
				}
				if(r2<h&&c2<w&&a[r2][c2]=='.'){
					add(dp[r2][c2],dp[row][col]);
				}
			}
		}
	}
	cout<<dp[h-1][w-1];
	return 0;
}
		


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

#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(int i=a ; i<=b ; i++)
#define FORD(i,a,b) for(int i=a ; i>=b ; i--)
#define INF 1000000000
#define ll long long int
#define eps (1e-8)
#define sq(x) ( (x)*(x) )
#define all(x) x.begin(),x.end()
#define flog2(n) 64 - __builtin_clzll(n) - 1
#define popcnt(n) __builtin_popcountll(n)

using namespace std;

typedef pair < int, int > pii;
typedef pair < ll, ll > II;

ll d[200005];

ll st[200005 * 4], lz[200005 * 4];

void down(int id, int l, int r) {
	if (l == r || !lz[id]) return;

	st[id * 2] += lz[id];
	lz[id * 2] += lz[id];

	st[id * 2 + 1] += lz[id];
	lz[id * 2 + 1] += lz[id];

	lz[id] = 0;
}

void update(int id, int l, int r, int u, int v, ll k) {
	if (v < l || r < u) return;
	if (u <= l && r <= v) {
		st[id] += k;
		lz[id] += k;
		return;
	}

	int mid = (l + r) / 2;
	down(id, l, r);

	update(id * 2, l, mid, u, v, k);
	update(id * 2 + 1, mid + 1, r, u, v, k);

	st[id] = max(st[id * 2], st[id * 2 + 1]);
}

ll getMax(int id, int l, int r, int u, int v) {
	if (v < l || r < u) return -1e18;
	if (u <= l && r <= v) return st[id];

	int mid = (l + r) / 2;
	down(id, l, r);

	return max(getMax(id * 2, l, mid, u, v), getMax(id * 2 + 1, mid + 1, r, u, v));
}

vector<II> leftInt[200005];
vector<II> rightInt[200005];

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

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

    FOR (i, 1, m) {
    	int l, r;
    	ll a;
    	cin >> l >> r >> a;

    	leftInt[l].pb(II(r, a));
    	rightInt[r].pb(II(l, a));
    }

    ll res = 0;

    FOR (i, 1, n) {
    	for (auto j: leftInt[i]) {
    		update(1, 0, n, 0, i - 1, j.second);
    	}

    	d[i] = getMax(1, 0, n, 0, i - 1);

    	update(1, 0, n, i, i, d[i]);

    	for (auto j: rightInt[i]) {
    		update(1, 0, n, 0, j.first - 1, -j.second);
    	}

    	res = max(res, d[i]);
    }

    cout << res << endl;
    
		
    return 0;
}

Measured memory_bytes: 36224