akhauriyash/Code-Regression huggingface dataset:
// 入力マクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }

    let mut e = count_map(
        &a.iter()
            .enumerate()
            .filter(|x| x.0 % 2 == 0)
            .map(|x| *x.1)
            .collect(),
    )
    .into_iter()
    .collect::<Vec<(usize, usize)>>();
    e.sort_by(|a, b| (b.1).cmp(&a.1));
    let mut o = count_map(
        &a.iter()
            .enumerate()
            .filter(|x| x.0 % 2 == 1)
            .map(|x| *x.1)
            .collect(),
    )
    .into_iter()
    .collect::<Vec<(usize, usize)>>();
    o.sort_by(|a, b| (b.1).cmp(&a.1));

    let ans = if e[0].0 != o[0].0 {
        n - e[0].1 - o[0].1
    } else {
        std::cmp::min(
            n - if e.len() == 1 { 0 } else { e[1].1 } - o[0].1,
            n - if o.len() == 1 { 0 } else { o[1].1 } - e[0].1,
        )
    };

    println!("{}", ans);
}

fn count_map<T: Eq + std::hash::Hash + Copy>(v: &Vec<T>) -> std::collections::HashMap<T, usize> {
    let mut map = HashMap::new();
    for e in v {
        let h = map.entry(*e).or_insert(0);
        *h += 1;
    }
    map
}


Measured memory_bytes: 10132
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
long long a[N];
long long n, m;
typedef long long LL;
bool check(LL x)
{
	long long h1, h2, cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		if (a[i])
		{
			h1 = h2 = x / a[i];
			if (x % a[i])
			{
				if ((x < 0 && a[i]>0) || (x > 0 && a[i] < 0)) --h1;//不能直接相乘判断正负，因为会 爆
				else ++h2;
			}
			if (a[i] < 0)  cnt += n + 1 - (upper_bound(a + 1, a + 1 + n, h1) - a);
			if (a[i] > 0) cnt += lower_bound(a + 1, a + 1 + n, h2) - a - 1;
			if (a[i] * a[i] < x) cnt--;
		}
		else if (x > 0) cnt += n - 1;
	}
	cnt>>=1;
	return cnt<m;
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
 
	while (cin >> n >> m)
	{
		for (int i = 1; i <= n; i++) cin >> a[i];
		sort(a + 1, a + 1 + n);
		LL r=1e18, l=-1e18;
		LL ans;
		while (l <= r)
		{
			LL mid = l + r >> 1;
			if (check(mid)) {
				ans = mid;
				l = mid + 1;
			}
			else
				r = mid - 1;
		}
		cout << ans << endl;
	}
 
	return 0;
}

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

int main(){
	string s;
	cin >> s;
	int a = 2000000, z = 0;
	for (int i = 0; i < s.size(); i ++) {
		if (s[i] == 'A' && a > i) a = i;
		if (s[i] == 'Z' && z < i) z = i;
	}
	cout << z - a + 1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;



int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  ll N;
  cin>>N;

  string res;
  int sign=1;
  while (N!=0) {
    if (N%2!=0) {
      res='1'+res;
      N-=sign;
    } else {
      res='0'+res;
    }
    sign*=-1;
    N/=2;
  }
  if (res.empty()) res="0";
  cout<<res<<"\n";
}


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

const long long MOD = 1000000007;

using ll = long long;

//----------------------------------------------------------------------

// https://github.com/atcoder-live/library/blob/master/mint.cpp
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// https://github.com/atcoder-live/library/blob/master/comb.cpp
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

//----------------------------------------------------------------------

void solve(long long K, std::string S){
    long long s = S.size();
    long long n = K + s;
    auto c = combination(n);
    auto ans = mint(0);
    for (long long i = s; i <= n; i++) {
        ans += mint(25LL).pow(n - i) * c(n, i);
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 36740
N,a,b,c=map(int,input().split())
l=[int(input()) for _ in range(N)]

ans=[]
for i in range(4**N):
  A=[]
  B=[]
  C=[]
  p=i
  for j in range(N):
    if p%4==1:
      A.append(l[j])
    elif p%4==2:
      B.append(l[j])
    elif p%4==3:
      C.append(l[j])
    p=(p-p%4)//4
  if len(A)>0 and len(B)>0 and len(C)>0:
    ans.append(abs(sum(A)-a)+10*(len(A)-1)+abs(sum(B)-b)+10*(len(B)-1)+abs(sum(C)-c)+10*(len(C)-1))
    
print(min(ans))


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

int main(){
    long long int n;
    long long int  d;
    cin>> n>>d;
    long long int x,y;
    long long int count = 0;

    for(long long int i=0; i<n; i++){
        cin >> x >> y;

        if((sqrt((x*x) + (y*y))) <= d)
            count++;
    }
    cout<<count<<endl;

}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(x) cout<<x<<endl
#define Gput(a,b) G[a].push_back(b)
int main() {
  ll n;
  cin>>n;
  vec a(n+1);
  vec b(n);
  loop(i,n+1){
    cin>>a[i];
  }
  ll asum=accumulate(all(a), 0ll);
  loop(i,n){
    cin>>b[i];
  }
  //にゃーっ
  loop(i,n){
    if(a[i]<=b[i]){
      b[i]-=a[i];
      a[i]=0;
      a[i+1]=max(a[i+1]-b[i],0ll);
    }
    else{
      a[i]-=b[i];
    }
  }

 putout(asum-accumulate(all(a), 0ll));
}


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

class score{
public:
	long x, y, z;
	score(long a=0, long b=0, long c=0){ x=a; y=b; z=c; }
	long sum(long a, long b, long c){return (long)a*x+b*y+c*z;}
	score operator+(score l){
		score S(x + l.x, y + l.y, z + l.z);
		return S;
	}
};

int main(){
	int N, M;
	long res = LONG_MIN;
	vector<score> arr;
	vector<long> brr;
	cin >> N >> M;
	arr.resize(N);
	brr.resize(N);
	for(int i=0;i<N;i++)cin >> arr[i].x >> arr[i].y >> arr[i].z;
	for(int t=0;t<8;t++){
		for(int i=0;i<N;i++){
			brr[i] = (1-2*((t/4)%2))*arr[i].x + (1-2*((t/2)%2))*arr[i].y + (1-2*(t%2))*arr[i].z;
		}
		sort(brr.begin(), brr.end(), greater<long>());
		long sum = 0;
		for(int j=0;j<M;j++)sum += brr[j];
		if(res < sum)res = sum;
	}
	cout << res << endl;
	return 0;
}


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

int main(){
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    
    sort(s.begin(),s.end());
    rep(i,n) cout << s[i];
    return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int n, k;
  cin >> n >> k;
  double ans = 0;
  rep1 (s, n) {
    double add = 1;
    int x = s;
    while (x < k) {
      x *= 2;
      add /= 2.;
    }
    ans += add;
  }
  ans /= n;
  Sp(ans);
}


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

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

    int ans = 0;

    for(int i=1; i<=K; i++){
        for(int j=1; j<=K; j++){
            for(int k=1; k<=K; k++){

                int gcd_ij = __gcd(i,j);
                ans += __gcd(gcd_ij,k);

            }
        }
    }
    cout << ans << endl;    
}

Measured memory_bytes: 3620
from collections import defaultdict


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    for ai in a:
        dict[ai] += 1


N = int(input())
dict = defaultdict(int)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    for ai in a:
        dict[ai] += 1


for i in range(1, N + 1):
    prime_factorize(i)

ans = 0

# p**4 * q**4 * r**2
for k1, v1 in dict.items():
    for k2, v2 in dict.items():
        for k3, v3 in dict.items():
            if k1 < k2 < k3:
                if v1 >= 2 and v2 >= 4 and v3 >= 4:
                    ans += 1
                if v1 >= 4 and v2 >= 2 and v3 >= 4:
                    ans += 1
                if v1 >= 4 and v2 >= 4 and v3 >= 2:
                    ans += 1

# p**14 * q**4
# p**24 * q*2
for k1, v1 in dict.items():
    for k2, v2 in dict.items():
        if k1 < k2:
            if v1 >= 14 and v2 >= 4:
                ans += 1
            if v1 >= 4 and v2 >= 14:
                ans += 1
            if v1 >= 24 and v2 >= 2:
                ans += 1
            if v1 >= 2 and v2 >= 24:
                ans += 1

# p**74
for k1, v1 in dict.items():
    if v1 >= 74:
        ans += 1

print(ans)


Measured memory_bytes: 73696
#include<iostream>
using namespace std;
#define fr(i,n) for(i=0;i++<n;)

int main(){
  int i,n,m,a;int c[100010]={};
  cin>>n>>m;
  fr(i,n){
    //cout<<c[i]<<endl;
  }
  fr(i,2*m){cin>>a;c[a]++;c[a]%=2;}
  fr(i,n){
    if(c[i]&1){
      cout<<"NO"<<endl;
      return 0;
    }
    //cout<<c[i]<<endl;
  }
  cout<<"YES"<<endl;
}


Measured memory_bytes: 640
<?php

    $n = trim(fgets(STDIN));
    $ary = [];
    
    for($i = 0;$i < $n;$i++) {
        $data = fgetcsv(STDIN,1024," ");
        $op = $data[0];
        $x = 0;
        if(count($data) > 1) {
            $x = $data[1];
        }
        
        switch($op) {
            case 0 :
                $ary[] = $x;
                break;
            case 1 :
                echo $ary[$x] . "\n";
                break;
            case 2 :
                array_pop($ary);
                break;
            default :
                break;
        }
    }


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

int main() {
  int a,b,h,m;cin>>a>>b>>h>>m;
  double pai=acos(-1);
  double hh=(double)(h*60+m)/720*2*pai;
  double mm=(double)m/60*2*pai;
  double x1=a*cos(hh),y1=a*sin(hh);
  double x2=b*cos(mm),y2=b*sin(mm);
  double dx=x1-x2,dy=y1-y2;
  double ans=sqrt(dx*dx+dy*dy);
  cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 4112
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> bs(n - 1); cin >> bs;
    int ans = bs[0] + bs.back();
    for(int i = 1; i < n - 1; i++){
        ans += min(bs[i], bs[i - 1]);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>
#include <map>
using namespace std;

vector<string> v, t;

int main()
{
   int H, W, K;

   cin >> H >> W >> K;

   v.resize(H);

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

   int ans = 0;
   for (int i = 0; i < (1 << H); i++)
   {
      
      for (int k = 0; k < (1 << W); k++)
      {
         t = v;
         for (int x = 0; x < H; x++)
         {
            for (int y = 0; y < W; y++)
            {
               if (((1 << x) & i) || ((1 << y) & k))
               {
                  t[x][y] = 'R';
               }
            }
         }

         int cnt = 0;
         for (int x = 0; x < H; x++)
         {
            for (int y = 0; y < W; y++)
            {
               if (t[x][y] == '#')
               {
                  cnt++;
               }
            }
         }

         /*
         for (int i = 0; i < H; i++)
         {
            cout << t[i] << "\n";
         }

         cout << cnt << "\n";
         */

         if (cnt == K)
         {
            ans++;
         }
      }
   }

   cout << ans;


   return 0;
}

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

using namespace std;

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

    char tmp = S[0];
    for(int i = 1; i < 4; ++i){
        if(tmp == S[i]){
            cout << "Bad" << endl;
            return 0;
        }
        tmp = S[i];
    }
    cout << "Good" << endl;

    return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int result;
  if(a * c <= b)
    result = c;
  else
    result = b / a;
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
W,E = 0,S.count("E")
ans,SUM = 0,10**10
for i in range(N):
    s = S[i]
    if s=="W":
        if SUM>W+E:
            SUM = W+E
            ans = i
        W+=1
    else:
        E -= 1
        if SUM>W+E:
            SUM = W+E
            ans = i
print(SUM)

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
int N,A,B;long H[size];
bool judge(long k){
	long d=A-B,sum=0;
	rep(i,0,N){
        if(H[i]>B*k) sum+=(H[i]-B*k+d-1)/d;
    }//cout<<k<<" "<<sum<<endl;
	return sum<=k;
}
int main(){
	cin>>N>>A>>B;
	rep(i,0,N) cin>>H[i];
	long a=0,b=1e9;
	while(b-a>1){
		if(!judge((a+b)/2)) a=(a+b)/2;
		else b=(a+b)/2;
	}cout<<b<<endl;
}

Measured memory_bytes: 1024
from sys import exit
import queue
dxy = [[1,0],[-1,0],[0,1],[0,-1]]
INF = (1 << 21)
H,W = [int(n) for n in input().split()]
ans = 0
Map = [[0 for _ in range(W)] for __ in range(H)]
D = [[INF for _ in range(W)] for __ in range(H)]
for h in range(H):
    Map[h] = list(input())
    ans+=Map[h].count(".")
# print(Map)
# print(ans)

def bfs(s):
    q = queue.Queue()
    q.put(s)
    D[s[0]][s[1]] = 1
    while(not q.empty()):
        u = q.get()
        for d in dxy:
            v = [u[0] + d[0], u[1] + d[1]]
            if (v[0] < 0 or v[1] < 0 or v[0] >= H or v[1] >= W or Map[v[0]][v[1]] == "#"):continue
            if (D[v[0]][v[1]] != INF):continue
            D[v[0]][v[1]] = D[u[0]][u[1]] + 1
            q.put(v)
bfs([0,0])
# for th in range(H):
#     print(D[th])
print(ans - D[H-1][W-1]  if D[H-1][W-1] != INF else -1)


Measured memory_bytes: 3952
// package app;

import java.util.Arrays;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String x = sc.next();
        // final String y = sc.next();

        final String s1 = sc.next();
        final String s2 = sc.next();
        final String s3 = sc.next();
        // final int N = sc.nextInt();
        // final int D = sc.nextInt();
        // System.out.println();

        StringBuffer result = new StringBuffer().append(s1.charAt(0)).append(s2.charAt(0)).append(s3.charAt(0));

        System.out.println(result.toString().toUpperCase());

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll f(ll b,ll n){
    if(n<b) return n;
    else return f(b,(n/b)) + (n % b);
}

// sq(n) <= sqrt(n)
ll sq(ll n){
    for(ll i=1;i<n;i++){
        if(i*i>n) return i-1;
    }
    return -1;
}

int main(){
    ll n,s;
    cin >> n >> s;


    ll sqn = sq(n);

    if(n < 1000000){
        for(int i=2;i<=n;i++){
            if(f(i,n)==s){
                cout << i << endl;
                return 0;
            }
        }
    }

    for(ll i=2;i<=sqn;i++){
        if(f(i,n)==s){
            cerr <<"shigure" << endl;
            cout << i << endl;
            return 0;
        }
    }

    if(n < s){
        cout << -1 << endl;
        return 0;
    }

    ll sqns = sq(n-s);
    for(ll x=sqns;x>0;x--){
        if((n-s)%x) continue;
        ll b = (n-s)/x + 1;
        ll y = s-x;
        if(b<2) continue;
        if(b > sqn and x < b and y>=0 and y<b){
            cerr << "yuudachi" << endl;
            cout << b << endl;
            return 0;
        }
    }

    if(s == n){
        cout << n+1 << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {    
    
    public static void main(String[] args){
       
        Scanner sc = new Scanner(System.in);       
      
        long x = sc.nextLong();        
        
        long ans = x/11;
        
        ans += ans;
        
        if(x%11 > 6){
            ans += 2;
        }else if(x%11 > 0){
            ans++;
        }
        
        System.out.println(ans);
          
    }      
}
        

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
typedef pair<int, int> P;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
void solve()
{
	int W, H;
	while(cin >> W >> H, W || H)
	{
		vector< vector<char> > field(H);
		for(int i = 0; i < field.size(); ++i)
		{
			field[i].resize(W);
		}
		queue<P> Que;
		for(int i = 0; i < field.size(); ++i)
		{
			for(int j = 0; j < field[i].size(); ++j)
			{
				cin >> field[i][j];
				if(field[i][j] == '@')
				{
					P p;
					p.first = j;
					p.second = i;
					Que.push(p);
					field[i][j] = '#';
				}
			}
		}
		int count = 1;
		while(!Que.empty())
		{
			P p = Que.front();
			Que.pop();
			for(int i = 0; i < 4; ++i)
			{
				P np;
				np.first = p.first + dx[i];
				np.second = p.second + dy[i];
				if((0 <= np.first && np.first < W) && (0 <= np.second && np.second < H) && field[np.second][np.first] == '.')
				{
					Que.push(np);
					field[np.second][np.first] = '#';
					++count;
				}	
			}
		}
		cout << count << endl;
	}
}

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

Measured memory_bytes: 1220
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

//abbreviations
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vb vector<bool>
#define vvi vector<vector<int>>

using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    char c;
    cin >>c;
    cout << ++c << endl;

    return 0;
}

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

using namespace std;


const int MAX = 1e4 + 9;
int arr[MAX];
set <int> ans;

int gcd(int a, int b) {
	return (!b) ? a : gcd(b, a % b);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for (int i = n; i >= 0; i--) {
		cin >> arr[i];
	}
	if (arr[n] < 0) {
		for (int i = 0; i < n + 1; i++) {
			arr[i] = -arr[i];
		}
	}
	int g = arr[0];
	for (int i = 1; i < n + 1; i++) {
		g = gcd(g, abs(arr[i]));
	}
	for (int i = 1; i * i <= g; i++) {
		if (g % i == 0) {
			bool p1 = true, p2 = true;
			for (int j = 2; j * j <= i; j++) {
				if (i % j == 0) {
					p1 = false;
					break;
				}
			}
			for (int j = 2; j * j <= g / i; j++) {
				if ((g / i) % j == 0) {
					p2 = false;
					break;
				}
			}
			if (p1) {
				ans.insert(i);
			}
			if (p2) {
				ans.insert(g / i);
			}
		}
	}
	for (int i = 0; i < n + 1; i++) {
		arr[i] /= g;
	}
	for (int i = 2; i < n + 1; i++) {
		bool prime = true;
		for (int j = 2; j * j <= i; j++) {
			if (i % j == 0) {
				prime = false;
				break;
			}
		}
		if (!prime) {
			continue;
		}
		int tmp[MAX];
		for (int j = 0; j < n + 1; j++) {
			tmp[j] = arr[j];
		}
		for (int j = n; j >= i; j--) {
			tmp[j - i + 1] += tmp[j];
			tmp[j] = 0;
		}
		bool ok = true;
		for (int j = 0; j < n + 1; j++) {
			if (tmp[j] % i != 0) {
				ok = false;
				break;
			}
		}
		if (ok) {
			ans.insert(i);
		}
	}
	ans.erase(ans.find(1));
	for (auto a : ans) {
		cout << a << '\n';
	}
	return 0;
}

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

Measured memory_bytes: 600
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a + b>=c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a,b,ab,x,y,ans=0;
	cin>>a>>b>>ab>>x>>y;
	if(a+b<2*ab){
		ans=a*x+b*y;
	}else{
		int Min=min(x,y);
		int Max=max(x,y);
		if(x<y){
			ans+=b*(y-x);
		}else{
			ans+=a*(x-y);
		}
		ans+=Min*2*ab;
		ans=min(ans,Max*2*ab);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int max_n = 1e5 + 10;
int n, m;
vector<int> g[max_n];
int d[max_n];
 
int dfs(int x){
	if(d[x] > 0) return d[x];
	int mx = 0;
	rep(i, g[x].size()){
		mx = max(mx, dfs(g[x][i]) + 1);
	}
 
	d[x] = mx;
	return mx;
}
 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	cin >> n >> m;
	rep(i, m){
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		g[x].push_back(y);
	}
 
	rep(i, n) d[i] = 0;
 
	int ans = 0;
	rep(i, n){
		if(d[i] == 0) ans = max(ans, dfs(i));
	}
 
	cout << ans << endl;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
	ll n;
	cin>>n;
	vl a(n);
	forr(i, n)
	{
		cin>>a[i];
	}
	ll s=1000;
	for(ll i=0; i<n-1; i++)
	{
		if(a[i+1]<=a[i])
			continue;
		else
		{
			//cout<<i<<endl;
			ll num=s/a[i];
			s=s-num*a[i];
			//cout<<num<<' ';
			ll j=i+1;
			while(j<n&&a[j]>=a[j-1])
			{
				j++;
			}
			if(j==n)
			{
				s+=num*(a[n-1]);
			}
			else
			{
				s+=num*(a[j-1]);
			}
			i=j-1;
		}
	}
	cout<<s<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3840
object Main{
  def main(args: Array[String]) : Unit = {
    System.err.println("ok")
    val sc = new java.util.Scanner(System.in)
    val n,k = sc.nextInt
    val h : Array[Int] = 0 +: (1 to n).toArray.map{_ => sc.nextInt } 

    val dp = new Array[Int](n + 1)
    dp(n) = 0
    dp(n-1) = (h(n-1) - h(n)).abs
    (n-2 to 1 by -1).foreach{ x => 
      dp(x) = (1 to k).map { jump =>
        if(x + jump > n) {
          10000000
        } else {
          (h(x) - h(x + jump)).abs + dp(x+jump)
        }
      }.min
    }
    println(dp(1))
  }
}



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

int main() {
  string S;
  cin >> S;
  int w;
  cin >> w;
  for(int i = 0; i < S.size(); i++) {
    if(i%w == 0) {
      cout << S.at(i);
    }
  }
}


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

int main(){
    int n;
    cin >> n;
    std::vector<long int> a(3*n);
    for(int i=0; i<3*n; i++) cin >> a[i];
    
    std::sort(a.begin(), a.end());
    long int ans = 0;
    for(int i=n; i<3*n; i+=2) ans += a[i];

    std::cout << ans << std::endl;

    return 0;
}

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

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = MAP()
A = LIST()

modA = [a%M for a in A]
modC = Counter(modA)

li = [Counter() for i in range(M)]
for a in A:
    li[a%M][a] += 1
for i in range(M):
    li[i] = li[i].most_common()
for i in range(M):
    tmp = []
    for j in range(len(li[i])):
        x, cnt = li[i][j]
        if cnt % 2 == 1:
            tmp.append((x, 1))
            li[i][j] = (x, cnt-1)
    li[i] += tmp

def sub(x, cnt):
    while li[x] and cnt - li[x][-1][1] >= 0:
        cnt -= li[x][-1][1]
        li[x].pop()
    if li[x]:
        li[x][-1] = (li[x][-1][0], li[x][-1][1] - cnt)

ans = 0
pcnt = modC[0] // 2
sub(0, pcnt*2)
ans += pcnt
if M % 2 == 0:
    pcnt = modC[M//2] // 2
    sub(M//2, pcnt*2)
    ans += pcnt

for i in range(1, ceil(M, 2)):
    j = M - i
    pcnt = min(modC[i], modC[j])
    sub(i, pcnt)
    sub(j, pcnt)
    ans += pcnt

for i in range(M):
    for _, cnt in li[i]:
        ans += cnt // 2
print(ans)


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

int main() {
  int m, f, b;
  cin >> m >> f >> b;
  if (m + f < b) {
    cout << "NA" << endl;
  } else {
    cout << (m > b ? 0 : b - m) << endl;
  }
  return 0;
}



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

using namespace std;
using ll = long long;


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

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

Measured memory_bytes: 640
#include <iostream>
using namespace std;

int main()
{
    int a, b, c, d, e, k;

    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> k;

    if( e - a > k ){
        cout << ":(" << endl;
    }
    else{
        cout << "Yay!" << endl;
    }
}


Measured memory_bytes: 256
n,x,m=map(int,input().split())

def f(ai,m):
    return (ai*ai)%m

if x==0:
    print(0)
elif x==1:
    print(n)
elif m==1:
    print(0)
elif n<=m*2:
    asum=x
    ai=x
    for i in range(1,n):
        ai=f(ai,m)
        asum+=ai
    print(asum)   
else:
    aa=[]
    ai,icnt,asum=x,0,0
    while not ai in aa:
        asum+=ai
        aa.append(ai)
        ai=f(ai,m)
        icnt+=1
    ai0,icnt0,asum0=x,0,0
    if ai!=x:
        for i in range(icnt+1):
            asum0+=ai0
            ai0=f(ai0,m)
            icnt0+=1
            if ai0==ai:
                break
    icntk=icnt-icnt0
#    print("1:",ai,asum,icnt,ai0,asum0,icnt0)
    n0=n-1-icnt0
    nk=n0//icntk
    nr=n0%icntk
    asumk=asum-asum0
    air,asumr=ai,0
    for i in range(nr):
        asumr+=air
        air=f(air,m)
    asumr+=air
       
    ans=asum0+asumk*nk+asumr    
    print(ans)       


Measured memory_bytes: 68840
import java.io.*;

public class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String line;
			while ((line = reader.readLine()) != null) {
				if (line.equals("0"))
					break;
				int sum = 0;
				for (int i = 0; i < line.length(); i++) {
					sum += line.charAt(i) - '0';
				}
				System.out.println(sum);
			}
		} catch (IOException e) {
		}
	}
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> py(M), py2(M);
    map<pair<int, int>, string> ma;
    for(int i = 0; i < M; ++i) {
        int p, y;
        cin >> p >> y;
        py[i] = make_pair(p, y);
        py2[i] = make_pair(p, y);
    }
    sort(py.begin(), py.end());
    int num = 1;
    for(int i = 0; i < M; ++i) {
        int p = py[i].first, y = py[i].second;
        string s;
        for(int j = 0; j < 5 - log10(p); ++j)
            s.push_back('0');
        s += to_string(p);
        for(int j = 0; j < 5 - log10(num); ++j)
            s.push_back('0');
        s += to_string(num);
        ma.insert(make_pair(make_pair(p, y), s));
        if(i < M - 1 && py[i].first != py[i + 1].first)
            num = 1;
        else
            num++;
    }
    for(int i = 0; i < M; ++i)
        cout << ma.at(py2[i]) << endl;
    return 0;
}


Measured memory_bytes: 15616
N = int(input())
from collections import Counter
c = Counter()
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            n = x*x + y*y + z*z + x*y + y*z + z*x
            c[n] += 1
for i in range(1,N+1):
    print(c[i])

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    int N;
    vector<int> num = {5, 7, 5, 7, 7};

    while (cin >> N, N) {
        vector<string> S(N);
        rep(i, N) cin >> S[i];

        rep(i, N) {
            int tmp_len = 0;
            int num_idx = 0;
            bool ok = false;
            
            for (int j=i; j<N; j++) {
                if (tmp_len < num[num_idx]) {
                    tmp_len += S[j].size();
                }

                if (tmp_len == num[num_idx]) {
                    num_idx++;
                    tmp_len = 0;
                } else if (tmp_len > num[num_idx]) {
                    break;
                }

                if (num_idx == 5) {
                    ok = true;
                    break;
                }
            }
            if (ok) {
                cout << i+1 << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 3172
use proconio::{input, fastout};

/* editorial.pdf
f(L,R) = |S| - |edge| = (R-L+1) - |edge|
S(L=1~N,S(R=L~N,f(L,R)))
 = S(L=1~N,S(R=L~N,(R-L+1))) - S(L=1~N,S(R=L~N,|edge(L,R)|))
 = S(L=1~N,(N-L+1)*(1-L + (N+L)/2)) - each.edge(l,r){S(L=1~l,S(R=(L|r)~N))}
 = S(L=1~N,(N-L+1)*(2+N-L)/2)       - each.edge(l,r){S(L=1~l,S(R=r~N))}
 = S(L=1~N,(L**2 - (2*N+3)*L + (N+1)*(N+2))/2) - each.edge(l,r){S(L=1~l,N-r+1)}
 = (N*(N+1)*(2*N+1)/6 - (2*N+3)*N*(N+1)/2 + N*(N+1)*(N+2))/2 - each.edge(l,r){l*(N-r+1)}
*/
#[fastout]
fn main() {
    input! {
        n: i64,
    }
    let mut ans: i64 = ((n*(n+1)/2*(2*n+1)/3) - (2*n+3)*n*(n+1)/2 + n*(n+1)*(n+2))/2;
    for _ in 0..(n-1) {
        input! {
            mut u: i64, mut v: i64,
        }
        if u > v {
            let t = u;
            u = v;
            v = t;
        }
        ans -= u * (n-v+1);
    }
    println!("{}", ans);
}


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

#define  ll long long int 


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;cin >> n ; 
  	cout << ( n * ( n - 1 ) )/2 ;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)

int calc(vector<int> v, vector<int> l, int N, int A, int B, int C)
{
  int mp = 0;
  int a = 0;
  int b = 0;
  int c = 0;
  rep(i, N)
  {
    int d = v[i + 1];
    if (d == 0)
    {
      if (a > 0)
        mp += 10;
      int ai = l[i];
      a += ai;
    }
    else if (d == 1)
    {
      if (b > 0)
        mp += 10;
      int bi = l[i];
      b += bi;
    }
    else if (d == 2)
    {
      if (c > 0)
        mp += 10;
      int ci = l[i];
      c += ci;
    }
  }

  if (a == 0 || b == 0 || c == 0)
    return 1000000007;

  mp += abs(A - a);
  mp += abs(B - b);
  mp += abs(C - c);

  return mp;
}

int dfs(int depth, vector<int> v, vector<int> l, int N, int A, int B, int C)
{

  int ans = 1000000000;
  // base case
  if (depth == 0)
  {
    return calc(v, l, N, A, B, C);
  }

  rep(i, 4)
  {
    v[depth] = i;
    int result = dfs(depth - 1, v, l, N, A, B, C);
    ans = min(result, ans);
    // cout << ans << endl;
  }

  return ans;
}

int main()
{

  int N, A, B, C;
  cin >> N >> A >> B >> C;

  vector<int> l(N);
  vector<int> v(N + 1);
  rep(i, N) cin >> l[i];

  cout << dfs(N, v, l, N, A, B, C);
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int a, b;
    cin >> a >> b;
    if((a * b) % 2 == 1){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 764
h,w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
answer = []
count = 0
for i in range (0,h-1):
    for j in range (0,w):
        if (a[i][j] % 2 != 0):
            a[i+1][j] += 1
            count += 1
            answer.append([i+1,j+1,i+2,j+1]) #座標に調整(両座標+1)
for k in range (0,w-1):
    if (a[h-1][k] % 2 != 0):
        a[h-1][k+1] += 1
        count += 1
        answer.append([h,k+1,h,k+2]) #同
print(count)
for l in range (0,len(answer)):
    print(*answer[l])

Measured memory_bytes: 30244
#include <iostream>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <sstream>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

void dfs(int &cnt, ll tmp,int n, bool a, bool b, bool c){
    if(tmp>n)return;

    if(a==true){
        if(b==true){
            if(c==true){
                cnt++;
            }
        }
    }


    dfs(cnt, tmp*10+3, n, true, b, c);
    dfs(cnt, tmp*10+5, n, a, true, c);
    dfs(cnt, tmp*10+7, n, a, b, true);
}


int main() {
    int n;cin>>n;
    ll tmp=0;
    int cnt=0;
    bool a=false,b=false,c=false;
    dfs(cnt, tmp, n, a, b, c);

    cout<<cnt<<endl;

    return 0;
}

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

int main() {

   long int N;
   cin >> N;
   long int num = 1;
   long long int a = 2;
   long long int b = 1;
   long long int c = 1;
   while(num < N) {

      
      num++;
      c = a + b;
      a = b;
      b = c;
      
   }

   cout << c << endl;
 return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
const long long mod = 1000000007;
//const long long mod = 998244353;
int shortest(char**S, int H, int W, int x1, int  y1, int  x2, int  y2) {
	static auto c = new int*[H] {};
	if (c[0] == NULL) {
		for (int i = 0; i < H; i++)c[i] = new int[W];
	}
	if (S[x1][y1] == '#' || S[x2][y2] == '#')return -1;
	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++)c[i][j] = 1000000;
	std::vector<std::pair<int, int>> q;
	q.push_back(std::pair<int, int>{x1, y1});
	c[x1][y1] = 0;
	for (int i = 0; i < q.size(); i++) {
		int x = q[i].first;
		int y = q[i].second;
		int xd = x + 1;
		int yd = y;
		if ((xd >= 0) && (xd < H) && (yd >= 0) && (yd < W) && S[xd][yd] == '.' && (c[xd][yd] > c[x][y] + 1)) {
			c[xd][yd] = c[x][y] + 1;
			q.push_back(std::pair<int, int>{xd, yd});
		}
		xd = x;
		yd = y + 1;
		if ((xd >= 0) && (xd < H) && (yd >= 0) && (yd < W) && S[xd][yd] == '.' && (c[xd][yd] > c[x][y] + 1)) {
			c[xd][yd] = c[x][y] + 1;
			q.push_back(std::pair<int, int>{xd, yd});
		}
		xd = x - 1;
		yd = y;
		if ((xd >= 0) && (xd < H) && (yd >= 0) && (yd < W) && S[xd][yd] == '.' && (c[xd][yd] > c[x][y] + 1)) {
			c[xd][yd] = c[x][y] + 1;
			q.push_back(std::pair<int, int>{xd, yd});
		}
		xd = x;
		yd = y - 1;
		if ((xd >= 0) && (xd < H) && (yd >= 0) && (yd < W) && S[xd][yd] == '.' && (c[xd][yd] > c[x][y] + 1)) {
			c[xd][yd] = c[x][y] + 1;
			q.push_back(std::pair<int, int>{xd, yd});
		}
	}
	return c[x2][y2];
}
int main() {
	int H, W;
	scanf("%d %d", &H, &W);
	auto S = new char*[H];
	for (int i = 0; i < H; i++)S[i] = new char[W + 1];
	for (int i = 0; i < H; i++)scanf("%s", S[i]);
	int max = 0;
	for (int i = 0; i < H*W; i++) {
		for (int j = i + 1; j < H*W; j++) {
			int c = shortest(S, H, W, i / W, i%W, j / W, j%W);
			//printf("%d %d %d %d %d\n", i / W, i%W, j / W, j%W, c);
			max = c > max ? c : max;
		}
	}
	printf("%d", max);
	return 0;
}

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

using namespace std;

int n;
int a[100];

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

  int min_cost = INT_MAX;
  for (int t = -100; t <= 100; t++) {
    int cost = 0;
    for (int i = 0; i < n; i++) {
      cost += (a[i] - t) * (a[i] - t);
    }
    min_cost = min(min_cost, cost);
  }
  cout << min_cost << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define pai 3.141592653589793238462643383279




int main(){
  string S; cin >> S; int N = S.size();
  if(S[0]=='0'){
    cout << -1 << endl; return 0;
  }
  if(S[N-1]=='1'){
    cout << -1 << endl; return 0;
  }
  rep(i, N-1){
    if(S[i]!=S[N-2-i]){
      cout << -1 << endl; return 0;
    }
  }
  vector<int> ichi;
  rep(i, N){
    if(S[i]=='1') ichi.push_back(i+1);
  }
  rep(i, ichi.size()){
    if(i==0) continue;
    for(int j=ichi[i-1]; j<ichi[i]; j++){
      cout << j << " " << ichi[i] << endl;
    }
  }
  cout << N-1 << " " << N << endl;
}


Measured memory_bytes: 4004