akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int par[100010];
int depth[100010];
void init(int n){
  for(int i=0;i<=n;i++){
      par[i]=i;
      depth[i]=0;
  }
}
int root(int x){
  return par[x]==x?x:par[x]=root(par[x]);
}
bool same(int x,int y){
  return root(x)==root(y);
}
void unite(int x,int y){
  x=root(x);
  y=root(y);
  if(x==y)return;
  if(depth[x]<depth[y]){
      par[x]=y;
  }else{
      par[y]=x;
      if(depth[x]==depth[y])depth[x]++;
  }
}
int main(){
    ll n,m;cin>>n>>m;
    vector<int>p(n+1);
    rep(i,n)cin>>p[i+1];
    init(n);
    rep(i,m){
        int x,y;cin>>x>>y;
        unite(x,y);
    }
    ll cnt=0;
    rep(i,n){
        if(same(i+1,p[i+1]))cnt++;
    }
    cout<<cnt<<endl;
}

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

#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define fi first
#define se second

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())

#define PF(a) push_front(a)
#define PB(a) push_back(a)
#define EMPF(...) emplace_front(__VA_ARGS__)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, -1, sizeof(a))

#define PW(n) (1LL << (n))
#define NUM(x) char(x + '0')
#define ALP(x) char(x + 'a')

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNIQUE(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int N, M;
vector<int> A, B;

void no() {
  cout << 0 << endl;
  exit(0);
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  A.resize(N);
  B.resize(M);
  REP(i, N) cin >> A[i];
  REP(i, M) cin >> B[i];
  SORT(A); REV(A);
  SORT(B); REV(B);
  vector<int> AA = A, BB = B;
  UNIQUE(AA); UNIQUE(BB);
  if (SZ(AA) < N || SZ(BB) < M) no();

  int ans = 1;
  int R = 0;
  int p = 0, q = 0;
  FORR(i, N*M, 1) {
    if (p == N && q == M) {
      (ans *= R) %= MOD;
      R--;
    } else if (p == N) {
      if (B[q] == i) {
        (ans *= p) %= MOD;
        R += p-1;
        q++;
      } else {
        (ans *= R) %= MOD;
        R--;
      }
    } else if (q == M) {
      if (A[p] == i) {
        (ans *= q) %= MOD;
        R += q-1;
        p++;
      } else {
        (ans *= R) %= MOD;
        R--;
      }
    } else {
      if (A[p] == i && B[q] == i) {
        R += p+q;
        p++; q++;
      } else if (A[p] == i && B[q] < i) {
        (ans *= q) %= MOD;
        R += q-1;
        p++;
      } else if (A[p] < i && B[q] == i) {
        (ans *= p) %= MOD;
        R += p-1;
        q++;
      } else if (A[p] < i && B[q] < i) {
        (ans *= R) %= MOD;
        R--;
      }
    }
    if (R < 0) no();
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d", &tmp);v.push_back(tmp);}}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s;

  s[3] = '8';
  cout << s << endl;
  return 0;
}



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

int ara[14];

bool ck(int x,int ps)
{
    return (bool)(x & (1<<ps));
}

int main()
{

        int n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        int x=0,y=0,cnt=0,res=0,ttl=0,ans=99999999,sum=0; int flg=0,flag=1,na=0,as=1;
        vector<int>u,v,w; vector< pair<int,int> >vct; vector<string>vst;
        set<int>st,nt,tt; map<int,int>mp,nq,qr; string str,ttr,ntr;

        char s[1006];

        scanf("%d %d %d",&n,&m,&k);

        for(i=0;i<n;i++)
        {
            scanf("%s",s); str=string(s); vst.push_back(str);
        }


            d=pow(2,n-1); d--;

            for(f=0;f<=d;f++)
            {
               p=0; flg=1;  cnt=0; ara[0]=0;
               //memset(ara,0,sizeof ara);

               for(j=0;j<m;j++)
               {
                   e=0; tr=0;

                   for(i=0;i<n;i++)
                   {

                       r=vst[i][j]-'0';

                       ara[e]=ara[e]+r;

                       if(ara[e]>k){ tr=-1;  }

                       if(ck(f,i)==true){e++; if(j==0){ ara[e]=0; } }

                   }

                   if(tr==-1)
                   {
                       cnt++;

                        e=0; ara[e]=0;

                        for(i=0;i<n;i++)
                        {
                            r=vst[i][j]-'0';
                            ara[e]=ara[e]+r;

                            if(ara[e]>k){  flg=0; break;  }

                            if(ck(f,i)==true){  e++; ara[e]=0;    }

                        }

                   }


                   if(flg==0)break;

               }

               if(flg==1)
               {
                   fr=__builtin_popcount(f)+cnt;
                   if(fr<ans)ans=fr;
               }

            }

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





    return 0;
}





Measured memory_bytes: 4108
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

		List<Integer> list = new ArrayList<>();
		int min = Math.min(A, B);
		for (int i = 1; i <= min; i++) {
			if (A % i == 0 && B % i == 0) {
				list.add(i);
			}
		}
		Collections.sort(list);
		System.out.println(list.get(list.size() - K));

	}
}


Measured memory_bytes: 23252
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll N;
ll A[100010];
mint H[100010];
combination comb( 100010 );

int main() {
  std::cin >> N;

  rep( i, N )
    std::cin >> A[i];

  rep( i, N )
    H[i+1] = H[i]+mint(i+1).inv();

  mint ans = 0;

  rep( i, N ) {
    ans += (H[i+1]+H[N-i]-1)*A[i];
  }

  ans *= comb.fact[N];

  std::cout << ans.x << endl;

  return 0;
}

Measured memory_bytes: 6332
#include<bits/stdc++.h>
using namespace std;
void slove(int question_num) {
    while (question_num--) {
        int n;
        cin >> n;
        cout << n / 2 + (n % 2 ? 1 : 0);
    }
}
int main() {
    //ios::sync_with_stdio(false);
    int num = 1;
    //    read(num);
    slove(num);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    if(N%2==0) cout <<(N-2)*N/2<<"\n";
    else cout <<(N-3)*(N-1)/2+N-1<<"\n";
    rep(i,1,N/2*2+1){
        rep(j,i+1,N/2*2+1){
            if(i!=j&&i+j!=N/2*2+1){
                cout <<i<<" "<< j<<"\n";
            }
        }
    }
    if(N%2){
        rep(i,1,N){
            cout <<N<<" "<< i<<"\n";
        }
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef vector<int> ivec;
typedef vector<string> svec;

//int a[100010];
int main(){
	string str;
	cin>>str;
	if(str.find("7")!=string::npos)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
} 


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(long long i=(a);((a)<(b)?i<=(b):i>=(b));((a)<(b)?++i:--i))
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

int main(){
	int n;
	cin>>n;
	
	vi x(n),y(n),h(n);
	REP(i,n) cin>>x[i]>>y[i]>>h[i];
	
	int yy,xx,hh;
	REP(i,n){
		if(h[i]>0){
			yy=y[i], xx=x[i], hh=h[i];
			break;
		}
	}
	
	FOR(cy,0,100)FOR(cx,0,100){//全探索.
		int ans=hh+abs(xx-cx)+abs(yy-cy);//ピラミッドの高さ.
		
		REP(i,n){
			bool jud=(max(ans-abs(x[i]-cx)-abs(y[i]-cy),0LL)==h[i]);//整合がとれてるか.
			if(!jud) goto Exit;
		}
		
		cout<<cx<<' '<<cy<<' '<<ans<<endl;
		return 0;
	
	Exit:
		continue;
	}
}

Measured memory_bytes: 3548
#include <iostream>
#include <cstring>

using namespace std;

typedef long long ll;

int n, k, a[105];
ll dp[100005];
const ll mod = (ll)1e9 + 7;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(int i = 0 ; i < n ; ++i){
	cin >> a[i];
}
dp[k] = 1;
for(int i = 0 ; i < n ; ++i){
	for(int j = k - 1 ; j >= 0 ; --j){
		dp[j] = (dp[j] + dp[j + 1]) % mod;
	}
	for(int j = a[i] + 1 ; j <= k ; ++j){
		dp[j - a[i] - 1] = (dp[j - a[i] - 1] - dp[j] + mod) % mod;
	}
}
cout << dp[0] << endl;

return 0;
}



Measured memory_bytes: 1024
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            String s = in.next();
            String l = s.substring(0, (s.length() - 1)/2);
            String r = s.substring((s.length() + 3) / 2 - 1);
            if (isPalin(s) && isPalin(l) && isPalin(r)){
                out.println("Yes");
            }else{
                out.println("No");
            }
        }
        public static boolean isPalin(String s){
            int start = 0;
            int end = s.length() - 1;
            return isPalin(s, start, end);
        }

        private static boolean isPalin(String s, int start, int end) {
            if (start > end){
                return true;
            }
            return (s.charAt(start) == s.charAt(end)) && isPalin(s, start+1, end-1);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(a%b,b);
}
int main() {
ll sum=0;
ll k;
cin >> k;
for (ll i = 1; i <= k; i++)
{
 for (ll j = 1; j <= k; j++)
  { 
    for (ll b = 1; b <= k; b++)
    {
      sum+=gcd(i,gcd(j,b));
    } 
  }
}

cout << sum <<endl;


}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 3636
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N = II()
    edges = collections.defaultdict(list)
    for __ in range(N - 1):
        a, b = ILI()
        edges[a].append(b)
        edges[b].append(a)
    return N, edges


def solve(N, edges):
    queue_from_f = set()
    queue_from_s = set()
    queue_from_f.add(1)
    queue_from_s.add(N)

    n_node_f = 1
    snuke_bool = True

    visited_f = [False] * (N + 1)
    visited_s = [False] * (N + 1)
    visited_f[0], visited_f[1] = True, True
    visited_s[0], visited_s[N] = True, True

    while len(queue_from_f) != 0:
        f_next_queue = set()
        for i in queue_from_f:
            next_point = edges[i]
            for point in next_point:
                if snuke_bool and point in queue_from_s:
                    snuke_bool = False
                    visited_f[point] = True

                if visited_f[point]:
                    continue
                else:
                    f_next_queue.add(point)
                    visited_f[point] = True

        n_node_f += len(f_next_queue)
        queue_from_f = f_next_queue

        if snuke_bool:
            s_next_queue = set()
            for i in queue_from_s:
                next_point = edges[i]
                for point in next_point:
                    if point in queue_from_f:
                        visited_f[i] = True
                        snuke_bool = False
                        break

                    if visited_s[point]:
                        continue
                    else:
                        s_next_queue.add(point)
                        visited_s[point] = True

            queue_from_s = s_next_queue

    if n_node_f > N // 2:
        ans = "Fennec"
    else:
        ans = "Snuke"


    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


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

int main(){
    int n,m;
    cin >> n >> m;
    int A[m];
    int sum = 0; 
    for(int i = 0; i < m; i++){
        cin >> A[i];
        sum += A[i];
    }
    if(n - sum > -1){
        cout << n - sum << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}



Measured memory_bytes: 3620
s = list(str(input()))
info = []
cnt = 0
for i in range(len(s)):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        cnt += 1
        info.append(cnt)
    else:
        cnt = 0
        info.append(cnt)
print(max(info))

Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
int main(void){
        int a[10][10],n,d,i,j,k,l=0,p=0;
        double s[1000]={},b[10][10];
        scanf("%d%d",&n,&d);
        for(i=0;i<n;i++){
            for(j=0;j<d;j++){
                scanf("%d",&a[i][j]);
                b[i][j]=a[i][j];
            }
        }
       for(i=0;i<n-1;i++){
            for(k=i+1;k<n;k++){
                for(j=0;j<d;j++){
                    s[p]=s[p]+(pow((b[i][j]-b[k][j]),2));
                }
                s[p]=sqrt(s[p]);
                if(round(s[p])-(s[p])==0){
                    l++;
                }
                p++;
            }
       }
       printf("%d",l);
       return 0;
}


Measured memory_bytes: 2152
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N,M = map(int,readline().split())
AB = []
C = []
for _ in range(M):
    AB.append(tuple(int(x) for x in readline().split()))
    C.append(sum(1<<(int(x)-1) for  x in readline().split()))

INF = 10**18
dp = [INF] * (1<<N)
dp[0] = 0

for n in range(1<<N):
    for (a,b),c in zip(AB,C):
        m = n|c
        dp[m] = min(dp[m],dp[n]+a)

answer = dp[-1]
if answer == INF:
    answer = -1
print(answer)

Measured memory_bytes: 42604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/300 < b.F.F/300)
		return 1;
	if(a.F.F/300 > b.F.F/300)
		return 0;
	if(a.F.S < b.F.S)
		return 1;
	if(a.F.S > b.F.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (2e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 100;
const int SQRT = BUCK+9;

inline int dig_sum(int n)
{
	int ans = 0;
	while(n > 0)
	{
		ans += (n%10);
		n /= 10;
	}
	return ans;
}

void solve()
{
	int n, i, ans = INF;
	cin >> n;
	fo(i,1,n+1)
		if(n-i >= i)
			ans = min(ans, dig_sum(i)+dig_sum(n-i));
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

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

int main(void) {
    int n;
    cin >> n;
    vector<char> a(n);
    int r = 0, w = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 'R') {
            r++;
        } else if (a[i] == 'W') {
            w++;
        }
    }
    int count = 0;
    int i = 0, j = n-1;
    while (true) {
        while (i < n) {
            if (a[i] == 'W') {
                break;
            }
            i++;
        }
        while (j >= 0) {
            if (a[j] == 'R') {
                break;
            }
            j--;
        }
        if (i < j) {
            char tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
            count++;
            i++;
            j--;
        } else {
            break;
        }
    }


    cout << count  << endl;


    return 0;
}

Measured memory_bytes: 3496
N = int(input())
h = list(map(int,input().split()))
dp = [0]*(N)
dp[1] = abs(h[1]-h[0])
for i in range(2,N):
    dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[N-1])


Measured memory_bytes: 13928
n,m=map(int,input().split())
A=list(map(int,input().split()))
L=[0,2,5,5,4,5,6,3,7,6]
dp=[0]+[-1]*n
for i in range(n+1):
  for a in A:
    if i+L[a]<=n:
      dp[i+L[a]]=max(dp[i+L[a]],dp[i]*10+a)
print(dp[n])


Measured memory_bytes: 14692
import sys
S = list(input())
T = list(input())
l = len(S)
k = len(T)

if k > l:
    print("UNRESTORABLE")
else:
    for i in range(l-k,-1,-1):
        p = 0
        for j in range(k):
            if S[i+j] != T[j] and S[i+j] != "?":
                p = 1
        if p == 0:
            for st in range(i):
                if S[st] == "?":
                    print("a",end="")
                else:
                    print(S[st],end="")
            print("".join(T),end="")
            for st in range(i+k,l):
                if S[st] == "?":
                    print("a", end="")
                else:
                    print(S[st], end="")
            sys.exit()
    print("UNRESTORABLE")

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

#define endl '\n'

using namespace std;

int H,W;

char a[1001][1001];

long long dp[1001][1001];

long long ans(int i,int j){

  if(dp[i][j]!=-1){
    return dp[i][j];
  }
  
  if(i==H-1&&j==W-1){
    return 1;
  }else{
    long long ret=0;
    
    if(i+1<H&&a[i+1][j]!='#'){
      ret=(ret%1000000007 +ans(i+1,j)%1000000007)%1000000007;
    }
    if(j+1<W&&a[i][j+1]!='#'){
      ret=(ret%1000000007+ ans(i,j+1)%1000000007)%1000000007;
    }

    return dp[i][j]=ret;
    
  }

}
int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  cin>>H>>W;

  memset(dp,-1,sizeof(dp));
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>a[i][j];
    }
  }

  cout<<ans(0,0)<<endl;
  
  return 0;

}


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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();

		int r = a * b;
		int y = 2 * (a + b);
		System.out.println(r+ " " + y);
	}

}

Measured memory_bytes: 26048
#include <iostream>
#include <cstring>
using namespace std;
int main(void){

	int n, m[101];
	long long d[101][21];
	memset(d, 0, sizeof(d));

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> m[i];

	d[0][m[0]] = 1;
	for (int i = 1; i < n - 1; i++){
		for (int j = 0; j < 21; j++){
			if (d[i - 1][j] != 0){
				if (j - m[i] >= 0)
					d[i][j - m[i]] += d[i - 1][j];
				if (j + m[i] <= 20)
					d[i][j + m[i]] += d[i - 1][j];
			}
		}
	}
	cout << d[n - 2][m[n - 1]] << endl;
}

Measured memory_bytes: 1180
import sys
input = sys.stdin.readline
from decimal import Decimal 
def main():
    A, B = map(Decimal, input().split())
    ans = int(A*B)
    # A = round(A)
    # B = round(B*100)
    # ans = round(A*B) 
    # ans = ans//100
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 10076
/* 
	Author: ankrypt
*/

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

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define PI 3.141592653589793
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
unordered_map<ll, ll> mp;
set<ll> s;
string S = "";
ll cases;

int main() {
	go;
	cin >> A >> B >> C;
	ll a = A;
	ll b = B;
	ll c = C;
    cin >> N;
    ll ok = 0;
    fei(j, 0, N, 1) {
    	b = B;
    	c = C;
    	// trace1(j);
	    fei(i, 0, j, 1) {
	    	b = b * pow(2, i);
	    	c = c * pow(2, j - i);
	    	// trace3(a, b, c);
	    	if(b > a && c > b) {
	    		ok = 1;
	    	}
	    	b = B;
	    	c = C;
	    }
    }
    if(ok) {
    	cout << "Yes\n";
    }
    else {
    	cout << "No\n";
    }
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 4044
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [w,a,b] <- map (read::String->Int) . words <$> getLine
  print $ rect w a b

rect w a b | a<b = judge w a b | otherwise = judge w b a
judge w x y | y-x-w<=0 =0 | otherwise = y-x-w

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
#define  vi vector<long long int>
#define  set1 set<long long int>
#define  pb push_back
#define  map1 map<long long int,long long int>
#define  ll    long long int
#define  mp make_pair
#define  inf 1e17
#define  minf INT_MIN
#define  setbits(x) __builtin_popcountll(x)
#define  pres(x,y) fixed<<setprecision(y)<<x
#define  pair1 pair<long long int,long long int>
#define  mk(arr,n,type) type *arr=new type[n];
#define  mod 1000000007
#define  pi  3.1415926535897932384626433832
#define  ins insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//find_by_order() --> returns an iterator to the k-th largest element (counting from zero)
//order_of_key()  --> the number of items in a set that are strictly smaller than our item.
#define  w(t) long long int t;t=1;while(t--)


void solve() {

	ll n, k;
	cin >> n >> k;
	ll a[n];

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

	ll dp[k + 1];
	memset(dp, 0, sizeof(dp));

	for (ll i = 1; i <= k; i++) {
		for (ll j = 0; j < n; j++) {
			if (i - a[j] >= 0) {
				if (dp[i - a[j]] == 0) {
					dp[i] = 1;
				}
			}

		}
	}

	if (dp[k] == 1) {
		cout << "First" << "\n";
		return;
	}
	cout << "Second" << "\n";




}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("inp.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	w(t) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 4428
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
    string a,b,c;
    cin >> a >> b >> c;
    cout << a[0] << b[1] << c[2] << endl;
    
	
	return  0;
}

Measured memory_bytes: 256
/*There's a possibility*/
/*but stop sucking first*/
#define dbg(...) ; 
#define db(...) ; 
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define tst cout<<'*';
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define pf push_front
using namespace std;
 
int main()
{
    fast;
    string s,t,ans="";
    int i,j;
    cin>>s>>t;

    int dp[s.size()+1][t.size()+1];
    memset(dp,0,sizeof(dp));

    f(i,0,s.size())
        f(j,0,t.size())
            if(s[i]==t[j])
                dp[i+1][j+1]=1+dp[i][j];
            else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
    
    i=s.size(); j=t.size();
    while(i>0 and j>0)
    {
        if(dp[i][j]==dp[i-1][j])
            i--;
        else if(dp[i][j]==dp[i][j-1])
            j--;
        else if(dp[i][j]==dp[i-1][j-1]+1)
            i--,j--,ans+=s[i];
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    // db(dp,0,5,0,5);
}

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)                                                             \
  sort(x.begin(), x.end());                                                    \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y)                                                           \
  cerr << "(" << #x << ", " << #y << ") = "                                    \
       << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

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

  int a = h1 * 60 + m1;
  int b = h2 * 60 + m2;

  int ans = b - a - k;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3652
def is_shiritori(s):
    before_mozi = None
    for mozi in s.split():
        if before_mozi is None:
            before_mozi = mozi
            continue
        else:
            if mozi[0] is not before_mozi[-1]:
                print("NO")
                return False
            before_mozi = mozi
    print("YES")

ss = input()
is_shiritori(ss)

Measured memory_bytes: 2940
//Keep Working Hard
  // I__Like__Food  
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast") 
  #pragma GCC optimize("unroll-loops")
  using namespace std;
  using namespace __gnu_pbds;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int mod = 1e9 + 7;
  const int mod2 = 998244353;
  const int N = 20005;
  const int INF = 1e16;
  const double PI = acos(-1);




int32_t main()
{
       

    IOS

    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a <<  " " <<  b;

  return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n,x;
    scanf("%d %d", &n, &x);
    if(x == 1 || x == 2*n-1){
        printf("No");
        return 0;
    }
    vector<int> viAns;
    if(x == 2){
        for(int i = 3; i < n+1; i++){
            viAns.push_back(i); 
        }
        viAns.push_back(1); 
        viAns.push_back(2);
        for(int i = n + 1; i <= 2 * n - 1; i++){
            viAns.push_back(i); 
        }
        printf("Yes\n");
        for(int i = 0; i < 2 * n - 1; i++){
            printf("%d\n", viAns[i]);
        }
        return 0;
    }
    
    int i = 3;
    while(viAns.size() < n - 2){
        if(i != x && i != x + 1){
            viAns.push_back(i);            
        }
        i++;
    }
    viAns.push_back(1);
    viAns.push_back(x);
    viAns.push_back(x + 1);
    viAns.push_back(2);
    while(viAns.size() < 2 * n - 1){
        if(i != x && i != x+1){
            viAns.push_back(i);
        }
        i++;
    }    
    printf("Yes\n");
    for(int i = 0; i < 2 * n - 1; i++){
        printf("%d\n", viAns[i]);
    }
    return 0;
}


Measured memory_bytes: 3880
// https://beta.atcoder.jp/contests/abc115

#define SUBMIT

#include <bits/stdc++.h>

using namespace std;
using ui64 = uint64_t;

int main() {
#ifdef SUBMIT
    auto& in = cin;
#else
    stringstream in(R"(1 1000
)");
#endif
    ui64 n, p;
    in >> n >> p;

    if (n == 1) {
        cout << p << endl;
        exit(0);
    }

    if (64 <= n) {
        cout << 1 << endl;
        exit(0);
    }

    ui64 ans = 1;
    for (ui64 i = 1; i <= p; ++i) {
        bool break_flag = false;
        ui64 y = 1;
        for (int j = 0; j < n; ++j) {
            y *= i;
            if (p < y) {
                break_flag = true;
                break;
            }
        }

        if (break_flag) break;
        if (p % y == 0) ans = i;
    }
    cout << ans << endl;
    return 0;
}

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

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

    long long dp[m+1][n+1];
    memset(dp[0],0,sizeof(dp[0]));
    for(int i=0;i<=m;i++)dp[i][0] = 0;

    //Taking grid as input
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            char c;
            cin>>c;
            if(c=='#'){
                dp[i][j] = -1;
            }
        }
    }

    //Base case
    dp[1][1] = 1;
    //Solving!!
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i==1 && j==1)continue;
            if(dp[i][j]!=-1 )
            {
                dp[i][j] = ( max((long long)0,dp[i-1][j]) + max((long long)0,dp[i][j-1]) )%(long long)(1000000007) ;
            }
        }
    }

    cout<<dp[m][n];


}


Measured memory_bytes: 8064
#include<iostream>
#include<string>
#include <cctype>
#include <algorithm>

using namespace std;
int main()
{
	// 整数の入力
	int a, b,i,flag=1;
	cin >> a >> b;
	std::string s;
	cin >> s;
	int f = s.find('-');
	if (f != std::string::npos && f == s.rfind('-')) {
		for (i = 0; i < a; i++) {
			if (!(isdigit(s[i]))) {
				flag = 0;
			}
		}
		for (i = 0; i < b; i++) {
			if (!(isdigit(s[i+f+1]))) {
				flag = 0;
			}
		}
		if (flag) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}
	cin >> s;
	return 0;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){
  int n, k;
  cin >> n >> k;
  int ans = k;
  forn(i, n - 1){
    ans *= (k-1);
  }
  cout << ans;
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

k (k-1) (k-1)

*/

Measured memory_bytes: 3592
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public static int n;
        public static int[] flags;
        public static Map<Integer, ArrayList<Integer>> graph;
        public static void flag(int v , int f){
            flags[v] = f;
            for (int i = 0; i <graph.get(v).size() ; i++){
                if (flags[graph.get(v).get(i)] == 0) flag(graph.get(v).get(i) , f );
            }
        }
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            n = in.nextInt();
            int m = in.nextInt();
            flags = new int[n+1];
            int[]ind= new int[n+1];
            graph = new HashMap<>();
            for (int i = 1; i <=n ; i++) {
                int v = in.nextInt();
                ind[v] = i;
            }
            for (int i = 0; i < m ; i++) {
                int v = in.nextInt(),u=in.nextInt();
                if(graph.get(v)== null) graph.put(v, new ArrayList<>());
                if (graph.get(u) == null)graph.put(u , new ArrayList<>());
                graph.get(v).add(u);
                graph.get(u).add(v);
            }
            int f ;
            for (int i = 1; i <=n; i++) {
                f = i;
                if (graph.get(i) == null) continue;
                if (flags[i] == 0){
                    flag(i ,f);
                }
            }
            int ans = 0;
            for (int i = 1; i <=n ; i++) {
                if (i != ind[i]){
                    if (flags[i] ==0 || flags[ind[i]] == 0)continue;
                    if (flags[i] == flags[ind[i]]) ans++;
                }
                else ans++;
            }
            out.println(ans);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


Measured memory_bytes: 85596