akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

using namespace std;
#define md 1000000007
#define itn int
#define pb push_back
#define mp make_pair
#define ull unsigned long long int
#define ll long long int
#define ppi pair<int, int>
#define ppl pair<ll, ll>
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ff first
#define lb lower_bound
#define ub upper_bound
#define ss second
#define inf 1e9
#define enld '\n'
#define cuot cout
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
       << z << endl
#define trace4(a, b, c, d)                                                     \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e)                                                  \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f)                                               \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl
#define trace(v)                                                               \
  for (auto it = v.begin(); it != v.end(); it++)                               \
    cerr << *it << " ";                                                        \
  cerr << endl;
#define linf 1e18
#define reset(x) memset(x, 0, sizeof(x))
#define rep(i, a, b) for (int i = a; i < b; i++)

using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    oset;

void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

void solve() {
    string s;cin>>s;
    int ff = (s[0] - '0') * 10 + (s[1]-'0');
    int ss = (s[2] - '0') * 10 + (s[3]-'0');
    if(ss<=12 && ss>0 && ff<=12 && ff>0){
      cout << "AMBIGUOUS";
    }
    else if(ss<=12 && ss>0){
        cout<<"YYMM";
    }
    else if(ff<=12 && ff>0){
        cout<<"MMYY";
    }
    else{
        cout<<"NA";
    }
}
int main() {
  fastio();
  int t;
  t = 1;
  //   cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 256
def gi; gets.split.map(&:to_i); end

N=gets.to_i

ps=(N+1).times.map{[]}
(N-1).times do
    a,b,c = gi
    ps[a] << [a,b,c]
    ps[b] << [b,a,c]
end

Q,K = gi

arr = Array.new(N+1,-1)
arr[K] = 0
q = ps[K].dup

until q.empty?
    parent,child,d = q.shift
    next if arr[child] != -1
    arr[child] = arr[parent] + d
    q.concat ps[child]
end

Q.times do
    x,y = gi
    puts arr[x]+arr[y]
end

Measured memory_bytes: 34744
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n,a,b;cin>>n>>a>>b;
    vector<ll> v(n);
    ll cost=0;
    REP(i,n)cin>>v[i];
    REP(i,n-1){
        ll l=v[i], r=v[i+1];
        if(b<(r-l)*a){
            cost+=b;
        }else{
            cost+=(r-l)*a;
        }
    }
    cout<<cost<<endl;
    return 0;
}


Measured memory_bytes: 4016
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
using namespace std;
struct P {
	int from, to, cost;
};
int parent[10000];
int root(int x) {
	if (parent[x] == x) return x;
	return parent[x] = root(parent[x]);
}
void unite(int x, int y) {
	x = parent[x];
	y = parent[y];
	parent[x] = y;
}
bool same(int x, int y) {
	return root(x) == root(y);
}
bool operator<(P a, P b) {
	return a.cost < b.cost;
}
bool operator>(P a, P b) {
	return a.cost > b.cost;
}
int main() {
	int n, m;
	while (cin >> n&&n != 0) {
		cin >> m;
		priority_queue<P, vector<P>, greater<P>>p;
		int a, b, c;
		for (int i = 0; i < m; i++) {
			scanf("%d,%d,%d", &a, &b, &c);
			p.push(P{ a,b,c });
		}
		for (int i = 0; i < n; i++) parent[i] = i;
		int d = 0,sum=0;
		while (d != n - 1) {
			P t = p.top(); p.pop();
			if (!same(t.from, t.to)) {
				unite(t.from, t.to);
				d++;
				sum += t.cost;
			}
		}
		sum /= 100;
		sum = sum - n + 1;
		cout << sum << endl;
	}
}

Measured memory_bytes: 3308
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	ll a,b,c,k;
	cin >> a >> b >> c >> k;
	
	REP(i,k){
		if(b <= a) b *= 2;
		else if(c <= b) c *= 2;
		else break;
	}
	
	if(a < b && b < c){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
	
	
	return 0;
}

Measured memory_bytes: 3596
a, b, c, x, y = gets.split.map(&:to_i)

a_1 = a * x + b * y
a_2 = [x, y].max * 2 * c
a_3 = x * 2 * c + [0, y - x].max * b
a_4 = y * 2 * c + [0, x - y].max * a

puts [a_1, a_2, a_3, a_4].min


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


int main(){
    int n; cin>>n;
    
    int x[n];
    for(int i=0;i<n;i++) x[i]=i+1;
    //たとえばn==3だとしてもデバックの時にはxの要素は5つになるので注意

    int p[n],q[n];
    for(int i=0;i<n;i++) cin>>p[i];
    for(int i=0;i<n;i++) cin>>q[i];

    int a,b,count=1;
    do{
        //配列が完全に同一であるかどうかは一つひとつの要素を順に見ていく必要がある
        int count1=0,count2=0;
        for(int i=0;i<n;i++){            
            if(x[i]==p[i]) count1++;
            if(x[i]==q[i]) count2++;
        }
        if(count1==n) a=count;
        if(count2==n) b=count;
        count++;
    }while(next_permutation(x,x+n));

    cout<<abs(a-b)<<endl;
}

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

using namespace std;

const int INF = 1e9+5;

int n, m;
vector <int> adj[200020];

vector <int> bfs(int src)
{
    vector <int> sign(n+1, INF);
    sign[src] = 0;

    queue <int> q;
    q.push(src);

    while (!q.empty())
    {
        int u = q.front();
        q.pop();

        for (int v: adj[u])
        {
            if (sign[v] == INF)
            {
                sign[v] = u;
                q.push(v);
            }
        }
    }

    return sign;
}

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

    for (int i = 1; i <= m; i++)
    {
        int u, v;

        cin >> u >> v;

        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector <int> sign = bfs(1);

    for (int i = 1; i <= n; i++)
    {
        if (sign[i] == INF)
        {
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";

    for (int i = 2; i <= n; i++)
    {
        cout << sign[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 12632
n=input()
z=[[[0 for _1 in xrange(2)] for _2 in xrange(2)] for _3 in xrange(n+1)]
z[-1][1][1]=1
for i in xrange(n-1,-1,-1):
  for j in xrange(2):
    for k in xrange(2):
      for t in xrange(10):
        z[i][j][k]+=z[i+1][j or t==0][k or t==9]
      z[i][j][k]%=(pow(10,9)+7)
print z[0][0][0]

Measured memory_bytes: 325572
import java.util.*;
import static java.lang.System.out;
import static java.lang.Math.*;
 
class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    while(scan.hasNext()){
      double x[] = new double[4];
      double y[] = new double[4];
      for(int i=0;i<4;i++){
        x[i] = scan.nextDouble();
        y[i] = scan.nextDouble();
      }
      double a = (x[0] - x[1]) * (x[2] - x[3]);
      double b = (y[0] - y[1]) * (y[2] - y[3]);
      if((float)a + (float)b == 0) out.println("YES");
      else out.println("NO");
    }
  }
}


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

signed main(){
  int H,W,N;
  cin>>H>>W>>N;
  int a,b;
  std::vector<int> v(N*9,-1);
  int x[3]={-1,0,1};
  int y[3]={-1,0,1};
  for(int i=0;i<N;i++){
    cin>>a>>b;
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(1<a+y[j]&&a+y[j]<H&&1<b+x[k]&&b+x[k]<W)v[i*9+3*j+k]=(a+y[j])*1000000000+b+x[k];
      }
    }
  }
  sort(v.begin(),v.end());
  std::vector<int> ans(10,0);
  int c=1;
  for(int i=0;i<N*9-1;i++){
    if(v[i]!=-1){
      if(v[i]==v[i+1])c++;
      else{
        ans[c]++;
        c=1;
      }
    }
  }
  if(N)ans[c]++;
  ans[0]=(H-2)*(W-2);
  for(int i=1;i<10;i++)ans[0]-=ans[i];
  for(int i=0;i<10;i++)cout<<ans[i]<<endl;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// #define int long long
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

int lcm(int, int);
map<int,int> GetPrimeFactors(int);
bool IsPrime(int);
int Factorial(int);
int npr (int, int);
int ncr (int, int);

/***** MAIN *****/
void Main() {
  int a, b, x;
  cin >> a >> b >> x;
  double v = pow(a,2) * b;
  double ans;
  if(x >= 0.5 * v) {
    ans = atan(2 * (v - x) / pow(a, 3));
  } else {
    ans = atan(a * pow(b, 2) / 2 / x);
  }
  ans *= 180 / PI;
  cout << ans << endl;
}
/***** MAIN *****/

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

int lcm(int a, int b) { return a / __gcd(a,b) * b;}

map<int,int> GetPrimeFactors(int n) {
  map<int,int> mp;
  // dived by 2, 3, 5, ...
  for(int i=2; i*i<=n; i+=2) {
    if(i==4) i = 3;
    while(n%i == 0) {
      ++mp[i];
      n /= i;
    }
  }
  if(n!=1) ++mp[n];

  return mp;
}

bool IsPrime(int a) {
  if(a <= 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(int i = 3; i*i <= a; i+=2) {
    if(a%i==0) return false;
  }
  return true;
}

int Factorial(int n){
  int ans = 1;
  while(n > 1){
    ans *= n;
    --n;
  }
  return ans;
}

int npr(int n, int r) {
  return Factorial(n)/Factorial(n-r);
}

int ncr (int n, int r){
  return npr(n,r)/Factorial(r);
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a == 0 & b == 0)
				break;
			for (int i = 0; i < a; i++) {
				for (int j = 0; j < b; j++) {
					if(i==0||i == a-1)
						System.out.print("#");
					else if(j==0||j==b-1)
						System.out.print("#");
					else
						System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 24636
#include <iostream>
#include <iomanip>
using namespace std;
int main( void )
{
	int h, m, s;
	while ( cin >> h >> m >> s && h != -1 && m != -1 && s != -1 )
	{
		int ss = h * 3600 + m * 60 + s;
		int a = 120 * 60 - ss;

		h = a / 3600;
		m = (a % 3600) / 60;
		s = a % 60;
		cout << setfill('0') << setw(2) << h << ":" << setw(2) << m << ":" << setw(2) << s << endl;

		a *= 3;
		h = a / 3600;
		m = (a % 3600) / 60;
		s = a % 60;
		cout << setfill('0') << setw(2) << h << ":" << setw(2) << m << ":" << setw(2) << s << endl;

	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
ll n, r;
map<int, int> m = {};
int main() {
  cin >> n;
  rep(i, n) {
    int a;
    cin >> a;
    m[a]++;
  }
  for (auto p : m) {
    if (p.first <= p.second)
      r += (p.second - p.first);
    else
      r += p.second;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 4736
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <sstream>
#include <string>
#include <vector>

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

  std::string s;

  std::cin >> s;

  if (s.c_str()[2] != s.c_str()[3]) {
    std::cout << "No" << "\n";
    return 0;
  }

  if (s.c_str()[4] != s.c_str()[5]) {
    std::cout << "No" << "\n";
    return 0;
  }

  std::cout << "Yes" << "\n";

  return 0;
}

Measured memory_bytes: 256
import Data.List
import Data.Char
main = do
      s <- getContents
      let v = map (return . toLower) s :: [String]
      mapM_ putStrLn (cntChar v)

cntChar :: [String] -> [String]
cntChar s = let rst=filter (\x->fst x >="a" && fst x <="z")$ map (\x-> (head x,length x)) $ group $ sort s
                in [c2s rst [c]| c<-['a'..'z']]
  where
        c2s :: [(String,Int)] -> String -> String
        c2s rst c = if (iskey rst c) then
                                      c ++ " : "++ (show (val' rst c))
                                  else
                                      c ++ " : "++ "0"     

iskey :: [(String,Int)] -> String -> Bool
iskey a s = elem s $ keys a

val' :: [(String,Int)] -> String -> Int
val' a s =
   snd $ head $ dropWhile (\x-> (fst x) /= s) $ a

keys :: [(String,Int)] -> [String]
keys a = map fst a

values:: [(String,Int)] -> [Int]
values a = map snd a

Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    ll N, K;
    cin >> N >> K;
    bool use[N][N];
    if (K > (N - 1) * (N - 2) / 2) {
        cout << -1 << endl;
        return 0;
    }
    FOR(i, 0, N) {
        FOR(j, 0, N) {
            use[i][j] = (i < j);
        }
    }
    FOR(i, 0, N - 1) {
        FOR(j, 0, N - 1) {
            if (K && use[i][j]) {
                use[i][j] = false;
                K--;
            }
        }
    }
    vector<pl> ans;
    FOR(i, 0, N) {
        FOR(j, 0, N) {
            if (use[i][j]) {
                ans.push_back(make_pair(i + 1, j + 1));
            }
        }
    }
    cout << ans.size() << endl;
    for (auto p : ans) {
        cout << p.first << ' ' << p.second << endl;
    }
}

Measured memory_bytes: 512
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{   
    static int[][] dp;
    static int[] a;
    static int[] b;
    static int[] c;
    static int days;
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner scan = new Scanner(System.in);
		days = scan.nextInt();
		dp = new int[3][days];
		a = new int[days]; b = new int[days]; c = new int[days];
		for(int i = 0; i < days; i++){
		    a[i] = scan.nextInt();
		    b[i] = scan.nextInt();
		    c[i] = scan.nextInt();
		}
		if(days == 1){
		    System.out.println(Math.max(a[0], Math.max(b[0], c[0])));
		    return;
		}
		dp[0][0] = Math.max(b[0], c[0]);
		dp[1][0] = Math.max(a[0], c[0]);
		dp[2][0] = Math.max(b[0], a[0]);
		for(int i = 1; i < days; i++){
		    dp[0][i] = Math.max(dp[1][i - 1] + a[i], dp[2][i - 1] + a[i]);
		    dp[1][i] = Math.max(dp[0][i - 1] + b[i], dp[2][i - 1] + b[i]);
		    dp[2][i] = Math.max(dp[1][i - 1] + c[i], dp[0][i - 1] + c[i]);
		}
		System.out.println(Math.max(dp[0][days-1], Math.max(dp[1][days-1], dp[2][days-1])));
	}
/*	public static int chose(int idx, int prev, int sum)
	{
	    if(idx == days - 1) {
	        if(prev == 0) return Math.max(sum + b[days - 1], sum + c[days - 1]);
	        else if(prev == 1) return Math.max(sum + a[days - 1], sum + c[days - 1]);
	        else return Math.max(sum + a[days - 1], sum + b[days - 1]);
	    }
	//    if(memo[prev][idx] != 0) return memo[prev][idx];
	    int f1 = 0;
	    int f2 = 0;
	    if(prev == 0){
	        f1 = chose(idx + 1, 1, sum + b[idx]);
	        f2 = chose(idx + 1, 2, sum + c[idx]);
	    }
	    else if(prev == 1){
	        f1 = chose(idx + 1, 0, sum + a[idx]);
	        f2 = chose(idx + 1, 2, sum + c[idx]);
	    }
	    else
	    {
	        f1 = chose(idx + 1, 1, sum + b[idx]);
	        f2 = chose(idx + 1, 0, sum + a[idx]);
	    }
	 //   memo[prev][idx] = Math.max(f1, f2);
	    return Math.max(f1, f2); //memo[prev][idx];
	}*/
}

Measured memory_bytes: 62664
#include <iostream>
#include <math.h>
using namespace std;
int N, S, y_max, z_max, ans;

int main(){
  while( cin >> N && N > 0){
    for(int i = 0; i <= 1000; i++){
      for(int j = 0; j <= 100; j++){
        if(i == 0 && j == 0) ans = N;
        if(ans > (i + j +(N-i*i-j*j*j)) && N-i*i-j*j*j >= 0) ans = i + j +(N-i*i-j*j*j);
      }
    }


    cout << ans << endl;


  }




}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <string>
#include <deque>

using namespace std;

typedef struct point {
  int row;
  int col;
  point(int r, int c) {
    this->row = r;
    this->col = c;
  }
} point;

vector<point> warp_point_gen(){
  vector<point> result;
  for(int i=-2; i<=2; i++){
    for(int j=-2; j<=2; j++){
      if(i == 0 && i == j) continue;
      result.push_back(point(i, j));
    }
  }
  return result;
}

int main(){
  int h, w;
  std::cin >> h >> w;

  point start = point(0, 0);
  std::cin >> start.row >> start.col;
  start.row -= 1;
  start.col -= 1;

  point goal = point(0, 0);;
  std::cin >> goal.row >> goal.col;
  goal.row -= 1;
  goal.col -= 1;

  vector<string> graph(h);
  for(int i=0; i<h; i++){
    std::cin >> graph[i];
  }

  vector<vector<int> > costs(h, vector<int>(w, INT_MAX));
  deque<point> q;
  point able_to_move_point[4] = {
    point(1, 0), point(-1, 0), point(0, 1), point(0, -1)
  };
  vector<point> warp_point_offset = warp_point_gen();

  costs[start.row][start.col] = 0;
  q.push_front(start);

  while(0 < q.size()){
    point p = q.front();
    q.pop_front();
    for(int i=0; i<4; i++){
      int row = p.row + able_to_move_point[i].row;
      int col = p.col + able_to_move_point[i].col;
      if(row < 0 || col < 0) continue;
      if(row >= h || col >= w) continue;
      if(graph[row][col] == '.'){
        if(costs[p.row][p.col] >= costs[row][col]) continue;
        q.push_front(point(row, col));
        costs[row][col] = costs[p.row][p.col];
      }
    }

    for(int i=0; i<24; i++){
      int row = p.row + warp_point_offset[i].row;
      int col = p.col + warp_point_offset[i].col;
      if(row < 0 || col < 0) continue;
      if(row >= h || col >= w) continue;
      if(graph[row][col] == '.'){
        if(costs[p.row][p.col] >= costs[row][col]) continue;
        q.push_back(point(row, col));
        costs[row][col] = costs[p.row][p.col] + 1;
      }
    }
  }

  if(INT_MAX == costs[goal.row][goal.col] ){
    std::cout << -1 << '\n';
  }else{
    std::cout << costs[goal.row][goal.col] << '\n';
  }

  return 0;
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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

ll modpow(ll a, ll n){
    ll res=1;
    while(n > 0){
        if(n & 1) res=res*a%MOD;
        a=a*a%MOD;
        n>>=1;
    }
    return res;
}

ll modinv(ll x){
    return modpow(x, MOD-2);
}

int main(){
    int n, k; cin >> n >> k;
    vector<ll> a(n);
    for(auto &x : a) cin >> x;
 
    vector<ll> p, m;
    bool flag=false;
    for(int i=0; i<n; i++){
        if(a[i] >= 0){
            p.push_back(a[i]);
            flag=true;
        } 
        else m.push_back(a[i]);
    }
    sort(all(p), greater<ll>{});
    sort(all(m));
    ll ans=1;

    if(n == k){
        for(int i=0; i<k; i++) ans=ans*a[i]%MOD;
    }
    else if(!flag){
        if(k%2 == 0){
            sort(all(a));
            for(int i=0; i<k; i++) ans=ans*a[i]%MOD;
        }
        else{
            sort(all(a), greater<ll>{});
            for(int i=0; i<k; i++) ans=ans*a[i]%MOD;
        }
    }
    else{
        int posp=0, posm=0;
        auto update=[&](ll &x, ll y, int &id){
            x=x*y%MOD;
            id++; 
        };
        for(int i=0; i<k; i++){
            if(posm == m.size() || p[posp] > -m[posm]){
                update(ans, p[posp], posp);
            }
            else update(ans, m[posm], posm);
        }
        
        if(ans < 0){
            if(posm == m.size() || posp == 0 || p[posp-1]*p[posp] > m[posm-1]*m[posm]){
                ans=ans*modinv(m[posm-1])%MOD*p[posp]%MOD;
            }
            else ans=ans*modinv(p[posp-1])%MOD*m[posm]%MOD;
        }
    }

    if(ans < 0) ans+=MOD;
    cout << ans << endl;
    return 0;
}

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

int main() {
    long int n,v;
    cin>>n;
v=2;
    long int b[n],c[n];
   for(int i=0;i<n;i++){
       cin>>b[i];
   }
   c[0]=0;
   c[1]=abs(b[0]-b[1]);
   for(int i=2;i<n;i++){
       c[i]=9999999999;
       for(int k=1;k<=v&&k<=i;k++){
       
         c[i]=min(abs(b[i]-b[i-k])+c[i-k],c[i]);
       }  
   }
   cout<<c[n-1];
	return 0;
}

Measured memory_bytes: 5196
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

bool hoge[1000000];

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int l, r;
		cin >> l >> r;
		for (int j = l; j <= r; j++) {
			hoge[j] = true;
		}
	}
	int ans = 0;
	for (int i = 0; i < 1000000; i++)
		if (hoge[i]) ++ans;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>

int main(){
  char str[1001]; //1000桁long longでも不可
  
  while(1){
    scanf("%s", str);
    if ( str[0] == '0' ) break;
    int sum = 0;
    for ( int i = 0; str[i] != '\0'; i++ ) { //終端文字
      sum += str[i] - '0';
    }
    printf ("%d\n", sum);
  }
  
  return 0;
}


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

string s;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5]) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


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

int main() {
  string w; cin>>w;
  int flag=1;
  for(int i=0;i<26;i++){
    int count=0;
    for(int j=0;j<w.size();j++){
      if(w[j]-'a'==i) count++;
    }
    if(count%2!=0){
      flag=0;
      break;
    }
  }
  if(flag==1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
    
  

    
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin>>n;
	int a[n],maxx=-99999999,x,y;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			x=abs(a[i]-a[j]);
			y=abs(a[j]-a[i]);
			if(maxx<x) maxx=x;
			if(maxx<y) maxx=y;
		}
	}
	cout<<maxx<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int k,x ;
   cin >> k >> x ;
  
   int num = k*2-1 ;
   int ans = x-k+1 ;
   for(int i=0;i<num;i++)
   {
     cout << ans << " " ;   
     ans ++;
   }
   cout << endl;  
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll h, w, l;
string c[110];

ll dir = 0;
ll px, py;
ll dx[] = { 0,1,0,-1 };
ll dy[] = { -1,0,1,0 };
ll d[4][110][110];
ll s = -1;
ll m = -1;
string t = "NESW";

void solve() {
	d[dir][py][px] = 0;
	ll cnt = 0;
	while (1) {
		cnt++;
		ll nx, ny;
		ll ndir = dir;
		while (1) {
			nx = px + dx[ndir];
			ny = py + dy[ndir];
			if (nx >= 0 && nx < w&&ny >= 0 && ny < h) {
				if (c[ny][nx] == '#')ndir = (ndir + 1) % 4;
				else break;
			}
			else ndir = (ndir + 1) % 4;
		}
		if (d[ndir][ny][nx] != INF) {
			s = d[ndir][ny][nx];
			m = cnt - s;
			break;
		}
		d[ndir][ny][nx] = cnt;
		px = nx;
		py = ny;
		dir = ndir;
	}
}

int main() {
	while (cin >> h >> w >> l&&h + w + l) {
		rep(i, 4)rep(j, 110)rep(k, 110)d[i][j][k] = INF;
		rep(i, h)cin >> c[i];
		rep(i, h) {
			rep(j, w) {
				if (c[i][j] != '.'&&c[i][j] != '#') {
					if (c[i][j] == 'N')dir = 0;
					if (c[i][j] == 'E')dir = 1;
					if (c[i][j] == 'S')dir = 2;
					if (c[i][j] == 'W')dir = 3;
					py = i, px = j;
				}
			}
		}
		solve();
		if (l > s) {
			//cout << "!!" << endl;
			l -= s;
			l %= m;
			l += s;
		}
		ll ans[3] = {};
		rep(k, 4) {
			rep(i, h) {
				rep(j, w) {
					if (d[k][i][j] == l) {
						ans[0] = k;
						ans[1] = i;
						ans[2] = j;
						break;
					}
				}
			}
		}
		//rep(k, 4) {
		//	rep(i, h) {
		//		rep(j, w) {
		//			cout << d[k][i][j] << " ";
		//		}
		//		cout << endl;
		//	}
		//	cout << endl;
		//}
		//cout << "!" << ans[0] << endl;
		cout << ans[1] + 1 << " " << ans[2] + 1 << " " << t[ans[0]] << endl;
	}
}


Measured memory_bytes: 3408
#include<bits/stdc++.h>
#include<iterator>
using namespace std;
int main()
{
    map<string ,int>m;
    map<string ,int>::iterator x;
    char s[10];
    int n;
    cin>>n;
    for(int i=1 ; i<=n ; i++)
    {
        cin>>s;
        m[s]++;
    }
    int cnt=0;
    for(x=m.begin() ; x!=m.end() ; x++)
        if(x->second)
            cnt++;
    cout<<cnt<<"\n";
}


Measured memory_bytes: 19148
#include<cstdio>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
#define MAXN 100005
int n,t[MAXN];
vector<int> G[MAXN];
void dfs(int u,int f)
{
	map<int,int> cnt;
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i];
		if(v==f) continue;
		dfs(v,u);
		cnt[t[v]]++;
	}
	map<int,int>::iterator it;
	for(it=cnt.begin();it!=cnt.end();it++)
	{
		if(it->second>1)
			cnt[(it->first)+1]+=it->second-1;
	}
	//父亲每个时刻只能找一个儿子打 剩下的儿子要推到后面
	if(it!=cnt.begin())//表示有儿子，进去过循环
		it--,t[u]=it->first+1;
}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		G[i].push_back(x);
		G[x].push_back(i);
	}
	dfs(1,0);
	printf("%d\n",t[1]);
}

Measured memory_bytes: 20096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		String a = scan.next();
		String b = scan.next();

		if(a.equals("H")){
			System.out.println(b);
		}else{
			if(b.equals("H")){
				System.out.println("D");
			}else{
				System.out.println("H");
			}
		}

	}

}


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

unsigned long long funcS( unsigned long long n )
{
	unsigned long long result = 0;
	for ( ; n > 0; n /= 10 )
	{
		result += n % 10;
	}

	return ( result );
}

unsigned int getD( unsigned long long input )
{
	unsigned int digit = 0;
	for ( ; input > 0; input /= 10 )
	{
		digit++;
	}

	return ( digit );
}

unsigned long long pow10( unsigned int input )
{
	unsigned long long result = 1;
	for ( int i = 0; i < input; i++ )
	{
		result *= 10;
	}

	return ( result );
}

int main()
{
	unsigned long long K;
	std::cin >> K;

	std::vector<unsigned long long> v = {
		1, 2, 3, 4, 5, 6, 7, 8, 9, 19,			//	問題文で与えられて、すでに判明している
	};

	// Kが10以下なら、既知の値をそのまま出力して終了
	if ( K <= 10 )
	{
		for ( int i = 0; i < K; i++ )
		{
			std::cout << v[i] << std::endl;
		}
	}
	else
	{
		// Kが10より大きければ、追加分を探す
		unsigned long long counter = 10;
		unsigned long long diff = 10;
		for ( unsigned long long k_ = 29; counter < K; k_ += diff )	//	続きは29から探す
		{
			bool bFind = true;
			for ( unsigned int d = 0; d < getD( k_ ); d++ ) // k_の桁数分ループ
			{
				// 候補となる値を計算する
				unsigned long long x = pow10( d + 1 );
				x *= (unsigned long long)( ( (double)k_ / pow10( d + 1 ) ) + 1 );
				x -= 1;

				if ( (double)k_ / funcS( k_ ) > (double)x / funcS( x ) )
				{
					bFind = false;
					break;
				}
			}

			if ( bFind )
			{
				diff = k_ - v.back();	//	差分を再計算して計算範囲を絞り込む
				v.emplace_back( k_ );
				counter++;
			}
		}

		for ( auto &&it : v )
		{
			std::cout << it << std::endl;
		}
	}

	return ( 0 );
}


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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int a,b;
  cin >> a >> b;
  if(b<10)
    a=10*a+b;
  else if(b==100)
    a=100+1000*a;
  else
    a=100*a+b;
  int t=sqrt(a);
  if(t*t==a){
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
#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 ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

const int MAX_N = 100010;
vector<int> G[MAX_N];
int d[MAX_N];
int d2[MAX_N];

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

    int n,u,v;
    cin >> n >> u >> v;
    u--;
    v--;
    
    rep(i,n-1)
    {
        int a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    if (u==v)
    {
        cout << 0 << endl;
        return 0;
    }
    
    fill(d, d+n, INF);
    priority_queue<P, vector<P>, greater<P> > que;
    d[u] = 0;
    que.push(P(0, u));
    while(!que.empty())
    {
        P p = que.top();que.pop();
        if (d[p.second] < p.first) continue;

        rep(i, G[p.second].size())
        {
            int to = G[p.second][i];
            if (d[to] > d[p.second]+1)
            {
                d[to] = d[p.second] + 1;
                que.push(P(d[to], to));
            }
        }
    }

    fill(d2, d2+n, INF);
    d2[v] = 0;
    queue<int> que2;
    que2.push(v);
    while(!que2.empty())
    {
        int now_at = que2.front();que2.pop();
        for (auto itr = G[now_at].begin(); itr!=G[now_at].end(); ++itr)
        {
            if (d2[*itr]==INF)
            {
                d2[*itr] = d2[now_at] + 1;
                que2.push(*itr);
            }
        }
    }

    int ans = 0;
    rep(i,n)
    {
        if (d[i] < d2[i])
        {
            ans = max(ans, d2[i]-1);
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 6912
#include <cstdio>
#include <string>
using namespace std;
int n; 
void dfs(string s,int now){
	if(s.size()==n){
		printf("%s\n",s.c_str());
		return;
	}
	for(int i=1;i<now;++i){
		dfs(s+char(i+'a'-1),now);
	}
	dfs(s+char(now+'a'-1),now+1);
}
int main(){
	scanf("%d",&n);
	dfs("",1); 
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
#define mod 1000000007;

int main (void){
	int n,x,i,m[101],sum=0;
	cin >> n >> x;
	for(i=0;i<n;i++) {
		cin >> m[i];
		sum+=m[i];
	}
	x-=sum;
	sort(m,m+n);
	cout << n+(x-x%m[0])/m[0] << endl;
	return 0;
}

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

bool eq(double x, double q){
    return abs(x*x*x-q) < 0.00001*q;
}

int main(){
    double n;
    while( scanf("%lf", &n), n > 0 ){
        double x = n/2;
        while( true ){
             x = x - (x*x*x-n)/(3*x*x);
             if( eq(x, n) ) break;
         }
        printf("%lf\n", x);
    }
    return 0;
} 

Measured memory_bytes: 1076
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <tuple>
using namespace std;

int main(){

    int n; cin >> n;

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

    vector<int> ans;
    int ntemp = n;
    bool flag = true;
    bool isValid = false;
    while(flag){
        flag = false;
        for(int i=ntemp-1; i>=0; i--){
            if(b[i] - i == 1){
                flag = true;
                ans.push_back(b[i]);
                for(int j=i; j<ntemp; j++){
                    b[j] = b[j+1];
                }
                ntemp--;
                break;
            }
        }
        if(ntemp == 0){
            isValid = true;
        }
    }

    if(isValid){
        for(int i=ans.size()-1; i>=0; i--){
            cout << ans[i] << endl;
        }
    }
    else{
        cout << -1;
    }

    return 0;
}

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

int ordena(const void* a, const void* b){
    if(*(int*)a < *(int*)b)
        return 1;
    if(*(int*)a > *(int*)b)
        return -1;
    else
        return 0;
}

int main(){
    int n,k;
    scanf("%d %d", &n, &k);
    int vetor[n];
        for(int i=0;i<n;i++){
            scanf("%d",&vetor[i]);
        }
    qsort(vetor,n,sizeof(int),ordena);

    int soma=0;
    for(int i=0;i<k;i++){
        soma=soma+vetor[i];
    }

    printf("%d\n", soma);

    return 0;
}


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

int d[10][10];

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

  int n;
  cin >> n;

  for (int i = 1; i <= n; ++i) {
    string s = to_string(i);
    
    int h = to_string(i).front() - '0';
    int t = to_string(i).back() - '0';

    ++d[h][t];
  }

  ll ans = 0;

  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      ans += d[i][j] * d[j][i];
    }
  }

  cout << ans << '\n';

  return (0);
}


Measured memory_bytes: 3720
N = int(input())
l = N // 4
ans = []

if N == 3:
	print("2 5 63")
	exit(0)
elif N == 4:
	print("2 5 20 63")
	exit(0)
elif N == 5:
	print("6 8 9 10 15")
	exit(0)
elif N == 6:
	print("6 8 9 10 12 15")
	exit(0)

for i in range(l):
	ans.extend([6*i+2,6*i+3,6*i+4,6*i+6])

add = [6*(l)+2,6*(l)+3,6*(l)+4,6*(l+1)]
ans.extend(add[:N%4])
s = sum(ans)
flg = s % 6

if flg == 1:
	cor = 2 - (ans[-1]%6)
	if cor <= 0:
		cor += 6
	ans[1] = ans[-1] + cor

elif flg == 2:
	ans[0] = ans[-1] - (ans[-1]%6) + 6
elif flg == 3:
	ans[1] = ans[-1] - (ans[-1]%6) + 6
elif flg == 4:
	ans[2] = ans[-1] - (ans[-1]%6) + 6
elif flg == 5:
	cor = 4 - (ans[-1]%6)
	if cor <= 0:
		cor += 6
	ans[1] = ans[-1] + cor

print(*ans,end=' ')


Measured memory_bytes: 4592
#include <bits/stdc++.h>
#define ll long long int
#define fip(arr, si, en) for (ll i = si; i<en; i++){cin >> arr[i];}
#define fop(arr, si, en) for (ll i = si; i<en; i++){cout << arr[i] << " "; if(i==en-1) cout << endl;}
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>

using namespace std;

int min (int a, int b) {
	return a < b ? a : b;
}

int main() {
	std::ios::sync_with_stdio(false);
	int n; cin >> n;
	int k; cin >> k;
	vi a(n);
	fip(a, 0, n);

	if (n == 1) {
		cout << 0;
		return 0;
	}
	vi dp(n, INT_MAX);
	dp[n - 1] = 0;

	for (int i = n - 2; i >= 0; i--) {
		for (int j = 1; j <= k && i + j < n; j++) {
			dp[i] = min(dp[i] , dp[i + j] + abs(a[i + j] - a[i]));
		}
	}
	cout << dp[0];
}

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

int main(){
  long long int n, m, a, b, p, q, ans;
  cin >> n >> m >> a >> b >> p >> q;
  if(a < b){
    swap(a, b);
    swap(p, q);
  }
  if(a == 1LL){
    if(m/(p + q) >= n) cout << m - n*(p + q) << endl;
    else{
      long long int t = m - m/(p + q)*(p + q);
      cout << min(t, p + q - t) << endl;
    }
    return 0;
  }
  ans = m;
  long long int x = 1LL, y = 1LL;
  for(int i = 1; i < n; ++i){
    if(m <= p*x + q*y) break;
    if(x > (1LL<<40)/a || y > (1LL<<40)/b) break;
    x *= a;
    y *= b;
  }

  while(x > 0){
    ans = min(ans, abs(m - (p*x + q*y)));
    if(m >= p*x + q*y) m -= p*x + q*y;
    x /= a;
    y /= b;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3092
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
	char s[101];
	int i=0,j,len,count=0;

	scanf("%s", s);
	len = strlen(s);

	while(i<len-1) {
		if (s[i] != 'C')i++;
		if (s[i] == 'C') {
			j = i + 1;
			while(j<len) {
				if (s[j] == 'F') {
					count++;
					printf("Yes\n");
					break;
				}
				else j++;
			}break;
		}
	}
	if (count == 0)printf("No\n");
	
	return 0;
}

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

int main() 
{
  int n,a_score=0,b_score=0;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++)
    cin >> a[i];

  sort(a,a+n,greater<int>());

  for(int i=0; i<n; i++)
  {
    if(i%2==0)
      a_score += a[i];
    else
      b_score += a[i];
  }

  cout << a_score - b_score << endl; 

  return 0;
}


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

int main(){
    int N,K;
    int sum=0;
    int a,b,c;
    scanf("%d%d%d%d%d",&N,&K,&a,&b,&c);
    char te[N];
    scanf("%s",te);
    for(int i=0;i+K<N;i++){
        if(te[i]==te[i+K]){
            te[i+K]='f';
        }else{
            ;
        }
    }
    for(int i=0;i<N;i++){
        if(te[i]=='r'){
            sum+=c;
        }else if(te[i]=='s'){
            sum+=a;
        }else if(te[i]=='p'){
            sum+=b;
        }else{
            ;
        }
    }
    printf("%d",sum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
#define newline std::cout<<'\n';
#define newlinedx(num) for(int i=0;i<num;i++)std::cout<<'\n';
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ui = uint64_t;

//----------------library in this time--------------------------------
template <class T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <class T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <class T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}

long long squareTwo(const long long a,const long long b) {
    return (b == 1) ? a : squareTwo(a * 2, b - 1);
}

template <class T>
inline T Max(const T a,const T b) {
    return (a >= b) ? a : b;
}

template <class T>
inline T Min(const T a,const T b) {
    return (a <= b) ? a : b;
}


//------------------------main function-------------------------------
void Main(){
    ll N; cin >> N;
    ll NN = static_cast<ll>(sqrt(N));
    for(ll i = NN; i > 0; i--)if(N % i == 0){
        cout << (i-1) + (N/i) - 1 << endl;
        return;
    }
}

//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
     
    Main();
    return 0;
}


Measured memory_bytes: 256
import sys

#  Input
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
runout = T1 * A1 - T1 * B1
TotalDiff = (T1 * A1 - T1 * B1) + (T2 * A2 - T2 * B2)

if TotalDiff == 0:
    print('infinity')
    sys.exit()
elif runout * TotalDiff > 0:
    print(0)
    sys.exit()

runout = abs(runout)
TotalDiff = abs(TotalDiff)

cnt = 0
cnt = (runout // TotalDiff) * 2
if runout % TotalDiff != 0:
    cnt += 1
print(cnt)


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline lint ty()
	{
		lint a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007;

inline lint pw2(lint x){return x*x;}
inline lint pw3(lint x){return x*x*x;}

int n;
lint val[_],res[_],nex[_];

map<lint,int> cnt;

int main()
{
	n=ty();
	for(int i=1;i<=n;i++)val[i]=ty();

	for(int i=1;i<=n;i++)
	{
		lint x=val[i];
		for(lint j=2;pw3(j)<=x;j++)
			while(x%pw3(j)==0)x/=pw3(j);
		res[i]=x,cnt[x]++;
		
		lint a=1;
		for(lint j=2;pw3(j)<=x;j++)
		{
			if(x%j!=0)continue;
			if(x%pw2(j)==0)a*=j;
			else a*=pw2(j);
			while(x%j==0)x/=j;
		}
		if(pw2(sqrt(x))==x)a*=sqrt(x);
		else a*=pw2(x);
		nex[i]=a;
	}

	int ans=0;
	if(cnt[1])ans++,cnt[1]=0;
	for(int i=1;i<=n;i++)ans+=max(cnt[res[i]],cnt[nex[i]]),cnt[res[i]]=cnt[nex[i]]=0;
	printf("%d\n",ans);
}


Measured memory_bytes: 15104
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a;

int main()
{
	ll x;
	ll ans1,ans2=0;
	
	cin >> x;
	ans1 = x / 500;
	ans2 = x % 500;
	ans2 /= 5;
	cout << ans1*1000+ans2*5 << endl;
	
	return 0;
}


Measured memory_bytes: 256
import Data.List

solve x _ [] = x
solve x (a:s) (b:t) = max x $ solve y s t where
  y = if a == b then x + 1 else 0

main = do
  n <- readLn
  s <- getLine
  print $ maximum $
    [min (n - length t) (solve 0 s t) | t <- tails s]


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

using namespace std;

int main(){
    int n,x;
    cin>>n>>x;
    int t=0;
    for (int i = 0; i < n; ++i) {
        int l;
        cin>>l;
        t+=l;
        if(t>x){
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<n+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
#define mod 1000000007
void dfs(vvi &v, vi &dp, vi &vis, int n,int i){
	vis[i]=1;
	F(j,0,v[i].size()){
		if(!vis[v[i][j]])dfs(v,dp,vis,n,v[i][j]);
	dp[i]=max(dp[i],dp[v[i][j]]+1);
}
}
int main()
{	
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int w=1;
	// cin>>w;
	while(w--){
		int h,w;
		cin>>h>>w;
		string s[h];
		F(i,0,h)cin>>s[i];
		int arr[h+1][w+1];
		F(i,0,h+1){
			arr[i][0]=0;
		}
		F(i,0,w+1)arr[0][i]=0;
		arr[1][1]=1;
		F(i,1,h+1){
			F(j,1,w+1){
				if(i==1&&j==1)continue;
				if(s[i-1][j-1]=='#'){
					arr[i][j]=0;
				}
				else {
					arr[i][j]=(arr[i-1][j]%mod+arr[i][j-1]%mod)%mod;
				}
			}
		}
		cout<<arr[h][w];
	}
}

Measured memory_bytes: 9412