akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N,M;
vector<intpair> s,c;
intvec ans;

void input() {
	cin>>N>>M;
	init(s,N); init(c,M);
	ans.resize(N);
}

void solve() {
	for(int i=0; i<N; i++) {
		int dis=INTINF;
		for(int j=0; j<M; j++) {
			int d=abs(s[i].fi-c[j].fi)+abs(s[i].se-c[j].se);
			if(d<dis) { ans[i]=j+1; dis=d; }
		}
		cout<<ans[i]<<endl;
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


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

int main(){
  int n;
  cin >> n;
  char c[n];
  rep(i,n)cin >> c[i];
  int fro=0,las=n-1;

  int ans=0;
  while(las-fro>0){
    if(c[fro]=='W' && c[las]=='R'){
      ans++;
      fro++;
      las--;
    }
    else if(c[fro]!='W')fro++;
    if(c[las]!='R')las--;
    
  }
  cout << ans << endl;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define INF (lo)(1e9 + 7)
#define MOD (lo)(1e9 + 7)
#define mp make_pair
#define pb push_back
#define pp pop_back
using namespace std;
typedef long long int lo;
lo n;

int main(){
    cin >> n;
    cout << (n*(n+1))/2;    
}




Measured memory_bytes: 256
def main():
    n = int(input())
    A, B = [None]*n, [None]*n
    for i in range(n):
        A[i], B[i] = map(int, input().split())
    A.sort()
    B.sort()
    if n%2 == 0:
        p = (A[n//2-1] + A[n//2])/2
        q = (B[n//2-1] + B[n//2])/2
        print(int((q-p+0.5)*2))
    else:
        print(B[n//2] - A[n//2] + 1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 25488
#include<bits/stdc++.h>
using namespace std;
int a[100002];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long int ans=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++){
		ans+=a[i]/2;
		a[i]%=2;
		int x=min(a[i],a[i+1]);
		ans+=x;
		a[i]-=x;
		a[i+1]-=x;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#define MAX 1300000
int N,P[MAX],F[MAX]={1,1},i,j,p=0;

int main()
{
	for(i=2;i<MAX;i++)
		if(!F[i])
		{
			P[p++]=i;
			for(j=i*2;j<MAX;j+=i)
			F[j]=1;
		}
	for(;scanf("%d",&N),N;)
	{
		for(i=0;P[i]<N;i++);
		printf("%d\n",N==P[i]?0:P[i]-P[i-1]);
	}
	return 0;
}

Measured memory_bytes: 6072
local n = io.read('*n')
io.read('*l')
local ret = true
for i = 1, n do
	local t = io.read('*n')
	local x = io.read('*n')
	local y = io.read('*n')
	if (t - (x + y)) < 0 then
		ret = false
	end
	if (t - (x + y)) % 2 > 0 then
		ret = false
	end
end
print(ret and 'Yes' or 'No')

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long int ans = 0;
  for (int i = 1; i <= n; i++){
    if (i%3 != 0 && i%5 != 0){
      ans = ans + i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3604
n=int(input())
a=list(map(int,input().split()))

l=[]
for i in range(n-1):
    if a[i+1]>a[i]:
        l.append(1)
    elif a[i+1]==a[i]:
        l.append(0)
    else:
        l.append(-1)

m=1000
k=0
for i in range(n-1):
    if l[i]==1:
        p=m//a[i]
        k+=p
        m-=p*a[i]

    if l[i]==-1:
        m+=k*a[i]
        k=0
#    print(k,m)
m+=k*a[n-1]
print(m)


Measured memory_bytes: 9200
package main

import "fmt"

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)
	arr := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &arr[i])
	}
	max := 0
	sum := 0
	for i := 0; i < N; i++ {
		if i < K {
			sum += convert(arr[i])
			continue
		}
		sum += convert(arr[i])
		sum -= convert(arr[i-K])
		if sum > max {
			max = sum
		}
	}
	if N == K {
		max = sum
	}
	var res float64
	res = float64(max) / 2
	fmt.Println(res)
}

func convert(val int) int {
	if val%2 == 0 {
		return val + 1
	}
	return val + 1
}


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

double jo(int b) {
    int i;
    double a = 1;
    for(i=0; i<b; i++) {
        a /= 2.0;
    }
    return a;
}
int compare_int(const void *a, const void *b)
{
    return *(int *)b - *(int *)a;
}

int main()
{

    int n;
    scanf("%d", &n);
    int *x = (int*)malloc(n * sizeof(int));
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &x[i]);
    }
    qsort(x, n, sizeof(int), compare_int);

    double sum = 0;
    for(i=0; i<n; i++) {
        if(i==n-1 || i==n-2) {
            sum += (double)x[i]*jo(n-1);
        }
        else {
            sum += x[i] * jo(i+1);
        }
    }
    printf("%f\n", sum);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,ans=1;
string s;
int main(){
	cin>>n>>s;
	int Left=0;
	for(int i=0;i<s.size();i++){
		int v=s[i]=='B';
		if(v==Left%2){
			//Right
			if(Left==0){
				puts("0");
				return 0;
			}
			ans=(long long)ans*Left%mod;
			Left--;
		}else{
			//Left
			Left++;
		}
	}
	if(Left!=0){
		puts("0");
		return 0;
	}
	for(int i=1;i<=n;i++){
		ans=(long long)ans*i%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,c;
    cin >> a >> b >> c;
    if(a==b) cout << c << endl;
    if(c==b) cout << a << endl;
    if(a==c) cout << b << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int h,a,b,i,I,s;
    cin>>h>>a>>b;
    i=a;
    s=0;
    while(1){
        if(i>b){break;}
        I=h%i;
        if(I==0){s++;}
        I=0;
        i++;
    }
    cout<<s<<endl;
}



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

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

    int N, D;
    cin >> N >> D;
    int X[N][D];
    rep(i, 0, N){
        rep(j, 0, D) cin >> X[i][j];
    }
    int ans = 0;
    rep(i, 0, N){
        rep(j, i+1, N){
            double res = 0.0;
            rep(k, 0, D){
                res += pow(X[i][k]-X[j][k], 2.0); 
            }
            res = sqrt(res);
            if (res == floor(res)) ans++;
        }
    }
    cout << ans << endl;
}

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

int main()
{
   int n,k;
   cin>>n>>k;
   int arr[k+5];
   for(int i=0;i<k;i++)cin>>arr[i];
   sort(arr,arr+k);
   vector<int>v;
   int sum=0;
   for(int i=1;i<k;i++)
   {
       sum+=(arr[i]-arr[i-1]);
       v.push_back(arr[i]-arr[i-1]);
   }
   sort(v.rbegin(),v.rend());
   int mid=min(n-1,k-1);
   for(int i=0;i<mid;i++)
   {
       sum-=v[i];
   }
   cout<<sum<<endl;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  A--;
  long long L = C / __gcd(C, D) * D;
  long long ans1 = B - B / C - B / D + B / L;
  long long ans2 = A - A / C - A / D + A / L;
  cout << ans1 - ans2 << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N, M = mi()
    a, b = i2(N)
    c, d = i2(M)

    for i in range(N):
        dist = 10**10
        for j in range(M):
            if dist > abs(a[i]-c[j])+abs(b[i]-d[j]):
                cp = j+1
                dist = abs(a[i]-c[j])+abs(b[i]-d[j])
        print(cp)

if __name__ == '__main__':
    main()


Measured memory_bytes: 67840
n500=int(input())
n100=int(input())
n50=int(input())
S=int(input())
a=0
for i in range(n500+1):
  for k in range(n100+1):
    for c in range(n50+1):
      s=500*i+100*k+50*c
      if s==S:
        a +=1
print(a)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1000000;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
int main(){ 
    int t; 
    ll x;
    cin >> t >> x;
    ll ans = x;
    t--;
    w(t){
        cin >> x;
        ans = lcm(ans, x);
    } 
    cout << ans << '\n';
    return 0;
}   

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int zero, one;
	zero = one = 0;
	rep(i, n) {
		if (i % 2 == 0) {
			if (s.at(i) == '0') zero++;
			else one++;
		}
		else {
			if (s.at(i) == '1') zero++;
			else one++;
		}
	}
	cout << min(zero, one) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
	string s;
	cin>>s;
	s+=',';
	int sna=-1,ans=0;
	for (int i=0;i<sz(s);i++){
		if (s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T')  ans++;
		else  sna=max(sna,ans),ans=0;
	}
	cout<<sna;
	re 0;
}

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

int main(){
	int n, a[100];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = (n - 1); i >= 0; i--){
		cout << a[i];
		if (i) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<cmath>
#include<functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void sort(int &a,int &b)
{
	if(a>b)
		swap(a,b);
}
void open(const char *s)
{
#ifndef ONLINE_JUDGE
	char str[100];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
	sprintf(str,"%s.out",s);
	freopen(str,"w",stdout);
#endif
}
int rd()
{
	int s=0,c;
	while((c=getchar())<'0'||c>'9');
	do
	{
		s=s*10+c-'0';
	}
	while((c=getchar())>='0'&&c<='9');
	return s;
}
int upmin(int &a,int b)
{
	if(b<a)
	{
		a=b;
		return 1;
	}
	return 0;
}
int upmax(int &a,int b)
{
	if(b>a)
	{
		a=b;
		return 1;
	}
	return 0;
}
double sum(int l,int r,double d,double x)
{
	return (d+(l-1)*x+d+(r-1)*x)*(r-l+1)/2;
}
double calc1(int n,double d,double x)
{
	return (sum(3,3,d,x)+sum(1,3,d,x)+(2*n-2)*d)/(2*n);
}
double calc2(int n,double d,double x)
{
	return (2*sum(4,4,d,x)+sum(2,4,d,x)+(2*n-3)*sum(2,2,d,x))/(2*n);
}
int main()
{
//	open("agc007c");
	double d,x;
	int n;
	scanf("%d%lf%lf",&n,&d,&x);
	double ans=0;
	while(n)
	{
		ans+=sum(1,2*n,d,x)/(2*n);
		if(n>=2)
		{
			double s1=calc1(n,d,x);
			double s2=calc2(n,d,x);
			x=s2-s1;
			d=s1;
		}
		n--;
	}
	printf("%.15f\n",ans);
	return 0;
}

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

int main(){
    while(1){
        int n, k;
        cin >> n >> k;
        if(n+k == 0)    break;
        int A[n+1];
        A[0] = 0;
        for(int i = 1; i <= n; i++){
            cin >> A[i];
            A[i] += A[i-1];
        }
        int ans = INT_MIN;
        for(int i = k; i <= n; i++){
            ans = max(ans, A[i] - A[i-k]);
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
  long long A,B,K;
  cin >> A >> B >> K;
  
  if (A >= K){
    cout << A-K << ' ' << B << endl;
  }
  else if (A+B >= K){
    cout << 0 << ' ' << A+B-K << endl;
  }
  else {
    cout << 0 << ' ' << 0 << endl;
  }
}



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

int func(int x1, int x2) {
    if (x1 > x2) {
        func(x2, x1);
    }

    int r;
    while (r = x2 % x1) {
        x2 = x1;
        x1 = r;
    }
    return x1;
}

int main() {

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

    int n;
    int x;
    cin >> n >> x;

    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    vector<int> w(n);
    w[0] = fabs(x - v[0]);
    for (int i = 0; i < n - 1; i++) {
        w[i + 1] = fabs(v[i] - v[i + 1]);
    }

    int ans = fabs(x - v[0]);
    for (int i = 0; i < n - 1; i++) {
        ans = min(ans, func(w[i], w[i + 1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);;
    int i,tmp;
    int pre=0;
    int n=sc.nextInt();
    int m=sc.nextInt();
    String[] a=new String[n];
    String[] b=new String[m];
    for(i=0;i<n;i++){a[i]=sc.next();}
    for(i=0;i<m;i++){b[i]=sc.next();}
    for(i=0;i<n-m+1;i++){
      for(int j=0;j<n-m+1;j++){
        if(j==0)tmp=0; else tmp=pre;
        tmp=a[i].indexOf(b[0],tmp);
        if(tmp==-1)break;
        pre=tmp;
        if(Main.check(m,tmp,i,a,b)){
          System.out.println("Yes");
          return;
        }
      }
    }
    System.out.println("No");
  }
  public static boolean check(int m,int col,int row,String[] a,String[] b){
    for(int i=1;i<m;i++){
      if(a[row+i].indexOf(b[i],col)!=col)return false;
    }
    return true;
  }
}

Measured memory_bytes: 21972
#include<stdio.h>
int main(void){
	int n,d,ans;
	scanf("%d %d",&n,&d);
	if(n%(2*d+1)==0)ans=n/(2*d+1);
	else ans=n/(2*d+1)+1;
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

typedef long long int ll;

const long long int mod = 1e9 + 7;

int main()
{
    int n, m, a;
    set <int> s;

    cin >> n >> m;

    for (int i = 0; i < m; i++)
    {
        cin >> a;
        s.insert(a);
    }

    vector <ll> dp(n+1, 0);
    dp[0] = 1;

    for (int i = 1; i <= n; i++)
    {
        if (s.find(i) == s.end())
        {
            if (i >= 1 && s.find(i-1) == s.end())
                dp[i] += dp[i-1];

            dp[i] %= mod;

            if (i >= 2 && s.find(i-2) == s.end())
                dp[i] += dp[i-2];

            dp[i] %= mod;
        }
    }

    cout << dp[n] << "\n";

    return 0;
}

Measured memory_bytes: 5760
N,X = map(int,input().split(" "))
x = map(int,input().split(" "))

A = sorted(map(lambda x:x - X,x))

while N > 1:
    a = A[0]
    b = A[1] % a
    if b == 0:
        A.pop(1)
        N -= 1
    else:
        A[1] = a
        A[0] = b

print(abs(A[0]))


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;
  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    int a; cin >> a;
    if (a == i) continue;
    cnt++;
    if (cnt >= 3) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;

  return 0;
}



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

int main() {
  ios::sync_with_stdio(false);
  int N, M, X;
  cin >> N >> M >> X;
  vector C(N, 0);
  vector A(N, vector(M, 0));
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }

  int ans = 1e9;
  for (int bit = 0; bit < 1 << N; bit++) {
    int c = 0;
    vector tmp(M, 0);
    for (int i = 0; i < N; i++) {
      if (bit >> i & 1) {
        c += C.at(i);
        for (int j = 0; j < M; j++) {
          tmp.at(j) += A.at(i).at(j);
        }
      }
    }
    int mi = *min_element(tmp.begin(), tmp.end());
    if (mi < X) continue;
    ans = min(ans, c);
  }
  cout << ((ans == 1e9) ? -1 : ans) << "\n";
}

Measured memory_bytes: 3636
A,B,M = [int(e) for e in input().split()]
a = [int(e) for e in input().split()]
b = [int(e) for e in input().split()]
x = [0]*M
y = [0]*M
c = [0]*M
for i in range(0,M):
    x[i],y[i],c[i] = [int(e) for e in input().split()]

d=[0]*M
for i in range(0,M):
    d[i] = a[x[i]-1] + b[y[i]-1] - c[i]
a.sort()
b.sort()
d.sort()
print(min(a[0]+b[0],d[0]))

Measured memory_bytes: 27256
object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    for (Array(h, m, s) <- in if h != -1) {
        val x = 7200-h*3600-m*60-s
        println("%02d:%02d:%02d".format(x/3600, x/60%60, x%60))
        println("%02d:%02d:%02d".format(x/1200, x/20%60, x*3%60))
    }
}

Measured memory_bytes: 44516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
ll a,b,c,n,k=0;
cin>>a>>b>>c>>n;
if(n<=a)
{
	k+=n;
}
else if(n>a&&n<=a+b)
{
		k+=a;
}
else
{
	k+=a;
	k-=(n-(a+b));
}
	

cout<<k<<endl;
return  0;
}





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

int main(){
  int N,count = 0;
  cin >> N;
  int arr[N];
  for(int i= 0;i < N;i++){
    cin >> arr[i];
  }

  for(int i= 0;i < N;i++){
    if(arr[i]%2 == 1 && (i+1)%2 == 1){
      count +=1;
    }
  }
  cout << count << endl;
  return 0;
}

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

using namespace std;

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

  int d, n;
  cin >> d >> n;
  if (n == 100) {
    ++n;
  }

  int ans = n;
  for (int i = 0; i < d; ++i) {
    ans *= 100;
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>


using namespace std;

int main(){
    string S;
    cin >> S;
    int cnt = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if(S.at(i)=='o') cnt++;
    }
    if (15-S.size()+cnt<8)
    {
        cout<< "NO" << endl;
    }else
    {
        cout<< "YES" << endl;
    }
    }


Measured memory_bytes: 384
#include <iostream>

#include <fstream>

using namespace std;
typedef long long ll;
static const ll Z = 1 << 21;
char s[Z], t[Z];

#define rep(i,s,n)for(ll i = s;i<n;i++)

ll strlength(const char *s) {
	ll n = 0;
	while (*s++)n++;
	return n;
}
int strcomp(const char *s, const char* t) {
	while (*s == *t) {
		if (*s == '\0') {
			return 0;
		}
		s++;
		t++;
	}

	return *s - *t;
}
int strcomp_s(const char *s, const char* t) {
	int i = 0;
	while (*s == *t) {
		if (*s == '\0') {
			return 0;
		}
		i++;
		s++;
		t++;
	}

	if (i == 0) {
		i++;
	}
	else {
		i--;
	}
	return i;
}
void strcopy(char *s, const char* t) {
	while ((*s++ = *t++) != '\0');
}
int main() {
	bool b[26] = { false };
	cin >> s;
	char ANS[26] = {};
	char  *S = &s[0];
	char last[] = "zyxwvutsrqponmlkjihgfedcba";
	if (strcomp(S, last) == 0) {
		cout << -1 << endl;
		return 0;
	}

	if (strlength(S) != 26) {
		while (*S) {
			b[*S - 'a'] = true;
			S++;
		}
		int i = 0;
		while (b[i++]);
		char f = 'a' + i - 1;

		cout << s << f << endl;
	}
	else {
		int p = 25;
		for (int p = 25; p >= 0; p--) {
			bool b[26] = { false };
			char *T = &s[0];
			rep(i, 0, p) {
				b[*T - 'a'] = true;
				T++;
			}
			T = &s[0];
			rep(i, 0, 26) {
				if (!b[i] && ('a' + i) > s[p]) {
					ll pos = p;
					T[pos++] = ('a' + i);
					T[pos] = '\0';
					cout << T << endl;
					return 0;
					//strcopy(ANS, T);
				}
			}
		}
		//	cout << ANS << endl;
	}

	return 0;
}

Measured memory_bytes: 2304
/*
May the God who gives endurance and encouragement give you the same attitude of mind toward each other that Christ Jesus had,
so that with one mind and one voice you may glorify the God and Father of our Lord Jesus Christ.
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;

const int N = (int)1e3+5;
const ll base = (ll)1e9+7;
int n, a, b, c, d;
ll P[N][N], fact[N], dp[N][N];
ll inv_fact_pw[N][N], inv_fact[N];

ll fast_pw(ll x, ll y) {
	if (y == 0) return 1;
	if (y == 1) return x;
	ll tmp = fast_pw(x, y / 2ll);
	tmp = (tmp * tmp) % base;
	if (y % 2ll) tmp = (tmp * x) % base;
	return tmp;
}

void init() {
	fact[0] = inv_fact[0] = 1;
	for (int i = 0; i <= n; ++i) {
		P[i][i] = P[i][0] = 1;
		if (i > 0) {
			fact[i] = fact[i - 1] * (ll)i % base;
			inv_fact[i] = inv_fact[i - 1] * fast_pw(i, base - 2) % base;
		}
		inv_fact_pw[i][0] = 1;
		for (int j = 1; j <= n; ++j)
			inv_fact_pw[i][j] = inv_fact_pw[i][j - 1] * fast_pw(fact[i], base - 2) % base;
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j < i; ++j)
			P[i][j] = (P[i - 1][j] + P[i - 1][j - 1]) % base;
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= i; ++j)
			P[i][j] = (P[i][j] * fact[j]) % base;
}

ll solve(int i, int j) {
	if (i == a - 1) return j == 0;
	if (dp[i][j] != -1) return dp[i][j];
	ll &ret = dp[i][j];
	ret = solve(i - 1, j);
	for (int k = c; k <= d; ++k) if (k * i <= j) {
		ll tmp = solve(i - 1, j - k*i);
		tmp = tmp * P[n - j + k * i][k * i] % base;
		tmp = tmp * inv_fact_pw[i][k] % base;
		tmp = tmp * inv_fact[k] % base;
		ret = (ret + tmp) % base;
	}
	return ret;
}

int main() {
	scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
	init();
	memset(dp, -1, sizeof(dp));
	printf("%lld", solve(b, n));
	return 0;
}


Measured memory_bytes: 24064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;



int main(){
    ll n;
    cin >> n;
    vector<pair<int,int>> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i].first >> p[i].second;
    }

    ll ans = 0;
    vector<ll> x2(n), y2(n);
    for(int i = 0; i < n; i++){
        x2[i] = p[i].first+p[i].second;
        y2[i] = p[i].first-p[i].second;
    }
    sort(x2.begin(), x2.end());
    sort(y2.begin(), y2.end());

    ans = max(x2[n-1]-x2[0], y2[n-1]-y2[0]);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7944
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define pb push_back
typedef vector<int> vi;
#define mod 1000000007
 int dp[1005][1005];
int32_t main() {
    int n,m;
    cin>>n>>m;
    char g[1005][1005];
    for(int i=0;i<=n;i++)
    g[i][0]='#';
    for(int i=0;i<=m;i++)
    g[0][i]='#';
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    cin>>g[i][j];
    dp[1][1]=1;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    {
        if(g[i][j]=='.')
        {
            dp[i][j]+=((g[i-1][j]=='.')?dp[i-1][j]:0);
            dp[i][j]%=mod;
            dp[i][j]+=((g[i][j-1]=='.')?dp[i][j-1]:0);
            dp[i][j]%=mod;
        }
    }
    cout<<dp[n][m];
    return 0;
}


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

using namespace std;

typedef long long ll;
const int maxn = (int) 2e5 + 1;

ll n, k;
ll ans = 1;
vector < pair < ll , int > > v;
int main(){
    cin >> n >> k;
    for(ll i = 2; i * i <= k; i++){
        if(k % i == 0){
            int t = 0;
            while(k % i == 0){
                t++;
                k /= i;
            }
            v.push_back({i, t});
        }
    }
    if(k > 0){
        v.push_back({k, 1});
    }
    for(pair < ll , int > i : v){
        for(int j = 1; j <= i.second / n; j++){
            ans *= i.first;
        }
    }
    cout << ans;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    string S;
    cin >> S;
    puts(S.find('7') != -1 ? "Yes" : "No");
}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
  char c;
  int n;
  int out;
  int end;
  int i;
  scanf("%d",&n);
  for(i=0;i<n+1;i++)
    {
      end=0;
      while(1)
	{
	  out=0;
	  while(1)
	    {
	      scanf("%c",&c);
	      if(out==0)
		{
		  switch(c)
		    {
		    case '1':
		      out=1;
		      break;
		    case '2':
		      out=6;
		      break;
		    case '3':
		      out=9;
		      break;
		    case '4':
		      out=12;
		      break;
		    case '5':
		      out=15;
		      break;
		    case '6':
		      out=18;
		      break;
		    case '7':
		      out=21;
		      break;
		    case '8':
		      out=25;
		      break;
		    case '9':
		      out=28;
		      break;
		    }
		}
	      else
		{
		  switch(c)
		    {
		    case '1':
		      if(out==5) out=1;
		      else out++;
		      break;
		    case '2':
		      if(out==8) out=6;
		      else out++;
		      break;
		    case '3':
		      if(out==11) out=9;
		      else out++;
		      break;
		    case '4':
		      if(out==14) out=12;
		      else out++;
		      break;
		    case '5':
		      if(out==17) out=15;
		      else out++;
		      break;
		    case '6':
		      if(out==20) out=18;
		      else out++;
		      break;
		    case '7':
		      if(out==24) out=21;
		      else out++;
		      break;
		    case '8':
		      if(out==27) out=25;
		      else out++;
		      break;
		    case '9':
		      if(out==31) out=28;
		      else out++;
		      break;
		    }
		}
	      if(c=='\n')
		{
		  end=1;
		  break;
		}
	      if(c=='0') break;
	    }
	  switch(out)
	    {
	    case 1:
	      printf(".");
	      break;
	    case 2:
	      printf(",");
	      break;
	    case 3:
	      printf("!");
	      break;
	    case 4:
	      printf("?");
	      break;
	    case 5:
	      printf(" ");
	      break;
	    case 6:
	      printf("a");
	      break;
	    case 7:
	      printf("b");
	      break;
	    case 8:
	      printf("c");
	      break;
	    case 9:
	      printf("d");
	      break;
	    case 10:
	      printf("e");
	      break;
	    case 11:
	      printf("f");
	      break;
	    case 12:
	      printf("g");
	      break;
	    case 13:
	      printf("h");
	      break;
	    case 14:
	      printf("i");
	      break;
	    case 15:
	      printf("j");
	      break;
	    case 16:
	      printf("k");
	      break;
	    case 17:
	      printf("l");
	      break;
	    case 18:
	      printf("m");
	      break;
	    case 19:
	      printf("n");
	      break;
	    case 20:
	      printf("o");
	      break;
	    case 21:
	      printf("p");
	      break;
	    case 22:
	      printf("q");
	      break;
	    case 23:
	      printf("r");
	      break;
	    case 24:
	      printf("s");
	      break;
	    case 25:
	      printf("t");
	      break;
	    case 26:
	      printf("u");
	      break;
	    case 27:
	      printf("v");
	      break;
	    case 28:
	      printf("w");
	      break;
	    case 29:
	      printf("x");
	      break;
	    case 30:
	      printf("y");
	      break;
	    case 31:
	      printf("z");
	      break;
	    }
	  if(end) break;
	}
      if(i!=0) printf("\n");	 
    }
  return 0;
}

Measured memory_bytes: 2608
using System;
using System.Linq;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int M = int.Parse(input[1]);
    
    int[] arr = Enumerable.Repeat(0, N).ToArray();
    for (int i = 0; i < M; i++) {
      input = Console.ReadLine().Split(' ');
      arr[int.Parse(input[0]) - 1]++;
      arr[int.Parse(input[1]) - 1]++;
    }
    for (int i = 0; i < N; i++) {
      Console.WriteLine(arr[i]);
    }
  }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int N = s.size();
  int L = -1;
  int R = -1;
  for (int i = 0; i < N - 1; i++){
    if (s[i] == s[i + 1]){
      L = i + 1;
      R = i + 2;
    }
  }
  for (int i = 0; i < N - 2; i++){
    if (s[i] == s[i + 2]){
      L = i + 1;
      R = i + 3;
    }
  }
  cout << L << ' ' << R << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
typedef pair<int, int> PI;
const ll MOD = 1000000007;

int X, Y, A, B, C;
int p, q, r;
vector<PI> V;

int main(void){
    cin >> X >> Y >> A >> B >> C;
    REP(i, A){
        cin >> p;
        V.emplace_back(-p, 0);
    }
    REP(i, B){
        cin >> q;
        V.emplace_back(-q, 1);
    }
    REP(i, C){
        cin >> r;
        V.emplace_back(-r, 2);
    }
    sort(V.begin(), V.end());
    int a = 0, b = 0, count = 0;
    ll res = 0;
    for(int i = 0;i < X+Y;i++){
        PI t = V[count++];
        if(t.second == 0){
            if(a++ >= X){
                i--; continue;
            }
        }else if(t.second == 1){
            if(b++ >= Y){
                i--; continue;
            }
        }
        res += -t.first;
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 6384
import java.util.Scanner;
class Main{
    int h,m,s;
    public void kozueteacher() {
    Scanner sc = new Scanner(System.in);
        int y = sc.nextInt();
        h = y /3600;
        m = ( y - h * 3600) / 60;
        s = y - (h * 3600) - (m * 60);
            System.out.println(h + ":" + m + ":" + s);
    }
    public static void main(String[] args) {
        new Main().kozueteacher();
    }
} 

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/*************************************************************************************/
void file(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
/*************************************************************************************/

const ll nax=2e5+1,mod=1e9+7;

ll memo[nax][13];
string s;
int n;


ll go(int pos,int rem){
    if(pos==n){
        ll ret;
        rem == 5 ? ret = 1: ret = 0;
        return ret;
    }
    if(memo[pos][rem]!=-1) return memo[pos][rem];
    ll ans = 0;
    if(s[pos]=='?'){
        fore(i,0,9) ans+=go(pos+1,(rem*10+i)%13), ans%=mod;
    }
    else{
        ans = go(pos+1,(rem*10+s[pos]-'0')%13);
    }
    return memo[pos][rem] = ans;
}


int main(){

    sync
  //  file();
    cin>>s;
    memset(memo,-1,sizeof(memo));
    n = s.size();
    cout<<go(0,0);

  return 0;
}

Measured memory_bytes: 28624
def main
  _, m = $stdin.readline.split(" ").map(&:to_i)
  lines = $stdin.read.split("\n").map{|l| l.split(" ").map(&:to_i)}.sort_by{|x| x[0]}
  min = 0
  lines.each do |line|
    line[1].times do
      min += line[0]
      m -= 1
      if m == 0
        puts min
        return
      end
    end
  end
end

main


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

int main(){
  int i, j, l, m, n, start, end;
  int atta = 0;
  cin >> start >> end;
  
  for( i = start; i <= end; i++ ){
    l = to_string(i).size();
    m = i;
    n = 0;

    for( j = 0; j < l; j++ ){
        n += (m%10)*pow(10,l-j-1);
		m /= 10;
    }
    
    if( i == n ){
      atta += 1;
//      cout << i << ":" << l << " " << n << endl;
    }
  }
  cout << atta << endl;

  return 0;
}

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

#define ris   return *this
#define tmplt template<class T
#define dbgo  debug& operator<<
tmplt > struct rge { T b, e; };
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
~debug(){cerr<<endl;}
tmplt > dbgo(T x){cerr<<boolalpha<<x;ris;}
tmplt, class C > dbgo(pair<T, C> x){ris<<"("<<x.first<<", "<<x.second<<")";}
tmplt > dbgo(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}ris<<"]";}
tmplt > dbgo(vector<T> x){ris<<range(x.begin(),x.end());}
#else
tmplt > dbgo(const T&){ris;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}


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

    int n;
    cin >> n;
    vector<int> a(n);
    forn(i, n) {
        cin >> a[i];
    }
    vector<int> ps(n+1), px(n+1);
    forn(i, n) {
        ps[i+1] = ps[i] + a[i];
        px[i+1] = px[i] ^ a[i];
    }
    
    auto get_sum = [&](int i, int j) {
        return ps[++j] - ps[i];
    };
    auto get_xor = [&](int i, int j) {
        return px[++j] ^ px[i];
    };
    ll ans = 0;
    forn(i, n) {
        int lo = i, hi = n-1;
        while(lo < hi) {
            int mid = (lo+hi+1)/2;
            if(get_xor(i, mid)==get_sum(i, mid)) {
                lo = mid;
            } else {
                hi = mid-1;
            }
        }
        ans += lo-i+1;
    }
    
    cout << ans << endl;
}













// Don't worry, you're getting better

// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)

// Author: blondie


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

int main(){
    int H,W,h,w;
    scanf("%d %d",&H,&W);
    scanf("%d %d",&h,&w);
    printf("%d",H*W-w*H-h*W+h*w);
    return 0;
}

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

int main(){
  string str,word[1024];
  string s[] = {",","."};
  getline(cin,str);
  stringstream ss(str);
  int cou = 0;
  while(!ss.eof()){
    ss >> word[cou];
    cou++;
  }
  bool flg = false;
  for(int i=0;i<cou;i++){
    for(int j=0;j<2;j++){
      int loc = word[i].find(s[j],0);
      if(loc != string::npos) word[i].erase(loc);
    }
    int len = word[i].size();
    if(len >= 3 && len <= 6){
      if(flg) cout << " ";
      flg = true;
      cout << word[i];
    }
  }
  cout << endl;
}

Measured memory_bytes: 1212
#!/usr/bin/env python3
import sys
import copy


def solve(N: int, A: "List[int]"):
    B = copy.deepcopy(A)
    B.sort(reverse = True)
    B1 = B[0]
    B2 = B[1]

    for i in A:
        if i == B1:
            print(B2)
        else:
            print(B1)
    
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14572
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
long long n,ans=LONG_LONG_MAX;
int main()
{
	cin>>n;
	for(long long i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			ans=min(ans,i+n/i-2);
		}	
	}
	cout<<ans;
}

Measured memory_bytes: 256
import java.io.*;
 
import java.text.*;
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		char b = sc.next().charAt(0);
		String msg = "";

		if (b == 'A')  {
			msg = "T";
		} else if (b == 'T') {
			msg = "A";
		} else if (b == 'C') {
			msg = "G";
		} else {
			msg = "C";
		}
		System.out.println(msg);
	}
}

Measured memory_bytes: 21716
def solve():
    H,W=map(int,input().split())
    s=[]
    s.append(['.'] * (W+2))
    for y in range(H):
        s.append(['.'] + list(input()) + ['.'])
    s.append(['.'] * (W+2))
    for y in range(1,H):
        for x in range(1,W):
            if s[y][x] == '#':
                if s[y-1][x] == '.' and \
                   s[y+1][x] == '.' and \
                   s[y][x-1] == '.' and \
                   s[y][x+1] == '.':
                   return 'No'
    return 'Yes'

print(solve())


Measured memory_bytes: 38896
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, k; cin >> n >> k;
	vi a(n); rep(i, n) cin >> a[i];
	vector<vi> can(n + 1, vi(k + 1));
	vector<vi> can2 = can;
	rep(it, 2){
		vector<vi> &dp = it ? can2 : can;
		dp[0][0] = 1;
		rep(i, n) rep(j, k + 1) if(dp[i][j]){
			int nj = min(j + a[i], k);
			dp[i + 1][j] = 1;
			dp[i + 1][nj] = 1;
		}
		rep(i, n + 1) rep(j, k) dp[i][j + 1] += dp[i][j];
		reverse(all(a));
	}
	int ans = 0;
	rep(i, n){
		bool ok = 0;
		/*
		dbg(can[i]);
		dbg(can2[n - i - 1]);
		*/
		rep(j, k) if(can[i][j] > (j ? can[i][j - 1] : 0)){
			const vi &c = can2[n - i - 1];
			
			int hi = k - 1 - j, lo = max(0, k - a[i] - j);
			if(c[hi] > (lo ? c[lo - 1] : 0)){
				ok = 1;
				break;
			}
		}
		if(!ok) ans++;
		
		//dbg(i, ok);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 195968
#include<stdio.h>

int main(void){

    char s[3],t[3];

    scanf("%s",s);
    scanf("%s",t);

    int i;
    int c=0;

    for(i=0;i<3;i++){
        if(s[i] == t[i]){
            c++;
        }
    }

    printf("%d",c);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>//brute force forever
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define pob						pop_back
#define pii						pair<int,int>
#define pll						pair<ll,ll>
#define FOR(i,n)                for(int i=0;i<n;i++)
#define FORE(i,a,b)             for(int i=a;i<=b;i++)
#define RFOR(i,n)               for(int i=n;i>0;i--)
#define RFORE(i,a,b)            for(int i=a;i>=b;i--)
#define mp                      make_pair
#define all(x)                  x.begin(),x.end()
#define rall(x)                 x.rbegin(),x.rend()
#define ff                      first
#define ss                      second
#define endl                    "\n"
#define MOD                     998244353
#define MAXN					300005
#define INFI					1000000000
#define ub(x)					upper_bound(x)
#define lb(x)					lower_bound(x)

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

void printarr(int arr[],int start,int size){
	for(int i=start;i<size;i++){
		cout<<arr[i]<<" ";
	}
}

void debug(int x){
	cout<<x<<endl;
}

vector<vector<int>> adj;
vector<bool> v;

void addBidirectionaledge(int u,int v){
    adj[u].pb(v);
    adj[v].pb(u);
}

void addDirectionaledge(int u,int v){
    adj[u].pb(v);
}

void DFS(int u){
    v[u]=true;
    for(auto itr: adj[u]){
        if(!v[itr]){
            v[itr]=true;
            DFS(itr);
        }
    }
} 



int main(){
    FIO();
    int t;
    t=1;
    //cin>>t;
    while(t--){
		int n,x,y,m;
        cin>>n>>m;
        adj.assign(n+1,vector<int>());
        v.assign(n+1,false);
        for(int i=0;i<m;i++){
            cin>>x>>y;
            x;y;
            addBidirectionaledge(x,y);
        }
		int cnt=0;
        for(int i=1;i<=n;i++){
			if(!v[i]){
				cnt++;
				DFS(i);
			}
		}
		cnt--;
		cout<<cnt<<endl;
    }
 	return 0;
}


Measured memory_bytes: 9244
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void) {
	ll N, h, n, bb, bs;

	cin >> N;

	for (h = 1; h <= 3500; h++) {
		for (n = h; n <= 3500; n++) {
			bs = N * h * n;
			bb = 4 * h * n - (h + n) * N;
			if (bb <= 0) continue;
			if (bs % bb == 0) {
				printf("%lld %lld %lld\n", h, n, bs / bb);
				return 0;
			}
		}
	}

	return 0;
}

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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//chcp 65001

signed main()
{
	int n, k; cin >> n >>k;
	int ans = k*pow(k-1, n-1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512