akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N;
  cin>>N;
  int A[N+1],C[N+1];
  rep(i,N) cin>>A[i];
  rep(i,N) cin>>C[i];
  int ans=0;
  rep(i,N) if(A[i]>C[i]) ans=ans+A[i]-C[i];
  cout<<ans<<endl;
}

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

int main(){
    int n,ans=0;
    cin >> n ;

    vector<int> a(n);

    for(int i=0;i<n;i++){
        cin >> a.at(i);
        while(a.at(i)%2==0){
            ans++;
            a.at(i)/=2;
        }
    }

    cout << ans << endl;

}

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

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

int main()
{
  double n;
  while (cin >> n){
    if (n <= 48.0) cout << "light fly" << endl;
    else if (n <= 51.0) cout << "fly" << endl;
    else if (n <= 54.0) cout << "bantam" << endl;
    else if (n <= 57.0) cout << "feather" << endl;
    else if (n <= 60.0) cout << "light" << endl;
    else if (n <= 64.0) cout << "light welter" << endl;
    else if (n <= 69.0) cout << "welter" << endl;
    else if (n <= 75.0) cout << "light middle" << endl;
    else if (n <= 81.0) cout << "middle" << endl;
    else if (n <= 91.0) cout << "light heavy" << endl;
    else cout << "heavy" << endl;
  }
}

Measured memory_bytes: 1220
// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <list>
#include <cstdlib>
#include <bitset>
#include <assert.h>
#include <time.h>
#include <iomanip>
// #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
// char buf[(1 << 21) + 1], * p1 = buf, * p2 = buf;
// #define int long long
#define lowbit(x) (x & (-x))
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
#define pb push_back
typedef unsigned long long ull;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> VI;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define SZ(x) ((int)((x).size()))
#define bug puts("BUG")
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-6;
template <class T>
inline void read(T &x)
{
    int sign = 1;char c = getchar();x = 0;
    while (c > '9' || c < '0'){if (c == '-')sign = -1;c = getchar();}
    while (c >= '0' && c <= '9'){x = x * 10 + c - '0';c = getchar();}
    x *= sign;
}
#ifdef LOCAL
    FILE* _INPUT=freopen("input.txt", "r", stdin);
    // FILE* _OUTPUT=freopen("output.txt", "w", stdout);
#endif
using namespace std;
const int maxn = 13;
int c[maxn];
int a[maxn][maxn];
int main()
{
    int n, m, x;
    read(n), read(m), read(x);
    for (int i = 0; i < n; ++i)
    {
        read(c[i]);
        for (int j = 0; j < m; ++j)
            read(a[i][j]);
    }
    ll res = INF;
    for (int cur = 1; cur < (1 << n); ++cur)
    {
        int tot[13] = {0};
        ll ret = 0;
        for (int j = 0; j < n; ++j)
        {
            if ((cur >> j) & 1)
            {
                ret += c[j];
                for (int k = 0; k < m; ++k)
                {
                    tot[k] += a[j][k];
                }
            }
        }
        bool okk = 1;
        for (int j = 0; j < m; ++j)
        {
            if (tot[j] < x)
            {
                okk = 0;
                break;
            }
        }
        if (okk)
            res = min(res, ret);
    }
    printf("%lld\n", res >= INF ? -1 : res);
}

Measured memory_bytes: 3760
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  //for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

int main()
{
  // A(1) + ... + A(N) = X(1) + ... + X(N) = Sum
  //
  // {X(i) + X(i+1)} / 2 = A(i)
  // X(i) + X(i+1) = 2 * A(i)
  //
  // X(1) = Sum - {X(2) + ... + X(N)}
  //      = Sum - [{X(2) + X(3)} + {X(4) + X(5)} + ... + {X(N-1) + X(N)}]
  //      = Sum - [{  2 * A(2) } + {  2 * A(4) } + ... + {   2 * A(N-1)}]
  // X(2) = 2 * A(1) - X(1)
  // X(3) = 2 * A(2) - X(2)
  // ...
  // ...

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);

  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  ll sum = std::accumulate(va.begin(), va.end(), 0LL);

  std::vector< ll > vx(N, 0LL);
  vx[0] = sum;
  for (ll i = 1; i < N; i+=2) {
    vx[0] -= 2 * va[i];
  }

  for (ll i = 1; i < N; i++) {
    vx[i] = 2 * va[i-1] - vx[i-1];
  }

  print(vx);
  return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                   \
  ifstream in("atcoder-problems/diverta2019_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  ll ans = 0;
  ll ea = 0;
  ll sb = 0;
  ll both = 0;

  rep(i, N) {
    string s;
    cin >> s;
    rep(j, s.size() - 1) {
      if (s[j] == 'A' && s[j + 1] == 'B') ans++;
    }
    if (s[0] == 'B' && s[s.size() - 1] == 'A')
      both++;
    else if (s[0] == 'B')
      sb++;
    else if (s[s.size() - 1] == 'A')
      ea++;
  }

  if (both == 0) {
    ans += min(ea, sb);
  } else {
    if (ea + sb > 0)
      ans += both + min(ea, sb);
    else
      ans += both - 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import itertools
import numpy as np

# 標準入力を取得
H, W, K = list(map(int, input().split()))
c = []
for h in range(H):
    c.append(input())

# 求解処理
l = np.zeros(shape=(H, W))
for h, w in itertools.product(range(H), range(W)):
    l[h, w] = (c[h][w] == "#")

ans = 0
for h_bit, w_bit in itertools.product(range(1 << H), range(1 << W)):
    l_copy = l.copy()
    for h in range(H):
        if h_bit & (1 << h):
            l_copy[h, :] = [0]
    for w in range(W):
        if w_bit & (1 << w):
            l_copy[:, w] = [0]
    ans += (np.sum(l_copy) == K)

# 結果出力
print(ans)


Measured memory_bytes: 27300
N = int(input())
K= int(input())
xlist = list(map(int, input().split()))

def Minl(x, K):
  l = abs(K - x)
  if l < x:
    return 2 * l
  else:
    return 2 * x

ans = 0
for x in xlist:
  ans = ans + Minl(x, K)

print(str(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cctype>
using namespace std;
 
typedef string::const_iterator iter;
 
int number(iter& p);
 
int expr(iter& p) {
    p++; // skip [
    int ans;
    if(isdigit(*p)) {
        int res = number(p);
        ans = res / 2 + 1;
    }
    else {
        vector<int> vec;
        while(*p == '[') {
            vec.push_back(expr(p));
        }
        sort(vec.begin(), vec.end());
        int res = 0;
        for(int i = 0; i < (int)vec.size() / 2 + 1; i++) {
            res += vec[i];
        }
        ans = res;
    }
    p++; // skip ]
    return ans;
}
 
int number(iter& p) {
    int res = 0;
    while(isdigit(*p)) {
        res *= 10;
        res += *p - '0';
        p++;
    }
    return res;
}
 
int main() {
    int n; cin >> n;
    while(n-- ){
        string s; cin >> s;
        iter it = s.begin();
        int res = expr(it);
        cout << res << endl;
    }
}
 

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

ll luca[100];

ll getluca(int n){
  if(n == 0) return 2;
  if(n == 1) return 1;
  if(luca[n]!=0) return luca[n];
  return luca[n] = getluca(n-1) + getluca(n-2);
}

int main(){
  int n;
  cin >> n;
  
  cout << getluca(n) <<endl;
}

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

#define pb push_back
#define rep(i, a, n) for(int (i)=a; (i)<(n); (i)++)
#define FOR(i, n) rep(i, 0, n)
#define F(n) FOR(i, n)
#define FF(n) FOR(j, n)
#define repi(i, a, n) for(int (i)=a; (i)<=(n); (i)++)
#define FORI(i, n) repi(i, 1, n)
#define FI(n) FORI(i, n)
#define FFI(n) FORI(j, n)
#define IN(x) int x; cin>>(x);
#define INN(x, y) int x, y; cin>>(x)>>(y);
#define INFO(a) cout<<"info "<<a<<endl
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define vpii vector<pair<int, int> >
#define sortv(x) sort((x).begin(), (x).end())
#define sortvd(x) sort((x).begin(), (x).end(), greater<int>())
#define lboundv(x,v) lower_bound((x).begin(),(x).end(),(v))-(x).begin();
#define uboundv(x,v) upper_bound((x).begin(),(x).end(),(v))-(x).begin();
#define ite iterator
#define fi first
#define se second
#define mems(a, v) memset((a), (v), sizeof((a)))
#define lmid(l, r) ((l)+(r)-1)/2
#define rmid(l, r) ((l)+(r))/2+1
#define mp make_pair

typedef long long ll;
typedef long double LD;

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	string s;
	cin>>s;
	cout<<((s.size()>3&&s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I') ? "Yes" : "No")<<endl;
	return 0;
}

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

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

int main(){

  int a,b;

  while(cin>>a>>b){
    if(a<b)swap(a,b);
    cout << gcd(a,b)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
<?php
fscanf(STDIN,'%s',$S);
$N=strlen($S);
$A=str_split($S);
$split="a";
$count=0;
$judge=0;
for ($i=1; $i <=$N/2 ; $i++) { 
    # code...
    $judge=0;
    $split=array_splice($A,-2,2);
    $count=count($A);
    for ($j=0; $j <$count/2-1 ; $j++) { 
        # code...
        if($A[$j]!=$A[$j+$count/2]){
            $judge++;
        }
      
      
    }
  if($judge==0){
    echo $count;
    break;
  }
}
echo "\n";
?>

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

int main() {

  int n;
  while( scanf("%d", &n) != EOF ) {

    int ans = 0;
    for(int i=0; i<10; i++) {
      for(int j=0; j<10; j++) {
	for(int k=0; k<10; k++) {
	  for(int l=0; l<10; l++) {
	    if( i + j + k + l == n ) ans++;
	  }
	}
      }
    }

    cout << ans << endl;
  }
}

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

int main() {
	int N,i;
	scanf("%d",&N);
	char s[N];
	for(i=0;i<N;i++)scanf("%c",&s[i]);
	
	i=strchr(s,(int)'Y');
	switch (i) {
		case 0:
		printf("Three\n");
		break;
		
		default:
		printf("Four\n");
		break;
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

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 (a>b) { a=b; return 1; } return 0; }
const ll LINF = 1e18;

int main()
{
  int N; cin >> N;
  vector<int> P(N), Q(N);
  REP(i, N) cin >> P[i]; REP(i, N) cin >> Q[i];

  vector<int> v(N);
  iota(ALL(v), 1);

  int pr, qr;

  int i = 0;
  do {
    if (P == v) pr = i;
    if (Q == v) qr = i;

    i++;
  } while (next_permutation(ALL(v)));

  cout << abs(pr-qr) << endl;
}


Measured memory_bytes: 256
from collections import  deque
import sys
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)

R = inp()
print(math.pi * 2 * R)



Measured memory_bytes: 9952
#include <stdio.h>

long long int calc(long long int a, long long int b, long long int p){
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        long long int d = calc(a, b / 2, p);

        return (d * d) % p;
    } else {
        return (a * calc(a, b - 1, p)) % p;
    }
}
long long int conb(long long int a, long long int b, long long int p){
    long long int sum = 1;

    for(long long int i = 1; i <= b; i ++){
        sum = (sum * (a - i + 1)) % p;
        sum = (sum * calc(i, p - 2, p)) % p;
    }
    return sum;
}

int main(){
    int X, Y;

    scanf("%d%d", &X, &Y);

    if((- X + 2 * Y) >= 0 && (2 * X - Y) >= 0 && (- X + 2 * Y) % 3 == 0 && (2 * X - Y) % 3 == 0){
        int a = (- X + 2 * Y) / 3;
        int b = (2 * X - Y) / 3;

        printf("%lld\n", conb(a + b, b, 1000000007));
    }else{
        printf("0\n");
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
	int n;
	cin >> n;
	if(n==7||n==5||n==3)
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A = [1000] + A + [0]

ans = 1000
stock = 0

for i, a in enumerate(A):
    if i > 0 and i < N + 1:
        if A[i-1] >= a and A[i+1] >= a:
            stock += ans // a
            ans -= a * (ans // a)

        if A[i-1] <= a and A[i+1] <= a:
            ans += stock * a
            stock = 0
        
print(ans)



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

int main()
{
	ll n;
	cin>>n;
	ll ans=0; 

	for(int i=1; i<=n; i++)
	{
		if(i%3 !=0 && i%5 !=0)
		{
			ans=ans+i;
		}
		

	}
	cout<<ans<<endl;
}


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

int main()
{
    int y=1;
    vector<char>s(4);
    for(int i=0;i<4;i++)
    {
        cin >> s.at(i);
    }

    switch (s.at(0))
    {
        case '1':
            if(s.at(1)=='1' || s.at(1)=='0')
            {
                y*=2;
            }else if(s.at(1)=='2')
            {
                y*=2;
                
            }
            break;

        case '0':
            if(s.at(1)!='0')
            {
                y*=2;
                break;
            }
    }

    switch (s.at(2))
    {
        case '1':
            if(s.at(3)=='1' || s.at(3)=='0')
            {
                y*=3;
                break;
            }else if(s.at(3)=='2')
            {
                y*=3;
                break;
            }

            break;
        case '0':
            if(s.at(3)!='0')
            {
                y*=3;
                break;
            }
    }

    switch (y)
    {
        case 1:cout << "NA" <<endl;break;
        case 2:cout << "MMYY" <<endl;break;
        case 3:cout << "YYMM" <<endl;break;
        case 6:cout << "AMBIGUOUS" <<endl;break;
    }







}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
     int a, n, t;
      
     a = 100000;

     scanf("%d", &n);
     
     while(0<1){
	  if(n==0) break;
	  
	  t = a / 20;
	  a = a + t;
	  t = a % 1000;

	  if(t>0) a = a - t + 1000;

	  n--;
     }

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

Measured memory_bytes: 592
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

const int INF = 1001001001;
int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<vector<int> > graph(n);
    vector<int> deg_in(n);
    rep (i, m) {
        int a, b; cin >> a >> b; a--; b--;
        graph[a].push_back(b);
        deg_in[b]++;
    }
    int argmin = -1, mind = INF;
    vector<int> minpred;
    rep (i, n) {
        bool breaked = false;
        int length = -1;
        vector<int> d(n); rep (i, n) d[i] = INF;
        vector<int> pred(n); rep (i, n) pred[i] = -1;
        d[i] = 0;
        priority_queue<P, vector<P>, greater<P>> que;
        que.emplace(0, i);
        while (!que.empty()) {
            P p = que.top(); que.pop();
            if (d[p.second] < p.first) continue;
            for (int j : graph[p.second]) {
                if (j == i) {
                    length = d[p.second] + 1;
                    pred[j] = p.second;
                    breaked = true;
                    break;
                }
                if (breaked) break;
                if (chmin(d[j], d[p.second] + 1)) {
                    que.emplace(d[j], j);
                    pred[j] = p.second;
                }
            }
        }
        if (length != -1) {
            if (chmin(mind, length)) {
                argmin = i;
                minpred = pred;
            }
        }
    }
    if (mind >= INF) {
        cout << -1 << "\n";
    } else {
        cout << mind << "\n";
        vector<int> cycle = {argmin, minpred[argmin]};
        while (cycle.back() != argmin) cycle.push_back(minpred[cycle.back()]);
        reverse(all(cycle));
        rep (i, cycle.size() - 1) cout << cycle[i] + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

#define INF 1e9

using namespace std;

typedef long long ll;

int main() {
	int w, d;
	while ( cin >> w >> d, w || d ) {
		int front[20] = {0}, side[20] = {0};
		for (int i = 0; i < w; ++i) {
			int h; cin >> h;
			++front[h-1];
		}
		for (int i = 0; i < d; ++i) {
			int h; cin >> h;
			++side[h-1];
		}
		int ans = 0;
		for (int i = 0; i < 20; ++i) {
			ans += max(front[i], side[i]) * (i+1);
		}
		cout << ans << endl;
		/*
		int m[10][10];
		fill(&m[0][0], &m[0][0]+10*10, INF);
		for (int i = 0; i < w; ++i) {
			int h; cin >> h;
			for (int j = 0; j < d; ++j) {
				m[i][j] = min(m[i][j], h);
			}
		}
		for (int j = 0; j < d; ++j) {
			int h; cin >> h;
			for (int i = 0; i < w; ++i) {
				m[i][j] = min(m[i][j], h);
			}
		}
		ll ans = 1;
		for (int i = 0; i < w; ++i) {
			for (int j = 0; j < d; ++j) {
				ans *= m[i][j];
			}
		}
		cout << ans << endl;
		*/
	}
}

Measured memory_bytes: 1160
import qualified Data.List as L

main :: IO ()
main = do
    _  <- getLine
    xs <- fmap read . words <$> getLine
    answer $ solve xs

type Answer = Int
answer :: Answer -> IO ()
answer = print

solve :: [Int] -> Answer
solve = subtract 1 . L.head . go
  where
    go = inner . L.sortBy (flip compare)
    inner []           = [1]
    inner [x]          = [x]
    inner (1 : 1 : xs) = go $                   xs
    inner (1 : y : xs) = go $          pred y : xs
    inner (x : 1 : xs) = go $ pred x          : xs
    inner (x : y : xs) = go $ pred x : pred y : xs


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

int main() {
  int N, C, K;
  cin >> N >> C >> K;
  vector<int> T(N);
  for (int i = 0; i < N; i++) cin >> T.at(i);
  sort(T.begin(), T.end());
  int D = -1, P = 0, ans = 0;
  for (int i = 0; i < N; i++) {
    P++;
    if (T.at(i) > D || P > C) {
      ans++;
      D = T.at(i) + K;
      P = 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3800
import scala.io.StdIn._

object Main extends App {


  val x = readInt()

  def solve(): Int = {
    val limit = 100010
    val primeNums = mkPrimeNums(limit)
    (x to limit).foreach { i =>
      if(primeNums(i)) return i
    }
    throw new Exception("can not find prime num")
  }

  def mkPrimeNums(limit: Int): Array[Boolean] = {
    val primeNums = Array.fill(limit+1)(true)
    (0 to Math.sqrt(limit).toInt).foldLeft(primeNums) { (acc, i) =>
      if(i == 0 || i == 1) acc.updated(i, false)
      else if(acc(i)) {
        val tmpAcc = acc
        for(j <- i * 2 to limit by i) tmpAcc(j) = false
        tmpAcc
      } else acc
    }
  }

  println(solve())

}



Measured memory_bytes: 54868
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	int n,a,b,p,x=0,y=0,z=0;
	cin>>n;cin>>a>>b;
	rep(i,n){
		cin>>p;
		if(p<=a) x++;
		else if(p<=b) y++;
		else z++;
	}
	cout<<min(x,min(y,z))<<endl;
}


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

int main() {
  int n,m,a,b,c,suma=0,sumb=0,sumc=0;
  cin >> n;
  vector<int> v(n);
  r(i,n)cin >> v[i];
  sort(v.begin(),v.end());
  m=v[0];
  r(i,n)v[i]-=m;
  a=(v[0]+v[n-1])/2;
  b=a-1;
  c=a+1;
  r(i,n)suma+=(a-v[i])*(a-v[i]);
  r(i,n)sumb+=(b-v[i])*(b-v[i]);
  r(i,n)sumc+=(c-v[i])*(c-v[i]);
  if(suma<sumb&&suma<sumc)cout<<suma<<endl;
  else if(sumb<suma){
    while(sumb<=suma){
    suma=sumb;
    sumb=0;
    r(i,n)sumb+=(b-1-v[i])*(b-1-v[i]);
      b--;
    }
    cout<<suma<<endl;
  }
  else{
    while(sumc<=suma){
    suma=sumc;
    sumc=0;
    r(i,n)sumc+=(c+1-v[i])*(c+1-v[i]);
      c++;
    }
    cout<<suma<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

int n,a,b;


const ll INF=100000000001;
int main() {

	cin>>n>>a>>b;
	cout<<min(b,n*a)<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	String s = scan.nextLine();
    	char[] ca = s.toCharArray();
    	
    	String change;
    	
    	for(int i = 0; i < ca.length; i++){
    		if(Character.isLowerCase(ca[i])){
    			ca[i] = Character.toUpperCase(ca[i]);
    		}else{
    			ca[i] = Character.toLowerCase(ca[i]);
    		}
    	}
    	change = String.valueOf(ca);
    	
    	System.out.println(change);
     }
}

Measured memory_bytes: 25976
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC091A
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split().Select(int.Parse).ToArray();

            if (line1[0] + line1[1] >= line1[2]) Console.WriteLine("Yes");
            else Console.WriteLine("No");

            Console.ReadKey();


        }
    }
}


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

int main(){
    int n;
    int p[101];
    int sum = 0;
    vector<int> n10;

    cin>>n;
    for(int i=0;i<n;i++) cin>>p[i];
    for(int i=0;i<n;i++)
        if(p[i] % 10 !=0)
            n10.push_back(p[i]); 

    sort(n10.begin(),n10.end());

    for(int i=0;i<n;i++) sum+=p[i];

    if(sum % 10 == 0){
        if(!n10.empty()) sum -= n10[0];
        else sum = 0;
    } 

    cout<<sum<<"\n";
}

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

using namespace std;

int main() {
    int N; cin >> N;
    int t, a; cin >> t >> a;
    long long int nt = t, na = a;
    for (int i = 1; i < N; i++) {
        int t, a; cin >> t >> a;
        long long int p = max((nt + t - 1)/ t, (na + a - 1)/ a);
        //long long int p = max(ceil((long double)nt/t), ceil((long double)na/a));
        nt = t * p;
        na = a * p;
    }
    cout << nt+na << endl;
    return 0;
}



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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination

int n;
vi data;

bool solve(int num)
{
    int sum = 0;
    rep(i, n) {
        int tmp = (data[i] + num + 1 - n); // +1
        if (tmp < 0) continue;
        sum += ( tmp / (n+1) + (!!(tmp % ( n+1 ))));
    }
//    cout << "num : " << num << " ans : " << sum << endl;
    if (sum <= num) {
        return true;
    } else {
        return false;
    }
}

signed main()
{
    cin >> n;
    data = vi(n);
    rep(i, n) {
        cin >> data[i];
    }

    int hohoge = 0, sum = 0;
    rep(i, n) {
        hohoge = max(hohoge, data[i]);
        sum += data[i];
    }
    if (hohoge < n) {
        std::cout << 0 << std::endl;
        return 0;
    }

    for (int i = max(1LL, sum - (n*n)-n);1; i++) {
        if (solve(i)) {
            std::cout << i << std::endl;
            return 0;
        }
    }


    /*
    int left = 0, right = INF;
    while (right - left > 1) {
        int mid = (right + left) / 2;

        if (solve(mid)) {
            right = mid;
        } else {
            left = mid;
        }
    }
    solve(2);
    */

    std::cout << right << std::endl;

    return 0;
}




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String key = br.readLine();
			if(key.equals("-")) break;
			int n=Integer.parseInt(br.readLine());
			for(int i=0;i<n;i++){
				int ch=Integer.parseInt(br.readLine());
				String tmpstr=key.substring(0,ch);
				key=key.substring(ch, key.length())+tmpstr;
			}
			System.out.println(key);
		}
	}
}

Measured memory_bytes: 17028
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	bool prime[100000];
	rep(i,100000)prime[i]=true;
	prime[0]=false;
	prime[1]=false;
	loop(i,2,1000){
		for(int j=i*2;j<100000;j+=i){
			prime[j]=false;
		}
	}
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		int cnt=0;
		rep(i,n/2+1){
			if(prime[n-i] && prime[i]){
				cnt++;
				//cout<<i<<" "<<n-i<<endl;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

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

#define NDEBUG
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


ll solve(int W,int H,vi& p,vi& q) {
    sort(ALL(p));
    sort(ALL(q));


    ll ans = 0;
    ans += accumulate(ALL(p), 0LL);
    ans += accumulate(ALL(q), 0LL);

    int pL = p.size(), qL = q.size();

    vll pAcc(pL+1);
    pAcc[0] = 0;
    rep(i,pL) pAcc[i+1] = pAcc[i] + p[i];

    for (int qj: q) {
        int ix = lower_bound(ALL(p), qj) - p.begin();
        ans += pAcc[ix] + (ll)qj * (pL - ix);
    }
    return ans;
}

int main() {
    int W, H; scanf("%d%d", &W, &H);
    vi p(W);
    rep(i,W) scanf("%d", &p[i]);
    vi q(H);
    rep(i,H) scanf("%d", &q[i]);
    cout << solve(W,H,p,q) << endl;
    return 0;
}


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

using namespace std;

int main() {
    int arr[5];
    for(int i = 0; i < 5; ++i) cin >> arr[i];
    sort(arr, arr+5);
    for(int i = 4; i >= 0; --i) {
        cout << arr[i];
        if(i != 0) cout << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	string str;
	cin>>str;
	int f1=0,f2=0;
	for(int i=0;i<3;i++){
		if(str[i]=='A')f1=1;
		if(str[i]=='B')f2=1;
	}
	if(f1 && f2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int t = sc.nextInt();
		String res = "TLE";
		int minCost = Integer.MAX_VALUE;
		
		for (int i = 0; i < n; i++) {
			int c = sc.nextInt();
			int T = sc.nextInt();
			
			if (T <= t) {
				if (c < minCost) {
					minCost = c;
					res = "" + c;
				}
			}
		}
		System.out.println(res);
	}

	static class FastReader { 
      BufferedReader br; 
      StringTokenizer st; 
  
      public FastReader() { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
      } 

      String next() { 
        while (st == null || !st.hasMoreElements()) { 
          try { 
            st = new StringTokenizer(br.readLine()); 
          } catch (IOException  e) { 
            e.printStackTrace(); 
          } 
       } 
       return st.nextToken(); 
      } 
  
      int nextInt() { 
        return Integer.parseInt(next()); 
      } 
 
      long nextLong() { 
        return Long.parseLong(next()); 
      } 
  
      double nextDouble() { 
        return Double.parseDouble(next()); 
      } 
  
      String nextLine() { 
        String str = ""; 
        try{ 
          str = br.readLine(); 
        } catch (IOException e) { 
          e.printStackTrace(); 
        } 
        return str; 
      } 
    } 
}


Measured memory_bytes: 22612
n, a, b, c, d = gets.split.map(&:to_i)
s = gets.chomp.chars

if s[(a - 1)..(d - 1)].each_cons(2).any? { |e| e == ['#', '#'] }
  puts :No
  exit
end

if c < d
  puts :Yes
else
  if s[(b - 2)..d].each_cons(3).any? { |e| e == ['.', '.', '.'] }
    puts :Yes
    exit
  end

  puts :No
end

Measured memory_bytes: 16764
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int main() {
    ll N, X;
    cin >> N >> X;
    vector<ll> a;

    for (int i = 0; i < N; ++i) {
        ll t;
        cin >> t;
        a.push_back(t);
    }

    sort(a.begin(),a.end());

    ll x = 0;

    int c = 0;
    for (int i = 0; i < N; ++i) {
        x += a[i];
        if(X >= x){
            c++;
        } else{
            break;
        }
    }
    if(x < X){
        c--;
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
S = input()
S_list = [int(x) for x in S]
S_list.reverse()
# print(S_list)
ans = 753
for i in range(len(S_list)-2):
  tmp_num = S_list[i+2]*100+S_list[i+1]*10+S_list[i]
  if abs(tmp_num-753)<ans:
    ans = abs(tmp_num-753)

print(ans)

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

int main(){
    int n, a, b, cnt = 0;
    cin >> n >> a >> b;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        if(a <= t and t < b);
        else cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
require "set"
x,n = gets.chomp.split(" ").map(&:to_i)
p_set = Set.new(gets.chomp.split(" ").map(&:to_i))

min = 999
result = 0
(0..101).each do |i|
  next if p_set.include?(i)
  tmp = (i - x).abs
  if tmp < min
    min = tmp
    result = i
  end
end

puts result

Measured memory_bytes: 14240
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n;
vl a, b, c;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  ll d;
  FOR(i, 0, n) cin >> d, a.pb(d);
  FOR(i, 0, n) cin >> d, b.pb(d);
  FOR(i, 0, n) cin >> d, c.pb(d);
  sort(rng(a));
  sort(rng(b));
  sort(rng(c));
  ll ans = 0;
  FOR(i, 0, n){
    ll l = -1, r = n, mid, ac, cc;
    while(r-l > 1){
      mid = (l+r)/2;
      if(a[mid] < b[i]){
        l = mid;
      }else{
        r = mid;
      }
    }
    ac = l+1;
    l = -1;
    r = n;
    while(r-l > 1){
      mid = (l+r)/2;
      if(c[mid] > b[i]){
        r = mid;
      }else{
        l = mid;
      }
    }
    cc = n-r;
    ans += ac*cc;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3316
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b,c = map(int,input().split())
    count=0

    if a % 2 ==1 and b % 2 ==1 and c % 2 ==1:
        print(count)
        exit()

    while True:
        if a == b ==c:
            print(-1)
            exit()
        elif a % 2 ==0 and b % 2==0 and c % 2 ==0:
            tmp_a=a/2
            tmp_b=b/2
            tmp_c=c/2
            a=tmp_b+tmp_c
            b=tmp_a+tmp_c
            c=tmp_b+tmp_a
            count+=1
        else:
            break
    print(count)

if __name__=="__main__":
    main()

Measured memory_bytes: 9272
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    long a, b;
    scan(a, b);
    writeln(a * b);

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  if(a * b % 2 == 0) {
    cout << "Even" << endl;
  }
  
  if(a * b % 2 == 1) {
    cout << "Odd" << endl;
  }
 }

Measured memory_bytes: 256
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))
S = set()
S.update(s)
#print(S)
#print(t)
cnt = 0
for i in t:
	if s.count(i) !=0:
		cnt = cnt +1

print(cnt)


Measured memory_bytes: 6540
N = int(input())
h = [int(x) for x in input().split()]

ans = 0
while max(h) :
    flag = False
    for i in range(N) :
        if flag == False :
            if h[i] != 0 :
                h[i] -= 1
                flag = True
        else :
            if h[i] != 0 :
                h[i] -= 1
            else :
                break
    ans += 1

print(ans)


Measured memory_bytes: 2940
#include<stdio.h>
int main()
{
	int a,b,c,k;
	while(scanf("%d%d",&a,&b)!=EOF)
	{
		k=0;
		c=a+b;
		for(;c!=0;)
		{
			c=c/10;
			k++;
		}
		printf("%d\n",k);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>

int main () {
  int N;
  std::cin >> N;
  int min = 1000000001;
  int max = -1;
  int sub = 0;
  for (int i = 0; i < N; i++) {
    std::cin >> sub;
    if (sub > max) {
      max = sub;  
    }
    if (sub < min) {
      min = sub;
    }
  }   
  std::cout << (max - min) << std::endl;
}

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

#define MAX_QUEUE (100 * 4 * 4 * 10 * 10)

typedef struct {
	int tx;
	int ty;
	int kx;
	int ky;
	int count;
} POS;


POS pos[MAX_QUEUE];
short flag[51][51][51][51];

int main(void)
{
	int X, Y;
	int tx, ty;
	int kx, ky;
	int d;
	int map[52][52];
	int tdx[4] = { 1, -1,  0,  0};
	int tdy[4] = { 0,  0,  1, -1};
	int kdx[4] = {-1,  1,  0,  0};
	int kdy[4] = { 0,  0, -1,  1};
	int i, j;
	int x, y;
	int p;
	int n;
	
	while (1){
		scanf("%d%d", &X, &Y);
		if (X == 0 && Y == 0){
			break;
		}
		
		scanf("%d%d", &tx, &ty);
		scanf("%d%d", &kx, &ky);
		
		for (y = 0; y <= Y + 1; y++){
			for (x = 0; x <= X + 1; x++){
				map[y][x] = 1;
			}
		}

		for (y = 1; y <= Y; y++){
			for (x = 1; x <= X; x++){
				scanf("%d", &map[y][x]);
			}
		}

		memset(flag, 0, sizeof(flag));
		
		n = 0;
		p = 0;
		
		pos[n].tx = tx;
		pos[n].ty = ty;
		pos[n].kx = kx;
		pos[n].ky = ky;
		pos[n].count = 0;
		
		n++;
		
		flag[ty][tx][ky][kx] = 1;

//printf("[p=%d, T=%d,%d, K=%d,%d, %d]", 
//p,
//pos[p].tx,
//pos[p].ty,
//pos[p].kx,
//pos[p].ky,
//pos[p].count);

		
		if (tx == kx && ty == ky){
            printf("0\n");
            goto end;
		}
        
		while (p != n){
			for (i = 0; i < 4; i++){
//printf("<%d>", i);
				tx = pos[p].tx;
				ty = pos[p].ty;
				kx = pos[p].kx;
				ky = pos[p].ky;

				if (map[ty + tdy[i]][tx + tdx[i]] == 0){
					tx = tx + tdx[i];
					ty = ty + tdy[i];
				}
				if (map[ky + kdy[i]][kx + kdx[i]] == 0){
					kx = kx + kdx[i];
					ky = ky + kdy[i];
				}

				if (flag[ty][tx][ky][kx] != 0){
					continue;
				}
				
				
//printf("(p=%d->%d, T=%d,%d, K=%d,%d, %d)", 
//p,n,
//tx, ty, kx, ky,
//pos[p].count + 1);

				if (tx == kx && ty == ky){
        		    printf("%d\n", pos[p].count + 1);
            		goto end;
				}
				if (pos[p].count + 1 > 102){
					printf("NA\n");
					goto end;
				}

				pos[n].tx = tx;
				pos[n].ty = ty;
				pos[n].kx = kx;
				pos[n].ky = ky;
				pos[n].count = pos[p].count + 1;

				n = (n + 1) % MAX_QUEUE;

				flag[ty][tx][ky][kx] = 1;
                        
                if (n >= MAX_QUEUE){
					return;
                }
			}
			p = (p + 1) % MAX_QUEUE;
		}
		printf("NA\n");
end:;
	}
	
	return (0);
}

Measured memory_bytes: 16964
import math


def main():
    n = int(input())
    ans = -1;
    for i in range(n + 1):
        if int(math.floor(1.08 * i)) == n:
            ans = i
            break
    if ans == -1:
        print(':(')
    else:
        print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#-*-coding:utf-8-*-

def main():
    n = int(input())
    ans = float('inf')
    for a in range(1, n):
        b = n - a
        ans = min(ans, sum(map(int, list(str(a)))) + sum(map(int, list(str(b)))))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
int h,w,k;
ll dp[110][10];

ll count(ll from,ll to){
  from--;to--;
 ll ans=0;
  for(int bid=0;bid<(1<<w-1);bid++){
    bool ok=true;
    vin br(w,0);
      rep(i,0,w-1){
       if(bid &(1<<i)){
         br[i]=1;
       }
    }
    if(from==to){
     rep(j,0,w-2){
       if(br[j]==1&&br[j+1]==1)ok=0;
     }
      if(br[from])ok=0;
      if(from-1>=0&&br[from-1])ok=0;
    }
    if(from==to-1){
      rep(j,0,w-2){
       if(br[j]==1&&br[j+1]==1)ok=0;
     }
      if(br[from]==0)ok=0;
    }
    if(from==to+1){
      rep(j,0,w-2){
       if(br[j]==1&&br[j+1]==1)ok=0;
     }
      if(br[from-1]==0)ok=false;
    }
    if(ok)ans++;
  }
  return ans;
}

int main(){cout<<fixed<<setprecision(20);
		   //dp[i][j]:=高さi　棒j からkに行くまでの通り数
           //dp[i][j]=dp[i+1][j-1]*(2^wのうち適するもの)+dp[i+1][j]*()+dp[i+1[j+1]*()
           //dp[h+1][k]=1,dp[h+1][j]=0 (j!=k)
           //i大きい順　j適当
           cin>>h>>w>>k;
           dp[h+1][k]=1;
           for(int i=h;i>=1;i--){
            rep(j,1,w+1){
              dp[i][j]+=dp[i+1][j]*count(j,j);
              if(j-1>=1)dp[i][j]+=dp[i+1][j-1]*count(j,j-1);
              if(j+1<=w)dp[i][j]+=dp[i+1][j+1]*count(j,j+1);
                dp[i][j]%=inf;
            }
           }
			cout<<dp[1][1]<<endl;
}

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

int main(){
  string s;
  std::cin >> s;
  int n = s.length(), cnt = 1, ans = 1e8;
  s.push_back('3');
  for (int i = 0; i < n; i++) {
    if(s[i] != s[i + 1]){
      ans = min(ans, max(i + 1, n - i - 1));
    }
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 512
inparray = list(map(int, input().split()))
inparray.sort(reverse=True)
a, b = inparray[0], inparray[1]

while True:
#	print(' {0} {1}'.format(a,b))
	if a % b == 0:
		print(b)
		exit(0)
	else:
		a, b = b, a % b


Measured memory_bytes: 5600
open Scanf
open Printf

let task a1 a2 a3 = 
 if a1 <= a2 && a1 <= a3 then (min a2 a3) - a1 + (max a2 a3) - (min a2 a3)
 else if a2 <= a1 && a2 <= a3 then (min a1 a3) - a2 + (max a1 a3) - (min a1 a3)
 else (min a1 a2) - a3 + (max a1 a2) - (min a1 a2)

let () = scanf "%d %d %d" task |> printf "%d\n"


Measured memory_bytes: 3816
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    long x=sc.nextLong();
    long twi=x/11;
    x-=11*twi;
    long ans=twi*2;
    if(x>6){
      ans+=2;
    }else if(x>0){
      ans++;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22608
S = input()
flag = 0
for i in range(len(S)):
	if i%2 == 0 and (S[i] not in ['R', 'U', 'D']):
		flag = 1
	if i%2 == 1 and (S[i] not in ['L', 'U', 'D']):
		flag = 1
if flag == 0:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 38256
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let nm = read_vec::<usize>();
    let n = nm[0];
    let a = read_vec::<usize>();
    let s: usize = a.iter().sum();
    if s > n {
        println!("-1");
    } else {
        println!("{}", n - s);
    }
}


Measured memory_bytes: 2248
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val N = scanner.nextLong()
    
    val even = (N + 10) / 11 * 2  // 偶数回操作するときです 11で割って切り上げをします
    val odd = (N + 4) / 11 * 2 + 1 // 奇数回操作するときです
    
    println(if(even < odd) even else odd) // 小さい方の回数を出力します
}

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

int main(){
  string s;
  cin >> s;
  int ans = 0, cnt = 0;
  for(int i=0; i<3; ++i){
    if(s[i] == 'R') ++cnt;
    else cnt = 0;
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int a, b;
  a = N;
  b = 0;
  while (a > 0) {
    b += a % 10;
    a /= 10;
  }
  if (N % b == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256