akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll 			long long
#define vl 			vector<ll>
#define vi 			vector<int>
#define pi 			pair<int,int>
#define pl 			pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb 			push_back
#define mp 			make_pair
#define F 			first
#define S 			second
#define trace(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 fast_io 	std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

using namespace std;


int main()
{
	fast_io;
	string s;
	cin>>s;
	int ans;
	for(int i=0;i<3;i++)if(s[i]=='1')ans++;
		cout<<ans;
	return 0;
}

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

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

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

const long long INF = 1LL << 60;

int main() {
    int N; cin >> N;
    long long h[100010];
    for (int i = 0; i < N; i++) cin >> h[i];

    long long dp[100010];
    for (int i = 0; i < N; i++) dp[i] = INF;
    dp[0] = 0;

    for (int i = 1; i < N; i++) {
        // dp[i] に ノードi-1からのコストを入れておく
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        // 上のdp[i]と、ノードi-2からのコストを比較
        if (i > 1) {
            chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
        }
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{  	
	int n;
	cin>>n;
	for(int i=1;i<=10;i++){
		if(i*1000-n>=0){
			cout<<i*1000-n<<endl;
			break;
		}
	}
	return 0;	
}


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

int main() {
  string s,t;
  cin >> s >> t;
  int ans = 0;
  if (s[0]==t[0]) ans++;
  if (s[1]==t[1]) ans++;
  if (s[2]==t[2]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3640
def s(num):
  val=0
  while num>0:
    val+=num%10
    num=num//10
  return val
n,a,b=[int(s) for s in input().split()]
ans=0
for i in range(1,n+1):
  x=s(i)
  if a<=x and x<=b:
    ans+=i
print(ans)

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

	int n,k;
	char ab;

	cin>>n;
	while(1){
cin>>ab;
		if(ab=='='){
			break;
		}
		if(ab=='+'){
			cin>>k;
			n+=k;
		}
		if(ab=='-'){
			cin>>k;
			n-=k;
		}
		if(ab=='*'){
			cin>>k;
			n*=k;
		}
		if(ab=='/'){
			cin>>k;
			n/=k;
		}
	}
	cout<<n<<endl;
	return 0;
}


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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    bool flag = true;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int m = A[i];
        int mj = i;
        for (int j = i+1; j < N; j++) {
            if (m > A[j]) {
                m = min(m, A[j]);
                mj = j;
            }
        }
        if (i != mj) {
            swap(A[i], A[mj]);
            cnt++;
        }
    }
    cout << A[0];
    for (int i = 1; i < N; i++) {
        cout << ' ' << A[i];
    }
    cout << endl;

    cout << cnt << endl;

}



Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cmath>
using namespace std;

int main()
{
	int n;
	int d[100000 + 1];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}

	sort(d, d + n);
	int a = d[n / 2 - 1];
	int b = d[n / 2];
	cout << b - a << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#define INF 100000000
using namespace std;

void dfs(int x,int y,int muki,int count);
int W,H;
int mas[20][20];
int gx,gy;
int sx,sy;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int ata;
int cnt;
int main(){
  while(1){
    cnt=INF;
    cin>>W>>H;
    if(W==0 && H==0) break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin>>mas[i][j];
	if(mas[i][j]==2){
	  sx=j;
	  sy=i;
	  mas[i][j]=0;
	}
	if(mas[i][j]==3){
	  mas[i][j]=0;
	  gx=j;
	  gy=i;
	}
      }
    }
    ata=0;
    dfs(sx,sy,-1,0);
    if(cnt==INF){
      cout<<-1<<endl;
    }else{
      cout<<cnt<<endl;
    }
  }
}

void dfs(int x,int y,int muki,int count){
  if(count>10){
    return;
  }
  if(x==gx && y==gy){
    //cout<<count<<endl;
    if(cnt>count){
      cnt=count;
    }
    return;
  }
  if(ata==0){
    for(int i=0;i<4;i++){
      int nextx=x+dx[i];
      int nexty=y+dy[i];
      if(0<=nextx && nextx<W && 0<=nexty && nexty<H && mas[nexty][nextx]==0){
	//cout<<x<<' '<<y<<endl;
	ata=1;
	dfs(nextx,nexty,i,count+1);
      }
    }
    
  }else{
    int nextx=x+dx[muki];
    int nexty=y+dy[muki];
    if(0<=nextx && nextx<W && 0<=nexty && nexty<H){
      if(mas[nexty][nextx]==1){
	mas[nexty][nextx]=0;
	ata=0;
	dfs(x,y,-1,count);
	mas[nexty][nextx]=1;
      }else if(mas[nexty][nextx]==0){
	dfs(nextx,nexty,muki,count);
      }
    }
  }
  return;
}
  

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i); //√n＊√nではない時
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main() {
 ll n,m;
  cin>>n>>m;
  //m約数求める
  ll ans=0;
  vll a=divisor(m);
  for(auto c:a){
    if(c*n<=m)
    chmax(ans,c);
  }
  cout<<ans<<endl;
}

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    string s;
    cin1(s);
    REP(i,0,s.length()) {
        if (i % 2 != 0) {
            if (s[i] == 'R') {
                cout << "No" << endl;
                return 0;
            }

        }
        else {
            if (s[i] == 'L') {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
s = input()
items = ['A', 'T', 'G', 'C']
length = 0
maxLen = 0

for i in s:
    if i in items:
        length += 1
    else:
        if length >= maxLen:
            maxLen = length

        length = 0


    if length >= maxLen:
        maxLen = length

print(maxLen)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int n; scanf("%d", &n);
	FOR(i, 1, 10){
		FOR(j, 1, 10){
			if(i*j==n){
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
}


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


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 998244353
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

struct Segtree{
    int N;
    vector<int> data;
    const int DEFAULT = 0;

    Segtree(int n){
        N=1;
        while(N <= n) N*=2;
        data.resize(2*N-1);
        for(int i=0;i<2*N-1;i++){
            data[i] = DEFAULT; 
            //maxの時は-1とか-INFとか、sumなら0
        }
    }

    void update(int k, int a){
        k+=N-1;//kは0-indexed
        data[k] = a;

        while(k > 0){
            k = (k-1)/2;
            data[k] = (data[2*k+1] + data[2*k+2]) %MOD; 
            //min,max,sumなどで可変
        }
    }

    int query(int a,int b){return query(a, b, 0, 0, N);}
    
    int query(int a, int b, int k, int l, int r){
        // [l,r)より、r未満になるように値を入力する必要がある
        if(r <= a || b <= l) return DEFAULT; //初期化値
        if(a <= l && r <= b) return data[k];
        int vl = query(a, b, 2*k+1, l, (l+r)/2);
        int vr = query(a, b, 2*k+2, (l+r)/2, r);
        return (vl + vr) % MOD;//minじゃなくても
    }

    int a(int k){
        return data[N+k-1]; //kは0-indexed
    }
};

int main(){
    ll N,K;
    cin>>N>>K;
    Segtree Seg(N+1);
    
    v L(K),R(K);
    rep(i,0,K){
        cin>>L[i]>>R[i];
    }

    Seg.update(0,1);
    Seg.update(1,-1);
    //cout<<Seg.query(0,1);
    rep(i,0,N-1){
        ll now = Seg.query(0,i+1);
        rep(j,0,K){
            if(i + L[j] > N-1)continue;
            Seg.update(i+L[j], (Seg.a(i+L[j]) + now)%MOD);
            
            if(i + R[j] + 1 > N-1)continue;
            Seg.update(i+R[j] + 1, (Seg.a(i+R[j] + 1) - now)%MOD);

        }
        //rep(i,0,N)cout<<Seg.a(i);
        //cout<<endl;
    }

    ll ans = Seg.query(0,N);
    if(ans < 0)cout<<(MOD-(-ans%MOD))%MOD;
    else cout<<ans%MOD;
    return 0;
}

Measured memory_bytes: 5356
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100;
int n,m,op_x,op_y,ans;
char S[maxn+8];
int f[maxn+8][maxn+8][maxn+8][maxn+8],v[maxn+8][maxn+8][2];

int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

int main()
{
    n=read(),m=read();
    for (int i=1;i<=n;i++)
	{
	    scanf("%s",S+1);
	    for (int j=1;j<=m;j++)
		{
		    v[i][j][0]=v[i][j][1]=S[j]=='o';
		    v[i][j][0]+=v[i][j-1][0];
		    v[i][j][1]+=v[i-1][j][1];
		    if (S[j]=='E') op_x=i,op_y=j;
		}
	}
    for (int l=0;l<=op_y-1;l++)
	for (int r=0;r<=m-op_y;r++)
	    for (int u=0;u<=op_x-1;u++)
		for (int d=0;d<=n-op_x;d++)
		    {
			ans=max(ans,f[l][r][u][d]);
			if (l+r<op_y-1) f[l+1][r][u][d]=max(f[l+1][r][u][d],f[l][r][u][d]+v[min(n-u,op_x+d)][op_y-l-1][1]-v[max(d,op_x-u-1)][op_y-l-1][1]);
			if (l+r<m-op_y) f[l][r+1][u][d]=max(f[l][r+1][u][d],f[l][r][u][d]+v[min(n-u,op_x+d)][op_y+r+1][1]-v[max(d,op_x-u-1)][op_y+r+1][1]);
			if (u+d<op_x-1) f[l][r][u+1][d]=max(f[l][r][u+1][d],f[l][r][u][d]+v[op_x-u-1][min(m-l,op_y+r)][0]-v[op_x-u-1][max(r,op_y-l-1)][0]);
			if (u+d<n-op_x) f[l][r][u][d+1]=max(f[l][r][u][d+1],f[l][r][u][d]+v[op_x+d+1][min(m-l,op_y+r)][0]-v[op_x+d+1][max(r,op_y-l-1)][0]);
		    }
    printf("%d\n",ans);
    return 0;
}
    


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

int main() {
  ll n,m=0;
  cin>>n>>m;
  vector<int> height(n);
  vector<pair<int,int>> ab(m);
  vector<bool> gorb(n);
  rep(i,n){
    cin>>height.at(i);
  }
  rep(i,m){
    cin>>ab.at(i).first>>ab.at(i).second;
  }
  rep(i,n){
    gorb.at(i)=true;
  }
    rep(j,m){
      if(height.at(ab.at(j).first-1)>height.at(ab.at(j).second-1)){
        gorb.at(ab.at(j).second-1)=false;
      }else if(height.at(ab.at(j).first-1)==height.at(ab.at(j).second-1)){
        gorb.at(ab.at(j).first-1)=false;
        gorb.at(ab.at(j).second-1)=false;
      }else{
        gorb.at(ab.at(j).first-1)=false;
      }
    }
  int ans=0;
  rep(i,n){
    if(gorb.at(i)){
      ans++;
    }
  }
  cout<<ans;
}

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


int main(){

    int N, M;
    long long int a[1000][3];

    cin >> N >> M;
    for( int i = 0; i < N; i++ ){
        for( int j = 0; j < 3; j++ ){
            cin >> a[i][j];
        }
    }

    
    long long int ans = 0;

    for( int i = 0; i < 8; i++ ){
        long long int sum = 0;
        long long int b[10000] = {};
        for( int j = 0; j < N; j++ ){
            for( int k = 0; k < 3; k++ ){
                if( i/(1<<k) % 2 == 0) b[j] += a[j][k];
                else b[j] -= a[j][k];
            }
        }
        sort( b, b+N, greater<long int>() );
        for( int j = 0; j < M; j++ ) sum += b[j];
        ans = max( ans, sum );
    }
    
    cout << ans << endl;

    return 0;

}

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

int main(int argc, char const *argv[]) {
    int x,y;
    cin >> x >> y;
    if(x==2 || y==2){
        if(x==y){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else if(x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12){
        if(y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        if(y==4 || y==6 || y==9 || y==11){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 764
program prob14
    implicit none
    integer :: a,b,c

    read(*,*) a,b,c
    
    if(a+b==c .or. b+c==a .or. c+a==b) then
        write(*,*) "Yes"
    else    
        write(*,*) "No"
    end if


    stop
contains
end program prob14

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

int main(){
    int r,c;
    cin>>r>>c;
    int a[r+1][c+1];
    rep(i,r)rep(j,c)cin>>a[i][j];
    rep(i,r){
        int s=0;
        rep(j,c){
            s+=a[i][j];
        }
        a[i][c]=s;
    }
    rep(i,c){
        int s=0;
        rep(j,r){
            s+=a[j][i];
        }
        a[r][i]=s;
    }
    int su=0;
    rep(j,c)su+=a[r][j];
    a[r][c]=su;
    rep(i,r+1){
        rep(j,c+1){
            if(j<c)cout<<a[i][j]<<" ";
            if(j==c)cout<<a[i][j];
        }
        cout<<endl;
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  if (H % h == 0 && W % w == 0) {
    no();
  }
  int x = (1000000000 - 1) / (h * w - 1);
  vector<vi32> ans(H, vi32(W, x));
  for (int i = h - 1; i < H; i += h) {
    for (int j = w - 1; j < W; j += w) {
      ans[i][j] = -(h * w * x - x + 1);
    }
  }
  i64 sum = 0;
  int c2 = 0, c17 = 0;
  rep(i, H) rep(j, W) {
    c2 += ans[i][j] == 2;
    c17 += ans[i][j] == -17;
  }
  rep(i, H) rep(j, W) sum += ans[i][j];
  assert(sum > 0);
  cout << "Yes" << '\n';
  rep(i, H) cout << ans[i] << '\n';
}


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


int main() {
int N, K, R, S, P;
string T;
cin >> N >> K >> R >> S >> P >> T;

auto score = [&](int i){
if (T[i] == 'r')return P;
else if (T[i] == 's') return R;
else return S;

}; 

long long res = 0;
for(int k = 0; k < K; ++k){
bool last = false;
for(int i = k; i < N; i += K){
    if(i >= K && T[i-K] == T[i] && last) last = false;
    else res += score(i), last = true;
}


}
cout << res << endl;
}



Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC093_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] inputs = input.Split(' ');
            var numbers = new List<int>();
            for (int i = 0; i < 3; i++)
            {
                numbers.Add(int.Parse(inputs[i]));
            }
            numbers.Sort();

            int subtractionTotal = (numbers[2] - numbers[1]) + (numbers[2] - numbers[0]);
            int ans = 0;
            if (subtractionTotal % 2 == 0)
            {
                ans = subtractionTotal / 2;
            }
            else
            {
                ans = (subtractionTotal / 2) + 2;
            }
            Console.WriteLine(ans);
        }
    }
}


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

int get_kai(int x){
    int ans=1;
    for(int i=1;i<x+1;i++)ans*=i;
    return ans;
}

int main(){
    int N;cin>>N;
    vector<int> lst1(N),lst2(N);
    rep(i,N)cin>>lst1[i];
    rep(i,N)cin>>lst2[i];
    vector<bool> hist1(N,1),hist2(N,1);
    int cnt1=1,cnt2=1;
    rep(i,N){
        hist1[lst1[i]-1] = 0;//使用済み.
        hist2[lst2[i]-1] = 0;//使用済み.
        int sm1 = 0,sm2 = 0;
        rep(j,lst1[i]-1)sm1+=hist1[j];
        rep(j,lst2[i]-1)sm2+=hist2[j];
        cnt1 += get_kai(N-i-1)*sm1;
        cnt2 += get_kai(N-i-1)*sm2;
    }
    cout<<abs(cnt1-cnt2)<<endl;
    return 0;
}

Measured memory_bytes: 256
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    a, b, c, d = nm()
    while True:
        c -= b
        if c <= 0:
            print('Yes')
            exit()
        a -= d
        if a <= 0:
            print('No')
            exit()


if __name__ == '__main__':
    main()

Measured memory_bytes: 9736
import collections
import sys

def solve(n, A, B):
  ans = B[:]
  same = collections.deque()
  for i, (a, b) in enumerate(zip(A, B)):
    if a == b:
      if same and B[same[0]] != a:
        j = same.popleft()
        B[i], B[j] = B[j], B[i]
      else:
        same.append(i)
 # print(A)
  #print(B)
  #print(same)
  if same:
    s = A[same[0]]
    to_swap = []
    possible = False
    for i, (a, b) in enumerate(zip(A, B)):
      if a != s and b!=s:
        to_swap.append(i)
      if len(to_swap) == len(same):
        possible = True
        break
    if not possible:
      print('No')
      return
    for i, j in zip(same, to_swap):
      B[i], B[j] = B[j], B[i]
  print('Yes')
  print(' '.join(map(str, B)) )


       


def main():
  input = sys.stdin.readline
  n = int(input())
  A = list(map(int, input().split()))
  B = list(map(int, input().split()))
  solve(n, A, B)

main()


Measured memory_bytes: 123992
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

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

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9; 
const int N = 6e5+5;                                         
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}

int n, m, sa, sb, ea, eb;
char a[1005][1005];

bool inset (int x, int y) {
	return x > 0 && y > 0 && x <= n && y <= m && a[x][y] == '.';
}
int d[1005][1005];

int main () {
	SpeedForce;
	
	cin >> n >> m >> sa >> sb >> ea >> eb;
	
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			cin >> a[i][j];
			d[i][j] = inf;
		}
	}
	deque<pair<int, int> > q;
	d[sa][sb] = 0;
	q.pb(mp(sa, sb));
	
	while(sz(q)) {
		int x, y;
		tie(x,y) = q.front();
		q.pop_front();
		if(x == ea && y == eb) {
			cout << d[x][y] << '\n';
			exit(0);
		}
		
		
		for (int i = 0; i < 4; ++i) {
			int nx = x + dx[i], ny = y + dy[i];
			if(inset(nx, ny) && d[nx][ny] > d[x][y]) {
				d[nx][ny] = d[x][y];
				q.push_front({nx, ny});
			}
		}
		for(int dy = -2; dy <= 2; ++dy) 
		for (int dx = -2; dx <= 2; ++dx) {
			
			int nx = x + dx, ny = y + dy;
			if(inset(nx, ny) && d[nx][ny] > d[x][y] + 1) {
				d[nx][ny] = d[x][y] + 1;
				q.push_back({nx, ny});
			}
		}
	}
	
	cout << -1 << '\n';
	
	return Accepted;
}

// B...a


Measured memory_bytes: 8576
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

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

int a[300010], b[300010];
signed main(void)
{
	int n;
	cin >> n;
	REP(i, 3*n) {
		cin >> a[i];
		b[i] = a[i];
	}
	FOR(i, 1, 3*n) a[i] += a[i-1];

	VL e, f;
	priority_queue<int> d;
	priority_queue<int, vector<int>, greater<int>> c;
	int ret = 0;
	REP(i, n) {
		c.push(b[i]);
		ret += b[i];
	}
	e.PB(ret);
	FOR(i, n, 2*n) {
		ret += b[i];
		c.push(b[i]);
		int tmp = c.top();
		ret -= tmp;
		c.pop();
		e.PB(ret);
	}
	ret = 0;
	for(int i=3*n-1; i>=2*n; --i) {
		d.push(b[i]);
		ret += b[i];
	}
	f.PB(ret);
	for(int i=2*n-1; i>=n; --i) {
		ret += b[i];
		d.push(b[i]);
		int tmp = d.top();
		ret -= tmp;
		d.pop();
		f.PB(ret);
	}

	int ans = -LLINF;
	REP(i, n+1) {
		ans = max(ans, e[i] - f[n-i]);
	}
	cout << ans << endl;

	return 0;
}


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

using uli = unsigned long int;
using lli = long long int;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define repa(a,i,x) for(int i=a;i<=x;i++)

queue<uli> que;

uli mydeque(){
	uli ret=que.front();
	que.pop();
	return ret;
}

int main(){
	int K;
	
	cin >> K;
	
	if(K<=10){
		cout << K << endl;
		return 0;
	}
	
	repn(i,9)que.push(i);
	uli buf=0;
	int cnt=9;
	
	rep(i,K){
		uli x=mydeque();
		if(x%10!=0){
			buf=x*10+(x%10)-1;
			cnt++;
			if(cnt==K)break;
			else que.push(buf);
		}
		
		buf=x*10+(x%10);
		cnt++;
		if(cnt==K)break;
		else que.push(buf);
		
		if(x%10!=9){
			buf=x*10+(x%10)+1;
			cnt++;
			if(cnt==K)break;
			else que.push(buf);
		}
	}
	cout << buf << endl;
}

Measured memory_bytes: 768
n,m,x=map(int,input().split())
lst=[]
skl=[0]*m

money=0
moneylst=[]
flag=0
for i in range(n):
    lst.append(list(map(int,input().split())))
for i in range(2**n):
    s=bin(i)[2:].zfill(n)
    sindx=0
    skl=[0]*m
    money=0
    for j in s:
        j=int(j)
        if j==1:
            
            for k in range(m):
                skl[k]+=lst[sindx][k+1]
            money+=lst[sindx][0]
            

            if all(p>=x for p in skl):
                flag=1
                moneylst.append(money)
        sindx+=1

if flag==1:
    print(min(moneylst))
else:
    print('-1')

    


Measured memory_bytes: 69556
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

string s;
int n,q,k;

ll solve(){
	cin >> k;
	vector<ll> dp(3); //DM D M
	ll ret = 0;
	rip(i,n,0){
		if(i >= k){
			if(s[i-k] == 'D'){
				dp[1]--;
				dp[0] -= dp[2];
			}
			else if(s[i-k] == 'M'){
				dp[2]--;
			}
		}
		if(s[i] == 'D'){
			dp[1]++;
		}
		else if(s[i] == 'M'){
			dp[2]++;
			dp[0] += dp[1];
		}
		else if(s[i] == 'C'){
			ret += dp[0];
		}
	}
	return ret;
}

int main(){
	cin >> n >> s >> q;
	vector<ll> ans(q);
	rip(i,q,0) ans[i] = solve();
	rip(i,q,0) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 1412
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
-- import Data.Array
import Data.Array.Unboxed

main :: IO ()
main = do
  l <- readLn
  as <- replicateM l $ readLn :: IO [Int]
  print $ solve' as

solve' :: [Int] -> Int
solve' = minimum . foldl' f (replicate 5 0) 
  where
    f :: [Int] -> Int -> [Int]
    f !as !a = [
      (head as) + a,
      (minimum . take 2 $ as) + if a == 0 then 2 else if a `mod` 2 == 0 then 0 else 1,
      (minimum . take 3 $ as) + if a `mod` 2 == 0 then 1 else 0,
      (minimum . take 4 $ as) + if a == 0 then 2 else if a `mod` 2 == 0 then 0 else 1,
      (minimum as) + a]


Measured memory_bytes: 193916
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(a-b>=0){
    cout << "delicious"<<endl;
    return 0;
  }
  if(abs(a-b)<=x){
    cout<<"safe"<<endl;
  }else{
    cout<<"dangerous"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3532
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int[] data = new int[s.length()+1];
    int[] ans = new int[s.length()+1];


    for (int i = 0; i < s.length(); i++) {
      data[i] = Integer.valueOf(s.substring(i,i+1));
      ans[i] = Integer.valueOf(s.substring(i,i+1));
    }

    for (int i = 1; i < s.length()-1; i++) {
      if (data[i-1]== data[i+1]) {
        if (data[i] == data[i+1]) {
          data[i] = Math.abs(data[i]-1);
        }
      } else {
        if (data[i-1] == data[i]) {
          data[i] = Math.abs(data[i]-1);
        } else {
          data[i+1] = Math.abs(data[i+1]-1);
        }
      }
    }

    int count = 0;

    for (int i = 0; i < s.length(); i++) {
      if (data[i] != ans[i]) {
        count++;
      }
    }

    System.out.println(count);

  }

}


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


def main():
    N = int(input())
    for h in range(1, 3501):
        for n in range(1, 3501):
            d = 4*h*n - n*N - h*N
            if d > 0:
                w = N*h*n / d
                if w.is_integer():
                    print(h, n, int(w))
                    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
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; }

int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
vector<int> a(101);
int num(int m) {
    int sum = 0;
    for (size_t x = 0; x < a.size(); ++x) {
        if (a[x] >= m - 1) sum++;
    }
    return sum;
}

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

    for (int i = 2; i <= n; ++i) {
        int cur = i;
        for (int j = 2; j < i + 1; ++j) {
            while (cur%j == 0) {
                a[j] += 1;
                cur /= j;
            }

        }
    }
    cout << num(75) + num(25)*(num(3) - 1) + num(15)*(num(5) - 1) + num(5)*(num(5)-1)*(num(3)-2)/2<< endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
c = []
for i in range(n):
    x= list(map(int, input().split()))
    x.append(sum(x))
    c.append(x)
    print(*x)
#print(c)
d = [0 for i in range(m+1)]
for i in range(n):
    for j in range(m+1):
        d[j]+=c[i][j]
print(*d)


Measured memory_bytes: 5720
/* Bismillahir Rahmanir Rahim */

#include <bits/stdc++.h>

#define rep(i, n)	for(int i=0;i<n;i++)
#define repn(i, n)	for(int i=1;i<=n;i++)
#define set(i, n)	memset(i, n, sizeof(i))

#define pb	push_back
#define oo	1e9 

using namespace std;

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

int main(){
	int k, s;
	cin >> k >> s;
	long long ret = 0;
	for(int i=0;i<=k;i++){
		for(int j=0;j<=k;j++){
			if(i + j > s) break;
			if(s - i - j <= k) ret += 1;
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #n = int(stdin.readline()[:-1])   
    r = stdin.readline()[:-1]
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]
    #n = int(r)
    #a = r.split()
    #a,b,c = r.split()
    #a = list(map(int, r.split()))
    a,b,c,d = map(int, r.split())
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]
    #res = 0

    print(max(a*b, c*d))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 19 13:32:42 2017

@author: yamakoshi
"""

s = input()
(x, y) = map(int, input().split())

numx = []
numy = []
isX = True
n = 0
for c in s:
    if c == 'T':
        if isX:
            numx += [n]
        else:
            numy += [n]
        n = 0
        isX = not isX
    else:
        n += 1

if n > 0:
    if isX:
        numx += [n]
    else:
        numy += [n]

px = numx[0]
numx = numx[1:]
py = 0

for ni in reversed(sorted(numx)):
    if px > x:
        px -= ni
    else:
        px += ni

for ni in reversed(sorted(numy)):
    if py > y:
        py -= ni
    else:
        py += ni

if px == x and py == y:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3188
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int main() {
  ll N;
  cin >> N;
  ll power=1;
  rep(i,N){
    power = (power * (i+1)) % MOD1; 
  }

  cout << power << endl;
  
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N, K = getNM()
sum = 0
for b in range(1, N + 1):
    opt1 = (N // b) * max(0, (b - K))
    if K == 0:
        opt2 = N % b
    else:
        opt2 = max(0, (N % b) - K + 1)
    sum += (opt1 + opt2)
print(sum)

Measured memory_bytes: 39920
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double val = sc.nextInt();
        double base = sc.nextInt();
        double count = 0;
        while (val >= base) {
            val = (val/base);
            count++;
        }
        System.out.println((int) (count + 1));
    }
}


Measured memory_bytes: 20948
n = int(input())
a = [int(i) for i in input().split()]

money = 1000
kabu = 0

for i in range(n - 1):
    if a[i] < a[i + 1]:
        buy = money // a[i]
        money = money - a[i] * buy
        kabu += buy
    elif a[i] > a[i + 1]:
        money = money + a[i] * kabu
        kabu = 0
    else:
        pass
if kabu != 0:
    money = money + a[n - 1] * kabu
print(money)

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

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

int N;
int a[MAX_N];

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  // 0-indexed
  REP(i, N)
  {
    int x;
    cin >> x;
    a[i] = x - 1;
  }

  int cur = 0, cnt = 0;
  while (cur != -1) {
    if (cur == 1) {
      break;
    }
    int next = a[cur];
    cnt++;
    a[cur] = -1;
    cur = next;
  }

  if (cur == -1) {
    cout << -1 << endl;
  }
  else {
    cout << cnt << endl;
  }

  return 0;
}


Measured memory_bytes: 640
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<=ll(b);++i)
#define ALL(f,x,...) ([&](decltype((x)) xxxx) { return (f)(begin(xxxx), end(xxxx), ## __VA_ARGS__); })(x)
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template <class T> T 
gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T 
lcm(T a, T b){return a * b / gcd(a, b);}
vector<char> 
string_to_vector_char(const string& input){vector<char> out(input.length());rep(i,input.length()){out[i]=input[i];}return out;}
map<char,int> 
count_same_elements(const vector<char>& v){map<char,int>cmap; for_each(v.begin(),v.end(),[&cmap](int x){cmap[x]++;}); return cmap; }
template<class A,class B> vector<B> 
mapf(const vector<A>& v,const function<B(A)>& func){vector<B> v_(v.size());rep(i,v.size()){ v_[i]=func(v[i]); }return v_;}
template<class A,class B> vector<B> 
adjacent_map(const vector<A>& v,const function<B(A,A)>& func){vector<B> v_(v.size()-1);rep(i,v.size()-1){ v_[i]=func(v[i+1],v[i]); }return v_;}
template<class A> bool
all_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]<1){flag=false;}; }return flag;}
template<class A> bool
any_of(const vector<A>& v){bool flag=false;rep(i,v.size()){ if(v[i]>0){flag=true; break;}; }return flag;}
template<class A> bool
none_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]>0){flag=false;}; }return flag;}
template<class T,class U>
void msg_with_compare(T A,T B,U A_greater_B,U A_eq_B,U A_less_B){
    if(A==B){cout<<A_eq_B<<"\n";}else if(A>B){cout<<A_greater_B<<"\n";}else{cout<<A_less_B<<"\n";}}
template<class B,class T>
void msg_with_boolean(B A,T true_msg,T false_msg){cout<< ( A? true_msg:false_msg);}
template<class B,class T>
void msg_with_boolean(B A1,B A2,T both_true_msg,T true_false_msg,T false_true_msg,T both_false_msg){
    if(A1){if(A2){cout<<both_true_msg;}else{cout<<true_false_msg;}
    }else{if(A2){cout<<false_true_msg;}else{cout<<both_false_msg;}}
}
template<class T>
void scan_vector(long long size,vector<T>& vector){
    vector.resize(size);
    for(long long i=0;i<size;++i){
        cin>>vector[i];
    }
}

ll n,x;
string s,t;
void input(){
    cin>>s;
}
void src(){
    bool f=true;
    if(s[0]!='A'){
        f=false;
    }
    ll count=0;
    repi(i,1,s.length()-1){
        if(isupper(s[i])){
            if(i==1 or i==s.length()-1 or s[i]!='C'){
                f=false;
            }
            count++;
        }
    }
    if(count!=1){
        f=false;
    }
    msg_with_boolean(f,"AC","WA");
}   

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
from argparse import ArgumentParser

args=ArgumentParser()
args.add_argument('-loc', '--local', type=bool,default=False)
LOCAL=args.parse_args().local

def input(): 
    x=sys.stdin.readline(); 
    if x[-1]=="\n": 
        return x.rstrip() 
    return x
    
def printe(*x):_=print("## ",*x,file=sys.stderr) if LOCAL else 0
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    s=input()
    t=input()
    ls=len(s)
    lt=len(t)
    tc=100000
    for i in range(ls-lt+1):
        cnt=0
        for j in range(lt):
            if t[j]!=s[j+i]:
                cnt+=1
        tc=min(cnt,tc)
    print(tc)


if __name__ == "__main__":
    main()

Measured memory_bytes: 73456
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n * m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, __gcd

int main() {
  ll N, a = pow(10, 12);
  ci(N);
  repi(i, 1, sqrt(N) + 1){
  	if(N % i == 0){
      a = min(a, i + N / i - 2);
    }
  }
  co(a);
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    for (ll i = 0; i < s.length(); ++i) {
        if (s.substr(i, 3) == "ABC") {
            ++ans;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
N,D = map(int,input().split())
X = [[int(x) for x in input().split()] for i in range(N)]
ans = 0
for i in range(N):
  for j in range(N):
    d = 0
    if i != j:
      for k in range(D):
        d += (X[i][k]-X[j][k])**2
      d = d ** (1/2)
      if int(d) == d:
        ans += 1
print(int(ans/2))

Measured memory_bytes: 3188
N,K=map(int,input().split())
p=[int(x) for x in input().split()]

M=S=sum(p[:K-1])
for i in range(K-1,N):
  S+=p[i]
  M=M if M>S else S
  S-=p[i-K+1]

print((M+K)/2)


Measured memory_bytes: 24548