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

int main() {
    int N; 
    long long K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i], --A[i];
    deque<int> a;
    vector<bool> seen(N, false);
    int cur = 0;
    while (true) {
        if (seen[cur]) {
            while (a[0] != cur) {
                K--;
                a.pop_front();
                if (K == 0) {
                    cout << a[0]+1 << endl;
                    return 0;
                }
            }
            break;
        }
        a.push_back(cur);
        seen[cur] = true;
        cur = A[cur];
    }
    cout << a[K % a.size()]+1 << endl;
}

Measured memory_bytes: 4848
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	long n;
	cin >> n;
	vector<long> a;
	rep(i,0,n){
		long tmp;
		cin >> tmp;
		a.push_back(tmp);
	}

	vsort(a);
	

	long cnt = 1;
	long long b = a[0];
	rep(i,1,n){

		if(b * 2 >= a[i]){
			b += a[i];
			cnt++;
		}
		else{
			b += a[i];
			cnt = 1;
		}
	}
	
	P(cnt);
	ret 0;
}

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

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

int main() {
    int n; cin >> n;
    int ans = 0;
    rep(i, 3){
        if(n%10 == 1) ans += 9 * pow(10, i);
        else ans += 1 * pow(10, i);
        n /= 10;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
typedef long long int ll;
typedef long double ld;
const int maxn=3E3+5;
const ld pi=acos(-1);
int n;
ld l,ansX,ansY,a[maxn];
inline void add(ld x,int c)
{
	ansX+=cos(x)*c;
	ansY+=sin(x)*c;
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>l;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		a[i]=pi*2*a[i]/l;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
		{
			ld x=(a[i]+a[j])/2;
			add(x,n-j+i-1);
			add(x+pi,j-i-1);
		}
	ansX/=(ld)n*(n-1)*(n-2)/6;
	ansY/=(ld)n*(n-1)*(n-2)/6;
	cout<<fixed<<setprecision(12)<<ansX<<" "<<ansY<<endl;
	return 0;
}


Measured memory_bytes: 4264
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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




int main(){
    int N; cin >> N;
    string S; cin >> S;
    int cnt = 0;
    REP(i, S.length() - 2){
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C')
            ++cnt;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
fun solve(S: String) {
    println("x".repeat(S.count()))
}

fun main() {
    val S = readLine()!!
//    val N = readLine()!!.toInt()
//    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
//    val A = readLine()!!.split(" ").map { it.toInt() }
    solve(S)
}

Measured memory_bytes: 35664
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main() {
    int X, A, B;
    cin >> X >> A >> B;

    cout << (X - A) % B << endl;

    return 0;
}


Measured memory_bytes: 256
/* 2020/03/16 Atcoder Beginner Contest 106 B - 105 */

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
    int n, ans = 0;
    cin >> n;
    for(int i=1; i<=n; i+=2) {
        int count = 0;
        for(int j=1; j<=i; j++) {
            if(i%j == 0) {
                count++;
            }
        }
        if(count == 8) ans++;
    }
    cout << ans << endl;

    return 0;
}

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

int main(int argc, const char * argv[]) {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(a - b) <= d && abs(b - c) <= d){//間接
        cout << "Yes";
        return 0;
    }
    if(abs(a-c) <= d){
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .split(/\s/)
  .map(Number);

var ret = 0;
for (var i = 1; i <= input[0]; i++) {
  var s = i.toString().split("");
  var sum = s.map(Number).reduce((a, b) => a + b);

  if (input[1] <= sum && sum <= input[2]) ret += i;
}

console.log(ret);

Measured memory_bytes: 10216
#include <cstdio>
#include <algorithm>

#define lowbit(x) (x&(-x))

using std::sort;

const int maxn = 300010;

int n, m, c[maxn];

struct node {
	int l, r, len;
	bool operator < (const node &a) const {
		return len < a.len;
	}
}a[maxn];

void add(int i, int x) {
	while(i <= m) c[i] += x, i += lowbit(i);
}

int ask(int i) {
	int ret = 0;
	while(i > 0) ret += c[i], i -= lowbit(i);
	return ret;
}

int main() {
	scanf("%d %d", &n, &m);
	for(int i = 1;i <= n;i ++) {
		scanf("%d %d", &a[i].l, &a[i].r);
		a[i].r ++, a[i].len = a[i].r - a[i].l;
	}
	sort(a + 1, a + n + 1);
	for(int i = 1, j = 1, ans;i <= m;i ++) {
		while(j <= n && a[j].len < i) {
			add(a[j].l, 1);
			add(a[j].r, -1);
			j ++;
		}
		ans =  n - j + 1;
		for(int k = i;k <= m;k += i)
			ans += ask(k);
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 4864
from collections import Counter
import numpy as np

A_MAX = 10 ** 6 + 1

N = int(input())
A = Counter(list(map(int, input().split(' '))))

dp = np.zeros(shape=A_MAX, dtype=np.int64)

if A[1] == 1:
    print(1)
elif A[1] > 1:
    print(0)
else:
    for a in A.keys():
        multiples = np.arange(a, A_MAX, a)
        np.add.at(dp, multiples, 1)

    ans = 0
    for a, count in A.items():
        if count > 1:
            continue
        if dp[a] == 1:
            ans += 1

    print(ans)


Measured memory_bytes: 53692
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<pair<int,int>> edge;
    rep(i,1,N+1){
        rep(j,i+1,N+1) if(j!=((N%2==1)?N-i:N+1-i)){
            edge.push_back({i,j});
        }
    }
    cout<<edge.size()<<endl;
    for(auto e:edge){
        cout<<e.first<<" "<<e.second<<endl;
    }
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define bit(n,m)(((n)>>(m))&1)

//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[200010];//適宜変える
	int id[100010];//適宜変える
}G;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}
int csort(const void*a,const void*b){
	ll p=(*(E*)a).c,q=(*(E*)b).c;
	return p<q?-1:p>q?1:0;
}

G g;
void readgraph(){
	//適宜変える
	ll n;
	scanf("%lld",&n);
	ll m=0;
	rep(i,0,n){
		ll k;
		scanf("%lld",&k);
		while(k--){
			ll t;
			scanf("%lld",&t);
			g.e[m].s=i;
			g.e[m].g=t;
			m++;
		}
	}
	g.vcnt=n;
	g.ecnt=m;
	qsort(g.e,g.ecnt,sizeof(E),esort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}


//LCA
//*
#define VCNT 100010
int dep[VCNT];
int oya[20][VCNT];
#undef VCNT
void lcainitdfs(int v){
	rep(i,g.id[v],g.id[v+1]){
		if(!dep[g.e[i].g]){
			oya[0][g.e[i].g]=v;
			dep[g.e[i].g]=dep[v]+1;
			lcainitdfs(g.e[i].g);
		}
	}
}
void lcainit(int root){
	dep[root]=1;
	lcainitdfs(root);
	rep(k,1,20)rep(v,0,g.vcnt)oya[k][v]=oya[k-1][oya[k-1][v]];
}
int lca(int u,int v){
	int du=dep[u];
	int dv=dep[v];
	if(du<dv){
		int t;
		t=du;du=dv;dv=t;
		t= u; u= v; v=t;
	}
	rep(k,0,20)if(bit(du-dv,k))u=oya[k][u];
 
	if(u==v)return u;
	for(int k=19;k>=0;k--)if(oya[k][u]!=oya[k][v]){
		u=oya[k][u];
		v=oya[k][v];
	}
	return oya[0][u];
}
//*/

int main(){
	readgraph();
	lcainit(0);
	int q;
	scanf("%d",&q);
	while(q--){
		int x,y;
		scanf("%d%d",&x,&y);
		printf("%d\n",lca(x,y));
	}
}


Measured memory_bytes: 17320
#include <iostream>
#include <vector>

using namespace std;

class DisjointSet {
   public:
    vector<int> parent;
    vector<int> height;

    DisjointSet(int n) {
        for (int i = 0; i < n; ++i) {
            parent.push_back(i);
            height.push_back(0);
        }
    }

    int find_set(int n) {
        if (n == parent[n])
            return n;
        else
            return find_set(parent[n]);
    }

    void unite(int x, int y) {
        int rep1 = find_set(x);
        int rep2 = find_set(y);

        if (height[rep1] > height[rep2]) {
            parent[rep2] = rep1;
        } else {
            parent[rep1] = rep2;
            if (height[rep1] == height[rep2])
                ++height[rep1];
        }
    }

    bool same(int x, int y) {
        if (find_set(x) == find_set(y))
            return true;
        else
            return false;
    }
};

int main() {
    ios::sync_with_stdio(false);

    int n, q;
    cin >> n >> q;

    DisjointSet d(n);
    int com, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> com >> x >> y;
        switch (com) {
            case 0:  // unite
                d.unite(x, y);
                break;
            case 1:  // same
                if (d.same(x, y))
                    cout << 1 << '\n';
                else
                    cout << 0 << '\n';
                break;
        }
    }
}



Measured memory_bytes: 3324
#include <cstdio>
int main()
{
  int x, n, y;
  scanf("%d", &n);
  for (x = 3; x <= n; x++)
  {
    y = x;
    if (x % 3 == 0)
    {
      printf(" %d", x);
    }
    else if (x % 10 == 3)
    {
      printf(" %d", x);
    }
    else
    {
      while (1)
      {
        y /= 10;
        if (y % 10 == 3)
        {
          printf(" %d", x);
          break;
        }
        if (y / 10 == 0)
        {
          break;
        }
      }
    }
  }
  printf("\n");
}



Measured memory_bytes: 2724
#include<bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
//g++ -std==c++14
//setprecision(10)
int main(){
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++)
        if(i % 2 == 0)
            cout << s[i];
    cout << endl;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void)
{	
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n ; i+=2) {
		int div = 0;
		rep1(j, i+1) {
			if (i%j == 0) { 
				div++;
			}
		}
		if (div == 8)ans++;
	}
	print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int L;
    cin >> L;
    double ans;
    ans = L*L*L/27.0;
    printf("%8lf", ans);

}

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

int main() {
	double A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	double i, j, k, l;

	double ans_water;
	double ans_sugar;

	double ans_p=0;
    
	for (i = 0; 100*i <= F; i++) {
		for (j = 0; 100*j <= F - j; j++) {
			for (k = 0; C*k <= F - 100*i - 100*j; k++) {
				for (l = 0; D*l <= F - 100*i - 100*j - C*k; l++) {

					double water = 100 * A * i + 100 * B * j;
					double sugar = C * k + D * l;
					double sum=water+sugar;
					double p = sugar / sum;

					if (sum <= F && p <= E/(100+E) && ans_p <= p) {
						ans_p = p;
						ans_water = water;
						ans_sugar = sugar;
					}
				}
			}
		}
	}

	cout << int(ans_water + ans_sugar) <<" "<< int(ans_sugar) << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int n = in.nextInt();

    double[][] xys = new double[n][2];
    double res = 0;

    int fact = fact(n);
    int factor = fact(n) * (n - 1) / ((n * (n - 1)) / 2);

    for (int i = 0; i < n; i++) {
      xys[i][0] = in.nextDouble();
      xys[i][1] = in.nextDouble();

      for (int j = 0; j < i; j++) {
        res += factor * Math.sqrt(
            (xys[i][0] - xys[j][0]) * (xys[i][0] - xys[j][0]) +
                (xys[i][1] - xys[j][1]) * (xys[i][1] - xys[j][1]));
      }
    }

    out.println(res / fact);

    out.close();
  }

  static int fact(int n) {
    int r = 1;
    for (int i = 2; i <= n; i++)
      r *= i;
    return r;
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }
}

Measured memory_bytes: 21332
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 20000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,M;
ll a[300100],_a[300100],b[300100],c[300100];
int main()
{
	scanf("%d",&N);
	rep(i,N)
	{
		scanf("%lld",&a[i]);
		_a[i]=a[i];
	}
	sort(a,a+N);
	sort(_a,_a+N);
	scanf("%d",&M);
	rep(i,M)scanf("%lld",&b[i]);
	rep(i,M)scanf("%lld",&c[i]);
	_a[N]=INF;
	rep(i,M)a[i+1]+=a[i];
	rep(i,M)
	{
		int k = upper_bound(_a,_a+N+1,b[i])-_a;
		ll sum = (k==0)?0ll:a[k-1];
		if(sum>=c[i])printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 10560
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

struct mi {
  int val; static const int MOD = 1e9+7; static_assert(MOD > 0, "Modulus not set!");
  mi(int v=0) : val(v) { if ((val %= MOD) < 0) val += MOD; }
  mi& operator += (const mi& b) { (val += b.val) %= MOD; return *this; }
  mi& operator -= (const mi& b) { return (*this) += MOD-b.val; }
  mi& operator *= (const mi& b) { val = ((ll)val*(ll)b.val) % MOD; return *this; }
  mi& operator /= (const mi& b) { return (*this) *= b.pow(MOD-2); }
#define _op(op, op2) mi operator op (const mi& b) const { mi ans = *this; return ans op2 b; }
  _op(+, +=); _op(-, -=); _op(*, *=); _op(/, /=);
#undef _op
  mi pow(ll e) const { mi res(1), b(*this); for (; e>0; e/=2, b*=b) { if (e&1) res*=b; } return res; }
  int toInt() const { return val; }
};

template <class T>
struct matrix {
  int r, c;
  vector<T> b;
  matrix(int n, int m) : r(n), c(m), b(n*m) { }
  T& operator()(int i, int j) {
    return b[i*c+j];
  }
  matrix operator*(matrix& o) const {
    assert(c == o.r); matrix ret(r, o.c);
    forx(i, r) forx(j, o.c) forx(k, o.c) ret(i, j) += b[i*c+k] * o(k, j);
    return ret;
  }
};

using mat = matrix<mi>;

int n;
ll k;

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n >> k;
  mat m(n, n), a(n, n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int v; cin >> v;
      m(i, j) = v;
    }
  }
  for (int i = 0; i < n; ++i) a(i, i) = 1;
  while(k) {
    if (k & 1) {
      a = a * m;
    }
    m = m*m;
    k /= 2;
  }
  mi ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      ans += a(i, j);
    }
  }
  cout << ans.toInt() << nl;

  return 0;
}


Measured memory_bytes: 256
/*
    Author: Mohammad faisal
    Problem: White Cells
    Date: 06/08/2019

*/
// #include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
#include<stack>
#include<map>
using namespace std;
int main()
{
 
  int a,b;
  cin >> a >> b;
  int r,c;
  cin >> r >> c;
  int total = a*b;
  total-=(r*b); // rows deletion
  a-=r;
  total-=(a*c);
  cout<<total<<endl;
  return 0;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int N;
  cin >> N;
  vector<int> b(N);
  REP(i, N) cin >> b[i];
  vector<int> ans(0);
  while (b.size() >= 1) {
    bool t = false;
    for (int i = b.size() - 1; i >= 0; i--) {
      if (b[i] == i + 1) {
        t = true;
        ans.push_back(i + 1);
        b.erase(b.begin() + i);
      }
      if (t) break;
    }
    if (!t) {
      cout << -1 << endl;
      return 0;
    }
  }
  reverse(ans.begin(), ans.end());
  REP(i, ans.size()) { cout << ans[i] << endl; }
}

Measured memory_bytes: 3640
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;

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

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

	constexpr int MAX_N = 10000;

	for(int p, n; cin >> p >> n && p;) {
		int x = MAX_N, y = 1;
		int u = 0, v = 1;

		const double sqrt_p = sqrt(p);

		REP(deno, 1, n + 1) {
			const double tmp = deno * sqrt_p;

			{ //update u/v
				const int nume = floor(tmp);
				if(nume <= n && nume * v > deno * u) {
					u = nume;
					v = deno;
				}
			}

			{ // update x/y	
				const int nume = ceil(tmp);
				if(nume <= n && nume * y < deno * x) {
					x = nume;
					y = deno;
				}
			}
		}

		cout << x << '/' << y << ' ' << u << '/' << v << endl;
	}
	return EXIT_SUCCESS;
}

Measured memory_bytes: 1192
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 1e2 + 5;
const int MAXM = 1e2 + 5;
const int inf = 0x3f3f3f3f;

inline void chk_min(int &a,int b){ if(a>b) a=b;}

char s[MAXN][MAXM];
int a[MAXN][MAXM];
int f[MAXN][MAXM][3];

int gao(int x,int y,int k)
{
	if(x<1 || y<1) return inf;
	if(~f[x][y][k]) return f[x][y][k];
	int &res = f[x][y][k] = inf;
	
	if(a[x][y])
	{
		chk_min(res, gao(x-1,y,0)+1);
		chk_min(res, gao(x-1,y,1));
		chk_min(res, gao(x,y-1,0)+1);
		chk_min(res, gao(x,y-1,1));
	}
	else
	{
		if(k)
		{
			chk_min(res, gao(x-1,y,0)+2);
			chk_min(res, gao(x-1,y,1)+a[x-1][y]);
			chk_min(res, gao(x,y-1,0)+2);
			chk_min(res, gao(x,y-1,1)+a[x][y-1]);
		}
		else
		{
			chk_min(res, gao(x-1,y,0));
			chk_min(res, gao(x-1,y,1));
			chk_min(res, gao(x,y-1,0));
			chk_min(res, gao(x,y-1,1));
		}
	}
	return res;
}

int main(void)
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; ++i) scanf("%s",s[i]+1);
	
	memset(f,-1,sizeof(f));
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=m; ++j)
		{
			a[i][j] = (s[i][j]=='#');
			if(a[i][j]) f[i][j][0]=inf;
		}
	if(a[1][1]) f[1][1][0]=inf, f[1][1][1]=1;
	else f[1][1][0]=0, f[1][1][1]=2;
	
	printf("%d",min(gao(n,m,0), gao(n,m,1)));
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 int H, W;
 int seen[10000][10000];
  char S[10000][10000];
vector<pair<ll, ll>> prime_factorize(ll n) { //素因数分解と各素数の個数
    vector<pair<ll, ll>> res;

    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i != 0)
        {
            continue;
        }
        int num = 0;
        
        while (n % i == 0)
        {
            ++num;
            n /= i;
        }
        res.push_back(make_pair(i, num));
       
    }
     if (n != 1) 
        {
            res.push_back(make_pair(n, 1));
        }
        return res;
        
} 
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll lcm(ll x, ll y) {
    return x / GCD(x, y) * y;//先に割り算をして掛けられる数を小さくして掛け算を行う
}
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

void dfs(int st, int fi) {
  //  cout << st << " " << fi <<  endl;
    if (st < 0 || fi < 0 || st >= H || fi >= W)
    {
        return ;
    }
    if (S[st][fi] == '#')
    {
        return ;
    }

    if (seen[st][fi] == 1)
    {
        return ;
    }
    
    
    if (S[st][fi] == '.')
    {
        seen[st][fi] = 1;
    }
    

    dfs(st + 1, fi);
    dfs(st, fi + 1);
    dfs(st, fi - 1);
    dfs(st - 1, fi);
    
}
int main() {
   int N;
   cin >> N;

   vector<int> s(N);

   for(int i = 0; i < N; i++) cin >> s[i];

   int sum = 0;
   for(int i = 0; i < N; i++) {
       sum += s[i];
   }
   sort(s.begin(), s.end());
    int a = 0;
   
   while(sum % 10 == 0) {
       if(s[a] % 10 != 0) {sum -= s[a]; break; }
        a++;
        if(a == N) break;
   }
   if(sum % 10 == 0) cout << 0 << endl;
   else cout << sum << endl;
 return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;


int main(){

    string S,ans;
    cin >> S;

    ans = S[0] + to_string(S.length()-2) + S[S.length()-1] ; 

    cout << ans <<endl;

    return 0;
}


Measured memory_bytes: 256
def calc(S, K):
    if (K == 1):
        return S[0]

    for i in range(K):
        if (S[i] != "1"):
            return S[i]
    
    return "1"

if __name__ == "__main__":
    S = input()
    K = int(input())

    print(calc(S, K))


Measured memory_bytes: 3064
import java.io.InputStream;
import java.util.Scanner;

/**
 * AtCoder Beginner Contest 055<br>
 * B - Training Camp<br>
 * <br>
 * <a href="https://atcoder.jp/contests/abc055/tasks/abc055_b">AtCoderへのリンク</a><br>
 */
public class Main {

    /**
     * エントリポイント
     */
    public static void main(String[] args) {
        // 入力
        int N = input(System.in);
        // 演算
        long power = proc(N);
        // 出力
        System.out.println(power);
    }

    /**
     * 入力値を取得
     */
    static int input(InputStream in) {
        int result = 0;
        try (Scanner sc = new Scanner(in)) {
            result = sc.nextInt();
        }
        return result;
    }

    /**
     *  演算を行う
     */
    static long proc(int N) {
        long power = 1;
        
        for (int i=1; i<=N; i++) {
            power = power * i % (1000000000 + 7);
        }
        
        return power;
    }

}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

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

int main() {
    ll a, b, ans;
    cin >> a >> b;

    ans = (a*b)/gcd(a, b);
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {

	unsigned long N, K;
	cin >> N >> K;

	vector<unsigned long> H(N);
	for (unsigned long i = 0; i < N; ++i)
	{
		cin >> H[i];
	}

	sort(H.begin(), H.end(), greater<unsigned long>());

	unsigned long count = 0;

	if (K > N) {
		cout << "0";
		return 0;
	}

	for (unsigned long i = 0; i < K; ++i)
	{
		H[i] = 0;
	}

	for (unsigned long i = 0; i < N; ++i)
	{
		count += H[i];
	}

	cout << count;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <algorithm>
#include <map>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector <int> v(n);

    for(auto& i : v) cin >> i;
    int cnt = 0;
    for(int i = n - 1; i >= 0; i--){
        bool ok = 1;
        for (int j = 0; j < i; ++j) {
            if(v[i] < v[j]) {
                ok = 0;
                break;
            }
        }
        cnt += ok;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
 
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
 
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
 
            if(a<= 8 && b<= 8 && a>=1 && b>=1)
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }
 
        }
    }
}

Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }

lint N, M, A, B;
plint arr[100000];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> M;
	REP(i, N) {
		cin >> A >> B;
		arr[i] = plint(A, B);
	}
	sort(arr, arr + N);
	lint cost = 0;
	REP(i, N) {
		if (arr[i].second >= M) {
			cost += (arr[i].first * M);
			break;
		}
		else {
			cost += (arr[i].first * arr[i].second);
			M -= arr[i].second;
		}
	}
	cout << cost;
}


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

using ll = long long;
using P = pair<int, int>;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N, K;
  cin >> N >> K;
  ll h[N];
  for (int i = 0; i < N; i++) cin >> h[i];

  sort(h, h + N);
  ll ans = 1e9;
  for (int i = 0; i <= N - K; i++) {
    ans = min(ans, h[i+K-1] - h[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        1000000007
#define all(x)     x.begin(),x.end()    
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
void comp() {
    ll i,j,k,n,m,a,r;
    char c;
    cin>>n>>k;
    vector<ll>v1;
    fl(i,n) {
        cin>>j;
        v1.pb(j);
    }
    sort(all(v1));
    ll sum=0;
    fl(i,k) sum+=v1[i];
    cout<<sum<<"\n";
}

int main() {
    speedup;
    ll i=0,t;
    t=1;
    //cin>>t;
    while(t--) {
        comp();
    }
    return 0;
}

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


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

using ll = long long;

/* vector<ll> v(N);
  小さい順: sort(v.begin(), v.end());
  逆順: reverse(v.begin(), v.end());
  vector<pair<ll, ll> > p; ＃ソートした場合、１つ目でソート
  tie(b, a) = p.at(i); #pairを分割
  tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
  xの二乗:  pow(x, 2.0);
  int: -2,147,483,648 ～ 2,147,483,647(2×10^9)
  ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807(9×10^18)
  long long型の2次元配列(3×4要素の)の宣言
  vector<vector<ll>> data(3, vector<ll>(4));
  string -> int : stoi(S);
  int -> string : to_string(N);
  Sのn文字以降をm文字取り出す : S.substr(n,m)
*/
 
 //126~
 //
int main() {
  
  int N,u,v,w,a,b,c;
  cin >> N;
  vector<vector<int>> pair(N),cost(N);
  vector<int> ans(N,-1);
  queue<int> check;

  rep(i,N-1){
    cin >> u >> v >> w;
    w = w%2;
    u--;
    v--;
    pair.at(u).push_back(v);
    pair.at(v).push_back(u);
    cost.at(u).push_back(w);
    cost.at(v).push_back(w);
  }

  check.push(0);
  ans[0]=0;
  while(!check.empty()){
    a = check.front();
    check.pop();

    rep(i,pair.at(a).size()){
      b= pair.at(a).at(i);
      c= cost.at(a).at(i);

      if(ans.at(b)!=-1) continue;

      check.push(b);
      ans.at(b)= (ans.at(a)-c)*(ans.at(a)-c);
    }
  }

  rep(i,N){
    cout << ans.at(i) << endl;
  }
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
using P = pair<int, int>;
const int mod = 1E9 + 7;
const int inf = 1 << 29;

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i * i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll, int>> factor(ll x) {
    vector<pair<ll, int>> res;
    for (int p : primes) {
      int y = 0;
      while (x % p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p, y);
    }
    if (x != 1) res.emplace_back(x, 1);
    return res;
  }
};

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

  Sieve s(1000005);
  auto fs = s.factor(n);

  int ans = 0;
  for (auto p : fs) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define ll long long
#define endl '\n'

char n;

void test() {
    cin >> n;
    if ('A'<=n&&n<='Z') {
        cout << 'A' << endl;
    }
    else {
        cout << 'a' << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    // int t;
    // cin >> t;
    // while (t--) {
    //     test();
    // }
    test();
    return 0;
}

Measured memory_bytes: 3608
def main():
    N = int(input())
    S = input()
    rcnt, gcnt, bcnt = 0, 0, 0
    for i, s in enumerate(S):
        if s=='R':
            rcnt += 1
        if s=='G':
            gcnt += 1
        if s=='B':
            bcnt += 1
    
    base = rcnt*gcnt*bcnt
    interval = 1
    totalminus = 0
    limit = 1 + (N-3)//2
    while interval <= limit:
        for i in range(interval, N-interval):
            a = S[i-interval]
            b = S[i]
            c = S[i+interval]
            if a!=b and b!=c and c!=a:
                totalminus += 1
        interval += 1
    print(base-totalminus)
main()

Measured memory_bytes: 9224
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
    ll n;
ll dp[100003][4];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    ll a[100002],b[100002],c[100002];
    for (int i = 1; i <=n; ++i)
    {
    	cin>>a[i]>>b[i]>>c[i];
    }
    dp[1][1]=a[1];
    dp[1][2]=b[1];
    dp[1][3]=c[1];
    for (int i = 2; i <=n ; ++i)
    {
    	dp[i][1]=a[i]+max(dp[i-1][2],dp[i-1][3]);
    	dp[i][2]=b[i]+max(dp[i-1][1],dp[i-1][3]);
    	dp[i][3]=c[i]+max(dp[i-1][2],dp[i-1][1]);
    }
    cout<<max({dp[n][1],dp[n][2],dp[n][3]})<<'\n';
}


Measured memory_bytes: 5760
#include<stdio.h>
int main(void)
{
	int S=0,W=0;
  
  	scanf("%d",&S);
  	scanf("%d",&W);
  
  	if(S>W){
    	puts("safe");
    }else{
    	puts("unsafe");
    }
  
  return 0;
  
}

Measured memory_bytes: 2088
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

typedef struct 
{
    unsigned int left;
    unsigned int area;
}AreaInfo_t;

#define CalcArea(x,y) ((x) - (y))

stack<unsigned int> ArealeftIdxStack;
vector<AreaInfo_t> AreaInfoStack;

int Decision(char, unsigned int);
void Fusion(AreaInfo_t);
void PrintArea(void);

int main(void){
    char ch;
    unsigned int idx = 0;
    unsigned int total = 0;
    
    while(cin >> ch)
    {
        total += Decision(ch, idx);
        idx++;
    }
    
    cout << total << endl;
    PrintArea();
    
    return 0;
    
}

int Decision(char ch, unsigned int idx)
{
    switch(ch)
    {
        case '\\':
            ArealeftIdxStack.push(idx);
            break;
        case '/':
            if(ArealeftIdxStack.empty())
            {
                break;
                
            }
            AreaInfo_t area;
            area.left = ArealeftIdxStack.top();
            area.area = CalcArea(idx, ArealeftIdxStack.top());
            Fusion(area);
            ArealeftIdxStack.pop();
            return area.area;
        case '_':
            // pass
            break;
        default:
            // unreachable
            return 0;
    }

    return 0;
}

void Fusion(AreaInfo_t tInfo)
{
    
    while(1)
    {
        if(!AreaInfoStack.empty())
        {
            AreaInfo_t tmp = AreaInfoStack.back();
            if(tmp.left > tInfo.left)
            {
                tInfo.area += tmp.area;
                AreaInfoStack.pop_back();
                continue;
            }
        }
        AreaInfoStack.push_back(tInfo);
        break;
    }
    return;
}

void PrintArea()
{
    cout << AreaInfoStack.size();
    for(vector<AreaInfo_t>::iterator it = AreaInfoStack.begin(); it != AreaInfoStack.end(); it++)
    {
        cout << ' ' <<  it->area;
    }
    cout << endl;

    return;
}



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

// A function to perform division of large numbers
string longDivision(string number, int divisor)
{
    // As result can be very large store it in string
    string ans;

    // Find prefix of number that is larger
    // than divisor.
    int idx = 0;
    int temp = number[idx] - '0';
    while (temp < divisor)
        temp = temp * 10 + (number[++idx] - '0');

    // Repeatedly divide divisor with temp. After
    // every division, update temp to include one
    // more digit.
    while (number.size() > idx)
    {
        // Store result in answer i.e. temp / divisor
        ans += (temp / divisor) + '0';

        // Take next digit of number
        temp = (temp % divisor) * 10 + number[++idx] - '0';
    }

    // If divisor is greater than number
    if (ans.length() == 0)
        return "0";

    // else return ans
    return ans;
}


string findSum(string str1, string str2)
{
    // Before proceeding further, make sure length
    // of str2 is larger.
    if (str1.length() > str2.length())
        swap(str1, str2);

    // Take an empty string for storing result
    string str = "";

    // Calculate length of both string
    int n1 = str1.length(), n2 = str2.length();

    // Reverse both of strings
    reverse(str1.begin(), str1.end());
    reverse(str2.begin(), str2.end());

    int carry = 0;
    for (int i=0; i<n1; i++)
    {
        // Do school mathematics, compute sum of
        // current digits and carry
        int sum = ((str1[i]-'0')+(str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');

        // Calculate carry for next step
        carry = sum/10;
    }

    // Add remaining digits of larger number
    for (int i=n1; i<n2; i++)
    {
        int sum = ((str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining carry
    if (carry)
        str.push_back(carry+'0');

    // reverse resultant string
    reverse(str.begin(), str.end());

    return str;
}
int main ()
{
    int compt=1;
    string attack="1";
    string h;
    cin>>h;
    while(h!="1")
    {
        h=longDivision(h,2);
        compt++;

    }
    string newatt="1";
    for(int i=1; i<compt; i++)
    {
        newatt=findSum(newatt,newatt);
        attack=findSum(attack,newatt);
        }
    //cout<<(compt*compt-1);
    cout<<attack;


    return 0;
}

Measured memory_bytes: 256
n = int(input())
num_list = [int(input()) for _ in range(n)]
max_num = 10**9*-1
min_num = num_list[0]

for i in range(1,len(num_list)):
    max_num = max(num_list[i]-min_num,max_num)
    min_num = min(num_list[i],min_num)

print(max_num)


Measured memory_bytes: 13592
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int n;
char chain[10000];

int ccount(int a, int b, int cnt){
	if (chain[a] != chain[b])return cnt;
	int len = 0;
	int i, j;
	for (i = a; i >= 0 && chain[a] == chain[i]; i--, len++);
	for (j = b; j < n&&chain[b] == chain[j]; j++, len++);
	if (len < 4)return cnt;
	if (i == -1 || j == n)return cnt + len;
	return ccount(i, j, cnt + len);
}

int main(){
	while (scanf("%d", &n), n){
		int ans = 0;
		for (int i = 0; i < n; i++){
			int d;
			scanf("%d", &d);
			chain[i] = d;
		}
		for (int i = 0; i < n; i++){
			char def = chain[i];
			for (int j = 1; j <= 3; j++){
				chain[i] = j;
				int s, g, cnt = 1;
				for (s = i - 1; s >= 0 && chain[s] == chain[i]; s--, cnt++);
				for (g = i + 1; g < n&&chain[g] == chain[i]; g++, cnt++);
				if (cnt >= 4){
					if (s == -1 || g == n)ans = max(cnt, ans);
					else ans = max(ccount(s, g, cnt), ans);
				}
			}
			chain[i] = def;
		}
		printf("%d\n", n - ans);
	}
	return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    sort(btoe(p));
    n=p.size();
    if(n==0){
        cout<<0<<endl;
        return 0;
    }
    vector<int> an(p[n-1]+5);
    rep(i,n){
        if(an[p[i]]<=1){
            for(int j=p[i]; j<=p[n-1]; j+=p[i]){
                an[j]++;
            }
        }
    }
    int ans=0;
    rep(i,n) if(an[p[i]]==1) ans++;
    cout<<ans<<endl;    
    return 0;
}

Measured memory_bytes: 7844
index = 0
while (n=gets.to_i) != 0
  index += 1
  x = []
  y = []
  n.times do
    a,b = gets.chomp.split.map(&:to_i)
    x.push(a)
    y.push(b)
  end
  s = 0
  for i in 0..n-1
    if i < n-1
      s += (x[i]*y[i+1] - y[i]*x[i+1])
    elsif i = n-1
      s += (x[i]*y[0] - y[i]*x[0])
    end
  end
  s = s.abs / 2.0

  puts "#{index} #{s}"

  gets
end

Measured memory_bytes: 6140
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int n,dp[100005][5],ans;
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      cin>>dp[i][j];
    }
  }

  for(int i=1;i<n;i++){
    dp[i][0]+=max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]+=max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]+=max(dp[i-1][0],dp[i-1][1]);
  }

  ans=max(dp[n-1][0] , max(dp[n-1][1],dp[n-1][2]) );
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};
 
typedef struct node * NodePointer;
 
NodePointer nil;
 
NodePointer listSearch(int key){
  struct node *cur = nil->next;
  while(cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}
 
void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}
 
void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}
 
void deleteNode(NodePointer t){
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}
 
void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}
 
void deleteLast(){
  deleteNode(nil->prev);
}
 
void delete(int key){
  deleteNode(listSearch(key));
}
 
 
void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
 
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}
 
int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
    if ( com[6] == 'F' ) deleteFirst();
    else if ( com[6] == 'L' ) deleteLast();
      } else {
    delete(key); nd++;
      }
      size--;
    }
  }
 
  printList();
  return 0;
}


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

int dp[4001][4001];

int main(){
    string a, b;
    while(cin >> a >> b){
        int ans = 0;

        for(int i = 0; i < a.length(); i++){
            for(int j = 0; j < b.length(); j++){
                dp[i][j] = 0;
            }
        }

        for(int j = 0; j < b.length(); j++) if(a[0] == b[j])    dp[0][j] = 1;
        for(int i = 0; i < a.length(); i++) if(a[i] == b[0])    dp[i][0] = 1;

        for(int i = 1; i < a.length(); i++){
            for(int j = 1; j < b.length(); j++){
                if(a[i] == b[j]){
                    dp[i][j] = dp[i-1][j-1]+1;
                    ans = max(ans, dp[i][j]);
                }
                // add this line if you want to get longest common substring
                //dp[i][j] = max(dp[i][j], max(dp[i-1][j], dp[i][j-1]));
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 65616
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#define LL long long
using namespace std;
inline int read( )
{
  int sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
inline bool getc( )
{
  char c=getchar( );
  while(c!='0'&&c!='1') c=getchar( );
  return c=='1';
}
const int N=2005;
bool c[N][N];int d[N][N],e[N][N],a[N][N],b[N][N];
int main( )
{
  int i,j,n,m,q,x1,x2,y1,y2;
  n=read( );m=read( );q=read( );
  for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
      c[i][j]=getc( );
  for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
      {
	d[i][j]=d[i-1][j]+d[i][j-1]-d[i-1][j-1]+c[i][j];
	e[i][j]=e[i-1][j]+e[i][j-1]-e[i-1][j-1]+(c[i][j]?c[i-1][j]+c[i][j-1]:0);
	a[i][j]=a[i-1][j]+(c[i][j]?c[i][j-1]:0);
	b[i][j]=b[i][j-1]+(c[i][j]?c[i-1][j]:0);
      }
  while(q--)
    {
      x1=read( );y1=read( );x2=read( );y2=read( );
      printf("%d\n",
	     (d[x2][y2]-d[x1-1][y2]-d[x2][y1-1]+d[x1-1][y1-1])
	     -(e[x2][y2]-e[x1-1][y2]-e[x2][y1-1]+e[x1-1][y1-1])
	     +(a[x2][y1]-a[x1-1][y1])+(b[x1][y2]-b[x1][y1-1]));
    }
  return 0;
}
  

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

int main(void){
  int n; cin >> n;
  ll ans = 0;
  for(int i = n-1; i >= 1; i--){
    ans += i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256