akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int H , W;
  cin >> H >> W;
  
  vector<vector<char>> grid(H, vector<char>(W));
  
  for(int i = 0; i < H; i++) {
    for(int k = 0; k < W; k++) {
      cin >> grid.at(i).at(k);
    }
  }
  
  for(int i = 0; i < H; i++) {
    for(int k = 0; k < W; k++) {
      if(grid.at(i).at(k) == '#') {
        break;
      }
      if(k == W - 1) {
        for(int x = 0; x < W; x++){
          grid.at(i).at(x) = 'x'; //横削除マーク
        }
      }
    }
  }
  for(int k = 0; k < W; k++) {
    for(int i = 0; i < H; i++) {
      if(grid.at(i).at(k) == '#') {
        break;
      }
      if(i == H - 1) {
        for(int x = 0; x < H; x++){
          grid.at(x).at(k) = 'x'; //縦削除マーク
        }
      }
    }
  }
  
  for(int i = 0; i < H; i++) {
    for(int k = 0; k < W; k++) {
      if(grid.at(i).at(k) == 'x') {
        if(k == W - 1) {
          for(int m = 0; m < W ; m++) {
            if(grid.at(i).at(m) == '#'){
              cout << endl;
              break;
            }
          }
        }
        continue;
      }
      else {
        cout << grid.at(i).at(k);
      }
      if(k == W - 1) {
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 256
N, M = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp

D = []
s = s[0, s.length - 1]
while(s.length > 0) do
  tmp = D.size
  M.downto(1){|i|
    if i <= s.length && s[-i] == "0" then
      D.push(i)
      s = s[0, s.length - i]
      break
    end
  }
  break if tmp == D.size
end

if s.length == 0 then
  (D.size - 1).downto(0){|i| printf("#{D[i]} ")}
  printf("\n")
else
  puts -1
end


Measured memory_bytes: 95920
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    //Seiranchan!
    string S;
    cin >> S;

    int size = S.size();

    for(int i=0;i<size;i+=2){
        cout << S[i];
    }
    cout <<endl;
}


Measured memory_bytes: 512
const fs = require("fs");

function Main(input){
    input = input.split(" ");
    const a = parseInt(input[0]);
    const b = parseInt(input[1]);
    const N = b - a;
    var x = N*(N-1)/2 - a;
    console.log(x);
}

Main(fs.readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int main() {
    #ifdef LOCAL
    assert(freopen("a.in", "r", stdin));
    #else
    #endif
    string t;
    cin >> t;
    string s = "CODEFESTIVAL2016";
    int res = 0;
    forn (i, sz(t)) {
        if (t[i] != s[i])
            ++res;
    }
    cout << res << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s[100];
	int N;
	bool flg = true;

	cin >> N;

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

	for (int i = 1; i < N; i++)
	{
		//cout << s[i][0] << " " << *(s[i-1].end() - 1) << endl;
		if (s[i][0] != *(s[i-1].end()-1)) {
			flg = false;
		}
	}

	sort(s, s + N);

	for (int i = 1; i < N; i++)
	{
		if (s[i] == s[i - 1]) {
			flg = false;
		}
	}

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

	return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define llINF ((long long)1e18)
#define INF ((int)1e9);
#define ALL(obj) obj.begin(), obj.end()

using namespace std;

template <typename Monoid>
struct SegmentTree {
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func F;
    const Monoid E;

    int SIZE = 1;
    vector<Monoid> node;

    SegmentTree(int n, const Func f, const Monoid &e) : F(f), E(e) {
        while (SIZE < n) SIZE *= 2;
        node.assign(SIZE * 2, E);
    }

    void set(int a, const Monoid &val) { node[a + SIZE] = val; }

    void build() {
        for (int k = SIZE - 1; k > 0; k--) {
            node[k] = F(node[2 * k], node[k * 2 + 1]);
        }
    }

    void update(int a, const Monoid &val) {
        int k = a + SIZE;
        node[k] = val;
        while (k >>= 1) node[k] = F(node[2 * k], node[2 * k + 1]);
    }

    Monoid query(int a, int b) {
        Monoid leftVal = E, rightVal = E;
        for (int left = a + SIZE, right = b + SIZE; left < right;
             left >>= 1, right >>= 1) {
            if (left & 1) leftVal = F(leftVal, node[left]), left += 1;
            if (right & 1) right -= 1, rightVal = F(rightVal, node[right]);
        }
        return F(leftVal, rightVal);
    }

    inline Monoid operator[](int a) { return node[a + SIZE]; }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    SegmentTree<long long> seg(
        N, [](long long a, long long b) { return min(a, b); }, (1ll << 31) - 1);
    seg.build();

    for (int i = 0; i < Q; i++) {
        int com;
        cin >> com;
        if (com == 0) {
            int i;
            long long x;
            cin >> i >> x;
            seg.update(i, x);
        } else {
            int s, t;
            cin >> s >> t;
            cout << seg.query(s, t + 1) << endl;
        }
    }
}


Measured memory_bytes: 4888
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii> 
using vec = vector<T>;

const ll INF = 1e18, MOD = 1e9 + 7;

const int MAX = 1e6;


ll powm(ll a, ll n = MOD - 2) {
    ll res = 1;
    for (; n; a = (a * a) % MOD, n >>= 1)
        if (n & 1)
            res = (res * a) % MOD;
    return res;
}

ll ft[MAX + 1], fti[MAX + 1];

void cf() {
    ft[0] = fti[0] = 1;
    for (int i = 1; i <= MAX; i++) {
        ft[i] = (i * ft[i - 1]) % MOD;
    }
    fti[MAX] = powm(ft[MAX]);
    for (int i = MAX - 1; i; i--) {
        fti[i] = ((i + 1) * fti[i + 1]) % MOD;
    }
}

ll nCr(ll n, ll r) {
    if (n < r) return 0;
    ll res = (ft[n] * fti[n - r]) % MOD;
    (res *= fti[r]) %= MOD;
    return res;
}


int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);

    cf();    
    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    (a *= powm(100 - c)) %= MOD;
    (b *= powm(100 - c)) %= MOD;
    (c *= powm(100)) %= MOD;
    
    c = (1 + MOD - c) % MOD;
    c = powm(c);
    // (c *= c) %= MOD;
    // ll ea = (a * c) % MOD,
    //    eb = (b * c) % MOD;

    ll res = 0;
    for (ll m = n; m < 2 * n; m++) {
        ll x = 0, xa = 0, xb = 0, y = 1;
        (xa += (powm(a, n) * powm(b, m - n)) % MOD) %= MOD;
        // (xa += (n * ea + (m - n) * eb) % MOD) % MOD;
        // (xa = powm(a, m) * m) %= MOD;

        (xb += (powm(a, m - n) * powm(b, n)) % MOD) %= MOD;
        // (xb += (n * eb + (m - n) * ea) % MOD) % MOD;
        // (xb = powm(b, m) * m) %= MOD;


        x = (xa + xb) % MOD;
        (x *= nCr(m - 1, n - 1)) %= MOD;

        y = (m * c) % MOD;

        (res += (x * y) % MOD) %= MOD;
    }
    cout << res << '\n';
}

Measured memory_bytes: 15872
#!/bin/bash
read mount_num
read mount_height
ary=(`echo $mount_height`)


max_height=0
mount_num_cansea=0
for i in `seq 1 ${#ary[@]}`
do
 target=${ary[$i-1]}
 if [ $target -ge $max_height ]; then
  max_height=$target
  (( mount_num_cansea++ ))
 fi
done

echo $mount_num_cansea

Measured memory_bytes: 528
#include <stdio.h>

#define MAX 100

int main()
{

	int Q, tc, ta, tn;
	int c[MAX], a[MAX], n[MAX], team;

	scanf( "%d", &Q );
	for( int i = 0; i < Q; i++ ) {

		scanf( "%d %d %d", &c[i], &a[i], &n[i] );

	}

	for( int i = 0; i < Q; i++ ) {

		tc = c[i]; ta = a[i] ; tn = n[i]; team = 0;

		while( tc > 0 && ta > 0 && tn > 0 ) {

			tc--;
			ta--;
			tn--;
			team++;

		}

		while( tc > 1 && ta > 0 ) {

			tc -= 2;
			ta--;
			team++;

		}

		while( tc > 2 ) {

			tc -= 3;
			team++;

		};

		printf( "%d\n", team );

	}

	return 0;

}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
int main(){
    vector<int> a(5); rep(i,5) cin >> a[i];
    vector<int> b(5); rep(i,5){ if(a[i]%10==0) b[i] = 0; else b[i]=(10-(a[i]%10));}
    cout << accumulate(a.begin(), a.end(), 0) + accumulate(b.begin(), b.end(), 0) - b[maxi(b)];
    //cout << accumulate(b.begin(), b.end(), 0) << " " << b[maxi(b)] << endl;
    //rep(i,5) cout << b[i] << endl;
    

     
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 9999999999999999
#define F first
#define S second
#define eb emplace_back
#define mpp make_pair
#define P(x) cout<<__LINE__ <<": "<<#x<<' '<<(x)<<'\n'
#define dbg cout<<__LINE__ <<": 0manush\n"
#define read(x) freopen("input.txt","r",stdin)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pi 2*acos(0.0)
#define ee exp(1)
#define mx 100009
#define mod 10000007
using namespace std;
int main(){//read(x);
//fast;
ll r,g,h,i,j,x,y,t,e,a,b,c,d,n,l,k;

    cin>>n;
    ll m[n+5][3],dp[n+55][3];
    for(i=0;i<n;i++)
        for(j=0;j<3;j++)
            cin>>m[i][j];

    dp[n][0]=dp[n][1]=dp[n][2]=0;
    l=0;
    for(i=n-1;i>=0;i--){
        dp[i][0]=max(m[i][1]+dp[i+1][1],m[i][2]+dp[i+1][2]);
        dp[i][1]=max(m[i][0]+dp[i+1][0],m[i][2]+dp[i+1][2]);
        dp[i][2]=max(m[i][1]+dp[i+1][1],m[i][0]+dp[i+1][0]);
    }
    //cout<<dp[0][0]<<' '<<dp[0][1]<<' '<<dp[0][2]<<endl;
    l=max(dp[0][0],max(dp[0][1],dp[0][2]));
    cout<<l<<endl;
}





















Measured memory_bytes: 8280
s = str(input())
moji = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
isOK = True
if s[0]=='A':
    tmp = s[2:-1]
    cnt = 0
    for i in range(len(tmp)):
        if tmp[i]=='C':
            cnt += 1
    if cnt!=1:
        isOK = False
else:
    isOK = False

cnt = 2
for i in range(len(s)):
    if s[i] in moji:
        cnt += 1
if len(s)!=cnt:
    isOK = False

if isOK:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 8976
#include<bits/stdc++.h>
char s[50],a[9]={6,8,6,8,8};
main(){for(int i,j,p,n,q;scanf("%d\n",&n),n;){for(i=0;i<n;s[i++]=strlen(gets(s+i)));
for(i=j=0;j<6;)for(p=i++,j=q=0;q>=0;)for(q=a[j++]-1;q>0;q-=s[p++]);
printf("%d\n",i);
}}

Measured memory_bytes: 1200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC086A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b,c;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = a * b;
            if (c%2==0)
                Console.WriteLine("Even");
            else
                Console.WriteLine("Odd");
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
from sys import stdin
import math


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    K = int(_in[0])  # type:int
    A,B = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    TF = 'OK' if math.ceil(A/K)<=math.floor(B/K) else 'NG'
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(TF)


Measured memory_bytes: 62172
class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size
    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)
    def same(self, x, y):
        return (self.find(x) == self.find(y))
 
N, M, *I = map(int, open(0).read().split())
P, XY = I[:N], I[N:]
 
uf = UnionFind(N + 1)
for x, y in zip(*[iter(XY)] * 2):
    uf.union(x, y)
 
ans = 0
for i, p in enumerate(P, 1):
    if uf.same(i, p):
        ans += 1
 
print(ans)

Measured memory_bytes: 43920
#include <iostream>
#include <set>
#include <math.h>
#include <list>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX_N 1005
#define MAX_M 100

long long A[MAX_N];
long long B[MAX_N];
int MOD = 1000000000 + 7;
string S;

int dp[MAX_N][MAX_N];
int lcs(string S, string T)
{
    rep(i, S.length())
    {
        rep(j, T.length())
        {
            if (S[i] == T[j])
            {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }
            else
            {
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }
    return dp[S.length()][T.length()];
}

int main()
{
    rep(i, MAX_N)
    {
        dp[i][0] = 0;
        dp[0][i] = 0;
    }
    int Q;
    cin >> Q;
    string S, T;
    rep(i, Q)
    {
        cin >> S >> T;
        cout << lcs(S, T) << endl;
    }

    return 0;
}



Measured memory_bytes: 7172
#include <iostream>
using namespace std;
int main() {
    int n, ans = 0;
    cin >> n;
    int p[n], min = n + 1;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        if (min > p[i]) {
            min = p[i];
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
//  RAKSHIT KADAM
//ALWAYS USE &IT FOR ITERATING USING AUTO ...
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!

// NUMERIC DEFINITIONS :
    #define INF 2000000000000000005
    #define MOD  1000000007
    #define newMOD  998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
 
 #define ll long long
 #define int long long
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
//ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}
void solve()
{
    ll n;cin>>n;
    ll a[n+4]; map<ll,ll>m;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        m[a[i]+i]++;
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        ans+=m[i-a[i]];
    }
    cout<<ans<<endl;
}
signed main()
{
 
   
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//    }

 solve();
    return 0;
}


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

int main() {
	int x, a, b; cin >> x >> a >> b;
	if (a - b >= 0)cout << "delicious";
	else {
		if (x + (a - b) >= 0)cout << "safe";
		else cout << "dangerous";
	}
	cout << endl;

	return 0;
}

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

using namespace std;

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

    vector<int> l(n);

    for (auto& x : l)
    {
        cin >> x;
    }

    sort(l.rbegin(), l.rend());

    int ans = 0;

    for (int i = 0; i < k; ++i)
    {
        ans += l[i];
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    d=int(input())
    c=list(map(int,input().split()))
    s=[list(map(int,input().split())) for _ in range(d)]
    last=[0]*27
    srate=[]
    ans=[]
    for i in range(1,d+1):
        a=0
        for j in range(1,27):
            a-=c[j-1]*(i-last[j])
        pa=0
        mlast=[0]*2
        for t in range(1,27):
            if s[i-1][t-1]+c[t-1]*(i-last[t])>pa:
                mlast=[t,i]
                pa=s[i-1][t-1]+c[t-1]*(i-last[t])
        a+=pa
        last[mlast[0]]=mlast[1]           
        ans.append(mlast[0])
        srate.append(a)
    for i in ans:
        print(i)
    #for i in srate:
    #    print(i)

if __name__ == '__main__':
    main()

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;


long long GCD(long long a, long long b) {
    return b != 0 ? GCD(b, a % b) : a;
}

int main() {
    ll N, X; cin >> N >> X;
    vll y(N);
    rep(i, N) {
        ll x; cin >> x;
        y[i] = abs(x - X);
    }

    ll D = y[0];
    rep(i, N - 1) {
        D = GCD(D, y[i + 1]);
    }

    cout << D << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100;
const ll mod = 1000000007;
typedef pair<int,int> P;
#define fi first
#define se second
vector<vector<int>> graph; 
#define pb push_back
int main(){
    int n,m;
    cin>>n>>m;
   vector<vector<bool>> path(n,vector<bool>(n)),cp(n,vector<bool>(n,false));
   vector<P> brid(m);
   graph.resize(n);
   for(int i=0;i<m;i++){
       int a,b;
       cin>>a>>b;
       a--;b--;
       brid.at(i)=P(a,b);
       graph.at(a).pb(b);
       graph.at(b).pb(a);
       cp[a][b]=true;
       cp[b][a]=true;
   }
   int ans=0;
for(int i=0;i<m;i++){
    vector<bool> check(n,false);
    path=cp;
    path[brid.at(i).fi][brid.at(i).se]=false;
    path[brid.at(i).se][brid.at(i).fi]=false; 
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int now=q.front();
        q.pop();
        for(int i=0;i<graph.at(now).size();i++){//訪れたところにチェック、残った経路を通って全てに印が付いていれば連結
            if(check[graph.at(now).at(i)])continue;
            if(!path[now][graph.at(now).at(i)])continue;
            check[graph.at(now).at(i)]=true;
            q.push(graph.at(now).at(i));
        }
    }
    for(int i=0;i<n;i++){
        if(!check[i]){
            ans++;
            break;
        }
    }
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
#define MAX 14348907
#define INF  (1e9) 
int ans[ MAX ];
int t[16],n,m;

void make_table(){
  queue<int> Q;
  for(int i=0;i<MAX;i++)ans[i]=INF;
  ans[0]=0;
  Q.push(0);
  while(!Q.empty()){
    int s=Q.front();Q.pop();
    int u[3]={0};
    int a,ns;
    for(int i=14;i>=0;i--){
      a= s/t[i]%3;
      u[a]=max(u[a],i);
    }
    ns=s;
    //0 to 1
    if(u[0]>u[1]){
      ns= s + t[ u[0] ];
      if(ans[ns]==INF){
	ans[ns]=ans[s]+1;
	Q.push(ns);
      }
    }
    //1 to 0
    if(u[1]>u[0]){
      ns= s - t[ u[1] ];
      if(ans[ns]==INF){
	ans[ns]=ans[s]+1;
	Q.push(ns);
      }
    }
    //1 to 2
    if(u[1]>u[2]){
      ns= s + t[ u[1] ];
      if(ans[ns]==INF){
	ans[ns]=ans[s]+1;
	Q.push(ns);
      }
    }
    //2 to 1
    if(u[2]>u[1]){
      ns= s - t[ u[2] ];
      if(ans[ns]==INF){
	ans[ns]=ans[s]+1;
	Q.push(ns);
      }
    }

  }//while
}

void init(){
  t[0]=1;
  for(int i=1;i<=15;i++)t[i]=t[i-1]*3;
}
int main(){
  init();
  make_table();
  int S,S2,a,b;
  while(cin>>n>>m&&n&&m){
    S=S2=0;
    for(int i=0;i<3;i++){
      cin>>a;
      for(int j=0;j<a;j++){
	cin>>b;
	b=b+(14-n);
	S+= t[b]*i;
	S2 += t[b]*(2-i);
      }
    }
    int X = min(ans[S],ans[S2]);
    if(X<=m)cout<<X<<endl;
    else cout<<"-1"<<endl;
    /*
    for(int i=0;i<15;i++){
      cout<<S/t[i]%3<<' ';
    }
    cout<<"  n="<<n<<endl;
    */
  }
  return 0;
}

Measured memory_bytes: 57264
n, k = (int(i) for i in input().split())
list_h = sorted([int(i) for i in input().split()])
if list_h[-1] < k:
    print("0")
    exit()
count = 0
for count in range(0, n):
    if list_h[count] >= k: break
print(len(list_h[count:]))

Measured memory_bytes: 18392
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int n,sum=0,al=0;cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum += a[i];
    }
    sort(a.rbegin(),a.rend());
    for(int i=0;i<n;i+=2){
        al += a[i];
    }
    cout<<al*2-sum<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
double x[10010],y[10010];
double ans;
int n;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x[i]>>y[i];
		if(i!=1) x[i]-=x[1],y[i]-=y[1];
	}
	x[1]=0,y[1]=0;
	for(int i=3;i<=n;i++){
		ans+=x[i-1]*y[i]-x[i]*y[i-1];
	}
	ans/=2;
	printf("%.1lf\n",ans);
	return 0;
}


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

#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;

const int N = 1e2;
int n;
int x[N+2], y[N+2];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    clock_t ck;
    ck = clock();
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
    }
    bool good = 0;
    for (int i = 3; i <= n && !good; i++) {
        if (x[i-2] == y[i-2] && x[i-1] == y[i-1] && x[i] == y[i])
            good = 1;
    }
    cout << (good ? "Yes" : "No") << '\n';
    ck = clock()-ck;
    cerr << "It took " << 1.0*ck/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

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

p=[int(i) for i in input().split()]
p.sort()
p.append(999999)

sco=999999
ans=None
i=-2
now=0
while i<105:
    if abs(i-x)<sco and p[now]!=i:
        sco=abs(i-x)
        ans=i
    i+=1
    if i>p[now]:
        now+=1
print(ans)
    

Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#define eol '\n'
using namespace std;

int gcd(int a, int b) {
  int mx = max(a, b);
  int mn = min(a, b);

  if (mx % mn == 0) {
    return mn;
  } else {
    return gcd(mx % mn, mn);
  }
}

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

  int a, b;
  cin >> a >> b;

  cout << gcd(a, b) << eol;
  
  return 0;
}

Measured memory_bytes: 3176
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  int x, y;// ,z;
  cin >> x >> y;// >> z;
  cout << x * y /2<< endl;
  return 0;
  // cout << fixed;//小数点を確実に10桁で表示するためのもの
  // cout << setprecision(10); 
}


Measured memory_bytes: 3636
#abc 158 d
from collections import deque
x=deque()
flag=True # muki  true: migi false: hidari
s=input()
x.append(s)
q=int(input())
cnt=0
for i in range(q):
    line=list(input().split())
    if len(line)==1:
        cnt+=1
        if cnt%2==1:
            flag=False
        else:
            flag=True
    else:
        t=line[2]
        if line[1]=="1":
            if flag==True:
                x.appendleft(t)
            else:
                x.append(t)
        else:
            if flag==True:
                x.append(t)
            else:
                x.appendleft(t)
ans="".join(x)
if flag==False:
    ans=ans[::-1]
print(ans)


Measured memory_bytes: 6900
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
using namespace std;
int main(){
int n;
cin>>n;
string s[n];
int p[n];
vector<tuple<string,int,int>> vec;
for(int i=0;i<n;i++){
 cin>>s[i]>>p[i];
 vec.push_back(make_tuple(s[i],-p[i],i+1));
}
sort(vec.begin(),vec.end());

for(int i=0;i<n;i++){
 cout<< get<2>(vec[i])<<endl;
}
}


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

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

    a[0]=b[0];a[n-1]=b[n-2];
    for(int i=1;i<n-1;i++){
        a[i]=min(b[i],b[i-1]);
    }

    int ans=0;
    for(int i=0;i<n;i++){
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAXN 1<<17
int a[MAXN], n;
int solve(void) {
    int res = 1;
    int mov = 0;
    for(int i = 0; i < n - 2; i++) {
        if(a[i] == a[i + 1] && a[i + 1] == a[i + 2]) continue;
        else if(a[i] >= a[i + 1] && a[i + 1] >= a[i + 2] && mov != 2) mov = 1;
        else if(a[i] <= a[i + 1] && a[i + 1] <= a[i + 2] && mov != 1) mov = 2;
        else {
            mov = 0;
            res++;
            i++;
        }
    }
    return res;
} 
int main(void) {
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    printf("%d", solve());
    return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int H, W; cin >> H >> W;
	vector<string> S(H); cin >> S;
	vvint sumleft(H+1, vint(W+1, 0));
	vvint sumright(H+1, vint(W+1, 0));
	vvint sumup(H+1, vint(W+1, 0));
	vvint sumdown(H+1, vint(W+1, 0));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			sumleft[i+1][j+1] = (S[i][j] == '.');
			sumup[i+1][j+1] = (S[i][j] == '.');
			sumright[i][j] = (S[i][j] == '.');
			sumdown[i][j] = (S[i][j] == '.');
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '.') {
				sumleft[i+1][j+1] += sumleft[i+1][j];
				sumup[i+1][j+1] += sumup[i][j+1];
			}
		}
	}
		
	for (int i = H-1; i >= 0; i--) {
		for (int j = W-1; j >= 0; j--) {
			if (S[i][j] == '.') {
				sumright[i][j] += sumright[i][j+1];
				sumdown[i][j] += sumdown[i+1][j];
			}
		}
	}

	int maxv = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') continue;
			chmax(maxv, sumleft[i+1][j] + sumright[i][j+1] + sumup[i][j+1] + sumdown[i+1][j]);
		}
	}
	cout << maxv+1 << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 67328
// In the name of God

#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int k, x;
	cin >> k >> x;
	for(int i=x-k+1; i<x+k; i++) cout << i << " ";
	return 0;
}


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

int main() {
  int n,k;
  cin >> n >> k;
  
  int X = 0;
  for(int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if(x > k - x) 
      X += 2 * (k - x);
    
    else
      X += 2 * x;
  }
  cout << X << endl;
}
   

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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

int main(int argc, const char* argv[]) {
	ll n;
	cin >> n;

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

	vector<ll> x(n), y(n);
	rep(i, n) {
		cin >> x[i] >> y[i];
	}

	map<pair<ll, ll>, ll> m;

	rep(i, n - 1) {
		repd(j, i + 1, n) {
			ll p = x[i] - x[j];
			ll q = y[i] - y[j];

			if(p == 0) {
				q = absi(q);
			} else if(p < 0) {
				p = -p;
				q = -q;
			}

			pair<ll, ll> pq = make_pair(p, q);
			auto itr = m.find(pq);

			if(itr == m.end()) {
				m[pq] = 1;
			} else {
				m[pq] += 1;
			}
		}
	}

	ll ret = 0;
	for(auto itr = m.begin(); itr != m.end(); ++itr) {
		if(ret < itr->second) {
			ret = itr->second;
		}
	}


	cout << n - ret << endl;

	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
  int a,b,c,temp;
  scanf("%d %d %d",&a,&b,&c);
//    printf("%d %d %d\n",a,b,c);
  if(a>b){
    temp=a;
    a=b;
    b=temp;
  };
//    printf("%d %d %d\n",a,b,c);
  if(b>c){
    temp=b;
    b=c;
    c=temp;
  };  
//    printf("%d %d %d\n",a,b,c);
  if(a>b){
    temp=a;
    a=b;
    b=temp;
  };
//  printf("%d %d %d\n",a,b,c);
  if(a==5 && b==5 && c==7){
    printf("YES");
  } else {
    printf("NO");
  };
}

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int left = a+b, right = c+d;
  if(left == right){
    cout << "Balanced" << endl;
  }else if(left > right){
    cout << "Left" << endl;
  }else{
    cout << "Right" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
/* global variables */
/* function */
/* main */
int main(){
    int h, w;
    cin >> h >> w;
    string ans = "";
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            string s;
            cin >> s;
            if (s == "snuke") {
                ans += (char) 'A' + (j - 1);
                ans += to_string(i);
            }
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
    
    char S[10+1];
    char T[10+1];
    scanf("%s%s", S, T);

    int A,B;
    scanf("%d%d", &A, &B);

    char U[10+1];
    scanf("%s", U);

    if( strcmp(U,S) == 0 ) A--;
    else if( strcmp(U,T) == 0 ) B--;

    printf("%d %d\n", A, B);

    return 0;
}





Measured memory_bytes: 128
/**
 * @author derrick20
 */
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();
        // Ah Errichto clever clever - just read the p when you're using it!
//        double[] p = new double[N];
//        for (int i = 0; i < p.length; i++) {
//            p[i] = sc.nextDouble();
//        }

        double[] dp = new double[N + 1];
        // dp[i] stores probability to get i heads, N - i tails
        // We implicitly store, with how many coins can we achieve this outcome
        // But really, we just go through all the coins and transition
        // the current heads to the new state, of using 1 more coin.
        dp[0] = 1;
        // A way to think about what's happening to the distribution of coins over time
        // is that, for every probability that's already in the dp array,
        // it is splitting itself and moving into two points:
        // Either it generates a head, which multiplies by p and sends it to the next
        // level, or it generates a tail * (1 - p), and changes the prob of the current
        // head count. Notice that this nets a sum of (p + 1 - p) * dp[heads].
        // However, when getting a tail, we don't add, but rather REPLACE the old
        // value of dp[heads]. So, what's happening is we add (p + 1 - p) * dp[heads],
        // but subtracted the old dp[heads], since that's no longer possible!
        for (int coin = 0; coin < N; coin++) {
            double p = sc.nextDouble();
            for (int heads = N - 1; heads >= 0; heads--) {
                // We must go downwards, because at each position,
                // we must rely on the answer for a smaller problem, then
                // update us!

                // There's a new way to reach the next coin
                dp[heads + 1] += dp[heads] * p;
                // In order to preserve this # heads, it's harder
                dp[heads] *= (1 - p);
            }
        }
        double sum = 0;
        for (int heads = N / 2 + 1; heads <= N; heads++) {
            sum += dp[heads];
        }
        out.println(sum);
        out.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        FastScanner(FileReader s) {
            br = new BufferedReader(s);
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        String nextLine() throws IOException { return br.readLine(); }

        double nextDouble() throws IOException { return Double.parseDouble(next()); }

        int nextInt() throws IOException { return Integer.parseInt(next()); }

        long nextLong() throws IOException { return Long.parseLong(next()); }
    }
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mod 1000000007

ll price[100005];

ll minAns;

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

bool checkZero(vector<ll> p,int m)
{
	for(int i=0;i<m;i++)
	{
		//cout<<p[i]<<" ";
		if(p[i]>0)
			return false;
	}
	//cout<<endl;
	return true;
}
void func(int st,int n,int m,int price_,vector<ll> p,vector<vector<int>> arr)
{
	/*for(int i=0;i<m;i++)
		cout<<p[i]<<" ";
	cout<<endl;*/

	if(checkZero(p,m))
	{
		minAns=min(minAns,price_);
		return;
	}

	if(st==n)
	{
		if(checkZero(p,m))
		{
			minAns=min(minAns,price_);
		}
		return;
	}
	//cout<<"p"<<price_<<endl;
	func(st+1,n,m,price_,p,arr);

	for(int i=0;i<m;i++)
	{
		p[i]-=arr[st][i+1];
	}
	func(st+1,n,m,price_+price[st],p,arr);
}
int main() {

	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

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

	int check[m+5]={0};
	//int price[n+5]={0};

	vector<vector<int>> arr;
	for(int i=0;i<n;i++)
	{
		vector<int> temp;
		for(int j=0;j<=m;j++)
		{
			temp.push_back(0);
		}
		arr.push_back(temp);
	}

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			cin>>arr[i][j];
			if(j==0)
			{
				price[i]=arr[i][j];
			}
			else{
				check[j]+=arr[i][j];
			}
		}
	}

	for(int i=1;i<=m;i++)
	{
		if(check[i]<x)
		{
			cout<<"-1\n";
			return 0;
		}
	}

	vector<ll> p(m+5,0);
	for(int i=0;i<m;i++)
	{
		p[i]=x;
	}

	minAns=INT_MAX;
	func(0,n,m,0,p,arr);
	cout<<minAns<<endl;
    
    return 0;
}

Measured memory_bytes: 3684
#if loc||local
#define _GLIBCXX_DEBUG
#endif

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
constexpr ll dx[]={1,0,-1,0,1,1,-1,-1};
constexpr ll dy[]={0,1,0,-1,1,-1,1,-1};
constexpr ll ddx[] = {2,2,2,2,2,-2,-2,-2,-2,-2,1,0,-1,1,0,-1};
constexpr ll ddy[] = {0,1,2,-1,-2,2,1,0,-1,-2,2,2,2,-2,-2,-2};
using T3 = tuple<ll,ll,ll>;
using T4 = tuple<ll,ll,ll,ll>;
signed main(){

  int h,w;
  cin>>h>>w;
  int ch,cw;
  cin>>ch>>cw;
  int dh,dw;
  cin>>dh>>dw;
  auto s = vec<char>(h,w);
  cin>>s;
  ch--;cw--;dh--;dw--;

  auto dist = vec<ll>(h,w);
  for(auto& di:dist)for(auto& dij:di)dij=INF;
  deque<T3> deq;
  deq.emplace_back(0,ch,cw);
  while(!deq.empty()){
    auto [cost,y,x] = deq.front();
    deq.pop_front();
    if(!chmin(dist[y][x],cost))continue;
    rep(i,4){
      int ny = y+dy[i];
      int nx = x+dx[i];
      if(ny==-1||nx==-1||ny==h||nx==w)continue;
      if(s[ny][nx]=='#')continue;
      //if(dist[ny][nx]!=INF)continue;
      deq.emplace_front(cost,ny,nx);
    }
    rep(j,4){
      int ny = y+dy[j+4];
      int nx = x+dx[j+4];
      if(ny==-1||nx==-1||ny==h||nx==w)continue;
      if(s[ny][nx]=='#')continue;
      //if(dist[ny][nx]!=INF)continue;
      deq.emplace_back(cost+1,ny,nx);
    }
    rep(k,16){
      int ny = y+ddy[k];
      int nx = x+ddx[k];
      if(ny<0||nx<0||ny>=h||nx>=w)continue;
      if(s[ny][nx]=='#')continue;
      //if(dist[ny][nx]!=INF)continue;
      deq.emplace_back(cost+1,ny,nx);
    }
  }
  cout<<(dist[dh][dw]==INF?-1:dist[dh][dw])<<endl;

}


Measured memory_bytes: 14664
<?php
$k=trim(fgets(STDIN));
if($k%2==0 or $k%5==0){
  echo -1;
  exit;
}
$m=7;
$i=1;
while(1){
  $m%=$k;
  if($m==0){
    echo $i;
    exit;
  }elseif(isset($r[$m])){
    echo -1;
    exit;
  }else{
    $r[$m]=1;
  }
  ++$i;
  $m=$m*10+7;
}

Measured memory_bytes: 57980
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
using ll = long long;
using P = pair<int, int>;

const int mod = 1000000007;
struct mint {
  ll x; 
  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;
  }

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

mint f(int n){ 
  if(n == 0)return 1;
  mint x = f(n / 2); 
  x *= x; 
  if(n % 2 == 1)x *= 2;
  return x;
}

map<ll, int> prime_factorize(ll m){
  map<ll, int> ans;
  for(int i = 2; i * i <= m; ++i){
    while(m % i == 0){
      if(ans.count(i) == 0)ans[i] = 1;
      else ++ans[i];
      m /= i;
    }
  }
  if(m != 1)ans[m] = 1; 
  return ans;
}

mint choose(int n, int a){
  mint x = 1, y = 1;
  for(int i = 0; i < a; ++i){
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

int a[10100];

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

  map<ll, int> mp;
  for(int i = 0; i < n; ++i){
  	auto factor = prime_factorize(a[i]);
  	for(auto f : factor){
  		mp[f.first] = max(mp[f.first], f.second);
  	}
  }

  mint x = 1;
  for(auto m : mp){
  	for(int i = 0; i < m.second; ++i){
  		x *= m.first;
  	}
  }

  mint ans = 0;
  for(int i = 0; i < n; ++i){
  	ans += x / (mint)a[i];
  }

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


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


int main() {
	//優先順位付きqueue
	int n, m;
	cin >> n >> m;
	priority_queue<int> q;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		q.push(a);
	}
	for(int i = 0; i < m; i++) {
		int a = q.top(); q.pop();
		q.push(a/2);
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += q.top(); q.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#include <iomanip>
#define INF (1<<29)
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int n;
double px[200],py[200],pz[200];
double vx[200],vy[200],vz[200];
double r[200],vr[200];


double squ(double x){return x*x;}


struct S{
	double t;
	int a,b;
	S(double t,int a,int b):t(t),a(a),b(b){}
	bool operator<(const S &s)const{return t<s.t;}
};



int main(){
	bool exist[200];


	while(cin>>n&&n){
		rep(i,n){
			cin>>px[i]>>py[i]>>pz[i];
			cin>>vx[i]>>vy[i]>>vz[i];
			cin>>r[i]>>vr[i];
		}
		memset(exist,true,sizeof(exist));
		vector<S> ev;

		rep(i,n){
			ev.push_back(S(r[i]/vr[i],i,-1));
			for(int j=i+1;j<n;j++){
				double a,b,c;
				a=b=c=0;
				a+=squ(vx[i]-vx[j]);
				a+=squ(vy[i]-vy[j]);
				a+=squ(vz[i]-vz[j]);
				a-=squ(vr[i]+vr[j]);

				b+=2*(vx[i]-vx[j])*(px[i]-px[j]);
				b+=2*(vy[i]-vy[j])*(py[i]-py[j]);
				b+=2*(vz[i]-vz[j])*(pz[i]-pz[j]);
				b-=-2*(vr[i]+vr[j])*(r[i]+r[j]);

				c+=squ(px[i]-px[j]);
				c+=squ(py[i]-py[j]);
				c+=squ(pz[i]-pz[j]);
				c-=squ(r[i]+r[j]);

				if(0<=b*b-4*a*c){
					double s=sqrt(b*b-4*a*c);
					double t=(-b-s)/a/2;
					double r=(-b+s)/a/2;
					if(0<t)ev.push_back(S(t,i,j));
					else if(0<r)ev.push_back(S(r,i,j));
				}
			}
		}
		sort(ev.begin(),ev.end());
		double ans[200];
		int cnt=0;
		rep(i,ev.size()){
			if(ev[i].b==-1){
				if(exist[ev[i].a]){
					exist[ev[i].a]=false;
					ans[ev[i].a]=ev[i].t;
					cnt++;
				}
			}else{
				if(exist[ev[i].a]&&exist[ev[i].b]){
					exist[ev[i].a]=exist[ev[i].b]=false;
					ans[ev[i].a]=ans[ev[i].b]=ev[i].t;
					cnt+=2;
				}
			}
			if(cnt==n){
				break;
			}
		}
		rep(i,n){
			printf("%.10f\n",ans[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 1916
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int k, n;
  cin >> k >> n;
  vector<int> a(n + 5), b(n, 0);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  //sort(a.begin(), a.end());
  int maxi = 0;
  b[n] = k - a[n - 1] + a[0];
  for(int i = 0; i < n - 1; i++) {
    b[i] = a[i + 1] - a[i];
    maxi = max(maxi, b[i]);
  }
  b[n - 1] = k - a[n - 1] + a[0];
  /*
  for(int i = 0; i < n; i++) {
    cout << b[i] << " ";
  }
  */
  int ans = 0;
  sort(b.begin(), b.end());
  for(int i = 0; i < n - 1; i++) {
    ans += b[i];
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1792
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

using namespace std;

typedef long long lint;
typedef long double ldouble;
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

int gcd(int x, int y){
    int r = x % y;
    while(r != 0){
        x = y;
        y = r;
        r = x % y;
    }
    return y;
}

bool solve(void){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    int maxA = 0;
    rep(i, n){
        cin >> a[i];
        if(a[i] == k){
            return true;
        }
        maxA = max(maxA, a[i]);
    }
    if(maxA < k){
        return false;
    }
    int g = a[0];
    rep(i, n){
        g = gcd(g, a[i]);
    }
    return k % g == 0;
}

int main(){
    if(solve()){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    double r= scan.nextDouble();
    double menseki = r * r * 3.14159265358979;
    double ensyu = 2 * r * 3.14159265358979;
    System.out.println(String.format("%.6f", menseki)+ " " + String.format("%.6f", ensyu));
  }
}


Measured memory_bytes: 28280