akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(LL i=0;i<(LL)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<LL,LL>
#define pll pair<LL,LL>

using namespace std;

LL to[100000];
bool used[100000];
LL loop[100000];

LL Kto[100000];

LL find_size(LL v,LL sz){
    used[v]=true;
    sz++;
    if(used[to[v]])return loop[v]=sz;
    else return loop[v]=find_size(to[v],sz);
}


int main(){

    LL N;cin>>N;
    LL x[N];REP(i,N)cin>>x[i];
    LL d[N-1];
    REP(i,N-1)d[i]=x[i+1]-x[i];


    LL M,K;cin>>M>>K;
    LL swp[N-1];
    REP(i,N-1)swp[i]=i;
    REP(i,M){
        LL a;cin>>a;--a;
        swap(swp[a-1],swp[a]);
    }
    REP(i,N-1)to[swp[i]]=i;
    fill_n(used,N,false);
    REP(i,N-1)if(!used[i])find_size(i,0);
    fill_n(Kto,N,-1);
    fill_n(used,N,false);

    REP(i,N-1){
        if(used[i])continue;
        LL mod = K%loop[i];
        LL kto=i;
        REP(j,mod)kto=to[kto];
        LL index=i;
        REP(j,loop[i]){
            used[index]=true;
            Kto[index]=kto;
            index=to[index];
            kto=to[kto];
        }
    }

    LL D[N-1];
    REP(i,N-1)D[Kto[i]]=d[i];
    LL ans[N];
    ans[0]=x[0];
    REP(i,N-1)ans[i+1]=ans[i]+D[i];
    REP(i,N)cout<<ans[i]<<" ";
    cout<<endl;





    return 0;
}

Measured memory_bytes: 7552
S = input()
N = len(S)
A = [0] * (N+1)
B = [0] * (N+1)
X = [0] * N
for i in range(N):
    if S[i] == "R":
        A[i+1] = A[i] + 1
for i in range(N)[::-1]:
    if S[i] == "L":
        B[i] = B[i+1] + 1
for i in range(1, N):
    if A[i] and B[i]:
        X[i] += A[i]//2
        X[i-1] += A[i] - A[i]//2
        X[i-1] += B[i]//2
        X[i] += B[i] - B[i]//2

print(*X)

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

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

        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < a.length; ++i) {
            a[i] = sc.nextInt();
        }

        System.out.println(solve(a));

        sc.close();
    }

    static int solve(int[] a) {
        return Arrays.stream(a).map(x -> x - 1).sum();
    }
}

Measured memory_bytes: 29404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

template<typename T>
void maxs(T &a, const T &b){
    if(a < b) a = b;
}

int dp[4010][4010];

int main(){
    string a,b;
    while(cin >> a >> b){
        REP(i,4010) memset(dp[i],0,sizeof(dp[i]));
        int ans = 0;
        for (int i = 0; i < sz(a); i++) {
            for (int j = 0; j < sz(b); j++) {
                if (a[i] == b[j]) {
                    dp[i+1][j+1] = dp[i][j] + 1;
                    ans = max(ans, dp[i+1][j+1]);
                }
            }
        }
        // for (int i = 0; i <= sz(a); i++) {
        //     if (i > 0) 
        //         cout << a[i - 1] << ": ";
        //     for (int j = 0; j <= sz(b); j++) {
        //         cout << dp[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        cout << ans << endl;
    }
}


Measured memory_bytes: 65900
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	int n;
	cin >> n;
	ll a[n];
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	ll tmp=a[1];
	for(int i=2; i<n; i++){
		tmp ^=a[i];
	}
	if(tmp==a[0]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int n,k,f[N];
long long a[N],b[N],l[N],r[N],d[N],fl[N],fr[N];

void modify(int t,int l,int r,int x,int y,int z){
	if (x<=l&&y>=r) {f[t]=z;return;}
	if (x<=(l+r)/2) modify(2*t,l,(l+r)/2,x,y,z);
	if (y>=(l+r)/2+1) modify(2*t+1,(l+r)/2+1,r,x,y,z);
}

int query(int t,int l,int r,int x){
	if (l==r) return f[t];
	if (x<=(l+r)/2) return min(f[t],query(2*t,l,(l+r)/2,x));
	return min(f[t],query(2*t+1,(l+r)/2+1,r,x));
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read(),k=read();
	for (int i=1;i<=n;i++){
		a[i]=a[i-1]+read();b[i]=read();
		if (2*(a[i]-a[i-1])>k&&b[i]==1) {printf("-1\n");return 0;}
		if (b[i]==2) l[i]=0,r[i]=k-1;
		else l[i]=(-2*a[i-1]%k+k)%k,r[i]=(-2*a[i]%k+k)%k;
		d[2*i-1]=l[i];d[2*i]=r[i];
	}
	sort(d+1,d+2*n+1);
	for (int i=1;i<=n;i++)
		l[i]=lower_bound(d+1,d+2*n+1,l[i])-d,
		r[i]=lower_bound(d+1,d+2*n+1,r[i])-d;
	fill(f+1,f+8*n+1,n+1);
	for (int i=n;i>=1;i--){
		int t=query(1,1,2*n,l[i]);
		if (t!=n+1) fl[i]=fl[t]+(d[l[t]]-d[l[i]]+k)%k;
		t=query(1,1,2*n,r[i]);
		if (t!=n+1) fr[i]=fl[t]+(d[l[t]]-d[r[i]]+k)%k;
		if (l[i]<=r[i]) {
			if (1<=l[i]-1) modify(1,1,2*n,1,l[i]-1,i);
			if (r[i]+1<=2*n) modify(1,1,2*n,r[i]+1,2*n,i);
		}
		else if (r[i]+1<=l[i]-1) modify(1,1,2*n,r[i]+1,l[i]-1,i);
	}
	long long ans=1ll<<60;
	for (int i=1;i<=n;i++){
		if (query(1,1,2*n,l[i])>=i) ans=min(ans,fl[i]);
		if (query(1,1,2*n,r[i])>=i) ans=min(ans,fr[i]);
	}
	printf("%lld\n",ans+2*a[n]);
	return 0;
}

Measured memory_bytes: 24064
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		 long double   ld;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;

ll a[100];
ll b[100];

ll n;
vll v;
ll vis[100];
ll cnt=0;
ll cnt1=0;
ll cnt2=0;
void go()
{
    if(zz(v)==n)
    {
        cnt++;
        ll f=1;
        for(ll j=0; j<zz(v); j++)
        {
            if(a[j]!=v[j])
                f=0;
        }
        if(f)
            cnt1=cnt;

        f=1;

        for(ll j=0; j<zz(v); j++)
        {
            if(b[j]!=v[j])
                f=0;
        }
        if(f)
            cnt2=cnt;

    }
    for(ll i=1; i<=n; i++)
    {
        if(vis[i])
            continue;

        v.pb(i);
        vis[i]=1;
        go();
        v.pop_back();
        vis[i]=0;
    }
}

int main()
{

//    ios::sync_with_stdio(0);
//    cin.tie(0);

    ll ans=0;
    // ll n;
    cin>>n;

    ll f=1;
    for(ll i=1; i<n; i++)
        f*=i;
    for(ll i=0; i<n; i++)
    {
        cin>>a[i];
    }




    for(ll i=0; i<n; i++)
    {
        cin>>b[i];
    }
    go();

    cout<<abs(cnt2-cnt1)<<nn;






}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int a[10005], b[505];
int n, q;

int search(int *a, int c)
{
	int idx = 0;
	a[n] = c;
	while(a[idx] != a[n])	idx ++;
	
	return idx != n;
}

int main()
{
	int sum = 0;
	cin >> n;
	for(int i = 0; i < n; ++ i)
		cin >> a[i];
	
	cin >> q;
	for(int i = 0; i < q; ++ i)
	{
		cin >> b[i];
		if(search(a, b[i]))	sum ++;
	}
	
	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 3120
//AtCoder ABC070 A - Palindromic Number
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    string N;
    cin>>N;
    ll v0=stoi(N);
    string tmp;
    for(ll i=N.size()-1;i>=0;--i){
        tmp.push_back(N[i]);
    }
    ll v1=stoi(tmp);
    cout<<(v0==v1?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())

def bs(ok, ng, cond):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if cond(mid):
            ok = mid
        else:
            ng = mid
    return ok

ans = bs(n, 0, lambda x: (x * 1.08) >= n)
if int(ans * 1.08) == n:
    print(ans)
else:
    print(':(')


Measured memory_bytes: 38384
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pb push_back
# define pdd pair < db , db >
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,a,b;
    fi>>n>>a>>b;
    static int s[1 << 20];
    for (int i = 1;i <= n;++i)
        fi>>s[i];
    ll ans = 0;
    for (int i = 2;i <= n;++i)
        ans += min((s[i] - s[i - 1]) * 1ll * a,1ll * b);
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

typedef long long ll;

const int dx[] = {0,1,0,-1};
const int dy[] = {-1,0,1,0};
int w,h, tatu_x[20], tatu_y[20], kazu_x[20], kazu_y[20];
int field[12][12], cx[36], cy[36], csize;
map<pair<int,int>, int> idx;
set<ll> visited[20][4][2];


bool inside(int x, int y){
    return !(x < 0 || x >= w || y >= h || y < 0 );
}

bool backtrack(int cnt, ll kS, int init_dir, int f){
    int i,j,k;

    if( visited[cnt][init_dir][f].count(kS) ) return false;
    if( csize/2 == cnt ) return true;

    rep(i,cnt){ // ツ達ツ姪ァツづ個チツδコツつゥツづァツ新ツつオツつ「ツ偲シツ陛督づ個チツδコツづーツ選ツ妥ー
        rep(k,4){
            int tx = tatu_x[i] + dx[k];
            int ty = tatu_y[i] + dy[k];
            if( !inside(tx,ty) || field[ty][tx] == 0 ) continue;

            // ツ妥篠可楪つキツづゥツ和ツ姪ァツづ個チツδコ
            int ttx = kazu_x[i] + dx[(k + init_dir + (f?2:0)) % 4];
            int tty = kazu_y[i] + dy[(k + init_dir) % 4];
            if( (tx == ttx && ty == tty) || !inside(ttx,tty) || field[tty][ttx] == 0 ) continue;

            field[ty][tx] = 0;
            tatu_x[cnt] = tx, tatu_y[cnt] = ty;

            field[tty][ttx] = 0;
            kazu_x[cnt] = ttx, kazu_y[cnt] = tty;

            if( backtrack(cnt+1, kS|(1LL<<idx[make_pair(ttx,tty)]), init_dir, f) ) return true;
            field[tty][ttx] = 1;
            field[ty][tx] = 1;
        }
    }
    visited[cnt][init_dir][f].insert(kS);
    return false;
}

bool solve(){
    int i,j,k;

    if( csize % 2 ) return false;

    // ツ達ツ姪ァ
    tatu_x[0] = cx[0], tatu_y[0] = cy[0];
    field[cy[0]][cx[0]] = 0;

    REP(j,1,csize){ // ツ和ツ姪ァ
        kazu_x[0] = cx[j], kazu_y[0] = cy[j];
        field[cy[j]][cx[j]] = 0;

        rep(k,4){
            if( backtrack(1, 1LL<<j, k, 0) ) return true;
            if( backtrack(1, 1LL<<j, k, 1) ) return true;
        }
        field[cy[j]][cx[j]] = 1;
    }
    field[cy[0]][cx[0]] = 1;

    return false;
}

int main(){
    int i,j,k,u;

    while( cin >> w >> h, w|h ){
        // init
        idx.clear();
        rep(i,20) rep(j,4) rep(k,2) visited[i][j][k].clear();
        csize = 0;

        // input
        rep(i,h) rep(j,w){
            cin >> field[i][j];
            if( field[i][j] == 1 ){
                cx[csize] = j, cy[csize] = i;
                idx[make_pair(j,i)] = csize;
                csize++;
            }
        }
        puts( solve() ? "YES" : "NO" );
    }

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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


    int n;cin>>n;
    vector<complex<long double>> v(n);
    rep(i,n){
        long double x,y;
        cin>>x>>y;
        v[i]=complex<long double>(x,y);
    }
    sort(ALL(v),[&](complex<long double> a,complex<long double> b){
        return arg(a)<arg(b);
    });
    long double ans=0;
    rep(i,n){
        complex<long double> sum=(0,0);
        rep(j,n){
            sum+=v[(i+j)%n];
            chmax(ans,abs(sum));
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

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

int main(){
    int A,B;
    cin >> A >> B;
    int num=max(A+B,A-B);
    num=max(num,A*B);
    cout << num;
    }

Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import sys
from collections import deque
inf = 10**15
mod = 10**9+7
R, C = map(int, input().split())
maps = [input() for i in range(R)]
whole = R*C
defoB = 0
for s in maps:
    for c in s:
        if c == '#':
            defoB+=1
dis = [[-1 for j in range(C)] for i in range(R)]

def bfsC(init_y, init_x, goal_y, goal_x):
    q = deque([[init_y, init_x]])
    dis[init_y][init_x] = 0
    while q:
        y, x = q.popleft()
        if y == goal_y and x == goal_x:
            return dis[y][x]
        distance = dis[y][x]+1
        for dy, dx in [[1,0],[-1,0],[0,1],[0,-1]]:
            if 0 <= y+dy < R and 0 <= x+dx < C and maps[y+dy][x+dx] != '#' and dis[y+dy][x+dx] == -1:
                q.append([y+dy, x+dx])
                dis[y+dy][x+dx] = distance
    return -1 # (見つからなかった)

result = bfsC(0, 0, R-1, C-1) + 1
if result != 0:
    print(whole - result - defoB)
else:
    print(-1)


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

int main()
{
	int a, b, c;
	int k;
	cin >> a >> b >> c;
	cin >> k;

	int tmp = std::max(a, b);
	tmp = std::max(tmp, c);
	int rest = a + b + c - tmp;
	for (int i = 0; i < k; i++)
		tmp *= 2;

	cout << tmp + rest << endl;
    return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int h,w,n;
    cin>>h>>w>>n;
    int x,y;
    cin>>x>>y;
    x--,y--;
    string s,t;
    cin>>s>>t;
    int ans=0;
    int memo;
    memo=y;
    rep(i,n){// Rに落とす
        if(s[i]=='R') memo++;
        if(memo>=w) ans++;
        if(t[i]=='L') memo--;
        chmax(memo,0LL);
    }
    // debug(ans);
    memo=y;
    rep(i,n){// Lに落とす
        if(s[i]=='L') memo--;
        if(memo<0) ans++;
        if(t[i]=='R') memo++;
        chmin(memo,w-1);
    }
    // debug(ans);
    memo=x;
    rep(i,n){// Dに落とす
        if(s[i]=='D') memo++;
        if(memo>=h) ans++;
        if(t[i]=='U') memo--;
        chmax(memo,0LL);
    }
    // debug(ans);
    memo=x;
    rep(i,n){// Dに落とす
        if(s[i]=='U') memo--;
        if(memo<0) ans++;
        if(t[i]=='D') memo++;
        chmin(memo,h-1);
    }
    // debug(ans);
    if(ans!=0){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }
}

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int i = a;i <= b;++i) cout << ary[i] << (b == i ? "]\n" : ", "); } while(0)
#define p_map(map,it) do {cout << "{";for (auto it = map.begin();;++it) {if (it == map.end()) {cout << "}\n";break;}else cout << "" << it->first << "=>" << it->second << ", ";}}while(0)

int main() {
	int n,cnt = 0,l = 0,r = 0;
	vector<int> len(200010,0),p[26];
	string a;
	map<char,bool> b;
	cin >> a;
	n = a.size();

	for (int i = n-1;i >= 0;--i) {
		if (!b[a[i]]) {
			b[a[i]] = true;
			cnt++;
		}
		if (cnt == 26) {
			cnt = 0;
			l++;
			b.clear();
		}
		len[i] = l;
	}
	len[n] = -1;len[n+1] = -1;

	for (int i = 0;i < n;++i) p[a[i]-'a'].push_back(i);
	for (int i = 0;i < 26;++i) p[i].push_back(n);

	for (int i = 0;i < l+1;++i) {
		for (int j = 0;j < 26;++j) {
			int c = *lower_bound(p[j].begin(),p[j].end(),r);
			if (len[r] > len[c+1]) {
				cout << (char)('a'+j);
				r = c+1;
				break;
			}
		}
	}
	cout << endl;
	return 0;
}

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

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"
#define ll long long
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

int main(){
	int n;
	cin >> n;
	double a[n];
	for(int i=0;i<n;i++)	cin >> a[i];
	double sum = 0;
	for(int i=0;i<n;i++)	sum += 1/a[i];
	sum = 1/sum;
	cout << fixed << setprecision(9) << sum <<endl;
	return 0;
}

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

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

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

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

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

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

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


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

    string s;
    cin >> s;
    char var1='0';
    char var2='1';
    ll cost1 = 0;
    ll cost2 = 0;
    F0R(i,s.length()){
      if(s[i] != var1) cost1++;
      if(s[i] != var2) cost2++;
      swap(var1,var2);
    }

    if(cost1 < cost2) cout << cost1 << endl;
    else cout << cost2 << endl;

    return 0;
}

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


Measured memory_bytes: 512
n=int(input())
mod=10**9+7

dp=[[[[0]*5 for _ in range(5)] for _ in range(5)] for _ in range(n+1)]
dp[0][0][0][0]=1

for x in range(n):
    for i in range(5):
        for j in range(5):
            for k in range(5):
                for l in range(1,5):
                    
                    if i==1 and j==2 and l==3:
                        continue
                    if i==1 and k==2 and l==3:
                        continue
                    if j==1 and k==2 and l==3:
                        continue
                    if j==2 and k==1 and l==3:
                        continue
                    if j==1 and k==3 and l==2:
                        continue
                    
                    dp[x+1][j][k][l]=(dp[x+1][j][k][l]+dp[x][i][j][k])%mod
ans=0
for i in range(1,5):
    for j in range(1,5):
        for k in range(1,5):
            ans =(ans+dp[n][i][j][k])%mod

print(ans)



Measured memory_bytes: 48240
#include<bits/stdc++.h>
using namespace std;
int main(void){
   int i,n;
   std::cin >> n;
   int d[n];

   for(i=0 ;i<n;i++){
      std::cin >>d[i];
    }
    sort(d, d+n);
   std::cout << d[(n-1)/2+1]-d[(n-1)/2] << std::endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<set>
using namespace std;
int main()
{
	int n, o, q, x;
	cin >> n;
	set<int> cpp;
	int coun = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		cpp.insert(x);
	}
	cin >> q;
	while (q--)
	{
		cin >> o;
		if (cpp.count(o))coun++;
	}
	cout << coun << endl;
	return 0;

}


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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(N + 1, vector<ll>(N + 1)));
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k <= i; k++) {
				if (1 + (i <= j) + (i <= k) != 1) {
					dp[i][j][k] = mod;
					dp[j][i][k] = mod;
					dp[j][k][i] = mod;
				}
			}
		}
	}
	for (int i = 0; i < M; i++) {
		int l, r, x;
		cin >> l >> r >> x;
		for (int j = 0; j <= r; j++) {
			for (int k = 0; k <= r; k++) {
				if (1 + (l <= j) + (l <= k) != x) {
					dp[r][j][k] = mod;
					dp[j][r][k] = mod;
					dp[j][k][r] = mod;
				}
			}
		}
	}
	dp[0][0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				if (dp[i][j][k] == mod) continue;
				int to = max({ i, j, k }) + 1;
				if (dp[i][j][to] != mod) (dp[i][j][to] += dp[i][j][k]) %= mod;
				if (dp[i][to][k] != mod) (dp[i][to][k] += dp[i][j][k]) %= mod;
				if (dp[to][j][k] != mod) (dp[to][j][k] += dp[i][j][k]) %= mod;
			}
		}
	}
	ll res = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			res = (res + dp[N][i][j]) % mod;
			res = (res + dp[i][N][j]) % mod;
			res = (res + dp[i][j][N]) % mod;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 216832
n = int(input())
ans = 0
for i in range(n + 1):
    if i % 2 == 0:
        continue
    cnt = 0
    for j in range(1, i + 1):
        if i % j == 0:
            cnt += 1
    if cnt == 8:
        ans += 1
print(ans)


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

int main(){
	int n,m;
	cin >> n >> m;
	vector<vector<double> > hei(n);
	for(int i=0; i<n; i++){
		int k;
		cin >> k;
		hei[i].push_back(0);
		for(int j=0; j<k; j++){
			int s,h;
			cin >> s >> h;
			for(int d=0; d<s*h; d++){
				hei[i].push_back(hei[i].back()+(double)1/s);
			}
		}
	}

	vector<double> dp(m+1, 0);
	for(int i=0; i<n; i++){
		auto ndp = dp;
		for(int j=1; j<(int)hei[i].size(); j++){
			for(int k=m; k>=0; k--){
				if(k+j > m) continue;
				ndp[k+j] = max(ndp[k+j], dp[k]+hei[i][j]); 
			}
		}
		dp = ndp;
	}
	cout << fixed << setprecision(10);
	cout << *max_element(dp.begin(), dp.end()) << endl;
    return 0;
}


Measured memory_bytes: 5304
#include <iostream>
#include <string>
using namespace std;
int main(void){
   int a,b,c;
   while(true){
       cin >> a >> b >> c;
       if(a == -1 and b == -1 and c == -1){
           break;
       } else {
           if(a == -1 or b == -1){
               cout << "F" << endl;
           } else if(a + b >= 80){
               cout << "A" << endl;
           } else if(a + b >= 65){
               cout << "B" << endl;
           } else if(a + b >= 50){
               cout << "C" << endl;
           } else if(a + b >= 30){
               if(c >= 50){
                   cout << "C" << endl;
               } else {
                   cout << "D" << endl;
               }
           } else {
               cout << "F" << endl;
           }
       }
   }
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

struct dijkstra{//1-origin
	vector<ll> min_dst;
	vector<vector<P>> G;
	dijkstra(ll n){
		min_dst.resize(n);
		G.resize(n);
	}

	void append(ll u, ll v, ll cost){G[u-1].push_back(P(v-1, cost));}
	
	void run(ll s){
		priority_queue<P, vector<P>, greater<P>> que;
		fill(min_dst.begin(), min_dst.end(), -1);
		min_dst[s-1] = 0;
		que.push(P(0, s-1));
		
		while(!que.empty()){
			P p = que.top(); que.pop();
			ll at = p.second;
			if(min_dst[at] < p.first){continue;}
			for(ll i = 0; i < G[at].size(); i++){
				ll to = G[at][i].first;
				ll cost = G[at][i].second;
				if(min_dst[to] == -1 || min_dst[at]+cost < min_dst[to]){
					min_dst[to] = min_dst[at]+cost;
					que.push(P(min_dst[to], to));
				}
			}
		}	
	}
	
	ll get(ll at){return min_dst[at-1];}
};

ll n, m, l, r, c;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> m;
	dijkstra d(n);
	rep(i, 1, m){
		cin >> l >> r >> c;
		d.append(l, r, c);
	}
	rrep(i, n-1, 1){
		d.append(i+1, i, 0);
	}
	d.run(1);
	print(d.get(n))
	return 0;
}

Measured memory_bytes: 9468
A, B, Q = map(int, input().split())

S = [0]*A
for i in range(A):
  S[i] = int(input())

T = [0]*B
for i in range(B):
  T[i] = int(input())

import bisect
ans = []
for i in range(Q):
  mini = 10**11
  x = int(input())
  indS = bisect.bisect(S,x)
  indT = bisect.bisect(T,x)
  if indS != A: #Sの右
    if indT != B:
        mini = min(max(S[indS],T[indT])-x,mini) #右右
        # print('rr',mini)
    if indT != 0:
        mini = min(S[indS]-T[indT-1]+min(S[indS]-x,x-T[indT-1]),mini) #右左
        # print('rl',mini)
  if indS != 0: #Sの左
    if indT != B:
        mini = min(T[indT]-S[indS-1]+min(x-S[indS-1],T[indT]-x),mini)  #左右
        # print('lr',mini)
    if indT != 0:
        mini = min(x-min(S[indS-1],T[indT-1]),mini) #左左
        # print('ll',mini)
  ans.append(mini)



# print(ans)
print(*ans, sep='\n')

Measured memory_bytes: 104408
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
string S,T,U;
int a,b;
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
inline void smax(int &x,int y) {
	x=x<y?y:x;
}
inline void smin(int &x,int y) {
	x=x>y?y:x;
}
int main() {
//	freopen("in.txt","r",stdin);
	cin>>S>>T;
	cin>>a>>b;
	cin>>U;
	if (U==S) --a;
	else --b;
	cout<<a<<' '<<b<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long long n, k;
	cin >> n >> k;

	vector<pair<int, int> > insertions(n);
	int a, b;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b;
		insertions[i] = {a, b};
	}

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

	vector<long long> count(n);
	map<long long, int> range;
	long long curr = 0;
	for (int i = 0; i < n; ++i) {
		curr += insertions[i].second;
		count[i] = curr;
		range[curr] = insertions[i].first;
	}

	vector<long long>::iterator low = lower_bound(count.begin(), count.end(), k);
	cout << range[*low] << "\n";

	return 0;

}

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

#define ll long long

ll GCD(ll a,ll b)
{
    return __gcd(a,b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,a,tmp=0;
    cin>>n;

    ll sum=0;
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
        for(int k=1;k<=n;k++){

                tmp=GCD(k,GCD(i,j));
                sum+=tmp;

        }
      }

    }

    cout<<sum<<endl;

   return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	//sort(a.begin(),a.end());
	int a, b, c;
	cin >> a >> b;
	c = max(a + b, a - b);
	c = max(c, a * b);
	cout << c;
	return 0;
}









Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int main(){
	int N, K;
	scanf("%d%d", &N, &K);
	int ma = N / 2;
	if(N % 2 == 1) ma++;
	if(ma >= K) printf("YES\n");
	else printf("NO\n");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(void){
   double x1, x2, y1, y2;
   cin >> x1 >> y1 >> x2 >> y2;
   cout << fixed << setprecision(5);
   cout << sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) << endl;
}


Measured memory_bytes: 3272
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
  L = []
  n, m, k = map(int, input().split())
  uf = UnionFind(n+1)
  F = [[] for _ in range(n+1)]
  for _ in range(m):
    a, b = map(int, input().split())
    F[a].append(b)
    F[b].append(a)
    uf.unite(a, b)
  G = [set() for _ in range(n+1)]
  for _ in range(k):
    c, d = map(int, input().split())
    G[c].add(d)
    G[d].add(c)
  for i in range(1, n+1):
    temp = uf.size(i)
    temp -= len(F[i])
    for v in G[i]:
      if uf.same(i, v):
        temp -= 1
    L.append(temp-1)
  print(*L)
    
if __name__ == "__main__":
  main()

Measured memory_bytes: 59412
#include<iostream>

using namespace std;

int m, n;
bool ice[92][92];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int ans = 0;

void search(int x, int y, int count = 1)
{
  ice[x][y] = false;
  for(int i = 0; i < 4; i++)
    if(ice[x + dx[i]][y + dy[i]])
      search(x + dx[i], y + dy[i], count + 1);
    else
      ans = max(count, ans);
  ice[x][y] = true;
  return;
}

int main()
{
  while(cin >> m >> n && (m || n)){

    //part1
    for(int i = 0; i <= n + 1; i++)
      ice[0][i] = ice[m + 1][i] = 0;
    for(int i = 0; i <= m + 1; i++)
      ice[i][0] = ice[n + 1][i] = 0;
    
    for(int i = 1; i <= n; i++)
      for(int j = 1; j <= m; j++)
	cin >> ice[i][j];
    
    //part2
    ans = 0;
    for(int i = 1; i <= n; i++)
      for(int j = 1; j <= m; j++)
	if(ice[i][j])
	  search(i, j);

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

Measured memory_bytes: 1168
// Problem : E - Dist Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 	
int mod=1e9+7;
int po(int x,int y,int m)  { if (y==0) return 1; int t=po(x,y/2,m)%m; t=(t*t)%m; if (y&1) return (t*x)%m;	return t%m; }

signed main() {

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0); 

	int n;
	cin>>n;
	vector<pair<int,int>> v(n);
	for (int i=0;i<n;++i){
		cin>>v[i].first>>v[i].second;
	}   	
	int ans=INT_MIN;
	int mi1=INT_MAX;
	int mi2=INT_MAX;
	int ma2=INT_MIN;
	int ma1=INT_MIN;
	for (int i=0;i<n;++i){
		mi1=min(mi1,v[i].first-v[i].second);
		mi2=min(mi2,v[i].first+v[i].second);
		ma1=max(ma1,v[i].first-v[i].second);
		ma2=max(ma2,v[i].first+v[i].second);
		ans=max({ans,ma2-mi2,ma1-mi1});
	}
	cout<<ans<<endl;
	
	
   
   	return 0;
}

Measured memory_bytes: 6308
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

N = int(input())
if N == 3:
    print("2 5 63")
    exit()
elif N == 4:
    print("2 5 20 63")
    exit()
elif N == 5:
    print("7 1580 9438 11373 22962")
    exit()

numbers = []

for k in range(0, 5000):
    numbers.extend([6*k+2, 6*k+3, 6*k+4, 6*k+6])

ans = numbers[:N]
S = sum(ans)


if S%6 == 0:
    pass
elif S%6 == 2:
    del ans[4]
    ans.append((ans[-1]//6 + 1)*6)
elif S%6 == 3:
    del ans[5]
    ans.append((ans[-1]//6 + 1)*6)
else:
    x, y = (ans[-1]//6)*6+4, (ans[-1]//6)*6+10
    ans.append(x if x > ans[-1] else y)
    del ans[5]
print(*ans)

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

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
const int N = 2e5+5;

ll n , a[N] , dp[N][5];
bool vis[N][5];

ll solve(int i , int rem)
{
    if (i>n) return 0;

    if (vis[i][rem])
        return dp[i][rem];

    ll ans = a[i] + solve(i+2 , rem);
    if (rem) ans = max(ans , solve(i+1 , rem-1));

    vis[i][rem] = 1;
    return dp[i][rem] = ans;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
    }

    ll ans = -2e18 , del = 1 + n%2;

    for(int i=1; i<=del+1; i++)
    {
        ans = max(ans , solve(i , del-(i-1)));
    }

    cout << ans << "\n";


    return 0;
}

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

int bingo(vector<vector<int>> A){
  int a1,a2,a3;
  int b1,b2,b3;
  int c1,c2;
  a1 = A.at(0).at(0) + A.at(0).at(1) + A.at(0).at(2);
  a2 = A.at(1).at(0) + A.at(1).at(1) + A.at(1).at(2);
  a3 = A.at(2).at(0) + A.at(2).at(1) + A.at(2).at(2);
  b1 = A.at(0).at(0) + A.at(1).at(0) + A.at(2).at(0);
  b2 = A.at(0).at(1) + A.at(1).at(1) + A.at(2).at(1);
  b3 = A.at(0).at(2) + A.at(1).at(2) + A.at(2).at(2);
  c1 = A.at(0).at(0) + A.at(1).at(1) + A.at(2).at(2);
  c2 = A.at(0).at(2) + A.at(1).at(1) + A.at(2).at(0);
  if (a1*a2*a3*b1*b2*b3*c1*c2==0){
    return 0;
  }
  else {
    return 1;
  }
}

void change(int b, vector<vector<int>> &A){
  for (int i=0; i<3; i++){
    for (int j=0; j<3; j++){
      if(A.at(i).at(j)==b){
        A.at(i).at(j)=0;
      }
    }
  }
  return;
}

int main(){
  vector<vector<int>> A(3,vector<int>(3));
  for (int i=0; i<3; i++){
    for (int j=0; j<3; j++){
      cin >> A.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  vector<int> b(N);
  for(int i=0; i<N; i++){
    cin >> b.at(i);
  }
  for (int i=0; i<N; i++){
    change(b.at(i),A);
  }
  if(bingo(A)){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,a,b;
  cin >> x >> a >> b;
  
  if (abs(x-a) > abs(x-b)){
    cout << 'B' << endl;
  }
  else {
    cout << 'A' << endl;
  }
}

Measured memory_bytes: 3612
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
typedef vector<int> VI; typedef vector<VI> VVI;
typedef vector<string> VS; typedef vector<VS>VVS;
typedef vector<char> VC; typedef vector<VC>VVC;
typedef pair<int, int> PII;
typedef long long LL;

int main(){
  int H, W;
  cin >> H >> W;
  VVC G(H);

  rep(i,H) {
    string str;
    cin.ignore(1024, '\n');
    cin >> str;

    rep(j,str.size()) {
      G[i].push_back(str[j]);
    }
  }

  vector< queue< pair<int, int> > > foundList;

  queue< pair<int, int> > que_default;
  rep(i,H)
    rep(j,W)
      if (G[i][j] == '#') {
        que_default.push(make_pair(i, j));
        //DEBUG
        //cout << "i : j = " << i << " " << j << endl;
      }

  foundList.push_back(que_default);
  
  int count = 0, flg = 1;
  //上下左右に移動
  int fourSide[4] = { 0, -1, 0, 1 };
  while (flg == 1) {
    flg = 0;
    queue< pair<int, int> > que;
    while (!(foundList[count].empty())) {
      int h0 = foundList[count].front().first;
      int w0 = foundList[count].front().second;
      foundList[count].pop();

      //黒マスに隣接するマスを黒にする
      rep(i, 4) {
        int h1 = h0 + fourSide[(i+1)%4];
        int w1 = w0 + fourSide[i];

        if ((h1 >= H || h1 < 0) || (w1 >= W || w1 < 0))
          continue;

        //h,w共にマス目の範囲内
        if (G[h1][w1] != '#') {
          G[h1][w1] = '#';
          que.push(make_pair(h1, w1));
          flg = 1;
        }
      }
    }
    if (flg == 1) { 
      foundList.push_back(que);
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


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


int main() {
  string text;
  
  cin >> text;
  
  if(text.at(0) == 'a' && text.at(1) == 'b' && text.at(2) == 'c')
    cout << "Yes";
  
  else if(text.at(0) == 'a' && text.at(1) == 'c' && text.at(2) == 'b')
    cout << "Yes";

  else if(text.at(0) == 'b' && text.at(1) == 'a' && text.at(2) == 'c')
    cout << "Yes";
  
  else if(text.at(0) == 'b' && text.at(1) == 'c' && text.at(2) == 'a')
    cout << "Yes";
  
  else if(text.at(0) == 'c' && text.at(1) == 'b' && text.at(2) == 'a')
    cout << "Yes";

  else if(text.at(0) == 'c' && text.at(1) == 'a' && text.at(2) == 'b')
    cout << "Yes";

  else 
    cout << "No";

  
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.abc120
{
  class a
  {
    static void Main(string[] args)
    {
      int[] ABC = GetIntArray();
      int WriteN = 0;
      WriteN = ABC[0] * ABC[2] > ABC[1] ? ABC[1] / ABC[0] : ABC[2];
      Console.Write(WriteN);
    }
    static int GetInt() => int.Parse(Console.ReadLine());
    static int[] GetIntArray()
    {
      string[] r = Console.ReadLine().Split(' ');
      int[] a = new int[r.Length];
      Parallel.For(0, r.Length, i => a[i] = int.Parse(r[i]));
      return a;
    }
  }
}


Measured memory_bytes: 15068
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main() {
  uint16_t r, g, b = 0;
  std::cin >> r >> g >> b;

  std::cout << ((r * 100 + g * 10 + b) % 4 == 0 ? "YES" : "NO") << std::endl;

  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N, M = map(int, input().split())

# 入力値の頂点ペア(辺)を格納する配列
a = [0] * 50
b = [0] * 50
# 頂点ペアが隣接しているかどうかを格納する配列
graph = [[False for i in range(50)] for j in range(50)]
# ある頂点が訪問済かどうかを格納する配列
visited = [False] * N

# 入力値の頂点ペア(辺)を格納していくループ
for i in range(M):
    a[i], b[i] = map(int, input().split())
    # 添字に合わせて入力値から1減らしておく
    a[i] -= 1
    b[i] -= 1
    # 入力値の内容に合わせて、隣接していることを記録
    graph[a[i]][b[i]] = True
    graph[b[i]][a[i]] = True

# 連結かどうか(全ての頂点が訪問済かどうか)を判定するDFS
def dfs(v):
    # 関数内で使用する変数のglobal宣言
    global graph
    global visited
    # 訪問済はやる意味ないのでreturn
    if visited[v]:
        return
    # 通った頂点は訪問済にする
    visited[v] = True
    for v2 in range(N):
        # 隣接している箇所は調べる
        if graph[v][v2]:
            # 調べる必要のある箇所は再帰的に調べていく
            dfs(v2)

ans = 0
# 各辺について、橋かどうかを判定していくループ
for i in range(M):
    # まず該当の辺を外す(この状態で連結ではなくなってしまえばそれは橋)
    graph[a[i]][b[i]] = False
    graph[b[i]][a[i]] = False
    # 訪問済判定を初期化
    for j in range(N):
        visited[j] = False
    # 連結かどうか(全ての頂点が訪問済かどうか)を判定するDFS
    dfs(0)
    # 各頂点について、訪問済かどうかを確認していく
    bridge = False
    for j in range(N):
        # 頂点で一つでも未訪問の箇所があれば橋と判定する
        if visited[j] == False:
            bridge = True
    if bridge:
        ans += 1
    # 外した辺を元に戻す
    graph[a[i]][b[i]] = True
    graph[b[i]][a[i]] = True

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,m;cin>>n>>m;
    vector<ll>par(n+1);
    vector<ll>dim(n+1);
    vector<vector<ll> >G(n+1);
    rep(i,n+m-1){
        ll a,b;cin>>a>>b;
        dim[b]++;
        G[a].pb(b);
    }
    queue<ll>q;
    ll p;
    REP(i,1,n+1){
        if(dim[i]==0)p=i;
    }
    q.push(p);
    while(!q.empty()){
        ll now=q.front();
        q.pop();
        for(auto e:G[now]){
            dim[e]--;
            if(dim[e]==0){
                par[e]=now;
                q.push(e);
            }
        }
    }
    REP(i,1,n+1){
        cout<<par[i]<<endl;
    }
}

Measured memory_bytes: 7808