akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H;
  int W;
  cin >> H >> W;
  vector<vector<char>> data(H, vector<char>(W));
  vector<vector<char>> answer(H, vector<char>(W));
  
  for(int i=0;i<H;i++){
   for(int j=0;j<W;j++){
   cin >> data.at(i).at(j);
   } 
  }
  for(int i=0;i<H;i++){
   for(int j=0;j<W;j++){
     int count=0;
   //左上判定  
   if(i-1 >=0 && j-1 >=0  && data.at(i-1).at(j-1) == '#'){count+=0;}
   if(i-1 >=0 && j-1 >=0  && data.at(i-1).at(j-1) == '#'){count+=1;}
   
   //真上判定
   if(i-1 >=0 && data.at(i-1).at(j) == '#'){count+=0;}
   if(i-1 >=0 && data.at(i-1).at(j) == '#'){count+=1;}
   
   //右上判定
   if(i-1 >=0 && j+1 <= W-1 && data.at(i-1).at(j+1) == '#'){count+=0;}
   if(i-1 >=0 && j+1 <= W-1 && data.at(i-1).at(j+1) == '#'){count+=1;}
    
   //左判定
   if(j-1 >=0  && data.at(i).at(j-1) == '#'){count+=0;}
   if(j-1 >=0  && data.at(i).at(j-1) == '#'){count+=1;}  
   
   //右判定
   if(j+1 <= W-1 && data.at(i).at(j+1) == '#'){count+=0;}
   if(j+1 <= W-1 && data.at(i).at(j+1) == '#'){count+=1;}   
   
   //左下判定
   if(i+1 <= H-1  && j-1 >=0 && data.at(i+1).at(j-1) == '#'){count+=0;}
   if(i+1 <= H-1  && j-1 >=0 && data.at(i+1).at(j-1) == '#'){count+=1;}  
   
   //真下判定
   if(i+1 <= H-1 && data.at(i+1).at(j) == '#'){count+=0;}
   if(i+1 <= H-1 && data.at(i+1).at(j) == '#'){count+=1;}  
     
   //右下判定
   if(i+1 <= H-1 && j+1 <= W-1 && data.at(i+1).at(j+1) == '#'){count+=0;}
   if(i+1 <= H-1 && j+1 <= W-1 && data.at(i+1).at(j+1) == '#'){count+=1;}  
   
     //回答配列へ入力
    if(count ==0){ answer.at(i).at(j)='0';}
    if(count ==1){ answer.at(i).at(j)='1';}
     if(count ==2){ answer.at(i).at(j)='2';}
     if(count ==3){ answer.at(i).at(j)='3';}
     if(count ==4){ answer.at(i).at(j)='4';}
     if(count ==5){ answer.at(i).at(j)='5';}
     if(count ==6){ answer.at(i).at(j)='6';}
     if(count ==7){ answer.at(i).at(j)='7';}
      if(count ==8){ answer.at(i).at(j)='8';}
     if(data.at(i).at(j) == '#'){ answer.at(i).at(j)='#';}
   
    
   } 
  }
  //回答配列の出力
  for(int i=0;i<H;i++){
   for(int j=0;j<W;j++){
      if(j == W-1){cout << answer.at(i).at(j) << endl;}else{
      cout << answer.at(i).at(j);
      }
   }
  }
}

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

vector<vector<pair<int, int> > > edge;//edge[i][j] firstがiからj番目のノード、secondがその重み
vector<int> d(100005,INF);

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

	vector<vector<int> > nums(2);
	if(s[0] == '0') nums[1].push_back(0);

	char last = s[0];
	int count = 1;
	for(int i = 1; i < n; i++){
		if(last == s[i]){
			count++;
		}else{
			nums[last - '0'].push_back(count);
			last = s[i];
			count = 1;
		}
	}
	nums[last - '0'].push_back(count);

	if(s[s.size()-1] == '0') nums[1].push_back(0);

/*
	for(int i: nums[0]) cout << i << " ";
	cout << endl;
	for(int i: nums[1]) cout << i << " ";
	cout << endl;
	*/

	int ans = 1;
	if(nums[0].size() <= k){
		ans = 0;
		for(int i: nums[0]) ans += i;
		for(int i: nums[1]) ans += i;
		cout << ans << endl;
		return 0;
	}


	
	for(int i = 0; i < nums[1].size()-k; i++){
		int temp = nums[1][i];
		rep(j,k){
			temp += nums[0][i+j] + nums[1][i+j+1];
		}
		ans = max(ans,temp);
	}
	
	
	cout << ans << endl;
}

Measured memory_bytes: 1408
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/agc038/tasks/agc038_a

//参考：
//https://www.programming-pack.com/entry/2019/10/29/235159

//ポイント：
//自由に構成する問題でも、落ち着いて行と列で分けて考えるのが重要

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL H,W,A,B;

bool no_flag = true;
vector<vector<int>> ans;

void solve(){
	no_flag = false;
	ans = vector<vector<int>>(H,vector<int>(W,0));
	for(int h=0;h<B;h++){
		for(int w=0;w<A;w++){
			ans[h][w] = 1;
		}
	}
	for(int h=B;h<H;h++){
		for(int w=A;w<W;w++){
			ans[h][w] = 1;
		}
	}
}
 
int main(){
    cin >> H >> W >> A >> B;
 
    solve();

    if(no_flag){
    	cout << "No" << endl;
    }else{
    	for(int h=0;h<H;h++){
    		for(int w=0;w<W;w++){
    			cout << ans[h][w];
    		}
    		cout << endl;
    	}
    }
    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main() {
	std::string S;
	cin >> S;
	
	int size = S.length();

	int err = 0;
  	for (int i = 0;i < ((size - 1)/2);i++){
      if(S[i] != S[size - 1 - i]){
	      err++;
      }
	}

  	for (int i = 0;i < size - ((size+3)/2) +1;i++){
      if(S[i + ((size+3)/2) -1] != S[size - 1 - i]){
	      err++;
      }
	}
	
	
	if(err == 0){
		cout << "Yes" << endl;
    }else{
		cout << "No" << endl;
    }
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from math import factorial

MOD = 1000000007  # type: int

def solve(N: int, M: int):
    if(N == M):
        print((2*factorial(N)*factorial(M))%MOD)
    elif(N == M-1 or M == N-1):
        print((factorial(N)*factorial(M))%MOD)
    else:
        print(0)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 2e5+1;
int n, a[N];
long psum[N], dp[N];

int main()
{
  fastio;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++){
    psum[i] = (i <= 2 ? a[i] : psum[i - 2] + a[i]);  
  }
  for (int i = 2; i <= n; i++) {
    if (i % 2) dp[i] = max(dp[i - 2] + a[i], dp[i - 1]);
    else dp[i] = max(dp[i - 2] + a[i], psum[i - 1]);
  }
  cout << dp[n];
  return 0;
}

Measured memory_bytes: 7572
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
vector<ll> fact(100001,1);

struct unionFind{
    vector<ll> par;
    vector<ll> siz;

    void init(ll n){
        for(ll i=0;i<n;i++){
            par.push_back(i);
            siz.push_back(1);
        }
    }
    ll root(ll x){
        //根を返す
        if(par[x]==x){
            return x;
        }
        else{
            return (par[x]=root(par[x]));
        }
    }
    bool sameParent(ll x,ll y){
        return(root(x)==root(y));
    }
    void unite(ll x, ll y){
        x=root(x);y=root(y);
        if(x==y)    return;
        //データ構造->小を大にくっつける
        if(siz[x]<siz[y]) swap(x,y);
        siz[x] += siz[y];
        par[y]=x;
    }

    ll size(ll x){
        return siz[root(x)];
    }
};


int main(){
    ll n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> edge;
    unionFind uf;
    uf.init(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;a--;b--;
        edge.push_back(make_pair(a,b));
    }
    vector<ll> ans;
    ans.push_back(n*(n-1)/2);
    ll pre=ans[0];
    for(ll i=m-1;i>=0;i--){
        ll x=edge[i].first,y=edge[i].second;
        if(uf.sameParent(x,y)){
            ans.push_back(pre);
            continue;
        }
        pre=pre-(uf.size(x))*(uf.size(y));
        ans.push_back(pre);
        uf.unite(x,y);
    }
    for(ll i=m-1;i>=0;i--){
        cout<<ans[i]<<endl;
    }
    return 0;
}

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

int main() {
  int h,w;
  cin >> h >> w;
  char c;
  int a[h][w]={0};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c;
      if(c=='#')a[i][j]=0;
      else a[i][j]=h+w;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=1;j<w;j++){
      if(a[i][j-1]-a[i][j]<-1)a[i][j]=a[i][j-1]+1;
    }
    for(int j=w-1;j>0;j--){
      if(a[i][j]-a[i][j-1]<-1)a[i][j-1]=a[i][j]+1;
    }
  }
  for(int j=0;j<w;j++){
    for(int i=1;i<h;i++){
      if(a[i-1][j]-a[i][j]<-1)a[i][j]=a[i-1][j]+1;
    }
    for(int i=h-1;i>0;i--){
      if(a[i][j]-a[i-1][j]<-1)a[i-1][j]=a[i][j]+1;
    }
  }
  int res=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(res<a[i][j])res=a[i][j];
    }
  }
  cout << res << endl;
}


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

using namespace std;

void Main() {
    int N;
    cin >> N;
    string last = "";
    set<string> history;
    for (int i = 0; i < N; ++i) {
        string w;
        cin >> w;
        if (i > 0 && last.back() != w.front()) {
            cout << "No" << endl;
            return;
        }
        last = w;
        history.insert(w);
    }

    if (history.size() != N) {
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3576
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
/*istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}*/
const ll INF=1<<30;

int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll q;
    cin >> q;
    vector<set<ll>> p(26);
    rep(i,n){
        p[s[i]-'a'].insert(i);
    }
    rep(i,26){
        p[i].insert(1e9);
    }
    while(q--){
        ll t;
        cin >> t;
        if(t==1){
            ll i;
            cin >> i;
            i--;
            char c;
            cin >> c;
            rep(j,26){
                p[j].erase(i);
            }
            p[c-'a'].insert(i);
        }
        else{
            ll le,ri;
            cin >> le >> ri;
            le--;
            ll cnt=0;
            rep(j,26){
                ll u=*p[j].lower_bound(le);
                ll v=*p[j].lower_bound(ri);
                //cout << u << " " << v << endl;
                if(u<v) cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;
} 


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

//.define
// #define FILE_IN_OUT
#define RET(_x)                       return cout << (_x) << '\n', 0;
#define all(_obj)                     (_obj).begin(), (_obj).end()
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define CeilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define sz(_obj)                      static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)                     std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                     {}
#endif
#define endl "\n"
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n;
    cin >> n;
    cout << n + n * n + n * n * n << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

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

typedef long long ll;
typedef short int sh;

const int inf=0x3f3f3f3f;
const int MAX=2e5+10;
const int mod=1e9+7;

ll fac[MAX]={0,1};

void Init()//计算(n!)%mod
{
    for(int i=2;i<MAX;i++)
    {
        fac[i]=fac[i-1]*i%mod;
    }
}

ll Qmul(ll a,ll n)//快速幂
{
    ll ans=1;
    while(n)
    {
        if(n&1)
            ans=(ans*a)%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}

ll C(ll n,ll m)//计算组合数
{
    if(!m||!n||n<=m)
        return 1;
    ll m_1,n_m_1;
    m_1=Qmul(fac[m],mod-2);//((m!)^-1)在%mod意义下的逆元
    n_m_1=Qmul(fac[n-m],mod-2);//(((n-m)!)^-1)在%mod意义下的逆元
    ll ans;
    ans=fac[n]*m_1%mod*n_m_1%mod;
    return ans;
}

int main()
{
    Init();
    ll ans,h,w,a,b;
    while(scanf("%lld%lld%lld%lld",&h,&w,&a,&b)!=EOF)
    {
        ans=0;
        for(ll i=b+1;i<=w;i++)
        {
            ans+=(C(h-a+i-2,i-1)*C(w-i+a-1,a-1))%mod;
            ans%=mod;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


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

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

    int n;
    cin >> n;
    vector<long long> A(n), B(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    for(int i = 0; i < n; i++){
        cin >> B[i];
    }

    long long b = 0;
    for(int i = 0; i < n; i++){
        if(A[i] >= B[i]){
            long long diff = A[i] - B[i];
            B[i] += diff;
            b += diff;
        }
    }

    for(int i = 0; i < n; i++){
        if(A[i] < B[i]){
            long long tmp = (B[i] - A[i]) / 2;
            A[i] += tmp * 2;
            b -= tmp;
            if(A[i] < B[i]){
                A[i] += 2;
                B[i] += 1;
            }
        }
    }

    cout << (b <= 0 ? "Yes" : "No") << endl;

    return 0;
}

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

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

    ll N, K;
    cin >> N >> K;

    ll ans = 0;

    if(K == 0) {
        cout << N * N << endl;
        return 0;
    }

    for(ll i = K + 1; i <= N; i++) {
        ans += (i - K) * (N / i);
        ans += max(0LL, N % i - K + 1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 100001
vector<int> e[N];
int n, k, ans;
int dfs(int u) {
    int l = 1, d;
    for (int v : e[u])
        if ((d = dfs(v)) == k)
            ans++;
        else
            l = max(d + 1, l);
    return l;
}
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1, x; i <= n; i++) {
        scanf("%d", &x);
        if (i > 1)
            e[x].push_back(i);
        else
            ans += x != 1;
    }
    for (auto v : e[1]) dfs(v);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 8832
from collections import defaultdict


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.par[x] > self.par[y]:
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)


def main():
    n, k, l = map(int, input().split())
    
    road = UnionFind(n)
    train = UnionFind(n)
    
    for _ in range(k):
        p, q = map(int, input().split())
        road.unite(p-1, q-1)
    
    for _ in range(l):
        r, s = map(int, input().split())
        train.unite(r-1, s-1)
        
    d = defaultdict(int)
    for i in range(n):
        d[(road.find(i), train.find(i))] += 1
    
    ans = []
    for i in range(n):
        ans.append(d[(road.find(i), train.find(i))])
    
    print(*ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 41832
#include <bits/stdc++.h>
#include <math.h>
typedef long long int ll;
#define pb         push_back
#define mp         make_pair
#define F          first
#define S          second
#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define pll        pair<ll,ll>
#define pii        pair<int,int>
#define all(v)     v.begin(),v.end()
#define M          1000000321

using namespace std;
bool isPrime(ll n)
{
    if(n<=1)
        return false;
    if(n<=3)
        return true;
    if(n%2==0 || n%3==0)
        return false;

    for(ll i=5;i*i<=n;i=i+6)
        if(n%i==0|| n%(i+2)==0)
            return false;

    return true;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b,a%b);

}

bool sortbydesc(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    if(a.S < b.S)
        return true;
    else
        return false;
}



int main()
{
 ios::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
 string x,y;
 cin>>x>>y;
 ll xl=x.length();
 ll yl=y.length();
 ll dp[xl+1][yl+1];
 memset(dp,0,sizeof(dp));
 string ans;
 fl(i,0,xl+1)
 {
    fl(j,0,yl+1)
    {
        if(i==0 || j==0)
            dp[i][j]=0;
        else if(x[i-1]==y[j-1])
            dp[i][j]=dp[i-1][j-1]+1;
        else
            dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
    }
 }
 ll i=xl,j=yl;
 while(i>0 && j>0)
 {
    if(x[i-1]==y[j-1])
    {
        ans+=x[i-1];
        i--;
        j--;
    }
    else if(dp[i-1][j]>dp[i][j-1])
        i--;
    else
        j--;
 }
 //cout <<i<<" "<<j<<endl; 
 reverse(all(ans));
 cout <<ans;
}

Measured memory_bytes: 70656
#include<iostream>

using namespace std;

int main(){
    //入力
    int a,b;
    cin>>a>>b;
    //処理
    
    if((a+b)%2==0){
        cout<<(a+b)/2<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
    //出力
}

Measured memory_bytes: 256
def main():
    s = int(input())
    if s < 3:
        print(0)
    else:
        total = [0]*(s+1)
        total[3] = 1
        mod = 10**9+7
        for i in range(4, s+1):
            total[i] = (total[i-3] + 1) + total[i-1]
            total[i] %= mod
        print((total[s-3]+1)%mod)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9176
//37
#include<iostream>
#include<vector>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    vector<int> c(n);
    for(int i=0;i<n;i++){
      c[i]=i+1;
    }
    vector<int>::iterator it=c.begin();
    while(c.size()!=1){
      it=c.erase(c.begin()+(it-c.begin()+m-1)%c.size());
    }
    cout<<c[0]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
// 素因数分解
vector<pair<long long, long long>> prime_factorize(long long n)
{
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p)
  {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0)
    {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}

int main()
{
  string s;
  cin >> s;
  int n = s.size();
  vector<ll> cum(n + 1);
  vector<ll> val(2019, 0);
  cum[0] = 0;
  ll fac = 1;
  val[0]++;
  for (int i = 1; i <= n; i++)
  {
    int add = s[n - i] - '0';
    cum[i] = (fac * add + cum[i - 1]) % 2019;
    fac = (fac * 10) % 2019;
    val[cum[i]]++;
  }
  ll ans = 0;
  for (int i = 0; i < 2019; i++)
  {
    ans += val[i] * (val[i] - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5244
#include <stdio.h>

int main(void) {
    int n, m, l, a[100][100], b[100][100];
    int i, j, k;
    long num;

    scanf("%d %d %d", &n, &m, &l);
    for (i=0; i<n; i++) {
        for (j=0; j<m; j++) scanf("%d", &a[i][j]);
    }
    for (i=0; i<m; i++) {
        for (j=0; j<l; j++) scanf("%d", &b[i][j]);
    }
    for (i=0; i<n; i++) {
        for (k=0; k<l; k++) {
	    num=0;
            for (j=0; j<m; j++) {
		num += a[i][j]*b[j][k];
            }
	    printf("%ld", num);
            if (k!=l-1) printf(" ");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
    int n,d,x;
    cin >> n >> d >> x;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int sum = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; ; j++) {
            if(j * a[i] + 1 <= d) {
                sum++;
            } else {
                break;
            }
        }
    }

    cout << (sum + x) << endl;
}

Measured memory_bytes: 256
object Main {

  case class Problems(i: Int, p: Int, c: Int) {
    def baseScore: Int = 100 * (i + 1)
    def fullScore: Int = baseScore * p + c
    def untilScore: Int = baseScore * (p - 1)
    def problemsOf(score: Int): Int =
      Math.ceil(score / baseScore.toDouble).toInt
  }

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val D, G = sc.nextInt()
    val problems: IndexedSeq[Problems] = (0 until D).map { i =>
      val p, c = sc.nextInt()
      Problems(i, p, c)
    }

    val INF = Int.MaxValue / 10

    def solve(): Int = {
      def dfs(i: Int, score: Int, unsolved: Option[Int]): Int =
        if (i < D) {
          val problem = problems(i)
          if (score < G)
            (dfs(i+1, score + problem.fullScore, unsolved) + problem.p) min
              dfs(i+1, score, Some(i))
          else dfs(i+1, score, Some(i))
        } else {
          if (score >= G) 0
          else if (unsolved.nonEmpty) {
            val problem = problems(unsolved.get)
            if (score + problem.untilScore >= G)
              problem.problemsOf(G - score)
            else INF
          } else INF
        }
      dfs(0, 0, None)
    }

    println(solve())
  }

}


Measured memory_bytes: 27324
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Map.Entry;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		String line;
		while ((line = reader.readLine()) != null) {
			if (line.isEmpty()) {
				break;
			}
			int n = Integer.parseInt(line);
			char[] a = new StringBuilder(Integer.toBinaryString(n)).reverse()
					.toString().toCharArray();
			int count = 0;
			for (int i = 0; i < a.length; i++) {
				if (a[i] != '0') {
					if (count != 0) {
						builder.append(' ');
					}
					builder.append((int) Math.pow(2, i));
					count++;
				}
			}
			builder.append('\n');
		}
		System.out.print(builder);
	}
}

Measured memory_bytes: 16888
N,M,C = list(map(int,input().split(" ")))
bs = map(int,input().split(" "))
bs = list(bs)
ans = 0
for i in range(N):
    num = 0
    As = map(int, input().split(" "))
    As = list(As)
    for a,b in zip(As,bs):
        num += a*b
    num += C
    if num >0:
        ans += 1

print(ans)


Measured memory_bytes: 3060
n = int(input())
x, y = 1, 1
for _ in range(n):
    t, a = map(int, input().split())
    if x <= t and y <= a:
        x = t
        y = a
    elif x <= t and y > a:
        if y % a == 0:
            i = y // a
        else:
            i = y // a + 1
        y = i*a
        x = i*t
    elif x > t and y <= a:
        if x % t == 0:
            i = x // t
        else:
            i = x // t + 1
        x = i*t
        y = i*a
    elif x > t and y > a:
        if x % t == 0:
            i_x = x // t
        else:
            i_x = x // t + 1

        if y % a == 0:
            i_y = y // a
        else:
            i_y = y // a + 1
        bigger = max(i_x, i_y)
        x = bigger*t
        y = bigger*a
print(x+y)

Measured memory_bytes: 73472
//https://atcoder.jp/contests/abc138/tasks/abc138_b
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define aakriti float
int main()
{
	int n;
	cin >> n;
	vector<aakriti>v(n) ;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		v[i] = (float(1)) / x;
	}
	aakriti sum = 0;
	for (auto x : v) sum += x;
	sum = 1.0 / sum;
	cout << sum << endl;
}

Measured memory_bytes: 256
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>

using namespace std;

long double eps = 1e-12;
vector<vector<long double>> POINTS;
int D, N;

void solve() {
	cin >> N >> D;
	POINTS.resize(N);
	for (int n = 0; n < N; n++) {
		POINTS[n].resize(D);
		for (int d = 0; d < D; d++) {
			cin >> POINTS[n][d];
		}
	}
	int counter = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			long double dist = 0;
			for (int d = 0; d < D; d++) {
				dist += (POINTS[i][d] - POINTS[j][d]) * (POINTS[i][d] - POINTS[j][d]);
			}
			dist = sqrt(dist);
			if (dist - floor(dist) < eps && dist-floor(dist) > -eps)counter++;
		}
	}
	cout << counter << endl;
	return;
}

Measured memory_bytes: 256
#include<cstdio>
const int MAXN=1000005;
int n;
int s[MAXN];
int main()
{
	int ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&s[i]);
	for(int i=1;i<n;i++)
		if(s[i]==s[i+1])
		{
			ans++;
			i++;
		}
	printf("%d",ans);
}

Measured memory_bytes: 128
#pragma GCC optimize(2) 
#include<iostream>

using namespace std;
const int mod=998244353;
long long a[100010];
long long n,x;
long long ksm(long long a,long long b){
	long long res=1;
	while(b){
		if(b&1){
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}

int main(){
//	ios::sync_with_stdio(0);
//	cin.tie(0),cout.tie(0);
	scanf("%lld",&n);
	int flag=0;
	scanf("%lld",&x);
	int ans=x;
	if(x!=0) flag=1;
	for(int i=1;i<n;i++){
		scanf("%lld",&x);
		a[x]++;
		if(x==0) flag=1;
		if(x>ans){
			ans=x;
		}
	}
	
	if(flag){
		printf("0\n");
	}
	else{
	long long sum=1;
		for(int i=1;i<ans;i++){
			if(a[i]==0){
				flag=1;
				break;
			}
			sum*=ksm(a[i],a[i+1]);
			sum%=mod;
//			cout<<"SUM:"<<sum<<endl;
		}
		if(flag) printf("0\n");
		else printf("%lld\n",sum);
	}
	return 0;
} 

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    int x,y,r;
    int W,H;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x-r<0||y-r<0||x+r>W||y+r>H){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 584
#include<iostream>
#include<string>
using namespace std;
const long double bi = 380000.0;
int N;
long double m, ans;
string s;
int main(){
  cin >> N;
  ans =0;
  for(int i=0; i<N; i++){
    cin >> m >> s;
    if (s == "JPY"){
      ans += m;
    }
    else ans += m *bi;
  }
  cout << ans << endl;
  return 0;
}

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


int main() {
 int N;
 string S;
 cin >> N >> S;

  int count=0;
  int count_max=0;

  for(int i=0;i<N;i++){
    if(S.at(i)=='I'){
      count++;
    }
    else{
      count--;
    }
    count_max=max(count,count_max);
  }

  cout << count_max <<endl;
}

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

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

    int n;
    cin >> n;
    
    vector<string> A(n), B(n);
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        string a = s, b = s;
        for(int j = 0; j < s.size(); j++){
            if(s[j] == '?'){
                a[j] = 'a';
                b[j] = 'z';
            }
        }
        A[i] = a;
        B[i] = b;
    }

    string t;
    cin >> t;

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    int l = lower_bound(B.begin(), B.end(), t) - B.begin();
    int r = upper_bound(A.begin(), A.end(), t) - A.begin();

    for(int i = l; i <= r; i++){
        cout << i + 1;
        if(i != r) cout << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int i;
  int64_t ans=k;
  for(i=0;i<n-1;i++){
    ans=ans*(k-1);
  }
  cout << ans;
}
    
    
  

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

int main() {
    int a, b, k;
    cin >> a >> b >> k;

    if (b - a + 1 <= 2 * k) {
        for (int i = a; i <= b; i++) {
            cout << i << endl;
        }
    } else {
        for (int i = a; i < a+k; i++) {
            cout << i << endl;
        }
        for (int i = b-k+1; i<= b; i++) {
            cout << i << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

vector<string> s(1000);
int visited[1010][1010];
int h, w, ch, cw, dh, dw;
vector<P> moves = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };

bool is_range(int y, int x) {
  return 0 <= y && 0 <= x && y < h && x < w;
}
bool is_wall(int y, int x) {
  return s[y][x] == '#';
}
bool already_visited(int y, int x, int dist) {
  return visited[y][x] <= dist;
}
bool is_goal(int y, int x) {
  return y == dh && x == dw;
}

// 0-1 BFS
void bfs() {
  deque<P> d;
  d.emplace_back( ch, cw );

  while(!d.empty()) {
    auto v = d.front(); d.pop_front();
    int y = v.first, x = v.second;
    int nd = visited[y][x];
    int ndd = nd+1;
    for(auto move:  moves) {
      int ny = y + move.first;
      int nx = x + move.second;

      if (!is_range(ny, nx)) continue;
      if (already_visited(ny,nx,nd)) continue;

      if (!is_wall(ny,nx)) {
        visited[ny][nx] = nd;
        d.emplace_front( ny, nx );
      } else {
        for (int i = -2; i <= 2; i++) {
          for (int j = -2; j <= 2; j++) {
            if (i==0 && j==0) continue;
            int ni = i+y;
            int nj = j+x;

            if (!is_range(ni,nj)) continue;
            if (is_wall(ni,nj)) continue;
            if (already_visited(ni,nj,ndd)) continue;

            visited[ni][nj] = ndd;
            d.emplace_back( ni, nj );
          }
        }
      }
    }
  }
}

int main() {
  IOS;
  cin >> h >> w;
  cin >> ch >> cw;
  cin >> dh >> dw;
  REP(i,h) cin >> s[i];
  ch--; cw--; dh--; dw--;
  REP(i,1010) REP(j,1010) visited[i][j] = INF;
  visited[ch][cw] = 0;

  bfs();

  if (visited[dh][dw] != INF) {
    COUT(visited[dh][dw]);
    return 0;
  }

  COUT(-1);
  return 0;
}


Measured memory_bytes: 8652
N, X  = map(int, input().split())
L = list(map(int, input().split()))

bound = []
for _ in range(N+1):
  bound.append(0)

for i in range(1,N+1):
  bound[i] = bound[i-1]+L[i-1]

ans = 0

for i in range(N+1):
  if bound[i] <= X:
    ans += 1
  else: 
   break

print(ans)

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

using namespace std;

long long n;

void dfs(string s,char lim){
    if(s.size()==n){
        cout<<s<<endl;
        return;
    }
    
    for(char i='a';i<=lim+1;i++){
        string hoge;
        hoge.push_back(i);
        dfs(s+hoge,max(i,lim));
    }
}

int main(){
    cin>>n;
    dfs("a",'a');
}


Measured memory_bytes: 1536
z='abcdefghijklmnopqrstuvwxyz'
e=lambda x,i,j:z[(z.index(x)*i+j)%26]
def f():
 for i in(1,3,5,7,9,11,15,17,19,21,23,25):
  for j in range(26):
   if''.join(e(c,i,j)for c in'that')in s or''.join(e(c,i,j)for c in'this')in s:return(i,j)
def g(x,y,s=0,t=1):
 q,r=x//y,x%y
 return g(y,r,t,s-q*t) if r else t
for _ in[0]*int(input()):
 s=input()
 a,b=f()
 h=g(26,a)
 print(''.join(z[h*(z.index(c)-b)%26]if c in z else c for c in s))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
vector<string> ans;
int n;

void dfs(int curr , int last , string s){
	if(curr == n){
		ans.push_back(s);
		return ;
	}
	if(s[curr] == '-'){
		s[curr] = 'a'+last;
		last += 1;
	}
	for(int i = curr+1 ; i < n ; i += 1){
		if(s[i] == '-'){
			string ss = s;
			ss[i] = ss[curr];
			dfs(curr+1,last,ss);
		}
	}
	dfs(curr+1,last,s);
}

int main(){
	cin >> n;
	string s = "";
	for(int i = 0 ; i < n ; i += 1){
		s += '-';
	}
	dfs(0,0,s);
	sort(ans.begin(),ans.end());
	for(string i : ans){
		cout << i << '\n';
	}
}

Measured memory_bytes: 7796
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100000
#define MO 1000000007
using namespace std;
int N,a[MAXN+5],d[MAXN+5],pre[MAXN+5];
int cnt[MAXN+5],f[MAXN+5];
bool vis[MAXN+5];
int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d",&a[i]),d[a[i]]++;
	for(int i=1;i<=N;i++)
		if(d[i]>2)
		{
			printf("0\n");
			return 0;
		}
	for(int i=1;i<=N;i++)
		if(d[i]==2&&vis[i]==false)
		{
			int p=i;
			do
			{
				if(vis[p]==true)
				{
					printf("0\n");
					return 0;
				}
				vis[p]=true;
				pre[a[p]]=p;
				p=a[p];
			}while(p!=i);
		}
	int ans=1;
	for(int i=1;i<=N;i++)//处理基环内向树 
		if(d[i]==0)
		{
			int p=i,len1=0,len2=0;
			do
			{
				vis[p]=true;
				p=a[p];
				len1++;
			}while(vis[p]==false);
			do
			{
				p=pre[p];
				len2++;
			}while(d[p]==1);
			if(len1>len2)
			{
				printf("0\n");
				return 0;
			}
			if(len2>len1)
				ans=2LL*ans%MO;
		}
	for(int i=1;i<=N;i++)//处理单个的循环 
		if(vis[i]==false)
		{
			int len=0,p=i;
			do
			{
				p=a[p];
				vis[p]=true;
				len++;
			}while(p!=i);
			cnt[len]++;
		}
	for(int i=1;i<=N;i++)
		if(cnt[i])
		{
			int mul=1;
			if(i%2==1&&i!=1)
				mul=2;
			f[0]=1,f[1]=mul;
			for(int j=2;j<=cnt[i];j++)
				f[j]=(1LL*f[j-2]*(j-1)%MO*i%MO+1LL*f[j-1]*mul%MO)%MO;
			ans=1LL*ans*f[cnt[i]]%MO;
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1408
N=int(input())
a=list(map(int, input().split())) 
Min=min(a)
Max=max(a)
M=0
for j in range(N):
    M=M+a[j]**2
for i in range(Min,Max+1):
    S=0
    for k in range(N):
        S=S+(a[k]-i)**2
    if S<M:
        M=S
print(M)

Measured memory_bytes: 3064
type Point = (i32,i32);

fn main() {
    let (w,h) = read_pair();
    let grid: Vec<Vec<u8>> = (0..w).map(|_| get_line().into_bytes()).collect();
    let prepare
        = |(sx, sy): Point, im: i32, (ix, iy): Point, jm: i32, (jx, jy): Point|{
        let mut memo = vec![vec![0;h as usize];w as usize];
        for i in 0..im { for j in 0..jm {
            let (x,y) = (sx +i*ix +j*jx, sy +i*iy +j*jy);
            match grid[x as usize][y as usize] {
                b'#' => memo[x as usize][y as usize] = 0,
                _ => {
                    if j == 0 { memo[x as usize][y as usize]=1; }
                    else { memo[x as usize][y as usize]=memo[(x-jx)as usize][(y-jy)as usize]+1; }
                }
            }
        }}
        memo
    };
    let l = prepare((  0,  0), h, ( 0, 1), w, ( 1, 0));
    let r = prepare((w-1,  0), h, ( 0, 1), w, (-1, 0));
    let u = prepare((  0,  0), w, ( 1, 0), h, ( 0, 1));
    let d = prepare((  0,h-1), w, ( 1, 0), h, ( 0,-1));
    let ans = {
        let mut ans = 0;
        for i in 0..w as usize { for j in 0..h as usize {
            ans = std::cmp::max(ans, l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
        }}
        ans
    };
    println!("{}", ans);
}

fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}
fn read<T: std::str::FromStr>() -> T{
    get_line().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T>{
    get_line().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_pair<T: std::str::FromStr + Copy>() -> (T,T){
    let v:Vec<T> = read_vec(); (v[0], v[1])
}
fn read_triple<T: std::str::FromStr + Copy>() -> (T,T,T){
    let v:Vec<T> = read_vec(); (v[0], v[1], v[2])
}

Measured memory_bytes: 73980
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t;
ll n,arr[10005];
string s;
int main()
{
    cin>>s;
    int l=s.length(),mx=0,cnt=0;
    for(int i=0;i<l;i++){
        cnt=0;
        while(s[i]=='R'){
            i++,cnt++;
        }
        mx=max(mx,cnt);

    }
    cout<<mx<<endl;
    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define all(x) (x).begin(), (x).end() 

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

long long INF=numeric_limits<long long>::max();

int vis[200222];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int a,b,c,d,n;
    cin >> n >> a >> b >> c >> d;
    a--; b--; c--; d--;
    string s; cin >> s;
    bool found = 0; int ptr = -1;
	bool ok = 1;
    for(int i = 0; i < s.length(); i++){
		if(s[i]=='#')
		{
			vis[i]++;
		}
	}
	for(int i = b; i < d; i++)
	{
		if(vis[i]&&vis[i+1]){
			ok = 0;
			break;
		}else if(!found&&!vis[i-1]&&!vis[i]&&!vis[i+1]){
			found = 1;
			ptr = i;
		}
	}
	if(c>d)
	{
		if(found)vis[ptr]=1;
		else vis[d] = 1;
	}
	for(int i = a; i < c; i++)
	{
		if(vis[i]&&vis[i+1]){
			ok = 0;
			break;
		}
	}
	if(ok)cout << "Yes" << endl;
	else cout << "No" << endl;
}	


Measured memory_bytes: 1360
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int[] a = new int[4];
		for(int i = 0 ; i < 4 ; i++){
			a[i] = Integer.parseInt(sc.next());
		}
		ou.print((a[0] - a[2]) * (a[1] - a[3]));
		ou.flush();
    }
}

Measured memory_bytes: 35864
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
  int a,n;
  cin >> n;
  vector<int> ans(n+1);
  for(int i=2; i <(n+1); i++){
    cin >> a;
    ans[a] +=1;
  }
  for(int i=1; i<n+1;i++) cout << ans[i]<<endl;
}


Measured memory_bytes: 3928
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(void)
{
    string b;
    cin>>b;
    if(b=="A")
    {cout<<"T\n";}
    else if(b=="C")
    {cout<<"G\n";}
    else if(b=="G")
    {cout<<"C\n";}
    else
    {cout<<"A\n";}
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m=0,p;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        m=m^a[i];
    }
    p=m;
    for(int i=0; i<n; i++)
    {
        p=m^a[i];
        cout<<p<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 4324
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        List<Integer> inputs = new ArrayList<Integer>();

        Scanner sc = new Scanner(System.in);
        for(int i=0; i<10; i++) {
            if(!sc.hasNextInt()) {
                break;
            }
            int input = sc.nextInt();
            inputs.add(Integer.valueOf(input));
        }

        Collections.sort(inputs, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        
        for(int height : inputs.subList(0, Math.min(inputs.size(), 3))) {
            System.out.println(height);
        }
    }
}

Measured memory_bytes: 26240
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int H, W, N;
    cin >> H;
    cin >> W;
    cin >> N;

    cout << ((N - 1) / max(H, W)) + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
a,b,c,x,y=input().split()
a=int(a)
b=int(b)
c=int(c)
x=int(x)
y=int(y)
ans = 5000 * 100000 * 3 * 2
ans1 = a*x+b*y
ans2 = a*max(0,x-y)+c*2*y
ans3 = b*max(0,y-x)+c*2*x
print(min([ans1, ans2, ans3]))

Measured memory_bytes: 3064
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
int gcd(int a, int b) // assuming a,b >= 1
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    if (a % b == 0)
        return b;
    return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
    return  a * b / gcd(a, b);
}
using namespace std;
#pragma endregion
signed main() {
    int N;
    string S;
    cin >> S;
    N = S.size();
    rep(i, N-1) {
        if (S[i]== S[i+1]) {
            cout << "Bad";
            return 0;
        }
    }
    cout << "Good";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int array[];
    static int ans[];

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

        int n = sc.nextInt();

        if (n % 1000 == 0)  {
            System.out.println(0);
            return;
        }

        System.out.println(1000 - (n % 1000));

        sc.close();

    }

}

Measured memory_bytes: 35728
#include<bits/stdc++.h>
using namespace std;
struct pr{
	int cost,to;
	bool operator>(const pr&oth)const{return this->cost>oth.cost;}
};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int v,e,r; cin>>v>>e>>r;
	vector<vector<pr>>g(v);
	for(int i=0;i<e;++i){
		int s,t,d; cin>>s>>t>>d;
		g.at(s).push_back({d,t});
	}
	vector<int>mn(v,2e9); mn.at(r)=0;
	priority_queue<pr,vector<pr>,greater<pr>>q;
	q.push({0,r});
	while(q.size()){
		int nw=q.top().to,nwcost=q.top().cost; q.pop();
		if(nwcost>mn.at(nw))continue;
		for(auto&&i:g.at(nw)){
			int nxp=i.to,nxcost=nwcost+i.cost;
			if(nxcost>mn.at(nxp))continue;
			mn.at(nxp)=nxcost;
			q.push({nxcost,nxp});
		}
	}
	for(auto&&i:mn){
		if(i!=2e9)cout<<i;
		else cout<<"INF"s;
		cout<<"\n"s;
	}
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

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

using namespace std;

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

const int limit=1<<24;
using S=short int;

S pre[3][limit];
S dist[limit];

inline int hstar(int n,int cmask,int tmask){
	int ret=0;
	rep(i,n){
		int cur=(cmask>>(8*i))&255;
		chmax<int>(ret,pre[i][cur]);
	}
	return ret;
}

int main(void){
	int w,h,n;
	
	while(cin >> w >> h >> n,n){
		int smask=0,tmask=0;
		string board[16];
		
		cin.ignore();
		rep(i,h) getline(cin,board[i]);

		// cout << w << " " << h << " " << n << endl;
		// rep(i,h) cout << board[i] << endl;

		rep(i,h)rep(j,w)rep(k,3){
			if(board[i][j]==('a'+k)) smask|=((16*i+j)<<(8*k));
			if(board[i][j]==('A'+k)) tmask|=((16*i+j)<<(8*k));
		}

		rep(i,3){
			fill(pre[i],pre[i]+256,300);
			const int start=(tmask>>(8*i))&255;
			pre[i][start]=0;
			queue<int> q;
			q.push(start);
			while(!q.empty()){
				int cmask=q.front();q.pop();
				const int cy=cmask/16,cx=cmask%16;
				rep(j,4){
					const int ny=cy+dy[j],nx=cx+dx[j];
					if(board[ny][nx]=='#') continue;
					if(chmin<S>(pre[i][16*ny+nx],pre[i][16*cy+cx]+1)) q.push(16*ny+nx);
				}
			}	
		}

		fill(dist,dist+limit,30000);
		dist[smask]=0;
		using state=tuple<S,int>;
		priority_queue<state,vector<state>,greater<state>> q;
		q.push(state(0,smask));

		while(!q.empty()){
			int cost,cmask;
			tie(cost,cmask)=q.top();q.pop();

			if(dist[tmask]!=30000) break;

			int cy[3],cx[3],tmp=cmask;
			rep(i,n){
				cx[i]=tmp&15;
				tmp>>=4;
				cy[i]=tmp&15;
				tmp>>=4;
			}

			const int all=pow<int>(5,n);

			rep(mask,all){
				const int didx[3]={mask%5,mask/5%5,mask/25};
				int ny[3],nx[3];
				rep(i,n){
					ny[i]=cy[i]+dy[didx[i]];
					nx[i]=cx[i]+dx[didx[i]];
				}
				
				bool ok=true;
				rep(i,n) if(board[ny[i]][nx[i]]=='#') ok=false;
				if(ok==false) continue;
				rep(i,n)rep(j,i) if(ny[i]==ny[j] && nx[i]==nx[j] ) ok=false;
				if(ok==false) continue;
				rep(i,n)rep(j,i) if(ny[i]==cy[j] && nx[i]==cx[j] && ny[j]==cy[i] && nx[j]==cx[i]) ok=false;
				if(ok==false) continue;


				int nmask=0;
				rep(i,n) nmask|=(16*ny[i]+nx[i])<<(8*i);

				if(chmin<S>(dist[nmask],dist[cmask]+1)) q.push(state(dist[nmask]+hstar(n,nmask,tmask),nmask));		
			}

		}
		cout << dist[tmask] << endl;
	}	
	return 0;
}

Measured memory_bytes: 38968