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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (ll i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        ll sum=0,a=sz(s)-1;
        loop(i,0,a)
        {
            sum+=(s[i]-'0');
        }
        if(sum%9) cout<<"No";
        else cout<<"Yes";

    }
    return 0;
}


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

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

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<bool> Dp(k + 1);
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i <= k; ++i)
		for (auto x : a)
			if (i - x >= 0 && !Dp[i - x])
				Dp[i] = true;
	cout << (Dp[k] ? "First" : "Second");
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,l;
  cin >> n >> l;
  vector<string>s(n);
  for(int i =0;i<n;i++){
    cin>> s.at(i);
  }
  sort(s.begin(),s.end());
  for(int i= 0;i<s.size();i++){
    cout << s.at(i);
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>

int main() {
	int n, m;
	std::cin >> n;

	std::vector<int> tx;
	tx.reserve((size_t) n);
	for (int i = 0; i < n; ++i) {
		int t;
		std::cin >> t;
		tx.push_back(t);
	}

	std::cin >> m;

	std::vector<std::pair<int, int>> px;
	px.reserve((size_t) m);
	for (int i = 0; i < m; ++i) {
		int p, x;
		std::cin >> p >> x;
		px.emplace_back(p, x);
	}

	int tsum = 0;
	for (int i = 0; i < n; ++i) {
		tsum += tx[i];
	}
	for (int i = 0; i < m; ++i) {
		int p, x;
		std::tie(p, x) = px[i];
		tsum += x - tx[p - 1];
		std::cout << tsum << std::endl;
		tsum -= x - tx[p - 1];
	}
}


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

# define ll long long
ll mod=pow(10,9)+7;

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

    ll n;
    map<ll,ll> mp;
    cin>>n;
    string s = to_string(n);

    string s1="";
    for(ll i=0;i<s.length();i++)
        s1+="7";

    ll num=stoi(s1);
    if(num<n)
        num=num*10 + 7;
    ll cnt=to_string(num).length();
    ll rem=num%n;
    ll flag=1;

    while(true){
        rem=num%n;
        if(rem==0)
            break;
        if(mp[num]!=0){
            flag=0;
            break;
        }
        mp[num]++;
        num=rem*10;
        num+=7;
        cnt++;
    }
    if(flag)
        cout<<cnt<<endl;
    else
        cout<<"-1\n";
}



Measured memory_bytes: 66176
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    int a[q];
    rep(i,q){cin >> a[i];
    a[i]--;}
    int f[n];
    rep(i,n)f[i] = k - q;
    rep(i,q)f[a[i]]++;

    int ans = 0;
    rep(i,n){
        if(f[i]>0)yn;
    }

    return 0;
}
 
 


Measured memory_bytes: 1408
#include <iostream>
#include <string.h>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;

#define ll long long

int main () {
  ll a, b, c;
  cin >> a >> b >> c;
  int max = 0;
  if (b > c) {
    max = c;   
  }  
  else {
    max = b;  
  }
  int min = 0;
  if (b + c >= a) {
    min = b + c - a;    
  }
  else {
    min = 0;  
  }
  cout << max << " " << min << endl;
}

Measured memory_bytes: 256
import heapq
N, M = map(int, input().split())
Alist = list(map(lambda x: int(x) * (-1), input().split()))

heapq.heapify(Alist)
for _ in range(M):
    a = heapq.heappop(Alist) * (-1)
    a = a // 2
    heapq.heappush(Alist, a * (-1))

print(sum(Alist) * (-1))

Measured memory_bytes: 14180
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


int n, k;
vector<ll> h;

void solve() {
    ll dp[n];
    rep(i, n) dp[i] = inf;
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; ++i) {
        for (int j = 1; j <= k; ++j) {
            if (i - j >= 0)chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }
    cout << dp[n - 1] << endl;
}

int main() {
    cin >> n >> k;
    h.resize(n);
    rep(i, n) cin >> h[i];
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<set>
#include<queue>
#include<string>
#include<sstream>
#include<iostream>
#include<sstream>
#include<stack>
#include<map>
#include<vector>
using namespace std;
long long c[110000];
long long  n, a, b;

bool ok(long long s)
{
	long long  sum = 0;
	long long num = s * b;
	for (long long  i = 0; i < n; i++)
	{
		long long  ttt = c[i] - num;
		if (ttt > 0)
		{
			if (ttt % (a-b) != 0)sum += (ttt / (a-b) )+ 1;
			else sum +=ttt / (a-b);
			if (sum > s)return false;
		}
	}
	return true;
}
int main()
{
	int i, j;
	scanf("%lld %lld %lld", &n, &a, &b);
	for (i = 0; i < n; i++)
	{
		scanf("%lld", &c[i]);
	}
	long long  ans=0, l=0, r=1999999999;
	while (l <= r)
	{
		long long  mid = (l + r) / 2;
		if (ok(mid))ans = mid, r = mid - 1;
		else l = mid + 1;
	}
	printf("%lld", ans);
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort()
b.sort()
c.sort()

ans = [0 for i in range(n)]
buf = [0 for i in range(n)]

a.reverse()
b.reverse()
c.reverse()
#
# print(a)
# print(b)
# print(c)


ind = 0
for i in range(n):
    buf[i]=buf[i-1]
    if ind > n - 1:
        continue
    while(True):
        if b[i] < c[ind]:
            buf[i] += 1
            ind += 1
            if ind > n-1:
                break
        else:
            break
# print(buf)


ind = 0
for i in range(n):
    ans[i]=ans[i-1]
    if ind > n - 1:
        continue
    while True:
        if a[i] < b[ind]:
            ans[i] += buf[ind]
            ind += 1
            if ind > n-1:
                break
        else:
            break

# print(ans)
print(sum(ans))

Measured memory_bytes: 23476
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    cnt=0
    cntmax=0
    for i in range(n-1):
        if l[i]>=l[i+1]:
            cnt+=1
            cntmax=max(cnt,cntmax)
        else:
            cntmax=max(cnt,cntmax)
            cnt=0
    print(cntmax)
resolve()

Measured memory_bytes: 14252
#include <stdio.h>
#include <string.h>
#define N 10
char a[N], b[N];

int main(void) { 
	scanf("%s", a);
	scanf("%s", b);
	int len = strlen(a);
	int cnt = 0;
	for(int i=0;i<len;i++) {
	    if(a[i] == b[i])cnt ++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 128
import numpy as np
from sys import stdin


def dp_solve(n):
    dp = np.zeros(n+1)
    dp[0] = 1
    pi = list(map(float, stdin.readline().split()))

    for i, p in enumerate(pi):
        dp[1:] = dp[1:]*(1-pi[i]) + dp[:n]*pi[i]
        dp[0] = dp[0]*(1-pi[i])
    return dp


if __name__ == "__main__":
    n = int(input())
    res = dp_solve(n)
    print(sum(res[n//2+1:]))


Measured memory_bytes: 12500
import math
from typing import Union


class Point(object):
    __slots__ = ['x', 'y']

    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Point(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Point(self.x - other.x, self.y - other.y)

    def __mul__(self, other: Union[int, float]):
        return Point(self.x * other, self.y * other)

    def __repr__(self):
        return f"({self.x},{self.y})"


class Segment(object):
    __slots__ = ['pt1', 'pt2', 'vector']

    def __init__(self, x: Point, y: Point):
        self.pt1 = x
        self.pt2 = y
        self.vector = self.pt2 - self.pt1

    def dot(self, other):
        return self.vector.x * other.vector.x + self.vector.y * other.vector.y

    def cross(self, other):
        return self.vector.x * other.vector.y - self.vector.y * other.vector.x

    def norm(self):
        return pow(self.vector.x, 2) + pow(self.vector.y, 2)

    def abs(self):
        return math.sqrt(self.norm())

    def projection(self, pt: Point)-> Point:
        t = self.dot(Segment(self.pt1, pt)) / pow(self.abs(), 2)
        return Point(self.pt1.x + t * self.vector.x, self.pt1.y + t * self.vector.y)

    def reflection(self, pt: Point) -> Point:
        return self.projection(pt) * 2 - pt

    def __repr__(self):
        return f"{self.pt1},{self.pt2},{self.vector}"


def main():
    p0_x, p0_y, p1_x, p1_y = map(int, input().split())
    seg = Segment(Point(p0_x, p0_y), Point(p1_x, p1_y))
    num_query = int(input())
    for i in range(num_query):
        pt_x, pt_y = map(int, input().split())
        reflection = seg.reflection(Point(pt_x, pt_y))
        print("{:.10f} {:.10f}".format(reflection.x, reflection.y))
    return


main()


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

using namespace std;

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

const ll INF=1e9+7;

int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	ll x,y;
    scanf("%lld%lld",&x,&y);
    if(llabs(x-y)>=2)
        printf("Alice\n");
    else
        printf("Brown\n");
    return 0;

	return 0;
}

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

bool isPrime(int num){
    if(num<2){
        return false;
    }else if(num==2){
        return true;
    }else if(num%2==0){
        return false;
    }
    
    double s=sqrt(num);
    for(int i=3;i<=((int)(s+1));i+=2){
        if(num%i==0){
            return false;
        }
    }
    return true;
}

int main(void){
    int x;
    std::cin >> x;
    
    while(true){
        if(isPrime(x)){
            std::cout << x << std::endl;
            break;
        }
        x++;
    }
    
}

Measured memory_bytes: 256
//At coder k stones 
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pri pair<int,int>
#define mpi map<int,int>
#define prl pair<ll,ll>
#define mp make_pair
#define mpl map<ll,ll>
#define umpl unordered_map<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 2e18
#define EPS 1e-3
#define PI 3.1415926535897932385
const double h = 1e-6;
const int MAX_  = 100005;
#define display(v) f(v.size())cout << v[i] << " "
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////
ll dp[3001][3001];
ll get_ac(ll arr[],int i,int j)
{
    if(i==j)
    {
        return arr[i];
    }
   else if(i+1==j)
    {
        return max(arr[i],arr[j]);
    }
    else if(dp[i][j]!=-1)
    {
        return dp[i][j];
    }
    else
    {
        dp[i][j] = max(arr[i]+min(get_ac(arr,i+2,j),get_ac(arr,i+1,j-1)), arr[j] + min(get_ac(arr,i+1,j-1),get_ac(arr,i,j-2)));
        return dp[i][j];
    }
}
int main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n; cin>>n;
    ll sum = 0;
    memset(dp,-1,sizeof(dp));
    ll arr[n]; f(n){cin>>arr[i];sum+=arr[i];}
   // sum = accumulate(arr,arr+n,0);
    ll x = get_ac(arr,0,n-1);
 //   cout << sum << " " << x << "\n";
    ll y = sum - x;
    cout << x-y << "\n";
    
    
    return 0;
 }

Measured memory_bytes: 70784
#include <iostream>
#include <iomanip>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

const double eps = 1e-15;

class Point
{
public:
    double x, y;
    Point() : x(0), y(0) {}
    Point(double _x, double _y) : x(_x), y(_y) {}
};

inline bool operator < (const Point& P, const Point& Q)
{
    if (P.y < Q.y) {
        return true;
    } else if (P.y > Q.y) {
        return false;
    } else if(P.x < Q.x) {
        return true;
    } else {
        return false;
    }
}

istream& operator >> (istream& in, Point& P)
{
    in >> P.x >> P.y;
    return in;
}

ostream& operator << (ostream& out, const Point& P)
{
    out << P.x << " " << P.y;
    return out;
}

class Vector
{
public:
    double x, y;
    Vector() : x(0), y(0) {}
    Vector(const Point& Start, const Point& End) : x(End.x - Start.x), y(End.y - Start.y) {}
    inline double OuterProd(const Vector& V)
    {
        return x * V.y - y * V.x;
    }
    inline bool IsLeftTurn(const Vector& V)
    {
        return (*this).OuterProd(V) > eps;
    }
    inline bool IsRightTurn(const Vector& V)
    {
        return (*this).OuterProd(V) < -eps;
    }
};

void FindHalfHull(const vector<Point>& vP, vector<Point>& vRes)
{
    vRes.clear();
    size_t n = vP.size();
    Point Prev, Now, Next;
    Prev = vP[0];
    Now = vP[1];
    vRes.push_back(Prev);
    vRes.push_back(Now);
    Vector VecPrev(Prev, Now);
    Vector VecNow;
    for (int i = 2; i < n; ++i) {
        Next = vP[i];
        VecNow = Vector(Now, Next);
        if (!VecPrev.IsRightTurn(VecNow)) {
            vRes.push_back(Next);
        } else {
            while (VecPrev.IsRightTurn(VecNow) && vRes.size() >= 3) {
                vRes.pop_back();
                auto it = vRes.end();
                Now = *(--it);
                Prev = *(--it);
                VecNow = Vector(Now, Next);
                VecPrev = Vector(Prev, Now);
            }
            if (VecPrev.IsRightTurn(VecNow) && vRes.size() == 2) {
                vRes.pop_back();
                Now = vRes[0];
                VecNow = Vector(Now, Next);
            }
            vRes.push_back(Next);
        }
        Prev = Now;
        Now = Next;
        VecPrev = VecNow;
    }
    vRes.pop_back();
}

ostream& operator << (ostream& out, vector<Point> vP)
{
    size_t n = vP.size();
    for (int i = 0; i < n; ++i) {
        out << vP[i] << endl;
    }
    return out;
}

int main()
{
    int n;
    cin >> n;
    vector<Point> vP(n);
    for (int i = 0; i < n; ++i) {
        cin >> vP[i];
    }

    vector<Point> vRightHull, vLeftHull;
    
    sort(vP.begin(), vP.end());
    FindHalfHull(vP, vRightHull);

    reverse(vP.begin(), vP.end());
    FindHalfHull(vP, vLeftHull);

    cout << vRightHull.size() + vLeftHull.size() << endl;
    cout << vRightHull << vLeftHull;
    getc(stdin);
    return 0;
}


Measured memory_bytes: 6740
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    int a[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    int n;
    cin>>n;
    for(int k=0;k<n;k++){
        int x;
        cin>>x;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(a[i][j]==x){a[i][j]=0;}
            }
        }
    }
    int flg=0;
    for(int i=0;i<3;i++){
        if(a[i][0]==0&&a[i][1]==0&&a[i][2]==0){flg=1;}
    }
    for(int j=0;j<3;j++){
        if(a[0][j]==0&&a[1][j]==0&&a[2][j]==0){flg=1;}
    }
    if(a[0][0]==0&&a[1][1]==0&&a[2][2]==0){flg=1;}
    if(a[0][2]==0&&a[1][1]==0&&a[2][0]==0){flg=1;}

    if(flg==1){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF=2305843009213693951;//巨大な定数
const int dx[]={0,1,0,-1};//x方向のベクトル
const int dy[]={1,0,-1,0};//y方向のベクトル

int main(){
    //入力
    ll h,w,ch,cw,dh,dw;
    cin>>h>>w>>ch>>cw>>dh>>dw;
    vector<vector<char>> S(h,vector<char>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>S[i][j];
        }
    }

    //1-indexedなので0-indexedに直す
    ch--;
    cw--;
    dh--;
    dw--;

    //BFS用のqueue
    //HとWには移動1で行けるH座標とW座標
    //H2とW2には移動2でH座標とW座標
    queue<ll> H,H2,W,W2;

    //初期地点をH,Wに追加
    H.push(ch);
    W.push(cw);

    //最低何回の魔法でたどり着けるかを記録する
    //巨大な数INFで初期化する
    vector<vector<ll>> T(h,vector<ll>(w,INF));

    //初期地点は0回の魔法でたどり着く
    T[ch][cw]=0;

    //BFSをする
    while(!H.empty()){
        while(!H.empty()){
            //現在の座標
            ll nh=H.front();
            ll nw=W.front();
            //queueから削除
            H.pop();
            W.pop();

            //移動A
            for(int i=0;i<4;i++){
                //移動先の座標
                ll th=nh+dx[i];
                ll tw=nw+dy[i];

                //範囲外になってないかチェック
                if(th>=h||th<0||tw>=w||tw<0){
                    continue;
                }

                //壁かチェック
                if(S[th][tw]=='#'){
                    continue;
                }

                //魔法の回数が多い場合更新
                if(T[th][tw]>T[nh][nw]){
                    T[th][tw]=T[nh][nw];
                    H.push(th);
                    W.push(tw);
                }
            }

            //移動B
            for(int i=-2;i<=2;i++){
                for(int j=-2;j<=2;j++){
                    //移動先の座標
                    ll th=nh+i;
                    ll tw=nw+j;

                    //範囲外になってないかチェック
                    if(th>=h||th<0||tw>=w||tw<0){
                        continue;
                    }

                    //移動先が壁かチェック
                    if(S[th][tw]=='#'){
                        continue;
                    }

                    //魔法の回数が多い場合更新
                    if(T[th][tw]>T[nh][nw]+1){
                        T[th][tw]=T[nh][nw]+1;
                        H2.push(th);
                        W2.push(tw);
                    }
                }
            }
        }
        //
        swap(H,H2);
        swap(W,W2);
    }

    //ゴールに到達出来ない場合
    if(T[dh][dw]==INF){
        cout<<-1<<endl;
    }
    
    //到達できる場合
    else{
        cout<<T[dh][dw]<<endl;
    }
}

Measured memory_bytes: 12456
#include <stdio.h>
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if(a==1&&b==2||a==2&&b==1)
	    printf("3\n");
	if(a==1&&b==3||a==3&&b==1)
	    printf("2\n");
	if(a==3&&b==2||a==2&&b==3)
	    printf("1\n");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    string s, t; cin >> s >> t;
    int A, B; cin >> A >> B;
    string u; cin >> u;
    if (s == u){
        cout << A - 1 << " " << B << endl;
    }
    else {
        cout << A << " " << B - 1 << endl;
    }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,A,B,C,D; cin>>N>>A>>B>>C>>D;
  string S; cin>>S;
  A--; B--; C--; D--;
  if(A>B){
    swap(A,B);
    swap(C,D);
  }
  string ans="Yes";
  REP(i,A+2,C){
    if(S[i]=='#'&&S[i-1]=='#'){
      ans="No";
      break;
    }
  }
  if(ans=="Yes"){
    if(C<D){
  REP(i,B+2,D){
    if(S[i]=='#'&&S[i-1]=='#'){
      ans="No";
      break;
    }
  }
    }
    else{
      ans="No";
      REP(i,B+1,D+1){
    if(S[i]=='.'&&S[i-1]=='.'&&S[i-2]=='.'){
      ans="Yes";
      break;
    }
  }
    }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

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

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> p)
{
    int cnt = 0;

    for (int i = 0; i < N; i++)
    {
        if (p[i] != i + 1)
        {
            cnt++;
        }
        else
        {
        }
    }
    if(cnt <= 2){
        cout << YES << endl;
    }else{
        cout << NO << endl;
    }
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> p(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &p[i]);
    }
    solve(N, std::move(p));
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	auto b = vector<int>(100002);
	for(auto i = 0; i < n; ++i){
		int a;
		cin >> a;
		if(a > 0) ++b[a - 1];
		++b[a];
		++b[a + 1];
	}
	int cnt = 0;
	for(auto i = 0; i <= 100001; ++i){
		cnt = max(cnt, b[i]);
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std; 
typedef vector<int> ve;
int n,k;
ve p,q,A,B,ip,iq;
void re(ve &x) {
	x.resize(n+1);
	fill(x.begin(),x.begin()+1+n,0);
}
ve inv(ve a) {
	ve orz;
	re(orz);
	for(int i=1;i<=n;i++) {
		orz[a[i]] = i;
	}
	return orz;
}
ve operator*(ve aa,ve bb) {
	ve orz; re(orz);
	for(int i=1;i<=n;i++) {
		orz[i] = aa[bb[i]];
	}
	return orz;
}
ve ksm(ve aa,int b) {
	ve orz; re(orz);
	for(int i=1;i<=n;i++) orz[i] = i;
	for(;b;b>>=1,aa = aa*aa) {
		if(b&1) {
			orz = orz*aa;
		}
	}
	return orz;
}
int main() {
	scanf("%d%d",&n,&k);
	re(p); re(q);
	for(int i=1;i<=n;i++) scanf("%d",&p[i]);
	for(int i=1;i<=n;i++) scanf("%d",&q[i]);
	ip = inv(p); iq = inv(q);
	ve yooo = q*ip*iq*p;
	A = ksm(yooo,(k-1)/6);
	int yo = k - (k-1)/6*6;
	switch(yo) {
		case 1:{
			B = p;
			break;
		}
		case 2:{
			B = q;
			break;
		}
		case 3:{
			B = q * ip;
			break;
		}
		case 4:{
			B = ip;
			A = A*q;
			break;
		}
		case 5:{
			B = iq;
			A = A*q*ip;
			break;
		}
		case 6:{
			B = iq*p;
			A = A*q*ip;
			break;
		}
	}
	ve ans = A * B * inv(A);
	for(int i=1;i<=n;i++) {
		printf("%d ",ans[i]);
	}
}

Measured memory_bytes: 5880
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 200500;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
     ll n,k;
     cin >> n >> k;
     ll ans = 0;
     for(ll i=k;i<=n+1;i++)
     {
          ll mini = (i*(i-1))/2;
          mini %= MOD;
          ll maxi =  (i*n)%MOD - mini + MOD;;
          maxi %= MOD;
          maxi = maxi - mini + MOD;
          maxi %= MOD;
          maxi++;
          ans = (ans + maxi)%MOD;
     }
     cout<<ans;
}

int main()
{
     FAST;
     ll t = 1;
   //  cin >> t;
     while(t--)
     {
          solve();
     }
}

Measured memory_bytes: 3648
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	char s[11];
	int i,flg1,flg2,cnt,len,x;
	scanf("%s",s);
	len=strlen(s);
	flg1=1;
	if(s[0]!='A')	flg1=0;
	cnt=0;
	for(i=2;i<=len-2;i++)	{
		if(s[i]=='C')	{
			cnt++;
			x=i;
		}
	}
	if(cnt!=1)	flg1=0;
	else {
		flg2=1;
		for(i=1;i<len;i++)	{
			if(i!=x)	{
				if(s[i]<'a' || s[i]>'z')	{
					flg2=0;	break;
				}
			}
		}
		if(flg2==0)	flg1=0;
	}
	if(flg1==0)	printf("WA\n");
	else printf("AC\n");
	return 0;
}

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

int n;
int a[210];

int main(){
    cin>>n;

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

    int cnt=0;

    while(true){
        bool odd_exists = false;
        for (int i = 0; i < n; i++)
        {
            if(a[i]%2==1) odd_exists = true;
        }
        
        if(odd_exists) break;

        cnt++;
        
        for (int i = 0; i < n; i++)
        {
            a[i] = a[i]/2;
        }
    }
    
    cout << cnt << endl;



    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  cout << ((N - 1) / 111 * 111 + 111) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>

using namespace std;

struct union_find {
    vector<int> par, sz;

    union_find(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i =0; i < n; i++)
            par[i] = i, sz[i] = 0;
    }

    int find(int x) {
        if (par[x] == x)
            return x;
        else 
            return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);

        if (x == y) return ;

        else if (sz[x] < sz[y])
            par[x] = y;
        else {
            par[y] = x;
            if (sz[x] == sz[y])
                sz[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int main() {
    int n, m;   cin >> n >> m;
    union_find u(n);

    for (int i = 0; i < m; i++) {
        int x, y, z;    cin >> x >> y >> z;
        u.unite(x-1, y-1);
    }

    set<int> s;
    for (int i = 0; i < n; i++) {
        s.insert(u.find(i));
    }

    cout << s.size() << endl;

    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll _() {
	ll x=0,f=1; char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())
		if(ch=='-')f=-f;
	for(;ch>='0'&&ch<='9';ch=getchar())
		x=x*10+ch-'0';
	return x*f;
}
#define _ _()
int n,m;
ll f[405*405],w[405*405],b[405*405];
ll ans;
char s[405][405];
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
inline int find( int x ) { return f[x]==x?x:f[x]=find(f[x]); } 
int main() {
	n=_; m=_;
	for( int i=1;i<=n*m;i++ ) f[i]=i;
	for( int i=1;i<=n;i++ ) scanf("%s",s[i]+1);
	for( int i=1;i<=n;i++ ) 
		for( int j=1;j<=m;j++ ) {
			for( int k=0;k<4;k++ ) {
				int nx=i+dx[k],ny=j+dy[k];
				if(nx<1||ny<1||nx>n||ny>m) continue;
				if(s[nx][ny]!=s[i][j]) {
					int fx=find((nx-1)*m+ny),fy=find((i-1)*m+j);
					f[fx]=f[fy]; 
				}
			}
		}
	for( int i=1;i<=n;i++ ) 
		for( int j=1;j<=m;j++ ) 
			if(s[i][j]=='#') b[find((i-1)*m+j)]++;
			else w[find((i-1)*m+j)]++;
	for( int i=1;i<=n*m;i++ )
		ans+=b[i]*w[i];
	printf("%lld\n",ans);
}

Measured memory_bytes: 4224
#include<cstdio>

int main(){
    int n;
    scanf("%d",&n);
    int b,f,r,v;
    int first[3][10];
    int second[3][10];
    int third[3][10];
    int forth[3][10];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            first[i][j] = 0;
            second[i][j] = 0;
            third[i][j] = 0;
            forth[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        if(b == 1){
            first[f - 1][r - 1] += v;
        }
        else if(b == 2){
            second[f - 1][r - 1] += v;
        }
        else if(b == 3){
            third[f - 1][r - 1] += v;
        }
        else if(b == 4){
            forth[f - 1][r - 1] += v;
        }
    }
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            printf(" %d",first[i][j]);
        }
        printf("\n");
    }
    printf("####################\n");
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            printf(" %d",second[i][j]);
        }
        printf("\n");
    }
    printf("####################\n");
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            printf(" %d",third[i][j]);
        }
        printf("\n");
    }
    printf("####################\n");
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            printf(" %d",forth[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2712
import sys
import itertools
import numpy as np

n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

tmp = make_divisors(n)
tmp.sort()
sq = np.sqrt(n)
tmpnum = n
for i in tmp:
    if i > sq:
        break
    else:
        tmpnum = min(tmpnum-1, n//i + i - 2)
print(tmpnum)

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

int main(){
  map<string, int> mp;
  string word_before = "";
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    mp[s]++;
    if(i == 0){
      word_before = s;
      reverse(word_before.begin(), word_before.end());
      continue;
    }
    if(word_before[0] != s[0] || mp[s] > 1){
      cout << "No" << endl;
      return 0;
    }
    word_before = s;
    reverse(word_before.begin(), word_before.end());
  }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3612
#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set> 
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define inf 200001
#define INF (int)1e9
#define mod (int)(1e9+7)
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;
int n;
 
struct edge{
    int y,nxt;
    edge(){}
    edge(int yy,int nn){
        y=yy,nxt=nn;
    }
}e[inf*2];
int head[inf],ecnt;
 
void addedge(int x,int y){
    ecnt++;
    e[ecnt]=edge(y,head[x]);
    head[x]=ecnt;
    return;
}

int p[inf],siz[inf],fa[inf],maxs[inf],maxf[inf],maxe[inf],maxex[inf];

void dfs1(int u,int last){
	fa[u]=last;
	siz[u]=p[u];
	maxs[u]=0;
	maxe[u]=INF;
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].y;
		if (v==last){
			continue;
		}
		dfs1(v,u);
		maxs[u]=max(maxs[u],maxs[v]+1);
		siz[u]+=siz[v];
		if (maxe[v]!=INF){
			maxe[u]=min(maxe[u],maxs[v]+1);
		}
	}
	if (p[u]){
		maxe[u]=min(maxe[u],maxs[u]);
	}
	return;
}

int sta[inf],top;

void dfs2(int u){
	maxf[u]=max(maxf[u],(fa[u]!=0)+maxf[fa[u]]);
	if (fa[u]){
		maxex[u]=max(maxex[u],maxf[u]-1);
	}
	int now=-1,top=0;
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].y;
		if (v==fa[u]){
			continue;
		}
		sta[++top]=v;
		maxf[v]=max(maxf[v],now+1);
		now=max(now,maxs[v]+1);
	}
	now=-1;
	for (int i=top;i>=1;i--){
		int v=sta[i];
		maxf[v]=max(maxf[v],now+1);
		now=max(now,maxs[v]+1);
	}
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].y;
		if (v!=fa[u]){
			dfs2(v);
		}
	}
	return;
}

int main(){
	rd(n)
    int x,y;
    for (int i=1;i<n;i++){
        rd(x) rd(y)
        addedge(x,y);
        addedge(y,x);
    }
    for (int i=1;i<=n;i++){
        char c=getchar();
        (c!='1' && c!='0')?c=getchar():p[i]=c-'0';
    }
    dfs1(1,0);
    dfs2(1);
    ll ans=0LL;
    for (int i=1;i<=n;i++){
    	int minv,maxv;
    	if (p[i]){
    		minv=0;
		}
		else{
			minv=min(maxe[i],(siz[1]==siz[i])?INF:maxf[i]);
		}
		maxv=max(maxs[i],maxf[i])-1;
		for (int j=head[i];j;j=e[j].nxt){
			int v=e[j].y;
			if (v!=fa[i]){
				maxv=min(maxv,maxex[v]+1);
			}
		}
		if (fa[i]){
			maxv=min(maxv,maxs[i]+1);
		}
		if (maxv>=minv){
			ans+=(ll)maxv-(ll)minv+1LL;
		}
	}
	printf("%lld\n",ans+1LL);
	return 0;
}

Measured memory_bytes: 16768
n = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))
T = sum(t)*2
kukan = [(0,0,0)]
for i in range(n):
    kukan.append((kukan[i][1],kukan[i][1]+t[i]*2,v[i]))
kukan.append((T,T,0))
vt = [[1000]*(len(kukan)) for _ in range(T+1)]
k = 0
for ts,te,v_ in kukan:
    for i in range(ts,te+1):
        vt[i][k] = v_
    for i in range(ts-1,-1,-1):
        vt[i][k] = vt[i+1][k]+0.5
    for i in range(te+1,T+1):
        vt[i][k] = vt[i-1][k]+0.5
    k += 1
ans = 0
d = [0]*len(vt)
for i in range(len(vt)):
    d[i] = min(vt[i])
for i in range(1,len(vt)):
    ans += (d[i]+d[i-1])*0.25
print(ans)

Measured memory_bytes: 134900
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}


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

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from math import floor, ceil

def main():
    H, W = map(int, readline().rstrip().split())
    ans = H * W
    if H >= 3:
        ans = min(ans, abs(W*(H//3) - W*(H-H//3*2)))
    if W >= 3:
        ans = min(ans, abs(H*(W//3) - H*(W-W//3*2)))
    
    # 縦にスライス + 残りに横にスライス
    # x1_cand = [floor(W/3), ceil(W/3)]
    x1_cand = [i for i in range(1, W)]
    y1 = H
    for x1 in x1_cand:
        x2 = W - x1
        x3 = x2
        y2 = H // 2
        y3 = H - y2
        ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))

        x2 = (W-x1) // 2
        x3 = (W-x1-x2)
        ans = min(ans, max((x1*H), (x2*H), (x3*H)) - min((x1*H), (x2*H), (x3*H)))

    # 横にスライス + 残りに縦にスライス
    # y1_cand = [floor(H/3), ceil(H/3)]
    y1_cand = [i for i in range(1, H)]
    x1 = W
    for y1 in y1_cand:
        y2 = H - y1
        y3 = y2
        x2 = W // 2
        x3 = W - x2
        ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))

        y2 = (H-y1) // 2
        y3 = (H-y1-y2)
        ans = min(ans, max((W*y1), (W*y2), (W*y3)) - min((W*y1), (W*y2), (W*y3)))

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 11060
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

struct UnionFind{
	vector<int> par;//par[i]:=(0以上の場合,iの親. 0未満の場合はiを含むグループのサイズ).
	int num;		//num:=(Number of groups).
	
	UnionFind(int n):par(n,-1),num(n){}//Constructor.
	
	void reset(int n){par.assign(n,-1), num=n;}
	int root(int x){return (par[x]<0)?x:par[x]=root(par[x]);}//Recrusion.
	int size(int x){return -par[root(x)];}
	bool same(int x,int y){return root(x)==root(y);}
	bool unite(int x,int y){
		x=root(x), y=root(y);
		if(x==y) return false;//Do nothing.
		if(size(x)<size(y)) swap(x,y);//Merge technique.
		par[x]+=par[y];
		par[y]=x;
		num--;
		return true;
	}
};

int main(){
	int n,m,k;
	cin>>n>>m>>k;
	
	vi a(m),b(m);
	REP(i,m){
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
	}
	
	vi c(k),d(k);
	REP(i,k){
		cin>>c[i]>>d[i];
		c[i]--, d[i]--;
	}
	
	UnionFind fri(n);
	vi ans(n,n-1);
	REP(i,m){
		ans[a[i]]--;
		ans[b[i]]--;
		if(!fri.same(a[i],b[i])) fri.unite(a[i],b[i]);
	}
	
	REP(i,k){
		if(fri.same(c[i],d[i])){
			ans[c[i]]--;
			ans[d[i]]--;
		}
	}
	
	REP(i,n){
		debug(fri.size(i));
		ans[i]-=n-fri.size(i);
	}
	
	line(ans);
}

Measured memory_bytes: 3200
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <set>
#include <functional>

using namespace std;

int d[102];
int main()
{
    int n,a,b,c,x;
    while(true){
        cin>>n>>a>>b>>c>>x;
        int tot=0;
        if(n==0){
            break;
        }
        for(int i=0;i<n;i++){
            cin>>d[i];
        }
        for(int i=0;i<n;i++){
            if(i>0){
                tot++;
                x=(a*x+b)%c;
            }
            while(true){
                if(x==d[i]){
                    break;
                }
                x=(a*x+b)%c;
                //cout<<"x: "<<x<<endl;
                tot++;
                if(tot>10000){
                    tot=-1;
                    goto next;
                }
            }
        }
    next:cout<<tot<<endl;
    }
    return 0;
}

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

int main(){
    string s;cin>>s;
    char c=s[0];
    int ans=0;
    for(int i=1;i<s.length();++i){
        if(s[i]!=c){
            ans++;
            c=s[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main() {
	int N, M; cin >> N >> M;
	vector<int> v(N);
	for (int i = 0; i < N; ++i) {
		v[i] = i;
	}
	for (int i = 0; i < M; ++i) {
		int a, b; scanf("%d,%d", &a, &b); --a, --b;
		swap(v[a], v[b]);
	}
	for (int i = 0; i < N; ++i) {
		cout << v[i]+1 << endl;
	}
}

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

int main(){
  string c;
  cin >> c;
  
  if(c == "a")
    cout << "vowel" << endl;
   else if(c == "i")
    cout << "vowel" << endl;
  else if(c == "u")
    cout << "vowel" << endl;
  else if(c == "e")
    cout << "vowel" << endl;
  else if(c == "o")
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

template <typename T> ll sum(const T first, const T last) {
    ll t = 0;
    for (auto it = first; it != last; it++) {
        t += *it;
    }
    return t;
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(ALL(a));

    ll t;
    ll t1 = 0;
    ll t2 = 0;
    if (n % 2 == 1) {
        for (int i = 0; i < n / 2; i++) {
            t1 += a[i];
        }
        for (int i = n / 2 + 1; i < n; i++) {
            t2 += a[i];
        }
        t = max({
            (t1 * 2 + a[n / 2] * 2 - (a[n / 2] + a[n / 2 - 1])) - (t2 * 2),
            (t2 * 2) - (t1 * 2 + a[n / 2] * 2 - (a[n / 2] + a[n / 2 - 1])),
            (t2 * 2 + a[n / 2] * 2 - (a[n / 2] + a[n / 2 + 1])) - (t1 * 2),
            (t1 * 2) - (t2 * 2 + a[n / 2] * 2 - (a[n / 2] + a[n / 2 + 1]))
        });

    } else {
        for (int i = 0; i < n / 2; i++) {
            t1 += a[i];
        }
        for (int i = n / 2; i < n; i++) {
            t2 += a[i];
        }
        t = max({
            t1 * 2 - t2 * 2 - a[n / 2 - 1] + a[n / 2],
            t2 * 2 - t1 * 2 - a[n / 2] + a[n / 2 - 1]
        });
    }
 
    cout << t << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  string s;
  R s;
  bool f1=0,f2=0;
  REP(m,1,13) {
    string r="";
    stringstream ss;
    ss << m;
    ss >> r;
    if(r.size()==1) r="0"+r;
    rep(y,100) {
      string t="";
      stringstream ss2;
      ss2 << y;
      ss2 >> t;
      if(t.size()==1) t="0"+t;
      if(r+t==s) f2=1;
      if(t+r==s) f1=1;
    }
  }
  if(f1&&f2) pr("AMBIGUOUS");
  else if(f1) pr("YYMM");
  else if(f2) pr("MMYY");
  else pr("NA");
}

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


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int A, B, C, D; cin >> A >> B >> C >> D;
  A -= C;
  B -= D;
  A = abs(A);
  B = abs(B);
  LL g = __gcd(A,B);
  A /= g;
  B /= g;
  cout << (A+B-1)*g << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC106_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var K = long.Parse(Console.ReadLine());

            for (int i = 0; i < K; i++)
            {
                var numi = long.Parse(S[i].ToString());
                if (numi != 1)
                {
                    Console.WriteLine(S[i]);
                    return;
                }
            }
            Console.WriteLine(1);
        }
    }
}


Measured memory_bytes: 13140