akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) for(int i = a, i <= b; i++)
#define REPD(i, a, b) for(int i = a, i >= b; i--)
#define SQ(a) (a) * (a)
#define all(c) c.begin(), c.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); ++it)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define sz(a) int((a).size())
#define endl "\n"
#define PI 3.1415926535
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(t) int x; cin >> t; while(t--)
using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef map<int, int> mii;
typedef map<string, int> mis;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void fio()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int32_t main()
{
	fio();
	int n;
	cin >> n;
	if (n % 1000 == 0)
		cout << "0\n";
	else
		cout << 1000 - n % 1000 << endl;
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
map<string,int>sad;
int main()
{
    _SAD()
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)<abs(x-b))
    {
        cout<<"A"<<NL;
    }
    else
    {
        cout<<"B"<<NL;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))
count = 0

for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i] and L[i]+L[j]>L[k] and L[k]+L[j]>L[i] and L[i]+L[k]>L[j]:
        count += 1
        
print(count)

Measured memory_bytes: 9208
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let h = read::<usize>();
    let w = read::<usize>();
    let n = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<usize>();
    }
    let mut ans = vec![vec![0; w]; h];
    let mut y = 0i32;
    let mut x = 0i32;
    let mut dx = 1i32;
    for c in 0..n {
        for _ in 0..seq[c] {
            ans[y as usize][x as usize] = c;
            let mut nx = x + dx;
            let mut ny = y;
            if nx < 0 || nx >= w as i32 {
                nx = x;
                dx *= -1;
                ny = y + 1;
            }
            x = nx;
            y = ny;
        }
    }
    for y in 0..h {
        for x in 0..w {
            if x != 0 {
                print!(" ");
            }
            print!("{}", ans[y][x] + 1);
        }
        println!("");
    }
}


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

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define _shv(v) for (auto _t1 : v) cerr << _t1 << " "; cerr << endl;
#define dbg(x) cerr << #x << ": " << (x) << endl;
#define dbgv(v) cerr << #v << ": "; _shv(v);
#define dbgm(m) cerr << #m << ":" << endl; for (auto _t2 : m) { _shv(_t2); }

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

template<typename T> inline int siz(T& x) { return x.size(); }
template<typename T> inline ll pow2(T n) { return 1ll << n; }
template<typename T, typename U> inline int bit(T x, U n) { return x >> n & 1; }
template<typename T> inline void prt(T x) { cout << x << endl; }
template<typename T, typename U>
inline void getv(T& v, U n) { v = T(n); rep(i, n) cin >> v[i]; }
template<typename T, typename U>
inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }


int main() {
    int n, m;
    cin >> n >> m;
    vi c; getv(c, m);
    vi dp(n + 1, 0);
    repp(i, n) {
        dp[i] = INF;
        rep(j, m) {
            if (i >= c[j])
                umin(dp[i], dp[i - c[j]] + 1);
        }
    }
    prt(dp[n]);

    return 0;
}



Measured memory_bytes: 3172
import java.util.Scanner;

class Main {

	public static void main(String[] args)  {

		Scanner sc = null;

		try {

			sc = new Scanner(System.in);

			String[] str = new String[2];

			int countA = 0;
			int countB  = 0;
			int countAb  = 0;
			int countO = 0;

			while (sc.hasNext()) {

				str = sc.nextLine().split(",");

				if("A".equals(str[1])){
					countA++;
				}else if ("B".equals(str[1])) {
					countB++;
				}else if("AB".equals(str[1])) {
					countAb++;
				}else if ("O".equals(str[1])) {
					countO++;
				}
			}
			System.out.println(countA);
			System.out.println(countB);
			System.out.println(countAb);
			System.out.println(countO);

		} finally {
			sc.close();
		}

	}

}

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

int main() {
  int N;
  int cnt = 0;
  int ans = 1;

  cin >> N;
  for(int i=1;i<=N;++i){
    int s = i;
    int t = 0;
    while(s % 2 == 0){
      t += 1;
      s /= 2;
    }
    if(t > cnt){
      cnt = t;
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3576
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
	num = int(input())
	for i in range(num):
		tri = [int(x) for x in input().split(" ")]
		tri.sort()
		if tri[2] ** 2 == tri[0] ** 2 + tri[1] ** 2:
			print("YES")
		else:
			print("NO")
			
if __name__ == '__main__':
  main()

Measured memory_bytes: 7636
N,H,W = map(int, input().split(' '))
AB = [(input()) for i in range(N) ]
A = [int(AB[i].split()[0]) for i in range(N)]
B = [int(AB[i].split()[1]) for i in range(N)]

ans = 0
for i in range(N):
    if A[i] >= H:
        if B[i] >= W:
            ans +=1
            
print(ans)

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
}

Node treeMaximum(Node x){
}

Node treeSearch(Node u, int k){
  if(u==NIL||u->key==k)return u;
  if(u->key<k)return treeSearch(u->right,k);

  return treeSearch(u->left,k);
}

Node treeSuccessor(Node x){
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
}

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

  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;

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

void inorder(Node u){
  if(u==NIL)return;
    inorder(u->left);
    cout<<" "<<u->key;
    inorder(u->right);

}
void preorder(Node u){
   if(u==NIL)return;
    cout<<" "<<u->key;
    preorder(u->left);
    preorder(u->right);

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


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

int main() {
    int n, max=0;
    cin >> n;
    vector<int> s(n);
    for (int i=0; i<n; i++) {
        int tmp;
        cin >> tmp;
        s[i] = tmp;
        max += tmp;
    }
    sort(s.begin(), s.end());
    if (max % 10 != 0) {
        printf("%d\n", max);
        return 0;
    }
    for (int i=0; i<n; i++) {
        int unko = max - s[i];
        if (unko % 10 != 0) {
            printf("%d\n", unko);
            return 0;
        }
    }
    puts("0");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	static long mod=1000000007;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int[] b=new int[1000001];
		for(int i=0; i<n; i++){
			a[i] =sc.nextInt();
			int tmp=a[i];
			for(int j=2; j*j<=a[i]; j++){
				int count=0;
				while(tmp%j==0){
					tmp/=j;
					count++;
				}
				b[j]=Math.max(b[j],count);
			}
			b[tmp]=Math.max(b[tmp],1);
		}
		long lcm=1;
		for(int i=2; i<1000001; i++){
			lcm*=pow(i,b[i]);
			lcm%=mod;
		}
		long ans=0;
		for(int i=0; i<n; i++){
			ans+=(lcm*pow(a[i],mod-2))%mod;
			ans%=mod;
		}
		System.out.println(ans);
	}
	static long pow(long p,long q){
		long res=1;
		while(q>0){
			if((q & 1)==1){
				res*=p;
				res%=mod;
			}
			q>>=1;
			p*=p;
			p%=mod;
		}
		return res;
	}
}


Measured memory_bytes: 36836
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main(){
    int h,w,n;
    cin>>h>>w>>n;
    
    map<pair<int,int>,bool> black;
    vector<pair<int,int>> ab(n);
    rep(i,n){
        int a,b;
        cin>>a>>b;
        a--;b--;
        black[make_pair(a,b)]=true;
        ab[i]=make_pair(a,b);
    }
    
    map<pair<int,int>,bool> checked;
    vector<int> ans(10);
    rep(i,n){
        int a,b;
        tie(a,b)=ab[i];
        
        rep(j,3){
            rep(k,3){
                int na=a-j;
                int nb=b-k;
                if(na<0 || nb<0) continue;
                if(na+2>=h || nb+2>=w) continue;
                if(checked[make_pair(na,nb)]) continue;
                checked[make_pair(na,nb)]=true;
                
                int cnt=0;
                rep(y,3){
                    rep(x,3){
                        if(black[make_pair(na+y,nb+x)]) cnt++;
                    }
                }
                ans[cnt]++;
            }
        }
    }
    
    int sum=0;
    FOR(i,1,9) sum+=ans[i];
    ll zero=(ll)(h-2)*(w-2)-sum;
    cout<<zero<<endl;
    FOR(i,1,9) cout<<ans[i]<<endl;
    
}



Measured memory_bytes: 213504
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    int add = 0;
    if (N % 1000) add++;
    ll ans = (N / 1000 + add) * 1000 - N;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int main(void){


    int s, t, spot;
    ll val;
    vector<ll> arrS, arrT;

    cin >> s >> t >> spot;
    for(int i = 0; i < s; i++){
        cin >> val;
        arrS.push_back(val);
    }

    for(int i = 0; i < t; i++){
        cin >> val;
        arrT.push_back(val);
    }

    // lower_bound ashiglah ved hamgiin ehnii esvel svvliinh baij boloh uchraas -+ utga ehlel togsgold nemeh
    arrS.push_back(-1e17);
    arrS.push_back(1e17);
    arrT.push_back(-1e17);
    arrT.push_back(1e17);
    sort(arrS.begin(), arrS.end());
    sort(arrT.begin(), arrT.end());

    for(int i = 0; i < spot; i++){
        ll ans = 1e18;
        cin >> val;

        int ii=lower_bound(arrS.begin(),arrS.end(), val)-arrS.begin();
        int jj=lower_bound(arrT.begin(),arrT.end(), val)-arrT.begin();

        ll ra = arrS[ii] - val;     
        ll rb = arrT[jj] - val;
        ll la = val - arrS[ii - 1];
        ll lb = val - arrT[jj - 1];

        // cout << ra << rb << endl;
        // cout << la << lb << endl;
        // cout << ans << endl;
        // ogogdson tseg ni hamag svvld esvel hamgiin ehend bh ved ehnii 2 tootsoolloor
        ans = min(ans, max(ra, rb));
        ans = min(ans, max(la, lb));

        // tseg ni shrine temple 2 iin dund bh ved
        ans = min(ans, ra + lb + min(ra, lb));
        ans = min(ans, la + rb + min(la, rb));

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+100;
ll f[N],g[N],h[N]; int a[N],n;

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d",&a[i]);
    for(int i=2;i<=n;i+=2){
        f[i]=f[i-2]+a[i-1];
        g[i]=max(f[i-2],g[i-2])+a[i];
    }
    if(n&1){
        for(int i=3;i<=n;i+=2){
            h[i]=max(h[i-2]+a[i],max(f[i-1],g[i-1]));
        }printf("%lld\n",h[n]);
    }else printf("%lld\n",max(f[n],g[n]));
}

Measured memory_bytes: 9188
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 20;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

ll my_sqrt(ll x){
	ll s = 0, e = 1e9+3, m;
	while(s <= e){
		m = (s+e) / 2;
		if(m*m > x) e = m-1;
		else s = m+1;
	}swap(s, e);
	return s;
}

int main()
{
	int Q;
	scanf("%d", &Q);
	for(int i = 1; i <= Q; i++){
		ll a, b;
		scanf("%lld%lld", &a, &b);
		ll x = my_sqrt(a*b-1), res = 0;
		if(x == 0){
			printf("0\n");
			continue;
		}
		if((a*b-1)/x == x) res = x*2 - 1;
		else res = x*2;
		if(x >= a || x >= b) res--;
		printf("%lld\n", res);
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#include <math.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int INF = LLONG_MAX/3;
const int MAX = 710000;

/*-----Library-----*/

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

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

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

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
//コンビネーション
/*
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 */
/*-----Library-----*/
const int MOD=1000000007;

signed main(){
    int n;
    cin>>n;
    int a[310000];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int cnt[60]={};
    for(int i=0;i<n;i++){
        for(int j=0;j<60;j++){
            if(a[i]&((int)1<<j))cnt[j]++;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<60;j++){
            if(a[i]&((int)1<<j)){
                cnt[j]--;
                ans+=(((int)1<<j)%MOD)*(n-1-i-cnt[j]);
            }
            else {
                ans+=(((int)1<<j)%MOD)*cnt[j];
            }
            ans%=MOD;
        }
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 2688
#include <stdio.h>  

int main(void)
{
	int sum = 0;
	int i;
	char str[4];

	scanf("%s", str);
	//printf("%s", str);
	
	for(i = 0; i < 4; i++){
		//if((strcmp(str[i], '+') != 0) | (strcmp(str[i], '-')) != 0)
		if(str[i] == '+'){
			sum++;
		}
		else if(str[i] == '-'){
			sum--;
		}
		else return -1;
	}
	printf("%d\n", sum);
}


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

using namespace std;

class node
{
public:
  int v;
  node *left,*right,*p;

  node(int _v=0)
  {
      v=_v,left=right=p=NULL;
  }
};

node *root=NULL;

void ins(int a)
{
    node *tmp=new node(a);

    node *x=root,*y=NULL;

    while(x)
    {
        y=x;

        if(a<x->v)
        {
            x=x->left;
        }else
        {
            x=x->right;
        }
    }

    tmp->p=y;

    if(!y)
    {
        root=tmp;
    }else if(a<y->v)
    {
        y->left=tmp;
    }else
    {
        y->right=tmp;
    }
}

void in(node *r)
{
    if(!r)  return;

    in(r->left);
    printf(" %d",r->v);
    in(r->right);
}

void pre(node *r)
{
    if(!r)  return ;


    printf(" %d",r->v);
    pre(r->left);
    pre(r->right);
}

void print()
{
    in(root);
    printf("\n");
    pre(root);
    printf("\n");
}

node* fnd(node *r,int a)
{
    if(!r) return NULL;

    if(r->v==a) return r;

    if(r->v<a) return fnd(r->right,a);
    else    return fnd(r->left,a);
}

node* get(node *p,int a)
{
    if(p->left) return get(p->left,a);
    else    return p;
}

void del(int a)
{
    node* z=fnd(root,a);

    if(z)
    {
        if(z->left==NULL&&z->right==NULL)
        {
            node* par=z->p;


            if(par)
            {
                if(par->left&&par->left->v==z->v)
                {
                    par->left=NULL;
                }else
                {
                    par->right=NULL;
                }
            }else
            {
                root=par;
            }
            delete z;
        }else if(z->left&&z->right)
        {
            node *tmp=get(z->right,a);
            int tmp1=tmp->v;
            del(tmp1);
            z->v=tmp1;
        }else if(z->left)
        {
            node *par=z->p;

            if(par)
            {
                if(par->left==z)
                {
                    par->left=z->left;
                }else
                {
                    par->right=z->left;
                }
            }else
            {
                root=z->left;
            }

            z->left->p=par;

            delete z;
        }else
        {
            node *par=z->p;


            if(par)
            {
                if(par->left==z)
                {
                    par->left=z->right;
                }else
                {
                    par->right=z->right;
                }
            }else
            {
                root=z->right;
            }

            z->right->p=par;
            delete z;
        }
    }
}

int main()
{
    int n;

    cin>>n;

    string s;
    int a;

    while(n--)
    {
        cin>>s;

        if(s=="insert")
        {
            cin>>a;
            ins(a);
        }else if(s=="find")
        {
            cin>>a;
            if(fnd(root,a))
            {
                cout<<"yes"<<endl;
            }else
            {
                cout<<"no"<<endl;
            }
        }else if(s=="delete")
        {
            cin>>a;

            del(a);
        }else
        {
            print();
        }
    }



    return 0;
}




Measured memory_bytes: 22072
//  string t = "keyence";//で文字列入力ができる
//s.empty() //emptyなら1を出力 入っていれば0を出力
/*//ABC018-B 部分的にreverseをかける解法
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n) cin>>a.at(i)>>b.at(i);
  rep(i,n)a.at(i)--;
  rep(i,n)b.at(i)--;
  string t;
  rep(i,n){
    t = s;
    for(int k=0;k<=b.at(i)-a.at(i);k++){
      t.at(a.at(i)+k) = s.at(b.at(i)-k);
    }
    s = t;
  }
  cout << s << endl;
}
*///ABC018-B
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int kan_hyaku(int n){
  int kurai = 0;
  for(int i=0;i<3;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int kan_ju(int n){
  int kurai = 0;
  for(int i=0;i<2;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int kan_ichi(int n){
  int kurai = 0;
  for(int i=0;i<1;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,n) cin>>a.at(i);
  int count = 0;
  for(int i=0;i<n;i++){
    if(i%2==0 && a.at(i)%2!=0)count++;
  }
  cout << count << endl;
}


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

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n,m;
  cin>>n>>m;
  vector<int> x(m, 0);
  for (int i=0; i<m; i++) {
    cin>>x[i];
  }
  if (n>=m) {
    cout << 0 << endl;
    return;
  }

  sort(x.begin(),x.end());
  vector<int> d(m, 0);
  for (int i=0; i<m-1; i++) {
    d[i] = x[i+1] - x[i];
  }
  sort(d.begin(),d.end(),greater<int>());
  int mx = x[m-1]-x[0];
  for (int i=0; i<n-1; i++) {
    mx -= d[i];
  }
  cout << mx << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <map>
#include <cstdio>
#include <cmath>
#include <unordered_map>
#include <iomanip>
using namespace std;

int main(){
  char C;
  cin >> C;
  cout << (char)(C+1) << endl;
}

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

int main(){
	int n;cin>>n;
	int a[n];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(i%2!=0 && a[i]%2!=0){
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
	
}

Measured memory_bytes: 3516
# AtCoder Beginner Contest 145 C - Average Length

import sys
import numpy as np
import itertools

N = int(input())
town = []
for _ in range(N):
    x, y = map(int, sys.stdin.readline().strip().split())
    town.append((x, y))


def distance(i, j):
    ans = np.sqrt((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2)
    return ans


total = 0
for i in itertools.permutations(iterable=town):
    for j in range(len(i) - 1):
        total += distance(i[j], i[j + 1])

n_fact = 1
for i in range(1, N + 1):
    n_fact *= i

ans = total / n_fact

print(ans)


Measured memory_bytes: 14404
import java.util.*;
class Main{

     public static void main(String []args){
        //System.out.println("Hello World");
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int y = scan.nextInt();
        int count2 = 0 ;
        for(int i = x ; i<=y ;i++){
            int k = 1 ;
            int count = 0 ;
            char[] arr = String.valueOf(i).toCharArray();
            for(int j= 0 ; j<=arr.length/2 ; j++){
                
                if(arr[j] == arr[arr.length-k]){
                    count++ ; 
                }
                k++;
            }
            if(count == Math.ceil(arr.length/2.0)){
                count2++ ;
            }
        }
        
        System.out.println(count2);
     }
}

Measured memory_bytes: 30132
import sys
 
 
def f(x, y):
    return x - y, x + y
 
 
def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    x = [0] * n
    y = [0] * n
    for i in range(n):
        x[i], y[i] = map(int, input().split())
    f0 = [0] * n
    f1 = [0] * n
    for i in range(n):
        f0[i], f1[i] = f(x[i], y[i])
    print(max(max(f0) - min(f0), max(f1) - min(f1)))
 
 
if __name__ == "__main__":
    main()

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

const string dir = "ENSW";
const string rdir = "WSNW";
constexpr int rot[4][6] = { {2, 1, 5, 3, 0, 4}, {3, 0, 2, 5, 4, 1},
							{1, 5, 2, 0, 4, 3}, {4, 1, 0, 3, 5, 2}};

vector<int> roll(vector<int> const& v, char d) {
	const int p = find(begin(dir), end(dir), d) - begin(dir);
	vector<int> res(6);
	for(int i = 0; i < 6; ++i) {
		res[i] = v[rot[p][i]];
	}
	return res;
}

bool check(vector<int> const& dice) {
	int v1 = dice[0] + dice[5], v2 = dice[2] + dice[4], v3 = dice[1] + dice[3];
	int cnt = 0;
	if(dice[0] < 0) return false;
	if(v1 >= v2 + v3 + 1) return false;
	if(v2 > v1 + v3 + 1) return false;
	if(v2 == v1 + v3 + 1) cnt++;
	if(v3 > v1 + v2 + 1) return false;
	if(v3 == v1 + v2 + 1) cnt++;
	return cnt <= 1;
};

bool found = false;
string ans, t;
void dfs(vector<int>& dice) {
	if(found && ans < t) {
		return;
	}
	if(*max_element(begin(dice), end(dice)) == 0) {
		if(found) {
			ans = min(ans, t);
		} else {
			ans = t;
		}
		//cout << "t: " << t << endl;
		found = true;
		return;
	}
	for(int i = 0; i < 4; ++i) {
		dice = roll(dice, dir[i]);
		dice[0]--;
		if(check(dice)) {
			t += dir[i];
			dfs(dice);
			return;
		}
		dice[0]++;
		dice = roll(dice, rdir[i]);
	}
	for(int i = 0; i < 6; ++i) {
		cout << dice[i] << ' ';
	}
	cout << endl;
	assert(false);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	vector<int> v(6);
	while(true) {
		ans.clear(), t.clear();
		found = false;
		for(int i = 0; i < 6; ++i) cin >> v[i];
		if(*max_element(begin(v), end(v)) == 0) break;
		sort(begin(v), end(v));
		int p, q;
		cin >> p >> q;
		
		do {
			auto tdice = v;
			if(!check(v)) continue;
			t.clear();
			dfs(tdice);
			//cout << "sum: " << accumulate(begin(v), end(v), 0) << endl;
		} while(next_permutation(begin(v), end(v)));
		
		if(!found) {
			cout << "impossible" << endl;
		} else {
			//cout << "sz: " << ans.size() << endl;
		    cout << ans.substr(p - 1, q - p + 1) << endl;
		}
	}
}


Measured memory_bytes: 5636
let md = stdin.ReadLine().Split() |> Array.map int

let ls = [for i in 2..9 do
          for j in 2..9 do
           yield (i,j)]

ls
|> List.sumBy (fun (x,y) -> if ((x * y) <= md.[0]) && ((10 * x + y) <= md.[1]) then 1 else 0)
|>stdout.WriteLine

Measured memory_bytes: 11348
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast")
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e6;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int a[1000001];
bool pr[1000001], was[1000001];
vector<int> prm;

int main()
{
    fast_io;
    int n, i, j, g, t;
    cin >> n;
    for (i = 1; i <= n; i++) cin >> a[i];
    for (i = 2; i <= 1e6; i++)
    {
        if (pr[i]) continue;
        for (j = 2 * i; j <= 1e6; j += i) pr[j] = 1;
        prm.pb(i);
    }
    g = a[1];
    for (i = 2; i <= n; i++) g = gcd(g, a[i]);
    if (g > 1) cout << "not coprime", exit(0);
    for (i = 1; i <= n; i++)
    {
        t = sqrt(a[i]);
        for (auto f: prm)
        {
            if (f > t) break;
            if (a[i] % f) continue;
            if (was[f]) cout << "setwise coprime", exit(0);
            while (a[i] % f == 0)
            {
                a[i] /= f;
                was[f] = 1;
            }
        }
        if (a[i] > 1)
        {
            if (was[a[i]]) cout << "setwise coprime", exit(0);
            was[a[i]] = 1;
        }
    }
    cout << "pairwise coprime";
    return 0;
}

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

static const int N_MAX = 50;

int main() {
    static int dp[N_MAX];
    fill(dp, dp + N_MAX, 0);
    dp[0] = 1;
    for(int i = 0; i <= 30; i++) {
        dp[i + 1] += dp[i];
        dp[i + 2] += dp[i];
        dp[i + 3] += dp[i];
    }

    for(int N; cin >> N, N; ) {
        cout << ceil(dp[N] / (10.0 * 365)) << endl;
    }
}

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

int main(){
//  入力を受け取る変数はcinの前に宣言する
  int M ;
//  入力がある場合は必ず受け取る
  cin >> M ;
//  あれこれ計算したり色々処理をする
  int A = 48-M ;
//  最後に答えを出力
  cout << A << endl ;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<sstream>
#include<stdlib.h>
using namespace std;

int main() {
	string S;
	int N;
	cin >> S;
	N = S.size();
	
	int M = 3 ;
	int s1 = 0;
	int s2 = 0;
	int s3 = 0;
	int ans = 0;
	int A = 10000;
	int favorite = 753;
	for (int i = 0; i <= N - M; i++) {
		s1 = S[i] - 48;
		s2 = S[i + 1] - 48;
		s3 = S[i + 2] -48;
		ans = favorite - (s1 * 100 + s2 * 10 + s3);
			if(abs(ans) < A){
				A = abs(ans);
			}
	}
	cout << A;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,p,c,i;
  int a[51];
  while(1){
    //skk
    for(int j=0;j<51;j++){
      a[j]=0;
    }
    i=0;

    cin >> n >> p;
    if(n==0&&p==0)break;
    c=p;
    while(1){
      if(c!=0){
	a[i]++;
	c--;
	if(a[i]==p){
	  cout << i << endl;
	  break;
	}
      }
      else{
	c+=a[i];
	a[i]=0;
      }
      i++;
      if(i==n)i=0;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdbool.h>
#include<set>
#define N 1000000007
using namespace std;
typedef long long ll;
int num[100001];
int main(void) {
	int a, b;
	cin >> a >> b;
	if (a <= b)cout << a << endl;
	else cout << a - 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int gcd(int a,int b);
int main() {
  int x,y;

  scanf("%d%d",&x,&y);

  printf("%d\n", gcd(x,y));
  return 0;
}

int gcd(int a,int b){
  int r;
  if(a>b){
    r=a;
    a=b;
    b=r;
    r=0;
  }
  if(a < b){
      //  swap(a, b);
    while(b > 0){
        r = a % b;
        a = b;
        b = r;
    }
  }
    return a;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
int v[109],w[109]; long long dp[109][100009];
long long  solve(int i, int wt) {
	if(wt<=0) {
		return 0;
	}
	if(i<0) {
		return 0;
	}
	if(dp[i][wt] != -1) {
		return dp[i][wt];
	}
	long long s1 = 0;
	if(wt >= w[i]) {
		s1 = solve(i-1, wt-w[i]) + v[i];
	}
	long long s2 = solve(i-1, wt);
	return dp[i][wt] = max(s1,s2);
}

int main() {
	int n,wt;
	int x = 5e9;
	cin>>n>>wt;
	for(int i=0;i<n;++i) {
		cin>>w[i]>>v[i];
	}
	memset(dp, -1, sizeof dp);
	cout<<solve(n-1, wt);
	return 0;
}

Measured memory_bytes: 85376
#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>
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 ;


vector<int> calc(string& S){
    vector<int> A(S.size());
    A[0] = S.size();
    int i = 1, j = 0;
    while (i < S.size()) {
        while (i+j < S.size() && S[j] == S[i+j]) ++j;
        A[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k;
        i += k; j -= k;
    }
    return A;
}
int main(){
    string S,t;
    cin>>S>>t;
    string w = "";
    while(w.size()<t.size())w+=S;
    string s=w+w+w;
    int ok = 0, ng = s.size()/t.size()+1;
    while(ng-ok>1){
        int mid = (ok+ng)/2;
        string u = "";
        rep(i,mid)u+=t;
        u+=s;
        auto ret = calc(u);
        int ma = 0;
        REP(i,mid*t.size(),ret.size()){
            ma=max(ma,ret[i]);
        }
        if(ma>=mid*t.size())ok=mid;
        else ng=mid;
    }
    s+=s;
    int res = ok;
    ok = 0, ng = s.size()/t.size()+1;
    while(ng-ok>1){
        int mid = (ok+ng)/2;
        string u = "";
        rep(i,mid)u+=t;
        u+=s;
        auto ret = calc(u);
        int ma = 0;
        REP(i,mid*t.size(),ret.size()){
            ma=max(ma,ret[i]);
        }
        if(ma>=mid*t.size())ok=mid;
        else ng=mid;
    }
    if(ok>res){
        cout<<-1<<endl;
    }
    else cout<<ok<<endl;
    return 0;
}

Measured memory_bytes: 83404
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL<<60;

//一般化できるポイント
// DP tableが大きすぎるとき
// 
// knapsack[i][j] : 
// 0~i-1番目までの荷物を選ぶとき
// 価値がjとなるときの
// 荷物の総和の最小値
// 答えは 0 <= j <= 100000

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


vector<vector<long long>> knapsack(110, vector<long long>(1010101, INF));


int main(){
    int n, W;
    cin >> n >> W;
    
    vector<int> w(n), v(n);
    
    for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
    
    knapsack[0][0] = 0;
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= 100000; j++){
            
            chmin(knapsack[i+1][j], knapsack[i][j]);
            
            if (j - v[i] >= 0) chmin(knapsack[i+1][j], knapsack[i][j - v[i]] + w[i]);
        }
    }
    
    
    int ans = 0;
    for (int i = 0; i <= 100000; i++){
        if (knapsack[n][i] <= W) ans = max(ans, i);
    }
    
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

constexpr int INF=1e9;
int h, w;
char s[125][125];
int d[125][125];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  cin>>h>>w;
  REP(i, h){
    REP(j, w){
      cin>>s[i][j];
      d[i][j]=INF;
    }
  }
  d[0][0]=(s[0][0]=='.' ? 0 : 1);
  REP(x, h){
    REP(y, w){
      if(x+1<h){
        int tx=x+1, ty=y;
        int tmp=(s[tx][ty]=='#' && s[tx][ty]!=s[x][y] ? d[x][y]+1 : d[x][y]);
        CHMIN(d[tx][ty], tmp);
      }
      if(y+1<w){
        int tx=x, ty=y+1;
        int tmp=(s[tx][ty]=='#' && s[tx][ty]!=s[x][y] ? d[x][y]+1 : d[x][y]);
        CHMIN(d[tx][ty], tmp);
      }
    }
  }
  // REP(i, h){
  //   REP(j, w){
  //     cout<<d[i][j]<<" \n"[j==w-1];
  //   }
  // }
  cout<<d[h-1][w-1]<<'\n';
  return 0;
}


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

ll p5(ll x){
    return x*x*x*x*x;
}

signed main(){
    ll x;cin>>x;
    for(ll a=-1000;a<=1000;a++){
        for(ll b=-1000;b<=1000;b++){
            ll res=p5(a)-p5(b);
            if(res==x){
                cout<<a<<' '<<b<<endl;
                return 0;
            }
        }
    }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> t(n);
  vector<double> v(n);
  int sumt=0;
  for (int i = 0; i < n; i++){
    cin >> t[i];
    sumt+=t[i];
  } 
  for (int i = 0; i < n; i++) cin >> v[i];
  vector<double> maxv(sumt*2+1,101);

  int left=0;
  int right=0;
  for (int i = 0; i < n; i++)
  {
    left=right;
    right += t[i]*2;
    for (int j = left; j <= right; j++)
    {
      maxv[j]=min(maxv[j],v[i]);
    }
  }
  maxv[0] = 0;
  maxv[right] = 0;

  for (int i = 1; i < sumt*2+1; i++)
  {
    maxv[i] = min(maxv[i],maxv[i-1]+0.5);
  }

  for (int i = sumt*2-1; i > 0; i--)
  {
    maxv[i] = min(maxv[i],maxv[i+1]+0.5);
  }

  double x = 0.0;
  for (int i = 0; i < sumt*2; i++)
  {
    x += 0.25*(maxv[i]+maxv[i+1]);
  }

  printf("%.9lf\n",x);
}

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

string s;
int cnt[26];

int main() {
	cin >> s;
	
	for (int i = 0; i < s.length(); i++) {
		cnt[s[i] - 'a']++;
	}
	
	for (int i = 0; i < 26; i++) {
		if (cnt[i] % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct SmallestEnclosingCircle {
private:
    double MAX_RADIUS;
    struct Point { double x, y; };
    vector<Point> p;
    
    double get_distance(Point a, Point b) {
        double dx = a.x - b.x;
        double dy = a.y - b.y;
        return sqrt(dx * dx + dy * dy);
    }
    
    double get_radius(double x, double y) {
        double res = 0;
        Point center = (Point){x, y};
        for(int i = 0, ps = p.size(); i < ps; i++) {
            res = max(res, get_distance(center, p[i]));
        }
        return res;
    }
    
    double y_binary_search(double x) {
        double l = 0, h = MAX_RADIUS;
        for(int i = 0; i < 80; i++) {
            double lm = (l * 2 + h) / 3;
            double hm = (l + h * 2) / 3;
            if (get_radius(x, lm) > get_radius(x, hm)) l = lm;
            else h = hm;
        }
        return get_radius(x, l);
    }
    
    double x_binary_search() {
        double l = 0, h = MAX_RADIUS;
        for(int i = 0; i < 80; i++) {
            double lm = (l * 2 + h) / 3;
            double hm = (l + h * 2) / 3;
            if (y_binary_search(lm) > y_binary_search(hm)) l = lm;
            else h = hm;
        }
        return y_binary_search(l);
    }
    
public:
    SmallestEnclosingCircle(int width, int height) {
        long long w = width, h = height;
        MAX_RADIUS = sqrt(w * w + h * h);
    }
    
    void add_point(double x, double y) {
        p.push_back((Point){x, y});
    }
    
    double get_radius() {
        return x_binary_search();
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    SmallestEnclosingCircle sec(1000, 1000);
    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        sec.add_point(x, y);
    }
    printf("%.10f\n", sec.get_radius());
    return 0;
}


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

int main(void){

    ll A,B; cin>>A>>B;
    ll Gcd = __gcd(A,B);
    ll ans = 1;

    for (ll i = 2; i*i <= Gcd; ++i) {
        if(Gcd%i==0){
            ans++;
            while(Gcd%i==0){
                Gcd /= i;
            }
        }
    }
    if(Gcd!=1) ans++;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
n=gets.to_i
odd=Array.new
for i in 1..n
    if(i%2!=0)
        odd.push(i)
    end
end
ret=0
require 'prime'
odd.each{|i|
    cnt=1
    insu=Prime.prime_division(i)
    a=insu.map{|soi|soi[1]+1}
    a.each{|j|
        cnt*=j
    }
    if cnt==8 then ret+=1 end
}
p ret

Measured memory_bytes: 2044