akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <random>
#include<map>

//AtCoderC++.cpp

using namespace std;


#define rep(i,from,to) for(int i=from;i<to;i++)
#define ints(name,n) vector<int> name;name.resize(n)

template<typename T> void Show(vector<vector<T>> v, string delimiter = " ") {
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].size(); j++) {
			cout << v[i][j];
			if (j != v[i].size() - 1) {
				cout << delimiter;
			} else {
				cout << endl;
			}
		}
	}
}
template<typename T> void Show(vector<T> v, string delimiter = " ") {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i];
		if (i != v.size() - 1) {
			cout << delimiter;
		} else {
			cout << endl;
		}
	}
}
template<typename T> vector<T> getUniform(T value, int n) {
	vector<vector<T>> ts;
	ts.resize(n);
	for (int i = 0; i < n; i++) {
		ts[i] = value;
	}
	return ts;
}
template<typename T> vector<vector<T>> getUniform(T value, int row, int col) {
	vector<vector<T>> ts;
	ts.resize(row);
	for (int i = 0; i < row; i++) {
		ts[i].resize(col);
		for (int j = 0; j < col; j++) {
			ts[i][j] = value;
		}
	}
	return ts;
}
bool All(vector<vector<bool>> ts) {
	int h = ts.size();
	int w = ts[0].size();
	rep(i, 0, h) {
		rep(j, 0, w) {
			if (!ts[i][j])return false;
		}
	}
	return true;
}

int main() {
	auto geneMap = map<char, char>();
	geneMap['A'] = 'T';
	geneMap['T'] = 'A';
	geneMap['G'] = 'C';
	geneMap['C'] = 'G';
	char a;
	cin >> a;
	cout << geneMap[a] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;
 
int n,k;
string s,ans;
signed main(){
    cin>>n>>k;
    cin>>s;
    rep(i,s.size()){
        if(i+1==k){
            char a=s[i];
            a=tolower(a);
            ans+=a;
        }else{
            ans+=s[i];
        }
    }
    cout<<ans<<endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (ll i = 0; i < s.size(); ++i) {
    cout << s[i] << t[i];
  }
  cout << "\n";
}


Measured memory_bytes: 256
from collections import defaultdict


def dfs(u, used, edges, result):
    used[u] = True
    for v in edges[u]:
        if not used[v]:
            dfs(v, used, edges, result)
    result.append(u)


def main():
    N, M = map(int, input().split())

    used = [False] * N
    edges = defaultdict(list)
    for _ in range(M):
        s, t = map(int, input().split())
        edges[s].append(t)

    result = []
    for i in range(N):
        if not used[i]:
            dfs(i, used, edges, result)

    print(*result[::-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 12160
#include <stdio.h>
int main(void){
	//?£? ??? ??¨?±?
	int a[4][3][10];
	//initialize
	int i,j,k;
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				a[i][j][k] = 0;
			}
		}
	}
	//scan
	int n;
	scanf("%d\n",&n);
	int l;
	for(l=0;l<n;l++){
		int b,f,r,v;
		scanf("%d %d %d %d\n",&b,&f,&r,&v);
		a[b-1][f-1][r-1] = a[b-1][f-1][r-1] + v;
	}
	//print
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				if(k==9){
					printf(" %d\n",a[i][j][k]);
				}else{
					printf(" %d",a[i][j][k]);
				}
			}
		}
		if(i!=3){
			int loop;
			for(loop=0;loop<20;loop++){
				printf("#");
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 604
n=int(input())
A=list(map(int,input().split()))
print(*A)
for i in range(1,n):
    v=A[i]
    j=i-1
    while j>=0 and v<A[j]:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    print(*A)


Measured memory_bytes: 5976
n, m = gets.split.map(&:to_i)
dr = Array.new(n, nil)
n.times do |i|
  dr[i] = gets.split.map(&:to_i)
end
dr.sort! do |d1, d2|
  d1[0] <=> d2[0]
end
mm = 0
cost = 0
dr.each do |d|
  k = [m - mm, d[1]].min
  mm += k
  cost += d[0] * k
  break if mm == m
end
puts cost


Measured memory_bytes: 12408
#include <bits/stdc++.h>
 
#define int          long long
#define pb          push_back
#define pii         pair<int,int> 
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007 
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cout << #x << " is " << x << flush << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
using namespace std;
const int maxn = 100010;
int n,wt;
int val[maxn], w[maxn];
void solve(){
	cin>>n>>wt;
	rep(i,1,n+1)
		cin>>w[i]>>val[i];
	int dp[n+1][wt+1];
	memset(dp, 0, sizeof(dp));

	rep(i, 1, n+1)
	{
		rep(j, 1, wt+1)
		{
			if(j<w[i])
				dp[i][j] = dp[i-1][j];
			else
				dp[i][j] = max(dp[i-1][j], val[i] + dp[i-1][j-w[i]]);
		}
	}
	cout<<dp[n][wt];






}
 
signed main(){
   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int t=1;
     //cin>>t;
 
    while(t--)
        solve();
    
    return 0;
}

Measured memory_bytes: 79232
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

# @njit
def solve(x,k,d):
  cand1 = x % d
  cand2 = -(abs(cand1) -  d)
  delta_c1 = abs(cand1 - x)
  delta_c2 = abs(cand2 - x)
  if abs(x//d) > k:
    return abs(x) - k*d
  elif (k-x//d) % 2 == 0:
    return cand1
  else:
    return cand2



def main():
  X,K,D = map(int,input().split())
  # a = list(map(int,input().split()))
  print(solve(X,K,D))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;


double betdeg(int a,int b,double deg){
    double c;
    c=pow(a,2)+pow(b,2)-2*a*b*cos(deg);
    return pow(c,0.5);
}


int main(){
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double deg1=m*2*M_PI/60;
    double deg2=(h*60+m)*M_PI/360;
    double deg3=0;
    if(deg1>deg2){
        deg3=deg1-deg2;
    }else if(deg1<deg2){
        deg3=deg2-deg1;
    }else{
        deg3=0;
    }
    cout<<fixed<<setprecision(10)<<betdeg(a,b,deg3)<<endl;

    return 0;
}

Measured memory_bytes: 4296
import sys
N = int(sys.stdin.readline().rstrip())
A = list(map(int, sys.stdin.readline().rstrip().split()))
B = list(map(int, sys.stdin.readline().rstrip().split()))

if A == B:
    print("Yes")
    exit()
diff = [a - b for a, b in zip(A, B)]
minus = []
plus = []
for d in diff:
    if d < 0:
        minus.append(-d)
    elif d > 0:
        plus.append(d)

total = 2 * sum(plus)
minus.sort()
while total:
    if not minus or sum(minus) < total:
        break
    if minus[-1] >= total:
        total = 0
    else:
        if minus[-1] % 2 == 1:
            total -= minus[-1] - 1
        else:
            total -= minus[-1]
        minus.pop()
else:
    print("Yes")
    exit()
print("No")

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

using ll = long long;

struct Town {
	ll x;
	ll y;
};

ll Factorial(ll n) {
	if (n == 0) return 1;
	else if (n == 1) return 1;
	else {
		return n * Factorial(n - 1);
	}
}

double DistanceBetweenTwoTowns(const Town& ta, const Town& tb) {
	return sqrt(static_cast<double>((ta.x - tb.x) * (ta.x - tb.x) + (ta.y - tb.y) * (ta.y - tb.y)));
}

int main() {
	ll n; cin >> n;
	vector<Town> towns(n);
	for (int i = 0; i < n; i++) {
		cin >> towns[i].x >> towns[i].y;
	}
	vector<int> v(n);
	for (int i = 0; i < n; i++) { v[i] = i; }
	double total = 0.0;
	do {
		for (ll i = 0; i < n - 1; i++) {
			total += DistanceBetweenTwoTowns(towns[v[i]], towns[v[i + 1]]);
		}
	} while (next_permutation(v.begin(), v.end()));
	ll f = Factorial(n);

	cout << fixed << setprecision(10) << total / f << endl;
}


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

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

    int n = S.length();
    int m = T.length();
    int flag = 0;
    vector<int> num;


    for(int i = 0; i <= (n - m); i++){
        for(int j = 0; j < m; j++){
            string a = S.substr(i + j, 1);
            string b = T.substr(j, 1);

            if(j == m - 1){
                if(a == "?" || a == b){
                    flag = 1;
                    break;
                }
            }

            if(a == "?"){
                continue;
            }else if(a == b){
                    continue;
            }else{
                break;
            }
        }
        if(flag == 1){
            num.push_back(i);
            flag = 0;
        }
    }

    string ans[num.size()];

    if(num.size() == 0){
        cout << "UNRESTORABLE" << endl;
    }else{
        for(int i = 0; i < num.size(); i++){
            for(int j = 0; j < num[i]; j++){
                if(S.substr(j, 1) == "?"){
                    ans[i] += "a";
                }else{
                    ans[i] += S.substr(j,1);
                }
            }
            ans[i] += T.substr(0);
            //cout << ans[i] << endl;
            //cout << S << "  " << n + num[i] << endl;
            for(int k = 0; k < n - m - num[i]; k++){
                //cout << "qwe" << endl;
                if(S.substr(k + m + num[i], 1) == "?"){
                    ans[i] += "a";
                }else{
                    ans[i] += S.substr(m + num[i] + k, 1);
                }
            }
        }

        string tr;
        for(int i = 0; i < n; i++){
            tr += "z";
        }
        //cout << tr << endl;
        for(int i = 0; i < num.size(); i++){
            //cout << ans[i] << endl;
            if(tr > ans[i]){
                tr = ans[i];
            }
        }

        cout << tr << endl;
    }

}

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

using namespace std;

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

    int m[4][4];

    for(int i=1; i<=3; i++){
        for(int j=1; j<=3; j++){
            cin >> m[i][j];
        }
    }

    int n;

    cin >> n;

    for(int k=1; k<=n; k++){
        int x;

        cin >> x;

        for(int i=1; i<=3; i++){
            for(int j=1; j<=3; j++){
                if(m[i][j] == x) m[i][j] = -1;
            }
        }
    }

    bool ans = false;

    if(m[1][1] + m[1][2] + m[1][3] == -3) ans = 1;
    if(m[2][1] + m[2][2] + m[2][3] == -3) ans = 1;
    if(m[3][1] + m[3][2] + m[3][3] == -3) ans = 1;
    if(m[1][1] + m[2][1] + m[3][1] == -3) ans = 1;
    if(m[1][2] + m[2][2] + m[3][2] == -3) ans = 1;
    if(m[1][3] + m[2][3] + m[3][3] == -3) ans = 1;
    if(m[1][1] + m[2][2] + m[3][3] == -3) ans = 1;
    if(m[1][3] + m[2][2] + m[3][1] == -3) ans = 1;

    if(ans)  cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut a: Vec<i32> = (0..n).map(|_| input()).collect();
    a.sort();
    let mut b = a.clone();
    b.dedup();

    let mut d = a.len() - b.len();
    if d % 2 != 0 {
        d += 1;
    }
    println!("{}", n - d);
}


Measured memory_bytes: 4352
"use strict";
function main(input) {
  let n = input[1].trim().split(" ");
  for(let i=0;i<n.length;i++){
    n[i] = parseInt(n[i]);
  }

  let judge = false;
  for(let i=0;i<n.length;i++){
    if (n[i]%2==0){
      if ((n[i]%3 !== 0) && (n[i]%5 !== 0)){
        judge = true;
        break;
      }
    }
  }
  console.log(judge?"DENIED":"APPROVED");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll h, w, l, d[100][100][4], x, y, di, m;
string s[100];

signed main() {
	while (1) {
		cin >> h >> w >> l;
		if (h==0) break;
		rep(i,h) {
			cin >> s[i];
			rep(j,w) if (s[i][j]!='.' && s[i][j]!='#') {
					x = i, y = j;
					if (s[i][j]=='E') di = 0;
					else if (s[i][j]=='S') di = 1;
					else if (s[i][j]=='W') di = 2;
					else di = 3;
			}
		}
		rep(i,h) rep(j,w) rep(k,4) d[i][j][k] = linf;
		d[x][y][di] = 0;
		m = 0;
		while (1) {
			if (m==l) break;
			chmin(d[x][y][di], m);
			int xx = x + dx[di], yy = y + dy[di];
			if (ool(xx,yy,h,w) || s[xx][yy]=='#') di++, di %= 4;
			else {
				x = xx, y = yy;
				m++;
				chmin(d[x][y][di], m);
				if (d[x][y][di]<m) {
					m += (l-m)/(m-d[x][y][di])*(m-d[x][y][di]);
					rep(i,h) rep(j,w) rep(k,4) d[i][j][k] = linf;
					d[x][y][di] = m;
					continue;
				}
			}
		}
		string t = "ESWN";
		cout << x+1 << ' ' << y+1 << ' ' << t[di] << ln << flush;
	}
}


Measured memory_bytes: 3504
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;

int main(){
	long long int X;
	cin>>X;
	X-=100;
	int cnt = 0;
	int mi = 1;
	long long int now = 100;
	for(int i = 1;;i++){
		
		X-=now/100;
		now += now/100;
		if(X <= 0){
			cout<<i<<endl;
			return 0;
		}
		
		
		
	}
}

Measured memory_bytes: 3632
/*
[dp] U - Grouping
*/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 16;
const ll INF = 1LL << 60;

int N;
int a[MAX_N][MAX_N];
ll dp[1 << MAX_N], s[1 << MAX_N];

ll solve() {
    int full = (1 << N) - 1;

    fill(dp, dp + full + 1, -INF);

    for (int b = 0; b <= full; b++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if ((b >> i) & (b >> j) & 1) {
                    s[b] += a[i][j];
                }
            }
        }
    }

    dp[0] = 0;
    for (int b = 0; b <= full; b++) {
        int nb = full ^ b;
        for (int sub = nb; sub >= 0; sub--) {
            sub &= nb;
            dp[b | sub] = max(dp[b | sub], dp[b] + s[sub]);
        }
    }

    return dp[full] / 2;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> a[i][j];
        }
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define all(x) x.begin(),x.end()
#define mod 1000000007

ll expo(ll a,ll b){ll r=1;a=a%mod;while(b){if(b%2)r=(r*a)%mod;a=(a*a)%mod;b=b/2;}
return r;}
struct greaterr
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};



/*vector<bool> sieve(10000007,true);

void help(){
     sieve[0] = false;
     sieve[1] = false;

     for(int i=2;i*i<=10000000;++i){
        if(sieve[i]){
            for(int j=i*i;j<=10000000;j+=i)
                sieve[j] = false;

        }
     }

}


ll exp(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}
*/

vector<ll> sum(200007,0);
vector<ll> adj[200007];
  void dfs(int x,int y)
  {
      sum[x]+=sum[y];
      for(auto xx:adj[x])
      {
          if(xx==y)
            continue;
          dfs(xx,x);
      }

  }
int main() {
   fastIO



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





   for(int i=0;i<n-1;++i)
   {
       int a,b;
       cin>>a>>b;
       adj[a].pb(b);
       adj[b].pb(a);

   }

   for(int i=0;i<q;++i)
   {
       int x,y;

       cin>>x>>y;
       sum[x]+=y;
   }

     dfs(1,0);

   for(int i=1;i<=n;++i)
      cout<<sum[i]<<" ";

	return 0;
}


Measured memory_bytes: 24320
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
#define REP(i,st,ed) for(int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(int i=st,i##end=ed;i>=i##end;--i)
const int maxn=100005,mod=1e9+7;
struct Mat{
	int s[3][3];
	void clear(){memset(s,0,sizeof(s));}
}RES,TMP;
long long ANS[3][3];
int n,m,pos[maxn];
void Mul(const Mat &G,Mat &H){
	REP(i,0,2)
		REP(j,0,2){
			ANS[i][j]=0;
			REP(k,0,2)
				ANS[i][j]+=1ll*G.s[i][k]*H.s[k][j]%mod;
		}
	REP(i,0,2)
		REP(j,0,2)
			H.s[i][j]=ANS[i][j]%mod;
}
void ksm(int y){
	if(y<=0)return;
	TMP.s[0][0]=1,TMP.s[0][1]=0,TMP.s[0][2]=1;
	TMP.s[1][0]=2,TMP.s[1][1]=1,TMP.s[1][2]=2;
	TMP.s[2][0]=1,TMP.s[2][1]=1,TMP.s[2][2]=2;
	while(y){
		if(y&1)Mul(TMP,RES);
		Mul(TMP,TMP),y>>=1;
	}
}
int main(){
	int x;
	scanf("%d%d",&n,&m);
	REP(i,1,m)scanf("%d",&pos[i]);
	RES.s[0][0]=1;
	RES.s[1][0]=2;
	RES.s[2][0]=1;
	REP(i,1,m){
		ksm(pos[i]-pos[i-1]-1);
		int k[3];
		REP(j,0,2)k[j]=RES.s[j][0];
		RES.clear();
		RES.s[0][0]=k[0];
		RES.s[1][0]=(k[1]+2ll*k[0])%mod;
		RES.s[2][0]=((k[0]+k[1])%mod+k[2])%mod;
	}
	ksm(n-pos[m]-1);
	printf("%d\n",RES.s[2][0]);
	return 0;
}

Measured memory_bytes: 640
import sys


def solve():
    N, K, *H = map(int, sys.stdin.read().split())
    dp = [0] * N
    for i in range(1, N):
        h_i = H[i]
        s = i-K if i-K > 0 else 0
        dp[i] = min(d_j + abs(h_i - h_j) for d_j, h_j in zip(dp[s:i], H[s:i]))
    return dp[-1]


if __name__ == "__main__":
    answer = solve()
    print(answer)


Measured memory_bytes: 13876
//#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

//ifstream cin ("x.in"); ofstream cout ("x.out");

const int nmax = 3000;
const int mod = 1e9 + 7;

int n, m;
int s[nmax + 1];
int d[nmax + 1][nmax + 1];

pair<int, int> w[nmax + 1];
vector< pair<int, int> > unu;

string vs;
int v[nmax + 1];

inline bool cmpdr (int x) {
    return x == 0;
}

inline bool cmpst (int x) {
    return x > 0;
}

void precalc() {
    unu.push_back(make_pair(0, 0));
    for (int i = 0; i < n; ++ i) {
        if (vs[ i ] == '1') {
            v[i + 1] = unu.size();
            unu.push_back(make_pair(0, 0));
        }
    }

    for (int i = 1; i <= m; ++ i) {
        stable_partition(v + w[ i ].first, v + w[ i ].second + 1, cmpdr);
    }

    for (int i = 1; i <= n; ++ i) {
        if (v[ i ]) {
            unu[ v[ i ] ].second = i;
        }
    }

    int shp = 0;
    for (int i = 0; i < n; ++ i) {
        if (vs[ i ] == '1') {
            v[i + 1] = ++ shp;
        } else {
            v[i + 1] = 0;
        }
    }

    for (int i = 1; i <= m; ++ i) {
        stable_partition(v + w[ i ].first, v + w[ i ].second + 1, cmpst);
    }

    for (int i = 1; i <= n; ++ i) {
        if (v[ i ]) {
            unu[ v[ i ] ].first = i;
        }
    }
}

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

    for (int i = 1; i <= m; ++ i) {
        int x, y;
        cin >> x >> y;
        w[ i ] = make_pair(x, y);
    }

    precalc();

    d[ 0 ][ 0 ] = 1;
    for (int i = 0; i <= n; ++ i) s[ i ] = 1;

    for (int i = 1; i < (int)unu.size(); ++ i) {
        for (int j = unu[ i ].first; j <= unu[ i ].second; ++ j) {
            d[ i ][ j ] = s[j - 1];
        }

        s[ 0 ] = 0;
        for (int j = 1; j <= n; ++ j) {
            s[ j ] = s[j - 1] + d[ i ][ j ];
            if (s[ j ] >= mod) {
                s[ j ] -= mod;
            }
        }
    }

    cout << s[ n ] << "\n";

    return 0;
}


Measured memory_bytes: 17408
S = input()
s = len(S)
K = int(input())

if len(set(list(S))) == 1:
    print(len(S) * K // 2)
else:
    l = []
    left = 0
    right = 1
    while right < s:
        if S[left] == S[right]:
            right += 1
            if right == s:
                l.append(right - left)
        else:
            if right - left > 1:
                l.append(right - left)
                left = right
                right += 1
            else:
                left = right
                right += 1
    l_o = l[:]
    l = [i // 2 for i in l]
    if S[0] == S[-1]:
        if S[0] != S[1] and S[-1] != S[-2]:
            print(sum(l) * K + K - 1)
        elif S[0] == S[1] and S[-1] == S[-2]:
            print(sum(l) * K - (l[0] + l[-1] - (l_o[0] + l_o[-1]) // 2) * (K - 1))
        elif S[0] == S[1]:
            print(sum(l) * K - (l[0] - (l_o[0] + 1) // 2) * (K - 1))
        else:
            print(sum(l) * K - (l[-1] - (l_o[-1] + 1) // 2) * (K - 1))
    else:
        print(sum(l) * K)

Measured memory_bytes: 3064
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<String, Integer> map = new HashMap<>();
		map.put("AC", 0);
		map.put("WA", 0);
		map.put("TLE", 0);
		map.put("RE", 0);
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			map.put(s, map.get(s) + 1);
		}
		sc.close();

		System.out.println("AC x " + map.get("AC"));
		System.out.println("WA x " + map.get("WA"));
		System.out.println("TLE x " + map.get("TLE"));
		System.out.println("RE x " + map.get("RE"));
	}
}


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


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, ans = 0;
    cin >> n;
    vi v(n);
    rep(i, n){
        cin >> v[i];
    }
    rep(i, n){
        int c;
        cin >> c;
        v[i] -=  c;
        if(v[i] > 0) ans += v[i];
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const [ s, t ] = readMany(2)
    let count = 0

    for (let i = 0; i < s.length; i += 1) {
        if (s[i] != t[i]) count += 1
    }

    console.log(count)
})()


Measured memory_bytes: 33024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        System.out.println(c - a + b < 0 ? 0 : c - a + b);
        sc.close();
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
 
#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 lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	const int MAX_N = 100;
	ll dp[MAX_N+1][4][4][4] = {};

	int N;
	cin >> N;

	dp[0][0][0][0] = 1;

	rep(i,0,N){
		rep(a,0,4){
			rep(b,0,4){
				rep(c,0,4){
					rep(d,0,4){
						if( b == 1 && c == 2 && d == 3 ) continue;
						if( b == 1 && c == 3 && d == 2 ) continue;
						if( b == 2 && c == 1 && d == 3 ) continue;
						if( a == 1 && b == 2 && d == 3 ) continue;
						if( a == 1 && c == 2 && d == 3 ) continue;
						dp[i+1][b][c][d] += dp[i][a][b][c];
						dp[i+1][b][c][d] %= mod;
					}
				}
			}
		}
	}

	ll ans = 0;
	rep(a,0,4) rep(b,0,4) rep(c,0,4){
		//cout << dp[N][a][b][c] << endl;
		ans += dp[N][a][b][c];
		ans %= mod;
	}

	cout << ans << endl;

	ret 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

int main()
{
    ll X, Y;
    cin >> X >> Y;
    bool f = false;
    REP(i,0,X+1) {
        ll t = i, k = X-i;
        if(t*2+k*4 == Y) {f = true; break;}
    }
    if(f) PR("Yes");
    else PR("No");


    return 0;
}

/*



*/

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


int main(){
    vector<int> cnt(26, 0);
    string w;
    cin >> w;
    for (int i = 0; i < (int)w.size(); i++){
        cnt[(int)(w[i] - 'a')]++;
    }
    for (int c : cnt) {
        if (c % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A.at(i);
  string aord = "APPROVED";
  for(int i=0; i<N; i++){
    if(A.at(i) % 2 == 0){
      if(A.at(i) % 3 != 0){
        if(A.at(i) % 5 != 0){
        	aord = "DENIED";
      	}
      }
    }
  }
   cout << aord << endl;
}

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

typedef long long ll;

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> arr(n);
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	vector<int> ans;
	for(int loop = 0; loop < n; loop++) {
		bool flag = false;
		for(int i = arr.size()-1; i >= 0; i--) {
			if(arr[i]==(i+1)) {
				ans.push_back(arr[i]);
				arr.erase(arr.begin()+i);
				flag = true;
				break;
			}
		}
		if(!flag) {
			cout << -1 << endl;
			return 0;
		}
	}
	for(int i = n-1; i >= 0; i--) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N,K,ans=0;
    cin>>N>>K;
    int l[N];
    for(int i=0;i<N;i++){
        cin>>l[i];
    }
    sort(l,l+N);
    for(int i=N-1;i>N-K-1;i--){
        ans+=l[i];
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int max = 0;
    int res = 1;
    for (int i = 1; i <= N; ++i) {
        bool can = true;
        int number = i;
        int count = 0;
        while(can) {
            if (number % 2 == 0) {
                number /= 2;
                ++count;
            }
            else {
                can = false;
                if (count > max) {
                    max = count;
                    res = i;
                }
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
# for i in range(n):
#     count = 0
#     while True:
#         if i+1 in a:
#             a.remove(i+1)
#             count += 1
#         else:
#             break
#     print(count)
b = [0]*n
for i in range(n-1):
    b[a[i]-1] += 1
for i in range(n):
    print(b[i])


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

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

    vector<int> b(n);
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }

    string ans = "";

    while((int)b.size() != 0){
        //cout << b.size();
        for (int i = b.size()-1; i >= 0; i--)
        {
            //cout << "!!" << endl;
            if(i+1 == b[i]){
                ans.insert(0, to_string(b[i])+"\n");
                b.erase(b.begin()+i);
                break;
            }
            if(i == 0){
                cout << -1 << "\n";
                return 0;
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int R, N; 
int x1,x2,h;
int B[50];
double ans = 10000.0;

double b(double x) {
	return (double) B[(int) (x + 25.0)];
	
}

double sun(double x) {
	double r = R;
	return sqrt(r * r - x * x) - r;
}

double f(double x) {
	return b(x) - sun(x);
}

int main() {
	cin >> R >> N;
	while(R + N) {
		ans = 10000000.0;
		for (int i = 0; i < 50; i ++) {
			B [i] = 0;
		}
		for (int i = 0; i < N; i++) {
			cin >> x1 >> x2 >> h;
			x1 += 25;
			x2 += 25;
			for (int x = x1; x < x2; x++ ) {
				B[x] = max(B[x], h);
			}
		}
		double r = R;
		for (double x = -r; x < r; x += 0.00001) {
			ans = min(ans, f(x));
		}
		printf("%f\n",ans);
		
		cin >> R >> N;
	}
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        if(!(i%3==0 || i%5==0))
            sum+=i;
    }
    cout<<sum;
}

Measured memory_bytes: 3652
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
#define rep(i, n) for (i32 i = 0; i < (i32)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
template <typename T>
class UnionFind
{
public:
    vector<T> par;
    UnionFind(T n) : par(n, -1) {}
    void init(T n)
    {
        for (i64 i = 0; i < n; i++)
        {
            par[i] = -1;
        }
    }

    i64 root(T x)
    {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool same(T x, T y)
    {
        return root(x) == root(y);
    }

    bool merge(T x, T y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    i64 size(T x)
    {
        return -par[root(x)];
    }
};
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n,m;
cin >> n >> m;
UnionFind uft(n);
rep(i,m){
    i64 a,b;
    cin >>a >> b;
    uft.merge(a - 1,b - 1);
}
i64 ans = 0;
rep(i,n){
    ans = max(ans,uft.size(i));
}
cout << ans << endl;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h> 
using namespace std;
const long INF=1000000000000000;
const long MOD=1000000007;

int main(){
    long A,B,C;
    cin>>A>>B>>C;
    
    if(C%__gcd(A,B)==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i =0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;

int main() {
	string n;cin>>n;
  if(n[2]==n[3]&&n[4]==n[5])cout<<"Yes";
  else cout<<"No";

}

Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}

#define trace(...) cerr<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,',');
    cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}

int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int n;

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    if(n&1) cout << 0;
    else{
        int ans=0;
        n/=2;
        int j=1;
        while(n){
            ans+=n/5;
            n/=5;
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int N,x,i,a=0;
char S[100];
cin >> N;
for(i=1;i<=N;i++){
cin >> S[i];
}
if(N%2==0){x=N/2*1;
for(i=1;i<=(N/2);i++){if(S[i]==S[i+N/2])a++;}
if(a==N/2){cout << "Yes" << endl;}else{cout << "No" << endl;}
}else{cout << "No" <<endl;}

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[100100];
long long sum[100100];
long long ans=0;
int main()
{
	cin>>n;
	for(int i=0;i<=n;i++) cin>>a[i];
	for(int i=n;i>=0;i--) sum[i]=sum[i+1]+a[i];
	long long now=1;ans=0;
	for(int i=0;i<=n;i++)
	{
		if(a[i]>now) return puts("-1"),0;
		ans+=now;now-=a[i];
		now=min(now+now,sum[i+1]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4796
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

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

    ll sum = 0;
    rep(i, S.size()) {
        sum += (S[i] - '0');
    }

    if (sum % 9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3752
N = int(input())
A = [0] + list(map(int, input().split())) + [0]

total_cost = 0
cost = [0] * (N+1)

for i in range(N+1):
    c = abs(A[i] - A[i+1])
    total_cost += c
    cost[i] = c

for i in range(N):
    print(total_cost - (cost[i]+cost[i+1]) + abs(A[i] - A[i+2]))


Measured memory_bytes: 20624
$><<x=y=[0,2].zip(*P=$<.map{|l|l.split.map(&:to_i)<<l}).all?{|f,w,j|l=w,0;(1..P[0][2]).all?{|k|4.times{|i|P[~h=i/2][1][~k]==:UDLR[f+i&=1]&&l[h^=i]=1-(g=i*2-l[h])+4[g]-1[w+g]};x,y=l;y<x}&&y<j&&j<=x}?:YES: :NO

Measured memory_bytes: 4476
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int H,W;cin>>H>>W;
    int Ch,Cw;cin>>Ch>>Cw;Ch--;Cw--;
    int Dh,Dw;cin>>Dh>>Dw;Dh--;Dw--;
    vector<vector<bool>> S(H,vector<bool>(W));
    vector<vector<int>> dist(H,vector<int>(W));
    for(int i=0;i<H;i++) for(int j=0;j<W;j++) dist[i][j] = 1e9;
    dist[Ch][Cw] = 0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            char c;cin>>c;
            if(c=='.') S[i][j] = true;
        }
    }
    const int di[] = {0,0,-1,1};
    const int dj[] = {-1,1,0,0};
    deque<pair<int,int>> que;
    que.push_back({Ch,Cw});
    while(que.size()){
        auto p = que.front();que.pop_front();
        int i = p.first, j = p.second;
        for(int k=0;k<4;k++){
            int i2 = i + di[k],j2 = j + dj[k];
            if(i2<0||i2>=H||j2<0||j2>=W) continue;
            if(!S[i2][j2]) continue;
            if(dist[i2][j2]>dist[i][j]){
                dist[i2][j2] = dist[i][j];
                que.push_front({i2,j2});
            }
        }
        for(int k=-2;k<3;k++){
            for(int l=-2;l<3;l++){
                int i2 = i + k,j2 = j + l;
                if(i2<0||i2>=H||j2<0||j2>=W) continue;
                if(!S[i2][j2]) continue;
                int d2 = dist[i][j] + 1;
                if(dist[i2][j2]>d2){
                    dist[i2][j2] = d2;
                    que.push_back({i2,j2});
                }
            }
        }
    }
    if(dist[Dh][Dw]!=1e9) cout << dist[Dh][Dw] << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 7736
while(1):
	N=int(input())
	if(N==0):
 	  exit()
	l=[]
	for i in range(9):
		tmp=int(input())
		l.append(tmp)
	ans=0
	for i in range(9):
		ans+=l[i]
		a=N-ans
	print(a)
	

Measured memory_bytes: 6720
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep1(n) rep2(i,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
int main(){
    ll n,h,w;
    cin>>n>>h>>w;
    ll a[1010],b[1010];
    ll ans=0;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        if(a[i]>=h&&b[i]>=w)ans++;
    }
    cout <<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int k,a,b,c,i;
    scanf("%d",&k);
    scanf("%d %d",&a,&b);
    for(i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            printf("OK");
            return 0;
        }
    }
    printf("NG");
    return 0;
}


Measured memory_bytes: 1704
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n;cin>>n;
  if(pow(int(sqrt(1+8*n)),2)!=1+8*n){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
    ll k=(1+int(sqrt(1+8*n)))/2;
    cout<<k<<endl;
    vector<set<ll>> v(k);
    ll cnt=1;
    rep(i,k-1){
      FOR(j,i+1,k){
        v[i].insert(cnt);
        v[j].insert(cnt);
        cnt++;
      }
    }
    rep(i,k){
      cout<<k-1;
      reps(x,v[i]){
        cout<<" "<<x;
      }
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//namespaces
using namespace __gnu_pbds; 
using namespace std;

//MACROS
#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long 
#define For(i,s,e) for (int i=(s); i<(e); i++)
#define Fod(i,s,e) for (int i=(s); i>=(e); i--)
#define pii pair<ll,ll>
#define f first
#define s second
#define endl "\n"
#define all(container) container.begin(), container.end()
#define mp make_pair

//debug
#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

//Templates
template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

//globals
ll const prime1 = 304933;
ll const prime2 = 15486277;
ll const mod = 1e9+7;
ll const inf = 1e18;
ll const size_1d = 1e6 + 7;
ll const size_2d = 1e3 + 7;

//functions
ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;} 
ll gcdext(ll a,ll b,ll *x = 0, ll *y = 0){if(a == 0){*x = 0;*y = 1;return b;}ll x1,y1;ll gcd1 = gcdext(b%a,a,&x1,&y1);*x = y1 - (b/a)*x1;*y = x1;return gcd1;}
int randomize(){return (rand()%10000);} 

// CODE STARTS HERE
std::vector<std::vector<int>> v(size_1d);
ll dp[size_1d][2];
void dfs(int a,int b = -1){
    dp[a][0] = 1;
    dp[a][1] = 1;
    for(auto &m : v[a]){
        if(m != b){
            dfs(m,a);
            dp[a][0] *= (dp[m][0] + dp[m][1])%mod;
            dp[a][1] *= dp[m][0];
            dp[a][0] %= mod;
            dp[a][1] %= mod;
        }
    }
}
int main(){
    IOS
    int n;cin >> n;
    For(i,0,n-1){
        int x,y;cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1,-1);
    cout << (dp[1][1] + dp[1][0])%mod << endl;
    return 0;
}

Measured memory_bytes: 31488
#include <stdio.h>
#include <string.h>
#define LEN 1000000

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN + 1];
int head = 0, tail = 0;

void enq(P x)
{
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P deq()
{
  P x = Q[head];
  head = (head + 1) % LEN;

  return x;
}

int time(int x, int y){
  if(x < y){
    return x;
  }
  else{
    return y;
  }
}

int main(void)
{
  int elaps = 0, c, i, n, q;
  P u;

  scanf("%d %d", &n, &q);

  for(i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n + 1;

  while(head != tail){
    u = deq();
    c = time(q, u.t);
    u.t -= c;                         //残り時間
    elaps += c;                       //経過時間

    if(u.t > 0){
      enq(u);
    }
    else{
      printf("%s %d\n", u.name, elaps);
    }
  }
  return 0;
}



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

int main(){
	string S,T;
	int A,B;
	string U;

	cin >> S >> T >> A>>B>>U;

	if(U == S){
		cout << A-1 <<" "<< B <<endl;
	}
	else cout << A << " " << B-1 <<endl;

	return 0;
}

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int N,M;
    cin >> N >> M;
    REP(_,M) {
        int a;
        cin >> a;
        N-=a;
        if (N < 0) {
            cout << -1 << endl;
            return;
        }
    }
    cout << N << endl;
}

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


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
using namespace std;
#define INF (1 << 30) - 1


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

  int ans = INF;
  for(int bit = 0; bit < (1 << n); ++bit){
    int num = 1;
    for(int i = 0; i < n; ++i){
      if(bit & (1 << i)){
        num *= 2;
      }
      else num += k;
    }
    if(num < ans)ans = num;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import(
  "fmt"
)

func main() {
  var n, k int
  fmt.Scan(&n, &k)
  
  heights := []int{}
  var h int
  for i := 0; i < n; i++ {
    fmt.Scan(&h)
    heights = append(heights, h)
  }
  
  count := 0
  for _, h := range heights {
    if h >= k {
      count++
    }
  }
  
  fmt.Println(count)
}

Measured memory_bytes: 7552