akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
    int h,w;
    char s[100][100];
    int cnt[100][100]={0};

    scanf("%d %d",&h,&w);
    for(int i=0;i<h;i++){
        scanf("%s",s[i]);
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i-1][j-1]=='#'&&i>0&&j>0)cnt[i][j]++;
            if(s[i-1][j]=='#'&&i>0)cnt[i][j]++;
            if(s[i-1][j+1]=='#'&&i>0&&j<w-1)cnt[i][j]++;
            if(s[i][j-1]=='#'&&j>0)cnt[i][j]++;
            if(s[i][j+1]=='#'&&j<w-1)cnt[i][j]++;
            if(s[i+1][j-1]=='#'&&i<h-1&&j>0)cnt[i][j]++;
            if(s[i+1][j]=='#'&&i<h-1)cnt[i][j]++;
            if(s[i+1][j+1]=='#'&&i<h-1&&j<w-1)cnt[i][j]++;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#')printf("#");
            else printf("%d",cnt[i][j]);
        }
        printf("\n");
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

bool G[55][55];
bool visit[55];
ll N;

void dfs(ll n){
  visit[n] = true;
  for(ll j=0;j<=N-1;j++)
    if(G[n][j] && !visit[j]) dfs(j);
}

int main(){
  ll M,i,k;
  ll a,b;
  ll ans = 0;
  cin >> N >> M;
  for(i=0;i<=M-1;i++){
    cin >> a >> b;
    a--,b--;
    G[a][b] = G[b][a] = true;
    }
  for(i=0;i<=N-2;i++)
    for(k=i+1;k<=N-1;k++){
      if(G[i][k]){
        G[i][k] = false;
        G[k][i] = false;
        dfs(0);
        ll x = 0;
        for(ll m = 0;m<=N-1;m++)
          if(!visit[m]) x = 1;
        ans += x;
        G[i][k] = true;
        G[k][i] = true;
        for(ll m=0;m<=N-1;m++)
          visit[m] = false;
      }
    }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define LL long long

using namespace std;

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        LL a[100005];
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
        }
        sort(a+1,a+n+1);
        int flag=0;
        int j=0;
        LL ans=1;
        for(int i=n;i>=1;i--)
        {
            if(a[i]==a[i+1])
            {
                ans=ans*a[i];
                j++;
                i--;
                if(j>1)
                {
                    flag=1;
                    break;
                }
            }
        }
        if(flag)
        {
            printf("%lld\n",ans);
        }
        else
        {
            printf("0\n");
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
typedef unsigned long long ull;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
vector<vector<int> > AB,A,B;
int Aidx[5],Bidx[5];

unordered_set<ull> S;
ull VtoH(const vector<vector<int> > &v){
  const ull B = 1777771;
  ull res = 0;
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++) res = res * B + (v[i][j]+'0');
  return res;
}

vector<int> rev(vector<int> a){reverse(a.begin(),a.end());return a;}
void mirror(vector<vector<int> > &res){for(int i=0;i<5;i++) res[i] = rev(res[i]);}

vector<vector<int> > rot(const vector<vector<int> > &a){
  vector<vector<int> > res(5,vector<int>(5));
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++) res[i][j] = a[4-j][i];
  return res;
}

void insert(vector<vector<int> > &v){
  S.insert(VtoH(v));
  v = rot(v) , v = rot(v), S.insert(VtoH(v));
  mirror(v), S.insert(VtoH(v));
  v = rot(v) , v = rot(v), S.insert(VtoH(v));
}

bool canPut(int idx,int j){
  int a = 1, b = 1;
  for(int i=0;i<5;i++) if(A[i][j] == B[idx][i]) a = 0;
  for(int i=0;i<5;i++) if(A[i][j] == B[idx][4-i]) b = 0;
  return a || b;
}

bool can(){
  int used = 0;
  for(int i=0;i<5;i++){
    for(int nx=0;nx<5;nx++){
      if((used>>nx&1) || !canPut(nx,i)) continue;
      Bidx[i] = nx;
      used |= (1<<nx);
      break;
    }
  }
  return used == (1<<5)-1;
}

int solve(){
  S.clear();
  int res = 0;
  for(int i=0;i<5;i++) Aidx[i] = i;
  for(int bit=0;bit<(1<<10);bit++){
    if(__builtin_popcount(bit) != 5) continue;    
    A.clear();B.clear();
    for(int i=0;i<10;i++) (bit>>i&1)? A.push_back(AB[i]):B.push_back(AB[i]);
    vector<vector<int> > tmp = A;
    do{
      for(int a=0;a<(1<<5);a++){
        for(int i=0;i<5;i++) A[Aidx[i]] = (a>>i&1)? rev(tmp[i]):tmp[i];
        if(!can() || S.count(VtoH(A))) continue;
        insert(A);
        res++;
      }
    } while(next_permutation(Aidx,Aidx+5));
  }
  return res/2;
}

signed main(){
  while(1){
    AB.clear();
    for(int i=0;i<10;i++){
      string str;
      cin>>str;
      if(str == "END") return 0;
      vector<int> tmp(5);
      for(int j=0;j<5;j++) tmp[j] = str[j] - '0';
      AB.push_back(tmp);
    }
    cout<<solve()<<endl;
  }
  return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int a,b,k;
  cin>>a>>b>>k;
  int i=__gcd(a,b);
  while(k>0){
    if(a%i==0 && b%i==0) k--;
    i--;
  }
  cout<<i+1<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


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

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mi;

#define rep(i,a,b) for (int i = a; i < b; i++)




int main(){
	int n;
	cin >> n;
	
	long long res = 0;
	rep(i,1,n+1){
		if (i % 3 == 0 || i % 5 == 0){
			continue;
		}
		else {
			res += i;
		}
		
	}
	cout << res;








	return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pp() pop_back()
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 /*int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }*/
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int a){
	par= vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0)
      return a;
    else
      return par[a]=find(par[a]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int gcm(int a,int b){
    if(b==0)
        return a;
    return gcm(b,a%b);
}
int lcm(int a,int b){
    return a/gcm(a,b)*b;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
/*struct dfs(){

}*/
signed main(){
  double a,b,c,e=1000000,f;
  cin>>a>>b>>c;
  V<double> d(a);
  fo(i,a){
    cin>>d[i];
    d[i]=b-d[i]*0.006;
  }
  fo(i,a){
    if(abs(c-d[i])<e){
      e=abs(c-d[i]);
      f=i;
    }
  }
  cout<<f+1<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

h, w, d = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
q = int(input())
lr = [list(map(int, input().split())) for _ in range(q)]


xy = []
for h_i in range(h):
    for w_i in range(w):
        xy.append((a[h_i][w_i], h_i + 1, w_i + 1))

xy.sort()
acm = [[0] for i in range(d)]
for i in range(d, h * w):
    magic = abs(xy[i][1] - xy[i-d][1]) + abs(xy[i][2] - xy[i-d][2])
    acm[i%d].append(acm[i%d][-1] + magic)

for l, r in lr:
    idx = (l - 1) % d
    ans = acm[idx][(r - 1)//d] - acm[idx][(l - 1)//d]
    print(ans)


Measured memory_bytes: 46372
#include<bits/stdc++.h>
#define repeat(i,a,n) for(int i=a;i<=n;i++)
using namespace std;

int main(){
  int W,a,b;
  cin >>W>>a>>b;
  
  int ans;
  
  if(b>a+W) ans = b-(a+W);
  else if (b+W<a) ans = a-(b+W);
  else ans = 0;
  
  cout <<ans<< endl;
}

Measured memory_bytes: 256
import * as fs from "fs";

let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [n, t] = input[0].split(" ").map((x: string): number => +x);
const a = input[1].split(" ").map((x: string): number => +x);

let min = Infinity;
let max_diff = -Infinity;
let count = 0;

for (const v of a) {
	if (v < min) min = v;
	if (v - min > max_diff) {
		max_diff = v - min;
		count = 1;
	}
	else if (v - min === max_diff) {
		count += 1;
	}
}

console.log(count);


Measured memory_bytes: 17612
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H1 = sc.nextInt();
        int M1 = sc.nextInt();
        int H2 = sc.nextInt();
        int M2 = sc.nextInt();
        int K = sc.nextInt();
        
        int ans = 60*(H2-H1)+(M2-M1)-K;
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 35796
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  vector<int> a(5);
  REP(i,5) cin >> a[i];
  
  REP(i,5){
    if(a[i] == 0){
      cout << i+1 << endl;
      return 0;
    }
  }
    
  

}

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

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


const int INF = 1010101010;

VV(int) G;
vector<int> ans;
vector<int> rminv, rmaxv;

void dfs(int u, int par, int minv, int maxv){
	int nminv, nmaxv;
	if(ans[u] != INF){
		if(ans[u] < minv || ans[u] > maxv || (ans[u] - minv) & 1){
			throw 0;
		}
		nminv = ans[u] - 1;
		nmaxv = ans[u] + 1;
		rminv[u] = rmaxv[u] = ans[u];
	}
	else{
		nminv = minv - 1;
		nmaxv = maxv + 1;
	}
	
	for(int v : G[u]){
		if(v == par){ continue; }
		dfs(v, u, nminv, nmaxv);
		rminv[u] = max(rminv[u], rminv[v] - 1);
		rmaxv[u] = min(rmaxv[u], rmaxv[v] + 1);
	}
	
	if(rminv[u] > rmaxv[u]){ throw 1; }
}

void dfs2(int u, int par, int minv, int maxv){
	minv = max(minv, rminv[u]);
	maxv = min(maxv, rmaxv[u]);
	ans[u] = minv;
	for(int v : G[u]){
		if(v == par){ continue; }
		dfs2(v, u, minv - 1, maxv + 1);
	}
}

void mainmain() try{
	int n;
	scanf("%d", &n);
	G.resize(n);
	for(int i = 1; i < n; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
	}
	
	ans.assign(n, INF);
	int k;
	scanf("%d", &k);
	int root = -1;
	for(int i = 0; i < k; ++i){
		int v, p;
		scanf("%d%d", &v, &p);
		--v;
		ans[v] = p;
		root = v;
	}
	
	rminv.assign(n, -INF);
	rmaxv.assign(n, INF);
	dfs(root, -1, ans[root], ans[root]);
	dfs2(root, -1, ans[root], ans[root]);
	puts("Yes");
	for(int i = 0; i < n; ++i){
		printf("%d\n", ans[i]);
	}
}
catch(...){
	puts("No");
}



}
int main() try{
//	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 15360
import java.util.*;

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

      int A = 0;
      int B = 0;
      int C;

      int[][] Card = new int[3][3];
      for(int i = 0; i < 3; i++){
          for(int j = 0; j < 3; j++){
              Card[i][j] = scan.nextInt();
              }
          }
      A = Card[0][0] - Card[0][1];
      B = Card[0][0] - Card[0][2];
      C = Card[0][1] - Card[0][2];

      for(int i = 1; i < 3; i++){
          if(A != Card[i][0] - Card[i][1] || B != Card[i][0] - Card[i][2] || C != Card[i][1] - Card[i][2]){
             System.out.println("No");
             return;
             }
          }

      System.out.println("Yes");
   }
}


Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;    
typedef long long ll;
 int main(){
 	   string s,t;
 	   cin>>s;
 	   cin>>t;
 	    int l1,l2,t1,sum;
 	    l1=s.size();
 	    l2=t.size();
 	     t1=l2;
 	    for(int i=0;i<=l1-l2;i++){
 	    	    sum=0;
 	    	  for(int j=i,h=0;h<l2&&j<l1;j++,h++){
 	    	  	        if(s[j]!=t[h])  sum++;
			   }
			    t1=min(t1,sum);
		 }
		 cout<<t1<<endl;
 	      
 } 

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line

int main()
{
	int n , x ;
	cin >> n >> x ;
	vector<int> l(n);
	int ans = 0 ;
	rep(i,n) cin >>l[i];
	int sum = 0 ;
	rep(i,n){
		if(sum  <= x){
			ans ++ ;
			sum += l[i];
		}
	}
	if(sum <= x ) ans ++ ;


	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
/*
int main(void){
    long N,K;
    vector<int> A;
    cin >> N >> K;
    int a;
    for(int i =0; i < N; i++){
        cin >> a;
        A.push_back(a);
    }
    set<int> st{-1,-2,-3};
    vector<int> route;
    int index=  1;

    int offset = 0;
    int cnt = 0;
    for(int i =0; i < K; i++){
        cout << index << endl;
        auto itr = st.find(index);
        if(itr != st.end()){
            cout << "index is" << index << endl;
            offset = distance(st.begin(), itr) - 1;
            cnt = cnt - index;
            break;
        }
        route.push_back(index);
        st.insert(index);
        cnt++;
        //cout << index << endl;
        int next = A[index - 1];
        index = next;
    }
    cout << "offset is " <<offset << endl;    
    cout << "cnt is " <<cnt << endl;

 
    for(int i =0 ; i < route.size(); i++){
        cout << "*" << route[i] << endl;
    }

    if(offset > 0){
        cout << route[(offset - 1) + (K - offset)%cnt - 2 ] << endl;   
    }else{
        cout << route[cnt -1] << endl;
    }
    return 0;
}*/
int main(void){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    long sum = 0;
    if(A >= K){
        cout << K << endl;
        return 0;
    }else{
        sum += A;
    }
    K = K - A;
    if(B >= K ){
        cout << sum << endl;
        return 0;
    }
    K = K - B;
    
    sum = sum - min(C,K);
    cout << sum << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<math.h>
using namespace std;

template <class T>
class _Point{
public:
	T x;
	T y;
	_Point(){}
	_Point(T _x, T _y) :x(_x), y(_y){}
	_Point(const _Point & v) :x(v.x), y(v.y){}

	const _Point operator + (const _Point & v)
	{
		return _Point(x+v.x,y+v.y);
	}
	const _Point operator - (const _Point & v)
	{
		return _Point(x - v.x, y - v.y);
	}
	T abs() const {
		return sqrt(x*x + y*y);
	}
	_Point unit() const{
		T len = abs();
		return _Point(x / len, y / len);
	}
	T operator*(const _Point &v) const
	{
		return x * v.x + y * v.y;
	}
	const _Point operator*(const T &len) const
	{
		return _Point(len * x, len * y);
	}
};
typedef double R;
typedef _Point<R> Point;
typedef Point Vector;

int main(){
	std::istream & c_in = cin;

	Point p, p1, p2;
	c_in >> p1.x >> p1.y >> p2.x >> p2.y;
	Vector P12(p2 - p1);
	Vector e12(P12.unit());

	int q;
	c_in >> q;
	for (int i = 0; i < q; ++i)
	{
		Point p;
		c_in >> p.x >> p.y;
		Point pp = p - p1;
		R projection = pp*e12;
		Vector b(projection*(e12.x), projection*(e12.y));
		Point X(p1 + b);
		Point Q(X);
		Vector px = X - p;
		Q = Q + px;
		cout << fixed << setprecision(10) << Q.x << " " << Q.y << endl;
	}
}

Measured memory_bytes: 1296
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n+1)
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


class UnionFindLabel(UnionFind):
    def __init__(self, labels):
        assert len(labels) == len(set(labels))
        
        self.n = len(labels)
        self.parents = [-1] * self.n
        self.d = {x: i for i, x in enumerate(labels)}
        self.d_inv = {i: x for i, x in enumerate(labels)}
    
    def find_label(self, x):
        return self.d_inv[super().find(self.d[x])]
    
    def union(self, x, y):
        super().union(self.d[x], self.d[y])
    
    def size(self, x):
        return super().size(self.d[x])
    
    def same(self, x, y):
        return super().same(self.d[x], self.d[y])
    
    def members(self, x):
        root = self.find(self.d[x])
        return [self.d_inv[i] for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [self.d_inv[i] for i, x in enumerate(self.parents) if x < 0]
#decayed briges
n,m=map(int,input().split())
lists=[0 for i  in range(m)]
Alists=[]
Alists.append(n*(n-1)//2)
for i in range(m):
    #計算量O(M)
    a,b=map(int,input().split())
    lists[i]=(a,b)
A=UnionFind(n)
lists=lists[::-1]
c=n*(n-1)//2
Alist=[]
for j in lists:
    a,b=j[0],j[1]
    if A.find(a)!=A.find(b):
        c=c-A.size(a)*A.size(b)
        A.union(a,b)
    Alists.append(c)
Alists=Alists[::-1]
for k in Alists[1:]:
    print(k)


Measured memory_bytes: 23664
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    if( (y%2 == 0) && y>=2*x && y<=4*x)
    {
        cout<<"Yes"<<'\n';
    }
    else
    {
        cout<<"No"<<'\n';
    }
    
}

Measured memory_bytes: 3600
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	private static final long MOD = 1_000_000_007L;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			if ((1 == m) || (1 == n)) {
				System.out.println(1);
				return;
			}
			List<Integer> factorCounts = calcFactorCounts(m);
			int max = factorCounts.stream().mapToInt(Integer::intValue).max().getAsInt();
			long[] factorial = new long[max + n], revFactorial = new long[max + n];
			factorial[0] = 1L;
			IntStream.range(1, max + n).forEach(i -> factorial[i] = factorial[i - 1] * i % MOD);
			revFactorial[max + n - 1] = modPow(factorial[max + n - 1], MOD - 2);
			IntStream.range(0, max + n - 1).map(i -> max + n - 2 - i)
					.forEach(i -> revFactorial[i] = revFactorial[i + 1] * (i + 1) % MOD);
			long result = 1L;
			for (int b : factorCounts) {
				result = result * factorial[b + n - 1] % MOD * revFactorial[n - 1] % MOD * revFactorial[b] % MOD;
			}
			System.out.println(result);
		}
	}

	/**
	 * mの因数の数を計算する
	 * 
	 * @param m
	 * @return mの因数の数の一覧
	 */
	private static List<Integer> calcFactorCounts(int m) {
		List<Integer> result = new ArrayList<>();
		int sqrt = (int) Math.sqrt(m);
		for (int i = 2; (i <= sqrt) && (m > 1); i++) {
			if (0 == (m % i)) {
				int count = 0;
				while (0 == (m % i)) {
					m /= i;
					count++;
				}
				result.add(count);
			}
		}
		if (m > 1) {
			result.add(1);
		}
		return result;
	}

	/**
	 * n^m mod MODを計算する
	 * 
	 * @param n
	 * @param m
	 * @return n^m mod MOD
	 */
	private static long modPow(long n, long m) {
		long result = 1L;
		while (m > 0) {
			if (1 == (m & 1)) {
				result = result * n % MOD;
			}
			n = n * n % MOD;
			m >>= 1;
		}
		return result;
	}
}


Measured memory_bytes: 39044
N, Y = gets.split.map(&:to_i)

res10000  = -1
res5000   = -1
res1000   = -1
break_flg = false
(0..N).each do |a|
  (0..N - a).each do |b|
    c     = N - a - b
    total = (10000 * a) + (5000 * b) + (1000 * c)
    if total == Y
      res10000 = a
      res5000  = b
      res1000  = c
    end
    break if break_flg
  end
  break if break_flg
end

puts [res10000, res5000, res1000].join(' ')


Measured memory_bytes: 1788
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	class index implements Comparable<index> {
		String key = "";
		LinkedList<Integer> p = new LinkedList<Integer>();
		@Override
		public int compareTo(index o) {
			return this.key.compareTo(o.key);
		}
		@Override
		public String toString() {
			String ret = key+"\n";
			Integer m[] = null;
			m=p.toArray(new Integer[0]);
			Arrays.sort(m);
			String r2 = "";
			for(int a :m){
				r2 += " "+a;
			}
			ret+=r2.trim();
			return ret;
		}
		@Override
		public boolean equals(Object obj) {
			return this.key.equals(((index)obj).key);
		}
	}
	
	void run(){
		LinkedList<index> map = new LinkedList<Main.index>();
		for(;sc.hasNext();){
			String w = sc.next();
			int p = sc.nextInt();
			index o = new index();
			o.key = w;
			o.p.add(p);
			int i = map.indexOf(o);
			if(i == -1){
				map.add(o);
			}else{
				map.get(i).p.add(p);
			}
		}
		index[] s  = map.toArray(new index[0]);
		Arrays.sort(s);
		for(int  i= 0; i < s.length;i++){
			System.out.println(s[i]);
		}
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll MOD = 1000000007;
ll INF =1<<30;



int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n)cin >> a[i];
    ll tot = 0;
    rep(i,n) tot+=a[i];
    ll left = 0;
    ll left2;
    rep(i,n){
        left+=a[i];
        if(left>=tot/2) {left2 = left-a[i];break;}
    }
    ll right = tot - left;
    ll right2 = tot - left2;
    cout << min(abs(left-right),abs(left2-right2)) <<endl;
}

Measured memory_bytes: 4820
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string S,T;
  cin >> S >> T;
  int N = S.size();

  //S = S.substr(N-1) + S.substr(0,N-1);

  for(int i=0;i<N;i++){
    S = S.substr(N-1) + S.substr(0,N-1);
    if(S==T) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
m=max(a)+1
b=[0 for i in range(m)] 
for x in a:
  b[x]+=1
ans=0
if len(b)>3:
  for i in range(m-2):
    ans=max(ans,sum(b[i:i+3]))
else:
  ans=len(a)
print(ans) 

Measured memory_bytes: 14092
N=int(input())
l=list(map(int,input().split()))
S_max=max(l[0],l[1])
S_min=min(l[0],l[1])
while S_max % S_min != 0:
   S_min,S_max=S_max % S_min,S_min
for i in range(1,N-1):
   S_max=max(S_min,l[i+1])
   S_min=min(S_min,l[i+1])
   while S_max % S_min != 0:
      S_min,S_max=S_max % S_min,S_min
print(S_min)

Measured memory_bytes: 14252
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)





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

	long long min = 10000000;
	long long sum = 0;

	FOR(i, 1, n - 1) {
		if (s[i] == 'E') {
			sum++;
		}
	}
	min = sum;
	FOR(i, 1, n - 1) {
		if (s[i - 1] == 'W') {
			sum++;
		}
		if (s[i] == 'E') {
			sum--;
		}

		if (sum < min) {
			min = sum;
		}
	}
	

	ANS(min);

	
	return 0;
}



Measured memory_bytes: 900
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

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

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

    static void solve(Scanner scanner) {
        Map<Integer, List<Integer>> m = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            m.put(i, new ArrayList<>());
        }

        int N = Integer.parseInt(scanner.nextLine());
        String S = scanner.nextLine();
        for (int i = 0; i < S.length(); i++) {
            m.get(S.charAt(i) - '0').add(i);
        }

        int ans = 0;
        for (int i = 0; i < 10; i++) {
            if (m.get(i).size() == 0) {
                continue;
            }
            int first = m.get(i).get(0);
            for (int j = 0; j < 10; j++) {
                int second = Collections.binarySearch(m.get(j), first + 1);
                if (second < 0) {
                    second = -(second + 1);
                }
                if (second == m.get(j).size()) {
                    continue;
                }
                second = m.get(j).get(second);
                for (int k = 0; k < 10; k++) {
                    int third  = Collections.binarySearch(m.get(k), second + 1);
                    if (third < 0) {
                        third = -(third + 1);
                    }
                    if (third < m.get(k).size()) {
                        ans++;
                    }
                }
            }
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 26820
def solve():
    N, C = map(int, input().split())# {{{
    L = [0]*N
    R = [0]*N

    S = []
    for n in range(N):
        x, v = map(int, input().split())
        S.append((x,v))
    res = 0

    # left round
    pre_x = 0
    diff = 0
    M = 0
    for n in range(N):
        x, v = S[n]
        diff -= abs(x - pre_x)
        diff += v
        M = max(diff, M)
        res = max(res, M)
        L[n] = M
        pre_x = x

    # print(L)

    # right round
    pre_x = C
    diff = 0
    M = 0
    for n in range(1, N+1):
        x, v = S[-n]
        diff -= abs(x - pre_x)
        diff += v
        M = max(diff, M)
        res = max(res, M)
        R[-n] = M
        pre_x = x

    # print(R)
    # }}}

    # left, right
    diff = 0
    for n in range(N-1):
        res = max(res, L[n]-S[n][0] + R[n+1])

    # right, left
    diff = 0
    for n in range(1, N):
        res = max(res, R[-n]-(abs(C-S[-n][0])) + L[-n-1])

    print(res)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 25760
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<map>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;

#define m(a, b) memset(a, b, sizeof(a))
#define py(b, a) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & (-x))

const int maxn = 1e5 + 10;
const int inf = 1e9;
typedef long long LL;
typedef pair<int, int> PII;

int n[maxn];
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(a, max(b, c)) - min(a, min(b, c)) << endl;
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
from math import ceil,floor,sqrt
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    tmp = min(a[i], b[i])
    ans += tmp
    b[i] -= tmp
    tmp = min(a[i+1], b[i])
    ans += tmp
    a[i+1] -= tmp

print(ans)



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

int main()
{
  int a, b, c, i, j=0;

  cin >> a >> b >> c;

  for(i=a; i<=b; i++)
    {
      if(c%i == 0)
	j += 1;
    }

  cout << j << endl;
  
  return 0;
}

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

int N, K, A_tmp, k, changed;
vector<int> A;

int main() {
    cin >> N >> K;
    A.resize(N + 1);

    for (int i = 1; i <= N; ++i) {
        cin >> A_tmp;
        ++A[A_tmp];
    }

    sort(A.begin(), A.end());

    for (int i = 1; i <= N; ++i) {
        if (A[i] != 0) {
            ++k;
        }
    }

    for (int i = 1; i <= N; ++i) {
        if (k <= K) {
            break;
        }

        if (A[i] != 0) {
            --k;
            changed += A[i];
        }
    }

    cout << changed << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<<" (L"<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int n;
ll a, b;
vll hp;

bool enough(ll T) {
    ll cnt = 0;
    rep(i, n) {
        if(hp[i] <= b * T) continue;
        cnt += (hp[i] - b * T - 1) / (a - b) + 1;
    }
    return cnt <= T;
}

int main() {
    cin >> n >> a >> b;
    hp = vll(n);
    rep(i, n) cin >> hp[i];
    ll mx = 0;
    rep(i, n) chmax(mx, hp[i]);
    ll l = 0, r = mx + 1;
    while(l + 1 < r) {
        const ll mid = (l + r) / 2;
        if(enough(mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
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);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    ll N,A[200007],sum=0,sum2=0;
    cin >> N;
    rep(i,N){
        cin >> A[i];
        sum += A[i];
    }
    rep(i,N){
        if(sum2+A[i]>=sum-sum2-A[i]){
            cout << min(sum2+A[i]-(sum-sum2-A[i]),sum-sum2-sum2) << endl;
            return 0;
        }
        sum2 += A[i];
    }
}

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int total = (h2-h1)*60+(m2-m1)-k;
    cout << total << "\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 3808
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> h{ 1,6,36,216,1296,7776,46656,9,81,729,6561,59049 };
	Int len = h.size();

	vector<Int> dp(200001, INF);
	dp[0] = 0;

	for (Int i = 0; i < 100000; i++) {
		for (Int j = 0; j < len; j++) {
			dp[i + h[j]] = min(dp[i + h[j]], dp[i] + 1);
		}
	}
	cout << dp[N] << "\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0;i < n;i++) {
    cin >> a[i];
    sum += a[i];
  }
  double m = sqrt((double)sum);
  vector<int> divisor(1334);
  int j = 0;
  for (int i = 1; i <= m; i++) {
    if (sum % i == 0) {
      divisor[j] = i;
      j++;
      divisor[j] = sum / i;
      j++;
    }
  }
  sort(divisor.begin(), divisor.end(), greater<int>());
  vector<int> rest(n);
  for (int i = 0; i < 1334;i++) {
    int gcd = divisor[i];
    int restsum = 0;
    int opetimes = 0;
    for (int k = 0;k < n;k++) {
      rest[k] = a[k] % gcd;
      restsum += rest[k];
    }
    sort(rest.begin(), rest.end(), greater<int>());
    int l = restsum / gcd;
    for (int k = 0;k < l;k++) {
      rest[k] -= gcd;
    }
    for (int k = 0;k < n;k++) {
      if (rest[k] > 0) opetimes += rest[k];
    }
    if (opetimes <= k) {
      cout << gcd << endl;
      return 0;
    }
  }
}

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

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		long N = cin.nextLong();
		long X = cin.nextLong();
		long gcd = Gcd(N, X);
		Console.WriteLine(gcd * ((N / gcd - 1) * 3));
	}

	// 最大公約数
	long Gcd(long a, long b)
	{
		if (b == 0) return a;
		else return Gcd(b, a % b);
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 2904
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
 
constexpr bool ygreater(const pii &a, const pii &b) {
    return a.second < b.second;
}
 
int main(void)
{
    //IOS
    int n; cin >> n;
    vector<pii> r,b;
    REP(i,n) {
        int x, y;
        cin >> x >> y;
        r.push_back({x,y});
    }
    REP(i,n) {
        int x, y;
        cin >> x >> y;
        b.push_back({x,y});
    }
    sort(ALL(r));
    sort(ALL(b));
    int ans = 0;
    vector<bool> ruse(r.size());
 
    REP(i,n) {
        int maxry = -1;
        int maxryj = -1;
        REP(j,n) {
            if (b[i].first > r[j].first && b[i].second > r[j].second && !ruse[j]) {
                if (maxry < r[j].second) {
                    maxry = r[j].second;
                    maxryj = j;
                }
            }
        }
        if (maxryj != -1) {
            cerr << r[i].first << " " << r[i].second << " " <<b[maxryj].first << " " <<b[maxryj].second <<endl; 
            ruse[maxryj] = true;
            ans++;
        }
    }

    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using ll = long long;

int main(){
  int N;
  std::cin >> N;
  ll res{0};
  for(int i=1; i<=N; i++){
    if (!(i % 3 == 0 || i % 5 == 0)) res += i;
  }
  std::cout << res << std::endl;
  return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include<string>
using namespace std;
int main() {
	string str, s, st;
	int a, b, n, m;
	cin >> n >> m;
	cin >> a >> s;
	if (a > m){
		str = "kogakubu10gokan";
	}
	for (int i = 0; i < n - 1; i++){
		cin >> b >> st;
		if (a <= m && m < b){
			str = s;
		}
		a = b;
		s = st;
	}
	if (m >= b){
		str = st;
	}
	cout << str << endl;
	char c;
	cin >> c;
	return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << a + b/2 << endl;
}



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

int main()
{
    string s,s1,s2,s3,s4,s5;
    cin>>s;
    s1=s;
    reverse(s1.begin(),s1.end());
    int n=s.size(),p,r;
    p=(n-1)/2;
    r=(n+3)/2;
    if(s1==s)
    {
        s2=s.substr(0,p);
        s3=s2;
        reverse(s3.begin(),s3.end());
        if(s3==s2)
        {
            s4=s.substr(r-1,n-r+1);
            s5=s4;
            reverse(s5.begin(),s5.end());
            if(s5==s4)
                cout<<"Yes\n";
            else
                cout<<"No\n";
        }
        else
        cout<<"No\n";
    }
    else
        cout<<"No\n";
    return 0;
}


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

int main(){
    int n,m,c,count=0,sum;
    cin >> n >> m >> c;
    int b[m];
    int a[n][m];
    for(int i=0;i<m;i++){
        cin >> b[i];
    }
    for(int i=0;i<n;i++){
        sum = c;
        for(int j=0;j<m;j++){
            cin >> a[i][j];
            sum += a[i][j] * b[j];
        }
        if(sum > 0) count++;
    }
    cout << count;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
	int a, b;
	
	scanf("%d %d", &a, &b);
	
	if( a > b){
			printf("a > b\n");
	}	else if ( a == b) {
			printf("a == b\n");
	}	else	{
			printf("a < b\n");
	}
	
	return 0;
}

Measured memory_bytes: 1752
N, D = map(int, input().split())
DD = D*D

def solve():
    count = 0
    for _ in range(N):
        x, y = map(int, input().split())
        if x**2 + y**2 <= DD:
            count += 1
    return count

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 9180