akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static int H, W;
    static char[][] m;
    static void solve(Scanner scanner) {
        H = Integer.parseInt(scanner.next());
        W = Integer.parseInt(scanner.next());
        m = new char[H][W];
        for (int i = 0; i < H; i++) {
            m[i] = scanner.next().toCharArray();
        }

        Set<Integer> visited = new HashSet<>();
        int max = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                for (int i2 = 0; i2 < H; i2++) {
                    for (int j2 = 0; j2 < W; j2++) {
                        if (visited.add(i * 1000000 + j * 10000 + i2 * 100 + j2) ||
                                visited.add(i2 * 1000000 + j2 * 10000 + i * 100 + j)) {
                            int res = bfs(i, j, i2, j2);
                            if (res >= 0) {
                                max = Math.max(max, res);
                            }
                        }
                    }
                }
            }
        }

        System.out.println(max);
    }

    static int[][][][] dist = new int[20][20][20][20];
    static int bfs(int sy, int sx, int ey, int ex) {
        Queue<Integer> q = new LinkedList<>();
        Set<Integer> visited = new HashSet<>();
        q.add(sy * 100 + sx);
        q.add(null);
        int d = 0;

        while (!q.isEmpty()) {
            Integer top = q.poll();
            if (top == null) {
                d++;
                if (q.peek() == null) {
                    break;
                }
                q.add(null);
                continue;
            }
            int y = top / 100;
            int x = top % 100;
            if (x < 0 || x >= W || y < 0 || y >= H || m[y][x] == '#') {
                continue;
            }

            if (y == ey && x == ex) {
                if (dist[sy][sx][ey][ex] > 0) {
                    dist[sy][sx][ey][ex] = Math.min(dist[sy][sx][ey][ex], d);
                } else {
                    dist[sy][sx][ey][ex] = d;
                }
                return dist[sy][sx][ey][ex];
            }
            if (dist[sy][sx][y][x] > 0) {
                dist[sy][sx][y][x] = Math.min(dist[sy][sx][y][x], d);
            } else {
                dist[sy][sx][y][x] = d;
            }
            if (dist[y][x][ey][ex] > 0) {
                dist[sy][sx][ey][ex] = Math.min(dist[sy][sx][ey][ex], d + dist[y][x][ey][ex]);
                return dist[sy][sx][ey][ex];
            }
            if (visited.add(top)) {
                q.add((y + 1) * 100 + x);
                q.add((y - 1) * 100 + x);
                q.add(y * 100 + x + 1);
                q.add(y * 100 + x - 1);
            }
        }

        return -1;
    }

}



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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

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

const int inf=1e9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};	
bool num[101];
int main(){
	int a[3][3];
	int n,b;
	

	for (int i = 0; i < 3; i++){
		for (int j = 0; j < 3; j++){
			cin>>a[i][j];
		}
	}
	cin>>n;
	for (int i = 0; i < n; i++){
		cin>>b;
		num[b]=true;
	}

	for (int i = 0; i < 3; i++){
		bool ok=true,ok2=true;
		for (int j = 0; j < 3; j++){
			if(num[a[i][j]]==false)ok=false;
			if(num[a[j][i]]==false)ok2=false;
		}
		if(ok||ok2){
			cout<<"Yes"<<endl;
			return 0;
		}
	}

	if(num[a[0][0]]&&num[a[1][1]]&&num[a[2][2]] || num[a[0][2]]&&num[a[1][1]]&&num[a[2][0]]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}



	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7, mod = 1e9 + 7;
typedef long long ll;
ll qkpow(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
int main() {
    ll n;
    cin >> n;
    ll tmp = ((qkpow(10, n) + qkpow(8, n)) % mod + mod) % mod;
    ll res = qkpow(9, n) * 2 % mod;
    tmp = ((tmp - res) % mod + mod) % mod;
    cout << tmp << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
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; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    int cnt = 1;
    int minnum = v[0];
    REP(i,1,n) {
        if(v[i]<minnum) {
            cnt++;
            minnum = v[i];
        }
    }
    cout << cnt << endl;

    return 0;
}

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

int main(){
  int n,k,a,b;
  cin>>n>>k;
  for(int i=0;i<k;i++){
    cin>>a>>b;
    a=min(a,n+1-a);
    b=min(b,n+1-b);
    a=min(a,b);
    a=(a-1)%3+1;
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repe1(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  if (a+b < n) {
    cout << min(a,b) << " " << 0 << "\n";
  } else {
    cout << min(a,b) << " " << (a+b)-n << "\n";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    string s;
    cin >> s;
    int ctr=0;
    rp(i,3){
        if(s[i]=='1') ctr++;
    }
    print(ctr);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int n;
int x[150][150];
int y[150][150];
int done[150][150];
int sx, sy;

bool dfs(int nx, int ny, int id){
  // cout << nx << " " << ny << endl;
  if(done[ny][nx] == id) return true;
  if(done[ny][nx] != -1) return false;
  done[ny][nx] = id;
  return dfs(x[ny][nx], y[ny][nx], id);
}

int main(){
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
	cin >> x[i][j] >> y[i][j];
	done[i][j] = -1;
      }
    }
    int cnt = 0;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
	sy = j;
	sx = i;
	//cout << endl;

	if(dfs(i, j, i*n+j)) {
	  cnt++;
	  //cout << "A " << i << " "<< j << endl;
	}
      }
    }
    cout << cnt << endl;
    
  }

}

Measured memory_bytes: 1340
import java.io.IOException;
import java.util.Scanner;

public class Main
{
    public static void main(String arg[]) throws IOException
    {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();

        int c = Integer.parseInt(a);
        int d = Integer.parseInt(b);

        int num = 2*c + 2*d;
        System.out.println(c*d +" "+ num);
    }

}



Measured memory_bytes: 25844
#include <iostream>

using namespace std;

#define MAX_N 20
#define MAX_V 50
#define MAX_C 50

int V[MAX_V], C[MAX_C];

int main( int argc, char **argv )
{
    int N;
    cin >> N;

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

    int max_diff = 0;
    for ( int i = 0; i < ( 1 << N ); i++ )
    {
        int diff = 0;
        for ( int j = 0; j < N; j++ )
            if ( i & ( 1 << j ) ) diff += V[j] - C[j];
        max_diff = max( max_diff, diff );
    }

    cout << max_diff << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){
    int a, b, x;
    scanf("%d%d%d",&a,&b,&x);
    if(x<a || a+b <x){
        printf("NO\n");
    }else{
        printf("YES\n");
    }
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace AtCoder.ABC122.D
{
    class Program
    {
        static void Rep(int n, Action<int> action) { for (var i = 0; i < n; ++i) { action(i); } }
        static void Rep(int n, int s, Action<int> action) { for (var i = s; i < n; ++i) { action(i); } }
        static int A = 0, G = 1, C = 2, T = 3;
        static long mod = (long)Math.Pow(10, 9) + 7;
        public static void Main()
        {
            // Solve(3);
            // Solve(4);
            // Solve(5);
            // Solve(100);

            var N = int.Parse(Console.ReadLine());
            Solve(N);
        }
        static void Solve(int N)
        {
            var dp = new long[N + 1, 4, 4, 4];
            Rep(N, i => Rep(4, j => Rep(4, k => Rep(4, l =>
            {
                dp[i, j, k, l] = 0;
            }))));
            Rep(4, j => Rep(4, k => Rep(4, l =>
            {
                if (j == A && k == G && l == C) return;
                if (j == A && k == C && l == G) return;
                if (j == G && k == A && l == C) return;
                dp[3, j, k, l] = 1;
            })));
            Rep(N + 1, 4, i => Rep(4, j => Rep(4, k => Rep(4, l => Rep(4, m =>
            {
                // NGパターン
                // AGC
                // ACG
                // GAC
                // A?GC
                // AG?C
                // mjkl
                if (j == A && k == G && l == C) return;
                if (j == A && k == C && l == G) return;
                if (j == G && k == A && l == C) return;
                if (m == A && k == G && l == C) return;
                if (m == A && j == G && l == C) return;
                dp[i, j, k, l] += dp[i - 1, m, j, k];
                dp[i, j, k, l] %= mod;
            })))));
            long ans = 0;
            Rep(4, j => Rep(4, k => Rep(4, l =>
            {
                ans += dp[N, j, k, l];
                ans %= mod;
            })));
            Console.WriteLine(ans);
        }
        Dictionary<int, int> cache = new Dictionary<int, int>();
        static int Count(string S, int begin, int end)
        {
            return CountChar(S.Substring(begin, end - begin + 1), "AC");
        }
        public static int CountChar(string s, string c)
        {
            return (s.Length - (s.Replace(c, "").Length)) / c.Length;
        }
    }
}



Measured memory_bytes: 11220
from sys import stdin, setrecursionlimit, stdout
#setrecursionlimit(1000000)
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
    x=list(stdin.readline())
    x.pop()
    return x
def si(): return stdin.readline()
mod=1000000007
res=['YES', 'NO']
############# CODE STARTS HERE #############
n, m=mi()
a=li()
print(max(-1, n-sum(a)))

Measured memory_bytes: 10440
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REPEACH(itr, k) for (auto &&itr : k)
#define MOD 1000000007

using namespace std;
typedef long long ll;

const ll INF = 1LL<<60;
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;}

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> l;
    REP(i,n){
        cin >> p[i];
        if(p[i]==i+1){
            l.push_back(i);
        }
    }
    if(l.size()==0){
        cout << 0 << endl;
        return 0;
    }
    int ans=l.size();
    bool is=false;
    for(int i=1;i<l.size();i++){
        if(l[i-1]+1==l[i]){
            if(is){
                is=false;
                continue;
            }
            ans--;
            is=true;
        }
        else{
            is=false;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e3+5;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	ll a, b;
	cin >> a >> b;
	if (a <= b)
		cout << min(a, b - a);
	else
		cout << min(a - b, min(a % b, b - a % b));
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
set<int>q;
int dis(int x1,int y1,int x2,int y2)
{
    return abs(x1-x2)+abs(y1-y2);
}
int a1[10000],b1[100000],a2[10000],b2[100000];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a1[i]>>b1[i];
    }
    for(int i=1;i<=m;i++)
    {
        cin>>a2[i]>>b2[i];
    }
    for(int i=1;i<=n;i++)
    {
        int pos;
        int Max=(1<<31)-1;
        for(int j=1;j<=m;j++)
        {
            int ans=dis(a1[i],b1[i],a2[j],b2[j]);
            if(ans<Max)
            {
                pos=j;
                Max=ans;
            }
        }
        cout<<pos<<endl;
    }
    return 0;
}

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

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

    ll i,j,k,l,m,n,w,x,y,z,p,q,tmp,sum=0;
    string str;
    ll a,b,c;
    cin>>a>>b>>c>>x>>y;
    if(x<y){
        y=y-x;
        z=x;
        x=0;
    }else{
        x=x-y;
        z=y;
        y=0;
    }
    if(a+b<c*2){
        sum=(a+b)*z;
    }else{
        sum=c*2*z;
    }
    if(a>c*2){
        sum+=x*c*2;
    }else{
        sum+=x*a;
    }
    if(b>c*2){
        sum+=y*c*2;
    }else{
        sum+=y*b;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    if (a*b >= c*d)
    {
        cout << a * b << endl;
    }
    else
    {
        cout << c * d << endl;
    }
    
}


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

#define DEBUG

#ifndef TZNLOCAL
#undef DEBUG
#endif

#ifdef DEBUG
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) ;
#endif

int main()
{
	int n;
	cin>>n;
	for(int a=1;a<=3500;a++)
	{
		for(int b=a;b<=3500;b++)
		{
			double val=4.0/n-1.0/a-1.0/b;
			double ival=1.0/val;
			if (ival>3600) continue;
			if (ival<1) continue;
			int v=(int)(ival);
			for(int c=max(1,v-10);c<=min(3500,v+10);c++)
			{
				long long v1=4,v2=n;
				long long v3=a*b+b*c+c*a;
				long long v4=1ll*a*b*c;
				if (v1*v4==v2*v3)
				{
					cout<<a<<' '<<b<<' '<<c<<endl;
					return 0;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int a, b; cin >> a >> b;

    if(b%a == 0 ) cout << a+b << ln;
    else cout << b-a << ln;
    return 0;
}

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

int main() {
  int n, k, distance = 0;
  cin >> n >> k;
  
  int xi;
  for (int i = 0; i < n; i++) {
    cin >> xi;
    if (k < xi) {
      distance += 2 * (xi - k);
    } else if (k > xi && k - xi > xi) {
      distance += 2 * xi;
    } else {
      distance += 2 * (k - xi);
    }
  }
  
  cout << distance << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  int total[50]={0};
  int r1,r2;
  for(int i=0;i<m;i++)
  {
      cin>>r1>>r2;
      total[r1-1]++;
      total[r2-1]++;
  }
  for(int i=0;i<n;i++)
  {
      cout<<total[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n;
    cin>>n;
    long long int sum=0;
    for (long long int i=1;sum<=n;i++) {
        sum+=i;
        if (sum>=n) {
            cout<<i<<endl;
            break;
        }
    }
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

//long double myabs(long double a) {
//    return a >= 0 ? a : -a;
//}
int run(istream& in, ostream& out) {
    ll N;
    in >> N;
    ll v[200000] = {0};
    REP(i, N) {
        in >> v[i];
    }
    ll ans = 0;
    ll recent_distance = 0;
    double min_distance = 10010010010010010010;
    ll distance = 0;
    ll total = 0;
    for(ll i = 0; i < N; ++i) {
        total += v[i];
    }
    for(ll i = 0; i < N; ++i) {
        distance += v[i];
        auto ds = abs((double)distance - ((double)total /2));
        if (ds < min_distance) {
            min_distance = ds;
            recent_distance = distance;
        }
    }
    ans = abs((total - recent_distance) - recent_distance);
    out << ans << endl;
    debug(ans);
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
using namespace std;

#define N 200005

vector <int> a[N];
int n;
int tot,head[2*N],to[2*N],than[2*N];
int ok[N],num[3];

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while((c<'0'||c>'9')&&c!='-')c=getchar();
	if(c=='-')c=getchar(),t=-1;
	while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+(c^48),c=getchar();
	return s*t;
}

void add(int x,int y){
	tot++;
	to[tot]=y;
	than[tot]=head[x];
	head[x]=tot;
}

void dfs(int now,int fa){
	for(int i=head[now];i;i=than[i]){
		int t=to[i];
		if(t==fa)continue;
		ok[t]=ok[now]^1,dfs(t,now);
	}
	num[ok[now]]++;
}

int main(void){
	n=read();
	for(int i=1;i<n;i++){
		int x,y;
		x=read();
		y=read();
		add(x,y);
		add(y,x);
	}
	dfs(1,0);
	int a=1,b=2,c=3;
	if(num[0]<=n/3){
		for(int i=1;i<=n;i++){
			if(ok[i]%2==0)printf("%d ",c),c+=3;
			else {
				if(a<=n){
					printf("%d ",a);
					a+=3;
				}
				else
				if(b<=n){
					printf("%d ",b);
					b+=3;
				}
				else
				if(c<=n){
					printf("%d ",c);
					c+=3;
				}
			}
		}
	}
	else
	if(num[1]<=n/3){
		for(int i=1;i<=n;i++){
			if(ok[i]&1)printf("%d ",c),c+=3;
			else{
				if(a<=n){
					printf("%d ",a);
					a+=3;
				}
				else
				if(b<=n){
					printf("%d ",b);
					b+=3;
				}
				else
				if(c<=n){
					printf("%d ",c);
					c+=3;
				}
			}
		} 
	}
	else{
		for(int i=1;i<=n;i++){
			if(ok[i]&1){
				if(a<=n){
					printf("%d ",a);
					a+=3;
				}
				else
				if(c<=n){
					printf("%d ",c);
					c+=3;
				}
			}
			else{
				if(b<=n){
					printf("%d ",b);
					b+=3;
				}
				else
				if(c<=n){
					printf("%d ",c);
					c+=3;
				}
			}
		}
	}
}

Measured memory_bytes: 18304
n = int(input())
arr = [int(x) for x in input().split()]

mxN = 10**18
if 0 in arr:
    print(0)
    exit()
    
mul = 1
for x in arr:
    mul*=x
    if mul > mxN:
        print(-1)
        exit()

print(mul)

Measured memory_bytes: 21672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Queue;

public class Main {
	static int n;

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

		n = Integer.parseInt(br.readLine());

		ArrayList<ArrayList<Integer>> edge = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			edge.add(new ArrayList<>());
		}

		for (int i = 0; i < n - 1; i++) {
			String str[] = br.readLine().split(" ");

			int a = Integer.parseInt(str[0]) - 1;
			int b = Integer.parseInt(str[1]) - 1;
			edge.get(a).add(b);
			edge.get(b).add(a);
		}

		int fennec = 0;
		int snuke = 0;

		int distF[] = bfs(edge, 0);
		int distS[] = bfs(edge, n - 1);

		for (int i = 0; i < n; i++) {
			if (distF[i] < distS[i]) {
				fennec++;
			} else if (distF[i] == distS[i]) {
				fennec++;
			} else {
				snuke++;
			}
			//System.out.println(i + " " + distF[i] + " " + distS[i]);
		}
		if (fennec > snuke) {
			System.out.println("Fennec");
		} else {
			System.out.println("Snuke");
		}
	}

	static int[] bfs(ArrayList<ArrayList<Integer>> edge, int s) {
		boolean used[] = new boolean[n];
		int[] dist = new int[n];
		Queue<Integer> queue = new ArrayDeque<>();

		Arrays.fill(dist, Integer.MAX_VALUE);
		dist[s] = 0;
		used[s] = true;
		queue.add(s);

		while (!queue.isEmpty()) {
			int now = queue.poll();
			for (int i = 0; i < edge.get(now).size(); i++) {
				int next = edge.get(now).get(i);
				if (!used[next]) {
					used[next] = true;
					dist[next] = dist[now] + 1;
					queue.add(next);
				}
			}
		}
		return dist;
	}
}

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

struct weighted_union_find {
	std::vector<long long> parent; // 頂点 i の直接の親
	std::vector<long long> size; // 頂点 i を含む連結成分の頂点数
	long long m; // 連結成分の数
	std::vector<long long> weight; // 辺 i -> parent[i] の重み

	weighted_union_find(long long n) {
		for (long long i = 0; i < n; i++) {
			parent.push_back(i);
			size.push_back(1);
			weight.push_back(0);
		}
		m = n;
	}

	long long root_of(long long n) {
		if (parent[n] == n) return n;
		{ // パス圧縮
			long long x = root_of(parent[n]);
			weight[n] += weight[parent[n]];
			parent[n] = x;
		}
		return parent[n];
	}

	long long weight_of(long long n) {
		if (parent[n] == n) return 0;
		return weight[n] + weight_of(parent[n]);
	}

	bool is_united(long long a, long long b) {return (root_of(a) == root_of(b));}

	bool unite(long long a, long long b, long long w) {
		if (is_united(a, b)) {
			return (weight_of(a) + w == weight_of(b));
		}
		w += weight_of(a) - weight_of(b);
		a = root_of(a); b = root_of(b);
		m--;
		if (size[a] < size[b]) { // マージテク
			std::swap(a, b);
			w *= -1;
		}
		size[a] += size[b];
		weight[b] = w;
		parent[b] = a;
		return true;
	}
};

int main() {
	long long n, m;
	std::cin >> n >> m;
	std::vector<long long> l(m), r(m), d(m);
	for (long long i = 0; i < m; i++) {
		std::cin >> l[i] >> r[i] >> d[i];
		l[i]--; r[i]--;
	}

	weighted_union_find wuf(n);
	for (long long i = 0; i < m; i++) {
		if (!wuf.unite(l[i], r[i], d[i])) {
			std::cout << "No" << std::endl;
			return 0;
		}
	}
	std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 10504
#include<stdio.h>
int count=0;
void check(long long int x){
    if(x%2==1)count++;
}

int main(){
    long long int a,b,c,d,e,f,g;
    scanf("%lld %lld %lld %lld %lld %lld %lld",&a,&b,&c,&d,&e,&f,&g);
    long long int ans=0;
    ans+=b;
    check(a);
    check(d);
    check(e);
    if(count<=1){
        ans+=(a/2)*2+(d/2)*2+(e/2)*2;
    }else if(count==2 &&a>0 &&d>0&&e>0){
        ans+=a+d+e-1;
    }else if(count==2){
        ans+=(a/2)*2+(d/2)*2+(e/2)*2;
    }else{
        ans+=a+d+e;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

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

int main(void){
  int a;
  int sum = 0,maximum = 0;

  for(int i = 0;i < 3;i++){
    scanf("%d",&a);
    maximum = max(a,maximum);
    sum += a;
  }  

  printf("%d\n",sum-maximum);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() 
{
  //input
  long long n,m;
  cin  >> n>>m;
  pair<long long,long long> stores[n];
  
  for(long long i = 0; i < n; i++)
  {
    cin  >> stores[i].first;
    cin  >> stores[i].second;
  }
   
  sort(stores,stores+n);
  long long answer = 0,i=0;
  long long brought=0;
  while(brought<m)
  {
    if(stores[i].second<(m-brought))
    {
      
      answer+=stores[i].second*stores[i].first;
      brought+=stores[i].second;
    }
       else
       {
         
         answer+=(m-brought)*stores[i].first;
         brought+=m-brought;
       }
       i++;
       }
    
  //output
  cout  << answer  << endl;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a.at(i);
	}
	for(int i=0;i<n;i++){
		if(i==0){
			a[i]--;
			continue;
		}
		if(i==n-1) break;
		if(a[i]>a[i-1]) a[i]--;
	}
	bool flag = true;
	for(int i=1;i<n;i++){
		if(a[i]<a[i-1]) flag = false;
	}
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    reverse(all(res));
    return res;
}

int main() {
    ll N,M;
    cin >>N>>M;
    
    const auto &res = enum_divisors(M);
    for (int i = 0; i < res.size(); ++i){
        if(res[i]<= (M/N)){
            cout<<res[i]<<endl;
            return 0;
        }
    }


    return 0;
    

}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static final long CONST = 100000007L;

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long numN  = scan.nextLong();

		long count = numN * (numN - 1) / 2L;

		System.out.println(count);
	}
}


Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int length = sc.nextInt();
			String s = sc.next();
			int ans = 1;
			char top = s.charAt(0);
			for (int i = 1; i < length; i++) {
				char temp = s.charAt(i);
				if (top == temp) {
					continue;
				}
				top = temp;
				ans++;
			}
			System.out.println(ans);
		}
	}
}


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

#define N 20
#define M 20

int di[] = { -1, 0, 1, 0 };
int dj[] = { 0, 1, 0, -1 };

char cc[N][M + 1];
int n, m;

int bfs(int i1, int j1, int i2, int j2) {
	static int dd[N][M], qu[N * M];
	int i, i_, j, j_, ij, d, h, head, cnt;

	head = cnt = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			dd[i][j] = n * m + 1;
	dd[i1][j1] = 0;
	qu[head + cnt++] = i1 * m + j1;
	while (cnt > 0) {
		ij = qu[head++];
		cnt--;
		i = ij / m;
		j = ij % m;
		d = dd[i][j] + 1;
		if (i == i2 && j == j2)
			return dd[i][j];
		for (h = 0; h < 4; h++) {
			i_ = i + di[h];
			j_ = j + dj[h];
			if (i_ >= 0 && i_ < n && j_ >= 0 && j_ < m && cc[i_][j_] == '.' && dd[i_][j_] > d) {
				dd[i_][j_] = d;
				qu[head + cnt++] = i_ * m + j_;
			}
		}
	}
	return -1;
}

int main() {
	int i, i1, j1, i2, j2, ans;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%s", cc[i]);
	ans = 0;
	for (i1 = 0; i1 < n; i1++)
		for (j1 = 0; j1 < m; j1++)
			if (cc[i1][j1] == '.')
				for (i2 = 0; i2 < n; i2++)
					for (j2 = 0; j2 < m; j2++)
						if (cc[i2][j2] == '.') {
							int x = bfs(i1, j1, i2, j2);

							if (ans < x)
								ans = x;
						}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, max_size):
        self.parent = [i for i in range(max_size+1)]
        self.depth = [0 for _ in range(max_size+1)]
        self.cnt = [1 for i in range(max_size+1)]
    def find(self, x):
        if self.parent[x]==x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x]) 
            return self.parent[x]
    
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        elif self.depth[x]<self.depth[y]:
            self.parent[x] = y
            self.cnt[y] += self.cnt[x]
        else:
            self.parent[y] = x
            self.cnt[x]+=self.cnt[y]
            if self.depth[x]==self.depth[y]:
                self.depth[x]+=1
    def same(self, x, y):
        return self.find(x)==self.find(y)
    def size(self,x):
        return self.cnt[self.find(x)]

n,m = map(int,input().split())
utree = UnionFind(n+10)
for _ in range(m):
    x,y,z = map(int,input().split())
    utree.unite(x,y)
l = [utree.find(i) for i in range(1,n+1)]
print(len(set(l)))

Measured memory_bytes: 18732
#include<iostream>

using namespace std;

int main(){
  int n;
  int A[210];
  
  cin >> n;
  
  for(int i=0; i<n; ++i){
   cin >> A[i];
  }
  
  bool flag=true;
  int check;
  int count = 0;
  while(flag){
    check=0;
    
    for(int i=0; i<n; ++i){
      if(A[i]%2==0) check+=1;
    }
    
    if(check==n){
      for(int i=0; i<n; ++i){
        A[i] /=2;
      }
      count +=1;
    }else{
      flag = false;
    }
  }
  cout << count;
  return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 3006
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
//#define P 998244353
int n , P;
int S[MAXN][MAXN] , C[MAXN][MAXN];

int Pow( int x , int a ) {
	int ret = 1;
	while( a ) {
		if( a & 1 ) ret = ret * 1ll * x % P;
		x = x * 1ll * x % P , a >>= 1;
	}
	return ret;
}

int p2[MAXN];
void solve() {
	cin >> n >> P;
	S[0][0] = C[0][0] = 1 , p2[0] = 1;
	rep( i , 1 , n + 1 ) {
		C[i][0] = 1 , S[i][0] = 0;
		rep( j , 1 , i ) S[i][j] = ( S[i - 1][j - 1] + S[i - 1][j] * 1ll * j ) % P , C[i][j] = ( C[i - 1][j - 1] + C[i - 1][j] ) % P;
		p2[i] = p2[i - 1] * 2 % ( P - 1 );
	}
	int ans = 0;
	rep( i , 0 , n ) {
		int re = 0;
		rep( j , 0 , i ) re = ( re + S[i + 1][j + 1] * 1ll * Pow( 2 , ( n - i ) * 1ll * j % ( P - 1 ) ) ) % P;
		re = re * 1ll * Pow( 2 , p2[n - i] ) % P * C[n][i] % P;
		ans = ( ans + ( ( i & 1 ) ? P - re : re ) ) % P;
	}
	cout << ans << endl;
}

signed main() {
//	freopen("ex_A2.in","r",stdin);
//	freopen("out","w",stdout);
//	int T;cin >> T;while( T-- ) solve();
    solve();
}



Measured memory_bytes: 58728
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<string>
#include<utility>
#include<iomanip>
#include<bitset>
#include<math.h>
using namespace std;

int main(){

	double n;
	cin >> n;

	if((int)n%2 == 0){
		cout << (n/2)/n << endl;
	}else{
		cout << (n/2 + 0.5) / n << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

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

    int cnt0 = 0, cnt1 = 0;
    rep(i, 0, s.size())
    {
        if (i % 2 == 0)
        {
            if (s[i] == '0')
                cnt1++;
            else
                cnt0++;
        }
        else
        {
            if (s[i] == '1')
                cnt1++;
            else
                cnt0++;
        }
    }
    cout << min(cnt0, cnt1) << endl;
}


Measured memory_bytes: 512
/**
 *   author: malviyanshiv
 *   created: 07 September 2019  17:44:07
**/
#include<bits/stdc++.h>

using namespace std;

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

    int n;
    cin >> n;
    vector<int> arr(n, 1e9);
    vector<int> arrb(n-1);
    for(int i = 0; i < n-1; i++)
        cin >> arrb[i];
    int idx = n-1;
    arr[idx] = min(arr[idx], arrb[n-2]);
    idx--;
    arr[idx] = min(arr[idx], arrb[n-2]);
    while(idx >= 1){
        arr[idx] = min(arr[idx], arrb[idx-1]);
        idx--;
        arr[idx] = arrb[idx];
    }
    long long sm = 0;
    for(int i = 0; i < n; i++)
        sm += arr[i];
    cout << sm ;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
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;}
typedef pair<ll,ll> P;

int main(){
    double a,b,x;
    cin>>a >> b>> x;
    if(a*a*b/2<x){
        double nokori = a*a*b-x;
        double h = 2*nokori/(a*a);
        cout <<fixed<<setprecision(7)<< 90 -90*atan(a/h)/(M_PI/2)<<endl;
    }else{
        double h = 2*x/(b*a);
        cout <<fixed<<setprecision(7)<< 90 -90*atan(h/b)/(M_PI/2)<<endl;
    }
  
    
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
	int nimotunum;
	int x,y,h,w;
	int totalfee;
	int i,j;
	const int weightlist[6]={2,5,10,15,20,25};
	const int sizelist[6]={60,80,100,120,140,160};
	const int feelist[7]={600,800,1000,1200,1400,1600,0};
	while(1) {
		scanf("%d",&nimotunum);
		if(nimotunum==0)break;
		totalfee=0;
		for(i=0;i<nimotunum;i++) {
			scanf("%d %d %d %d",&x,&y,&h,&w);
			for(j=0;j<6;j++) {
				if(w<=weightlist[j] && x+y+h<=sizelist[j])break;
			}
			totalfee+=feelist[j];
		}
		printf("%d\n",totalfee);
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
using namespace std;
const int N=1e5+11,mod=1e9+7;
int n,m,len,ans;
char s[N];
int sum[N];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	rep(i,1,n){
		if(s[i]=='A'||s[i]=='G'||s[i]=='T'||s[i]=='C')
			++len;
		else
			len=0;
		ans=max(ans,len);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
  int n, q;
  int s[10005];
  int t[505];
  int i, j;
  int count=0;
  scanf("%d", &n);
  for(i=0; i<n; ++i){
	scanf("%d", &s[i]);
}
  scanf("%d", &q);
  for(i=0; i<q; ++i){
	scanf("%d", &t[i]);
}
  //探索
  for(i=0; i<q; ++i){
	for(j=0; j<n; ++j){
	  if(t[i]==s[j]){
		++count;
		break;
	  }
	}
  }
  printf("%d\n", count);
  //
  return 0;
}



Measured memory_bytes: 2044
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    #n = int(stdin.readline().rstrip())
    n,m = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    if n==m:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9132
N = int(input())
dp = [1000000] * (N + 1)
dp[0] = 0
for i in range(1, N + 1):
    dp[i] = dp[i - 1] + 1
    x = 6
    while i - x >= 0:
        dp[i] = min(dp[i], dp[i - x] + 1)
        x *= 6
    x = 9
    while i - x >= 0:
        dp[i] = min(dp[i], dp[i - x] + 1)
        x *= 9

print(dp[N])


Measured memory_bytes: 3828
#include <cstdio>

int main(){
	int n, i=1;
	scanf(" %d", &n);
	
	while(i <= n){
		int x=i;
		
		if(x%3==0) {
			printf(" %d", i);
		}
		else {
			while(x){
				if(x%10==3){
					printf(" %d", i);
					break;
				}
				else x/=10;
			}
		}
		
		++i;
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 2708
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,ans=1;
    cin >> n;
    vector<ll> a(n+1,0);
    a[0]=3;
    rep(i,n){
        ll f;
        cin >> f;
        (ans*=a[f])%=MOD;
        a[f]--;
        a[f+1]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat
ll n, m ,k;
const int  N = 200005;
ll a[N], b[N], dp[N], pp[N];

int main(int argc, char const *argv[])
{
	sync;
	cin >> n >> m >> k;
	rep(i,n){
		cin >> a[i];
		if(i == 0){
			dp[i] = a[i];
			continue;
		}
		dp[i] = dp[i-1] + a[i];
	}
	rep(i,m){
		cin >> b[i];
		if(i == 0){
			pp[i] = b[i];
			continue;
		}
		pp[i] = pp[i-1] + b[i];
	}
	ll p1 = 0, p2 = 0;
	rep(i,n){
		if(dp[i] <= k){
			p1 = i + 1;
		}
	}
	rep(i,m){
		if(pp[i] <= k){
			p2 = i + 1;
		}
	}
	ll ans = 0;
	rep(i,n){
		ll val = k - dp[i]; 
		if(val < 0){
			break;
		}
		ll pos = lower_bound(pp,pp+m,val) - pp;
		if(pos == m){
			pos--;
		}
		else if(pp[pos] != val){
			pos--;
			if(pos < 0){
				continue;
			}
		}
		//cout << pos sp i << endl;
		ans = max(ans, pos + i + 2);
	}
	ans = max(ans, max(p1,p2));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9896
import sys
s=list(input())
n=len(s)
l=0;r=n-1
ans=0
while l<r:
  if s[l]==s[r]:
    l+=1;r-=1
  elif s[l]=='x':
    l+=1
    ans+=1
  elif s[r]=='x':
    r-=1
    ans+=1
  else:
    print(-1)
    sys.exit()
print(ans)

Measured memory_bytes: 4084
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int nx,ny,n;
    int ans=0;
    cin>>nx>>ny>>n>>nx>>ny;
    for(int i=1;i<n;++i){
        int gx,gy;
        cin>>gx>>gy;
        if((gx>=nx&&gy>=ny)||(nx>=gx&&ny>=gy)){
            ans+=max(abs(gx-nx),abs(gy-ny));
        }else{
            ans+=abs(gx-nx)+abs(gy-ny);
        }
        nx=gx;ny=gy;
    }
    cout<<ans<<endl;
    return 0;
}

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

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

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  string S;
  cin >> S;
  if(S[0]=='S'){
    cout << "Cloudy" << endl;
  }else if(S[0]=='C'){
    cout << "Rainy" << endl;
  }else{
    cout << "Sunny" << endl;
  }
}



Measured memory_bytes: 256
#!/mnt/c/Users/moiki/bash/env/bin/python
N,P = list(map(int, input().split()))
import math

if N == 1:
    print(P)
    exit(0)

def get_prime(n):
    """ Returns  a list of primes < n """
    sieve = [True] * n
    for i in range(3,int(n**0.5)+1,2):
        if sieve[i]:
            sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,n,2) if sieve[i]]

primax = int(1e7) + 9 * int(1e6)
primes = get_prime(primax)
# print(primes)



def df(P, p):
    if P >= p:
        cnt = 0
        while P >= p and P % p == 0:
            P = int(P//p)
            cnt += 1
        return cnt
    else:
        raise "P , p error."

gc = []
for p in primes:
    if P % p == 0:
        cnt = df(P, p)
        P = int( P // int(p**cnt))
        gc.append([p, cnt])
ans = 1
for g,cnt in gc:
    if cnt >= N:
        ans *= g**(cnt//N)

debug = 1
for g,cnt in gc:
    debug *= g**cnt

# N > 100:  why WA
# debug < P: under 3 RE
# debug*2 > P:  None
if P > 1e9 and debug != P and  debug < P and N == 1:
    raise "errror"
print(ans)


Measured memory_bytes: 221580