akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <stdio.h>

constexpr unsigned int MAX_INPUT = 4e5 + 5e4;
char Input[MAX_INPUT];
char* input = Input;

template <class Integer = long long int>
inline Integer get(void){
    Integer res = 0;
    if(*input == '-'){
        while(*(++input) >= '0'){ res = 10 * res + *input - '0'; }
        return -res;
    }
    do{ res = 10 * res + *(input++) - '0'; } while(*input >= '0');
    return res;
}

struct circle{
    long long int x, y;
    int radius;
    circle(void):x(),y(),radius(){}
    static double distance(const long long int dx, const long long int dy){
        return __builtin_sqrt(dx * dx + dy * dy);
    }
    inline void in0(void){x = get(); input++; y = get(); input++;}
    inline void in(void){ x = get(); input++; y = get(); input++; radius = get<int>(); input++;}
    inline double distance(const circle& other){
        double d = distance(x - other.x, y - other.y) - (radius + other.radius);
        return (d < 0) ? 0 : d;
    }
};

inline void chmin(double& v, const double val){ if(v > val) v = val; }

using uint = unsigned int;
constexpr uint MAX_N = 1000;
constexpr double inf = 3e18 + 3e17 + 4e16;
circle Point[MAX_N + 2];
bool visited[MAX_N + 2];
double dist[MAX_N + 2];

int main(void){
    fread_unlocked(Input, sizeof(char), MAX_INPUT, stdin);

    Point[0].in0(); Point[1].in0();

    uint n = get(); input++;
    Point[++n] = Point[1]; dist[n] = inf;

    for(uint i = 1; i < n; ++i) { Point[i].in(); dist[i] = inf;}

    for(uint _ = 0, s = 0; _ < n; ++_){
        double min = inf; uint nearest = 0; visited[s] = true;
        for(uint v = 1; v <= n; ++v) if(not visited[v]){
            const double d = Point[s].distance(Point[v]);
            chmin(dist[v], dist[s] + d);
            if(min > dist[v]){ min = dist[v]; nearest = v; }
        }
        s = nearest;
        if(s == n) break;
    }
    printf("%.16lf\n", dist[n]);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
answer = 0
for i in range(1, N):
    if P[i-1] == i:
        P[i], P[i-1] = P[i-1], P[i]
        answer += 1
if P[N-1] == N:
    answer += 1
print(answer)    

Measured memory_bytes: 14008
#include<bits/stdc++.h>
using namespace std;
const long long INFdesu=2E10;
vector<int> s;
int mnisin(int N){
    if(N==0)return 0;
    if(N%2==0) {
        s.push_back(0);
        return mnisin(-N/2);
    }else {
        s.push_back(1);
        return mnisin(-(N-1)/2);
    }
}
int main(){
    int N;
    cin >> N;
    if(N==0) cout << 0 << endl;
    else{
        mnisin(N);
        reverse(s.begin(),s.end());
        for(auto itr =s.begin(); itr !=s.end();itr++){
            cout << *itr ;
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){

	int n,a,b,c;
	string s;
	cin >> a >> b >> c;
	cout << max(0,c-(a-b)) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<vector>

using namespace std;

int main() {


	int n, m;
	vector<int> time;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		time.push_back(t);
	}

	cin >> m;

	int sum = 0;
	for (int i = 0; i < m; i++) {
		int p, x;
		cin >> p >> x;
		sum = 0;
		for (int j = 0; j < time.size(); j++) {
			if (j == p - 1)sum += x;
			else sum += time[j];
		}
		cout << sum << endl;

	}

	return 0;
}

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

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

ll N,M;
P in[100005];
ll ans[100005];

class UnionFind {
public:
	vector<ll> uni;
	UnionFind(ll s) : uni(s, -1) { }

	ll root(ll a) {
		if (uni[a] < 0) return a;
		return uni[a] = root(uni[a]);
	}

	bool connect(int a,int b) {
		a = root(a);
		b = root(b);
		if (a == b) return false;

		if (uni[a] > uni[b]) {
			a ^= b;
			b ^= a;
			a ^= b;
		}

		uni[a] = uni[a] + uni[b];
		uni[b] = a;
		return true;
	}

	bool isConnect(ll a,ll b) {
		return root(a) == root(b);
	}

	ll size(ll a) {
		return -uni[root(a)];
	}

};

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

	cin >> N >> M;

	for (int i = 0;i < M;i++){
		ll A,B; cin >> A >> B;
		in[i] = P(A,B);
	}

	UnionFind uf(N+10);
	ll now = 0;
	ll all = (N*(N-1))/2;
	ans[M] = all;

	for (int i = M-1;i >= 1;i--){
		ll A = in[i].first, B = in[i].second;
		if(uf.isConnect(A,B)) ans[i] = all-now;
		else{
			ll s = uf.size(A);
			now -= (s*(s-1))/2;
			s = uf.size(B);
			now -= (s*(s-1))/2;
			uf.connect(A,B);
			s = uf.size(A);
			now += (s*(s-1))/2;
			ans[i] = all-now;
		}
	}

	for (int i = 1;i <= M;i++){
		cout << ans[i] << endl;
	}

	return 0;

}


Measured memory_bytes: 3712
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
	char a,b;
	cin>>a>>b;
	if(a=='H'&&b=='H')
	{
	cout<<"H";	
	}
if(a=='D'&&b=='H'){
	cout<<"D";
}
if(a=='H'&&b=='D'){
cout<<"D";
}
	if(a=='D'&&b=='D')
	{
		cout<<"H";
	}
}

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

int main()
{
  int n;
  cin >> n;
  int a;
  vector<int> v;

  v.push_back(0);
  ll all = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> a;
    v.push_back(a);
    all += abs(a - v[i]);
  }
  v.push_back(0);
  all += abs(v[n]);

  for (int i = 1; i <= n; i++)
  {
    ll next = v[i + 1];
    ll prev = v[i - 1];
    ll now = v[i];
    cout << all + abs(next - prev) - (abs(next - now) + abs(now - prev)) << endl;
  }
}

Measured memory_bytes: 1784
// AOJ 2313 Box Witch
// 2018.3.15 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

// AOJ 2118 Oil Company
// 2018.3.10 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*******************************************/
/* Dinic's Max Flow Algorithm 
/*******************************************/

#define INF 0x01010101
#define VMAX 505
typedef struct { int to, cap, rev; char run; } EDGE;
EDGE  edge[VMAX][VMAX]; int hi[VMAX];
int   V, source, sink;
char  used[VMAX];
short tbl[VMAX][VMAX];

void add_edge(int from, int to)
{
	int f, t;
	EDGE *e;

	f = hi[from]++, t = hi[to]++;
	e = &edge[from][f], e->to = to, e->cap = 1, e->rev = t, e->run = 1;
	e = &edge[to][t], e->to = from, e->cap = 1, e->rev = f, e->run = 1;
	tbl[from][to] = f, tbl[to][from] = t;
}

int dfs(int v, int t, int f)
{
	int i, d;
	EDGE *e;
	
	if (v == t) return f;
	used[v] = 1;
	for (i = 0; i < hi[v]; i++) {
		e = &edge[v][i];
		if (e->run == 0) continue;
		if (e->cap > 0 && !used[e->to]) {
			d = dfs(e->to, t, f <= e->cap? f: e->cap);
			if (d > 0) {
				e->cap -= d;
				edge[e->to][e->rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int maxFlow(int s, int t, int max)
{
	int f, flow = 0;
	while (max > 0) {
		memset(used, 0, V);
		if (!(f = dfs(s, t, max))) break;
		flow += f, max -= f;
	}
	return flow;
}

int back_edge(int from, int to)
{
	EDGE *e = &edge[from][tbl[from][to]];
	if (e->run) {
		e->run = 0;
		if (e->cap == 0 && maxFlow(from, to, 1) == 0) {
			maxFlow(from, source, 1);
			maxFlow(sink, to, 1);
			return 1;
		}
	}
	return 0;
}

/**********************************************/

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int main()
{
	int N, E, Q, i, ans;

	N = in(), E = in(), Q = in();
	
	source = 0, sink = N-1, V = sink+1;
	for (i = 0; i < E; i++) {
		int f = in()-1, t = in()-1;
		add_edge(f, t);
	}

	ans = maxFlow(source, sink, INF);

	while (Q--) {
		int m = in(), a = in()-1, b = in()-1;
		if (m == 1) {
			add_edge(a, b);
			ans += maxFlow(source, sink, 1);
		} else {
			ans -= back_edge(a, b);
			ans -= back_edge(b, a);
		}
		printf("%d\n", ans);
	}
	return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int array[n];

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

	int answer = 0;

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; j++)
		{
			if (abs(array[i]-array[j])>=answer) answer = abs(array[i] - array[j]);
		}
	}
		
	cout << answer;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
const ll INF = 1000000007;
const ld PI = 3.141592653589793;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
int gcd(ll a,ll b){return __gcd(a,b);}

ld calcAngle(int h,int m){
    if(h == 12) h = 0;  
    if(m == 60) m = 0;
    ld hour_angle =(ld)(0.5 * (h * 60 + m)); 
    ld minute_angle = (ld)(6.0*m);
    ld angle = abs(hour_angle - minute_angle);  
    angle = min(360.000 - angle, angle);
    return angle;  
}
int main(){
    FAST_IO;
    ll _=1;
    //cin>>_;3 4 9 0
    for(ll ii=1;ii<=_;ii++)
    {
		int a,b,h,m;
		cin>>a>>b>>h>>m;
		cout<<fixed<<setprecision(10);
		ld angc=(ld)(calcAngle(h,m));
		angc = angc*(PI/180.000000);
		ld c = (ld)(a*a+b*b-2*a*b*cos(angc));
		cout<<sqrt(c)<<endl;
	}
	//cout<< "Done in " <<fixed<<setprecision(15)<<(double)clock()/7.33e8<<"sec"<< endl;
    return 0;
}


Measured memory_bytes: 4168
S = input()
S = S[::-1]
key = [
    "dream"[::-1],
    "erase"[::-1],
    "dreamer"[::-1],
    "eraser"[::-1]
]
f = False
while(S != ""):
    f = False
    for i in range(4):
        tmp = S[0:len(key[i])]
        if (tmp == key[i]):
            S = S[len(key[i]):]
            f = True
            break
    if not(f):
        break
        
if (f):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll 				long long
#define ld 				long double
#define fastio 			ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) 		cerr<<#x<<" "<<x<<endl
#define cina(a,n) 		for(ll i = 0;i<n;i++)	cin>>a[i];
#define couta(a,n) 		for(ll i = 0;i<n;i++) cout<<a[i]<<" ";
#define fauto(ar)		for(auto x : ar)	cout<<x<<" ";
#define mod 			1000000007
#define siz 			2000005
#define f 				first
#define s 				second
#define pb 				push_back
#define endl 			"\n"
#define ci 				cin.ignore()
using namespace std;
ll fact[siz],inv[siz];
ll power(ll a,ll n)
{
	ll res = 1;
	while(n)
	{
		n&1 ? res *= a , res %= mod : 1;
		a *= a;
		a %= mod;
		n >>= 1;
	}
	return res;
}
ll ncr(ll n,ll r)
{
	ll val = fact[n]*inv[r]%mod;
	val = val*inv[n-r]%mod;
	return val;
}
int main()
{
	ll n,r1,r2,c1,c2,i;
	
	cin>>r1>>c1>>r2>>c2;
	
	fact[0] = 1;
	for(i = 1;i<siz;i++)
	{
		fact[i] = fact[i-1]*i%mod;
	}
	
	inv[siz-1] = power(fact[siz-1],mod-2);
	
	for(i = siz-2;i>=0;i--)
	{
		inv[i] = (i+1)*inv[i+1]%mod;
	}
	
	ll op1 = ncr(r2+c2+2,r2+1) - ncr(r2+c1+1,r2+1) - ncr(r1+c2+1,r1) + ncr(r1+c1,r1);
	
	op1 %= mod;
	op1 += mod;
	op1 %= mod;
	
	cout<<op1;
	
	
	
	
	
}

Measured memory_bytes: 31488
import sys

def pokakito(num_line):
    if not num_line and flag == 1:
        result_lis.append(check_num)
        return True
    for num in num_line:
        if three(num, num_line): return True
        if two(num, num_line): return True
        if straight(num, num_line): return True
    
def three(num, num_line):
    count = 0
    for check in num_line[:3]:
        if check == num:
            count += 1
    else:
        if count == 3:
            if pokakito(num_line[3:]): return True

def two(num, num_line):
    global flag
    count = 0
    for check in num_line[:2]:
        if check == num:
            count += 1
    else:
        if count == 2:
            flag += 1
            if pokakito(num_line[2:]): return True
            flag -= 1

def straight(num, num_line):
    for check in [num,num+1,num+2]:
        if not check in num_line:
            break
    else:
        for n in [num,num+1,num+2]:
            index = 0
            while num_line:
                if num_line[index] == n:
                    del num_line[index]
                    break
                index += 1
        else:
            if pokakito(num_line): return True
            
flag = 0
result_lis = []
check_num = 0
for input_line in sys.stdin:
    for i in range(9):
        check_num = i+1
        input_line = input_line.rstrip()
        line = sorted(input_line + str(check_num))
        line = ''.join(line)
        index = line.find(str(check_num))
        if line[index:index+5] == str(check_num)*5:
            continue
        pokakito([int(char) for char in line])
        result = sorted([str(num) for num in result_lis])
        flag = 0
    else:
        if result_lis:
            print ' '.join(result)
        else:
            print 0
    flag = 0
    result_lis = []
    check_num = 0

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

int64_t cal(int n){
	return n*(n-1)/2;
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>a(n),c(n,0);
	for(auto&i:a){
		cin>>i;
		++c.at(--i);
	}
	int64_t ans=0;
	for(auto&i:c)ans+=(int64_t)i*(i-1)/2;
	for(auto&i:a){
		cout<<ans-cal(c.at(i))+cal(c.at(i)-1)<<"\n"s;
	}
}

Measured memory_bytes: 4224
import heapq
n, q = [int(x) for x in input().split()]
L = [ [] for _ in range(n)]
for _ in range(q):
    c, t, x = [int(x) for x in (input()+ " 0").split()][:3]
    if c == 0:
        heapq.heappush(L[t],-x)
    elif c == 1:
        try:
            print(-L[t][0])
        except IndexError:
            pass
    else:
        try:
            heapq.heappop(L[t])
        except IndexError:
            pass





Measured memory_bytes: 13360
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int p=1e9+7;
ll n,X,Y,Z,i,j,k,nt,hh,mx,ans,f[42][500010];
int main(){
	scanf("%lld%lld%lld%lld",&n,&X,&Y,&Z);
	hh=1ll<<Z-1;
	hh|=1ll<<(Z+Y-1);
	hh|=1ll<<X+Z+Y-1;
	mx=(1ll<<X+Y+Z)-1;
	f[0][0]=1;
	for(i=1;i<=n;i++){
		for(j=0;j<mx;j++){
			for(k=1;k<=10;k++){
				nt=(j<<k)|(1ll<<k-1);
				nt&=mx;
				if((nt&hh)!=hh)f[i][nt]=(f[i][nt]+f[i-1][j])%p;
			}
		}
	}
	ans=1;
	for(i=1;i<=n;i++)ans=ans*10%p;
	for(i=0;i<mx;i++)ans=(ans-f[n][i]+p)%p;
	printf("%lld",ans);
}

Measured memory_bytes: 127232
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine());
		String S = sc.nextLine();
		int K = Integer.parseInt(sc.nextLine());
		
		String[] spl = S.split("");
		String keyString = spl[K-1];
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < spl.length; i++){
			if(!(spl[i].equals(keyString))){
				spl[i] = "*";
			}
			sb.append(spl[i]);
		}
		System.out.println(sb.toString());
	}

}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p.at(i);
  }
  vector<int> ref(n);
  ref = p;
  sort(ref.begin(), ref.end());
  int count = 0;
  for(int i = 0; i < n; i++){
    if (p.at(i) != ref.at(i)) count++;
  }
  count--;
  cout << (count <= 1 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"2 ABCXYZ"# => r#"CDEZAB"#,

}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        n: usize,
        s: chars,
    }
    let mut ans = "".to_string();

    for i in 0..s.len() {
        let c = (s[i] as u8) + (n as u8);
        let b = if ('Z' as u8) < c { 'A' as u8 + (c - ('Z' as u8) - 1) } else { c };
        ans.push_str(&(b as char).to_string());
    }

    ans
}

Measured memory_bytes: 4352
unittest
{
	assert( [ "1 3" ].parse.expand.solve == "Positive" );
	assert( [ "-3 -1" ].parse.expand.solve == "Negative" );
	assert( [ "-1 1" ].parse.expand.solve == "Zero" );
	
	assert( [ "-4 -1" ].parse.expand.solve == "Positive" );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ab = input.front.split.to!( long[] );
	return tuple( ab[ 0 ], ab[ 1 ] );
}

auto solve( long a, long b )
{
	if( a <= 0 && 0 <= b ) return "Zero";
	if( b < 0 && ( a - b ) % 2 == 0 ) return "Negative";
	else                              return "Positive";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
int main(){
  int n;cin>>n;
  vec v(n);
  rep(i,n)cin>>v[i];
  
  vec rev(n);
  rep(i,n) rev[v[i]-1]=i+1;
  rep(i,n) cout<<rev[i]<<endl;
}

Measured memory_bytes: 1664
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        List<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(Integer.parseInt(sc.next()));
        }
        sc.close();

        // 主処理
        a.sort(Collections.reverseOrder());
        int base = a.get(0);
        int center = (int) Math.ceil(base / 2.0);

        List<Integer> diff = new ArrayList<>();
        for (int i = 1; i < a.size(); i++) {
            diff.add(Math.abs(center - a.get(i)));
        }

        int min = diff.stream().mapToInt(i -> i).min().orElse(0);
        int index = diff.indexOf(min) + 1;

        String result = base + " " + a.get(index);

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 62436
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    ll n; cin>>n;
    ll ans=10000000000000000;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ll j=n/i;
            chmin(ans,i+j-2);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int cnt = 0;
		if((A%2 + B%2 + C%2)==1){
				if(A%2!=0){
					B++;
					C++;
				}
				else if(B%2!=0){
					A++;
					C++;
				}
				else if(C%2!=0){
					A++;
					B++;
				}
				cnt++;
		}
		if((A%2 + B%2 + C%2)==2){
				if(A%2!=1){
					B++;
					C++;
				}
				else if(B%2!=1){
					A++;
					C++;
				}
				else if(C%2!=1){
					A++;
					B++;
				}
				cnt++;
		}

		int maxval=A;

		if(maxval<B) maxval = B;
		if(maxval<C) maxval = C;

		System.out.println((maxval-A)/2+(maxval-B)/2+(maxval-C)/2+cnt);	
		
	}

}

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

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(void)
{
    int a,b,c,x;

    cin >> a >> b >> c >> x;

    int sum = 0;
    int count = 0;
    for (int i = 0; i <= a; i++) {
        sum = 0;
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                sum = 500 * i + 100 * j + k * 50;
                if (sum == x) {
                    count++;
                }
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
const ll mod = 1e9+7;

template<typename T> ostream& operator << (ostream& os, vector<T> v) {
  for (auto& i : v) os << i << " "; return os; 
}
template<typename T> istream& operator >> (istream& is, vector<T>& v) {
  for (auto& i : v) is >> i; return is;
}
template<typename K, typename V> ostream& operator << (ostream& os, unordered_map<K, V> m) {
  for (auto& i : m) os << i.first << ":" << i.second << endl; return os;
}
template<typename T> inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template<typename T> inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

int N;
ll A[401];

ll B[404];
void init() {
  B[0] = A[0];
  rep(i, 1, N) B[i] = B[i - 1] + A[i];
}
ll get(int L, int R) {
  ll res = B[R];
  if (L) res -= B[L - 1];
  return res;
}

ll memo[404][404];
int vis[404][404];
ll dp(int L, int R) {
  if (L == R) return 0;
  if (vis[L][R]) return memo[L][R];
  vis[L][R] = 1;

  ll res = infl;
  rep(c, L, R) chmin(res, dp(L, c) + dp(c + 1, R) + get(L, R));
  return memo[L][R] = res;
}

int main() {
  cin >> N;
  rep(i, 0, N) cin >> A[i];
  init();
  cout << dp(0, N - 1) << endl;
}


Measured memory_bytes: 2176
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	long long x;
	long long a;
	int  b;
	a = 0;
	b = 0;
	x = 0;
	scanf("%lld", &x);
	a = (x-1)/ 11;
	b = (x-1)% 11;
	a = a * 2;
	if (b <6) printf("%lld\n", a + 1);
	else printf("%lld\n", a + 2);

	return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

template<class T>
class BinaryIndexedTree
{
public:
  int n;
  vector<T> bit;

  BinaryIndexedTree():n(-1){}

  BinaryIndexedTree(int n_, T d):n(n_),bit(n_+1,d){}

  T sum(int i)
  {
    T s = 0;
    while(i > 0){
      s += bit[i];
      s %= mod;
      i -= i&-i;
    }
    return s;
  }

  void add(int i, T x)
  {
    if(i == 0) return;
    while(i <= n){
      bit[i] += x;
      bit[i] %= mod;
      i += i&-i;
    }
  }

  T sum0(int i)
  {
    return sum(i+1);
  }

  void add0(int i, T x)
  {
    add(i+1, x);
  }

  T query(int l, int r)
  {
    return sum(r-1)-sum(l-1);
  }

  T query0(int l, int r)
  {
    return (sum(r)-sum(l)+mod)%mod;
  }
};

int n, k, a[100];

signed main(){
  cin >> n >> k;
  rep(i, 0, n) cin >> a[i];

  vector<BinaryIndexedTree<int>> bit(n+1, BinaryIndexedTree<int>(k+5, 0));
  bit[0].add0(k, 1);
  rep(i, 0, n){
    rep(j, 0, k+1){
      int tmp = bit[i].query0(j, min(j+a[i], k)+1);
      bit[i+1].add0(j, tmp);
    }
  }

  cout << bit[n].sum0(0) << endl;

  return 0;
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N,D;
    cin >> N >> D;
    vector<vector<i64>> X(N,vector<i64>(D));
    rep(i,0,N){
        rep(j,0,D){
            cin >> X[i][j];
        }
    }
    
    i64 ans=0;
    rep(i,0,N){
        rep(j,i+1,N){
            i64 d=0;
            rep(k,0,D) d+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
            rep(k,0,10000){
                if(k*k==d){
                    ++ans;
                    break;
                }
            }
        }
    }
    
    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    int ans = m;
    for(int i = 0; i <= n - m; i++){
        int c = m;
        for(int j = 0; j < m; j++){
            if(s[i + j] == t[j]) c--;
        }
        ans = min(ans, c);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
n, k, *a = map(int, open(0).read().split())
l = k.bit_length()
pre = sum((x >> l) << l for x in a)
dp = [[0] * 2 for _ in range(l + 1)]
dp[0] = [pre, -float("inf")]
for i in range(l):
	t = 1 << l - i - 1
	s = sum(x & t for x in a)
	ms = t * n - s
	if k & t:
		dp[i + 1][0] = dp[i][0] + ms
		dp[i + 1][1] = max(dp[i][1] + max(s, ms), dp[i][0] + s)
	else:
		dp[i + 1][0] = dp[i][0] + s
		dp[i + 1][1] = dp[i][1] + max(s, ms)
print(max(dp[-1]))

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(i,array) for(auto& x:array)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define inf 10000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;


int main(){
    int n;
    cin>>n;
    vint l(n);
    rep(i,n)cin>>l[i];

    sort(all(l));
    int sum=0;
    rep(i,n-1)sum+=l[i];
    cout<<(l[n-1]<sum? "Yes" : "No");

    return 0;
}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define print(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int bexp(int a, int b, int mod)
{
    int res = 1;

    while (b)
    {
        if (b & 1) res = (res * a) % mod;

        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

const int N = 100010;
const int mod = 998244353;

struct comp {
    bool operator() (const pair<int, int> a, const pair<int, int> b) const
    {
        return a.ss > b.ss;
    }
};

int32_t main() 
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    int n, x, m;
    cin >> n >> x >> m;

    int p = x;
    int f[m] = {};
    vector<int> a;
    a.pb(0);

    while (n) {
        if (f[p] == 1) {
            break;
        }

       
        f[p]++;
        n--;
        a.pb(p + a.back());
        p = p * p % m;
    } 

    int ans = a.back();

    int in = 0;
    for (int i = 1; i < (int)a.size(); ++i)
    {
        if (a[i] - a[i - 1] == p) {
            in = i;
            break;
        }
    }

    // cout << ans << " " << n << " " << in <<  "\n";
    int no = a.size() - in;

    if (in != 0)
        ans = ans + n / no * (a.back() - a[in - 1]);

    if (in != 0)
        ans = ans + (a[in + n % no - 1] - a[in - 1]);

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

Measured memory_bytes: 4568
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;
using ll = long long;

struct katana
{
    ll a, b;
    bool operator < (const katana & B) const
    {
        return b > B.b;
    }
};

const int MAXN = 1e6+5;
katana tab[MAXN];

int main()
{
    ll n, h;
    cin >> n >> h;
    ll maks = 0;
    for (int i= 0; i < n; i++)
    {
        cin >> tab[i].a >> tab[i].b;
        maks = max(maks, tab[i].a);
    }

    sort(tab, tab+n);
    int res = 0;
    for (int i = 0; tab[i].b > maks; i++)
    {
        h -= tab[i].b;
        res++;
        if (h <= 0)
        {
            cout << res << "\n";
            return 0;
        }
    }
    res += ceil((double)h / (double)maks);
    cout << res << "\n";
}


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

int main()
{
  int n;
  cin>>n;
  if(n<1&&81<n){
    cout<<"No"<<endl;
  } else if(n==11||n==13||n==17||n==19||n==22||n==23||n==26||n==29||n==31||n==33||n==34||n==37||n==38||n==39||n==41||n==43||n==44||n==46||n==47||n==50||n==51||n==52||n==53||n==55||n==57||n==58||n==59||n==60||n==61||n==62){
    cout<<"No"<<endl;
  } else if(n<=65){
    cout<<"Yes"<<endl;
  } else if(n==72||n==81){
    cout<<"Yes"<<endl;
  } else{
    cout<<"No"<<endl;
  }
}

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

int main() {
	long long n,m;cin>>n>>m;
	long long sn,sm;sn=sm=1;
	long long def=1;
	for(int i=0;i<9;i++)def*=10;
	def+=7;
	for(int i=2;i<=n;i++){
		sn*=i;
		if(sn>def)sn%=def;
	}
	for(int i=2;i<=m;i++){
		sm*=i;
		if(sm>def)sm%=def;
	}
	long long ans;
	if(n==m){
		ans=sn*sm;
		if(ans>def)ans%=def;
		ans*=2;
		if(ans>def)ans%=def;
	}else if(n==m-1){
		ans=sn*sm;
		if(ans>def)ans%=def;

	}else if(m==n-1){
		ans=sn*sm;
		if(ans>def)ans%=def;
	}else{
		ans=0;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,c0=0,c1=0,c2=0,c3=0;
    cin >> t;
    while(t--)
    {
        string s;
        cin >> s;
        char c;
        c=s[0];
        switch(c)
        {
        case 'A':
            c0++;
            break;
        case 'W':
            c1++;
            break;
        case 'T':
            c2++;
            break;
        case 'R':
            c3++;
            break;
        }
    }
    cout << "AC x " << c0 << "\n";
    cout << "WA x " << c1 << "\n";
    cout << "TLE x " << c2 << "\n";
    cout << "RE x " << c3 << "\n";
}


Measured memory_bytes: 3628
N=int(input())
A=list(map(int, input().split()))
A=sorted(A)
s=0
for num in range(1, N+1):
  count = 0
  for i in range(s, N-1):
    if A[i] == num:
      count += 1
    else:
      break
  s+=count
  print(count)

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

int main()
{
  // 項目数
  int N;
  cin >> N ;
  // 入力の配列
  int P[N];

  //答え
  int answer = 0;

  int input;
  //今いくついれてる？
  int counter = 0;
  //最小
  int minimum = 200001;
  //素朴に
  bool isLower;

  for (int i = 0; i < N; i++)
  {
    //cin >> P[i];
    cin >> input;
      if (input < minimum)
      {
        answer++;
        minimum = input;
      }
  
  }

  cout << answer;

  return 0;

}

Measured memory_bytes: 256
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
l=[[0]*26 for i in range(10)]
for d in range(D):
    x=[]
    for b in range(10):
        x.extend([(S[d][i]-sum([(d+1-l[b][j])*C[j] for j in range(26) if i!=j]),i,b) for i in range(26)])
    x=sorted(x,key=lambda a:a[0])[::-1]
    l2=[]
    for _,i,b in x[:10]:
        l2.append(l[b])
        l2[-1][i]=d+1
    l=l2
    print(x[0][1]+1)

Measured memory_bytes: 9516
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>

using namespace std;

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

	int ans = 0;

	int x = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
			x++;
		}
		else {
			x = 0;
		}
		ans = max(ans, x);
	}

	cout << ans << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
vector<long long> a(51, 0);
vector<long long> b(51, 0);
vector<long long> c(51, 0);
vector<long long> d(51, 0);

int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
	}
	for (int j = 0; j < M; j++) {
		cin >> c[j] >> d[j];
	}

	for (int i = 0; i < N; i++) {
		long long minDes = 10000000000;
		long long number = 0;
		for (int j = 0; j < M; j++) {
			long long tmpCalc = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (tmpCalc < minDes) {
				minDes = tmpCalc;
				number = j + 1;
			}
		}
		cout << number << endl;
	}
	return 0;
}

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


int main() {
	
	int64_t N;
	cin >> N;
	int64_t i=sqrt(N);
	while(1){
		if(N % i == 0) break;
		i--;
	}
	int cnt = 1;
	N /= i;
	while(1){
		N /= 10;
		if(N == 0){
			cout << cnt << endl;
			break;
		}
		cnt++;
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] v1 = new int[100001];
        int[] v2 = new int[100001];
        int max1 = 0;
        int m1=0;
        int m2=0;
        int max2 = 0;
        for (int i=0;i<n/2;i++){
            v1[scanner.nextInt()]++;
            v2[scanner.nextInt()]++;
        }
        for (int i=1;i<100001;i++){
            max1 = Math.max(max1,v1[i]);
            if (v1[i]==max1)m1=i;
            max2 = Math.max(max2,v2[i]);
            if (v2[i]==max2)m2=i;
        }
        if (max1>max2){
            for (int i=1;i<100001;i++){
                if (i!=m1)max2 = Math.max(max2,v2[i]);
            }
        }else if (max1<max2){
            for (int i=1;i<100001;i++){
                if (i!=m2)max1 = Math.max(max1,v1[i]);
            }
        }else {
            int j=0;
            int k=0;
            for (int i=1;i<100001;i++){
                if (i!=m1)j = Math.max(j,v2[i]);
                if (i!=m2)k = Math.max(k,v1[i]);
            }
            max2 = Math.max(j,k);
        }
        if (max1==max2&&m1==m2&&max1+max2==n){
            System.out.println(n/2);
        }else {
            System.out.println(n-max1-max2);
        }
    }
}

Measured memory_bytes: 60744
use proconio::input;

fn main() {
    input!(n: usize, txy: [(i32, i32, i32); n]);
    for i in 0..n {
        let (t0, x0, y0) = if i == 0 { (0, 0, 0) } else { txy[i - 1] };
        let (t1, x1, y1) = txy[i];
        let dt = t1 - t0;
        let d = (x1 - x0).abs() + (y1 - y0).abs();
        if dt < d || (dt - d) % 2 == 1 {
            println!("No");
            std::process::exit(0);
        }
    }
    println!("Yes");
}


Measured memory_bytes: 4516
#include <bits/stdc++.h>
using namespace std;
int main() {
	// #ifndef ONLINE_JUDGE
	// 	// for getting input from input.txt
	// 	freopen("input.txt", "r", stdin);
	// 	// for writing output to output.txt
	// 	freopen("output.txt", "w", stdout);
	// #endif

		int a,b,c=0,o=1;

		cin>>a>>b;
	
		while(o<b){
			o--;
			o= o+a;
			c++;
		}
		
		cout<<c<<"\n";
		
		return 0;
	}	

Measured memory_bytes: 256
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

a, b = list(map(int, sys.stdin.readline().split()))

i = b - a

s = 0
for j in range(1000):
    s += j
    if j == i:
        print(s - b)
        exit()


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

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	int a[n];
	int x;
	for(int i=0;i<n;i++)
	{
		cin >> x;
		a[i] = x;
	}
	sort(a, a + n);
	int sum = 0;
	for(int i=n-1;i>n-1-m;i--)
	{
		sum += a[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        var scaner = new Scanner(System.in);

        var s = scaner.next().toCharArray();
        var t = scaner.next().toCharArray();

        long ans = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i] != t[i]) {
                ans++;
            }
        }

        System.out.println(ans);

        scaner.close();
    }

}

Measured memory_bytes: 41924
//ABC083A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

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

Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n , m = f()
    d = []
    for i in range(m):
        d.append(f())
    
    d = [(i[0], i[1]-1) for i in d]

    d = sorted(d, key = lambda x: (x[1]))


    cover = 0
    cnt = 0
    for i in d:
        if i[0]>cover:
            cover = i[1]
            cnt += 1

    
    print(cnt)



solve()


Measured memory_bytes: 37880
import java.util.*;

public class Main {
	int w, h, sx, sy, ans;
	int[][] map;
	LinkedList<Integer> x, y;
	
	void loop(int p, int q, int r){
		if(r>=ans || r>=10) return;
		
		for(int i=p-1;i>=0;i--){
			if(map[q][i]==3){
				ans = r+1;
			}else if(map[q][i]==1){
				if(i==p-1){
					break;
				}else{
					map[q][i] = 0;
					x.push(i);
					y.push(q);
					loop(i+1, q, r+1);
					map[y.pop()][x.pop()] = 1;
					break;
				}
			}
		}
		
		for(int i=p+1;i<w;i++){
			if(map[q][i]==3){
				ans = r+1;
			}else if(map[q][i]==1){
				if(i==p+1){
					break;
				}else{
					map[q][i] = 0;
					x.push(i);
					y.push(q);
					loop(i-1, q, r+1);
					map[y.pop()][x.pop()] = 1;
					break;
				}
			}
		}
		
		for(int i=q-1;i>=0;i--){
			if(map[i][p]==3){
				ans = r+1;
			}else if(map[i][p]==1){
				if(i==q-1){
					break;
				}else{
					map[i][p] = 0;
					x.push(p);
					y.push(i);
					loop(p, i+1, r+1);
					map[y.pop()][x.pop()] = 1;
					break;
				}
			}
		}
		
		for(int i=q+1;i<h;i++){
			if(map[i][p]==3){
				ans = r+1;
			}else if(map[i][p]==1){
				if(i==q+1){
					break;
				}else{
					map[i][p] = 0;
					x.push(p);
					y.push(i);
					loop(p, i-1, r+1);
					map[y.pop()][x.pop()] = 1;
					break;
				}
			}
		}
	}

	void solve(){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if(w==0 && h==0) break;
			
			map = new int[h][w];
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					map[i][j] = sc.nextInt();
					if(map[i][j]==2){
						sx = j;
						sy = i;
					}
				}
			}
			
			x = new LinkedList<Integer>();
			y = new LinkedList<Integer>();
			ans = Integer.MAX_VALUE;
			loop(sx, sy, 0);
			if(ans==Integer.MAX_VALUE) ans = -1;
			System.out.println(ans);
		}
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}	
}

Measured memory_bytes: 51604
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
long long a,b,k;
int main()
{
	cin>>a>>b>>k;
	long long x=min(a,k);
	k-=x;
	a-=x;
	if(k)
	{
		x=min(b,k);
		b-=x;
	}
	cout<<a<<' '<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

def judge(s1, s2):
    d = {}
    for i,c in enumerate(s1):
        if c not in d:
            d[c] = [i]
        else:
            d[c].append(i)
    for v in d.values():
        a = v[0]
        for b in v:
            if s2[a]!=s2[b]:
                return 0
            a = b
    return 1

if judge(S,T)*judge(T,S) == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 56252
n, k = gets.chomp.split.map(&:to_i)
a_n = gets.chomp.split.map(&:to_i)

(k - 1).upto(n - 1) do |i|
  if i >= k
    puts(a_n[i-k] < a_n[i] ? 'Yes' : 'No')
  end
end

Measured memory_bytes: 35808
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	int T, P, R;
	List<Team> teams;
	Map<Integer, Integer> pena;


	public static void main(String[] args) {
		while(true) {
			int m = sc.nextInt();
			int t = sc.nextInt();
			int p = sc.nextInt();
			int r = sc.nextInt();
			if(m==0 && t==0 && p==0 && r==0) break;
			Main main = new Main(t, p, r);
			main.action();
			main.print();
		}
	}

	Main(int T, int P, int R) {
		this.T=T; this.P=P; this.R=R;
		teams = new ArrayList<Team>(T+1);
		for(int i=0; i<T; i++) {
			teams.add(new Team(i+1));
		}
		pena = new HashMap<Integer, Integer>();
	}

	void action() {
		for(int i=0; i<R; i++) {
			int m = sc.nextInt();
			int t = sc.nextInt() - 1;
			int p = sc.nextInt();
			int r = sc.nextInt();

			if(r == 0) {
				Team team = teams.get(t);
				team.maru++;
				team.time += m + getPena(t, p);
			} else {
				setPena(t, p);
			};
		}
		Collections.sort(teams);
	}

	void print() {
		for(int i=0; i<T; i++) {
			System.out.print(teams.get(i).numb);
			if(i == T-1) continue;
			if(teams.get(i).eq(teams.get(i+1))) {
				System.out.print("=");
			} else {
				System.out.print(",");
			}
		}
		System.out.println();
	}

	int getPena(int t, int p) {
		int key = (P+1)*t + p;
		if(pena.containsKey(key)) {
			return pena.get(key);
		} else {
			return 0;
		}
	}

	void setPena(int t, int p) {
		int key = (P+1)*t + p;
		int val = 20;
		if(pena.containsKey(key)) {
			val += pena.get(key);
		}
		pena.put(key, val);
	}
}


class Team implements Comparable<Team> {
	int numb;
	int maru = 0;
	int time = 0;

	Team(int n) {
		numb = n;
	}

	boolean eq(Team op) {
		if(maru != op.maru) return false;
		if(time != op.time) return false;
		return true;
	}

	@Override
	public int compareTo(Team op) {
		int ret = op.maru - maru;
		if(ret == 0) ret = time - op.time;
		if(ret == 0) ret = op.numb - numb;
		return ret;
	}
}

Measured memory_bytes: 61416
#include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
int main() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    int count = n;
    for (int i = 0; i < count; i++)
    {
        cin >> a.at(i);
        /* code */
    }
    sort(a.begin(), a.end());
    long long ans = 0;
    for (int i = 0; i < count; i++)
    {
        ans += a.at(i);
        /* code */
    }
    cout << a.at(0) << " " << a.at(n-1) << " " << ans <<endl;
}


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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int ans;
    ans=min(b,a*n);

    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(void){
    int a, b, c, t;
    cin >> a >> b >> c;
    if (a > b){
        t = a;
        a = b;
        b = t;
    }
    if (b > c){
        t = b;
        b = c;
        c = t;
    }
    if (a > b){
        t = a;
        a = b;
        b = t;
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>

int main(){

	char s[100001];
	int k;

	scanf("%s", s);
	scanf("%d", &k);

	int i=0;
	char*c;

	for(c=s;*c!='\0';c++){
		if(*c=='a') continue;
		int diff=('z'+1-*c);
		if(k>=diff){
			*c='a';
		     k-=diff;
		 }
	}
	c--;

(*c)+=(k%26);

	printf("%s", s);

	return 0;
}


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

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

    int ans;
    if (op == "+")
        ans = A + B;
    else
        ans = A - B;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256