akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int state[8][8][8][8][8][8][8];
priority_queue<pair<int,vector<int> >,vector<pair<int,vector<int> > >,greater<pair<int,vector<int> > > > bfs;

#define f(x,y) a[x]=a[y];a[y]=0;b[a[x]]=x;b[a[y]]=y;if(state[a[0]][a[1]][a[2]][a[3]][a[4]][a[5]][a[6]]==-1){state[a[0]][a[1]][a[2]][a[3]][a[4]][a[5]][a[6]]=n.first+1;bfs.push(mp(n.first+1,a));}a[y]=a[x];a[x]=0;b[a[x]]=x;b[a[y]]=y;

int main() {
	vector<int> a;
	memset(state,-1,sizeof(state));
	for(int i=0;i<8;i++)a.push_back(i);
	bfs.push(mp(0,a));
	state[a[0]][a[1]][a[2]][a[3]][a[4]][a[5]][a[6]]=0;
	while(!bfs.empty()){
		pair<int,vector<int> > n;
		n=bfs.top();
		bfs.pop();
		a=n.second;
		vector<int> b(8);
		int i;
		for(i=0;i<8;i++){
			b[n.second[i]]=i;
		}
		switch(b[0]){
		case 0:
			f(0,1);
			f(0,4);
			break;
		case 1:
			f(1,0);
			f(1,2);
			f(1,5);
			break;
		case 2:
			f(2,1);
			f(2,3);
			f(2,6);
			break;
		case 3:
			f(3,2);
			f(3,7);
			break;
		case 4:
			f(4,0);
			f(4,5);
			break;
		case 5:
			f(5,1);
			f(5,4);
			f(5,6);
			break;
		case 6:
			f(6,2);
			f(6,5);
			f(6,7);
			break;
		case 7:
			f(7,3);
			f(7,6);
			break;
		}
	}
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6]>>a[7]){
		cout<<state[a[0]][a[1]][a[2]][a[3]][a[4]][a[5]][a[6]]<<endl;
	}
	return 0;
}

Measured memory_bytes: 9132
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define P pair<int, int>
#define Q pair<int, pair<int, int>>
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
const int Mod = 1e9 + 7;
const int mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
			comp_[i] = mod_pow(fact_[i], mod - 2, mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % mod * comp_[y] % mod;
}*/
//---------------------------------------------------
signed main() {
	int n;
	cin >> n;
	vector<int>a;
	for (int i = 0; i < n; i++) {
		a.push_back(read());
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			ans += a[i] * a[j];
		}
	}
	cout << ans << endl;
}

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

int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  if(c < (a+b)){
    puts("No");
    return 0;
  }
  if(4*a*b < (c-(a+b))*(c-(a+b))) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
/* 
chirag11032000
Chirag Thakur
*/

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

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e4 + 10;

int a[N];
ll dp[2][N][2];

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	for (int l = n; l >= 1; --l) {
		for (int r = 1; r <= n; ++r) {
			for (int take_max = 0; take_max <= 1; ++take_max) {
				int curr = l & 1, nxt = !curr;
				if (l > r) {
					dp[curr][r][take_max] = 0;
				} else if (take_max) {
					dp[curr][r][take_max] = max(a[l] + (l + 1 <= n ? dp[nxt][r][!take_max] : 0), a[r] + dp[curr][r - 1][!take_max]);
				} else {
					dp[curr][r][take_max] = min(-a[l] + (l + 1 <= n ? dp[nxt][r][!take_max] : 0), -a[r] + dp[curr][r - 1][!take_max]);
				}
			}
		}
	}
	cout << dp[1][n][1] << "\n";
}

// ll solve(int l, int r, bool p) {
//     if (l > r) {
//         return 0;
//     }
//     ll &ans = dp[l][r][p];
//     bool &vis = seen[l][r][p];
//     if (!vis) {
//         vis = true;
//         if (p) {
//             ans = min(solve(l + 1, r, !p) - a[l], solve(l, r - 1, !p) - a[r]);
//         } else {
//             ans = max(solve(l + 1, r, !p) + a[l], solve(l, r - 1, !p) + a[r]);
//         }
//     }
//     return ans;
// }

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;
int main()
{
   string a;
   cin>>a;
   for(int i=0;i<a.length();i++)
    if(i%2==0)
    cout<<a[i];
   cout<<endl;
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
string s;
int main(){
	set<string>st;
	s.clear();
	int n;cin >> n;
	int cnt = 0;
	fo(i,1,n){
		cin >> s;
		if(!st.count(s))st.insert(s) , cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 19256
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>

#define INF 1050000000
#define MOD 1000000007
#define LONGINF 1005000000000000000
using namespace std;

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

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (i + j > n) {
				continue;
			}
			int k = n - (i + j);
			if (i * 10000 + j * 5000 + k * 1000 == y) {
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;





}

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var a = int.Parse(input.ReadLine());
        var b = int.Parse(input.ReadLine());

        if (a != 1 && b != 1) return 1;
        if (a != 2 && b != 2) return 2;
        if (a != 3 && b != 3) return 3;

        return 0;
    }
}


Measured memory_bytes: 13140
n,k = map(int,input().split())
now = (n-1) * (n-2) // 2 - k
if now < 0:
  print(-1)
else:
  print(n-1+now)
  for i in range(1,n):
    print(1,i+1)
  i = 1
  while True:
    if now > n-1-i:
      for j in range(i+1,n):
        print(i+1,j+1)
      now -= n-1-i
      i += 1
    else:
      for j in range(i+1,i+1+now):
        print(i+1,j+1)
      now -= now
      break

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

int main(void) {
  unordered_set< int > sol;
  int a, b, c;
  cin >> a >> b >> c;
  sol.insert(a); sol.insert(b);
  sol.insert(c);
  cout << sol.size() << "\n";
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
if M == 0:
  if N == 1:
    print(0)
  else:
    m = 10 ** (N - 1)
    print(m)
else:
  dic = {}
  t = ''
  flg = True
  for _ in range(M):
    s, c = map(int, input().split())
    if s not in dic:
      dic[s] = c
    else:
      if dic[s] != c:
        flg = False
        break
  if N == 1:
    if dic[1] == 0:
      ans = 0
    else:
      ans = dic[1]
  else:
    if 1 in dic:
      if dic[1] == 0:
        flg = False
      else:
        t += str(dic[1])
    else:
      t += '1'
    for j in range(2, N + 1):
      if j in dic:
        t += str(dic[j])
      else:
        t += '0'
    ans = int(t)
  if flg:
    print(ans)
  else:
    print(-1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,lt;
char t[200010];
void update(int q,int &last,int &d)
{
    if(d!=0&&q!=last%2)d=3-d;
    last=q;
}
pair<vector<int>,vector<int> > solve(int n)
{
    if(!n)
        return make_pair(vector<int>({0}),vector<int>(lt,0));
    auto prev=solve(n-1);
    const auto& p=prev.first,w=prev.second;
    vector<int> new_w(w.size());
    int psiz=p.size();
    vector<int> d(3*psiz);
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<psiz;j++)
        {
            d[i*psiz+j]=i;
        }
    }
    int q=0;
    vector<int> last(3*psiz);
    for(int i=0;i<lt;i++)
    {
        int k=w[i];
        for(int j=k;j<3*psiz;j+=psiz)
        {
            update(q,last[j],d[j]);
            if(d[j]==2)new_w[i]=j;
        }
        if(t[i]=='S')q^=1;
        else
        {
            for(int j=k;j<3*psiz;j+=psiz)d[j]=(d[j]+1)%3;
        }
    }
    vector<int> new_p(3*psiz);
    for(int i=0;i<3*psiz;i++)
    {
        update(q,last[i],d[i]);
        new_p[i]=p[i%psiz]+d[i]*psiz;
    }
    return make_pair(new_p,new_w);
}
int main()
{
    scanf("%d%s",&n,t);
    lt=strlen(t);
    vector<int> res=solve(n).first;
    for(int &x:res)printf("%d ",x);
    return 0;
}

Measured memory_bytes: 17040
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let mut ant:Vec<i32> = Vec::new();
	let v:Vec<i32> = procon_read();
	ant.push(v[0]);
	let v:Vec<i32> = procon_read();
	ant.push(v[0]);
	let v:Vec<i32> = procon_read();
	ant.push(v[0]);
	let v:Vec<i32> = procon_read();
	ant.push(v[0]);
	let v:Vec<i32> = procon_read();
	ant.push(v[0]);
	let v:Vec<i32> = procon_read();
	let k:i32 = v[0];
	let mut flag = false;
	for i in 0..5 {
		for j in (i+1)..5 {
			if ant[j] - ant[i] > k{
				flag = true;
				break;
			}
		}
		if flag {
			break;
		}
	}
	if flag {
		println!(":(");
	}else{
		println!("Yay!");
	}
}

Measured memory_bytes: 4352
import java.util.Scanner;
import java.lang.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 
			
		String s = sc.nextLine(); 
		String ns = "";
		
		for(int i = 0; i < s.length(); i++) { 
			char c = s.charAt(i); 
			if('a' <= c && c <= 'z') System.out.print((char)(c - 32)); 
			else if('A' <= c && c <= 'Z') System.out.print((char)(c + 32)); 
			else System.out.print(c); 
		}
		
		System.out.println();
	}
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;

set<string> C[4];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	
	C[0].insert("");
	FORR(c,S) {
		for(i=2;i>=0;i--) {
			FORR(s,C[i]) C[i+1].insert(s+c);
		}
	}
	cout<<C[3].size()<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 384
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar(); 
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=200005;
int n;
int a[maxn],b[maxn];

bool check(int x){
	REP(i,n)b[i]=(a[i]<=x);
	REP(i,n){
		int j=i;
		while(j<=n&&(j==i||b[j]!=b[j-1]))j++;
		if(i==1&&j==n+1)return b[1];
		if(b[i-1]==b[j]){
			for(int k=i;k<j;k++)b[k]=b[i-1];
		}
		else{
			for(int k=i;k<=i+(j-i)/2-1;k++)b[k]=b[i-1];
			for(int k=i+(j-i)/2;k<=j-1;k++)b[k]=b[j];
		}
		i=j-1;
	}
	return b[n/2+1]==1;
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d",&n);
	n=2*n-1;
	REP(i,n)scanf("%d",&a[i]);
	int l=0,r=n;
	while(r-l>1){
		int mid=(l+r)>>1;
		if(check(mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/

Measured memory_bytes: 1920
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int d,g;
    int p[10] = {0},c[10] = {0};
    cin >> d >> g;
    for (int i = 0; i < d; i++){
        cin >> p[i] >> c[i];
    }

    int n = d;
    int ans = 1e9;
    for (int i = 0; i < (1 << n); i++){
        vector<int> s;
        int rest_max = -1;
        for (int k = 0; k < n; k++){
            if (i & (1 << k)){
                s.push_back(k);
            } else {
                rest_max = k;
            }
        }
        int sum = 0;
        int cnt = 0;
        for (int k = 0; k < s.size(); k++){
            sum += 100 * (s[k]+1) * p[s[k]] + c[s[k]];
            cnt += p[s[k]];
        }

        if (sum < g){
            int s1 = 100 * (rest_max + 1);
            int need = (g - sum + s1 -1) /s1;
            //int need = (g-sum) / s1;
            if (need >= p[rest_max]){
                continue;
            }
            cnt += need;
        }
        ans = min(ans, cnt);
    }
        cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main (){
	int card[5][14] = {0};
	int n,d,i,j;
	char c;

	scanf("%d",&n);

	for (j = 0;j < n; j++){
		scanf(" %c %d",&c,&d);
		if (c == 'S'){
			card[1][d] = 1;
		}
		if (c == 'H'){
			card[2][d] = 1;
		}
		if (c == 'C'){
			card[3][d] = 1;
		}
		if (c == 'D'){
			card[4][d] = 1;
		}
	}

	for (i = 1; i <= 4; i++){
		for (j = 1; j <= 13; j++){
			if (card[i][j] != 1)
			{
				if (i == 1){
					printf("S %d\n",j);
				}
				if (i == 2){
					printf("H %d\n",j);
				}
				if (i == 3){
					printf("C %d\n",j);
				}
				if (i == 4){
					printf("D %d\n",j);
				}
			}
		}
	}

	return 0;
}


Measured memory_bytes: 2028
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath> 
#include <queue>
#include <functional>

using namespace std;
//typedef long long ll;
//typedef pair<int, int> P;
//static const int dx[4] = {1, -1, 0, 0};
//static const int dy[4] = {0, 0, 1, -1};

//const ll MOD = 1e+9 + 7;
//const int MAX = 10001;

int main() {

    int N, D;
    cin >> N >> D;
    vector< vector<int> > X(10, vector<int>(10, 0));

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    vector<int> Pow;
    int ans = 0;
    for (int i = 1; i * i <= 40 * 40 * 10; i++) {
        Pow.push_back(i * i);
    }
/*
            for (int ind = 0; ind < Pow.size(); ind++) {
              cout <<  Pow[ind] << ' ';
            }
            cout << '\n';
*/ 


    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            int temp = 0;
            for (int d = 0; d < D; d++) {
                temp += abs(X[i][d] - X[j][d]) * abs(X[i][d] - X[j][d]);;
            }
            for (int ind = 0; ind < Pow.size(); ind++) {
                if (temp == Pow[ind])
                    ans++;
            }
        }
    }

    cout << ans << '\n';

}


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

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

using namespace std;

typedef long long int lli;

int main () {
    lli H, W;
    cin >> H >> W;
    lli ans = 1LL << 60;
    ans = min(ans, !!(W % 3) * H);
    ans = min(ans, !!(H % 3) * W);
    REP (i, 0, H) {
        lli a = i * W;
        lli b = (H - i) * (W / 2);
        lli c = (H - i) * ((W + 1) / 2);
        ans = min(ans, max({a, b, c}) - min({a, b, c}));
    }
    REP (i, 0, W) {
        lli a = i * H;
        lli b = (W - i) * (H / 2);
        lli c = (W - i) * ((H + 1) / 2);
        ans = min(ans, max({a, b, c}) - min({a, b, c}));
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 502;
int G[MAX_N][MAX_N];
bool used[MAX_N];
int n;

void add_edge(int from, int to, int cap){
    G[from][to] = cap;
    G[to][from] = cap;
}
void erase_edge(int from, int to){
    G[from][to] = 0;
    G[to][from] = 0;
}
int dfs(int v,int t,int f){
    if(v == t) return f;
    used[v] = true;
    rep(i,n){
        int& cap = G[v][i];
        if(!used[i] && cap > 0){
            int d = dfs(i,t,min(f,cap));
            if(d > 0){
                cap -= d;
                G[i][v] += d;
                return d;
            }
        }
    }
    return 0;
}
int max_flow(int s,int t){
    int flow = 0;
    while(true){
        memset(used,0,sizeof(used));
        int f = dfs(s,t,INF);
        if(f == 0) return flow;
        flow += f;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int E,q;
    cin >> n >> E >> q;
    rep(i,E){
        int a,b;
        cin >> a >> b;
        add_edge(a-1,b-1,1);
    }
    int res = max_flow(0,n-1);
    rep(i,q){
        int a,b,c;
        cin >> a >> b >> c;
        --b,--c;
        if(a == 1){
            add_edge(b,c,1);
            res += max_flow(0,n-1);
        }else{
            int cap = G[b][c];
            erase_edge(b,c);
            if(cap == 2){
                swap(b,c);
            }
            if(cap != 1){
                memset(used,0,sizeof(used));
                int f = dfs(b,c,1);
                //a??????b???????????????1????????????(???(a,b)???????????????????????????????????????)
                if(f == 0){
                    memset(used,0,sizeof(used));
                    dfs(b,0,1);
                    memset(used,0,sizeof(used));
                    dfs(n-1,c,1);
                    --res;
                }
            }
        }
        cout << res << "\n";
    }
}

Measured memory_bytes: 4188
const main = (input: void) => {
  const args: string[] = input.split('');
  let cnt: number = 0;

  if (args[0] === '1') {
    cnt++;
  }
  if (args[1] === '1') {
    cnt++;
  }
  if (args[2] === '1') {
    cnt++;
  }
  console.log(cnt);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
long long o[70100][16];
int l[52][22],pp[70000];
int j[80001];

long long x,y,z,mod=1000000007;
string r;
//char r[2];

P u[1];
queue<int> q;
stack<int> s;
//set<int> s;
map<int,int> p;

vector<P> v[75551];


bool as(P a,P b)
{
  return a.x<b.x;
}

long long f(int n,int m)
{
  if((n==e-1)&&m==a-1) return 0;
  if((n==e-1)&&m!=a-1) return mod*mod;
  if(o[n][m]>=0) return o[n][m];
  o[n][m]=mod*mod;
  int s=n-(1<<m);
  for(int h=0;h<v[s].size();h++)
  if(!(v[s][h].x&(1<<m)))
  {
    if(pp[v[s][h].x]>=0&&l[m][pp[v[s][h].x]]) o[n][m]=min(o[n][m],f(n+v[s][h].x,pp[v[s][h].x])+v[s][h].y);
    o[n][m]=min(o[n][m],f(n+v[s][h].x,m)+v[s][h].y);
  }
  return o[n][m];
}

int main()
{
  scanf("%d %d",&a,&b);
  e=(1<<a);
  //printf("%d",e);
  memset(o,-1,sizeof(o));
  memset(pp,-1,sizeof(pp));
  for(int i=0;i<a;i++)
    pp[1<<i]=i;
  for(int t=1;t<=b;t++)
  {
    scanf("%d %d %d",&n,&m,&k);
    n--,m--;
    l[n][m]+=k;
    l[m][n]+=k;
  }
  for(int t=0;t<e;t++)
  {
    for(int p=e-1-t;p;p--,p&=(e-1-t))
    {
      //s.push(p);
      j[p]=0;
      if(pp[p]>=0)
      {
        for(int h=0;h<a;h++)
        if(t&(1<<h)) j[p]+=l[pp[p]][h];
        v[t].push_back({p,j[p]});
      }
      else s.push(p);
    }
    for(;s.size();s.pop())
    {
      j[s.top()]=j[(s.top()-1)&s.top()]+j[s.top()-((s.top()-1)&s.top())];
      v[t].push_back({s.top(),j[s.top()]});
    }
    //for(int h=0;h<v[t].size();h++)
    //  printf("%d ",v[t][h].x);
    //  puts("");
  }
  //puts("#");
  /*for(int t=1;t<=e;t++)
  for(int h=0;h<a;h++)
    o[t][h]=mod;
  o[1][0]=0;
  for(int i=1;i<e;i++)
  for(int t=0;t<a;t++)
  if(i&(1<<t))
  {
    int s=i-(1<<t);
    for(int h=0;h<v[s].size();h++)
    if((v[s][h].x&(1<<t))==0)
    {
      o[i+v[s][h].x][t]=min(o[i+v[s][h].x][t],o[i][t]+v[s][h].y);
      if(pp[v[s][h].x]>=0)
        o[i+v[s][h].x][pp[v[s][h].x]]=min(o[i+v[s][h].x][pp[v[s][h].x]],o[i][t]+v[s][h].y);
    }
  }*/
  //printf("%d",o[e-1][a-1]);
  printf("%lld",f(1,0));
  
}
//15


//261



Measured memory_bytes: 125636
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,a,n) for(ll i=a;i<n;i++)
#define w(_t) ll _t;cin>>_t;while(_t--)


int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    ll x;cin>>x;
    if(x>=30) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

using namespace std;
const int N = 1000 + 10, mod = 1e9 + 7;
typedef long long ll;

int main()
{
    int n, m;
    while(cin>>n>>m)
    {
        ll ans1 = 1, ans2 = 1, ok1 = 0, ok2 = 0;
        int tmp = m;
        for(int i = 1; i<=n; i++)
        {
            ans1 = ans1 * (n-i+1)%mod;
            if(tmp == 0)
            {
                if(i != n){
                    ok1++;
                    break;
                }
                else break;
            }
            ans1 = ans1 * tmp % mod;
            tmp--;
        }
        if(tmp!=0)
            ok1  ++;
        tmp = n;
        for(int i = 1; i<=m; i++)
        {
            ans2 = ans2 * (m-i+1)%mod;
            if(tmp == 0)
            {
                if(i != m){
                    ok2++;
                    break;
                }
                else break;
            }
            ans2 = ans2 * tmp % mod;
            tmp--;
        }
        if(tmp)
            ok2++;
        if(ok1+ ok2 == 2)
            puts("0");
        else if(!ok1 && !ok2)
            cout<<(ans1 + ans2)%mod<<endl;
        else if(!ok1)
            cout<<ans1<<endl;
       else cout<<ans2<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
s =str(input())
flag = True
for i in range((len(s)-1)//2):
     if s[i] != s[i + (len(s)+3)//2-1] or s[i] != s[(len(s)-1)//2-i-1]:
          flag = False



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

Measured memory_bytes: 3060
#include<iostream>
#include<string.h>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;

int ans[100000];
vector<int>rinsetu[100000];
int mincost[100000];
int E[100000], F[100000], G[100000];
int K[100000];//その地点から探索した最大の距離の地点
signed main() {
	memset(ans, -1, sizeof(ans));
	memset(K, -1, sizeof(K));
	int a, b;
	scanf("%d%d", &a, &b);
	for (int c = 0; c < b; c++) {
		int d, e; scanf("%d%d", &d, &e); d--; e--;
		rinsetu[d].push_back(e);
		rinsetu[e].push_back(d);
	}
	int c; scanf("%d", &c);
	for (int d = 0; d < c; d++) {
		int e, f, g; scanf("%d%d%d", &e, &f, &g);
		e--;
		E[c - d - 1] = e;
		F[c - d - 1] = f;
		G[c - d - 1] = g;
	}
	for (int d = 0; d < c; d++) {
		int e = E[d], f = F[d], g = G[d];
		memset(mincost, -1, sizeof(mincost));
		mincost[e] = 0;
		queue<int>Q;
		Q.push(e);
		while (Q.size()) {
			int i = Q.front(); Q.pop();
			if (mincost[i] > f)break;
			if (K[i] < f - mincost[i]) {
				K[i] = f - mincost[i];
			}
			else continue;
			if (ans[i] == -1)ans[i] = g;
			for (int j : rinsetu[i]) {
				if (mincost[j] == -1) {
					mincost[j] = mincost[i] + 1;
					Q.push(j);
				}
			}
		}
	}
	for (int i = 0; i < a; i++) {
		if (ans[i] == -1)puts("0");
		else  printf("%d\n", ans[i]);
	}
}

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

int main(){
  vector<int> a(5),b(5),c(5);
  int count = 0, plus = 0;
  
  for(int i = 0; i < 5; i++){
    cin >> a.at(i);
    b.at(i) = a.at(i) % 10;
    c.at(i) = a.at(i) / 10;
  }
  
  sort(b.begin(),b.end());
  
  for(int i = 0; i < 5; i++){
    if(b.at(i) != 0){
      count++;
    }
  }
  if(count != 0){
    count -= 1;
  }
  
  for(int i = 0; i < 5; i++){
    if(b.at(i) != 0){
      plus = b.at(i);
      break;
    }
  }

  for(int i = 0; i < 5; i++){
    count += c.at(i);
  }
  cout << count * 10 + plus ;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n,i;
	int a,b,c;
	
	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%d %d %d",&a,&b,&c);
		if((a*a) == (b*b+c*c) || (b*b) == (c*c+a*a) || (c*c) == (a*a+b*b))
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 580
s = input()
slen = len(s)
fs = ""
bs = ""
a = 0

if slen%2==1:
    fs = s[0:(slen//2)+1]
    bs = (s[::-1])[0:(slen//2)+1]

else:
    fs = s[0:(slen//2)]
    bs = (s[::-1])[0:(slen//2)]

for f,b in zip(fs,bs):
    if f != b:
        a += 1

print(a)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
ll n,cnt=0;
multiset<int> s;//multiset，允许重复，升序排列
map<int,int>mp;
int main() {
//    freopen("../in.in", "r", stdin);
//    freopen("../out.out","w",stdout);
    ios::sync_with_stdio(false);
    ll t, i, j = 0;
    ll m, x, y,k;
    cin>>n>>m;
    for(i=1;i<=m;i++) mp[i]=i,s.insert(0);//初始化
    for(i=1;i<=n;i++){
        int l,r;
        cin>>l>>r;
        auto it=mp.lower_bound(l);//从l开始
        int mx=0;
        while(it->first<=r&&it!=mp.end()){//循环到l-r区间结束
            mx=max(mx,it->second);//取离r最近的点
            s.erase(s.find(it->first-it->second));//将点从map和set中删去
            mp.erase(it++);
        }
        if(mx!=0&&r<m&&mp[r+1]<mx){//前两项防止越界，当map中不存在r+1时
            mp[r+1]=mx;//将r+1加入map和set
            s.insert(r+1-mx);
        }
        if(s.size()) cout<<*(s.begin())+i<<endl;//若set有点，直接取第一个+跨层步数i就是解
        else cout<<-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 22340
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let nk: Vec<u64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nk[0];
    let k = nk[1];


    if n+1 >= 2*k {
        println!("YES");
    } else {

        println!("NO");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define N 100003
#define what_is(x) cerr << #x << " is " << x << endl;

using namespace std;

int main() {
	// for fast input output using cin cout
	std::ios_base::sync_with_stdio(false);

	// size of array
	// input
	int n;
	cin>>n;
	int ans = 0;

	int temp = -1;
	while (n > 0) {
		if (temp == n % 10)
			ans++;
		else
			ans = 1;
		if (ans == 3)
			break;

		temp = n % 10;
		n /= 10;
	}

	if (ans == 3)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	string s, t;
	ll x, n;
	cin >> s;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i]=='B')
		{
			a++;
		}
		else
		{
			ans += a;
		}
	}
	cout << ans << endl;

	//cout << ans << endl;
	//cout <<  << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 640
n,m,c = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
a = n.times.map { gets.split.map(&:to_i)}
cnt = 0
for i in 0.. n -1 do
    sum = 0
    for j in 0.. m - 1 do
        sum = sum + a[i][j] * b[j]
    end
    sum + c > 0 ? cnt += 1: sum = 0
end
puts cnt

Measured memory_bytes: 1788
package main

import "fmt"

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var K, A, B int
	ans := 0
	fmt.Scan(&K, &A, &B)
	if (A + 2) >= B {
		ans = 1 + K
	} else {
		if 1 < A {
			K -= min(A-1, K)
		}
		n := K / 2
		ans = n*B - (n-1)*A + K%2
	}
	fmt.Println(ans)
}


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

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

	string s;

	cin >> s;

	int cnt1 = 0;
	int cnt2 = 0;

	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='0')
		{
			cnt1++;
		}
		else
		{
			cnt2++;
		}
	}

	cout << 2*min(cnt1,cnt2) << '\n';
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<cmath>
#include<string>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)
#define show(x) cout<< #x << " = " << (x) << endl
#define show_array(arr) REP(i,int((arr).size()))cout<< #arr << "["<<i<<"]"<<"="<<arr[i]<<endl

int main(){
	
	ios::sync_with_stdio(false);
	string str;
	cin>>str;

	string str_y("YAKI");
	
	bool ts = false;
	if(str.size() >= 4){
	ts = true;
	REP(i,4){
		ts = ts && (str_y[i] == str[i]);
	}
	}
	cout<< (ts ? "Yes" : "No")<<endl;	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int n, a, mon;
bool out;
int main() {
	cin >> n;
	char h;
	for (int i = 0; i < n; ++i) {
		cin >> h >> a;
		if (h == '(') { mon += a; }
		else { mon -= a; }
		if (mon < 0) {
			out = 1;
			break;
		}
	}
	if (!out&&mon == 0) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  ll n,m,v,p;
  cin >> n >> m >> v >> p;
  vll a(n);
  rep(i,n) cin >> a[i];
  sort(ALL(a));
  vll s(n+1);
  s[0] = 0;
  rep(i,n) s[i+1] = s[i]+a[i];
  ll cnt = 0;
  rep(i,n){
    if(a[i]+m<a[n-p])continue;
    ll vorte = m*(v);
    ll l = upper_bound(ALL(a),a[i])-a.begin();
    //ll u = lower_bound(ALL(a),a[i])-a.begin();
    ll r = lower_bound(ALL(a),a[i]+m)-a.begin();
    //ll k = distance(upper_bound(ALL(a),a[i]+m),a.end());
    vorte -= m*l;
    //if(i==2)cout << k << endl;
    vorte -= m*(p-1);
    vorte -= max((a[i]+m)*(min(r-1,n-p)-l+1)-s[min(r,n-p+1)]+s[l],0LL);
    //if(i==2)cout << s[r] << " " << s[l]  << endl;
    if(vorte<=0LL){
      cnt++;
      //cout << i << endl;
    }
  }
  cout << cnt << endl;
  
}






Measured memory_bytes: 1920
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt()
	}
	sort.Ints(a)
	if a[0] == 0 {
		fmt.Println(0)
		return
	}

	ans := 1
	for _, v := range a {
		if ans*v > 1000000000000000000 || v > math.MaxInt64/ans {
			fmt.Println(-1)
			return
		}
		ans *= v
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5916
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

#define Rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PrintLn(X) cout << X << endl
int main(void)
{
	int a, b;
	cin >> a >> b;
	if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0){
		PrintLn("Possible");
	}else{
		PrintLn("Impossible");
	}
	return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
M = [input() for _ in range(h)]

bk = '#'
wt = '.'

for r in range(h):
    for c in range(w):
        if M[r][c] == bk:
            flg = False
            for dx, dy in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
                r2 = r + dy
                c2 = c + dx
                if (0 <= r2 < h) and (0 <= c2 < w):
                    if M[r2][c2] == bk:
                        flg = True
                        break
            if not flg:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064
# A XOR_Circle
n = int(input())
a = list(map(int,input().split()))
dic = {}
a.sort()
for i in a:
    if (i in dic):
        dic[i] += 1
    else:
        dic[i] = 1

if (len(dic) == 1):
    if (0 in dic):
        print("Yes")
    else:
        print("No")
elif (len(dic) == 2):
    if (0 in dic):
        if (dic[0] == n/3):
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif (len(dic) == 3):
    l = list(dic.keys())
    if (l[0]^l[1]^l[2] == 0):
        v = list(dic.values())
        if (v[0] == v[1])&(v[1] == v[2])&(v[2] == n/3):
            print("Yes")
        else:
            print("No")
    else :
        print("No")
else:
    print("No")
    

Measured memory_bytes: 14116
line1 = input()
line2 = input()

aryLine1 = line1.split()
arystrLine2 = line2.split()

K = int(aryLine1[0]);
N = int(aryLine1[1]);

aryLine2 = [int(s) for s in arystrLine2]
#print(aryLine2)

aryLine2.sort()
#print(aryLine2)

ans = K

for i in range(0, N):
    temp1 = int(aryLine2[i])
    if i == N - 1:
        temp2 = int(aryLine2[0]) + K
    else:
        temp2 = int(aryLine2[i + 1])

    temp = temp1 - temp2 + K

    if temp < ans:
        ans = temp

print(ans)

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


int main() {

	int N;
	cin >> N;

	vector<int> d(N);
	for (int i = 0; i < N; i++)
	{
		cin >> d[i];
	}

	int sum = 0;
	for (int i = 0; i < N-1; i++)
	{
		for (int j = i+1; j < N; j++)
		{
			sum += d[i] * d[j];
		}

	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
//Heaplax
#include<bits/stdc++.h>
#define int long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int a,b,c,d,n;
main()
{
	re(a),re(b),re(c),re(d),re(n);
	c=min(c,min(4*a,2*b));
	d=min(d,2*c);
	printf("%lld\n",n/2*d+(n&1)*c);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

const ULL M = 998244353;

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N) cin >> A[i];
		ULL ans = 1; rep(i, N) ans = ans * 3 % M;
		UL S = 0; rep(i, N) S += A[i];
		UL J = S / 2;
		vector<ULL> dp(J + 1); dp[0] = 1;
		vector<ULL> dp2(J + 1); dp2[0] = 1;
		rep(i, N) {
			vector<ULL> buf = dp;
			vector<ULL> buf2 = dp2;
			for (UL j = A[i]; j <= J; j++) {
				buf[j] += dp[j - A[i]] << 1;
				buf2[j] += dp2[j - A[i]];
			}
			rep(i, J + 1) {
				dp[i] = buf[i] % M;
				dp2[i] = buf2[i] % M;
			}
		}
		rep(i, J + 1) {
			ans += (M - dp[i]) * 3;
		}
		if (J * 2 == S) ans += dp2[J] * 3;
		ans %= M;
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 1704
n = int(input())
S = list(map(int,input().split()))
bl = True
for i in range(1,n):
    if S[i]-S[i-1]>0:
        S[i] -=1
    elif S[i] == S[i-1]:
        S[i] +=0
    else:
        bl = False
        break
print('Yes' if bl else 'No')

Measured memory_bytes: 14396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		long a[] = new long[n + 1];

		String str[] = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(str[i]);
		}

		long dp[][] = new long[n + 1][n + 1];

		for (int len = 1; len <= n; len++) {
			for (int l = 0; l + len <= n; l++) {
				int r = l + len;
				if ((n - len) % 2 == 0) {
					dp[l][r] = Math.max(dp[l + 1][r] + a[l], dp[l][r - 1] + a[r - 1]);
				} else {
					dp[l][r] = Math.min(dp[l + 1][r] - a[l], dp[l][r - 1] - a[r - 1]);
				}
			}
		}

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


Measured memory_bytes: 129484
import java.io.*;
import java.util.*;

public class Main {

	void submit() {
		int n = nextInt();
		int p = nextInt();
		int c0 = 0;
		int c1 = 0;
		for (int i = 0; i < n; i++) {
			int x = nextInt();
			if (x % 2 == 0) {
				c0++;
			} else {
				c1++;
			}
		}
		
		if (c1 == 0) {
			out.println(p == 0 ? (1L << n) : 0);
		} else {
			out.println(1L << (n - 1));
		}
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    // source code
    int N = inputValue();    
    string S;
    cin >> S;
    rep (i, S.size()) {
        cout << char(((S[i] - 'A' + N) % 26 + 'A'));
    }
    return 0;
}

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

int main() {
    int L;
    cin >> L;
    int r = 0;
    while(L >> (r + 1)) ++r;
    int cnt = __builtin_popcount(L) - 1;

    cout << r + 1 << ' ' << 2 * r + cnt << endl;
    for(int i=0; i<r; ++i) {
        cout << i + 1 << ' ' << i + 2 << ' ' << 0 << endl;
        cout << i + 1 << ' ' << i + 2 << ' ' << (1 << i) << endl;
    }
    for(int i=r-1; i>=0; --i) {
        if(L - (1 << i) >= (1 << r)) {
            cout << i + 1 << ' ' << r + 1 << ' ' << L - (1 << i) << endl;
            L ^= (1 << i);
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAXN 102

long long pow9(long long K)
{
    long long ans = 1;
    for(;K > 0; K--)
      ans *= 9;
    return ans;
}
long long nck(long long N, long long K)
{
    if(K > N)
      return 0;
    if(K == 0)
      return 1;
    if(K == 1)
      return N;
    if(K == 2)
      return ((N * (N - 1)) / 2);
    if(K == 3)
      return ((N * (N - 1) * (N - 2)) / 6);
    return 0;
}

long long compute(long long *a, long long N, long long K)
{
    if(K == 0)
      return 1;
    if(N == 0)
      return 0;
    if(K > N)
      return 0;
    long long ans = 0;
    if(!a[0])
        return compute(a + 1, N - 1, K);
    ans += nck(N - 1, K) * pow9(K);
   // printf("N = %lld, K = %lld, ans when 0 = %lld\n", N, K, ans);
    ans = a[0] ? ans + (a[0] - 1) * nck(N - 1, K - 1) * pow9(K - 1) + compute(a + 1, N - 1, K - 1) : ans;
   // printf("N = %lld, ans = %lld\n", N, ans);
    return ans;
}

int main()
{
    long long  K, N, i, a[MAXN];
    char str[MAXN];
    scanf("%s", str);
    scanf("%lld", &K);
    for(i = 0; str[i]; i++)
    {
      a[i] = (long long) (str[i] - '0');
      // printf("%lld ", a[i]);
    }
    N = i;
    printf("%lld\n", compute(a, N, K));
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  const int mod = 1000000007;
  long long ans = 1;
  for (int i = 1; i <= n; i++) {
    ans *= i;
    ans %= mod;
  }
  cout << ans << endl;
  return(0);
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {

    int h, a;
    cin >> h >> a;

    if(h % a == 0){
        cout << h / a << endl;
    }
    else{
        cout << h / a + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		int count = 0;
		while (true) {
			boolean containOdd = false;
			for (int i = 0; i < a.length; i++) {
				int tmp = a[i];
				if (tmp % 2 == 0) {
					a[i] = tmp / 2;
				} else {
					containOdd = true;
					break;
				}
			}
			if (containOdd)
				break;
			else
				count++;
		}
		System.out.println(count);
		sc.close();
	}
}

Measured memory_bytes: 23892