akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
int main(int argc, char const *argv[]) {
    std::string s;
    std::cin >> s;
    bool flag=true;
    for (size_t i = 0; i < s.size(); i++) {
        std::string sub=s.substr(i+1,s.size()-i);
        if (sub.find(s[i])!=-1) {
            std::cout << "no" << '\n';
            flag=false;
            break;
        }
    }
    if (flag) {
        std::cout << "yes "<< '\n';
    }
    return 0;
}


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

int main() {
        ios_base::sync_with_stdio(false); 
        cin.tie(NULL);
        // Code Starts...
        ll n;
        cin>>n;
        vector<ll > v(n);
        for (int i=0;i<n;i++)
            cin>>v[i];
        vector<ll > dp(n+1,inf); // it stores the min cost incurred so far...
        dp[0] = 0; // cost at stone 1 is 0...
  		dp[1] = abs(v[1] - v[0]); // cost for stone 1...
        // Now what matters so far i.e. at ith stone 
  		// 1. from where i had jumped from...
  		// 2. cost so far stored in dp[i]...that is of course minimum...
  		for (int i=2;i<n;i++)
            dp[i] = min(dp[i-1] + abs(v[i]-v[i-1]) , dp[i-2] + abs(v[i]-v[i-2]));
        cout<<dp[n-1];
        // Code Ends...
        return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
    int D,T,S;
    cin>>D>>T>>S;
    if(D<=T*S){
        cout<<"Yes"<<endl;
    }
    else
    cout<<"No"<<endl;
}

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

#define int long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    int n,a,b;
    cin>>n>>a>>b;
    if(a>b) swap(a,b);
    if((b-a)%2!=0)
        cout<<"Borys"<<endl;
    else
        cout<<"Alice"<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int A, B; cin >> A >> B;

  if (B == 1) {
    cout << 0 << endl;
    return 0;
  }

  int ans = 1;
  rep(i, 100) {
    int y = A * ans - (ans - 1);
    if (y >= B) break;
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
while True:
    h, w = map(int, input().split())
    
    if h ==0 and w == 0:
        break
    else:
        pass
    
    for i in range(h):
        for j in range(w):
            if i % 2 != 0:
                
                if j % 2 != 0:
                    print("#", end="")
                else:
                    print(".", end="")
            else:
                
                if j % 2 != 0:
                    print(".", end="")
                else:
                    print("#", end="")
        print()
    print()


Measured memory_bytes: 7004
#include<stdio.h>
#include<string.h>
int main()
{
    char a[101],b[101];
    int i,j,c=0;
    char *p,*p1,p2,tm;

    scanf("%s",a);
    scanf("%s",b);

    for(i=0;i<strlen(a);i++)
    {

        if((strcmp(a,b))==0)
            {
                c++;
                break;
            }



        p2=a[0];

        for(j=0;a[j+1]!='\0';j++)
        {
            a[j]=a[j+1];
        }
        a[j]=p2;


    }
    if(c==0) printf("No");
    else printf("Yes");

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <cmath>

using namespace std;

int main() {
	string S;
	long long K;
	cin >> S >> K;

	char res = '1';

	for (int i = 0; i < K; i++) {
		if (S[i] != '1') {
			res = S[i];
			break;
		}
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 100000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main() {
  IN(ll,A);
  IN(ll,B);
  A %= B;
  chmin(A, B-A);
  OUT(A);
}



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

int main() {
  int N, K, D;
  cin >> N >> K;
  vector<int> V(10);
  while (cin >> D) V.at(D) = 1;
  while (N) {
    int tmp = N;
    while (tmp) {
      if (V.at(tmp % 10)) goto NG;
      tmp /= 10;
    }
    cout << N << "\n";
    return 0;
    NG: N++;
  }
}

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

int n,pos;
vector<int> pre,in,post;

void rec(int l,int r){
  if(l>=r)
    return;
  int root=pre[pos++];
  int m=distance(in.begin(),find(in.begin(),in.end(),root));
  rec(l,m);
  rec(m+1,r);
  post.push_back(root);
}

void solve(){
  pos=0;

  rec(0,pre.size());
  int i;
  for(i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<post[i];
  }
  cout<<endl;
}

int main(){
  int k;
  cin>>n;
  int i;
  for(i=0;i<n;i++){
    cin>>k;
    pre.push_back(k);
  }

  for(i=0;i<n;i++){
    cin>>k;
    in.push_back(k);
  }
  solve();

  return 0;
}



Measured memory_bytes: 3144
# -*- coding: utf-8 -*-
a = int(input())
xy = [map(int, input().split()) for _ in range(a)]
x, y = [list(i) for i in zip(*xy)]
flag = 0
b=0
for i in range(a):
    if (x[i] == y[i]):
      flag = flag+1
      if (flag ==3):
        b = 1
    else:
      flag = 0
    
if b==1:
    print("Yes")
else:
  print("No")





Measured memory_bytes: 9184
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : August 04, 2020 4:33 PM
 *    Problem Name  : C - Marks
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_c
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
#define ll long long int 
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);

    ll n,k;
    cin >> n >> k;

    ll arr[n+1];

    for(ll i=0; i<n; i++)
        cin >> arr[i];
    
    for(ll i=k; i<n; i++){
        if( arr[i-k] < arr[i] ){
            cout << "Yes" << endl;
        }

        else cout << "No" << endl;
    }

    return 0 ;
}


Measured memory_bytes: 5208
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int s[15],n,m,o,a[150][20],b[150][20],i,j,k,l,u,sum=0,max;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        for(j=1;j<=10;j++)
        scanf("%d",&a[i][j]);
    for(i=1;i<=n;i++)
        for(j=0;j<11;j++)
        scanf("%d",&b[i][j]);
    for(i=1;i<=1023;i++)
    {int p[150]={0};
        m=i;o=1;
        while(m)
        {
            s[o++]=m%2;
            m/=2;
        }
        for(j=o;j<=10;j++)
            s[j]=0;
        //for(k=1;k<=10;k++)
        //  printf("%d ",s[k]);
        //printf("\n");
        for(k=1;k<=10;k++)
        {
            if(s[k]==1)
            {
                for(l=1;l<=n;l++)
                {
                    if(a[l][k]==1)
                        p[l]++;
                }
            }
        }
        sum=0;
        for(u=1;u<=n;u++)
        sum+=b[u][p[u]];
        if(i==1)
            max=sum;
        if(sum>max)
            max=sum;
    }
    printf("%d\n",max);
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
int  n,k,a[150],ans;
bool cmp(int a,int b){
	return a>b;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
	    scanf("%d",&a[i]);
	sort(a,a+n,cmp);
	for(int i=0;i<k;i++)
	    ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
from collections import deque

N, u, v = map(int, input().split())
vec = [[] for _ in range(N)]
for _ in range(N - 1) :
  A, B = map(int, input().split())
  vec[A - 1].append(B - 1)
  vec[B - 1].append(A - 1)

du = [0] * N
pu = [-1] * N
q = [(u - 1, -1)]
while q :
  cur, pre = q.pop()
  for nex in vec[cur] :
    if nex != pre :
      du[nex] = du[cur] + 1
      pu[nex] = cur
      q.append((nex, cur))

dv = [0] * N
pv = [-1] * N
q = [(v - 1, -1)]
while q :
  cur, pre = q.pop()
  for nex in vec[cur] :
    if nex != pre :
      dv[nex] = dv[cur] + 1
      pv[nex] = cur
      q.append((nex, cur))

# du[u - 1] = 2
# dv[v - 1] = 2

ret = 0
for i, (u, v) in enumerate(zip(du, dv)) :
  if u < v or (u == v and pu[i] != pv[i]) :
    if u == v :
      ret = max(ret, u)
    else :
      ret = max(ret, v - 1)
print(ret)

Measured memory_bytes: 70764
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Action<long[], int, int> updateDP = (dp, buyPrice, sellPrice) =>
        {
            if (buyPrice > sellPrice) return;
            var benefit = sellPrice - buyPrice;
            for (int i = buyPrice; i < dp.Length; i++)
            {
                dp[i] = Max(dp[i], dp[i - buyPrice] + benefit);
            }
        };

        {
            //どんぐりi個を換金した時に得られる最大利益
            var dp = new long[n + 1];
            updateDP(dp, a[0], b[0]);
            updateDP(dp, a[1], b[1]);
            updateDP(dp, a[2], b[2]);
            n = n + (int)dp.Max();
        }

        {
            //どんぐりi個を換金した時に得られる最大利益
            var dp = new long[n + 1];
            updateDP(dp, b[0], a[0]);
            updateDP(dp, b[1], a[1]);
            updateDP(dp, b[2], a[2]);
            Console.WriteLine(n + dp.Max());
        }
    }
}

Measured memory_bytes: 208480
import sys
c=[list(map(int,l.split())) for l in sys.stdin.read().splitlines()]
for i in range(2):
  c[2-i]=[x-y for x, y in zip(c[2-i],c[1-i])]
for i in range(2):
  for j in range(3):
    c[j][2-i]-=c[j][1-i]

if c[1][1:]==c[2][1:]==[0,0]:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9136
#include<bits/stdc++.h>
#define scan($) scanf("%d",&$)
#define test() int $;scan($);while($--)
using namespace std;
int gcd(int p, int q)
{
    if(p % q == 0)
        return q;
    return gcd(q, p % q);
}

int main()
{
    int n;
    int ans =0;
    scan(n);
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            for(int k=1; k<=n; k++)
            {
                ans+=gcd(gcd(i,j),k);
            }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 3772
import java.util.Scanner;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        s+=sc.nextLine();
        System.out.println((s.substring((s.indexOf('A')),(s.lastIndexOf('Z'))).length())+1);
    }
}

Measured memory_bytes: 29732
import java.io.*;
public class Main {
    public static void main(String [] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int x= Integer.parseInt(br.readLine());
        bw.write((x >= 30 ? "Yes" : "No"));
        bw.flush();
        bw.close();
        br.close();
    }
}


Measured memory_bytes: 32688
#include<stdio.h>

int main(void){

  int W,H,x,y,r,flag;

  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

  if(x-r>=0 && y-r>=0 && x+r<=W && y+r<=H){
    printf("Yes\n");
  }else{
    printf("No\n");
  }


}



Measured memory_bytes: 2076
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int K = stdIn.nextInt();
			if(K == 0)
			{
				break;
			}
			int sum = 0;
			int n = K * (K - 1) / 2;
			for(int i = 0; i < n; ++i)
			{
				int a = stdIn.nextInt();
				sum += a;
			}
			System.out.println(sum / (K - 1));
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<utility>
#include<iomanip>
#define mod 998244853 
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long long x, m=100000000000000;
    cin >> x;
    for(int i = 1; i <= (int)(sqrt((double)(x))); i++)
    {
        if(x%i==0)
        {
            if(i+(x/i)-2 < m)
                m=i+(x/i)-2;
        }
    }
    cout <<m << '\n';
}

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

int main()
{
  int a, b;
  cin >> a;
  cin >> b;
  
  if((a + b) % 2 == 0)
  {
    cout << (a + b) / 2 << endl;
  }
  else
  {
    cout << (a + b) / 2 + 1 << endl;
  }
}

Measured memory_bytes: 256
#define z(m,n)for(;m;m--)scanf("%d",&s),x[s+n]++
x[41];main(m,n,s){for(;scanf("%d%d",&m,&n),m;printf("%d\n",s)){memset(x,0,164);z(m,0);z(n,20);for(m=21,s=0;m--;s+=m*(x[m]>x[m+20]?x[m]:x[m+20]));}return 0;}

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

int main() {
	int x, y, z;
	string s;
	cin >> x >> y >> z;
	if (x == y&&y == z)cout << '1' << endl;
	else if (x == y&&y != z)cout << '2' << endl;
	else if (x == z&&y != z)cout << '2' << endl;
	else if (z == y&&x != z)cout << '2' << endl;
	else cout << '3' << endl;	
	return 0;
}

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

namespace _001_FindingMissingCards
{
    /*
     */

    class Program
    {
        static void Main()
        {
            string line1st = Console.ReadLine();
            string []line1stSplit = line1st.Split(' ');
            int n = Convert.ToInt32(line1stSplit[0]);
            int m = Convert.ToInt32(line1stSplit[1]);
            int l = Convert.ToInt32(line1stSplit[2]);

            long[,] c = new long[n, l];
            int[,] a = new int[n, m];
            int[,] b = new int[m, l];


            for (int i = 0; i < n; i++)
            {
                string lineElement = Console.ReadLine();
                string[] lineElementSplit = lineElement.Split(' ');
                for (int j = 0; j < m; j++)
                {
                    a[i, j] = Convert.ToInt32(lineElementSplit[j]);
                }
            }
            for (int i = 0; i < m; i++)
            {
                string lineElement = Console.ReadLine();
                string[] lineElementSplit = lineElement.Split(' ');
                for (int j = 0; j < l; j++)
                {
                    b[i, j] = Convert.ToInt32(lineElementSplit[j]);
                }
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    for (int k = 0; k < m; k++)
                    {
                        c[i, j] += a[i, k] * b[k, j];
                    }
                }
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < l - 1; j++)
                {
                    Console.Write("{0} ", c[i, j]);
                }
                Console.WriteLine("{0}", c[i, l-1]);
            }


            
        }
    }
}

Measured memory_bytes: 9772
n = gets.to_i
d = gets.chomp.split
n.times do |i|
    d[i] = d[i].to_i
end

d_combinations = d.combination(2).to_a
sum = 0
d_combinations.each do |d_combi|
    sum += d_combi[0] * d_combi[1]
end

puts sum

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

#define fi first
#define se second

const int N = 100100;
const long long mod = 1e9 + 9;

using namespace std;

int n;
int d[N];
bool used[N];
vector < int > v[N];

void dfs(int x)
{
        if(used[x]){
                return;
        }
        used[x] = true;
        for(int y: v[x]){
                dfs(y);
                d[x] = max(d[x], d[y] + 1);
        }
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        int m;
        cin >> n >> m;
        for(int i = 1; i <= m; i++){
                int x, y;
                cin >> x >> y;
                v[x].push_back(y);
        }
        int res = 0;
        for(int i = 1; i <= n; i++){
                dfs(i);
                res = max(res, d[i]);
        }
        cout << res << "\n";
}



Measured memory_bytes: 8320
MOD = 10**9 + 7
MAX = 2000 + 5
fact = [1 for _ in range(MAX)]
finv = [1 for _ in range(MAX)]
for i in range(2, MAX):
    fact[i] = fact[i - 1] * i % MOD
    finv[i] = pow(fact[i], MOD-2, MOD)

def comb(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    return (fact[n] * finv[k] % MOD) * finv[n-k] % MOD

n, k = map(int, input().split())

for i in range(1, k+1):
    ans = comb(k-1, i-1) * comb(n-k+1, i) % MOD
    print(ans)


Measured memory_bytes: 42736
#include <stdio.h>

void swap(int *,int *);

int main(){
  int i,j,N,minj;
  int k=0;
  int A[100];

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

  for(i=0;i<N-1;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j] < A[minj]){
    minj=j;
      }
    }
    if(A[minj]<A[i]){
    k++;
  }
    swap(&A[i],&A[minj]);
  }

  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i<N-1){
      printf(" ");
    }
  }
  printf("\n%d\n",k);
  return 0;
}

void swap(int *x,int *y){
  int z;
  z=*x;
  *x=*y;
  *y=z;
}



Measured memory_bytes: 2104
n = gets.strip.to_i
count = 0

while line = gets do
  num = line.strip.to_i
  root_num = Math.sqrt(num).floor

  can_divide = (2..root_num).any? do |i|
    num % i == 0
  end

  if !can_divide then
    count += 1
  end
end

p count

Measured memory_bytes: 6100
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;
const ll MOD = 1000000007;

ll gcd(ll x, ll y) {
	while (y) {
		x %= y;
		swap(x, y);
	}
	return x;
}

int main() {
	ll N, M, G;
	cin >> N >> M;
	G = gcd(N, M);
	string S, T;
	cin >> S >> T;

	string ns, nt;
	for (int i = 0;i < G;i++) {
		ns += S[i * (N / G)];
		nt += T[i * (M / G)];
	}
	if (ns == nt) {
		cout << N / G * M << endl;
	}
	else {
		cout << -1 << endl;
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int pre = -1000;
  rep(i, n) {
    if(pre <= a[i]-1) {
      pre = a[i] - 1;
    } else  if(pre <= a[i]) {
      pre = a[i];
    } else {
      puts("No");
      return 0;
    }
  }
  puts("Yes");

  return 0;
}


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

int main(){
	string s,t;
	while(1){
		int cnt[2][10] = {},hit = 0,blow = 0;
		cin >> s >> t;
		if(s == "0") break;
		for(int i = 0;i < 4;i++){
			if(s[i] == t[i]) hit++;
			else{
				cnt[0][s[i] - '0']++;
				cnt[1][t[i] - '0']++;
			}
		}
		for(int i = 0;i < 10;i++){
			blow += min(cnt[0][i],cnt[1][i]);
		}
		cout << hit << " " << blow << endl;
	}
	return 0;
}

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

const int N=105;
int g[N][N];
int dist[N];
bool vis[N];
int n, ans=0;

void prim(){
    dist[0]=0;
    for(int i=0; i<n; ++i){
        int node=-1;
        for(int j=0; j<n; ++j){
            if(!vis[j] && (node==-1 || dist[j]<dist[node])) node=j;
        }
        if(node==-1) break;
        vis[node]=true;
        ans+=dist[node];
        for(int j=0; j<n; ++j) 
            if(g[node][j]!=-1) dist[j]=min(dist[j], g[node][j]);
    }
}

int main(){
    memset(dist, 0x3f, sizeof dist);
    memset(vis, 0x00, sizeof vis);
    cin>>n;
    for(int i=0; i<n; ++i)
        for(int j=0; j<n; ++j)
            cin>>g[i][j];
            
    prim();
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3116
MOD = 10 ** 9 + 7

k = int(input())
n = len(input())
s = n + k

comb_s = [1]
rest = pow(25, s, MOD)
for i in range(1, n):
    comb_s.append(comb_s[-1] * (s+1-i) * pow(i, MOD-2, MOD) % MOD)
    rest += pow(25, s-i, MOD) * comb_s[i]

print((pow(26, s, MOD) - rest) % MOD)

Measured memory_bytes: 186024
import collections

n, k = map(int, input().split())

a = list(map(int, input().split()))
c= collections.Counter(a)

length = n - c.most_common()[0][1] + 1

if length == 1:
    ans = 0
else:
    ans = (length + k - 3) // (k - 1)
    
print(ans)

Measured memory_bytes: 26712
#include <iostream>

using namespace std;

int fibo[45];

int fib(int n) {
	if (fibo[n]) return fibo[n];
	return fibo[n] = fib(n - 1) + fib(n - 2);
}

int main() {
	int n; cin >> n;
	fibo[0] = fibo[1] = 1;
	cout << fib(n) << endl;

	return 0;
}


Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();

		if(A >= 1200){
			System.out.println("ARC");
		} else if (A < 1200) {
			System.out.println("ABC");			
		}			

	}

}


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

int main()
{
	int n;
	cin >> n;
	vector<long long> a( n );
	for( int i = 0; i < n; i++ ) {
		cin >> a[i];
	}

	long long nn = *max_element( a.begin(), a.end() );
	long long half = nn / 2;
	long long half1 = half + 1;
	long long r = *min_element( a.begin(), a.end() );
	for( int i = 0; i < n; i++ ) {
		if( abs( a[i] - half ) < abs( r - half ) || nn % 2 && abs( a[i] - half1 ) < abs( r - half1 ) ) r = a[i];
	}

	cout << nn << " " << r << endl;
}


Measured memory_bytes: 4028
import java.util.Scanner;

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();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int k = sc.nextInt();

		System.out.println(e-a>k ? ":(" : "Yay!");
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define n_max int(2*1e5 +5)


int main(){
    int n;
    cin >>n;
    int ans=0;
    int A[1000];
    int tmp =100000;
    REP(i,n) cin >> A[i+1];
    A[0]=99999;
    A[n+1]=99998;
    FOR(i,1,n+1){
        if(A[i] == A[i-1]){
            A[i]=tmp;
            tmp+=1;
            ans+=1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
    if(x>y)swap(x,y);
    for(int i=x; i >= 1; i--){
        if(i == 1)return 1;
        else if( x % i  == 0 && y % i == 0)return i;
        //最大公約数、lcm = x*y/gcd 僕のVSCではgcd関数が使えませんでした(泣)だれか教えてください。
    }
}
typedef long long ll;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;




int main(){
    string s,t;
    cin >> s >> t;
    for(int i=0;i<s.length();i++){
        if(s==t){
            puts("Yes");
            return 0;
        }
        s.pb(s[0]);
        s.erase(s.begin());
    }
    puts("No");
    return 0;
}

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

class Comb:
    def __init__(self, n, mod=pow(10, 9)+7, f=True, i=False):
        self.n = n
        self.mod = mod
        self.factorial_table = None
        self.inverse_table = None
        if f: self.get_factorial()
        if i: self.get_inverse()
        
    def get_factorial(self):
        self.factorial_table = [1]*(self.n+1)
        for i in range(1, self.n+1):
            self.factorial_table[i] = self.factorial_table[i-1]*i%self.mod
        self.inverse_table = None
    
    def get_inverse(self):
        mod = self.mod
        self.inverse_table = [1]*(self.n+1)
        for i in range(self.n+1):
            self.inverse_table[i] = pow(self.factorial_table[i], -1, mod)
    
    def factorial(self, n):
        if self.factorial_table == None:
            return None
        return self.factorial_table[n]
    
    def inverse(self, n):
        if self.inverse_table == None:
            return None
        return self.inverse_table[n]   
    
    def permutation(self, n, k):
        if self.factorial_table == None:
            return None
        mod = self.mod
        if self.inverse_table == None:
            return self.factorial_table[n]*pow(self.factorial_table[n-k], -1, mod)%mod
        return self.factorial_table[n]*self.inverse_table[n-k]%mod
            
    def comb(self, n, k):
        mod = self.mod
        if self.factorial_table == None:
            res = 1
            for i in range(k):
                res *= n-i
                res *= i+1
                res %= mod
            return res
        if self.inverse_table == None:
            res = self.factorial_table[n]*pow(self.factorial_table[n-k], -1, mod)%mod\
                                    *pow(self.factorial_table[k], -1, mod)%mod
        else:
            res = self.factorial_table[n]*self.inverse_table[n-k]%mod\
                                    *self.inverse_table[k]%mod
        return res
    
    def recomb(self, n, k):
        if n+k-1 > self.n:
            return None
        return self.comb(n+k-1, k)
        


def main():
    n, m, k = map(int, input().split())
    mod = pow(10, 9) + 7
    
    comb = Comb(n*m, i=True)
    
    ans = 0
    
    for i in range(n):
        ans += (i) * (n-i) * m**2
        ans %= mod
        
    
    for i in range(m):
        ans += (i) * (m-i) * n**2
        ans %= mod
    
    
    
    ans *= comb.comb(n*m-2, k-2)
    ans %= mod
    
    print(ans)
    
    
if __name__ == "__main__":
    main()



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

const int Inf = 1e9;

int main() {
  int N, K;
  cin >> N >> K;
  int x[3*N];
  rep(i, N) x[i] = -Inf;
  rep(i, N) cin >> x[N+i];
  rep(i, N) x[2*N+i] = Inf;
  int id0 = distance(x, lower_bound(x, x+3*N, 0));
  bool flag = (x[id0] == 0);

  int ans = Inf;
  ans = min(ans, x[id0 + K-1]);
  ans = flag ? min(ans, -x[id0 - (K-1)]) : min(ans, -x[id0 - K]);
  for (int i = K-2; i >= 0; --i) {
    int tmp = 2 * x[id0 + i] - x[id0 - (K-1 - i)];
    ans = min(ans, tmp);
  }
  for (int i = K-1; i >= 1; --i) {
    int tmp = -2 * x[id0 - i] + x[id0 + (K-1 - i)];
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
int main(){
		int a,b,c;
		cin>>a>>b>>c;
		int arr [2000];
		for (int i=0;i<a;i++)arr[i]=0;
		for(int i=1;i<a;i++)
			for(int j=i+1;j<=a;j++){
				if(j<=b||i>=c){
					arr[j-i]++;
					continue;
				}
				if(i>=b&&j<=c){
					arr[min(j-i,c-b+1-j+i)]++;
					continue;
				}
				if(i<b&&j>c){
					arr[b-i+j-c+1]++;
					continue;
				}
				if(i<b&&j<=c){
					arr[b-i+min(j-b,c-b+1-j+b)]++;
					continue;
				}
				if(i>=b&&j>c){
					arr[j-c+min(c-i,c-b+1-c+i)]++;
				}
			}
		for(int i=1;i<a;i++)cout<<arr[i]<<endl;	
		return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    ll x;
    cin >> x;
    ll ans = (x/500) * 1000 + ((x%500)/5) * 5;
    cout << ans << endl; 
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ans;
  if(b<=c){
    ans=0;
  }else if(a<=c&&c<=b&&b<=d){
    ans=b-c;
  }else if(a<=c&&d<=b){
    ans=d-c;
  }else if(c<=a&&b<=d){
    ans=b-a;
  }else if(c<=a&&a<=d&&d<=b){
    ans=d-a;
  }else if(d<=a){
    ans=0;
  }
  
  cout<<ans;
    return 0;
}


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

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

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  cin >> n;

  string s[10010];
  REP(i,n){
    cin >> s[i];
  }


  int a = 0, b = 0, ab = 0;
  llong ans = 0;
  REP(i,n){
    int len = s[i].length();
    REP(j,len-1){
      if(s[i][j] == 'A' && s[i][j+1] == 'B') {ans++;}
    }
    if(s[i][0] == 'B' && s[i][len-1] == 'A'){ab++;}
    else if(s[i][0] == 'B') b++;
    else if(s[i][len-1] == 'A') a++;
  }
  //cout << ans << " "  << a << " " << b << " " << ab << endl; 
  if(a > 0 && b > 0 && ab > 0){
    a--; b--;
    ans += ab + 1;
  }else if((a > 0 && ab > 0) || (b > 0 && ab > 0)){
    if(a > 0) a--;
    else b--;
    ans += ab;
  }else if(ab > 0){
    ans += ab - 1;
  }
  ans += min(a, b);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	string res = "second";
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] % 2 == 1) {
			res = "first";
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 200005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

ll tree[4 * N];
void update(int p, ll val, int l, int r, int i)
{
	if(l <= p && p <= r)
	{
		if(l == p && p == r)
		{
			tree[i] = val;
			return;
		}
		int mid = (l + r) / 2;
		update(p, val, l, mid, 2 * i);
		update(p, val, mid + 1, r, 2 * i + 1);
		tree[i] = max(tree[2 * i], tree[2 * i + 1]); 
	}
}
ll query(int ql ,int qr, int l, int r, int i)
{
	if(ql > r || qr < l)
		return 0;
	if(ql <= l && r <= qr)
		return tree[i];
	int mid = (l + r) / 2;
	return max(query(ql, qr, l, mid, 2 * i), query(ql, qr, mid + 1, r, 2 * i + 1));
}
int main()
{
	ll ans = 0, val;
	int n, h[N], b[N];
	memset(tree, 0, sizeof(tree));
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cin >> b[i];
	}
	for (int i = 0; i < n; ++i)
	{
		val = query(1, h[i], 1, n, 1);
		ans = max(ans, val + b[i]);
		update(h[i], val + b[i], 1, n, 1);
	}
	cout << ans;
}



Measured memory_bytes: 8064
/*      Welcome to my Code      */

#include <bits/stdc++.h>
#define ll                      long long int
#define i(a,n)                  int a=n;
#define l(a,n)                  ll a=n;
#define d(a,n)                  double a=n;
#define s(a)                    string a;
#define c(a)                    ll a; cin>>a;a
#define cd(a)                   double a; cin>>a;
#define cs(a)                   string a; cin>>a;
#define ci(a)                   cin>>a;
#define co(a)                   cout<<a;
#define cos(a)                  cout<<a<<" ";
#define con(a)                  cout<<a<<endl;
#define yes                     cout<<"YES"<<endl
#define no                      cout<<"NO"<<endl
#define nl                      cout<<endl;
#define ca(arr,n)               for(ll i=0;i<n;i++) cin>>arr[i];
#define f0(i,a,n)               for(ll i=a;i>=n;i--)
#define f(i,n)                  for(ll i=0;i<n;i++)
#define f1(i,a,n)               for(ll i=a;i<n;i++)
#define lcm(a,b)                (a*b)/__gcd(a,b)
#define T                       ll t=1; cin>>t; while(t--)
#define fast                    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ret(x)                  return cout<<x,0;

using namespace std;

using namespace std;

int n;
long long ans;
long long num[25][25];
int main()
{
	cin>>n;
	while(n--)
	{
		double t;
		cin>>t;
		long long a=t*1e9+0.5;
		int n2=1,n5=1;
		while(a%2==0)
		{
			a/=2;
			n2++;
		}
		while(a%5==0)
		{
			a/=5;
			n5++;
		}
		n2=min(19,n2);
		n5=min(19,n5);
		f1(i,20-n2,20) f1(j,20-n5,20) ans+=num[i][j];
		num[n2][n5]++;
	}
	cout<<ans<<endl;
	return 0;
}

/*It's not who I am underneath, but what I do that defines me

MMMMMMMMMMMMMMMMMMMMM.                             MMMMMMMMMMMMMMMMMMMMM
 `MMMMMMMMMMMMMMMMMMMM           M\  /M           MMMMMMMMMMMMMMMMMMMM'
   `MMMMMMMMMMMMMMMMMMM          MMMMMM          MMMMMMMMMMMMMMMMMMM'
     MMMMMMMMMMMMMMMMMMM-_______MMMMMMMM_______-MMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
     .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM.
    MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
                   `MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
                          `MMMMMMMMMMMMMMMMMM'
                              `MMMMMMMMMM'
                                 MMMMMM
                                  MMMM
                                   MM
*/


Measured memory_bytes: 3648
mod=10**9+7
n=int(input())
s=list(input())
#前処理
for i in range(0,2*n,2):
    if s[i]=='W':
        s[i]='B'
    else:
        s[i]='W'

#Lの数を数えてRとマッチング
countL=0
ans=1
for i in range(2*n):
    if s[i]=='W':
        countL+=1
    else:
        ans*=countL
        if countL==0:
            print(0)
            exit()
        ans%=mod
        countL-=1
if countL!=0:
    print(0)
    exit()
# 答えはansの階乗
for i in range(1,n+1):
    ans*=i
    ans%=mod
print(ans)




Measured memory_bytes: 61680
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type node struct {
	v          int
	prev, next *node
}
type list struct {
	head, tail node
}

func newList() *list {
	nl := new(list)
	nl.head.next = &nl.tail
	nl.tail.prev = &nl.head
	return nl
}
func (ll *list) pushBack(v int) {
	nn := new(node)
	nn.v = v
	nn.next = &ll.tail
	nn.prev = ll.tail.prev
	ll.tail.prev.next = nn
	ll.tail.prev = nn
}
func (ll *list) popBack(v *int) (ret bool) {
	if ll.head.next == &ll.tail {
		ret = false
	}
	ret = true
	*v = ll.tail.prev.v
	ll.tail.prev = ll.tail.prev.prev
	ll.tail.prev.next = &ll.tail
	return
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)
	sc.Scan()
	words := strings.Split(sc.Text(), " ")
	l := newList()
	for i := 0; i < len(words); i++ {
		if words[i] == "+" || words[i] == "-" || words[i] == "*" {
			var a, b, c int
			l.popBack(&b)
			l.popBack(&a)
			// fmt.Println("i", i, "poped a", a, "poped b", b)
			switch words[i] {
			case "+":
				c = a + b
			case "-":
				c = a - b
			case "*":
				c = a * b
			}
			l.pushBack(c)
		} else {
			v, _ := strconv.Atoi(words[i])
			l.pushBack(v)
			// fmt.Println("i", i, "pushed v", v)
		}
	}
	var ans int
	l.popBack(&ans)
	fmt.Println(ans)
}



Measured memory_bytes: 1148
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>p(n); rep(i, n)cin >> p[i];
	int cnt = 0;
	rep(i, n - 1) {
		if (p[i] == i + 1) {
			cnt++;
			swap(p[i], p[i + 1]);
		}
	}
	if (p[n - 1] == n) {
		cnt++;
		swap(p[n - 1], p[n - 2]);
	}
	cout << cnt << endl;
	
	return 0;
}

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

int main() {
  string a;
  cin >> a;
  int b;
  b = a.size();
  int c = 0;
  for(int i = 0;i < b;i++){
    if(a.at(i) == 'p'){c++;}
  }
  cout << b / 2 - c << endl;
}

Measured memory_bytes: 512
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return len(divisors)


ans = 0
N = int(input())
for i in range(1, N + 1, 2):
    cnt = make_divisors(i)
    if cnt == 8:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
const int mod=998244353;
ll n,q,l,r,k;
ll num[N],all_1[N];
struct A
{
    ll l,r,num,lazy;
} a[2000005];
void f(int root,int k)
{
    a[root].lazy=k;
    a[root].num=(k*all_1[a[root].r-a[root].l+1])%mod;
}
void pushback(int root)
{
    int l=a[root].l;
    int r=a[root].r;
    ll mid=(l+r)>>1;
    if (a[root].lazy!=0)
    {
        f(root<<1,a[root].lazy);
        f(root<<1|1,a[root].lazy);
    }
    a[root].lazy=0;
}
void pushup(int root)
{
    a[root].num=(a[root<<1].num*num[a[root<<1|1].r-a[root<<1].r]+a[root<<1|1].num)%mod;
}
void buid(int l,int r,int root)
{
    a[root].l=l;
    a[root].r=r;
    if(l==r)
    {
        a[root].num=1;
        return ;
    }
    ll mid=(l+r)>>1;
    buid(l,mid,root<<1);
    buid(mid+1,r,root<<1|1);
    pushup(root);
}
void update(ll l,ll r,ll root,ll d)
{
    pushback(root);
    if(a[root].r<=r&&a[root].l>=l)
    {
        f(root,d);
        return ;
    }
    ll mid=(a[root].l+a[root].r)>>1;
    if(mid>=l)
    {
        update(l,r,root<<1,d);
    }
    if(mid<r)
    {
        update(l,r,root<<1|1,d);
    }
    pushup(root);
}
ll quary(ll l,ll r,ll root)
{
    pushback(root);
    if(a[root].l>=l&&a[root].r<=r)
    {
        return a[root].num;
    }
    int mid=(a[root].r+a[root].l)/2;
    ll lso=0,rso=0;
    if(mid>=l)
    {
        lso=quary(l,r,root<<1);
    }
    if(mid<r)
    {
        rso=quary(l,r,root<<1|1);
    }
    ll sum=(lso*(n-a[root<<1].r)+rso)%mod;
    return sum;
}
int main()
{
    cin>>n>>q;
    num[0]=1;
    for (int i=1; i<=n; i++)
        num[i]=(num[i-1]*10)%mod;
    all_1[1]=1;
    for (int i=2; i<=n; i++)
        all_1[i]=(all_1[i-1]*10+1)%mod;
    buid(1,n,1);
    while (q--)
    {
        cin>>l>>r>>k;
        update(l,r,1,k);
        cout<<quary(1,n,1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 39544
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int a,b;
  cin >> a >> b;
  cout << (a-1)*(b-1) << endl;
}

Measured memory_bytes: 384
def find_pos(board, n)
  @h.times do |y|
    @w.times do |x|
      return [x, y] if board[y][x] == n
    end
  end
end

def in_check(x, y)
  0 <= x && x < @w && 0 <= y && y < @h
end

def can_visit(cx, cy, mx, my, board)
  visited = @h.times.map{ [false] * @w }
  visited[my][mx] = true
  queue = [[mx, my]]
  until queue.empty?
    x, y = queue.shift
    @dir.each do |dx, dy|
      xx = x + dx; yy = y + dy
      if in_check(xx, yy) && !visited[yy][xx] &&
        board[yy][xx] != 1 && !(cx == xx && cy == yy)
        queue << [xx, yy]
        visited[yy][xx] = true
      end
    end
  end
  visited
end

def move(cx, cy, mx, my, board)
  move_pos = can_visit(cx, cy, mx, my, board)
  @dir.each_with_index.map { |(dx, dy), i|
    x = cx + dx; y = cy + dy
    i if in_check(x, y) && move_pos[y][x]
  }.compact
end

def solve(cx, cy, mx, my, board)
  used = @h.times.map{ @w.times.map{ [false] * 4 } }
  queue = []
  move(cx, cy, mx, my, board).each do |i|
    queue << [cx, cy, i, 0]
    used[cy][cx][i] = true
  end
  until queue.empty?
    x, y, i, n = queue.shift
    return n if x == @gx && y == @gy
    move(x, y, x + @dir[i][0], y + @dir[i][1], board).each do |ii|
      xx = x + @dir[(ii + 2) % 4][0]
      yy = y + @dir[(ii + 2) % 4][1]
      if in_check(xx, yy) && !used[yy][xx][ii] && board[yy][xx] != 1
        queue << [xx, yy, ii, n + 1]
        used[yy][xx][ii] = true
      end
    end
  end
  -1
end

@dir = [[-1, 0], [0, 1], [1, 0], [0, -1]]
loop do
  @w, @h = gets.split.map(&:to_i)
  break if @w == 0
  board = @h.times.map{ gets.split.map(&:to_i) }

  cx, cy = find_pos(board, 2)
  @gx, @gy = find_pos(board, 3)
  mx, my = find_pos(board, 4)

  puts solve(cx, cy, mx, my, board)
end

Measured memory_bytes: 8904
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/05/02.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC167
//
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const int MOD = 1000000007;
//#define __DBG__



void solve(void){
  
  string S, T;
  
  cin >> S >> T;
  
  string A = T.substr(0,S.size());
  
  if(S.size()+1==T.size() && A == S){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return;
}



#define TESTCASES 1

int main() {


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

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}




Measured memory_bytes: 3652
n=int(input())
ar=list(map(int,input().split()))
li=[]
bo=True
for i in range(n-1):
	if bo and ar[i+1]>=ar[i]:
		li.append(ar[i])
		bo=False
	elif not bo and ar[i]>ar[i+1]:
		li.append(ar[i])
		bo=True
if len(li)==0:
	print(1000)
	exit()
if bo and li[-1]==ar[n-2]:
	if ar[n-1]>ar[n-2]:
		li.pop()
		li.append(ar[n-1])
if not bo:
	li.append(ar[-1])
s=1000
l=len(li)
for i in range(0,l,2):
		a=li[i]
		b=li[i+1]
		x=s//a
		r=s%a
		s=b*x+r
print(s)
		

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  
  int count = 0;

  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
    
  while(true){
    bool exist_odd = false;
    
    for(int i=0; i<N; i++){
      if(A.at(i)%2 != 0)
        exist_odd = true;
    }
    if(exist_odd){
      break;
    }
    for(int i=0; i<N; i++){
        A.at(i) /= 2;
    }
    
    count++;
  }
  
  cout << count <<endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for (int64_t i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    ll a,v,b,w,t; cin>>a>>v>>b>>w>>t;
    if(v<=w){
        cout<<"NO"<<endl;
        return 0;
    }
    a=abs(a-b);
    v=v-w;
    if(a<=v*t) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3596