akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    int ans=0;
    int kai=0;
    rep(i,n-2){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if(a[i]<a[j]+a[k]){
                    ans++;
                }
                else{
                    kai=1;
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
int h, w;
string s[55];
int dot_num = 0;
int dis[55][55];
/**********************************************/

void bfs(int x, int y, int num){
    if(y+1 < h && dis[y+1][x] > num && s[y+1][x] == '.'){
        dis[y+1][x] = num;
        bfs(x, y+1, num+1);
    }
    if(y-1 >= 0 && dis[y-1][x] > num && s[y-1][x] == '.'){
        dis[y-1][x] = num;
        bfs(x, y-1, num+1);
    }
    if(x+1 < w && dis[y][x+1] > num && s[y][x+1] == '.'){
        dis[y][x+1] = num;
        bfs(x+1, y, num+1);
    }
    if(x-1 >= 0 && dis[y][x-1] > num && s[y][x-1] == '.'){
        dis[y][x-1] = num;
        bfs(x-1, y, num+1);
    }
    return;
}

signed main(){
    cin >> h >> w;
    REP(i, h) cin >> s[i];
    REP(i, h){
        REP(j, w){
            if(s[i][j] == '.') dot_num++;
        }
    }
    REP(i, 55){
        REP(j, 55){
            dis[i][j] = INF;
        }
    }
    dis[0][0] = 1;
    bfs(0, 0, 2);
    if(dis[h-1][w-1] != INF) cout << dot_num -  dis[h-1][w-1] << endl;
    else cout << -1 << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    ll x,t;cin>>x>>t;
    cout<<max(0LL,x-t)<<endl;
}


Measured memory_bytes: 256
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve = show . length . nub . words

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 380
#include <bits/stdc++.h>
#include <cstring> 
using namespace std;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define int long long int
#define mpp make_pair
#define F first
#define mem(a,b) memset(a,b,sizeof(a))
#define F first
#define S second
#define MOD 100007
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
const int MAXN = 1e6+1;
#define MAXI 2e18+3
#define all(v) v.begin(), v.end()
#define endl "\n"
# define PI 3.14159265358979323846

int cnt[200];


signed main(){
 
    fast;
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    int n, k, i;
    cin>>n>>k;
    while(k--){
    	int d;
    	cin>>d;
    	while(d--){
    		int a;
    		cin>>a;
    		cnt[a]++;
    	}
    }
    int c=0;
    for(i=1;i<=n;i++){
    	if(cnt[i]==0){
    		c++;
    	}
    }
    cout<<c<<endl;
}

Measured memory_bytes: 3704
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int W,H,N;
    while(cin >> W >> H >> N){
        int x1 = 0,x2 = W,y1 = 0,y2 = H;
        int buf;
        int x0,y0;
        for(int i = 1;i <= N;++i){
            cin >> x0 >> y0 >> buf;
            if(buf == 1) x1 = max(x0,x1);
            else if(buf == 2) x2 = min(x0,x2);
            else if(buf == 3) y1 = max(y1,y0);
            else if(buf == 4) y2 = min(y0,y2);
        }
        if(x2-x1 < 0||y2-y1 < 0) cout << 0 << endl;
        else cout << (x2-x1)*(y2-y1) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 998244353;
using ll = long long;
using P = pair<ll, ll>;
double PI = acos(-1);

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    deque<int> d;

    rep(i,n) {
        int p = lower_bound(d.begin(), d.end(), a[i])- d.begin();
        if(p==0) {
            d.push_front(a[i]);   
        }else {
            d[p-1]=a[i];
        }
    }

    cout << d.size() << endl;
    
    return 0;
}



Measured memory_bytes: 4760
#include <iostream>
using namespace std;
int main() {
   char s[100];
   int i;
   cin>>s;
   for(i=0;i<3;i++)
   {
       if(s[i]=='7')
       {
           cout<<"Yes"<<endl;
           break;
       }
       else
       {
           if(i==2)
               cout<<"No"<<endl;
       }
   }
    return 0;
}

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


Measured memory_bytes: 256
import math
N=int(input())
A=math.floor(N/1.08)
B=math.floor(A*1.08)
if B==N:
  print(A)
else:
  B=math.floor((A+1)*1.08)
  if B==N:
    print(A+1)
  else:
    print(":(")





Measured memory_bytes: 2940
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

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

	string S;
	cin >> S;

	if (S == "ABC") {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}

	return 0;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
  int i;
  char s[110];
  cin >> s;
  for(i=0;i<110 && s[i]!='\0';i++){
    if((i%2 == 0 && s[i] == 'L')||(i%2 == 1 && s[i] == 'R')){
      cout << "No" << endl;
      return 0;
      }
    }
  cout << "Yes" << endl;
  }

Measured memory_bytes: 256
# coding: utf-8


def solve(arg: str) -> str:
    h, w, a, b = map(int, arg.split())
    mat = [[0] * w for _ in range(h)]
    sumy = [0] * w

    for y in range(h):
        sumx = 0
        for x in range(w):
            if(
                (sumy[x] < b and sumx < a) or
                (sumy[x] < h - b and sumx < a) or
                (sumy[x] < b and sumx < w - a) or
                (sumy[x] < h - b and sumx < w - a)
            ):
                mat[y][x] = 1
                sumx += 1
                sumy[x] += 1
        if(min(sumx, w - sumx) != a):
            return 'No'

    for s in sumy:
        if(min(s, h - s) != b):
            return 'No'

    ret = ''
    for y in range(h):
        for x in range(w):
            ret += str(mat[y][x])
        if(y != h-1):
            ret += '\n'

    return ret


if __name__ == "__main__":
    print(solve(input()))


Measured memory_bytes: 12916
import std.algorithm;
import std.array;
import std.bigint;
import std.bitmanip;
import std.conv;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

T[] readToArray(T)() {
    return readln.split.to!(T[]);
}

void readInto(T...)(ref T ts) {
    auto ss = readln.split;
    foreach(ref t; ts) {
        t = ss.front.to!(typeof(t));
        ss.popFront;
    }
}

void main() {
    ulong n;
    readInto(n);
    ulong[] p = readToArray!(ulong);
    ulong cnt = 0;

    for(ulong i = 1; i < p.length-1; i++) {
        //writefln("%d %d %d", p[i-1], p[i], p[i+1]);
        if(p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
        else if (p[i+1] < p[i] && p[i] < p[i-1]) cnt++;
    }
    writeln(cnt);
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <queue>

using namespace std;

#define N 3
#define N2 9

struct Puzzle {
  int field[N2];
  int blank;
  int count;

  bool operator < (const Puzzle &p) const {
    int i;
    
    for (i = 0; i < N2; i++) {
      if (field[i] == p.field[i]) continue;
      return field[i] > p.field[i];
    }
    return false;
  }
};

bool isTrue(Puzzle p);
int bfs(Puzzle s);

int x[4] = {-1, 0, 1, 0};
int y[4] = {0, -1, 0, 1};

int main() {
  Puzzle input;
  int i;

  for (i = 0; i < N2; i++) {
    cin >> input.field[i];
    if (input.field[i] == 0) {
      input.field[i] = N2;
      input.blank = i;
    }
  }

  cout << bfs(input) << endl;

  return 0;
}

bool isTrue(Puzzle p) {
  int i;
  
  for (i = 0; i < N2; i++) {
    if (p.field[i] != i + 1) return false;
  }
  return true;
}

int bfs(Puzzle s) {
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u, v;
  int x1, y1, x2, y2, i;
  s.count = 0;
  Q.push(s);
  V[s] = true;

  while (!Q.empty()) {
    u = Q.front();
    Q.pop();
    if (isTrue(u)) return u.count;
    x1 = u.blank / N;
    y1 = u.blank % N;
    for (i = 0; i < 4; i++) {
      x2 = x1 + x[i];
      y2 = y1 + y[i];
      if (!(x2 >= 0 && y2 >= 0 && x2 < N && y2 < N)) continue;
      v = u;
      swap(v.field[u.blank], v.field[x2 * N + y2]);
      v.blank = x2 * N + y2;
      if (!V[v]) {
	V[v] = true;
	v.count++;
	Q.push(v);

      }
    }
  }
}



Measured memory_bytes: 20488
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val Array(a, b, x) = new BufferedReader(new InputStreamReader(System.in)).readLine().split("\\s+").map(_.toDouble)

    val h = x / a / a

    val degree = Math.toDegrees(Math.atan(
      if (b < h * 2) {
        (b - h) * 2.0 / a
      } else {
        b * b / a / h / 2.0
      }
    ))

    System.out.println(f"$degree%2.10f")
  }
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;


int main() {
    int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    rep(i, n-1) {
        if (a[i] == a[i+1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    
    return 0;
}


    


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int h, w, n, x, y, a, p[111][111], res;

signed main() {
	cin >> w >> h >> n;
	while (n--) {
		cin >> x >> y >> a;
		if (a==1) rep(i,h) rep(j,x) p[i][j] = 1;
		if (a==2) rep(i,h) reps(j,x,w) p[i][j] = 1;
		if (a==3) rep(i,y) rep(j,w) p[i][j] = 1;
		if (a==4) reps(i,y,h) rep(j,w) p[i][j] = 1;
	}
	rep(i,h) rep(j,w) res += p[i][j]==0;
	cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
 
 
void swap (int *x, int *y) {
  int temp;    
 
  temp = *x;
  *x = *y;
  *y = temp;
}
 
int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }
 
  if(b==0){
    return a;
  }
 
  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }
 
  return b;
}
 
/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}
 
 
int modpow(int a,int n,int mod){
  int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}
 
int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}
 
int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}
 
void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }
 
  return;
}
 
void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }
 
  return;
}
 

int main(void){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(a*b<c*d){
    printf("%d\n",c*d);
  }else{
    printf("%d\n",a*b);
  }
  return 0;
}

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

int main()
{
	int n, count;
	while (cin>>n, n) {
		count = 0;
		while (n != 1) {
			count++;
			if (n&1) n = 3*n+1;
			else n /= 2;
		}
		cout<<count<<endl;
	}
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vd vector<double>
#define vull vector<ull>
#define vc vector<char>
#define vs vector<string>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int t; cin >> t; for(int cs = 1; cs <= t; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ld long double
#define reset(x,y) memset(x,y,sizeof x);
#define sqr(x) 1LL*(x)*(x)
#define cube(x) 1LL*(x)*(x)*(x)
#define ub(v, a) upper_bound(all(v), a)
#define lb(v, a) lower_bound(all(v), a)
#define EPS 1e-10
#define INF 2000000000
#define mod 1000000007
#define minof(a) min_element(all(a))
#define maxof(a) max_element(all(a))
#define debug(val) cerr << "The value of " << #val << " is = " << val << endl;
#define testing cerr << "--------------------------\n";

//input space ---> scanf("%[^\n]%*c",s);

ll dp[100005],a[100005],n;

int main() {
	IOS
	cin >> n;
	fori(i,1,n,1) {
		cin >> a[i];
	}
	dp[1] = 0;
	dp[2] = abs(a[1]-a[2]);
	fori(i,3,n,1) {
		dp[i] = min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
	}
	cout << dp[n] << endl;
}


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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int Mod = 1e9 + 7;

inline int fpm(LL b, int e, int m)
{
	b %= m;
	LL t = 1;
	for ( ; e; e >>= 1, (b *= b) %= m)
		if (e & 1) (t *= b) %= m;
	return t;
}

const int maxn = 3000100;

int fac[maxn + 5], ifac[maxn + 5];

inline void prepare()
{
	fac[0] = 1;
	REP(i, 0, maxn) fac[i + 1] = (LL)fac[i] * (i + 1) % Mod;
	ifac[maxn] = fpm(fac[maxn], Mod - 2, Mod);
	for (int i = maxn - 1; i >= 0; --i) ifac[i] = (LL)ifac[i + 1] * (i + 1) % Mod;
}

inline int calc(int x, int y) { return (LL)fac[x + y] * ifac[x] % Mod * ifac[y] % Mod; }

int x[6], y[6];

int work(int xl, int xr, int yl, int yr, int dx, int dy)
{
	int _ret = 0;
	REP(i, xl, xr + 1)
		REP(j, yl, yr + 1)
			(_ret += (LL)calc(i, j) * calc(dx - i, dy - j) % Mod) %= Mod;
	int ret = 0;
	REP(i, 0, xr - xl + yr - yl + 2)
	{
		int tmpx = -1, tmpy = -1;
		if (i <= xr - xl) 
		{
			tmpx = xl + i, tmpy = yl;
			(ret += (LL)calc(tmpx, tmpy - 1) * calc(dx - tmpx, dy - tmpy) % Mod * (dx + dy - tmpx - tmpy + 1) % Mod) %= Mod;
		}
		else 
		{
			tmpx = xl, tmpy = yl + i - (xr - xl) - 1;
			(ret += (LL)calc(tmpx - 1, tmpy) * calc(dx - tmpx, dy - tmpy) % Mod * (dx + dy - tmpx - tmpy + 1) % Mod) %= Mod;
		}
		if (i <= xr - xl) 
		{
			tmpx = xr - i, tmpy = yr;
			(ret -= (LL)calc(tmpx, tmpy) * calc(dx - tmpx, dy - tmpy - 1) % Mod * (dx + dy - tmpx - tmpy) % Mod) %= Mod;
		}
		else 
		{
			tmpx = xr, tmpy = yr - (i - (xr - xl) - 1);
			(ret -= (LL)calc(tmpx, tmpy) * calc(dx - tmpx - 1, dy - tmpy) % Mod * (dx + dy - tmpx - tmpy) % Mod) %= Mod;
		}
	}
	return ret;
}

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	prepare();
	REP(i, 0, 6) scanf("%d", x + i);
	REP(i, 0, 6) scanf("%d", y + i);
	int ans = 0;
	REP(i, 0, 4) REP(j, 0, 4)
	{
		int coe = 1;
		int ux, uy, vx, vy;
		if (!(i & 1)) ux = x[0] - 1;
		else ux = x[1], coe = -coe;
		if (!(i >> 1)) uy = y[0] - 1;
		else uy = y[1], coe = -coe;
		if (!(j & 1)) vx = x[5] + 1;
		else vx = x[4], coe = -coe;
		if (!(j >> 1)) vy = y[5] + 1;
		else vy = y[4], coe = -coe;
		(ans += work(x[2] - ux, x[3] - ux, y[2] - uy, y[3] - uy, vx - ux, vy - uy) * coe) %= Mod;
	}
	(ans += Mod) %= Mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

long long SOD(long long n){
    long long sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

signed main(){
    int k;
    cin >> k;
    vector<ll> cand;
    for(int i = 0; i < 1000; i++){
        string t;
        for(int j = 0; j <= 15; j++){
            cand.emplace_back(stoll(to_string(i) + t));
            t.push_back('9');
        }
    }
    sort(ALL(cand));
    reverse(ALL(cand));
    cand.erase(unique(ALL(cand)), cand.end());
    vector<ll> ans;
    double mn = LINF;
    for(ll n : cand){
        double t = (double)n / (double)SOD(n);
        if(t <= mn) ans.emplace_back(n);
        mn = min(mn, t);
    }
    sort(ALL(ans));
    rep(i,k){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef map<int,int> mi;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N;
int a[100010];
int main(){
  cin>>N;
  rep(i,N) cin>>a[i];
  bool f=true;
  if(N%3==0){
    mi m;
    rep(i,N) m[a[i]]++;
    if(m.size()==3){
      int x=0;
      for(auto itr=m.begin();itr!=m.end();itr++){
	x=x^itr->first;
	if(itr->second!=N/3){
	  f=false;
	  break;
	}
      }
      if(x!=0) f=false;
    }
    else if(m.size()==2){
      for(auto itr=m.begin();itr!=m.end();itr++){
	if(itr->first==0){
	  if(itr->second!=N/3){
	    f=false;
	    break;
	  }
	}
	else{
	  if(itr->second!=2*N/3){
	    f=false;
	    break;
	  }
	}
      }
    }
    else if(m.size()==1){
      if(m[0]==0) f=false;
    }
    else f=false;
  }
  else{
    rep(i,N){
      if(a[i]!=0){
	f=false;
	break;
      }
    }
  }
  if(f) prin("Yes");
  else prin("No");
  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    if(s[5] != '1' && (s[6] == '1' || s[6] == '2' || s[6] == '3' || s[6] == '4')){
        cout << "Heisei" << endl;
    }
    else{
        cout << "TBD" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

template<typename T>bool chkmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool chkmin(T &a,T b){return (a>b)?a=b,1:0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int n,k;
int vis[4005][4005];
int ed[4005];
int g[4005];
int tot;
int dp[4005][4005][2],ff[4005];
const int mod=924844033;
int main () {
#ifndef ONLINE_JUDGE
//file("agc005d");
#endif
     n=read();
	 k=read();
	 ff[0]=1;
	 F(i,1,2*n)ff[i]=1ll*i*ff[i-1]%mod;
     F(i,1,n){
	   F(j,0,1){
	     if(!vis[i][j]){int len=0;
		 for(int x=i,y=j;x<=n;x+=k,y^=1)vis[x][y]=1,++len;
                ed[tot+=len]=1;
	   }
	   }
	 }
	 dp[1][0][0]=1;
	 F(i,1,tot){
	   F(j,0,n){
	      dp[i+1][j][0]=(dp[i][j][0]+dp[i][j][1])%mod;
            if(!ed[i])dp[i+1][j+1][1]=dp[i][j][0];
	   }
	 }
	 F(i,0,n)g[i]=(dp[tot][i][0]+dp[tot][i][1])%mod;
     int ans=ff[n];
	 F(i,1,n){
	     if(i&1)ans=(ans-1ll*ff[n-i]*g[i]%mod+mod)%mod;
		 else ans=(ans+1ll*ff[n-i]*g[i]%mod)%mod;
	 }
	 printf("%d\n",ans);
	 return 0;
}

Measured memory_bytes: 157184
import java.util.Scanner;



public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y=sc.nextInt();
		String s=sc.next();

		String b = s.substring(y-1,x);
		String as=s.substring(0,y-1);
		String c = b.substring(0,1);
		String ac=c.toLowerCase();
      String ab=s.substring(y,x);
		System.out.println(as+ac+ab);




	}
}




Measured memory_bytes: 21332
import math

N = int(input())

a = int(round(N / 1.08))
b = a + 1
#print(a, b)

A = int(math.floor(a*1.08))
B = int(math.floor(b*1.08))
#print(A, B)

if A == N:
    print(a)
elif B == N:
    print(b)
else:
    print(":(")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((c + d) % 2 == 1 and a * b % 2 == 1)cout << "No" << endl;
	else cout << "Yes" << endl;
}





Measured memory_bytes: 3112
S = input()


char_list = list(S)


num=0
res = True # good
for c in char_list:
        num+=1
        if num%2 != 0 :
                if c in  ["R","U","D"]:
                        continue
        else:
                if c in  ["L","U","D"]:
                        continue
        res =False
        break

if res:
        print("Yes")
else:
        print("No")


Measured memory_bytes: 2940
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		List<Integer> list = new ArrayList<>();

		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a >= 13) {
			System.out.println(b);
		} else if (a <= 5) {
			System.out.println(0);

		} else {
			System.out.println(b / 2);

		}
	}
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  sort(rALL(h));
  ll ans = INF64;
  rep(i, n-k+1) chmin(ans, h[i]-h[i+k-1]);
  cout << ans << endl;
}

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

int main() {
    long int a, b, c, k;
    long int max_sum = 0;
    cin >> a >> b >> c >> k;

    if(k <= a)
    {
        max_sum = k;
    }
    else
    {
        max_sum = a;
        if(k > (a+b))
        {
            max_sum -= (k-(a+b));
        }
    }
    cout << max_sum << endl;

    return 0;
}



Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int x1 = sc.nextInt();
        int y1 = sc.nextInt();
        int x2 = sc.nextInt();
        int y2 = sc.nextInt();
        int xx = x2 - x1;
        int yy = y2 - y1;
        System.out.println((x2 - yy) + " " + (y2 + xx) + " " + (x1 - yy) + " " + (y1 + xx));
    }


}




Measured memory_bytes: 21716
#include <stdio.h>

int main(void){
  int i, j, n, m;
  int W[300], H[300];
  for(n=0 ; ; n++){
    scanf("%d %d",&H[n],&W[n]);
    if(H[n]==0 && W[n]==0){
      m=n;
      break;
    }
  }
  for(n=0 ; n<m ; n++){
    for(i=0 ; i<H[n] ; i++){
      for(j=0 ; j<W[n] ; j++){
	if(i%2==0 && j%2==0){
	  printf("#");
	}else if(i%2==0 && j%2==1){
	  printf(".");
	}else if(i%2==1 && j%2==0){
	  printf(".");
	}else{
	  printf("#");
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    long a = scanner.nextLong();
    long b = scanner.nextLong();
    long x = scanner.nextLong();
    
    long count = b / x;
    
    if(a == 0L) {
      count++;
    } else {
      count -= (a - 1L) / x;
    }
    
    System.out.println(count);
  }
}

Measured memory_bytes: 35888
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxn 100005
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
const int infi=1e15+7;
void printVector(vector<int> v){
    for(int i=0;i<(int)v.size();i++)
        cout<<v[i]<<" ";
    out endl;
}

void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
 vi prime_number;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
           primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
//for making unordered_map with pair
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
int32_t main()
{
fastio;
int s,w;
cin>>s>>w;
if(w>=s) out "unsafe";
else out "safe";
    return 0;
}

/*
google kick start
  cout << "Case #" << tt << ": "<<ans<<endl;
*/


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)


constexpr ll mod_number = 1000000000+7;

ll repeatSquare(ll a,ll n,ll mod){
	ll answer = 1;

	while(n > 0){
		if(n & 1){	//nが奇数なら先に答えの方にa^1をかけておく事で残りのa^n-1を2分割できるようにしている
			answer = answer * a % mod;
		}
		a = a * a % mod;
		n = n>>1;	//nを2で割ると同じ
	}
	return answer;
}

int main(){

	ll n, a, b;
	cin>>n>>a>>b;

	ll enable_hanataba = (repeatSquare(2,n,mod_number) - 1) % mod_number;

	ll nCa = 1;	
	ll nCb = 1;	
	
	for(ll i = 0; i < a; i++){
		nCa = nCa * (n-i) % mod_number;
		nCa = nCa * (repeatSquare(i+1,mod_number-2,mod_number) % mod_number) % mod_number;
	}	
	for(ll i = 0; i < b; i++){
		nCb = nCb * (n-i) % mod_number;
		nCb = nCb * (repeatSquare(i+1,mod_number-2,mod_number) % mod_number) % mod_number;
	}
	//cout<<enable_hanataba<<endl;
	//cout<<nCa<<" : "<<nCb<<endl;
	
	ll ans = enable_hanataba - (nCa + nCb)%mod_number;
	
	if(ans < 0)ans = ans + mod_number;
	cout<<ans<<endl;
	return 0;
}


//(2^n-1) - nCa - nCb : 0本の花束は存在しないので
//
//rei : 15 - 4 - 4 = 7
//
//nCa = n
//
//
//15 % 2 = (30 / 2 )% 2 =  (30%2 / 2) % 2


Measured memory_bytes: 256
S,dum=gets.chomp.split(' ').map{|n| n}
l = S.size
w = l
0.upto(l-2){|i|
	if(S[i]!=S[i+1])
		a = S.size - (i+1)
		b = i+1
		c = a > b ? a : b
		w = w > c ? c : w
	end
}
puts w


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 3e18+7
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B;
    cin>>A>>B;
    cout<<max({A+B,A*B,A-B})<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

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

  ll ans = ((A <= 9) && (B <= 9)) ? A * B : -1;

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


Measured memory_bytes: 256
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static Scanner s=new Scanner(System.in);
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n) {return REPS(n).map(i->getInt());}
	static int getInt(){return Integer.parseInt(s.next());}
	static class Pair<T,U>{
		T l;U r;
		Pair(T L,U R){l=L;r=R;}
		T getL(){return l;}
		U getR(){return r;}
	}
	public static void main(String[]$){
		int n=getInt(),a[]=INS(n*3).toArray();
		PriorityQueue<Integer>left=new PriorityQueue<>(),right=new PriorityQueue<>();

		long[]lres=new long[n+1];
		{
			for(int i=0;i<n;++i) {
				int v=a[i];
				lres[0]+=v;
				left.add(v);
			}
			for(int i=1;i<=n;++i) {
				int v=a[n+ i-1];
				left.add(v);
				lres[i]=lres[i-1]+v-left.poll();
			}
			//System.out.println(Arrays.toString(lres));
		}

		long[]rres=new long[n+1];
		{
			for(int i=0;i<n;++i) {
				int v=-a[n*3-1 -i];
				rres[0]+=v;
				right.add(v);
			}
			for(int i=1;i<=n;++i) {
				int v=-a[n*2   -i];
				right.add(v);
				rres[i]=rres[i-1]+v-right.poll();
			}
			//System.out.println(Arrays.toString(rres));
		}
		System.out.println(
				REPS(n+1)
				.mapToLong(i->lres[i]+rres[n-i])
				.max().getAsLong()
				);
	}
}

Measured memory_bytes: 65744
#include<bits/stdc++.h>
typedef long long int LL;
typedef long double dd; 
#define endl "\n"
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
LL dp[2000001];
LL mod=1e9+7;
using namespace std;
bool isPrime(LL n) {
  LL j; 
  for( j=2;j<=sqrt(n);j++){
    if(n%j==0){
      break;  
    } 
  }
  if(j>sqrt(n)){
    return 1; 
  }
  else{
    return 0; }
}
 void solve(LL k){
 LL n,d,c=0; 
 cin>>n>>d;
 while(n--){
   LL x, y;
   cin>>x>>y; 
   dd z=sqrt((x*x)+(y*y));
 if(z<=d){
   c++;
 }
 }
cout<<c<<endl; 
 
 }
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
// LL t;
//cin>>t;
 LL k=1;
//while(k<=t){
   solve(k);
//  k++;
 // }
   return 0;
   }

Measured memory_bytes: 3688
#include <iostream>
#include <vector>

using vi = std::vector<int>;

int Partition(vi& target, int iP, int iR);
void solve();

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

int Partition(vi& target, int iP, int iR)
{
    using namespace std;

    int x = target[iR];
    int i = iP - 1;

    for (int j = iP; j < iR; ++j)
    {
        if (target[j] <= x)
        {
            swap(target[++i], target[j]);
        }
    }
    
    swap(target[++i], target[iR]);

    return i;
}

void solve()
{
    using namespace std;

    int n;
    cin >> n;
    vi v(n);

    for (auto& x : v)
        cin >> x;

    int index = Partition(v, 0, v.size() - 1);

    for (int i = 0; i < v.size(); ++i)
    {
        if (i == index)
            cout << "[" << v[i] << "]";
        else
            cout << v[i];

        if (i + 1 != v.size())
            cout << " ";
    }

    cout << endl;
}


Measured memory_bytes: 3144
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#define _USE_MATH_DEFINENS
#include <cmath>
using namespace std;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = max((a * b), (c * d));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
 
#define INF 1000000000
 
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

long N;
long L[101];

int comp(const void *x, const void *y) {
	const long* a=(const long*)x;
	const long* b=(const long*)y;
	if(*a>*b)return 1;
	if(*a<*b)return -1;
	return 0;
}

int main() {
	long i, j;
	long ans = 0;
	
	scanf("%ld", &N);
	for(i=0;i<2*N;i++) {
		scanf("%ld", &L[i]);
	}
	
	qsort((void *)L, 2*N, sizeof(long), comp);
	
	for(i=0;i<2*N;i+=2) {
		ans += L[i];
	}
	
	printf("%ld\n", ans);
	
	return 0;
}

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

using namespace std;

int arr[123456][3];
int dp[123456][3];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >>arr[i][0] >> arr[i][1] >> arr[i][2];
    }

    dp[1][0] = arr[1][0];
    dp[1][1] = arr[1][1];
    dp[1][2] = arr[1][2];

    for (int i = 2; i <= n; i++) {
        dp[i][0] = max(dp[i-1][1] , dp[i-1][2])+arr[i][0];
        dp[i][1] = max(dp[i-1][2] , dp[i-1][0])+arr[i][1];
        dp[i][2] = max(dp[i-1][0] , dp[i-1][1])+arr[i][2];
    }
    cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main(){
    int n,ans=1;
    cin>>n;
    vector <string> s(n);
    rep(i,n)
    cin>>s.at(i);
    sort(s.begin(),s.end());
    rep(i,n-1){
        if(s.at(i)!=s.at(i+1))
        ++ans;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9568
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        String s=gs();

        
	    
	    
        System.out.println(s.replace("2017", "2018"));
//        if (a+b>c+d) {
//        	System.out.print("Left");
//        }else if(a+b==c+d){
//        	System.out.print("Balanced");
//        }else {
//        	System.out.print("Right");
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
	
	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll digsum(ll n){
    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

int main()
{
    string s,t;
    cin >> s >> t;

    ll ans = 0;
    rep(i,3){
        if(s[i] == t[i])ans++;
    }

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

Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  int n, c; readV(n, c);
  struct R { int s, t, c; }
  R[] r; readS(n, r);

  auto r2 = new R[][](c+1);
  foreach (ri; r) r2[ri.c] ~= ri;
  foreach (ri; r2) ri.sort!"a.s < b.s";

  auto tm = r.map!(ri => ri.t).reduce!max;
  auto u = new int[](tm*2+2);
  foreach (ri; r2)
    foreach (i, rij; ri) {
      if (i > 0 && ri[i-1].t == rij.s)
        u[rij.s*2]++;
      else
        u[rij.s*2-1]++;
      u[rij.t*2]--;
    }

  foreach (i; 1..tm*2+2) u[i] += u[i-1];
  writeln(u.reduce!max);
}


Measured memory_bytes: 5884
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
long int i,j,k;
string s;
vector<long int> nums;

long int sum;
long int ssum;
long int fac;//+で区切られた数


int main(){
    cin>>s;
    //各桁の値をnumsに格納
    for(i=0;i<s.length();i++)nums.push_back(stoi(s.substr(i,1)));
    

    //全パターン
    for(i=0;i< 1<<(nums.size()-1);i++){
        
        //1パターン
        //cout<<endl<<i<<"---------"<<endl;
        fac=0;
        for(j=0;j<nums.size();j++){
            
            
            fac+=nums[j];
            if(((i>>j)&1)==1){
                sum+=fac;
                //cout<<fac<<endl;
                fac=0;
            }else{
                fac*=10;
            }
        }
        //cout<<fac/10<<endl;
        sum+=fac/10;
        

        //cout<<endl<<i<<endl;
    }

    cout<<endl<<sum;
    

    return 0;
}

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	string s;
	ll k;
	cin >> s >> k;

	char now = s[0];
	ll tmp = 1;
	ll first = 1;
	bool fj = true;
	ll res = 0;
	rep (i, 1, (int)s.size()) {
		if (now == s[i]) {
			tmp++;
			if (fj)
				first++;
		} else {
			if (fj) {
				fj = false;
			} else {
				res += tmp / 2;
			}
			now = s[i];
			tmp = 1;
		}
	}

	res *= k;

	if (s[0] == s[s.size() - 1]) {
		if (first == (int)s.size())
			res += first * k / 2;
		else
			res += (first / 2) + ((first + tmp) / 2 * (k - 1)) + (tmp / 2);
	} else {
		res += ((first / 2) + (tmp / 2)) * k;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256