akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
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; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    ll A, B;
    in2(A, B);

    ll ans = 0;
    chmax(ans, A + A - 1);
    chmax(ans, B + B - 1);
    chmax(ans, A + B);

    outl(ans);


    return 0;
}

Measured memory_bytes: 3624
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> v(n+1);
    rep(i,n+1) cin >> v[i];
    vector<ll> node(n+1, INF);
    node[0] = 1 - v[0];
    reps(i,n){
        // node[i] = min(INF, node[i-1] * 2 - v[i]);
        chmin(node[i], node[i-1] * 2 - v[i]);
    }
    debug(node);
    if(node[n] < 0){
        cout << -1 << endl;
        return 0;
    }
    vector<ll> rev(n+1);
    rev[n] = 0;
    rrep(i,n){
        rev[i] = min(node[i], (rev[i+1] + v[i+1]));
    }
    debug(rev);

    ll ans = 0;
    rep(i,n+1){
        ans += v[i] + rev[i];
    }
    bool ok = true;
    rep(i,n)ok &= rev[i] > 0;

    cout << (ok ? ans : -1) << endl;
}

Measured memory_bytes: 5548
#include <stdio.h>
#include <string.h>

int main(){
    int i;
    char a[5],b[5];
    
    scanf("%s",a);
    scanf("%s",b);
    
    if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0]){
        printf("YES\n");
    }
    
    else{
        printf("NO\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
def dump(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    s = input()
    n = len(s)

    key = 'keyence'
    if n == 7:
        if s == key:
            print("YES")
            return 0
        else:
            print("NO")
            return 0

    for i in range(n):
        pre = s[:i]
        suf = s[i+(n-7):]
        dump(pre)
        dump(suf)
        if (pre+suf == key):
            print("YES")
            return 0

    print("NO")
    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
    except:
        pass
    solve()
# vim: set foldmethod=marker:}}}


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

from math import log2, floor

L = int(input())

N = floor(log2(L)) + 1
edge = []

# 長さ0の辺
for i in range(1, N):
    edge.append((i, i+1, 0))

# 長さ2**(i-1)の辺
for i in range(1, N):
    edge.append((i, i+1, 2**(i-1)))

# ここまでで長さ0,...,X-1のパスが完成
X = 2 ** (N-1)

# 残りの辺
while L > X:
    r = floor(log2(L - X))
    edge.append((r + 1, N, X))
    X += 2 ** r

# 出力
M = len(edge)
print(N, M)
for e in edge:
    print(' '.join(map(str, e)))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int r; cin >> r;
    cout << fixed << setprecision(20) << 2 * r * acos(-1.0) << '\n';

}

Measured memory_bytes: 3788
using System;
					
public class Program
{
	public static void Main()
	{
		Console.WriteLine( Fib( int.Parse( Console.ReadLine() ) ) );
	}
	
	public static int Fib(int n)
	{
		if(n == 0)	return 1;
		if(n == 1)	return 1;
		
		int b, b1, b2;
		
		b  = 1;
		b1 = 1;
		for(int i = 2; i <= n; i++ ) {
			b2 = b1;
			b1 = b;
			b = b2 + b1;
		}
		return b;
	}
}

Measured memory_bytes: 9176
///in the name of Allah the most beneficent the most merciful.
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 998244353
//#define mod2 20071027
//#define MOD 998244353
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
#define base 139
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
const ll N=300010, M=1000005;
ll n, x, a[N];
///I-0, J-3, L-4,
int main()
{
    for(int i=0;i<7;i++)
    in1(a[i]);
    ll s = (a[0]%2)+(a[3]%2)+(a[4]%2),f=0;
    if(s>=2) f=1;
    ll k=min(a[3], min(a[4], a[0]));
    if(k%2!=f) k--;
    k=max(0LL,k);
    ll res=(k*3);
    a[0]-=k, a[3]-=k, a[4]-=k;
    res+=((a[0]/2)*2)+a[1]+((a[3]/2)*2)+((a[4]/2)*2);
    printf("%lld\n",res);

    return 0;
}
/*

*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e4 + 100;
const int mod = (int)1e9 + 7;
const long long INF = (long long)1e18;
int dd;
long long d[N][100];
long long get(string s){
    int n = s.size();
    for(int i = 0;i < 10;i++)d[1][(i % dd)]++;
    for(int i = 2;i <= n;i++){
        for(int m = 0;m < dd;m++){
            for(int j = 0;j < 10;j++){
                d[i][m] += d[i - 1][(((m - j) % dd) + dd) % dd];
                d[i][m] %= mod;
            }
        }
    }
    long long ans = 0;
    int ss = 0;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < (s[i] - '0');j++){
             ss += j;
            if((i == n - 1) && ((ss % dd) == 0))ans++;
            ans += d[n - i - 1][(((dd - ss) % dd) + dd) % dd];
            ans %= mod;
            ss-=j;
        }
        ss += (s[i] - '0');
        if((i == n - 1) && ((ss % dd) == 0))ans++;
    }
    return (ans - 1 + mod) % mod;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    string s;
    cin >> s >> dd;
    cout << get(s);
    return 0;
}

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


int main(){
	int a,b;
	cin>>a>>b;
	string s[a];
	for (int i = 0; i < a; i++){
		cin>>s[i];
	}

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


Measured memory_bytes: 256
#define LOCAL
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define ll long long
#define sz(x) (int)(x).size()
#define endl '\n'
#define print_case() cout << "Case #" << test_case_number++ << ": "

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
        sim > struct rge { c b, e; };
        sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
        sim > auto dud(c* x) -> decltype(cerr << *x, 0);
        sim > char dud(...);
        struct debug {
#ifdef LOCAL
            ~debug() { cerr << endl; }
            eni(!=) cerr << boolalpha << i; ris; }
        eni(==) ris << range(begin(i), end(i)); }
        sim, class b dor(pair < b, c > d) {
            ris << "(" << d.first << ", " << d.second << ")";
        }
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int test_case_number = 1;

#define int long long
void solve(){
    print_case();
}

int MOD = 1e9 + 7;
void show(vec<vec<int>> dp){
    for(auto x : dp){
        for(auto y : x){
            cout << y << '\t';
        }
        cout << endl;
    }
    cout << endl;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m;
    cin >> n >> m;
    vec<string> grid(n);
    string t;

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

    vec<vec<int>> dp(n, vec<int>(m, 0));
    dp[0][0] = 1;
    for(int i = 1; i < n; ++i){
        if(grid[i][0] == '#')
            dp[i][0] = 0;
        else
            dp[i][0] = dp[i - 1][0];
    }
    for(int j = 1; j < m; ++j){
        if(grid[0][j] == '#')
            dp[0][j] = 0;
        else
            dp[0][j] = dp[0][j - 1];
    }
    for(int i = 1; i < n; ++i){
        for(int j = 1; j < m; ++j){
            if(grid[i][j] == '#')
                dp[i][j] = 0;
            else
                dp[i][j] = ((((dp[i - 1][j] + dp[i][j - 1]) % MOD) + MOD) % MOD);
        }
    }
    cout << dp[n - 1][m - 1] << endl;
}


Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int N;
	cin >> N;

	int a = N / 100, b = N%100;

	if(1 <= a && a <= 12 && 1 <= b && b <= 12)cout << "AMBIGUOUS" << endl;
	else if(1 <= a && a <= 12)cout << "MMYY" << endl;
	else if(1 <= b && b <= 12)cout << "YYMM" << endl;
	else cout << "NA" << endl;
	
	return 0;
}

Measured memory_bytes: 256
input_line = input()
input_T = input()
count = 0

if len(input_line) != len(input_T)-1:
    print('No')
else:
    for i in range(len(input_line)):
        if input_line[i] == input_T[i]:
            count += 1

    if count == len(input_line):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 9056
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n;
    int w;
    cin >> n >> w;
    vector w_s(n, 0);
    vector<i64> v_s(n);
    rep(i, n)
    {
        cin >> w_s[i] >> v_s[i];
    }

    int winf = w + 1;
    // [0,i)の品物を使った重さj以下の解
    vector<i64> dpo(winf, 0), dpn(winf);

    rep(i, n)
    {
        dpn = dpo; // コピー

        // 処理
        rep(j, winf - w_s[i])
        {
            chmax(dpn[j + w_s[i]], dpo[j] + v_s[i]);
        }

        swap(dpo, dpn); // dpoに保存
    }

    cout << dpo[w] << '\n';

    return 0;
}


Measured memory_bytes: 4780
import numpy as np

N, W = map(int, input().split())
wv = np.array([[int(i) for i in input().split()] for j in range(N)])

max_v = 10**3*(N+1)
dp = np.full([N+1,max_v], np.inf)
dp[0,0] = 0
 
for i in range(N):
    # 遷移元なし
    dp[i+1,:wv[i,1]] = dp[i,:wv[i,1]]
    # 遷移元あり
    dp[i+1,wv[i,1]:] = np.minimum(dp[i,wv[i,1]:], dp[i,:max_v-wv[i,1]]+wv[i,0])

print(np.max(np.where(dp <= W)))

Measured memory_bytes: 177548
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;


int main(){
	/*input*/
	int n,m;
	cin >> n >> m;
	int k[30];
	vector<int> a(30,0);
	for(int i = 0; i < n; i++){
		cin >> k[i];
		for(int j = 0; j < k[i]; j++){
			int tmp;
			cin >> tmp;
			--tmp;
			a[tmp] += 1;
		}
	}
	/*calc*/
    int ans = 0;
    for(int i = 0; i < m; i++){
   		if(a[i] == n) ans += 1;
    }
    /*output*/
	cout<< ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

int n;
int h[1000];

int main(){
    cin >> n;
    REP(i, n) {
        cin >> h[i];
    }
    
    int output = 0;
    bool finish = false;
    while(!finish) {
        finish = true;
        bool watering = false;
        REP(i, n) {
            if (!watering && h[i]>0) {
                output ++;
                watering = true;
                finish = false;
            }

            if(h[i]>0) {
                h[i]--;
                continue;
            }

            if (watering && h[i] == 0) {
                watering = false;
            }
        }
    }
    cout << output << endl;
}


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define MOD 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n;
    cin >> n;
    REP(i, 1, n + 1)
    {
        int temp = i * 1.08;
        if (temp == n)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}


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

const int N=2005;
typedef long long ll;
struct node
{
    ll x;
    int pos;
}d[N];
ll dp[N][N];
int n;

bool cmp(node a,node b)
{
    return a.x>b.x;
}
ll f(int l,int r)
{
    if(l>r) return 0;
    if(dp[l][r]) return dp[l][r];
    int i=l+n-1-r;
    dp[l][r]=max(f(l+1,r)+d[i].x*abs(d[i].pos-l),f(l,r-1)+d[i].x*abs(d[i].pos-r));
    return dp[l][r];
}

int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
        scanf("%lld",&d[i].x);
        d[i].pos=i;
    }
    sort(d,d+n,cmp);
    printf("%lld\n",f(0,n-1));
    return 0;
}


Measured memory_bytes: 26516
import scala.io.StdIn._

object Main extends App {

  val s = readLine()

  def solve() = {
    var diffPat1 = 0
    var diffPat2 = 0
    (0 until s.length) foreach { i =>
      if(i % 2 == 0) {
        if(s(i) == '0') diffPat1 += 1
        else diffPat2 += 1
      } else {
        if(s(i) == '0') diffPat2 += 1
        else diffPat1 += 1
      }
    }
    Math.min(diffPat1, diffPat2)
  }

  println(solve())

}



Measured memory_bytes: 54992
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		String B = sc.next(); // 文字列で受け取る
		sc.close();
		BigDecimal a = new BigDecimal(A);
		BigDecimal b = new BigDecimal(B);
		prtln(a.multiply(b).toBigInteger());
	}

	public static <T> void prtln(T t) { System.out.println(t); }
}


Measured memory_bytes: 27276
#include <iostream>

using namespace std;

int main() {
    int a[3][3];
    bool b[3][3];
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> a[i][j];
            b[i][j] = false;
        }
    }

    int N;
    cin >> N;
    for(int i = 0; i < N; i++) {
        int c;
        cin >> c;
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 3; k++) {
                if(a[j][k] == c) b[j][k] = true;
            }
        }
    }

    bool f = false;
    for(int i = 0; i < 3; i++) {
        if(b[i][0] == true && b[i][1] == true && b[i][2] == true) f = true;
        if(b[0][i] == true && b[1][i] == true && b[2][i] == true) f = true;
    }
    if(b[0][0] == true && b[1][1] == true && b[2][2] == true) f = true;
    if(b[0][2] == true && b[1][1] == true && b[0][2] == true) f = true;

    if(f) {
    cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
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; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007

int main(){

    int n;

    cin >> n;

    vector<int> a(n);

    map<int,int,greater<int>> stick;

    REP(i,n){
        cin >> a[i];
        stick[a[i]]++;
    }

    int height = -1;

    for(auto i=stick.begin();i!=stick.end();i++){
        if(i->second<2)continue;
        if(height == -1){
            if(i->second>=4){
                cout << (ll)(i->first)*(i->first) << endl;
                return 0;
            }else
            {
                height = i->first;
            }
        }else{
            cout << (ll)height * (i->first);
            return 0;
        }
    }

    cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 8156
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main(){
    int K,X;
    cin >> K >> X;
    for(int i=X-K+1;i<=X+K-1;i++){
        cout << i ;
        if(i!=X+K-1){
            cout << " ";
        }
        else cout << endl;
    }
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<long long>a(n);
    long long sum=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(i==0)continue;
        sum+=a[i];
    }
    vector<long long>dp(n,0);
    dp[0]=a[0];
    long long ans=labs(sum-dp[0]);
    for(int i=1;i<n-1;i++){
        dp[i]+=(dp[i-1]+a.at(i));
        sum-=a.at(i);
        ans=min(ans,abs(sum-dp[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> vs(n);
  for(Int i=0;i<n;i++) cin>>vs[i];

  Int ans=-n*(n+1)/2;
  for(Int v:vs) ans+=v;

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



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


int main(){
  int N;
  long long int K;
  cin >> N >> K;
  vector<int> A(N);
  for(auto& a : A){
    cin >> a;
    a--;
  }

  vector<long long int> count(N, 0);
  int pos=0;
  for(long long int ii=K; ii>0; ii--){
    pos=A[pos];
    if(count[pos]!=0){
      ii = (ii-1)%(K-ii+1 - count[pos]) + 1;
    }else{
      count[pos] = K-ii+1;
    }
  }
  cout << pos+1 << endl;
  return 0;
}


Measured memory_bytes: 5636
#include<iostream>
#include<vector>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h;
    cin>>h;
    vector<int> v(h);
    for(int i=0;i<h;++i)cin>>v[i];
    for(int i=0;i<h;++i){
        cout<<"node "<<i+1<<": key = "<<v[i];
        if(i)cout<<", parent key = "<<v[(i-1)/2];
        if(2*i+1<h)cout<<", left key = "<<v[2*i+1];
        if(2*i+2<h)cout<<", right key = "<<v[2*i+2];
        cout<<", "<<endl;
    }
}

Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    string s,t;
    cin >> s >> t;

    int n = s.size();
    int m = t.size();

    vector<string> sol;

    for(int i = 0; i < n; i++){
        string now = s;
        for(int j = 0; j < m; j++){
            if(now[i+j] != t[j] && now[i+j] != '?') break;
            else now[i+j] = t[j];

            if(j == m-1){
                for(int k = 0; k < n; k++){
                    if(now[k] == '?') now[k] = 'a';
                }
                sol.push_back(now);
            }
        }
    }

    if(sol.empty()){
        cout << "UNRESTORABLE" << endl;
    }else{
        sort(all(sol));
        cout << sol[0] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var ap = new string[n];
            var maxL = 0;
            for (int i = 0; i < n; i++)
            {
                var s = Console.ReadLine().Trim();
                ap[i] = s;
                maxL = Max(maxL, s.Length);
            }
            Console.WriteLine(getAns(ap,maxL));
        }
    }
    static int getAns (string[] ap, int maxL)
    {
        if (checkK(ap, 1)) return 1;
        if (!checkK(ap, maxL)) return -1;
        var ng = 1; var ok = maxL; 
        while (ok - ng > 1)
        {
            var mid = ng + (ok - ng) / 2;
            if (checkK(ap, mid)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
    static bool checkK (string[] ap , int k)
    {
        var hs = new HashSet<string>();
        foreach (var x in ap)
            if (!hs.Add(getCode(x, k))) return false;
        return true;
    }
    static string getCode (string s , int k)
    {
        var b = "aiueo";
        var ans = s.Substring(0, 1);
        var preb = false;
        if (b.Contains(ans)) preb = true;
        var count = 1;
        var sL = s.Length;
        for (int i = 1; i < sL; i++)
        {
            if (count == k) return ans;
            if (preb) { ans += s[i]; count++; }
            preb = b.Contains(s[i]) ? true : false;
        }
        return ans;
    }
}



Measured memory_bytes: 20620
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int main(){
	LL q,h,s,d,n;
	cin>>q>>h>>s>>d>>n;
	LL ans=1e18;
	ans=min(ans,n*4*q);
	ans=min(ans,n*2*h);
	ans=min(ans,n*s);
	long long res=0;
	if(n&1)res=min(s,min(h*2,q*4));
	ans=min(ans,n/2*d+res);
	cout<<ans<<endl;
}



Measured memory_bytes: 256
'use strict';
        (function(stdin) {
          var inputs  = stdin.toString();
          var cols = inputs.split('\n')[0].split(' ').map(Number);
          var a = cols[0];
          var b = cols[1];
          if(a < b){
            console.log('a < b');
          }else if(a > b){
            console.log('a > b');
          }else{
            console.log('a == b');
        }
      }(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7376
#include<stdio.h>
int main() {

	int l;
	long double a, b, c;

	scanf("%d", &l);

	a = (long double)l / 3.0;
	b = (long double)l / 3.0;
	c = (long double)l - (a + b);

	printf("%llf", a * b * c);

	return 0;
}

Measured memory_bytes: 2216
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define MAX_N 111111
int N;
vector<int>G[MAX_N];
bool f[MAX_N];
int s[MAX_N];
int dfs(int v){
	
	if((int)G[v].size()==0){
		//printf("\n");
		return 0;
	}
	vector<int>re;
	for(int i=0;i<(int)G[v].size();i++){
		int x=dfs(G[v][i]);
		//printf("%d %d ",G[v][i],x);
		re.pb(x);
	}
	//printf("\n");
	sort(re.begin(),re.end());
	reverse(re.begin(),re.end());
	vector<int>re1;
	for(int i=0;i<(int)re.size();i++){
		re1.pb(re[i]+i+1);
	}
	sort(re1.begin(),re1.end());
	/*
	for(int i=1;i<(int)re1.size();i++){
		if(re1[i-1]>re1[i]){
			re1[i]=re1[i-1]+1;
		}
	}
	*/
	return re1[(int)re1.size()-1];
}
int main()
{
	scanf("%d",&N);
	/*
	for(int i=0;i<N;i++){
		f[i]=true;
	}
	*/
	for(int i=1;i<N;i++){
		int num;scanf("%d",&num);num--;
		G[num].pb(i);
		//f[num]=false;
	}
	printf("%d\n",dfs(0));
	return 0;
}


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

    int main (){
        int n;
        cin >> n;
        vector<int> a(n+1);
        
        rep(i,n){
            int x;
            cin >> x;
            a[x]=i;
        }
        
        rep(i,n){
            cout << a[i] << endl;
        }
        

    }

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define N 300005
#define pb push_back

int main()
{
    int n;
    cin>>n;
    string s;
    rep(i,n)
    {
        s+="ACL";
    }
    cout<<s;
}

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

int main() {
  int A, B, c, d, e;
  cin >> A >> B;
  
  int j = 0;
  for (int i = A; i <= B; i++) {
    c = i % 10;
    d = (i - c) % 100;
    e = i - c * 10000 - d * 100;
    if (e >= 0 && e < 1000) 
      j++;
  }
  cout << j << endl;
}

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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define sf scanf
#define pb push_back
#define pf printf
typedef long long ll;
typedef double db;
const int maxn = 53;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db eps = 1e-9;
const int zqc = 1e9+7;

char S[3][maxn];
int N, f[maxn][3][3], st;

int main()
{
	sf("%d",&N);
	fo(i,1,2) scanf("%s",S[i]+1);
	if(S[1][1] == S[2][1]) fo(j,0,2) f[1][j][j] = 1, st = 2;
	else fo(j,0,2) fo(k,0,2) if(j!=k) f[2][j][k] = 1, st = 3;
	fo(i,st,N)
	{
		if(S[1][i] == S[2][i])
		{
			fo(j,0,2) fo(lj,0,2) fo(lk,0,2) if(j!=lj&&j!=lk)
				f[i][j][j] = (f[i][j][j]+f[i-1][lj][lk])%zqc;
		}
		else
		{
			fo(j,0,2) fo(k,0,2) if(j!=k) fo(lj,0,2) fo(lk,0,2) if(j!=lj&&k!=lk)
				f[i+1][j][k] = (f[i+1][j][k]+f[i-1][lj][lk])%zqc;
			++ i;
		}
	}
	int ans = 0;
	fo(j,0,2) fo(k,0,2) ans = (ans + f[N][j][k])%zqc;
	pf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define int long long
set < ll> primes;
 int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int n;
bool isvalid(int x,int y){
  return (x>=0 and x<n and y>=0 and y<n);
}
void Sieve(ll n) 
{ 
    bool prime[n+1];
	for(ll i=0;i<n+1;++i)
		prime[i]=true;
    for (ll p=2;p*p<=n;++p) 
    {
        if (prime[p] == true) 
        {  
            for (ll i=2*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    }  
    for(ll p=2; p<=n; p++) 
       if (prime[p]) 
		primes.insert(p);  
}

ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
        return gcd(b % a, a); 
} 
ll powermod(ll x, ll y){
    if(y==0)
    return 1;
        
    if(y%2==0)
    return (powermod(x,y/2)*powermod(x,y/2))%mod;
    else
    return (((powermod(x,y/2)*powermod(x,y/2))%mod)*x)%mod;
}

 
 

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
  
    string s;
    cin>>s;
    int n=s.size();
    if(s.size()%2)
    {
        string t=s;
        reverse(t.begin(),t.end());
        if(t==s)
        {
            
        
        
        string ans=s.substr(0,(n-1)/2);
        string temp=ans;
        //deb(temp);
        reverse(temp.begin(),temp.end());
        if(temp==ans)
        {
            if((n+3)/2-1>=0 && (n+3)/2-1<n )
            {
                string temp1=s.substr((n+3)/2-1);
               
                //deb(temp1);
                string temp2=temp1;
                reverse(temp1.begin(),temp1.end());
                if(temp1==temp2)
                {
                    cout<<"Yes";
                }
                else
                {
                    cout<<"No";
                }
            }
            else 
            {
                cout<<"Yes";
            }
           
            
            
            
        }
        else
        {
            cout<<"No";
        }
        
        
        }
        else cout<<"No";
    }
    else cout<<"No";
   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=15;
int main()
{
  int a[N],n,sum=0;
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];
  sort(a+1,a+n+1);
  for(int i=1;i<n;i++) sum+=a[i];
  sum+=(a[n]/2);
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
function main(_stdin) {
    const stdin = _stdin.split('\n');
    const count = parseInt(stdin.shift(), 10);
    const stack = [];
    const colors = [''];
    const stamps = [];
    const way = [];

    for (let i = 1; i < 1 + count; i++) {
        colors[i] = 'white';
    }

    for (let i = 1; i < 1 + count; i++) {
        stamps[i] = [];
    }

    for (let i = 1; i < 1 + count; i++) {
        for (let ij = 1; ij < 1 + count; ij++) {
            if (!way[i]) way[i] = [];
            way[i][ij] = 0;
        }
    }

    const data = stdin.filter((e, i) => i < count).map(
        e => e.split(' ').map(e => parseInt(e, 10)));

    dfs(stack, data, data[0][0], colors, 1, stamps, way);
    stamps.shift();
    for (let i = 0, l = stamps.length; i < l; i++) {
        console.log(i+1, stamps[i][0], stamps[i][1]);
    }
}

function dfs(stack, data, key, colors, time, stamps, way) {
    stack.push(key);
    colors[key] = 'gray';
    stamps[key][0] = time++;

    while (stack.length) {
        key = stack[stack.length - 1];
        const d = data.find(e => e[0] === key);
        const next = getNext(d, way);
        if (next) {
            if (colors[next] === 'white') {
                colors[next] = 'gray';
                stamps[next][0] = time++;
                stack.push(next);
            }
        } else {
            const last = stack.pop();
            colors[last] = 'black';
            stamps[last][1] = time++;
        }
    }
    const untouch = stamps.findIndex((e, i) => i > 0 && !e.length);
    if(untouch > 0){
        dfs(stack, data, untouch, colors, time, stamps, way);
    }
}

function getNext(data, way) {
    const children = data.slice(2);
    if (children.length) {
        for (let child of children) {
            if (way[data[0]][child] === 0) {
                way[data[0]][child] = 1;
                return child;
            }
        }
    } else {
        return null;
    }
}



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




Measured memory_bytes: 18112
#include<iostream>
#include <cstdlib>
using namespace std;
int main(){
	long long a,b;
  	cin >> a >> b;
  	long long z = (a%b)<(b-a%b)?a%b:(b-a%b);
  	if(b>(2*a)) cout << a;
  	else if(b>a) cout << b-a;
  	else cout << z;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

int main() {
    string s;
    cin >> s;
    int len = s.size();
    if (s[0] == '0' || s[len - 1] == '1') {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0; i < len - 1; i++) {
        if (s[i] != s[len - 1 - i - 1]) {
            cout << -1 << endl;
            return 0;
        }
    }
    s[len - 1] = '1';
    pii ans[len - 1];
    int parent = len - 1;
    for (int i = len - 2; i >= 0; i--) {
        ans[i] = pii(i + 1, parent + 1);
        if (s[i] == '1') {
            parent = i;
        }
    }
    for (int i = 0; i < len - 1; i++) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}


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

int main(){
  string n;
  cin >> n;
  
  string ans = "No";
  for(int i = 0; i < 3; i++){
    if(n[i] == '7'){
      ans = "Yes";
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
int main() {
	int n;
	cin >> n;
	if (n == 0)cout << 1 << endl;
	else cout << 0 << endl;



	return 0;
}

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

int main()
{
    char c;
    cin>>c;
    if(c=='a')
    {cout<<"vowel";
    return 0;
    }
    else
         if(c=='e')
    {
        cout<<"vowel";
    return 0;
    }
    else
        if(c=='i')
    {
        cout<<"vowel";
    return 0;
    }
    else
        if(c=='o')
    {
        cout<<"vowel";
    return 0;
    }
    else
        if(c=='u')
    {
        cout<<"vowel";
    return 0;
    }
    else
        cout<<"consonant";
    return 0;
}

Measured memory_bytes: 256
import sys
from io import StringIO
import unittest


def resolve():
    int(input())
    A = [int(i) for i in input().split()]
    Aa = set(A)
    if len(A) == len(Aa):
        print("YES")
    else:
        print("NO")


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5
2 6 1 4 5"""
        output = """YES"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """6
4 1 3 1 6 2"""
        output = """NO"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """2
10000000 10000000"""
        output = """NO"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

using namespace std;

int main() {
    while(true) {
        int D, N, M;
        cin >> D;
        if(!D) break;
        cin >> N >> M;

        vector<int> shops;
        shops.push_back(0);
        for(int i = 1; i < N; ++i) {
            int d;
            cin >> d;
            shops.push_back(d);
        }

        int ans = 0;
        sort(shops.begin(), shops.end());
        while(M--) {
            int k;
            cin >> k;
            vector<int>::iterator it = lower_bound(shops.begin(), shops.end(), k);
            vector<int>::iterator it2;
            if(it == shops.begin()) it2 = shops.end()-1;
            else it2 = it-1;
            int d1 = (abs(*it-k+D)) % D;
            int d2 = (abs(*it2-k+D)) % D;
            //cout << min(d1, d2) << endl;
            ans += min(min(d1, D-d2) % D, min(d2, D-d2) % D);
            //ans += min(d1, d2);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1432
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
#input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

from collections import deque

def main():
	h,w,k=MI()
	x1,y1,x2,y2=MI()
	G=["@"]*(w+2)
	for _ in range(h):
		G.append("@")
		G+=(list(map(str,input().rstrip())))
		G.append("@")
	G+=["@"]*(w+2)
	#print(G)


	G[x1*(w+2)+y1]=0
	#print(G)

	Q=deque()
	Q.append((x1*(w+2)+y1,0))

	while Q:
		#print(Q)
		now,d=Q.popleft()
		#print(Q)
		for m in [1,-1,w+2,-w-2]:
			for i in range(1,k+1):
				if G[now+m*i]==d or G[now+m*i]=="@":
					break
				elif G[now+m*i]==".":
					G[now+m*i]=d+1
					Q.append([now+m*i,d+1])
				elif G[now+m*i]==d+1:
					continue
				else:
					break

		#print(Q)
	#print(G)

	if G[x2*(w+2)+y2]==".":
		print(-1)
	else:
		print(G[x2*(w+2)+y2])


if __name__ == "__main__":
	main()


Measured memory_bytes: 282940
#include <bits/stdc++.h>
using namespace std;
 
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL); cout.tie(NULL);}
#define f first
#define s second
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;
 
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}
 
mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(61378913);
/* usage - just do rng() */
 
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}

#include <atcoder/all>
using namespace atcoder;
 
const lld pi = 3.14159265358979323846;
// const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;
 


ll n, m, k, q, l, r, x, y, z;
const ll template_array_size = 1e6 + 1531;
ll a[template_array_size];
ll b[template_array_size];
ll c[template_array_size];
string s, t;
ll ans = 0;

pair<pair<ll, ll>, ll> p[200005];
ll res[200005];
bool vis[200005];

void solve(int tc = 0) {
	cin >> n;
	
	for (ll i = 0; i < n; i++) {
		cin >> p[i].f;
		p[i].s = i;
	}
	
	sort(p, p + n);
	
	for (ll i = 0; i < n; i++) res[i] = -1;
	
	memset(vis, 0, sizeof(vis));
	
	ll last = 0;
	ll pt = n;
	for (ll i = 0; i < n; i++) {
		vis[p[i].f.s] = 1;
		
		while (vis[pt]) --pt;
		
		if (pt == n - i - 1) {
			res[i] = i - last + 1;
			last = i + 1;
		}
	}
	
	ll r;
	for (ll i = n - 1; i >= 0; i--) {
		if (res[i] != -1) r = res[i];
		res[i] = r;
		b[p[i].s] = res[i];
	}
	
	for (ll i = 0; i < n; i++) cout << b[i] << '\n';
}
 
int main() {
	#ifdef galen_colin_local
		auto begin = std::chrono::high_resolution_clock::now();
	#endif
	
	send help
 
	#ifndef galen_colin_local
		// usaco("moop");
	#endif
	
	// usaco("cowland");
	
	// freopen("tc.cpp", "r", stdin);
 
	
	
	int tc = 1;
	// cin >> tc;
	for (int t = 0; t < tc; t++) solve(t);
	
	#ifdef galen_colin_local
		auto end = std::chrono::high_resolution_clock::now();
		cout << setprecision(4) << fixed;
		// cout << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
	#endif
} 

Measured memory_bytes: 11680
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

int main()
{
	int n;
	while (cin >> n, n){
		vector<pair<int, int> > vp;
		for (int i = 0; i < n; i++){
			int id;
			cin >> id;
			int score = 0;
			for (int i = 0; i < 4; i++){
				int m, s;
				cin >> m >> s;
				score += m * 60 + s;
			}
			vp.push_back(make_pair(score, id));
		}
		sort(vp.begin(), vp.end());
		printf("%d\n%d\n%d\n", vp[0].second, vp[1].second, vp[n - 2].second);
	}
	return (0);
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main(){
  ll N;
  cin >> N;
  map<ll,ll> A;
  REP(i,N){
    ll a;
    cin >> a;
    A[a]++;
  }
  
  ll ans = 0;
  for(auto p:A){
    ans += p.first*p.second;
  }
  
  ll Q;
  cin >> Q;
  REP(i,Q){
    ll b,c;
    cin >> b >> c;
    ll tmp_b = A[b];
    ans -= b*tmp_b;
    ans -= c*A[c];
    A[b] = 0;
    A[c] += tmp_b;
    ans += c*A[c];
    cout << ans << endl;
  }
}

Measured memory_bytes: 9452
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

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

int main() {
    int n, k;
    cin >> n >> k;
    vint a(n);
    rep(i, n) cin >> a[i];
    int g = a[0];
    srep(i, n, 1) {
        g = gcd(g, a[i]);
    }
    int mx = vmax(a);
    if (k <= mx && (k % g == 0 || g == 1)) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 640