akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>

int main(void){
    long long int n;
    scanf("%lld",&n);
    long long int x = 1, y = n;
    long long int i = 1, j = 1, id;
    double d = sqrt((double)n);
    id = (int)d;
    if(n % 2 != 0){
        j = 2;
    }
    while(i <= id){
        if(n % i == 0){
            if(x + y >= i + n/i){
                x = i;
                y = n / i;
            }
        }        
        if(x >= y || i >= y){
            break;
        }
        i += j;
    }
    printf("%lld\n",x+y-2);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

void print_stack(stack<char> st) {
    if (st.empty()) return;

    auto x = st.top();
    st.pop();

    print_stack(st);

    cout << x;
    st.push(x);
}

int main() {
    INIT;

    ll N;
    cin >> N;
    string s;
    cin >> s;

    stack<char> a;

    rep(i, N) {
        if (s[i] == '(')
            a.push('(');
        else if (s[i] == ')') {
            if (!(a.empty())) {
                char c = a.top();
                if (c == '(') {
                    a.pop();
                } else {
                    a.push(')');
                }
            } else {
                a.push(')');
            }
        }

        // stack<char> b = a;
        // print_stack(b);
        // cout << endl;
    }

    while (!a.empty()) {
        char c = a.top();
        a.pop();
        if (c == '(') {
            s = s + ")";
        } else if (c == ')') {
            s = "(" + s;
        }
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
void outp(int s) {
	if (s%3==1) printf("1\n");
	else if (s%3==2) printf("2\n");
	else printf("3\n");
}
int main() {
	int n, k;
	scanf("%d%d",&n,&k);
	for (int i=0; i<k; i++) {
		int a, b; scanf("%d%d",&a,&b);
		int x1=b, x2=abs(n-b)+1, y1=a, y2=abs(n-a)+1;
		if (x1>x2) swap(x1,x2);
		if (y1>y2) swap(y1,y2);
		if (x1<=a&&a<=x2) outp(x1);
		else if (y1<=b&&b<=y2) outp(y1);
	}
}

Measured memory_bytes: 0
import java.io.*;
import java.util.*;

public class Main {
	private static boolean canReach(List<Integer> dists, int target) {
		int sum = 0;
		for (int d : dists) {
			sum += d;
		}
		if ((sum + target) % 2 != 0) {
			return false;
		}
		if ((target > sum) || (target < -1*sum)) {
			return false;
		}
		int realTarget = (sum + target) / 2;
		boolean[][] dp = new boolean[dists.size() + 1][sum + 1];
		dp[0][0] = true;
		for (int i = 1; i <= dists.size(); i++) {
			int next = dists.get(i - 1);
			for (int j = 0; j <= sum; j++) {
				dp[i][j] = dp[i - 1][j];
			}
			for (int j = 0; j <= sum - next; j++) {
				dp[i][j + next] = dp[i][j + next] || dp[i - 1][j];
			}
		}
		return dp[dists.size()][realTarget];
	}
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		String s = f.readLine();
		StringTokenizer st = new StringTokenizer(f.readLine());
		int x = Integer.parseInt(st.nextToken());
		int y = Integer.parseInt(st.nextToken());
		List<Integer> xSet = new ArrayList<>();
		List<Integer> ySet = new ArrayList<>();
		int counter = 0;
		while (counter < s.length() && s.charAt(counter) == 'F') {
			counter++;
		}
		x -= counter;
		int start = counter + 1;
		boolean isX = false;
		counter = 0;
		for (int i = start; i < s.length(); i++) {
			if (s.charAt(i) == 'T') {
				if (isX) {
					xSet.add(counter);
				} else {
					ySet.add(counter);
				}
				isX = !isX;
				counter = 0;
			} else {
				counter++;
			}
		}
		if (isX) {
			xSet.add(counter);
		} else {
			ySet.add(counter);
		}
		boolean good = canReach(xSet, x) && canReach(ySet, y);
		if (good) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 31180
#include<stdio.h>

int main()
{
  int i,j,e,m;
  double k;

  while(1){
    scanf("%d",&e);
    if(e==0)break;
    m=1000000;
    for(i=0;i<101;i++){
      for(j=0;j<1001;j++){
	k=e-(i*i*i+j*j);
          if(i+j+k<m && k>=0){
	    m=i+j+k;
	  }
	}
      }
    
    printf("%d\n",m);
  }
  return 0;
}

Measured memory_bytes: 600
from collections import deque
n,m = map(int,input().split())
r = []
for _ in range(m):
    r.append(tuple(map(int,input().split())))
r = deque(sorted(r,key = lambda x:x[1]))
ans = 0
while len(r) > 0:
    _,y = r[0]
    ans += 1
    while len(r) > 0 and r[0][0] < y:
        r.popleft()
print(ans)

Measured memory_bytes: 19292
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
char map[105][105];
char s[105];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<=n+1;i++)
        for(int j=0;j<=m+1;j++)
    {
        map[i][j]='#';
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s+1);
        for(int j=1;j<=m;j++)
            map[i][j]=s[j];
    }
    for(int i=0;i<=n+1;i++)
    {
        for(int j=0;j<=m+1;j++)
        {
            printf("%c",map[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x[ohara],y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n;
    rep(i,n){
        cin>>x[i];
        a[i]=x[i];
    }
    sort(a,a+n);
    tmp=a[n/2-1];
    tmpp=a[n/2];
    rep(i,n){
        if(tmp==x[i])Cout(tmpp);
        else if(tmpp==x[i])Cout(tmp);
        else{
            if(x[i]<tmp)Cout(tmpp);
            else Cout(tmp);
        }
    }
    return 0;
}


Measured memory_bytes: 7936
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    int n;

    cin >> n;
    vector<int> a(n, 0);
    int tmp_a;
    for(int i=1; i<n; i++){
        cin >> tmp_a;
        tmp_a--;
        a[tmp_a]++;
    }

    for(int i=0; i<n; i++){
        cout << a[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3976
from collections import deque
import sys

N, K = map(int, input().split())
mod = 10**9+7

T = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)

fac = [0]*(K+1)
fac[0] = 1
fac[1] = 1
for i in range(2, K+1):
    fac[i] = fac[i-1] * i % mod

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

if K - len(T[0]) - 1 < 0:
    print(0)
    sys.exit()

ans = fac[K] * modinv(fac[K - len(T[0]) - 1])
q = deque(T[0])
used = [0]*N
used[0] = 1
for i in T[0]:
    used[i] = 1

while(len(q)>0):
    a = q.popleft()
    if len(T[a]) != 1:
        if K - len(T[a]) - 1 < 0:
            print(0)
            sys.exit()
        ans *= fac[K-2]*modinv(fac[K - len(T[a]) - 1])
        ans %= mod
    for i in T[a]:
        if used[i] == 0:
            q.append(i)
            used[i] = 1
print(ans%mod)

Measured memory_bytes: 67872
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N;
  cin >> N;
  vector<string> A(N);
  for_each(begin(A), end(A), [](auto& x) { cin >> x; });
  map<string, ll> m;
  m["AC"] = 0;
  m["WA"] = 0;
  m["TLE"] = 0;
  m["RE"] = 0;

  for (const auto& x : A) {
    m[x]++;
  }

  cout << "AC x " << m["AC"] << endl;
  cout << "WA x " << m["WA"] << endl;
  cout << "TLE x " << m["TLE"] << endl;
  cout << "RE x " << m["RE"] << endl;

  return 0;
}



Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
int n,A[25],ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>A[i];
	for(int i=2;i<n;i++)
		if((A[i]>A[i-1]&&A[i]<A[i+1])||(A[i]<A[i-1]&&A[i]>A[i+1]))ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {
	
	int count = 0;//???????????°
	int n;//??°????????°
	int i,j;//????????????
	int a[100]={0};
	int min;
	int temp;
	
	scanf("%d\n",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	
	for(i=0;i<n;i++){
		min = i;
		for(j=i;j<n;j++){
			if(a[min]>a[j]) min = j;
			else{}
			

		}
			if (i != min){
				temp = a[i];
				a[i] = a[min];
				a[min] = temp;
				
				count++;
			}
			else{}
	}
	
	for(i=0;i<n;i++){
		printf("%d",a[i]);
		if (i != n-1) printf(" ");
		else{}
	}
	
	printf("\n%d\n",count);
	
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for (int i=0; i<3; i++) {
    if (s[i]==t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>       // for next_permutation
#include <vector>

using namespace std;

int main() {
	int i;
	int num_a;
	int num_b;
	int num;
	int n;

	scanf("%d",&n);

    vector<int> v(n);
	vector<int> a(n);
	vector<int> b(n);


	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}

	for(i=0;i<n;i++){
		scanf("%d",&b[i]);
	}

	for(i=0;i<n;i++){
		v[i] = i + 1;
	}
	num = 0;
    do {
//		printf("\n");
//		for(i=0;i<n;i++){
//			printf("%d ",v[i]);
//		}
		if(v == a){
			num_a = num;
		}

		if(v == b){
			num_b = num;
		}
		num++;
    } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成


	printf("%d\n",abs(num_a - num_b));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int t;t=1;
	while(t--){
		string s;cin>>s;
		int n = s.length();
		int count1=0; int count2=0;
		bool flag = false;
		for(int i=0;i<n;i++){
			if(s[i]=='C'){
				count1++;
			}
			else if(s[i]=='F'){
				if(count1>0){
					flag = true; break;
				}
			}
		}
		if(flag==true){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}

}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
    int s;
    double w,h;
    
    while(scanf("%d,%lf,%lf\n",&s,&w,&h)==3){
        if(w/(h*h)>=25)printf("%d\n",s);
    }
    
    return 0;
}



Measured memory_bytes: 2028
#include <bits/stdc++.h>
        using namespace std;
		
		#include <string>
		#include <vector>
		#include <sstream>

        int main() {
          int M, K;
          cin>> M >> K;
          int N=1;
          for (int i=0; i<M; i++){
            N*=2; 
          }
          // N=2^M;
          
          if(K>N-1){
            cout << -1 << endl; 
          }
          else if(M==0){
            cout << 0 <<' '<< 0 << endl;
          }
          else if(M==1){
            if(K==1){
              cout << -1 << endl;
            }
            else{
              cout << 0 <<' '<< 0 <<' '<< 1 <<' '<< 1 << endl;
            }
          }
          else{  //でかいelse開始
           vector<int> A(N-1);
           vector<int> B(N-1);
           for (int i = 0; i < N-1; i++) {
             if(i>=K){ 
               A.at(i)=i+1;
               B.at(i)=i+1;
             }
             else{
               A.at(i) = i;
               B.at(i)=i ;
             }
  	    	}
         reverse(B.begin(), B.end()); 
          
         for (int i = 0; i < N-1; i++) {
         	cout << A.at(i)<<' '; 
         }      
            cout << K <<' '; 
         for (int i = 0; i < N-1; i++) {
         	cout << B.at(i)<<' '; 
         }
            cout << K <<' '; 
        }// 大きいelse終了
       }

Measured memory_bytes: 2816
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int a = sc.nextInt();
   int b = sc.nextInt();
   int c = sc.nextInt();

   if(a==b&&b==c)System.out.println(1);
   else if(a!=b&&b!=c&&c!=a) System.out.println(3);
   else System.out.println(2);
 }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    string S;
    cin >> N >> S;
    auto check = [&](string X)->bool{
        int idx = 0;
        rep(i,N){
            if(X[idx] == S[i])idx++;
            if(idx == 3)return true;
        }
        return false;
    };
    ll ans = 0;
    rep(i,10)rep(j,10)rep(k,10){
        string tmp = "";
        tmp.push_back(char(i + '0'));
        tmp.push_back(char(j + '0'));
        tmp.push_back(char(k + '0'));
        if(check(tmp))ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == s[i-1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int a,b,c,x ;

scanf("%d %d %d",&a,&b,&c) ;

if(a>b){

x = a ;

a = b ;

b = x ;


}

if(b>c){

x = b ;

b = c ;

c = x ;

}

if(a>b){

x = a ;

a = b ;

b = x ;


}

printf("%d %d %d\n",a,b,c) ;

return 0 ;

}

Measured memory_bytes: 596
// 2011/06/04 Tazoe

#include <iostream>
#include <stack>
using namespace std;

int main()
{
	stack<int> st;

	while(true){
		int n;
		cin >> n;
		if(cin.eof())
			break;

		if(n!=0){
			st.push(n);
		}
		else{
			cout << st.top() << endl;
			st.pop();
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
using namespace std;

int N;
int A[100010], B[100010], C[100010];
long long BB[100010];
long long res;

int bsrch(int v)
{
	int l=0, r=N;
	int m;
	while(l<r){
		m = (l+r)/2;
		if(A[m] >= v)
			r = m;
		else
			l = m+1;
	}
	return l;
}

int bsrch2(int v)
{
	int l=0, r=N;
	int m;
	while(l<r){
		m = (l+r)/2;
		if(B[m] >= v)
			r = m;
		else
			l = m+1;
	}
	return l;
}

void solve()
{
	sort(A, A+N);
	sort(B, B+N);
	sort(C, C+N);
	int i, j;
	for(i=0; i<N; i++){
		j = bsrch(B[i]);
		BB[i] = j;
	}
	for(i=1; i<N; i++){
		BB[i] += BB[i-1]; 
	}
	for(i=0; i<N; i++){
		j = bsrch2(C[i]);
		if(j>0){
			res += BB[j-1];
		}
	}
	printf("%lld\n", res);
}

int main()
{
	int i;
	scanf("%d", &N);
	for(i=0; i<N; i++)
		scanf("%d", &A[i]);
	for(i=0; i<N; i++)
		scanf("%d", &B[i]);
	for(i=0; i<N; i++)
		scanf("%d", &C[i]);
	solve();
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define ll long long
#define inf 10e9+1
using namespace std;
class item{
    public:
    int wt,val;
};

ll solve(vector<item>ar,int n,int w){
    int mxV = n*1000;
    ll dp[n+1][mxV+1];

    for(int val=0;val<=mxV;val++)
        dp[1][val] = inf;
    
    dp[1][0] = 0;
    dp[1][ar[1].val] = ar[1].wt;

    for(int i=2;i<=n;i++)
    {
        for(int v=0;v<=mxV;v++)
        {
            dp[i][v] = dp[i-1][v];
            if(ar[i].val>v)
                continue;
            
            dp[i][v] = min(dp[i][v],ar[i].wt+dp[i-1][v-ar[i].val]);
        }
    }
    ll ans =0;
    for(int x =0;x<=mxV;x++)
        if(dp[n][x]<=w){
            ans=x;
        }

    return ans;
}
int main()
{
    int n,w;
    cin>>n>>w;
    vector<item>ar(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>ar[i].wt>>ar[i].val;
    }


    cout<<solve(ar,n,w);


    
    return 0;
}

Measured memory_bytes: 81716
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const ll mod = 1e9+7;
const ll INF = 2e9;
const double PI = 3.1415926535;

char s1[53];
char s2[53];

int main(void){
    int n; scanf("%d", &n);
    scanf("%s", &s1); scanf("%s", &s2);
    int now = 0, fl;
    ll ans;
    if(s1[0] == s2[0]){
        ans = 3; now = 1; fl = 0;
    }else{
        ans = 6; now = 2; fl = 1;
    }
    while(s1[now] != '\0'){
        if(s1[now] == s2[now]){
            if(fl){
                now++; fl = 0;
            }else{
                ans *= 2; ans %= mod; now++;
            }
        }else{
            if(fl){
                ans *= 3; ans %= mod; now += 2;
            }else{
                ans *= 2; ans %= mod; now += 2; fl = 1;
            }
        }
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, a, b = na()
print(min(n * a, b))


Measured memory_bytes: 5084
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(System.Console.ReadLine());
            //var c = s.Split(' ');


            int n = 0;
            int k = 0;
            while (k < x)
            {
                n++;
                k =(n * (n + 1))/2;               
            }
            Console.WriteLine(n);
        }
    }
}


Measured memory_bytes: 11092
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue
        cnt = 0
        for dx in [-1, 0, 1]:
            for dy in [-1, 0, 1]:
                if 0 <= dy + i < h and 0 <= dx + j < w:
                    if s[i+dy][j+dx] == '#':
                        cnt += 1
                else:
                    continue
        s[i][j] = str(cnt)
for k in s:
    print("".join(k))


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int p,q,r;
	cin >>p >>q >>r;
	int ans =p+q+r;
	
	cout << ans - max({p,q,r}) << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define ld long double
    #define ll long long
    using namespace std;
    
    
    
    int main() {
        
            ll n, c=0;
            string A, B;
            cin>>A>>B;
            n=A.size();
            for(ll i=0; i<n; i++)
            {
                if(A[i]!=B[i])
                c++;
            }
            cout<<c;
        return 0;
    }

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

typedef long long i64;
typedef pair<i64, i64> pii;

const int INF = 0x3f3f3f3f;
const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  int c, a, n;
  rep(i, q) {
    cin >> c >> a >> n;

    int cnt = 0;
    while (c && a && n) {
      --c; --a; --n;
      ++cnt;
    }

    while (c >= 2 && a) {
      c -= 2; --a;
      ++cnt;
    }

    while (c >= 3) {
      c -= 3;
      ++cnt;
    }

    cout << cnt << "\n";
  }
  return 0;
}



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

using namespace std;

const int MAXN = 1e5 + 1;



int main() {
	ios_base::sync_with_stdio(0);
	
	string s;
	cin >> s;
	
	int x = 0;
	int a = (s[0] - '0') * 10 + s[1] - '0';
	int b = (s[2] - '0') * 10 + s[3] - '0';
	
	if(1 <= a && a <= 12) x+=1;
	if(1 <= b && b <= 12) x+=2;
	
	if(x == 0) {
		cout << "NA\n";
	} else if(x == 1) {
		cout << "MMYY\n";
	} else if(x == 2) {
		cout << "YYMM\n";
	} else {
		cout << "AMBIGUOUS\n";
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
double cal(long long x){
    long long y=10,len=1,sum=0,ret=x;
    while(y<=x)y=(y<<1)+(y<<3),++len;
    while(len--){
        y/=10;
        sum+=x/y;
        x%=y;
    }
    return ret*1.0/sum;
}
bool judge(long long x){
    long long a=1;
    while(a<=x){
        if(cal(x+a)<cal(x))return false;
        a=(a<<1)+(a<<3);
    }
    return true;
}
long long k,now;
int main(){
    scanf("%d",&k);
    while(k--){
        long long a=1;
        while(true){
            if(judge(now+a)){
                now+=a;
                break;
            }
            a=(a<<1)+(a<<3);
        }
        cout<<now<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
command_num = int(input())
dict = set([])

for i in range(command_num):
    in_command, in_str = input().rstrip().split(" ")
    
    if in_command == "insert":
        dict.add(in_str)
    elif in_command == "find":
        if in_str in dict:
            print("yes")
        else:
            print("no")

Measured memory_bytes: 33108
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Fri Mar 27 18:29:10 JST 2020
 **/

signed main() {
    Int H, W;
    cin >> H >> W;
    vector<string> a(H);
    REP(i, H) cin >> a[i];
    vector<bool> row(H), col(W);
    REP(i, H) {
        REP(j, W) {
            if (a[i][j] == '#') {
                row[i] = true, col[j] = true;
            }
        }
    }
    REP(i, H) {
        if (!row[i]) continue;
        REP(j, W) {
            if (!col[j]) continue;
            cout << a[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int32_t main()
{
    FastIO;
    int n,m,b,c;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;++i)
    cin>>a[i];
    vector<pair<int,int>>v(m);
    for(int i=0;i<m;++i)
    {
        cin>>b>>c;
        v.push_back(make_pair(c,b));
    }
    sort(a,a+n);
    sort(v.rbegin(),v.rend());
    int cnt=0,s=0,p=0;
    for(auto x:v)
    {
        int c=x.first;
        int b=x.second;
        cnt=0;
        for(int j=p;j<n;++j)
        {
            if(a[j]>=c||cnt>=b)
            break;
            if(a[j]<c&&cnt<b)
            {
                a[j]=c;
            }
            ++p;
            ++cnt;
        }
    }
    int ans=0;
    for(int i=0;i<n;++i)
    {
        ans+=a[i];
    }
    cout<<ans;
}

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

int main() {
  // �����Ƀv���O������ǋL
  int r,s;
  int g=0;
  cin >> r;
     while(r){
		s=r%10;
		g=g+s;
		r=r/10;
	}
	
	
    cout << g << endl;
  
}

Measured memory_bytes: 256
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<string>
#include<vector>
using namespace std;
int n,a,b,m,num,ans;
vector<pair<int,int> > v;
int main(){
	cin>>n>>m;
	for (int i=0;i<m;i++){
		cin>>a>>b;
		v.push_back(pair<int,int>(a,b-1));
	}
	sort(v.begin(),v.end());
	for (int i=0;i<m&&num<=n;)
		if (num<v[i].second)
			num++;
		else if (num==v[i].second){
			ans++;
			while (i<m&&num>=v[i].first){
				if (num>v[i].second) num=v[i].second;
				i++;
			}
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
int N, a[100001], O;
int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		scanf("%d", a + i);
	for (int i = 1; i <= N; )
	{
		O++;
		int j = i;
		while (j < N && a[j] == a[j + 1])
			j++;
		int k = j;
		while (k < N && (a[j] < a[j + 1] ? a[k] <= a[k + 1] : a[k] >= a[k + 1]))
			k++;
		i = k + 1;
	}
	printf("%d\n", O);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
inline int rd(){
	char ch=getchar(); int i=0,f=1;
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){i=(i<<1)+(i<<3)+ch-'0';ch=getchar();}
	return i*f; 
}
inline void W(int x){
	static int buf[50];
	if(!x){putchar('0');return;}
	if(x<0){putchar('-');x=-x;}
	while(x){buf[++buf[0]]=x%10;x/=10;}
	while(buf[0])putchar(buf[buf[0]--]+'0');
}
const int N=2e5+50,Mod=924844033,G=5;
int n,g[N],v[N*2],nt[N*2],ec;
int sze[N],fa[N],cnt[N];
int fac[N],invfac[N];
inline int power(int a,int b){
	int rs=1;
	for(;b;b>>=1,a=(ll)a*a%Mod)
		if(b&1)rs=(ll)rs*a%Mod;
	return rs;
}
inline void add(int x,int y){nt[++ec]=g[x];g[x]=ec;v[ec]=y;}
inline void dfs(int x,int y){	sze[x]=1; fa[x]=y;
	for(int e=g[x];e;e=nt[e]){
		if(v[e]!=y){
			dfs(v[e],x);
			sze[x]+=sze[v[e]];
		}
	}
	if(x!=1)++cnt[sze[x]];
}
int A[N*8],B[N*8],ans[N];
namespace fft{
	int k,pos[N*8];
	inline void init(int len){
		for(k=1;k<len;k<<=1); k<<=1;
		for(int i=1;i<k;i++)
			pos[i]=(i&1)?((pos[i>>1]>>1)^(k>>1)):(pos[i>>1]>>1);
	}
	inline void dft(int *a){
		for(int i=1;i<k;i++)
			if(pos[i]>i)swap(a[pos[i]],a[i]);
		for(int bl=1;bl<k;bl<<=1){
			int tl=bl<<1,wn=power(G,(Mod-1)/tl);
			for(int bg=0;bg<k;bg+=tl){
				int w=1;
				for(int j=0;j<bl;++j){
					int &t1=a[bg+j],&t2=a[bg+j+bl],t3=(ll)t2*w%Mod;
					t2=(t1-t3+Mod)%Mod;
					t1=(t1+t3)%Mod;
					w=(ll)w*wn%Mod;
				}
			}
		}
	}
	inline void dft(int *a,int *b){
		for(int i=0;i<k;i++) a[i]=(ll)a[i]*b[i]%Mod;
		dft(a); reverse(a+1,a+k);
		for(int i=0;i<k;i++) a[i]=(ll)a[i]*power(k,Mod-2)%Mod;
	}
}
int main(){
	n=rd();
	for(int i=1;i<n;i++){
		int x=rd(),y=rd();
		add(x,y); add(y,x);
	}
	dfs(1,0);
	fac[0]=(invfac[0]=1); 
	for(int i=1;i<=n;i++) fac[i]=(ll)fac[i-1]*i%Mod;
	for(int i=1;i<=n;i++) invfac[i]=power(fac[i],Mod-2);
	for(int i=0;i<=n;i++) A[i]=(ll)cnt[n-i]*fac[n-i]%Mod, B[i]=invfac[i];
	fft::init(n+1);
 	fft::dft(A); fft::dft(B);
	fft::dft(A,B);
	for(int i=1;i<=n;i++) ans[i]=(ans[i]-A[n-i]+Mod)%Mod;
	memset(A,0,sizeof(A));
	for(int i=0;i<=n;i++) A[i]=(ll)cnt[i]*fac[n-i]%Mod;
	fft::dft(A); fft::dft(A,B);
	for(int i=1;i<=n;i++) ans[i]=(ans[i]-A[n-i]+Mod)%Mod;
	for(int i=1;i<=n;i++){
		int t=(ll)fac[n]*invfac[n-i]%Mod*invfac[i]%Mod;
		ans[i]=(ll)ans[i]*invfac[i]%Mod;
		ans[i]=(ans[i]+(ll)t*n%Mod)%Mod;
	}
	for(int i=1;i<=n;i++)W(ans[i]),putchar('\n');
}

Measured memory_bytes: 29312
#include <iostream>
#include <vector>

using namespace std;

//combinationを作る前処理
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

const int MAX = 210000;
const int MOD = 1000000007;



long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long com(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main() {
    int n, m;
    COMinit();
    cin >> n >> m;
  
    auto vec = prime_factorize(m);
  
    long long res = 1;
  
    for (auto pa : vec) {
      
        int k = pa.second;
       
        res = (res * com(n+k-1,k)) % MOD;
    }
    cout << res << endl;
}          


Measured memory_bytes: 5120
#include <iostream>
#include <set>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <map>
#include <math.h>
#define LL long long
using namespace std;
LL n;
int a[100005];
int main()
{
    scanf("%d",&n);
    LL sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    LL nn=n*(n+1)/2;
    if(sum%nn!=0)
    {
        cout<<"NO"<<endl;
    }
    else
    {
        LL k=sum/nn;
        int temp=a[0]-a[n-1];
        for(int i=n-1;i>0;i--)
        {
            a[i]=a[i]-a[i-1];
        }
        a[0]=temp;
        for(int i=0;i<n;i++)
        if(k-a[i]<0||(k-a[i])%n)
        {
            cout<<"NO"<<endl;
            return 0;
        }
        cout<<"YES"<<endl;
    }
    return 0;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define pb push_back

int main(){
	int n,k;
	cin>>n>>k;
	int l=((n-2)*(n-1))/2;
	if(k>l){
		cout<<-1;
		return 0;
	}
	vector<pair<int,int>> vp;
	for(int i=2;i<=n;i++){
		pair<int,int> p;
		p={1,i};
		vp.pb(p);
	}
	int ans=l;
	int cur=2;
	int cur1=3;
	while(1){
		if(k==ans) break;
		else{
			pair<int,int> p;
			p={cur,cur1};
			vp.pb(p);
			cur1++;
			if(cur1==n+1) cur++,cur1=cur+1;
			ans--;
		}
	}
	cout<<vp.size()<<endl;
	pair<int,int> h;
	for(auto it=vp.begin();it!=vp.end();it++){
		h=*it;
		cout<<h.first<<" "<<h.second<<endl;
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::cin >> n;
	std::vector<int> ans(n, 0);
	for(int i = 1; i < n; i++) {
		int x;
		std::cin >> x;
		ans[x-1]++;
	}
	for(int i = 0; i < n; i++) {
		std::cout << ans[i] << (i + 1 == n ? '\n' : ' ');
	}
}

Measured memory_bytes: 3964
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>

using namespace std;

#define N_MAX 3001
#define VAL_MAX 3001

int memo[2][N_MAX][VAL_MAX];
pair<int, int> food[N_MAX];

int func(int time, int index, int last)
{
	if (time <= 0){
		return 0;
	}
	if (0 == index){
		if (0 == last){
			return food[index].first;
		}
		else{
			if (time >= food[index].second){
				return food[index].first;
			}
			else{
				return 0;
			}
		}
	}

	if (-1 != memo[last][time][index]){
		return memo[last][time][index];
	}

	int ret = 0;

	if (0 == last){
		ret = max(ret, func(time - 1, index - 1, 1) + food[index].first);
	}
	if (time >= food[index].second){
		ret = max(ret, func(time - food[index].second, index - 1, last) + food[index].first);
	}
	ret = max(ret, func(time, index - 1, last));

	return memo[last][time][index] = ret;
}

void solv()
{
	int N, T; scanf("%d%d", &N, &T);
	for (int i = 0; i < N; i++){
		int a, b; scanf("%d%d", &a, &b);
		food[i] = make_pair(b, a);
	}

	sort(food, food + N);

	for (int i = 0; i < 2; i++){
		for (int j = 0; j < N_MAX; j++){
			fill(memo[i][j], memo[i][j] + VAL_MAX, -1);
		}
	}
	printf("%d", func(T, N - 1, 0));

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 70784
import java.awt.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
    public static void main(String args[] ) throws Exception {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        int[] b=a.clone();
        Arrays.sort(b);

        for(int i=0;i<n;i++){
            a[i]=a[i]-b[i];
        }

        int invCount=0;
        for(int i=0;i<n;i++){
            if(a[i]!=0)invCount++;
        }

        if(invCount<=2) System.out.println("YES");
        else System.out.println("NO");
    }

}



Measured memory_bytes: 21716
using System;
using System.Collections.Generic;

namespace cswork
{

    class Program
    {
        public Program() { }

        Scanner cin;

        void Omame()
        {
            cin = new Scanner();
            string s = cin.next();

            s = s.Replace("eraser", "");
            s = s.Replace("erase", "");
            s = s.Replace("dreamer", "");
            s = s.Replace("dream", "");

            if (s.Equals(""))
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }
    }

    class Scanner
    {
        string[] s;
        int i;

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

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

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

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

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

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

Measured memory_bytes: 12384
def get_area(a, b):
    return a * b

def get_perimeter(a, b):
    return (a * 2) + (b * 2)

if __name__ == '__main__':
    a, b = map(int, input().split(' '))
    area = get_area(a, b)
    perimeter = get_perimeter(a, b)
    print('{} {}'.format(area, perimeter))



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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) { 
        cin >> a[i];
    }
    sort(all(a));
    ll ans = a[n-1];
    ll tmp = INF;
    ll r = 0;
    rep(i, n) {
        if (abs((ans+1) / 2 - a[i]) < tmp) {
            tmp = abs((ans+1) / 2 - a[i]);
            r = a[i];
        }
    }
    print(ans << " " << r);
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;
#define MAX 100
#define INF 10000
int M[MAX][MAX];
int n;
int d[MAX];
int color[MAX];
int p[MAX];



int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> M[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    d[i] = INF;
    color[i] = 0;
  }

  int w = 0;
  d[0] = 0;
  while(true) {

    int com = INF;
    int u;
    for (int i = 0; i < n; i++) {
      if (color[i] != 2 && com > d[i] && d[i] != -1){
        com = d[i];
        u = i;
      }
    }

    if (com == INF) {
      break;
    }

    w += com;
    color[u] = 2;

    for (int j = 0; j < n; j++) {
      if (M[u][j] != -1 && M[u][j] < d[j] && color[j] != 2) {
        d[j] = M[u][j];
        p[j] = u;
      }
    }
  }

  cout << w << endl;
  return 0;
}

Measured memory_bytes: 3096
// WeirdBugsButOkay

#include <bits/stdc++.h>
 
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
 
using namespace std;

ll pow3(ll a,ll b,ll m=1000000007)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}

void solve()
{
    ll x;
    cin>>x;
    ll ans=1000*(x/500)+5*((x%500)/5);
    cout<<ans;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll q=1;
    //cin>>q;
    for(ll i=0;i<q;i++)
    {
        solve();
    }
    return 0;
}

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

int main(){
    string s; int w;
    cin>>s>>w;
    rep(i,s.size()){
        if(i%w==0)cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main() {

	char S[105];
	scanf("%s",S);

	int i;

	int ans = 0;

	for (i = 1; i <= strlen(S); i++) {
		if (i % 2 == 1 && (S[i - 1] == 'R' || S[i - 1] == 'U' || S[i - 1] == 'D')) {
			ans++;
		}
		else if (i % 2 == 0 && (S[i - 1] == 'L' || S[i - 1] == 'U' || S[i - 1] == 'D')) {
			ans++;
		}
	}
	if (ans == strlen(S)) {
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;
int n,a=0;
void check(int x);
int main(void){
    for(;;){
        int z,b,c;
        a=0;
        cin>>n;
        if(n==0)break;
        check(0);
        if(a%10==0)b=a/10;
        else b=1+a/10;
        if(b%365==0)c=b/365;
        else c=1+b/365;

        cout<<c<<endl;
    }


	return 0;
}

void check(int x){

    if(x==n){
        a++;
        return;
    }

    if(x+3<=n)check(x+3);

    if(x+2<=n)check(x+2);

    if(x+1<=n)check(x+1);

}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <limits>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
constexpr int INF = 1 << 28;
inline bool check(const set<P>& st, const P& v)
{
    auto upper = st.upper_bound({v.first, -INF});
    if (upper == st.begin()) {
        return false;
    } else {
        upper--;
        return upper->second < v.second;
    }
}
inline bool shouldInsert(set<P>& st, const P& v)
{
    auto upper = st.upper_bound(v);
    if (upper == st.begin()) {
        return true;
    } else {
        upper--;
        return upper->first != v.first and upper->second != v.second;
    }
}
inline void insertAndErase(set<P>& st, const P& v)
{
    auto lower = st.lower_bound({v.first, -INF});
    for (; lower != st.end() and lower->second >= v.second;) {
        lower = st.erase(lower);
    }
    if (shouldInsert(st, v)) {
        st.insert(v);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        int M, N, A, B;
        cin >> M >> N >> A >> B;
        if (M == 0 and N == 0 and A == 0 and B == 0) {
            break;
        }
        int a = A;
        int b = B;
        const auto gen = [&]() {
            constexpr int C = ~(1 << 31);
            constexpr int M = (1 << 16) - 1;
            a = 36969 * (a & M) + (a >> 16);
            b = 18000 * (b & M) + (b >> 16);
            return (C & ((a << 16) + b)) % 1000000;
        };
        const auto comp = [](const PP& pp1, const PP& pp2) {
            return pp1.first != pp2.first ? pp1.first < pp2.first : pp1.second > pp2.second;
        };
        vector<PP> p(M + N);
        for (int i = 0; i < M; i++) {
            int x, y, z;
            cin >> x >> y >> z;
            p[i] = {x, {y, z}};
        }
        for (int i = M; i < M + N; i++) {
            const int x = gen();
            const int y = gen();
            const int z = gen();
            p[i] = {x, {y, z}};
        }
        sort(p.begin(), p.end(), comp);
        vector<set<P>> tail(M + N + 1);
        tail[0].insert({-INF, -INF});
        for (int i = 0; i < M + N; i++) {
            int inf = -1;
            int sup = N + M + 1;
            while (sup - inf > 1) {
                const int mid = (sup + inf) / 2;
                if (check(tail[mid], p[i].second)) {
                    inf = mid;
                } else {
                    sup = mid;
                }
            }
            insertAndErase(tail[sup], p[i].second);
        }
        for (int i = N + M; i >= 0; i--) {
            if (not tail[i].empty()) {
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 24936
N = int(input())
A = list(map(int,input().split()))
dif1 = []
dif2 = []
A.insert(0,0)
A.append(0)
sum = 0
for i in range(N):
    dif1.append(abs(A[i + 1] - A[i]))
    dif2.append(abs(A[i + 2] - A[i]))
    sum += dif1[i]
dif1.append(abs(A[N+1] - A[N]))
sum += dif1[N]

for i in range(N):
    print(sum - dif1[i] - dif1[i+1] + dif2[i])

Measured memory_bytes: 17128
#include<iostream>
#include<unordered_set>
#include<string>
#include<vector>
using namespace std;
#define int long long
int a[114514];
signed main() {
	int n, x;
	cin >> n >> x;
	for (int i = 1; i <= n; i++)cin >> a[i];
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		if (a[i] + a[i + 1] > x) {
			ans += a[i] + a[i + 1] - x;
			a[i + 1] = x - a[i];
		}
	}
	cout << ans << endl;
}

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

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
  int n;
  cin>>n;
  long long int maxi = INT_MIN;
  long long int mini = INT_MAX;
  long long int maxi2 = INT_MIN;
  long long int mini2 = INT_MAX;
  while(n--)
  {
    long long int x,y;
    cin>>x>>y;
    maxi = max((x+y),maxi);
    mini = min((x+y),mini);
    maxi2 = max((x-y),maxi2);
    mini2 = min((x-y),mini2);

  }

  cout<<max(abs(mini-maxi),abs(mini2-maxi2))<<endl;

}


Measured memory_bytes: 3576
#include<iostream>
#include<queue>
using namespace std;
int k,cnt,inf=0x3f3f3f3f,inqueue[100001],head[100001],dis[100001];
struct bian{
	int to;
	int cost;
    int next;
}edge[200001];
void addedge(int u,int v,int cost)
{
	edge[++cnt].to=v;
	edge[cnt].cost=cost;
	edge[cnt].next=head[u];
	head[u]=cnt;
}
int main()
{
	cin>>k;
	for(int i=0;i<=100000;i++)head[i]=-1,dis[i]=inf;
	for(int i=0;i<=k-1;i++)addedge(i,(i+1)%k,1);
	for(int i=0;i<=k-1;i++)addedge(i,10*i%k,0);
	queue <int> q;
	q.push(1);dis[1]=1;inqueue[1]=1;
	while(!q.empty())
	{
		int from=q.front();
		q.pop();
		inqueue[from]=0;
		for(int i=head[from];i!=-1;i=edge[i].next)
		{
			int to=edge[i].to,cost=edge[i].cost;
			if(dis[from]+cost<dis[to])
			{
				dis[to]=dis[from]+cost;
				if(inqueue[to]==0)
				{
					inqueue[to]=1;
					q.push(to);
				}
		    }
		}
	}
	cout<<dis[0]<<endl;
	return 0;
}


Measured memory_bytes: 3840
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
	int a,b,c;
	int i,n,flag;
	long long sum;
	while(~scanf("%d %d %d",&a,&b,&c))
	{
		flag=0;
		n = c % b;
		for(i = 0;i < 1000;i++)
		{
			sum = (i + 1) * a;
			if(sum % b == n)
			{
				flag=1;
				break;
			}
		}
		if(flag==1)
			printf("YES\n");
		if(flag==0)
			printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

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

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve() {
    ins(s);

    ll left = 0, right = s.size() - 1;
    while (s[left] != 'A')
        left++;
    while (s[right] != 'Z')
        right--;

    out(right - left + 1);
}


Measured memory_bytes: 3784