akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

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

Measured memory_bytes: 3756
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
using namespace std;
int main(){
  long long n,k;
  cin >> n >> k;
  long long a=n/k, b=a+1;
  cout << min(n%k,k*b-n) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
constexpr ll mod = 1000000007;

class uft {
private:
    int p[100010], c[100010];
    queue<int> q;
public:
    uft() {
        for (int i = 0; i < 100010; i++) {
            p[i] = -1;
            c[i] = 1;
        }
    }

    int root(int n) {
        int d = n;
        while (p[d] != -1) {
            q.push(d);
            d = p[d];
        }
        while (!q.empty()) {
            p[q.front()] = d;
            q.pop();
        }
        return d;
    }

    void un(int a, int b) {
        if (root(a) != root(b)) {
            c[root(b)] += c[root(a)];
            p[root(a)] = root(b);
        }
    }

    int sz(int a) {
        return c[root(a)];
    }

    bool fi(int a, int b) {
        return root(a) == root(b);
    }
};

uft t;

int main() {
    int n, m, k, c[100010];
    cin >> n >> m >> k;
    vector<pair<int, int>> ab(m), cd(k);
    for (auto &e:ab) cin >> e.first >> e.second;
    for (auto &e:cd) cin >> e.first >> e.second;
    for (auto &e:ab) t.un(e.first, e.second);
    for (int i = 1; i <= n; i++) c[i] = t.sz(i);
    for (auto &e:ab) {
        if (t.fi(e.first, e.second)) {
            c[e.first]--;
            c[e.second]--;
        }
    }
    for (auto &e:cd) {
        if (t.fi(e.first, e.second)) {
            c[e.first]--;
            c[e.second]--;
        }
    }
    for (int i = 1; i <= n; i++) cout << c[i] - 1 << ' ';
    cout << endl;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

LL gcd(LL x,LL y)
{
    return y==0?x:gcd(y,x%y);
}

int main()
{
    LL n=read(),m=read();
    bool ok=true;
    string s,t;
    cin>>s>>t;
    LL l=n/gcd(n,m)*m;
    map<LL,LL> mp;
    for(int i=0;i<n;i++){
        mp[i*l/n+1]=s[i]-'a'+1;
    }
    for(int i=0;i<m;i++){
        if(mp[i*l/m+1]==t[i]-'a'+1||mp[i*l/m+1]==0)continue;
        else{
            ok=false;break;
        }
    }
    if(!ok)puts("-1");
    else printf("%lld\n",l);
    return 0;
}


Measured memory_bytes: 10880
#include <iostream>
#include <math.h>
#include <list>

int main()
{
	std::list<int> n;
	n.push_back(2);
	int A;
	int N=3;
	int NS;
	int B;

	std::cin >> A;

	if (A == 2) {
		B = 2;
	}
	else {
		do {
			NS = sqrt(N);
			for (auto itr = n.begin(); itr != n.end(); ++itr) {
				if (N % *itr == 0) {
					break;
				}
				if (*itr == n.back()) {
					n.push_back(N);
					break;
				}
			}
			N++;
		} while (n.back() < A);
		B = n.back();
	}

    std::cout << B;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N,D,ans;
  cin>>N>>D;
  ans=(N-1)/(2*D+1);
  cout<<ans+1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    double D;
    cin >> N >> D;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        double X, Y;
        cin >> X >> Y;
        double d = sqrt(X * X + Y * Y);
        if(d <= D) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin>>N;
long double sum=0.0,num;
string name;
for(int i=0;i<N;i++){
    cin>>num>>name;
    if(name=="JPY")sum+=num;
    else sum+=((380000.0*num)/1.0);
}
cout<<sum;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
long long gcd(long long a,long long b){
	if(a<b){
		long long temp =a;
		a=b;
		b=temp;
	}
	long long r=a%b;
	while (r!=0){
		a=b;
		b=r;
		r=a%b;
	}
	return b;
}
int main(){
	long long n,m;
	cin >> n>>m;
	string s,t;
	cin >> s>>t;
	long long l,a,x,y;
	a=gcd(n,m);
	//l=(n*m)/a;
	//x=n/a;
	//y=m/a;
	bool ans=1;
	for (long long i=0;i<a;i++){
		//long long c=n/a*i,d=m/a*i;
	if(s[n/a*i]!=t[m/a*i])ans=0;
	}
	if(ans==1)cout << (n*m)/a<<endl;
	else cout << "-1"<<endl;
}
	


Measured memory_bytes: 512
quit() = exit(0)
in_1() = parse(Int, readline())
in_a() = [parse(Int,s) for s in split(readline())]
in_t() = (in_a()...,)
yesno(b) = b ? "Yes" : "No"

function main()
  N, K = in_a()
  ans = 0
  while N > 0
    ans += 1
    N = div(N, K)
  end
  ans |> println
end

isempty(ARGS) && main()


Measured memory_bytes: 110588
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int mod=998244353;
ll g[10005],inv[10005],F[10005];
int f[10005][10005];
ll quick_pow(ll a,ll b){
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1) ans=ans*a%mod;
	return ans;
}
char a[10005],b[10005];
int n,m;
int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
ll C(int n,int m){
	return F[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	scanf("%s%s",a+1,b+1);
	n=strlen(a+1);
	inv[0]=F[0]=1;
	for(int i=1;i<=n;i++) F[i]=F[i-1]*i%mod,inv[i]=quick_pow(F[i],mod-2);
	for(int i=1;i<=n;i++) if(a[i]=='1'&&b[i]=='1') m++;
	int o=n;n=0;
	for(int i=1;i<=o;i++) if(a[i]=='1') n++;
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		f[i][0]=1;
		for(int p=1;p<i&&p<=m;p++){
			f[i][p]=add(f[i-1][p],1LL*f[i-1][p-1]*(i-p)%mod);
		}
	}
	g[0]=1;
	for(int i=1;i<=n;i++){
		for(int p=0;p<i;p++) g[i]=(g[i]+g[p]*inv[p])%mod;
		g[i]=g[i]*F[i-1]%mod;
	}
	ll ans=0;
	for(int i=0;i<=m;i++){
		ll sum=C(m,i)*g[i]%mod;
		ans=(sum*f[n-i][m-i]%mod*F[n-m]%mod*F[n-m]%mod*F[m-i]%mod*F[i]%mod*C(n,i)+ans)%mod;
	}
	printf("%lld",ans);
	return 0;
}

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

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

#define ll long long
#define vl vector<ll>
#define vll vector<vl>
#define P pair<ll, int>

const int INF = 1e9;
const long double pi=3.14159265358979323846;
const ll mod = 998244353;

#define E pair<int, ll>

#define pb push_back

vector<int> e[100010];

int a[100010], b[100010];

ll sum[100010];
int p[100010];

void dfs(int from)
{
	rep(i, e[from].size())
	{
		int to=e[from][i];
		if(to!=p[from])
		{
			dfs(to);
			sum[from]+=sum[to];
		}
	}
	sum[from]+=(ll)a[from];
}

int main() {
	int n;
	cin >> n;
	int aa, bb;
	rep(i, n-1)
	{
		cin >> aa >> bb;
		aa--; bb--;
		e[aa].pb(bb); e[bb].pb(aa);
	}
	bool done[100010]={};
	done[0]=true;
	queue<int> q;
	q.push(0);
	while(!q.empty())
	{
		int from=q.front();
		q.pop();
		rep(i, e[from].size())
		{
			int to=e[from][i];
			if(!done[to])
			{
				done[to]=true;
				q.push(to);
				p[to]=from;
			}
		}
	}

	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) a[i]=(b[i]-a[i]);

	dfs(0);
	//rep(i, n) cout << sum[i] << endl;

	ll ans[100010];
	ans[0]=0;
	rep(i, n) done[i]=false;
	done[0]=true;
	q.push(0);
	while(!q.empty())
	{
		int from=q.front();
		q.pop();
		rep(i, e[from].size())
		{
			int to=e[from][i];
			if(!done[to])
			{
				done[to]=true;
				q.push(to);
				ans[to]=ans[from]-sum[to];
			}
		}
	}
	//rep(i, n) cout << ans[i] << endl;
	sort(ans, ans+n);
	rep(i, n-1) ans[i+1]+=ans[i];
	cout << ans[n-1]-n*ans[0] << endl;
	return 0;
}


Measured memory_bytes: 17168
Module _20190421

    Sub Main()

        Dim sRead As String = Console.ReadLine()

        Select Case sRead
            Case "A"
                Console.WriteLine("T")
            Case "T"
                Console.WriteLine("A")
            Case "C"
                Console.WriteLine("G")
            Case "G"
                Console.WriteLine("C")
        End Select

    End Sub

End Module

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

using namespace std;

#define ll long long
#define REP(i, n) for(int i=0; i < (int)(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)

string judge(string A, string B){
    REP(i, A.length()){
        if(A[i] > B[i])
            return "GREATER";
        else if(A[i] < B[i])
            return "LESS";
    }
    return "EQUAL";
}

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

    if(A.length() > B.length())
        cout << "GREATER" << endl;
    else if(A.length()<B.length())
        cout << "LESS" << endl;
    else 
        cout << judge(A, B) <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b,aa[110000],ab[110000],cnt=0;
double d;
string s,ss;
signed main()
{
	cin>>a;
	rep(i,a){
		cin>>aa[i];
	}
	rep(i,a){
		cin>>ab[i];
		if(aa[i]-ab[i]>0){
			cnt+=aa[i]-ab[i];
		}
	}
	cout<<cnt;
}

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

int main(){
    int n;
    cin>>n;
    int b[n],ans=0;
    for(int i=0;i<n-1;i++){
        cin>>b[i];
    }
    ans+=b[0]+b[n-2];
    for(int i=0;i<n-2;i++){
        ans+=min(b[i],b[i+1]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

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

    int m;
    scanf("%d",&m);
    int px[m][2];
    for(int i=0;i<m;i++){
        for(int j=0;j<2;j++){
            scanf("%d",&px[i][j]);
        }
    }

    for(int i=0;i<m;i++){
        int sum=0;
        for(int j=0;j<n;j++){
            if(px[i][0]==j+1){
                sum+=px[i][1];
            }else{
                sum+=t[j];
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');
    cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble;
    int n;
    cin>>n;
    int cnt=0;
    int f=0;
    rep(i,0,n){
        int x,y;
        cin>>x>>y;
        if(x==y)
            cnt++;
        else cnt=0;
        if(cnt>2)f=1;
    }
    if(f)cout<<"Yes";
    else cout<<"No";
    return 0;
}



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

int main() {
	int a,b;
	std::cin >> a >> b;
	if(a < 10 and b < 10){
	    std::cout << a*b << std::endl;
	}else{
	    std::cout << "-1" << std::endl;
	}
	return 0;
}

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

using namespace std;

int main(){
    long long x,y;
    int n,t,a;
    scanf("%d",&n);
    scanf("%lld %lld",&x,&y);
    for (int i=1;i<n;i++) {
        scanf("%d %d",&t,&a);
        if (x<=t && y<=a) {
            x=t;
            y=a;
        } else {
            long long tk=t*max(x/t,y/a);
            long long ak=a*max(x/t,y/a);
            x=t*max((x+t-1)/t,(y+a-1)/a);
            y=a*max((x+t-1)/t,(y+a-1)/a);
//            for(int j=0;;j++) {
//                if (tk+(t*j)>=x && ak+(a*j)>=y) {
//                    x=tk+(t*j);
//                    y=ak+(a*j);
//                    break;
//                }
//            }
        }
    }
    printf("%lld\n",x+y);
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    x = int(args[0])
    k = 1
    y = x
    while y % 360 != 0:
        y = y+x
        k += 1
    return str(k)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 9188
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dp = [0] * (n + 1)

for i in range(n):
    if a[i] >= b[i]:
        dp[i + 1] = dp[i] + b[i]
        a[i] -= b[i]
    else:
        if a[i] + a[i + 1] > b[i]:
            dp[i + 1] = dp[i] + b[i]
        else:
            dp[i + 1] = dp[i] + a[i] + a[i + 1]
        a[i + 1] = max(a[i] + a[i + 1] - b[i], 0)

print(dp[-1])


Measured memory_bytes: 19004
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	cnt := 0
  for i := 0; i < len(s); i++ {
		if s[i] == 'R' {
			cnt ++
		}
	}

	if s == "RSR" {
		fmt.Println(1)
	} else {
		fmt.Println(cnt)
	}
}


Measured memory_bytes: 1768
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n,m;
  cin >> n >> m;
  ll MN=0,MX=INF;
  rep(i,m){
    ll a,b;
    cin >> a >> b;
    MN=max(MN,a),MX=min(MX,b);
  }
  cout << max((ll)0,MX-MN+1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
#define mod 1000000007;
using namespace std;

int main(){
    int N,A,B;
    cin  >> N >> A >> B;
    cout << min(N*A,B) <<  endl;

    return 0;
}



Measured memory_bytes: 888
n,m=map(int,input().split())
c=list(map(int,input().split()))

c.sort()

dp=[[500000]*(n+1) for i in range(m)]

for ni in range(0,n+1):
    dp[0][ni]=ni

for mi in range(0,m-1):
    for ni in range(n+1):
        if c[mi+1]>ni:
            dp[mi+1][ni]=dp[mi][ni]
        else:
            dp[mi+1][ni]=min(dp[mi+1][ni-c[mi+1]]+1,dp[mi][ni])
#    print(dp[mi])

print(dp[m-1][n])            


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

using namespace std;

int main(){
  double n,k; cin >> n >> k;
  //i+1はサイコロの目
  double ans=0;
  for(int i=0;i<n;i++){
    //j+1は表が出る回数
    long long score=i+1;
    double a=1.0;
    if(score<k){  
      for(int j=0;j<k;j++){
        score *=2;
        a /=2.0;
        if(score>=k){
          break;
        }
      }
    }
    ans+=a/(n*1.0);
  }
  cout << fixed << setprecision(20);
  cout << ans << endl;
}


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

using namespace std;
typedef long long LL;

int main(){
  string S;
  cin >> S;
  int N=S.size();
  S.push_back(' ');
  vector<int> ans(N);
  int Rnum=0, Lnum=0;
  int rec=-1;
  rep(i,N){
    if(rec!=-1&&S[i]=='L') Lnum++;
    if(rec!=-1&&(S[i]=='R'||i==N-1)){
      ans[rec]+=(Rnum+1)/2+Lnum/2;
      ans[rec+1]+=Rnum/2+(Lnum+1)/2;
      Rnum=0, Lnum=0;
      rec=-1;
    }
    if(S[i]=='R') Rnum++;
    if(S[i]=='R'&&S[i+1]=='L') rec=i;
  }
  rep(i,N-1) cout << ans[i] << " ";
  cout << ans[N-1] << endl;

  return 0;
}


Measured memory_bytes: 1024
public class Main {

	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);

		char a = sc.next().charAt(0);
		char b = sc.next().charAt(0);


		if (a == 'H') {
			if (b == 'H') {
				System.out.println('H');
			}else {
				System.out.println('D');
			}
		}else {
			if (b == 'H') {
				System.out.println('D');
			} else {
				System.out.println('H');
			}
		}

	}
}


Measured memory_bytes: 19924
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	string S=in<string>();

	int si,f,s;
	sscanf(S.c_str(),"%d",&si);
	f = si/100;
	s = si%100;
	auto check=[](int y,int m){
		if(m<1 || m>12) return false;
		return true;
	};

	int flag=0;
	flag += check(f,s) ? 1 : 0;
	flag += check(s,f) ? 10 : 0;
	switch(flag){
	case 0:
		cout << "NA" << endl;
		return 0;
	case 1:
		cout << "YYMM" << endl;
		return 0;
	case 10:
		cout << "MMYY" << endl;
		return 0;
	case 11:
		cout << "AMBIGUOUS" << endl;
		return 0;
	}
	return 0;
}


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

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

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

set<int> ms;
int main(){
    int n, a;
    cin >> n;
    for(int i=0;i<n;i++) cin >> a, ms.insert(a);
    if(sz(ms) == n) cout << "YES\n";
    else cout << "NO\n";
}

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

int main()
{
  string str1, str2, str3[1000];
  cin >> str1 >> str2;

  for (int i = 0; i < str1.size(); i++)
  {
    if (i != str2.size())
    {
      cout << str1[i];
      cout << str2[i];
    }
    else
    {
      cout << str1[i];
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner stdIn=new Scanner(System.in);

        String S=stdIn.next();
        String B="ABC";
        String R="ARC";

        if(S.equals(B)){
            System.out.println(R);
            
        }
        else if(S.equals(R)){
            System.out.println(B);
            
        }
        
        
    }

}

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

int main(){
    string card;
    int h;
    int n;


    
    while(cin >> card){
        if(card == "-")break;

        cin >> n;

        for(int i=0;i<n;i++){
            cin >> h;
            string tmp = card.substr(0, h);
            card.erase(0, h);
            card += tmp;
        }
        cout << card << endl;
    }
    return 0;
}


Measured memory_bytes: 3148
def passable(road):
    n=len(road)
    for i in range(n-1):
        block=road[i:i+2]
        if block=='##':
            return False
    return True

def blank(road):
    n=len(road)
    for i in range(1,n-1):
        block=road[i-1:i+2]
        if block=='...':
            return True
    return False

def judge(A,B,C,D,S):
    if C<D:
        return passable(S[A:C+1]) and passable(S[B:D+1])
    else:
        return passable(S[A:C+1]) and passable(S[B:D+1]) and blank(S[B-1:D+2])
N,A,B,C,D=map(int,input().split())
S=input()
if judge(A-1,B-1,C-1,D-1,S):
    print('Yes')
else:
    print('No')

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

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

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

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

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

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

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

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

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


int main(){

    int a,b;
    IN a >> b;
    P(max(max(a+b,a-b),a*b));
    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() {
  int H, N;
  cin >> H >> N;

  int A;
  rep(i, N) {
    cin >> A;
    H -= A;
    if (H <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int euclid(int a, int b){
  int r = a%b;
  if(r == 0) return b;
  else euclid(b,a%b);
}

int main(){
  int a,b,gcd;

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

  if(a >= b) gcd = euclid(a,b);
  else gcd = euclid(b,a);

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

  return 0;
}





Measured memory_bytes: 2752
//
// Created by ?????°?????? on 2016/05/15.
//

#include <iostream>
#include <queue>
using namespace std;
const int N = 100;
const int INFTY = (1<<21);

int n,M[N][N];
int d[N]; //?????¢

void bfs(int s){
    queue<int> q;
    q.push(s);
    for (int i = 0; i < n ; ++i) d[i] = INFTY;
    d[s] = 0;
    int u;
    while(! q.empty()){
        u = q.front(); q.pop();
        for (int v = 0; v < n ; ++v) {
            if(M[u][v] == 0) continue;
            if(d[v] != INFTY) continue;
            d[v] = d[u] +1;
            q.push(v);
        }
    }
    for (int i = 0; i < n ; ++i) {
        cout << i +1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
    }
}

int main(){
    int u,v,k;
    for (int i = 0; i < n ; ++i) {
        for (int j = 0; j < n ; ++j) {
            M[i][j] = 0;
        }
    }
    cin >> n;
    for (int i = 0; i < n ; ++i) {
        cin >> u >> k;
        u --;
        for (int j = 0; j < k ; ++j) {
            cin >> v;
            v --;
            M[u][v] = 1;
        }
    }
    bfs(0);
    return 0;
}

Measured memory_bytes: 1240
import math
n=int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    C,S,F=map(int,input().split())
    c.append(C)
    s.append(S)
    f.append(F)


for j in range(n-1):
    t=s[j]
    for i in range(j,n-1):

        if t<=s[i]:
            t=s[i]+c[i]
        else:
            k=t-s[i]
            t=s[i]+math.ceil(k/f[i])*f[i]+c[i]
    print( t)

print(0)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  int N;
  scanf("%d", &N);
  float a[N];
  for (int i = 0; i < N; ++i) {
    scanf("%f", &a[i]);
  }

  sort(a,a+N);

  float ans = a[0];

  FOR(i,0,N-2){
      ans = (ans+a[i+1])/2;
  }

  cout << ans << endl;



}



Measured memory_bytes: 256
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e5 + 211;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, a[N], b[N], l, r;

main () {
	cin >> n;
	for (int i = 1; i <= n; ++i) 
		cin >> a[i] >> b[i];
	

	sort(a + 1, a + 1 + n);
	sort(b + 1, b + 1 + n);
	int l = (n & 1) ? a[(n + 1) / 2] : (a[n / 2] + a[n / 2 + 1]), r = (n & 1) ? b[(n + 1) / 2] : b[n / 2] + b[n / 2 + 1];

	cout << r - l + 1 << endl;
}

                                                                                   	



Measured memory_bytes: 6768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
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;}

int main(){
  int N, M; cin >> N >> M;
  vector<int> A(M); rep(i,M) cin >> A[i];
  ll sum = 0;
  rep(i,M) sum += A[i];
  if(N<sum) cout << -1 << endl;
  else cout << N-sum << endl;

  return 0;
}


Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll D;
    cin >> D;
    vl c(26);
    rep(i, 26){
        cin >> c[i];
    }
    vll s(D, vl(26));
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }

    ll v = 0;
    vl last(26, -1);
    rep(d, D){
        ll t;
        cin >> t; t--;
        v += s[d][t];
        last[t] = d;
        rep(i, 26){
            v -= c[i] * (d - last[i]);
        }
        cout << v << endl;
    }
}

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

int N;
bool ada = false;

int main (){
    cin >> N;
    for(int i=1; i<=9; i++) {
        for(int j=1; j<=9; j++) {
            if(i*j ==N) {
                ada = true;
            }
        }
    }
    if(ada) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

//kopa

Measured memory_bytes: 3636
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

set<ll> S1, S2, S3;
ll A, B;

int main() {
	cin >> A >> B;
	for(int i = 1; i <= sqrt(A); i++) {
		if(A % i == 0) {
			S1.insert(i);
			S1.insert(A / i);
		}
	}
	for(int i = 1; i <= sqrt(B); i++) {
		if(B % i == 0) {
			S2.insert(i);
			S2.insert(B / i);
		}
	}
	set<ll> :: iterator itr, itr1;
	for(itr = S1.begin(); itr != S1.end(); itr++) {
		if(S2.find(*itr) != S2.end()) {
			S3.insert(*itr);
		}
	}
	ll cnt = 0;
	for(itr1 = S3.begin(); itr1 != S3.end(); itr1++) {
		int flag = 0;
		for(int j = 2; j <= sqrt(*itr1); j++) {
			if(*itr1 % j == 0) {
				flag = 1;
			}
		}
		if(!flag) {
			cnt++;
		}
	}
	printf("%lld\n", cnt);
 	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 1152
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $a = array_map('intval', explode(" ", trim(fgets(STDIN))));

  $avg = round(array_sum($a) / $n);

  $ans = 0;
  for ($i=0; $i<$n; $i++) {
    $ans += ($a[$i] - $avg)*($a[$i] - $avg);
  }
echo $ans;

Measured memory_bytes: 16176
N=int(input())
s=dict()
for _ in range(N):
    S=input()
    if S not in s:
        s[S]=0
    s[S]+=1
M=int(input())
for _ in range(M):
    t=input()
    if t in s:
        s[t]-=1
print(max(max(0,x) for x in s.values()))


Measured memory_bytes: 9168
import numpy as np

n = int(input())
s = input()

blacks = [0]
count = 0

for ele in s:
	if ele == '#':
		count += 1
	blacks.append(count)

whites = [0]
count = 0

for ele in s[::-1]:
	if ele == '.':
		count += 1
	whites.append(count)
#print(blacks)
#print(whites)

blacks = np.array(blacks)
whites = np.array(list(reversed(whites)))

totals = np.add(blacks, whites)
#print(totals)

print(min(totals))

Measured memory_bytes: 32784
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	int fg[n+1];
	int fg2[n+1];
	memset(fg,0,sizeof(fg));
	memset(fg2,0,sizeof(fg2));
	int sum1[n+1],sum2=0,sum3=0;
	memset(sum1,0,sizeof(sum1));
	while(m--){
		int a;
		string s;
		cin >> a >> s;
		if(s=="WA"){
			if(fg[a]==0&&fg2[a]==0){
				sum1[a]++;
			}
		}
		else{
			if(fg2[a]==0){
				sum2++;
				sum3+=sum1[a];
				fg2[a]=1;
			}
		}
	}
	cout << sum2 << " " << sum3 << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i]--;
    b[a[i]]++;
  }
  sort(b.begin(), b.end());
  ll ans = 0;
  for (int i = 0; i < n - k; ++i) {
    ans += b[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
// AOJ DSL_2_A Range Minimum Query (RMQ)
// 2018.5.5 bal4u

#include <stdio.h>
#include <stdlib.h>

#define INF 0x7fffffff

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];
	char inf[11] = "2147483647";

	if (!n) pc('0');
	else if (n == INF) for (i = 0; i < 10; i++) pc(inf[i]);
	else {
		i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}

// セグメント木の初期化：配列の確保と初期値による初期化
int seg[1<<18]; int sz;

void segtree(int n, int init_val)
{
	int i;

	sz = 1; while (sz < n) sz <<= 1;
	n = sz << 1;
//	seg = malloc(n << 2);
	for (i = 0; i < n; i++) seg[i] = init_val;
}

// k番目（0-index）の値を v に変更
void update(int k, int v)
{
	int p;

	k += sz - 1;
	seg[k] = v;
	while (k > 0) {
		if (!(k & 1)) k--;
		p = k, k >>= 1;
		v = seg[p++]; if (v > seg[p]) v = seg[p];
		seg[k] = v;
	}
}

int query2(int a, int b, int k, int l, int r) 
{
	int m, lmin, rmin;

	if (r <= a || b <= l) return INF;
    if (a <= l && r <= b) return seg[k];
	k <<= 1, m = (l+r) >> 1;
    lmin = query2(a, b, k+1, l, m);
    rmin = query2(a, b, k+2, m, r);
	if (lmin > rmin) lmin = rmin;
    return lmin; 
}

// 空間 [a, b] 内の最小値
int range_min_query(int a, int b)
{
	return query2(a, b+1, 0, 0, sz);
}


int main()
{
	int n, q, op, x, y;

	n = in(), q = in();
	segtree(n, INF);

	while (q--) {
		op = in(), x = in(), y = in();
		if (op) out(range_min_query(x, y));
		else update(x, y);
	}
	return 0;
}



Measured memory_bytes: 2584
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(a) (a).begin(), (a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x, 0, sizeof(x))
#define MINF(x) memset(x, 0x3f, sizeof(x))
#define MMINUS(a) memset(a, 0xff, sizeof(a))
#define ten(n) ((int)1e##n)

const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double EPS = 1.0 / INF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

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

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

using namespace std;

//===================================== template =========================================================

int main() {
    cin.tie(nullptr); ios_base::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> V(N); REP(i, N) cin >> V[i];
    vector<int> LS(N, 0); 
    REP(i, N) {
        if (i == 0) LS[i] = abs(V[i]);
        else LS[i] = LS[i-1] + abs(V[i] - V[i-1]);
    }
    reverse(ALL(V));
    vector<int> RS(N, 0);
    REP(i, N) {
        if (i == 0) RS[i] = abs(V[i]);
        else RS[i] = RS[i-1] + abs(V[i] - V[i-1]);
    }
    reverse(ALL(RS));
    reverse(ALL(V));
    REP(i, N) {
        if (i == 0) { cout << abs(V[1]) + RS[1] << endl; continue; }
        if (i == N-1) { cout << abs(V[N-2]) + LS[N-2] << endl; continue; }
        cout << LS[i-1] + abs(V[i+1] - V[i-1]) + RS[i+1] << endl;
    }
}


Measured memory_bytes: 2432
a,b=['light fly', 'fly', 'bantam', 'feather', 'light', 'light welter','welter', 'light middle', 'middle', 'light heavy', 'heavy'],[48, 51, 54, 57, 60, 64, 69, 75, 81, 91]
while 1:
    try:
        c=float(input())
    except:break
    for i in range(10):
        if c<=b[i]:
            print(a[i])
            break
    else: print(a[10])


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001
#define MOD ((ll)1e9 + 7)


int main(){
  cin.sync_with_stdio(false);
  ll n;
  cin >> n;

  ll in = 1, ans = 1, cnt = -1;
  rep(i, n) {
    ll tmp;
    cin >> tmp;
    if (in > tmp) {
      ans *= (in / 2) + 1;
      ans %= MOD;
      cnt++;
    } else {
      in += 2;
    }
  }

  repl(i, 2, n - cnt) {
    ans *= i;
    ans %= MOD;
  }

  print(ans);

  return 0;
}

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

vector<int> dh = {1, 0, -1, 0};
vector<int> dw = {0, 1, 0, -1};

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> field(h);
    for (int i = 0; i < h; i++) {
        cin >> field[i];
    }

    vector<vector<bool>> seen(h, vector<bool>(w, false));
    queue<pair<int, int>> to_visit;
    vector<vector<int>> dist(h, vector<int>(w, -1));


    to_visit.push(make_pair(0, 0));
    seen[0][0] = true;
    dist[0][0] = 0;
    while (to_visit.empty() == false) {
        pair<int, int> cur_pos = to_visit.front(); to_visit.pop();
        int cur_h = cur_pos.first;
        int cur_w = cur_pos.second;
        for (int i = 0; i < 4; i++) {
            int next_h = cur_h + dh[i];
            int next_w = cur_w + dw[i];
            if (next_h < 0 || next_h >= h || next_w < 0 || next_w >= w) {
                continue;
            }
            else if (field[next_h][next_w] == '#' || seen[next_h][next_w] == true) {
                continue;
            }
            else {
                to_visit.push(make_pair(next_h, next_w));
                seen[next_h][next_w] = true;
                dist[next_h][next_w] = dist[cur_h][cur_w] + 1;
            }
        }
    }

    if (dist[h - 1][w - 1] == -1) {
        cout << -1 << endl;
        return 0;
    }
    else {
        int score = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (field[i][j] == '.') {
                    score++;
                }
            }
        }

        int ans = 0;
        ans = score - dist[h - 1][w - 1] - 1;

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long int
#define pb push_back
#define mk make_pair
#define flp(i, k, n) for(int i=k; i<n; i++)
#define rev(i, k) for(int i=k; i>=0; i--)
#define F first
#define S second
#define pi pair<int, int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};

int32_t main(void)
{
    int a, b, c, k;
    cin>>a>>b>>c>>k;
    int ct=0, ans=0;
    if(k<=a)
    {
        ans=min(a, k);
    }

    else if(k<=(a+b))
    {
        ans=a;
    }

    else
    {
        ans=a-(k-(a+b));
    }
    cout<<ans<<"\n";
    return 0;
}

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

#define ll long long
#define mod 1000000007
#define f(i, a, b) for (long long i = a; i < b; i++)
#define fm(i, a, b, c) for (long long i = a; i > b; i--)
#define vi vector<i>
#define vl vector<long long>
#define vs vector<string>
#define t     \
    ll t;     \
    cin >> t; \
    while (t--)
#define pb(i) push_back(i)
#define mp(i, j) make_pair(i, j)
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL)
int main()
{
    ll k, n;
    cin >> k >> n;
    ll a[n], b[n];
    f(i, 0, n)
    {
        cin >> a[i];
    }
    f(i, 0, n - 1)
    {
        b[i] = a[i + 1] - a[i];
    }
    b[n - 1] = a[0] + k - a[n - 1];
    ll max = 0;
    f(i, 0, n)
    {
        if (max < b[i])
            max = b[i];
    }
    cout << k - max << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdlib>
#include<cstdio>
#include<utility>
#include<list>
using namespace std;
int main(){
	int A,B,C,D,min1=0,min2=0;
	cin>>A>>B>>C>>D;
	min1 = min(A, B);
	min2 = min(C, D);
	cout<<min1+min2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int pref[300200];
int suff[300200];

signed main()
{
    int n;
    cin >> n;
    vector<int>a(n + 1);
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    for(int i = 1; i <= n; ++i)
        pref[i] = max(pref[i - 1], a[i]);
    for(int i = n; i >= 1; --i)
        suff[i] = max(suff[i + 1], a[i]);
    for(int i = 1; i <= n; ++i)
    {
        cout << max(pref[i - 1], suff[i + 1]) << '\n';
    }
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<17;

int main(){
    int N,x;
    cin >> N >> x;
    int a[2*N-1];
    memset(a,0,sizeof(a));
    if(x==1||x==2*N-1){
        puts("No");
        return 0;
    }
    else{
        puts("Yes");
        int u=1;
        if(x==2||x==2*N){
            a[N-2]=x-1;
            a[N-1]=x;
            a[N]=x+1;
            for(int i=0;i<2*N-1;i++){
                if(u==x-1){
                    u+=3;
                }
                if(a[i]!=0) continue;
                a[i]=u;
                u++; 
            }
        }
        else{
            a[N-2]=x-1;
            a[N-1]=x;
            a[N]=x+1;
            a[N+1]=x-2;
            for(int i=0;i<2*N-1;i++){
                if(u==x-2){
                    u+=4;
                }
                if(a[i]!=0) continue;
                a[i]=u;
                u++;
            }
        }
    }
    for(int i=0;i<2*N-1;i++){
        cout << a[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << ", "
template <typename T> ostream& operator<<(ostream& _o_, const vector<T>& _v_){ \
 if(!_v_.empty()){_o_<<'[';copy(_v_.begin(),_v_.end(),ostream_iterator<T>(_o_,", "));_o_<<"\b\b]";}return _o_;}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
typedef unsigned int uint;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unsigned char uchar;
struct secure_hash {
 static uint64_t splitmix64(uint64_t x) {
  x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); }
 size_t operator()(uint64_t x) const {
  static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } };
template<typename T> using V = vector<T>;
template<typename T, typename U> using umap = unordered_map<T,U,secure_hash>;
template<typename T> using uset = unordered_set<T,secure_hash>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using max_heap = priority_queue<T>;

int n;
V<V<int>> adj;
V<V<ll>> dp;
const ll M = 1e9+7;

ll dfs(int u, bool c, int parent)
{
    ll& ans = dp[u][c];
    if (ans != -1) return ans;
    ans = 1;
    for (int v : adj[u]) {
        if (v != parent) {
            ll cnt = dfs(v, !c, u);
            if (!c) cnt += dfs(v, c, u);
            ans = cnt % M * ans % M;
        }
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    adj.resize(n);
    rep(i,0,n-1) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dp.assign(n, V<ll>(2, -1));
    cout << (dfs(0, 0, -1) + dfs(0, 1, -1)) % M << endl;
}


Measured memory_bytes: 19584
#include<iostream>
#include<algorithm>
using namespace std;
int main(void) {
  int n, k;
  int a[200001]={0};
  int ans=0;
  int c=0;
  cin>>n>>k;
  for(int i=0; i<n; i++) {
    int x;
    cin>>x;
    if(a[x]==0) c++;
    a[x]++;
  }
  sort(a, a+200001, greater<int>());
  sort(a, a+c);
  
  for(int i=0; i<c-k; i++) {
    // a[i+1]+=a[i];
    ans+=a[i];
    // for(int j=i+1; j<c; j++) {
    //   if(a[j]<=a[j+1]) break;
    //   else swap(a[j], a[j+1]);
    // }
    // for(int j=i; j<c; j++) {
    //   cout<<a[j]<<" ";
    // }
    // cout<<endl;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
n,a,b=map(int,input().split())
l=[]
for i in range(1,n+1):
    tmp=0
    tmp_l=[]
    for j in range(len(str(i))):#各桁の和を算出
        tmp_l.append(int(str(i)[j]))
        tmp=sum(tmp_l)
    if a<= tmp <=b:
        l.append(i)
        
ans=sum(l)
print(ans)

Measured memory_bytes: 3404
#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  
  int a[n+1];
  
  for(int i=1;i<=n;i++)
  {
    cin >> a[i];
  }
  int b[n+1];
  for(int i=1;i<=n;i++)
  {
   	b[a[i]] = i; 
  }
  
  for(int i=1;i<=n;i++)
  {
    cout << b[i] << " ";
  }
  
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define Endl endl

signed main(void){
    int N,M;
    const int MEM=2019;
    int S[MEM],T[MEM];
    int dp[MEM][MEM]={};
    cin >> N >> M;
    REP(i,N){
        cin >> S[i];
    }
    REP(i,M){
        cin >> T[i];
    }
    dp[0][0]=1;
    REP(i,N+1){
        REP(j,M+1){
            if(i>0)dp[i][j]=(dp[i][j]+dp[i-1][j])%MOD;
            if(j>0)dp[i][j]=(dp[i][j]+dp[i][j-1])%MOD;
            if(i>0&&j>0&&S[i-1]!=T[j-1])dp[i][j]=(dp[i][j]-dp[i-1][j-1]+MOD)%MOD;
        }
    }
    
    cout << dp[N][M] << endl;
    return 0;
}



Measured memory_bytes: 32128
import math
X,K,D = map(int,input().split())
if(X>0):
    posneg = 0
else:
    posneg = 1

if(posneg == 0):
    Ki = math.ceil(X/D)
    D = D*(-1)
else:
    Ki = abs(math.floor(X/D))

if(K == Ki):
    print(abs(X+D*K))
elif(K < Ki):
    print(abs(X+D*K))
else:
    if((K-Ki)%2 == 0):
        print(abs(X+D*Ki))
    else:
        print(min(abs(X+D*(Ki-1)),abs(X+D*(Ki+1))))

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
string s,t;cin>>s>>t;
if(s==t.substr(0,s.size())){
  puts("Yes");
}else {
  puts("No");

}
  return 0;
}


Measured memory_bytes: 3644