akhauriyash/Code-Regression huggingface dataset:
lists = []
3.times do
  lists << gets.split.map(&:to_i)
end
flat_lists = lists.flatten
n = gets.to_i
called = []
n.times do
  called << gets.to_i
end
ans_lists = Array.new(9, false)
called.each do |i|
  ans_lists[flat_lists.index(i)] = true if flat_lists.include?(i)
end
bingo_lists = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
ans = 'No'
bingo_lists.each do |ary|
  ans = 'Yes' if ans_lists[ary[0]] && ans_lists[ary[1]] && ans_lists[ary[2]]
end
puts ans


Measured memory_bytes: 1788
using System;
using System.Linq;
class Program
{
  static void Main(string[] args)
  {
    // 入力
    long x = long.Parse(Console.ReadLine());
    long q = 0;
    long r = 0;
    string ans = "";

    while (x != 0)
    {
      x--;
      r = x % 26;
      q = x / 26;

      ans += ((char)(r + 97)).ToString();
      //Console.WriteLine($"q = {q}, r = {r}, char = {(char)(r + 97)}");
      x = q;
    }
    Console.WriteLine(new string(ans.Reverse().ToArray()));
  }  
}

Measured memory_bytes: 28200
#include<iostream>
    using namespace std;
    int main(){
      int n,cnt=0;
      int *x;
      cin >> n;
      x=new int[n];
      for(int i=0;i<n;i++){
        cin >> x[i];
        if(x[i]!=i+1)
          cnt++;
      }
      if(cnt<=2)
        cout << "YES\n";
      else
        cout << "NO\n";
     
      delete[] x;
      return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>
#include <map>

using namespace std;

void show(set<int> &s) {
	for (auto e : s) {
		cout << e << " ";
	}
	cout << endl;
}

void show(map<int, set<int>> &m) {
	for (auto p : m) {
		cout << p.first << ": ";
		show(p.second);
	}
}

int main() {
	int n, a, b;
	cin >> n;

	map<int, set<int>> connect;
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b;
		connect[a].insert(b);
		connect[b].insert(a);
	}

	set<int> leaves;
	for (auto p : connect) {
		if (p.second.size() == 1) {
			leaves.insert(p.first);
		}
	}

// cout << "leaf: ";
// show(leaves);
// show(connect);

	while (!leaves.empty()) {
// cout << "leaf: ";
// show(leaves);

		int leaf = *leaves.begin();
		leaves.erase(leaf);

		int leaf_next = *connect[leaf].begin();
		connect.erase(leaf);

		auto next_nexts = connect[leaf_next];
		connect.erase(leaf_next);
// printf("%d - %d - \n", leaf, leaf_next);
// cout << "next_nexts: ";
// show(next_nexts);

		for (auto x : next_nexts) {
// cout << "erase " << x << endl;
			connect[leaf_next].erase(x);
			if (x == leaf) {
// cout << "erase leaf " << x << endl;
				continue;
			}
			connect[x].erase(leaf_next);
// show(connect);
			if (connect[x].size() == 0) {
				cout << "First" << endl;
				return 0;
			} else if (connect[x].size() == 1) {
				leaves.insert(x);
			}
		}
	}

	cout << "Second" << endl;
	return 0;
}


Measured memory_bytes: 21376
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long LL;
char str[200005];
int main(){
	int n;
	cin >> n >> str;
	int fsr = n-1;
	int fsw = 0;
	int cnt = 0;
	while(fsr > fsw){
		while(fsr > 0 && str[fsr]!='R') fsr--;
		while(fsw < n && str[fsw]!='W') fsw++;
		//cout << fsr << ' ' << fsw << endl; 
		if(fsr > fsw){
			 swap(str[fsr],str[fsw]);
			 cnt++;
		}
	}
	cout << cnt;
} 

Measured memory_bytes: 3336
#include<stdio.h>

/* 選択ソート (0オリジン) */
int selectionSort(int A[], int N) {
    int i, j, t, sw = 0, mini;
    for ( i = 0; i < N - 1; i++) {
        mini = i;
        for ( j = i; j < N; j++ ) {
            if ( A[j] < A[mini] ) mini = j;
        }
        t = A[i]; A[i] = A[mini]; A[mini] = t;
        if ( i != mini ) sw++;
    }
    return sw;
}

int main() {
    int A[100], N, i, sw;

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

    sw = selectionSort(A, N);

    for ( i = 0; i < N; i++ ) {
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", sw);

    return 0;
}


Measured memory_bytes: 2764
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
  string s;
  cin >> s;
  int count1 = 0;
  int count2 = 0;

  for (int i = 0; i < s.size(); i++) {
    int j = i % 2;
    count1 += (s[i] == '1') ^ j;
    count2 += (s[i] == '1') ^ (j ^ 1);
  }

  cout << min(count1, count2) << endl;
  return 0;
}


Measured memory_bytes: 512
from collections import deque
n = int(input())

std = deque([])

deque.append(std, ['a', 1])

for i in range(n-1):
    m = len(std)
    for j in range(m):
        tmp = deque.popleft(std)
        tmp_str = tmp[0]
        tmp_val = tmp[1]
        for k in range(tmp_val+1):
            append_chr = chr(ord('a')+k)
            s = tmp_str + append_chr
            if k == tmp_val:
                v = tmp_val+1
            else:
                v = tmp_val
            deque.append(std, [s, v])
            
for s, v in std:
    print(s)

Measured memory_bytes: 24032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> inline void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T> inline T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

bool dp[81][81][13000]={};

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int h,w;cin>>h>>w;
  VV<int> e(h,vector<int> (w,0));
  rep(i,0,h)rep(j,0,w){
    int x;cin>>x;
    e[i][j]+=x;
  }
  rep(i,0,h)rep(j,0,w){
    int x;cin>>x;
    e[i][j]-=x;
  }

  dp[0][0][abs(e[0][0])]=true;
  rep(i,0,h)rep(j,0,w){
    if(i){
      rep(l,0,13000){
        if(dp[i-1][j][l]){
          dp[i][j][abs(l+e[i][j])]=true;
          dp[i][j][abs(l-e[i][j])]=true;
        }
      }
    }
    if(j){
      rep(l,0,13000){
        if(dp[i][j-1][l]){
          dp[i][j][abs(l+e[i][j])]=true;
          dp[i][j][abs(l-e[i][j])]=true;
        }
      }
    }
  }

  rep(i,0,13000){
    if(dp[h-1][w-1][i]){
      cout<<i<<endl;
      return 0;
    }
  }
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?


Measured memory_bytes: 81664
N = int(input())
K = int(input())
x = list(map(int, input().split()))
answer = 0
for i in range(N):
    if x[i] <= abs(K - x[i]):
        answer += 2 * x[i]
    else:
        answer += 2 * abs(K - x[i])

print(answer)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define N 200100
#define Q 1000000007
using namespace std;
int x[N],v[N],a[N],b[N],dv[N];
int l[N],r[N];
int c[N];
bool cmp1(int i,int j){
	return x[i]<x[j];
}
bool cmp2(int i,int j){
	return v[a[i]]<v[a[j]];
}
int sum(int x){
	int r=0;
	while(x){
		r+=c[x];
		r%=Q;
		x-=x&-x;
	}
	return r;
}
void upd(int x,int v){
	while(x<N){
		c[x]=(c[x]+v)%Q;
		x+=x&-x;
	}
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x[i],&v[i]);
		a[i]=b[i]=i;
	}
	sort(a+1,a+n+1,cmp1);
	sort(b+1,b+n+1,cmp2);
	for(int i=1;i<=n;i++) dv[b[i]]=i;
	l[n]=dv[n];
	r[1]=dv[1];
	for(int i=n-1;i>=1;i--) l[i]=min(l[i+1],dv[i]);
	for(int i=2;i<=n;i++) r[i]=max(r[i-1],dv[i]);
	for(int i=1;i<=n;i++){
		int s=sum(r[i]);
		if(l[i]==1) s++;
		else s-=sum(l[i]-2);
		s=(s+Q)%Q;
		upd(r[i],s);
	}
	printf("%d\n",(sum(n)-sum(n-1)+Q)%Q);
	return 0;
}

Measured memory_bytes: 6528
n, m = map(int, input().split())
a = list(map(int, input().split()))
d = dict()
for x in a:
  d[x] = d.get(x, 0) + 1

for _ in range(m):
  b, c = map(int, input().split())
  d[c] = d.get(c, 0) + b

ans = 0
for x in sorted(d.items(), reverse=True):
  if n >= x[1]:
    ans += x[0] * x[1]
    n -= x[1]
  else:
    ans += x[0] * n
    break
print(ans)

Measured memory_bytes: 40608
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first;
#define snd second;
#define ALL(obj) (obj).begin(), (obj).end();
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<lint> a(n);
    lint x;
    for (int i=0; i<n; ++i){
        cin >> a[i];
    }
    for (int t=0; t<q; ++t){
        cin >> x;
        lint res = 0;
        int r = 0;
        lint sum = 0;
        for (int l = 0; l < n; ++l){
            while(r < n && sum + a[r] <= x){
                sum += a[r];
                ++r;
            }
            res += r - l;
            if(r == l){
                ++r;
            }
            else {
                sum -= a[l];
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3492
S = input()
list_S = list(S)
result = [0]*(len(list_S)-2)
for i in range(len(list_S)-2):
  x = 0
  for j in range(3):
    x += int(list_S[i+j]) * 10**(2-j)
  result[i] = abs(753-x)

print(min(result))

Measured memory_bytes: 3060
a,b,C=map(float,input().split())
import math
d=float(math.sin(C/180*math.pi))
c=float(math.sqrt(a**2+b**2-2*a*b*math.cos((C/180)*math.pi)))
h=float('{:.6f}'.format(b*d))
L=float('{:.6f}'.format(a+b+c))
S=float('{:.6f}'.format(a*h*0.5))

print(S,L,h)


Measured memory_bytes: 5696
N=int(input())
L=list(map(int,input().split()))
L.sort()
c=0
for s in range(N-2):
	for t in range(s+1,N-1):
		two=L[s]+L[t]
		if L[s] != L[t]:
			for u in range(t+1,N):
				if L[u] == L[t]:
					c+=0
				elif two > L[u]:
					c+=1
					#print(s,t,u)
				else:
					break
print(c)

Measured memory_bytes: 9188
n, m, k = map(int, input().split())

mod = 10 ** 9 + 7
MAX = n * m

fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact[i] = (fact[i-1] * i) % mod

inv = [1] * (MAX + 1)
inv[MAX] = pow(fact[MAX], mod - 2, mod)
for i in range(MAX, 0, -1):
    inv[i-1] = (inv[i] * i) % mod


def comb(n, k):
    return fact[n] * inv[n-k] * inv[k] % mod


ans = 0
for i in range(n):
    for j in range(m):
        add = (n - i) * (m - j) * (i + j) % mod
        if i != 0 and j != 0:
            add *= 2
            add %= mod

        ans += add
        ans %= mod

ans *= comb(MAX - 2, k - 2)
ans %= mod
print(ans)


Measured memory_bytes: 18804
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long int;



bool col(char t){
    if(t == '#'){return false;}
    else{return true;}
}

void dfs(ll &h, ll &i, ll H, ll W, int y, int x, const vector<vector<char>> &map, vector<vector<bool>> &ald){
    if(y<0||y>=H||x<0||x>=W){return;}
    ald[y][x] = true;
    bool p = col(map[y][x]);
    if(p == true){h++;}
    else{i++;}
    if(y != 0){
    if(col(map[y-1][x]) != p&&!ald[y-1][x]){dfs(h,i, H, W, y-1, x, map, ald);}
    }
    if(x != 0){
    if(col(map[y][x-1]) != p&&!ald[y][x-1]){dfs(h,i, H, W, y, x-1, map, ald);}
    }
    if(y != H-1){
    if(col(map[y+1][x]) != p&&!ald[y+1][x]){dfs(h,i, H, W, y+1, x, map, ald);}
    }
    if(x != W-1){
    if(col(map[y][x+1]) != p&&!ald[y][x+1]){dfs(h, i, H, W, y, x+1, map, ald);}
    }
}

int main(){
    ll H, W;
    cin >> H >> W;
    ll count = 0;
    ll x = 0;
    vector<vector<char>> map(H, vector<char>(W));
    for(int i=0; i<H; i++){
      for(int j=0; j<W; j++){
          cin >> map[i][j];
      }
    }
    vector<vector<bool>> ald(H, vector<bool>(W,false));
    for(int i=0; i<H; i++){
      for(int j=0; j<W; j++){
          
          if(ald[i][j] == false){

          ll h = 0;
          ll g = 0;
          dfs(h,g,H,W,i,j,map,ald);
          x++;
          count += h*g;
          }
      }     
    }

    cout << count;
}


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

const int MAXN = 1000 * 1000 + 10;
const long long INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 10;

long long mod = 1000 * 1000 * 1000 + 7;
int n, k;
int candy[MAXN];

long long dp[200][MAXN]; // dp [number of students][remained candies]
long long sum[MAXN];

void update(int students)
{
    //cerr << "students " << students << endl;

    sum[0] = dp[students - 1][0];

    for(int i = 1; i <= k; i++) sum[i] = (sum[i - 1] + dp[students - 1][i]) % mod;

    dp[students][0] = sum[candy[students - 1]] % mod;
    //cerr << "i " << 0 << ' ' << dp[students][0] << endl;

    for(int i = 1; i <= k; i++){
        dp[students][i] = (mod + sum[min(candy[students - 1] + i, k) ] - sum[i - 1]) % mod;
        //cerr << "i " << i << ' ' << dp[students][i] << endl;
    }
}

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


    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> candy[i];

    dp[0][k] = 1;

    for(int i = k - candy[0]; i <= k; i++) dp[1][i] = 1;

    for(int i = 2; i <= n; i++) update(i);

    cout << dp[n][0] % mod << endl;


    return 0;
}



Measured memory_bytes: 82920
def check(q):
    if q % 15 == 0:
        return 0
    elif q %5 == 0:
        return 0
    elif q % 3 == 0:
        return 0
    else:
        return q

a = int(input())
b = 0

if a <= 10000000 and a >= 1:

    for i in range(a+1):
        b += check(i)
        
print(b)


Measured memory_bytes: 9192
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(A),
    get_number(B),
    get_number(H),
    X is (A + B) * H div 2,
    writeln(X).


Measured memory_bytes: 8064
N = int(input())
a = [input().split() for i in range(2)]
candy = [int(a[i][j]) for i in range(2) for j in range(N)]
MAX = 0

for i in range(N):
    MAX = max(MAX, sum(candy[:i+1]) + sum(candy[i+N:]))

print(MAX)

Measured memory_bytes: 3060
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    var n = parseInt(input[0], 10);
    var h = input[1].split(" ");
    var count = 0;
    var max = count;
    for (var i = 0; i < (n - 1); i++) {
        if (parseInt(h[i]) >= parseInt(h[i + 1])) {
            count++;
        } else {
            count = 0;
        }
        if (count > max) {
            max = count;
        }
    }
    //出力
    console.log('%s', max);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 19532
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {
	os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T,class U> ostream& operator<<(ostream &os, const tuple<S,T,U> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class S, class T,class U,class V> ostream& operator<<(ostream &os, const tuple<S,T,U,V> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<","<<get<3>(t)<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef _DEBUG
#ifdef _DEBUG
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
#else
#define out
#endif
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
	string s;
	cin>>s;
	vector<int> cnt(200);
	for(char c:s) ++cnt[c];
	vector<int> v={cnt['a'],cnt['b'],cnt['c']};
	sort(all(v));
	cout<<(v[2]-v[0]<=1?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

using namespace std;


int main(){

    int n,k;
    cin >> n >> k;
    int ans = 0;

    rep(i,n){
        int tmp;
        cin >> tmp;
        if(k <= tmp) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;

typedef pair<int, int> P;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };

ll a[100100], x[510];
int main() {
	a[0] = 0;
	int N, Q;
	cin >> N >> Q;
	REP(i, N) {
		ll c; cin >> c;
		a[i + 1] = a[i] + c;
	}
	REP(i, Q)cin >> x[i];
	REP(k, Q) {
		ll ans = 0;
		ll sum = 0;
		int right = 1;
		FOR(left, 0, N) {
			while (right < N + 1 && (a[right] - a[left]) <= x[k]) {
				right++;
			}
			ans += (right - left-1);
			if (right == (left + 1))right++;
		}
		cout << ans << endl;
	}
}



Measured memory_bytes: 3876
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;


/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/

int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
       ll x;
       cin>>x;
       int ans=((log(x)/log(2)));
       ans++;
       cout<<power(2,ans)-1<<endl;
 }
}















Measured memory_bytes: 3852
N, K = map(int, input().split())
p = list(map(int, input().split()))

import numpy as np

data = np.array(p) + 1

Pcum = np.zeros(N + 1, np.int32)
Pcum[1:] = data.cumsum()

length_K_sums = Pcum[K:] - Pcum[0:-K]

print(np.max(length_K_sums)/2)


Measured memory_bytes: 39000
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<vector<ll>>> vvvll;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================





int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================
	

	ll N;
	cin >> N;
	vll A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		A[i]--;
	}

	ll ans = 0;
	for (int i = 0; i < N; i++)
	{
		if (A[A[i]] == i)
		{
			ans++;
		}
	}


	cout << ans / 2 << endl;






}





Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int a, b;

  cin >> a >> b;

  int m = a*b;
  int s = a-b;
  int ad = a+b;
  
  cout << max(m,max(s, ad)) << endl;
}


Measured memory_bytes: 768
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;wahile(t--) 
const int maxx  = 3*1e5 , limit = 1e17 , MOD=1e9+7;
string binary(int n){bitset<32>b(n) ;string p =b.to_string();return p;}
int decimal(string s){int res = 0; for(int i = 0; i < s.size() ; i++ ){if(s[i] == '1')res = res + pow(2,s.size() - i -1);}    return res;}
bool isPrime(int n){if (n <= 1) return false; if (n <= 3) return true;if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
int pow (int x, int n,int mod) {if (n == 0) return 1; int res = pow (x, n / 2,mod);res = (res * res) % mod;if (n % 2) res = (res * x ) % mod;return res;}
#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int32_t main(){
    boost;
    
    int s,w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe\n";
    }else cout<<"safe\n";
}

Measured memory_bytes: 3672
#include<iostream>
#include<vector>
#include<unordered_map>
#include<unordered_set>
#include<cmath>
#include<algorithm>
using namespace std;

//input
int N;
vector<int> A;

unordered_map<int, int> d;
unordered_set<int> s;


void divisor(int n) {
    for (int i = 1; i < int(sqrt(n)) + 1; ++i) {
        if (n % i == 0) {
            s.insert(i);
            s.insert(n / i);
        }
    }
    return;
}

int main(){
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < 2; ++i) divisor(A[i]);
    int ans = 1;

    for (int i = 0; i < N ; ++i) {
        for (auto itr = s.begin(); itr != s.end(); ++itr) {
            if (A[i] % *itr == 0) d[*itr]++;
        } 
    }

    for (auto itr = d.begin(); itr != d.end(); ++itr) {
        if (itr->second >= N - 1) ans = max(ans, itr->first);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ins insert
#define sz(x) (long long)x.size()
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5;
const ld pi = 3.141592653;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll INF = __LONG_LONG_MAX__;

using namespace std;

int dx[9] = {1, -1, 0, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 0, 1, -1, 1, -1, 1, -1, 0};

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int T = 1;
        //cin>>T;
        while(T--)
        {
                string t = "ACL";
                int k; cin>>k;
                for(int i = 0; i<k; i++) cout<<t;
        }
        return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    map<char, char> m;
    m['A'] = 'T';
    m['T'] = 'A';
    m['C'] = 'G';
    m['G'] = 'C';

    char b; cin >> b;
    cout << m[b] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m) res -= m;
	if(res < 0){
		if(res <= -m) res += m<<1;
		else res += m;
	}
	return res;
}

ll mul(ll a, ll b, ll m = MOD){ 
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 1000+5;

int n, m;
char table[N][N];
bool vis[N][N];
int memo[N][N];
int dx[] = {1,0};
int dy[] = {0,1};

bool validPos(int i, int j){
	return i >= 0 and j >= 0 and i < n and j < m;
}

int DP(int x, int y){
	if(x == n-1 and y == m-1) return 1;
	if(vis[x][y]) return memo[x][y];
	int ans = 0;
	for(int i=0; i<2; i++){
		int vx = x + dx[i];
		int vy = y + dy[i];
		if(validPos(vx,vy) and table[vx][vy] != '#'){
			ans = add(ans,DP(vx,vy));
		}
	}
	vis[x][y] = true;
	return memo[x][y] = ans;
}

int main(){
	ri2(n,m);
	for(int i=0; i<n; i++){
		scanf("%s",table[i]);
	}
	printf("%d\n",DP(0,0));
	return 0;
}


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

int main(void)
{
   char a[11], b[11], c[11];

   scanf("%s%s%s",a,b,c);

   if((a[strlen(a)-1]==b[0]) && (b[strlen(b)-1]==c[0]))
     printf("YES\n");
   else printf("NO\n");
  
   return 0;
}


Measured memory_bytes: 128
N,K = map(int,input().split())
A = list(map(int,input().split()))
plusminus = [0]*len(A)
plusor0 = [0]*len(A)
plusminus[0] = A[0]
plusor0[0] = max(0,A[0])
for i in range(1,N):
  plusminus[i] = plusminus[i-1]+A[i]
  plusor0[i] = plusor0[i-1]+max(0,A[i])
plusminus.insert(0,0)
plusor0.insert(0,0)
ans = 0
for i in range(N-K+1):
  s = plusminus[i+K]-plusminus[i]
  if i == 0:
    s += plusor0[N]-plusor0[K]
  elif i == N-K:
    s += plusor0[N-K]
  else:
    s += plusor0[i]+plusor0[N]-plusor0[i+K]
  if ans <= s:
    ans = s
for i in range(N-K+1):
  s = 0
  if i == 0:
    s += plusor0[N]-plusor0[K]
  elif i == N-K:
    s += plusor0[N-K]
  else:
    s += plusor0[i]+plusor0[N]-plusor0[i+K]
  if ans <= s:
    ans = s
print(ans)

Measured memory_bytes: 17996
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <vector>

#define rep2(i, b, n) for(int i=b; i < n; ++i)
#define repm(i, b, n) for(int i=b; i > n; --i)
#define rep(i, n) rep2(i, 0, n)
#define sz(v) v.size()
#define mp(x, y) make_pair(x, y)
#define fst first
#define scd second

using namespace std;

typedef pair<int, int> pii;

int main ( void )
{
	int n, t, h, l;
	
	pii p[100];
	
	while (cin >> n >> t >> h >> l)
	{
		for (int i = 0; i < n; i += 1)
		{
			cin >> p[i].fst >> p[i].scd;
		}
		
		int kin, ans;
		kin = ans = 0;
		
		while(1)
		{
			if (p[ans].fst == 0)
			{
				if (p[ans].scd == 0)
				{
					break;
				}
				else
				{
					kin += 100;
					--p[ans].scd;
					++h;
				}
			}
			else
			{
				kin += 10;
				--p[ans].fst;
				++t;
			}
			
			if (t > l) // over
				break;
			else if (kin >= 90)
			{
				int sub = (kin - 90) / 10;
				if (t >= sub)
				{
					t -= sub;
					p[ans].fst += sub;
					kin = 0;
				}
				else
					break;
			}
			ans = (ans + 1) % n;
		}
		
		cout << (ans + 1) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int n,i;
    cin >> n >> i;
    int ans = n-i+1;
    cout << ans << endl;
}

Measured memory_bytes: 3652
N = int(input())
reds = [list(map(int, input().split())) for i in range(N)]
blues = [list(map(int, input().split())) for i in range(N)]

reds.sort(key=lambda x: x[1], reverse=True)
blues.sort()

done = [False] * N
ans = 0
for bx, by in blues:
    for i, (rx, ry) in enumerate(reds):
        if done[i]: continue
        if rx < bx and ry < by:
            ans += 1
            done[i] = True
            break

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
#define ll long long
#define ld long double
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];


const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

vector<string> field;

/* if bfs

   queue<pair<int, int> > que
   que.push(start x, start y);

   int dist[x][y];
   memset(dist, -1, sizeof(dist));
   dist[start x][start y] = 0;
*/


// int N; cin >> N;
// field.resize(N);
int main() {
  int N, M; cin >> N >> M;
  rep(i, N) {
    string S; cin >> S;
    field.push_back(S);
  }
  set<int> Row, Column;
  rep(i, N) {
    rep(j, M) {
      if (field[i][j] == '#') {
        Row.insert(i);
        Column.insert(j);
      }
    }
  }
  
  rep(i, N) {
    int flag = 0;
    rep(j, M) {
      if (Row.count(i) && Column.count(j)) {
        cout << field[i][j];
        flag = 1;
      }
    }
    if (flag) cout << endl;
  }
}


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

int main()
{
	int n,k; cin>>n>>k; int a[n],dp[n];
	for (int i=0; i<n; i++)
	{
		cin>>a[i];
		dp[i]=INT_MAX;
	}
	dp[0]=0;
	for (int i=1; i<n; i++)
	{

		for (int j=1; j<=i && j<=k; j++)
			dp[i] = min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int mat[60][60];
  rep(i, 60) {
    rep(j, 60) {
      mat[i][j] = 0;
    }
  }

  int h, w; cin >> h >> w;
  vector<string> s(h);
  rep(i, h) {
    cin >> s.at(i);
  }

  rep(i, h) {
    rep(j, w) {
      if (s.at(i).at(j) == '#') {
        mat[i][j]++;
        mat[i][j+1]++;
        mat[i][j+2]++;
        mat[i+1][j]++;
        mat[i+1][j+1] = 9;
        mat[i+1][j+2]++;
        mat[i+2][j]++;
        mat[i+2][j+1]++;
        mat[i+2][j+2]++;
      }
    }
  }

  for(int i=1; i<=h; i++) {
    for(int j=1; j<=w; j++) {
      if (mat[i][j] >= 9) {
        cout << '#';
      } else {
        cout << mat[i][j];
      }
    }
    cout << endl;
  }
}

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

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

typedef long long ll;

int check(int x) {
	int i = 2;
	while (i * i <= x) {
		if (x % i == 0) {
			x /= i;
			return 0;
		}
		i++;
	}
	return 1;
}

int main()
{
	/*string s, t;
	cin >> s >> t;
	t += s;
	cout << t;*/


	/*ll a, b, k;
	cin >> a >> b >> k;
	ll a2 = a;
	a = max(a - k, 0ll);
	k -= a2 - a;
	b = max(b - k, 0ll);
	printf("%lld %lld", a, b);*/


	int x;
	cin >> x;
	int i;
	for (i = x;; i++) {
		if (check(i)) {
			cout << i;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Diagnostics;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var c = s.IndexOf('C');
            var f = s.LastIndexOf('F');
            var result = c >= 0 && f >= 0 && c < f ? "Yes" : "No";
            Console.WriteLine(result);
        }
    }

    public static class Ex
    {
        public static int ToInt(this string str) => int.Parse(str);
    }
}


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

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int grid[22][22];

vector<int> output;

struct D {
  int x,y;
};

struct P {
  int x,y;
  vector<D> del;
};

void solve(int,int);

int main () {
  int w,h;
  while(cin>>w>>h,w|h)
    solve(w,h);
  for(int i=0;i<output.size();++i)
    cout<<output[i]<<endl;
}

void solve (int w,int h) {
  int sx,sy;
  for(int j=1;j<=h;++j) {
    for(int i=1;i<=w;++i) {
      int a;cin>>a;
      if(a==2){
	sx=i,sy=j;
	grid[i][j]=0;
      }else{
	grid[i][j]=a;
      }
    }
  }
  for(int i=0;i<=h+1;++i)grid[0][i]=grid[w+1][i]=4;
  for(int i=0;i<=w+1;++i)grid[i][0]=grid[i][h+1]=4;
  queue<P> q;q.push((P){sx,sy,vector<D>()});
  for(int k=1;k<=10;++k){
    int qc=q.size();
    for(int m=0;m<qc;++m){
      P p=q.front();q.pop();
      int x=p.x,y=p.y;
      vector<D> del=p.del;
      for(auto itr=del.begin();itr!=del.end();++itr)grid[itr->x][itr->y]=0;
      for(int i=0;i<4;++i){
	int dmx=dx[i],dmy=dy[i],mx=x+dmx,my=y+dmy;
	int s=grid[mx][my];
	if(s==3){output.push_back(k);return;}
	if(s==0){
	  do{
	    mx+=dmx;my+=dmy;
	    s=grid[mx][my];
	  }while(s==0);
	  if(s==1){
	    del.push_back((D){mx,my});
	    q.push((P){mx-dmx,my-dmy,del});
	    del.pop_back();
	  }else if(s==3){output.push_back(k);return;}
	}
      }
      for(auto itr=del.begin();itr!=del.end();++itr)grid[itr->x][itr->y]=1;
    }
  }
  output.push_back(-1);
}

Measured memory_bytes: 12376
# 雰囲気で書いたら通ってしまったがなんで通ったかわからん
# i<jという前提を無視しているのではと感じる

N = int(input())
A = list(map(int, input().split()))
# i<jとして、条件は j-i = A_i + A_j
# i + A_i = j - A_j

dict1 = {}
for i in range(1, N + 1):
    tmp = i + A[i - 1]
    if tmp not in dict1:
        dict1[tmp] = 1
    else:
        dict1[tmp] += 1

dict2 = {}
for i in range(1, N + 1):
    tmp = i - A[i - 1]
    if tmp not in dict2:
        dict2[tmp] = 1
    else:
        dict2[tmp] += 1

# print(dict1, dict2)
ans = 0
for k, v in dict1.items():
    if k in dict2:
        ans += v * dict2[k]
print(ans)


Measured memory_bytes: 59468
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n;
    cin >> n;
    int Min = 2e5+1, ans = 0;
    rep(i,n){
        int p;
        cin >> p;
        if(Min >= p) ans++;
        Min = min(Min, p);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  
  double t = ((h * 5) + (5.0 * m / 60.0) - m) * M_PI / 30.0;
  double ans = sqrt(a * a + b * b - 2.0 * a * b * cos(t));
  cout << setprecision(20) << ans << endl;
  return 0;
}



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

typedef pair<long long, int> li;
const int N = 100005;
const long long INF = 1e18;

int n, m, cost;
long long sum, res = INF;
long long d[N];
bool visit[N];
vector<li> G[N];

void dijkstra() {
	priority_queue<li> pq;
	for (int i = 1; i <= n; ++i) d[i] = INF;
	pq.push(li(0, 1)), d[1] = 0;
	
	while (pq.size()) {
		int u = pq.top().second;
		long long du = -pq.top().first;
		pq.pop();

		if (du != d[u]) continue;

		for (auto v : G[u]) {
			if (d[v.second] > d[u] + v.first) {
				d[v.second] = d[u] + v.first, pq.push(li(-d[v.second], v.second));
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m >> cost;
	for (int i = 0; i < m; ++i) {
		int u, v, w;
		cin >> u >> v >> w;
		G[u].push_back(li(w, v));
		G[v].push_back(li(w, u));
		sum += w;
	}

	dijkstra();

	vector<li> go;
	for (int i = 1; i <= n; ++i) {
		go.push_back(li(d[i], i));
	}
	sort(go.begin(), go.end());

	for (int i = 0; i < n; ++i) {
		visit[go[i].second] = 1;
		for (auto v : G[go[i].second]) {
			if (visit[v.second]) sum -= v.first;
		}
		res = min(res, cost * go[i].first + sum);
	}

	cout << res << '\n';
}

Measured memory_bytes: 19440
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{

	public static void main(String[] args) {
		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		String str="";
		StringTokenizer stk;

		try {
			str=bfr.readLine();

			if(str.equals("")) {
				System.exit(0);
			}

			else {
				int gatu,nichi;
				stk=new StringTokenizer(str," ");
				gatu=Integer.parseInt(stk.nextToken());
				nichi=Integer.parseInt(stk.nextToken());

				if(gatu<=nichi) {
					System.out.println(gatu);
				}

				else if(gatu>nichi) {
					System.out.println(gatu-1);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		catch(NumberFormatException ee) {
			System.exit(0);
		}

		catch(NullPointerException eee) {
			System.exit(0);
		}

	}
}

Measured memory_bytes: 21076
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
vector<bool> seen;

void dfs(vector<vector<int>> &g, int v){
    seen[v]=true;
    for (int j=0;j < g[v].size();j++){
        if (seen[j]) continue;
        else if (g[v][j]==0) continue;
        else dfs(g,j);
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> edge(n,vector<int> (n,0));
    vector<pair<int,int>> edges(m);
    seen.resize(n,false);
    for (int i=0;i < m;i++){
        int x,y;
        cin >> x >> y;
        x--;y--;
        pair<int,int> p=make_pair(x,y);
        edges[i]=p;
        edge[x][y]=1;
        edge[y][x]=1;
    }
    int count=0;
    int ans=0;
    for (int j=0;j <m;j++){
        pair<int,int> p=edges[j];
        edge[p.first][p.second]=0;
        edge[p.second][p.first]=0;
        for (int v=0;v < n;v++){
            if (seen[v]) continue;
            dfs(edge,v);
            count++;
        }
        if (count!=1) ans++;
        //printf("(x,y)=(%d,%d) count = %d\n",p.first,p.second,count);
        rep(i,n) seen[i]=false;
        count=0;
        edge[p.first][p.second]=1;
        edge[p.second][p.first]=1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package MyApp;
use utf8;
use 5.016;

print func(map { chomp; $_ } <>);

sub func {
    my ($n, $m) = split / /, shift;
    my ($min, $max) = (1, $n);
    while (my $line = shift) {
        my ($l, $r) = split / /, $line;
        $min = $l if $l > $min;
        $max = $r if $r < $max;
    }
    my $result = 0;
    $result = $max - $min + 1 if $max >= $min;
    return join("\n", $result, '');
}

1;
__END__


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


int main() {
    int A,B,T;
    cin>>A>>B>>T;
    int count=0;
    int a=A;
    while(T>=a){
        count +=B;
        a+=A;
    }
    cout<<count<<endl;
}

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

int main() {
    int n; cin>>n;
    for(int i=0; i<n; i++){
        string order, message;
        cin>>order>>message;
        reverse(order.begin(), order.end());
        for(char c : order){
            if(c == 'J'){
                rotate(message.rbegin(), message.rbegin()+1, message.rend());
            }else if(c == 'C'){
                rotate(message.begin(), message.begin()+1, message.end());
            }else if(c == 'E'){
                if(message.size()%2 == 0){
                    message = message.substr(ceil(message.size()/2.0), message.size()) + message.substr(0, message.size()/2);
                }else{
                    int index = message.size()/2;
                    message = message.substr(ceil(message.size()/2.0), message[index]) + message[index] + message.substr(0, message.size()/2);
                }
            }else if(c == 'A'){
                reverse(message.begin(), message.end());
            }else if(c == 'P'){
                for(int j=0; j<message.size(); j++){
                    if(isdigit(message[j])){
                        int digit = stoi(message.substr(j,1).c_str());
                        message[j] = to_string(digit == 0 ? 9 : digit-1)[0];
                    }
                }
            }else{
                for(int j=0; j<message.size(); j++){
                    if(isdigit(message[j])){
                        int digit = stoi(message.substr(j,1).c_str());
                        message[j] = to_string((digit+1)%10)[0];
                    }
                }
            }
        }
        cout << message << endl;
    }
}



Measured memory_bytes: 3216