akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define forn(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) (x).size())


int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h, a;
	cin >> h >> a;
	cout << (h + a - 1) / a << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a,b,x;
signed main()
{
    scanf("%lld%lld%lld",&a,&b,&x);
    printf("%lld",!(a%x)?b/x-a/x+1:b/x-a/x);
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
main=do
 [x,n]<-map read.words<$>getLine
 lr<-replicateM n(map read.words<$>getLine)
 let a=maximum[l|[l,r]<-lr]
 let b=minimum[r|[l,r]<-lr]
 print$max(b-a+1)0

Measured memory_bytes: 88444
#include <stdio.h>
int main(void){
    int NUM,i;

    scanf( "%d" , &NUM );
    int ary[NUM];

    for( i = 0; i < NUM; i++ ){
        scanf("%d " , &ary[i] );
    }
    for( i = NUM - 1; 0 < i ; i-- ){
        printf("%d ", ary[i] );
    }
    printf("%d\n" , ary[0]);
    
}


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

int main() {
  ll N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = __gcd(A[0],A[1]);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 2; i < N; i++) {
    ans = __gcd(ans,A[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define mod 100000007
#define SIZE 500006
int vec[SIZE];

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

      int t,i,n,a,b,c=1;
      string s;
      cin>>t;
      cin>>s;
      for(i=1;i<s.size();i++)
      {
         if(s[i]!=s[i-1])
            c++;
         else
            continue;
      }
     cout<<c<<"\n";

    return 0;
}


Measured memory_bytes: 512
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF32		INT32_MAX
#define	INF64		INT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

// main function
int main()
{
	string ans = "NO";
	ll C1 = 0;
	ll C2 = 0;
	ll C3 = 0;
	ll C4 = 0;
	ll arr[10] = {0};

	cin >> C1 >> C2 >> C3 >> C4;
	arr[C1]++;
	arr[C2]++;
	arr[C3]++;
	arr[C4]++;

	if (arr[1] > 0 && arr[9] > 0 && arr[7] > 0 && arr[4] > 0) ans = "YES";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;
const int N = 6e5 + 500;
const int LN = 21;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;

long long n, m, u, v, k, t, q, a, x, d, b, c, p;


set <int> res;

int arr[N];

int main() {
   ios::sync_with_stdio(false);cin.tie(0);
   cin >> n;
   for (int i = 1; i <= n; ++i) {
      cin >> arr[i];
      res.insert(arr[i]);
   }
   
   sort(arr + 1, arr + 1 + n);
   
   if (res.size() == 1 and arr[1] == 0) {
      cout << "Yes" << endl;
      return 0;
   }
   
   if (n % 3 != 0 or res.size() > 3) {
      cout << "No" << endl;
      return 0;
   } else {
      int f = n / 3;
      if (arr[1] != arr[f] or arr[f + 1] != arr[2 * f] or arr[2 * f + 1] != arr[3 * f]) {
         cout << "No" << endl;
         return 0;
      }
      if ((arr[1] ^ arr[1 + f]) != arr[2 * f + 1]) {
         cout << "No" << endl;
         return 0;
      }
   }
   
   cout << "Yes" << endl;
}







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

int main() {
	int x, y, z;
	cin >> x >> y;
	if (x == 1)x = 14;
	if (y == 1)y = 14;
	if (x == y)cout << "Draw" << endl;
	else if (x>y)cout << "Alice" << endl;
	else cout << "Bob" << endl;
	
	return 0;
}

Measured memory_bytes: 256
N,M,S = map(int,input().split())
edges = [[] for _ in range(2500*50 + 100)]
def indexer(city,coin):
    return 50*coin + city

for _ in range(M):
    u,v,a,b = map(int,input().split())
    u -= 1
    v -= 1
    for scoin in range(a,2501):
        edges[indexer(u,scoin)].append((b,indexer(v,scoin-a)))
        edges[indexer(v,scoin)].append((b,indexer(u,scoin-a)))
## 両替
for i in range(N):
    c,d = map(int,input().split())
    for scoin in range(c,2501):
        edges[indexer(i,scoin-c)].append((d,indexer(i,scoin)))


def dijkstra(s,n,edges):
    import heapq
    dist = [float('inf')] * n
    fixed = [False]*n
    dist[s] = 0
    fixed[s] = True
    priority_que = []
    for e in edges[s]:
        heapq.heappush(priority_que,e)

    while len(priority_que):
        edge = heapq.heappop(priority_que)
        if fixed[edge[1]]:
            continue
        v = edge[1]
        dist[v] = edge[0]
        fixed[v] = True
        for ne in edges[v]:
            heapq.heappush(priority_que,(ne[0]+dist[v], ne[1]))
    return dist

d=dijkstra(indexer(0,min(2500,S)),2500*50 + 100,edges)
for i in range(1,N):
    ans = float('inf')
    for j in range(2501):
        ans = min(ans,d[indexer(i,j)])
    print(ans)

Measured memory_bytes: 145548
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a<=5)
    {
        cout<<"0"<<endl;
    }
    else if(a<=12)
    {
        cout<<b/2<<endl;
    }
    else
        cout<<b<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
using namespace std;
const int INF = 1e9;
int main(){
  string S;
  cin >> S;
  map<char, int> mp;
  for(int i = 'a'; i <= 'z'; i++){
    mp[i] = 0;
  }
  for(int i = 0; i <= S.size(); i++){
    mp[S[i]]++;
  }
  for(int i = 'a'; i <= 'z';i++){
    if(mp[i] % 2 == 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

int winner(int a, int b)
{
  if (a == 1 && b == 2) return (1);
  if (a == 2 && b == 3) return (2);
  if (a == 1 && b == 3) return (3);
}

signed main()
{
  ios::sync_with_stdio(false);
  int input[5];
  
  while (cin >> input[0], input[0]){
    bool check[4] = {false};
    check[input[0]] = true;
    REPS(i, 1, 5){
      cin >> input[i];
      check[input[i]] = true;
    }

    int out[2], j = 0;
    int only = 0;
    REPS(i, 1, 4){
      if (!check[i]){
        only++;
      }
      else {
        out[j++] = i;
      }
    }

    if ((check[1] && check[2] && check[3]) || only == 2){
      REP(i, 5){
        print("3");
      }
    }
    else {
      int win = winner(out[0], out[1]);
      REP(i, 5){
        if (input[i] == win){
          print("1");
        }
        else {
          print("2");
        }
      }
    }
  }

  return (0);
}

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

using namespace std;
int mod = 1e9+7;
int fac[200005];
int ifac[200005];

int power(int x,int y)
{
    if(y==0)
        return 1;
    int tmp = power(x,y/2);
    if(y&1)
        return ((tmp*tmp)%mod * x)%mod;
    else
        return (tmp*tmp)%mod;
}

int C(int k,int n)
{
    int ans = fac[n];
    ans *= ifac[k];
    ans %= mod;
    ans *= ifac[n-k];
    ans %= mod;

    return ans;
}

signed main()
{
    int h,w,a,b;
    cin>>h>>w>>a>>b;

    fac[0] = 1;
    for(int i=1;i<=200000;i++)
        fac[i] = (fac[i-1] * i) % mod;

    //cout<<fac[7];

    ifac[200000] = power(fac[200000],mod-2);
    for(int i = 200000 - 1;i>=0;i--)
        ifac[i] = (ifac[i+1] * (i+1)) % mod;


    int ans = 0;
    for(int i=b+1;i<=w;i++)
    {
        ans += (C(i-1,i+h-a-2) * C(a-1,w+a-i-1))%mod;
        ans %= mod;
    }

    cout<<ans;

}


Measured memory_bytes: 3328
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { N: number[] } => {
  const N = lines[1].split(' ').map(line => +line)
  const obj = { N }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { N } = parseLines(lines)
  const origin = []
  for (let i = 1; i <= N.length; i++) {
    origin.push(i)
  }

  let diffCount = 0
  for (let i = 0; i < origin.length; i++) {
    if (origin[i] !== N[i]) {
      diffCount++
    }
  }

  if (diffCount === 2 || diffCount === 0) {
    return 'YES'
  } else {
    return 'NO'
  }
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 11596
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ll ret = 0;
  for (ll i=1; i<=N; i++) {
    if (i % 3 != 0 && i % 5 != 0) ret += i;
  }
  cout << ret << endl;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

int MOD = 998244353;
ll ans[100010] = {0};
vector<ll> G[100010];
ll cnt[100010] = {0};
signed main(){
    ll n,m;
    cin >> n >> m;

    queue<ll> q;

    rep(i,m){
        ll x,y;
        cin >> x >> y;
        G[x-1].pb(y-1);
        cnt[y-1]++;
    }

    rep(i,n){
        if(cnt[i] == 0){
            q.push(i);
            ans[i] = 1;
        }
    }

    while(q.size()){
        ll i = q.front();
        q.pop();
        for(auto x:G[i]){
            ans[x] = max(ans[x],ans[i]+1);
            cnt[x]--;
            if(cnt[x] == 0)q.push(x);
        }
    }

    ll res = 0;
    rep(i,n)res = max(res,ans[i]);
    cout << res-1 << endl;
    
      
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://dp.contest.atcoder.jp/tasks/dp_f

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int x;
    cin >> x;
    int n = 0;
    for (int i = 0; i <= x; i++) {
        if(i * (i + 1) / 2 >= x) {
            n = i;
            break;
        }
    }
    cout << n << "\n";
}

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

using namespace std;
using ll = long long;

int main(){
    ll n,l,r;
    while(cin>>n>>l>>r and n>0 and l>0 and r>0){
        ll ans=0;
        vector<ll> A(n);
        for(auto &&e:A)
            cin>>e;
        for(ll x=l; x<=r; ++x){
            ll i;
            for(i=0; i<n; ++i){
                if(x%A[i]==0){
                    if((i+1)%2==1){
                        ++ans;
                    }
                    break;
                }
            }
            if(i==n){
                if(n%2==0){
                    ++ans;
                }
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fs first
#define sc second
#define mk make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int INF = 1e9+1;
const ll LINF = 1e17;
const int MAKS = 300100;
int n, a[MAKS], ans[MAKS];
int maks;
int main(){
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for (int i = n-1; i > 0; i--){
		if (a[i+1]<=a[i]) ans[i] = ans[i+1]+1;
		maks = max(maks, ans[i]);
	}
	cout << maks;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
    int r, c;
    cin >> r >> c;
    int rc[101][101];

    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++)
            rc[i][j] = 0;
    }

    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> rc[i][j];
            rc[i][c] += rc[i][j];
            rc[r][j] += rc[i][j];
            rc[r][c] += rc[i][j];
        }
    }

    for(int i = 0; i <= r; i++){
        for(int j = 0; j < c; j++){
            cout << rc[i][j] << " ";
        }
        cout << rc[i][c] << endl;
    }

    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int a,b;
	cin >> a >> b;
	println(max(max(a+b,a-b),a*b));
	return 0;
}


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

int main(){

    int n,d; cin>>n>>d;

    vector<vector<int>> p(n,vector<int>(d));

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

    int count =0;

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

            int dis =0;

            for(int k=0; k<d; k++){

                int far = abs(p[i][k] - p[j][k]);

                dis += far * far;
            }

            bool check = false;

            for(int k=0; k<=dis; k++){

            if(k*k == dis) check = true;
            }

            if(check) count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#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() {
	int n, k;
	cin >> n >> k;
	vector<int> x(n);
	rep(i, n) cin >> x[i];

	int ans = 1001001001;
	for (int i = 0; i <= n - k; i++) {
		int l = x[i];
		int r = x[i + k - 1];
		if (r <= 0) {
			ans = min(ans, -l);
		}
		else if (l <= 0) {
			ans = min({ ans,r - 2 * l,2 * r - l });
		}
		else {
			ans = min(ans, r);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l  
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |   
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) reverse((a).begin(),(a).end())

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

     // エラトステネスのふるい
    int MAX = 1000000;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }

    vector<int>is_2017(MAX,0);
    for(int i=0;i<MAX;i++){
        if(is_prime[(i+1)/2] && is_prime[i]) is_2017[i]=1;
    }

    //累積和
    vector<int>ans(MAX+1,0);
    for(int i=1;i<MAX;i++){
        ans[i+1]=ans[i];
        if(is_2017[i]) ans[i+1]++;
    }

    for(int i=0;i<n;i++) cout<<ans[r[i]+1]-ans[l[i]]<<endl;

}







Measured memory_bytes: 13184
#include<iostream>
#include<algorithm>
using namespace std;
int p[200000];

int main() {


	//A
	string s, t;
	int a, b;
	string u;
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	if (s == u) {
		a--;
	}
	else {
		b--;
	}
	cout << a << ' '<< b << endl;
	return 0;

	//B
	/*string s;
	cin >> s;
	int i;
	for (i = 0; i < s.size(); i++) {
		s[i] = 'x';
	}
	cout << s << endl;
	return 0;*/

	//C
	/*int n;
	cin >> n;
	int i;
	for (i = 0; i < n; i++) {
		cin >> p[i];
	}
	sort(p, p + n);
	for (i = 0; i < n-1; i++) {
		if (p[i] == p[i + 1]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;*/
	//D
	/*int n, k;
	cin >> n >> k;
	int i;
	for (i = 0; i < n; i++) {
		cin >> p[i];
	}
	int max = 0;
	int sum = 0;
	for (i = 0; i < k; i++) {
		sum = sum + p[i];
	}
	max = sum;
	for (i = k; i < n; i++) {
		sum = sum + p[i] - p[i - k];
		if (sum > max)max = sum;
	}
	//cout << max + k << endl;
	double f = (double)(((double)max +(double) k) / 2);
	printf("%.10f\n", f);
	//cout << (max + k) / 2 << endl;
	return 0;
	*/
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Point {
  int x, y;
  Point(int x, int y) : x(x), y(y) {;}
};

vector<Point> points[10];
inline int dist(int x1, int y1, int x2, int y2) {
  return abs(x1 - x2) + abs(y1 - y2);
}

int gx, gy;
int memo[1010][1010][5];
int calc(int used, int prev, int x, int y) {
  if (used == 31) { return dist(x, y, gx, gy); }
  if (memo[x][y][prev] != -1) { return memo[x][y][prev]; }
  int ret = 1 << 25;
  int next = (prev + 1) % 5;
  FORIT(it, points[next]) {
    ret = min(ret,
        calc(used | (1 << next), next, it->x, it->y) + dist(it->x, it->y, x, y));
  }
  return memo[x][y][prev] = ret;
}

int h, w;
char field[1010][1010];
int main() {
  while (scanf("%d %d", &w, &h), w|h) {
    REP(i, 10) { points[i].clear(); }
    int sx, sy;
    REP(y, h) {
      scanf("%s", field[y]);
      REP(x, w) {
        if (field[y][x] == 'S') {
          sx = x; sy = y;
        } else if (field[y][x] == 'G') {
          gx = x; gy = y;
        } else if (isdigit(field[y][x])) {
          points[field[y][x] - '1'].push_back(Point(x, y));
        }
      }
    }
    int ans = 1 << 20;
    int type = -1;
    REP(i, 5) {
      memset(memo, -1, sizeof(int) * 5 * 1010 * w);
      int lans = calc(1 << i, i, sx, sy);
      if (lans < ans) {
        ans = lans;
        type = i + 1;
      }
    }
    if (type == -1) {
      puts("NA");
    } else {
      printf("%d %d\n", type, ans);
    }
  }
}

Measured memory_bytes: 21000
#include<bits/stdc++.h>
#define INF (1e9)
using namespace std;
 
int main(){
  double ans;
  int d,e;
  while(1){
    cin>>d>>e;
    if(!d&&!e)break;
    ans=INF;
    for(int i=0;i<=d;i++)
      for(int j=i;j<=d;j++)
    if(i+j==d)ans=min(ans,abs(sqrt(i*i+j*j)-e));
    printf("%.8f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define ll long long
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
signed main(){
	ll n,k;
	cin>>n>>k;
	if(n%k==0)puts("0");
	else puts("1");
	return 0;
}


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

ll dp[202][100010];

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

    ll n,x;
    cin>>n>>x;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll mod = 1e9+7;
    dp[0][x]=1;
    sort(a,a+n,greater<ll>());

    for(int i=0;i<n;i++){
        for(int j=0;j<=x;j++){
            dp[i+1][j%a[i]] += dp[i][j];
            dp[i+1][j%a[i]] %= mod;
            dp[i + 1][j] += dp[i][j] * (n - i - 1); dp[i + 1][j] %= mod;
        }
    }
    ll ans = 0;
    for(ll i=0;i<=x;i++){
        ans += i*dp[n][i];
        ans %= mod;
        //cerr<<i<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 157184
// #include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <iomanip>  
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#define debug(x) cout << '>' << #x << ':' << x << endl;
 
#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
const int mod = 1e9+7;
using namespace std;
using ll = long long int;
const ll invmod = 998244353; 
const int N = 5*(int)(1e5) + 1;
const int MAXN = 1e5+10;


int main()
{
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);freopen("out.txt", "w", stdout);
	#endif 	*/
	int n;
	cin >> n;
	int arr[n];
	int ans = 0;
	for(int i = 0; i < n; i++)  cin >> arr[i], ans ^= arr[i];

	// cout << ans << '\n';
	
	for(int i = 0; i < n; i++)
	{
		int temp = ans ^ arr[i];
		cout << temp << ' ';
	}
			
}



Measured memory_bytes: 4392
while gets
  n, m = $_.split.map(&:to_i)
  dp = 3.times.map{ [-1] * (m + 1) }
  3.times{ |i| dp[i][0] = 0 }
  n.times do
    gets
    l = gets.split.map(&:to_i)
    3.times do |i|
      (m - l[0] + 1).times do |j|
        if dp[i][j] != -1
          dp[i][j + l[0]] = [dp[i][j + l[0]], dp[i][j] + l[i + 1]].max
        end
      end
    end
  end
  p dp.flatten.max
end

Measured memory_bytes: 9380
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int a,b;
long long k,la,lb;
int main()
{
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%d%d",&a,&b);
	if(a<la||b<lb){
	  k=(long long)(la/a+(la%a?1:0));
	  k=max(k,(long long)(lb/b+(lb%b?1:0)));
	  la=(long long)a*k;
	  lb=(long long)b*k;
	}
	else{
	  la=a;
	  lb=b;
	}
  }
  printf("%lld",la+lb);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;


int main()
{
  int a, b, d, g; //かっている数//最大100
  string s, t;
    string S;
    cin >> S;


    int N = S.size();

    ll dp[100010][4] = {};

    for(int i = N; i >= 0; --i){//文字の後ろからみていく
        for(int j = 3; j >= 0; --j){//3から0まで:  Sのうち i-1番目まで?を置換していて、そのうちABCからjこ選択しているときの個数
            if(i == N){//最後尾のとき
                dp[i][j] = (j == 3 ? 1 : 0);//jが3なら1ほかなら0//初期値
            }else{//iが末尾じゃないとき
                dp[i][j] = dp[i+1][j] * (S[i] == '?' ? 3 : 1);//iの文字が?なら3通り追加する.

                if(j < 3 && (S[i] == '?' || S[i] == "ABC"[j])){//ABCのうち確定しているのが2文字以下のときで、S[i]が?か対応するABCのとき,
                    dp[i][j] += dp[i+1][j+1];//まるをつけた場合の値を追加ex Bならdp[i][1]はdp[i+1][2]を追加する
                }

                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[0][0] << endl;
}



Measured memory_bytes: 3584
n = int(input())
h = list(map(int, input().split()))

max_moves = 0
for i in range(n):
    if i == 0:
        moves = 0
    elif h[i - 1] < h[i]:
        moves = 0
    else:
        moves += 1
    max_moves = max(max_moves, moves)
print(max_moves)


Measured memory_bytes: 20612
#include <stdio.h>


int main(){

	int w, h, x, y, r;

	scanf( "%d %d %d %d %d", 
		&w, &h, &x, &y, &r );

	if( x-r >= 0 && y-r >= 0 &&
		x+r <= w && y+r <= h ){
		
		printf( "Yes\n" );
	}else{
		printf( "No\n" );
	}



	return 0;

}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<vector<int>> arr(3, vector<int> (3));
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++) 
            cin >> arr[i][j];
    int a = arr[0][0] - arr[0][1], b = arr[0][1] - arr[0][2];
    for(int i = 1; i < 3; i++) {
        if(arr[i][0] - arr[i][1] != a || arr[i][1] - arr[i][2] != b) {
            cout << "No";
            return 0;
        }
    }
    a = arr[0][0] - arr[1][0], b = arr[1][0] - arr[2][0];
    for(int i = 1; i < 3; i++) {
        if(arr[0][i] - arr[1][i] != a || arr[1][i] - arr[2][i] != b) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 3600
#include <algorithm>
#include <iostream>
#include<string>

int main( ){
  int n;
  std::cin >> n;
  std::string s;
  std::cin >> s;
  std::string t;
  std::cin >> t;
  std::string res;
  for(int i = 0; i < n; i ++){
      res.push_back(s.at(i));
      res.push_back(t.at(i)); 
  }
  std::cout << res;
}

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

int main(){
	int n, k;
	double ans = 0;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i){
		if (i < k) ans+=1.0/n*pow(0.5, ceil(log((double)k / i) / log(2)));
		else ans+=1.0/n;
	}
	printf("%.12lf\n", ans);
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
         int x;

	     for(int count = 1; ;count++){
	    	 x  = scan.nextInt();
	    	 if(x == 0)break;

	    	 System.out.println("Case " + count + ": " + x);

	     }
	}

}

Measured memory_bytes: 42704
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long i64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 6, C = 5e1+5, S = 1<<6;
int n, c, L[N], res; i64 ans, f[N*C][S];
int main()
{
    n = read(), c = read();
    for(int i = 0; i < n; ++i) L[i] = read();
    sort(L, L+n);
    do
    {
        memset(f, 0, sizeof(f)), f[L[n-1]*n][0] = 1;
        for(int i = 0; i <= n*c; ++i)
            for(int j = i; j <= n*c; ++j)
                for(int s = 0; s < 1<<(n-1); ++s)
                    if(i%n&&(~s>>(i%n-1)&1))
                        f[min(n*c, max(j, i+L[i%n-1]*n))][s|(1<<(i%n-1))] += f[j][s];
        ans += f[n*c][(1<<(n-1))-1], ++res;
    }while(next_permutation(L, L+n-1));
    printf("%.15lf\n", ans/pow(c, n-1)/res);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;

const int N = 100100;
int n, k;
char s[N];

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

	scanf(" %s %d", s, &k);
	n = strlen(s);
	for (int i = 0; i < n - 1; i++)
	{
		int x = (int)(s[i] - 'a');
		if (x == 0) continue;
		if (26 - x <= k)
		{
			k -= 26 - x;
			s[i] = 'a';
		}
	}
	int x = (int)(s[n - 1] - 'a');
	x += k;
	x %= 26;
	s[n - 1] = (char)('a' + x);
	printf("%s\n", s);

	return 0;
}

Measured memory_bytes: 384
# time complexity: O(HW)
# space complexity: O(HW)

from collections import deque


H, W = [int(elem) for elem in input().split(' ')]
s_list = [tuple(input()) for _ in range(H)]
assert len(s_list) == H
assert len(s_list[0]) == W


def calc_num_white(s_list):
    num_white = sum([sum([1 if elem == "." else 0 for elem in row]) for row in s_list])
    return num_white


# BFS
visited = [[False] * W for _ in range(H)]
queue = deque([[[0, 0], [[0, 0]]]])
visited[0][0] = True
direction = ((-1, 0), (1, 0), (0, -1), (0, 1))
while queue:
    position, path = queue.popleft()
    y, x = position
    for dy, dx in direction:
        next_position = [y+dy, x+dx]
        if next_position[0] < 0 or next_position[0] >= H or next_position[1] < 0 or next_position[1] >= W:
            continue
        elif s_list[next_position[0]][next_position[1]] == "#":
            continue
        elif visited[next_position[0]][next_position[1]] == True:
            continue
        elif next_position == [H-1, W-1]:
            len_min_path = len(path) + 1
            num_white = calc_num_white(s_list)
            score = num_white - len_min_path
            print(score)
            exit(0)
        else:
            visited[next_position[0]][next_position[1]] = True
            queue.append([next_position, path+[next_position]])
print(-1)


Measured memory_bytes: 3572
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
  int N;
  cin >> N;
  int a = N % 10;
  if (a == 3) {
    cout << "bon" << endl;
  } else if (a == 0 || a == 1 || a == 6 || a == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;

P baby[2000] = {};
ll dp[2001][2001] = {};

int main(){
    ll n, i, j;
    cin >> n;
    for(i=0; i<n; i++){
        baby[i].second = i+1;
        cin >> baby[i].first;
    }
    sort(baby, baby+n, greater<P>());
    for(i=0; i<=n; i++){
        for(j=0; j<=n; j++){
            if(i == 0 && j == 0){
                dp[i][j] = 0;
            }else if(i == 0){
                dp[i][j] = dp[i][j-1]+baby[i+j-1].first*abs(baby[i+j-1].second-(j-1)-1);
            }else if(j == 0){
                dp[i][j] = dp[i-1][j]+baby[i+j-1].first*abs(n-baby[i+j-1].second-(i-1));
            }else if(i+j>n){
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            }else{
                dp[i][j] = max(dp[i-1][j]+baby[i+j-1].first*abs(n-baby[i+j-1].second-(i-1)), dp[i][j-1]+baby[i+j-1].first*abs(baby[i+j-1].second-(j-1)-1));
            }
        }
    }
    cout << dp[n][n];
    return 0;
}

Measured memory_bytes: 34908
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef struct _data {
	int N;
	int P;
} data;

int  main()
{
	int n;
	cin >> n;
	struct _data s[n];
	rep(i, n)
	{
		s[i].N = i+1;
		cin >> s[i].P;
	}
	int min = n+1;
	int cnt = 0;
	rep(i, n)
	{
		if (s[i].P < min)
		{
			min = s[i].P;
			cnt++;
		}
	}
	cout << cnt << endl;
	return (0);
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    A, B, C = map(int, input().split())
    K = int(input())

    answer = "No"
    for i in range(K):
        if A>=B:
            B *= 2
        elif B>=C:
            C *= 2
    if A<B and B<C:
        answer = "Yes"
    print(answer)

if __name__ == "__main__":
    main()



Measured memory_bytes: 9180
import java.util.*;

public class Main {
	public static void main(String[] args) {
		 
               Scanner sc = new Scanner(System.in);
                
               int H = sc.nextInt();
               int W = sc.nextInt();
                             
               char a[][] = new char[H+2][W+2];
               
               for(int w = 0;w <= W + 1;w++){
                   a[0][w]   = '#';
               }
               
               for(int w = 0;w <= W + 1;w++){
                   a[H+1][w] = '#';
               }
               
               for(int h = 0;h <= H + 1;h++){
                   a[h][0]   = '#';
               }
               
               for(int h = 0;h <= H + 1;h++){
                   a[h][W+1] = '#';
               }
               
               for(int h = 1; h < H+1;h++){
                   String str = sc.next();
                   for(int w = 1; w < W+1;w++){
                          a[h][w] = str.charAt(w-1);                                                                             
                   }
               }       
               
               for(int h = 0 ;h <= H+1;h++){
                   for(int w = 0; w <= W + 1;w++){
                       System.out.print(a[h][w]);                       
                   }                   
                   System.out.println();
               }

               
        }
}


Measured memory_bytes: 24788
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
using namespace std;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    srand (time(NULL));
    int n, k, s;
    cin >> n >> k >> s;
    int a[100100] ={};
    // if (s / k < 1) {
    //     for (int i = 0; i < k; i++)
    //     {
    //         a[i] = s;
    //     }
    //     for (int i = k; i < n; i++)
    //     {
    //         a[i] = rnd % (1e9+1);
    //     }
        
    // } else {
    //     int len = s % 
    //     for (int i = 0; i < k; i++)
    //     {
    //         a[i] = s/;
    //     }
    //     for (int i = k; i < n; i++)
    //     {
    //         a[i] = rnd % (1e9+1);
    //     }
    // }
        for (int i = 0; i < k; i++)
        {
            a[i] = s;
        }
        for (int i = k; i < n; i++)
        {
            a[i] = rand() % (int)(1e9+1);
        }
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << "\n";
    

}

Measured memory_bytes: 1664
#include <vector>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define R register
#define MN 100005
typedef long long ll;
inline int read(){
	R int x; R bool f; R char c;
	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');
	for (x=c^'0'; (c=getchar())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0'));
	return f?-x:x;
}
int n,m,f[MN],vl[MN],tp[MN],tcnt,a[MN],an;ll ans;
std::vector<int> val[MN];
inline int gf(int x){return f[x]?f[x]=gf(f[x]):x;}
int main(){
	n=read(),m=read();
	for (R int i=1; i<=n; ++i) vl[i]=read();
	for (R int i=1,x,y; i<=m; ++i){
		x=read()+1,y=read()+1;
		f[gf(x)]=gf(y);
	}
	for (R int i=1; i<=n; ++i) if (!f[i]) tp[i]=++tcnt;
	if (tcnt==1) return 0*puts("0");
	if ((tcnt-1)*2>n) return 0*puts("Impossible");
	for (R int i=1; i<=n; ++i) val[tp[gf(i)]].push_back(vl[i]);
	for (R int i=1; i<=tcnt; ++i){
		std::sort(val[i].begin(),val[i].end());
		ans+=val[i][0];
		for (R int j=1; j<val[i].size(); ++j)
			a[++an]=val[i][j];
	}
	std::sort(a+1,a+an+1);
	for (R int i=1; i<=tcnt-2; ++i) ans+=a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5632
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<stack>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

int main(){
	while(true){
		stack<double> s;
		char In[81];
		double num=0;
		bool is_pos=true;
		int r;
		for(int i=0;r=scanf("%c",&In[i]);i++){
			if(In[i]=='\n') break;
			if(r==EOF) return 0;
		}
		for(int i=0;In[i]!='\n';i++){
			if(In[i]==' ') continue;
			if('0'<=In[i] && In[i]<='9'){
				num = num*10+(In[i]-'0');
				if(In[i+1]<'0' || '9'<In[i+1]){
					if(is_pos==false) num *= -1;
					s.push(num);
					num = 0; is_pos = true;
				}
			}
			else{
				if(In[i]=='-' && '0'<=In[i+1] && In[i+1]<='9'){
					is_pos = false;
				}
				else{
					double a,b;
					b = s.top(); s.pop();
					a = s.top(); s.pop();
					if(In[i]=='+') s.push(a+b);
					else if(In[i]=='-') s.push(a-b);
					else if(In[i]=='*') s.push(a*b);
					else s.push(a/b);
				}
			}
		}
		printf("%lf\n",s.top());
	}
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

const int INF = 1e9;

int n,t;
int a[100010];

int solve(){
    int mi = INF;
    int opt = 0;
    rep(i,n){
        mi = min(mi, a[i]);
        opt = max(opt, a[i] - mi);
    }


    int cnt = 0;
    mi = INF;
    rep(i,n){
        mi = min(mi, a[i]);
        if(a[i] - mi == opt){
            ++cnt;
        }
    }

    return cnt;
}


int main(){
    while(cin >> n >> t){
        rep(i,n) cin >> a[i];
        cout << solve() << endl;
    }
}


Measured memory_bytes: 640
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

int fun(int&x, int y) {

}
signed main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    //int t = 1; cin >> t; while(t--)
    {
    	int h, w;
    	cin >> h >> w;
    	string s[h];
    	for(int i = 0; i < h; i++)
    		cin >> s[i];

    	int dp[h][w];
    	for(int i = 0; i < h; i++) {
    		for(int j = 0; j < w; j++)
    			dp[i][j] = LLONG_MAX;
    	}

    	dp[0][0] = (s[0][0] == '#');
    	for(int i = 0; i < h; i++) {
    		for(int j = 0; j < w; j++) {
    			if(!i && !j)
    				continue;
    			if(i)
    				dp[i][j] = min(dp[i][j], dp[i - 1][j] + (s[i][j] == '#' && s[i - 1][j] == '.'));
    			if(j)
    				dp[i][j] = min(dp[i][j], dp[i][j - 1] + (s[i][j] == '#' && s[i][j - 1] == '.'));
    		}
    	}

    	cout << dp[h - 1][w - 1] << '\n';
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in);) {
            String s = scanner.next();
            int counter = 0;
            int result = 0;

            for (int i = 0; i < 3; i++) {
                char next = s.charAt(i);
                if (next == 'R') {
                    counter++;
                } else {
                    counter = 0;
                }
                result = Math.max(result, counter);
            }
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 35556
while(True):
	h, w = map(int, input().split())
	if (h+w) == 0:break
	e = list(list(int(i) for i in input().split()) for i in range(h))
	e_T = list(zip(*e))
	ans = 0
	for i in range(h-2):
		for j in range(w-2):
			for k in range(i+2,h):
				for l in range(j+2,w):
					flag = False
					count = 0
					wall = min(min(e[i][j:l+1]), min(e[k][j:l+1]), min(e_T[j][i:k+1]), min(e_T[l][i:k+1]))
					#print(wall)
					for m in range(i+1,k):
						for n in range(j+1,l):
							if wall > e[m][n]:
								count += wall - e[m][n]
							else:
								flag = True
								break
						if flag:break
					
					if ans < count and not flag:
						ans = count				
	print(ans)



Measured memory_bytes: 5624
#include <iostream>
#include <algorithm>
using namespace std;
int S[101][101];

int main(){
  int n;
  cin >> n;
  fill(S[0],S[101],0);
  for(int i = 1 ; i <= n ; i++ ){
    for(int j = 1 ; j <= n ; j++ ){
      int x;
      cin >> x;
      S[i][j] = S[i-1][j] + S[i][j-1] - S[i-1][j-1] + x;
    }
  }

  int mx = -99999999;
  for(int i = 1 ; i <= n ; i++ ){
    for(int j = 1 ; j <= n ; j++ ){
      for(int y = 1 ; y <= i ; y++ ){
	for(int x = 1 ; x <= j ; x++ ){
	  mx = max(mx,S[i][j] - S[y-1][j] - S[i][x-1] + S[y-1][x-1]);
	}
      }
    }
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define Y first
#define X second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

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

int main(){
  int n, m, i, j, d, res;
  while(scanf("%d%d", &n, &m) && n+m){
    char cas[128][128];
    int cnt[128][128];
    rep(i, m) rep(j, n) cnt[i][j] = INF;
    rep(i, m) scanf("%s", cas[i]);

    int x, y;
    rep(i, m) rep(j, n) if(cas[i][j] == '&'){ y = i; x = j;}
    cnt[y][x] = 0;
    cas[y][x] = '.';
    queue<pi>q;
    q.push(make_pair(y, x));
    while(!q.empty()){
      int qsize = (int)q.size();
      rep(i, qsize){
	pi now = q.front(); q.pop();
	//	printf("%d %d\n", now.Y, now.X);
	rep(d, 4){
	  int ny = now.Y + dy[d], nx = now.X + dx[d];
	  if(ny < 0 || nx < 0 || ny >= m || nx >= n) continue;
	  int cost = cnt[now.Y][now.X] + ((cas[ny][nx] == '#' && cas[now.Y][now.X] != '#') ? 1 : 0);
	  if(cnt[ny][nx] <= cost) continue;
	  cnt[ny][nx] = cost;
	  q.push(make_pair(ny, nx));
	}
      }
    }

    /*    rep(i, m){
      rep(j, n) printf("%d ", cnt[i][j]); puts("");
      }*/

    res = INF;
    rep(i, m){
      res = min(res, cnt[i][0]);
      res = min(res, cnt[i][n-1]);
    }
    rep(i, n){
      res = min(res, cnt[0][i]);
      res = min(res, cnt[m-1][i]);
    }
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1288
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main() {

	int n;	// さいころ数
	int k;	// 隣接するさいころの数

	int i;
	scanf("%d %d", &n, &k);

	double ex_value[n];

	int p[n];
	double cum_sum[n - k + 1];
	double tmp = 0;
	double index = 0;

	for(i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}

	for(i = 0; i < n; i++) {
		ex_value[i] = (double)(1 + p[i]) / 2;
	}

	// 累積和
	for(i = 0; i < n; i++) {
		cum_sum[i] += ex_value[i];
		tmp += ex_value[i];
		if(i >= k) {
			tmp -= ex_value[i-k];
		}
		if(index < tmp) {
			index = tmp;
		}
	}

	printf("%.12f", index);

	return 0;


}


Measured memory_bytes: 4096
#include <iostream>
#include <stack>

int main(){

	std::stack<int> train;

	int buf;

	while(std::cin >> buf){

		if(buf == 0){

			std::cout << train.top() << std::endl;
			train.pop();

		}else{

			train.push(buf);

		}
	
	}

	return 0;
}	

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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 2e3 + 10;
const int inf = 0x3f3f3f3f;


int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);
  int n; cin >> n;
  vector<int> a(n + 1, 0);
  vector<long long> cnt(n + 1, 0);
  for (int i = 1; i <= n; ++i){
    cin >> a[i];
    cnt[a[i]]++;
  }
  ll sum = 0;
  for (int i = 1; i <= n; ++i){
    if (cnt[i] < 1) continue;
    sum = sum + (1ll * cnt[i] * (cnt[i] - 1) / 2);
  }
  for (int i = 1; i <= n; ++i){
    cout << sum - max(0ll, cnt[a[i]] - 1) << '\n';
  }
return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int n,k,d[123],a[123][123],s[123],ans;
int main(){
    cin>>n>>k;
    for(int i=0;i<k;i++){
        cin>>d[i];
        for(int j=0;j<d[i];j++){
            cin>>a[i][j];
            s[a[i][j]]++;
        }
    }
    for(int i=1;i<=n;i++){
        if(s[i]>0)ans++;
    }
    cout<<n-ans<<endl;
}


Measured memory_bytes: 3680
def DFS(now, visited):

    if len(visited) == n:
        ans.append(1)
        return

    for i in graph[now]:
        if not i in visited:
            DFS(i, visited + [i])


n, m = map(int, input().split())
graph = [[] for i in range(n)]
ans = []

for i in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

DFS(0,[0])

print(len(ans))


Measured memory_bytes: 3064