akhauriyash/Code-Regression huggingface dataset:
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;
use std::cmp::min;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let x = scan.read::<i64>();
    let a = scan.readn::<i64>(n);
    let mut b = a.clone();
    let mut ret = 1i64 << 60;
    for k in 0..n {
        ret = min(ret, k as i64 * x + b.iter().cloned().sum::<i64>());
        for i in 0..n {
            b[i] = min(b[i], a[(i + n - k - 1) % n]);
        }
    }
    println!("{}", ret);
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
    ll n;
    cin >> n;
    set<string> st;
    for (ll i = 0; i < n; i++) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
}


Measured memory_bytes: 19256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

string s;
cin >> s;
int ln = s.size()-2;
if(s[0]==s[s.size()-1])ln--;
if(ln%2==0)
    cout << "Second" << endl;
else cout << "First" << endl;

  }


Measured memory_bytes: 3700
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
using namespace std;
using ll =long long;
int main() {
	int N;
	cin >> N;
	map<ll,ll>A;
	vector<ll>B;
	int c;
	int max=0;
	for (int i = 0; i < N; i++) {
		cin >> c;
		A[c]++;
		B.push_back(c);
		
	}
	unsigned long long count=0;
	for (auto i = A.begin(); i != A.end(); i++) {
		if (i->second > 1) {
			count += i->second * (i->second - 1) / 2;
		}
	}
	for (int i = 0; i < N; i++) {
		if (A[B[i]] > 1) {
			cout << count - (A[B[i]] - 1) << endl;
		}
		else {
			cout << count<<endl;
		}
	}
	
}

Measured memory_bytes: 13040
/* Grading */
#include <stdio.h>

int main(void) {
        int m, f, r;

        while (1) {
                scanf("%d %d %d", &m, &f, &r);

                /* End of records */
                if ( m == -1 && f == -1 && r == -1 ) {
                        break;}

                /* F */
                if ( m == -1 || f == -1 ) {
                        printf("F\n");
                        continue;}

                /* F */
                if ( m + f < 30 ) {
                        printf("F\n");
                        continue;}

                /* D */
                if ((m + f >= 30) && (m + f < 50)) {
                        if ( r >= 50 ) {
                                printf("C\n");
                                continue;}
                        else {
                                printf("D\n");
                                continue;}
                }

                /* C */
                if ((m + f >= 50) && (m + f < 65)){
                                printf("C\n");
                                continue;}

                /* B */
                if ((m + f >= 65) && (m + f < 80)){
                                printf("B\n");
                                continue;}

                /* A */
                if ( m + f >= 80) {
                                printf("A\n");
                                continue;}
}
return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);
    
    int N,K;
    cin >> N >> K;
    int ans = 0;
    for(int i=0; i<N; i++){
        int x;
        cin >> x;
        ans += 2*min(x,K-x);
    }
    cout << ans << endl;
    
    return 0;
}


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

int main(int argc, const char * argv[]) {
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  int xmax = -999;
  int ymin = 999;
  int a;
  for(int i = 0; i < n; i++){
    cin >> a;
    xmax = max(xmax,a);
  }
  for(int i = 0; i < m; i++){
    cin >> a;
    ymin = min(ymin,a);
  }

  if(xmax < ymin && x < ymin && xmax < y){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}

signed main() {
    accell();
    int n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<int>a(n);
    for (auto &i : a)
        cin >> i;
    sort(rall(a));
    int l = p - 1, r = n;
    while (r - l > 1) {
        int mid = l + r >> 1;
        int cur = a[mid] + m;
        int curv = v - (n - mid);
        int should = v - (p - 1) - (n - mid);
        should *= m;
        int res = 0;
        for (int i = mid - 1; i >= p - 1; --i) {
            res += (cur - a[i]);
        }
        bool govno = false;
        for (int i = mid - 1; i >= p - 1; --i) {
            if (a[i] > cur) {
                govno = true;
            }
        }
        if (res >= should && !govno)
            l = mid;
        else
            r = mid;
    }
    cout << l + 1;
    return 0;
}


Measured memory_bytes: 1024
def use_fast_io():
    global input
    import io
    import sys
    f = io.BytesIO(sys.stdin.buffer.read())
    input = f.readline
use_fast_io()
 
 
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
 
N, M, L = map(int, input().split())
graph = np.full((N, N), 10**10)
for _ in range(M):
    s, t, w = map(int, input().split())
    if w <= L:
        graph[s-1][t-1] = graph[t-1][s-1] = w
graph = floyd_warshall(graph, directed=False)
graph = floyd_warshall(graph <= L, directed=False)
graph[np.isinf(graph)] = 0
 
Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(int(graph[s-1][t-1]) - 1)
print(*ans, sep='\n')

Measured memory_bytes: 20252
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
class dsu {
public:
   vector<int> p;
   vector<int> sz;
   int n , cc;

   dsu(int _n) : n(_n) , cc(_n) {
      p.resize(n);
      sz.resize(n);
      fill(sz.begin() , sz.end() , 1);
      iota(p.begin(), p.end(), 0);
   }

   inline int get(int u) {
      return (u == p[u] ? u : (p[u] = get(p[u])));
   }

   inline bool unite(int u, int v) {
      u = get(u);
      v = get(v);

      if(u == v)return false;

      if(sz[v] < sz[u])swap(u , v);
      p[u] = v;
      sz[v] += sz[u];
      cc--;
      return true;
   }
};
const int N = 1e5 + 44;
int deg[N] , bad[N];
vector<int> adj[N];
int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n , m , k;
   cin >> n >> m >> k;
   dsu ds(n + 1);
   for(int i = 0 ; i < m ; ++i){
      int u , v;
      cin >> u >> v;
      deg[u]++ , deg[v]++;
      ds.unite(u , v);
   }

   for(int i = 0 ; i < k ; ++i){
      int u , v;
      cin >> u >> v;
      adj[u].pb(v);
      adj[v].pb(u);
   }

   for(int i = 1 ; i <= n ; ++i){
      for(int v : adj[i]){
         if(ds.get(v) == ds.get(i)){
            bad[i]++;
         }
      }
   }

   int res = ds.sz[ds.get(1)] - 1 - deg[1] - bad[1];
   cout << res;
   for(int i = 2 ; i <= n ; ++i){
      res = ds.sz[ds.get(i)] - 1 - deg[i] - bad[i];
      cout << ' ' << res;
   }
   cout << "\n";
}

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define rep(i, n) for(int i = 0; i < n; i++)
const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
  int N;
  cin >> N;
  int count = 0;
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    if(a == b) {
      count++;
    }
    else {
      count = 0;
    }
    if(count == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    int x,y,z;
    cin>>x>>y>>z;
    cout<<z<<' '<<x<<' '<<y<<endl;



    
return 0;
}


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

using ll = long long;
using ull = unsigned long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >>N;
    
    int ans = 0;
    int h, h_prev = 0;
    rep(i, N) {
        cin >> h;
        if (h > h_prev)
            ans += h - h_prev;
        h_prev = h;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
q = lambda i:input('%d\n'%i)
i, j = 0, n - 1
a, b = q(i), q(j)
while True:
  k = (j - i + 1) // 2 + i
  c = q(k)
  if (k - i)%2 == (a==c):
    j = k
  else:
    a = c
    i = k


Measured memory_bytes: 9212
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int keta(ll a) {
  ll tmp = 1e10;
  int ans;
  for(int i=11;i>=1;--i) {
    if(a/tmp>0) {
      ans = i;
      break;
    }
    tmp /= 10;
  }
  return ans;
}

int main() {
  ll N;
  cin>>N;
  int ans = inf;
  for(ll i=1;i*i<=N;++i) {
    if(N%i==0) {
      ans = min(ans, max(keta(i), keta(N/i)));
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3608
n = int(input())

dp = [0]*(45)
dp[0] = 1
dp[1] = 1
def fib(i):
    j = 2
    while j <= i:
        if j >= 2:
            dp[j] = dp[j-1] + dp[j-2]
        j += 1

fib(n)
print(dp[n])



Measured memory_bytes: 5600
import sys, re

def echo(A):
    for i, a in enumerate(A):
        if i < len(A) - 1:
            sys.stdout.write('%d ' % a)
        else:
            sys.stdout.write('%d\n' % a)

def insertionSort(A, N):
    echo(A)
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        echo(A)


n = int(raw_input())
a_text = raw_input()
splits = re.split(' ', a_text)
a = []
for i, s in enumerate(splits): 
    if s:
        a.append(int(s))

insertionSort(a, n)

Measured memory_bytes: 6404
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n,m;
  cin >> n >> m;

  vector<pair<bool,ll>> t(n);

  for(auto itr = t.begin();itr!=t.end();itr++)
  {
    itr->first = false;
    itr->second = 0; 
  }

  for(ll i = 0;i <m;i++)
  {
    ll a;
    string b;
    cin >> a >> b;

    if(t[a-1].first)
    {
      // すでに正当答ならなにもしない
    }
    else
    {
      if(b == "WA")
      {
        t[a-1].second++;
      }
      else
      {
        t[a-1].first = true;
      }
    }
  }

  ll AC = 0,WA = 0;
  for(auto itr=t.begin();itr!=t.end();itr++)
  {
    if(itr->first)
    {
      AC++;
      WA += itr->second;
    }
  }



  cout << AC << " " << WA << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

ll sqrtll(ll N) {
    ll ok = 1;
    ll ng = sqrt(N) + 1;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (mid * mid <= N) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    return ok;
}

void solve(ll A, ll B) {
    if (A > B) {
        swap(A, B);
    }

    if (abs(A - B) > 1) {
        ll C = sqrt(A * B);
        if (C * C == A * B) {
            C--;
        }
        if (C * (C + 1) >= A * B) {
            cout << 2 * C - 2 << endl;
        } else {
            cout << 2 * C - 1 << endl;
        }
    } else {
        cout << 2 * A - 2 << endl;
    }
}

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

    ll Q;
    cin >> Q;
    vector<p> qs;
    for (ll q = 0; q < Q; q++) {
        ll A, B;
        cin >> A >> B;
        qs.emplace_back(A, B);
    }

    for (auto&& q : qs) {
        solve(q.first, q.second);
    }
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <set>
using namespace std;
int n;
struct node{
	int x,y,z;
	bool operator<(const node &t)const{
		if(x!=t.x)return x<t.x;
		if(y!=t.y)return y<t.y;
		return z<t.z;
	}
	node(int a,int b,int c){
		x=a;
		y=b;
		z=c;
	}
};
set<node>s;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		s.clear();
		for(int a=2;a*a<=2*i;++a){
			for(int b=2;a*a+b*b<=2*i;++b){
				if(floor(sqrt(2*i-a*a-b*b))!=sqrt(2*i-a*a-b*b))continue;
				int c=sqrt(2*i-a*a-b*b);
				int x=a+b-c,y=a+c-b,z=b+c-a;
				if(x%2||y%2||z%2)continue;
				x/=2;
				y/=2;
				z/=2;
				if(!(x>0&&y>0&&z>0))continue;
				s.insert(node(x,y,z));
			}
		}
		printf("%d\n",(int)s.size());
	}
	return 0;
}


Measured memory_bytes: 3320
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<map>

using namespace std;

int n, t[100000], x[100000], y[100000];

int main() {
	string ans = "Yes";
	cin >> n;
	for (int i = 0; i < n; i++)cin >> t[i] >> x[i] >> y[i];
	int ct = 0, cx = 0, cy = 0;
	for (int i = 0; i < n; i++) {
		int d = abs(x[i] - cx) + abs(y[i] - cy);
		if (d <= t[i] - ct && (t[i] - ct - d) % 2 == 0) {
			if (i == n - 1)break;
			else
				ct = t[i], cx = x[i], cy = y[i];
		}
		else {
			ans = "No";
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#define int long long
using namespace std;

const int N = 1e5+1;

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  int n, wmax;
  cin >> n >> wmax;
  int w[n], v[n];
  for(int i = 0; i < n; i++)
    cin >> w[i] >> v[i];
  int minw[N];
  for(int i = 1; i < N; i++)
    minw[i] = 1 << 30;
  minw[0] = 0;
  for(int i = 0; i < n; i++)
    for(int j = N-1; j >= v[i]; j--)
      minw[j] = min(minw[j], minw[j-v[i]] + w[i]);
  for(int i = N-1; i > -1; i--)
    if(minw[i] <= wmax) {
      cout << i;
      return 0;
    }
}

Measured memory_bytes: 1024
#ダメそうな雰囲気する

n=int(input())
amod4=[i%4 for i in map(int,input().split())]
#print(amod4)
from collections import Counter
s=Counter(amod4)
num4=s[0]
num2=s[2]

#print(num4,num2,another)

def ok():print("Yes");exit()
def ng():print("No");exit()

if num2==n:
  ok()
  
if num4>=(n-(num2-1)*(n>num2>0))//2:ok()

else:
  ng()



Measured memory_bytes: 11096
n, m, x, y = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

ans = "War"

for z in range(x+1, y+1):
    if(max(X) < z & z <= min(Y)):
        ans = "No War"

print(ans)


Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int d,n;
int t[222];
vector<int> m[66];
int c[222];

int dp[222][222];
int solve(int i,int b){
  if(i == d) return 0;
  if(dp[i][b] >= 0) return dp[i][b];

  int tt = t[i];
  int ret = 0;
  //cout << i << ":" << m[tt].size() << endl;
  for(int j = 0; j < (int)m[tt].size(); j++){
    int a = m[tt][j];
    ret = max(ret,solve(i+1,a) + ((i > 0)?abs(c[a] - c[b]):0));
  }

  return dp[i][b] = ret;
}

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

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

  for(int i = 0; i < n; i++){
    int a,b;
    cin >> a >> b >> c[i];
    for(int j = a; j <= b; j++){
      m[j].push_back(i);
    }
  }

  memset(dp,-1,sizeof(dp));
  cout << solve(0,0) << endl;

}

Measured memory_bytes: 1456
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	string s, t; cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());
	if (s < t) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define pob         pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define sc3(a,b,c)  cin>>a>>b>>c
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define	mp3(a,b,c)  make_pair(a,make_pair(b,c))
#define se          second
#define fi          first 
#define sse         second.second
#define sfi         second.first
#define soA         sort(A+1,A+1+n)
#define so(A,n)     sort(A+1,A+1+n)
#define sov(v)      sort(all(v))
#define sovr(v)     sort(all(v),greater<ll>())
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	
	string s,s2,s3;
	cin>>s>>s2;
	cin>>x>>y;
	sc(s3);
	if(s3==s2)pr2(x,y-1);
	else pr2(x-1,y);
	
	
	
	
	
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	} 		
}

Measured memory_bytes: 256
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);
  auto s = new char[][](2, n);
  foreach (i; 0 .. 2)
    s[i] = readln.chomp.to!(char[]);

  const long mod = 10 ^^ 9 + 7;
  auto dp = new long[][](2, n);
  if (s[0][0] == s[1][0])
    dp[0][0] += 3;
  else
    dp[1][1] += 6;
  foreach (i; 1 .. n) {
    if (s[0][i] == s[1][i]) {
      dp[0][i] = (dp[0][i - 1] * 2 + dp[1][i - 1]) % mod;
    } else if (i >= 2) {
      dp[1][i] = (dp[0][i - 2] * 2 + dp[1][i - 2] * 3) % mod;
    }
  }
  writeln((dp[0][n - 1] + dp[1][n - 1]) % mod);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


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

int main(void){
	int N;
	uint64_t a[50][2];
	std::cin >> N;
	for(int i=0;i<N;i++)std::cin >> a[i][0];
	uint64_t ans = 0;
	while(true){
		bool end = true;
		for(int i=0;i<N;i++)if(a[i][0] >= N)end = false;
		if(end)break;
		uint64_t sum = 0;
		for(int i=0;i<N;i++){
			uint64_t x = a[i][0] / N;
			sum += x;
			a[i][1] = x;
			a[i][0] = a[i][0] % N;
		}
		ans += sum;
		for(int i=0;i<N;i++){
			a[i][0] += sum - a[i][1];
		}
	}
	std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  998244353;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}
  void init(int n) { par.assign(n, -1); }

  int root(int x) {
    if (par[x] < 0)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if (par[x] > par[y])
      swap(x, y);
    par[x] += par[y];
    par[y] = x;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { return -par[root(x)]; }
};

signed main() {
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  vector<vector<ll>> dic('z' - 'a' + 1);
  REP(i, s.size()) {
    dic[s[i] - 'a'].push_back(i);
  }
  ll ans = 0;
  ll index = -1;
  REP(i, t.size()) {
    int c = t[i] - 'a';
    if(dic[c].size() == 0) {
      cout << -1 << endl;
      return 0;
    }
    int ni = bsearch(dic[c], index+1);
    // cout << "==== " << t[i] << " ====" << endl;
    // cout << "index = " << index << endl;
    // cout << "ni = " << ni << endl;
    // cout << dic[c][ni]  << endl;
    if(dic[c][ni] > index) {
      index = dic[c][ni];
    }
    else if(ni+1 < dic[c].size() && dic[c][ni+1] > index) {
      index = dic[c][ni+1];
    }
    else {
      ans += 1;
      index = dic[c][0];
    }
  }
  ans *= s.size();
  ans += index + 1;
  cout << ans << endl;
  return 0; 
}


Measured memory_bytes: 1736
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair
#define MOD 1000000007

//先手が勝てるか
bool dp[200001][2];
bool already[200001][2] ={};
bool solve(int now, int player){
	if(now == 1){
		if(player == 0) return true;
		else return false;
	}
	if(now == 2) return solve(1, player^1);
	if(already[now][player]) return dp[now][player];
	already[now][player] = true;
	if(player == 0){
		return dp[now][player] = (solve(now-1, player^1) || solve(now-2, player^1));
	}
	else{
		return dp[now][player] = (solve(now-1, player^1) && solve(now-2, player^1));
	}
}

int N;
vector<int> edge[200000];
int cost[200000];

int main(){
	cin >> N;
	for(int i=0; i<N-1; i++){
		int a, b;
		cin >> a >> b;
		edge[a-1].PB(b-1);
		edge[b-1].PB(a-1);
		cost[i] = INT_MAX;
	}
	cost[N-1] = INT_MAX;

	queue<int> que;
	que.push(0);
	cost[0] = 0;
	while(!que.empty()){
		int now = que.front();
		que.pop();
		for(int i=0; i<edge[now].size(); i++){
			int next = edge[now][i];
			if(cost[next] > cost[now]+1){
				cost[next] = cost[now]+1;
				que.push(next);
			}
		}
	}
	
	int M = -1;
	int idx = -1;
	for(int i=0; i<N; i++){
		if(cost[i] > M){
			M = cost[i];
			idx = i;
		}
		cost[i] = INT_MAX;
	}

	que.push(idx);
	cost[idx] = 0;
	while(!que.empty()){
		int now = que.front();
		que.pop();
		for(int i=0; i<edge[now].size(); i++){
			int next = edge[now][i];
			if(cost[next] > cost[now]+1){
				cost[next] = cost[now]+1;
				que.push(next);
			}
		}
	}

	M = -1;
	for(int i=0; i<N; i++){
		M = max(M, cost[i]);
	}

	if(solve(M+1, 0)) cout << "First" << endl;
	else cout << "Second" << endl;
}

Measured memory_bytes: 22144
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

result = -float('inf')
for i in range(1, 1024):
    t = 0
    for j in range(N):
        c = 0
        for k in range(10):
            c += (i >> k & 1) & F[j][k]
        t += P[j][c]
    result = max(result, t)
print(result)


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

int main(){
    int N, A, B;
    scanf("%d", &N);
    if(N == 1){
        printf("Hello World");
    }else if(N == 2){
        scanf("%d%d", &A, &B);
        printf("%d", A + B);
    }
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : (x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair((x), (y))

typedef long long ll;

typedef double T;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<T> vt;
typedef vector<vt> vvt;
typedef vector<pii> vpi;
typedef vector<vpi> graph;
typedef complex<T> Pt;
typedef pair<Pt, Pt> Line;

const ll MOD = 1e9+7; // 998244353;
const T EPS = 1e-7;
const int INF = 1e9 + 1;

template <typename A, typename B>
istream& operator>>(istream &in, pair<A, B> &p) {
    in >> p.first >> p.second;
    return in;
}

template <typename A, typename B>
ostream& operator<<(ostream &out, pair<A, B> &p) {
    out << "(" << p.first << " " << p.second << ")";
    return out;
}

template <typename I>
istream& operator>>(istream &in, vector<I> &a) {
    trav(i, a) in >> i;
    return in;
}

template <typename I>
ostream& operator<<(ostream &out, vector<I> &a) {
    rep(i, 0, sz(a)) {
        if (i) out << " ";
        out << a[i];
    }
    return out;
}

void fast_io() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin.exceptions(cin.failbit);
}

void solve_test() {
    ll n, m;
    cin >> n >> m;
    string s, t; 
    cin >> s >> t;
    rep(i, 0, n) {
        if (i*m%n == 0 && s[i] != t[i*m/n]) {
            cout << "-1\n";
            return;
        }
    }
    int a = min(n, m), b = max(n, m);
    while (a) {
        int c = b%a;
        b = a;
        a = c;
    }
    cout << n*m/b << "\n"; 
}

void setup() {
}

int main() {
    setup();
    srand(time(0));
    fast_io();
    int t = 1;
    // cin >> t;
    while (t--) {
        solve_test();
    }
}

Measured memory_bytes: 640
import itertools
n = int(input())
l = list(map(int, input().split()))
len_list = list(itertools.combinations(l, 3))
answer = 0
for lens in len_list:
  if len(set(lens)) == 3 and lens[0] < lens[1] + lens[2] and lens[1] < lens[0] + lens[2] and lens[2] < lens[0] + lens[1]:
    answer += 1
print(answer)

Measured memory_bytes: 20536
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)

inf = 10 ** 15
mod = 10 ** 9 + 7

s = input()
length = len(s)
if s[0] == 'A':
    tmp = s[2:length-1]
    count = 0
    if s[1].isupper():
        print('WA')
        sys.exit()
    for c in tmp:
        if c.isupper():
            if c == 'C':
                count += 1
            else:
                print('WA')
                sys.exit()
    if count == 1 and s[-1].islower():
        print('AC')
    else:
        print('WA')

else:
    print('WA')

Measured memory_bytes: 38384
/*
 *  AUTHOR : MANAV PATEl
*/
#include<bits/stdc++.h>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

namespace fastio {

	template <class T> istream &operator>>(istream &os, vector<T> & vec) {
		for (auto &u : vec)os >> u;
		return os;
	}
	template <class T> ostream &operator<<(ostream &os, const vector<T> & vec) {
		for (auto &u : vec)os << u << " ";
		return os;
	}
	template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p) {
		return os >> p.first >> p.second;
	}
	template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
		return os << p.first << " " << p.second;
	}
	template <class T> ostream &operator<<(ostream &os, set<T> & con) {
		for (auto &u : con) os << u << " ";
		return os;
	}
	void re() {}
	template <typename T, typename... args> void re(T& x, args&... tail) {
		cin >> x;
		re(tail...);
	}
	void pr() {}
	template <typename T> void pr(const T& x) {
		cout << x;
	}
	template <typename T, typename... args> void pr(const T& x, const args&... tail) {
		cout << x << " ";
		pr(tail...);
	}
	template <typename... args> void prln(const args&... tail) {
		pr(tail...);
		cout << "\n";
	}
}
using namespace fastio;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

int main()
{
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	int n;
	re(n);
	int arr[n], arr1[n];
	for(int i = 0; i < n; i++)
	{
		re(arr[i]);
		arr1[i] = arr[i];
	}
	sort(arr,arr+n);
	if(arr[n-1] == arr[n-2])
	{
		for(int i = 0; i < n; i++)
		{
			cout << arr[n-1] << "\n";
		}
	}
	else
	{
		for(int i = 0; i < n; i++)
		{
			if(arr1[i] == arr[n-1]) cout << arr[n-2] << "\n";
			else cout << arr[n-1] << "\n";
		}
	}
}



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

#define int long long
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) otp(v[i]) cte
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

string s;

main() {
    cin >> s;
    sort(all(s));
    auto ss=s.size();
    vdelete(s)
    if (s.size() == ss) ct("yes")
    else ct("no")
}

Measured memory_bytes: 256
A = [int(i) for i in input().split()]
B = [A[1],A[0],A[3],A[4]]
ans = 0
ans += B[0]
if min(B[1:]) == 0:
	for b in B[1:]:
		ans += b//2*2
elif not sum([i%2 for i in B[1:]])%3:
	ans += sum(B[1:])
else:
	ans += sum(B[1:])-1
print(ans)


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

int main() {
  int n,k;
  cin >> n >> k;
  long double ans = 0;
  rep(i,1,n+1) {
    int t = i;
    long double p = (long double)1/(long double)n;
    while(t < k) {
      p *= (long double)0.5;
      t *= 2;
    }
    ans += p;
  }
  printf("%.10lf\n", (double)ans);
  return 0;
}


Measured memory_bytes: 3684
get_string(String) :-
  current_input(Input),
  read_string(Input, ' \n', '', _, String).
 
get_number(Number) :-
  get_string(String),
  number_string(Number, String).

comp([],[_]).
comp([H1|S],[H1|T]) :- comp(S,T).
    
main :-
  get_number(A),
  get_number(B),
  get_number(C),
  get_number(K),
  (A >= K -> writeln(K);(D is A + B, D >= K)->writeln(A);Ans is A - (K - A - B), writeln(Ans)).

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

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

        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());

        st  = new StringTokenizer(br.readLine());

        int[] arr = new int[n];

        for (int i=0; i<n; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }

        int l=1,h=1000000000;
        while(l<h) {
            int mid = l+(h-l)/2;
            boolean res = check(mid,arr,k);
            if (res) {
                h=mid;
            }
            else
                l=mid+1;
        }
        if (check(l,arr,k)) {
            System.out.println(l);
        }
        else
            System.out.println("-1");


    }

    public static boolean check(int mid, int[] arr, int k) {
        for (int i=0; i<arr.length; i++) {
            if(arr[i]>mid){
                k-=arr[i]/mid;
                if (k<0) {
                    return false;
                }
            }
        }
        return true;
    }



}

Measured memory_bytes: 54752
#include<bits/stdc++.h>
using namespace std;
   
int main()
{
    int n,min,ans=1;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    min=arr[0];
    for(int i=1;i<n;i++){
        if(arr[i]<min)
            ans++,min=arr[i];
    }
    cout<<ans;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include <limits.h>
/* 値を入れ替える関数 */
void swap(int* x, int* y) {
	int temp;    // 値を一時保存する変数

	temp = *x;
	*x = *y;
	*y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition(int array[], int left, int right) {
	int i, j, pivot;
	i = left;
	j = right + 1;
	pivot = left;   // 先頭要素をpivotとする

	do {
		do { i++; } while (array[i] < array[pivot]);
		do { j--; } while (array[pivot] < array[j]);
		// pivotより小さいものを左へ、大きいものを右へ
		if (i < j) { swap(&array[i], &array[j]); }
	} while (i < j);

	swap(&array[pivot], &array[j]);   //pivotを更新

	return j;
}

/* クイックソート */
void quick_sort(int array[], int left, int right) {
	int pivot;

	if (left < right) {
		pivot = partition(array, left, right);
		quick_sort(array, left, pivot - 1);   // pivotを境に再帰的にクイックソート
		quick_sort(array, pivot + 1, right);
	}
}

int main() {
	long long int n;
	int i;
	char s[1000];
	scanf("%lld", &n);
	
	for (i = 0; n > 0; i++) {
		n--;
		s[i] = 'a'+ n % 26;
		n = n / 26;
	}
	while (i > 0) {
		i--;
		printf("%c", s[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int solve(int h,int w){
    if(h%3==0||w%3==0) return 0;
    int a1,a2;
    if(h%3==1){
        int k=h/3;
        a1=((w+1)/2)*(h-k)-k*w;
    }else{
        int k=(h+1)/3;
        a1=k*w-(w/2)*(h-k);
    }
    if(w%3==1){
        int k=w/3;
        a2=((h+1)/2)*(w-k)-k*h;
    }else{
        int k=(w+1)/3;
        a2=k*h-(h/2)*(w-k);
    }
    return min(min(h,w),min(a1,a2));
}

int main(){
    int h,w; cin>>h>>w;
    co(solve(h,w));
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main() {
	/*string s, t;
	cin >> s >> t;
	int ans = 0;
	rep(i, 3)if (s[i] == t[i])ans++;
	cout << ans;*/


	/*int a, b;
	cin >> a >> b;
	int ans = 0;
	while (ans * a - (ans - 1) < b) {
		ans++;
	}
	cout << ans;*/


	/*int n;
	cin >> n;
	int ans = 0;
	int h;
	int pre = -1;
	int k = 0;
	rep(i, n) {
		cin >> h;
		if (h <= pre) { k++; }
		else { ans = max(ans, k); k = 0; }
		pre = h;
	}
	ans = max(ans, k);
	cout << ans;*/


	ll n;
	cin >> n;
	cout << (n - 1) * n / 2;
	return 0;
}

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

typedef long long ll;
const int INF = 1e+9;

int main() {
	int N, W, sum = 0;
	static ll dp[110][100010];
	cin >> N >> W;
	vector<int> w(N), v(N);
	for (int i = 0; i < N; ++i)
		cin >> w[i] >> v[i];
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= W; ++j) {
			if (j >= w[i - 1]) dp[i][j] = max(dp[i-1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
			else dp[i][j] = dp[i - 1][j];
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

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

int main(){
  int t;
  cin >> t;
  for(int q=0;q<t;q++){
    LL a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a<b||d<b){
      cout << "No" << endl;
      continue;
    }
    LL g=gcd(b,d);
    if(a>c) a=a-(a-c+b-1)/b*b;
    a=a+(c-a+g)/g*g;
    if(a<b) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>
#include <sstream> // std::stringstream
#include <bitset>  // std::bitset<N>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
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;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a){
	
	if(a[index]>key){
		return true;
	}
	
	return false;
}

ll bin_search(ll key, vector<ll> &a){
	
	ll l=-1;
	ll r=a.size();

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

/*
//深さ優先探索
void dfs(vector<vector<ll>> &gra,vector<bool> &seen, ll v){

	seen[v]=true;

	for(auto next : gra[v]){
		if(seen[next]){
			continue;
		}

		dfs(gra,seen,next);
	}
	
}
*/

const ll MOD=1000000007;

ll min(ll a, ll b){
	if(a>=b){
		return b;
	}
	else{
		return a;
	}
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


void solve()
{
	ll n;
	cin >> n;
	bool ans = false;
	if(n%4==0){
		ans = true;
	}
	else{
		for (ll i = 0; i < (n / 4) + 1;i++){
			if((n-(i*4))%7==0){
				ans = true;
				break;
			}
		}
	}

	if (ans)
	{
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

int main(){
	
	solve();
	
    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int a[MAXN];
int G[105][105];

int main()
{
    int h,w;
    while(scanf("%d%d",&h,&w)!=EOF)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
            scanf("%d",&a[i]);
        int cnt=1;
        for(int i=1;i<=h;++i)
        {
            if(i&1)
            {
                for(int j=1;j<=w;++j)
                {
                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }else
            {
                for(int j=w;j>=1;--j)
                {
                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }
        }
        for(int i=1;i<=h;++i)
        {
            for(int j=1;j<=w;++j)
            {
                if(j!=w) printf("%d ",G[i][j]);
                else printf("%d\n",G[i][j]);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    rep(i,N){
        cin >> P[i];
    }
    rep(i,N){
        cin >> Q[i];
    }
    vector<int> permutation(N);
    rep(i,N){
        permutation[i] = i + 1;
    }
    int num = 1;
    for (int i = 1; i <= N; i++){
        num *= i;
    }
    int num_p = 0;
    int num_q = 0;
    rep(i,num){
        bool p = true;
        bool q = true;
        rep(j,N){
            if (permutation[j] != P[j]) p = false;
            if (permutation[j] != Q[j]) q = false;
        }
        if (p) num_p = i;
        if (q) num_q = i;
        next_permutation(all(permutation));
    }
    cout << max(num_p - num_q, num_q - num_p) << endl;
}


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

int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    int dx = c-a;
    int dy = d-b;
    int x = c;
    int y = d;
    for (int i=0; i<2; i++) {
        swap(dx, dy);
        dx *= -1;
        //int x = c+dx;
        //int y = d+dy;
        cout << x+dx << ' ' << y+dy << ' ';
        x = x+dx;
        y = y+dy;
    }

    return 0;
}


Measured memory_bytes: 256