akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define ll          long long
#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)
#define track(x)                cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define ed(i)       i.end()
#define mem(a)	    memset(a, 0, sizeof(a))
#define MOD         100000000
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int &b) {a = max(a, b); }
void self_min(int &a, int &b) {a = min(a, b); }
#define hell        1000000007
bool isPrime(long int n) 
{
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

long long power1(long long N, long long expo)
{
    long long ans = 1;
    
    while(expo)
    {
        if(expo % 2) {
            ans = ans * N % MOD;
            ans = ans % 10;
        }
        
        N = N * N % MOD;
        N = N % 10;
        expo /= 2;
    }
    
    return ans;
}

long long power(long long N, long long expo)
{
    long long ans = 1;
    
    while(expo)
    {
        if(expo % 2) {
            ans = ans * N % MOD;
        }
        
        N = N * N % MOD;
        expo /= 2;
    }
    
    return ans;
}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { 
    return (a.second < b.second); 
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll dp[200005], arr[200005];
void solve(){
	int n;
	cin >> n;
	rep(i, 0, n)	cin >> arr[i];
	dp[0] = 0, dp[1] = abs(arr[0] - arr[1]);
	for(int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 2] + abs(arr[i - 2] - arr[i]), dp[i - 1] + abs(arr[i] - arr[i - 1]));
	}
	cout << dp[n-1] << endl;

}	
int main() {
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ar[100009];
int main()
{
    ll a,b,ans,sum,mi,p,i,c=0,c1=0,m=0;
    cin>>a>>b;
    ll t=a+b;
    for(int j=b-1;;j--){
            if(c==a-1)break;
     //cout<<j<<" ";
     ar[m++]=j;
    c++;

    }
    for(i=b;;i++){
        if(c1==a)break;
        ar[m]=i;m++;
        //if(i==t) cout<<i;
    //else cout<<i<<" ";
    c1++;
    }
    sort(ar,ar+m);
    for(i=0;i<m;i++){
        if(i==m-1)cout<<ar[i];
        else cout<<ar[i]<<" ";
    }
    cout<<endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string bans(bool ans){
  return (ans?"Yes":"No");
}
map<ll,ll> memo;
ll atack(ll h){
  if(memo[h]>0){
    return memo[h];
  }
  if(h==1)return 1;
  ll ans=atack(h/2);
  ll res=ans*2+1;
  memo[h/2]=ans;
  return res;
}
int main() {
  ll h;cin>>h;
  ll ans=atack(h);
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using lli = long long int;

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


int main() {
    int T;
    cin >> T;
    for (int t = 0; t < T; t++) {
	lli A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A < B || D < B) {
	    cout << "No" << endl;
	    continue;
	}
	if (C >= B) {
	    cout << "Yes" << endl;
	    continue;
	}
	A %= B;
	D %= B;
	lli g = gcd(B, D);
	lli x = (B - A - 1) / g;
	if (A + g * x <= C) {
	    cout << "Yes" << endl;
	}
	else {
	    cout << "No" << endl;
	}
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> box(n);
    vector<bool> virus(n);
    for(int i = 0; i < n; i++)
    {
        box[i] = 1;
        virus[i] = false;
    }
    virus[0] = true;

    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if(virus[a])
        {
            virus[b] = true;
        }
        box[b]++;
        box[a]--;
        if(box[a] == 0)
        {
            virus[a] = false;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(virus[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
M, D = map(int, input().split())
ans = 0
for d in range(1, D + 1):
    d10 = d // 10
    d1 = d % 10
    if d1 < 2:
        continue
    if d10 < 2:
        continue
    if 1 <= d1 * d10 and d1 * d10 <= M:
        ans += 1
    # print(d1, d10)
print(ans)



Measured memory_bytes: 3316
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF = 1e18;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,K;
    cin >> n >> K;
    VP vec(n);
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        vec[i] = {x, y};
    }
    ll res = 5*1e18;
    rep(i,n){
        rep(j,n){
            rep(k,n){
                rep(l,n){
                    if(vec[i].F<=vec[j].F&&vec[k].S<=vec[l].S){
                        ll cou = 0;
                        rep(m,n){
                            if(vec[m].F>=vec[i].F&&vec[m].F<=vec[j].F&&vec[m].S>=vec[k].S&&vec[m].S<=vec[l].S){
                                cou++;
                            }
                        }
                     //   cout<<cou<<endl;
                        if(cou>=K){
                            chmin(res, (vec[j].F - vec[i].F) * (vec[l].S - vec[k].S));
                        }
                    }
                }
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
move = [(0, 1), (1, 1), (-1, 1), (0, -1), (1, -1), (-1, -1), (1, 0), (-1, 0)]
#A
def A():
    a, b, c = LI()
    if a == b:
        print(c)
    if b == c:
        print(a)
    if a == c:
        print(b)
    return

#B
def B():
    h, w = LI()
    s = SR(h)
    for y in range(h):
        for x in range(w):
            if s[y][x] == ".":
                b = 0
                for my, mx in move:
                    ym = my + y
                    xm = mx + x
                    if 0 <= ym < h and 0 <= xm < w:
                        if s[ym][xm] == "#":
                            b += 1
                s[y][x] = b
    for i in range(h):
        print("".join(map(str, s[i])))
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 41328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    pii p[N];
    rep(i, N) cin >> p[i].first >> p[i].second;
    sort(p, p+N, greater<pii>());
    //mR[i]:=[i+1, N)でのRの最小値
    int mR[N];
    mR[N-1] = inf;
    rep3(i, N-2, 0) mR[i] = min(mR[i+1], p[i+1].second);
    int now = p[0].second, ans = 0;
    rep2(i, 1, N-1){
        int l1 = p[0].first, r1 = now, l2 = p[i].first, r2 = p[i].second;
        int tmp1 = max(0, min(r1, mR[i])-l1+1) + max(0, r2-l2+1);
        int tmp2 = max(0, min(r2, mR[i])-l2+1) + max(0, r1-l1+1);
        chmin(now, p[i].second);
        chmax(ans, tmp1), chmax(ans, tmp2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

  unordered_map<string, ll> fst;
  
  for(ll i = 0; i < N; i++){
    string s; cin >> s;
    fst[s]++;
  }

  ll max_n = 0;
  for(auto e: fst){
    max_n = max(max_n, e.second);
  }

  vector<string> ans;
  for(auto e: fst){
    if(e.second == max_n){
      ans.push_back(e.first);
    }
  }

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

  for(auto a : ans)
    cout << a << endl;
}

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

const set<char> m = {'a', 'i', 'u', 'e', 'o'};

string get_code(string s, int k) {
	string ret;
	ret.push_back(s[0]);

	for(int i=1;i<s.size() && ret.size() < k;i++) {
		if(m.count(s[i - 1]) > 0) {
			ret.push_back(s[i]);
		}
	}
	return ret;
}

int main() {

	while(true) {
		int n;
		cin >> n;
		if (n == 0) break;

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

		bool ok = false;
		for(int k=1;k<=50;k++) {
			set<string> codes;
			for(int i=0;i<n;i++) {
				codes.insert(get_code(s[i], k));
			}
			if(codes.size() == n) {
				ok = true;
				cout << k << endl;
				break;
			}
		}
		if(!ok) {
			cout << -1 << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3132
#include <stdio.h>

int md[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char *da[] = {"Wednesday", "Thursday", "Friday",
    "Saturday", "Sunday", "Monday", "Tuesday"};

int main(void)
{
    int m, d;
    int i;

    for (;;) {
        scanf("%d %d", &m ,&d);
        if (m == 0 && d == 0) break;

        for (i = 0; i < m - 1; i++) {
            d += md[i];
        }

        printf("%s\n", da[d % 7]);
    }

    return 0;
}

Measured memory_bytes: 584
(h, w) = list(map(int, input().split()))
a = []
for i in range(h):
    a.append(list(map(int, input().split())))
move = []
def print_move(bh, bw, ah, aw):
    global move
    move.append(str(bh + 1) + ' ' + str(bw + 1) + ' ' + str(ah + 1) + ' ' + str(aw + 1))

for i in range(h - 1):
    for j in range(w):
        if a[i][j] % 2 == 1:
            a[i][j] -= 1
            a[i + 1][j] += 1
            print_move(i, j, i + 1, j)

for j in range(w - 1):
    if a[h - 1][j] % 2 == 1:
        a[h - 1][j] -= 1
        a[h - 1][j + 1] += 1
        print_move(h - 1, j, h - 1, j+1)
print(len(move))
for i in move:
    print(i)

Measured memory_bytes: 16344
A,B,K=map(int,input().split())
ans=[]
for i in range(A,min(A+K,B)):
    ans.append(i)
for i in range(max(A+1,B-K+1),B+1):
    ans.append(i)
if A==B:ans.append(A)
ans=sorted(set(ans))
for i in ans: print(i)

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

int main() {
    int i,n,q,elapsedt=0,head=0,tail;
    vector<pair<string,int> > que(1000000);
    cin>>n>>q;
    tail=n;
    for(i=0;i<n;i++)cin>>que[i].first>>que[i].second;
    while(head!=tail){
        if(que[head].second <= q || (que.size()+tail-head)%que.size() == 1) {
            elapsedt += que[head].second;
            cout<<que[head].first<<" "<<elapsedt<<endl;
            head = (head+1)%que.size();
        } else {
            elapsedt += q;
            que[tail].first = que[head].first;
            que[tail].second = que[head].second - q;
            head = (head+1)%que.size();
            tail = (tail+1)%que.size();
        }
    }
    return 0;
}


Measured memory_bytes: 20872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
const int INF = 0x3f3f3f3f;
const int N = 200000 + 5;
ll a[N];
int b[N];
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> b[i];
		a[b[i]]++;
	}
	ll sum = 0;
	for(int i = 1; i <= n; i++){
		sum += (a[i] * (a[i]-1)/2);
	}
	for(int i = 1; i <= n; i++){
		cout << sum-(a[b[i]]-1) << endl;
	}
    return 0;
}

Measured memory_bytes: 3968
#include <iostream>

using namespace std;

int main(void){
    int a[5];
    int rest = 0;
    int sum = 0;

    for(int i = 0; i < 5; i++){
        cin >> a[i];
    }
    
    for(int j = 1; j <= 10; j++){
        for(int i = 0; i < 5; i++){
            if(a[i] % 10 == j) rest = j - 10;
        }
        if(rest != 0) break;
    }

    for(int i = 0; i < 5; i++){
        if(a[i] % 10 == 0){
            sum += a[i];
        }else{ 
            sum += a[i] / 10 * 10 + 10;
        }
    }
    sum += rest;
    cout << sum << endl;


    return 0;
}

Measured memory_bytes: 256
N, M = [int(s) for s in input().split(' ')]
PY = []
PYsorted = []
for m in range(1, M + 1):
    p, y = [int(s) for s in input().split(' ')]
    PY.append((p, y))
    PYsorted.append((p, y))

PYsorted.sort(key=(lambda x: x[1]))
count = [0] * (N + 1)
ret = dict()

for py in PYsorted:
    p, y = py
    count[p] += 1
    ret[(p, y)] = count[p]

for py in PY:
    p, y = py
    print('%06d%06d' % (p, ret[(p, y)]))


Measured memory_bytes: 43464
def myAnswer(N:int,S:list) -> int:
   counter = 0
   dic = {}
   for s in S:
      if(s in dic.keys()):
         dic[s]+=1
      else:
         dic[s] = 0
   for value in dic.values():
      counter += (value * (value + 1)) // 2
   return counter

def modelAnswer():
   return
def main():
   N = int(input())
   S = ["".join(sorted(list(input()))) for _ in range(N)]
   print(myAnswer(N,S))
if __name__ == '__main__':
   main()

Measured memory_bytes: 19500
#include<stdio.h>
 
int main(){
	int ans, jp, mp, jm, mm, i;
	scanf("%d", &ans);
	scanf("%d %d %d %d", &jp, &mp, &jm, &mm);
	for(i = ans - 1; i >= 1; i--){
		jp -= jm;
		mp -= mm;
		if(jp <= 0 && mp <= 0) break;
	}
	printf("%d\n", i);
	return 0;
}

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

using namespace std;
typedef long long ll;

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

int main(){
// ここに処理を記述

    int N;
    cin >> N;

    vector<int> L;
    int temp = 0;
    for(int i=0; i<N; i++){
        cin >> temp;
        L.push_back(temp);
    }

    sort(L.begin(),L.end(),greater<int>());

    int ans = 0;
    REP(i,N-2){
        int big = i+1;
        int small = N;
        while(L[big] > L[i]/2){
            while(L[big] + L[small] <= L[i]){
                small--;
            }
            ans += small - big;
            big++;
        }
    }

    cout << ans << endl;

return 0;
}

Measured memory_bytes: 256
ref = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
while 1:
    N,M,Q = map(int,raw_input().split())
    if N == 0: break
    sn = set(range(N))
    corr = [set(range(N)) for _ in range(M)]
    s = [0]*N
    for loop in xrange(Q):
        S,B = raw_input().split()
        s = [1-s[i] if S[i] == "1" else s[i] for i in range(N)]
        on  = set([i for i in range(N) if s[i]])
        off = sn-on
        for i in range(M):
            corr[i] &= on if B[i] == "1" else off
    ans = [ref[list(i)[0]] if len(i) == 1 else "?" for i in corr]
    print "".join(ans)
    

Measured memory_bytes: 6760
S = input()

dec = {}

for i in range(4):
    if S[i] not in dec:
        dec[S[i]] = 1
    else:
        dec[S[i]] += 1

ok = True
for i in dec:
    if dec[i] != 2:
        ok = False

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


Measured memory_bytes: 2940
#include<cstdio>
typedef struct{
    int d[26];
}S;

int main(){
    int D, c[26];
    scanf("%d", &D);
    for(int i=0;i<26;i++) scanf("%d", &c[i]);

    S s[D];
    for(int i=0;i<D;i++){
        for(int j=0;j<26;j++) scanf("%d", &s[i].d[j]);
    }
    int ans[D], ans_s[D];
    for(int i=0;i<D;i++){
        ans_s[i] = 0;
        for(int j=0;j<26;j++){
            if(ans_s[i] < s[i].d[j]){
                ans_s[i] = s[i].d[j];
                ans[i] = j+1;
            }
        }
    }
    for(int i=0;i<D;i++) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 1764
#include<iostream>
#include<map>

std::map<int, int> use[10001];
std::map<int, bool> stu[10001];
int N,M,r,t,n,m,s;

int solve(int s, int e, int m){
	int ans = 0;
	int tmp = 0;
	
	for(int i=540; i<=1260; i++){
		if(tmp && i>s && i<=e)
			ans++;
			
		if(use[m][i])
			tmp += use[m][i];
	}

	return ans;
}

int main(){
using namespace std;
	while(1){
		cin >> N >> M;
		if(!N && !M)
			break;
			
		cin >> r;
		for(int i=0; i<r; i++){
			cin >> t >> n >> m >> s;
			if(s)
				use[m][t]++;
			else
				use[m][t]--;
		}
		
		cin >> r;
		for(int i=0; i<r; i++){
			cin >> s >> t >> m;
			cout << solve(s,t,m) << endl;
		}
		
		for(int i=1; i<=M; i++){
			use[i].clear();
			stu[i].clear();
		}
	}
	
	return 0;
}

Measured memory_bytes: 2256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#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())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
#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 ll long long

using namespace std;

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

    string s, t;
    cin >> s >> t;

    

    REP(_,(int)s.length()){
        if (s == t) {
            cout << "Yes";
            return 0;
        }
        char e = s[s.length()-1];
        s.insert(s.begin(),e);
        s.erase(--s.end());
    }
    cout << "No";

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
//Ninda Irvany
int main() {
   int j, k, n, r;
   cin >> n >> r;
   k = 10-n;
   if( n<10 ) {
       cout << r+(100*k) << endl;
   }else{
       cout << r << endl;
   }
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>

using namespace std;

int main () {
    
    int a, b;
    cin >> a >> b;
    
    if (a%2 == 0 || b%2 == 0) {
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }
    
}


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

using namespace std;
using LL = long long;

signed main() {
  // freopen("in", "r", stdin);
  string s;
  cin >> s;
  if (s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;  
  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q; cin >> q;
  set<int> s;
  vector<int> ans;
  REP(i, q){
    int Q, x; cin >> Q >> x;
    if(Q){
      if(s.find(x) != s.end()){
        ans.push_back(1);
      }else{
        ans.push_back(0);
      }
    }else{
      s.insert(x);
      ans.push_back(s.size());
    }
  }
  for(auto &i : ans) cout << i << endl;
}


Measured memory_bytes: 13040
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,l;
    cin>>n>>l;
    int a[n];
    int sum=0;
    for(int i=0;i<n;i++){
        int x=l+i;
        a[i]=x;
        sum+=x;
    }
    int ans = 1e18;
    for(int i=0;i<n;i++){
        int t;
        if(a[i]>0){
            t = sum-a[i];
        }else{
            t = sum+a[i];
        }
        ans = min(ans,abs(t-sum));
    }
    if(sum>0){
        if(ans>0){
            cout<<sum-ans<<endl;
        }else{
            cout<<sum+ans<<endl;
        }
    }else{
        if(ans>0){
            cout<<sum+ans<<endl;
        }else{
            cout<<sum-ans<<endl;
        }
    }
    
    return 0;
    
}


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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()

# まず男女の偶奇を確認する
print(0, flush=True)
s=input()
if s=='Male':
    even='Male'
    odd='Female'
elif s=='Female':
    even='Female'
    odd='Male'
else:
    exit()

def calc(q):
    print(q, flush=True)
    s=input()
    if s=='Vacant':
        exit()
    # 順番が合っているかどうかを判定
    if q%2==0: 
        return s==even
    else: 
        return s==odd

# 二分探索
hi=N-1
low=0
while low+1<hi:
    mid=(hi+low)//2
    if calc(mid):
        # 順番が合っていれば、答えはそこより先にある
        low=mid
    else:
        # 違っていれば、手前にある
        hi=mid
print(hi, flush=True)


Measured memory_bytes: 6060
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x)(x)*(x)
#define fz1(i,n) for (i=1;i<=n;i++)
#define fd1(i,n) for (i=n;i>=1;i--)
#define fz0g(i,n) for (i=0;i<=n;i++)
#define fd0g(i,n) for (i=n;i>=0;i--)
#define fz0k(i,n) for (i=0;i<n;i++)
#define fd0k(i,n) for (i=(long long)(n-1);i>=0;i--)
#define fz(i,x,y) for (i=x;i<=y;i++)
#define fd(i,y,x) for (i=y;i>=x;i--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
long long n,m,i,j,ans;
int main()
{
	scanf("%lld%lld",&n,&m);
	fz0k(i,m)
	{
		j=(m-i)%m;
		if ((j+j)%m!=0) continue;
		long long t1=n/m,t2=n/m;
		if (i!=0&&i<=n%m) t1++;
		if (i!=0&&i<=n%m) t2++;
		ans+=t1*t2*t2;
		if (i!=j){ans+=t1*t2*t2;ans+=t1*t2*t2;}
	}
	printf("%lld\n",ans);
	return 0;
}

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

// main.cpp

typedef std::int_fast64_t i64;

int main() {
  i64 N;
  std::cin >> N;
  std::multiset<i64> D;
  std::copy_n(std::istream_iterator<i64>(std::cin), N, std::inserter(D, D.end()));
  i64 M;
  std::cin >> M;
  std::multiset<i64> T;
  std::copy_n(std::istream_iterator<i64>(std::cin), M, std::inserter(T, T.end()));

  std::cout << (std::includes(D.begin(), D.end(), T.begin(), T.end()) ? "YES" : "NO") << std::endl;
  return 0;
}

Measured memory_bytes: 18944
s = input()
ok=True
if s[0]!='A': ok=False
n = s.find('C')
if not 2<=n<len(s)-1: ok=False
for i in range(len(s)):
    if i!=0 and i!=n and s[i].isupper(): 
        ok=False
print('AC'if ok else 'WA')

Measured memory_bytes: 38384
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

int h,w;
vector<string>field(h);
bool seen[100][100];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int cnt = 0;

int dfs(int y,int x,int &cnt){
    cnt++;
    seen[y][x] = true;
    rep(i,4){
        int ny = y+dy[i],nx = x+dx[i];
        if(ny<0 || ny>=h || nx<0 || nx>=w)continue;
        if(field[ny][nx] != '#')continue;
        if(seen[ny][nx])continue;
        cnt++;
        dfs(ny,nx,cnt);
    }
    return cnt;
}

int main(){
    ll n,m;cin>>n>>m;
    vector<pair<ll,ll>>mp;
    rep(i,n){
        ll a,b;cin>>a>>b;
        mp.emplace_back(a,b);
    }
    sort(ALL(mp));
    ll res = 0;
    for(auto p : mp){
        if(m<=0)break;
        res += (p.first*min(p.second,m));
        m -= min(m,p.second);
    }
    cout<<res<<endl;
}



Measured memory_bytes: 2420
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>



using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a)

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef  long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const double EPS = 1e-7;
const int MAX = 20 * 1000 + 47;
const int MAS = 1e5 * 6;
const int MOD = 1000 * 1000 * 1000 + 7;

double DIST(double x1, double x2, double y1, double y2)
{
    return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}






int main()
{
    int n, w;
    cin >> n >> w;
    vector<pair<int,int >>  v(n);
  
    VI vaga(n), cost(n);
    LL sum = 0;
    rep(i, n)
    {
        cin >> vaga[i] >> cost[i];
        sum += cost[i]; 
    }
   
    vector<LL> dp(sum+ 100,INF);
    dp[0] = 0;  
    rep(i, n)
    {
        RFOR(j, sum - cost[i] + 1, 0)
        {
            dp[j + cost[i] ] = min(dp[j + cost[i]], dp[j] + vaga[i]); 
        }
    }

    int  ans = 0; 
    rep(i, sum + 1)
    {
        if (dp[i] <= w)
        {
            ans = max(ans, i);  
        }
    }
    cout << ans << endl; 


}










Measured memory_bytes: 1024
row1 = list(map(int, input().split()))
row2 = list(map(int, input().split()))
row3 = list(map(int, input().split()))
n = int(input())
bs = []
for i in range(n):
    bs.append(int(input()))

bs = set(bs)

atari = (set(row1) <= bs or
set(row2) <= bs or
set(row3) <= bs or
set([row1[0], row2[0], row3[0]]) <= bs or
set([row1[1], row2[1], row3[1]]) <= bs or
set([row1[2], row2[2], row3[2]]) <= bs or
set([row1[0], row2[1], row3[2]]) <= bs or
set([row1[2], row2[1], row3[0]]) <= bs
)

if atari:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#define ll long long
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define FOR(i, stop) for(int i = 0; i < (stop); i++)
#define PI 3.141592653589793
using namespace std;

int main(){

  int A,B,H,M;
  cin >> A >> B >> H >> M;

  double x,y,rad;

  x = (0.5 * (H * 60 + M));
  y = (M * 6);
  rad = abs(x - y) * PI / 180.0;

  double c = A * A + B * B - 2 * A * B * cos(rad);

  cout << setprecision(14) << sqrt(c) << endl;

  return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

struct SegmentTree{
  vector <ll> Tree[21];
  
  void Make(){
    for (int i = 0; i < 21; i++) {
      Tree[i].resize(1<<i);
    }
  }
  void Add(int num, ll val){
    for (int i = 20; i >= 0; i--){
      Tree[i][num] += val; num /= 2;
    }
  }
  ll Search(int num){
    int now = 20; ll ans = Tree[now][num];
    while (num > 0){
      if (num % 2 != 0) num--;
      else{
        now--; num /= 2; num--;
      }
      ans += Tree[now][num];
    }
    return ans;
  }
};

int N, Q;
string S;
SegmentTree Tree[26];

int main(){
  for (int i = 0; i < 26; i++) Tree[i].Make();

  cin >> N >> S >> Q;
  for (int i = 1; i <= N; i++){
    Tree[S[i-1] - 'a'].Add(i, 1);
  }

  for (int i = 0; i < Q; i++){
    int num; cin >> num;
    if (num == 1){
      int iq; char cq; cin >> iq >> cq;
      Tree[S[iq - 1] - 'a'].Add(iq, -1);
      Tree[cq - 'a'].Add(iq, 1);
      S[iq - 1] = cq;
    }else{
      int L, R; cin >> L >> R;
      int ans = 0;
      for (int j = 0; j < 26; j++){
        if (Tree[j].Search(R) - Tree[j].Search(L - 1) > 0) ans++;
      }
      cout << ans << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 430984
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 505
using namespace std;
ll n,ans=0,dp[N][N],dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
bool vis[N][N];
queue<pair<ll,ll> > q;
void upd(ll x,ll y)
{
	ll i,tx,ty;
	q.push(make_pair(x,y));
	while(!q.empty())
	{
		x=q.front().F;
		y=q.front().S;
		q.pop();
		for(i=0;i<4;i++)
		{
			tx=x+dx[i];
			ty=y+dy[i];
			if(tx>=0&&tx<n&&ty>=0&&ty<n)
			{
				if(vis[x][y])
				{
					if(dp[x][y]<dp[tx][ty])
					{
						dp[tx][ty]=dp[x][y];
						q.push(make_pair(tx,ty));
					}
				}
				else
				{
					if(dp[x][y]+1<dp[tx][ty])
					{
						dp[tx][ty]=dp[x][y]+1;
						q.push(make_pair(tx,ty));
					}
				}
			}
		}
	}
	return;
}
int main(){
	ll i,j,x,y;
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			dp[i][j]=min(min(i,n-i-1),min(j,n-j-1));
		}
	}
	for(i=0;i<n*n;i++)
	{
		scanf("%lld",&x);
		y=(x-1)%n;
		x=(x-1)/n;
		ans+=dp[x][y];
		vis[x][y]=true;
		upd(x,y);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5944
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

const long long int mod=1000000007;
const long long int INF=99999999999999999;



long long int n,m,cou=0,res=0;
string s,t;                
int main() {
	cout << fixed << setprecision(10);
	cin>>n>>m;
	for(int i=0;i<30;i++){
		if((n-1)*i+1>=m){
			cout<<i<<endl;
			return 0;
		}
	}
} 


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

int f( const int N )
{
int i;
int n;
int iSum;

	n = N;
	iSum = 0;
	while( n > 0 )
	{
		iSum += n % 10;
		n /= 10;
	}
	
	return iSum;
}

int main()
{
int F;
int N;

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

	cin >> N;

	F = f( N );

	if( N % F == 0 )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}






Measured memory_bytes: 256
N = int(input())
w = [input() for i in range(N)]
for i in range(len(w) - 1):
    if (w.count(w[i]) > 1): print('No'); exit(0)
    if (w[i][-1] != w[i + 1][0]): print('No'); exit(0)
print('Yes')


Measured memory_bytes: 3060
/*            AUTHOR - SHIVAM GUPTA
                       Jalpaiguri Govt. Engg College             */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const ll p=1e9+7;
vector<ll> v[25];
ll n;
ll memo[(1<<22)];

ll dp(ll mask)
{
    ll x=0;
    x=__builtin_popcount(mask);
    if(x==n)
        return 1;
        
    if(memo[mask] != -1)
        return memo[mask];
        
    if(memo[mask] == -1)
        memo[mask] = 0;
        
    for(auto it : v[x+1])
        if( (mask|(1<<it)) != mask)
            memo[mask] = ( memo[mask] + dp(mask|(1<<it)) ) % p;
            
    return memo[mask];
}

void solve()
{
    vector<pair <ll,ll>> vp;
    map<ll,ll> mp;       set<ll> st;        multiset<ll> mst;
    ll m=0,i=0,j=0,k=0,c=0,l=0,r=0,p=0,q=0,x=0,y=0,z=0,flag=0,sum=0;
    ll a[25][25]={0},b[300005]={0},ans[300005];
    string s,t;
    memset(memo,-1,sizeof(memo));
    cin>>n;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            cin>>a[i][j];
            
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            if(a[i][j]==1)
                v[i+1].push_back(j);
    
    cout<<dp(0)<<endl;
    
}
bool imp=false;int main()
{
    fio;
    int t=1;
    if(imp)
	cin>>t;
	ll j=t;
    while(t--){
    // cout<<"Case #"<<j-t<<": ";
    solve();}
    return 0;
}

Measured memory_bytes: 33024
x,n=map(int, input().split())
P=list(map(int, input().split()))

ans = 200
abs_ans = 200
for i in range(102):
    if i in P:
        continue
    if abs(x-i) < abs_ans:
        ans = i
        abs_ans = abs(x-i)
print(ans)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll h,w; cin>>h>>w;
  if (h%3 == 0 || w%3 == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = inf;
  for (int i=1; i<=h/2; i++) {
    ll j = h-i;
    {
      ll x = i * w;
      ll y = j * (w/2);
      ll z = j * ((w+1)/2);
      ll mi = min(x, min(y, z));
      ll ma = max(x, max(y, z));
      ans = min(ans, abs(ma-mi));
    }
    {
      ll k = j/2;
      ll x = i * w;
      ll y = k * w;
      ll z = (j-k) * w;
      ll mi = min(x, min(y, z));
      ll ma = max(x, max(y, z));
      ans = min(ans, abs(ma-mi));
    }
  }
  for (int i=1; i<=w/2; i++) {
    ll j = w-i;
    {
      ll x = i * h;
      ll y = j * (h/2);
      ll z = j * ((h+1)/2);
      ll mi = min(x, min(y, z));
      ll ma = max(x, max(y, z));
      ans = min(ans, abs(ma-mi));
    }
    {
      ll k = j/2;
      ll x = i * h;
      ll y = k * h;
      ll z = (j-k) * h;
      ll mi = min(x, min(y, z));
      ll ma = max(x, max(y, z));
      ans = min(ans, abs(ma-mi));
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;

const long long TIME_LIMIT=10000;

ll scorecalc(vector<vector<ll>> a, vector<ll> los, ll d, vector<ll> an)
{
    ll ans = 0;
    
    vector<ll> last(los.size(), 0);
    for (int i = 0; i < an.size(); i++)
    {
        ll loss = 0;
        for (int j = 0; j < 26; j++)
        {
            if (j == an[i] - 1)
                continue;

            loss += los[j] * (i+1LL - last[j]);
        }
        ans += a[i][an[i] - 1] - loss;
        last[an[i] - 1] = i + 1LL;
    }

    return ans;
}

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

    ll d;
    cin >> d;
    vector<ll> c(26);
    rep(i, 26)
    {
        cin >> c[i];
    }
    vector<vector<ll>> s(d, vector<ll>(26));
    rep(i, d)
    {
        rep(j, 26)
            cin >> s[i][j];
    }

    vector<ll> ans(d);

    vector<ll> last(26, 0);

    for (ll i = 0; i < d; i++)
    {
        ll lost = 0;
        for (int j = 0;j < 26; j++)
        {
            lost += c[j] * (i + 1 - last[j]);
        }
        ll man = s[i][0]-lost+c[0]*(i+1-last[0]);
        ll manu = 1;
        for (int j = 0; j < 26; j++)
        {
            if (man <= s[i][j]-lost+c[j]*(i+1-last[j]))
            {
                man = s[i][j] - lost + c[j] * (i + 1 - last[j]);
                manu = j + 1LL;
                last[j] = i + 1;
            }
        }
        ans[i] = manu;
    }
    ll score = scorecalc(s, c, d, ans);
    ll times = 0;
    while (times < 10000)
    {
        vector<ll> tmpD(1000);
        rep(j, 1000)
        {
            tmpD[j] = (ll)rand() % d;
        }
        vector<ll> tmpN(1000);
        rep(j, 1000)
        {
            tmpN[j] = ans[tmpD[j]];
            ans[tmpD[j]] = (ll)rand() % 26 + 1;
        }

        if (score >= scorecalc(s, c, d, ans))
            rep(j, 1000)
            ans[tmpD[j]] = tmpN[j];
        else
            score = scorecalc(s, c, d, ans);

        times++;
    }

    rep(i, d)
    {
        cout << ans[i] << endl;
    }

	return 0;

}

Measured memory_bytes: 3840
#include <iostream>
#include <algorithm>

using namespace std;

int num[100000];

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

	int sign = 1;
	int64_t sum = 0;

	for(int i = 0; i < n; ++i){
		int tmp;
		cin >> tmp;
		if(tmp < 0){
			sign *= -1;
			tmp *= -1;
		}
		num[i] = tmp;
		sum += tmp;
	}

	sort(num, num+n);

	if(sign < 0){
		sum -= 2*num[0];
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 640
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n
        self.n = N
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        self.parents[x] = self.find(self.parents[x])
        return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if x > y:
            x, y = y, x

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

    def maxGroup(self):
        return -min(self.parents)

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

for _ in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    uf.union(a, b)

print(uf.maxGroup())



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || '9' < c) break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int main()
{
    int N;

    gc(N);

    vector<int> vi(N + 2, 0);

    FOR(i, 1, N + 1) gc(vi[i]);

    int S = 0;
    FOR(i, 1, N + 2)
    {
        S += abs(vi[i] - vi[i - 1]);
    }

    FOR(i, 1, N + 1)
    {
        int ans =
            S - abs(vi[i] - vi[i - 1]) - abs(vi[i + 1] - vi[i])
            + abs(vi[i + 1] - vi [i - 1]);

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1664
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let vec: Vec<&str> = buf.split_whitespace().collect();
    let a: i32 = vec[0].parse().unwrap();
    let b: i32 = vec[1].parse().unwrap();
    let c: i32 = vec[2].parse().unwrap();
    let d: i32 = vec[3].parse().unwrap();

    if (a-c).abs() <= d || (((a-b).abs() <= d) && ((c-b).abs() <= d)){
        println!("Yes");
    }else {
        println!("No" );
    }
}


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N;
    ll count = 0;
    ll match = 0;
    ll index = 1;
    vector<pair<bool, ll>> lis;
    cin >> N;
    lis.resize(N, pair<bool, ll>{true, 0});
    for(ll i = 0;i < N;i++) cin >> lis[i].second;
    for(ll i = 0;i < lis.size();i++) {
        if(index == lis[i].second) {
            index++;
            match++;
        } else {
            lis[i].first = false;
            count++;
        }
    }
    cout << (match ? count : -1) << endl;
    return 0;
}


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

int sum_digits(int x) {
  int ans = 0;
  while(x > 0) {
    ans += x % 10;
    x /= 10;    
  }
  
  return ans;

}

int main() {
  int N,A,B;
  cin >> N >> A >> B;  
  int ans;
  
  for (int i=1;i<N+1;i++) {
    int y_sum = sum_digits(i);
    if ((y_sum >=A ) && (y_sum <=B )) {
      ans+=i;
    }
  }
  

  cout << ans << endl;
}


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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int N = 200005;

int n, x, y;
int cnt[2005];

int getDist(int a, int b) {
    return abs(b - a);
}

int dist(int a, int b) {
    return min({getDist(a, b), getDist(a, x) + 1 + getDist(b, y), getDist(a, y) + 1 + getDist(b, x)});
}

int main() {
    
    scanf("%d %d %d", &n, &x, &y);
    
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            cnt[dist(i, j)]++;
        }
    }
    
    for (int i = 1; i < n; i++) {
        printf("%d\n", cnt[i]);
    }
    
    return 0;
}


Measured memory_bytes: 256