akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n;
   cin >> n;
   vector<int> a(n, 0);
   for (int i = 0; i < n; i++)
      cin >> a[i];
   sort(a.begin(), a.end());
   cout << a[n - 1] - a[0] << endl;
   return 0;
}


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


int main()
{
    string s;
    char s_[100001];
    cin >> s;
    int j = 0;
    for (int i = 0; i < s.size(); i += 2)
    {
        s_[j++] = s[i];
    }
    cout << s_ << endl;
}

Measured memory_bytes: 640
#coding:utf-8

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

s = 0

for n in range(N):
    s += B[A[n]-1]
    if n > 0:
        if A[n]-1 == A[n-1]:
            s += C[A[n-1]-1]

print(s)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define pii pair<ll,ll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(ll i=a;i<=(ll)b;++i)
#define per(i,a,b) for(ll i=a;i>=(ll)b;--i)
#define ll long long
#define lowbit(x) ((x)&(-x))

const int maxn=2e3+5;
ll ans[maxn];
vector<ll>v;
int main()
{
    IOS
    ll n,x,y;cin>>n>>x>>y;
    rep(i,1,n-1){
        rep(j,i+1,n){
            if(i<x){
                if(j<=x) v.pb(j-i);
                else if(j>x&&j<=y) v.pb(min(j-i,x-i+1+y-j));
                else if(j>y) v.pb(x-i+1+j-y);
            }
            else if(i>=x&&i<y){
                if(j<=y) v.pb(min(j-i,i-x+1+y-j));
                else v.pb(min(j-i,i-x+1+j-y));
            }
            else v.pb(j-i);
        }
    }
    for(auto x:v) ans[x]++;
    rep(i,1,n-1) cout<<ans[i]<<" ";
    cout<<"\n";
}

Measured memory_bytes: 18536
n=int(input())
s=input()
l=len(s)
ans=0
lis1=[]
for i in range(l-2):
    lis2=[]
    if s[i] not in lis1:
        lis1.append(s[i])
        for j in range(l-i-2):
            lis3=[]
            if s[i+j+1] not in lis2:
                lis2.append(s[i+j+1])
                for k in range(l-i-j-2):
                    if s[i+j+k+2] not in lis3:
                        lis3.append(s[i+j+k+2])
                        ans+=1

print(ans)


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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
constexpr int loose = 0;
constexpr int tight = 1;


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;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll n,W;
	cin>>n>>W;
	Array w(n),v(n);
	REP(i,n) cin>>w[i]>>v[i];

	ll V=101010;
	Matrix dp(n+1, Array(V,INF));//iこまでみて、価値jのときの最小の重さ
	dp[0][0]=0;

	REP(i,n){
		REP(j,V){
			if(dp[i][j]==INF) continue;
			chmin(dp[i+1][j], dp[i][j]);//とらない
			if(j+v[i]<=V) chmin(dp[i+1][j+v[i]],dp[i][j]+w[i]);//とる
		}
	}
	
	ll ans=0;
	REP2(i,V) if(dp[n][i]<=W){
		ans=i;
		break;
	}
	cout<<ans<<en;
	
}

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

    solve();
    return 0;
}

Measured memory_bytes: 81024
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int a =sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a<b){
            if(b<c){
                System.out.printf("%d %d %d\n", a, b, c);
            }else if(a<c){
                System.out.printf("%d %d %d\n", a, c, b);
            }else{
                System.out.printf("%d %d %d\n", c, a, b);
            }
                
        }else if(a<c){
            System.out.printf("%d %d %d\n", b, a, c);
        }else if(b<c){
            System.out.printf("%d %d %d\n", b, c, a);
        }else{
            System.out.printf("%d %d %d\n", c, b, a);
        }
    }
}


Measured memory_bytes: 26320
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(4100000)

n = int(input())
a = list(map(int, input().split()))
c = [0] * 8
cnt = 0
for i in a:
    if i < 3200:
        c[i // 400] = 1
    else:
       cnt += 1
# print(c)
min_ans = sum(c)
max_ans = min_ans + cnt
# print(c, cnt)
if min_ans == 0:
    print(1, cnt)
else:
    print(min_ans, max_ans)


Measured memory_bytes: 5068
#include <vector>
#include <iostream>
#include <climits>

using namespace std;

const int kSize = 200000;

int cnt = 0;

void BubbleSort(int A[], int n) {
    for (int i = 0; i < n - 1; ++i) {
        for (int j = n - 1; j >= i + 1; --j) {
            if (A[j] < A[j - 1]) {
                swap(A[j], A[j - 1]);
                cnt++;
            }
        }
    }
}
int main() {
    int A[kSize];
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    BubbleSort(A, n);
    for (int i = 0; i < n; ++i) {
        if (i > 0) {
            cout << " ";
        }
        cout << A[i];
    }

    cout << endl;
    cout << cnt << endl;
}


Measured memory_bytes: 3116
# SPDX-License-Identifier: X11
# 2020-09-13

function _main()
  N = parse(Int, readline())
  X, Y = parse.(Int, split(readline()))
  A = [(X + Y, X - Y)]
  for i ∈ 2:N
    X, Y = parse.(Int, split(readline()))
    push!(A, (X + Y, X - Y))
  end
  return max(maximum(x -> x[1], A) - minimum(x -> x[1], A),
         maximum(x -> x[2], A) - minimum(x -> x[2], A))
end

println(_main())


Measured memory_bytes: 218516
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
using namespace std;
#define fastestiointhewest   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll          long long
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define mii         map<int,int>
#define vi          vector<int>
#define vll         vector<long long>
#define lbnd        lower_bound
#define ubnd        upper_bound
#define all(a)      (a).begin(),(a).end()
#define clz(a)      __builtin_clz(a) // count leading zeroes
#define ctz(a)      __builtin_ctz(a) // count trailing zeroes
#define popc(a)     __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define SIZE        1000005
#define F           first
#define S           second
#define debug(x)    cerr << #x << " = " << x << endl;
#define mod         998244353

#define TRACE

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

#define endl        '\n'
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

set<ll> s;
void solve()
{
   ll n,m; cin>>n>>m;
   pair<ll,ll> p[n];
   rep(i,0,n)
   {
     cin>>p[i].F>>p[i].S;
   }
   sort(p,p+n);
   ll ans=0;
   rep(i,0,n)
   {
      ans+=min(p[i].S,m)*p[i].F;
      m-=p[i].S;
      if(m<=0) break;
   }
   cout<<ans;
}  
int main()
{   
    fastestiointhewest;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int m=Min(s[1],s[0]);
		long ans=0;
		for(int i = 0;i<=m;i++) {
			if(s[1]-i<=s[0]){
				ans+=Max(s[1]-i+1,0);
			}
			else{
				ans+=Max(s[0]-(s[1]-i-s[0])+1,0);
			}
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13268
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007;
const ld PI = 4.0 * atanl(1.0), PREC = .000001;
const char nl = '\n';

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define ins insert

int n, m, t, a[MXN], b[MXN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

int main() {
  fast();
  cin >> n;
  FOR(i, 0, n) {
    int x;
    cin >> x;
    a[i] = x;
    b[i] = x;
  }
  sort(a, a + n);
  if (a[0] != 1) {
    cout << -1;
    return 0;
  }
  int ans = 0;
  int j = 1;
  FOR(i, 0, n) {
    if (b[i] != j) {
      ++ans;
      continue;
    } else {
      ++j;
    }
  }

  if (ans == n) {
    cout << -1;
    return 0;
  }

  cout << ans;
  return 0;
}



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

int main() {
  ll n,k,now=0,w;
  cin >> n>>k;
  vector<ll> a(n),memo(n,0),jun;
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }
  rep(i,k){
    if(memo[now]==1){
      break;
    }
    jun.push_back(now);
    memo[now]=1;
    now=a[now];
    if (i + 1 == k){
      cout << now + 1 <<endl;
      return 0;
    }
  }
  if(now!=0){
    rep(i,jun.size()){
      if(jun[i]==now){
        w=i;
        k-=i;
        k%=(jun.size()-i);
        break;
      }
    }
    cout << jun[k+w]+1<<endl;
  }else{
    k%=jun.size();
    cout << jun[k]+1<<endl;
  }
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  string s, t;

  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());

  if (s < t) printf("Yes\n");
  else printf("No\n");
}


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

using namespace std;
#define PI 3.1415926535897932384

int a, b, h, m;

int main(){
  cin>>a>>b>>h>>m;
  long double ans = 0;
  ans = sqrt((a * a) + (b * b) - (2 * a * b* cos(abs(30*h - 5.5*m) * PI/180)));
  cout<<fixed<<setprecision(20)<<ans;

  return 0;
}


Measured memory_bytes: 4188
#include"bits/stdc++.h"
using namespace std;
int main(){
	string a[10]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
	string b;
	cin>>b;
	if(b=="SAT")cout<<1<<endl;
	if(b=="FRI")cout<<2<<endl;
	if(b=="THU")cout<<3<<endl;
	if(b=="WED")cout<<4<<endl;
	if(b=="TUE")cout<<5<<endl;
	if(b=="MON")cout<<6<<endl;
	if(b=="SUN")cout<<7<<endl;
} 

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

#define gcd(a,b)		__gcd(a,b)
#define lcm(a,b)		(a*b)/gcd(a,b)
#define ff              first
#define ss              second
#define int             long long
#define pb              emplace_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             INT64_MAX
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(x)			x.begin(),x.end()
#define digits(x)		floor(log10(x))+1
#define FIO				ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

class dsu {
private:
	int *id;
	int* sz;

	int root(int i) {
		while (i != id[i]) {
			id[i] = id[id[i]];
			i = id[i];
		}
		return i;
	}
public:
	int n;
	dsu(int v) {
		n = v;
		id = new int[n];
		sz = new int[n];

		for (int i = 0; i < n; i++) {
			id[i] = i;
			sz[i] = 0;
		}
	}

	bool find(int p , int q) {
		return root(p) == root(q);
	}

	void join(int p , int q) {
		int i = root(p);
		int j = root(q);
		if (i == j) {
			return;
		}
		if (sz[i] < sz[j]) {
			id[i] = j ;
			sz[j] += sz[i];
		}
		else {
			id[j] = i;
			sz[i] += sz[j];
		}
	}
};

class BIT {
private:
	int* FT;
	int n;
public:
	void updateBIT(int index , int val) {
		index += 1;
		while (index <= n) {
			FT[index] += val;
			index += (index & (-index));
		}
	}

	int getSum(int index) {
		index += 1;
		int sum = 0 ;
		while (index > 0) {
			sum += FT[index];
			index -= (index & (-index));
		}
		return sum;
	}


	BIT(int* a , int v) {
		n = v ;
		FT = new int[n + 1];
		for (int i = 1 ; i <= n ; i++) {
			FT[i] = 0 ;
		}
		for (int i = 0 ; i < n ; i++) {
			updateBIT(i, a[i]);
		}
	}
};

int nCr(int n , int r ) {
	int p = 1, k = 1;

	if (n - r < r ) {
		r = n - r;
	}
	if (r != 0) {
		while (r != 0) {
			p *= n ;
			k *= r ;
			int m = __gcd(p, k);
			p /= m;
			k /= m;
			n--;
			r--;
		}
	}
	else {
		p = 1;
	}
	return p ;
}

int modPower(int x, int y , int p) {
	//Used to calculate (x^y)%p
	int res = 1;
	if (y == 0) {
		return 1;
	}

	x = x % p;
	if (x == 0) {
		return 0  ;
	}

	while (y > 0) {
		if (y & 1) {
			res = (res * x) % p;
		}

		y >>= 1;
		x = (x * x) % p;
	}
	return res ;

}

int32_t main() {
	FIO;

	int n , k ;
	cin >> n >> k;

	if (n % k == 0) {
		cout << 0;
	}
	else {
		cout << 1;
	}


	return 0;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());
            int i = 500;
            int j = 5;
            if(X % i == 0)
            {
                Console.WriteLine(X / i * 1000);
            }
            else if(X > i)
            {
                int k = X - (X / i * i);
                Console.WriteLine((X / i * i) * 2 + (k / j * j));
            }
            else
            {
                Console.WriteLine(X / j * j);
            }
        }
    }
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 27336
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int H, N;
    cin >> H >> N;
    int sum=0;
    for(int i = 0; i<N; i++){
        int x;
        cin >> x;
        sum +=x;
    }
    
    if(sum >= H){
        cout<<"Yes"<<endl;
    }else if(H > sum){
        cout<< "No" <<endl;
    }
    
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(void){
    int N, K;
    char S[50];
    if(scanf("%d %d", &N, &K) == 1);
    if(scanf("%s", S) == 1);
    S[K-1] += 'a' - 'A';
    printf("%s\n", S);
    return 0;
}

Measured memory_bytes: 128
def toStr(n,base):
   convertString = "0123456789"
   if n < base:
      return convertString[n]
   else:
      return toStr(n//base,base) + convertString[n%base]

a, b = input().split()
a = int(a)
b = int(b)
c = toStr(a, b)
c = int(c)
count = 0
while(c>0):
    count=count+1
    c=c//10
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long

using namespace __gnu_pbds;
using namespace std;

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


signed main() {
	// your code goes here
	int a,b,k;
	cin>>a>>b>>k;
	if (a>=k)
    {
        a=a-k;
    }
    else
    {
        k=k-a;
        a=0;
        
        b=max(b-k,(int)0);
    }
    cout<<a<<" "<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,m,x,y;
    cin >> n >> m >> x >> y;
    ll xx[n+1];
    ll yy[m+1];
    F0R(i,n) cin >> xx[i];
    F0R(i,m) cin >> yy[i];
    xx[n] = x;
    yy[m] = y;
    sort(xx,xx+n+1);
    sort(yy,yy+m+1);
    if(xx[n] < yy[0]) cout << "No War"<<endl;
    else cout << "War"<<endl;


    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)

// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll N, K;
	cin >> N >> K;
	ll x[N];
	for (ll i = 0; i < N; ++i) cin >> x[i];
 
	// 解法
	ll ans_pm =  1000000000000000000000000;
	for (ll i = 0; i < N-K+1; ++i){
		ll tmp1 = abs(x[i]) + abs(x[i]- x[i+K-1]);
		ll tmp2 = abs(x[i+K-1]) + abs(x[i]- x[i+K-1]);
		ll tmp = min(tmp1, tmp2);
		if (tmp<ans_pm) ans_pm = tmp;
	}
	
	
	cout << ans_pm << endl;
	
}
 


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;

int main () {
    int n, d; cin >> n >> d;
    cout << ceil((double)n / (2*d+1)) << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def primeFactors(n):
    res = []
    while n%2==0:
        res.append(2)
        n //= 2
    x = 3
    while n>1 and n>=x*x:
        while n%x==0:
            res.append(x)
            n //= x
        x += 2
    if n>1:
        res.append(n)
    return res

class BiCoeff(object):
    def __init__(self, MAX, m):
        super(BiCoeff, self).__init__()
        fac = [0]*MAX
        finv = [0]*MAX
        inv = [0]*MAX

        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2,MAX):
            fac[i] = (fac[i-1]*i)%m
            inv[i] = m - (inv[m%i] * (m//i))%m
            finv[i] = (finv[i-1] * inv[i])%m

        self.MAX = MAX
        self.m = m
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def calc(self,n,k):
        if n<k:
            return 0
        if n<0 or k<0:
            return 0
        return (self.fac[n] * (self.finv[k]*self.finv[n-k])%self.m)%self.m

from collections import defaultdict
MOD = 10**9 + 7
n,m = map(int, input().split())

bicoeff = BiCoeff(n+100,MOD)

d = defaultdict(int)
for p in primeFactors(m):
    d[p] += 1

res = 1
for v in d.values():
    res *= bicoeff.calc(n-1+v,n-1)
    res %= MOD
print(res)


Measured memory_bytes: 15212
using System;

namespace abc083A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C = int.Parse(str[2]);
            int D = int.Parse(str[3]);
            if ((A + B) < (C + D))
                Console.WriteLine("Right");
            else if ((A + B) == (C + D))
                Console.WriteLine("Balanced");
            else
                Console.WriteLine("Left");
        }
    }
}


Measured memory_bytes: 13140
N=int(input())
A=list(map(int,input().split()))
mod = 10**9+7
S = [sum(A[1:])]
for a in A[1:-1]:
  S.append((S[-1]-a)%mod)
#print(S)
ans = 0
for a,s in zip(A,S):
  ans = (ans + a*s)%mod
print(ans)



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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define de(x) cout<<#x<<" = "<<(x)<<endl
#define de2(x,y) cout<<#x<<" = "<<(x) <<' '<< #y<<" = "<<y<<endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N=1e5+5;
int dp[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n;
	cin>>n;
	vector<int> a(n);
	for(auto& it:a) cin>>it;
	ms(dp,INF);
	dp[0]=0;
	for(int i=1;i<n;i++){
		dp[i]=min(dp[i],dp[i-1]+abs(a[i]-a[i-1]));
		if(i>1) dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1];
    return 0;
}



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

typedef unsigned long long ull;

ull gcd(ull, ull);

int main() {
	ull a;
	ull b;
	ull ans;

	cin >> a >> b;

	if(a < b) { swap(a, b); }

	ans = a;

	while(ans % b != 0) {
		ans += a;
	}

	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
vector<vector<int> > ed;
vector<int> dp;
vector<int> v;
vector<int> t;
int INF = (int)1 << 30;
int N;
int m;
bool f;
int dfs(int a) {
	if (!f) {
		return -2;
	}
	v[a] = 1;
	vector<int> b;
	int k;
	for (int i = 0; i < ed[a].size(); i++) {

		if (v[ed[a][i]] == 0) {
			k = dfs(ed[a][i]);
			if (k != -1) {
				b.push_back(k);
			}
		}
		if (!f) {
			return -2;
		}
	}

	if ((int)ed[a].size() % 2 == 1) {
		b.push_back(0);
	}
	sort(b.begin(), b.end());
	
	if (b.size() % 2 == 0) {
		for (int i = 0; i < (int)b.size()/2; i++) {
			if (b[i] + b[(int)b.size() - 1 - i] > m) {
				f = false;
			}
		}
		return -1;
	}
	else {
		for (int i = 0; i < (int)(b.size() - 1) / 2; i++) {
			if (b[i] + b[(int)b.size() - 2 - i] > m) {
				f = false;
			}
		}
		int res;
		if (f) {
			res = b.back();
			int l = 0;
			for (int i = (int)b.size() - 1; i >= 1; i--) {
				if (l < i) {
					if (b[i] + b[(int)b.size() - 1 - i] > m) {
						break;
					}
				}
				else {
					if (b[i] + b[(int)b.size() - i] > m) {
						break;
					}
				}
				l++;
				res = b[i - 1];
			}
		}
		if (f) {
			return res + 1;
		}
		else {
			return -1;
		}
	}


}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;

	int res = 0;
	int a, b;
	ed.resize(N);
	for (int i = 0; i < N - 1; i++) {
		cin >> a >> b;
		a--;
		b--;
		ed[a].push_back(b);
		ed[b].push_back(a);
	}
	int u = N;
	int d = 0;
	while (u - d > 1) {
		dp.clear();
		dp.resize(N, INF);
		v.clear();
		v.resize(N, 0);
		m = (u + d) / 2;
		f = true;
		dfs(0);
		if (f) {
			u = m;
		}
		else {
			d = m;
		}
	}
	res = 0;
	for (int i = 0; i < N; i++) {
		if (ed[i].size() % 2 == 1) {
			res++;
		}
	}
	cout << (res/2) <<" " <<u << endl;
}

Measured memory_bytes: 15232
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>

#ifdef LOCAL
#include "local.h"
#endif

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define clr(a, x) memset(a, x, sizeof(a))
#define sz(a) ((int)(a).size())
#define mp(a, b) make_pair(a, b)
#define ten(n) ((long long)(1e##n))

template <typename T, typename U> void upmin(T& a, const U& b) { a = min<T>(a, b); }
template <typename T, typename U> void upmax(T& a, const U& b) { a = max<T>(a, b); }
template <typename T> void uniq(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

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

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


int main()
{
    int n;
    cin >> n;
    vector<int> t(n);
    rep(i, n)
        cin >> t[i];
    sort(all(t));

    if (n == 1)
    {
        cout << t[0] << endl;
        return 0;
    }

    int res = ten(9);
    for (int p = 0; p <= (n - 2) / 2; ++p)
    {
        int c = 0;
        rep(i, p)
        {
            c += t[0] + 2 * t[1];
            c += t[n - 1 - 2 * i];
        }

        int m = n - 2 * p;
        c -= t[0];
        for (int i = 1; i < m; ++i)
            c += t[i] + t[0];

        upmin(res, c);
    }
    cout << res << endl;
}


Measured memory_bytes: 1212
#include<stdio.h>

int main(){
  int n,p,f[100001]={},cnt=0,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&p);
    if(p==i+1) f[i]=1;
  }
  if(f[0]){
    cnt++;
    f[0]=0;
    f[1]=0;
  }
  for(i=1;i<n-1;i++){
    if(f[i]){
      cnt++;
      f[i]=0;
      f[i+1]=0;
    }
  }
  if(f[n-1]){
    cnt++;
  }
  printf("%d\n",cnt);
}

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

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    char now;
    bool ok = false;
    map<string, int> a;
    for(int i = 0; i< n; i++){
        string s;
        cin >> s;
        if(a[s] == 1) ok = true;
        a[s]++;
        if(i != 0){
            if(now == s[0]){ 
                now = s[s.length()-1];
                continue;
            }
            else{
                ok = true;
            }
        }
        now = s[s.length()-1];
    }
    if(ok){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define f first
#define s second
#define MOD 998244353
 
using namespace std;


int main(){
 
	ios_base::sync_with_stdio(false);
	//cin.tie(0);
	cout<<fixed<<setprecision(12);
	//memset(dp,-1,sizeof(dp));
	string s;
	cin>>s;
	int a=0;
	for(int i=0; i<3; i++){
		if(s[i] == 'A') a++;
	}

	if(a != 0 && a != 3) cout<<"Yes";
	else cout<<"No";

	

	return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int N;
	cin >> N;
	int P;
	while (true)
	{
		P = N % 10;
		if (P == 9) {
			cout << "Yes";
			break;
		}
		N /= 10;

		if (N == 0)
		{
			cout << "No";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 300005
using namespace std;
typedef long long ll;
ll a[N],L[N],R[N],tot[N],sum[N];
int n,m,s[N],top;
int D=0;
ll f[N],h[N],ans[N];
ll calc(int x,int i){
	return h[x]+tot[i-x]+sum[x]-sum[i];
}
ll suan(int p,int j){
	return 2*(h[p]-h[j]-sum[j]+sum[p])-1LL*j*j+1LL*p*p+j-p;
}
void push(int x){
	while(top>1&&suan(s[top-1],s[top])*2*(s[top]-x)<=suan(s[top],x)*2*(s[top-1]-s[top])) top--;
	s[++top]=x;
}
void solve(int l,int r){
	if(l==r){
		f[l]=max(f[l],L[l-1]+R[r+1]+1-a[l]);
		return;
	}
	int mid=l+r+D>>1;
	top=0;
	for(int i=l-1;i<mid;i++){
		h[i]=L[i];
		push(i);
	}
	for(int i=mid+1;i<=r;i++){
		while(top>1&&calc(s[top],i)<=calc(s[top-1],i)) top--;
		h[i]=calc(s[top],i)+R[i+1];
	}
	for(int i=r-1;i>mid;i--) h[i]=max(h[i],h[i+1]);
	for(int i=mid+1;i<=r;i++) f[i]=max(f[i],h[i]);
	solve(l,mid);
	solve(mid+1,r);
}
void dp(){
	top=1;
	s[1]=0;
	for(int i=1;i<=n;i++){
		while(top>1&&calc(s[top],i)<=calc(s[top-1],i)) top--;
		h[i]=max(h[i-1],calc(s[top],i));
		push(i);
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+a[i];
		tot[i]=tot[i-1]+i;
	}
	dp();
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[n-i+1],L[i]=h[i];
	dp();
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i],R[i]=h[n-i+1];
	for(int i=1;i<=n;i++) f[i]=-1e15;
	solve(1,n);
	for(int i=1;i<=n;i++) ans[i]=f[i];
	for(int i=1;i+i<=n;i++) swap(a[i],a[n-i+1]);
	for(int i=1;i<=n;i++) swap(L[i],R[n-i+1]),sum[i]=sum[i-1]+a[i];
	memset(f,0,sizeof(f));
	D=-1;
	for(int i=1;i<=n;i++) f[i]=-1e15;
	solve(1,n);
	for(int i=1;i<=n;i++) ans[i]=max(ans[i],f[n-i+1]);
	scanf("%d",&m);
	for(int i=1;i+i<=n;i++) swap(a[i],a[n-i+1]);
	for(int i=1;i<=n;i++) swap(L[i],R[n-i+1]);
	for(int i=1,x,w;i<=m;i++){
		scanf("%d%d",&x,&w);
		ll ret=max(ans[x]+a[x]-w,L[x-1]+R[x+1]);
		printf("%lld\n",ret);
	}
	return 0;
}

Measured memory_bytes: 22528
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
const int M=2e5+10;
ll ans=0;
int n,a[M];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    ll tmp=a[0];
    for(int i=1;i<n;i++)
        ans+=(tmp-a[i]>0)?(tmp-a[i]):0,tmp=max(tmp,(ll)a[i]);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 4588
import sys
input = sys.stdin.readline

n = int(input())
a, b = list(map(int, input().split()))
n1 = n

while n1 < b:
  if (a <= n1):
    break
  else:
    n1 += n

if (n1 <= b):
  print("OK")
else:
  print("NG")


Measured memory_bytes: 9172
# -*- coding: utf-8 -*-
h,w = list(map(int,input().split()))
board = []
for _ in range(h):
    board.append(list(input()))
inf=float("inf")
dp = [[inf] * w for _ in range(h)]

if board[0][0]==".":
    dp[0][0]=0
else:
    dp[0][0]=1
#1列目を計算
for i in range(1,w):
    pre = board[0][i-1]
    if board[0][i]==".":
        dp[0][i]=dp[0][i-1]
    else:
        if pre==board[0][i]:
            dp[0][i]=dp[0][i-1]
        else:
            dp[0][i]=dp[0][i-1]+1
#2列目移行を計算
for i in range(1,h):
    for j in range(w):
        if j==0:
            if board[i][j]=="#" and board[i-1][j]==".":
                dp[i][j]=dp[i-1][j]+1
            else:
                dp[i][j]=dp[i-1][j]
        else:
            if board[i][j]=="#":
                left_add = 0
                up_add = 0
                if board[i][j-1]==".":
                    left_add=1
                if board[i-1][j]==".":
                    up_add=1
                dp[i][j]=min(dp[i-1][j]+up_add,dp[i][j-1]+left_add)
            else:
                dp[i][j]=min(dp[i-1][j],dp[i][j-1])
print(dp[-1][-1])

Measured memory_bytes: 3316
#include<iostream>

int main(){
	const int MAX_N = 100;
	int n, a[MAX_N];
	while(std::cin >> n, n){
		for(int i=0;i<n;i++){
			std::cin >> a[i];
		}

		int t = 0;
		while(true){
			bool update = false;
			for(int i=0;i<n-1;i++){
				if(a[i] > a[i+1]){
					std::swap(a[i], a[i+1]);
					t++;
					update = true;
				}
			}
			
			if(!update){
				break;
			}
		}

		std::cout << t << std::endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main(){
	int n, suit_int;
	char suit;
	bool cards[4][13] = {};
	cin >> n;

	for(int i = 0; i < n; i++){
		int number;
		cin >> suit >> number;
		switch(suit){
		case 'S': suit_int = 0; break;
		case 'H': suit_int = 1; break;
		case 'C': suit_int = 2; break;
		case 'D': suit_int = 3; break;
		}
		cards[suit_int][number-1] = true;
	}

	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 13; j++){
			if(cards[i][j] == false){
				switch(i){
				case 0: suit = 'S'; break;
				case 1: suit = 'H'; break;
				case 2: suit = 'C'; break;
				case 3: suit = 'D'; break;
				}
				cout << suit << " " << j + 1 << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>
unsigned int factorial(unsigned int n){
    if (n==0) return 1;
    else return n*factorial(n-1);
}
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ll long long
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> p(n),q(n),v(n);
    for (int i=0;i<n;i++) cin>>p[i];
    for (int i=0;i<n;i++) cin>>q[i];
    for (int i=0;i<n;i++) v[i]=i+1;
    int cnt=1;
    int a=0,b=0;

    do{
        if(v==p) a=cnt;
        if(v==q) b=cnt;
        cnt++;
    }while(next_permutation(v.begin(),v.end()));
    cout<<abs(a-b)<<endl;

    return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
const int maxn = 22;
char g[maxn][maxn];
int h,w;
int ans;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
bool vis[maxn][maxn];
int dis[maxn][maxn];
bool test(int x,int y)
{
    return x >= 1 && x <= h && y>=1 && y<=w && g[x][y] == '.';
}
int bfs(int x,int y,int tx,int ty)
{
    queue<pair<int,int>> q;
    memset(vis,0,sizeof vis);
    memset(dis,0x7f,sizeof dis);
    q.push({x,y});
    vis[x][y]=1;
    dis[x][y]=0;
    while(!q.empty())
    {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        for(int i=0;i<4;++i)
        {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(test(nx,ny) && !vis[nx][ny])
            {
                vis[nx][ny] = 1;
                dis[nx][ny] = dis[x][y]+1;
                q.push({nx,ny});
            }
        }
    }
    return dis[tx][ty];
}
int main()
{
    cin>>h>>w;
    for(int i=1;i<=h;++i)cin>>g[i]+1;
    for(int i=1;i<=h;++i)
    {
        for(int j=1;j<=w;++j)
        {
            if(g[i][j] == '#')continue;
            for(int k=1;k<=h;++k)
            {
                for(int l=1;l<=w;++l)
                {
                    if(k==i&&l==j)continue;
                    if(g[k][l] == '#')continue;
                    ans = max(ans,bfs(i,j,k,l));
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
using ll = long long;
const char E = '\n';
const int N = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, a[N], dp[N], K;
	cin >> n >> K;
	dp[1] = 0;
	for (int i=1; i<=n; i++) {
        cin >> a[i];
        if (i == 1) {
            continue;
        }
        dp[i] = 2*1e9;
        for (int j=i-1; j>=max(i-K, 1); j--)
            dp[i] = min(dp[i], dp[j] + abs(a[i]-a[j]));
	}
	cout << dp[n];
    return 0;
}


Measured memory_bytes: 1024
import sys
import itertools as it
from bisect import bisect_left, bisect_right

input = sys.stdin.readline

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AS = list(it.accumulate([0]+A))
BS = list(it.accumulate([0]+B))
max_value = 0
for i in range(N+1):
    if AS[i] > K:
        continue
    max_b = K - AS[i]
    ng = bisect_right(BS, max_b)
    ok = ng - 1
    max_value = max(i + ok, max_value)
print(max_value)

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

using namespace std;

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    string a;
    vector <string> arr;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a;
        arr.push_back(a);
    }
    cout << "AC x " << count(arr.begin(), arr.end(), "AC") << "\n";
    cout << "WA x " << count(arr.begin(), arr.end(), "WA") << "\n";
    cout << "TLE x " << count(arr.begin(), arr.end(), "TLE") << "\n";
    cout << "RE x " << count(arr.begin(), arr.end(), "RE") << "\n";
}



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

int main() {
    int n;
    char arare;
    bool yello = false;

    cin >> n;

    for(int i=0; i<n; i++){
        cin >> arare;
        if(arare == 'Y'){
            yello = true;
        }
    }
    if(yello){
        cout << "Four" << endl;
    }else{
        cout << "Three" << endl;
    }
}

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

int main(){
  int N;
  cin >> N;
  vector<tuple<string, int, int>> restaurant(N);
  for(int i=0; i<N; i++){
    string place;
    int point;
    cin >> place >> point;
    restaurant[i]=make_tuple(place, (-1)*point, i+1);
  }
  sort(restaurant.begin(), restaurant.end());
  for(int i=0; i<N; i++){
    int ans;
    tie(ignore, ignore, ans)=restaurant[i];
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
from collections import deque
n = int(input())

d = deque()
dic = {}
dic_l = {}

for i in range(n-1):
    a,b = map(int,input().split())

    if(a in dic):
        dic[a].append(b)
    else:
        dic[a] = [b]
    
    if(b in dic):
        dic[b].append(a)
    else:
        dic[b] = [a]
    
    l = max(a,b)
    s = min(a,b)
    dic_l[s,l] = i


#print(dic_l)
mx = 0
for k in dic:
    mx = max(mx,len(dic[k]))

#print("mx",mx)
col = [i+1 for i in range(mx)]
ans = [0 for _ in range(n-1)]
seen = {1}

cnt = 0
tmp = deque()
for i in dic[1]:
    if not(i in seen):
        d.append(i)
        seen.add(i)
        tmp.append(1)
        tmp.append(i)

    load_key = (1,i)
    l_num = dic_l[load_key]
    ans[l_num] = col[cnt]
    cnt += 1


while d:
    nxt = d.popleft()
    tmp_1 = tmp.popleft()
    tmp_2 = tmp.popleft()
    ng = (tmp_1,tmp_2)
    #print(ng)
    ng_col = ans[dic_l[ng]]
    cnt = 0
    for i in dic[nxt]:
        if not(i in seen):
            d.append(i)
            seen.add(i)
            tmp.append(nxt)
            tmp.append(i)
            l = max(nxt,i)
            s = min(nxt,i)
            load_key = (s,l)
            l_num = dic_l[load_key]
            while cnt+1 == ng_col:
                cnt += 1
            ans[l_num] = col[cnt]
            cnt += 1

print(mx)
for s in ans:
    print(s)


Measured memory_bytes: 108504
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<ll>> A(H, vector<ll>(W, 0)), B(H, vector<ll>(W, 0));
	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++)cin >> A[i][j];
	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++)cin >> B[i][j];

	vector<vector<bitset<40001>>> dp(H, vector<bitset<40001>>(W, bitset<40001>()));
	dp[0][0][20000 + A[0][0] - B[0][0]] = 1;
	dp[0][0][20000 - A[0][0] + B[0][0]] = 1;

	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++) {
		for (int k = 0; k < 40001; k++) {
			if (dp[i][j][k]) {
				if (i != H - 1 && k + A[i + 1][j] - B[i + 1][j] >= 0 && k + A[i + 1][j] - B[i + 1][j] <= 40000) {
					dp[i + 1][j][k + A[i + 1][j] - B[i + 1][j]] = 1;
				}
				if (j != W - 1 && k + A[i][j + 1] - B[i][j + 1] >= 0 && k + A[i][j + 1] - B[i][j + 1] <= 40000) {
					dp[i][j + 1][k + A[i][j + 1] - B[i][j + 1]] = 1;
				}
				if (i != H - 1 && k - A[i + 1][j] + B[i + 1][j] >= 0 && k - A[i + 1][j] + B[i + 1][j] <= 40000) {
					dp[i + 1][j][k - A[i + 1][j] + B[i + 1][j]] = 1;
				}
				if (j != W - 1 && k + A[i][j + 1] - B[i][j + 1] >= 0 && k + A[i][j + 1] + B[i][j + 1] <= 40000) {
					dp[i][j + 1][k - A[i][j + 1] + B[i][j + 1]] = 1;
				}
			}
		}
	}
	ll ans = INF;
	for (int i = 0; i < 40001; i++) {
		if (dp[H - 1][W - 1][i])ans = min(ans, abs(i - 20000LL));
	}
	cout << ans << endl;
}

Measured memory_bytes: 32128
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,c,d,e,f=LI()
  ans_n=-inf
  ans_pair=[0,0]

  z=100*e/(100+e)
  # print(z)
  
  for i in range(31):
    for j in range(31):
      for k in range(3001):
        for l in range(3001):
          _a=a*i*100+b*j*100
          _b=k*c+l*d

          if _a+_b>f:
            break

          if _a+_b==0:
            break

          y=100*_b/(_a+_b)

          if y<=z:
            if ans_n<=y:
              ans_n=y
              ans_pair=[_a+_b,_b]

  return str(ans_pair[0])+' '+str(ans_pair[1])

# main()
print(main())


Measured memory_bytes: 5840