akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <array>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cstdio>
#include <queue>

using namespace std;

#define int long long

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

    int step[100000 + 10];


    int n, m;

    cin >> n >> m;


    for (int i = 1; i <= n; ++i)
    {
        step[i] = 0;
    }
    step[0] = 1;

    int in;
    for (int i = 0; i < m; ++i)
    {
        cin >> in;
        step[in] = -1;
    }

    for (int i = 0; i <= n; ++i)
    {
        if (step[i] == -1)
        {
            continue;
        }

        if (step[i + 1] != -1)
        {
            step[i + 1] += step[i];
            step[i + 1] %= 1000000007;
        }
        if (step[i + 2] != -1)
        {
            step[i + 2] += step[i];
            step[i + 2] %= 1000000007;
        }
    }

    cout << step[n] << endl;

}

Measured memory_bytes: 1024
N,K = map(int,input().split())
h = [int(input()) for i in range(N)]
h.sort(reverse = True)
l = [0]*(N-(K-1))
for i in range(N-(K-1)):
  l[i] = h[i]-h[i+K-1]
ans = min(l)
print(ans)

Measured memory_bytes: 11036
input_data = input()
N, Y = map(int, input_data.split())
result = False
count_10000 = 0
count_5000 = 0
count_1000 = 0

for count_10000 in range(0, N + 1):
    for count_5000 in range(0, N + 1 - count_10000):
        count_1000 = N - count_10000 - count_5000
        total = count_10000 * 10000 + count_5000 * 5000 + count_1000 * 1000
        count = count_10000 + count_5000 + count_1000
        if total == Y and count == N:
            result = True
            break
    else:
        continue
    break

if result:
    print("{} {} {}".format(count_10000, count_5000, count_1000))
else:
    print("-1 -1 -1")


Measured memory_bytes: 3064
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, a, b = LI()


if n >= a + b:
    print(min(a, b), 0)
else:
    print(min(a, b), a + b - n)

Measured memory_bytes: 3064
class Main:
    t1, a1, t2, a2= map(int,input().split());
    w = "t1"
    while t1 >= 0 or t2 >= 0:
        if t2 <= 0:
            w = "t1"
            break;
        t2 = t2 - a1;
        if t1 <= 0:
            w = "t2"
            break;
        t1 =  t1 - a2;

    if w == "t1":
        print("Yes");
    else:
        print("No")



Measured memory_bytes: 8996
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> height(N);
    rep(i,N){
        cin >> height[i];
    }
    int ans = 0;
    rep(i,N){
        if (height[i] >= K){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
N=int(input())
Vn=list(map(int,input().split()))
Cn=list(map(int,input().split()))

best = 0
for i in range(2**N):
    t = 0
    for j in range(N):
        if (i >> j) & 1:
            t += (Vn[j] - Cn[j])
    if t > best:
        best = t
print(best)


Measured memory_bytes: 41068
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <math.h>
#include <stack>
using namespace std;
typedef long long ll;

int n,m;
int a[14];
double p[14][3];
double dp[1<<14];
double pp[1<<13][6];
int ma[1<<13];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> m; n--;
	for(int i=0;i<n;i++){
		cin >> a[i];
		cin >> p[i][0] >> p[i][1] >> p[i][2];
		p[i][0]/=100,p[i][1]/=100,p[i][2]/=100;
	}
	dp[0]=1;
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<3;j++){
			double res=1;
			for(int k=0;k<n;k++){
				if((1<<k)&i){
					res*=p[k][j];
				}
			}
			pp[i][j]=res;
		}
		for(int j=0;j<3;j++){
			double res=1;
			for(int k=0;k<n;k++){
				if((1<<k)&i){
					res*=(1-p[k][j]);
				}
			}
			pp[i][j+3]=res;
		}
	}
	for(int i=0;i<(1<<n);i++){
		int res=0;
		for(int j=0;j<n;j++){
			if((i>>j)&1){
				res=max(res,a[j]);
			}
		}
		ma[i]=res;
	}
	for(int s=1;s<(1<<n);s++){
		double rrr=0,sss=0,ppp=0;
		for(int t=0;t<s;t++){
			if((s&t)==t){
				double winr,wins,winp;
				winr=pp[s-t][2]*pp[t][0];
				winp=pp[s-t][0]*pp[t][1];
				wins=pp[s-t][1]*pp[t][2];
				rrr+=dp[t]*winr;
				sss+=dp[t]*wins;
				ppp+=dp[t]*winp;
			}
		}
		double drowr,drows,drowp;
		drowp=(1-(pp[s][5]+pp[s][3]-pp[s][1]*2));
		drows=(1-(pp[s][4]+pp[s][3]-pp[s][2]*2));
		drowr=(1-(pp[s][5]+pp[s][4]-pp[s][0]*2));
		if(ma[s]<m){
			rrr+=drowr;
			ppp+=drowp;
			sss+=drows;
		}
		dp[s]+=max({rrr,sss,ppp});
	}
	printf("%.9f\n",dp[(1<<n)-1] );
}


Measured memory_bytes: 3800
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll h[101010];
ll dp[101010];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n, k;
	cin >> n >> k;
	rep(i, n) {
		cin >> h[i];
		dp[i] = INF;
	}
	dp[0] = 0;
	rep(i, n) {
		for (ll j = 1;j <= k;++j) {
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10e+6
#define DEKA 1000000007

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> vec0(100010,0);
    vector<int> vec1(100010,0);
    int b[n+10];
    
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        b[i]=a;
        if(i%2==0) {
            vec0.at(a)++;
        }
        else {
            vec1.at(a)++;
        }
    }
    int ans0=0,ans1=0;
    int e0,e1;
    for(int i=0;i<100010;i++){
        if(ans0<vec0.at(i)){
            ans0=vec0.at(i);
            e0=i;
        }
        if(ans1<vec1.at(i)){
            ans1=vec1.at(i);
            e1=i;
        }
    }
    int ans2=0,ans3=0;
    int d0,d1;
    for(int i=0;i<100010;i++){
        if(ans2<vec0.at(i)&& i!=e0){
            ans2=vec0.at(i);
            d0=i;
        }
        if(ans3<vec1.at(i)&& i!=e1){
            ans3=vec1.at(i);
            d1=i;
        }
    }
    
    if(e0!=e1){
        int ans=0;
        for(int i=0;i<n;i++){
            if(i%2==0){
                if(b[i]!=e0) ans++;
            }
            else {
                if(b[i]!=e1) ans++;
            }
        }
        cout << ans << endl;
    }
    else{
        int ans=0;
        for(int i=0;i<n;i++){
            if(i%2==0){
                if(b[i]!=e0) ans++;
            }
            else {
                if(b[i]!=d1) ans++;
            }
        }
        int anss=0;
        for(int i=0;i<n;i++){
            if(i%2==0){
                if(b[i]!=d0) anss++;
            }
            else {
                if(b[i]!=e1) anss++;
            }
        }
        ans=min(ans,anss);
        cout << ans << endl;
    }
    
}



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

int main()
{
    int a, b;
    cin >> a >> b;
    int s = a - 1;
    int t = b - 1;
    int ans = (t + s - 1) / s;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define FOR(i,e) for(int i=0;i<(int)(e);i++)
using namespace std;

int main(){
  double pb[100][5001];
  int x,y,z;
  int v[4],e[51],a[100];

  while(cin >> x >> y >> z && (x||y||z)){

    FOR(i,x)cin >> v[i];
    FOR(i,y+1)e[i] = a[i] = 0;
    FOR(i,z){
      int n,m,l;
      cin >> n >> m >> l;
      e[n] = m; a[n] = l;
    }

    FOR(i,y+1)FOR(j,5001)pb[i][j] = 0.0;
    pb[0][0] = 1.0;

    FOR(i,y)FOR(j,5001){
      FOR(k,x){
	if(pb[i][j] == 0.0)continue;
	int next = min(y,i+v[k]),value = j;
	if(e[next] == 1)next = min(y,next+a[next]);
	else if(e[next] == 2)value = j + a[next];
	else if(e[next] == 3)value = max(0,j-a[next]);
	pb[next][value] += pb[i][j]/x;
      }
    }

    double ans = 0.0;
    FOR(i,5001)ans += pb[y][i] * i;
    cout << (int)(ans) << endl;
  }
}

Measured memory_bytes: 2868
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,ans=0;
  cin>>N;
  vector<vector<int>> A(20,vector<int>(20));
  while(N--){
    string S;
    cin>>S;
    long double d=stod(S);
    if(d==0)A[19][19]++;
    else if(d==(int)d){
      ans--;
      int n2=0,n5=0;
      for(int i=d;i%2==0;i/=2)n2++;
      for(int i=d;i%5==0;i/=5)n5++;
      A[min(n2,9LL)+10][min(n5,9LL)+10]++;
    }else{
      string T="";
      int n;
      for(int i=0;i<S.size();i++){
        if(S[i]!='.')T+=S[i];
        else n=i;
      }
      for(int i=T.size()-n;i<9;i++)T+='0';
      int D=stoll(T);
      int n2=1,n5=1;
      for(int i=D;i%2==0;i/=2)n2++;
      for(int i=D;i%5==0;i/=5)n5++;
      A[min(n2,19LL)][min(n5,19LL)]++;
    }
  }
  for(int i=0;i<20;i++)
    for(int j=0;j<20;j++)
      for(int k=0;k<20;k++)
        for(int l=0;l<20;l++)
          if(i+k>=20 && j+l>=20){
            ans+=A[i][j]*A[k][l];
          }
  cout<<ans/2<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

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

int main(){
  ll k,sum=0,a,b;
  cin >> k;
  rep(i,1,k+1){
    rep(j,1,k+1){
      rep(l,1,k+1){
        a= gcd(i,gcd(j,l));
        sum+= a;
        //printf("%d,%d,%d:%d\n",i,j,l,a);
      }
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputtext = Console.ReadLine();

            char[] changestring = inputtext.ToCharArray();

            for(int i = 0; i < changestring.Length; i++)
            {
                //??§???????????????????°??????????????????????
                if (char.IsUpper(changestring[i])) changestring[i] = char.ToLower(changestring[i]);

                //?°?????????????????????§???????????????
                else if (char.IsLower(changestring[i])) changestring[i] = char.ToUpper(changestring[i]);
            }

            string output = new string(changestring);

            Console.WriteLine(output);
        }
    
    }

}

Measured memory_bytes: 9108
H, W = list(map(int, input().split()))


def get_data():
    yield ['.'] * (W + 1)
    for _ in range(H):
        yield ['.'] + list(input()) + ['.']
    yield ['.'] * (W + 1)


def check(array):
    for i, row in enumerate(array):
        if i == 0 or i == len(array) - 1:
            continue
        sharp_index = [i for i, value in enumerate(row) if value == '#']
        for j in sharp_index:
            if j - 1 in sharp_index or j + 1 in sharp_index:
                continue
            if '#' in (array[i+1][j], array[i-1][j]):
                continue
            return False
    return True


Array = list(get_data())
if check(Array):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9+7
typedef long long int ll;
const int maxn = 200000;
ll mod = INF;


int main(){

    int n;
    ll ans=0;
    ll a[maxn];
    map<ll,int> sum;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]>=n){continue;}
        sum[i+1+a[i]]++;
    }

    for(int i=0;i<n;i++){
        int temp=i+1-a[i];
        if(temp<2){continue;}
        ll num=sum[temp];
        ans+=num;
    }

    cout << ans<<endl;

    return 0;
}

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

const string tbl[] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

int main()
{
  int T;
  cin >> T;
  for (int t = 0; t < T; ++t) {
    string s;
    cin >> s;

    int index = 0, cnt = 0;
    for (unsigned int i = 0; i < s.size(); ++i) {
      if (index == 0) {
	index = s[i] - '0';
	cnt = 0;
      } else {
	if (s[i] == '0') {
	  cout << tbl[index][cnt%tbl[index].size()];
	  index = 0;
	} else {
	  ++cnt;
	}
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//constants
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1<<28;


int main(int argc, char **argv) {
    int N;
    vector<int> A;
    cin >> N;
    A.resize(N, 0);
    REP(i, N) cin >> A[i];
    REP(i, N)
        if (A[i] >= N){
            cout << 0 << endl;
            return 0;
        }

    vector<int> memo;
    memo.resize(N, 0);
    REP(i, N)
        memo[A[i]]++;

    bool flag = (N%2==1);
    bool ans=true;
    if(flag && memo[0] != 1)
        ans=false;
    FOR(i, 1, N){
        if(flag){
            if(i%2==0 and memo[i] != 2)
                ans=false;
        }
        else{
            if(i%2==1 and memo[i] != 2)
                ans=false;
        }
    }

    if (!ans){
        cout << 0 << endl;
    }
    else{
        long long res = 1;
        REP(i, N/2)
            res = (res*2)%1000000007;
        cout << res << endl;
    }
    return 0;

}


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

using namespace std;

#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define INF 0x3f3f3f3f
#define f1(n) for(int i=0 ; i<n ; i++)
#define f2(m) for(int j=0 ; j<m ; j++)
#define ll long long
typedef pair<int, int> iPair;
const double epsilon = 1e-7;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int x, n;
  cin >> x >> n;
  int y;
  unordered_set<int> s;
  for(int i=0; i<n; ++i) {
    cin >> y;
    s.insert(y);
  }
  int ans = INT_MAX;
  for (int i=0; i<=101; ++i) {
    if (s.find(i) == s.end() and abs(x-i) < abs(x-ans)) {
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;

typedef long long ll;
typedef vector<int> VI;

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

//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];
ll N;

int a[200010];
ll sum[200010];
signed main(void) {
    cin >> N;
    REP(i, N) cin >> a[i];
    sort(a, a+N);
    vector<int> v;
    for(int i=N-1; i>=1; --i){
        if(v.size()==2) break;
        if(a[i]==a[i-1]) {
            v.push_back(a[i]);
            --i;
        }
    }
    if(v.size()==2) cout << (long long)v[0]*v[1] << endl;
    else cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 6016
class SegmentTree():
    def segfunc(self, x, y):
        return x|y #関数
    
    def __init__(self, a): #a:リスト
        n = len(a)
        self.ide_ele = 0 #単位元
        self.num = 2**((n-1).bit_length()) #num:n以上の最小の2のべき乗
        self.seg = [self.ide_ele]*2*self.num
        
        #set_val
        for i in range(n):
            self.seg[i+self.num-1] = a[i]
        #built
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1], self.seg[2*i+2])
        
        
    def update(self, k, s):
        x = 1<<(ord(s)-97)
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2])
            
    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res = self.ide_ele
        while q - p > 1:
            if p&1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f
    

N = int(input())
S = list(input())
for i in range(N):
    S[i] = 1<<(ord(S[i])-97)
Seg = SegmentTree(S)
Q = int(input())
for i in range(Q):
    x, y, z = input().split()
    if int(x) == 1:
        Seg.update(int(y)-1, z)
    else:
        print(popcount(Seg.query(int(y)-1, int(z))))

Measured memory_bytes: 128936
#include <stdio.h>
int main() {
    int a, b;
    scanf("%d %d", &a, &b);

    int d, r;
    double f;
    d = a / b;
    r = a % b;
    f = (double)a / b;

    printf("%d %d %lf\n", d, r, f);

    return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N, T;
  cin >> N >> T;
  
  int minimum_cost = 1001;
  for(int i = 0; i < N; ++i)
  {
    int c, t;
    cin >> c >> t;
    if(c < minimum_cost && t <= T)
    {
      minimum_cost = c;
    }
  }
  
  if(minimum_cost == 1001)
  {
    cout << "TLE" << endl;
  }
  else
  {
    cout << minimum_cost << endl;
  }
  return 0;
}

Measured memory_bytes: 256
x = gets.to_i

m = 1
while x > 5 * m ** 4 + 10 * m ** 3 + 10 * m ** 2 + 5 * m + 1
    m += 1
end
m += 1

nums = (0..m).map{|it| it ** 5}
(0..m).to_a.combination(2).each{|a, b|
    if x == nums[a] + nums[b]
        puts [a, -b].join(' ')
        break
    elsif  x == nums[b] - nums[a]
        puts [b, a].join(' ')
        break
    end
}


Measured memory_bytes: 14312
N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(0, N-1):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if (L[i] != L[j] and L[i] != L[k] and L[j] != L[k]) and (L[i] + L[j] > L[k] and L[i] + L[k] > L[j] and L[j] + L[k] > L[i]):
                ans += 1
            else:
                continue
print(ans)

Measured memory_bytes: 9208
use std::io::*;
use std::str::FromStr;
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
 
fn main() {
    let mut abc: Vec<u32> = (0..3).map(|_| read()).collect();
    let mut ans = 0;
 
    loop {
        abc.sort();
        if abc[0] == abc[2] {
            break;
        }
        if (abc[2] - abc[0]) >= 2{
            abc[0] += 2;
        }else if (abc[2] - abc[0]) < 2 {
            if abc[1] == abc[2] {
                abc[0] += 2;
            }else if abc[0] == abc[1] {
                abc[0] += 1;
                abc[1] += 1;
            }
        }
        ans += 1;
    }
 
    println!("{}", ans);
}

Measured memory_bytes: 4352
import itertools

n = int(input())
balls = {i: list(map(int, input().split())) for i in range(n)}
dist_cnt = {}

for i, j in itertools.combinations(range(n), 2):
    x = balls[j][0] - balls[i][0]
    y = balls[j][1] - balls[i][1]
    
    if not x in dist_cnt.keys():
        dist_cnt[x] = {}
    if not x*(-1) in dist_cnt.keys():
        dist_cnt[x*(-1)] = {}
    if not y in dist_cnt[x].keys():
        dist_cnt[x][y] = 0
    if not y*(-1) in dist_cnt[x*(-1)].keys():
        dist_cnt[x*(-1)][y*(-1)] = 0

    dist_cnt[x][y] += 1
    dist_cnt[x*(-1)][y*(-1)] += 1
        

cnt = 0
for x, v in dist_cnt.items():
    cand = max(v.values())
    if cand > cnt:
            cnt  = cand
            
print(n - cnt)

Measured memory_bytes: 3956
#include<cstdio>
#include<vector>
#include<string.h>
#include<cassert>
using namespace std;

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

int map[22][22];
int ans = 100;
int tx,ty;

void dfs(int map[22][22],int depth) {
  if(depth >= 10 || depth >= ans) return;

  int sx=-1,sy=-1,px,py;
  for(int i=0; i<22; i++) {
    for(int j=0; j<22; j++) {
      if(map[i][j]==2) sx=i,sy=j;
      //      printf("%d ",map[i][j]);
    }
    //    printf("\n");
  }

  //printf("%d %d\n",sx,sy);

  for(int i=0; i<4; i++) {
    px = sx;
    py = sy;
    if(map[px+dx[i]][py+dy[i]]==1 || map[px+dx[i]][py+dy[i]]==-1) continue;
    while(1) {
      if(map[px+dx[i]][py+dy[i]] == -1) break;
      if(map[px+dx[i]][py+dy[i]] == 0) {
	px += dx[i];
	py += dy[i];
	continue;
      }
      if(map[px+dx[i]][py+dy[i]] == 1) {

	int nmap[22][22];
	for(int k=0; k<22; k++)
	  for(int j=0; j<22; j++)
	    nmap[k][j] = map[k][j];

	nmap[sx][sy]=0;
	nmap[px][py]=2;
	nmap[px+dx[i]][py+dy[i]] = 0;
	dfs(nmap,depth+1);
	break;
      }
      if(map[px+dx[i]][py+dy[i]] == 3) {
	ans = min(ans,depth+1);
	//	printf("depth : %d\n",depth);
	return;
      }
    }
  }

  return;
}

int main() {
  int w,h,t;
  while(1) {
    scanf("%d %d",&w,&h);
    if(!w) break;

    memset(map, -1, sizeof(map));
    ans = 100;

    for(int i=1; i<=h; i++)
      for(int j=1; j<=w; j++) {
	scanf("%d",map[i]+j);

      }

    dfs(map ,0);
    printf("%d\n",(ans==100) ? -1 : ans);
  }
}

Measured memory_bytes: 784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int k;
    cin >> k;
    queue<ll> q;
    VL ans;
    for(int i = 1; i < 10; i++){
        q.push(i);
        ans.push_back(i);
    } 
    ll cnt = q.size();
    while(cnt < k){
        ll x = q.front(); q.pop();
        ll d = x % 10;
        x *= 10;
        if (d != 0) {
            q.push(x + (d-1));
            ans.push_back(x + (d-1));
            cnt++;
        }
        q.push(x + d);
        ans.push_back(x + d);
        cnt++;
        if (d != 9){
            q.push(x + (d+1));
            ans.push_back(x + (d+1));
            cnt++;
        }
    }
    cout << ans[k-1] << endl;
    return 0;
}

Measured memory_bytes: 4564
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int S, W;
	cin >> S >> W;
	string ans="safe";
	if (S - W <= 0) {
		ans = "unsafe";
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}

Measured memory_bytes: 3616
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    int a,b,c;
    bool ans=true;

    cin>>a>>b>>c;

    if(a+b+c>21){
        ans=false;
    }

    if(ans){
        cout<<"win"<<endl;
    }
    else{
        cout<<"bust"<<endl;
    }

    return 0;
}

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

int main(void) {

    int k;
    char s[101];
    scanf("%d", &k);
    scanf("%s", s);
    int s_len = strlen(s);

    if (s_len <= k) {
        printf("%s", s);
    } else {
        for (int i = 0; i < k; i ++) {
            printf("%c", s[i]);
        }
        printf("...");
    }

    //printf("%s, %d", s, s_len);


    return 0;
}

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

int main(){
    int a,b,c,d,i;

    cin >> a >> b >> c >> d;

    for( i = 1; i <= 100; i++){
        if( ( c - b ) <= 0 ){
            cout << "Yes\n";
            break;
        }
        else
        {
            c -= b;
        }
        if( ( a - d ) <= 0 ){
            cout << "No\n";
            break;
        }
        else
        {
            a -= d;
        }
        
    }

}

Measured memory_bytes: 3632
import std.array;
import std.algorithm;
import std.range;
import std.stdio;


void main() {
    int n, y;
    readf("%d %d\n", &n, &y);
    foreach (i; 0 .. y / 10000 + 1) {
        foreach (j; 0 .. min(y / 5000 + 1, n - i + 1)) {
            auto k = n - i - j;
            if (i * 10000 + j * 5000 + k * 1000 == y) {
                writefln("%d %d %d", i, j, k);
                return;
            }
        }
    }
    writeln("-1 -1 -1");
}

Measured memory_bytes: 256
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
//const ll mod = 998244353 ;
//long double PI = acosl(-1);
const ll infl = 1e18+0;
//const int inf = 1e9;
const int nmax = 2e5+5;
//const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;



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

    string s;
    cin>>s;
    for(char &ch : s) if(ch=='?') ch = 'D';
//    int ans = 0;
//    for(int i=0; i<s.size(); i++){
//        if(i<s.size()-1) if(s[i]=='P' and s[i+1]=='D') ans++;
//        if(s[i]=='D') ans++;
//    }
    cout<<s<<endl;
}
/*

*/


Measured memory_bytes: 3772
class UFT(): #Union-find tree class
    def __init__(self, N): 
        self.tree = [int(i) for i in range(N)] 
        self.rank = [0 for i in range(N)]

    def find(self, a):
        if self.tree[a] == a: return a
        else:
            self.tree[a] = self.find(self.tree[a])
            return self.tree[a]

    def unite(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b: return
        if self.rank[a] < self.rank[b]: self.tree[a] = b
        else:
            self.tree[b] = a
            if self.rank[a] == self.rank[b]: self.rank[a] += 1

N, M = map(int, input().split())
parent = UFT(N)
for i in range(M):
    x, y, z = map(int, input().split())
    parent.unite(x-1, y-1)
for i in range(N):
    parent.find(i)

print(len(set(parent.tree)))

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

using namespace std;

int main(){
    ios:: sync_with_stdio(0);

    int n;
    cin >> n;
    vector<int> h(n + 1);
    vector<long long> dp(n + 1);
    for(int i = 1; i <= n; ++i)
        cin >> h[i];

    dp[2] = abs(h[1] - h[2]);

    for(int i = 3; i <= n; ++i){
        dp[i] = min (dp[i - 1] + abs(h[i] - h[i - 1]),
                     dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[n];
}


Measured memory_bytes: 1408
use std::io;

fn main() {
    io::stdin().read_line(&mut String::new()).ok();

    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();

    let (_, res, _) = s.trim().split(' ').rev().fold((0, 0, 0), |(v, n, x), y| {
        let z = y.parse().unwrap();
        let d = x - z;

        if z > x {
            (v, n, z)
        }
        else if v < d {
            (d, 1, x)
        }
        else if v == d {
            (v, n + 1, x)
        }
        else {
            (v, n, x)
        }
    });

    println!("{}", res);
}


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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
	int N;
	cin >> N;
	int res = 0;
	vector<long long> L(N);
	for (int i = 0; i < N; ++i) cin >> L[i];

	for (int i = 0; i < N; ++i) {
		for (int j = i+1; j < N; ++j) {
			for (int k = j+1; k < N; ++k) {
				vector<long long> v = {L[i], L[j], L[k]};
				sort(v.begin(), v.end());
				if (v[0] == v[1] || v[1] == v[2]) continue;
				if (v.back() < v[0] + v[1]) ++res;
			}
		}
	}
	cout << res << endl;
}
















Measured memory_bytes: 3628
import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


n, k = map(int, input().split())
h = np.array([int(x) for x in input().split()])

dp = np.array([0] * n)

for i in range(1, n):
    j = max(0, i-k)
    dp[i] = np.min(np.abs(h[i] - h[j:i]) + dp[j:i])

print(dp[n-1])

Measured memory_bytes: 24064
import java.util.*;


public class Main {
	public static void main(String[] args) {
		int a; //（上辺）
		int b; //（底辺）
		int h; //（高さ）
		int s; //（面積）
		
		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		b = sc.nextInt();
		h = sc.nextInt();
		
		s = ( a + b ) * h / 2;
		
		System.out.println( s );
	}
}
		

Measured memory_bytes: 9796
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

ll n, sum;

int main() {
    ios_base::sync_with_stdio(0);

    cin >> n;

    for(int i=1; i <= n; ++i) {
        for(int j=i; j <= n; j += i) {
            sum += j;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) (V).begin(),(V).end()

int main(){
	ll H, W, h, w;
	cin >> H >> W >> h >> w;

	if (H%h == 0 && W%w == 0) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	vector<vector<int>> ANS(H,vector<int>(W, 501));
	for (int i = 0;i < H;i++) {
		for (int j = 0;j < W;j++) {
			if (i%h == h - 1 && j%w == w - 1)
				ANS[i][j] = -501 * (h*w - 1) - 1;
			cout << ANS[i][j] << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 2432
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {
    const rows = input.split('\n')
    const N = parseInt(rows[0].split(' ')[0], 10)
    const M = parseInt(rows[0].split(' ')[1], 10)
    const A = []
    const B = []
    for (var i = 0; i < M; i++) {
        A[i] = parseInt(rows[i + 1].split(' ')[0], 10)
        B[i] = parseInt(rows[i + 1].split(' ')[1], 10)
    }

    const map = Array(N + 1).fill(null).map(() => [])
    for (let i  = 0; i < M; i++) {
        map[A[i]].push(B[i])
        map[B[i]].push(A[i])
    }
    const res = Array(N).fill(0)
    const s = [1]
    let n = 0
    while (n = s.shift()) {
        map[n].forEach(_n => {
            if (res[_n - 1] === 0) {
                s.push(_n)
                res[_n - 1] = n
            }
        })
    }

    if (res.indexOf(0) === -1) {
        res[0] = 'Yes'
        res.forEach(val => {
            console.log(val)
        })
    } else {
        console.log('No')
    }

})(input)


Measured memory_bytes: 108292
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
 int a;
 int b;
 cin >> a ;
 cin >> b ;
 int c;

 c = b - a;

 for (int i = c -1 ; i > 0; i--){
    c += i;
 }
 cout << c - b;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int h,w;
int conv(int y, int x){
    return y*w+x;
}

//verified AOJ GRL_1
#define MAX_V 100000
template <typename T>
struct edge{int to;T cost;};

template <typename T>
void dijkstra(int s, vector<T> &d, vector<edge<T>> G[MAX_V]){
    priority_queue< pii,vector<pii>,greater<pii> > que;
    rep( i,d.size() )d[i]=INF;
    d[s] = 0;
    que.push( pii(0,s) );
    
    while( que.size() ){
        pii p=que.top();
        que.pop();
        
        int v=p.second;
        if(d[v]<p.first)continue;
        
        rep(i,G[v].size()){
            edge<T> e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    }
}

int main(){
    cin>>h>>w;
    
    vector<string> vs(h);
    rep(i,h)cin>>vs[i];
    
    pii s,g;
    
    rep(i,h){
        rep(j,w){
            if(vs[i][j]=='S')s = pii(i,j);
            if(vs[i][j]=='G')g = pii(i,j);
        }
    }
    
    
    int dy[]={1,0,-1,0};
    int dx[]={0,1,0,-1};
    
    vector<edge<int>> G[MAX_V];
    rep(i,h){
        rep(j,w){
            rep(k,4){
                int ddy = i+dy[k];
                int ddx = j+dx[k];
                if(ddx<0 || ddy<0 || ddx>=w || ddy>=h || vs[ddy][ddx]=='#')continue;
                if(vs[ddy][ddx]=='.' || vs[ddy][ddx]=='G'){
                    G[conv(i,j)].pb( edge<int>{conv(ddy,ddx),2} );
                }
                else if(vs[ddy][ddx]=='o'){
                    G[conv(i,j)].pb( edge<int>{conv(ddy,ddx),1} );
                }
            }
            rep(k,4){
                for(int l=1;l<=3;l++){
                    int ddy = i+dy[k]*l;
                    int ddx = j+dx[k]*l;
                    if(ddx<0 || ddy<0 || ddx>=w || ddy>=h || vs[ddy][ddx]=='#')break;
                    G[conv(i,j)].pb( edge<int>{conv(ddy,ddx),2+l} );
                }
            }
        }
    }
    vector<int> d(h*w);
    dijkstra(conv(s.first, s.second), d, G);
    
    cout<<d[conv(g.first, g.second)]<<endl;
}



Measured memory_bytes: 5600
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 a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int tmp;
		if(a>b){
			tmp=a;
			a=b;
			b=tmp;
		}
		if(b>c){
			tmp=b;
			b=c;
			c=tmp;
		}
	    if(a>b){
		    tmp=a;
		    a=b;
		    b=tmp;
	    }
	    System.out.println(a+" "+b+" "+c);
	}
}

Measured memory_bytes: 26108
#include <cstdio>
#include <cstring>
using namespace std;
int main(void){
  char a[128], b[128], c[128];
  scanf("%s%s%s",a,b,c);
  puts(a[strlen(a)-1]==b[0] && b[strlen(b)-1]==c[0]? "YES":"NO");
  return 0;
  
}

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

ll const INF = 1e18;

int a, b, c;
int x, y;
ll ans;

void solve() {
	ans = INF;
	fi(0, max(x, y) * 2) {
		ll cur = (ll) c * i;
		int ra = max(0, x - i / 2);
		int rb = max(0, y - i / 2);
		cur += (ll) ra * a;
		cur += (ll) rb * b;
		ans = min(ans, cur);
	}
	printf("%lld\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);  
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
    int x,y;

    while(1)
	{
		scanf("%d %d", &x, &y);
		if(0==x && 0==y){
			break;
		}

		if(x < y)
            printf("%d %d\n", x, y);
	    else
            printf("%d %d\n", y, x);
	}
    return 0;
}

Measured memory_bytes: 596
#include<iostream>

int memo[500001];

int main(){
	int n, m;
	while(std::cin >> n >> m, n){
		for(int i=0;i<500001;i++){
			memo[i] = 0;
		}

		bool flag = false;
		char prev_c, c;
		int combo = 0;
		for(int i=0;i<m;i++){
			std::cin >> c;

			if(flag){
				if(prev_c == c){//清算処理
					for(int j=1;j<=combo;j++){
						memo[j] += combo - (j-1);
					}
					flag = false;
					combo = 0;
				}else{
					combo += (c=='I')?1:0;
				}
			}

			if(!flag && c == 'I'){
				flag = true;
			}

			prev_c = c;
		}

		std::cout << memo[n] << std::endl;
	}
}

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

class State{
public:
	int x1,y1,x2,y2,cost;

	State(int tx1,int ty1,int tx2,int ty2,int tcost){
		x1 = tx1;
		y1 = ty1;
		x2 = tx2;
		y2 = ty2;
		cost = tcost;
	}
};

int w,h;
bool t[52][52];
bool closed[52][52][52][52];

int dx1[] = {-1,1,0,0};
int dx2[] = {1,-1,0,0};
int dy1[] = {0,0,1,-1};
int dy2[] = {0,0,-1,1};

int main(void){
	while(cin>>w>>h && (w||h)){
		int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		x1--; y1--; x2--; y2--;

		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin>>t[i][j];
			}
		}

		int ans = -1;
		queue<State> open;

		memset(closed,0,sizeof(closed));
		closed[x1][y1][x2][y2] = true;
		open.push(State(x1,y1,x2,y2,0));

		while(!open.empty()){
			State st = open.front(); open.pop();
			if(st.cost >= 100) break;

			if(st.x1 == st.x2 && st.y1 == st.y2){
				ans = st.cost;
				break;
			}

			for(int i=0;i<4;i++){
				int nx1 = st.x1 + dx1[i];
				int ny1 = st.y1 + dy1[i];
				int nx2 = st.x2 + dx2[i];
				int ny2 = st.y2 + dy2[i];
				State nst = st;
				nst.cost++;

				if(nx1>=0 && nx1<w && ny1>=0 && ny1<h && !t[ny1][nx1]){
					nst.x1 = nx1;
					nst.y1 = ny1;
				}
				if(nx2>=0 && nx2<w && ny2>=0 && ny2<h && !t[ny2][nx2]){
					nst.x2 = nx2;
					nst.y2 = ny2;
				}

				if(!closed[nst.x1][nst.y1][nst.x2][nst.y2]){
					closed[nst.x1][nst.y1][nst.x2][nst.y2] = true;
					open.push(nst);
				}
			}
		}

		if(ans == -1)
			cout<<"NA\n";
		else
			cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 8404
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<VV> VVV;


int main() {
	int s,co1=0,co2=0;
	cin >>s;
	int s1 = (s / 100) % 10 + ((s / 1000)%10) * 10;
	int s2 = ((s / 10)%10) * 10 + s % 10;
	int a[12] = { 1,2,3,4,5,6,7,8,9,10,11,12 };
	for (int i = 0; i < 12;i++) {
		if (s1 == a[i])co1 = 1;
		if (s2 == a[i])co2 = 1;
	}
	if (co1 == 1 && co2 == 1) {
		cout << "AMBIGUOUS" << endl;
	}
	else if(co1==1){
		cout << "MMYY" << endl;
	}
	else if (co2 == 1) {
		cout << "YYMM" << endl;
	}
	else {
		cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
class Node

  attr_accessor:id, :parent, :child_left, :right_sibling, :depth

  def initialize(id)
    @id = id
    @parent = nil
    @child_left = nil
    @right_sibling = nil
    @depth = 0
  end

  def depth
    if @parent.nil?
      0
    else
      @parent.depth + 1
    end
  end

  def type
    if @parent == nil
      "root"
    elsif @child_left.nil?
      "leaf"
    else
      "internal node"
    end
  end

  def to_s
    parent_id =
      if @parent.nil?
        -1
      else
        @parent.id
      end
    "node #{@id}: parent = #{parent_id}, depth = #{depth}, #{type}, [#{children_to_s.join(', ')}]"
  end

  def children_to_s
    ss = []
    if @child_left.nil?
      ss
    else
      a = @child_left
      while a != nil
        ss.push(a.id.to_s)
        a = a.right_sibling
      end
      ss
    end
  end
end

def set_depth(tree, u, depth)
  tree[u].depth = depth
  if tree[u].right_sibling != nil
    set_depth(tree, tree[u].right_sibling.id, depth)
  end
  if tree[u].child_left != nil
    set_depth(tree, tree[u].child_left.id, depth + 1)
  end
end


n = STDIN.gets.to_i

tree = []
for i in 0..(n - 1)
  as = STDIN.gets.split(' ')
  id = as[0].to_i
  m = as[1].to_i
  children = as.drop(2).map { |x| x.to_i }

  node = tree[id]
  if node.nil?
    node = Node.new(id)
    tree[id] = node
  end

  l = 0
  children.each_with_index { |c, j|
    child_node = tree[c]
    if child_node.nil?
      child_node = Node.new(c)
      tree[c] = child_node
    end
    if j == 0
      node.child_left = child_node
    else
      tree[l].right_sibling = child_node
    end
    l = c
    tree[c].parent = node
  }
end

root = tree.find { |node| node.parent == nil }.id

#set_depth(tree, root, 0)

for i in 0..(n-1)
  puts tree[i].to_s
end

Measured memory_bytes: 28492
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       int h=s.nextInt(),w=s.nextInt(),k=s.nextInt();
       s.nextLine();
       int[][] arr=new int[h][w];
       int x=0,y=0;
       for(int i=0;i<h;i++){
        char[] c=s.nextLine().toCharArray();
        for(int j=0;j<w;j++){
          if(c[j]=='#'){
            arr[i][j]=-1; x=i;y=j;
          }
        }
       }
       int count=1;
       int[][] res=new int[h][w];
       for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(arr[i][j]==0||res[i][j]!=0){continue;}
          res[i][j]=count;
          int a=i-1,b=i+1;
          while(a>=0&&(arr[a][j]!=-1)&&res[a][j]==0){
            res[a][j]=count; a--;
          }
          while(b<h&&(arr[b][j]!=-1)&&res[b][j]==0){
            res[b][j]=count; b++;
          }
          count++;
        }
       }       

       int lc=y-1,rc=y+1;
       while(lc>=0){
        if(res[0][lc]!=0){lc--;continue;}
        for(int i=0;i<h;i++){
          res[i][lc]=res[i][lc+1];
        }
        lc--;
       }
       while(rc<w){
        if(res[0][rc]!=0){rc++;continue;}
        for(int i=0;i<h;i++){
          res[i][rc]=res[i][rc-1];
        }
        rc++;
       }
       BufferedWriter out =new BufferedWriter(new OutputStreamWriter(System.out));
       for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          out.write(res[i][j]+" ");
        }
        out.write("\n");
       out.flush();
       }
        }
    }


Measured memory_bytes: 40452
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll n, m;
    cin >> n >> m;
    if(n >= m / 2){
        cout << m / 2 << endl;
    }else{
        cout << n + (m - n * 2) / 4 << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD =1e9+7;

ll modpow(ll a, ll n, ll mod = MOD) {
    ll rtn = 1;
    while (n > 0) {
        if (n & 1) rtn = rtn * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return rtn;
}


int main(){
    
    int N,K;
    cin >> N >> K;
    
    vector<ll> dd(K+1);
    vector<ll> d(K+1);
    ll ans=0;
    
    for(int i=K; i>0; i--){
        
        d.at(i) = modpow(K/i,N,MOD);
        
        for(int j=2*i; j<=K; j+=i){
            d.at(i) += (MOD - d.at(j))%MOD;//
        }
        
        ans += (i*d.at(i))%MOD;
        ans %= MOD;
        
    }
    
    cout << ans << endl;
    
    return 0;
}

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

int main(){
	int a,b,c; cin>>a>>b>>c;
	if(a==b+c) cout<<"Yes"<<endl;
	else if(b==a+c) cout<<"Yes"<<endl;
	else if(c==a+b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3604