akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

#define INF 115141919
int N;
int X[100010], Y[100010];
int X0, Y0, X1, Y1, X2, Y2, X3, Y3;

bool f(int A, int x, int y) {
  if (abs(X0-x)+abs(Y0-y) <= A && abs(X1-x)+abs(Y1-y) <= A) return true;
  if (abs(X2-x)+abs(Y2-y) <= A && abs(X3-x)+abs(Y3-y) <= A) return true;
  return false;
}
bool f(int A) {
  for (int _=0; _<=2; _++) {
    if (_ == 1) swap(X1, X2), swap(Y1, Y2);
    if (_ == 2) swap(X1, X2), swap(Y1, Y2), swap(X0, X2), swap(Y0, Y2);
    bool b = true;
    for (int i=0; i<N; i++) {
      if (!f(A, X[i], Y[i])) {
        b = false;
        break;
      }
    }
    if (b) return true;
  }
  return false;
}

int main() {
  cin >> N;
  for (int i=0; i<N; i++) cin >> X[i] >> Y[i];

  int a = -INF, b = -INF, c = -INF, d = -INF;
  for (int i=0; i<N; i++) {
    int x = X[i], y = Y[i];
    if ( (x+y) > a) a =  (x+y), X0 = x, Y0 = y;
    if ( (x-y) > b) b =  (x-y), X1 = x, Y1 = y;
    if (-(x+y) > c) c = -(x+y), X2 = x, Y2 = y;
    if (-(x-y) > d) d = -(x-y), X3 = x, Y3 = y;
  }

  int lo = 0, hi = INF;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    if (f(mid)) hi = mid;
    else        lo = mid;
  }
  cout << hi << "\n";
  return 0;
}

Measured memory_bytes: 3788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		String[] str = br.readLine().split(" ");
		double x1 = Double.parseDouble(str[0]);
		double x2 = Double.parseDouble(str[2]);
		double y1 = Double.parseDouble(str[1]);
		double y2 = Double.parseDouble(str[3]);
		double distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
		BigDecimal bd = new BigDecimal(distance);
		BigDecimal bd2 = bd.setScale(8, BigDecimal.ROUND_HALF_UP);
		System.out.println(bd2.doubleValue());

	}
}

Measured memory_bytes: 24716
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
struct UnionFind{
    vector<int> data;

    UnionFind(int sz){
        data.assign(sz, -1);
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return(false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return(true);
    }

    int find(int k){
        if(data[k] < 0) return(k);
        return(data[k] = find(data[k]));
    }

    int size(int k){
        return(-data[find(k)]);
    }
};
int main(){
    int N,M;
    while(cin>>N>>M,N)
    {
        vector<int>h(N);
        vector<pair<int,int> >hh(N);
        for(int i=0;i<N;i++)
        {
            cin>>h[i];
            hh[i]=make_pair(h[i],i);
        }
        sort(hh.begin(),hh.end());
        reverse(hh.begin(),hh.end());
        vector<pair<pair<int,int>,pair<int,int> > >E;
        for(int i=0;i<M;i++)
        {
            int a,b,c;cin>>a>>b>>c;
            a--,b--;
            E.push_back(make_pair(make_pair(min(h[a],h[b]),-c),make_pair(a,b)));
        }
        sort(E.begin(),E.end());
        reverse(E.begin(),E.end());
        UnionFind uf(N);
        int id=0,H=0;
        for(int i=0;i<N;i++)
        {
            int nowh=hh[i].first;
            while(id<M&&E[id].first.first>=nowh)
            {
                uf.unite(E[id].second.first,E[id].second.second);
                id++;
            }
            if(uf.size(hh[i].second)<=i)
            {
                H=i;
            }
        }
        if(H==N-1)
        {
            cout<<0<<endl;
            continue;
        }
        H=hh[H+1].first;
        vector<pair<pair<int,int>,pair<int,int> > >F;
        for(pair<pair<int,int>,pair<int,int> >p:E)
        {
            F.push_back(make_pair(make_pair(min(H,p.first.first),p.first.second),p.second));
        }
        sort(F.begin(),F.end());
        reverse(F.begin(),F.end());
        long long ans=0;
        UnionFind P(N);
        for(pair<pair<int,int>,pair<int,int> >p:F)
        {
            if(P.unite(p.second.first,p.second.second))
            {
                ans-=p.first.second;
            }
        }
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 4132
def hoge():
  from itertools import permutations
  N, M, R = map(int, input().split())
  r = map(int, input().split())
  inf = float('inf')
  d = [[inf] * N for i in range(N)]

  for i in range(N):
      d[i][i] = 0

  for i in range(M):
      a, b, c = map(int, input().split())
      a -= 1
      b -= 1
      t = min(c, d[a][b])
      if d[a][b] > c:
          d[a][b], d[b][a] = t, t


  for k in range(N):
      for i in range(N):
          for j in range(N):
            t = d[i][k] + d[k][j]
            if d[i][j] > t:
              d[i][j] = t


  ans = inf
  for i in permutations(r):
      temp = 0
      for j in range(len(i)-1):
          temp += d[i[j]-1][i[j+1]-1]
          if temp > ans:
              break
      if ans > temp:
        ans = temp
      # ans = min(ans, temp)

  print(ans)
hoge()


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

#define PB push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

const int inf = 1e9;
int D;
vl c, ans;
vvl s;

void init() {
    cin >> D;
    ans.assign(D, 0);
    c.resize(26);
    s.assign(D, vl(26));
    rep(t, 26) cin >> c[t];
    rep(d, D) rep(t, 26) {
        cin >> s[d][t];
    }
}

ll evaluate(vl typeOfDays, int numDays = D) {
    ll score = 0;
    vl lasts(26, 0);
    rep(d, numDays) {
        score += s[d][typeOfDays[d]];
        lasts[typeOfDays[d]] = d + 1;
        rep(t, 26) {
            score -= c[t] * (d - lasts[t] + 1);
        }
    }
    return score;
}

// random in range [a, b]
ll rand(int a, int b) {
    random_device rd;
    mt19937 mt(rd());
    uniform_int_distribution<> rnd(a, b);
    return rnd(mt);
}
ll rand(int b) {
    return rand(0, b);
}

void solve() {
    rep(d,D/2) {
        ll mx = -inf;
        vl cand = ans;
        rep(t1,26) rep(t2,26) {
            cand[2*d] = t1;
            cand[2*d+1] = t2;
            ll sc = evaluate(cand, 2*d+2);
            if (sc > mx) {
                mx = sc;
                ans = cand;
            }
        }
    }
    ll mx = -inf;
    vl cand = ans;
    rep(t,26) {
        cand[D-1] = t;
        ll sc = evaluate(cand);
        if (sc > mx) {
            mx = sc;
            ans = cand;
        }
    }
    cerr << evaluate(ans) << endl;
}

void output() {
    rep(d,D) cout << ans[d]+1 << endl;
}

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


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,w;
	cin>>n>>w;
	ll w1=0;
	vector<ll>a[4];
	for(ll i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		if(i==0){
			w1=x;
		}
		a[x-w1].push_back(y);
	}
	for(ll i=0;i<4;i++){
		sort(a[i].begin(),a[i].end());
		a[i].push_back(0);
		reverse(a[i].begin(),a[i].end());
		for(ll j=1;j<a[i].size();j++){
			a[i][j]=a[i][j]+a[i][j-1];
		}
	}
	ll ans=0;
	for(ll i=0;i<a[0].size();i++){
		for(ll j=0;j<a[1].size();j++){
			for(ll k=0;k<a[2].size();k++){
				for(ll l=0;l<a[3].size();l++){
					if(i*w1+j*(w1+1)+k*(w1+2)+l*(w1+3)>w){
						continue;
					}
					ans=max(ans,a[0][i]+a[1][j]+a[2][k]+a[3][l]);
				}
			}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> x(101, 0);
  x.at(1) = 1;
  for(int i = 2; i <= n; i++){
    int now = i, div = 2;
    while(now > 1){
      if(now % div == 0){
        x.at(div)++;
        now /= div;
      }
      else div++;
    }
  }
  
  long long c2 = 0, c2notc4 = 0, c4 = 0, c14 = 0, c24 = 0, c74 = 0;
  for(int i = 2; i <= 100; i++){
    if(x.at(i) >= 2 && x.at(i) <= 3) c2notc4++;
    if(x.at(i) >= 2) c2++;
    if(x.at(i) >= 4) c4++;
    if(x.at(i) >= 14) c14++;
    if(x.at(i) >= 24) c24++;
    if(x.at(i) >= 74) c74++;
  }
  
  long long ans = 0;
  ans += c74;
  ans += (c2 - 1) * c24;
  ans += (c4 - 1) * c14;
  ans += (c4 * (c4 - 1) * (c2 - 2) / 2);
  
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 101
#define INF 999999
#define WHITE 0
#define BLACK 1

void print(int sum){
  printf("%d\n",sum);
}

void prim(int n,int w[N][N]){
  int u,v,i,d[N],pi[N],color[N],mincost,sum=0;
  for(u=0;u<n;u++){
    d[u]=INF;
    pi[u]=0;
    color[u]=WHITE;
  }
  d[0]=0;

  while(1){
    mincost=INF;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
        mincost=d[i];
        u=i;
      }
    }
    if(mincost==INF)break;
    color[u]=BLACK;

    for(v=0;v<n;v++){
      if(color[v]!=BLACK && w[u][v]<d[v] && w[u][v]!=-1){
        pi[v]=u;
        d[v]=w[u][v];
      }
    }
  }
  for(i=0;i<n;i++)sum+=d[i];
  print(sum);
}
int main(){
  int n,Adj[N][N],i,j,k,min,m,P[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    P[i]=INF;
    for(j=0;j<n;j++){
      scanf("%d",&Adj[i][j]);
    }
  }
  prim(n,Adj);
  return 0;
}



Measured memory_bytes: 2112
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
a, b = MAP()
if a + b == 15:
	print("+")
elif a * b == 15:
	print("*")
else:
	print("x")


Measured memory_bytes: 5200
import sys
from math import sqrt
from bisect import bisect_right


def _i(): return int(sys.stdin.readline().strip())


def main():
    n = _i()
    sqn = int(sqrt(n))
    p = [True] * (sqn+1)
    d = {}
    for i in range(2, sqn + 1):
        if not p[i]:
            continue

        for j in range(i+i, sqn+1, i):
            p[j] = False

        while n % i == 0:
            d[i] = d.get(i, 0) + 1
            n //= i

    c = 0 if n == 1 else 1
    arr = [1, 3, 6, 10, 15, 21, 28, 36]
    for v in d.values():
        c += bisect_right(arr, v)
    return c


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 93256
#include<bits/stdc++.h>
using namespace std;
int64_t mod=1000000007;
int64_t pow(int64_t x,int64_t y) {
  int64_t z;
  if (y==0) return 1;
  else {
    z=(((pow(x,y/2)+mod)%mod)*((pow(x,y/2)+mod)%mod)+mod)%mod;
    if (y%2==1) z=(z*x+mod)%mod;
    return (z+mod)%mod;
  }
}
int main() {
  int64_t n,i,j,b,c,l=1,ans=0;
  bool f;
  cin>>n;
  vector<int64_t> a(n),p;
  p.push_back(2);
  for(i=3;i<=1000;i+=2){
    f=true;
    for(j=0;j<p.size();j++){
      if(i%p.at(j)==0) {
        f=false;
        j=p.size();
      }
    }
    if(f==true) p.push_back(i);
  }
  vector<int64_t> q(p.size());
  set<int64_t> s;
  for(i=0;i<n;i++) {
    cin>>a.at(i);
    ans=(ans+pow(a.at(i),mod-2)+mod)%mod;
    b=a.at(i);
    for(j=0;j<p.size();j++){
      c=0;
      while(b%p.at(j)==0){
        b/=p.at(j);
        c++;
      }
      if(c>q.at(j)) q.at(j)=c;
    }
    if(b>1 && s.count(b)==false) {
      s.insert(b);
      l=(l*b+mod)%mod;
    }
  }
  for(i=0;i<p.size();i++) if(q.at(i)>0) l=(l*pow(p.at(i),q.at(i))+mod)%mod;
  ans=(ans*l+mod)%mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
ll fact_[5000000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 5000000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
H a[300000];
signed main() {
	cin >> n;
	ll ans = -1, sum = -1;
	for (int i = 0; i < n; i++) {
		cin >> a[i].x >> a[i].y;
		sum += a[i].x * a[i].y;
		ans += a[i].y;
	}
	cout << ans + sum / 9 << endl;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){
  int A,B;
  cin >> A >> B;
  int ans = 0;
  FOR(i,A,B+1){
    if(i/10000 == i%10 && i/1000 % 10 == i / 10 % 10){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  let
    n' = n - 1 :: Int
  print . sum . map (n' `div`) $ [1 .. n']

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 3780
#include<iostream>
#include<map>
using namespace std;

#define MAX 3000
#define MAX_X 5001
#define MAX_Y 5001
struct Point{
	int x,y;
	Point():x(0),y(0){}
	Point(int x, int y):x(x),y(y){}
	bool operator<(const Point &t)const{
		if( x < t.x )
			return true;
		if( x == t.x  && y < t.y )
			return true;
		return false;
	}
	bool operator==(const Point &t)const{
		return x == t.x && y == t.y;
	}
};
ostream &operator<<(ostream &os, const Point &t){
	os << '(' << t.x << ',' << t.y << ')';
	return os;
}
int main(){
	while(true){
		int n;
		int ans = 0;
		map< Point, int > xy;
		Point p[MAX];
		
		scanf("%d", &n);
		if( n == 0 ) break;
		for(int i = 0; i < n; ++i){
			scanf("%d%d", &p[i].x, &p[i].y);
			xy[ p[i] ] = 1;	
		}
		map<Point,int>::iterator it = xy.begin();
		while(it != xy.end()){
			//cout << it->first.x << ',' << it->first.y << endl; 
			++it;
		}

		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				if( i != j ){
					int dx = p[j].x - p[i].x;
					int dy = p[j].y - p[i].y;
					if( dx >= 0 && dy <= 0 ){
						dy = -dy;
						Point p2(p[j].x + dy, p[j].y + dx);
						Point p3(p[i].x + dy, p[i].y + dx);

						//cout << p[i] << p[j] << p2 << p3 << endl;

						if( xy.find( p2 ) != xy.end() && xy.find( p3 ) != xy.end() ){
							ans = max( ans, dx*dx + dy*dy );
						}
					}
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1044
#include <iostream>
#include <string>
using namespace std;
int main() {
	int W,a,b;
	cin>>W>>a>>b;
		
		if(a<=b+W &&  b<=a+W){
			cout<<"0";}
	
		if(b>a && a>=b+W ){
			if(b-(a+W)>=1){
				cout<<b-(a+W);}}
		if(b>a && b>=a+W){
			if(b-(a+W)>=1){
				cout<<b-(a+W);}}
		if(a>b && a>=b+W){
			if(a-(b+W)>=1){
			cout<<a-(b+W);}}
		if(a>b && b>=a+W){
			if(a-(b+W)>=1){
			cout<<a-(b+W);}}	
			
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <bitset>
#define N 210000
#define M 210000
using namespace std;
int ans,n;
int sum;
int a[2100];
bitset<4100000> f;
int main()
{
	scanf("%d",&n);
	ans=-2147483647;
	f.reset();
	f|=1;
	sum=0;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		ans=max(a[i],ans);
		sum+=a[i];
		f=(f<<a[i])|f;
	}
	if(ans<sum-ans)
	{
		for(int i=(sum+1)/2;;i++)
			if(f.test(i)){ ans=i; break; }
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2304
import bisect
import sys
import itertools
import queue
input = sys.stdin.readline
sys.setrecursionlimit(100000)
# mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 

def f(N):
    c = 0
    for n in range(1, int(N ** 0.5) + 1):
        if N % n == 0:
            c += 1
            if n * n != N:
                c += 1
    return c - 1


def main():
    N = int(input())

    res = 0
    res += f(N - 1)

    for n in range(1, int(N ** 0.5) + 1):
        if N % n == 0:
            if n != 1:
                M = N
                while M % n == 0:
                    M //= n
                if M % n == 1:
                    res += 1
        
            if n * n != N:
                n = N // n
                M = N
                while M % n == 0:
                    M //= n
                if M % n == 1:
                    res += 1

    print(res)


if __name__ == "__main__":
    main()


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n, m, k, a;
  cin >> n >> m;
  vector<int> bin(m);
  for(int i = 0; i < n; ++i)
  {
    cin >> k;
    for(int j = 0; j < k; ++j)
    {
      cin >> a;
      bin[a - 1]++;
    }
  }

  int ans = 0;
  for(int i = 0; i < m; ++i)
  {
    ans += bin[i] == n;
  }
  cout << ans;

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3656
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

cnt = [[float('inf')]*w for _ in range(h)]
if s[0][0] == '.':
    cnt[0][0] = 0
else:
    cnt[0][0] = 1

for i in range(h):
    for j in range(w):
        for dy, dx in [[1, 0], [0, 1]]:
            x = j+dx
            y = i+dy
            if x >= w or y >= h:
                continue
            if s[i][j] == s[y][x]:
                cnt[y][x] = min(cnt[y][x], cnt[i][j])
            else:
                cnt[y][x] = min(cnt[y][x], cnt[i][j] + 1)

if s[-1][-1] == '#':
    cnt[-1][-1] += 1
print(cnt[-1][-1]//2)

Measured memory_bytes: 3188
#include<iostream>

using namespace std;

class BinaryTree
{
private:
    struct Node
    {
        int parent,leftChild,rightChild;
        Node(){parent=leftChild=rightChild=NIL;}
    };
    Node* nodes;
    
public:
    const static int NIL=-1;

    BinaryTree(int nodeSum);
    ~BinaryTree();

    void PreParse(int nodeId);
    void InParse(int nodeId);
    void PostParse(int nodeId);

    void SetParent(int nodeId,int parent){nodes[nodeId].parent=parent;}
    int GetParent(int nodeId)const{return nodes[nodeId].parent;}
    void SetLeftChild(int nodeId,int left){nodes[nodeId].leftChild=left;}
    int GetLeftChild(int nodeId)const{return nodes[nodeId].leftChild;}
    void SetRightChild(int nodeId,int right){nodes[nodeId].rightChild=right;}
    int GetRightChild(int nodeId)const{return nodes[nodeId].rightChild;}
};

BinaryTree::BinaryTree(int nodeSum)
{
    nodes=new Node[nodeSum];
}

BinaryTree::~BinaryTree()
{
    delete nodes;
}

void BinaryTree::PreParse(int nodeId)
{
    if(nodeId==NIL)return;
    cout<<" "<<nodeId;
    PreParse(nodes[nodeId].leftChild);
    PreParse(nodes[nodeId].rightChild);
}

void BinaryTree::InParse(int nodeId)
{
    if(nodeId==NIL)return;
    InParse(nodes[nodeId].leftChild);
    cout<<" "<<nodeId;
    InParse(nodes[nodeId].rightChild);
}

void BinaryTree::PostParse(int nodeId)
{
    if(nodeId==NIL)return;
    PostParse(nodes[nodeId].leftChild);
    PostParse(nodes[nodeId].rightChild);
    cout<<" "<<nodeId;
}


int main()
{
    int nodeSum;
    cin>>nodeSum;
    BinaryTree bt(nodeSum);

    for(int i=0;i<nodeSum;i++)
    {
        int nodeId,leftChild,rightChild;
        cin>>nodeId>>leftChild>>rightChild;
        bt.SetLeftChild(nodeId,leftChild);
        bt.SetRightChild(nodeId,rightChild);
        if(leftChild!=BinaryTree::NIL)bt.SetParent(leftChild,nodeId);
        if(rightChild!=BinaryTree::NIL)bt.SetParent(rightChild,nodeId);
    }
    
    int root=-1;
    for(int i=0;i<nodeSum;i++)if(bt.GetParent(i)==BinaryTree::NIL)root=i;

    for(int i=0;i<3;i++)
    {
        if(i==0)
        {
            cout<<"Preorder"<<endl;
            bt.PreParse(root);
            cout<<endl;
        }
        else if(i==1)
        {
            cout<<"Inorder"<<endl;
            bt.InParse(root);
            cout<<endl;
        }
        else
        {
            cout<<"Postorder"<<endl;
            bt.PostParse(root);
            cout<<endl;
        }
        
    }

    return 0;
}


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

int main(){
    
    int A,B,C,K;
    cin>>A>>B>>C>>K;

    if (K-A>=0){
        if(K-A-B>=0){
            if(K-A-B-C>=0){
                cout<<A+(-1)*C<<endl;
            }
            else{
                cout<<A+(-1)*(K-A-B)<<endl;
            }
        
        }
        else {
            cout<<A<<endl;
        }

    }
    else {
        cout<<K<<endl;
    }

}

Measured memory_bytes: 3596
#include <stdio.h>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

char st1[200];
char st2[200];
long long gcd(long long a,long long b)
{
    return b==0?a:gcd(b,a%b);
}

int main()
{
    long long a,b;
    scanf("%lld%lld",&a,&b);
    printf("%lld\n",a*b/gcd(a,b));

}


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

struct process {
	char name[11];
	int time;
	int ans;
};

struct process pro[100001], ans_pro[100001];

int main(void) {

	int n, q, i, j, co = 0, coo = 0, cot = 0, co_zero = 0, co_time = 0, co_end = 0, co_ans = 0;
	struct process k;

	scanf("%d %d", &n, &q);
	for (i = 0; i < n; i++) {
		scanf("%s %d", pro[i].name, &pro[i].time);
	}

	while (n != co_zero) {
		coo = co_zero;
		cot = 0;
		for (i = 0; i < n - coo; i++) {
			if (pro[i].time > q) {
				co_time += q;
				pro[i].time -= q;
				pro[i - cot] = pro[i];
			}
			else {
				co_time += pro[i].time;
				ans_pro[co_ans].ans = co_time;
				strcpy(ans_pro[co_ans].name, pro[i].name);
				co_ans++;
				co_zero++;
				cot++;
			}
		}
	}
	for (i = 0; i < n; i++) {
		printf("%s %d\n", ans_pro[i].name, ans_pro[i].ans);
	}
	return 0;
}

Measured memory_bytes: 2568
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
def lcm(a,b,g):
    return a*b/g

while 1:
    try:
        a,b=map(int,raw_input().split())
        g=gcd(a,b)
        print g,lcm(a,b,g)
    except:
        break

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int N;
vector<P> g[100100];
vector<int> ans(100100);
set<int> color;

void solve(int u,int c,int pa=-1){
    int tmp=1;
    for(auto e:g[u]){
        int ind=e.second;
        int v=e.first;
        if(v==pa) continue;
        if(tmp==c) tmp++;
        ans[ind]=tmp;
        color.insert(tmp);
        solve(v,tmp,u);
        tmp++;
    }
}

int main(){
    cin >> N;
    for(int i=0;i<N-1;i++){
        int a,b; cin >> a >> b;
        a--;b--;
        g[a].push_back({b,i});
        g[b].push_back({a,i});
    }
    solve(0,0);
    cout << color.size() << endl;
    for(int i=0;i<N-1;i++){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    if (a[0] != 0)
    {
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    for (ll i = 0; i < n - 1; i++)
    {
        if (a[i + 1] == 1 || a[i + 1] - a[i] == 1)
        {
            ans++;
        }
        else
        {
            ans += a[i + 1];
        }
        if (a[i + 1] - a[i] > 1)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    vi a(3);
    REP(i, 3) cin >> a[i];

    sort(ALL(a));

    cout << 10 * a[2] + a[0] + a[1] << endl;

}

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

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

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;

struct Dijk{
  // solve(s, g) or solve(s).
  // show d and p.
  typedef double T;
  const T tinf = 1e18;
//##########################################
  typedef pair<T,int> pti;
  typedef pair<int, T> pit;
  int n;
  vector<vector<pit> > E;
  vector<T> d;
  vi p;
  void init(const vector<vector<pit> >&e){
    n=sz(e);
    E=e;
    d.resize(n);
    p.resize(n);
  }
  void o(int S,int G){
    FOR(i,0,n){
      d[i] = (i==S) ? 0 : tinf;
      p[i] = -1;
    }
    priority_queue<pti,vector<pti>,greater<pti>>Q;
    Q.push(pti(0, S));
    pti t;
    vector<bool>F(n);
    T f;
    int c=0,s;
    while(!Q.empty()){
      t=Q.top(); Q.pop();
      f=t.fi; s=t.se;
      if(F[s])continue;
      F[s]=1;
      c++;
      if(c==n||s==G)break;
      each(itr,E[s]){
        int ff=itr->fi;
        T ss=itr->se;
        if((!F[ff])&&(f+ss<d[ff])){
          d[ff]=f+ss;
          p[ff]=s;
          Q.push(pti(f+ss,ff));
        }
      }
    }
  }
  T solve(int s,int g){o(s,g);return d[g];}
  void add(int a, int b, T l){E[a].pb(pit(b, l));} // a to b :: l
  void solve(int s){o(s,-1);}
};
ll x, y, n, r;
vector<pair<pll, ll> > v;
vector<vector<pair<int, double> > > G;
Dijk dijk;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  FOR(i, 0, 2){
    cin >> x >> y;
    v.pb(mp(mp(x, y), 0));
  }
  cin >> n;
  FOR(i, 0, n){
    cin >> x >> y >> r;
    v.pb(mp(mp(x, y), r));
  }
  G.resize(n+2);
  FOR(i, 0, n+2)FOR(j, 0, n+2){
    double dx = v[i].fi.fi - v[j].fi.fi, dy = v[i].fi.se - v[j].fi.se;
    G[i].pb(mp(j, max(0.0, sqrt(dx*dx + dy * dy) - v[i].se - v[j].se)));
  }
  dijk.init(G);
  dout(dijk.solve(0, 1));
  return 0;
}

Measured memory_bytes: 38384
x, y = input().split()
a = [i for i in range(10, 16)]
b = ['A', 'B', 'C', 'D', 'E', 'F']
d = dict(zip(b, a))
x = d[x]
y = d[y]
print('<' if x < y else '=' if x == y else '>')

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define REP(i, a, b) for(int i = (a); i < int(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef int weight;
typedef pair<weight, int> P;
constexpr weight INF = (1 << 29);

struct edge {
	int to;
	int cap;
	weight cost;
	int rev;
	edge(int to_, int cap_, weight cost_, int rev_):to(to_), cap(cap_), cost(cost_), rev(rev_){};
};

vector<vector<edge>> G;

void init(int V) {
	G.assign(V, vector<edge>());
}

void add_edge(int from, int to, int cap, weight cost) {
	G[from].emplace_back(to, cap, cost, G[to].size());
	G[to].emplace_back(from, 0, -cost, G[from].size() - 1);
}

weight min_cost_flow(int s, int t, weight f) {
	const int n = G.size();
	weight res = 0;
	vector<int> prevv(n), preve(n);
	while(f > 0) {
		vector<weight> dist(n, INF);
		dist[s] = 0;

		while(true) {
			bool update = false;
			for(int v = 0; v < n; ++v) {
				for(unsigned i = 0; i < G[v].size(); ++i) {
					const auto &e = G[v][i];
					if(e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
						dist[e.to] = dist[v] + e.cost;
						prevv[e.to] = v;
						preve[e.to] = i;
						update = true;
					}
				}
			}
			if(!update) break;
		}

		if(dist[t] == INF) return -1;

		int d = f;
		for(int v = t; v != s; v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}

		f -= d;
		res += d * dist[t];
		for(int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}

	return res;
}


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

	int m, n, k;
	cin >> m >> n >> k;

	vector<int> w(n);
	for(auto &e : w) cin >> e;

	init(k + 1);

	vector<int> prev(n, -1);
	int ans = 0;

	rep(i, k) {
		int a;
		cin >> a;
		--a;

		ans += w[a];

		add_edge(i, i + 1, INF, 0);
		if(prev[a] != -1) {
			if(prev[a] + 1 == i) {
				ans -= w[a];
			}
			else {
				add_edge(prev[a] + 1, i, 1, -w[a]);
			}
		}
		prev[a] = i;
	}

	cout << ans + min_cost_flow(0, k, m - 1) << endl;

	return EXIT_SUCCESS;
}

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


int main(){
    int n, k, ans = 0;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n){
        int x;
        cin >> x;
        int distk = abs(x-k);
        ans += distk < x ? 2*distk : 2*x;
    }
    cout << ans << endl;

}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    Scanner sc;

    int h, w, c;
    int[][] p;
    boolean[][] done; // biribiri用フラグ

    public static void main(String[] args) {
        new Main().run();
    }

    Main() {
        sc = new Scanner(System.in);
    }

    boolean init() {
        h = sc.nextInt();
        w = sc.nextInt();
        c = sc.nextInt();

        if (h == 0 && w == 0 && c == 0) return false;

        p = new int[h][w];
        for (int i = 0; i < h; i++) 
            for (int j = 0; j < w; j++) 
                p[i][j] = sc.nextInt();

        return true;
    }

    void debug_p() {
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) 
                System.out.print(p[i][j] + " ");
            System.out.println("");
        }
    }

    void run() {
        while (init()) {
            System.out.println(solve());
        }
    }

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

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

    int count(int y, int x) {
        done = new boolean[h][w];
        return count_dfs(y, x);
    }

    int count_dfs(int y, int x) {
        if (p[y][x] != c) return 0;
        done[y][x] = true;
        int cnt = 1;
        for (int i = 0; i < 4; i++) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (0 <= ny && ny < h && 0 <= nx && nx < w && !done[ny][nx]) {
                cnt += count_dfs(ny, nx);
            }
        }
        return cnt;
    }

    void change_color(int color) {
        done = new boolean[h][w];
        biribiri(0, 0, color);
//        debug_p();
    }

    void biribiri(int y, int x, int color) {
        done[y][x] = true;
//        System.out.printf("%d,%d: %d\n", x, y, color);
        int prev = color;
        for (int i = 0; i < 4; i++) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (0 <= ny && ny < h && 0 <= nx && nx < w && p[y][x] == p[ny][nx] && !done[ny][nx]) {
                biribiri(ny, nx, color);
            }
        }
        p[y][x] = color;
    }

    int max_panel(int time) {
//        System.out.printf("%d ", time);
        if (time == 4) {
            int cnt;
            int _p[][] = new int[h][w];
            for (int i = 0; i < h; i++)
                for (int j = 0; j < w; j++)
                    _p[i][j] = p[i][j];
            change_color(c);
            cnt = count(0, 0);
//            debug_p();
            for (int i = 0; i < h; i++) 
                for (int j = 0; j < w; j++)
                    p[i][j] = _p[i][j];
//            System.out.printf("%d\n", cnt);
            return cnt; 
        }
        int cnt = 0;
        for (int color = 1; color <= 6; color++) {
            int _p[][] = new int[h][w];
            for (int i = 0; i < h; i++)
                for (int j = 0; j < w; j++)
                    _p[i][j] = p[i][j];
            change_color(color);
            cnt = Math.max(cnt, max_panel(time+1));
            for (int i = 0; i < h; i++)
                for (int j = 0; j < w; j++)
                    p[i][j] = _p[i][j];
        }
        return cnt;
    }
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N, K; cin >> N >> K;
  vector<ll> a(N); rep(i, N) cin >> a[i];
  ll ans = INF;

  ll d, a1, a2;
  rep(i, N - K + 1) {
    d = a[i + K - 1] - a[i];
    a1 = d + abs(a[i + K - 1]);
    a2 = d + abs(a[i]);
    ans = min(ans, min(a1, a2));
  }
  
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 4040
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <set>

using namespace std;

#define sp ' '
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "
#define TEST cout << "TEST" << endl

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

const long long int MOD = 1e9 + 7;
const long long int INF = 2e9 + 13;
const long long int mINF = -2e9 - 13;
const double PI = acos(-1.0);
const double EPS = 1e-9;

ll mx(ll x, ll y){ return (x>y?x:y); }
ll mn(ll x, ll y){ return (x<y?x:y); }

void max_self(ll &x, ll y){ x = mx(x, y); }
void min_self(ll &x, ll y){ x = mn(x, y); }
void add(ll &x, ll y){ x += (y%MOD); x %= MOD; }
void multipy(ll &x, ll y){ x *= (y%MOD); x %= MOD; }

ll mul(ll a, ll b){ return (((a%MOD)*(b%MOD))%MOD); }

ll us(ll n, ll x, ll m){
    if(x == 0) return 1;
    ll a = us(n, x>>1, m);
    return (((a*a)%m)*(x&1?n:1))%m;
}

ll N, K;

struct M{
    vvll t;
    M(){t.resize(N, vll(N));}
    M operator* (const M& b) const{
        M c = M();
        for(ll i = 0; i < N; ++i){
            for(ll k = 0; k < N; ++k){
                for(ll j = 0; j < N; ++j){
                    add(c.t[i][j], mul(t[i][k], b.t[k][j]));
                }
            }
        }
        return c;
    }
};

int main(int argc, char **argv){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    //freopen(".gir", "r", stdin);
    //freopen(".cik", "w", stdout);
    
    cin >> N >> K;
    vvll can(N, vll(N));
    forn(N, i) forn(N, j) cin >> can[i][j];
    M answer = M();
    forn(N, i) answer.t[i][i] = 1;
    M m = M();
    m.t= can;

    while(K){
        if(K&1){ answer = answer*m; }
        m = m*m;
        K >>= 1;
    }

    ll total = 0;
    forn(N, i) forn(N, j) add(total, answer.t[i][j]);
    cout << total << endl;

    return 0;
}

//cikisir



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll mini = LONG_LONG_MAX;
    ll sum = 0;
    vector<ll> A;
    cin >> N;
    A.resize(N);
    rep(i, N) {
        ll temp;
        cin >> temp;
        A[i] = temp + (i > 0 ? A[i - 1] : 0);
        sum += temp;
    }
    rep(i, N - 1) {
        ll sunuke = A[i];
        ll arai = sum - sunuke;
        mini = min(mini, abs(sunuke - arai));
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

void solve() {
  static const int MOD = 1e9 + 7;
  static const int INV2 = MOD - MOD / 2;
  int n, k;
  cin >> n >> k;
  int result = 0;
  for (int i = k; i <= n + 1; ++i) {
    result = (result + (n - i + 1LL) * i + 1) % MOD;
  }
  cout << result << "\n";
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int o_o = 1;
  if (!o_o)
    cin >> o_o;
  for (; o_o; --o_o)
    solve();
  return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535897932;
const ll MOD = 1000000007;

int main()
{
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int start = h1 * 60 + m1;
    int end = h2 * 60 + m2;
    cout << end - start - k << endl;
    return 0;
}

Measured memory_bytes: 3640
#!/usr/bin/env python
#coding:utf-8

def input_strs():
    return input().split(" ")

def input_nums():
    return [int(i) for i in input_strs()]


n = int(input())
k = int(input())
x = int(input())
y = int(input())

if n <= k:
    print(x * n)
else:
    print(k * x + (n-k) * y)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const
#define int ll

inline
int getint(){
	re int num;
	re char c;
	re bool f=0;
	while(!isdigit(c=gc()))f^=c=='-';num=c^48;
	while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
	return f?-num:num;
}

inline
void outint(ll a){
	static char ch[23];
	if(a==0)pc('0');
	while(a)ch[++ch[0]]=a-a/10*10,a/=10;
	while(ch[0])pc(ch[ch[0]--]^48);
}

cs ll INF=0x3f3f3f3f3f3f3f3f;
cs int N=1005;
cs int dx[4]={1,-1,0,0};
cs int dy[4]={0,0,-1,1};
cs char s[4]={'R','L','D','U'};

int n;
ll x[N],y[N];
vector<ll> len;
bool flag;

signed main(){
	n=getint();
	for(int re i=1;i<=n;++i){
		x[i]=getint(),y[i]=getint();
		if(i^1){
			if(((x[i]^y[i])&1)!=flag)return puts("-1"),0;
		}
		else flag=(x[i]^y[i])&1;
	}
	for(int re i=0;i<=30;++i){
		len.push_back(1ll<<i);
	}
	if(flag==0)len.push_back(1);
	
	sort(len.rbegin(),len.rend());
	
	outint(len.size()),pc('\n');
	for(int re i=0;i<len.size();++i)
	outint(len[i]),pc(' ');
	pc('\n');
	
	for(int re i=1;i<=n;++i){
		ll xx=x[i],yy=y[i];
		for(int re j=0;j<len.size();++j){
			int pos;
			ll minn=INF;
			for(int re k=0;k<4;++k){
				ll tmpx=xx-len[j]*dx[k];
				ll tmpy=yy-len[j]*dy[k];
				if(abs(tmpx)+abs(tmpy)<minn){
					minn=abs(tmpx)+abs(tmpy);
					pos=k;
				}
			}
			pc(s[pos]);
			xx=xx-len[j]*dx[pos];
			yy=yy-len[j]*dy[pos];
		}pc('\n');
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

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

  int ans;

  ans = (K - (K / 2)) * (K / 2);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1e17
#define int long long

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() {
  cerr << "]\n";
}
template<typename T, typename ...Args> void DBG(T first, Args... args) {
  cerr << first; if (sizeof...(args))cerr<<", "; DBG(args...);
}

/////////////////////////// GLOBAL ///////////////////////////

/////////////////////////// GLOBAL ///////////////////////////
void solve() {
  string s;
  cin>>s;
  int n = s.length();
  int count = 0;
  int maximum = 0;
  for(int i=0;i<n;i++){
    if(s[i] == 'R'){
      count++;
      if(count>maximum) maximum = count;
    }
    else if(s[i] == 'S'){
      if(count > maximum) maximum = count;
      count = 0;
    }
  }
  cout<<maximum<<"\n";
}

int32_t main() {
  #ifndef ONLINE_JUDGE
  clock_t tStart = clock();
  freopen("in.txt", "r", stdin);
  //freopen("output.txt","w",stdout);
  #endif 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  //cin >> t;
  for (int tt=1;tt<=t;tt++) {
    //cout << "Case #"<<tt<<": ";
    solve();
  }
  #ifndef ONLINE_JUDGE
    cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
  #endif
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[1000],i,j,k,c=0;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(i=0;i<n-2;i++)
    {
        for(j=i+1;j<n-1;j++)
        {
            for(k=j+1;k<n;k++)
            {
                if(a[i]<a[j]&&a[j]<a[k])
                {
                    if(a[i]+a[j]>a[k]&&a[j]+a[k]>a[i]&&a[i]+a[k]>a[j])
                    {
                        c++;
                    }
                }
            }
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3604