akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

#define debug(x) cerr<<#x<<'='<<x<<'\n'

namespace T {
	int l[23333333], r[23333333];
	int size[23333333];
	long long v[23333333];
	int root=0, tot=0;
	int merge(int x, int y) {
		if (!x || !y) {
			return x+y;
		}
		if (v[x]<v[y]) {
			swap(x, y);
		}
		r[x]=merge(r[x], y);
		size[x]+=size[y];
		if (size[l[x]]<size[r[x]]) {
			swap(l[x], r[x]);
		}
		return x;
	}
	inline long long top(void) {
		if (!root) {
			return -0x3f3f3f3f;
		} else {
			return v[root];
		}
	}
	inline void pop(void) {
		root=merge(l[root], r[root]);
	}
	inline void insert(long long x) {
		++tot;
		l[tot]=r[tot]=0;
		size[tot]=1;
		v[tot]=x;
		root=merge(root, tot);
	}
}

long long a[66];

int main(void) {
	int n;
	scanf("%d", &n);
	for (int i=1; i<=n; i++) {
		scanf("%lld", a+i);
		T::insert(a[i]);
	}
	long long k=0;
	while (T::top()+k>=n) {
		long long p=T::top()+k;
	//	debug(p);
		T::pop();
		k+=p/n;
	//	debug(k);
		p%=n;
	//	debug(p);
		T::insert(p-k);
	}
	cout<<k;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	int n;
	cin >> n;
	ll i=1;
	while(i*2 <= n){
		i*=2;
	}
	cout << i;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

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

    ll ans1 = 0, ans2 = 0;
    ll sum1 = 0, sum2 = 0;
    // + - + - + - ...
    for(int i=0; i<N; i++){
        sum1 += a[i];
        if(i%2 == 0 && sum1 <= 0){
            ans1 += 1-sum1;
            sum1 = 1;
        }
        else if(i%2 == 1 && sum1 >=0){
            ans1 += 1+sum1;
            sum1 = -1;
        } 
    }

    // - + - + - + ...
    for(int i=0; i<N; i++){
        sum2 += a[i];
        if(i%2 == 0 && sum2 >= 0){
            ans2 += 1+sum2;
            sum2 = -1;
        }
        else if(i%2 == 1 && sum2 <=0){
            ans2 += 1-sum2;
            sum2 = 1;
        } 
    }

    cout << min(ans1, ans2) << endl;

    // const int inf = 1<<29;
    // vector<ll> dp(100005, 0); // dp[i]:= i段目までの登り方の総数%mod
    // vector<bool> broken(100005, false);

    // dp[0] = 1;
    // if(broken[1] == true) dp[1] = 0;
    // else dp[1] = 1;

    // for(int i=2; i<=N; i++){
    //     if(broken[i] == true) dp[i] = 0;

    //     dp[i] = dp[i-1]+dp[i-2];
    //     dp[i] %= mod;
    // }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 9999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> K >> S;
  T=S;
  Sort(T);
  rrep(i,N,0){
    if(S[i]==T[0])sum++;
    else break;
  }
  while(N>sum){
    if(sum>0)sum*=2;
    else sum++;
    num++;
  }
  if(K>=num){
    rep(i,0,N)NeOut(T[0]);
    Out("");
  }
  else{
    rep(i,0,K-1){
      Vec(G,string,0,"");
      T=S;
      Rev(T);
      S+=T;
      Rev(S);
      rep(j,0,N+1){
        T=S.substr(j,N);
        G.pb(T);
      }
      Sort(G);
      S=G[0];
      Rev(S);
      //Out(S);
    }
    Vec(G,string,0,"");
    T=S;
    Rev(T);
    S+=T;
    rep(i,0,N+1)G.pb(S.substr(i,N));
    Sort(G);
    Out(G[0]);
  }
}



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

using namespace std;

const int max_n = 100111, inf = 1000111222;

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

int n, k;
vector<int> p, q;

vector<int> inv(const vector<int> &p) {
    vector<int> res(p.size());
    for (int i = 0; i < res.size(); ++i) {
        res[p[i]] = i;
    }
    return res;
}

vector<int> product(const vector<int> &p, const vector<int> &q) {
    vector<int> res(p.size());
    for (int i = 0; i < res.size(); ++i) {
        res[i] = p[q[i]];
    }
    return res;
}

vector<int> power(const vector<int> &v, int k) {
    vector<int> res(v.size());
    for (int i = 0; i < res.size(); ++i) {
        res[i] = i;
    }
    if (k == 0) {
        return res;
    }
    --k;
    vector<char> used(v.size());
    for (int i = 0; i < v.size(); ++i) {
        if (!used[i]) {
            int pos = i;
            vector<int> q;
            while (!used[pos]) {
                q.push_back(v[pos]);
                used[pos] = 1;
                pos = v[pos];
            }
            vector<int> w(q.size());
            for (int i = 0; i < w.size(); ++i) {
                w[i] = (q[(i + k) % w.size()]);
            }
            reverse(w.begin(), w.end());
            while (!w.empty()) {
                res[pos] = w.back();
                w.pop_back();
                pos = v[pos];
            }
        }
    }
    return res;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d", &n, &k);
    p.resize(n);
    q.resize(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &p[i]);
        --p[i];
    }
    for (int i = 0; i < n; ++i) {
        scanf("%d", &q[i]);
        --q[i];
    }
    --k;
    vector<int> v = product(q, product(inv(p), product(inv(q), p)));
    vector<int> cur = power(v, k / 6);
    k %= 6;
    p = product(cur, product(p, inv(cur)));
    q = product(cur, product(q, inv(cur)));
    while (k--) {
        vector<int> v = product(q, inv(p));
        p = q;
        q = v;
    }
    for (int x : p) {
        printf("%d ", x + 1);
    }
    puts("");
    return 0;
}


Measured memory_bytes: 3180
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr1 = new int[n];
    int[] arr2 = new int[n];
    for(int i = 0; i < n; i++) {
      int tmp = sc.nextInt();
      arr1[i] = tmp;
      arr2[i] = tmp;
    }
    Arrays.sort(arr1);
    int center_1 = arr1[n / 2 - 1];
    int center_2 = arr1[n / 2];
    for(int i = 0; i < n; i++) {
      if(center_1 == arr2[i]) {
        System.out.println(center_2);
      } else if(center_2 == arr2[i]) {
        System.out.println(center_1);
      } else if(arr2[i] < center_1 && arr2[i] < center_2) {
        System.out.println(center_2);
      } else if(arr2[i] > center_1 && arr2[i] > center_2) {
        System.out.println(center_1);
      }
    }
  }
}


Measured memory_bytes: 91956
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    int a, b;
    cin >> a >> b;
    int ab = b-a;
    int k = ab*(ab+1)/2;
    cout << k-b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int x;
    scanf("%d",&x);
    if(x%100>=1&&x%100<=12){
        if(x/100>=1&&x/100<=12){
            printf("AMBIGUOUS");
        }
        else{
            printf("YYMM");
        }
    }
    else{
        if(x/100>=1&&x/100<=12){
            printf("MMYY");
        }
        else{
            printf("NA");
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
    int n,ans = -1;
    cin >> n;
    for(float i=1;i<=n;i++){
        if(int(i * 1.08) == n){
            ans = i;
        }
    }
    if(ans != -1){
        cout << ans << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, X, M;
    cin >> N >> X >> M;

    vector<int> ord(M, -1);
    vector<ll> rireki, syu;
    ll res = 0;
    for (int n = 0; n < N; n++) {
        if (ord[X] != -1) {
            int p = ord[X];
            for (int i = p; i < n; i++) {
                syu.push_back(rireki[i]);
            }
            break;
        }
        ord[X] = n;
        rireki.push_back(X);
        res += X;
        X = (X * X) % M;
        cerr << X << endl;
    }
    N -= rireki.size();
    if (N == 0)
    {
        cout << res << endl;
        return 0;
    }

    vector<ll> sum(syu.size() + 1, 0);
    for (int i = 0; i < syu.size(); i++)
        sum[i + 1] = sum[i] + syu[i];

    ll q = N / syu.size();
    ll r = N % syu.size();
    res += sum[syu.size()] * q + sum[r];
    cout << res << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; ++i)

const int MAX = 17;
int N;
ll A[MAX][MAX];

ll dp[1<<MAX];

int main () {
	cin >> N;
    REP (i, N) REP (j, N) cin >> A[i][j];

    REP (i, (1<<N)) {
        ll res = 0;
        REP (j, N) REP (k, j)
            if ((i>>j)&(i>>k)&1) res += A[j][k];

        for (int j = i; j > 0; j = (j-1)&i)
            res = max(res, dp[j]+dp[i^j]);

        dp[i] = res;
    }
    cout << dp[(1<<N)-1] << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()

int main() {
    int n; cin>>n;
    vector<int> a(n), b(n);
    rep(i,n){
        a[i] = 30000 * i + 1;
        b[i] = 30000 * (n - i);
    }
    rep(i,n){
        int p; scanf("%d", &p);
        a[p-1] += i;
    }

    rep(i,n){
        printf("%d", a[i]);
        if(i==n-1) puts(""); else printf(" ");
    }

    rep(i,n){
        printf("%d", b[i]);
        if(i==n-1) puts(""); else printf(" ");
    }

    return 0;
}

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

int n,m,M,t[1000100];

int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&m);
		t[m]++;
		if(t[m]>2) t[m]-=2;
	}
	M=m=0;
	for(int i=1;i<=100000;i++){
		if(t[i]) m++;
		if(t[i]==2) M^=1;
	}
	m-=M;
	printf("%d\n",m);
	return 0;
} 

Measured memory_bytes: 640
n=int(input())
s=list(input())
INF=10**10
cost_w=0
cost_b=s.count(".")
ans=[INF for i in range(n+1)]
ans[0]=cost_b
for i in range(n):
    if s[i]=="#":
        cost_w+=1
    else:
        cost_b-=1
    ans[i+1]=cost_w+cost_b
print(min(ans))

Measured memory_bytes: 12740
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> A(N);
	for (ll i = 0; i < N; ++i) cin >> A[i];
	vector<ll> sum(N+1, 0);
	for (ll i = 0; i < N; ++i)
		++sum[A[i]];

	ll s{0};
	for (ll i = 1; i <= N; ++i)
		s += sum[i] * (sum[i]-1)/2;
	for (ll i = 0; i < N; ++i)
	{
		std::cout << s - sum[A[i]] + 1<< std::endl;
	}
}

Measured memory_bytes: 5760
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;

typedef long long LL;

const int N = 200005;

int n, a[N];

map<int, int> mp;

LL ans = 0;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		ans += mp[i - a[i]];
		mp[a[i] + i]++;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 20896
#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int H, W, C, P[7][8][8];

int isin(int y, int x) {
  return 0 <= y && y < H && 0 <= x && x < W;
}

int color(int n, int c, int d, int y, int x) {
  if(P[n + 1][y][x] != d) return 0;

  int dd[5] = { 0, 1, 0, -1, 0 };
  int ret = 1;
  P[n + 1][y][x] = c;
  REP(i, 0, 4) {
    int ny = y + dd[i], nx = x + dd[i + 1];
    if(!isin(ny, nx)) continue;
    ret += color(n, c, d, ny, nx);
  }

  return ret;
}

int dfs(int n) {
  if(n == 5) {
    REP(i, 0, H) REP(j, 0, W) P[n + 1][i][j] = P[n][i][j];
    return color(n, 100, C, 0, 0);
  }

  int ret = 0;
  REP(i, 1, 7) {
    if(P[n][0][0] == i) continue;
    REP(i, 0, H) REP(j, 0, W) P[n + 1][i][j] = P[n][i][j];
    color(n, i, P[n][0][0], 0, 0);
    ret = max(ret, dfs(n + 1));
  }
  return ret;
}

int main(void) {
  while(cin >> H >> W >> C, H) {
    REP(i, 0, H) REP(j, 0, W) {
      cin >> P[0][i][j];
      REP(k, 1, 7) P[k][i][j] = 0;
    }
    cout << dfs(0) << endl;
  }

  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N+1);
    vector<int> B(N+1);
    vector<int> C(N);
    for (int i = 1; i <= N; i++) {
        scanf("%d", &A.at(i));
    }
    for (int i = 1; i <= N; i++) {
        scanf("%d", &B.at(i));
    }
    for (int i = 1; i <= N-1; i++) {
        scanf("%d", &C.at(i));
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += B.at(A.at(i));
        if (i >= 2) {
            if (A.at(i) == A.at(i-1) + 1) {
                ans += C.at(A.at(i-1));
            }
        }
    }
    cout << ans << endl;    
}

Measured memory_bytes: 256
N,C =gets.split.map &:to_i
ds = Array.new(C+1){Array.new}
for i in 1..C
    ds[i]=[nil]+gets.split.map(&:to_i)
end
cs = Array.new(N+1){Array.new}
for i in 1..N
    cs[i]=[nil]+gets.split.map(&:to_i)
end
oddness=Array.new(3){Array.new(C+1,0)}
(1..C).to_a.each do |color|
    for i in 1..N
        for j in 1..N
            oddness[(i+j)%3][color]+=ds[cs[i][j]][color]
        end
    end
end
oddness.map!{|e|e[1..-1]}
ans=Float::INFINITY
(0...C).to_a.permutation(3) do |x,y,z|
    j = oddness[0][x]+oddness[1][y]+oddness[2][z]
    ans = j < ans ? j : ans
end
puts ans


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

using namespace std;

pair<int, int> arr [100005];

int main(){
	int n;
	cin>>n;
	for(int i = 0; i<n; i++){
		cin>>arr[i].first>>arr[i].second;
	}
	sort(arr, arr+n);
	cout<<arr[n-1].first+arr[n-1].second<<endl;
	return 0;
}

Measured memory_bytes: 1152
h,w = map(int,input().split())
s = [input() for i in range(h)]
def judge(i,j,s):
    #print('judge')
    for k in range(-1,2):
        for l in range(-1,2):
            if abs(k-l) == 1:
                temp_i = i+k
                temp_j = j+l
                if temp_i < 0 or temp_i-1 > h or temp_j < 0 or temp_j > w-1:
                    #print('pass{} {}'.format(k,l))
                    pass
                else:
                    #print('notpass{} {}'.format(k,l))
                    #print(s[i][j])
                    if s[temp_i][temp_j] == '#':
                        return True
    return False

flag = True
for i in range(h):
    for j in range(w):
        #print('{} {}'.format(i,j))
        if s[i][j] == '#':
            flag = judge(i,j,s)
            if flag == False:
                print('No')
                exit()
print('Yes')


Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (n, c, k) = readLine()!!.split(' ').map(String::toLong)
    val tList = mutableListOf<Long>()
    for (i in 0 until n) tList.add(readLine()!!.toLong())
    tList.sort()
    var countBus = 1L
    var countMan = 1L
    var first = tList[0]
    for (i in 1 until n) {
        val t = tList[i.toInt()]
        if (countMan < c && t <= first + k) {
            countMan++
        }else{
            countMan = 1L
            first = t
            countBus++
        }
    }
    println(countBus)
}

Measured memory_bytes: 44572
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl

//-----
const int N = 1e5 + 7;
int n, a[N];
bool les(int a, int b, int c) {
	a = min(a, c - a);
	b = min(b, c - b);
	return a < b;
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
  cin >> n;
  rep(i, 0, n) cin >> a[i];
	sort(a, a + n);
	int ans = a[0];
	rep(i, 1, n - 1) if (les(ans, a[i], a[n - 1])) ans = a[i];
	cout << a[n - 1] << " " << ans;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=15;
string s[10];
int n,m,k,res;
int main(){
	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	int x=(1<<(n));
	int y=(1<<(m));
	for(int i=0;i<x;i++){
		for(int j=0;j<y;j++){
			int cnt=0;
			for(int a=0;a<n;a++){
				for(int b=0;b<m;b++){
					if(((i>>a)&1)||((j>>b)&1)||s[a][b]=='.')continue;
					cnt++;
					
				}
			}
			if(cnt==k)res++;
		}
	} 
	cout<<res;
}

Measured memory_bytes: 3544
from collections import Counter
N = int(input())
A = []
B = []
E = []
for i in range(N):
  l = list(input().split())
  l[1] = int(l[1])
  A.append(l)
  B.append(l[0])
  E.append(l[1])
A.sort()
C = Counter(B)
C = sorted(C.items(), key=lambda x:x[0])
cnt = 0
for c in C:
  c = c[1]
  D = reversed(A[cnt:cnt+c])
  cnt += c
  for d in D:
    print(E.index(d[1])+1)

Measured memory_bytes: 38512
s=input()
sl=len(s)

def kaibun(ss):
  for i in range(len(ss)//2):
    if ss[i]!=ss[-1-i]:
      print('No')
      exit()

kaibun(s)
kaibun(s[:sl//2])
kaibun(s[sl//2+1:])

print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std ; 
#define ll long long int 
#define pb push_back
#define ff first 
#define dobara(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define ss second 
#define S(x) scanf("%d",&x) 
#define SL(x) scanf("%lld",&x)
#define M 1000000007
#define sz(x) (int)x.size()
#define all(a) (a).begin(),(a).end()

int main(){
	string s , t ; 
	cin>>s>>t ; 
	int ans = 0 ;
	for(int i=0;i<3;i++){
		if(s[i] == t[i])
			ans++ ; 
	}
	cout<<ans<<"\n" ;
}

Measured memory_bytes: 256
N = input().split()
S = list(input())

Slist = list(S)

#print(Slist)

ans = 0
for i in range(0, 1000):
  a = i // 100
  b = (i % 100) // 10
  c = i % 10
  
  if(str(a) in Slist):
    nextList = Slist[Slist.index(str(a))+1:]
    if(str(b) in nextList):
      finalList = nextList[nextList.index(str(b))+1:]
#      print(finalList)
      if(str(c) in finalList):
        ans += 1

print(ans)
  

Measured memory_bytes: 132380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main(){
    int N;
    cin>>N;
    bool exist_odd=false;
    rep(i,N){
        int a;
        cin>>a;
        if(a & 1) exist_odd=true;
    }
    if(exist_odd) puts("first");
    else puts("second");
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
su = int(input())
su_store = su
cnt =0
cnt4 =0
for a_ in range(a+1):
  if cnt4 ==0:
    su = su_store
    su -= 500*a_
   
    if su ==0:
      cnt +=1
      cnt4 +=1
    if su >0:
      cnt3 =0
      for b_ in range(b+1):      
        if cnt3 ==0:
          su -=100*b_
          if su ==0:
            cnt +=1
           
            cnt3 +=1
          if su >0:
            cnt2 = 0
            for c_ in range(c+1):
              if cnt2 ==0:
                su -=50*c_
                
                if su ==0:
                  cnt +=1
                  cnt2 +=1
                su +=50*c_
          su +=100*b_
print(cnt)
        
  

Measured memory_bytes: 3064
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var S = Read();
        var N = S.Length;

        var zero = S.Where(_ => _ == '0').Count();
        var one = N - zero;

        Console.WriteLine(N - Math.Abs(zero - one));
    }


    public static string Read() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read()); }

    public static string[] Reads() { return Console.ReadLine().Split(' '); }
    public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); }
    public static long[] ReadLongs() { return Reads().Select(_ => long.Parse(_)).ToArray(); }
    public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); }
}




/*
----  

----
*/


Measured memory_bytes: 11488
S = list(input())
ans = [0] * len(S)
l_num = 0
counter = 0

for i in range(len(S)):
    if S[i] == "L" and S[i-1] == "R":
        
        if (i - l_num -counter) % 2 == 1:
            # print("a1")
            ans[i] += (i-l_num+1 -counter)/2
            ans[i-1] +=  (i-l_num-1 -counter)/2 + 1
        
        elif (i - l_num -counter) % 2 == 0:
            # print("a2")
            ans[i] += (i-l_num -counter)/2 + 1
            ans[i-1] += (i-l_num -counter)/2

        l_num = i + 1
        counter = 0
    
    elif S[i] == "L" and S[i-1] == "L":
        counter += 1
        if (i - l_num) % 2 == 1:
            # print("b1")
            ans[l_num-1] += 1
        
        elif (i - l_num) % 2 == 0:
            # print("b2")
            ans[l_num-2] += 1

ans = list(map(int, ans))
ans = list(map(str, ans))
print(" ".join(ans))

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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*alias*/
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -fsanitize=signed-integer-overflow -fno-sanitize-recover=all -o template template.cpp

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

signed main()
{
	string s; cin >> s;

	//s is reversed
	reverse(s.begin(), s.end());
	//"dream" to "maerd"
	for(int i = 0, i_len = 4; i < i_len; ++i){
		reverse(divide[i].begin(), divide[i].end());
	}

	bool can = true;
	for(int i = 0, i_len = s.size(); i < i_len;){
		bool can2 = false;
		for(int j = 0, j_len = 4; j < j_len; ++j){
			string d = divide[j];
			if(s.substr(i,d.size()) == d){
				can2 =true;
				i += d.size();
			}
		}
		if(!can2){
			can = false;
			break;
		}
	}
	if(can) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main ()
{
    int a, b, c, x, y, minxy, maxxy, p1, p2, p3;
    scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
    if (x > y)
    {
        minxy = y;
        maxxy = x;
    }
    else
    {
        minxy = x;
        maxxy = y;
    }
    p1 = c * minxy * 2 + (x - minxy) * a + (y - minxy) * b;
    p2 = maxxy * c * 2;
    p3 = a * x + b * y;
    if (p1 < p2)
    {
        if (p1 < p3) printf("%d", p1);
        else printf ("%d", p3);
    }
    else
    {
        if (p2 < p3) printf("%d", p2);
        else printf("%d", p3);
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const int INF = INT_MAX / 4;

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

	while ( true )
	{
		int s, d;
		cin >> s >> d;

		if ( !( s | d ) )
		{
			break;
		}
		
		VI distance( d, INF );
		REP( i, 0, s )
		{
			REP( j, 0, d )
			{
				int tmp;
				cin >> tmp;
				if ( tmp == 0 )
				{
					continue;
				}
				distance[j] = min( distance[j], tmp );
			}
		}

		vector< vector<PII> > G( d );
		REP( i, 0, d - 1 )
		{
			REP( j, 0, d - i - 1 )
			{
				int tmp;
				cin >> tmp;
				if ( tmp == 0 )
				{
					continue;
				}

				G[ i ].PB( MP( i + j + 1, tmp ) );
				G[ i + j + 1 ].PB( MP( i, tmp ) );
			}
		}

		priority_queue< PII, vector<PII>, greater<PII> > que;
		REP( i, 0, d )
		{
			if ( distance[i] == INF )
			{
				continue;
			}
			que.push( MP( distance[i], i ) );
		}

		vector<bool> used( d, false );
		int res = 0;
		while ( !que.empty() )
		{
			auto cur = que.top();
			que.pop();

			if ( used[ cur.snd ] || distance[ cur.snd ] < cur.fst )
			{
				continue;
			}

			res += cur.fst;
			used[ cur.snd ] = true;

			REP( i, 0, G[ cur.snd ].size() )
			{
				auto e = G[ cur.snd ][i];
				if ( distance[ e.fst ] <= e.snd )
				{
					continue;
				}
				distance[ e.fst ] = e.snd;
				que.push( MP( e.snd, e.fst ) );
			}
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>
#define _CRT_SECURE_NO_WARNINGS
using namespace std;

int swap(int &a,int &b){
	int c;
	c=a;
	a=b;
	b=c;

	return 0;
}



int main(){
	int a,b;
	cin>>a>>b;
	cout<<a/b<<" "<<a%b<<" ";
	printf("%.5lf\n",static_cast<double>(a)/b);
	cout<<endl;

	return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>

using namespace std;
int main()
{
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> range(m);
  for (auto i = 0; i < m; i++) {
    long long b, e;
    cin >> b >> e;
    range[i] = make_pair(b, e);
  }

  sort(range.begin(), range.end());

  long long mine = n + 1;
  long long ret = 0;
  for (auto i = 0; i < m; i++) {
    if (mine <= range[i].first) {
      ret++;
      mine = range[i].second;
    } else mine = min(mine, range[i].second);
    while ((i+1) < m && range[i].first == range[i+1].first) {
      i++;
    }
  }
//  size_t cur = 0;
//  for (auto i = 0; i <= n; i++) {
//    if (mine <= i) {
//      ret++;
//      mine = n + 1;
//    }
//    while (cur < m && i == range[cur].first) {
//      mine = min(mine, range[cur].second);
//      cur++;
//    }
//  }

  cout << ret+1 << endl;
  return 0;
}


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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> l(n+1);
    l[0] = 0;
    for(int i = 1; i <= n; i++){
        cin >> l[i];
    }
    int res = 0;
    int val = 0;
    for(int i = 0;i <= n;i++){
        val += l[i];
        if(val > x) break;
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
h = list(map(int, input().split()))

cnt = [0]*n
for i in range(1, n):
    cnt[i] = min(abs(h[m]-h[i])+cnt[m] for m in range(max(0, i-k), i))
print(cnt[n - 1])


Measured memory_bytes: 53344
#include <stdio.h>
#include <math.h>
#define M_PI 3.14159265358979323846

int main(int argc, char *argv[])
{
    double a, b, deg;
    scanf("%lf%lf%lf", &a, &b, &deg);
    const double rad = M_PI * deg / 180;
    const double x = b * cos(rad), y = b * sin(rad);
    const double c = sqrt(pow(a - x, 2) + pow(y, 2));
    printf("%.8lf\n%.8lf\n%.8lf\n", a * y / 2, a + b + c, y);
    return 0;
}



Measured memory_bytes: 2116
kaku = input()
s_list = input().split(' ')
if not int(kaku) == len(s_list):
    print('No')
else:
    hen_list = [int(x) for x in s_list]
    m = max(hen_list)
    total = sum(hen_list)
    if m < total - m:
            print('Yes')
    else:
        print('No')



Measured memory_bytes: 2940
#include<stdio.h>

int main(void)
{
	double r, S, l = 0;
	double p = 3.141592653589;
	
	scanf("%lf", &r);
	
	S = r * r * p;
	l = 2 * p * r;
	
	printf("%lf %lf\n", S, l);
	
	return 0;
	
}




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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#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=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

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

    int R; cin >>R;

    if (R<1200) ANS("ABC");
    else if (R<2800) ANS("ARC");
    else ANS("AGC");
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;
int main(){
 int h,w; cin >>h>>w;
 char a[110][110];
 for(int i=0 ; i < h ; i++){
   for(int j=0; j<w;j++){
     cin >>a[i][j];
   }
 }
for(int i=-1;i<h+1;i++){
  for(int j=-1;j<w+1;j++){
    if(i==-1 || i==h) cout<<'#';
    else{
      if(j==-1 || j==w) cout <<'#';
      else cout<<a[i][j];
    }
  }
  cout <<endl;
}
}


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

struct Node {
    struct Node * previous;
    int matched;
    char value;
    bool selected;
} typedef tNode;

void printNode(tNode * node) {
    if (node->previous != NULL) {
        printNode(node->previous);
    }

    if (node->selected) {
        printf("%c", node->value);
    }
}

void printLargestSubstring(char * s, char * t, int n, int m) {
    int i, j;
    tNode matches[n][m];

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            matches[i][j].matched = 0;
            matches[i][j].previous = NULL;
            matches[i][j].value = '\0';
            matches[i][j].selected = false;
        }
    }

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            matches[i][j].value = s[i];

            if (matches[i][j].value == t[j]) {
                matches[i][j].matched = 1;
                matches[i][j].selected = true;
            } else {
                matches[i][j].matched = 0;
                matches[i][j].selected = false;
            }

            if (i > 0 && j > 0) {
                matches[i][j].previous = &matches[i - 1][j - 1];
                matches[i][j].matched += matches[i][j].previous->matched;
            }

            if (i > 0) {
                if (matches[i - 1][j].matched > matches[i][j].matched) {
                    matches[i][j].previous = &matches[i - 1][j];
                    matches[i][j].matched = matches[i - 1][j].matched;
                    matches[i][j].selected = false;
                }
            }

            if (j > 0) {
                if (matches[i][j - 1].matched > matches[i][j].matched) {
                    matches[i][j].previous = &matches[i][j - 1];
                    matches[i][j].matched = matches[i][j - 1].matched;
                    matches[i][j].selected = false;
                }
            }
        }
    }

    printNode(&matches[n - 1][m - 1]);

    printf("\n");
}

int main() {
    char s[3000], t[3000];

    scanf("%s", s);
    scanf("%s", t);

    int n = strlen(s);
    int m = strlen(t);

    if (n < m) {
        printLargestSubstring(s, t, n, m);
    } else {
        printLargestSubstring(t, s, m, n);
    }

	return 0;
}


Measured memory_bytes: 140800
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int N;
string S;
cin >> N >> S;

int cnt = 0;
// 最大で 10^3 通り
rep(i, 0, 10) rep(j, 0, 10) rep(k, 0, 10){// 整数ijk を探す．
    rep(s, 0, N){
        if ((char)(i + '0') != S[s]) continue;
        else {
            ++s;
            for (; s < N; ++s){
                if ((char)(j + '0') != S[s]) continue;
                else {
                    ++s;
                    for (; s < N; ++s){
                        if ((char)(k + '0') != S[s]) continue;
                        else {
                            ++cnt; 
                            break;
                        }
                    }
                    break;
                }
            }
            break;
        }   
    }
}
cout << cnt << endl;

}

// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void){
    // Your code here!
    int p[200001];
    int n, k;
    int temp;
    
    scanf("%d %d", &n, &k);
    
    for(int i = 0; i < n; i++){
        scanf("%d", &temp);
        if(i == 0) p[i] = temp;
        else p[i] = p[i-1] + temp;
    }
    
    int max = p[k-1];
    for(int i = k; i < n; i++){
        if(max < p[i] - p[i-k]) max = p[i] - p[i-k];
    }
    
    printf("%f\n", (float)(max + k)/2.0);
}


Measured memory_bytes: 896
# coding:utf-8
from scipy.sparse.csgraph import floyd_warshall

int_max = 2 ** 63 - 1

def get_cost(start, end):
    return 1 if start == '.' and end == '.' else 2 ** 63 - 1


def main():

    H, W = map(int, input().split(' '))
    ad_table = [[int_max for _ in range(H*W)] for _ in range(H*W)]
    maze = []
    for _ in range(H):
        maze.append(input())

    for si in range(H):
        for sj in range(W):
            for ti in range(H):
                for tj in range(W):
                    if si == ti and sj == tj:
                        ad_table[(si*W)+sj][(ti*W)+tj] = 0
                    elif (abs(si - ti) == 1 and sj - tj == 0) or (si - ti == 0 and abs(sj - tj) == 1):
                        ad_table[(si*W)+sj][(ti*W)+tj] = get_cost(maze[si][sj], maze[ti][tj])

    res = floyd_warshall(ad_table)
    ans = -1
    for i in range(H*W):
        for j in range(i+1,H*W):
            if res[i][j] != int_max:
                ans = max(res[i][j], ans)
    print(int(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 18008
build = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())

for i in range(n):
    b,f,r,v = map(int, input().split())
    build[b-1][f-1][r-1] += v

for i in range(4):
    if i>=1:
        print("#"*20)
    for j in range(3):
        for k in range(10):
            print(" "+str(build[i][j][k]), end="")
        print()



Measured memory_bytes: 5620
#include<stdio.h>
#include<bits/stdc++.h>
#define uc unsigned char
using namespace std;
int H,W;
int sm[190][190];
int lg[190];
char ss[190][190];

bool query(uc x,uc y,uc l,uc r) {
	int orz = sm[y][r]+sm[x-1][l-1]-sm[x-1][r]-sm[y][l-1];
	if(orz==0||orz==(y-x+1)*(r-l+1)) return 1;
	return 0;
}

int gzt(uc x,uc y,uc l,uc r) {
	x--;  l--; 
	return (y*(y-1)/2+x)*(93*185) + (r*(r-1)/2+l);
}
uc dp[300000000];
uc dfs(uc x,uc y,uc l,uc r) {
	if(query(x,y,l,r)) return 0;
	int zt = gzt(x,y,l,r);
	if(dp[zt]) return dp[zt];
	uc ans = lg[y-x+1] + lg[r-l+1];
	int L = x; int R = y+1;
	while(L+1<R) {
		int mid = (L+R)>>1;
		uc a = dfs(x,mid-1,l,r);
		uc b = dfs(mid,y,l,r);
		if(min(a,b)+1>=ans) break;
		ans = min((uc)ans,(uc)(max(a,b)+1) );
		if(a>=b) R = mid;
		else L = mid;
	}
	L = l; R = r+1;
	while(L+1<R) {
		int mid = (L+R)>>1;
		uc a = dfs(x,y,l,mid-1);
		uc b = dfs(x,y,mid,r);
		if(min(a,b)+1>=ans) break;
		ans = min(ans,(uc)(max(a,b)+1) );
		if(a>=b) R = mid;
		else L = mid;
	}
	return dp[zt] = ans;
}   

int main() {
	scanf("%d%d",&H,&W);
	for(int i=0;i<=185;i++) while((1<<lg[i])<i) lg[i]++;
	for(int i=1;i<=H;i++) {
		scanf("%s",&ss[i][1]);
		for(int j=1;j<=W;j++) {
			sm[i][j] = sm[i-1][j] + sm[i][j-1] - sm[i-1][j-1] + (ss[i][j]=='#' ?1:0 );
		}
	}
	printf("%d",(int)dfs(1,H,1,W) );
}

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

const int N = 2e3 + 5;
int n, m, q, ver[N][N], edO[N][N], edV[N][N], p, y, z, l, ans;
bool x[N][N];
char c;

void readInput() {
	cin >> n >> m >> q;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			cin >> c;
			x[i][j] = (c == '1');
		}
}

void countVer() {
	ver[1][1] = x[0][0];
	for (int i = 1; i < n; i++)
		ver[i + 1][1] = ver[i][1] + x[i][0];
	for (int i = 1; i < m; i++)
		ver[1][i + 1] = ver[1][i] + x[0][i];
	for (int i = 1; i < n; i++)
		for (int j = 1; j < m; j++)
			ver[i + 1][j + 1] = ver[i][j + 1] + ver[i + 1][j] - ver[i][j] + x[i][j];
}

void countEdge() {
	for (int i = 1; i < n; i++)
		edV[i + 1][1] = edV[i][1] + (x[i][0] & x[i - 1][0]);
	for (int i = 1; i < m; i++)
		edO[1][i + 1] = edO[1][i] + (x[0][i] & x[0][i - 1]);
	for (int i = 1; i < n; i++)
		for (int j = 1; j < m; j++)
			edO[i + 1][j + 1] = edO[i][j + 1] + edO[i + 1][j] - edO[i][j] + (x[i][j] & x[i][j - 1]);
	for (int i = 1; i < n; i++)
		for (int j = 1; j < m; j++)
			edV[i + 1][j + 1] = edV[i][j + 1] + edV[i + 1][j] - edV[i][j] + (x[i][j] & x[i - 1][j]);
}

void solve() {
	countVer();
	countEdge();
	while (q--) {
		cin >> p >> y >> z >> l;
		ans = ver[z][l] - ver[p - 1][l] - ver[z][y - 1] + ver[p - 1][y - 1];
		ans -= edO[z][l] + edV[z][l] - edV[z][y - 1] - edV[p][l] + edV[p][y - 1] - edO[z][y] - edO[p - 1][l] + edO[p - 1][y];
		cout << ans << endl;
	}
}


int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve();
	return 0;
}

Measured memory_bytes: 54624
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

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


int H, W;
char mat[1005][1005];
int dist[1005][1005];

signed main()
{
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    cin >> mat[i];
  }

  queue<pii> que;
  memset(dist, INF, sizeof(dist));

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (mat[i][j] == '#') {
        que.emplace(i, j);
        dist[i][j] = 0;
      }
    }
  }

  int ans = 0;

  while(!que.empty()) {
    const auto now = que.front(); que.pop();

    for (int i = 0; i < 4; ++i) {
      const int ny = now.first + dy[i];
      const int nx = now.second + dx[i];
      if (ny < 0 || nx < 0 || ny >= H || nx >= W || dist[ny][nx] < INF) continue;
      const int nc = dist[now.first][now.second] + 1;
      mat[ny][nx] = '#';
      chmin(dist[ny][nx], nc);
      chmax(ans, dist[ny][nx]);
      que.emplace(ny, nx);
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 13328
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main() {
	/*
	int a = 0;//整数変数aを作る
	int b = 0;//整数変数bを作る

	cin >> a >> b;//2つの数字を受け取り、a,bに代入

	cout << a * b << endl;//a*bを出力
	*/
	/*
	string S;
	cin >> S;
	if (S[0]=='7'||S[1]=='7'||S[2]=='7') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	*/
	int a = 0;
	int b = 0;
	int ans = 0;

	cin >> a >> b;

	int apb = a + b;
	int akb = a * b;
	int amb = a - b;
	ans = apb;
	if (ans < a - b) {
		ans = a - b;
	}


	if (ans < a * b) {
		ans = a * b;
	}
	cout << ans << endl;




	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, cnt = 0;
  cin >> a >> b >> c;
  for(int i = a; i <= b; i++){
    if(c % i == 0){
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

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

const ll INF = 1LL << 60;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    vector<ll> dp(n, INF);
    dp[0] = 0;

    rep(i, n)  {
        for (int j = 1; j <= k; j++) {
            int nj = min(i+j, n-1);
            chmin(dp[nj], dp[i]+abs(h[nj]-h[i]));
        }
    }

    cout << dp[n-1] << endl;
    return 0;
}

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

int a[] = {0, 0, 0, 0};
int ans, n;
char c[] = {'+', '+', '+'};

int main(){
    cin >> n;

    for(int i = 0; i < 4; i++){
        a[3 - i] = n % 10;
        n = n/10;
    }

    for(int i = 0; i < 8; i++){
        ans = 0;
        if( (i & 1) == 1){
            ans = a[0] + a[1];
            c[0] = '+';
        }else{
            ans = a[0] - a[1];
            c[0] = '-';
        }
        if( (i & 2) == 2){
            ans = ans + a[2];
            c[1] = '+';
        }else{
            ans = ans - a[2];
            c[1] = '-';
        }
        if ( (i & 4) == 4)
        {
            ans = ans + a[3];
            c[2] = '+';
        }else{
            ans = ans - a[3];
            c[2] = '-';
        }
        if(ans == 7){
            cout << a[0] << c[0] << a[1] << c[1] << a[2] << c[2] << a[3] << "=7" <<  endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
    #define MAX_NUM 300000
     
    int main() {
      int N;
      char S[MAX_NUM + 1];
      
      scanf("%d", &N);
      scanf("%s", S);
      
      int i;
      int W_all = 0;
      int E_all = 0;
      
      for (i = 0; i < N; i++) {
        if (S[i] == 'W') {
          W_all += 1;
        }
        if (S[i] == 'E') {
          E_all += 1;
        }
      }
      
      int W_count = 0;
      int E_count = 0;
      int score = 0;
      int min_score = MAX_NUM;
      
      for (i = 0; i < N; i++) {
        score = W_count + E_all - E_count;
        if (S[i] == 'W') {
          W_count += 1;
        }
        if (S[i] == 'E') {
          E_count += 1;
          score -= 1;
        }
        
        if (score < min_score) {
          min_score = score;
        }
      }
      
      printf("%d\n", min_score);
        
      return 0;
    }

Measured memory_bytes: 512
// Leftmost Ball
// * frank_c1
// * 2017 / 09 / 29

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

LL pow_mod(LL b, LL p, LL k) {
	LL ret = 1;
	for (; p; p >>= 1) {
		if (p & 1) ret = ret * b % k;
		b = b * b % k;
	} return ret;
}

const int maxn = 3005;
const int mo = (int)(1e9) + 7;
LL fac[maxn * maxn], ivf[maxn * maxn];
int f[maxn][maxn];

inline LL C(int n, int m) {
	if (m < 0 || n - m < 0) return 0;
	return (fac[n] * ivf[m] % mo) * ivf[n - m] % mo;
}

inline void add(int& x, int v) {
	x += v; if (x >= mo) x -= mo;
}

int main() {
	int n, K;
	scanf("%d%d", &n, &K);
	if (K == 1) return printf("1\n"), 0;
	int mx = n * (K + 1);
	fac[0] = ivf[0] = 1;
	for (int i = 1; i <= mx; ++i) fac[i] = fac[i - 1] * i % mo;
	ivf[mx] = pow_mod(fac[mx], mo - 2, mo);
	for (int i = mx - 1; i >= 1; --i) ivf[i] = ivf[i + 1] * (i + 1) % mo;
	f[0][0] = 1;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			if (i < j) add(f[i + 1][j], f[i][j]);
			if (j < n) add(f[i][j + 1], 1LL * f[i][j] * C(i + (j + 1) * (K - 1) - 1, K - 2) % mo);
		}
	} 
	return printf("%lld\n", 1LL * f[n][n] * fac[n] % mo), 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int a[26];
string s;
int main() {
    cin >> s;
    bool ok = true;
    for (int i = 0; i < s.length(); ++i) {
        if (++a[s[i] - 'a'] > 1) {
            ok = false;
        }
    }
    if (ok)
        cout << "yes" << endl;
    else
        cout << "no" << endl;
    return 0;
}


Measured memory_bytes: 3652