akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

vector<vector<int>> dp(3005,vector<int>(3005,0));

void reconstruct(int n,int m,string& res,string s,string t)
{
	if(n<=0 || m<=0)
		return;
	if(s[n-1]==t[m-1])
	{
		res=s[n-1]+res;
		reconstruct(n-1,m-1,res,s,t);
	}
	else
	{
		if(dp[n-1][m]>dp[n][m-1])
			reconstruct(n-1,m,res,s,t);
		else
			reconstruct(n,m-1,res,s,t);
	}
}

int main() 
{
    fastio;

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif

	string s;
	string t; 
	cin>>s>>t;
	

	for(int i=1;i<=s.size();i++)
	{
		for(int j=1;j<=t.size();j++)
		{
			if(s[i-1]==t[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}   
	string res;
	reconstruct(s.size(),t.size(),res,s,t);
	cout<<res<<endl;

    return 0;
}		

Measured memory_bytes: 65920
#include <stdio.h>
int main(void){
    char number[1001];
    int i, sum;
    while(1){
        scanf("%s", number);
        if(number[0]=='0')break;
        sum=0;
        for(i=0;number[i]!='\0';i++){
            sum+=number[i]-'0';
        }
        printf("%d\n", sum);
    }
    return 0;
}


Measured memory_bytes: 2044
#include<iostream>
#include<iomanip>
#include <math.h>
using namespace std;
int main(){
    double r, PI;
    PI = 3.14159265358979;
    cin >> r;
    cout << fixed << setprecision(6) << PI * r * r << " " << 2 * PI * r << endl;
    return 0;
}



Measured memory_bytes: 3268
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int N;
int a[101];
int max(int a,int b){
  return a<b ?b :a; 
}
int main(){
  cin >> N;
  for(int i=0;i<N;i++)cin >> a[i];
  sort(a,a+N,greater<int>());
  //for(int i=0;i<N;i++)printf("%d ",a[i]);
  //printf("\n");
  int D=a[0];
  int flag=0;
  for(int i=0;i<=D;i++){
    for(int j=0;j<N;j++){
      flag=0;
      if(a[j]==max(i,D-i)){a[j]=0;flag=1;}
      if(flag==1)break;
    }
    if(flag==0){
       cout << "Impossible" << endl;
      return 0;
    }
  }
  sort(a,a+N,greater<int>());
  // for(int i=0;i<N;i++)printf("%d ",a[i]);
  // printf("\n");
  int i=0;
  for(int i=0;i<N && a[i]!=0;i++){
    if(a[i]<(D+1)/2+1){
      cout << "Impossible" << endl;
      return 0;
    }
    
  }
  cout << "Possible" << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ull base = 239;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	vector<string> a(n);
	for (auto &s : a) cin >> s;
	map<pair<int, ull>, unordered_map<char, int>> cnt;
	for (auto &s : a) {
		ull h = 0, p = 1;
		for (int i = s.size() - 1; i; i--, p *= base) h += p * s[i];
		cnt[{s.size() - 1, h}][s[0]]++;
	}
	ll ans = 0;
	auto solve = [&](pair<int, ull> key, vector<int> &mask) {
		unordered_map<char, int> &now = cnt[key];
		for (int i = 0; i < 26; i++) {
			if (mask[i] && now.find('a' + i) != now.end()) ans += now['a' + i];
		}
	};
	for (auto &s : a) {
		ull h = 0, p = 1;
		vector<int> cnt(26, 0);
		for (auto c : s) cnt[c - 'a']++;
		solve({h, 0}, cnt);
		for (int i = s.size() - 1; i; i--, p *= base) {
			h += p * s[i];
			cnt[s[i] - 'a']--;
			solve({s.size() - i, h}, cnt);
		}
	}
	cout << ans - n << '\n';
}

Measured memory_bytes: 113760
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int main()
{
    int n;
    cin >> n;
    vll h(n);
    rep(i, 0, n) cin >> h[i];

    int m = 0;
    int cnt = 0;
    rep(i, 1, n)
    {
        if (h[i] <= h[i - 1])
            cnt++;
        else
        {
            m = max(m, cnt);
            cnt = 0;
        }
    }
    m = max(m, cnt);
    cout << m << endl;
}


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

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

int MOD=1e9+7;
ll INF=1e18;

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

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

    int cnt=0;
    for(int i=0; i<n; i++){
        if(p[i]==i+1){
            if(i==n-1){
                swap(p[i-1], p[i]);
                cnt++;
            }
            else{
                swap(p[i], p[i+1]);
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

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

#define LLINF (1LL<<60)
typedef long long ll;

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

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

//C++14 (GCC 5.4.1)
int main() {
    int X,A;
    cin >>X>>A;


    cout << ((X<A) ? 0 : 10) <<endl;
    return (0);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int A[200010],B[200010],num[200010];
int N,M,W,C,D,E,G,K;
int ans,ans2,Max=0,Min=INF;
string S,T;
vector<int> V;
set<int> U;
map<int,int> H;
bool F,Q[200010];

signed main(){
	cin>>N>>M>>W;
	REP(i,N){
		cin>>A[i]>>B[i];
	}
	REP(i,N){
		if(A[i]>=M&&B[i]>=W){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  cin >> A;
  
  map<string, int> OOTJNY;
  
  for(string YUNI; A--;){
    cin >> YUNI;
    OOTJNY[YUNI]++;
  }
  
  cout << OOTJNY.size() << endl;
}

Measured memory_bytes: 19228
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
long long n,i,top,zhan[200005],head,tail,dui[200005];
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
   	n=read();
   	while(n){
		if(n&1){
			n>>=1;
			top++;
			zhan[top]=2;
		}
		else{
			n--;
			top++;
			zhan[top]=1;
		}	
	}
	head=top+1;tail=top;
	for(i=top;i>=1;i--){
		if(zhan[i]==1){
			head--;
			dui[head]=top-i+1;
		}
		else{
			tail++;
			dui[tail]=top-i+1;
		}
	}
	pus(top<<1,2);
	for(i=head;i<=tail;i++)
		pus(dui[i],1);
	for(i=1;i<=top;i++)
		pus(i,1);
	cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX=1001;
//char result[MAX];
//int cnt=0;
//string ans[MAX];
int lcs(string x,string y,int xlen,int ylen) 
{
	int i=0,j=0,c[MAX][MAX];
	for (i=0;i<=xlen;i++)c[i][0]=0;
	for (i=0;i<=ylen;i++)c[0][i]=0;
	for (i=1;i<=xlen;i++) 
	for (j=1;j<=ylen;j++) 
	if (x[i -1]==y[j-1])
	{
		c[i][j]=c[i-1][j-1]+1; 
		//b[i][j]=1;
	}
	else if (c[i-1][j]>c[i][j-1]) 
	{
		c[i][j]=c[i-1][j]; 
		//b[i][j]=2;
	}
	else if(c[i-1][j]<c[i][j-1])
	{
		c[i][j]=c[i][j-1]; 
		//b[i][j]=3;
	}
	else
	{
		c[i][j]=c[i][j-1]; //??????c[i][j]=c[i-1][j];
		//b[i][j]=4;
	}
	 /*cout << "???????????????????????????????????????" << endl;
	 for(i = 1; i <= xlen; i++)
	 {
		for(j = 1; j < ylen; j++)cout << c[i][j] << " ";
		cout << endl;
	  }*/
	  return c[xlen][ylen];
}
/*void show(int i,int j,string x,int b[][MAX],int cur,int max) 
{
	if(i==0||j==0) 
	{
		for(int s=0;s<max;s++)ans[cnt].push_back(result[s]);
		++cnt;
		return;
	}
	if(b[i][j]==1) 
	{ 
		--cur;
		result[cur]=x[i-1];
		show(i-1, j-1, x, b,cur,max);
	}
	else if(b[i][j]==2)show(i-1, j, x, b,cur,max);
	else if(b[i][j]==3)show(i, j-1, x, b,cur,max);
	else
	{
		show(i,j-1,x,b,cur,max);
		show(i-1,j,x,b,cur,max);
	}
}*/
 int main()
 {
	int n;cin>>n;
	string X,Y;
	while(n--)
	{
		//while(
		cin>>X>>Y;
		//)
		//{
			//cnt=0;
			//for(int i=0;i<MAX;++i)ans[i].clear();
			int x=X.length(),y=Y.length(),len=lcs(X,Y,x,y);//b[MAX][MAX];
			cout<<len<<endl;
			//show(x,y,X,b,len,len);
			//sort(ans,ans+cnt);
			//for(int i=0;i<cnt;++i)cout<<ans[i]<<"\n";
		//}
	}
	
 }

Measured memory_bytes: 7032
#include<bits/stdc++.h>
using namespace std;
long long a,b,ans;
int main(){
    cin>>a>>b;
    if(a%b==0){
        cout<<-1<<endl;
        return 0;
    }
    for(ans=2;ans*a<1000000000000000000;++ans){
        if(ans*a%b!=0){
            cout<<ans*a<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
N,T=gets.chomp.split(' ').map{|n| n.to_i}
minc = 99999999999999999
0.upto(N-1){|d|
	c,t=gets.chomp.split(' ').map{|n| n.to_i}
	minc = c if minc > c && t <= T
}
if(minc == 99999999999999999)
	puts "TLE"
else
	puts minc
end


Measured memory_bytes: 1788
MOD = 10 ** 9 + 7
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 1

if t[0] > a[0] or t[-1] < a[-1] or t[-1] != a[0]:
	ans *= 0

for i in range(1, n - 1):
	if t[i - 1] != t[i]:
		if t[i] > a[i]:
			ans *= 0
			break
		else:
			continue
	if a[i + 1] != a[i]:
		if t[i] < a[i]:
			ans *= 0
			break
		else:
			continue
	ans = (ans * min(t[i], a[i])) % MOD

print(ans)

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  cout << 800 * N - 200 * (N / 15) << endl;

  return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#define INF 1e+9
using namespace std;

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

typedef pair<int,int> P;

int main(){
	int h,w,k,mi = INF;
	bool used[800][800] = {};
	string field[800];
	cin >> h >> w >> k;
	queue<P> que;
	for(int i = 0;i < h;i++){
		cin >> field[i];
		for(int j = 0;j < w;j++){
			if(field[i][j] == 'S'){
				que.push(P(i,j));
			}
		}
	}
	for(int d = 0;d <= k;d++){
		int siz = que.size();
		if(!siz) break;
		for(int i = 0;i < siz;i++){
			P p = que.front();que.pop();
			int x = p.first,y = p.second;
			mi = min({mi,x,y,h - 1 - x,w - 1 - y});
			for(int j = 0;j < 4;j++){
				int nx = x + dx[j],ny = y + dy[j];
				if(nx >= 0 && nx < h && ny >= 0 && ny < w && field[nx][ny] != '#' && !used[nx][ny]){
					used[nx][ny] = true;
					que.push(P(nx,ny));
				}
			}
		}
	}
	if(!mi) cout << 1 << endl;
	else cout << (mi - 1) / k + 2 << endl;
	return 0;
}

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

int main () {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  sort(h.begin(), h.end());
  int ans = h.at(N-1) - h.at(0);
  for (int i = 0; i <= N-K; i++) {
    int count = h.at(i+K-1) - h.at(i);
    ans = min(ans, count);
  }
 cout << ans << endl;
}

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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];
    
    int res = 1001001001;
    for(int k=-100; k<=100; ++k) {
        int tmp = 0;
        for(int i=0; i<N; ++i) tmp += (A[i] - k) * (A[i] - k);
        res = min(res, tmp);
    }
    cout << res << '\n';
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 1e3 + 5;
ll x, y, z, k, mx, a[N], b[N], c[N];
vector<ll>tmp, ans;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> x >> y >> z >> k;
    for(int i = 0; i < x; i++)
        cin >> a[i];
    for(int i = 0; i < y; i++)
        cin >> b[i];
    for(int i = 0; i < z; i++)
        cin >> c[i];
    for(int i = 0; i < x; i++)
        for(int j = 0; j < y; j++)
            tmp.push_back(a[i] + b[j]);
    sort(tmp.rbegin(), tmp.rend());
    sort(c, c + z, greater<ll>());
    for(int i = 0; i < min(k, x * y); i++){
        for(int j = 0; j < z; j++)
            ans.push_back(tmp[i] + c[j]);
    }
    sort(ans.rbegin(), ans.rend());
    for(int i = 0; i < k; i++)
        cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 43108
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

struct node{
	LL w,s,v;
}b[1005];
bool cmp(node x,node y){
	if(x.s + x.w == y.s + y.w) return x.s < y.s;
	return x.s + x.w < y.s + y.w;
}

LL n,V;
LL dp[1005][30005] = {0};

int main(){
	scanf("%lld",&n);
	for(LL i = 1;i <= n;i ++) scanf("%lld %lld %lld",&b[i].w,&b[i].s,&b[i].v);
	sort(b + 1,b + 1 + n,cmp);
	V = b[n].s + b[n].w;
	for(LL i = 1;i <= n;i ++){
		for(LL v = 0;v <= V;v ++) dp[i][v] = max(dp[i][v],dp[i - 1][v]);
		for(LL v = 0;v <= b[i].s;v ++) dp[i][v + b[i].w] = max(dp[i][v + b[i].w],dp[i - 1][v] + b[i].v);
	}
	LL ans = 0;
	for(LL i = 0;i <= V;i ++) ans = max(ans,dp[n][i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 235008
// Author: πα

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

const int N = 301;
double dp[N][N][N];
int f[4];

int main()
{
    int n, d;
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> d, f[d]++;
    for(int k = 0; k <= n; ++k)
        for(int j = 0; j <= n-k; ++j)
            for(int i = 0; i <= n-k-j; ++i)
            {
                double m = n, &cur = dp[i][j][k];
                if(not(i or j or k))
                    continue;
                if(i)
                    cur += dp[i-1][j][k] * i/m;
                if(j)
                    cur += dp[i+1][j-1][k] * j/m;
                if(k)
                    cur += dp[i][j+1][k-1] * k/m;
                cur++, cur *= m/(i+j+k);
            }
    cout << fixed << setprecision(12) << dp[f[1]][f[2]][f[3]];
    return 0;
}


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

void cout_grid(vector<vector<bool>>& g) {
    for (int y = g[0].size()-1; y >= 0; y--) {
        for (int x = 0; x < g.size(); x++) {
            cout << g[x][y] << " ";
        }
        cout <<endl;
    }
}

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

    int W,H,N; cin >> W>>H>>N;
    vector<int> x(N),y(N),a(N);
    for (int i=0; i<N; i++)
        cin >> x[i] >> y[i] >> a[i];
    // cout << FMT3(W,H,N) << endl;
    vector<vector<bool>> grid(W, vector<bool>(H, true));
    // cout_grid(grid); cout<<"---"<<endl;
    for (int i=0; i<N; i++) {
        if (a[i] == 1) {
            for (int w = 0; w < x[i]; w++)
                for (int h = 0; h < grid[w].size(); h++)
                    grid[w][h] = false;
        } else if (a[i] == 2) {
            for (int w = x[i]; w < grid.size(); w++)
                for (int h = 0; h < grid[w].size(); h++)
                    grid[w][h] = false;
        } else if (a[i] == 3) {
            for (int w = 0; w < grid.size(); w++)
                for (int h = 0; h < y[i]; h++)
                    grid[w][h] = false;
        } else if (a[i] == 4) {
            for (int w = 0; w < grid.size(); w++)
                for (int h = y[i]; h < grid[w].size(); h++)
                    grid[w][h] = false;
        }
        // cout_grid(grid); cout<<"---"<<endl;
    }

    int ans =0;
    for (auto g: grid)
        ans += count(ALL(g), true);
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"

	"os"
	"io"
	"bufio"
	"bytes"

	"strings"
	"strconv"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}
func NewConsole() Console {
	return Console{ bufio.NewWriter(os.Stdout) }
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}

func CreateList(n int, input string) []int {
	list := make([]int, n)
	elements := strings.Split(input, " ")
	for i := 0; i < n; i++ {
		list[i], _ = strconv.Atoi(elements[i])
	}
	return list
}

func Swap(list *[]int, lhs int, rhs int) {
	(*list)[lhs], (*list)[rhs] = (*list)[rhs], (*list)[lhs]
}

func Rotate(list *[]int, begin int , mid int, end int) {
	// fmt.Printf("%d %d %d\n", begin, mid, end)
	after := make([]int, end - begin)
	for k := 0; k < end - begin; k++ {
		after[(k + (end - mid)) % (end - begin)] = (*list)[begin + k]
	}
	for i := range after {
		(*list)[begin + i] = after[i]
	}
}

func main() {
	con := NewConsole()
	defer con.Flush()

	// create list
	var n int
	fmt.Scanf("%d", &n)
	lines, _ := ReadLongLines(1)
	list := CreateList(n, lines[0])

	// query
	var q int
	fmt.Scanf("%d", &q)
	lines, _ = ReadLongLines(q)
	for _, v := range lines {
		args := strings.Split(v, " ")
		begin, _ := strconv.Atoi(args[0])
		mid, _ := strconv.Atoi(args[1])
		end, _ := strconv.Atoi(args[2])
		Rotate(&list, begin, mid, end)
	}

	for i := 0; i < len(list); i++ {
		if i == 0 {
			con.Printf("%d", list[i])
		} else {
			con.Printf(" %d", list[i])
		}
	}
	con.Println("")
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int n = 3;
    vvi data(n, vi(n));
    rep(i, n) {
        rep(j, n) {
            cin >> data[i][j];
        }
    }

    Rep(i, n) {
        int diff = data[i-1][0] - data[i][0];
        Rep(j, n) {
            if (diff != data[i-1][j] - data[i][j]) {
                std::cout << "No" << std::endl;
                return 0;
            }
        }
    }

    Rep(j, n) {
        int diff = data[0][j-1] - data[0][j];
        Rep(i, n) {
            if (diff != data[i][j-1] - data[i][j]) {
                std::cout << "No" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "Yes" << std::endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>

#define INF 1050000000
#define MOD 1000000007

using namespace std;



int main() {
	int n; cin >> n;
	string s; cin >> s;
	int ansr = 0, ansb = 0;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {
			ansr++;
		}
		else {
			ansb++;
		}
	}

	if (ansr > ansb) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}





}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int A;
  cin >> N >> A;
  
  int a = N % 500;
 
  if (a == 0) {
    cout << "Yes" << endl;
  }
  
  else {
    
    if (a <= A) {
      cout << "Yes" << endl;
    }
    
    else {
      cout << "No" << endl;
    }
  }
}

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

bool X[ 1000010 ];

int main()
{
int i;
int s;

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

	cin >> s;

	X[ s ] = true;
	for( i = 2; i < 1000010; i++ )
	{
		if( s % 2 == 0 )
			s /= 2;
		else
			s = s * 3 + 1;

		if( X[ s ] )
		{
			cout << i << endl;

			return 0;
		}

		X[ s ] = true;
	}

	return 0;
}






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

using namespace std;

int main()
{
    int N,temp,c=0;

    cin >> N;

    for(int i=0; i<N; i++)
    {
        cin >> temp;
        if(temp%2) c++;
    }

    if(c%2==0) cout << "YES\n";
    else cout << "NO\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
typedef long long LL;
char s[maxn];
char tmp[maxn];
void solve()
{
    //ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s=="AAA"||s=="BBB")
        printf("No\n");
    else
        printf("Yes\n");
}
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e5+1;
const int mod = 1e9+7;
using cd = complex<double>;
const double PI = acos(-1);
 
void fft(vector<cd> & a, bool invert) {
    ll n = a.size();
 
    for (int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;
 
        if (i < j)
            swap(a[i], a[j]);
    }
 
    for (int len = 2; len <= n; len <<= 1) {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1);
            for (int j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }
 
    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}
vector<ll> multiply(vector<ll> const& a, vector<ll> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    ll n = 1;
    while (n < a.size() + b.size()) 
        n <<= 1;
    fa.resize(n);
    fb.resize(n);
 
    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);
 
    vector<ll> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}
vl a;
int main() {
	int n,inp;
	ll m;
	a.resize(100001);
	sd(n);slld(m);
	for(int i = 1; i <= n; i++){
		sd(inp);a[inp]++;
	}
	a=multiply(a,a);
	ll ans=0;
	for(int i = a.size(); i>=0; i--){
		ll x=a[i];x=min(x,m);
		m-=x;ans+=x*1LL*i;
		if(! m) break;
	}
	plld(ans);
	return 0;
}

Measured memory_bytes: 11592
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ub upper_bound
#define lb lower_bound
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
void input(vector<int>&a,int n)
{
   rep(i,0,n-1)
   cin>>a[i];
}

void solve()
{
  string s; cin>>s; 
  vector<int>f(27,0);
  for(int i=0;i<=3;i++)
  {
  	int i1=s[i]-65; f[i1]++; 
  }
  int c2=0; 
  for(auto i:f)
  {
  	if(i==2) c2++;
  }
  if(c2==2) cout<<"Yes\n";
  else cout<<"No\n"; return;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  while(t--)
  {
	 solve();
  }
  return 0;
}




Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

signed main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	cout << max({a * c, a * d, b * c, b * d}) << endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 300300;
int res[MN];
int main() {
	ll n,a,b;
	scanf("%lld %lld %lld",&n,&b,&a);
	if(a*b < n) {printf("-1\n");return 0;}
	if(a+b > n+1) {printf("-1\n");return 0;}
	for(int i=0;i<b;i++) {
		res[i] = 1;n--;
	}
	for(int i=0;i<b;i++) {
		int h = min(n,a-res[i]);
		res[i] += h;n -= h;
	}
	int ct = 0;
	bool fs = true;
	for(int i=0;i<b;i++) {
		ct += res[i];
		for(int j=0;j<res[i];j++) {
			if(!fs) {printf(" ");}
			fs = false;
			printf("%d",ct-j);
		}
	}
	printf("\n");
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define int long long
#define mod 998244353
#define maxn 4005
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pp;
const long long inf = 2e18;
int n,k,c[maxn][maxn],lg[maxn];
void prep(){
	int i,j;
	for (i=0;i<maxn;i++) c[i][i]=1;
	for (i=0;i<maxn;i++) c[i][0]=1;
	for (i=2;i<maxn;i++){
		for(j=1;j<i;j++){
			c[i][j]=c[i-1][j-1]+c[i-1][j];
			c[i][j]%=mod;
		}
	}
	lg[0]=1;
	for (i=1;i<maxn;i++){
		lg[i]=lg[i-1]*2; lg[i]%=mod;
	}
}
void solve(){
	int i,j,val,num;
	for (i=2;i<=2*k;i++){
		int bons=i; if (bons>(k+1)) bons=k+1-(bons-k-1);
		val=(bons-1)/2; num=k-val; if (i%2==0) num--;
		//cout<<val<<' '<<num<<' '<<n<<'\n';
		int dau=1,ans=0,x;
		for (j=0;j<=val;j++){
			x=c[val][j]*c[n+num-j-1][num-j-1]; x%=mod;
			x=x*lg[val-j]; x%=mod;
			if (dau==1) ans+=x; else ans-=x;
			ans%=mod; if (ans<0) ans+=mod;
			dau=dau*(-1);
		}
		//cout<<x<<'\n';
		if (i%2==0){
			int n2=n-1; dau=1;
			for (j=0;j<=val;j++){
				x=c[val][j]*c[n2+num-j-1][num-j-1]; x%=mod;
				x=x*lg[val-j]; x%=mod;
				if (dau==1) ans+=x; else ans-=x;
				ans%=mod; if (ans<0) ans+=mod;
				dau=dau*(-1);
			}
		}
		cout<<ans<<'\n'; 
		//exit(0);
	}
}
main(){
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen(".inp","r",stdin); freopen(".out","w",stdout);
	//freopen("inp.txt","r",stdin);
	cin>>k>>n; int i,j;
	// careful...
	prep();
	solve();
}

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

using namespace std;

typedef long long ll;
typedef double long dl;
typedef pair < int , int > pii;
typedef pair < pii, pii > p2i;
const int maxn = (int) 1e5 + 2;
const int mod = (int) 1e9 + 7;
const ll inf = (ll)1e18;

#define fi first
#define se second
#define acel ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define next continue
#define getsz(x) (int) log10(x)

int n, m;
int a[maxn];
int x, y, t;
int u[maxn];
vector < int > g[maxn];
set < int > w[maxn];
void dfs(int v, int p){
    u[v] = t;
    w[t].insert(a[v]);
    for(int i : g[v]){
        if(i == p){
            next;
        }
        if(!u[i]){
            dfs(i, v);
        }
    }
}

int ans;
int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= m; i++){
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int i = 1; i <= n; i++){
        if(a[i] == i){
            ans++;
            next;
        }
        if(!u[i]){
            t++;
            dfs(i, i);
        }
    }
    for(int i = 1; i <= n; i++){
        if(i == a[i]){
            next;
        }
        ans += w[u[i]].count(i);
    }
    cout << ans;
}


Measured memory_bytes: 20992
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int N,Q;
ll L;
vector<ll>x;
vector<ll>canreach;
int nxt[40][101010];

int check(ll mid,int a) {
	for (ll i = 39; i >= 0; i--) {
		if ((mid >> i) & 1LL)a = nxt[i][a];
	}
	return a;
}

int calc(int a,int b){
	if (a > b)swap(a, b);
	int ok = 101010, ng = 0;
	while (ok - ng > 1) {
		int mid = (ok + ng) / 2;
		if (check(mid,a) >= b)ok = mid;
		else ng = mid;
	}
	return ok;
}

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

	cin >> N;
	x.resize(N);
	canreach.resize(N);
	for (int i = 0; i < N; i++)cin >> x[i];
	cin >> L >> Q;


	int right = 0;
	ll curdist = 0;
	for (int left = 0; left < N-1; left++) {
		while (right < N-1 && curdist + (x[right+1]-x[right])<=L) {
			curdist += x[right+1] - x[right];
			right++;
		}
		canreach[left] = right;
		curdist -= x[left+1]-x[left];
	}
	canreach[N-1] = N-1;

	memset(nxt, -1, sizeof(nxt));
	for (int i = 0; i < N; i++)nxt[0][i] = canreach[i];
	for (int k = 0; k < 37; k++) {
		for (int i = 0; i < N; i++) {
			if (nxt[k][i] == -1)nxt[k + 1][i] = -1;
			else nxt[k + 1][i] = nxt[k][nxt[k][i]];
		}
	}
	
	for (int i = 0; i < Q; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		puts(calc(a, b));
	}
	
	return 0;
}


Measured memory_bytes: 18176
def main20():
    data = input().split()
    num = []
    for i in range(2):
        num.append(int(data[i]))
    if num[0] >= 13:
        print(num[1])
    elif num[0] >= 6:
        print(int(num[1]/2))
    else:
        print(0)

if __name__ == "__main__":
    main20()

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <type_traits>

#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << min({a + b, b + c, c + a}) << endl;
}

Measured memory_bytes: 256
//============================================================================
//dice1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
int alds1_2(void)
{
    int i,j,k,l,n,S; int cnt, *ary;

    scanf("%d", &n);
    ary=malloc(n*sizeof(int));
    for (i=0; i<n; i++)
        scanf("%d", &ary[i]);
    for (k=cnt=0, l=n; k<n-1; k++, l--)
    for (i=0,j=1; j<l; i++, j++){
        if (ary[j]<ary[i]){
            S=ary[i];
            ary[i]=ary[j];
            ary[j]=S;
            cnt++;
        }
	}
    for (i=0; i<n; i++){
        if (i)
            printf(" ");
        printf("%d", ary[i]);
    }
    printf("\n%d\n", cnt);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
int main(void)
{
    alds1_2();
    return 0;
}
//----------------------------------------------------------------------------

Measured memory_bytes: 604
N, Y = map(int, input().split())

match = False
for a in range(N+1):
    for b in range(N+1):
        c = N - (a + b)
        y = 10000*a + 5000*b + 1000*c
        if c >= 0 and y == Y:
            match = True
            break
    if match:
        break

if match:
    print(a, b, c)
else:
    print(-1, -1, -1)

Measured memory_bytes: 3064
n, m = gets.split.map(&:to_i)

r = ' '*n

ng = false
m.times do
  s, c = gets.split.map(&:to_i)
  s-=1
  c = c.to_s
  ng ||= r[s] != ' ' && r[s] != c
  r[s] = c
end

r[0] = n==1 ? '0' : '1' if r[0] == ' '
ng ||= n>1 && r[0] == '0'
r.gsub!(' ', '0')

puts ng ? -1 : r


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int w, h, n;
    cin >> w >> h >> n;

    vector<int> v[4];
    v[0].push_back(0);
    v[1].push_back(w);
    v[2].push_back(0);
    v[3].push_back(h);

    rep(r, n)
    {
        int x, y, a;
        cin >> x >> y >> a;
        --a;
        if (a == 0 || a == 1)
            v[a].push_back(x);
        else
            v[a].push_back(y);
    }

    rep(i, 4) sort(ALL(v[i]));

    OP(max(v[1][0] - v[0][v[0].size() - 1], 0) * max(v[3][0] - v[2][v[2].size() - 1], 0));
    return 0;
}

Measured memory_bytes: 256
// play dirty
#include "bits/stdc++.h"
#include "sstream"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int N=2e5+1;
int main() {
long long a,ans=0; scanf("%lld",&a);
if((a&1)){ return printf("0"),0;}
a/=2;
while(a){ans+=a/5,a/=5;}
printf("%lld",ans);
}

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;
using P = pair<int,int>;
const int INF = 1000000001;

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

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> g(h, vector<char>(w));
  rep(i, h) rep(j, w) cin >> g[i][j];

  vector<vector<int>> dist(h, vector<int>(w, INF));
  if(g[0][0] == '#') dist[0][0] = 1;
  else dist[0][0] = 0;

  for(int x = 1; x < w; ++x){
    if(g[0][x] == '#' && g[0][x-1] == '.'){
      dist[0][x] = dist[0][x-1] + 1;
    }
    else{
      dist[0][x] = dist[0][x-1];
    }
  }
  for(int y = 1; y < h; ++y){
    if(g[y][0] == '#' && g[y-1][0] == '.'){
      dist[y][0] = dist[y-1][0] + 1;
    }
    else{
      dist[y][0] = dist[y-1][0];
    }
  }

  for(int y = 1; y < h; ++y){
    for(int x = 1; x < w; ++x){
      int right = dist[y][x-1];
      int down = dist[y-1][x];
      if(g[y][x] == '#' && g[y][x-1] == '.'){
        right++;
      }
      if(g[y][x] == '#' && g[y-1][x] == '.'){
        down++;
      }
      dist[y][x] = min(right, down);
    }
  }
  cout << dist[h-1][w-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <sstream>
using namespace std;
 
#define INF (1<<29)
 
int toInt(string s){
  istringstream iss(s);
  int a;
  iss >> a;
  return a;
}
 
int main(){
  int n;
  string s;
  while(cin >> n >> s){
    if(n == 0 && s == "0") break;
    int ans = -1;
    vector<string> ans2;
    map<int, int> is_found;
     
    for(int i = 0 ; i < (1<<(s.size()-1)) ; i++){
      vector<string> tmp;
      int pos = 0, point = 0;
      for(int j = 0 ; j < s.size() ; j++){
	if(j == s.size()-1){
	  string t = s.substr(pos, j-pos+1);
	  tmp.push_back(t);
	  pos = j+1;
	  point += toInt(t);
	}
	
	else if((1<<j) & i){
	  string t = s.substr(pos, j-pos+1);
	  tmp.push_back(t);
	  pos = j+1;
	  point += toInt(t);
	}
      }
      
      is_found[point]++;
      if(point <= n && n-point < n-ans){
	ans = point;
	ans2 = tmp;
      }
    }
    
    bool f = true;
    if(is_found[ans] > 1) f = false;
    
    if(ans == -1) cout << "error" << endl;
    else if(!f){
      cout << "rejected" << endl;
    }
    else{
      cout << ans << ' ';
      for(int i = 0 ; i < ans2.size() ; i++){
	cout << ans2[i];
	if(i != ans2.size()-1) cout << ' ';
	else cout << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1228
#include "bits/stdc++.h"
#include <unordered_set>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

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

int main(){

    ll x, y; cin >> y >> x;

    vector<vector<ll > > vec(y, vector<ll >(x, 0));
    vector<vector<ll > > conf(y, vector<ll >(x, 0));
    vector<vector<pair<ll, ll > > > path(y);

    for(ll row = 0; row < y; row++){
        string S; cin >> S;
        for(ll col = 0; col < x; col++){
            if(S[col] == '#'){
                vec[row][col] = 1;
                conf[row][col] = 1;
            }
            //準備
            path[row].push_back(make_pair(0, 0));
        }       
    }

    //start
    conf[0][0] = 1;
    queue<pair<ll, ll > > que;
    que.push(make_pair(0, 0));

    bool f = false;
    ll i = 0;
    while(!que.empty()){
        //cout << i << endl;
        pair<ll, ll > from = que.front();
        que.pop();

        ll now_x = from.second;
        ll now_y = from.first;
        
        conf[now_y][now_x] = 1;
        
        for(ll i = 0; i < 4; i++){
            ll next_x = now_x  + dx[i];
            ll next_y = now_y  + dy[i];
            if(next_x < x && next_x >= 0 && next_y < y && next_y >= 0){
                if(vec[next_y][next_x] == 1) continue;
                if(conf[next_y][next_x] == 1) continue;
                //cout << "next" << next_x << " " << next_y << endl;
                //cout << "now" << now_x << " " << now_y << endl;
                //キューに積む
                que.push(make_pair(next_y, next_x));
                //経路記憶
                conf[next_y][next_x] = 1;
                path[next_y][next_x].first = now_y;
                path[next_y][next_x].second = now_x;
                
                if(next_y == y-1 && next_x == x-1){
                    f = true;
                    break;
                }
            }   
        }
        if(f == true){
            break;
        }
        i++;
    }

    if(f == false){
        cout << -1 << endl;
        return 0;
    }

    ll X = x - 1; ll Y = y - 1;
    while(!(X == 0 && Y == 0)){
        //cout << X << " " << Y << endl;
        vec[Y][X] = 1;
        ll t_X = path[Y][X].second;
        ll t_Y = path[Y][X].first;
        X = t_X;
        Y = t_Y;
    }

    //計算
    ll ans = 0;

    for(ll row = 0; row < y; row++){
        for(ll col = 0; col < x; col++){
            if(vec[row][col] == 0){
                ans++;
            }
        }       
    }

    cout << ans - 1 << endl;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base :: sync_with_stdio(0),cin.tie(0)
#define file() freopen("in.txt","r",stdin)



int main()
{
 // IO;
 // file();
  long long a,b,c,d,x,y;
  cin>>a>>b>>c>>d;
  long long k;
  k=a*c;
  k=max(k,a*d);
  k=max(k,b*c);
  k=max(k,b*d);
  cout<<k<<endl;

 return 0;
}


Measured memory_bytes: 3588
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n,ans=0;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    rep(i,(n+1)/2){
        if(a[2*i]%2==1){
            ans++;
        }
    }
    out(ans);
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d;
int main(){
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	a--;
	long long l=c*d/__gcd(c,d);
	printf("%lld\n",(b-b/c-b/d+b/l)-(a-a/c-a/d+a/l));
	return 0;
}


Measured memory_bytes: 256
open System

let m = stdin.ReadLine() |> int
let dc = [
    for _ in [1 .. m] ->
        let [|d; c|] = stdin.ReadLine().Split() |> Array.map int64
        (c, d*c) ]

let nd = List.sumBy fst dc
let sd = List.sumBy snd dc

printfn "%d" <| nd + (sd - 1L) / 9L - 1L

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

int main(){
    int n, r, t;
    cin >> n >> r >> t;
    
    int p[n];
    for(int i = 0; i < n; i++)  cin >> p[i];

    int ans = 0;
    vector<int> stock(r, 0);
    for(int i = 1; i <= t; i++){
        vector<int> next(r, 0);
        for(int j = 0; j < n; j++){
            int pos = i*p[j]%r;
            if(stock[pos])  stock[pos]--;
            else            ans++;
            if(i!=1)    next[pos]++;
        }
        for(int j = 0; j < r; j++)  stock[j] += next[j];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k, s;
    cin >> k >> s;
    ll ans = 0;
    for(int x = 0; x <= k; x++) {
        for(int y = 0; y <= k; y++) {
            int z = s - (x + y);
            ans += 0 <= z and z <= k;
        }
    }
    cout << ans << endl;
    return 0;
}


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

void print_ans(pair<long, long> &ans){
  string up = "";
  int tens = 1e5;
  while(tens){
    up = up + (char)((ans.first/tens)%10 + (int)'0');
    tens /= 10;
  }
  string down = "";
  tens = 1e5;
  while(tens){
    down = down + (char)((ans.second/tens)%10 + (int)'0');
    tens /= 10;
  }
  cout << up << down << endl;
}

int main(){
  int n, m;  cin >> n >> m;
  vector<vector<pair<long, long>>> pre(n);
  for(int i=0; i<m; i++){
    long p, y;  cin >> p >> y;
    pre[--p].push_back({y, i});
  }
  for(int i=0; i<n; i++)  sort(pre[i].begin(), pre[i].end());
  vector<pair<long, long>> ans(m);
  for(int i=0; i<n; i++){
    for(int j=0; j<pre[i].size(); j++){
      ans[pre[i][j].second] = {i+1, j+1};
    }
  }
  for(int i=0; i<m; i++)
    print_ans(ans[i]);
  
  return 0;
}


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

int main(){
  int N,M;
  cin >> N >> M;
  priority_queue <int64_t> pq;
  int64_t A;
  for(int i=0;i<N;i++){
    cin >> A;
    pq.push(A);
  }
  while(M>0){
    pq.push(pq.top()/2);
    pq.pop();
    M--;
  }
  int64_t ans=0;
  for(int i=0;i<N;i++){
    ans+=pq.top();
    pq.pop();
  }
  cout << ans << endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

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

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

int main(){
  int n, m;
  cin >> n >> m;

  COMinit();

  vector<int> b;
  int d = 2;
  int cnt = 0;
  bool flag = false;
  while (1 < m) {
    if (m % d == 0) {
      m /= d;
      cnt++;
      if (!flag) b.push_back(1);
      else b[b.size() - 1]++;
      flag = true;
    } else {
      d++;
      flag = false;
    }
  }

  LL ans = 1;
  for (auto x : b) {
    ans = ans * COM(x + n - 1, x) % MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 12160