akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int euclid( int a, int b )
{
    int temp;
    if( a < b ) { temp = a; a = b; b = temp; }
    if( b < 1 ) return -1;
    if( a % b == 0 ) return b;
    return euclid( b, a % b );
}


int main(void){
    int N;
    scanf("%d",&N);
    int A[N];
    for(int i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    int n;
    for(int i=1;i<N;i++){
        A[i] = euclid(A[i-1],A[i]);
    }
    printf("%d",A[N-1]);
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;

    bool flg=false;

    for(int i=1;i<b;i++){
        if(a*i%b==c){
            flg=true;
        }
    }

    if(flg){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int S, soma = 0, i, inicio;
    
    scanf ("%d", &S);
    
    inicio = S;
    
    while (1){
        if (S < 10)
        break;
        soma = soma + (S % 10);
        S = S / 10;
    }
    soma = soma + S;
    
    if (inicio % soma == 0)
        printf ("Yes");
    else 
        printf ("No");
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
typedef vector<int > vi;
int n;
vector<vector<int > >adjlist;
vi sz;
vi stree;
void dfs(int u,int p){
	int maxstree=0;
	for(auto v: adjlist[u]){
		if(v==p)continue;
		dfs(v,u);

	}
	for(auto v: adjlist[u]){
		if(v==p)continue;
		maxstree = max(maxstree,stree[v]);
		stree[u]+=stree[v];
	}
	sz[u] = max(maxstree,n-stree[u]-1);
	//cout<<u+1<<' '<<maxstree<<' '<<sz[u]<<'\n';
	stree[u]+=1;
}
int main(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	//if both are po
	ll prod;
	if(b>=0 && d>=0){
		prod = b*d;
		prod = max(prod,a*c);
	}
	else if(b<0 && d<0){
		prod = a*c;
		prod = max(prod,b*d);
	}
	else if(b<0 && d>=0){
		prod = b*c;
		prod = max(prod,a*c);
	}
	else if(b>=0 && d<0){
		prod = d*a;
		prod = max(prod,a*c);
	}
	cout<<prod;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s1,s2;
  int count=0;
  cin>>s1>>s2;
  for(int i=0;i<3;i++)
  {
    for(int j=0;j<3;j++)
    {
      if(i==j)
      {
        if(s1[i]==s2[j])
        {
          count++;
        }
      }
    }
  }
  cout<<count<<endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
using namespace std;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<pair<int, int>>;
using VTIII = vector<tuple<int, int, int>>;
using Complex = complex<double>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a==b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a==b)){ a=b; return true; } return false; }
template<typename T> inline bool isin(const T& x, const T& l, const T& r){ return l <= x and x < r; }
inline ostream& fcout(int n = 10){ return cout << fixed << setprecision(n); }
inline ostream& rcout(int n = 2){ return cout << right << setw(n); }
constexpr int64_t INF = numeric_limits<int64_t>::max();
constexpr int32_t INF32 = numeric_limits<int32_t>::max();
constexpr int64_t MOD = 1000000007LL;
constexpr double PI = 3.14159265358979323846264338327950288;
constexpr double EPS = 1e-10;


int N, M;
int P[100010];
int A[100010];
int B[100010];
int C[100010];
int s[100010];


int32_t main(){
    cin >> N >> M;
    rep(i, 0, M) cin >> P[i], P[i]--;
    rep(i, 0, N-1) cin >> A[i] >> B[i] >> C[i];

    int pre = P[0];
    rep(i, 0, M){
        s[min(pre, P[i])]++;
        s[max(pre, P[i])]--;
        pre = P[i];
    }

    int ans = 0;
    rep(i, 0, N-1){
        ans += min(C[i]+s[i]*B[i], s[i]*A[i]);
        s[i+1] += s[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7012
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  ll a,b,c,k;cin>>a>>b>>c>>k;
  if(k%2==0){
    P(a-b);
  }else{
    P(b-a);

  }
  return 0;
}


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

template <typename List>
void split(const std::string& s, const std::string& delim, List& result){
    result.clear();

    using string = std::string;
    string::size_type pos = 0;

    while(pos != string::npos){
        string::size_type p = s.find(delim, pos);
        if(p == string::npos){
            result.push_back(s.substr(pos));
            break;
        }else{
            result.push_back(s.substr(pos, p - pos));
        }

        pos = p + delim.size();
    }
}

int main(){
    float value, sum=0;
    int N, index;
    string unit;

    cin >> N;
    for(index = 1; index <= N; index++){
        cin >> value >> unit;
        if(unit == "JPY"){
            sum += value;
        }else if(unit == "BTC"){
            sum += value * 380000;
        }else{
            cout << "unit error" << endl;
            return 1;
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
import copy
import sys
import math

def main():
	n = int(input())
	a = list(map(int,input().split()))
	a.sort()
	tmp = listtodict(a)
	b = {}
	for k,v in tmp.items():
		b[k] = int(v/2)
	b = sorted(b.items(), key=lambda x:x[0])
	w = -1
	for i in reversed(b):
		k=i[0]
		v=i[1]
		if(v>1 and w==-1):
			print(k**2)
			sys.exit()
		elif(v>0 and w==-1):
			w = k
		elif(v>0):
			print(w*k)
			sys.exit()
	print(0)


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()


Measured memory_bytes: 83688
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n;
	cin >> n;
	vector<int> buc(n);
	for(int i = 1, inp; i < n; i++) {
		cin >> inp, inp--;
		buc[inp]++;
	}
	for(auto& el: buc) cout << el << '\n';
}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int x,y,z;
  cin>>x>>y>>z;
  cout << z <<" "<< x <<" "<< y << endl;
  return 0;
}



Measured memory_bytes: 256
N = int(input())
z_t = []*N
t0 = 0
x0 = 0
y0 = 0
ans = 'No'
for i in range(N):
    s = input().rstrip().split()
    z_t.append(s)

for i in range(N):
    dt = int(z_t[i][0]) - t0
    dx = abs(int(z_t[i][1]) - x0)
    dy = abs(int(z_t[i][2]) - y0)
    extra_t = dt - (dx+dy)
    if extra_t >=  0 and extra_t%2 == 0:
        t0 = int(z_t[i][0])
        x0 = int(z_t[i][1])
        y0 = int(z_t[i][2])
        if i == N-1:
            ans = 'Yes'
    else:
        break
print(ans)

Measured memory_bytes: 32144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int a[n];
    bool flag = false;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 1) flag = true;
    }
    if (!flag) cout << -1 << endl;
    else {
        int cnt = 0, top = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == top+1) {
                top++;
            } else {
                cnt++;
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			(a).begin(),(a).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				(1000 * 1000 * 1000 * 2)
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<int, int>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// メイン
int main()
{
	int N;
	cin >> N;
	vector<ll> A(N);
	REP(i, N) {
		cin >> A[i];
	};

	vector<int> col(9, 0);
	REP(i, N) {
		if (3200 <= A[i]) {
			col[8]++;
		} else {
			col[A[i] / 400]++;
		}
	}

	int ans = 0;
	REP(i, 8) {
		if (0 < col[i]) {
			ans++;
		}
	}

	int ansMax = min(8, ans + col[8]);
	if (ans == 0) {
		cout << 1 << " " << ans + col[8] << endl;
	} else {
		cout << ans << " " << ans + col[8] << endl;
	}
	return 0;
}


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

using namespace std;

int main()
{
    string s;
    int cnt1 = 0, cnt0 = 0;
    long long int ans = 0;

    cin >> s;

    for (int i = 0; i < (int)s.size(); i++) {
        if (s[i] == '0') {
            cnt0++;
        }
        else {
            cnt1++;
        }
        if (cnt0 > 0 && cnt1 > 0) {
            ans += 2;
            cnt1--;
            cnt0--;
        }
    }

    cout << ans << endl;
        
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n;
    string s, t;
    cin >> n >> s >> t;

    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int same = 0;
        bool flag = true;
        for(int j = i; j < n; j++)
        {
            if(s[j] == t[same])
            {
                same++;
            }
            else
            {
                flag = false;
                break;
            }
        }
        if(!flag) continue;
        ans = same;
        break;
    }
    cout << n + n - ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <climits>
#include <ctime>

using namespace std;

const int len = 100010;
int a[len],n,p[len],jl[len];

int main() {
    //freopen("test.in","r",stdin);
    //freopen("test.out","w",stdout);
    cin >> n;
    for (int i=1;i<=n;i++) {
        cin >> a[i];
    }
    memset(p,0,sizeof(p));
    memset(jl,0,sizeof(jl));
    bool flag = true;
    int k = 1;
    p[k] = 1;
    int sum = 0;
    bool f = false;
    while (flag) {
        if (k == 2) {f = true;flag = false;break;}
        if (jl[k] == 1) {flag = false;break;}
        sum++;
        p[k] = 0;
        jl[k] = 1;
        p[a[k]] = 1;
        k = a[k];
    }
    if (f) cout << sum << endl;
    else cout << "-1" << endl;
    return 0;
}

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

int main(){
//srandom((unsigned long)time(NULL));
long double l;
cin>>l;
cout<<fixed<<setprecision(8)<<(l/3.000000000)*(l/3.0000000000)*(l/3.0000000000)<<endl;
return 0;
}

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

#define ll long long
using namespace std;
bool s[200050] = {};
bool t[200050] = {};
int main()
{
	ll n, m;
	cin >> n >> m;

	for (int i = 0; i < m; i++)
	{
		ll a, b;
		cin >> a >> b;

		if (a == 1) {
			t[b] = true;
		}

		if (b == n) {
			s[a] = true;
		}
	}

	for (int i = 0; i < 200050; i++)
	{
		if (s[i] && t[i]) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}

	cout << "IMPOSSIBLE" << endl;
	return 0;

}

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  vector<bool> bh(h);
  vector<vector<char>> v(h, vector<char>(w));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> v[i][j];
      if (v[i][j] == '#')
        bh[i] = true;
    }
  }

  int color = 1;
  vector<vector<int>> ans(h, vector<int>(w));
  bool found;

  found = false;
  for (int i = 0; i < h; ++i) {
    if (bh[i]) {
      if (found)
        ++color;
      found = true;
    }
    for (int j = 0; j < w; ++j) {
      ans[i][j] = color;
    }
  }

  int curr = 1;
  int i = 0;
  while (i < h) {
    vector<bool> bw(w);
    int ni = i;
    int j = 0;
    while (ni < h && ans[ni][j] == curr) {
      if (v[ni][j] == '#')
        bw[j] = true;
      ++j;
      if (j < w)
        continue;
      j = 0;
      ++ni;
    }
    int cnt = 0;
    for (int l = 0; l < w; ++l) {
      if (bw[l]) {
        if (cnt > 0)
          ++color;
        ++cnt;
      }
      for (int k = i; k < ni; ++k) {
        if (cnt > 1)
          ans[k][l] = color;
      }
    }
    if (ni >= h)
      break;
    curr = ans[ni][0];
    i = ni;
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      printf("%d%c", ans[i][j], j < w - 1 ? ' ' : '\n');
    }
  }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i = a; i <= b; ++i)
#define ff(i, a, b) for(ll i = a; i < b; ++i)
#define F(i, a, b) for(ll i = a; i >= b; --i)
#define FF(i, a, b) for(ll i = a; i > b; --i)
#define x first
#define y second
#define X real()
#define Y imag()
using namespace std;
typedef complex<ll> P;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;

ll a, b;

signed main(){
//	freopen("PERFECT1.inp","r",stdin);
//	freopen("PERFECT1.out","w",stdout);
//	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> a >> b;
	f(i,b-a+1,b+a-1) cout << i <<" ";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
//ll

int main(){
  int k,s;cin>>k>>s;
  int ans = 0;
  rep(x,k+1){
    rep(y,k+1){
      if(s-x-y>=0&&k>=s-x-y)ans++;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std; 
  
// Function to compute num (mod a) 
int mod(string num, int a) 
{ 
    // Initialize result 
    int res = 0; 
  
    // One by one process all digits of 'num' 
    for (int i = 0; i < num.length(); i++) 
         res = (res*10 + (int)num[i] - '0') %a; 
  
    return res; 
} 
  
// Driver program 
int main() 
{ 
    string num;
    cin>>num;
     ll k = mod(num, 9);
     if(k==0)
     {cout<<"Yes"<<endl;}
     else
     {
         cout<<"No"<<endl;
     }
     
    return 0; 
} 

Measured memory_bytes: 3772
A,B,C,X,Y=map(int,input().split())
ans=A*X+B*Y
for i in range(min([X,Y])+1):
    M=A*X+B*Y-A*i-B*i+2*C*i
    if M<ans:
        ans=M
S=max([X,Y])
T=min([X,Y])
if S*2*C<ans:
    ans=S*2*C
print(ans)


Measured memory_bytes: 3060
import java.io.*;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String weather = br.readLine();
		
		String tomorrow_weather;
		if(weather.equals("Sunny")) {
			tomorrow_weather = "Cloudy";
		} else if(weather.equals("Cloudy")){
			tomorrow_weather = "Rainy";
		} else {
			tomorrow_weather = "Sunny";
		}

		System.out.println(tomorrow_weather);
	}
}

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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(a) a.begin(), a.end()

const int maxn = 200010;
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;
ll n, m, a[maxn];
map<int, int> M, N;
set<int> S;
string s;

void solve()
{
    int a, b;
    vector<int> v;
    cin >> a >> b;
    for(int i = 1; i <= 999; i++)
    {
        int x = i*i+i;
        x/=2;
        v.push_back(x);
    }
    for(int i = 0; i < v.size()-1; i++)
    {
        if(v[i]<a) continue;
        if(v[i+1]<b)continue;
        if(v[i]-a!=v[i+1]-b) continue;
        cout << v[i]-a << "\n";
        return;
    }
}

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


Measured memory_bytes: 3652
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      _a: [[u8; n]; n]
   }
   let mut a = vec![vec![true; n]; n];
   for i in 0..n {
      for j in 0..n {
         if _a[i][j] == 0 {
            a[i][j] = false;
         }
      }
   }
   let mut dp = vec![-1_i64; 1 << n];
   dp[0] = 1;
   let ans = rec((1 << n) - 1, 0, &a, &mut dp);
   println!("{}", ans);
}

const MOD: i64 = 1000000007;

fn rec(state: usize, c: usize, a: &Vec<Vec<bool>>, dp: &mut Vec<i64>) -> i64 {
   if dp[state] != -1 {
      dp[state]
   } else {
      let mut r = 0;
      for (i, &b) in a[c].iter().enumerate() {
         if (state >> i) & 1 == 1 && b {
            r += rec(state ^ (1 << i), c + 1, a, dp);
         }
      }
      dp[state] = r % MOD;
      dp[state]
   }
}


Measured memory_bytes: 20732
N=int(input())
b=list(map(int, input().split()))
ans=[]
for i in range(N):
  for j in range(len(b)-1, -1, -1):
    if b[j]==j+1:
      ans.append(b.pop(j))
      break
      
if len(ans)<N:
  print(-1)
else:
  for i in range(N-1, -1, -1):
    print(ans[i])


Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i,k){
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
<?php
fscanf(STDIN,"%d %d",$n,$k);

$have = [];
for ($i = 0;$i < $k;++$i) {
    $d = trim(fgets(STDIN));
    $snuke = trim(fgets(STDIN));
    $tmp = explode(" ",$snuke);

    foreach ($tmp as $val) {
        $have[] = $val;
    }
}
$have = array_unique($have);

echo $n - count($have).PHP_EOL;

Measured memory_bytes: 16792
a, b = $<.map(&:chomp).drop(1).map(&:split)
c = a.zip(b).map { |e| e.map(&:to_f).reduce(:-).abs }
1.upto(3) { |i| p c.map { |e| e ** i }.reduce(:+) ** (1.0 / i) }
p c.max

Measured memory_bytes: 8860
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    x = kwargs["x"]
    t = kwargs["t"]
    res = n // x * t
    if n % x > 0:
        res += t
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"], kwargs["x"], kwargs["t"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 31176
#define _USE_MATH_DEFINES
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <cctype>
#include <cstdlib>
using namespace std;

#define INF (1 << 20)
#define EPS (1e-10)
#define EQ(a,b) (fabs((a)-(b)) < EPS)

int main(){
	long long int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		double xa, ya, ra, xb, yb, rb;
		cin >> xa >> ya >> ra >> xb >> yb >> rb;
		double ab = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
		if (ab + rb - ra <= -EPS) cout << 2 << endl;
		else if (ab + ra - rb <= -EPS) cout << -2 << endl;
		else if (ab - ra - rb >= EPS) cout << 0 << endl;
		else cout << 1 << endl;
	}
	return 0;
}

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

int main() {
    int n;cin>>n;
    int a[n];
    int ans=1000000;
    
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=a[0];i<=a[n-1];++i){
        int tmp=0;
        for(int j=0;j<n;++j){
            tmp+=(i-a[j])*(i-a[j]);
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
	return 0;
}

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

int main() {
	string s; cin>>s;
	set<char> se;
	for(int i=0; i<s.size(); i++){
		se.insert(s[i]);
	}
	
	if(se.size()==2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
  int N,length,ans=0,i,j;
  char W[100][11];
  for(i=0;i<100;i++)for(j=0;j<11;j++)W[i][j]=0;
  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%s",W[i]);
  for(i=0;i<N && ans==0;i++) {
    length=11;
    if(i != 0) {
      for(j=0;j<i;j++)if(strcmp(W[j],W[i])==0)ans++;
      for(j=0;j<11 && length==11;j++)if(W[i-1][9-j]!=0)length=9-j;
      if(W[i][0]!=W[i-1][length])ans++;
    }
  }
  if(ans==0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
  long long N;
  cin >> N;
  long long tmp = N/4;
  for (long long h = tmp > 1 ? tmp : 1; (4*h <= 3*N) && (h <= 3500) ; h++) {
    for (long long w = 3*tmp > h ? 3*tmp : h; w <= 3500; w++) {
      if (4*h*w-N*(h+w) == 0) continue;
      long long n = N*h*w/(4*h*w-N*(h+w));
      if (n <= 0) continue;
      if (4*h*n*w == N*(h*n+n*w+w*h)) {
        cout << h << ' ' << n << ' ' << w << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+5;
const int mod=1e9+7;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x,y,z;
	cin>>x>>y>>z;
	swap(x,y);
	swap(x,z);
	cout<<x<<" "<<y<<" "<<z<<'\n';






}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
/*
ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=2000005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

ll nPk(ll n,ll k){
	return nCk(n,k)*F[k]%mod;
}*/


int main(){
	ll X,K,D;
	cin>>X>>K>>D;
	__int128 x=X,k=K,d=D;
	x=abs(x);
	if(0<x-k*d) cout<<(ll)(x-k*d)<<endl;
	else{
		__int128 t=k*d-x;
		t%=2*d;
		cout<<(ll)min(t,2*d-t)<<endl;
	}
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> p(N);
	rep(i, N) cin >> p[i];
	vector<ll> sum(N-K+1, 0);
	rep(i, K) {
		sum[0] += (p[i] + 1);
	}

	int id = 0;
	for(int i=1; i<N-K+1; i++) {
		sum[i] = sum[i-1] - p[i-1] + p[i+K-1];

		if(sum[i]>sum[id]) id = i;
	}

	// rep(i, N-K+1) {
	// 	cout << sum[i] << endl;
	// }

	double ans = (double)(sum[id])/2.0;

	std::cout<<std::fixed<<std::setprecision(9);
	cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define EPS (1e-10)
using namespace std;
double P,E,T;

double dfs(int k,double L,double R){
  double H=(R+L)/2,PP=H>=T ?1-P:P;
  if(k==0)return abs(H-T)<=E;
  if(T<R-E||L+E<T)return 0;
  return PP*dfs(k-1,H,R)+(1-PP)*dfs(k-1,L,H);
}

int main(){
  double K,R,L;
  cin>>K>>R>>L>>P>>E>>T;
  printf("%.10f\n",dfs(K,L,R));
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
const long long mod = 1e9 + 7;
int n, k, a[N];
long long dp[N], da[N];

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

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

	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		memset(da, 0, sizeof da);
		for (int c = k; c >= 0; c--) {
			int l = c + 1;
			int r = min(c + a[i], k);
			da[l] = (da[l] + dp[c]) % mod;
			da[r + 1] = (da[r + 1] + mod - dp[c]) % mod;
		}
		
		long long pref = 0;
		for (int i = 0; i <= k; i++) {
			pref = (pref + da[i]) % mod;
			dp[i] = (dp[i] + pref) % mod;
		}
	}

	cout << dp[k] << endl;

	return 0;
}


Measured memory_bytes: 1792
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int H,W,i,j,k,cnt,ni,nj,di[8]={-1,-1,-1,0,0,1,1,1},dj[8]={-1,0,1,-1,1,-1,0,1};
string S[50];
inline void solve(){
  IN2(H,W);
  REP(i,H)IN(S[i]);
  REP(i,H){
    REP(j,W){
      if(S[i][j]=='.'){
        cnt=0;
        REP(k,8){
          ni=i+di[k];
          nj=j+dj[k];
          if(ni>=0&&ni<H&&nj>=0&&nj<W&&S[ni][nj]=='#')cnt++;
        }
        S[i][j]=cnt+'0';
      }
    }
  }
  REP(i,H)OUT(S[i]);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
count = [0] * n
ans = 1
mod = 10 ** 9 + 7
for i in a:
    if i == 0:
        ans = ans * (3 - count[0]) % mod
    else:
        ans = ans * max(0, (count[i - 1] - count[i])) % mod
    count[i] += 1
print(ans % mod)

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

int main()
{
  int n,K,sum=0;
  cin>>n>>K;
  int a[n];
  for(int i=1; i<=n; i++)cin>>a[i];
  sort(a+1,a+1+n);
  for(int i=1; i<=n; i++)sum+=a[i];
  for(int i=1; i<=n-K; i++)sum-=a[i];
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    long long y;
    cin>>y;
    long long h;
    if(y%500==0){
        h=1000*(y/500);  
    }
    else if ((y%500)!=0){
        long long r=y%500;
             h=(1000*(y/500))+((r/5)*5); 
        // else{
        //     h=(1000*(y/500));
            
        // }
    }
    cout<<h;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
w_list = [input() for _ in range(N)]

cnt = Counter(w_list).most_common(1)[0][1]
if cnt > 1:
    print('No')
else:
    for i in range(0,N - 1):
        if w_list[i][-1] != w_list[i + 1][0]:
            print('No')
            break
    else:
        print('Yes')

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

from __future__ import division, print_function, absolute_import, unicode_literals

s = input()
ans = 0

N = len(s)
for i in range(1<<(N-1)):
    tmp = s[0]
    for n in range(N-1):
        if ((1 << n) & i):
            tmp += '+'
        tmp += s[n+1]
    ans += eval(tmp)
print(ans)


Measured memory_bytes: 3064
n, k = map(int, input().split())
p = list(map(lambda x: (int(x)+1)/2, input().split()))

# 1~p: 期待値は(p+1)/2
s = sum(p[:k])
ans = s
for i in range(k,n):
  s += p[i] - p[i-k]
  ans = max(ans, s)
print(ans)

Measured memory_bytes: 23524
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
#define vec vector
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 200005;

int main(){
	int n;
	cin >> n;
	ll h[n],a[n];
	cu(i,0,n)cin >> h[i];
	cu(i,0,n)cin >> a[i];
	map<int,ll> m;
	m[0] = 0;
	cu(i,0,n){
		auto it = m.lower_bound(h[i]);
		--it;
		ll b = it->S;
		++it;
		auto nd = it;
		while(nd != m.end() && nd->S <= a[i] + b){
			++nd;
		}
		m.erase(it, nd);	
		m[h[i]] = a[i] + b;	
	}
	auto it = m.end();
	--it;
	cout << it->S << '\n';
}


Measured memory_bytes: 15872
fun main(arg: Array<String>) {
    var S = next()
    val K = listOf("dream", "dreamer", "erase", "eraser")
    do {
        var done = false
        if (S.length == 0) return println("YES")
        for (n in K.indices)
            if (S.endsWith(K[n])) {
                S = S.substring(0, S.length - K[n].length)
                done = true
                break
            }
    } while (done)
    println("NO")
}

fun next() = readLine()!!


Measured memory_bytes: 117184
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
        int t = sc.nextInt();
        int s = sc.nextInt();
        if(t * s >= d){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
	}
}

Measured memory_bytes: 35600
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

const inf = 1001001001

func main() {
	sc.Split(bufio.ScanWords)

	a := make([]int, 0)
	n := 1
	for n < 100000 {
		n *= 6
		a = append(a, n)
	}
	n = 1
	for n < 100000 {
		n *= 9
		a = append(a, n)
	}
	a = append(a, 1)
	sort.Ints(a)
	N := getInt()

	dp := make([]int, N+1)
	for i := 0; i <= N; i++ {
		dp[i] = inf
	}
	dp[0] = 0
	for k := 0; k < 100; k++ {
		for i := 0; i < len(a); i++ {
			for j := 0; j <= N; j++ {
				if j+a[i] <= N {
					dp[j+a[i]] = min(dp[j+a[i]], dp[j]+1)
				}
			}
		}
		//		for i := 0; i <= N; i++ {
		//			fmt.Printf("%d:%d ", i, dp[i])
		//		}
		//		out()
	}
	out(dp[N])
}


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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct LazySegmentTree {
private:
    int n;
    vector<ll> node,lazy;
    vector<bool> upd;
public:
    LazySegmentTree(vector<ll> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1,0);
        upd.resize(2*n-1,false);
        for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
        for (int i = n-2;i >= 0;--i) node[i] = min(node[i*2+1],node[i*2+2]);
    }

    void eval(int k,int l,int r) {
        if (upd[k]) {
            node[k] = lazy[k];
            if (r-l > 1) {
                lazy[2*k+1] = lazy[2*k+2] = lazy[k];
                upd[2*k+1] = upd[2*k+2] = true;
            }
            lazy[k] = 0;
            upd[k] = false;
        }
    }

    void update(int a,int b,ll x,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        eval(k,l,r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] = x;
            upd[k] = true;
            eval(k,l,r);
        } else {
            update(a,b,x,2*k+1,l,(l+r)/2);
            update(a,b,x,2*k+2,(l+r)/2,r);
            node[k] = min(node[2*k+1],node[2*k+2]);
        }
    }

    ll getmin(int a,int b,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (b <= l || r <= a) return INT64_MAX;
        eval(k,l,r);
        if (a <= l && r <= b) return node[k];
        ll vl = getmin(a,b,k*2+1,l,(l+r)/2);
        ll vr = getmin(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
};

struct kouji {
    int s,t,x;
    bool operator<(const kouji& a) const {
        return x < a.x;
    }
};

int main() {
    int n,q;
    cin >> n >> q;
    vector<kouji> a(n),b(n);
    vector<int> d(q),e(n);
    for (int i = 0;i < n;++i) cin >> a[i].s >> a[i].t >> a[i].x;
    for (int i = 0;i < q;++i) cin >> d[i];

    LazySegmentTree seg(vector<ll>(q+1,1LL<<60));
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    d.push_back(1e9);
    for (int i = 0;i < n;++i) {
        int l = lower_bound(d.begin(),d.end(),a[i].s-a[i].x)-d.begin();
        int r = lower_bound(d.begin(),d.end(),a[i].t-a[i].x)-d.begin();
        seg.update(l,r,a[i].x);
        // cout << l << " " << r << endl;
    }
    for (int i = 0;i < q;++i) {
        ll l = seg.getmin(i,i+1);
        if (l < 1e9) printf("%d\n",l);
        else printf("-1\n"); 
    }
    // for (int i = 0;i < n;++i) cout << a[i].s << " " << a[i].t << " " << a[i].x << endl;
    // for (int i = 0;i < q+1;++i) cout << seg.getmin(i,i+1) << " ";
    return 0;
}

Measured memory_bytes: 16468
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.next();
        final int n = s.length();
        final Integer[] array = IntStream.range(0, n)
                .mapToObj(i -> s.charAt(i) - '0')
                .toArray(Integer[]::new);

        final int[] just = new int[n + 1];
        just[0] = 0;
        final int[] extra = new int[n + 1];
        extra[0] = 1;
        for (int i = 0; i < n; i++) {
            final int digit = array[i];
            just[i + 1] = Math.min(just[i] + digit, extra[i] + 10 - digit);
            extra[i + 1] = Math.min(just[i] + digit + 1, extra[i] + 9 - digit);
        }

        System.out.println(just[n]);
    }
}


Measured memory_bytes: 49632
#include <cstdio>
using namespace std;

int main()
{
	int r, g, b;
	scanf("%d %d %d", &r, &g, &b);
	if ((r * 100 + g * 10 + b) % 4) 
		printf("NO\n");
	else
		printf("YES\n");

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > a(N), b(N);
  long long asum=0, bsum=0;
  for (int i=0; i<N; i++){
    scanf("%d", &a[i]);
    asum += a[i];
  }
  for (int i=0; i<N; i++){
    scanf("%d", &b[i]);
    bsum += b[i];
  }
  long long diff = bsum-asum;
  if (diff<0){
    printf("No\n");
  } else {
    long long areq=0, breq=0;
    for (int i=0; i<N; i++){
      if (a[i]>b[i]){
        breq+=a[i]-b[i];
      } else {
        if (a[i]%2==b[i]%2){
          areq += (b[i]-a[i])/2;
        } else {
          areq += (b[i]+1-a[i])/2;
          breq++;
        }
      }
    }
    //printf("areq=%lld, breq=%lld, diff=%lld\n", areq, breq, diff);
    if (areq>diff || breq>diff){
      printf("No\n");
    } else if (2*(diff-areq)==diff-breq){
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;cin>>n;int w[n];int m=1000;
  for(int i=0;i<n;i++)
    cin>>w[i];
  int s1=0,s2=0;
  for(int i=0;i<n-1;i++)
  {for(int j=0;j<=i;j++)
  s1=s1+w[j];
  for(int j=i+1;j<n;j++)
  s2=s2+w[j];
  int d=abs(s1-s2);
  if(d<m)
    m=d;s1=0;s2=0;
  }cout<<m;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int an[5];
  int k;
  for(int i=0; i<5; i++){
    scanf("%d", &an[i]);
  }
  scanf("%d", &k);

  if(an[4]-an[0]>k) {
    printf(":(\n");
  } else {
    printf("Yay!\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int N, Y;


void solve()
{
	for (int i = 0; i * 10000 <= Y; i++) {
		for (int j = 0; i * 10000 + j * 5000 <= Y ; j++) {
			int k = (Y - i * 10000 - j * 5000) / 1000;
			if (i + j + k == N) {
			   cout << i << " " << j << " " << k << endl;
			   return;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
}

int main()
{
	cin >> N >> Y;
	solve();
	return 0;
}

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

using namespace std;
using ll=long long;

void solve(const vector<ll> &v) {
  const size_t n = v.size();
  vector<ll> dp(n,0);

  for(unsigned long long i = 1; i < v.size(); ++i) {

    dp[i] = dp[i-1] + abs(v[i] - v[i-1]);

    if(i>1){
      dp[i] = std::min(dp[i], dp[i-2] + abs(v[i] - v[i-2]));
    }
  }
  cout<<dp[n-1]<<endl;
}

int main(){
  int n; cin>>n;
  vector<ll> v(n);
  copy_n(istream_iterator<ll>(cin), n, begin(v));
  solve(v);
  return 0;
}

Measured memory_bytes: 4828
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;


int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int a,b;
	scanf("%d%d", &a,&b);
	if (a > 8 || b > 8) {
		puts(":(");
	}
	else {
		puts("Yay!");
	}
}

Measured memory_bytes: 128
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto N = RD!long;
	auto a = RDR.split.to!(long[]);
	a.sort();

	long ans;
	long last = a[0], lastPos;
	foreach (i; 1..N)
	{
		if (a[i] != last)
		{
			auto x = i - lastPos;
			ans += x >= last ? x - last : x;
			last = a[i];
			lastPos = i;
		}
	}
	auto x = N - lastPos;
	ans += x >= last ? x - last : x;

	writeln(ans);
	stdout.flush();
}

Measured memory_bytes: 4292
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n;
string s,w;

int main(){
	cin >> n >> s >> w;
	
	int mi=2*n;
	REP(i,0,s.size()){
		int pos=2*n;
		REP(j,0,s.size()-i){if(s[i+j]==w[j]) pos--; else{pos=2*n; break;}}
		mi=min(mi,pos);
	}
	
	cout << mi << endl;
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC042
{
	class Q1
	{
		static void Main()
		{
			List<int> datas = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
			Console.WriteLine(datas.Where(x => x == 5).Count() == 2 && datas.Where(x => x == 7).Count() == 1 ? "YES" : "NO");
		}
	}
}


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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<int> a(3);
    for (auto& x: a) cin >> x;
    vector<string> s(n);
    for (auto& x: s) cin >> x;
    string res(n,'?');
    for (int _ = 0; _ < n; _++) {
        int i = s[_][0]-'A';
        int j = s[_][1]-'A';
        if (a[i] == 0 && a[i]==a[j]) {
            cout << "No"; return;
        }
        int k = i;
        if (a[i] == 1 && a[i]==a[j]) {
            if (_+1<n) {
                int ii = s[_+1][0]-'A';
                int jj = s[_+1][1]-'A';
                if (i==ii||i==jj) k = i;
                else k = j;
            }
        } else {
            k = a[i]>a[j]? j : i;
        }
        res[_] = char('A'+k);
        ++a[k]; --a[k==i?j:i];
    }
    cout << "Yes\n";
    for (char c:res) cout << c << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


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

int main() {
	int t;
	cin >> t;
	int h,m,s;
	h = t/3600;
	m = (t-h*3600)/60;
	s = t-h*3600-m*60;
	cout << h << ":" << m << ":" << s << endl;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i=0; i<(int)(n); i++)
#define REP2(i,x,n) for(int i=x; i<(int)(n); i++)
using ll = long long;
int main(){
    ll N,M;
    cin >> N >> M;

    vector<vector<ll>>  road(M,vector<ll>(2));

    REP(i,M){
        REP(j,2){
            cin >> road.at(i).at(j);
        }
    }

    vector<ll> city(N);
    REP(i,M){
        REP(j,2){
            REP(k,N){
                if(road.at(i).at(j)==k+1){
                    city.at(k)++;
                }
            }
            //if(road.at(i).at(j)==1){
                //city.at(0)++;
            //}
            //if(roat.at(i).at(j)==2){
                //city.at(1)++;
            //}
        }
    }

    REP(i,N){
        cout << city.at(i) << endl;
    }
}

Measured memory_bytes: 256