akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc121/tasks/abc121_d

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int LEN = 40;
const ll G0[] = { 0LL, 1LL, 1LL, 0LL };

ll A, B;

ll g(ll n, int i) {
  if (i == 0) return G0[n % 4];
  ll per = 1LL << i;
  ll q = n / per;
  ll r = n % per;
  return ((q % 2 > 0) && (r % 2 == 0)) ? 1LL : 0LL;
}

ll f(ll n) {
  ll ret = 0;
  REP(i, LEN) {
    ll v = g(n, i);
    // printf("n:%lld i:%d v:%lld\n", n, i, v);
    ret |= v << i;
  }
  return ret;
}

void solve() {
  ll ans = f(B);
  if (A > 0) ans ^= f(A - 1);
  printf("%lld\n", ans);
}

void input() {
  scanf("%lld%lld", &A, &B);
}

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


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

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

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

#define MAX_N 2010

int N, x;
int a[MAX_N];
class rminq{
public:
    int n;
    vector<int> dat;
    rminq(int n_);
    void update(int k, int a);
    int query(int a, int b, int k, int l, int r);
    int query(int a, int b);
};
rminq::rminq(int n_){
    n=1;
    while (n < n_) n*= 2;
    dat.resize(2*n-1,INF); //最大値INFの時
}
void rminq::update(int k, int a){
    k += n-1;
    dat[k] = a;
    while(k>0){
        k = (k-1) / 2;
        dat[k] = min(dat[k*2+1],dat[k*2+2]);
    }
}
int rminq::query(int a, int b, int k, int l, int r){
    if(r<=a || b<=l) return INF; //最大値INFの時
    if(a<=l && r<=b) return dat[k];
    int vl = query(a,b,k*2+1,l,(l+r)/2);
    int vr = query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
}
int rminq::query(int a, int b){
    return query(a,b,0,0,n);
}
int main(){
    
    ios::sync_with_stdio(false);
    cin >> N >> x;
    
    REP(i,N) cin >> a[i];
    
    rminq m(N);
    REP(i,N) {
        m.update(i, a[i]);
    }
    
    // 魔法を唱える回数k
    ll ans = INF * INF;
    REP(k,N) {
        ll tmp_ans = k * x;
        REP(right,N) {
            ll left = (N + right - k) % N;
            if (left > right) {
                tmp_ans += min(m.query(left,N), m.query(0,right+1) );
            }
            else {
                tmp_ans += m.query(left, right+1);
            }
        }
        ans = min(tmp_ans, ans);
    }
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;


int main() {
	int len,sumA,sumB;
	string r;

	while (1) {
		cin >> r;
		len = r.size();
		if (len == 1) {
			break;
		}

		sumA = sumB = 0;
		for (int index = 1; index < len; index++) {
			if (r[index] == 'A') {
				sumA++;
			}
			else {
				sumB++;
			}
		}

		if (sumA > sumB) {
			sumA++;
		}
		else {
			sumB++;
		}
		cout << sumA << " " << sumB << endl;
	}

	return 0;
}


Measured memory_bytes: 3108
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  ll n, p;

  cin >> n >> p;

  if(n == 1){
    cout << p << endl;
    return 0;
  }
  
  ll ans = 1;
  
  for(ll i=2;i*i<=p;i++){
    if(p%i == 0){
      int counter = 0;

      while(p%i == 0){
        p/=i;
        counter++;
      }

      for(int j=0;j<counter/n;j++) ans *= i;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}




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

using namespace std;

int main() {
    string s;
    cin >> s;
    int num[] = { 0, 0, 0 };
    for (auto c : s) {
        num[c - 'a']++;
    }
    sort(num, num + 3);

    cout << (num[2] - num[0] <= 1 ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 512
<?php
$day = trim(fgets(STDIN));
$c = explode(' ',trim(fgets(STDIN)));

for ($i = 0; $i < $day; $i++) {
     $scores = explode(' ',trim(fgets(STDIN)));
     foreach($c as $ck => $cv){
         $scores[$ck] -= $cv * (365 - $i -1);
     }
     arsort($scores);
     echo array_key_first($scores) +1;
     echo "\n";
}



?>




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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n, m;
  cin >> n >> m;
  vector<int> bitmask(n, 0);       // (1)each element for each person. (2)int because m <= 30, so will fit in an int.

  REP(i, 0, n){
      int k;
      cin >> k;
      REP(j, 0, k){
          int a;
          cin >> a;
          bitmask[i] |= (1<<a);   //bitmasking in 1-index
      }
  }

  int x = bitmask[0];
  REP(i, 1, n)
      x &= bitmask[i];

  cout << __builtin_popcount(x) << endl;



  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace  std;
typedef long long int ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define filla(a,k,n) memset(a,k,sizeof(a[0])*n)
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
ll dp[3005][3005][2];
ll a[3005];
ll n,k;
void solve(ll i,ll j,ll t)
{
	if(dp[i][j][t]!=-1)
	{
		return;
	}
	if(i==j)
	{
		if(t==1)
		dp[i][j][t]=-a[i];
		else
		dp[i][j][t]=a[i];
		return;
	}
	if(t==0)
	{
		solve(i+1,j,!t);
		solve(i,j-1,!t);
		dp[i][j][t]=max(a[i]+dp[i+1][j][!t],a[j]+dp[i][j-1][!t]);
	}
	else
	{
		solve(i+1,j,!t);
		solve(i,j-1,!t);
		dp[i][j][t]=min(-a[i]+dp[i+1][j][!t],-a[j]+dp[i][j-1][!t]);
	}
	return;

}
int main()
{
	cin>>n;
	ll i;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	memset(dp,-1,sizeof(dp));
	solve(0,n-1,0);
	cout<<dp[0][n-1][0];




}


Measured memory_bytes: 141568
import math
s = str(input())
cou = 0
co = 0
ans = 0
while cou + co +2 <= len(s):
  if s[cou] == "x":
    if s[-1-co] == "x":
      cou += 1
      co += 1
    else:
      cou += 1
      ans += 1
  else:
    if s[-1-co] == "x":
      co += 1
      ans += 1
    else:
      if s[cou] == s[-1-co]:
        cou += 1
        co += 1
      else:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 3316
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define MP make_pair
#define PB push_back

int N;
vector<pair<int,int>> edge[100000];

int ans[100000] = {};

void solve(int now, int par, int t){
	ans[now] = t+1;
	for(int i=0; i<edge[now].size(); i++){
		if(edge[now][i].first == par) continue;
		solve(edge[now][i].first, now, (edge[now][i].second%2 == 0 ? t : (t+1)%2));
	}
}

int main(){
	cin >> N;
	for(int i=0; i<N-1; i++){
		int a, b, w;
		cin >> a >> b >> w;
		edge[a-1].PB(MP(b-1,w));
		edge[b-1].PB(MP(a-1,w));
	}
	solve(0,-1,0);
	for(int i=0; i<N; i++) cout << ans[i]-1 << endl;
	
	return 0;
}


Measured memory_bytes: 9984
n,l=[int(i) for i in input().split()]
app=[0]*(n)
for i in range(n):
    app[i]=l+i
m=1000000000000000000
num=0
for i,j in enumerate(app):
    if m>j and j>=0:
        m=j
        num=i
if m==1000000000000000000:
    m,num=max(app),app.index(max(app))
print(sum(app[0:num]+app[num+1:]))

Measured memory_bytes: 3064
N, K = map(int, input().split())
K0 = (N - 1) * (N - 2) // 2
if K > K0:
	print(-1)
else:
	print((N - 1) + (K0 - K))  # K0-Kがスターに追加する個数
	# まずは頂点1を中心にしてスターを作る
	for i in range(2, N + 1):
		print(1, i)
	# 追加分を出力
	cnt = 0
	for i in range(2, N):
		for j in range(i + 1, N + 1):
			cnt += 1
			if cnt > K0 - K:
				break
			print(i, j)


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

int main()
{
	int x;
	cin >> x;

	for (int i = 8, j = 400; 0 < i; i--, j += 200)
	{
		if (j <= x && x < j + 200)
		{
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}

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

using namespace std;
string s,t;
string res="";
bool RES(int pos,string &tmp)
{
	tmp=s;
	for(int i=0;i<t.size();i++)
	{
		if(s[pos+i]!='?'&&s[pos+i]!=t[i])
		{
			return false;
		}
		else
		{
			tmp[pos+i]=t[i];
		}
	}
	for(int i=0;i<tmp.size();i++)
	{
		if(tmp[i]=='?')
		{
			tmp[i]='a';
		}
	}
	return true;
}
int main()
{
	string tmp;
	cin>>s>>t;
	for(int i=0;i+t.size()<=s.size();i++)
	{
		if(RES(i,tmp)) 
		{
			if(res==""||tmp<res)
			{
				res=tmp;
			}
		} 
	}
	if(res=="")
	{
		cout<<"UNRESTORABLE"<<endl;
	}
	else
	{
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	int ans = 0;
	int a[n], b[n];
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n){
		if(a[i] > b[i]) ans += a[i] - b[i];
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

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

void solve(){
   int n;
   string s;
   cin>>n>>s;
   if(n<3200)
    cout<<"red";
    else
        cout<<s;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String S = sc.next();
	sc.close();
	
	int cnt = 0;
	for(int i=0;i<3;i++)if (S.charAt(i)=='1') cnt++;
	System.out.println(cnt);
	
	}
}


Measured memory_bytes: 21588
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a,b, c=0, n, k;
string s,t;
//cout<<<<endl;


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


Measured memory_bytes: 256
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/
ll n, m;
ll a[8]={-1, -1, -1, 0, 0, 1, 1, 1};
ll b[8]={-1, 0, 1, -1, 1, -1, 0, 1};
ll calcu(ll i, ll j, vs &v){
    int x, y, ii, p=0;
    for(ii=0; ii<8; ii++){
        x=a[ii]+i;
        y=b[ii]+j;
        if(x<0 || y<0 || x>=n || y>=m)continue;
        if(v[x][y]=='#')p++;
    }
    return p;
}

int main()
{
    fastt;

    ll  k, i, j, x, y, p=0, h, f=0;
    cin>>n>>m;
    vs v, v1;
    string s;
    for(i=0; i<n; i++){
        cin>>s;
        v.pb(s);
        v1.pb(s);
    }
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            if(v[i][j]=='.'){
                h=calcu(i, j, v);
                v1[i][j]='0'+h;
            }
        }
    }
    for(i=0; i<n; i++){
        cout<<v1[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 3560
#include<stdio.h>

int main(){
    int a,b;
    char op;
    int x;
    
    while(1){
        scanf("%d %c %d\n",&a,&op,&b);
        if(op == '?'){
            break;
        }else if(op == '+'){
            x = a + b;
        }else if(op == '-'){
            x = a-b;
        }else if(op == '*'){
            x = a*b;
        }else if(op == '/'){
            x = a/b;
        }
        printf("%d\n",x);
    }
    return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=2e3+3;



int main(){
	int N,x;
	cin>>N>>x;
	int a[MAX];
	rep(i,N)cin>>a[i];
	
	//dp[i][j]はi個目について、j個戻れるとしての最小値
	int dp[MAX][MAX];
	rep(i,N)dp[i][0]=a[i];
	rep1(j,N-1){
		rep(i,N){
			dp[i][j]=min(dp[(N+i-1)%N][j-1],a[i]);
		}
	}
	ll ans=1e18;
	//変色j回固定での和を見る
	rep(j,N){
		ll pa=(ll)j*x;
		rep(i,N)pa=pa+(ll)dp[i][j];
		ans=min(ans,pa);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 15872
#include<stdio.h>
int main()
{
    int a[101][101], b[101][101];
    long c[101][101]={{0}}; 
    int n, m, l, i, j, k;  
     
    scanf("%d%d%d", &n, &m, &l);  
     
    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            scanf("%d", &a[i][j]); 
        }
    }
     
    for(i=0; i<m; i++)
    {
        for(j=0; j<l; j++) 
        {
            scanf("%d", &b[i][j]);
        } 
    }
     
    for(i=0; i<n; i++)
    {
        for(k=0; k<m; k++)
        {
            for(j=0; j<l; j++)
            {
                c[i][j] += a[i][k] * b[k][j];    
            }
        }
    }
 
    for(i=0; i<n; i++) 
    {
        for(j=0; j<l; j++)
        {
            printf("%ld", c[i][j]);       
             
            if(l-1 == j) 
            {
                printf("\n");   
            }
            else
            {
                printf(" ");    
            }
        }
    }
    return 0; 
}

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

int N, K;
long long inf = 1e12;
vector<long long> h;
vector<long long> cost;

long long rec(long long n)
{
    if (n == 0)
    {
        return cost.at(n) = 0;
    }

    if (cost.at(n) != inf)
    {
        return cost.at(n);
    }

    for (int i = 1; i < K + 1; i++)
    {
        if (n - i >= 0)
        {
            long long dif = abs(h.at(n) - h.at(n - i));
            cost.at(n) = min(cost.at(n), dif + rec(n - i));
        }
    }

    return cost.at(n);
}

int main()
{
    cin >> N >> K;
    h.resize(N);
    cost.assign(N, inf);

    for (int i = 0; i < N; i++)
    {
        cin >> h.at(i);
    }

    cout << rec(N - 1) << endl;
}


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


int main(){
    bool ok[30]={0};
    for(int i=0;i<28;i++){
        int a;cin>>a;
        ok[--a]=true;
    }

    for(int i=0;i<30;i++)if(!ok[i]){
        cout<<i+1<<endl;
    }


    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

using namespace std;

constexpr int INF = 1000000000;/* 1e+9a */
constexpr int MODULO = 1000000007;

typedef int64_t ll;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int start = max(a, c);
    int end = min(b, d);
    int ans = end - start;
    if(ans < 0) ans = 0;
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int v[26],i;
  char s[27];
  scanf("%s",s);
  for(i=0;i<26;i++)v[i]=0;
  for(i=0;s[i];i++){if(v[s[i]-'a']){printf("no");return 0;}v[s[i]-'a']=1;}
  printf("yes");
}


Measured memory_bytes: 256
// Problem : A - Multiplication 1
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define sort(v) sort(all(v))
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;
int main()
{
    IOS
    int t=1;
    //cin>>t;
    while(t--)
    {
		int a,b;
		cin>>a>>b;
		cout<<a*b;
    }
    return 0;
}


Measured memory_bytes: 3644
package main

import (
	"bytes"
	"fmt"
)

//Ktai has a keyboard and a state.
type Ktai struct {
	keyboard KeyBoard
	textBuf  *bytes.Buffer
}

// KeyBoard is type of a map.
type KeyBoard map[rune]string

// KEYBOARD that Ktai has
var KEYBOARD = KeyBoard{
	'0': "",
	'1': ".,!? ",
	'2': "abc",
	'3': "def",
	'4': "ghi",
	'5': "jkl",
	'6': "mno",
	'7': "pqrs",
	'8': "tuv",
	'9': "wxyz",
}

func main() {
	var N int
	fmt.Scanf("%d", &N)
	ktai := &Ktai{
		KEYBOARD, &bytes.Buffer{},
	}
	for i := 0; i < N; i++ {
		var numstr string
		fmt.Scanf("%s", &numstr)
		ktai.feed(numstr)
		ktai.print()
	}
}

func (ktai *Ktai) feed(str string) {
	var char *byte
	for _, v := range str {
		if v == '0' {
			if char != nil {
				ktai.textBuf.WriteByte(*char)
				char = nil
			}
			continue
		} else {
			runestring := ktai.keyboard[v]
			idx := ktai.indexOf(char, runestring)
			next := (idx + 1) % len(runestring)
			c := runestring[next]
			char = &c
		}
	}
}

func (ktai *Ktai) indexOf(ch *byte, str string) int {
	if ch == nil {
		return -1
	}
	r := rune(*ch)
	idx := -1
	for i, v := range str {
		if r == v {
			idx = i
			break
		}
	}
	return idx
}

func (ktai *Ktai) print() {
	fmt.Println(ktai.textBuf.String())
	ktai.textBuf.Reset()
}



Measured memory_bytes: 1280
// CPP program to find the number of pairs 
// such that gcd equals to 1 
#include <bits/stdc++.h> 
#define lld long long
using namespace std; 
  
#define N 1000005 
  
lld lpf[N], mobius[N]; 
 
void least_prime_factor() 
{ 
    for (lld i = 2; i < N; i++) 
  
        if (!lpf[i]) 
  
            for (lld j = i; j < N; j += i) 
                if (!lpf[j]) 
                    lpf[j] = i; 
} 
  
void Mobius() 
{ 
    for (lld i = 1; i < N; i++) { 
  
        if (i == 1) 
            mobius[i] = 1; 
        else { 
  
            if (lpf[i / lpf[i]] == lpf[i]) 
                mobius[i] = 0; 
  
            else
                mobius[i] = -1 * mobius[i / lpf[i]]; 
        } 
    } 
} 
  

lld gcd_pairs(lld a[], lld n) 
{ 
    lld maxi = 0; 
  
    lld fre[N] = { 0 }; 
  
    for (lld i = 0; i < n; i++) { 
        fre[a[i]]++; 
        maxi = max(a[i], maxi); 
    } 
  
    least_prime_factor(); 
    Mobius(); 
  
    // To store number of pairs with gcd equals to 1 
    lld ans = 0; 
  
    // Traverse through the all possible elements 
    for (lld i = 1; i <= maxi; i++) { 
        if (!mobius[i]) 
            continue; 
  
        lld temp = 0; 
        for (lld j = i; j <= maxi; j += i) 
            temp += fre[j]; 
  
        ans += temp * (temp - 1) / 2 * mobius[i]; 
    } 
  
    // Return the number of pairs 
    return ans; 
} 
  
// Driver code 
int main() 
{ 
    lld n;
    cin>>n;

    lld a[n];

    for(lld i=0;i<n;i++)
    	cin>>a[i]; 
    lld ans=gcd_pairs(a, n);

    if(ans==n*(n-1)/2)
    	cout<<"pairwise coprime"<<endl;

    else
    {
    	lld an=0;
    	for(lld i=0;i<n;i++)
    		an=__gcd(an,a[i]);

    	if(an==1)
    		cout<<"setwise coprime"<<endl;
    	else
    		cout<<"not coprime"<<endl;
    }
  
    return 0; 
} 

Measured memory_bytes: 34880
// AOJ Vol3-0380 Celsius and Fahrenheit
// 2018.12.22

//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int F, C;

	scanf("%d", &F);
	C = (F - 30) / 2;
	printf("%d\n", C);
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  int now;
  rep(i, n){
    ll x;
    cin >> x;
    if(i == 0) now = x;
    else{
      if(a*(x - now) < b){
        ans += a*(x-now);
      }else{
        ans += b;
      }
      now = x;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanText() string {
	sc.Scan()
	return sc.Text()
}

func max(a,b int) int {
	if a>b {
		return a
	}
	return b
}

func main() {
	var h,w int
	fmt.Scan(&h,&w)

	s := make([]string, 0)
	for i := 0; i < h; i++ {
		s = append(s,scanText())

	}

	l := make([][]int,h)
	r := make([][]int,h)
	u := make([][]int,h)
	d := make([][]int,h)
	for i := 0; i < h; i++ {
		l[i] = make([]int,w)
		r[i] = make([]int,w)
		u[i] = make([]int,w)
		d[i] = make([]int,w)
	}

	for i := 0; i < h; i++ {
		count := 0
		for j := 0; j < w; j++ {
			if string(s[i][j]) == "#" {
				count = 0
				continue
			}
			count++
			l[i][j] = count
		}
	}
	
	for i := 0; i < h; i++ {
		count := 0
		for j := w-1; j >= 0; j-- {
			if string(s[i][j]) == "#" {
				count = 0
				continue
			}
			count++
			r[i][j] = count
		}
	}

	for i := 0; i < w; i++ {
		count := 0
		for j := h-1; j >= 0; j-- {
			if string(s[j][i]) == "#" {
				count = 0
				continue
			}
			count++
			u[j][i] = count
		}
	}

	for i := 0; i < w; i++ {
		count := 0
		for j := 0; j < h; j++ {
			if string(s[j][i]) == "#" {
				count = 0
				continue
			}
			count++
			d[j][i] = count
		}
	}

	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			a := l[i][j]+r[i][j]+u[i][j]+d[i][j]-3
			if ans < a {
				ans = a
			}
		}
	}

	fmt.Println(ans)

}


Measured memory_bytes: 138240
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    string a;
    vector<string> s;
    for(int i=0;i<h;i++){
        cin >> a;
        s.push_back(a);
    }
    for(int i=0;i<w+2;i++){
        cout << '#';
    }
    cout << endl;
    for(int i=0;i<h;i++){
        cout << '#'+s[i]+'#' << endl;
    }
    for(int i=0;i<w+2;i++){
        cout << '#';
    }
    cout << endl;

  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
	"sort"
)

func main() {
	sc := NewScanner(os.Stdin)
	n := sc.Int()
	a := sc.Ints(n)
	sort.Ints(a)

	max := a[n-1]
	dp := make([]int, max+1)

	for _, n := range a {
		dp[n]++
		if dp[n] > 1 {
			continue
		}

		for v := n + n; v <= max; v += n {
			dp[v]++
		}
	}

	var count int
	for _, v := range a {
		if dp[v] == 1 {
			count++
		}
	}
	fmt.Println(count)
}

type Scanner struct {
	r     io.Reader
	buf   []byte
	delim byte
	size, eof,
	start, end int
}

func NewScanner(r io.Reader) *Scanner { return NewScannerSize(r, 4096) }
func NewScannerSize(r io.Reader, size int) *Scanner {
	return &Scanner{
		r:     r,
		buf:   make([]byte, size),
		delim: ' ',
		size:  size, start: size, end: size,
	}
}

func (s *Scanner) Int() int { return ParseInt(s.bytes()) }

func (s *Scanner) Ints(len int) []int {
	a := make([]int, len)
	for i := 0; i < len; i++ {
		a[i] = s.Int()
	}
	return a
}

func (s *Scanner) bytes() []byte { b, _ := s.next(); return b }
func (s *Scanner) next() (b []byte, size int) {
	for n := 0; ; {
		for i := s.end; i < s.size; i++ {
			if s.buf[i] == s.delim || s.buf[i] == '\n' || i == s.eof {
				b, size = s.buf[s.start:i], i-s.start
				s.start, s.end = i+1, i+1
				return
			}
		}
		s.end = s.size
		if n++; n == 2 {
			panic("lack of buffer size")
		}
		s.read()
	}
}
func (s *Scanner) read() {
	copy(s.buf, s.buf[s.start:s.end])
	s.end -= s.start
	s.start = 0
	n, _ := s.r.Read(s.buf[s.end:])
	s.eof = s.end + n
}

func ParseInt(b []byte) (n int) {
	var i int
	if b[0] == '-' {
		i++
	}
	for ; i < len(b); i++ {
		n *= 10
		n += int(b[i] - '0')
	}
	if b[0] == '-' {
		return -n
	}
	return
}


Measured memory_bytes: 11556
N, L = gets.chop.split.map(&:to_i)

min_taste = L
max_taste = L + N - 1

all_taste = ((min_taste + max_taste) * N) / 2
pie_taste = 0 

if L * (L + N - 1) <= 0
  pie_taste = all_taste
elsif max_taste < 0
  pie_taste = all_taste - max_taste
else
  pie_taste = all_taste - min_taste
end
puts pie_taste



Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

const int dy[16] = { 0,-1, 0, 1, 1,-1, 1,-1, 0,-2, 0, 2};
const int dx[16] = { 1, 0,-1, 0, 1, 1,-1,-1, 2, 0,-2, 0};

bool check(char m[55][55], int y, int x){
	rep(d,4){
		int ny = y + dy[d];
		int nx = x + dx[d];
		if(m[ny][nx] == '#') return true;
	}
	return false;
}

int main(){
	int h, w;
	cin >> h >> w;

	char m[55][55];
	rep(i,h) rep(j,w) m[i][j] = '.';
	rep(i,h){
		rep(j,w){
			cin >> m[i + 1][j + 1];
		}
	}

	rep(i,h){
		rep(j,w){
			if(m[i][j] == '#'){
				if(not check(m, i, j)){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static final boolean TEST = false;
	private static final int TEST_NUM = 3;

	public static void main(String[] args) {
		int N = 0;
		Integer[] A = {};
		Integer[] A1 = {-10,5,-4};
		Integer[] A2 = {10,-4,-8,-11,3};
		Integer[] A3 = {-1000000000,1000000000,-1000000000,1000000000,-1000000000,0,1000000000,
				-1000000000,1000000000,-1000000000,1000000000};

		switch(TEST_NUM) {
		case 1:
			N = 3;
			A = A1;
			break;
		case 2:
			N = 5;
			A = A2;
			break;
		case 3:
			N = 11;
			A = A3;
			break;
		default:
				break;
		}
		if(!TEST) {
			Scanner sc = new Scanner(System.in);
			N = sc.nextInt();
			A = new Integer[N + 1];
			for(int i = 0; i < N; i++) {
				A[i] = sc.nextInt();
			}
			sc.close();
		}
		solve(A, N);
	}

	static void solve(Integer[] A, int N) {
		// i番目までにおいてのスコア
		// j=0のときAiを反転しておらず、j=1のときAiを反転している状態

		// 初期化
		long[][] dp = new long[N + 1][2];
		dp[1][0] = A[0];
		dp[1][1] = -1 * A[0];

		for(int i = 1; i < N; i++) {
			dp[i + 1][0] = Math.max(dp[i][0] + A[i], dp[i][1] - A[i]);
			dp[i + 1][1] = Math.max(dp[i][0] - A[i], dp[i][1] + A[i]);
 		}

		System.out.println(dp[N][0]);
	}
}


Measured memory_bytes: 62448
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

ll func(ll a, ll b, ll c) {
	ll smax, smin;
	smax = max(a, b);
	smax = max(smax, c);
	smin = min(a, b);
	smin = min(smin, c);
	return smax - smin;
}
bool bColor[8];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,a[200010];
	deque<int> ans;
	scanf("%d", &n);
	REP(i,n)scanf("%d", &a[i]);
	int lastMod = (n - 1) % 2;
	
	REP(i, n) {
		if (i % 2 == lastMod) {
			ans.push_front(a[i]);
		}
		else {
			ans.push_back(a[i]);
		}
	}
	
	cout << ans[0];
	for(int i=1;i<n;i++){
		cout << " " << ans[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3840
#include<stdio.h>
#include<math.h>

float s(float a) {
	a *= 1000;
	if (a > 0) {
		a += 0.5;
	}
	else {
		a -= 0.5;
	}
	int b = a;
	a = b;
	a /= 1000;
	return a;
}

int main() {
	float a, b, c, d, e, f;
	while (~scanf("%f %f %f %f %f %f", &a, &b, &c, &d, &e, &f)) {
		float x, y;
		if (a == 0) {
			y = c / b;
			x = (f - e * y) / d;
		}
		else if (d == 0) {
			y = f / e;
			x = (c - b * y) / a;
		}else {
			b *= d;
			c *= d;
			e *= a;
			f *= a;
			y = (c - f) / (b - e);
			x = (c / d - b / d * y) / a;
		}
		printf("%.3f %.3f\n", s(x), s(y));
	}
}



Measured memory_bytes: 2612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define   PI    acos(-1)
#define mx 100005
int fx[]= {0,0,-1,1};
int fy[]= {1,-1,0,0};
int a[mx],b[mx],c[mx];
int dp[mx][3];
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    int n,i,j,res=0;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(i=1; i<=n; i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    res=max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    cout<<res<<endl;


    return 0;
}
/*
3
10 40 70
20 50 80
30 60 90
*/






Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(void){
    int input, h, m, s;
    cin >> input;
    
    s = input % 60 % 60;
    
    int tmp1;
    tmp1 = input - s;
    h = tmp1 / 60 / 60;
    
    //int tmp2;
    m = (tmp1 - (h * 60 * 60)) / 60;
    //m = tmp2 % 60;
    
    //cout << h << endl;
    cout << h << ":" << m << ":" << s << endl;
    
    return 0;
}


Measured memory_bytes: 3100
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args){
        Scanner r =new Scanner(System.in);
        int w = r.nextInt();
        int h = r.nextInt();
        int x = r.nextInt();
        int y = r.nextInt();
        int z = r.nextInt();
        if(z <= x && x <= (w -z) && z <= y && y <= (h - z)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
 
}

Measured memory_bytes: 26352
#include <iostream>
#include <string>
#include <cstring>

using namespace std;
int main() {
    string S;
    string T;
    int w = 0;
    cin >> S;
    cin >> T;

    switch (S[0]){
        case 'S':
            if(T[0] == 'S') w++;
            break;
        case 'C':
            if(T[0] == 'C') w++;
            break;
        case 'R':
            if(T[0] == 'R') w++;
            break;
    }

    switch (S[1]){
        case 'S':
            if(T[1] == 'S') w++;
            break;
        case 'C':
            if(T[1] == 'C') w++;
            break;
        case 'R':
            if(T[1] == 'R') w++;
            break;
    }

    switch (S[2]){
        case 'S':
            if(T[2] == 'S') w++;
            break;
        case 'C':
            if(T[2] == 'C') w++;
            break;
        case 'R':
            if(T[2] == 'R') w++;
            break;
    }

    cout << w << 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;
using P = pair<int,int>;

int c[3][3];
int a[3];
int b[3];
const int INF = 1001001001;
int main(){
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>c[i][j];
    }
  }
  int d1,d2;
  d1=c[0][1]-c[0][0];
  d2=c[0][2]-c[0][1];
  
  if(c[1][1]-c[1][0]==d1&&c[1][2]-c[1][1]==d2){
      if(c[2][1]-c[2][0]==d1&&c[2][2]-c[2][1]==d2){
          cout<<"Yes"<<endl;return 0;
      }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
using namespace std;
#define int long long
#define inf 1145141919810
typedef pair<int, int> P;
int wall[205][205];
int num[10];
int c[10][10];
signed main() {
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)cin >> c[i][j];

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> wall[i][j];
			if (wall[i][j] > -1)num[wall[i][j]]++;
		}
	}

	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				c[j][k] = min(c[j][i] + c[i][k],c[j][k]);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 10; i++) {
		ans += num[i] * c[i][1];
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
s=input()
a=int(s[:2])
b=int(s[2:])
if 1<=a & a<=12:
    if 1<=b & b<=12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1<=b & b<=12:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
  	string s,t;
	getline(cin, s);
	getline(cin, t);
	int slen = s.size();
	int tlen = t.size();
	int ans = t.size();
	for(int st = 0; st <= slen - tlen; st++)
	{
		int res = 0,pt = 0;
		for(int ps = st; ps <= st + tlen - 1; ps++)
		{
			if(s[ps] != t[pt]) res++;
			pt++;
		}
		ans = min(ans, res);
	}
	cout <<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
  string s;
  cin >> s;
  string ans = "No";
  if(s.at(2) == s.at(3) && s.at(4) == s.at(5)) ans = "Yes";
  cout << ans << endl;
return 0;
}

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

int main() {
  int A, B, C; cin >> A >> B;
  if (A*B%2 != 0) C=2;
  else if (A*B%3 != 0) C=3;
  else C=1;
  printf("%d\n", C);
}

Measured memory_bytes: 256
# coding: utf-8

import sys
input = sys.stdin.readline

def f(s):
    if flag[s]:
        return(memo[s])
    # 分けない場合
    p = 0
    for i in range(N):
        for j in range(i + 1, N):
            if (s >> i) & 1 and (s >> j) & 1:
                p += a[i][j]
    t = s
    while True:
        t = (t - 1) & s
        if not t:
            break
        p_ = f(t) + f(t ^ s)
        if p < p_:
            p = p_
    flag[s] = 1
    memo[s] = p
    return(p)

N = int(input()) # 1 <= N <= 16
a = [list(map(int, input().split())) for _ in range(N)]
memo = [0] * (1 << N)
flag = [0] * (1 << N)
print(f((1 << N) - 1))


Measured memory_bytes: 49628
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cassert>
#include <numeric>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef long long ll;
typedef double lf;
typedef long double llf;
typedef pair<int,int> pii;
typedef vector<int> vec;
#define fi first
#define se second
/* */
#define all(x) begin(x),end(x)
#define rall(x) rbegin(x),rend(x)
#define forEach(i, s) for(auto i=begin(s);i!=end(s);i++)
#define for_each_n(i, s, n) for(auto i=begin(s),_5=next(i,n);i!=_5;i++)
#define pb push_back
#define mp make_pair

/* special */
#define Mem(x) memset(x,0,sizeof(x))
#define GET_MACRO(_0,_1,_2,_3,_NAME,...) _NAME
/* */
#define rep(...)  GET_MACRO(_0,##__VA_ARGS__,rep3,rep2,rep1,rep0)(__VA_ARGS__)
	#define rep3(i,a,b) for(int i=(a);i<(b);++i)
	#define rep2(i,a) for(int i=0;i<(a);++i)
	#define rep1(a) rep2(_,a)
	#define rep0()	while(1)
#define callOnce if([]{static int i=-1;i++;return !i;}())


/* input */
namespace my{
	#define out(x) cout<<(x)<<endl
	inline int in(int &x) {return scanf("%d",&x);}
	inline int in(double &x) {return scanf("%lf",&x);}
	inline int in(ll &x) {return scanf("%lld",&x);}
	inline int in(int &x,int &y) {return scanf("%d %d",&x,&y);}
	inline int in(int &x,int &y,int &z) {return scanf("%d %d %d",&x,&y,&z);}
	inline int in(char s[]) {return scanf("%s",s);}
	inline int in(char &c) {return scanf("%c",&c);}
}

using namespace my;

/* debug */
#ifndef ONLINE_JUDGE
	#define D0()
	#define D1(x) {cout<<" ";cout.width(5);cout<<(x);}
	#define D2(x,y) {D1(x)D1(y)}
	#define D3(x,y,z) {D2(x,y)D1(z)}
	#define Dset(...) for(auto i : __VA_ARGS__ ) D1(i) //std::size()
	#define Darr1(x,fir) for(auto _7 = begin(x),_6=next(begin(x),fir);_7!=_6;++_7) D1(*_7)
	#define Darr2(x,fir,sec) for(auto _8=begin(x),_9=next(begin(x),fir);_8!=_9;++_8){ Darr1((*_8),sec)D()}
	#define D(...) {cout<<#__VA_ARGS__<<" ";GET_MACRO(_0,##__VA_ARGS__,D3,D2,D1,D0)(__VA_ARGS__);cout<<endl;}
	#define Da(...)  {cout<<#__VA_ARGS__;D()GET_MACRO(""##__VA_ARGS__,UNUSED,Darr2,Darr1,Dset)(__VA_ARGS__)D()}
#endif // ONLINE_JUDGE

// template<class T> T gcd(T a, T b){if(!b)return a;return gcd(b,a%b);}
#define pow2(X) (1<<(X))
#define gcd __gcd
#define lcm(a,b) ((a)/gcd(a,b)*(b))
ll mod=1e9+7;
inline ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

const double pi=acos(-1.0);
const double eps=1e-11;
const int INF=0x3f3f3f3f;//0x3f
const int NINF=0xcfcfcfcf;//0xcf
const int maxn=1e5+10;
int N,t,K,H,W,p,y,v;
int x[maxn];


int main(){

	cin>>N>>K;
	rep(i,N) in(x[i]);

	int ans=INF;
	rep(i,N-K +1){
		ans=min({ans,abs(x[i])+abs(x[i+K-1]-x[i]),abs(x[i+K-1])+abs(x[i+K-1]-x[i])});
	}
	printf("%d",ans);
	
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and Constants    *******/

#define int long long
#define ull unsigned long long 
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define w(x) int x;cin>>x;while(t--)
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__);
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

const int POSITIVE_INFINITY = 9223372036854775807;
const int NEGATIVE_INFINITY = -9223372036854775807;
const int MOD = 1000000007;
const ld PI = acos(-1.0);
const int INF = 1e18;
const int MX = 1000001;


int32_t main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    int arr[n],pref[n];
    rep(i,0,n)cin>>arr[i];
    pref[0]=arr[n-1];
    for(int i = 1;i<n;i++){
        pref[i]=pref[i-1]+arr[n-1-i];
        // see(pref[i]);
    }
    int sum = 0;
    for(int i = 0;i<n-1;i++){
        sum=((sum%MOD)+((arr[i]%MOD)*(pref[n-2-i]%MOD))%MOD)%MOD;
    }
    cout<<sum<<endl;

    
 
    return 0;
}


Measured memory_bytes: 6728
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;


int main(void){

	int n;
	cin >> n;

	unsigned long long int ans = 1;

	for( int i = 1; i <= n; i++ )
		ans *= i;

	cout << ans << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

class Combination {
 public:
  Combination(ll _max_n, ll _mod_val = LLONG_MAX)
    : max_n(_max_n), mod_val(_mod_val), factional(max_n + 1), inv(max_n + 1) {
    factional[0] = 1;
    inv[0] = 1;
    for (ll i = 0; i < max_n; i++) {
      factional[i + 1] = factional[i] * (i + 1) % mod_val;               // n!(mod M)
      inv[i + 1] = inv[i] * this->mod_pow(i + 1, mod_val - 2) % mod_val; // k!^(M-2) (mod M)
    }
  }

  // x^n(mod M)
  ll mod_pow(ll x, ll n) {
    ll ans = 1;
    while (n != 0) {
      if (n & 1)
        ans = ans * x % mod_val;
      x = x * x % mod_val;
      n = n >> 1;
    }
    return ans;
  }

  // nCk(mod M)
  ll get(ll n, ll k) {
    if (n == 0 && k == 0)
      return 1;
    if (n < k || n < 0)
      return 0;
    ll tmp = inv[n - k] * inv[k] % mod_val;
    return tmp * factional[n] % mod_val;
  }

 private:
  const ll max_n;
  const ll mod_val;
  std::vector<ll> factional;
  std::vector<ll> inv;
};

ll ext_gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll q = a / b;
  ll g = ext_gcd(b, a - q * b, x, y);
  ll z = x - q * y;
  x = y;
  y = z;
  return g;
}

// 逆元
ll mod_inv(ll a, ll m) {
  ll x, y;
  ext_gcd(a, m, x, y);
  x %= m;
  if (x < 0)
    x += m;
  return x;
}

// prime factorization (素因数分解)
// key: value of prime factor
// value: number of prime factor
std::map<ll, ll> prime_factorization(ll n) {
  std::map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, m;
  cin >> n >> m;

  auto a = prime_factorization(m);
  Combination C(500000, mod);

  ll ans = 1;
  FORm(it, a) {
    ans *= C.get(n + it->second - 1, n - 1);
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <algorithm>

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

  std::string S;
  std::cin >> S;

  int f = 0, m = 0;
  for (int i = 0; i < S.size(); i++) {
    auto c = S[i];
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
      f++;
    } else {
      f = 0;
    }
    m = std::max(f, m);
  }

  std::cout << m << std::endl;

  return 0;
}


Measured memory_bytes: 3124
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
string names;

string karuta[100100];
int nn[400];
vector<pair<int, int>> workk;
long long summ;
int main() {
	int N = 0;
	cin >> N;
	int a = 0, b = 0;
	for (int i = 0; i < N; i++) {
		cin >> a >> b;
		workk.push_back(make_pair(a, b));
		swap(workk[i].first, workk[i].second);
	}
	sort(workk.begin(), workk.end());
	for (int i = 0; i < N; i++) {
		summ += workk[i].second;
		//cout << summ << ' ' << workk[i].first << endl;
		if (summ > workk[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3188
#include <stdio.h>



int main(){
	int h,w;
	scanf("%d %d\n",&h,&w);
	for(int i=0;i<w+2;++i)
	{
		printf("#");
	}
	printf("\n");
	for(int j=0;j<h;++j)
	{
		printf("#");
		char width[w];
		gets(width);
		printf("%s",width);
		printf("#\n");	
	}
	for(int i=0;i<w+2;++i)
	{
		printf("#");
	}
	printf("\n");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,m,ans=0;
	cin>>n>>m;
	if(n==1&&m==1)
	{
	cout<<1;
	return 0;
    }
	if(n==1||m==1)
	{
	cout<<n+m-3;
	return 0;
    }
	else
	cout<<(m-2)*(n-2);
	return 0;
}

Measured memory_bytes: 256
import math

N = int(input())
lists = []
result = 0
tempres = 0
for i in range(N):
    lists.append(input())

sortedlist = []
for i in range(0, N):
    sortedlist.append(sorted(lists[i]))

sortedlist.sort()
for i in range(0, N):
    if tempres != 0:
        tempres -= 1
        result += tempres
        continue

    for j in range(i + 1, N):
        if sortedlist[i] == sortedlist[j]:
            tempres += 1
        else:
            break
    result += tempres

print(result)


Measured memory_bytes: 31828