akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int d=1,n;
    in(n);
    while(d<=n){
        d*=2;
    }
    out(d/2);
}


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

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

fn solve(i: usize, d: i32, j: usize, par: &mut Vec<usize>, depth: &mut Vec<i32>, graph: &Vec<Vec<usize>>, rgraph: &Vec<Vec<usize>>) {
    if depth[i] >= d {
        return;
    }
    if rgraph[i].len() > 1 {
        for k in rgraph[i].iter() {
            if *k != j && depth[*k] == -1 {
                return;
            }
        }
    }
    par[i] = j;
    depth[i] = d;
    for k in graph[i].iter() {
        solve(*k, d+1, i, par, depth, graph, rgraph);
    }
}

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

    let mut graph: Vec<Vec<usize>> = vec![Vec::new(); n];
    let mut rgraph: Vec<Vec<usize>> = vec![Vec::new(); n];
    for i in 0..n+m-1 {
        let ab: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let a = ab[0];
        let b = ab[1];

        graph[a-1].push(b-1);
        rgraph[b-1].push(a-1);
    }

    let mut par: Vec<usize> = vec![n; n];
    let mut depth: Vec<i32> = vec![-1; n];
    for i in 0..n {
        if rgraph[i].len() == 0 {
            depth[i] = 0;
            for j in graph[i].iter() {
                solve(*j, 1, i, &mut par, &mut depth, &graph, &rgraph);
            }
            break;
        }
    }

    for i in 0..n {
        if depth[i]==0 {
            println!("{}", 0);
        } else {
            println!("{}", par[i] + 1);
        }
    }
}


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

int main() {
  string A, B;
  cin >> A >> B;

  if (A.size()==B.size()) {
    cout << (A>B ? "GREATER": A==B ? "EQUAL": "LESS");
  } else {
    cout << (A.size()>B.size() ? "GREATER": "LESS");
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
int tt[24][6]={
{4,12,8,16,1,3},
{9,5,17,13,2,0},
{18,10,14,6,3,1},
{15,19,7,11,0,2},
{23,15,9,0,5,7},
{10,20,1,12,6,4},
{2,11,13,21,7,5},
{14,3,22,8,4,6},
{7,0,21,17,9,11},
{22,4,18,1,10,8},
{19,23,2,5,11,9},
{3,16,6,20,8,10},
{5,21,0,19,13,15},
{1,6,16,22,14,12},
{17,2,23,7,15,13},
{20,18,4,3,12,14},
{0,13,11,23,17,19},
{8,1,20,14,18,16},
{21,9,15,2,19,17},
{12,22,3,10,16,18},
{11,17,5,15,21,23},
{6,8,12,18,22,20},
{13,7,19,9,23,21},
{16,14,10,4,20,22}};
int n,c,a,p,i;
string s;
while(cin>>n,n){
a=1;p=0;
for(i=0;i<n;i++){
cin>>s;
if(s=="North")c=0;
else if(s=="East")c=1;
else if(s=="West")c=2;
else if(s=="South")c=3;
else if(s=="Right")c=4;
else c=5;
p=tt[p][c];
a+=p/4+1;
}
cout<<a<<endl;
}
return 0;
}

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

int h, w;

int bomb_count(vector<vector<char>> &v, int x, int y) {
  vector<pair<int, int>> points;
  points.push_back(make_pair(x - 1, y - 1));
  points.push_back(make_pair(x,     y - 1));
  points.push_back(make_pair(x + 1, y - 1));
  points.push_back(make_pair(x + 1, y));
  points.push_back(make_pair(x + 1, y + 1));
  points.push_back(make_pair(x,     y + 1));
  points.push_back(make_pair(x - 1, y + 1));
  points.push_back(make_pair(x - 1, y));

  int num = 0;
  for (auto point : points) {
    int xx = point.first;
    int yy = point.second;
    if (xx >= 0 && xx < h && yy >= 0 && yy < w) {
      if (v.at(xx).at(yy) == '#') {
        num++;
      }
    }
  }
  return num;
}

int main() {
  cin >> h >> w;

  vector<vector<char>> v(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> v.at(i).at(j);
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (v.at(i).at(j) == '.') {
        cout << bomb_count(v, i, j);
      } else {
        cout << '#';
      }
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3552
#include <stdio.h>

using namespace std;

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

char sign(int op) { return (op == 0) ? '+' : '-'; }

int main() {
    char ABCD[5];
    scanf("%s", ABCD);

    int A = ABCD[0] - '0';
    int B = ABCD[1] - '0';
    int C = ABCD[2] - '0';
    int D = ABCD[3] - '0';

    char op1;
    char op2;
    char op3;

    REP(o1, 2) {
        int v = 0;
        REP(o2, 2) {
            REP(o3, 2) {
                op1 = sign(o1);
                v = (o1 == 0) ? A + B : A - B;
                op2 = sign(o2);
                v = (o2 == 0) ? v + C : v - C;
                op3 = sign(o3);
                v = (o3 == 0) ? v + D : v - D;
                // printf("%d%c%d%c%d%c%d=%d\n", A, op1, B, op2, C, op3, D, v);
                if (v == 7) break;
            }
            if (v == 7) break;
        }
        if (v == 7) break;
    }

    printf("%d%c%d%c%d%c%d=7\n", A, op1, B, op2, C, op3, D);

    return 0;
}


Measured memory_bytes: 128
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys
d = [int(s) for s in stdin.readline().rstrip().split()]
h1 = d[0]
m1 = d[1]
h2 = d[2]
m2 = d[3]
k = d[4]
if h1 > h2:
    print(0)
elif h2 == h1:
    num = m2-m1
    if num <= 0:
        print(0)
    else:
        if (num-k) <= 0:
            print(0)
        else:
            print(num-k)
else:
    minu = m2-m1
    if minu < 0:
        res = (h2-h1-1)*60+(minu+60)
        if (res-k) <= 0:
            print(0)
        else:
            print(res-k)
    else:
        res = (h2-h1)*60+(minu)
        if (res-k) <= 0:
            print(0)
        else:
            print(res-k)


Measured memory_bytes: 77172
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
Q[tail] = x;
tail = (tail + 1) % LEN;
}
P dequeue() {
P x = Q[head];
head = (head + 1) % LEN;
return x;
}

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

int main(){
int elaps = 0,c;
int i,q;
P u;
scanf("%d %d", &n,&q);

for(i=1;i <= n;i++){
scanf("%s",Q[i].name);
scanf("%d",&Q[i].t);
}

head = 1;
tail = n+1;

while(head != tail){
    u = dequeue();
    c = min(q, u.t);

    u.t -= c;

    elaps += c;

    if(u.t > 0)enqueue(u);
    
    else
    {
        printf("%s %d\n",u.name, elaps);
    }
    
}
return 0;
}




Measured memory_bytes: 11836
s = input()
K = int(input())
N = len(s)

S = [0 for _ in range(N)]

for i in range(N):
    S[i] = ord(s[i])-97

tmp = K
ans = ''

for i in range(N):
    if S[i]==0:
        ans += 'a'
    elif 26-S[i] <= tmp:
        ans += 'a'
        tmp -= 26-S[i]
    else:
        ans += s[i]
        
if tmp:
    ans = ans[:-1]+chr((ord(ans[-1])-97+tmp)%26+97)
    
print(ans)

Measured memory_bytes: 4340
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MAX = 510000;
const int MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll n, q, cnt = 0,h,w, ans = 0,a,b; string s;
int dx[9] = { -2,-2,-2,-1,-1,-1,0,0,0 }, dy[9] = { 0,-1,-2,0,-1,-2,0,-1,-2 };
int main(void) {
    int n; cin >> n; vector<ll> a(n);
    ll sum = 0,ans = 0;
    rep(i, n) {
        cin >> a[i]; sum += a[i];
        sum %= MOD;
    }
    rep(i, n) {
        ans += (a[i] * (((sum - a[i])+MOD) % MOD))%MOD;
        ans %= MOD;
    }if (ans % 2==1) ans += MOD;
    cout << (ans / 2)%MOD << endl;
}

Measured memory_bytes: 4844
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import qualified Data.IntMap as IMap
import qualified Data.Vector as V
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)

bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt

sqleft :: Seq a -> a
sqleft q = sqleft_(Sq.viewl q)
sqleft_ :: ViewL a -> a
sqleft_ (x :< xs) = x
sqright :: Seq a -> a
sqright q = sqright_(Sq.viewr q)
sqright_ :: ViewR a -> a
sqright_ (xs :> x) = x

-------------------------------------------------------------
count :: [[Int]] -> Int -> Int -> Int
count (c:cn) n k = if (n + b) >= k
                   then a
                   else count cn (n+b) k
                   where a = c !! 0
                         b = c !! 1

main = do
    [n,k] <- map bsreadInt . BC.words <$> BC.getLine
    abin <- map ((map bsreadInt . BC.words)) <$> replicateM n BC.getLine
    let ab = sort abin
    print $ count ab 0 k


Measured memory_bytes: 64892
#include<bits/stdc++.h>
using namespace std;
string s;
int len;
bool c=0,f=0;
int main()
{
	cin>>s;
	len=s.size();
	for(int i=0;i<len;i++)
	{
		if(s[i]=='C')c=1;
		if(c==1&&s[i]=='F')f=1;
		if(c==1&&f==1)break;
	}
	if(c==1&&f==1)
	{
		cout<<"Yes";
		return 0;	
	}
	else
	{
		cout<<"No";
		return 0;
	}
}


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

int main() {
  int n;
  cin >> n;
  vector<int>a(n-1);
  vector<int>b(n);
  for(int i=0;i<n-1;i++){
  cin >> a.at(i);
  }
  for(int i=0;i<n-1;i++){
  b.at(a.at(i)-1)++;
  }
  for(int i=0;i<n;i++){
  cout << b.at(i) << endl;
  }
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

template <class T> using Tree = tree <T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool a) {
    return a ? "T" : "F";
}

string to_string(const char* s) {
    return to_string((string) s);
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

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

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

#define X first
#define Y second

using ll = long long;
using ld = long double;

const int N = 2e5 + 10;

int n;
int p[N];
int ps[N];
int nxt[N];

void run() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }

    for (int i = 1; i <= n; ++i) {
        ps[p[i]] = i;
    }

    for (int i = 1; i <= n; ++i) {
        nxt[i] = ps[p[i] + 1];
    }

    int nw = ps[1];
    int cnt = 0;
    int mx = 0;
    for (int i = 1; i < n; ++i) {
        if (nxt[nw] > nw) {
            ++cnt;
        } else {
            cnt = 0;
        }
        maxi(mx, cnt);
        nw = nxt[nw];
    }

    cout << n - mx - 1 << endl;

}

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


Measured memory_bytes: 2560
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    vector<ll> x(n);
    vector<ll> y(n);
    vector<ll> h(n);
    rep(i, n) cin >> x[i] >> y[i] >> h[i];
    rep(xi, 101) rep(yi, 101) {
        ll hmax = 1e18;
        ll hmin = -1;
        rep(i, n) {
            ll sa = abs(x[i]-xi) + abs(y[i]-yi);
            if (h[i] == 0) {
                hmax = min(hmax, sa);
            }
            else {
                hmin = max(hmin, h[i]+sa);
                hmax = min(hmax, h[i]+sa);
            }
        }
        if (hmax == hmin) {
            printf("%d %d %lld\n", xi, yi, hmin);
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

int A,B;

int main(){
    cin>>A>>B;

    cout<<(A+B)%24<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>




int main()
{
	int i, N;

	scanf("%d", &N);

	int a[11];
	int t[11];

	for (i = 0; i < N; i++) scanf("%d", &a[i]);

	for (i = 0; i < N; i++) {
		if (a[i] % 2 == 0) {
			t[i] = 2;
		}
		else t[i] = 1;
	}

	int seki=1;

	for (i = 0; i < N; i++) {
		seki*= t[i];
	}

	int p=1;

	for (i = 0; i < N; i++) {
		p *= 3;
	}


	printf("%d", p - seki);
}






Measured memory_bytes: 128
#include <stdio.h>

int main (void){
  int H[100], W[100], i = 0, j, x, y;

  while (1) {
    scanf("%d %d", &H[i], &W[i]);
    if(H[i] == 0 && W[i] == 0) break;
    i++;
  }

  for(j = 0; j < i; j++){
    for(x = 0; x < H[j]; x++){
      for(y = 0; y < W[j]; y++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int n, k;
	cin >> n >> k;
	cout << (n % k ? 1 : 0) << endl;
}



Measured memory_bytes: 384
<?php
while (true) {
    list($height, $width) = getSpacesByExplodeTrimInput();

    if ($height == 0 && $width == 0) {
        break;
    }

    $widthSymbolNum = str_repeat('#', $width).PHP_EOL;
    echo str_repeat($widthSymbolNum, $height).PHP_EOL;
}

function getSpacesByExplodeTrimInput()
{
    return explode(' ', trim(fgets(STDIN)));
}

Measured memory_bytes: 15316
#線形探索
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
c = 0

for i in range(q):
    t = T[i]
    for j in range(n):
        if S[j] == t:
            c += 1
            break
print(c)


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

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

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  long long A, B, C, K;
  cin >> A >> B >> C >> K;

  if(abs(A-B) > 1000000000000000000){
    printf("Unfair\n");
  }else if(K%2 == 0){
    printf("%lld\n", A - B);
  }else{
    printf("%lld\n", B - A);
  }
}


Measured memory_bytes: 3728
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	while (1) {
		int n, x; cin >> n >> x;

		if (n == 0 && x == 0)break;

		int ans = 0;
		for (int i = 1; i <= n-2; i++) {
			for (int j = i + 1; j <= n-1; j++) {
				for (int k = j + 1; k <= n; k++) {
					if (i + j + k == x) ans++;
				}
			}
		}

		cout << ans << endl;
	}
}


Measured memory_bytes: 3108
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;
import std.bigint;
import core.checkedint;
import core.bitop;

void main()
{
	int n = readln.chomp.to!int;
	writeln = ["ABC", "ABD"][n / 1000];
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}


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

typedef long long ll;
typedef pair<ll,ll> P;

#define fr first
#define sc second

const ll INF=10000000000;

int main(){
	static ll n;
	static ll a[1<<18];
	scanf("%lld",&n);
	for(int i=0;i<(1<<n);i++){
		scanf("%lld",&a[i]);
	}
	
	static ll dp[1<<18][2];
	for(int i=0;i<(1<<n);i++){
		dp[i][0]=a[i];
		dp[i][1]=-INF;
	}
	for(int j=0;j<n;j++){
		for(int i=0;i<(1<<n);i++){
			if((i>>j)&1){
				dp[i][1]=max(dp[i][1],dp[i-(1<<j)][0]);
				if(dp[i][0]<dp[i][1])swap(dp[i][0],dp[i][1]);
				dp[i][1]=max(dp[i][1],dp[i-(1<<j)][1]);
			}
		}
	}
	ll ret=0;
	for(int i=1;i<(1<<n);i++){
		ret=max(ret,dp[i][0]+dp[i][1]);
		printf("%lld\n",ret);
	}
}



Measured memory_bytes: 9216
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B)OUT(C);
	else if (B == C)OUT(A);
	else OUT(B);
}

Measured memory_bytes: 384
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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

	int F;
	cin >> F;
	cout << (F - 30) / 2 << endl;
}


Measured memory_bytes: 3172
#include<iostream>
#include<algorithm>
using namespace std;
long long b[1000000], a[1000000], c[1000000], x[1000000], n, p, q, sum, maxn;
int main() {
	cin >> n >> p >> q; c[0] = p*q;
	for (int i = 0; i < n; i++) { cin >> b[i]; a[i] = b[i] - (q - i)*p; sum += b[i]; }
	sort(a, a + n); maxn = sum;
	for (int i = 0; i < n; i++) {
		sum -= a[i];
		sum += 2 * i * p;
		maxn = max(sum, maxn);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 10952
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin>>n;
    vector<int> a(n),cnt(1000100);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.rbegin(),a.rend());
    for(int i=0;i<n;i++){
        for(int j=a[i];j<=a[0];j+=a[i]){
            cnt[j]++;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(cnt[a[i]]==1) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8008
/*
tarun360
IIT Indore
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define forn_s(i,start,lim) for(ll_s i=start;i<lim;i++)
#define forn_d_s(i,start,lim) for(ll_s i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define debug1(a) cout<<a<<endl
#define debug2(a,b) cout<<a<<" "<<b<<endl
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define debug4(a) cout<<"chu "<<a<<endl

ll dp[1005][1005],a[1005][1005];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll h,w;
  char ch;
  cin>>h>>w;
  forn(i,0,h){
    forn(j,0,w){
      cin>>ch;
      if(ch=='#')
        a[i][j]=-1;
    }
  }
  bool f=true;
  dp[0][0]=1;
  forn(i,1,h){
    if(a[i][0]!=-1 && f==true){
      dp[i][0]=1;
    }else{
      f=false;
      dp[i][0]=0;
    }
  }
  f=true;
  forn(i,1,w){
    if(a[0][i]!=-1 && f==true){
      dp[0][i]=1;
    }else{
      f=false;
      dp[0][i]=0;
    }
  }
  forn(i,1,h){
    forn(j,1,w){
      if(a[i][j]==-1)
        dp[i][j]=0;
      else{
        dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
      }
    }
  }
  cout<<dp[h-1][w-1]<<endl;
  return 0;
}


Measured memory_bytes: 16000
import numpy as np
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    cnt_neg, cnt_zro, cnt_pos = 0, 0, 0
    neg_a, zro_a, pos_a = [], [], []
    n_ap = neg_a.append
    z_ap = zro_a.append
    p_ap = pos_a.append
    for v in a:
        if v < 0:
            cnt_neg += 1
            n_ap(v)
        elif v == 0:
            cnt_zro += 1
            z_ap(v)
        else:
            cnt_pos += 1
            p_ap(v)
    num_neg_pair = cnt_neg * cnt_pos
    num_pos_pair = cnt_neg*(cnt_neg-1)//2 + cnt_pos*(cnt_pos-1)//2
    num_zro_pair = n*(n-1)//2 - num_neg_pair - num_pos_pair
    if k <= num_neg_pair:
        neg_a = np.array(neg_a)
        pos_a = np.array(pos_a)
        l = -1*10**18
        r = 0
        while l+1 < r:
            p = (l+r)//2
            cnt = np.searchsorted(pos_a, p//neg_a, side="riget").sum()
            result = n*cnt_neg - (cnt + (cnt_neg + cnt_zro)*cnt_neg)
            if result < k:
                l = p
            else:
                r = p
        print(l)
    elif k <= num_neg_pair + num_zro_pair:
        print("0")
    else:
        k -= num_neg_pair + num_zro_pair
        for i in range(len(neg_a)):
            neg_a[i] = -neg_a[i]
        neg_a = np.array(neg_a)
        neg_a = np.sort(neg_a)
        pos_a = np.array(pos_a)
        l = 1
        r = 10**18+1
        while l+1 < r:
            p = (l+r)//2
            cnt_1 = np.searchsorted(neg_a, (p+neg_a-1)//neg_a, side="left").sum()
            cnt_2 = np.searchsorted(pos_a, (p+pos_a-1)//pos_a, side="left").sum()
            cnt_1 -= np.count_nonzero(neg_a < (p+neg_a-1)//neg_a)
            cnt_2 -= np.count_nonzero(pos_a < (p+pos_a-1)//pos_a)
            result = (cnt_1 + cnt_2)//2
            if result < k:
                l = p
            else:
                r = p
        print(l)

if __name__ == "__main__":
    main()


Measured memory_bytes: 32688
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
const int maxn=1e5+10;
int n,q,pos,timer,head[maxn],pre[maxn];
int vis[maxn],low[maxn],w[maxn];
struct node
{
	int next,to;
}fbk[maxn*2];
void add(int u,int v)
{
	fbk[++pos].next=head[u];
	fbk[pos].to=v;
	head[u]=pos;
}
void dfs(int u,int fa)
{
	w[u]=low[u]=++timer;
	vis[u]=1;
	for(int i=head[u];i;i=fbk[i].next)
	{
		int v=fbk[i].to;
		if(!vis[v])
		{
			pre[v]=u;
			dfs(v,u);
			low[u]=min(low[u],low[v]);
		}else if(v!=fa)
		{
			low[u]=min(low[u],w[v]);
		}
	}
}
int main()
{
	int a,b;
	cin>>n>>q;
	for(int i=1;i<=q;i++)
	{
		scanf("%d%d",&a,&b);
		add(a,b);
		add(b,a);
	}
	pre[0]=-1;
	dfs(0,-1);
	set<int>yukino;
	int hachiman=0;
	for(int i=1;i<n;i++)
	{
		if(pre[i]==0) hachiman++;
		else if(w[pre[i]]<=low[i])
		{
			yukino.insert(pre[i]);
		}
	}
	if(hachiman>1) yukino.insert(0);
	for(auto it=yukino.begin();it!=yukino.end();it++)
	{
		cout<<*it<<endl;
	}
}


Measured memory_bytes: 4508
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n, k;
		int a[];
		int num;
		int sum, max;

		n = sc.nextInt();
		k = sc.nextInt();
		while (n + k != 0) {
			sum = 0;
			max = 0;
			a = new int[n];
			for (int i = 0; i < k; i++) {
				a[i] = sc.nextInt();
				sum += a[i];
				max = sum;
			}
			for (int i = k; i < n; i++) {
				a[i] = sc.nextInt();
				sum -= a[i - k];
				sum += a[i];
				if (max < sum) {
					max = sum;
				}
			}
			System.out.println(max);
			n = sc.nextInt();
			k = sc.nextInt();
		}
	}
}

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

struct edge{ int to; long long int cost; int id; };
vector<vector<edge>> graph;
vector<bool> used;
vector<vector<set<long long int>>> condition;

void DFS(int v, long long int vi, int parity){
    for(edge e : graph[v]){
        if(used[e.id] == true) continue;

        used[e.id] = true;
        condition[e.to][(parity+1)%2].insert(e.cost - vi);
        DFS(e.to, e.cost-vi, parity+1);
    }
    return ;
}

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

    graph.resize(n);
    used.assign(m, false);
    condition.resize(n, vector<set<long long int>>(2));

    for(int i=0; i<m; i++){
        int u, v;
        long long s;
        cin >> u >> v >> s;
        u -= 1;
        v -= 1;
        graph[u].push_back({v,s,i});
        graph[v].push_back({u,s,i});
    }

    condition[0][0].insert(0);
    DFS(0,0,0);

    long long int lower = 1, upper = 1e9 - 1;
    for(int i=0; i<n; i++){
        if(condition[i][0].size() >= 2
        || condition[i][1].size() >= 2){
            cout << 0 << endl;
            return 0;
        }
        else if(condition[i][0].empty() == false && condition[i][1].empty() == false){
            lower = (*condition[i][1].begin() - *condition[i][0].begin());
            if(lower % 2 == 1){
                cout << 0 << endl;
                return 0;
            }
            lower /= 2;
            upper = lower;
        }
        else if(condition[i][0].empty() == false) lower = max(lower, 1 - *condition[i][0].begin());
        else if(condition[i][1].empty() == false) upper = min(upper,     *condition[i][1].begin() - 1);

        if(lower > upper){
            cout << 0 << endl;
            return 0;
        }
    }
    long long int ans = upper - lower + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 40920
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]

using namespace std;

string to_hex(int x)
{
    stringstream ss;
    ss << hex << x;
    return ss.str();
}

inline int get_int()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}

inline vector<int> get_ints(int n)
{
    vector<int> ret(n);
    FOR(i, n)
    {
        scanf("%d", &ret[i]);
    }
    return ret;
}

inline string get_str()
{
    string ret;
    cin >> ret;
    return ret;
}

bool is_prime(int n)
{
    int s = sqrt(n) + 1;
    for (int i = 2; i <= s; ++i)
    {
        if (n % i == 0)
        {
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n)
{
    vector<P> ret;
    int s = sqrt(n) + 1;
    int c = 0;
    for (int i = 2; i <= s; ++i)
    {
        if (n % i == 0)
        {
            c = 0;
            do
            {
                ++c;
                n /= i;
            } while (n % i == 0);
            ret.push_back(P(i, c));
        }
    }
    return ret;
}

string to_string(string s)
{
    return s;
}

template <class T>
string to_string(vector<T> v)
{
    string ret = "{";
    FOR(i, v.size() - 1)
    {
        ret += to_string(v[i]) + ",";
    }
    if (v.size() > 0)
    {
        ret += to_string(LAST(v));
    }
    ret += "}";
    return ret;
}

void debug()
{
    cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail)
{
    cerr << " " << to_string(head);
    debug(tail...);
}

int main()
{
    int N, K;
    cin >> N >> K;
    int D[10] = {};
    FOR(i, K)
    {
        int d;
        cin >> d;
        D[d] = 1;
    }
    int x = 1;
    while(1){
        string s=to_string(N);
        bool f=1;
        for(int i=0;i<s.size();++i){
            if(D[s[i]-'0']==1){
                f=0;
            }
        }
        if(f)break;
        ++N;
    }
    cout<<N<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main() {

	int int_flag[64] = { 0 };	//64フラグ、初期値全て0


	int int_q;	//命令の個数
	int int_query;	//命令種別番号
	int int_i;	//該当番号


	int int_lcount1;	//繰り返し数
	int int_lcount2;

	int int_fcount;	//フラグ数カウント用
	unsigned long long long_long_val;	//状態の整数値（2進数を10進数にしたもの）


	scanf("%d", &int_q);	//命令（繰り返し）数入力

	for (int_lcount1 = 0; int_lcount1 < int_q; int_lcount1++) {
		scanf("%d", &int_query);
		switch (int_query)
		{
		case 0:		//test(i):i番目のフラグの状態がONの場合1、OFFの場合0を出力する
			scanf("%d", &int_i);
			if (int_flag[int_i] == 1) {
				printf("1\n");
			}
			else {
				printf("0\n");
			}
			continue;

		case 1:		//set(i):i番目のフラグをONにする
			scanf("%d", &int_i);
			int_flag[int_i] = 1;
			continue;

		case 2:		//clear(i):i番目のフラグをOFFにする
			scanf("%d", &int_i);
			int_flag[int_i] = 0;
			continue;

		case 3:		//flip(i):i番目のフラグを反転する
			scanf("%d", &int_i);
			if (int_flag[int_i] == 1) {
				int_flag[int_i] = 0;
			}
			else {
				int_flag[int_i] = 1;
			}
			continue;

		case 4:		//all: 全てのフラグがONになっている場合1、なっていない場合0を出力する
			long_long_val = 0;
			for (int_lcount2 = 0; int_lcount2 < 64; int_lcount2++) {
				long_long_val += int_flag[int_lcount2] *(long long) pow(2, (int_lcount2));
			}
			if (long_long_val == 0xffffffffffffffff) printf("1\n");
			else printf("0\n");
			continue;

		case 5:		//any: 何れかのフラグがONになっている場合1、なっていない場合0を出力する
			long_long_val = 0;
			for (int_lcount2 = 0; int_lcount2 < 64; int_lcount2++) {
				long_long_val += int_flag[int_lcount2] * (long long)pow(2, (int_lcount2));
			}
			if (long_long_val>=1) printf("1\n");
			else printf("0\n");
			continue;

		case 6:		//none: 全てのフラグがOFFになっている場合1、なっていない場合0を出力する
			long_long_val = 0;
			for (int_lcount2 = 0; int_lcount2 < 64; int_lcount2++) {
				long_long_val += int_flag[int_lcount2] * (long long)pow(2, (int_lcount2));
			}
			if (long_long_val == 0) printf("1\n");
			else printf("0\n");
			continue;

		case 7:		//count: ONになっているフラグの数を出力する
			int_fcount = 0;
			for (int_lcount2 = 0; int_lcount2 < 64; int_lcount2++) {
				if (int_flag[int_lcount2] == 1) {
					int_fcount++;
				}
			}
			printf("%d\n", int_fcount);
			continue;

		case 8:		//val: 状態の整数値を出力する
			long_long_val = 0;
			for (int_lcount2 = 0; int_lcount2 < 64; int_lcount2++) {
				long_long_val += int_flag[int_lcount2] * (long long)pow(2, (int_lcount2));
			}
			printf("%llu\n", long_long_val);
			continue;

		default:
			continue;
		}
	}
	return 0;
}


Measured memory_bytes: 2048
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <queue>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _sc _il bool scan
_T T in(int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_il int in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _ot _il void out
#define _ol _il void outl
_ot(bool b) {pcu('0'+b);}
_ot(const char *s){while(*s)pcu(*s++);}
_ot(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_ot(string s){for(char c:s)pcu(c);}
#endif
_T _ot(T n){static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_ol(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _ot(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _ot(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _ol(T&&... t){out(move(t)...);outl();}

struct map {
	struct node {int x, y, c;};
	int c;
	vector<vector<bool>> t;
	map(int i) : c(i), t(i * 2 + 1, vector<bool>(i * 2 + 1, true)) {}
	void put(int x, int y) {
		t[y][x] = false;
	}
	int walk(int x, int y, int c) {
		static const int tx[] = {1, 0, -1, -1, 0, 1}, ty[] = {0, -1, -1, 0, 1, 1};
		queue<node> q;
		q.push({x, y, c});
		put(x, y);
		int r = 1;
		while (!q.empty()) {
			node n = q.front();
			q.pop();
			if (n.c--)
				for (int i = 0; i < 6; i++) {
					int nx = n.x + tx[i], ny = n.y + ty[i];
					if (t[ny][nx]) {
						q.push({nx, ny, n.c});
						put(nx, ny);
						r++;
					}
				}
		}
		return r;
	}
};

int main() {
	for (int t, n; t = in(), n = in(), t || n;) {
		map m(30 + t);
		while (n--) {
			int x = in(), y = in();
			m.put(x + m.c, y + m.c);
		}
		int x = in(), y = in();
		outl(m.walk(x + m.c, y + m.c, t));
	}
}


Measured memory_bytes: 2532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
ll h , w ;
const ll INF = 1LL << 60; //MAX 9223372036854775807

bool inarea(ll x,ll y){
  return x >= 0 && y >= 0 && x < h && y < w ;
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main()
{
cin >> h >> w ;
vector<vector<bool>> v(h, vector<bool>(w,0) );
ll sh , sw ;
cin >> sh >> sw ;
ll gh , gw ;
cin >> gh >> gw ;
rep(i,h)rep(j,w){
  char t ;
  cin >> t ;
  if(t=='#')v[i][j]=1;
}
vector<vector<ll>> d(h, vector<ll>(w,INF) );
d[sh-1][sw-1]=0;
queue<pair<ll,ll>> q,qq;
q.push({sh-1,sw-1});
qq.push({sh-1,sw-1});

while(1){
while(!q.empty()){
  auto p=q.front();
  q.pop();
  qq.push(p);
  rep(i,4){
    if(inarea(p.first+dx[i],p.second+dy[i])&&!v[p.first+dx[i]][p.second+dy[i]]&&d[p.first+dx[i]][p.second+dy[i]]>d[p.first][p.second]){
      d[p.first+dx[i]][p.second+dy[i]]=d[p.first][p.second];
      q.push({p.first+dx[i],p.second+dy[i]});
      qq.push({p.first+dx[i],p.second+dy[i]});
    }
  }
}
while(!qq.empty()){
  auto p=qq.front();
  qq.pop();
  rep(i,25){
    if(inarea(p.first+(i%5)-2,p.second+(i/5)-2)&&!v[p.first+(i%5)-2][p.second+(i/5)-2]&&d[p.first+(i%5)-2][p.second+(i/5)-2]>d[p.first][p.second]+1){
      d[p.first+(i%5)-2][p.second+(i/5)-2]=d[p.first][p.second]+1;
      q.push({p.first+(i%5)-2,p.second+(i/5)-2});
    }
  }
}
if(q.empty())break;
}
if(d[gh-1][gw-1]==INF)d[gh-1][gw-1]=-1;
cout << d[gh-1][gw-1] << endl;
return 0;
}


Measured memory_bytes: 11932
/*************************************************************************
     File Name: c.cpp
     ID: obsolescence
     BLOG: http://blog.csdn.net/obsolescence
     LANG: C++ 
     Mail: 384099319@qq.com 
     Created Time: 2016年07月23日 星期六 20时21分57秒
 ************************************************************************/
#include<bits/stdc++.h>
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)
#define Abs(x,y) ((x)>(y)?((x)-(y)):((y)-(x)))
#define ll long long
#define Mem0(x) memset(x,0,sizeof(x))
#define Mem1(x) memset(x,-1,sizeof(x))
#define MemX(x) memset(x,0x3f,sizeof(x))
#define pb push_back
using namespace std;
const int N=20;
bool flag[N];

int main(){
  int k,i,x,j;
  char n[N],s[N];
  while(~scanf("%s%d",n,&k)){
    Mem0(flag);
    for(i=0;i<k;++i){
      scanf("%d",&x);
      flag[x]=1;
    }
    int len=strlen(n),f1=0,f2=0;
    for(i=0;i<len;++i){
      if(f2){
        for(j=0;j<=9;++j){
          if(flag[j]==0 && j>n[i]-'0'){
            s[i]='0'+j;
            n[i]=s[i];
            break;
          }
        }
        if(j==10){
          if(!i){ f1=1; break; }
          i-=2,f2=1;
          continue;
        }else{
          f2=i;
          break;
        }
      }
      if(flag[n[i]-'0']){
        for(j=0;j<=9;++j){
          if(flag[j]==0 && j>n[i]-'0'){
            s[i]='0'+j;
            n[i]=s[i];
            break;
          }
        }
        //cout<<"i="<<i<<" f1="<<f1<<endl;
        if(j==10){
          if(!i){ f1=1; break; }
          f2=1,i-=2;
          continue;
        }else{
          f2=i;
          break;
        }
      }else s[i]=n[i];
    }
    //cout<<"f1="<<f1<<endl;
    if(f1){
      //cout<<"--------"<<endl;
      for(i=1;i<=9;++i)
        if(flag[i]==0){
          printf("%d",i);
          break;
        }
      for(i=0;i<=9;++i)
        if(flag[i]==0){
          while(len--)printf("%d",i);
          break;
        }
    }else{
      if(i==len)printf("%s",n);
      else{
        for(i=0;i<=f2;++i)
          printf("%c",s[i]);
        for(j=0;j<=9;++j)
          if(flag[j]==0){
            for(;i<len;++i)
              printf("%d",j);
            break;
          }
      }
    }
    puts("");
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  int A,B,C,d[3],count=0,donkaku=0,tyokkaku=0,eikaku=0;
  while(1){
    cin >> A >> B >> C;
    if(((A + B) > C) && ((A + C) > B) && ((B + C) > A)){
      d[0] = A;
      d[1] = B;
      d[2] = C;
      sort(d,d+3);
      if((d[0]*d[0] + d[1]*d[1]) < d[2]*d[2])
        donkaku++;
      else if((d[0]*d[0] + d[1]*d[1]) == (d[2]*d[2]))
        tyokkaku++;
      else
        eikaku++;
      count++;
    }else{
      cout << count << " " << tyokkaku << " " << eikaku << " " << donkaku << endl;
      break;
    }
  }
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}




Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef vector<int> vi;
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
string s[5];
int f[3][3][2020][2020];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	rep (i, 0, 2) cin >> s[i];
	auto calc = [&] (int dp[][2020], string x, string y) {
		per (i, SZ(x) - 1, 0) {
			per (j, SZ(y) - 1, 0) {
				if (x[i] == y[j] || x[i] == '?' || y[j] == '?') {
					dp[i][j] = dp[i + 1][j + 1] + 1;
				}
			}
		}
	};
	auto solve = [&] (vector<int> p) {
		int res = 0x3f3f3f3f;
		rep (i, 0, SZ(s[p[0]]) - 1) {
			if (f[p[0]][p[1]][i][0] != min(SZ(s[p[1]]), SZ(s[p[0]]) - i)) continue;
			int now = max(SZ(s[p[0]]), i + SZ(s[p[1]]));
			res = min(res, now + SZ(s[p[2]])); 
			rep (j, 0, now - 1) {
				int rnow = max(now, j + SZ(s[p[2]]));
				if (j >= SZ(s[p[0]]) || f[p[0]][p[2]][j][0] == min(SZ(s[p[2]]), SZ(s[p[0]]) - j)) {
					int l1 = i, r1 = i + SZ(s[p[1]]) - 1;
					int l2 = j, r2 = j + SZ(s[p[2]]) - 1;
					if (max(l1, l2) <= min(r1, r2)) {
						int l = max(l1, l2), r = min(r1, r2);
						if (f[p[1]][p[2]][l - i][l - j] > r - l) {
							res = min(res, rnow);
						}
					} else {
						res = min(res, rnow);
					}
				}
			}
		}
		return res;
	};
	rep (i, 0, 2) {
		rep (j, 0, 2) if (i != j) {
			calc(f[i][j], s[i], s[j]);
		}
	}
	int res = SZ(s[0]) + SZ(s[1]) + SZ(s[2]);
	vector<int> order({0, 1, 2});
	do {
		res = min(res, solve(order));
	} while (next_permutation(all(order)));
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 102656
/*input
4
141421356 17320508 22360679 244949
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
const int M=1e9+7;
int n, sq=0, s=0;
int a[200005];

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>n;
	for(int i=1; i<=n; ++i){
		cin>>a[i];
	}
	for(int i=2; i<=n; ++i){
		s += a[i]*(a[i-1])%M;
		s %= M;
		(a[i] += a[i-1]) %= M;;
	}
	cout<<s;
	return 0;	
}

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

int main() {
	int H, W;

	while (1) {
		cin >> H >> W;

		if (!H && !W)
			break;

		for (int r = 1; r <= H; r++)
		{
			if (r%2!=0)
			{
				for (int c = 1; c <= W; c++)
				{
					if (c % 2 != 0)
						cout << "#";
					else
						cout << ".";
				}
				cout << endl;
			}
			else
			{
				for (int c = 1; c <= W; c++)
				{
					if (c % 2 == 0)
						cout << "#";
					else
						cout << ".";
				}
				cout << endl;
			}
		}
		cout << endl;

	}

	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<ll> P(N);
  for (ll i = 0; i < N; ++i) {
    cin >> P.at(i);
  }
  ll ans = 0;
  for (ll i = 1; i < N - 1; ++i) {
    if (P.at(i) > min(P.at(i - 1), P.at(i + 1)) && P.at(i) < max(P.at(i + 1), P.at(i - 1))) {
      ans += 1;
    }
  }
  cout << ans << "\n";
}


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

int main() {
    int k;
    cin >> k;
    int ans = -1;
    long long mul = 7;
    for(int digit = 1; digit <= 1e7; digit++) {
        if(mul % k == 0) {
            ans = digit;
            break;
        }
        mul = (mul * 10 + 7) % k;
    }
    cout << ans;
}

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

int main()
{
    int n;
    cin>>n;
    float s[n];
    for(int i=0;i<n;i++)
    {
    cin>>s[i];
    }
    float sum=0;
    for(int i=0;i<n;i++)
    {
    s[i]=1/s[i];
    sum+=s[i];
    }
    cout<<1/sum;
}


Measured memory_bytes: 256