akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s;
int N = 3;
vector<int> v(N);
int a, b;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int c;

  cin >> a >> b >> c;
  if (a == b)
    pr(c);
  else if (b == c)
    pr(a);
  else
    pr(b);
  return 0;
}

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

int main() {
    int n, m;
    while (cin >> n >> m, n + m) {
        vector<int> pmax(n, 0), pmin(n, 0);
        for (int i = 0; i < m; i++) {
            int s, k, c; cin >> s >> k;
            for (int j = 0; j < k; j++) {
                cin >> c; c--;
                pmax[c] += s;
            }
            if (k == 1) pmin[c] += s;
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;
                ans = max(ans, pmax[i] - pmin[j]);
            }
        }
        cout << ans + 1 << endl;
    }
}



Measured memory_bytes: 3188
# -*- coding: utf-8 -*-

N = int(input())

now_txy = [0, 0, 0]

plan = []
for _ in range(N):
    plan.append(list(map(int, input().split())))

for i in range(N):
    next_txy = plan[i]
    diff = abs(next_txy[1] - now_txy[1]) + abs(next_txy[2] - now_txy[2]) - (next_txy[0] - now_txy[0])
    if (diff <= 0) & (diff % 2 == 0):
        now_txy = next_txy.copy()
    else:
        print('No')
        exit()

print('Yes')



Measured memory_bytes: 27300
#include<stdio.h>

int main(void){
  long long int N,A,B;
  long long int i;
  long long int h[100000];
  long long int K;
  long long int left,right;
  long long int sum;

  scanf("%lld %lld %lld",&N,&A,&B);
  //printf("%d\n", N);

  for(i=0;i<N;++i){
    scanf("%lld",&h[i]);
    //printf("h[%lld]=%lld\n", i,h[i]);
  }



  left=0;
  right=1000000000;
  K=(right+left)/2;

  //printf("%d\n", K);

  while(1){
    sum=0;
    for(i=0;i<N;i++){
      if(h[i]-K*B > 0){
        sum += (h[i]-K*B)%(A-B) ? (h[i]-B*K)/(A-B)+1 :(h[i]-B*K)/(A-B);
      }
    }
    if(sum <= K){
      right=(right+left)/(long long int)2;
    }else{
      left=(right+left)/(long long int)2;
    }
    //printf("%lld,%lld\n", left,right);
    K=(right+left)/2;
    if(left==right-1){
      break;
    }
  }

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

  return 0;
}


Measured memory_bytes: 896
s=input()

ll=0
rr=len(s)-1

cnt=0
while ll<=rr:
    if s[ll]==s[rr]:
        ll+=1
        rr-=1
    elif s[ll]=="x":
        cnt+=1
        ll+=1
    elif s[rr]=="x":
        cnt+=1
        rr-=1
    else:
        print(-1)
        exit()
print(cnt)



Measured memory_bytes: 39664
#include<stdio.h>
#include<algorithm>
using namespace std;
long long dp[1<<20];
long long c[20];
int d[20];
long long gcd(long long a,long long b){
	while(a){
		b%=a;
		long long C=a;
		a=b;
		b=C;
	}
	return b;
}
long long ABS(long long a){return max(a,-a);}
int main(){
	int a;
	long long b;
	scanf("%d%lld",&a,&b);
	for(int i=0;i<a;i++)scanf("%lld",c+i);
	for(int i=0;i<a;i++)scanf("%d",d+i);
	for(int i=1;i<(1<<a);i++){
		long long GCD=0LL;
		long long m=1;
		for(int j=0;j<a;j++){
			if(i&(1<<j)){
				GCD=gcd(m,c[j]);
				double lcm=(double)m/GCD*c[j];
				if(lcm>(double)b+0.001){
					m=b+1;break;
				}else m=m/GCD*c[j];
			}
		}
		dp[i]=b/m;
	}
	for(int i=0;i<a;i++)
		for(int j=0;j<(1<<a);j++)
			if(j&(1<<i))dp[j]-=dp[j^(1<<i)];
	double ret=0;
	for(int i=0;i<(1<<a);i++){
		double p=1;
		for(int j=0;j<a;j++)if(i&(1<<j))p*=0.01*d[j];else p*=0.01*(100-d[j]);
		ret+=p*(ABS(dp[i]));
	}
	printf("%.9f\n",ret);
}

Measured memory_bytes: 9260
#include <iostream>
#include <vector>
#include <algorithm>

bool SecondDecending(const std::pair<int, int> &l, const std::pair<int, int> &r){return l.second > r.second;}

int main(){
   int N, M;
   std::cin >> N >> M;
   std::vector<int> A(N);
   for(int i=0; i<N; ++i){
      std::cin >> A[i];
   }
   std::sort(A.begin(),A.end());
   std::vector<std::pair<int,int> > BC;
   int cmax = 0;
   for(int i=0; i<M; ++i){
      int B, C;
      std::cin >> B >> C;
      BC.push_back(std::make_pair(B,C));
      cmax = std::max(cmax,C);
   }
   std::sort(BC.begin(),BC.end(), SecondDecending);
   //std::sort(BC.begin(),BC.end(), std::greater<std::pair<int,int> >);

   std::vector<int> D;
   int index = 0;
   for(auto itr=BC.begin(); itr!=BC.end(); ++itr){
      for(int j=0; j<itr->first; ++j){
	 D.push_back(itr->second);
	 if(N<++index) break;
      }
   }

   long long ans = 0;
   int count = 0;
   for(int i=0; i<N; ++i){
      if(A[i]<cmax){
	 ++count;
	 D.push_back(A[i]);
      }else ans += A[i];
   }
   std::sort(D.rbegin(),D.rend());
   for(int i=0; i<count; ++i)
      ans += D[i];
   std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 3572
#include<stdio.h>
int main(void){
  int N,L[200];
  int i,j;
  int a;
  int sum;
  sum=0;
  scanf("%d",&N);
  for(i=0;i<N*2;i++){
    scanf("%d",&L[i]);
  }
  for(i=0;i<=N*2-1;i++){
    for(j=i;j<=N*2-1;j++){
      if(L[j]<L[i]){
	a=L[i];
	L[i]=L[j];
	L[j]=a;
      }
    }
  }
  for(i=0;i<=N*2-1;i=i+2){
    sum=sum+L[i];
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

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

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

int n, v[maxN];

long long sum;

long long ans;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i)
    {
        scanf("%d", &v[i]);
        sum += v[i];
    }
    long long crts = 0LL;
    ans = abs(sum - 2 * v[1]);
    for (int i = 1; i < n; ++ i)
    {
        crts += v[i];
        if (abs(sum - 2 * crts) < ans)
            ans = abs(sum - 2 * crts);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
def main():
    h, w = map(int, input().split())
    if h == 1 or w == 1:
        print(1)
        return 0
    ans = 0
    if w&1:
        ans += w * (h//2)
        if h % 2 == 1:
            ans += (w+1)//2
    else:
        ans += h*(w//2)

    print(ans)

main()



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

vector<vector<long>> find_cycle(vector<long> to) {
  long n = to.size();
  vector<vector<long>> ret;
  vector<long> vec(n, -1);
  for (long v = 0; v < n; v++) {
    if (vec.at(v) == -1) {
      long nv = v;
      do {
        vec.at(nv) = v;
        nv = to.at(nv);
      } while (vec.at(nv) == -1);
      if (vec.at(nv) == v) {
        vector<long> tmp;
        long end = nv;
        do {
          tmp.push_back(nv);
          nv = to.at(nv);
        } while (nv != end);
        ret.push_back(tmp);
      }
    }
  }
  return ret;
}

int main() {
  long N, K;
  cin >> N >> K;
  vector<long> P(N);
  for (int i = 0; i < N; i++) cin >> P.at(i), P.at(i)--;
  vector<long> C(N);
  for (int i = 0; i < N; i++) cin >> C.at(i);

  auto FC = find_cycle(P);
  long ans = LONG_MIN;
  
  for (auto fc : FC) {
    long n = fc.size();
    long sum = 0;
    for (auto a : fc) sum += C.at(a);
    if (sum <= 0) {
      for (auto a : fc) {
        long now = a;
        long tmp = 0;
        long cnt = min(K, n);
        while (cnt--) {
          now = P.at(now);
          tmp += C.at(now);
          ans = max(ans, tmp);
        }
      }
    } else {
      for (auto a : fc) {
        long now = a;
        long tmp = 0;
        long cnt = K;
        if (K / n) {
          tmp = sum * (K / n - 1);
          cnt = K % n + n;
        }
        while (cnt--) {
          now = P.at(now);
          tmp += C.at(now);
          ans = max(ans, tmp);
        }
      }
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    ll N;
    cin >> N;
    ll cnt = (N + 1000 - 1) / 1000;
    cout << 1000 * cnt - N << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int n;
    cin >> n;
    if (n % 2 == 0)
        cout << n;
    else
        cout << n * 2;
}


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

int main(void){
    int n;
    cin >> n;
    int a[n];
    int b,c,d;
    c=1;
    d=0;

    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    b=a[0];
    for(int i=0;i<n;i++){
        if(b==2){d=c;break;}
        else{c++;}
        b=a[b-1];
    }
    if(d==0){printf("-1");}
    else{printf("%d",d);}
    
}

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

int main(){
  int A,B,C,D,E;cin>>A>>B>>C>>D>>E;
  if(A==0){
    cout<<1<<endl;
  }
  else if(B==0){
    cout<<2<<endl;
  }
  else if(C==0){
    cout<<3<<endl;
  }
  else if(D==0){
    cout<<4<<endl;
  }
  else if(E==0){
    cout<<5<<endl;
  }
}

Measured memory_bytes: 3620
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)


int main() {
    ll N;
    cin >> N;
    vector<ll> T(N);
    rep(i,N){
        cin >> T[i];
    }
    ll M;
    cin >> M;
    vector<vector<ll>> PX(M,vector<ll>(2));
    rep(i,M){
        cin >> PX[i][0] >> PX[i][1];
    }

    vector<ll> tmp = T;
    rep(i,M){
        ll sum=0;
        T[PX[i][0]-1] = PX[i][1];
        rep(j,N){
            sum += T[j];
        }
        cout << sum << endl;
        T = tmp;
    }

}



Measured memory_bytes: 3524
#include<cstdio>
using namespace std;
int cnt1,cnt2;
long long powd(long long x,long long y){
	long long res=1;
	while(y)
	{
		if(y&1) res=res*x;
		x=x*x;
		y>>=1;
	}
	return res;
}
int main()
{
//	freopen("A.in","r",stdin);
	int n,p;
	scanf("%d%d",&n,&p);
	int x;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(x&1) cnt1++;
		else cnt2++;
	}
	long long ans1=powd(2,cnt1);
	long long ans2=powd(2,cnt2);
	if(p==1&&!cnt1)
	{
		printf("0\n");
		return 0;
	}
	if(ans1>1) ans1>>=1;
	printf("%lld\n",ans1*ans2);
	return 0;
}


Measured memory_bytes: 128
def main():
    
    N,W = map(int,input().split())
    w,v = [],[]
    for i in range(N):
        a,b = map(int,input().split())
        w.append(a)
        v.append(b)
    dp = [[0]*(W+1) for i in range(N+1)]

    for i in range(N):
        for j in range(W+1):
            if j-w[i] >= 0:
                dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j])
            else:
                dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    #print(dp)
    print(dp[N][W])

if __name__ == '__main__':
    main()

Measured memory_bytes: 118640
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[100009], pre[100009] = {0};
const ll MOD = 1e9+7;
ll qpow(ll a, ll b)
{
	ll res = 1;
	while(b)
	{
		if(b%2) res = res * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}
	return res;
}
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++)
		scanf("%lld", a+i);
	
	sort(a+1, a+1+n);
	for(int i = 1; i <= n; i++)
		pre[i] = (pre[i-1] + a[i]) % MOD;
		
	if(k==1) printf("0\n");
	else
	{
		ll res = 0, tmp = 1;
		for(int i = k, j = k-2; i <= n; i++, j++)
		{
			ll sum = (pre[n] - pre[i-1]  - pre[n-i+1] + MOD * 2) % MOD;
			res = (res + tmp * sum % MOD) % MOD;
			tmp = (tmp * (j + 1) % MOD) * qpow(j-k+2+1, MOD-2) % MOD;
		}
			printf("%lld\n", res);
	}
	

}

Measured memory_bytes: 1664
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long a, b, c = 1000001, d = -c, e = 0; cin >> a;
	for (int h = 1; h <= a; h++) {
		cin >> b;
		if (c > b) {
			c = b;
			//min
		}
		if (b > d) {
			d = b;
			//max
		}
		e += b;
	}
	cout << c << ' ' << d << ' ' << e << endl;
}


Measured memory_bytes: 3084
#include<iostream>
using namespace std;
int main(){
	int w,h,a,b;
	while(1){
	cin>>h>>w;
	if(h==0&&w==0){
		break;
	}
	w-=2;
	a=w;
	b=h;
	for(;h>0;h--){
		cout<<'#';
		for(w=a;w>0;w--){
			if(h==b||h==1){
				cout<<'#';
			}else{
				cout<<'.';
			}
		}
		cout<<'#';
		cout<<endl;
	}
	cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>

int main(void)
{
	double a, b, c, d, e, f, x, y;
	while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF)
	{
		x = (b*f - e*c)/(b*d - a*e);
		y = (c - a*x)/b;
		if (x < 0.0005 && -0.0005 <= x)
			x = 0.0;
		if (y < 0.0005 && -0.0005 <= y)
			y = 0.0;
		printf("%.3f %.3f\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 652
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
int main(){
    int n;
    while(cin >> n,n){
        vector<long long> T;
        for(int i = 0; i < n; i++){
            int a;
            cin >> a;
            T.push_back(a);
        }
        sort(T.begin(),T.end());
        long long int now = 0;
        long long ans = 0;
        for(int i = 0; i < n-1; i++){
            now += T[i];
            ans += now;
        }
        cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 1340
m,n = map(int, input().split())
if n >= 1<<m:
  print(-1)
   
else:
  if m == 1:
    if n == 1:
      print(-1)
    else:
      print(0,0,1,1)
  else:
    ans = [i for i in range((1<<m)-1, -1, -1)]
    ans.remove(n)
    ans.append(n)
    for i in range(1<<m):
      if i == n:
        continue
      else:
        ans.append(i)
    ans.append(n)
    print(" ".join(map(str, ans)))


Measured memory_bytes: 94272
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl     '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii      map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
  ll h1,m1,h2,m2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  m1+=h1*60;
  m2+=h2*60;
  cout<<max(0LL,m2-m1-k)<<endl;
}
signed main()
{
  
    /***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/
 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS=1;
//  cin>>TESTS;
  while(TESTS--)
  {
    solve();
    
  }
  TIME
  return 0;
}

Measured memory_bytes: 3780
//q093.cpp
//Sun Sep 13 15:33:44 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int h,w,k;
string t[30];

int scorecalc(int x,int y){
	int ret = 0;
	int c[30][30];
	rep(i,h)rep(j,w) c[i][j] = t[i][j]-'0';
	for(int i=x-1;i>=0;i--){
		c[i+1][y] = c[i][y];
	}
	c[0][y] = -1;
	int count = 1;
	while(1){
		int flag = 0;
		rep(i,h){
			int contig = 1;
			for(int j=1;j<w;j++){
				if (c[i][j]==c[i][j-1]){
					contig++;
				}else {
					if (contig>=k && c[i][j-1]!=-1){
						flag = 1;
						ret += contig*c[i][j-1]*count;
						for (int z=j-contig;z<j;z++){
							c[i][z] = -1;
						}
					}
					contig = 1;
				}
			}
			if (contig>=k && c[i][w-1]!=-1){
				flag = 1;
				ret += contig*c[i][w-1]*count;
				for (int z=w-contig;z<w;z++){
					c[i][z] = -1;
				}
			}
		}
		if (!flag) break;

		for (int i=h-1;i>=0;i--){
			rep(j,w){
				if(c[i][j]==-1){
					for (int z=i-1;z>=0;z--){
						if (c[z][j]!=-1){
							c[i][j] = c[z][j];
							c[z][j] = -1;
							break;
						}
					}
				}
			}
		}
		count = count * 2;
	}
	return ret;
}


int main(){
	cin >> h >> w >> k;

	rep(i,h) cin >> t[i];

	int ans = 0;
	rep(i,h)rep(j,w){
		ans = max(ans,scorecalc(i,j));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main(void)
{
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a < b"<<endl;
	}
	else if(a>b){
		cout<<"a > b"<<endl;
	}
	else{
		cout<<"a == b"<<endl;
	}
	return 0;
}

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

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--;y1--;x2--;y2--;
    vector<string> grid(H);
    for (int i = 0; i < H; i++) cin >> grid[i];
    
    int inf = 1e9;
    vector<vector<int>> dist(H, vector<int>(W, inf));
    dist[x1][y1] = 0;
    queue<int> q;
    q.push(x1*W+y1);
    while (!q.empty()) {
        int x = q.front()/W;
        int y = q.front()%W;
        q.pop();
        for (int i = 1; i <= K; i++) {
            int nx = x-i, ny = y;
            if (nx <= -1 || nx >= H || ny <= -1 || ny >= W) break;
            if (grid[nx][ny] == '@') break;
            if (dist[nx][ny] <= dist[x][y]) break;
            if (dist[nx][ny] > dist[x][y]+1) {
                dist[nx][ny] = dist[x][y]+1;
                q.push(nx*W + ny);
            }
        }
        for (int i = 1; i <= K; i++) {
            int nx = x+i, ny = y;
            if (nx <= -1 || nx >= H || ny <= -1 || ny >= W) break;
            if (grid[nx][ny] == '@') break;
            if (dist[nx][ny] <= dist[x][y]) break;
            if (dist[nx][ny] > dist[x][y]+1) {
                dist[nx][ny] = dist[x][y]+1;
                q.push(nx*W + ny);
            }
        }
        for (int i = 1; i <= K; i++) {
            int nx = x, ny = y-i;
            if (nx <= -1 || nx >= H || ny <= -1 || ny >= W) break;
            if (grid[nx][ny] == '@') break;
            if (dist[nx][ny] <= dist[x][y]) break;
            if (dist[nx][ny] > dist[x][y]+1) {
                dist[nx][ny] = dist[x][y]+1;
                q.push(nx*W + ny);
            }
        }
        for (int i = 1; i <= K; i++) {
            int nx = x, ny = y+i;
            if (nx <= -1 || nx >= H || ny <= -1 || ny >= W) break;
            if (grid[nx][ny] == '@') break;
            
            if (dist[nx][ny] <= dist[x][y]) break;
            if (dist[nx][ny] > dist[x][y]+1) {
                dist[nx][ny] = dist[x][y]+1;
                q.push(nx*W + ny);
            }
        }
    }
    
    if (dist[x2][y2] == inf) cout << -1 << endl;
    else cout << dist[x2][y2] << endl;
    return 0;
}

Measured memory_bytes: 12096
#include <string>
#include <iostream>
#include <vector>

using namespace std;

int main (){
    long long n ;
    cin >> n;
    
    bool before = 0;
    long long now;
    
    long long accm = 0;
    for (int i =0  ; i < n;  i++) {
        cin >> now;
        if (before && now > 0) {
            accm ++;
            now --;
        }
        accm += now / 2;
        before = now % 2;
    }
    
    cout << accm << endl;
    
    return 0;
}

Measured memory_bytes: 256
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

import bisect

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

N = 10**7+1

arr = [1]*N

def sieve():
    for i in range(2, N,2):
        cnt = 0
        num = i
        while num % 2 == 0:
            cnt+=1
            num = num//2
        arr[i] = arr[i]*(cnt+1)
    
    # p = 3
    for i in range(3, N, 2):
        if arr[i] == 1:
            for j in range(i, N, i):
                cnt = 0
                num = j
                while num % i == 0:
                    cnt+=1
                    num = num//i
                arr[j]  =arr[j] * (cnt+1)


sieve()
n = int(ri())

# print(arr[:5])
ans= 0
for i in range(1,n+1):
    ans+=i*arr[i]

print(ans)




Measured memory_bytes: 146416
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)

int main() {
	int a, p;
	cin >> a >> p;
	cout << (a * 3 + p)/2;
}
	



Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string A, B;
    int i, FLG;
    int asize, bsize;
    cin >> A >> B;

    asize = A.size();
    bsize = B.size();

  if (A.size() > B.size()){
      cout << "GREATER" << endl;
    }else if (A.size() < B.size()){
      cout << "LESS" << endl;
    }else{
      for (i = 0; i < A.size(); i++){
        if (A[i] > B [i]){
          cout << "GREATER" << endl;
          break;
        }else if (A[i] < B [i]) {
          cout << "LESS" << endl;
          break;
        }
        if(i == A.size()-1){
          cout << "EQUAL" << endl;
        }
      }
  }
}

Measured memory_bytes: 256
from sys import exit, setrecursionlimit
import sys
from io import StringIO

def read():
    return int(input())

def reads():
    return [int(x) for x in input().split()]

setrecursionlimit(1000000)

# inputstr = """
# 2 10 4
# 20
# 20
# """[1:]
# sys.stdin = StringIO(inputstr)

(N, A, B) = reads()
H = [0] * N

for i in range(N):
    H[i] = read()

def satisfy(t):
    q = A - B
    cnt = sum((max(h-B*t, 0) + q - 1)//q for h in H)
    return cnt <= t

(l, r) = (0, 10**9)

while True:
    if l + 1 == r:
        break
    m = (l + r) // 2
    if satisfy(m):
        r = m
    else:
        l = m

print(r)

Measured memory_bytes: 6900
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            String s = in.next();
            if (a >= 3200)
                out.println(s);
            else
                out.println("red");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

typedef long long int   ll;
#define int             ll
#define PI              3.1415926535897932384626433832795

#define pb              push_back
#define rep0            for(int i=0;i<n;i++)
#define rep1            for(int i=1;i<=n;i++)
#define inputar0(ar)    for(int i=0;i<n;i++)cin>>ar[i]
#define inputar1(ar)    for(int i=1;i<=n;i++)cin>>ar[i]

#define hell            freopen("input.txt","r", stdin);freopen("output.txt", "w", stdout);freopen("error.txt", "w",stderr);
#define fastasF_boi()   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl            "\n"
//#define cerr            if(false)cerr

int mod=1000000007;
int maxn=200001;
int binpow(int a,int b,int mod){int res=1;while(b>0){if(b%2){res=(res*a)%mod;b--;}a=(a*a)%mod;b/=2;}return res%mod;}
int binpow(int a,int b){int res=1;while(b>0){if(b%2){res=(res*a);b--;}a=(a*a);b/=2;}return res;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}
int mulmod(int a,int b){return ((a%mod)*(b%mod))%mod;}
int addmod(int a,int b){return (((a%mod)+(b%mod))+mod)%mod;}

int n,m;
vector<vector<int>> adj(1000001);
vector<bool> vis(1000001,false);

void dfs(int node,int &cnt){
    cnt++;
    vis[node]=true;
    for(auto it:adj[node]){
        if(vis[it])
            continue;
        dfs(it,cnt);
    }
}

void solve(){
    cin>>n>>m;
    map<pair<int,int>,int> mp;
    for(int i=0;i<m;i++){
        int x,y;cin>>x>>y;
        if(mp[{x,y}] or mp[{y,x}])
            continue;
        else {
            mp[{x,y}]=1,mp[{y,x}]=1;
            adj[x].push_back(y);
            adj[y].push_back(x);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(vis[i]==false){
            int cnt=0;
            dfs(i,cnt);
            ans=max(ans,cnt);
        }
    }
    cout<<ans<<endl;
}

signed main(){
//    hell;

    fastasF_boi();
    int t=1;
//    cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
}



Measured memory_bytes: 67308
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    sort(all(a));
    int ans=0;
    if(n%2){
        rep(i,n/2)ans-=a[i]*2;
        Rep(i,n/2+1,n)ans+=a[i]*2;
        cout<<max(ans-a[n/2]+a[n/2-1],ans+a[n/2]-a[n/2+1])<<endl;
        return;
    }
    rep(i,n/2)ans-=a[i]*2;
    Rep(i,n/2,n)ans+=a[i]*2;
    cout<<ans-a[n/2]+a[n/2-1]<<endl;
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();
            int[][] a = new int[H][];
            for (int i = 0; i < H; i++) {
                a[i] = in.nextIntArray(W);
            }
            List<int[]> ans = new ArrayList<>();
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W - 1; j++) {
                    if (a[i][j] % 2 == 1) {
                        ans.add(new int[]{i, j, i, j + 1});
                        a[i][j]--;
                        a[i][j + 1]++;
                    }
                }
            }
            for (int i = 0; i < H - 1; i++) {
                if (a[i][W - 1] % 2 == 1) {
                    ans.add(new int[]{i, W - 1, i + 1, W - 1});
                    a[i][W - 1]--;
                    a[i + 1][W - 1]++;
                }
            }
            out.println(ans.size());
            for (int[] e : ans) {
                out.printf("%d %d %d %d\n", e[0] + 1, e[1] + 1, e[2] + 1, e[3] + 1);
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

    }
}



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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
// typedef pair<ll,ll> p;

int n,k;
string s;

int main(){
  cin >> n >> k;
  cin >> s;

  for(int i = 0; i < n; i++){
    if(i==k-1){
      s[i] = s[i] +0x20;
    }
  }
  cout << s << endl;
}


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

typedef long long ll;

int a,b,q;
ll s[100005];
ll t[100005];
ll st[100005];
ll ts[100005];
//数组定义环节

//求距离的数组，用于简化代码
ll dis(int xb1,int xb2){//xb1是对于s的下标，同理，xb2是对于t的下标
    if(xb1>=a||xb2>=b)return 1e18;
    return abs(s[xb1]-t[xb2]);
}

int main(){

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

    cin>>a>>b>>q;
    for(int i=0;i<a;i++){
        cin>>s[i];
    }
    for(int i=0;i<b;i++){
        cin>>t[i];
    }
    //一开始的读入数组环节
    sort(s,s+a);
    sort(t,t+b);
    //排序，方便接下来的指针预处理最短距离
    int pst=0;
    for(int i=0;i<a;i++){
        while(dis(i,pst)>dis(i,pst+1)){
            pst++;
        }
        st[i]=dis(i,pst);
        //预处理对于第i个圣地的去寺庙的最短距离
    }
    int pts=0;
    for(int i=0;i<b;i++){
        while(dis(pts,i)>dis(pts+1,i)){
            pts++;
        }
        ts[i]=dis(pts,i);
        //预处理对于第i个寺庙的去圣地的最短距离
    }
    while(q--){
        ll x;
        cin>>x;
        ll ans=1e18;
        //读入x并初始化ans为INF
        int ps=lower_bound(s,s+a,x)-s;
        for(int i=ps-5;i<=ps+5;i++){
            if(i>=0&&i<a){
                ans=min(ans,abs(x-s[i])+st[i]);
            }
        }
        //二分，为防止错误采用循环多check几个圣地
        int pt=lower_bound(t,t+b,x)-t;
        for(int i=pt-5;i<=pt+5;i++){
            if(i>=0&&i<b){
                ans=min(ans,abs(x-t[i])+ts[i]);
            }
        }
        //二分，为防止错误采用循环多check几个寺庙
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 4480
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n := nextInt()
	lis := make([]int, 0, n)

	for i := 0; i < n; i++ {
		lis = append(lis, nextInt())
	}

	var x2 int
	for i, item := range lis {
		if i%2 == 0 {
			x2 += item
		} else {
			x2 -= item
		}
	}

	ans := make([]int, len(lis), len(lis))

	ans[0] = x2 / 2
	for i := 1; i < n; i++ {
		ans[i] = lis[i-1] - ans[i-1]
	}

	for _, item := range ans {
		fmt.Printf("%#v ", item*2)
	}
	fmt.Println()
}


Measured memory_bytes: 5760
#include <stdio.h>
 
#define N 2000
#define M 200
 
int solve(int,int);
 
int A[N];
int n;
 
int main(){
 
  int ans,q,i;
  int mi[M];
 
  scanf("%d",&n);
 
  for(i=0 ; i<n ; i++){
    scanf("%d",&A[i]);
  }
 
  scanf("%d",&q);
  for(i=0 ; i<q ; i++){
    scanf("%d",&mi[i]);
  }
 
 
  for(i=0 ; i<q ; i++){
    ans = solve(0,mi[i]);
    if(ans==1) printf("yes\n");
    else printf("no\n");
  }
 
  return 0;
}
 
int solve(int i, int m){
 
  int ans;
 
    if(m==0)return 1;
    if(i>=n)return 0;
 
    ans = solve(i+1,m) || solve(i+1,m-A[i]);
 
}


Measured memory_bytes: 2104
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
struct node{
	int x,y,z;
};
node p,next1;
char a[1010][1010];
int n,m,k,b[1010][1010];
int d[4][2]={0,1,0,-1,1,0,-1,0};
void bfs(int &x,int &y,int z,int &ans){
	p.x=x;
	p.y=y;
	p.z=0;
	queue<node> q;
	while(!q.empty())
		q.pop();
	q.push(p);
	while(!q.empty()){
		p=q.front();
		q.pop();	 
		for(int i=0;i<4;i++){
			next1.x=p.x+d[i][0];
			next1.y=p.y+d[i][1];
			if(a[next1.x][next1.y]!='X'&&next1.x>0&&next1.x<=n&&next1.y>0&&next1.y<=m&&b[next1.x][next1.y]==0){
				if(a[next1.x][next1.y]==z+48){
					ans+=p.z+1;
					x=next1.x;
					y=next1.y;
					return;
				}
				next1.z=p.z+1;\
				b[next1.x][next1.y]=1;
				q.push(next1);
			}
		}
		
	}
}
int main(){
	int i,j,x,y,ans;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++){
		scanf("%s",a[i]);
		for(j=strlen(a[i]);j>0;j--){
			a[i][j]=a[i][j-1];
			if(a[i][j]=='S'){
				x=i;
				y=j;
			}
		}
		a[i][0]='0';
	}
	ans=0;
	for(i=1;i<=k;i++){
		memset(b,0,sizeof(b));
		b[x][y]=1;
		bfs(x,y,i,ans);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 7584
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        long N = sc.nextInt();
        long A = sc.nextInt();
        long B = sc.nextInt();

      	long min = A*(N-1)+B;
      	long max = A+B*(N-1);
     
      	if(A>B){
        System.out.println(0);
        }
      
    else if(N == 1 && A!=B){
          System.out.println(0);
        }
      else if(A==B){
       System.out.println(1);
      }
        // 出力
        else{
          System.out.println(max-min+1);
        }
    }
}

Measured memory_bytes: 23764
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
a.sort()

sum_v=0
ans=0
for i in range(n-1):
  sum_v+=a[i]
  if sum_v*2>=a[i+1]:
    ans+=1
  else:
    ans=0

ans+=1
print(ans)

Measured memory_bytes: 20236
#!/usr/bin/ruby                                                                                                                               
# -*- coding: utf-8 -*-                                                                                                                       


def isPalindromic(s)
  if s == s.reverse
    return true
  else
    return false
  end
end

s = gets.chomp
i = 0
while true
  tmp = (s.to_i - i).to_s
  if isPalindromic tmp
    puts tmp
    break
  end
  tmp = (s.to_i + i).to_s
  if isPalindromic tmp
    puts tmp
    break
  end
  i += 1
end

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

const int N = 510, P = 1e9 + 7;
inline int mpow(int a, int b) {
    int ans = 1;
    for (; b; b >>= 1, a = (ll) a * a % P)
        if (b & 1) ans = (ll) ans * a % P;
    return ans;
}
inline void upd(int &x, int y) { x = x + y - P; x += x >> 31 & P; }

int fac[N], ifac[N];

void genfac(int n) {
    fac[0] = 1;
    for (int i = 1; i <= n; ++i) fac[i] = (ll) fac[i - 1] * i % P;
    ifac[n] = mpow(fac[n], P - 2);
    for (int i = n - 1; i >= 0; --i) ifac[i] = (ll) ifac[i + 1] * (i + 1) % P;
}

int n, X, l[N], cnt[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    genfac(500);
    cin >> n >> X;
    for (int i = 1; i <= n; ++i) {
        cin >> l[i];
        ++cnt[l[i]];
    }
    ++X;
    vector<vector<int>> dp(X + 1, vector<int>(X + 1, 0));
    dp[0][0] = 1;
    for (int len = X; len >= 1; --len) {
        vector<vector<int>> new_dp(X + 1, vector<int>(X + 1, 0));
        for (int c = 0; c <= X; ++c)
            for (int x = 0; x <= X; ++x) if (dp[c][x] != 0) {
                // cerr << "FF (" << c << ',' << x << ")\n";
                for (int i = 0; x + i * len <= X && c + i <= X; ++i) {
                    // cerr << "(" << c << ',' << x << ") -> " << "(" << c + i << ',' << x + i * len << ")\n";
                    upd(new_dp[c + i][x + i * len], (ll) dp[c][x] * ifac[i] % P);
                }
            }
        for (int c = 0; c <= X; ++c)
            for (int x = X; x >= c * len; --x)
                new_dp[c][x] = (ll) new_dp[c][x] * mpow(x - c * len, cnt[len]) % P;
        swap(dp, new_dp);
        /*
        for (int c = 0; c <= X; ++c) {
            for (int x = 0; x <= X; ++x) {
                cerr << dp[c][x] << " ";
            }
            cerr << '\n';
        }
        */
    }
    int ans = 0, coeff = 1;
    for (int i = 1; i <= X; ++i) {
        // cerr << (ll) fac[i] * dp[i][X] % P << '\n';
        upd(ans, (ll) fac[i] * coeff % P * dp[i][X] % P);
        coeff = P - coeff;
    }
    cout << ans << '\n';
    return 0;
}

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

signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	cout.tie(nullptr);
	ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int ans=0;
    vector<int> a(n);
    vector<vector<P>> xy(n);
    rep(i,n){
        cin>>a[i];
        xy[i].resize(a[i]);
        rep(j,a[i])cin>>xy[i][j].first>>xy[i][j].second;
    }
    rep(i,(1U<<n)){
        int cnt=0;
        bool b=true;
        rep(j,n){
            if(i&(1<<j)){
                cnt++;
                rep(k,a[j]){
                    if(((i>>(xy[j][k].first-1))&1)!=xy[j][k].second)
                        b=false;
                }
            }
        }
        if(b)ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}


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

namespace AtCoder
{
	public class ABC
	{
		static int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			int x = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			string ans = "NO";
			if (x == 7 || x == 5 || x == 3) {
				ans = "YES";
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}
}


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

int main(){
    string s;
    cin >> s;
    int count = 0;
    for(int i = 0;i < s.size()/2;i++){
        if(s.at(i) != s.at(s.size() - i - 1)){
            count++;
        }
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int w,n,m;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>w>>n>>m;
	const int M=10001;
	vp a(n);
	for(int i=0;i<n;i++) cin>>a[i].first>>a[i].second;
	sort(a.begin(),a.end());
	vi dp(M,-inf);
	dp[0]=0;
	for(auto p:a){
		for(int j=M-1;j>=p.first;j--) dp[j]=max(dp[j],dp[j-p.first]+p.second);
	}
	for(int i=1;i<=m;i++){
		int mx=0;
		for(int j=0;j<=w/i;j++) mx=max(mx,dp[j]);
		cout<<mx*i<<endl;
	}
}


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

int main() {
 string s;cin>>s;
 string k="keyence";
 int n=0;
 for(int i=0;i<7;i++){
	 if(s[i]!=k[i]){
		 break;
	 }
	 n++;
 }
 for(int i=0;i<7;i++){
	 if(s[s.size()-1-i]!=k[6-i]){
		 break;
	 }
	 n++;
 }
 if(n>=7){
	 cout<<"YES"<<endl;
 }else{
 cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256