akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vstr=vector<string>;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }



void solve() {
    ll N,M;
    cin >> N >> M;
    vvll to[N];
    set<ll> from1,toN;
    ll a,b;
    rep(i,M){
       cin >> a >> b;
    //    a--;b--;
    //    to[a].pb(b); 
       if(a==1){
           from1.insert(b);
       }
       if(b==N){
           toN.insert(a);
       }
    }

    bool ok = false;
    for(auto x:from1){
        if(toN.find(x) != toN.end()){
            ok = true;
            break;
        }
    }
    print(ok ? "POSSIBLE" : "IMPOSSIBLE");
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 17660
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << (x) << ", "
#define de(x) cout << #x << " = " << (x) << "\n"
#define endl "\n"

//-----
const int N = 2e5 + 7;
int n, a[N];
ll sadd[N], sxor[N];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> n; 
	rep(i, 1, n + 1) {
		cin >> a[i];
		sxor[i] = sxor[i - 1] ^ a[i];
		sadd[i] = sadd[i - 1] + a[i];
	}
	int beg = 0;
	ll ans = 0;
	rep(i, 1, n + 1) {
		while ((sxor[i] ^ sxor[beg]) != (sadd[i] - sadd[beg])) beg++;
		ans += i - beg;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4224
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MOD ((ll)1e9 + 7)
#define MAXN (1 << 10)

ll a[MAXN], b[MAXN];

int main() {
	ll n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int j = 0; j < m; j++) {
		cin >> b[j];
	}
	sort(a, a + n);
	sort(b, b + m);
	reverse(a, a + n);
	reverse(b, b + m);
	int cura = 0;
	int curb = 0;
	int inda = 0;
	int indb = 0;
	ll cur = n * m;
	ll ret = 1;
	//termination on cur?
	while (((inda < n) || (indb < m)) || (cur)) {
		// handle too big numbers later
		if ((a[inda] == cur) && (b[indb] == cur)) {
			inda++;
			indb++;
			cura++;
			curb++;
		} else if (a[inda] == cur) {
			inda++;
			cura++;
			ret *= curb;
			ret %= MOD;
		} else if (b[indb] == cur) {
			indb++;
			curb++;
			ret *= cura;
			ret %= MOD;
		} else {
			int left = cura * curb - (n * m - cur);
			ret *= left;
			ret %= MOD;
		}	
		cur--;
		if (!cur) {
			break;
		}
	}
	if ((inda != n) || (indb != m)) {
		cout << 0 << endl;
		return 0;
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int n; cin >> n;
    unordered_map<string, int> mp;
    REP(i, n){
        string s; cin >> s;
        sort(ALL(s));
        ++mp[s];
    }
    ll ans=0;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        ans += ll(itr->second) * (itr->second - 1) / 2;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 10660
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define dbg(P)      cout<<P<<" "
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)


const ll N   =  200005;
const ll mod = 1e9 + 7;

using namespace std;
vector<ll> bit(N+4);
void update(ll x,ll val)
{
for (;x<=N;x+= (x&-x))
{
    bit[x] = max(val,bit[x]);
}   
}
ll query(ll x)
{
  ll res= 0;
  for (;x>0;x-=(x&-x))
  {
    res = max(res,bit[x]);
  }
  return res;
}

void solve()
{
// string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n;
  ll a[n],h[n];
  for (ll i = 0; i < n; ++i)
  {
  cin>>h[i];
  }
  for (ll i = 0; i < n; ++i)
  {
  cin>>a[i];
  x = query(h[i]-1) + a[i];
  ans = max(ans,x);
  update(h[i],x);
  }
  cout<<ans<<"\n";
}

signed main(){
     
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 4992
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int N =sc.nextInt();
     boolean b = true;
      for(int i=0;i<N;i++){
      int a =sc.nextInt();
      if(a%2==0 && a%3!=0 && a%5!=0){
      b=false;
      }
      }
        System.out.println(b?"APPROVED":"DENIED");
    }
}

Measured memory_bytes: 21844
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>
using namespace std;

#define ll long long
#define dd double

ll  mod =100000009;

ll a[25];
ll b[25];
ll c[25];
char ans[1000000];
char ans1[100000];
char ans2[100000];

ll convert(char x){
    
    ll lol=(ll)x-(ll)'a';
    return lol;
}

void reset (){
    for(int i=0;i<=25;i++){
        c[i]=0;
        b[i]=0;
    }

  
}



int main(){
    ll n;
    cin>>n;
    
    ll cut=1;
    for(int i=0;i<n;i++){
        cin>>ans[i];
        a[convert(ans[i])]=1;
    }
    ll mak=-1;
    while(cut<=n-1){
        for(int i=0;i<cut;i++){
            ans1[i]=ans[i];
            b[convert(ans[i])]=1;
        }
        
        for(int i=cut;i<n;i++){
            ans2[i]=ans[i];
            c[convert(ans[i])]=1;
        }
        
        ll count =0;
        
        for(int i=0;i<=25;i++){
            if(b[i]==1&&c[i]==1){
                count++;
            }
        }
        
        reset();
        mak=max(count,mak);
        cut++;
    }
    
    
    cout<<mak<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VL a(n);
    ll sum = 0;
    REP(i,n){
        a[i] = in();
        sum += a[i];
    }

    ll ans = 1e18, s = 0;
    REP(i,n-1){
        s += a[i];
        ll d = abs(sum - 2 * s);
        chmin(ans, d);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
N, KK = map(int, input().split())
P = [0] + list(map(int, input().split()))
C = [0] + list(map(int, input().split()))

cnt = [1] * (N+1)
retsu = []
for i in range(1,N+1):
    idx = i
    r = []
    for _ in range(N):
        if cnt[idx] == 0:
            break
        r.append(C[P[idx]])
        cnt[idx] = 0
        idx = P[idx]
    if r:
        retsu.append(r)

ans = -1 * (10 ** 10)
for z in retsu:
    K = KK
    s = sum(z)
    l = len(z)
    if K <= l:
        plus = 0
    elif s <= 0:
        plus = 0
        K = l
    else:
        plus = s * (K // l)
        if K % l == 0:
            plus -= s
    K %= l
    if K == 0:
        K = l
    
    moto = z + z
    point = [[0] * l for _ in range(l+K-1)]
    kari = -1 * (10 ** 10)
    for i in range(l+K-1):
        for j in range(l):
            if i == j:
                point[i][j] = moto[i]
            elif i - j >= K or i < j:
                continue
            else:
                point[i][j] = moto[i] + point[i-1][j]
            kari = max(kari, point[i][j])
    ans = max(ans, plus + kari)
print(ans)

Measured memory_bytes: 466116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

ll gcd(ll x, ll y){return y?gcd(y,x%y):x;};

ll ans = 0;

int main(){
    int n; cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                ans += gcd(gcd(i,j),k);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdbool.h>

static const int MAX = 100;

void swap(unsigned short *a, unsigned short *b ) {
	unsigned short temp;
	temp = *a;
	*a = *b;
	*b = temp;
}

short bubbleSort( unsigned short *p_dt, unsigned short n ) {
	bool flag = true;
	short i, j, sw = 0;

	while ( flag ) {
		flag = false;
		for ( i = (n - 1); i >= 1; i-- ) {
			if ( p_dt[i] < p_dt[i - 1] ) {
				swap( &p_dt[i], &p_dt[i -1] );
				flag = true;
				sw++;
			}
		}
	}
	return sw;
}

int main( void ) {
	short i, sw;
	unsigned short n, dt[MAX];

	scanf( "%d", &n );
	for ( i = 0; i < n; i++ ) scanf( "%d", &dt[i] );

	sw = bubbleSort( dt, n );

	for( i = 0; i < (n - 1); i++ ) printf( "%d ", dt[i] );
	printf( "%d\n%d\n", dt[i], sw );

	return 0;
}



Measured memory_bytes: 2120
/*
Problem : AtCoder Beginner Contest 120 D
Algorithm : ²¢²é¼¯ 
Status :
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
#define int long long
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

int n,m;
int father[MAXN],sum[MAXN],ans[MAXN],X[MAXN],Y[MAXN];

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

signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%lld%lld",&n,&m);
	for(int i = 1;i < MAXN;i++){
		sum[i] = 1;
		father[i] = i;
	}
	for(int i = 1;i <= m;i++)
		scanf("%lld%lld",&X[i],&Y[i]);
	ans[m + 1] = n * (n - 1) / 2;
	for(int i = m;i >= 2;i--){
		int fx = find(X[i]);
		int fy = find(Y[i]);
		if(fx != fy){
			ans[i] = ans[i + 1] - sum[fx] * sum[fy];
			sum[fx] += sum[fy];
			sum[fy] = 0;
			father[fy] = fx;
		}else
		    ans[i] = ans[i + 1];
	}
	for(int  i = 2;i <= m + 1;i++)
	    printf("%lld\n",ans[i]);
	return 0;
}


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

ng_map = {}
for p in P:
    ng_map[int(p)] = True

min_val = 999
candidate = x
for i in range(102):
    if i in ng_map:
        continue
    val = abs(x - i)
    if val < min_val:
        candidate = i
        min_val = val
print(candidate)



Measured memory_bytes: 9184
#include <cstdio>
#include <vector>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;
using P = std::pair<int, int>;

int N;
std::vector<int> G[100];
int M;
std::vector<int> es;
std::map<P, ll> e;
ll mask[100];

bool dfs( int v, int to, int p )
{
  if( v == to )
    return true;

  for( int u : G[v] )
  {
    if( u == p )
      continue;

    if( dfs( u, to, v ) )
    {
      es.emplace_back( e[P(v,u)] );

      return true;
    }
  }

  return false;
}

int main()
{
  scanf( "%d", &N );

  ll p = 0;
  rep( i, N-1 )
  {
    int a, b;
    scanf( "%d%d", &a, &b );
    --a; --b;

    G[a].emplace_back( b );
    G[b].emplace_back( a );

    e[P(a,b)] = p;
    e[P(b,a)] = p;

    ++p;
  }

  scanf( "%d", &M );

  rep( i, M )
  {
    int u, v;
    scanf( "%d%d", &u, &v );
    --u; --v;

    es.clear();
    dfs( u, v, -1 );

    for( int ve : es )
      mask[i] |= 1ll<<ve;
  }

  ll ans = 0;

  rep( i, 1ll<<M )
  {
    ll bit = 0;
    ll cnt = 0, cntI = 0;

    rep( j, M ) if( i >> j & 1 )
      bit |= mask[j], ++cntI;

    rep( j, N-1 ) if( bit >> j & 1 )
      ++cnt;

    ans += (cntI%2==0?1:-1)*(1ll<<(N-1-cnt));
  }

  printf( "%lld\n", ans );

  return 0;
}

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

int main(){
 string S; 
int K;
cin >> K >> S;
 string x;

if(S.size() <= K){
  cout << S << endl;
}
else{
  for(int i = 0; i < K;i++){
    x = S.at(i);
    cout << x;
  }
     cout <<"...";
}
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  string c1, c2;
  cin >> c1;
  cin >> c2;
  bool ans = true;
  rep(i, 3) {
    if (c1.at(i) != c2.at(2 - i)) ans = false;
  }
  if (ans == true) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int i = 0, j = 0;

	for(i = 1; i <= 9; i++)
	{
		for(j = 1; j<= 9; j++)
		{
			printf("%dx%d=%d\n", i, j, i * j);
		}
	}

	return 0;
}

Measured memory_bytes: 524
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
# mod = 10**9 + 7

n = int(input())
s,t = input().split()
# s = deque(input())
# q = int(input())

# n, k = map(int, input().split())
# a = list(map(int, input().split()))

ans = ""
for i in range(n):
    ans += s[i]
    ans += t[i]

print(ans)

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

constexpr long mod = 998244353;
vector<long> fact, inv;

long power(long n, long k) {
  if (k == 0) return 1;
  long res = power(n * n % mod, k / 2);
  if (k % 2) res = res * n % mod;
  return res;
}

void init(int n) {
  fact.push_back(1);
  inv.push_back(1);
  for (int i = 0; i < n; i++) {
    fact.push_back(fact.at(i) * (i + 1) % mod);
    inv.push_back(power(fact.at(i + 1), mod - 2));
  }
}

long ncr(long n, long r) {
  return fact.at(n) * inv.at(r) % mod * inv.at(n - r) % mod;
}

int main() {
  ios::sync_with_stdio(false);
  int N, M, K;
  cin >> N >> M >> K;
  init(N);
  long ans = 0;
  for (int i = 0; i <= K; i++) {
    (ans += M * power(M - 1, N - i - 1) % mod * ncr(N - 1, i) % mod) %= mod;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 6664
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    int n,k;
    cin >> n >> k;
    vector<long long> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=k; i<n; i++){
        if(a[i-k]<a[i])cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4844
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 19;

char T[maxN];
set <int> S[400];

void solve()
{
	int n, q;
	scanf ("%d%s%d", &n, T, &q);
	
	FOR(i, 0, n)
		S[T[i]].insert(i);
	FOR(i, 'a', 'z'+1)
		S[i].insert(n+1);
	
	while (q--)
	{
		int ev;
		scanf ("%d", &ev);
		if (ev == 1)
		{
			int i;
			char in[5];
			scanf ("%d%s", &i, in);
			i--;
			S[T[i]].erase(i);
			T[i] = in[0];
			S[T[i]].insert(i);
		}
		
		else
		{
			int a, b;
			scanf ("%d%d", &a, &b);
			a--, b--;
			int res = 0;
			FOR(c, 'a', 'z'+1)
				if (*(S[c].lower_bound(a)) <= b)
					res++;
			printf("%d\n", res);
		}
	}
} 
 
int main()
{
    int t;
    t = 1;//scanf ("%d", &t);
    while (t--)
    	solve();
    return 0;    
}




Measured memory_bytes: 24192
while True:
  try:
    a, b, c, d, e, f = map(int, input(). split())
    D = (a * e) - (b * d)
    x = (e * c) - (b * f)
    y = (a * f) - (d * c)
    x /= D
    y /= D
    if x / D == 0:
      x = 0
    if y / D == 0:
      y = 0
    print("%.3f %.3f" % (round(x, 3), round(y, 3)))
  except:
    break

Measured memory_bytes: 7524
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
//using P = pair<int, int>;

ll str2ll(string s) {
  ll ten = 1, ret = 0;
  for (int i = s.size()-1; i >= 0; --i) {
    if (s[i] == '.') continue;
    int a = (s[i]-'0');
    ret += a * ten;
    ten *= 10;
  }
  return ret;
}

int main() {
  ll a;
  string s;
  cin >> a >> s;
  ll ans = a * str2ll(s) / 100;
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include <iostream>
using namespace std;;
int main(){
  int K,N;
  int p = 0;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> K;
    if(K%2 == 0){
      if(K % 5 == 0 || K % 3 == 0)continue;
      else{p=1;}
    }
  }
  if(p==1){
    cout << "DENIED";
  }else{
    cout << "APPROVED";
  }
}

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

using namespace std;

int main() {
   int A,B;
    cin >>A>>B;
    int K=A+B;
    int U=K%2;
    if(U==0){
       K=K/2;
       cout<<K<<endl;
    }
    else{
       cout<<"IMPOSSIBLE"<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

int main() {
  int N,A,B;
  cin>>N>>A>>B;
  say(min(A*N,B));
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define fi first
#define sec second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,a,b)     for(int i=b;i>=a;i--)
#define all(v)          v.begin(),v.end()
void fast(){ ios::sync_with_stdio(false); cin.tie(NULL);}
void file()
{ 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin); 
    freopen("output.txt","w",stdout);
    #endif
}

string s;
set<char> st;
int main()
{
    fast();
    

    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if(st.count(s[i]))
            st.erase(s[i]);
        else
            st.insert(s[i]);
    }
    if(st.empty())
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <ctype.h>
 
int main(void)
{
    char ch;
    while(1){
        scanf("%c", &ch);
        if(isupper(ch)) {
            ch = ch + 32;
        } else if(islower(ch)) {
            ch = ch - 32;
        }
        printf("%c",ch);
            if ( ch == '\n' ) break;
    }   
    return 0;
}

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

using namespace std;

set <int> a;

int main() {
	int n, tr, sa = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> tr;
		a.insert(tr);
		if (a.size() == sa) {
			cout << "NO\n";
			return 0;
		}
		sa = a.size();
	}
	cout << "YES\n";
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second

const int N = 2e5 + 1e3;
int a[N];
map<int, int> cnt;
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    int ans = 0, two = 0;
    for (auto &el : cnt) {
        if (el.se % 2 == 0) {
            two++;
        }
        ans++;
    }
    if (two % 2 == 1) {
        ans--;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;


int main(){
    ll N, K;
    cin>>N>>K;
    ll Sum=0;
    for(ll i=K; i<=N+1; i++){
        Sum+=N*(N+1)/2-(N-i)*(N-i+1)/2-(i-1)*i/2+1;
        Sum%=MOD;
    }
    cout<<Sum<<endl;
}



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

int main()
{
  int n,k;
  cin>>n>>k;
  
  vector<int> h(n);
  for(int i=0;i<n;i++)
    cin>>h[i];
  
  vector<int> memo(n,2147483647);
  memo[0]=0;
  memo[1]=abs(h[1]-h[0]);
  
  for(int i=2;i<n;i++)
  {
    int j=i-1;
    if(k==1)
      memo[i]=memo[i-1]+abs(h[i]-h[i-1]);
    else
    {
      do
      {
      	memo[i]=min(memo[i],min(memo[j]+abs(h[i]-h[j]),memo[j-1]+abs(h[i]-h[j-1])));
        //if(i==n-1)
          //cout<<memo[i]<<endl;
      	j--;
      }while(i-j<k&&j>0);
    }
    
  }
  //for(int i=0;i<n;i++)
    //cout<<memo[i]<<endl;
  cout<<memo[n-1]<<endl;
}

Measured memory_bytes: 1024
#!/bin/bash
read input
IFS=' '
set -- $input
num1=$1
num2=$2
sum=0

# first choice
if [ $num1 -ge $num2 ]; then
 sum=$((sum+num1))
 ((num1--))
else 
 sum=$((sum+num2))
 ((num2--))
fi

# second choice
if [ $num1 -ge $num2 ]; then
 sum=$((sum+num1))
else 
 sum=$((sum+num2))
fi


echo "$sum"

Measured memory_bytes: 376
N, M, Q = map(int, input().split())
G = []
for i in range(Q):
    a, b, c, d = map(int, input().split())
    G.append([a, b, c, d])

ans = 0


def dfs(s):
    global ans
    if len(s) == N:
        now = 0
        for a, b, c, d in G:
            if s[b - 1] - s[a - 1] == c:
                now += d
        ans = max(ans, now)
        return

    for i in range(s[-1], M):
        dfs(s + [i])


s = [0]
dfs(s.copy())

print(ans)


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

int cal(int num){
	int res=0;
	while(num > 0){
		res += num % 10;
		num /= 10;
	}
	return res;
}

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	long long ans=0;
	for(int i=1; i<=n; i++){
		int num = cal(i);
		if(num >= a && num <=b){
			ans += i;
		}
	}
	cout << ans << endl;
}


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

using namespace std;

int kannondo(int n){
  vector<int> a;
  int answer=0;
  a.resize(n+3);
  a[0]=0;
  a[1]=0;
  a[2]=1;
  for (int i=3;i<n+3;i++){
    a[i]=a[i-1]+a[i-2]+a[i-3];
  }
  answer=a[n+2]/3650+1;
  return answer;
}


int main(){
  while(true){
    int a;
    cin>>a;
    if(a==0) break;
    int result;
    result=kannondo(a);
    cout<<result<<endl;
  }
  return 0;
}

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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 998244353ll;
const ll MAXN = (ll) 1e6 + 10;
const ll INF = (ll) 9223372036854775;
const ld EPS = (ld) 1e-8;

bool see[MAXN];

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n;
	cin >> n;
	if(n == 3 or n == 5 or n == 7) return cout << "YES", 0;
	cout << "NO";
	return 0;
}


/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	int N;
	cin >> N;

	ll L[100];
	L[0] = 2;
	L[1] = 1;

	for (int i = 2; i <= 86; i++) {
		L[i] = L[i - 1] + L[i - 2];
	}
	co(L[N]);

	Would you please return 0;
}

Measured memory_bytes: 256
/*
"Won't stop untill I'm Phenomenal"
- Phenomenal, EMINEM
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;

int n; 
string s;
vector<int> r,g,b;

int calc(int i, int j){
    i++;
    j++;
    set<char> to_find;
    to_find.insert('R');
    to_find.insert('G');
    to_find.insert('B');
    to_find.erase(s[i-1]);
    to_find.erase(s[j-1]);
    char of = *to_find.begin();
    int ans = ((of=='R')?(r[j]-r[i]): ((of=='G')?(g[j]-g[i]):(b[j]-b[i])));
    if(((j-i)&1^1)&&(s[i + (j-i)/2 - 1]==of))
        ans--;
    return ans;
}

int main(){
    Shazam;
    cin>>n;
    cin>>s;
    ll ans = 0;
    r = g = b =  vector<int>(n+1);
    for(int i = 0; i < n; i++){
        if(s[i]=='R')
            r[i+1] = 1;
        else if(s[i]=='G')
            g[i+1] = 1;
        else
            b[i+1] = 1;
    }
    for(int i = 1; i < n+1; i++){
        r[i] += r[i-1];
        g[i] += g[i-1];
        b[i] += b[i-1];
    }
    for(int i = 0 ; i < n; i++){
        for(int j = i + 2; j < n; j++){
            if(s[i]==s[j]) continue;
            ans += calc(i,j);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

void solve(string s){
	vector<int> v;
	for(int i=0; i<s.size(); ++i){
		if(s[s.size()-1-i] == 'n')
			v.push_back(0);
		if(s[s.size()-1-i] == 'w')
			v.push_back(1);
	}
	int a = -1, b = 1;
	if(v[0] == 0) a = 0;
	else a = 90;
	for(int i=1; i<v.size(); ++i){
		b *= 2;
		a *= 2;
		if(v[i] == 0) a -= 90;
		else a += 90;
	}
	if(a % b == 0) cout << a/b << "\n";
	else{
		while(a % 2 == 0 && b % 2 == 0){
			a /= 2;
			b /= 2;
		}
		cout << a << "/" << b << "\n";
	}
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		string s;
		cin >> s;
		if(s == "#") return 0;
		solve(s);
	}
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using ll = long long;
int main(){ 
    ll l,r;
    cin>>l>>r;
    if(r-l>=2018){
        cout<<0;
        return 0;
    }
    ll a=0;
    ll b=100000000;
while(l>=2019){
    r-=2019;
    l-=2019;
}
if(r>=2019){
    cout<<0;
    return 0;
}
for(int i=l;i<r;i++){
    for(int j=i+1;j<r+1;j++){
        a=i*j;
        a%=2019;
        b=min(a,b);
    }
}           
cout<<b;
    return 0;
}


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

using namespace std;

int main(){
        double x[8];
        while(cin >> x[0]){
                for(int i = 1 ; i < 8; i++) cin >> x[i];
                bool flag = false;
                for(int i = 0; i < 2; i++){
                        if(max(x[0+i], x[2+i]) < min(x[4+i], x[6+i]) || max(x[4+i], x[6+i]) < min(x[0+i],x[2+i])){
                                flag = true;
                        }   
                }   
                if(flag) cout << "NO";
                else cout << "YES";
                cout << endl;
        }   
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int r;
  cin >> r;
  cout << r*r << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#include<cstdio>
#include<cmath>
const int N=100005;
int n,f[N],k=0;
struct bian
{
	int u,v,w;
}
b[N*2];
struct node
{
	int x,y,self;
}
a[N];
int cmp1(node c,node d)
{
	return c.x<d.x;
}
int cmp2(node c,node d)
{
	return c.y<d.y;
}
int cmp3(bian c,bian d)
{
	return c.w<d.w;
}
void prepare()
{
	sort(a+1,a+1+n,cmp1);
	for(int i=1;i<n;i++)
	{
		k++;
		b[k].u=a[i].self;
		b[k].v=a[i+1].self;
		b[k].w=abs(a[i+1].x-a[i].x);
	}
	sort(a+1,a+1+n,cmp2);
	for(int i=1;i<n;i++)
	{
		k++;
		b[k].u=a[i].self;
		b[k].v=a[i+1].self;
		b[k].w=a[i+1].y-a[i].y;
	}
}
int ff(int x)
{
	if(f[x]==x)
	return x;
	if(f[x]!=x)
	return f[x]=ff(f[x]);
}
int kruskal()
{
	int ans=0;
	sort(b+1,b+k+1,cmp3);
	int t=0;
	for(int i=1;i<=k;i++)
	{
		int x1=ff(b[i].u);
		int x2=ff(b[i].v);
		if(x1!=x2)
		{
			ans+=b[i].w;
			f[x1]=x2;
			t++;
		}
		if(t==n-1)
		break;
	}
	return ans;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].x>>a[i].y;
		a[i].self=i;
		f[i]=i;
	}
	prepare();
	cout<<kruskal();
}

Measured memory_bytes: 4224
X = int(input())
if X < 600:
    print(8)
elif X < 800:
    print(7)
elif X < 1000:
    print(6)
elif X < 1200:
    print(5)
elif X < 1400:
    print(4)
elif X < 1600:
    print(3)
elif X < 1800:
    print(2)
else:
    print(1)


Measured memory_bytes: 61644
// https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_D
// 最長増加部分列 (LIS: Longest Increasing Subsequence)
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr int INF = 1000000000+8;

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

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

    vector<int> dp(n, INF);

    for (int i = 0; i < n; i++) {
        *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
    }

    const int ans = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
    cout << ans << endl;
}



Measured memory_bytes: 4424
#include<stdio.h>
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int a[55]={0};
        int cnt=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]!=i)
                cnt++;
        }
        if(cnt==0||cnt==2)
            printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var K = sc.ReadInt();
        var X = sc.ReadLongArray(N);
        var ans = long.MaxValue;
        for (int i = K - 1; i < N; i++)
        {
            var v1 = X[i - K + 1];
            var v2 = X[i];
            if (v1 * v2 >= 0)
            {
                ans = Math.Min(ans, Math.Max(Math.Abs(v1), Math.Abs(v2)));
            }
            else
            {
                var res1 = Math.Abs(v1) * 2 + Math.Abs(v2);
                var res2 = Math.Abs(v1) + Math.Abs(v2 * 2);
                ans = Math.Min(ans, Math.Min(res1, res2));
            }
        }
        Console.WriteLine(ans);
    }

    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 24544
use std::io::*;
use std::str::FromStr;
use std::vec::Vec;
use std::cmp::max;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}
 
fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let (k, n) = read_touple::<usize>();
    let mut a: Vec<i64> = read_vec();
    let k = k as i64;
    let mut ans = 0;
    
    for i in 0..n{
        let mut t = a[(i+1)%n] - a[i];
        if t < 0{
            t += k;
        }
        ans = max(ans,t);
    }
    println!("{}", k-ans);
}   


Measured memory_bytes: 10492
N = int(input())
H = list(map(int, input().split()))
count = 0
countmax = 0
for i in range(N-1):
    if H[i] >= H[i + 1]:
        count += 1
    else:
        if count >= countmax:
            countmax = count
        count = 0
if count >= countmax:
    countmax = count
print(countmax)


Measured memory_bytes: 14224
h, w = gets.split.map(&:to_i)
ss = h.times.map { gets.chomp }

ans = Array.new(h) { Array.new(w, 0) }

h.times do |i|
  w.times do |j|
    if ss[i][j] == "#"
      ans[i][j] = ss[i][j]
      next
    end

    l = j - 1 < 0 ? j : j - 1
    r = j + 1 > w ? j : j + 1

    if i - 1 >= 0
      ans[i][j] += ss[i - 1][l..r].count("#")
    end

    ans[i][j] += ss[i][l..r].count("#")

    if i + 1 <= h - 1
      ans[i][j] += ss[i + 1][l..r].count("#")
    end
  end
end

ans.each { |a| puts a.join }


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

using namespace std;

int main()
{
	int a[10];
	for (int i = 0; i < 10; i++) {
		cin >> a[i];
	}
	sort(a, a + 10); // algorithm: ???????????????????´????????????????????????????
	cout << a[9] << endl
		<< a[8] << endl
		<< a[7] << endl;

    return 0;
}

Measured memory_bytes: 3152
from fractions import gcd
from decimal import Decimal
A, B, C, D = map(Decimal, input().split())
_A = A-1
print(int(B - _A - (B//C - _A//C + B//D - _A//D - B//(C*D/gcd(C, D)) + _A//int(C*D/gcd(C, D)))))

Measured memory_bytes: 5048
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
 
using ll = long long int;
 
int main(void){
    
    ll h,w,result = 10000000000000;
    cin >> h >> w;
    
    if((h%3) == 0 || (w%3) == 0){
        cout << 0 << endl;
        return 0;
    }else{
        for(int i = 0; i < h; i++){
		ll a = i * w;
		ll b = h*w - a;
		ll c;
		
		if(b % 2 == 0){
		    b /= 2;
		    c = b;
		}else{
		    b = max((h-i),w)/2 * min((h-i),w);
		    c = (max((h-i),w)+1)/2 * min((h-i),w);
		}
		
		//cout << a << " " << b << " " << c << endl;
 
		result = min(result,max({a,b,c}) - min({a,b,c}));
 
	}
 
	for(int i = 0; i < w; i++){
		ll a = i * h;
		ll b = h*w - a;
		ll c;
		
		if(b % 2 == 0){
		    b /= 2;
		    c = b;
		}else{
		    b = max((w-i),h)/2 * min((w-i),h);
		    c = (max((w-i),h)+1)/2 * min((w-i),h);
		}
		result = min(result,max({a,b,c}) - min({a,b,c}));
 
	}
 
        
    }
    
    cout << result << endl;
    
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int main()
{
    for (int i = 1; i <= 9; i ++)
    {
        for (int j = 1; j <= 9; j ++)
        {
            printf("%dx%d=%d\n", i, j, i * j);
        }
    }
    return 0;
}

Measured memory_bytes: 2572
Scanf.scanf "%d %d %d %d %d" (fun x1 x2 x3 x4 x5 ->
    Printf.printf "%d\n" @@
    if x1 = 0 then 1 else
    if x2 = 0 then 2 else
    if x3 = 0 then 3 else
    if x4 = 0 then 4 else 5
)

Measured memory_bytes: 3780
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    L = max(L)
    R = min(R)

    if L <= R:
        print(R - L + 1)
    elif L > R:
        print(0)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R)


if __name__ == "__main__":
    main()


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

int main(){
    int n; string s; cin >> n >> s;
    vector<pair<int, int>> a(n);
    a[0] = ((s[0] == '(') ? make_pair(1, 0) : make_pair(0, 1));
    for (auto i = 1; i < n; i++) {
        if(s[i] == '(') a[i] = {a[i - 1].first + 1, a[i - 1].second};
        else a[i] = {a[i - 1].first, a[i - 1].second + 1};
    }

    int rc = 0, lc = 0;
    for (auto i = 0; i < n; i++) {
        if(a[i].first + lc - a[i].second < 0) {
            string t = "(" + s; s = t; lc++;
        }
    }
    while ((a.back().first + lc) - (a.back().second + rc) > 0) {
        s.push_back(')'); rc++;
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=998244353;
const int size=1e5;
const int inf=1e9;
int main(){
	int N,M; cin>>N>>M;
	if(M % 2 == 1){ cout<<-1<<endl; return 0; }
	int a,b;
	set<int> g[size],h[size];
	int deg[size] = {};
	rep(i,0,M){
		cin>>a>>b; a--; b--;
		g[a].insert(b);
		g[b].insert(a);
		deg[a]++; deg[b]++;
	}
	set<pair<int,int>> st;
	rep(i,0,N) st.insert({deg[i], i});
	rep(i,0,N){
		pair<int,int> p = *st.begin();
		st.erase(st.begin());
		int v = p.second;
		bool flag = false;
		if(h[v].size() % 2 == 1) flag = true;
		for(int u:g[v]){
			if(h[v].count(u) || h[u].count(v)) continue;
			if(flag){ h[v].insert(u); flag = false; }
			else h[u].insert(v);
			st.erase(st.find({deg[u], u}));
            deg[v]--; deg[u]--;
            st.insert({deg[u], u});
		}
	}
	rep(i,0,N){
		for(int j:h[i]) cout<<i + 1<<" "<<j + 1<<endl;
	}
}

Measured memory_bytes: 26624
h,w=map(int,input().split())
b=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for k in range(h):
    a=list(input().split())
    for l in range(w):
        if a[l]=='snuke':
            print(b[l]+str(k+1))

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

int N;
int color[9];
int main(){
  std::cin>>N;
  for(int i=0;i<N;++i){
    int temp;
    std::cin>>temp;
    
    if(temp>=3200)
      ++color[8];
    else
      ++color[temp/400];
  }
  
  int ans=0;
  for(int i=0;i<8;++i)
    if(color[i]!=0)
      ++ans;
  
  std::cout<<std::max(1,ans)<<' '<<std::max(1,ans+color[8])<<std::endl;
    
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
int n, mx, x[55], y[55];
map<pair<int, int>, int> mp;
int main() {
	int i, j;
	cin>>n;
	for(i=0; i<n; i++) cin>>x[i]>>y[i];
	for(i=0; i<n; i++) for(j=0; j<n; j++) if(i!=j) {
		mx = max(mx, ++mp[{x[j]-x[i], y[j]-y[i]}]);
	}
	cout<<n-mx;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e16
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)     for(lint i=n-1;i>=0;--i)
#define REPR1(i,n)    for(lint i=n;i>0;--i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
void dijkstra(const vector<vector<pair<lint, lint>>>&edge, vector<lint>&cost, lint start = 0)
{
	fill(ALL(cost), INF); cost[start] = 0;
	priority_queue<pair<lint, lint>, vector<pair<lint, lint>>, greater<pair<lint, lint>>> node_queue; node_queue.push(make_pair(0, start));
	while (!node_queue.empty())
	{
		const lint  tpn_cost = node_queue.top().first, tpn_index = node_queue.top().second; node_queue.pop();
		REPC(i, edge[tpn_index])
		{
			const lint dst_index = i.first, dst_cost = i.second;
			if (tpn_cost + dst_cost < cost[dst_index])
			{
				cost[dst_index] = tpn_cost + dst_cost;
				node_queue.push(make_pair(cost[dst_index], dst_index));
			}
		}
	}
	return;
}
signed main()
{
	lint n = in(), m = in(), s = in(), t = in();
	vector<vector<pair<lint, lint>>>edge_yen(n), edge_snook(n);
	REP(i, m)
	{
		lint u = in(), v = in(), a = in(), b = in();
		edge_yen[u - 1].push_back(make_pair(v - 1, a));
		edge_yen[v - 1].push_back(make_pair(u - 1, a));
		edge_snook[u - 1].push_back(make_pair(v - 1, b));
		edge_snook[v - 1].push_back(make_pair(u - 1, b));
	}
	vector<lint>cost_yen(n), cost_snook(n);
	dijkstra(edge_yen, cost_yen, s - 1);
	dijkstra(edge_snook, cost_snook, t - 1);
	vector<pair<lint, lint>>cost(n);
	REP(i, n)cost[i] = make_pair(cost_yen[i] + cost_snook[i], i);
	sort(ALL(cost));
	int j = 0;
	REP(i, n)
	{
		while (cost[j].second < i) j++;
		cout << (1000000000000000 - cost[j].first) << endl;
	}
}

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

int main(){
    int a,b,c;
    int s,k;
    int count=0;

    cin >> k >> s;
    a=0;
    while(a <= k){
        b=0;
        while(b<=k && a+b <= s){
            if( 0<=s-a-b && s-a-b <= k) count++;
            b++;
        }
        a++;
    }
    cout << count << endl;

}

Measured memory_bytes: 256
#include<cstdio>

long long min(long long a,long long b){ return a>b?b:a; }

long long max(long long a,long long b){ return a>b?a:b; }

int main(){
    long long a,b,c;
    long long x,y;
    scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&x,&y);
    long long ans = a*x+b*y;
    for(long long i = 1; i <= max(x,y); i++){
        long long cur = i*2*c+max(0,x-i)*a+max(0,y-i)*b;
        ans = min(ans,cur);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1708
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<queue>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int a;
signed main()
{
	std::ios::sync_with_stdio(false);
	for(int i=1;i<=5;++i)
	{
		cin>>a;
		if(a==0)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <cctype>

using namespace std;

int main() {
    char ch;
    vector<int> data(26);
    string str;
    locale l = locale::classic();
    // getline(cin, str);
    while(getline(cin, str)){
        // cout << str << endl;
        for(auto x: str){
        //  cout << ch;
            if(isalpha(x)){
                char lower = tolower(x, l);
                int num = lower - 'a';
                data[num]++;
            }
        }
    }

    // cout << str << endl;
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    int i = 0;
    for(auto x: data){
        cout << alphabet[i] << " : " << x << endl;
        i++;
    }
    return 0;
}


Measured memory_bytes: 3212