akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const ll INF = 1e17;
// https://atcoder.jp/contests/abc143/submissions/8034843

int main() {
    // input
    int N;
    cin >> N;

    vector<ll> vec_A;
    vector<ll> vec_B;
    vector<ll> vec_C;
    vec_A.resize(N);
    vec_B.resize(N);
    vec_C.resize(N);
    for (int i=0; i<N; i++) cin >> vec_A.at(i);
    for (int i=0; i<N; i++) cin >> vec_B.at(i);
    for (int i=0; i<N; i++) cin >> vec_C.at(i);
    sort(vec_A.begin(), vec_A.end());
    sort(vec_B.begin(), vec_B.end());
    sort(vec_C.begin(), vec_C.end());
    
    // resolve
    ll ans =0;
    for (auto b: vec_B)
    {
        auto itA = lower_bound(vec_A.begin(), vec_A.end(), b);
        int indexA = itA - vec_A.begin();
        auto itC = lower_bound(vec_C.begin(), vec_C.end(), b+1);
        int indexC = itC - vec_C.begin();
        //cout << indexA << ", " << vec_C.size() - indexC << endl;
        ans += (indexA) * (vec_C.size() - indexC);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int N,A;cin>>N>>A;
  if (N%500 - A <= 0) {
    P("Yes");
  }else{
    P("No");
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int A;
    int B;
    int C;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = sc.nextInt();
        this.B = sc.nextInt();
        this.C = sc.nextInt();
    }
    
    //解答処理
    private String solve() {
        String answer = "No";
        
        if (A==B && B!=C || A==C && B!=C || B==C && C!=A) {
        	answer = "Yes";
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}


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

int main() {
	int a, b, k,j = 0,ar[1000000];
	cin >> a >> b >> k;
  	int i=min(a,b);
	while (1) {
		if (b%i == 0 && a%i == 0){
          j++; ar[j]=i;}
      	if(j==k)break;
		i--;
	}cout << ar[j] << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
mina = maxa = a[0]
suma = 0
for i in range(n):
    if a[i] < mina:
        mina = a[i]
    if a[i] > maxa:
        maxa = a[i]
    suma += a[i]
print(mina, maxa, suma)



Measured memory_bytes: 6604
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}


string s;
int n;


signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

	
	cin >> n >> s;
	if(n>=3200){
		cout << s << endl;
	}
	else cout << "red" << endl;

return 0;
}
///....


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<cmath>
/*
for(i=0;i<n;i++)
{
scanf("%lld",&arr[i]);
}
scanf("%lld",&n);
*/


using namespace std;
int main()
{
	long long int t=1,n,i,s;
	
	while(t--)
	{
		s=0;
	scanf("%lld",&n);
	long long int arr[n];	
	for(i=0;i<n;i++)
{
scanf("%lld",&arr[i]);
}
sort(arr,arr+n);
	for(i=0;i<n-1;i++)
{
s=s+arr[i];
}
if(s>arr[n-1])
printf("Yes\n");
else 
printf("No\n");		
		
		
		
	}	
	return 0;
}					

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cstdlib>

#include <math.h>

typedef long long ll;
using namespace std;

int main()
{
	int N,K; 	cin >> N >> K ;
	vector<int> h_data(N+1);
	vector<ll> dp(N+1); 

	for( int i = 1; i <= N; i++ ){
		cin >> h_data.at(i) ;
	}
	for( int i = 1; i <= N; i++ ){
		dp.at(i) = 0x7fffffffffffffff; 
	}

	dp.at(1) = 0 ;
	for( int i = 1; i <= N; i++ ){
		for( int k = 1; k <= K; k++){
			if(i+k <= N){
				ll u = dp.at(i)+abs(h_data.at(i)-h_data.at(i+k));
				if( dp.at(i+k) > u )
				{
					dp.at(i+k) = u ;
				}
			}
		}
	}
	cout << dp.at(N) << endl;
}

Measured memory_bytes: 1408
#119c
N, A, B, C = map(int,input().split())
l = [int(input()) for i in range(N)]
INF = 10**9

def dfs(bamboo_number,a,b,c):
    #停止条件
    #深さに限らず，任意の停止条件を書く
    if bamboo_number == N:
        #合成完了　長さを調整
        if min(a,b,c) > 0:
            return abs(a-A)+abs(b-B)+abs(c-C) - 30 #最初の1本分の合成コストは無料なので-10 *3
        else:
            return INF
        
    # pos (bamboo_number)を進めながら（末端に進みながら）分岐処理
    # 末端まで到達した時それぞれの分岐から値が返される
    # for 文で書ける場合は for 文で実装
    ret1 = dfs(bamboo_number+1,a,b,c);
    ret2 = dfs(bamboo_number+1,a+l[bamboo_number],b,c) + 10
    ret3 = dfs(bamboo_number+1,a,b+l[bamboo_number],c) + 10
    ret4 = dfs(bamboo_number+1,a,b,c+l[bamboo_number]) + 10

    #それぞれの分岐からの戻り値の処理を行う関数
    return min(ret1, ret2, ret3, ret4)

print(dfs(0,0,0,0))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    vector<vector<LL>> dp(n+1, vector<LL>(2, 0));
    dp[1][0] = a[0];
    dp[1][1] = -a[0];
    FOR(i, 1, n-1)
    {
        dp[i+1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
        dp[i+1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]);
        //cout << dp[i+1][0] << " " << dp[i+1][1] << endl;
    }
    dp[n][0] = dp[n-1][0] + a[n-1];
    dp[n][1] = dp[n-1][1] - a[n-1];
    cout << max(dp[n][0], dp[n][1]) << endl;
}

Measured memory_bytes: 6144
####################
def pri(n):
  i = 2
  X = {}
  while i * i <= n:
    while n % i == 0:
      n /= i
      if i in X:
        X[i] = X[i] + 1
      else:
        X[i] = 1
    i += 1
  if n > 1:
    X[n] = 1
  return X
####################


N,X = list(map(int, input().split()))

x = list(map(int, input().split()))
x.append(X)

x.sort()

d = []
for i in range(N):
  dif = x[i+1] - x[i]
  if dif not in d:
    d.append(dif)

d.sort()

if len(d) == 1:
  print(d[0])
  exit()

m = d[0]
P = pri(d[0])

for i in range(1,len(d)):
  if d[i] % m != 0:
    t = pri(d[i])
    m = 1
    for j in list(P):
      if j in t:
        P[j] = min(P[j], t[j])
        m *= j ** P[j]
      else:
        del P[j]

print(int(m))

Measured memory_bytes: 14252
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
using namespace std;

stack<int> s;

int opr(char ch, int a, int b) {
	switch(ch) {
		case '+':
			return a+b;
			break;
		case '-':
			return a-b;
			break;
		case '*':
			return a*b;
			break;
	}
	return -1;
}

int main() {
//	freopen("/Users/liyingyan/Documents/ACM/in.txt", "r", stdin);
	std::ios::sync_with_stdio(false);
	char ch;
	int tmp = 0;
	int flag = 0;
	while((ch = getchar()) != '\n') {
		if(ch == ' ') {
			if(flag) s.push(tmp);
			tmp = 0;
		} else if(ch >= '0' && ch <= '9') {
			flag = 1;
			tmp = tmp * 10 + ch - '0';
		} else {
			flag = 0;
			int a = s.top();
			s.pop();
			int b = s.top();
			s.pop();
			int t = opr(ch, b, a);
			s.push(t);
		}
	}
	int ans = s.top();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3232
import numpy as np
import itertools
H, W, K = [int(_) for _ in input().split()]
C = np.array([[0 if c == '.' else 1 for c in input()] for _ in range(H)],
             dtype=int)
ans = 0
for bh in itertools.product([True, False], repeat=H):
    D = C.copy()
    D[np.array(bh), :] = np.zeros(W, dtype=int)
    for bw in itertools.product([True, False], repeat=W):
        E = D.copy().T
        E[np.array(bw), :] = np.zeros(H, dtype=int)
        if np.sum(E) == K:
            ans += 1
print(ans)


Measured memory_bytes: 27188
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int main(){
    int n;cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans=0;
    multiset<int> st;
    for (int i = 0; i < n; i++) {
        auto p = st.upper_bound(-a[i]);
        if(p==st.end()){
            ans++;
        }
        else{
            st.erase(p);
        }
        st.insert(-a[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>

int s,  cub[1000005], cont=0;

void f(int v){
    cont ++;
    int res;
    if(v %2 == 0){
        res = v/2;
    } else {
        res = 3*v+1;
    }
    if(cub[res] > 0){
        printf("%d\n", cont);
        return ;
    } else {
        cub[res] = 1;
    }
    f(res);
}

int main(){
    scanf("%d", &s);
    cub[s] = 1;
    cont = 1;
    f(s);
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    long long ret = 1;
    int k = 0;
    for(int i=1; i<=100000000; ++i){
        ret += min(4 * i, n - k);
        while(k < n && h[k] == i)
            ++ k;
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 1192
#include <cstdio>
#include <iostream>
#include <algorithm> 
#include <cstring>
using namespace std;
char s[1000005];
int n,nxt[1000005];
bool f[3][1000005];
void KMP(int x) {
	int j=0;
	nxt[1]=0;
    for (int i=2; i<=n; i++) {
    	while (j!=0 && s[i]!=s[j+1]) j=nxt[j];
    	if (s[i]==s[j+1]) j++;
    	nxt[i]=j;
    }

    for (int i=1; i<=n; i++)
	    if (nxt[i]==0 || i%(i-nxt[i])!=0)
		    f[x][i]=true;
}
bool check() {
	bool flag=false;
	for (int i=2; i<=n; i++)
	    if (s[i]!=s[i-1]) flag=true;
	if (!flag) return true;
	else return false; 
}
int main() {
	scanf("%s",s+1);
	n=strlen(s+1);	
	KMP(1);
	if (f[1][n]==true) {
		printf("1\n1\n");
		return 0;
	}
	if (check()) {
		printf("%d\n1\n",n);
		return 0; 
	} 
	reverse(s+1,s+1+n);
	KMP(2);
	int ans=0; 
	for (int i=1; i<=n; i++)
	    if (f[1][i] && f[2][n-i])
		     ans++;
	printf("2\n%d\n",ans); 
	return 0; 
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for(ll i=(ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
constexpr ll INF = 1LL<<60;

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

    cout << min(n%k, abs(n%k-k)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#define EPS (1e-7)
using namespace std;






int main() {

	int N, K;
	cin >> N >> K;

	if (K == 1) {
		cout << "0" << endl;
		return 0;
	}


	int div = N - K;

	cout << div << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, s, a[105];
int main() {
	cin>>n>>a[0];
	for(int i=1; i<n; i++) {
		cin>>a[i];
		if(a[i] == a[i-1]) s++, a[i] = 0;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu long long unsigned
int main()
{
    int t,a,b,x,y,z,n,mx,mn,tmp;
        int cnt=0,ans=0;
        string s="";
        vector<int>vc;
        map<int,int>mp;
        map<char,int>mc;
        scanf("%d",&x);
        char ch,ch2;
        for(int j=1;j<=x;j++){
            scanf("%d",&y);
            if(j%2!=0 && y%2!=0) ans++;
        }
        printf("%d\n",ans);


    return 0;
}







Measured memory_bytes: 3784
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int Hmax = 1e9;

ll ceil(ll a, ll b) {  // a÷b以上の最小の整数
    if(a%b == 0) {
        return a/b;
    }
    else {
        return a/b + 1LL;
    }
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll c = a-b;

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

    int left = 0;
    int right = Hmax;
    while(left < right) {

        int mid = (left + right)/2;

        rep(i, n) {
            H[i] = h[i] - b*mid;
        }

        ll cnt = 0;
        rep(i, n) {
            if(H[i] > 0) {
                cnt += ceil(H[i], c);
            }
        }

        if(cnt == mid) {
            cout << mid << endl;
            return 0;
        }
        else if(cnt > mid) {
            left = mid+1;
        }
        else if(cnt < mid) {
            right = mid;
        }
    }

    cout << left << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main
{
    
    public static void main(String[] args) throws IOException
    {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
        String s = r.readLine();
        String[] sl = s.split("[\\s]+");
        int a = Integer.parseInt(sl[0]);
        int b = Integer.parseInt(sl[1]);
        int ab = Integer.parseInt(sl[2]);
        int x = Integer.parseInt(sl[3]);
        int y = Integer.parseInt(sl[4]);
        
        int apb = Math.min(a + b, 2 * ab);
        int sum = 0;
        int v = Math.min(x, y);
        sum += v * apb;
        x -= v;
        y -= v;
        if(x == 0)
        {
            sum += Math.min(y * b, 2 * y * ab);
        }
        else
        {
            sum += Math.min(x * a, 2 * x * ab);
        }
        System.out.println(sum);
    }
    
}


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using ld = long double;

template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

const int INF = 1e9;
const int DX[4] = {0, 0, -1, 1};
const int DY[4] = {1, -1, 0, 0};

signed main()
{
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    vector< vector<int> > dist(n, vector<int>(m, INF));
    queue<pii> q;
    for (int i = 0; i < n; ++i)
    {
        string s;
        cin >> s;
        for (int j = 0; j < m; ++j)
        {
            if (s[j] == '#')
            {
                q.push(mp(i, j));
                dist[i][j] = 0;
            } 
        }
    }
    while (!q.empty())
    {
        int x = q.front().fi;
        int y = q.front().se;
        q.pop();
        for (int d = 0; d < 4; ++d)
        {
            int i = x + DX[d];
            int j = y + DY[d];
            if (0 <= i && i < n && 0 <= j && j < m && chkmin(dist[i][j], dist[x][y] + 1))
            {
                q.push(mp(i, j));
            }
        }
    }
    int mx = 0;
    for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) chkmax(mx, dist[i][j]);
    cout << mx << '\n';
    
    return 0;
}

Measured memory_bytes: 12432
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

/*** MOD CALCULATION ***/

const int MOD = 998244353;
const int MAX = 200100;

ll addM(ll a, ll b){
	return (a + b) % MOD;
}

ll mulM(ll a, ll b){
	ll temp = (a * b) % MOD;
  	while(temp<0){ temp += MOD; }
  	return temp;
}

ll powM(ll a, ll b){
	if(b == 0) return 1;
  	else if(b == 1) return a%MOD;
  	else if(b%2==0) return mulM(powM(a,b/2),powM(a,b/2));
  	else return mulM(a,mulM(powM(a,(b-1)/2),powM(a,(b-1)/2)));
}

// b^{-1} = b^{p-2} (mod p)
// a/b = a*b^{p-2} (mod p)
ll divM(ll a, ll b){ 
  	return mulM(a,powM(b,MOD-2));
}

// n!, (n!)^{-1} のテーブル作成
ll fac[MAX], finv[MAX], inv[MAX];
void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep3(i,2,MAX-1){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COMB(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

/*** MOD CALCULATION ここまで ***/

void Main(){
    ll n, m, k;
    cin >> n >> m >> k;

    COMBinit();
    
    ll ans = 0;
    rep(i, k+1){
        ll temp = m;
        temp = mulM(temp, powM(m-1, n-i-1));
        temp = mulM(temp, COMB(n-1, i));
        ans = addM(ans, temp);
        // cout << ans << endl;
    }
    
    cout << ans << endl;
    return;
}

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


Measured memory_bytes: 8276
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N, A, B, C = lmi()
S = [input().strip() for _ in range(N)]

a = A
b = B
total = A + B + C
ans = []
if total != 2:
    for s in S:
        c = total - a - b
        if s == "AB":
            if a == 0 and b == 0:
                print("No")
                exit()
            if a > b:
                a -= 1
                b += 1
                ans.append('B')
            else:
                a += 1
                b -= 1
                ans.append('A')
        if s == "AC":
            if a == 0 and c == 0:
                print("No")
                exit()
            if a > c:
                a -= 1
                ans.append('C')
            else:
                a += 1
                ans.append('A')
        if s == "BC":
            if b == 0 and c == 0:
                print("No")
                exit()
            if b > c:
                b -= 1
                ans.append('C')
            else:
                b += 1
                ans.append('B')
        # print(a,b,c)

    # print(ans, a, b, c)
    print('\n'.join(['Yes'] + ans))
    exit()

case = {(A, B, C): []}  # 1,1 1,0 0,1 0,0 2,0 0,2
ans = []

for i, s in enumerate(S):
    # while True:
    #     s = input().strip()
    new_case = {}
    for (a, b, c), v in case.items():
        if s == "AB":
            if a == 0 and b == 0:
                continue
            elif a == 1 and b == 1:
                new_case[(0, 2, 0)] = list(v) + ['B']
                v.append('A')
                new_case[(2, 0, 0)] = v
                # two case
                pass
            else:
                v.append('A' if b else 'B')
                new_case[(abs(a - 1), abs(b - 1), c)] = v
        if s == "AC":
            if a == 0 and c == 0:
                continue
            if a == c:
                new_case[(2, 0, 0)] = list(v) + ['A']
                v.append('C')
                new_case[(0, 0, 2)] = v

                # two case
                pass
            else:
                v.append('C' if a else 'A')
                new_case[(abs(a - 1), b, abs(c - 1))] = v

        if s == "BC":
            if b == 0 and c == 0:
                continue
            elif b == c:
                new_case[(0, 2, 0)] = list(v) + ['B']
                v.append('C')
                new_case[(0, 0, 2)] = v
            else:
                v.append('B' if c else 'C')
                new_case[(a, abs(b - 1), abs(c - 1))] = v

    if not new_case:
        print("No")
        exit()
    case = new_case
    if len(case) == 1:
        key = list(case.keys())[0]
        ans += case[key]
        case[key] = []

print('\n'.join(['Yes'] + ans + list(case.values())[0]))


Measured memory_bytes: 85484
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;

double f(vector<vector<vector<double>>>& dp, int a, int b, int c, int N){
    if(dp[a][b][c] > -0.5)return dp[a][b][c];
    int d = N - a - b - c;
    // cout<<a<<b<<c<<endl;
    double res = 0;
    {
        double da = a,db = b,dc = c, dd=d,dN = N;
        double A = a > 0 ? (f(dp,a-1,b+1,c,N)+1.0) * da / dN : 0.0;
        double B = b > 0 ? (f(dp,a,b-1,c+1,N)+1.0) * db / dN : 0.0;
        double C = c > 0 ? (f(dp,a,b,c-1,N  )+1.0) * dc / dN : 0.0;
        res = dN/(dN-dd) * (A+B+C) + dd/(dN-dd);
        // cout<<a<<b<<c<<"!"<<endl;
    }
    dp[a][b][c] = res;
    // cout<<a<<b<<c<<d<<" "<<res<<endl;
    return dp[a][b][c];

}

int main(){
    int N,a,b,c;cin>>N;
    a=b=c=0;
    for(int i = 0;i < N;i++){
        int n;cin>>n;
        if(n == 3)a++;
        else if(n==2)b++;
        else if(n==1)c++;
    }
    vector<vector<vector<double>>> dp(N+1, vector<vector<double>>(N+1, vector<double>(N+1,-1.0)));
    dp[0][0][0] = 0;
    cout<<fixed<<setprecision(12)<<f(dp,a,b,c,N)<<endl;
}

Measured memory_bytes: 216960
import bisect

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
#print(A)

# Aの累積和を求めておく。
csum = [A[0] for _ in range(N+1)]
for i in range(1,N):
  csum[i] = csum[i-1]+A[i]

# M回以上握手できるとなる最小の幸福度を求める。
# l:M回以上握手ができる最小の幸福度。
l = 0
r = 10**6
while (l+1 < r):
  m = (l+r)//2
  p = 0 # 幸福度がm以上になる握手の回数
  for a in A:
    q = bisect.bisect_left(A,m-a)
    #print(q,m-a,A)
    p += N-q
  #print(l,m,r,p)
  if p >= M:
    l = m
  else:
    r = m
#print(l,m,r)

# 幸福度がl-1のときに握手ができる回数と幸福度を求める。
# その回数とMとの差の回数だけ、幸福度にlを追加する。
# (幸福度がlになる握手のパターンは複数ある可能性がある)
ans = 0
cnt = 0
for a in A:
  q = bisect.bisect_right(A,l-1-a)
  if q == 0:
    ans += csum[N-1]+a*N
    cnt += N
  elif q < N:
    ans += csum[N-1]-csum[q-1]+a*(N-q)
    cnt += N-q
  #print(a,q,ans,cnt)
ans +=l*(M-cnt)
print(ans)


Measured memory_bytes: 58832
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = float(10 ** 5)
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()
s = SR(n)
ans = 0
for i in range(n):
    flg = True
    for j in range(n):
        for k in range(n):
            if s[(j + i) % n][k] != s[(k + i) % n][j]:
                flg = False
                break
        if not flg:
            break
    else:
        ans += n

print(ans)

Measured memory_bytes: 42220
def gcd(a,b):
  return a if b == 0 else gcd(b,a%b)

N = int(input())
A = [int(x) for x in input().split()]

gcd_from_left = [0]*N # 自分のindexは含まないようなもの
gcd_from_right = [0]*N

for i in range(1,N):
  gcd_from_left[i] = gcd(A[i-1],gcd_from_left[i-1])
  gcd_from_right[N-1-i] = gcd(A[N-i],gcd_from_right[N-i])

ans = 0

for a,b in zip(gcd_from_left, gcd_from_right):
  x = gcd(a,b)
  if ans < x:
    ans = x
    
print(ans)

Measured memory_bytes: 63984
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1010, K = 21, mod = 1e9+7;
int n,m,a[N],dp[K][N];

inline int power(int a,int b){
	int ret=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) ret=1ll*ret*a%mod;
	return ret;
}
int fac[N],ifac[N];
inline void init(int n){
	fac[0]=1;
	For(i,1,n) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=power(fac[n],mod-2);
	Dow(i,n-1,0) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
inline int C(int n,int m){
	if (n<m||m<0) return 0;
	return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}

int main(){
	n=read(),m=read();
	init(n);
	dp[0][0]=1;
	For(i,1,m){
		a[i]=read();
		For(j,0,n) if (dp[i-1][j])
			For(k,0,min(n-j,a[i])) dp[i][j+k]=(dp[i][j+k]+1ll*dp[i-1][j]*C(n-j,k)%mod*C(n-k,a[i]-k))%mod; 
	}
	printf("%d\n",dp[m][n]);
}

Measured memory_bytes: 3788
import sys,math
import numpy as np
input = sys.stdin.readline

a_max=0
a = []
b = []
N,H = map(int,input().split())
for i in range(N):
    an,bn = map(int,input().split())
    b.append(bn)
    a_max = max(a_max,an)

b = np.array(b)
b = sorted(list(b[b>=a_max]))

cnt = 0
for i in range(len(b)):
    H -= b.pop()
    cnt += 1
    if H <=0:
        print(cnt)
        exit()

cnt += math.ceil(H/a_max)
print(cnt)


Measured memory_bytes: 33116
'''
WA
'''
n,k = map(int,input().split()) 
t = list(str(input()))
t = [int(s) for s in t]
last = t[0]
temp_c = 0
s = []
con_c = 0
temp_con_c = 0
corrent_p = 0
sum_t = []
for i in range(n):
    if last == t[i]:
        temp_c += 1
    else:
        last = t[i]
        s.append(temp_c)
        temp_c = 1
s.append(temp_c)
if t[n-1] == 0:
    s.append(0)
l = len(s)
if k*2 <= l:
    sum_t.append(0)
    for i in range(l):
        sum_t.append(sum_t[i]+s[i])
    l = len(sum_t)
    if t[0] == 0:
        for i in range(l-k*2-1):
            if i%2 == 0:
                temp_con_c = sum_t[i+k*2]-sum_t[i]
            else:
                temp_con_c = sum_t[i+k*2+1]-sum_t[i]
            if temp_con_c > con_c:
                con_c = temp_con_c
    else:
        for i in range(l-k*2-1):
            if i%2 ==0:
                temp_con_c = sum_t[i+k*2+1]-sum_t[i]
            else:
                temp_con_c = sum_t[i+k*2]-sum_t[i]
            if temp_con_c > con_c:
                con_c = temp_con_c
else:
    con_c = n

print(con_c)

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

using namespace std;

typedef long long ll;

struct point {
  ll x, y;
  int id;
  point () {}
  point (ll _x, ll _y, int _id) {
    x = _x, y = _y, id = _id;
  }
  bool operator < (const point &other) const {
    return x == other.x ? y < other.y : x < other.x;
  }
};

struct edge {
  int u, v;
  ll cost;
  edge () {}
  edge (int _u, int _v, ll _w) {
    u = _u, v = _v, cost = _w;
  }
  bool operator < (const edge &other) const {
    return cost < other.cost;
  }
};

const int N = 100010;

point p[N];
int n, par[N];
vector <edge> e;

bool cmp (point a, point b) {
  return a.y == b.y ? a.x < b.x : a.y < b.y;
}

int find (int x) {
  return par[x] == x ? x : par[x] = find(par[x]);
}

ll ans = 0;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    p[i].id = i;
    scanf("%lld %lld", &p[i].x, &p[i].y);
  }
  sort(p + 1, p + n + 1);
  for (int i = 2; i <= n; ++i) {
    e.push_back(edge(p[i - 1].id, p[i].id, p[i].x - p[i - 1].x));
  }
  sort(p + 1, p + n + 1, cmp);
  for (int i = 2; i <= n; ++i) {
    e.push_back(edge(p[i - 1].id, p[i].id, p[i].y - p[i - 1].y));
  }
  sort(e.begin(), e.end());
  for (int i = 1; i <= n; ++i) {
    par[i] = i;
  }
  for (int i = 0; i < int(e.size()); ++i) {
    int u = e[i].u, v = e[i].v;
    ll cost = e[i].cost;
    u = find(u), v = find(v);
    if (u == v) continue;
    par[u] = v, ans += cost;
  }
  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 8304
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    char[] s = scanner.next().toCharArray();
    int K = scanner.nextInt();
    for (int i = 0; i < s.length; i++) {
      if (s[i] == 'a') continue;
      int r = 'z' - s[i] + 1;
      if (K >= r) {
        s[i] = 'a';
        K -= r;
      }
    }
    s[s.length - 1] = (char) (s[s.length - 1] + K % 26);
    System.out.println(new String(s));
  }
}


Measured memory_bytes: 27300
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<sstream>
#include<string>
#include<vector>
#include<cstdio>
#include<ctime>
#include<bitset>
#include<algorithm>
#include<string>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define lson l , mid , rt << 1
#define rson mid + 1 , r , rt << 1 | 1

int read() {
	int ans = 0, flag = 1;
	char ch = getchar();
	while ((ch > '9' || ch < '0') && ch != '-') ch = getchar();
	if (ch == '-') flag = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
	return ans * flag;
}



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

	int m = a;
	int n = b;
	if (a < b)
	{
		int temp = a;
		a = b;
		b = temp;
	}

	int c;
	while (b != 0)
	{
		c = a % b;
		a = b;
		b = c;
	}
	cout << (long long int)(m / a)*n << endl;

	return 0;
}









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

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    int ALL = a[0];
    for(int i = 1; i < N; i++){
        ALL = ALL^a[i];
    }
    for(int i = 0; i < N; i++){
        int hoge = ALL^a[i];
        cout << hoge << " ";
    }
    cout << endl;
}

Measured memory_bytes: 4392
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<unordered_set>
#include<limits.h>
using namespace std;

typedef long long ll;



int main(){
    ll n;
    cin>>n;
    vector<ll> a(n),b(n);
    ll ans=0;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    for(ll i=n-1;i>=0;i--){
        a[i]+=ans;
        if(a[i]%b[i]==0)continue;
        if(a[i]<b[i]){
            ans+=b[i]-a[i];
        } else {
            ans+=(1+a[i]/b[i])*b[i]-a[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

string s;deque<char> deq;
void  t2(int f,char c,int cur){
    if(f-1 == cur){
        deq.push_front(c);
    }else if(f-1 != cur){
        deq.push_back(c);
    }
}

int main(){
    int q,cur = 0;
    cin >> s >> q;
    for(auto a : s)deq.push_back(a);
    for(int i = 0;i < q;i++){
        int t;cin >> t;
        if(t == 1){
            cur = 1-cur;
        }else if(t == 2){
            int f;char c;cin >> f >> c;
            t2(f,c,cur);
        }
    }
    string t;
    for(auto a : deq)t.push_back(a);
    if(cur)reverse(t.begin(),t.end());
    cout << t;
    return 0;
}


Measured memory_bytes: 1412
#include <iostream>
#include <string>
#include<algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;
int main()
{
	string yn[2] = { "Yes","No" };
	int a, b, c,x=1;
	cin >> a >> b >> c;
	int max = a;
	if (max < b) max = b;
	if (max < c) max = c;
	if (a + b + c - max == max) x = 0;
	cout << yn[x] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
#define int ll
signed main(){
    ios::sync_with_stdio(false);
    int n,m,k;
    cin>>n>>m>>k;
    vector<int> sa(n+1), sb(m+1);
    sa[0] = 0; sb[0] = 0;
    rep(i,n) {
        int a;
        cin >> a;
        sa[i+1] = sa[i]+a;
    }
    rep(i,m) {
        int b;
        cin >> b;
        sb[i+1] = sb[i]+b;
    }
    int ans = 0;
    for(int i = 0; i<= n; i++) {
        int rem = k-sa[i];
        if(rem < 0) break;
        auto b_num_it = upper_bound(sb.begin(),sb.end(),rem);
        int b_num;
        if (b_num_it == sb.end()) b_num = m;
        else b_num = b_num_it - sb.begin() - 1;
        chmax(ans,i + b_num);
    }
    cout << ans << endl;
}


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

int main()
{
    char W[10+1];
    char T[1000+1];
    int count;
    int W_len, T_len;
    int i, j;

    scanf("%s", W);
    W_len = strlen(W);
    for(i = 0; i < W_len; i++) {
        if(W[i] >= 'a' && W[i] <= 'z') {
            W[i] = W[i] - 'a' + 'A';
        }
    }

    count = 0;
    while(1) {
        scanf("%s", T);
        if(strcmp(T, "END_OF_TEXT") == 0) {
            break;
        }

        T_len = strlen(T);
        if(T_len == W_len) {
            for(i = 0; i < T_len; i++) {
                if(T[i] == W[i] || (T[i] >= 'a' && T[i] <= 'z' && (T[i]-'a'+'A') == W[i])) {
                    ;
                } else {
                    break;
                }
            }
            if(i == W_len) {
                count += 1;
            }
        }
    }

    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 2096
import math
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
t = sum(a)
c = 0
f = 0
for i in range(n):
	if a[i] >= math.ceil(t/(4*m)):
		c += 1

if c>=m:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
int x,y;
cin>>x>>y;

int mini=x*2;
int maxi=x*4;

	if(y<=maxi && y>=mini)
	{
		if(y%2==0)
		cout<<"Yes";
		else
	cout<<"No";
	}
	else
	cout<<"No";
}

Measured memory_bytes: 3592
import java.util.*;

class Main {
	  static int mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
      long cnt =0;
      int flg=0;
      long N = sc.nextInt();
      long L = sc.nextInt();
      
      for(int i=0;i<N;i++) {
    	  cnt=cnt+L+i;
    	  if(L+i==0) {
    		  flg = 1;
    	  }
      }
      if (flg==0) {
    	  if(L<0) {
    		  cnt = cnt -(L+N-1);
    	  } else {
    		  cnt = cnt - (L);
    	  }
      }
      
      System.out.println(cnt);    	  
  }
 
}

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

main()
{
	int n;
	cin >> n;
	int ans = 0;
	
	while(n--) {
		ll l;
		cin >> l;
		ans += __builtin_ctzll(l);
	}
	cout << ans << '\n';
}

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

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans=0;
    ans=(n/(a+b))*a;
    ll save=n%(a+b);
    if(save<a) ans+=save;
    else ans+=a;
    cout << ans << endl;
}

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

int main()
{
    int R,G,B,N;
    cin >> R >> G >> B >> N;
    int r,g;
    int N1=N;
    int N2=N;
    int c=0;
    for (r=0;r<=N/R;r++){
        N1=N-R*r;
        if(N1==0){
        	c++;
            break;
        }
    	for(g=0;g<=N1/G;g++){
            N2=N1-G*g;
            if(N2==0){
            	c++;
                break;
            }
            if(N2%B==0){
            	c++;
                continue;
            }
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <iomanip>
#include <map>
#include <bitset>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define INF 1200000000
#define LLINF 1100000000000000000
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define SHOWVEC(v, n) for(int i = 0; i < (n); i++)cerr<<(v[i])<<' ';cerr<<endl;

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

int main()
{
  int N; cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  sort(ALL(A));
  vector<ll> Asum(A);
  REP(i, N - 1) Asum[i + 1] += Asum[i];

  int idx = N - 1;
  while (idx > 0 && 2*Asum[idx - 1] >= A[idx]) idx--;
  cout << (N - idx) << endl;

  return 0;
}

Measured memory_bytes: 1792
-- Simultaneous Equation
import Text.Printf -- printf

main = getContents >>= putStr . solve

solve :: String -> String
solve = unlines . map (unwords . map (floatFormat . roundZero) . simul . map read . words) . lines

roundZero :: Float -> Float
roundZero x | x == 0.0 = 0
            | otherwise = x

floatFormat :: Float -> String
floatFormat = printf "%.3f"

simul :: Fractional a => [a] -> [a]
simul [a,b,c,d,e,f] = [x,y]
  where
    det = a * e - d * b
    x = (c * e - b * f) / det
    y = (a * f - c * d) / det

-- printf :: PrintfType r => String -> r
-- printf "format"

Measured memory_bytes: 4336
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int w = sc.nextInt();
		int h = sc.nextInt();
		while(w != 0 && h != 0){
			int sx = -1;
			int sy = -1;
			int[][] tile = new int[h][w];
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					tile[i][j] = sc.nextInt();
					if(tile[i][j] == 2){
						sy = i;
						sx = j;
					}
				}
			}
			int res = func(tile, sx, sy, 1);
			System.out.println(res > 10 ? -1 : res);
			w = sc.nextInt();
			h = sc.nextInt();
		}
		
		sc.close();
	}
	static int func(int[][] tile, int x, int y, int n){
		if(n > 10){
			return 11;
		}
		int[] mx = {0, 0, 1,-1};
		int[] my = {1,-1, 0, 0};
		int res = 11;
		for(int i = 0; i < 4; i++){
			int tx = x + mx[i];
			int ty = y + my[i];
			if(tx >= 0 && tx < tile[0].length && ty >= 0 && ty < tile.length && tile[ty][tx] != 1){
				while(tx >= 0 && tx < tile[0].length && ty >= 0 && ty < tile.length){
					if(tile[ty][tx] == 3){
						return n;
					}
					if(tile[ty][tx] == 1){
						tile[ty][tx] = 0;
						int tmp = func(tile, tx - mx[i], ty - my[i], n + 1);
						if(res > tmp){
							res = tmp;
						}
						tile[ty][tx] = 1;
						break;
					}
					tx = tx + mx[i];
					ty = ty + my[i];
				}
			}
		}
		return res;
	}
}

Measured memory_bytes: 61340
#include<stdio.h>
#include<string.h>
int ab (int a,int i);
int main(void)
{
    int ini,i,hit,out,ten;
    char event[8];
    scanf("%d",&ini);
    for(i=0;i<ini;i++){
        hit=0,out=0,ten=0;
        while(1){
            if(out==3)break;
            scanf("%s",event);
            if(!strcmp(event,"HIT")){
                hit++;
                if(hit==4){
                    ten++;
                    hit--;
                }
            }
            else if(!strcmp(event,"HOMERUN")){
                ten+=hit+1;
                hit=0;
            }
            else if(!strcmp(event,"OUT")){
                out++;
            }
        }
        printf("%d\n",ten);
    }
    return 0;
}

Measured memory_bytes: 596
PROGRAM piyo
      IMPLICIT NONE
      INTEGER,PARAMETER :: prec = 16
      real(prec) :: b
      integer(prec) :: aa,bb
      
      read*,aa,b
      

      bb = nint( b*100_prec )
      print'(i0)',aa*bb/100_prec
      
      
      stop
      !debugg
      
      
      
      END PROGRAM

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

typedef long long ll;
#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 INF 999999999
#define DEBUG(s) cout << s << endl

using namespace std;

int main() {
    int n;
    int a[2][101];
    cin >> n;
    if (n == 1) {
        int x, y;
        cin >> x >> y;
        cout << x + y;
        return 0;
    }
    int sum[2][101];
    for (int j = 0; j < 2; j++) {
        for (int i = 1; i <= n; i++)
            cin >> a[j][i];
    }
    for (int j = 0; j < 2; j++) {
        sum[j][0] = 0;
        for (int i = 1; i <= n; i++)
            sum[j][i] = sum[j][i - 1] + a[j][i];
    }
    int ans = 0;
    for (int i = 1; i < n; i++) {
        ans = max(ans, sum[0][i] + sum[1][n] - sum[1][i - 1]);
    }
    cout << ans;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# ITP1_9_D
# 文字列変換

s =input()
n = int(input())

for i in range(n):
    data = list(input().split())
    
    if data[0] == "print":
        print(s[int(data[1]):int(data[2]) + 1] )
    elif data[0] == "reverse":
        rs = s[int(data[1]):int(data[2]) + 1]
        rs = rs[::-1]
        s = s[:int(data[1])] + rs + s[int(data[2]) + 1:]
    else:
        s = s[:int(data[1])] + data[3] + s[int(data[2]) + 1:]



Measured memory_bytes: 5616
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1,ans=0;
vll_t a,b;
// int c(int a){
// 	return ((a)*(a-1)*(a-2))/6;
// }
// int find(int n){
// 	int c=n,count=0;
// 	while(c>0){
// 		count++;
// 		c/=10;
// 	}
// 	return count;
// }
 void solve(ll num,ll n,int has3,int has5,int has7){
	if(num>n){
		return ;
	}
	if(has3>0&&has5>0&&has7>0){
		ans++;
	}
	solve(num*10+3,n,has3+1,has5,has7);
	solve(num*10+5,n,has3,has5+1,has7);
	solve(num*10+7,n,has3,has5,has7+1);
}
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
	ll n;
	cin>>n;
	// int dp[10];
	// dp[0]=dp[1]=dp[2]=0;
	// for(int i=3;i<10;i++){
	// 	dp[i]=dp[i-1]+c(i)*6*pow(3,i-3);
	// }
	// int digits=find(n);
	// if(digits<3){
	// 	cout<<0<<endl;
	// 	return 0;
	// }
	solve(0,n,0,0,0);
	cout<<ans<<endl;
}

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

using namespace std;

char ch[1000005];

int main()
{
    long int s=0,l=0,i,j;

    scanf("%[^\n]",ch);
    l=strlen(ch);

    for(i=1; i<l; i++){
        if (ch[i]!=ch[i-1]){
            ++s;
        }
    }
    printf("%ld\n",s);
    return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s; cin >> s;
    int n = s.size();
    ll res = 0;
    rep(i, 1 << n-1){
        string tmp = {s[0]};
        rep(j, n-1){
            if(i & (1 << j)){
                res += stoll(tmp);
                tmp = "";
            }
            tmp = tmp + string({s[j+1]});
        }
        res += stoll(tmp);
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352