akhauriyash/Code-Regression huggingface dataset:
/*
Author:Jenil Mehta
Not yet serious but trying to be serious :)
Coding is lub
*/
 
#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#define boostup ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
using namespace std;
int main()
{
    boostup;
    // ll t;
    // while(t--)
    // {
        string s;
        cin>>s;
        ll i,j;
        ll n=s.length();
        if(n==6)
        {
            if(s[2]==s[3])
            {
                if(s[4]==s[5])
                {
                    cout<<"Yes"<<endl;
                }
                else
                {
                    cout<<"No"<<endl;
                }
            }
            else
            cout<<"No"<<endl;
        }
        else
        cout<<"No"<<endl;
    //}
}

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

using namespace std;

const int N = 31;
int n, m;
int cnt[N];

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

    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        int k;
        cin >> k;
        for(int j = 0; j < k; j++)
        {
            int a;
            cin >> a;
            cnt[a]++;
        }
    }

    int ans = 0;
    for(int i = 1; i <= m; i++)
    {
        if(cnt[i] == n)
            ans++;
    }

    cout << ans;

    return 0;
}


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

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


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

int line_serch(vector<int> v, int num) {
	int i = 0;
	v.push_back(num);
	while (v[i] != num) i++;
	if (i == v.size()-1) return 0;
	return 1;
}


int main() {
	int n; cin >> n;
	vector<int> s(n);
	for (int i = 0; i < n; i++) cin >> s[i];
	int m; cin >> m;
	int t, ans = 0;
	for (int i = 0; i < m; i++) {
		cin >> t;
		ans += line_serch(s, t);
	}
	cout << ans << endl;
}


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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); ++i)
#define REP(i,start,end) for(int i=(start);i<=(end);++i)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	char x,y;
	cin >> x >> y;

	if(x > y) cout << ">\n";
	else if(x == y) cout << "=\n";
	else cout << "<\n";
	return 0;
}

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

int N;
string S;

void solve() {
  int r = 0, b = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'R') {
      r++;
    } else {
      b++;
    }
  }
  if (r > b) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return;
}

int main() {
  cin >> N >> S;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const double pi=acos(-1);
int sx,sy,tx,ty;
int n,x[N],y[N];
struct work{int x,y;}p[N];
ll ans=0,cnt=0;
int ret=0;
bool cmp1(work a,work b){return a.x<b.x;}
int d[N],len=0,cc;
int lis()
{
	for (int i=1;i<=cnt;i++)
	if (!len||p[i].y>d[len]) d[++len]=p[i].y;
	else 
	{
		cc=lower_bound(d+1,d+len+1,p[i].y)-d;
		d[cc]=p[i].y;
	}
	return len;
}
int main()
{
	scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
	ans=1ll*100*(abs(sx-tx)+abs(sy-ty));
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d%d",&x[i],&y[i]);
	if (tx<sx) swap(sx,tx),swap(sy,ty);
	if (ty<sy)
	{
		for (int i=1;i<=n;i++) y[i]=1e8-y[i];
		ty=1e8-ty;sy=1e8-sy;
	}
	for (int i=1;i<=n;i++)
		if (x[i]>=sx&&x[i]<=tx&&y[i]>=sy&&y[i]<=ty) p[++cnt]=work{x[i],y[i]};
	sort(p+1,p+cnt+1,cmp1);
	ret=lis();
	printf("%.13f",ans-1.0*ret*(20-pi*5)+((ret==min(tx-sx+1,ty-sy+1))?pi*5.0:0));
}

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

const ll mod = 1e9 + 7;
ll fact[N] , inv_fact[N];
ll C(ll n, ll r)
{
    if(n < 0 || r < 0 || r > n)   return 0;
    return (fact[n] * ((inv_fact[n-r] * inv_fact[r])%mod))%mod;
}
ll fp(ll a, ll p)
{
    ll r = 1;
    while(p)
    {
        if(p&1) r = (r*a)%mod;
        p >>= 1;
        a = (a*a)%mod;
    }
    return r;
}
ll paths(ll a , ll b)
{
    ll tmp = C(a+b-2,b-1);
    return tmp;
}
bool comp ( pair < ll , ll > a , pair < ll , ll > b)
{
    return a.first + a.second < b.first + b.second;
}
int main()
{
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i < N ; i++)
        fact[i] = (fact[i-1]*i)%mod , inv_fact[i] = fp(fact[i],mod-2);
    int h , w, n;
    scanf("%d%d%d",&h,&w,&n);
    vector < pair < int , int > > v(n);
    for(int i = 0 ;i < n; i++)
        scanf("%d%d",&v[i].first,&v[i].second);
    v.push_back({h,w});

    sort(v.begin(),v.end(),comp);
    ll dp[n+1];
    for(int i = 0 ; i <= n; i++)
    {
        ll cnt = paths(v[i].first , v[i].second);
        for(int j = 0 ; j < i ; j++)
            if(v[j].first <= v[i].first && v[j].second <= v[i].second)
                cnt = (cnt + mod - ((dp[j]*paths(v[i].first - v[j].first + 1 , v[i].second - v[j].second + 1))%mod))%mod;
        dp[i] = cnt;
    }
    printf("%lld\n",dp[n]);
    return 0;
}


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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"
#include "profile.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define profile(X) LOG_DURATION(X)
#else
#define debug(...) 42
#define profile(...) 42
#endif

using ll = int64_t;
using ld = double;
const ld EPS = 1e-9;
//const ll MOD = 924844033;
const ld PI = 3.141592653589793;
const int maxn = 600001;
const int MOD = 1e9 + 7;
using cd = complex<double>;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

int dp[301][301][301]; // rgb
int used[301][301][301]; // rgb
signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    profile("all");

    auto solve = [](int _) {
        int n;
        cin >> n;
        int cnt[5] = {};
        for (int i = 1; i <= n; ++i) {
            int a;
            cin >> a;
            if (a & 1) {
                ++cnt[1];
            } else if (a / 2 & 1) {
                cnt[2]++;
            } else {
                cnt[4]++;
            }
        }
        if (cnt[2]) {
            if (cnt[4] >= cnt[1]) {
                cout << "Yes\n";
            } else {
                cout << "No\n";
            }
        } else {

            if (cnt[4] + 1 >= cnt[1]) {
                cout << "Yes\n";
            } else {
                cout << "No\n";
            }

        }
    };


    fast_io();
    cout.precision(9);
    cout << fixed;

    solve(1);


}


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

int main()
{
    int a,b,c,k;cin >> a >> b >> c >> k;
    int res=0;
    if(a>=k){
        res=k;
    } else if(a+b>=k){
        res=a;
    } else{
        res=a-(k-a-b);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3636
n = int(input())
line = input()
arr = line.split(" ")
nums = []
for c in range(n):
    nums.append(int(arr[c]))

def trace(n_list):
    n_list_str = ""
    for num in n_list:
        n_list_str += str(num)
        n_list_str += " "
    print(n_list_str.rstrip(" "))
            
print(line)
for i in range(1, n):
    v = nums[i]
    j = i-1
    while j >= 0 and nums[j] > v:
        nums[j+1] = nums[j]
        j -= 1
    nums[j+1] = v
    trace(nums)

Measured memory_bytes: 5600
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);
    swap(x,y); swap(x,z);
    printf("%d %d %d\n",x,y,z);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    ll a,b,k;
    cin>>a>>b>>k;
    vll v;
    rep2(i,a,min(b+1,a+k)) v.pb(i);
    rep2(i,max(a,b-k+1),b+1) v.pb(i);
    sort(all(v));
    ERASE(v);
    for(auto i:v) cout<<i<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,m;
 cin>>n>>m;
 double a[n];
 int i;
 double sum=0;
 for(i=0;i<n;i++)
 {
 	cin>>a[i];
 	sum+=a[i];
 }
 sum/=4*m;
 sort(a,a+n);
 int ans=1;
 for(i=n-1;i>=n-m;i--)
 {
 	if(a[i]>=sum)
 	continue;
 	else
 	{
 		ans=0;
 		break;
	 }
 }
 if(ans==1)
 cout<<"Yes"<<endl;
 else
 cout<<"No"<<endl;
 return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int dx[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
int dy[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
const ll MOD = 1000000007;
const ll INF = 1000000;
const int MAX = 10000000;

int h, w, D;
int a[100005];
int sum[100005];
int main() {
    cin >> h >> w >> D;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            int  s;
            cin >> s;
            a[s] = w*i + j;
        }
    }

    for (int i = D + 1; i <= h*w; i++){
        sum[i] = sum[i - D] + abs(a[i] / w - a[i - D] / w) + abs(a[i] % w - a[i - D] % w);
    }

    int Q;
    cin >> Q;
    while (Q > 0){
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l] << endl;
        Q--;
    }
    
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;  //このネームスペースを使う

int main(){
  const float BTC_RATE = 380000.0;
  int N ;
  int i;
  float sum;

  cin >> N ;
  sum = 0;

  float x[N];
  string u[N];

  for(i=0;i<N;i++){
    cin >> x[i] >> u[i];
    //cout << x[i] << endl;
    //cout << u[i] << endl;
    if(u[i] == "BTC"){
      sum += x[i] * BTC_RATE;
    }
    else{
      sum += x[i];
    }
  }
  
  cout << sum << endl;
  

  return 0;
}



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

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

  if (A + B == C + D) cout << "Balanced" << endl;

  else if (A + B < C + D) cout << "Right" << endl;
  
  else cout << "Left" << endl;


}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





int n, q;
vector<int> edge[200000];
int val[200000];


void dfs(int u, int par, int x) {
	val[u] += x;

	for (int v: edge[u]) {
		if (v == par)continue;
		dfs(v, u, val[u]);
	}
}


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

	cin >> n >> q;
	rep(i,n-1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	rep(i, q) {
		int p, x;
		cin >> p >> x;
		p--;
		val[p] += x;
	}
	dfs(0, -1, 0);


	rep(i,n) {
		if (i)cout << ' ';
		cout << val[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 23552
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

unordered_map<long, long> mp;

int main() {
    int n;
    cin >> n;
    int posm = -1, negm = 1;
    int posmi, negmi;
    VI v;
    REP(i,n) {
        int a;
        cin >> a;
        if (a >= 0) {
            if (a > posm) {
                posm = a;
                posmi = i + 1;
            }
        } else {
            if (a < negm) {
                negm = a;
                negmi = i + 1;
            }
        }
        v.push_back(a);
    }
    if (posm == -1) {
        // all negative
        cout << n - 1 << endl;
        for (int i = n; i > 1; i--) {
            cout << i << " " << i - 1 << endl;
        }
        return 0;
    }
    if (negm == 1) {
        // all positive
        cout << n - 1 << endl;
        for (int i = 1; i < n; i++) {
            cout << i << " " << i + 1 << endl;
        }
        return 0;
    }
    
    if (posm > abs(negm)) {
        cout << 2 * n - 1 << endl;
        for (int i = 1; i <= n; i++) {
            cout << posmi << " " << i << endl;
        }
        for (int i = 1; i < n; i++) {
            cout << i << " " << i + 1 << endl;
        }
        return 0;
    }
    
    cout << 2 * n - 1 << endl;
    for (int i = 1; i <= n; i++) {
        cout << negmi << " " << i << endl;
    }
    for (int i = n; i > 1; i--) {
        cout << i << " " << i - 1 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    string ans;
    cin >> ans;
    ll q;
    cin >> q;
    ll re = 0;
    string front = "";
    while(q--){
        ll t;
        cin >> t;
        if(t==1){
            re ^= 1;
        }else{
            ll f;
            string c;
            cin >> f >> c;
            if((re==0&&f==1)||(re==1&&f==2)){
                front += c;
            }else{
                ans += c;
            }
        }
    }
    reverse(all(front));
    ans = front + ans;
    if (re == 1) reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 1196
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    N = int(input())
    A = list(map(int, input().split()))
    total = [0]*(N+1)
    wa = 0
    for i in range(N):
        wa += A[i]
        total[i+1] = wa
    res = 0
    c = Counter(total)
    for i in c.values():
        res += (i*(i-1))//2
    print(res)

if __name__ == '__main__':
    main()

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


int h, w;
char table[100][100];


void solve(int x, int y, char f){
	table[y][x] = '_';

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

	for (int i = 0; i < 4; i++){
		int X = x + dx[i];
		int Y = y + dy[i];

		if (0 <= X && X < w && 0 <= Y && Y < h && table[Y][X] == f)
			solve(X, Y, table[Y][X]);

	}
}


int main(){
	while (cin >> h >> w, (h | w) != 0){
		int cnt = 0;
		for (int y = 0; y < h; y++){
			for (int x = 0; x < w; x++){
				cin >> table[y][x];
			}
		}

		for (int y = 0; y < h; y++){
			for (int x = 0; x < w; x++){
				if (table[y][x] != '_'){
					cnt++;
					solve(x, y, table[y][x]);
				}
			}
		}

		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 4112
import math
import copy

def trial_division(n):
    check = 0
    #素因数を格納するリスト
    factor = []
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp+1):
        while n % num == 0:
            n /= num
            factor.append(num)
            check = 1
    #素数チェック
    if check == 0:
        factor.append(n)
    return factor

n = int(input())
ans = 1

div = []
for i in range(2,n+1):
    for j in trial_division(i):
        div.append(j)
        div = list(set(div))

for i in div:
    x = 0
    for j in range(i,n+1):
        num = j
        while num % i == 0:
            x += 1
            num /= i
    ans = (ans*(x+1))%(10**9+7)

print(ans)


Measured memory_bytes: 41456
# ABC 061: C – Big Array
N, K = [int(i) for i in input().split()]
a, b = [], []
for _ in range(N):
    tmp = input().split()
    a.append(int(tmp[0]))
    b.append(int(tmp[1]))

cnt = [0] * (100000 + 1)

for i in range(N):
    cnt[a[i]] += b[i]

for j in range(100000 + 1):
    if K <= cnt[j]:
        print(j)
        break
    K -= cnt[j]

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

struct point{
    int tx;
    int ty;
    int kx;
    int ky;
    int t;
};

int main(){
  while(true){
      int X, Y;
      cin >> X >> Y;
      if(X==0&&Y==0)
          break;

      int d[52][52];
      for(int y=0; y<=Y+1; y++)
          for(int x=0; x<=X+1; x++)
                d[y][x] = 1;

      struct point now;
      cin >> now.tx >> now.ty;
      cin >> now.kx >> now.ky;
      now.t = 0;

      queue<struct point> que;
      que.push(now);

      map<int, bool> org;

      for(int y=1; y<=Y; y++)
          for(int x=1; x<=X; x++)
                cin >> d[y][x];

      while(true){
          if(que.empty()){
              cout << "NA" << endl;
                break;
          }

          now = que.front();
          que.pop();

          int tk = ((now.tx*100+now.ty)*100+now.kx)*100+now.ky;
          if(org.find(tk)!=org.end())
              continue;
          else
              org[tk] = true;

          if(now.t>=100){
              cout << "NA" << endl;
              break;
          }

          if(now.tx==now.kx&&now.ty==now.ky){
              cout << now.t << endl;
              break;
          }

          struct point nxt = now;
          if(d[nxt.ty-1][nxt.tx]==0)
              nxt.ty--;
          if(d[nxt.ky+1][nxt.kx]==0)
              nxt.ky++;
          nxt.t++;
          que.push(nxt);

          nxt = now;
          if(d[nxt.ty+1][nxt.tx]==0)
              nxt.ty++;
          if(d[nxt.ky-1][nxt.kx]==0)
              nxt.ky--;
          nxt.t++;
          que.push(nxt);

          nxt = now;
          if(d[nxt.ty][nxt.tx-1]==0)
              nxt.tx--;
          if(d[nxt.ky][nxt.kx+1]==0)
              nxt.kx++;
          nxt.t++;
          que.push(nxt);

          nxt = now;
          if(d[nxt.ty][nxt.tx+1]==0)
              nxt.tx++;
          if(d[nxt.ky][nxt.kx-1]==0)
              nxt.kx--;
          nxt.t++;
          que.push(nxt);
      }
  }

  return 0;
}



Measured memory_bytes: 11592
# B - Substring

S = str(input())
T = str(input())

s = len(S)
t = len(T)
ans = 10**18

for i in range(s-t+1):
    tmp = 0
    for j in range(t):
        if S[i+j] == T[j]:
            continue
        else:
            tmp += 1
    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 9036
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int a = -1, b, c = 0;
vi s;
vvi g;
auto dfs(int v) {
	if (v == b) {
		c++;
		return;
	}
	s[v] = 1;
	REP(i, 2) {
		if (s[g[v][i]] == 0)dfs(g[v][i]);
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vi d(n, 0);
	g.resize(n);
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		d[a]++;
		d[b]++;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	REP(i, n)if (d[i] & 1) {
		cout << "No" << endl;
		return 0;
	}
	if (*max_element(ALL(d)) >= 6) {
		cout << "Yes" << endl;
		return 0;
	}
	int cnt = 0;
	REP(i, n) {
		if (d[i] == 4)cnt++;
	}
	if (cnt >= 3) {
		cout << "Yes" << endl;
		return 0;
	}
	else if (cnt <= 1) {
		cout << "No" << endl;
		return 0;
	}
	s.resize(n, 0);
	REP(i, n) {
		if (d[i] == 4) {
			if (a == -1)a = i;
			else b = i;
		}
	}
	REP(i, 4) {
		s[a] = 1;
		dfs(g[a][i]);
	}
	if (c == 4) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}


}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, val;;
    cin >> n;
    ll total = 1, odd = 1;
    for(int i = 0; i < n; i++) {
        cin >> val;
        if (val % 2 == 0)
            odd *= 2;
        total *= 3;
    }
    cout << total - odd << endl;
    return 0;
}


Measured memory_bytes: 3648
n, m = list(map(int, input().split()))
root = [[] for _ in range(n)]
answer = [-1]*n
answer[0]=0
for i in range(m):
    c = list(map(int, input().split()))
    root[c[1]-1].append(c[0]-1)
    root[c[0]-1].append(c[1]-1)
count = 1  # 最初から1の部屋はOKにしとく
queue = [0]
# print(root)
newqueue = []
while(count < n and len(queue) != 0):
    for j in queue:
        for rootnum in root[j]:
            if(answer[rootnum] == -1):
                answer[rootnum] = j
                newqueue.append(rootnum)
                count += 1
	
    queue = newqueue[:]
    newqueue = []
if(count < n):
    print('No')
else:
    print('Yes')
    for l in range(n-1):
        print(answer[l+1]+1)


Measured memory_bytes: 33812
#include <stdio.h>

int main(){
  int r,c,a[101][101],i,j,sum=0;
  scanf("%d %d",&r,&c);
  for(i=0; i<101; i++){
    for(j=0; j<101; j++){
      a[i][j]=0;
    }
  }
  for(i=0; i<r; i++){
    for(j=0; j<c; j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(i=0; i<r; i++){
    for(j=0; j<c; j++){
      a[r][j]+=a[i][j];
      a[i][c]+=a[i][j];
    }
  }//-----            
for(i=0; i<r; i++){
    for(j=0; j<c; j++){
      a[r][c]+=a[r][j];
      a[r][c]+=a[i][c];
    }
  }
  a[r][c]/=(r+c);
  for(i=0; i<=r; i++){
    for(j=0; j<=c; j++){
      if(j==c)printf("%d\n",a[i][j]);
      else printf("%d ",a[i][j]);
    }
  }
  return 0;
}



Measured memory_bytes: 2032
#include<cstdio>
#include<climits>
#include<iostream>
#include<vector>
using namespace std;

vector<int> cs;
vector<vector<int> > sm;

int total_satisfaction(vector<int>& ts, int d) {
	vector<int> ls;
	for (int i = 0; i < 26; i++) ls.push_back(0);
	int s = 0;

	for (int i = 0; i < d; i++) {
		int t = ts[i];
		t--;
		s += sm[i][t];
		ls[t] = i + 1;
		
		int dis = 0;
		for (int j = 0; j < 26; j++) {
			dis += cs[j] * ((i+1) - ls[j]);
		}
		s -= dis;
	}

	return s;
}

int main() {
	int d;
	vector<int> ts;

	cin >> d;

	int x;
	for (int i = 0; i < 26; i++) {
		cin >> x;
		cs.push_back(x);
	}
	for (int i = 0; i < d; i++) {
		vector<int> v;
		sm.push_back(v);
		for (int j = 0; j < 26; j++) {
			cin >> x;
			sm[i].push_back(x);
		}
	}

	for (int i = 0; i < d; i++) {
		int mx = INT_MIN;
		int mxt = -1;

		for (int t = 1; t <= 26; t++) {
			ts.push_back(t);
			int s = total_satisfaction(ts, i + 1);
			if (s > mx) {
				mx = s;
				mxt = t;
			}
			ts.pop_back();
		}

		ts.push_back(mxt);
		cout << mxt << endl;
	}
}


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

signed main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

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

  auto get_cost = [&](int b) {
    int64_t res = 0;
    for (int i = 0; i < N; ++i) {
      res += abs(A[i] - (b + i));
    }
    return res;
  };

  int lb = -1e9, ub = 1e9;
  while (9 < ub - lb) {
    int xb = lb + (ub - lb) / 3;
    int yb = lb + (ub - lb) / 3 * 2;
    int64_t lc = get_cost(lb);
    int64_t xc = get_cost(xb);
    int64_t yc = get_cost(yb);
    int64_t uc = get_cost(ub);
    if (lc <= xc && xc <= yc && yc <= uc) {
      ub = yb;
    } else if (lc >= xc && xc <= yc && yc <= uc) {
      ub = yb;
    } else if (lc >= xc && xc >= yc && yc <= uc) {
      lb = xb;
    } else if (lc >= xc && xc >= yc && yc >= uc) {
      lb = xb;
    } else assert(false);
  }

  int64_t ans = 1LL << 60;
  for (int i = lb; i < ub + 1; ++i) {
    ans = min(ans, get_cost(i));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
<?php
fscanf(STDIN,'%d%d',$H,$W);
$A=[];
for ($i=0; $i <$H ; $i++) {
  // code...
  fscanf(STDIN,'%s',$S);
  $P=str_split(trim($S));
  $A[$i]=$P;
}
$c=0;
for ($i=0; $i <$H ; $i++) {
  // code...
  $c=0;
  for ($j=0; $j <$W ; $j++) {
    // code...
    $c=0;
    if($A[$i][$j]=="#"){

    }else{
      if(isset($A[$i][$j+1]) and $A[$i][$j+1]==="#"){
        $c++;

      }
      if(isset($A[$i][$j-1]) and $A[$i][$j-1]==="#"){
        $c++;

      }
      if(isset($A[$i+1][$j]) and $A[$i+1][$j]==="#"){
        $c++;

      }
      if(isset($A[$i-1][$j]) and $A[$i-1][$j]==="#"){
        $c++;

      }
      if(isset($A[$i-1][$j-1]) and $A[$i-1][$j-1]==="#"){
        $c++;

      }
      if(isset($A[$i-1][$j+1]) and $A[$i-1][$j+1]==="#"){
        $c++;

      }
      if(isset($A[$i+1][$j-1]) and $A[$i+1][$j-1]==="#"){
        $c++;

      }
      if(isset($A[$i+1][$j+1]) and $A[$i+1][$j+1]==="#"){
        $c++;

      }
      $A[$i][$j]=$c;
    }
  }
}
for ($i=0; $i <$H ; $i++) {
  // code...
  for ($j=0; $j <$W ; $j++) {
    // code...
    echo $A[$i][$j];
  }
  echo "\n";
}
echo "\n";





 ?>


Measured memory_bytes: 4084
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string.h>
#include <utility>
#include <queue>
#include <stack>
#include <iomanip>
#include <ctype.h>
#include <map>
#include <set>
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <sstream>
#include <math.h>
#include <time.h>
#include <iostream>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <tuple>
#include <cmath>
#include <stdio.h>      /* printf, fgets */
#include <stdlib.h>
#include <fstream>

using namespace std;

typedef long long LL;

#define FOR(i,n) for(int i = 0;i < n;i++)
#define MP make_pair
#define PB push_back
#define ALL(a) (a).begin(),(a).end()
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define CLEAR(a) memset(a, 0, sizeof(a))
#define ERASE(a) memset(a, -1, sizeof(a))
#define INF 2000000007LL
#define y1 uu1
#define y2 uu2
const double EPS = 1E-12;
const double PI = acos(-1.0);

using namespace std;

const LL mod = 998244353;

int n,x,y;
vector<PII> g[100005];
int ans[100005];
int k = 0;

void dfs(int idx, int from, int col) {
  int cidx = 0;
  if (col == 0) cidx++;
  FOR(i, g[idx].size()) {
    if (g[idx][i].first == from) continue;
    ans[g[idx][i].second] = cidx;
    dfs(g[idx][i].first, idx, cidx);
    cidx++;
    if (cidx == col) cidx++;
  }
}

int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin >> n;
  FOR(i, n-1) {
    cin >> x >> y;
    g[x-1].push_back(MP(y-1, i));
    g[y-1].push_back(MP(x-1, i));
  }

  FOR(i, n) k = max(k, (int)g[i].size());

  dfs(1, -1, -1);
  cout << k << endl;
  FOR(i, n-1) {
    cout << ans[i] + 1 << '\n';
  }

  return 0;
}


Measured memory_bytes: 9344
Q = int(input())
MAX_N = 100000
ps = [False] * MAX_N
ps[2] = True
for i in range(3, MAX_N, 2):
    flg = True
    for j in range(2, MAX_N):
        if not flg or  j * j > i:
            break
        elif not ps[j]:
            continue
        flg = flg and i % j != 0
    ps[i] = flg

like = [False] * MAX_N
for i in range(3, MAX_N, 2):
    like[i] = ps[i] and ps[(i+1)//2]

ss = [0] * MAX_N
for i in range(2, MAX_N-1):
    if like[i]:
        ss[i] += 1
    ss[i+1] += ss[i]

for i in range(Q):
    l, r = map(int, input().split())
    print(ss[r]-ss[l-1])


Measured memory_bytes: 55776
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int t[] = { 111,222,333,444,555,666,777,888,999 };
	for (int i = 0; i < 9; i++) {
		if (t[i] >= n) {
			cout << t[i] << endl;

			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF=1e9;
int n;
int a[101];
int dp[101][21];
signed main() {
    cin>>n;
    for(int i=0; i<n; i++) cin>>a[i];
    dp[0][a[0]]=1;
    for(int i=0; i<n-2; i++) {
        for(int j=0;j<21;j++) {
            if(0<=j+a[i+1] && j+a[i+1]<=20) dp[i+1][j+a[i+1]]+=dp[i][j];
            if(0<=j-a[i+1] && j-a[i+1]<=20) dp[i+1][j-a[i+1]]+=dp[i][j];
        }
    }
    cout<<dp[n-2][a[n-1]]<<endl;
    return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
int N;
LL A[MAX];

int main(void) {
    scanf("%d", &N);
    LL x = 0;
    REP(i, N) {
        scanf("%lld", A + i);
        x += A[i];
    }

    REP(i, N) if (i % 2 == 1) {
        x -= A[i] * 2;
    }

    REP(i, N) {
        printf("%lld%c", x, (i + 1 == N ? '\n' : ' '));
        x = A[i] * 2 - x;
    }
}


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


using S = set<int>;
S U;
map<char, S> m;

string s;
int N;
int c;

S expr();
S factor();
S num();

void debug(string text){
	return;
	cout << text + " " + s << endl;
	for(int i = 0; i < text.size() + 1 + N; i++){
		if(i == text.size() + 1 + c) cout << "*";
		else cout << " ";
	}
	cout << endl;
}

S Union(S s1, S s2){
	for(auto v : s2){
		s1.insert(v);
	}
	return s1;
}

S Intersection(S s1, S s2){
	S ret;
	for(auto v : s2){
		if(s1.count(v)) ret.insert(v);
	}
	return ret;
}

S Diff(S s1, S s2){
	S ret;
	for(auto v : s1){
		if(!s2.count(v)) ret.insert(v);
	}
	return ret;
}

S SymDiff(S s1, S s2){
	S ret;
	for(auto v : s1){
		if(!s2.count(v)) ret.insert(v);
	}
	for(auto v : s2){
		if(!s1.count(v)) ret.insert(v);
	}
	return ret;
}

S Comp(S s1){
	S ret;
	for(auto v : U){
		if(!s1.count(v)) ret.insert(v);
	}
	return ret;
}

S expr(){
	debug("expr");
	S x = factor();
	while(c < N){
		if(s[c] == 'u'){
			c++;
			x = Union(x, factor());
		}
		else if(s[c] == 'i'){
			c++;
			x = Intersection(x, factor());
		}
		else if(s[c] == 'd'){
			c++;
			x = Diff(x, factor());
		}
		else if(s[c] == 's'){
			c++;
			x = SymDiff(x, factor());
		}
		else break;
	}
	return x;
}

S factor(){
	debug("factor");
	bool rev = false;
	if(s[c] == 'c'){
		rev = 1;
		c++;
	}

	if(s[c] == '('){
		c++;
		S ret = expr();
		assert(s[c] == ')');
		c++;
		if(rev) ret = Comp(ret);
		return ret;
	}
	S ret = num();
	if(rev) ret = Comp(ret);
	return ret;
}

S num(){
	debug("num");
	S ret = m[s[c]];
	c++;
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	while(true){
		m.clear();
		U.clear();
		char name;
		int n;
		while(true){
			if(!(cin >> name >> n)) return 0;
			if(name == 'R') break;
			for(int i = 0; i < n; i++){
				int a;
				cin >> a;
				U.insert(a);
				m[name].insert(a);
			}
		}
		m['U'] = U;
		cin >> s;
		N = s.size();
		c = 0;
		S ans = expr();
		if(ans.size()){
			vector<int> v(ans.begin(), ans.end());
			for(int i = 0; i < v.size(); i++){
				cout << v[i];
				if(i != v.size() - 1) cout << " ";
			}
			cout << endl;
		}
		else{
			cout << "NULL" << endl;
		}
	}
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
#define ll long long 
#define pb push_back
#define fi first
#define se second


	
int main(){
    ll x,n; cin>>x>>n;
    ll a[n];
    vector<bool>visited(102,false);
    for(ll i=0;i<n;i++){
        cin>>a[i];
        visited[a[i]]=true;
    } 

                ll ind=0,mini=1000;
                for(ll i=0;i<102;i++){
                    if(visited[i]==false){
                        if(abs(x-i)<mini){
                            mini=abs(x-i);
                            ind=i;
                        }
                        else if(abs(x-i)==mini){
                            if(ind>i){
                                ind=i;
                            }
                        }
                    }
                }

  


                cout<<ind<<"\n";
        
        
    
}



Measured memory_bytes: 3592
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root, NIL;
int maxh;

void insert(int k){
  int H;
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if ( z->key < x->key ){
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if ( y == NIL ){
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node u){
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node u){
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  maxh = 0;
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( strcmp(com, "insert") == 0 ){
      scanf("%d", &x);
      insert(x);
    } else if ( strcmp(com, "print") == 0 ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 25180
#include<iostream> 
#include<algorithm> 
#include<set> 
#include<string>
#include<cmath>
#include<cstring>
using namespace std; 
int main() 
{ 
	set<string> se;
	int n,k=1;
	string s;
	char ch='1';
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		if(se.count(s))
			k=0;
		if(i>1)
		{
			if(s[0]!=ch)
			k=0;
		}
		ch=s[s.size()-1];
		se.insert(s);
	}
	if(k==0)
	printf("No\n");
	else
	printf("Yes\n");
	return 0; 
}


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


int main() {
	int input, temp, i, j;
	int number[4];
	bool isPlus[8][3]{ {true, true, true} , {true, true, false} ,{true, false, true},
	{false, true, true}, {true, false, false}, {false, true, false}, {false, false, true},
	{false, false, false} };


	cin >> input;

	for (int i = 0; i < 4; i++) {
		number[i] = input / pow(10, 3 - i);
		input -= number[i] * pow(10, 3 - i);
	}

	temp = 7 - number[0];

	for (i = 0; i < 8; i++) {
		temp = number[0];
		for (j = 0; j < 3; j++) {
			isPlus[i][j] ? temp += number[j + 1] : temp -= number[j + 1];
		}
		if (temp == 7) {
			break;
		}
	}

	for (int n = 0; n < 3; n++) {
		cout << number[n];
		isPlus[i][n] ? cout << "+" : cout << "-";
	}

	cout << number[3] << "=7";

	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;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = n;
  if(n >= b - 1) x = b -1;
  ll ans = a * x / b - a*(x/b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
def main():
    import math
    a,b = map(int,input().split())
    g = math.gcd(a,b)
    ans = [1]
    for m in range(2,int(g**0.5)+1):
        if g%m==0:
            ans.append(m)
            while g%m==0:
                g = g//m
        if g==1:
            break
    if g!=1:
        ans.append(g)
    print(len(ans))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9436
class UnionFind:
    def __init__(self, n):
        self.par = [-1 for i in range(n+1)]
        self.size = [1 for i in range(n+1)]
    # 検索
    def find(self, x):
        path = []
        curr = x
        # 親ノードの手前で止まる(どの根に紐づくかの情報を持ちながら)
        while self.par[curr] != -1:
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            path.append(curr)
            curr = self.par[curr]
        for p in path:
            self.par[p] = curr
        return curr

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        self.par[y] = x
        self.size[x] += self.size[y]
        self.size[y] = 1

    # 判定
    def judge(self,x,y):
        return self.find(x) == self.find(y)

N, M = map(int,input().split())
pairs = [tuple(map(int,input().split())) for _ in range(M)]
uf = UnionFind(N)
p = N*(N-1)//2
ans = [p]
for a,b in reversed(pairs[1:]):
    if not uf.judge(a,b):
        size_a = uf.size[uf.find(a)]
        size_b = uf.size[uf.find(b)]
        uf.union(a,b)
        size_a_update = uf.size[uf.find(a)]
        p = p + size_a*(size_a-1)//2 + size_b*(size_b-1)//2 - size_a_update*(size_a_update-1)//2

    ans.append(p)
for a in reversed(ans):
    print(a)



Measured memory_bytes: 23312
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <cmath>


using namespace std;
#define MAX 100000

int main(){
    int A1, A2, A3;
    int max_n, min_n;

    scanf("%d%d%d", &A1, &A2, &A3);

    max_n = max({ A1, A2, A3 });
    min_n = min({ A1, A2, A3 });

    int ans = max_n - min_n;

    printf("%d", ans);

    return 0;
}

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

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

const long long INF = 1LL << 60;

int main(){
  int N;
  long long W;
  cin >> N >> W;
  vector<long long> vec_w(N);
  vector<long long> vec_v(N);
  for (int i = 0; i < N; i++) {
      cin >> vec_w.at(i) >> vec_v.at(i);
  }
  using vi = vector<long long>;
  using vvi = vector<vi>;
  vvi dp(N+1, vi(W+1));
  for (int i = 0; i < N+1; i++) {
    for (int j = 0; j < W+1; j++) {
      dp.at(i).at(j) = 0;
    }
  }

  for(int i = 0; i < N; i++){
    for(int sum_w = 0; sum_w <= W; sum_w++){
      if(sum_w - vec_w.at(i) >= 0){
       chmax( dp.at(i+1).at(sum_w) , dp.at(i).at(sum_w - vec_w.at(i)) + vec_v.at(i) );
      }
      chmax( dp.at(i+1).at(sum_w), dp.at(i).at(sum_w) );
    }
  }
  cout << dp.at(N).at(W) << endl;
}


Measured memory_bytes: 80256
#include<iostream>
#include<vector>

int main(void){
    int N, K;
    std::cin >> N >> K;
    std::vector<long long> h(N + K - 1, 0), c(N + K - 1, 1E+10);
    for(int i = 0; i < N; i++) std::cin >> h[i];
    c[0] = 0;
    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j <= i + K; j++) c[j] = std::min(c[j], c[i] + abs(h[i] - h[j]));
    }
    std::cout << c[N - 1] << std::endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
long long n,k[51];bool m;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>k[i];
	for(int ii=2;ii<=n;ii++)
		if(k[ii]-1!=k[ii-1])
			break;
		else
			if(ii==n)
			{
				cout<<"YES";
				return 0;
			}
	for(int i=1;i<=n;i++)
		for(int I=1;I<=n;I++)
		{
			swap(k[i],k[I]);
			m=0;
			for(int ii=2;ii<=n;ii++)
				if(k[ii]-1!=k[ii-1])
				{
					m=1;break;
				}
			if(m==1)
				swap(k[i],k[I]);
			else
			{
				cout<<"YES";return 0;
			}
		} 
	cout<<"NO";
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define vi vector<int>
#define test int t; cin>>t; while(t--)
#define yn cout<<"YES\n"
#define nn cout<<"NO\n"
#define nl cout<<"\n"
//#define fisier 1
const double PI=3.14159265359;
const int MOD = 1e9 + 7;
const int NMAX = 2e9;

int32_t main(){
	#ifdef fisier
        ifstream cin("input.in");
        ofstream cout("output.out");
    #endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int a, b;
	cin >> a >> b;
	cout << a * b;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  sort(ALL(a));
  ll ans=0;
  for(ll i=0;i<n;i++){
    for(ll j=i+1;j<n;j++){
      ll p=(lower_bound(ALL(a),a[i]+a[j])-a.begin());
      ans+=max((ll)0,p-j-1);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print(int u)
{
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if(T[u].p == NIL) cout << "root, ";
  else if(T[u].l == NIL) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for(i=0, c=T[u].l; c!=NIL; i++, c=T[c].r)
  {
    if(i)cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

//再帰的に深さを求め
void rec(int u, int p)
{
  D[u]=p;
  if(T[u].r != NIL) rec(T[u].r, p);
  if(T[u].l != NIL) rec(T[u].l, p+1);
}

int main(){
  int i, j, d, v, c, l, r;
  cin >> n;

  for(i=0; i<n; i++)
    T[i].p=T[i].l=T[i].r=NIL;

  for(i=0; i<n; i++)
  {
    cin >> v >> d;
    for(j=0; j<d; j++)
    {
      cin >> c;
      if(j == 0) T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0; i<n; i++)
  {
    if(T[i].p == NIL)
      r=i;
  }

  rec(r, 0);

  for(i=0; i<n; i++)
    print(i);

  return 0;
}



Measured memory_bytes: 7768
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<double, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
 	return 0;
}


Measured memory_bytes: 3652
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------
def F(a,b):
    return max(len(str(a)), len(str(b)))

# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())

ds = set()
dl = list()
for i in range(1,10**5+1):
    if N%i == 0:
        ds.add(i)
        dl.append(i)
for d in dl:
    ds.add(N//d)
D = sorted(list(ds))

ans = 100
for d in D:
    ans = min(ans,F(d,N//d))

print(ans)

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

using namespace std;

vector<int> a;
int n;

int main(){

    cin >> n;

    a.resize(n);

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

    int minA = 0, curr = 0;
    int cnt = 0;

    for(int i = 1; i < n - 1; ++i){

        if((a[i] > a[i + 1] && a[i] < a[i - 1]) || (a[i] < a[i + 1] && a[i] > a[i - 1]))
            cnt++;
    }

    cout << cnt;

    return 0;
}


Measured memory_bytes: 256