akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using P = pair<int,int>;
using ll = long long; 

int main(){
    ll n;
    cin>>n;
    ll ans=0;
    if(n<=9){
        ans=n;
    }else if(n<=99){
        ans=9; 
    }else if(n<=999){
        ans=9+n-99;
    }else if(n<=9999){
        ans=9+999-99;
    }else if(n<=99999){
        ans=9+999-99+n-9999;
    }else if(n==100000){
        ans=90909;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3644
//abc150_c.cpp
//Thu Feb  6 21:58:03 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n;
	cin >> n;

	int x[n];
	for (int i=0;i<n;i++){
		x[i] = i+1;
	}
	vector<int> per;
	do {
		int tmp = 0;
		int y = 1;
		for (int i=0;i<n;i++){
			if (i!=0){
				y *= 10;
			}
			tmp += x[i]*y;
		}
		per.push_back(tmp);
	} while (next_permutation(x,x+n));

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

	int p = 0;
	int q = 0;
	int y = pow(10,n);
	for (int i=0;i<n;i++){
		y = y/10;
		int tmp;
		cin >> tmp;
		p += tmp*y;
	}
	y = pow(10,n);
	for (int i=0;i<n;i++){
		y = y/10;
		int tmp;
		cin >> tmp;
		q += tmp*y;
	}
	int px = 0;
	int qx = 0;
	for (int i=0;i<per.size();i++){
		if (per[i]==p){
			px = i;
		}
		if (per[i]==q){
			qx = i;
		}
	}
//	cout << p << " " << q << endl;
	cout << abs(px-qx) << endl;
}

Measured memory_bytes: 640
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define pii pair<int,int>
#define fr(i, a, b) for(int i = a; i < b; i++)
#define frb(i, a, b) for(int i = a; i > b; i--)
#define sz(s) (int)s.size()
#define all(v) (v).begin(), (v).end()
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
#define iset tree < int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define oset tree < pair<int, int> ,  null_type ,  less<pair<int, int> > ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define ll long long
using namespace std; 
using namespace __gnu_pbds; 


int  prg()
{
    int n;
    cin>>n;
    vector<ll> a(n);
    unsigned ll m=1;
    fr(i,0,n)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            cout<<'0';
            return 0;
        }
    }
    fr(i,0,n)
    {
        if(log10(m)+log10(a[i])>18)
        {
            cout<<"-1";
            return 0;
        }
        m*=a[i];
        if(m>(ll)1e18)
        {
            cout<<"-1";
            return 0;
        }
    }
    cout<<m;
    return 0;

}
void multi()
{
    int t;
    cin>>t;
    for(int i=0;i<t;++i)
    {
       prg();
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    prg();
    return 0;
}

Measured memory_bytes: 3996
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int[][] red = new int[N][3];
    int[][] blue = new int[N][3];

    for (int i = 0; i < N; i++) {
      red[i][0] = sc.nextInt();
      red[i][1] = sc.nextInt();
      red[i][2] = 0;
    }

    for (int i = 0; i < N; i++) {
      blue[i][0] = sc.nextInt();
      blue[i][1] = sc.nextInt();
      blue[i][2] = 0;
    }

    sc.close();

    int count = 0;

    Arrays.sort(red, (a,b) -> Integer.compare(a[1],b[1]));
    Arrays.sort(blue, (a,b) -> Integer.compare(a[0],b[0]));

    for (int i = 0; i < N; i++) {
      for (int j = N-1; 0 <= j; j--) {
        if (red[j][2] == 0 && blue[i][2] == 0) {
          if (red[j][0] < blue[i][0] && red[j][1] < blue[i][1]) {
            red[j][2] = 1;
            blue[i][2] = 1;
            count++;
          }
        }
      }
    }

    System.out.println(count);

  }

}

Measured memory_bytes: 26708
from bisect import bisect_left

n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def check(mid):
    cnt = 0
    for i in range(n):
        s = mid-a[i]
        cnt += n-bisect_left(a, s)
        if cnt >= m:
            return True
    return False

left = 0
right = 10**11
while right-left>1:
    mid = (right+left)//2
    if check(mid):
        left = mid
    else:
        right = mid
cs = [0]
for i in reversed(range(n)):
    cs.append(cs[-1]+a[i])
ans = 0

cnt = 0
for i in range(n):
    j = n-bisect_left(a, right-a[i])
    ans += j*a[i] + cs[j]
    cnt += j
ans += (m-cnt)*left
print(ans)


Measured memory_bytes: 60700
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vvll as(n, vll(n));
  rep(i, n) rep(j, n) cin >> as[i][j];

  vll pts(1 << n);
  vvll pats(n + 1);
  rep(s, 1 << n) {
    pats[__builtin_popcount(s)].push_back(s);
    rep(i, n) repLRE(j, i + 1, n - 1) {
      if ((s >> i) & (s >> j) & 1) pts[s] += as[i][j];
    }
  }

  vll dp(1 << n, 0);
  rep(i, n + 1) {
    rep(j, (ll)pats[i].size()) {
      ll s = pats[i][j];
      chmax(dp[s], pts[s]);
      for (ll t = s; t > 0; --t &= s) {
        chmax(dp[s], dp[s & t] + dp[s & ~t]);
      }
    }
  }

  cout << dp[(1 << n) - 1] << endl;

  return 0;
}


Measured memory_bytes: 2048
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)

ans = a[0]
ans_l = []
ans_e = a[-1]

if ans_e >= 0:
    for i in range(1,n-1):
        if a[i] < 0:
            ans_l += [(ans_e, a[i])]
            ans_e -= a[i]
        if a[i] >= 0:
            ans_l += [(ans, a[i])]
            ans -= a[i]

    ans_l += [(ans_e,ans)]
    ans = ans_e - ans

else:
    ans = ans_e
    for i in range(0,n-1):
        ans_l += [(ans, a[i])]
        ans -= a[i]

print(ans)

for x, y in ans_l:
    print(x,y)


Measured memory_bytes: 63196
def main():
	C = [[0 for _ in range(3)] for _ in range(3)]
	for i in range(3):
		C[i] = list(map(int, input().split()))
	possible = True
	for i in range(1, 3):
		tmp = C[i][0]-C[i-1][0]
		for j in range(1, 3):
			if C[i][j]-C[i-1][j] != tmp:
				possible = False
				break
	for j in range(1, 3):
		tmp = C[0][j]-C[0][j-1]
		for i in range(1, 3):
			if C[i][j]-C[i][j-1] != tmp:
				possible = False
				break
	if possible:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        let line = line.unwrap();
        let v: Vec<_> = line.split_whitespace().collect();
        let (a, b): (i32, i32) = (v[0].parse().unwrap(), v[2].parse().unwrap());
        let result = match v[1] {
            "+" => a + b,
            "-" => a - b,
            "*" => a * b,
            "/" => a / b,
            "?" => return,
            _ => panic!("error"),
        };
        println!("{}", result);
    }
}



Measured memory_bytes: 5052
#include <bits/stdc++.h>
using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;

int main(void) {
    string s, t;
    cin >> s >> t;
    s.push_back('A');
    t.push_back('B');
    // dp[i][j] contains the length of the longest subsequence if s from s_0..s_i
    // and t from t_0..t_j
    vector <vector <pair <int, pair <int, int>>>> dp(s.size(), vector <pair <int, pair <int, int>>>(t.size(), { 0, {-1, -1} }));
    for (int i = 0; i < (int)s.size(); i++) {
        for (int j = 0; j < (int)t.size(); j++) {
            if (s[i] == t[j]) {
                if (i + 1 < (int)dp.size() && j + 1 < (int)dp[0].size() && dp[i + 1][j + 1].first < 1 + dp[i][j].first) {
                    dp[i + 1][j + 1] = { 1 + dp[i][j].first, {i, j} };
                }
            }
            else {
                if (i + 1 < (int)dp.size() && j + 1 < (int)dp[0].size() && dp[i + 1][j + 1].first < dp[i][j].first) {
                    dp[i + 1][j + 1] = dp[i][j];
                }
                if (i + 1 < (int)dp.size() && dp[i + 1][j].first < dp[i][j].first) {
                    dp[i + 1][j] = dp[i][j];
                }
                if (j + 1 < (int)dp[0].size() && dp[i][j + 1].first < dp[i][j].first) {
                    dp[i][j + 1] = dp[i][j];
                }
            }
        }
    }

    string ans;
    int index_s = s.size() - 1, index_t = t.size() - 1;
    while (index_s != -1) {
        ans.push_back(s[index_s]);
        int a = index_s, b = index_t;
        auto x = dp[a][b];
        index_s = x.second.first, index_t = x.second.second;
    }
    reverse(ans.begin(), ans.end());
    ans.pop_back();
    cout << ans << '\n';
}

Measured memory_bytes: 108780
#include"bits/stdc++.h"
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using ll=long long; 
using ld=long double; 
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int mod1=1e9+7; 
int main()
{
    #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  int n; cin>>n; vector<pair<int,int>>v; int x,y; 
  rep(i,0,n-1){ cin>>x>>y; v.emplace_back(x,y); }
  rep(i,2,n-1)
  {
  	if(v[i-2].first==v[i-2].second and v[i-1].first==v[i-1].second and v[i].first==v[i].second)
    { puts("Yes"); return 0; }
  }
  puts("No"); return 0; 
} 

Measured memory_bytes: 3628
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    ll h=0,w=0;
    vll x(n);
    vll y(m);
    REP(i,n){
        cin >> x[i];
    }
    REP(i,m)cin >> y[i];
    REP(i,n-1){
        ll x1 = x[i+1]-x[i];
        x1%=mod;
        ll x2 = (i+1)*(n-i-1);
        x2%=mod;
        w += x1*x2;
        w%=mod;
    }
    REP(i,m-1){
        ll y1 = y[i+1]-y[i];
        y1%=mod;
        ll y2 = (i+1)*(m-i-1);
        y2%=mod;
        h += y1*y2;
        h%=mod;
    }
    ll ans = h*w;
    ans%=mod;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n,s[22],p[22];
  while(cin >> n && n){
    for(int i = 0; i < n; i++) cin >> p[i];

    bool f = true;
    int m = 0;
    while(f){
      f = false;
      for(int i = 0; i < n; i++) s[i] = p[i];
      for(int i = 0; i < n; i++){
	p[i] = 0;
	for(int j = 0; j < n; j++){
	  if(s[i] == s[j])p[i]++;
	}
	if(s[i]!=p[i]) f = true;
      }
      if(!f) break;
      m++;
    }
    cout << m << endl;
    for(int i = 0; i < n; i++) cout << p[i] << (i+1==n?'\n':' ');
  }
}

Measured memory_bytes: 1160
//#include <bits/stdc++.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

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

    int h,w,k; cin >>h>>w>>k;
    vvc s(h,vc(w));
    rep(i,h)rep(j,w)cin>>s[i][j];
    int res=INF;

    rep(bit,1<<(h-1)){
    //int bit=510;{
        int pop=__builtin_popcount(bit);
        vi div(pop+1,0);
        int tmp=pop;
        bool can=true;
        rep(j,w){
            int p=0;
            bool over=false;
            rep(i,h){
                div[p]+=(s[i][j]=='1');
                if(div[p]>k) over=true;
                if(bit&(1<<i))p++;
            }
            if(over){
                rep(i,pop+1)div[i]=0;
                p=0; 
                tmp++;
                rep(i,h){
                    div[p]+=(s[i][j]=='1');
                    if(div[p]>k) can=false;
                    if(bit&(1<<i))p++;
                    
                }       
            }
            if(can==false) break;
        }
        if(can) chmin(res,tmp);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3648
c = [list(map(int,input().split())) for i in range(3)]
a1,a2,a3,b1,b2,b3 = 0,c[1][0]-c[0][0],\
c[2][0]-c[0][0],c[0][0],c[0][1],c[0][2]

if c[1][1]==a2+b2 and c[1][2]==a2+b3 and\
c[2][1]==a3+b2 and c[2][2]==a3+b3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}



signed main(){
	ll cnt = 0;
	string s;
	
	cin >> s;
	
	rep(i,0,s.size()/2){
		if(s[i] != s[s.size()-1-i]) cnt++;
	}
	
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <cstdlib>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include <assert.h>
#include<map>
#include<set>
#include<bitset>
#include <iomanip>
#include<stack>
#include <unordered_map>
#include<cmath>
using namespace std;
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.14159265358979323846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
#define STDIN freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m,n) for (int i = m;  i < n; i++)
#define PII pair<int,int>
#define PLL pair<long, long>
#define ft first
#define sd second
#define pb push_back
const int maxn = 333333, mod = 1000000009;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read() { char ch = getchar(); int x = 0, f = 0; while (ch < '0' || ch>'9')f |= ch == '-', ch = getchar(); while (ch >= '0' && ch <= '9')x = x * 10 + ch - '0', ch = getchar(); return f ? -x : x; }


int main()
{
    
    unordered_map<ll, int > umap;
    int n; cin >> n;
    ll cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        ll t; cin >> t;
        ll y = i - t;
        cnt += umap[y];
        umap[t + i] += 1;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 23044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;

char board[101][101];

int main(){
long A, B;
cin >> A >> B;
erep(i, 100){
  erep(j, 50){
    board[i][j] = '#';
  }
  for(long j = 51; j <= 100; j++){
    board[i][j] = '.';
  }
}


erep(i, ((A-1)/24)){
  erep(j, 24){
    board[2*i][2*j] = '.';
  }
}
erep(j, ((A-1)%24)){
  board[((A-1)/24)*2+2][j*2] = '.';
}
erep(i, ((B-1)/24)){
  for(long j = 1; j <= 24; j++){
    board[2*i][2*j+50] = '#';
  }
}
for(long j = 1; j <= ((B-1)%24); j++){
  board[((B-1)/24)*2+2][j*2+50] = '#';
}

cout << 100 << ' ' << 100 << endl;
erep(i, 100){
  erep(j, 100){
    cout << board[i][j];
  }
  cout << endl;
}







return 0;
}

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

int main() {
	string S, T;
	cin >> S >> T;

	T += S;
	cout << T << endl;

}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;

int f( int x ) {
    return x <= 1 ? 1 : x * f(x - 1);
}

int main() {

    int n;
    cin >> n;
    vector<pii> coord(n);

    fo(i, n) cin >> coord[i].ff >> coord[i].ss;

    long double ans = 0;
    sort(all(coord));
    int cont = 0;
    
    do {
        cont++;
        fo(i, n - 1) {
            long double aux = 0;
            aux += pow((coord[i].ff - coord[i + 1].ff), 2)/* * (coord[i].ff - coord[i + 1].ff)*/;
            aux += pow((coord[i].ss - coord[i + 1].ss), 2)/* * (coord[i].ss - coord[i + 1].ss)*/;
            ans += sqrt(aux);
        }
        // ans += sqrt(aux);
    } while ( next_permutation(all(coord)) );

    // cout << cont << "perms\n";
    cout << fixed << setprecision(10) << ans / f(n) << endl;

    return 0;
}

Measured memory_bytes: 256
import math

n, a, b = map(int, input().split())
MOD = 1000000000 + 7

inv = [1, 1]
com = [0, n]
for i in range(2, max(a, b) + 1):
    inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD)
    com.append(com[i - 1] * (n - i + 1) * inv[i] % MOD)

print((pow(2, n, MOD) - com[a] - com[b] - 1) % MOD)


Measured memory_bytes: 24600
using System;
using System.Collections.Generic;
using System.Linq;

public class Solver
{
    public const int MaxType = 26;
    public int Days;
    public long[] Downs;
    public long[][] Scores;
    public void Init()
    {
        Days = int.Parse(Console.ReadLine());
        Downs = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        Scores = new long[Days][];
        for (int i = 0; i < Days; i++)
        {
            Scores[i] = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
    }

    public long CalcScore(int[] plan)
    {
        long score = 0;
        var last = new int[MaxType];
        for (int d = 1; d <= Days; d++)
        {
            var i = d - 1;
            var type = plan[i];
            last[type] = d;
            score += Scores[i][type];
            score -= last.Select((la, index) => Math.Max(Downs[index] * (d - la), 0)).Sum();
        }

        return score;
    }

    public int[] Solve()
    {
        var plan = new int[Days];
        for (int d = 0; d < Days; d++)
        {
            var t = Enumerable.Range(0, MaxType).OrderByDescending(i => Scores[d][i]).First();
            plan[d] = t;
        }
        return plan;
    }

}

public static class Solution
{
    public static void Main()
    {
        var solver = new Solver();
        solver.Init();
        var answer = solver.Solve();
        var score = solver.CalcScore(answer);
        Console.Error.WriteLine(score);

        Console.WriteLine(string.Join(Environment.NewLine, answer.Select(i => i + 1)));
    }
}

Measured memory_bytes: 29268
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	A := sc.nextIntSlice(N + 1)
	B := sc.nextIntSlice(N)
	count := 0
	before := 0
	for i, _ := range A {
		if before > 0 {
			if A[i] > before {
				A[i] -= before
				count += before
			} else {
				count += A[i]
				A[i] = 0
			}
		}
		if i == N {
			break
		}
		if A[i] > B[i] {
			A[i] -= B[i]
			count += B[i]
			B[i] = 0
		} else {
			count += A[i]
			B[i] -= A[i]
			A[i] = 0
		}
		before = B[i]
	}
	fmt.Println(count)
}


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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll x, y; cin >> x >> y;
    int ans = 0;
    while (x <= y) {
        x *= 2;
        ans++;
    }
    cout << ans << '\n';
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#define lld long long int
#define DBG1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define DBG2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define DBG3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int a[1001];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// freopen("input.txt", "r", stdin);  
	int n;
	cin >> n;
	for(int i=2;i<=n;i++)
	{
		int temp=i;
		for(int j=2;j*j<=i;j++)
		{
			while(temp%j==0)
			{
				// cout << "dsf";
				a[j]++;
				temp/=j;
			}
		}
		if(temp>1)
			a[temp]++;
	}
	lld ans=1;
	for(int i=2;i<=1001;i++)
	{
		// cout << i << " " <<  ans  << "\n";
		if(a[i]>0)
		{
			ans*=(a[i]+1);
			ans%=1000000007;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 15 12:43:21 2018
ABC049C
@author: maezawa
"""

s = input()
a = ('dream', 'dreamer', 'erase', 'eraser')

i = len(s)
ans = 'YES'
while True:
    if s[-5:] == a[0] or s[-5:] == a[2]:
        i -= 5
    elif i>=6 and s[-6:] == a[3]:
        i -= 6
    elif i>=7 and s[-7:] == a[1]:
        i -= 7
    else:
        ans = 'NO'
        break
    if i == 0:
        ans = 'YES'
        break
    elif i<5:
        ans = 'NO'
        break
    s = s[:i]

    #print(s)
print(ans)

Measured memory_bytes: 3316
n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
	for j in range(1,105):
		for k in range(1,105):
			v = i*i+j*j+k*k+i*j+j*k+k*i
			if v<10050:
				ans[v]+=1
for i in range(n):
	print(ans[i+1])

Measured memory_bytes: 9384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	z := getNextInt(scanner)
	w := getNextInt(scanner)

	aa := make([]int, n+1)

	aa[0] = w
	for i := 0; i < n; i++ {
		aa[i+1] = getNextInt(scanner)
	}

	ans := solve(n, z, w, aa)
	fmt.Fprintln(writer, ans)

	writer.Flush()
}

func solve(n, z, w int, aa []int) int {
	dp := make([][2]int, n+1)
	for i := 1; i < n; i++ {
		dp[i][0] = -1
		dp[i][1] = -1
	}
	return play(1, n, 0, aa, dp)
}

func play(i, n, xy int, aa []int, dp [][2]int) int {
	if i == n {
		return absint(aa[i] - aa[i-1])
	}
	if dp[i][xy] >= 0 {
		return dp[i][xy]
	}
	ans := absint(aa[n] - aa[i-1])
	for ii := i + 1; ii <= n; ii++ {
		if xy == 0 {
			ans = maxint(ans, play(ii, n, 1-xy, aa, dp))
			continue
		}
		ans = minint(ans, play(ii, n, 1-xy, aa, dp))
	}

	dp[i][xy] = ans

	return ans
}

func absint(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func maxint(a int, b int) int {
	if a > b {
		return a
	}
	return b
}
func minint(a int, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 1152
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int H, W, N;
  cin >> H >> W >> N;

  map<pair<int, int>, int> cnt;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    // cout << a << " " << b << endl;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (a - i >= 0 && a - i < H - 2 && b - j >= 0 && b - j < W - 2) {
          // cout << "* " << a - i << " " << b - j << endl;
          cnt[pair<int, int>(a - i, b - j)]++;
        }
      }
    }
  }

  long long ans[10];
  memset(ans, 0, sizeof(ans));
  long long filled = 0;
  for (auto t: cnt) {
    ans[t.second]++;
    filled++;
  }

  ans[0] = ((long long)H - 2) * ((long long)W - 2) - filled;
  for (int i = 0; i < 10; i++) {
    cout << ans[i] << endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 59760
#include <iostream>
#include <cmath>
#include <queue>
#include <string>
#include <algorithm>
#include <iomanip>

void extract(std::priority_queue<int>& S) {
    printf("%d\n", S.top());
    S.pop();
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::string s;
    std::priority_queue<int> S;
    while (true) {
        std::cin >> s;
        if (s == std::string("insert")) {
            int operand;
            std::cin >> operand;
            S.push(operand);
        } else if (s == std::string("extract")) {
            extract(S);
        } else {
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 7024
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
# define rep(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a % 2 == 0 || b % 2 == 0)No;
    else Yes;
    return 0;
}


Measured memory_bytes: 256
loop do
    m, f, r = gets.split.map(&:to_i)
    break if m == -1 && f == -1 && r == -1
    
    if m == -1 || f == -1
        puts "F"
        next
    end
    
    sum = m + f
    grade = case sum
    when 80..100
        "A"
    when 65..80
        "B"
    when 50..65
        "C"
    when 30..50
        if r >= 50
            "C"
        else
            "D"
        end
    else
        "F"
    end
    puts grade
end

Measured memory_bytes: 8588
#include "math.h"
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
int main()
{
    int n;
    cin >> n;
    int a[200005], p[200005] = {};
    rep(i, n) p[i] = i;
    rep(i, n)
    {
        cin >> a[i];
    }
    int start = n / 2;
    rep(i, n)
    {
        start = start + (i & 1 ? -1 : 1) * i;
        p[start] = i;
    }
    if (n & 1)
        reverse(p, p + n);
    /*rep(i, n)
    {
        cout << p[i] << " ";
    }
    cout << endl;
    */
    rep(i, n)
    {
        cout << a[p[i]] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3712
# N体の敵、K回の必殺技
N, K = map(int, input().strip().split(' '))
N_list = list(map(int, input().strip().split(' ')))
sorted_N = sorted(N_list, reverse=True)

# 必殺技で体力が多い敵からヤる
del sorted_N[:K]

if sorted_N ==[]:
  print(0)
else:
  print(sum(sorted_N))

Measured memory_bytes: 87772
n = int(input())
sa = input()
sb = input()
p = 1000000007

sal =list(sa)
sal.append("2")
rel =[0]

for i in range(n):
    if rel[-1] ==2:
        rel.append(0)
    elif sal[i] ==sal[i+1]:
        rel.append(2)
    else:
        rel.append(1)

rell =[s for s in rel if s != 0]

if rell[0] ==2:
    res = 6
else:
    res = 3

for j in range(1,len(rell)):
    if rell[j-1] ==2 and rell[j] ==2:
        res = res*3 % p
    elif rell[j-1] ==2 and rell[j] ==1:
        pass
    else:
        res = res*2 % p

print(res)

Measured memory_bytes: 3192
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;
     string s1,s2;
     cin>>s1>>s2;
     for(i=0;i<s1.size();i++){
        if(s1[i]!=s2[i]){
            l++;
        }
     }
     cout<<l<<endl;


     return EXIT_SUCCESS;
}


Measured memory_bytes: 3804
#include<iostream>
#include<list>
#include<vector>
#include<string>
#include<cmath>

using namespace std;

int main(){
    string s;
	cin >> s;
	int l = s.size();
    int pMine = l/2;
    int pCount = 0;
  
  	for (int i = 0; i < l; i++){
      if (s[i] == 'p'){
        pCount++;
      }
    }
    int scoreMax = pMine - pCount;
    cout << scoreMax << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;

signed main() {
    int n;
    int v[20] = {0};
    int c[20] = {0};
    int ans = 0;
    cin >> n;
    rep(i, n) {
        cin >> v[i];
    }
    rep(i, n) {
        cin >> c[i];
    }
    rep(i, n) {
        if (v[i] > c[i]) {
            ans += v[i] - c[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


vint d;
int data[5][3] = {
    {1868, 9, 8},
    {1912, 7, 30},
    {1926, 12, 25},
    {1989, 1, 8}, 
    {10000, 1, 1}
};


int main() {
    d.resize(3);
    
    vector<vector<int> > sec(4);
    for (int i = 0; i < 4; ++i) for (int j = 0; j < 3; ++j) sec[i].PB(data[i][j]);
    
    while (cin >> d[0] >> d[1] >> d[2]) {
        int it = upper_bound( ALL(sec), d ) - sec.begin();
        
        //cout << it << " : " << d;
        
        if (it == 0) puts("pre-meiji");
        else { 
            if (it == 1) d[0] -= 1867, cout << "meiji ";
            else if (it == 2) d[0] -= 1911, cout << "taisho ";
            else if (it == 3) d[0] -= 1925, cout << "showa ";
            else if (it == 4) d[0] -= 1988, cout << "heisei ";
            
            cout << d[0] << " " << d[1] << " " << d[2] << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 1216
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];

        int sum = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            sum = sum ^ A[i];
        }

        for (int i = 0; i < N; i++) {
            System.out.println(A[i]^sum);
        }



    }
}

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

using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
const int n = 26;
int c[n + 1];
int s[366][n + 1];
vector<int> get_scores (vector<int> t) {
    int ans = 0;
    vector<int> v;
    int lst[n + 1] = {0};
    for (int i = 0; i < (int) t.size(); ++i) {
        ans += s[i + 1][t[i]];
        lst[t[i]] = i + 1;
        for (int j = 1; j <= n; ++j) {
            ans -= c[j] * (i + 1 - lst[j]);
        }
        v.push_back(ans);
    }
    return v;
}
void solve() {
    int d;
    cin >> d;
    for (int i = 1; i <= n; ++i)
        cin >> c[i];
    for (int i = 1; i <= d; ++i)
        for (int j = 1; j <= n; ++j)
            cin >> s[i][j];
    vector<int> t(d);
    for (int i = 0; i < d; ++i) 
        cin >> t[i];
    auto ans = get_scores(t);
    for (auto &i: ans)
        cout << i << '\n';
}           

Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define int long long
#define rint register int
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for(; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
const int N = 4e6 + 233;
namespace {
  const int mo = 1e9 + 7;
  inline int add(int x, int y) {
    if((x += y) >= mo) x -= mo;
    return x;
  }
  inline int sub(int x, int y) {
    if((x -= y) < 0) x += mo;
    return x;
  }
  inline int mul(int x, int y) {
    return x * y % mo;
  }
  inline int pw(int a, int k, int mo) {
    int ans = 1;
    for(; k; k >>= 1, a = mul(a, a))
      if(k & 1) ans = mul(ans, a);
    return ans;
  }
  inline void U(int &x, int y) {
    x = add(x, y);
  }
}
int fac[N], fac_inv[N], dp[2333][2333];
int n, k;
inline void init(void) {
  fac[0] = 1;
  for(int i = 1; i < N; i ++)
    fac[i] = mul(fac[i - 1], i);
  fac_inv[N - 1] = pw(fac[N - 1], mo - 2, mo);
  for(int i = N - 2; i >= 0; i --)
    fac_inv[i] = mul(fac_inv[i + 1], i + 1);
}

inline int C(int n, int m) {
  if(n < m) return 0;
  else if(n == m || m == 0) return 1;
  else return mul(fac[n], mul(fac_inv[m], fac_inv[n - m]));
}

main(void) {
  init();
  read(n); read(k);
  if(k == 1) return cout << 1 << "\n", 0;
  dp[0][0] = 1;
  for(int i = 1; i <= n; i ++) {
    for(int j = 0; j <= i; j ++) {
      if(j) U(dp[i][j], mul(dp[i][j - 1], C(n * k - i - (j - 1) * (k - 1) - 1, k - 2)));
      U(dp[i][j], dp[i - 1][j]);
    }
  }
  int ans = mul(dp[n][n], fac[n]);
  cout << ans << "\n";
}


Measured memory_bytes: 99584
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    ll h, w;
    cin >> h >> w;

    if(w%3 == 0 || h%3 == 0){
        cout << 0 << endl;
        return 0;
    }

    if(h==2 && w==2){
        cout << 1 << endl;
        return 0;
    }

    ll res = inf;

    res = min(w*(h-2*h/3) - w*(h/3), res);
    res = min(h*(w-2*w/3) - h*(w/3), res);

    //cout << res << endl;

    reps(i, 1, h-1){
        ll maxi = 0;
        ll mini = inf;
        maxi = max(w*i, maxi);
        mini = min(w*i, mini);

        maxi = max(w/2 * (h-i), maxi);
        mini = min(w/2 * (h-i), mini);

        maxi = max((w - w/2) * (h-i), maxi);
        mini = min((w - w/2) * (h-i), mini);
        
        res = min(maxi-mini, res);
        //cout << maxi << " " << mini << endl;
        //cout << res << endl;
    }

    //cout << res << endl;

    reps(i, 1, w-1){
        ll maxi = 0;
        ll mini = inf;
        maxi = max(h*i, maxi);
        mini = min(h*i, mini);

        maxi = max(h/2 * (w-i), maxi);
        mini = min(h/2 * (w-i), mini);

        maxi = max((h - h/2) * (w-i), maxi);
        mini = min((h - h/2) * (w-i), mini);
        
        res = min(maxi-mini, res);
        //cout << maxi << " " << mini << endl;
        //cout << res << endl;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb  push_back
using namespace std;
typedef long long ll;
int main(){
    string s; cin >> s;
    s.pop_back();
    
	int n = s.size();
	
	if(n%2) n--,s.pop_back();
	
	int k = n/2;
	
//	cout << s.substr(0,k) << " "<<s.substr(k,k)<<endl;
	
	while(1){
		if(s.substr(0,k) == s.substr(k,k)){
			cout << 2*k;
			return 0;
		}
		else{
			s.pop_back();
			s.pop_back();
			k-=1;
		}
	}
		
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define LL long long
int main(){
	LL x,y,z,i,n;
	scanf("%lld",&n);
	x=2;
	y=1;
	if(n==1){
		printf("%lld\n",y);
		return 0;
	}
	for(i=2;i<=n;i++){
		z=x+y;
		x=y;
		y=z;
		if(n==i)	break;
	}
	printf("%lld\n",y);
	return 0;
}

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

#pragma GCC optimize("Ofast")
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
    int h,w;
    while(1){
        cin >> h >> w;
        if(h ==  0){
            break;
        }else
        {
            //in
            int ike[h][w];
            rep(i,0,h) {
                rep(j,0,w) {
                    cin >> ike[i][j];
                }
            }
            int ans = 0;
            rep(sx,0,w-2){
                rep(sy,0,h-2){
                    rep(gx,sx+2,w){
                        rep(gy,sy+2,h){
                            int innerSum = 0;
                            int innerH = 0;
                            int outerH = MOD;
                            rep(innerX,sx,gx+1){
                                rep(innerY,sy,gy+1){
                                    if(innerX == sx || innerX == gx){
                                        outerH = min(outerH, ike[innerY][innerX]);
                                    }else if(innerY == sy || innerY == gy){
                                        outerH = min(outerH, ike[innerY][innerX]);
                                    }else{
                                        innerH = max(innerH, ike[innerY][innerX]);
                                    }
                                }
                            }
                            /*
                            cout <<sx << " "<< sy << " ";
                            cout <<gx << " " << gy << " ";
                            cout << innerH << " " << outerH << "\n";
                            */
                            rep(innerX,sx,gx+1){
                                rep(innerY,sy,gy+1){
                                    if(innerX == sx || innerX == gx){
                                    }else if(innerY == sy || innerY == gy){
                                    }else{
                                        innerSum += max(0,outerH - ike[innerY][innerX]);
                                    }
                                }
                            }
                            
                            //  cout << "outerSum= " << innerSum << "\n";
                            
                            if(innerH < outerH){
                                ans = max(ans,innerSum);
                            }
                        }
                    }
                }
                
            }
            cout << ans << "\n";
        }

    }
    
}


Measured memory_bytes: 3076
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  if(n >= 1000) cout << "ABD" << endl;
  else cout << "ABC" << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p =map(int, input().split())
t = input()

def point(w):
    if w == 'r':
        return p
    elif w == 's':
        return r
    else:
        return s

total = 0
enable = [True for _ in range(n)]
for i in range(n):
    if enable[i]:
        #print(enable)
        total += point(t[i])
        if i+k < n and t[i] == t[i+k]:
            enable[i+k] = False

print(total)


Measured memory_bytes: 45552
#include<stack>
#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
const int N=2e5;
bitset<N>now;
bitset<N>tran;
bool vis[N];
int main(){
	int k;
	cin>>k;
	int s=1;
	while(!now[s]){
		now[s]=1;
		now[s+k]=1;
		s=(s*10)%k;
	}
	tran=now;
	queue<int>q;
	int dp;
	for(dp=1;dp<=50&&!now[0];dp++){
		bitset<N>cur=now;
		vector<int>chk;
		for(int i=0;i<k;i++){
			if(!vis[i]){
				chk.push_back(i);
			}
		}
		for(auto i:chk){
			if(cur[i]){
				now|=tran<<i;
				vis[i]=true;
			}
		}
		for(int i=0;i<k;i++){
			if(now[i]){
				now[i+k]=1;
			}
		}
		for(int i=k;i<k+k;i++){
			if(now[i]){
				now[i-k]=1;
			}
		}
	}
	cout<<dp;
}

Measured memory_bytes: 1400
n = int(input())
a = list(map(int, input().split()))

flg = None 
slash = 0
for i in range(n - 1):
    if a[i] == a[i + 1]:
        pass
    elif flg == None:
        flg = (a[i] < a[i + 1]) 
    elif flg == (a[i] < a[i + 1]):
        pass
    else:
        slash += 1
        flg = None 

print(slash + 1)



Measured memory_bytes: 15020