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

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=320,mo=998244353;

int a[N][N];
int n,m;

inline ll ksm(ll o,ll t)
{
	ll y=1;
	for(;t;t>>=1,o=o*o%mo)
	if(t&1)y=y*o%mo;
	return y;
}

bool bz[N];

inline int get()
{
	fo(i,1,m){
		int kk=0;
		fo(l,1,n)if(a[l][i]==1&&!bz[l]){
			kk=l; break;
		}
		bz[kk]=true;
		fo(l,1,n)if(!bz[l]&&a[l][i])
		fo(j,i,m)a[l][j]^=a[kk][j];
	}
	int ans=0;
	fo(i,1,n){
		int op=0;
		fo(l,1,m)op=op|a[i][l];
		ans=ans+op;
	}
	return ans;
}

int main()
{
	scanf("%d%d",&n,&m);
	fo(i,1,n)fo(l,1,m)scanf("%d",&a[i][l]);
	int r=get();
	ll da=(ksm(2,n+m-1)-ksm(2,n+m-1-r)+mo)%mo;
	cout<<da;
}

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

using namespace std;
#define ll long long
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int inf = 1e9 + 9;
const ll linf  = 1ll * inf * inf;
const int N = 500000 + 7;
const int M = 30;
const int multipleTest = 0;
const double pi = acos(-1);


int a, b, c;
int x, y;

void solve() {
	cin >> a >> b >> c >> x >> y;
	ll res = inf;
	
	for (int i = 0; i <= max(x, y); i ++) {
		ll cur = 2ll * i * c + max(0, x - i) * a + max(0, y - i) * b;
		res = min(res, cur);
	}
	cout << res;
	
}

int main() {
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin);
	//    freopen("out.txt", "w", stdout);
#endif
	int Test = 1;
	if (multipleTest) {
		cin >> Test;
	}
	for(int i = 0; i < Test; ++i) {
		//		printf("Case #%d: ", i + 1);
		solve();
	}
#ifdef _LOCAL_
	cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n+1);
  vector<int> check(n+1, true);
  int ans = n;
  for (int i = 1; i <= n; i++) cin >> h[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (h[a] >= h[b] && check[b]) {
      check[b] = false;
      ans--;
    }
    if (h[a] <= h[b] && check[a]) {
      check[a] = false;
      ans--;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4052
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 0
typedef long long LL;

LL dp1[102][5];  // tight dp, keta, K
LL dp2[102][5];  // less  dp, keta, K

int main() {
  std::string N; std::cin >> N;
  int K; std::cin >> K;
  int length = static_cast<int>(N.length());

  // Zero Initialize.
  for (int i = 0; i <= length; ++i) {
    for (int k = 0; k <= K; ++k) {
      dp1[i][k] = 0; dp2[i][k] = 0;
    }
  }

  dp1[0][0] = 1;
  for (int i = 1; i <= length; ++i) {
    int v = N[i-1] - '0';
    for (int k = 0; k <= K; ++k) {
      if (v == 0) {
        dp1[i][k] += dp1[i-1][k];
        dp2[i][k + 1] += 9 * dp2[i-1][k];  // Select 1-9
        dp2[i][k] += dp2[i-1][k];          // Select 0
      } else {
        dp1[i][k + 1] += dp1[i-1][k];
        dp2[i][k + 1] += 9 * dp2[i-1][k] + (v-1) * dp1[i-1][k]; // Select 1-9
        dp2[i][k] += dp2[i-1][k] + dp1[i-1][k];                 // Select 0
      }
    }
#if DEBUG
    std::cout << "t: ";
    for (int k = 0; k <= K; ++k) {
      std::cout << dp1[i][k] << " ";
    }
    std::cout << std::endl;
    std::cout << "l: ";
    for (int k = 0; k <= K; ++k) {
      std::cout << dp2[i][k] << " ";
    }
    std::cout << std::endl;
    std::cout << "-------------------" << std::endl;
#endif
  }

  std::cout << dp1[length][K] + dp2[length][K] << std::endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double r = sc.nextDouble();
    String area = String.format("%.5f", r*r*Math.PI);
    String length = String.format("%.5f", 2*Math.PI*r);
    System.out.println(area + " " + length);
  }
}

Measured memory_bytes: 28272
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[1024];
	int i;

	fgets(str, 1024, stdin);

	for (i = 0; i < strlen(str) - 1; i++){
		if (strncmp(&str[i], "apple", 5) == 0){
			strncpy(&str[i], "peach", 5);
		}
		else if (strncmp(&str[i], "peach", 5) == 0){
			strncpy(&str[i], "apple", 5);
		}
	}

	printf("%s", str);

	return (0);
}

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <utility>
#include <climits>

using namespace std;
typedef pair<string, string> pss;

vector<pss> repTokens;
set<string> passed;

string replace(const string &src, const string &alpha, const string &beta){
        string result;
        size_t p = 0, q;
        while((q = src.find(alpha, p)) != string::npos){
                for(size_t i = p; i < q; ++i){ result += src[i]; }
                result += beta;
                p = q + alpha.size();
        }
        for(size_t i = p; i < src.size(); ++i){ result += src[i]; }
        return result;
}

int dfs(const string &str, const string &to, int step, int limit){
        if(step > limit){ return INT_MAX; }
        if(str == to){ return step; }
        if(str.size() >= to.size()){ return INT_MAX; }
        if(passed.find(str) != passed.end()){ return INT_MAX; }
        passed.insert(str);
        int answer = INT_MAX;
        for(int i = 0; i < repTokens.size(); ++i){
                string replaced = replace(
                        str, repTokens[i].first, repTokens[i].second
                );
                int retval = dfs(replaced, to, step + 1, limit);
                if(retval < limit){ limit = retval; }
                answer = min(answer, retval);
        }
        return answer;
}

int main(){
        while(true){
                int n;
                cin >> n;
                if(n == 0){ break; }
                repTokens.resize(n);
                passed.clear();
                for(int i = 0; i < n; ++i){
                        cin >> repTokens[i].first >> repTokens[i].second;
                }
                string gamma, zeta;
                cin >> gamma >> zeta;
                int answer = dfs(gamma, zeta, 0, zeta.size() - gamma.size());
                if(answer == INT_MAX){
                        cout << "-1" << endl;
                }else{
                        cout << answer << endl;
                }
        }
        return 0;
}

Measured memory_bytes: 0
using System;
    class Program
    {
        static void Main(string[] args)
        {
            string[] xInputMax = Console.ReadLine().Split(' ');
            int xMaxN = int.Parse(xInputMax[0]);
            int xMaxM = int.Parse(xInputMax[1]);

            int[] a = new int[xMaxN];
            int[] b = new int[xMaxN];
            for (int i = 0; i < xMaxN; ++i)
            {
                string[] xInput = Console.ReadLine().Split(' ');
                a[i] = int.Parse(xInput[0]);
                b[i] = int.Parse(xInput[1]);
            }

            int[] c = new int[xMaxM];
            int[] d = new int[xMaxM];
            for (int i = 0; i < xMaxM; ++i)
            {
                string[] xInput = Console.ReadLine().Split(' ');
                c[i] = int.Parse(xInput[0]);
                d[i] = int.Parse(xInput[1]);
            }

            for (int i = 0; i < xMaxN; ++i)
            {
                int xDistance = int.MaxValue;
                int xCheckpoint = 0;
                for (int j = 0; j < xMaxM; ++j)
                {
                    int xNewDistance = System.Math.Abs(c[j] - a[i]) + System.Math.Abs(d[j] - b[i]);
                    if (xNewDistance < xDistance)
                    {
                        xDistance = xNewDistance;
                        xCheckpoint = j;
                    }
                }
                Console.WriteLine(xCheckpoint + 1);
            }
        }
    }


Measured memory_bytes: 13140
#!/usr/bin/env python3

def solve(k: int, s: str) -> str:
    if len(s) <= k:
        return s
    else:
        return s[:k] + '...'

# generated by online-judge-template-generator v4.1.0 (https://github.com/kmyk/online-judge-template-generator)
def main():
    K = int(input())
    S = input()
    zzy = solve(K, S)
    print(zzy)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}

int main()
{
   int n;
   string s;
   cin>>n>>s;
   int cnt=1;
   int tt=0;
   for(int i=1;i<n;i++)
   {
   	
   		if(s[i-1]!=s[i])
   			cnt++;
   }
   
   cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

class ArticulationPoints {
public:
  int n;
  vector<vector<int>> G;
  vector<bool> visited;
  vector<int> prenum, parent, lowest;
  int timer;
  set<int> ap;

  ArticulationPoints() {}
  ArticulationPoints(int n_, vector<vector<int>> G_) {init(n_, G_);}
  void init(int n_, vector<vector<int>> G_) {
    n = n_;
    G = G_;
    visited.resize(n, false);
    prenum.resize(n, 0);
    parent.resize(n, 0);
    lowest.resize(n, 0);
    timer = 1;
    find();
  }

  void dfs(int current, int prev) {
    prenum[current] = lowest[current] = timer;
    timer++;
    visited[current] = true;
    for (int next: G[current]) {
      if (!visited[next]) {
        parent[next] = current;
        dfs(next, current);
        chmin(lowest[current], lowest[next]);
      }
      else if (next != prev) {
        chmin(lowest[current], prenum[next]);
      }
    }
  }

  void find() {
    dfs(0, -1);
    int np = 0;
    FOR(i, 1, n) {
      int p = parent[i];
      if (p == 0) np++;
      else if (prenum[p] <= lowest[i]) ap.insert(p);
    }
    if (np > 1) ap.insert(0);
  }
};

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

  int n, m;
  cin >> n >> m;
  vector<vector<int>> G(n);
  rep(i, m) {
    int s, t;
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  ArticulationPoints ap(n, G);
  auto ans = ap.ap;
  for (int x: ans) cout << x << '\n';

  
  return 0;
}


Measured memory_bytes: 6360
import java.util.*;
import java.io.*;
class Program{

}
class Main{
    public static void main(String args[]) throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(); double val, sum = 0; String total;
    while(N-->0){
        val = sc.nextDouble(); total = sc.next();
        if (total.equals("JPY")){
            sum += val;
        }
        else{
            sum += val* 380000;
        }
    }
    System.out.println(sum);
    }
}

Measured memory_bytes: 23252
import java.util.Scanner;

/**
 * Created by weiyuan on 2018/03/16.
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a+b >= c) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<algorithm>
#define INF (1LL<<61)

using namespace std;

typedef unsigned long long ull;

ull dp[4001][4001],K[4001][4001];

int main(void){

  int n;
  cin >> n;
  vector<ull>a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(i>0)a[i]+=a[i-1];
  }

  fill(dp[0],dp[4001],INF);
  fill(K[0],K[4001],0);

  for(int i=0;i<n;i++)dp[i][i]=0,K[i][i]=i;

  for(int w=1;w<n;w++){
    for(int i=0,j=i+w;j<n;i++,j++){
      for(int r=K[i][j-1];r<=K[i+1][j];r++){
        ull cost=dp[i][r]+dp[r+1][j]+a[j]-((i>0)?a[i-1]:0);
        if(dp[i][j]>cost)dp[i][j]=cost,K[i][j]=r;
      }
    }
  }
  cout << dp[0][n-1] << endl;

  return 0;
}

Measured memory_bytes: 251352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

using pi = pair<int,int>;

int main()
{
    int n;
    scanf(" %d", &n);
    vector<pi> p(n);
    rep(i,n) scanf(" %d %d", &p[i].se, &p[i].fi);

    sort(all(p), greater<pi>());

    ll l=0, r=n+1;
    while(r-l>1)
    {
        ll m=(l+r)/2;

        ll sumA=0;
        priority_queue<int> A;
        rep(i,m)
        {
            sumA += p[i].se;
            A.push(p[i].se);
        }

        bool valid=(sumA<=m*p[m-1].fi);
        if(!valid)
        {
            for(int i=m; i<n; ++i)
            {
                int maxA = A.top();
                if(maxA > p[i].se)
                {
                    sumA = sumA - maxA + p[i].se;
                    A.pop();
                    A.push(p[i].se);
                }

                if(sumA<=m*p[i].fi)
                {
                    valid=true;
                    break;
                }
            }
        }

        if(valid) l=m;
        else r=m;
    }

    printf("%lld\n", l);
    return 0;
}

Measured memory_bytes: 8376
from collections import Counter

h, w = map(int, input().split())
a = Counter(''.join(input() for _ in range(h)))

center = h * w % 2
side = (h // 2) * (w % 2) + (w // 2) * (h % 2)

cnt = 0
for i in a:
    if a[i] % 2 == 1:
        a[i] -= 1
        cnt += 1
if cnt != center:
    print('No')
    exit()

print('Yes' if sum(a[i] % 4 == 2 for i in a) <= side else 'No')


Measured memory_bytes: 9464
function main(input) {
    const lines = input.split("\n");
    const [K, N] = lines[0].split(' ').map(Number);
    const aList = lines[1].split(' ').map(Number);

    let maxSpan = 0;
    for (let i = 0; i < aList.length; i++) {
        let next = aList[i+1];
        let span;
        if (!next) {
            span = K - aList[i] + aList[0];
        } else {
            span = next - aList[i];
        }
        maxSpan = Math.max(maxSpan, span);
    }
    
    console.log(K - maxSpan);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 33928
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

int main(){
	//2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
	int ans=0;
	int n;
	int c1, c2, c3;
	std::cin>>n;
	std::vector<int> prime=
	 {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
	std::vector<int> numPrime(25, 0);


	for(int i=1; i<=n; i++){
		int num= i;
		int idx=0;
		while(num!=1){
			if(num%prime[idx]==0){
				num/=prime[idx];
				numPrime[idx]++;
			}
			else{
				idx++;
			}
		}
	}

	c1=0, c2=0;
	for(int i=0; i<25; i++){
		if(numPrime[i]>=4)
			c1++;
		if(numPrime[i]>=2)
			c2++;
	}
	ans+= c1*(c1-1)/2 * (c2-2);

	c1=0, c2=0;
	for(int i=0; i<25; i++){
		if(numPrime[i]>=14)
			c1++;
		if(numPrime[i]>=4)
			c2++;
	}
	ans+= c1*(c2-1);

	c1=0, c2=0;
	for(int i=0; i<25; i++){
		if(numPrime[i]>=24)
			c1++;
		if(numPrime[i]>=2)
			c2++;
	}
	ans+= c1*(c2-1);

	c1=0;
	for(int i=0; i<25; i++){
		if(numPrime[i]>=74)
			c1++;
	}
	ans+= c1;


	std::cout<<ans<<std::endl;

	return 0;
}

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

typedef long long ll;
const int MAX_N = 50;

int main() {
	int n, cnt[26];
	std::string S[MAX_N], alphabet = "abcdefghijklmnopqrstuvwxyz";
	std::cin >> n;
	for(int i = 0; i < n; ++i) {
		std::cin >> S[i];
	}

	for(int i = 0; i < 26; ++i) {
		cnt[i] = 50;
		for(int j = 0; j < n; ++j) {
			int tmp = 0;
			for(char c : S[j]) {
				if(c == alphabet[i]) ++tmp;
			}
			cnt[i] = std::min(cnt[i], tmp);
		}
	}

	for(int i = 0; i < 26; ++i) {
		for(int j = 0; j < cnt[i]; ++j) {
			std::cout << alphabet[i];
		}
	} std::cout << std::endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
using LL = long long;

LL solve(int N, vector<pair<LL, LL>> &xys);

int main() {
    int N;
    cin >> N;
    vector<pair<LL, LL>> xys(N);
    for (auto & xy : xys){
        cin >> xy.first >> xy.second;
        if (xy.first > xy.second) swap(xy.first, xy.second);
    }
    cout << solve(N, xys) << endl;
    return 0;
}

LL solve(int N, vector<pair<LL, LL>> &xys){
    // xmin = Rmin, ymax = Bmax となるケース
    // Rmax = xmax, Bmin = ymin とすればよい。
    LL xmin = 2e9;
    LL ymin = 2e9;
    LL xmax = -2e9;
    LL ymax = -2e9;
    LL xmin_rev_min = 2e9;
    LL xmin_rev_max = -2e9;
    LL ymax_rev_min = 2e9;
    LL ymax_rev_max = -2e9;
    vector<pair<int, LL>> ymax_idx_val;
    for (int i = 0; i != N; ++i){
        auto x = xys[i].first;
        auto y = xys[i].second;
        if (x == xmin){
            xmin_rev_min = min(xmin_rev_min, y);
            xmin_rev_max = max(xmin_rev_max, y);
        }
        if (x < xmin){
            xmin = x;
            xmin_rev_min = y;
            xmin_rev_max = y;
        }
        xmax = max(xmax, x);
        ymin = min(ymin, y);
        if (y == ymax){
            ymax_rev_min = min(ymax_rev_min, x);
            ymax_rev_max = max(ymax_rev_max, x);
        }
        if (y > ymax){
            ymax = y;
            ymax_rev_min = x;
            ymax_rev_max = x;
        }
    }
    LL ans1 = (xmax - xmin) * (ymax - ymin);

    // xmin = Rmin, ymax = Rmax となるケース
    LL Bmin = min(ymax_rev_min, xmin_rev_min);
    LL Bmax = max(ymax_rev_max, xmin_rev_max);
    sort(xys.begin(), xys.end());
    Bmax = max(Bmax, xys.back().first);
    LL record = Bmax - xys[0].first;
    for (int i = 1; i != N; ++i){
        Bmax = max(Bmax, xys[i - 1].second);
        Bmin = min(Bmin, xys[i - 1].second);
        record = min(record, Bmax - min(Bmin, xys[i].first));
    }
    LL ans2 = (ymax - xmin) * record;

    return min(ans1, ans2);

}


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

int N;
int A[210];

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

    int counter = 0;

    while (true){
        bool exist_odd = false;  // A[i] がすべて偶数かどうかを判定するフラグ
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;  // 奇数があったらフラグを立てる
        }

        if (exist_odd) break; 

        for (int i = 0; i < N; ++i) A[i] /= 2;

        counter += 1;
    }

    cout << counter << endl;

}

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

using namespace std;
#define int long long 
#define N 666666
int arr[N],a[N],b[N];
#define pi 6.28318530717958623200
signed main(){
	int n;
	cin>>n;
	printf("%.20f",pi*n);
	return 0;
}



Measured memory_bytes: 3724
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處
int solve(vector<int>& v, int t) {
    return upper_bound(v.begin(), v.end(), t) - lower_bound(v.begin(), v.end(), t);
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    vector<int> A(N);
    vector<int> v1, v2, v3, v4;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        v1.push_back(i-A[i]);
        v2.push_back(i+A[i]);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    // for (auto x: v1)  cout << x << ' ';
    // cout << endl;
    // for (auto x: v2)  cout << x << ' ';
    // cout << endl;
    LL ans = 0;
    for (int i = 0; i < N; ++i) {
        // cout << "i " << i << endl;
        ans += solve(v1, i+A[i]);
        // cout << ans << endl;
        ans += solve(v2, i-A[i]);
        // cout << ans << endl;
    }
    cout << ans / 2 << endl;
    return 0;
}


Measured memory_bytes: 5928
/**
 *    Author:  AKASH-ALAM       
**/
#include <bits/stdc++.h>
#define endl        '\n'
#define db          double
#define ld          long double
#define ll          long long
#define ull         unsigned long long
#define sqr(x)      (x) * (x)
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)   ((a/gcd(a,b)) * b)
#define pf(x) 		push_front(x)
#define pb(x)       push_back(x)
#define eb(x)		emplace_back(x)
#define all(x)      (x).begin(), (x).end()
#define rall(x) 	(x).rbegin(), (x).rend()
#define sz(x) 		(int)x.size()
#define debug(x) 	cerr << #x << " = " << (x) <<endl
#define Fast_io    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

const ld PI = acos((ld)-1);
const int MOD = 1e9+7;
const ll INF = 1e18; 
using namespace std;

int main(){
    Fast_io;
    int n;  cin >> n;
    cout << (n*800) - (n / 15) * 200 << endl;
    return 0;
}


Measured memory_bytes: 3604
// https://atcoder.jp/contests/abc168/tasks/abc168_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<vector<int>> g(N);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    // 開始点からBFS
    queue<pair<int, int>> q;
    q.push({0, 0});
    bitset<100000> bt;
    bt.set(0);
    vector<int> ans(N);
    while (!q.empty()) {
        auto t = q.front();
        q.pop();
        for (auto &x : g[t.first]) {
            if (!bt[x]) {
                bt.set(x);
                q.push({x, t.first});
                ans[x] = t.first;
            }
        }
    }
    if ((int)bt.count() == N) {
        cout << "Yes\n";
        FOR(i, 1, N) { cout << ans[i] + 1 << "\n"; }
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 13520
#include<iostream>
#include<algorithm>
using namespace std;
int a,b,c,d,e,f,g;
int main(){
	cin>>a>>b>>c>>d>>e;
	f=min(a,min(b,c));
	g=min(d,e);
	cout<<f+g-50<<endl;
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const long double PI=3.14159265358979323846;


vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    ll ans = 0ll;
    map<pair<string,string>,ll> m;
    rep(bit,0,1<<n){
        string a = "", b = "";
        rep(i,0,n){
            if(bit&(1<<i)){
                a += s[i];
            }
            else{
                b += s[i];
            }
        }
        m[make_pair(a,b)]++;
    }
    rep(bit,0,(1<<n)){
        string pa = "", pb = "";
        rep(i,0,n){
            if(bit&(1<<i)){
                pa += s[n+i];
            }
            else{
                pb += s[n+i];
            }
        }
        std::reverse(all(pa));
        std::reverse(all(pb));
        ans += m[pair<string,string>(pb,pa)];
    }
    cout << ans << endl;
}


Measured memory_bytes: 87040
#include<iostream> 
#include<stdio.h>
#include<string>
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (n); ++i)	
//setprecision(16)

void outi(int x) { cout << x << endl; }
void outl(ll x) { cout << x << endl; }
void outs(string x) { cout << x << endl; }
ll max(ll a, ll b) {
	ll max;
	if (a > b) max = a;
	else max = b;
	return max;
}
ll min(ll a, ll b) {
	ll min;
	if (a < b) min = a;
	else min = b;
	return min;
}
//---------------------------------------------------------------

const int INF = 1001001001;
int main() {

	int n, m, x;
	cin >> n >> m >> x;

	int c[15];
	int a[15][15];

	rep(i, n) {
		cin >> c[i];
		rep(j, m) {
			cin >> a[i][j];
		}
	}

	int ans = INF;
	rep(s, 1 << n) {
		int cost = 0;

		vector<int> d(m);
		rep(i, n) {
			if (s >> i & 1) {
				cost += c[i];
				rep(j, m) {
					d[j] += a[i][j];
				}
			}

		}
		bool can = true;
		rep(j, m) {
			if (d[j] < x) can = false;
		}
		if (can) ans = min(ans, cost);
	}
	if (ans == INF) {
		outi(-1);
	}
	else outi(ans);
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define mk make_pair
using namespace std;
const int N = 2e3 + 5;
int n, m, ans;
int a[N][N], h[N], que[N];
char s[N][N];
bool check(int x, int y) {
	int res = 0;
	res += (s[x][y] == '#');
	res += (s[x - 1][y] == '#');
	res += (s[x][y + 1] == '#');
	res += (s[x - 1][y + 1] == '#');
	return res % 2 == 0;
}
int main() {
	cin >> n >> m;
	ans = max(n, m); 
	for (int i = 1; i <= n; i++) {
		scanf("%s", s[i] + 1);
	} 
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < m; j++) {
			a[i][j] = max(a[i][j], 1);
			if (check(i, j)) 
				a[i][j] = a[i - 1][j] + 1;
			h[j] = a[i][j]; 
		}
		int t = 0;
		for (int j = 1; j <= m; j++) {
			while (t && h[que[t]] > h[j]) {
				ans = max(ans, (j - que[t - 1]) * h[que[t]]);
				t--;
			}
			que[++t] = j;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 19840
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
A = np.array(lr(), np.int32)
total = A.sum()
A *= 4*M
count = (A >= total).sum()
bl = count >= M
print('Yes' if bl else 'No')


Measured memory_bytes: 21408
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class T> inline T re(){
	T N = 0; char c = getchar(); bool neg = 0;
	for (; c < '0' || c > '9'; c = getchar()) neg |= c == '-';
	for (; c >= '0' && c <= '9'; c = getchar())
		N = (N<<3)+(N<<1) + c - '0';
	return neg ? -N : N;
}

int n, k, tot = 0;
int main(){
	n = re<int>(); k = re<int>();
	for (int i = 1; i <= n; i++){
		tot += (re<int>()) >= k;
	}
	printf("%d\n", tot);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll T[N],A[N];
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  if (N == 1) {
    if (A[0] == T[0]) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
    return 0;
  }
  bool exist = true;
  int tmp = max(T[0],A[0]);
  for (int i = 0; i < N; i++) {
    if (max(A[i],T[i]) != tmp) {
      exist = false;
    }
  }
  for (int i = 1; i < N; i++) {
    if (T[i-1] != T[i]) {
      if (A[i] < T[i]) {
        exist = false;
      }
    }
  }
  for (int i = 0; i < N-1; i++) {
    if (A[i+1] != A[i]) {
      if (T[i] < A[i]) {
        exist = false;
      }
    }
  }
  if (!exist) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  for (int i = 0; i < N; i++) {
    if (i == 0 || i == N-1) {
      ans *= 1;
    } else {
      if (T[i-1] == T[i] && A[i] == A[i+1]) {
        ans *= min(T[i],A[i]);
        ans %= Mod;
      } else {
        ans *= 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N);
	rep(i,N){
		cin >> A[i];
	}
	ll sum = 0;
	rep(i,N){
		sum += A[i];
	}
	
	rep(i,N-1){
		A[i+1] += A[i];
	}
	
	ll ans = 1LL<<60;
	rep(i,N-1){
		ans = min(ans, abs(sum-2*A[i]));
	}
	
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P2;
const int inf=1000000000;
int main() {
	int n;
	int a[200001]={};
	cin>>n;
	for(int i=0;i<n;++i)cin>>a[i];
	cout<<a[n-1];
	for(int i=n-3;i>=0;i-=2)cout<<" "<<a[i];
	for(int i=(n%2);i<=n-2;i+=2)cout<<" "<<a[i];
	cout<<endl;
	return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k, n;
    string s;
    cin>>k>>s;
    n  = s.size();
    if(n>k)
    {
        for(int i=0;i<k;i++)
        {
            cout<<s[i];
        }
        cout<<"...";
    }
    else
    {
        cout<<s;
    }
    cout<<endl;
    return 0;
}


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

h,w=nii()
ch,cw=nii()
dh,dw=nii()
s=[list(input()) for i in range(h)]

ch-=1
cw-=1
dh-=1
dw-=1

dist=[[-1]*w for i in range(h)]
dist[ch][cw]=0

que=deque()
que.append((ch,cw))

def BFS(que):
  while que:
    y,x=que.popleft()

    if y==dh and x==dw:
      print(dist[y][x])
      exit()

    for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
      ny=y+dy
      nx=x+dx
      if 0<=ny<h and 0<=nx<w and s[ny][nx]!='#':
        que.appendleft((ny,nx))
        s[ny][nx]='#'
        dist[ny][nx]=dist[y][x]

    for i in range(-2,3):
      for j in range(-2,3):
        ny=y+i
        nx=x+j
        if 0<=ny<h and 0<=nx<w and s[ny][nx]!='#' and dist[ny][nx]==-1:
          que.append((ny,nx))
          dist[ny][nx]=dist[y][x]+1

BFS(que)

print(-1)

Measured memory_bytes: 134880
#include<iostream>
#include<vector>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(var,init,end) for(int var=init;var<end;var++)
int main() {
	int n;

	cin >> n;
	vector<string> line;
	line.resize(n);

	REP(i, n) {
		cin >> line[i];
	}

	int a = 0;
	int cnt = 0;
	REP(a, n) {
		int init = 1;
		FOR(i, 0, n) {
			FOR(j, init, n) {
				if (line[i][j]!=(line[j][i])) {
					goto L_NEXT;
				}
			}
		}
		cnt++;
	L_NEXT:
		string tmp = line[0];
		REP(s, n-1) {
			line[s] = line[s + 1];
		}
		line[n - 1] = tmp;
	}
	cout << cnt*n;
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
   
// g++ -std=c++11 prac.cpp
        
int main(){
    ll a,b,c,n,x,y,m=-1,k,w,sum=1,ans=0,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u;
    bool ok=true;
    cin >> n >> a >> b;
    if((b-a)%2==1){
        cout << "Borys" << endl;
        return 0;
    }
    else{
        cout << "Alice" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
// Code by ajcxsu
// Geometry template

#include<bits/stdc++.h>
#define EPS (1e-9)
using namespace std;

struct Point {
    double x,y;
    Point(double x=0,double y=0):x(x), y(y) {}

    Point operator +(Point p) { return Point(x+p.x,y+p.y); }
    Point operator -(Point p) { return Point(x-p.x,y-p.y); } // 加减
    Point operator *(double a) { return Point(x*a,y*a); }
    Point operator /(double a) { return Point(x/a,y/a); } // 数乘

    double norm() { return x*x+y*y; } // 范数
    double abs() { return sqrt(norm()); } // 大小

    bool operator < (const Point &p) { return x!=p.x?x<p.x:y<p.y; }
    bool operator == (const Point &p) { return fabs(p.x-x) < EPS && fabs(p.y-y) < EPS; }
} ;
typedef Point Vector;

double dot(const Point &a, const Point &b) {
    return a.x*b.x+a.y*b.y;
} // 内积
double cross(const Point &a, const Point &b) {
    return a.x*b.y-a.y*b.x;
} // 外积
bool equals(double a, double b) { return fabs(a-b)<EPS; } // 误差相等

struct Line {
    Point p1,p2;
} ;
typedef Line Seg;

/* 1 正交 2 平行 0 其他 */
int PO(Vector a, Vector b) {
    if(equals(dot(a,b), 0)) return 1;
    else if(equals(cross(a,b), 0)) return 2;
    else return 0;
}
int PO(Line a, Line b) { // 正交、平行判定
    return PO(a.p2-a.p1, b.p2-b.p1);
}

istream& operator >>(istream &in, Vector &a) {
    in>>a.x>>a.y;
    return in;
}
istream& operator >>(istream &in, Line &a) {
    in>>a.p1>>a.p2;
    return in;
} // 输入重载

Point project(Point a, Seg b) {
    Vector base=b.p2-b.p1;
    Vector hypo=a-b.p1;
    return b.p1+base*(dot(base, hypo)/ base.norm());
}

ostream& operator <<(ostream &out, Vector a) {
    out<<a.x<<' '<<a.y;
    return out;
} // 输出重载

int main() {
    cout.setf(ios::fixed);
    cout<<setprecision(10); // 设置输出精度

    Line x;
    cin>>x;
    int q;
    cin>>q;
    while(q--) {
        Point a;
        cin>>a;
        cout<<project(a,x)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3272
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int f(ll n){
	ll ans=0;
	while(n){
		ans+=n%10;
		n/=10;
	}
	return ans;
}

int main(){
	int a,b,n;
	scanf("%d%d%d",&n,&a,&b);
	ll ans=0;
	rep(i,1,n+1){
		ll t=f(i);
		if(a<=t&&t<=b)ans+=i;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdint>
using namespace std;
int main(){
	int n, c = 0;
	cin >> n;
	n -= 2;
	string s;
	cin >> s;
	for (int i = 0; i < n; i++){
		if (s.at(i) == 'A'){
			if (s.at(i + 1) == 'B'){
				if (s.at(i + 2) == 'C'){
					c++;
				}
			}
		}
	}
	cout << c << endl;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7

a=I()
s=input()
print(s if a>=3200 else 'red')

Measured memory_bytes: 38640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

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

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

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

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

    public double nextDouble() {
      return Double.parseDouble(next());
    }

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

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int si = sc.nextInt() - 1;
    int sj = sc.nextInt() - 1;
    int di = sc.nextInt() - 1;
    int dj = sc.nextInt() - 1;
    String[][] cells = new String[h][w];
    for (int i = 0; i < h; i++) {
      cells[i] = sc.next().split("");
    }
    int[][] mins = new int[h][w];
    for (int i = 0; i < h; i++) {
      Arrays.fill(mins[i], Integer.MAX_VALUE);
    }
    mins[si][sj] = 0;
    PriorityQueue<Integer> queue = new PriorityQueue<>((Integer a, Integer b) -> {
      int ai = a / w;
      int aj = a % w;
      int bi = b / w;
      int bj = b % w;
      return mins[ai][aj] - mins[bi][bj];
    });
    queue.add(si * w + sj);
    while (!queue.isEmpty()) {
      int id = queue.poll();
      int ci = id / w, cj = id % w;
      for (int ai = -2 + ci; ai <= 2 + ci; ai++) {
        for (int aj = -2 + cj; aj <= 2 + cj; aj++) {
          if (ai == ci && aj == cj) continue;
          if (ai < 0 || aj < 0 || ai >= h || aj >= w) continue;
          if (cells[ai][aj].equals("#")) continue;
          int cost = 0;
          if (Math.abs(ai - ci) + Math.abs(aj - cj) > 1) cost = 1;
          if (mins[ai][aj] <= mins[ci][cj] + cost) continue;
          mins[ai][aj] = mins[ci][cj] + cost;
          int aid = ai * w + aj;
          queue.add(aid);
        }
      }
    }
    if (mins[di][dj] < Integer.MAX_VALUE) System.out.println(mins[di][dj]);
    else System.out.println(-1);
  }
}

Measured memory_bytes: 115212
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String p = sc.next();
		
		StringBuilder sb = new StringBuilder(s);
		sb.append(s);
		
		if(sb.indexOf(p) >= 0){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26296
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int P;
char S[200000+2];
int main(){
  int i;
  long long now;
  long long res = 0;
  long long mul = 1;
  long long ind;
  long long inv;
  map<int,int> mp;
  rd(N);
  rd(P);
  rd(S);
  for(i=(0);i<(N);i++){
    S[i] -= '0';
  }
  if(P==2 || P==5){
    for(i=(0);i<(N);i++){
      if(S[i]%P==0){
        res += i+1;
      }
    }
    wt_L(res);
    wt_L('\n');
    return 0;
  }
  for(i=(1);i<(P);i++){
    if( (i*10)%P == 1 ){
      break;
    }
  }
  inv = i;
  now = 0;
  mp[0]++;
  for(i=(0);i<(N);i++){
    mul = (mul * inv) % P;
    now = (now * 10 + S[i]) % P;
    ind = (now * mul) % P;
    res += mp[ind];
    mp[ind]++;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200303-1 [beta]

// --- original code ---
// //no-fwrite
// int N, P;
// char S[2d5+2];
// {
//   ll now;
//   ll res = 0, mul = 1, ind, inv;
//   map<int,int> mp;
//   rd(N,P,S);
//   
//   rep(i,N) S[i] -= '0';
// 
//   if(P==2 || P==5){
//     rep(i,N) if(S[i]%P==0) res += i+1;
//     wt(res);
//     return 0;
//   }
// 
//   rep(i,1,P) if( (i*10)%P == 1 ) break;
//   inv = i;
// 
//   now = 0;
//   mp[0]++;
//   rep(i,N){
//     mul = (mul * inv) % P;
//     now = (now * 10 + S[i]) % P;
//     ind = (now * mul) % P;
//     res += mp[ind];
//     mp[ind]++;
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pr(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mkp make_pair
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 150005
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll H, W, D;
ll a;
ll Q;
ll l, r;
ll cost[MAX];

int main(void) {
    ll i, j;
    cin >> H >> W >> D;
    P pos[MAX];
    for(i=0; i<H; i++) {
        for(j=0; j<W; j++) {
            cin >> a;
            pos[a]=mkp(i, j);
        }
    }
    
    for(i=1; i+D<=H*W; i++) {
        cost[i+D]=cost[i]+abs(pos[i+D].first-pos[i].first)+abs(pos[i+D].second-pos[i].second);
    }
    
    cin >> Q;
    for(i=0; i<Q; i++) {
        cin >> l >> r;
        pr(cost[r]-cost[l]);
    }
    
}




















Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] B = new int[N-1];
		long sumA = 0;

		for (int i = 0; i < B.length; i++) {
			B[i] = sc.nextInt();
		}

		sumA += B[0];
		for (int i = 1; i < B.length; i++) {sumA += Math.min(B[i], B[i-1]);}
		sumA += B[N - 2];

		System.out.println(sumA);
	}

}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
#define MOD 1000000007
using namespace std;


int f(int pos , string & s1 , string & s2){
	int n = sz(s1);
	if(s1[pos] == s2[pos]){
		return 0;
	}
	return 1;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 

	int n;
	cin >> n;
	
	string s1 , s2;
	cin >> s1 >> s2;
	
	ll ans = 1;
	int prev = -1;
	
	
	rep(i , n){
		int cur = f(i , s1 , s2);
		if(prev == -1 && cur == 0){
			ans = 3;
		}else if(prev == -1 && cur == 1){
			ans = 6;
		}else if(prev == 0 && cur == 0){
			ans = (ans + ans) % MOD;
		}else if(prev == 0 && cur == 1){
			ans = (ans + ans) % MOD;
		}else if(prev == 1 && cur == 0){
			//
		}else if(prev == 1 && cur == 1){
			ans = (ans + ans + ans) % MOD;
		}
		prev = cur;
		i += cur;
	}
	cout << ans % MOD << nl;

	return 0;
}

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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  ll a, b, x; cin >> a >> b >> x;
  if(a==0) {
    cout << b/x+1 << "\n";
  } else {
    cout << b/x - (a-1)/x << "\n";
  }
  return 0;
}

Measured memory_bytes: 3676