akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////


int main(){fastio
    ll n,k;cin>>n>>k;
    ll h[n];rep(i,0,n-1)cin>>h[i];
    ll dp[n];rep(i,0,n-1)dp[i]=inf;
    dp[0]=0;
    rep(i,1,n-1){
        rep(j,i-k,i-1){
            if(j>=0)Min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n-1]<<endl;
    
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N;
vector<ll> A;

int main(){
    cin >> N;
    A.resize(N);
    rep(i,N){
        cin >> A[i];
    }

    vector<ll> rsum(N+10);  // rsum[i] = A[0] + .. + A[i-1]
    rsum[0] = 0;
    for(int i=0;i<N;i++){
        rsum[i+1] = rsum[i] + A[i];
    }

    map<ll,ll> cnt;
    cnt[0] = 1;
    ll ans = 0;
    for(int i=0;i<N;i++){   // [? .. A[i]]
        ll val = rsum[i+1];
        ans += cnt[val];
        cnt[val]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> R,G,B;
    string s;
    cin >> s;
    for(int i=0; i<n; i++) {
        char c=s[i];
        if ( c=='R' ) R.push_back(i);
        if ( c=='G' ) G.push_back(i);
        if ( c=='B' ) B.push_back(i);
    }

    LL ans=0;
    for (int i=0; i<n; i++) {
        for (int j=i-1; j>=0; j--) {
            if ( s[i]==s[j] ) continue;
            if ( s[i]=='R' ) {
                if ( s[j]=='G' ) {
                    auto it=upper_bound(ALL(B), i);
                    int ok=(i+i-j<n && s[i+i-j]=='B'? 1:0);
                    ans += B.end()-it-ok;
                }
                if ( s[j]=='B') {
                    auto it=upper_bound(ALL(G), i);
                    int ok=(i+i-j<n && s[i+i-j]=='G'? 1:0);
                    ans += G.end()-it-ok;                    
                }
            }
            if ( s[i]=='G' ) {
                if ( s[j]=='R' ) {
                    auto it=upper_bound(ALL(B), i);
                    int ok=(i+i-j<n && s[i+i-j]=='B'? 1:0);
                    ans += B.end()-it-ok;
                }
                if ( s[j]=='B') {
                    auto it=upper_bound(ALL(R), i);
                    int ok=(i+i-j<n && s[i+i-j]=='R'? 1:0);
                    ans += R.end()-it-ok;
                }
            }
            if ( s[i]=='B' ) {
                if ( s[j]=='R' ) {
                    auto it=upper_bound(ALL(G), i);
                    int ok=(i+i-j<n && s[i+i-j]=='G'? 1:0);
                    ans += G.end()-it-ok;
                }
                if ( s[j]=='G') {
                    auto it=upper_bound(ALL(R), i);
                    int ok=(i+i-j<n && s[i+i-j]=='R'? 1:0);
                    ans += R.end()-it-ok;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3692
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long
const int dx[4] = { 1,-1,0,0 };
const int dy[4] = { 0,0,1,-1 };
bool OOA(int x,int y,int H,int W){return (0<=x&&x<H)&&(0<=y&&y<W);}

struct Graph {
	int V, E, t;
	//vector<int>cost;
	vector<int>gr;
	//vector<bool>vzt;
	vector<vector<int>>adj;
	void init(int dflt) {//dflt!=0
		adj = vector<vector<int>>(V + 1);
	//	cost = vector<int>(V + 1, dflt);
		gr = vector<int>(V + 1, dflt);
	//	vzt = vector<bool>(V + 1, false);
	}

	void dfs(int now) {
		if (gr[now] == -1) { gr[now] = t; }
		else return;
		for (int i = 0;i<adj[now].size();i++)dfs(adj[now][i]);
		return;
	}

	void CC(){
		for(int i=0;i<V;i++){
			if(gr[i]==-1){
				t=i;
				dfs(i);
			}
		}
		return;
	}
};

Graph G;
int n,m,q;

int main() {
	cin>>n>>m;
	G.V=n;
	G.init(-1);
	for(int i=0;i<m;i++){
		int s,t;
		cin>>s>>t;
		G.adj[s].push_back(t);
		G.adj[t].push_back(s);
	}
	G.CC();
	cin>>q;
	for(int i=0;i<q;i++){
		int s,t;
		cin>>s>>t;
		cout<<(G.gr[s]==G.gr[t]?"yes":"no")<<endl;
	}
	return 0;
}


Measured memory_bytes: 10468
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%mood;
		x = x * x%mood;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

string s;

signed main() {
	cin >> s;
	if (s == "Sunny")cout << "Cloudy" << endl;
	else if (s == "Cloudy")cout << "Rainy" << endl;
	else cout << "Sunny" << endl;
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




int n;
double x[55], y[55], X, Y, d, e;
double dist(double a, double b)
{
    return a*a + b*b;
}

int main()
{
//    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    S("%d", &n);
	for (int i = 0; i < n; i++)
    {
		S("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double p = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*p;
		Y += (y[f] - Y)*p;
		p *= 0.999;
	}
	P("%.10lf",sqrt(d));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>

using namespace std;
int main(void){
    int a; cin>>a;
    int c=a;
    int b=0;
    for(int i=0;i<10;i++){
        b+=c%10;
        c/=10;
    }
    if(a%b==0)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int x = 0;
		int max = 0;
		for(int i=0; i<n; i++){
			x = s.charAt(i) == 'I' ? x + 1 : x - 1;
			if(x > max){
				max = x;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 35584
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

struct PQ{
	ll p;
	ll q;
};

int main()
{
	int N;
	ll X[50];
	ll Y[50];
	
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> X[i] >> Y[i];
	}
	
	if( N == 1){
		cout << "1" << endl;
		return 0;
	}
	
	vector<PQ> pqs;
	for(int i = 0; i < N-1; i++){
		for(int j = i+1; j < N; j++){
			ll p = (X[i] - X[j]);
			ll q = (Y[i] - Y[j]);
			PQ pq;
			pq.p = p;
			pq.q = q;
			pqs.push_back(pq);
		}
	}
	
	int ans = 9999999;
	for(int i = 0; i < pqs.size(); i++){
		PQ pq = pqs[i];
		bool Done[50];
		for(int j = 0; j < N; j++){
			Done[j] = false;
		}
		
		int count = 0;
		for(int j = 0; j < N; j++){
			if(!Done[j]){
				count++;
				PQ xy = {X[j], Y[j]};
				vector<PQ> xys;
				xys.push_back(xy);
				
				for(int r = 0; r < N; r++){
					for(int k = j+1; k < N; k++){
						if(Done[k]){
							continue;
						}
						for(int XY = 0; XY < xys.size(); XY++){
							if(((xys[XY].p-X[k]) == pq.p && (xys[XY].q-Y[k]) == pq.q) || ((xys[XY].p-X[k]) == -pq.p && (xys[XY].q-Y[k]) == -pq.q)){
								Done[k] = true;
								PQ xy2 = {X[k], Y[k]};
								xys.push_back(xy2);
								break;
							}
						}
					}
				}
			}
		}
		ans = min(ans, count);
		// cout << pq.p << " " << pq.q  << " : " << count << endl;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
K , N  = map(int,input().split())
A = list(map(int,input().split()))
max_dist = A[0] - A[N-1] + K
for i in range(N-1):
    if max_dist <= A[i+1] - A[i]:
        max_dist = A[i+1] - A[i]
print(K - max_dist)

Measured memory_bytes: 26444
using System;using System.Linq;
class PRO {static void Main(){
int []a=Console.ReadLine().Split().Select(int.Parse).ToArray();
int n=a[0]+a[1];
if(n==0){Console.WriteLine(0);}
else if(n<0){Console.WriteLine(-1);}
else if(n>0){Console.WriteLine(1);}


}}

Measured memory_bytes: 9600
#include<stdio.h>

int main(void)
{
	int i, a, b,r=0,w=0;
	int n, m, sum=0,sum2=0;
	char c[200001];

	scanf("%d", &n);
	scanf("%s",&c);
	for (int i = 0;i < n;i++) {
		if (c[i] == 'R') {
			r++;
		}if (c[i] == 'W') {
			w++;
		}
	}
	for (int i = 0;i < r;i++) {
		if (c[i] == 'W') {
			sum++;
		}
	}
	for (int i = r;i < n;i++) {
		if (c[i] == 'R') {
			sum2++;
		}
	}
	if (r == 0) {
		printf("0");
		return 0;
	}
	if (w == 0) {
		printf("0");
		return 0;
	}
	if (sum == 0) {
		printf("%d", sum2);
		return 0;
	}
	if (sum2 == 0) {
		printf("%d", sum);
		return 0;
	}

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 1924
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

typedef long long ll;
const ll INF = 1e12;

typedef std::pair< ll, ll > P;

const ll MAX_N = 100;
const ll MAX_W = 1e9;
const ll MAX_DIFF = 3;

// 最大価値 = i個目まで選択, j個選択, 重さk(差分のみで計算)
ll dp[MAX_N+1][MAX_N+1][MAX_DIFF * MAX_N + 1];

int main(int argc, char* argv[])
{
  ll N, W;
  std::cin >> N >> W;
  std::vector< P > vp(N+1, std::make_pair(0, 0));

  std::cin >> vp[0].first >> vp[0].second;
  ll base_w = vp[0].first;
  vp[0].first = 0;
  for (ll i = 1; i < N; i++) {
    std::cin >> vp[i].first >> vp[i].second;
    vp[i].first -= base_w;
  }

  // Initialize
  for (ll j = 0; j <= MAX_N; j++) {
    for (ll w = 1; w <= MAX_DIFF * MAX_N; w++) {
      dp[0][j][w] = -INF;
    }
  }
  for (ll i = 1; i <= N; i++) {
    for (ll j = 1; j <= i; j++) {
      ll max_w = 3 * j;
      for (ll k = 0; k <= max_w; k++) {
	if (W - base_w * j - k >= 0 && k - vp[i-1].first >= 0) {
	  dp[i][j][k] = std::max(dp[i-1][j-1][k-vp[i-1].first] + vp[i-1].second, dp[i-1][j][k]);
	} else {
	  dp[i][j][k] = dp[i-1][j][k];
	}
      }
    }
  }

  ll ans = 0;
  for (ll j = 0; j <= N; j++) {
    for (ll k = 0; k <= MAX_DIFF * MAX_N; k++) {
      if (W - base_w * j - k >= 0) {
	ans = std::max(ans, dp[N][j][k]);
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 22528
<?php
list($n) = ints();
for ($i = 0; $i < $n; ++$i) list($a[]) = ints();
$cur = 0;
$cnt = 0;
$used[0] = true;
while (true) {
    $cnt++;
    $cur = $a[$cur];
    $cur--;
    if (isset($used[$cur])) exit('-1');
    if ($cur === 1) break;
    $used[$cur] = true;
}
echo $cnt;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 17140
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <iomanip>
#include <cmath>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>

#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long 
//#define int long long
#define ld long double
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define iii pair<int,ii>
#define il pair<ll,ll>
#define vv vector
//#define endl '\n'
using namespace std;
const int MAXN = 700 + 5;

set<ii> s[(1<<18)];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int xx = n;
    n = (1<<n);
    int arr[n];
    FOR(i,n)cin >> arr[i];
    FOR(i,n)s[i].insert({arr[i],i});
    FOR(i,n){
    	FOR(j,xx){
    		int v = i|(1<<j);
    		if(v != i){
    			for(auto e: s[i])s[v].insert(e);
    			while(s[v].size() > 2)s[v].erase(s[v].begin());
    		}
    	}
    }
    int mx = 0;
    FOR(i,n){
    	int sum = 0;
    	//cout << "FOR: " << i << " : ";
    	//for(auto e: s[i])cout << e.ff << " ";cout << endl;
    	for(auto e :s[i])sum += e.ff;
    	mx = max(mx,sum);
    	if(i > 0)cout << mx << endl;
    }

    return 0;
}


Measured memory_bytes: 41512
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int h,w;cin>>h>>w;
    string s;
    for(int j=0;j<w+2;j++) cout<<"#";
    cout<<endl;
    for(int i=0;i<h;i++){
        cin>>s;
        cout<<"#"<<s<<"#"<<endl; 
    }
    
    for(int j=0;j<w+2;j++) cout<<"#";
    cout<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,g=0,max=0;
	while(scanf("%d",&a),a!=0)
	{
		for(e=0;e<a;e++)
		{
			scanf("%d %d %d",&b,&c,&d);
			f=c+d;
			if(max<f)
			{
				max=f;
				g=b;
			}
		}
		printf("%d %d\n",g,max);
		max=0;
	}
	return 0;
}

Measured memory_bytes: 2568
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int H, W, visited[100][100], ans;
const int di[4] = {-1, 0, 1, 0}, dj[4] = {0, 1, 0, -1};
char S[100][100];

int main(){
  cin >> H >> W;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> S[i][j];
      if (S[i][j] == '.') ans++;
    }
  }
  fill((int*)visited, (int*)(visited + H), -1);

  visited[0][0] = 1;
  queue <Pii> que; que.push(make_pair(0, 0));

  while (!que.empty()){
    Pii Q = que.front(); que.pop();
    int i = Q.first, j = Q.second;
    for (int k = 0; k < 4; k++){
      int I = i + di[k], J = j + dj[k];
      if (0 <= I && I < H && 0 <= J && J < W){
        if (S[I][J] == '.' && visited[I][J] == -1){
          visited[I][J] = visited[i][j] + 1;
          que.push(make_pair(I, J));
        }
      }
    }
  }
  
  if (visited[H - 1][W - 1] == -1){
    cout << -1 << endl;
  }else{
    cout << ans - visited[H - 1][W - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
def calc(x):
  ans = 0
  while (x % 2 == 0):
    ans += 1
    x //= 2
  return ans

def resolve():
  n = int(input())
  a = list(map(int, input().split()))
  ans = 0
  for x in a:
    ans += calc(x)
  print(ans)
  return

if __name__ == "__main__":
  resolve()


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


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}

int main(){
    ll N;
    cin>>N;
    if(N%1000 == 0)cout<<0;
    else cout<<1000-(N%1000);
    
    return 0;
}

Measured memory_bytes: 3632
from math import *
x, k, d = map(int, input().split())
x = abs(x)
z = ceil(x/d)
if x-k*d >= 0:
    print(x-k*d)
else:
    if (k-z)%2 == 0:
        print(abs(x-z*d))
    else:
        print(x-z*d+d)

Measured memory_bytes: 61848
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;

int main() {
    string str1, str2;
    cin >> str1 >> str2;
    str1 += str1;
    for (int i = 0; i < str1.size() - str2.size() + 1; i++) {
        if (str1.substr(i, str2.size()) == str2) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3200
<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));

if (0 < $a) {
    echo 'Positive';
} elseif ($a * $b <= 0){
    echo 'Zero';
} else {
    if(($b - $a + 1) % 2 == 1 || $a == $b){
        echo 'Negative';
    } else {
        echo 'Positive';
    }
}

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

int main() {
    string S;
    cin >> S;
    int A = stoi(S.substr(0, 2)), B = stoi(S.substr(2));
    if ((0 < A && A <= 12) && (0 < B && B <= 12)) cout << "AMBIGUOUS" << endl;
    else if ((0 < A && A <= 12) && (B == 0 || B > 12)) cout << "MMYY" << endl;
    else if ((0 < B && B <= 12) && (A == 0 || A > 12)) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}

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

using namespace std;

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

typedef long long ll;

const int N_MAX = 100000;
const int M_MAX = 200000;

int N, M;
int u[M_MAX];
int v[M_MAX];

vector<int> G[N_MAX];
int color[N_MAX];

bool dfs(int v, int c) {
  bool ret = false;
  color[v] = c;
  REP(i, G[v].size()) {
    int u = G[v][i];
    if (color[u] == 0) {
      ret |= dfs(u, 3 - c);
    } else if (color[u] == c) {
      ret = true;
    }
  }
  return ret;
}

void build_graph() {
  REP(i, M) {
    G[u[i] - 1].push_back(v[i] - 1);
    G[v[i] - 1].push_back(u[i] - 1);
  }
}

void solve() {
  build_graph();

  ll si = 0;
  ll bi = 0;
  ll ot = 0;
  REP(v, N) {
    if (color[v] == 0) {
      bool ret = dfs(v, 1);
      if (G[v].size() == 0) {
        si++;
      } else {
        ret ? ot++ : bi++;
      }
    }
  }

  ll ans = 0;
  ans += si * N * 2 - si * si;
  ans += (bi + ot) * (bi + ot);
  ans += bi * bi;
  printf("%lld\n", ans);
}

void input() {
  scanf("%d%d", &N, &M);
  REP(i, M) scanf("%d%d", u + i, v + i);
}

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


Measured memory_bytes: 13312
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 100000000;

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}

int factrial(int n){
    if(n==0){
        return 1;
    }else{
        return n*factrial(n-1);
    }
}

int main(void){
    string s,t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}

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

using namespace std;

int main(){
    int N;
    bool ans = false;
    cin >> N;

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(4*i+7*j==N){
                ans = true;
                break;
            }
        }
        if(ans==true) break;
    }
    cout << (ans==true ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

void main() {
    int A; readf("%d\n", &A);
    int x = 1;
    int k;
    for (k = 1; x < A; x += k + 1, k++) {}
    int d = x - A;
    char[] ans;
    for (int l = k; d >= 0 && l > 0; l--) {
        int m = (l == k ? k - 1 : l);
        if (d - m < 0) {
            foreach (i; 0 .. l) ans ~= ')';
            foreach (i; 0 .. l) ans ~= '(';
            swap(ans[2 * (l - k) + l - d], ans[2 * (l - k) + l]);
            break;
        } else {
            d -= m;
            ans ~= (l == k ? ")(" : "()");
        }
    }
    writeln(ans);
}

Measured memory_bytes: 2476
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

signed main(void)
{
  int n, y;
  cin >> n >> y;

  int a = y/10000, b=(y-a*10000)/5000, c=(y-a*10000-b*5000)/1000;
  int dif = n-(a+b+c);
  if(dif < 0) {
    cout << "-1 -1 -1" << endl;
    return 0;
  }

  while(dif > 0) {
    if(dif >= 4 && b>0) b--, c+=5, dif -= 4;
    else if(a>0) a--, b+=2, dif--;
    else {
      cout << "-1 -1 -1" << endl;
      return 0;
    }
  }
  cout << a << " " << b << " " << c << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
from itertools import permutations
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

N, M, R = [int(x) for x in input().strip().split()]
r = [int(x) for x in input().strip().split()]
G = [[float('inf')] * N for _ in range(N)]
for m in range(M):
    a, b, c = [int(x) for x in input().strip().split()]
    G[a-1][b-1] = c
    G[b-1][a-1] = c

for n in range(N):
    G[n][n] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            G[i][j] = min(G[i][j], G[i][k] + G[k][j])

ans = float('inf')
for rr in permutations(r):
    ans_ = 0
    for i in range(len(rr)-1):
        ans_ += G[rr[i]-1][rr[i+1]-1]
    ans = min(ans, ans_)
print(ans)    

Measured memory_bytes: 68700
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let n = read::<i64>();
    let an = read_vec::<i64>();
    let ans= an.iter().fold(0,|x,y| x+solve(*y));
    println!("{}",ans);
}

fn solve(x:i64) -> i64{
    let mut sub = x;
    let mut count = 0;
    loop {
        if sub % 2 != 0 {
            break;
        }else{
            sub = sub /2;
            count = count + 1;
        }
        
    }
    count
}

Measured memory_bytes: 4352
fun main(args:Array<String>?): Unit {
    while(true) {
        val (r0, w0, c, r) = readLine()!!.trim().split(' ').map(String::toLong)
        if (r0 == 0L && w0 == 0L && c == 0L && r == 0L) return
        println(if (r0 >= c * w0) 0 else (w0 * c - r0 + r - 1) / r)
    }
}


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

typedef long long ll;
typedef pair<int, int> ii;

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);

    printf("%d\n", n * (n - 1) / 2 + m * (m - 1) / 2);

    return 0;
}


Measured memory_bytes: 256
s=list(map(int,input().split()))
a=0
if s[0]<s[1]:
  a=a+s[1]
  s[1]=s[1]-1
else:
  a=a+s[0]
  s[0]=s[0]-1
  
if s[0]<s[1]:
  a=a+s[1]
  s[1]=s[1]-1
else:
  a=a+s[0]
  s[0]=s[0]-1
print(a)

Measured memory_bytes: 3060
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    ans = set()
    a, b, k = map(int, input().split())
    for i in range(a, min(b + 1, a + k)):
        ans.add(i)
    for i in range(b, max(a - 1, b - k), -1):
        ans.add(i)
    for i in sorted(ans):
        print(i)

main()


Measured memory_bytes: 3060
import java.util.Scanner;

//Treasure Hunt
public class Main{

	public static class P{
		public double x;
		public double y;
		public P(double x, double y) {
			this.x = x;
			this.y = y;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x = 0;
		double y = 0;
		int a = 0;
		while(true){
			String[] s = sc.next().split(",");
			int l = Integer.parseInt(s[0]);
			int da = Integer.parseInt(s[1]);
			if(l==0&&da==0)break;
			P p = rotate(l, a);
			x += p.x;
			y += p.y;
			if(da<0)da+=360;
			a+=da;
			a%=360;
		}
		System.out.printf("%d\n%d\n", (int)x, (int)y);
	}
	
	public static P rotate(int l, int a){
		double dx = l*Math.sin(a*Math.PI/180.0);
		double dy = l*Math.cos(a*Math.PI/180.0);
		return new P(dx, dy);
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)
#define ALL(x) (x).begin(),(x).end()
const char* LF = "\n";
namespace{struct _{_(){
    cin.tie(0);
    ios::sync_with_stdio(false);
}}a;}

vector<ll> A;
vector<ll> Ai_i;

signed main() {
    int N;
    cin >> N;
    A.resize(N+1, 0);
    FOR(i, 1, N+1) cin >> A[i];
    
    Ai_i.resize(N+1, 0);
    FOR(i, 1, N+1) {
        Ai_i[i] = A[i] - i;
    }
    sort(Ai_i.begin()+1, Ai_i.end());

    auto b = Ai_i[(N+1)/2];

    ll ans = 0;
    FOR(i, 1, N+1) {
        ans += abs(A[i] - (b + i));
    }

    cout << ans << LF;
    return 0;
}


Measured memory_bytes: 3328
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, D = LI()

x = 2*D + 1
res = N//x
if N % x > 0:
    res += 1
print(res)


Measured memory_bytes: 67052
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
answer = 1
if 0 in A:
    print(0); exit()
for a in A:
    answer *= a
    if answer > 10 ** 18:
        print(-1); exit()
print(answer)


Measured memory_bytes: 21644
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
  int64_t N,M;
  cin>>N>>M;
  string s,t;
  cin>>s>>t;
  int64_t n=__gcd(N,M);
  if(s[0]!=t[0]){cout<<-1<<endl;}
  else{
    if(n==1){cout<<N*M/n<<endl;return 0;}
    for(int i=1;i<n;i++){
    if(s[i*N/n]!=t[i*M/n]){cout<<-1<<endl;return 0;}
  }
    cout<<N*M/n<<endl;
  }
  return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <string.h>
#include <vector>
#include <map>
using namespace std;
#define ll long long

int main () {
  ll n, m;
  cin >> n >> m;
  ll x[m];
  ll sum[m - 1];
  for (ll i = 0; i < m - 1; i++) {
    sum[i] = 0;  
  }
  for (ll i = 0; i < m; i++) {
    cin >> x[i];
  }
  if (n >= m) {
    cout << 0 << endl;
    return 0;  
  }
  sort(x, x + m);
  for (ll i = 1; i < m; i++) {
    sum[i-1] = x[i] - x[i - 1];  
  }
  sort(sum, sum + m - 1);
  ll ans = 0;
  for (ll i = 0; i < m - n; i++) {
    ans += sum[i];
  }
  cout << ans << endl;

    
}

Measured memory_bytes: 1792
// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef pair<int, int> p;
typedef long long ll;

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  ll n;
  cin >> n;
  ll res = 0;
  vector<int> a(n + 1, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  // rep(i, n + 1) cout << a[i] << ' ';
  // cout << endl;
  for (int i = 1; i <= n; i++) {
    res += (ll)a[i] * (ll)i;
  }
  cout << res << endl;
}


Measured memory_bytes: 42336
#include <bits/stdc++.h>
#define int int64_t
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
using namespace std;
//using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

//プロトタイプ宣言
//int myfunc(int, vvec);

//グローバル変数
//int N, M;
//vvec data(N, vec(M));

//関数：
int gcd(int mx, int mn) {
	if(mn == 0) return(mx);
	else gcd(mn, mx%mn);
}

bool has_divisor(int n, int i) {
	//base case 1:
	if (i == n) return false;
	//base case 2:
	if (n % i == 0) return true;
	return has_divisor(n, i+1);
}

bool is_prime(int n) {
	if (n == 1) return false;
	else if (n == 2) return true;
	else {
		return !has_divisor(n, 2);
	}
}

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

	int N; cin >> N;
	vec d(N);
	rep(i, N) cin >> d[i];
	int ans = 0;
	rep(i, N)rep(j, N) {
		if(i < j) {
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
	return 0;
}
//std::string str;
//str = std::to_string(int i);
//bitset<3> s(N);
//int ans = (char)grid - '0';

Measured memory_bytes: 256
use std::io::prelude;
use std::{io};
use std::collections::{HashMap, HashSet, VecDeque};
use std::cmp::Ordering;

fn string_to_nums(s: String) -> Vec<isize> {
    let mut v = Vec::new();
    for part in s.split_whitespace() {
        v.push(part.parse::<isize>().unwrap())
    }
    v
}

fn read_a_line() -> String {
    let mut s = String::new();
    assert!(io::stdin().read_line(&mut s).is_ok());
    s.trim().to_string()
}

fn read_nums() -> Vec<isize> {
    string_to_nums(read_a_line())
}

fn main() {
    let s = read_a_line();
    let mut ss:Vec<_> = s.as_str().split_whitespace().collect();
    let mut c:char = ss[0].chars().last().unwrap();
    for s in ss.into_iter().skip(1) {
        if s.chars().next().unwrap() != c { println!("NO"); return }
        c = s.chars().last().unwrap();
    }
    println!("YES");
}


Measured memory_bytes: 4352
#include<stdio.h>
void swap(int *, int *);

int main(){
  int A[100],N,i,j,k,minj,cnt=0;

  //入力
  scanf("%d",&N);
  for(k=0; k<N; k++){
    scanf("%d",&A[k]);
  }

  //selection sort
  for(i=0; i<N; i++){
    minj = i;
    for(j=i; j<N; j++){
      if(A[j] < A[minj]) minj = j;
    }
    if(A[i] != A[minj]) cnt++;
    swap(&A[i],&A[minj]);
  }

  for(k=0; k<N; k++){
    if(k>0)printf(" ");
    printf("%d",A[k]);
  }
  printf("\n");
  printf("%d\n",cnt);
}

void swap(int *a, int *b){
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;

  return;
}



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

int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  vector<int> x(N);
  for (int i=0; i<N; i++) {
    cin >> x[i];
  }
  int len = 0;
  for (int j=0; j<N; j++) {
    if (x[j] <= K / 2) {
      len += x[j];
    }
    else {
      len += (K - x[j]);
    }
  }
  cout << len * 2 << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

struct item{
    ll a,b;
};

bool asc( const item& left, const item& right ) {
    return left.a == right.a ? left.b < right.b : left.a < right.a;
}

int main() {
    

    ll n,m;
    cin >> n >> m;
    vector <item> v;
    for (ll i=0;i<n;i++){
        item p;
        cin >> p.a >> p.b;
        v.push_back(p);
    }
    sort(v.begin(), v.end(), asc);
    ll ans = 0;
    ll idx = 0;
    while(m > 0){
        if(v[idx].b >= m){
            ans += v[idx].a * m;
            m = 0;
        }else{
            ans += v[idx].a * v[idx].b;
            m -= v[idx].b;
            idx++;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 2420
#include <stdio.h>

int main (void){
	char S[13];
	int i;
	scanf("%s", &S);
	for(i = 0;i<4;i++){
		printf("%c", S[i]);
	}
	printf(" ");
	for(;i<12;i++){
		printf("%c", S[i]);
	}
	printf("\n");
	

	return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int k;
	cin >>k;
	if(k <=12){cout <<k <<"\n"; return 0;}
	
	queue<ll> q;
	rep2(i,1,10) q.push(i);
	k -=9;
	while(k>0){
		ll cr = q.front(); q.pop();
		if(cr%10 !=0){
			k--; if(k==0){cout <<cr*10 + cr%10 -1 <<"\n"; return 0; }
			q.push(cr*10 + cr%10-1);
		}
		k--;if(k==0){cout <<cr*10 + cr%10 <<"\n"; return 0; }
		q.push(cr*10 + cr%10);
		if(cr%10 !=9){
			k--; if(k==0){cout <<cr*10 + cr%10 +1 <<"\n"; return 0; }
			q.push(cr*10 + cr%10+1);
		}
		
	}
	
	return 0;
}


Measured memory_bytes: 3868
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int A,B;
	scan(A>>B);
	if(A%2==B%2) prin((A+B)/2);
	else prin("IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll N,X;
ll num1[51], num2[51];//サイズ　パティの数
//depth index
ll cnt(ll d, ll ind){
    //cout << d << " " << ind << endl;
    if(d == 0)return 1;
    if(ind == 1)return 0;
    if(ind == num1[d-1] + 2)return num2[d-1] + 1;
    if(ind == num1[d-1] * 2 + 3)return num2[d];

    if(ind < num1[d-1] + 2)return cnt(d-1, ind-1);
    else                 return cnt(d-1, ind - num1[d-1] - 2) + num2[d-1] + 1;
}
main(){
    cin >> N >> X;
    num1[0] = num2[0] = 1;
    rep(i,0,N){
        num1[i+1] = num1[i] * 2 + 3;
        num2[i+1] = num2[i] * 2 + 1;
    }
    
    //rep(i,0,N+1)cout << num1[i] << " " << num2[i] << endl;
    //cout << endl;
    cout << cnt(N, X) << endl;

}

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

int root[200010]; //root[i]=i's parent
int element[200010]; //element[i]=i's group's element
//element[find(i)] is better
 
void init(int n){
  for(int i=0;i<n;i++) root[i]=i,element[i]=1;
}//reset
int find(int x){
  if(root[x]==x){
    return x;
  }
  else{
    return root[x]=find(root[x]);
  }
}//search x's parent
bool same(int x,int y){
  return find(x)==find(y);
}
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;
  root[x]=y;
  element[y]+=element[x];
}//x"->"y

int main(){
  int n,m;
  cin>>n>>m;
  init(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    unite(a,b);
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans=max(ans,element[i]);
  }
  cout<<ans<<endl;
}

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;
    //arc59c
    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        int[] a = in.ni(n);
        int min = inf;
        for (int i = -100; i <= 100; i++) {
            int loss = 0;
            for (int j = 0; j < n; j++) {
                loss += (i-a[j])*(i-a[j]);
            }
            min = Math.min(min, loss);
        }
        out.println(min);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 21204
H, W = map(int, input().split())
a = [list(map(str, input())) for i in range(H)]
counter = []

for i in range(H):
    if list(set(a[i])) != ["."]:
        counter.append(list(a[i]))

b = list(zip(*counter))
banswer = []

for i in range(W):
    if list(set(b[i])) != ["."]:
        banswer.append(list(b[i]))

answer = list(zip(*banswer))

for j in answer:
    result = "".join(j)
    print(result)


Measured memory_bytes: 9488
n = int(input())
s = input()
ans = 0
for i in range(len(s)):
    z = []
    cnt = 0
    x = s[0:i+1]
    y = s[i+1:len(s)]
    for j in range(len(x)):
        if x[j] in y and not x[j] in z:
            z.append(x[j])
            cnt += 1
    ans = max(cnt,ans)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <functional>
using namespace std;

int main ()  {
  
    int n;
    cin >> n;
    string name;
    int score;
    int counter = 1;
    map<string, vector<pair<int,int>>> map;
    for(int i = 0; i < n; i++){
        cin >> name;
        cin >> score;
        
        map[name].emplace_back(score, counter++);
    }
     
/*    typedef std::function<bool(pair<int, int>) Sort = [&](pair<int, int> pair_sort) {

     return pair_sort.first > pair_sort.second;
    };
*/
     for(auto it = begin(map); it != end(map); it++) {
        sort(it->second.rbegin(), it->second.rend());
    }



    for(auto it = begin(map); it != end(map); it++) {
    	for(auto each_score : it->second) {
    	cout <<	each_score.second << "\n"; 
    	}
    }


	return 0;
    
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int b,c[5],i,j;

  while(scanf("%d,%d,%d,%d,%d",c,c+1,c+2,c+3,c+4)!=EOF){
    for(i=0;i<4;i++) for(j=i+1;j<5;j++) if(c[i]>c[j]) { b=c[i];c[i]=c[j];c[j]=b; }
    if((c[0]+1==c[1] && c[1]+1==c[2] && c[2]+1==c[3] && c[3]+1==c[4]) ||
       (c[0]==1 && c[1]==10 && c[2]==11 && c[3]==12 && c[4]==13)) printf("straight\n");
    else if((c[0]==c[1] && c[0]==c[2] && c[0]==c[3]) || (c[1]==c[2] && c[1]==c[3] && c[1]==c[4])) printf("four card\n");
    else if((c[0]==c[1] && c[0]==c[2] && c[3]==c[4]) || (c[0]==c[1] && c[2]==c[3] && c[2]==c[4])) printf("full house\n");
    else if((c[0]==c[1] && c[1]==c[2]) || (c[1]==c[2] && c[2]==c[3]) || (c[2]==c[3] && c[3]==c[4])) printf("three card\n");
    else if((c[0]==c[1] && (c[2]==c[3] || c[3]==c[4])) || (c[1]==c[2] && c[3]==c[4])) printf("two pair\n");
    else if(c[0]==c[1] || c[1]==c[2] || c[2]==c[3] || c[3]==c[4]) printf("one pair\n");
    else printf("null\n");
  }

  return 0;
}

Measured memory_bytes: 580
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using lli=int64_t;

int main() {
    int N,M;
    cin>>N>>M;
    vector<int> card(N+2);
    for(int i=1;i<=M;++i){
        int l,r;
        cin>>l>>r;
        card[l]+=1;
        card[r+1]-=1;
    }
    int no=0;
    int ans=0;
    for(int i=1;i<=N;++i){
        no+=card[i];
        if (no==M){
            ++ans;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
N = int(input())
a = list(map(int,input().split()))
ls = []
for i in a:
    ls.append(i)
    ls.append(i+1)
    ls.append(i-1)
import collections as col
dic = col.defaultdict(int)
for i in ls:
    dic[i] += 1
print(max(dic.values()))

Measured memory_bytes: 25972
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[100100][3];

int main() {
	ll n;
  cin>>n;
  clr(dp,0);
  ll a0,b0,c0;
  cin>>a0>>b0>>c0;
  dp[0][0] = a0;
  dp[0][1] = b0;
  dp[0][2] = c0;
  rep(i,1,n){
    ll a,b,c;
    cin>>a>>b>>c;
    dp[i][0] = max(dp[i][0],a+max(dp[i-1][1],dp[i-1][2]));
    dp[i][1] = max(dp[i][1],b+max(dp[i-1][0],dp[i-1][2]));
    dp[i][2] = max(dp[i][2],c+max(dp[i-1][0],dp[i-1][1]));
  }
  cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;
	return 0;
}

Measured memory_bytes: 2560