akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc113/tasks/abc113_b
# Ruby 1st Try
N = gets.chomp.to_i
calcDiffTemp = Array.new(N,0.0)
T,A = gets.chomp.split(' ').map(&:to_f)
Hi = gets.chomp.split(' ').map(&:to_f)
minDiffTemp = 10000.00
answer = 0
for j in 0..(N-1) do
    calcDiffTemp[j] = (A-(T-Hi[j]*0.006)).abs
    if calcDiffTemp[j] < minDiffTemp
        answer = j
        minDiffTemp = calcDiffTemp[j]
    end
end
# p calcDiffTemp
puts(answer+1)


Measured memory_bytes: 3836
w,h,n=map(int,input().split())

y_max,x_max=h,w
y_min,x_min=0,0

for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    x_min=max(x_min,x)
  elif a==2:
    x_max=min(x_max,x)
  elif a==3:
    y_min=max(y_min,y)
  elif a==4:
    y_max=min(y_max,y)

width=max(x_max-x_min,0)
height=max(y_max-y_min,0)

print(int(width*height))





Measured memory_bytes: 9084
#include<iostream>
#include<cmath>
#include<vector>
#include<bitset>
#include<bitset>
#include<string>
#include<utility>
#include<algorithm>
#include<queue>

using namespace std;

int main(){
    int n,p;
    string s;
    // vector<int> modarray(n+1,0);
    
    cin >> n >> p >> s;
    if(p==2 || p==5){
        long long int res=0;
        for(int i=0;i<n;i++){
            if((s.at(i)-'0')%p==0){
                res+=(i+1);
            }
        }
        cout << res << endl;
        return 0;
    }

    vector<long long int> modlist(p,0);
    modlist.at(0)=1;
    // mod10=10%p;
    int mod10n=1,temp=0;
    for(int i=1;i<n+1;i++){
        
        temp=(temp+(s.at(n-i)-'0')*mod10n)%p;
        modlist.at(temp)++;
        mod10n=(10*mod10n)%p;
    }
    long long int res=0;
    for(int i=0;i<p;i++){
        if(modlist.at(i)>=2)
        res+= (modlist.at(i)*(modlist.at(i)-1))/2;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3488
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


# inputna
n,c = list(map(int, input().split()))
xv = [tuple(map(int, input().split())) for _ in range(n)]
c0 = []
c1 = []
v = 0
for i in range(n):
    v += xv[i][1]
    c0.append(v-xv[i][0])
v = 0
for i in range(n-1,-1,-1):
    v += xv[i][1]
    c1.append(v-(c-xv[i][0]))
c1 = c1[::-1]
d0 = []
d1 = []
v = 0
for i in range(n):
    v += xv[i][1]
    d0.append(v-2*xv[i][0])
v = 0
for i in range(n-1,-1,-1):
    v += xv[i][1]
    d1.append(v-2*(c-xv[i][0]))
d1 = d1[::-1]
# print(d0,d1)
for i in range(1,n):
    c0[i] = max(c0[i-1], c0[i])
    d0[i] = max(d0[i-1], d0[i])
for i in range(n-2, -1, -1):
    c1[i] = max(c1[i+1], c1[i])
    d1[i] = max(d1[i+1], d1[i])
m0 = max(c0)
m1 = max(c1)
if n>1:
    m2 = max((c0[i]+d1[i+1]) for i in range(n-1))
    m3 = max((c1[i]+d0[i-1]) for i in range(1,n))
else:
    m2 = m3 = -1
ans = max(m0,m1,m2,m3,0)
print(ans)

Measured memory_bytes: 112040
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 998244353
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000


int main(void) {
	int n, k; cin >> n >> k;

	vint a(n);
	rep(i, n) {
		cin >> a[i];
	}

	sort(all(a));
	int  ans=0;
	rep(i, k) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
	char a[10],b[10];
	int c,i,flag=0;
	scanf("%s ",a);
	scanf("%s",b);
	strcat(a,b);
	c=atoi(a);
	for(i=0;i<1000;i++)
	{
		if(c==(i*i))flag=1;
	}
	if(flag)printf("Yes");
	else printf("No");
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int main()
{
    //freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n=read();
	pr2(n*n*n);
    return 0;
}

Measured memory_bytes: 128
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val ls = in.map(_.toInt)
  val K = ls.last
  val list = ls.dropRight(1)
  val min = list.min
  val max = list.max
  val b = (max - min) <= K
  val ret = if(b) "Yay!" else ":("
  println(ret)
}


Measured memory_bytes: 26940
str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 

a = int(input())
s = list(input())

ans = ''
for char in s:
    
    c = str.index(char) + a 

    if c >= 26:
        c = c - 26
    ans = ans + str[c] #文字列は加算できる

print(ans)

Measured memory_bytes: 40924
#include <bits/stdc++.h>
#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a[100010];

int main(){
	cin >> n;
	REP(i,0,n) cin >> a[i]; sort(a,a+n);
	int s=1;
	REP(i,0,n/2) (s*=2)%=MOD;
	
	if(n%2){
		bool f=(a[0]==0);
		REP(i,1,n){
			if(a[i]!=a[i+1]) f=false;
			i++;
			if(a[i]%2) f=false;
		}
		if(f) cout << s << endl;
		else cout << 0 << endl;
	}else{
		bool f=true;
		REP(i,0,n){
			if(a[i]!=a[i+1]) f=false;
			i++;
			if(1-a[i]%2) f=false;
		}
		if(f) cout << s << endl;
		else cout << 0 << endl;
	}
		
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define N 101

int main(){
  int i,n,k,j,l,tmp=0;
  int A[N],B[N][N];

  l=0;
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d%d",&A[i-1],&A[i]);
  }
  
  for(i=1;i<=n;i++){
    B[i][i]=0;
  }
  for(j=2;j<=n;j++){
    for(i=1;i<=n-j+1;i++){    
      k=i+j-1;
      B[i][k]=INT_MAX;
   

      for(l=i;l<=k-1;l++){
	tmp=B[i][l]+B[l+1][k]+A[i-1]*A[l]*A[k];

	if(B[i][k]>tmp){
	  B[i][k]=tmp;
	}else{
	  B[i][k]=B[i][k];
	}
      }
    }
  }

  printf("%d\n",B[1][n]);

  return 0;
}

Measured memory_bytes: 632
#include <stdio.h>
#define MAX 100005
#define NIL - 1

typedef struct Node{
  int p,l,r;
}Node;

Node T[MAX];

int depth(int);
void print_degree(int);

int main(){

  int n,i,j,node,degree,child,sibling;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }

  for(i = 0; i < n; i++){
    scanf("%d%d",&node,&degree);
    for(j = 0; j < degree; j++){
      scanf("%d",&child);
      T[child].p = node;
      if(j == 0){
        T[node].l = child;
      }
      else{
        T[sibling].r = child;
      }
      sibling = child;
    }
  }

  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,depth(i));
    if(T[i].p == NIL){
      printf("root, [");
    }
    else if(T[i].l == NIL){
      printf("leaf, [");
    }
    else{
      printf("internal node, [");
    }
    print_degree(T[i].l);
    printf("]\n");
  }

  return 0;
}

int depth(int node){
  if(T[node].p == NIL){
    return 0;
  }
  else {
    return depth(T[node].p) + 1;
  }
}

void print_degree(int i){
  if(i != NIL){
    if(T[i].r == NIL){
      printf("%d",i);
    }
    else printf("%d, ",i);
    print_degree(T[i].r);
  }
}

Measured memory_bytes: 1784
#include<stdio.h>
int sum[20000];
int main(){
int a,b;
char c;
int i;
for( i=0;;i++){
    scanf("%d %c %d",&a,&c,&b);
    if(c == '+'){
        sum[i] = a + b;
    }
    else if(c == '-'){
        sum[i] = a - b;
    }
    if(c == '*'){
        sum[i] = a * b;
    }
    if(c == '/'){
        sum[i] = a / b;
    }
    if(c == '?'){
    break;
    }
}
for(int j=0;j<i;j++){
    printf("%d\n",sum[j]);
}


return 0;
}



Measured memory_bytes: 2064
#include <bits/stdc++.h>
std::vector<int> A['   '];
int N, M, S['   '], B, L, R, I;
int U(int z, int u) {
  while (z <= N)
    S[z] += u, z += z & -z;
}
main() {
  scanf("%d%d", &M, &N);
  for (; ~scanf("%d%d", &L, &R);)
    A[R - L + 1].push_back(L);
  for (L = 1; L <= N; L++) {
    for (B = M, I = L; I <= N; I += L) {
      R = I;
      for (;R;)
        B += S[R], R -= R & -R;
    }
    for (int u : A[L])
      U(u, 1), U(u + L, -1), M--;
    printf("%d\n", B);
  }
}

Measured memory_bytes: 53760
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


//const int mod = 1000000007;
const int MAX = 1000005;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}


// パスカルの三角形を使った実装
ll C[51][51]; // C[n][k] -> nCk

void comb_table(int N){
    for(int i=0; i<=N; i++){
        for(int j=0; j<=i; j++){
            if(j==0 || j==i) C[i][j] = 1LL;
            else C[i][j] = (C[i-1][j-1]+C[i-1][j]);
        }
    }
}

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

    COMinit();
    ll N, M, K; cin >> N >> M >> K;
    ll ans = 0;
    
    repr(a, 1, N) {
        ll add = a * (N-a) % mod * M % mod * M % mod * COM(N*M-2, K-2) % mod;
        ans += add;
        chmod(ans);
    }

    repr(a, 1, M) {
        ll add = a * (M-a) % mod * N % mod * N % mod * COM(N*M-2, K-2) % mod;
        ans += add;
        chmod(ans);
    }

    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 23680
#include <iostream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

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

#define rep(i, n) for(ll i = 0LL; i < n; i++)
#define repext(i, a, b) for (ll i = a; i < b; i++)
#define reprev(i, n) for (ll i = n - 1; i >= 0; i--)
#define repextrev(i, a, b) for (ll i = b - 1; i >= a; i--)

#define repv(v, values) for (auto v : values)

#define vec_all(vec) vec.begin(), vec.end()
#define sum(vec) accumulate(vec_all(vec), 0LL)
#define srt(vec) sort(vec_all(vec))
#define rev(vec) reverse(vec_all(vec))
#define revsrt(vec) srt(vec); rev(vec)

// vectorデバッグ
template<typename T>
void dump_vec(vector<T> vec) {
    rep(i, vec.size()) {
        cout << i << ": " << vec[i] << endl;
    }
}

template<typename T, typename S>
void dump_dic(map<T, S> dic) {
    for (auto v : dic) {
        cout << v.first << ": " << v.second << endl;
    }
}

// --- notice ---
// intの和はllにしろ

int main() {
    int k, t;
    cin >> k >> t;
    vector<int> a(t);
    rep(i, t) {
        cin >> a[i];
    }

    revsrt(a);
    int eat_index = 0;
    vector<int> eat(k, -1);
    
    if (k % 2 == 0) {
        for (int i = 0; i < k; i += 2)
        {
            eat[i] = eat_index;
            a[eat_index]--;
            if (a[eat_index] == 0)
            {
                eat_index++;
            }
        }
        for (int i = ((k % 2 == 0) ? k - 1 : k - 2); i > 0; i -= 2)
        {
            eat[i] = eat_index;
            a[eat_index]--;
            if (a[eat_index] == 0)
            {
                eat_index++;
            }
        }
    } else {
        for (int i = 0; i < k; i += 2)
        {
            eat[i] = eat_index;
            a[eat_index]--;
            if (a[eat_index] == 0)
            {
                eat_index++;
            }
        }
        for (int i = 1; i < k; i += 2)
        {
            eat[i] = eat_index;
            a[eat_index]--;
            if (a[eat_index] == 0)
            {
                eat_index++;
            }
        }
    }

    int cnt = 0;
    rep(i, k - 1) {
        if (eat[i] == eat[i + 1]) {
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n, k, q; cin >> n >> k >> q;
	vector<int> a(q);
	rep(i, q) {
		cin >> a[i]; a[i]--;
	}

	vector<int> win(n, 0);
	rep(i, q) win[a[i]]++;

	rep(i, n) {
		int point = k - q + win[i];
		cout << (point > 0 ? "Yes" : "No") << endl;
	}
	return 0;
}


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

int main(){
  int N,K,Q;
  cin>>N>>K>>Q;
  int A[N];
  
  for(int i=1;i<N+1;i++){
    A[i]=K-Q;
  }
  
  for(int i=0; i<Q;i++){
    int b;
    cin>>b;
    A[b]++;
  }
  
  for(int i=1;i<N+1;i++){
    if(A[i]>0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}


Measured memory_bytes: 1024
use proconio::marker::Chars;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: Chars,
        t: Chars,
    }
    let mut res = t.len();
    for i in 0..=s.len() - t.len() {
        let mut cnt = 0;
        for j in 0..t.len() {
            if s[i + j] != t[j] {
                cnt += 1;
            }
        }
        if res > cnt {
            res = cnt;
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 2196
import java.util.Scanner;

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

		//配列array
		int n = src.nextInt();
		int[] array = new int[n];
		for (int i=0; i<n; i++)
			array[i] = src.nextInt();

		int q = src.nextInt();
		for(int i=0; i<n; i++) {
//			System.out.print(array[i] + "debug");
		}

		for(int i=0; i<q; i++) {

			int b = src.nextInt();
			int e = src.nextInt() - 1;

			for(int j=0; j<(e+1 - b) / 2; j++) {
				int tmp = array[b+j];
				array[b+j] = array[e-j];
				array[e-j] = tmp;

			}
		}
		for(int i=0; i<n-1; i++) {
			System.out.print(array[i] + " ");
		}
		System.out.println(array[n-1]);
	}
}


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

int main()
{
	unsigned count = 0;

	while(1) {
		bool rev = true;
		string str;
		cin >> str;
		if(cin.eof()) break;

		for(unsigned i = 0; i < str.length() / 2; i++)
			if(str.at(i) != str.at(str.length() - i - 1))
				rev = false;

		if(rev == true)
			count++;
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
#include <stdio.h>
#define int long long
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}
int Max(int x, int y) {
	if (x > y)return x;
	else return y;
}
int Min(int x, int y) {
	if (x < y)return x;
	else return y;
}

/*Library End!*/
int c[3][3];
signed main(){
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++)cin >> c[i][j];
	}
	int a[3], b[3];
	a[0] = c[0][0];
	b[0] = 0;
	a[1] = c[1][0];
	a[2] = c[2][0];
	b[1] = c[0][1] - a[0];
	b[2] = c[0][2] - a[0];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (a[i] + b[j] != c[i][j]) {
				cout << "No" << endl;
				goto end;
			}
		}
	}
	cout << "Yes" << endl;
end:;
	system("PAUSE");
	return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
ll mod,d,f;
string s;
string::iterator p;
ll fact();
ll term();
ll exp();
 
ll extgcd(ll a, ll b, ll &x, ll &y){
  ll g=a;
  if(b==0) {
    x=1;
    y=0;
  } else {
    g=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }
  return g;
}
 
ll modinv(ll a, ll m){
  ll x,y;
  if(extgcd(a,m,x,y) == 1) return (x + m) % m;
  return -1; 
}
 
ll fact() {
  ll x;
  if(*p=='(') {
    ++p;
    x=exp();
    ++p;
  } else {
    x=0;
    while(isdigit(*p)) {
      x*=10;
      x+=*p-'0';
      x%=mod;
      p++;
    }
  }
  return x;
}
  
ll term() {
  ll x = fact();
  while(*p == '*' || *p == '/') {
    if(*p == '*') {
      ++p;
      d=fact();
      x*=d;
      x%=mod;
    } else {
      ++p;
      d=fact();
      if(d==0) {
        f=0;
        p=s.end();
      } else {
        x*=modinv(d,mod);
        x%=mod;
      }
    }
  }
  return x;
}
  
ll exp() {
  ll x = term();
  while(*p == '+' || *p == '-') {
    if(*p == '+') {
      ++p;
      d=term();
      x+=d;
      x%=mod;
    } else {
      ++p;
      d=term();
      x+=mod-d;
      x%=mod;
    }
  }
  return x;
}
 
int main() {
  string t;
  while(getline(cin,t) && t!="0:") {
    mod=0;
    int i=0;
    while(t[i]!=':') {
      mod*=10;
      mod+=t[i++]-'0';
    }
    s="";
    for(int j=i+1; j<t.size(); j++) {
      if(t[j]!=' ') s+=t[j];
    }
    p=s.begin();
    f=1;
    ll ans=exp();
    if(f) cout<<s<<" = "<<ans<<" (mod "<<mod<<")"<<endl;
    else cout<<"NG"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3236
import bisect

N, Q = map(int, input().split())
S = input()
idx = []

for i in range(N-1):
  if S[i] == "A" and S[i+1] == "C":
    idx.append(i+1)

for i in range(Q):
  l, r = map(int, input().split())
  lid = bisect.bisect_left(idx, l)
  rid = bisect.bisect_right(idx, r-1)
  print(rid-lid)
  

Measured memory_bytes: 5724
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	D = defaultdict(int)
	ans = 0
	for i in range(N):
		ans += D[-A[i] + i]
		D[A[i] + i] += 1

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 137844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    string s;
    cin >> s;
    bool ok=false;
    rep(i,s.size()){
        for(int j=0; j<s.size()-i; j++){
            string A = s;
            A.erase(i,j);
            if(A == "keyence") ok = true;
        }
    }
    if(ok) cout << "YES" <<endl;
    else cout << "NO" <<endl;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
X = list(map(int, input().split()))
ans = []


for i in range(n-k+1):
  l = X[i]
  r = X[i+k-1]
  
  ans.append(abs(r-l)+min(abs(l), abs(r)))
  
print(min(ans))

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  int n,m; cin >> n >> m;
  vector<string> a(n),b(m);
  for(int i=0; i<n; ++i) cin >> a.at(i);
  for(int i=0; i<m; ++i) cin >> b.at(i);

  for(int i=0; i<n-m+1; i++) {
    for(int j=0; j<n-m+1; j++) {
      if(a[i][j]==b[0][0]) {
      //if(i+m-1>=n || j+m-1>=n) continue;
        int ok=1;
        for(int k=0; k<m; ++k) {
          for(int l=0; l<m; ++l) {
            if(a[i+k][j+l]!=b[k][l]) {
              ok=0;
            }
          }
        }
        if(ok) drop("Yes");
      }
    }
  }
  cout << "No" << endl;

  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3632
import Control.Monad

main = do
   a <- words <$> getLine
   aa <- words <$> getLine
   aaa <- words <$> getLine
   n <- read <$> getLine
   b <- replicateM n getLine
   let c = map (\x -> if elem x b then "0" else x) a
   let cc = map (\x -> if elem x b then "0" else x) aa
   let ccc = map (\x -> if elem x b then "0" else x) aaa
   let zeros = ["0","0","0"]
   if zeros == c || zeros == cc || zeros == ccc || zeros == [c !! 1,cc !! 1,ccc !! 1] || zeros == [c !! 2,cc !! 2,ccc !! 2] || zeros == [c !! 0,cc !! 0,ccc !! 0] || zeros == [c !! 0,cc !! 1, ccc !! 2] || zeros == [c !! 2,cc !! 1,ccc !! 0]
      then putStrLn "Yes"
      else putStrLn "No"

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

#define ll long long int

using namespace std;

int main() {
    string s;
    cin >> s;
    ll sum = 0;
    for (auto c : s) {
        ll i = c - '0';
        sum += i;
        sum %= 9;
    }
    if (sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3732
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll sum,n,m,a,b;
vector<pair<ll,ll>> p;
main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        p.push_back({a,b});
    }
    sort(p.begin(),p.end());
    for(int i=0;i<n;i++){
        if(p[i].second<=m)sum+=p[i].first*p[i].second,m-=p[i].second;
        else {
          sum+=m*p[i].first;
          break;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
int main()
{
	ll n,m;
	cin>>n>>m;
	char dp[n][m];
	ll dp1[n][m];
	memset(dp1,0,sizeof(dp1));
	for(ll i=0;i<n;i++)
	for(ll j=0;j<m;j++)
	{
		cin>>dp[i][j];
	}
	
	for(ll i=0;i<m;i++)
	{
		if(dp[0][i]=='#')
		break;
		else
		dp1[0][i]=1;
	}
	for(ll i=0;i<n;i++)
	{
		if(dp[i][0]=='#')
		break;
		else
		dp1[i][0]=1;
	}
	
	for(ll i=1;i<n;i++)
	{
		for(ll j=1;j<m;j++)
		{
			if(dp[i][j]=='#')
			continue;
			dp1[i][j]=0;
			if(dp1[i-1][j]!=-1)
			dp1[i][j]=(dp1[i-1][j])%mod;
			if(dp1[i][j-1]!=-1)
			dp1[i][j]=(dp1[i][j]+dp1[i][j-1])%mod;
		}
	}
	cout<<dp1[n-1][m-1];
	return 0;
}
	


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

using namespace std;

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

    vector<pair<int, int>> poses;
     
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        auto pair = make_pair(x, y);
        poses.push_back(pair);
    }
    sort(poses.begin(), poses.end());

    vector<pair<int, int>> v;
    int p, q = 0;
    for (int i = 0; i < poses.size(); i++) {
      for (int j = 0; j < poses.size(); j++) {
        if (poses.at(i) == poses.at(j)) continue;
        auto pq = make_pair<int, int>(
          poses.at(i).first - poses.at(j).first,
          poses.at(i).second - poses.at(j).second
        );
        v.push_back(pq);
      }
    }
    sort(v.begin(), v.end());
    int max = 0;
    int count = 0;
    pair<int, int> pre;
    for (int i = 0; i < v.size(); i++) {
      auto current = v.at(i);
      if (pre == current) {
        count++;
      } else {
        count = 1;
      }
      if (count >= max) max = count;
      pre = current;
    }
    
    cout << N - max<< endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
using namespace std;

int main(){
    long long n, k, _h, d, min=1000000000;
    vector<int> h(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> _h;
        h.push_back(_h);
    }
    sort(h.begin(), h.end());

    for (int i=0;i<n-k+1;i++){
        d = h[i+k-1] - h[i];
        if(min > d) min = d;
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 892
n,a,b = map(int,input().split())
ans = 0;
for i in range(1,n+1):
    sum = 0;
    x = i;
    while x:
        sum += int(x%10);
        x/=10;
    if a <= sum <= b:
        ans+=i;
print("%d" % (ans) );

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

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

    int ans;
    for (int i = 1; i < 4; i++){
        if (i != a){
            if (i != b)
                ans = i;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

#define rep(i,n) for(int (i)=0;(i)<(n); ++(i))
using namespace std;

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

    vector<int> p(n, 0);
    rep(i, n) {
        cin >> p[i];
    }

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

    auto result = find(p.begin(), p.end(), x);

    int max_val = x + 1;
    int min_val = x - 1;

    if (result == p.end()) {
        cout << x << endl;
        return 0;
    } else {
        int x_index = distance(p.begin(), result);

        for(int i = 1; x_index - i >= 0; i++) {
            if(p[x_index - i] != x - i) {
                min_val = x - i;
                break;
            }
            min_val = x - (i + 1);
        }

        for(int i = 1; x_index + i < n; i++) {
            if(p[x_index + i] != x + i) {
                max_val = x + i;
                break;
            }
            max_val = x + (i + 1);
        }

        if(x - min_val <= max_val - x) {
            cout << min_val << endl;
        } else {
            cout << max_val << endl;
        }

        return 0;
    }
}

Measured memory_bytes: 3184
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    int flag=0;
    for(int i=a*100/8;i<=b*10+9;i++){
        
        if(floor(i*0.08)==a&&floor(i*0.1)==b){
            cout<<i<<endl;
            flag=1;
            break;
        }
        
    }
    if(!flag)
        cout<<"-1"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<math.h>
#include<cstdio>
using namespace std;
typedef complex<double> xy_t;
xy_t P[110];

double area(xy_t a, xy_t b) {return (conj(a)*b).imag();}

int main()
{
    int N;
    cin >> N;
    int x, y;
    for (int i = 0; i < N; i++) {
        cin >> x >> y;
        P[i] = xy_t((double)x, (double)y);
    }
    double sum = 0.0;
    xy_t a = P[0];
    for (int i = 0; i < N - 2; i++) {
        xy_t b = P[i + 1], c = P[i + 2];
        sum += area(c - a, b - a) / 2.0;
    }
    sum = abs(sum);
    printf("%.1f\n", sum);
    return 0;
}

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

using ll = long long ;

const ll MOD = 1e9+7;
ll N, M;

ll kai(ll x) {
   ll ret = 1;
   while (x > 0) {
      ret = ((ret%MOD) * (x%MOD))%MOD;
      x--;
   }
   return ret;
}

int main() {
   cin >> N >> M;

   if (abs(N-M) >= 2) {
      cout << 0 << endl;
      return 0;
   }

   ll Min = min(N, M), Max = max(N, M);
   if (Min == Max) {
      cout << ((2*kai(Min))%MOD * (kai(Min))%MOD)%MOD << endl;
   } else {
      cout << ((kai(Min)%MOD) * (kai(Max)%MOD))%MOD << endl;
   }


   return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const long long linf = 1e18 + 7;
const int inf = 1e9 + 7;
const int N = 2e5 + 5;

typedef long long ll;

ll q, h, s, d, n, ans;

int main(){
      cin >> q >> h >> s >> d >> n;
      q *= 4;
      h *= 4;
      s *= 4;
      d *= 4;
      n *= 4;
      h = min(h, q * 2);
      s = min(s, h * 2);
      d = min(d, s * 2);
      ans = (n / 8) * d;
      n %= 8;
      ans += (n / 4) * s;
      n %= 4;
      ans += (n / 2) % s;
      n %= 2;
      ans += q * n;
      cout << ans / 4 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

int main() {
    while (1) {
        int t;
        string s;
        cin >> t;
        cin >> s;
        if (t == 0) {
            break;
        }
        int len = s.size();
        int ansnum = -1;
        int anscut = -1;
        bool ok = true;
        for (int i = 0; i < (1 << (len - 1)); i++) {
            int sum = 0;
            string cur = "";
            cur += s[0];
            for (int j = 1; j < len; j++) {
                if (i & (1 << (j - 1))) {
                    sum += stoi(cur);
                    cur = s[j];
                } else {
                    cur += s[j];
                }
            }
            sum += stoi(cur);
            if (sum <= t && sum > ansnum) {
                ansnum = sum;
                anscut = i;
                ok = true;
            } else if (sum <= t && sum == ansnum) {
                ok = false;
            }
        }
        if (ansnum == -1) {
            cout << "error" << endl;
        } else {
            if (!ok) {
                cout << "rejected" << endl;
            } else {
                cout << ansnum << " ";
                string cur = "";
                cur += s[0];
                for (int j = 1; j < len; j++) {
                    if (anscut & (1 << (j - 1))) {
                        cout << cur << " ";
                        cur = s[j];
                    } else {
                        cur += s[j];
                    }
                }
                cout << cur << endl;
            }
        }
    }
}



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

using namespace std;

bool is_biparitite(vector<vector<int>> &g){
  bool ret = true;
  
  int n = (int)g.size();
  vector<int> color(n, 0);
  color[0] = 1;
  
  stack<int> s;
  s.push(0);
  while(!s.empty()){
    int v = s.top();
    s.pop();
    
    for(int j = (int)g[v].size() - 1; j >= 0; j--){
      if(color[g[v][j]] != 0){
        if(color[v] == color[g[v][j]]){
          ret = false;
          break;
        }else{
          continue;
        }
      }
      
      color[g[v][j]] = -color[v];
      
      s.push(g[v][j]);
    }
  }
  
  return ret;
}

int bfs(int root, vector<vector<int>> &g){
  int d = 0;
  
  int n = (int)g.size();
  vector<int> dist(n, -1);
  dist[root] = 0;
  
  queue<int> q;
  q.push(root);
  while(!q.empty()){
    int v = q.front();
    q.pop();
    
    for(int j = 0; j < (int)g[v].size(); j++){
      if(dist[g[v][j]] != -1) continue;
      
      d = max(d, (dist[g[v][j]] = dist[v] + 1));
      
      q.push(g[v][j]);
    }
  }
  
  return d + 1;
}

int main(){
  int n;
  cin >> n;
  
  vector<vector<int>> g(n);
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    for(int j = 0; j < n; j++) if(s[j] == '1') g[i].push_back(j);
  }
  
  int d = -1;
  if(is_biparitite(g)){
    for(int i = 0; i < n; i++){
      d = max(d, bfs(i, g));
    }
  }
  
  cout << d << endl;
  
  return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderCs
{

    class Program
    {

        const int Mod = 1000000007;

        static void Main()
        {

            var str = Console.ReadLine().ToArray();
            var result = 0;

            for (int i = 0, l = str.Length / 2, max = str.Length - 1; i < l; i++)
            {

                if (str[i] != str[max - i]) result++;

            }

            Console.WriteLine(result);

        }


    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()

//use (__int128)to extend ll range
double doINF = 1.0/0.0 ;
ostream_iterator <int> outp(cout," ");
inline ll modadd(ll n,ll m,ll mod){
    ll sum = ((n+m)%mod+mod)%mod;
    return sum;
} 
inline ll modsub(ll n,ll m, ll mod){
    ll diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}
inline ll modpro(ll n,ll m,ll mod){
    ll pro = ((n*m)%mod+mod)%mod;
    return pro;
}
inline ll pow(int x,int y){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
inline ll powmod(ll x,ll y,ll mod){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}
ll min(ll a, ll b){
   if(a>b){
       return b;
   }
   return a;
}

ll max(ll a, ll b){
   if(a>b){
       return a;
   }else return b;
}
 
bool pairdec(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 		if(a.fi!=b.fi)
       	return (a.fi> b.fi);
		else return a.se>b.se;  
} 
ll power(ll x, ll y, ll mod) 
{ 
    ll res = 1; 
    x = x%mod; 
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % mod; 
  
        y = y >> 1;
        x = (x * x) % mod; 
    } 
    return res; 
} 
ll modInverse(ll a, ll mod) 
{ 
    return  powmod(a, mod - 2, mod); 
} 
ll modFact(ll n, ll mod) 
{ 
    if (n >=mod) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) %mod; 
  
    return result; 
} 
//cout<<setprecision(9)<<fixed<<sum<<endl; --- precision for double numbers
//copy(v.beg,v.en,outp);
//-----comparision for pairs------
 
// bool comp(const pair<int,int>pia,const pair<int,int>pib)
// {
// 	if(pia.fi==pib.fi) return pia.se>pib.se;
// 	else return pia.fi>pib.fi;
// }

const ll N=1e9+7;
int main()
{
    ll n,k;
    cin>>k>>n;
    ll sum=0;
    ll arr[n+1];
    forl(i,0,n) cin>>arr[i];
    arr[n]=arr[0]+k;
    ll maxi=-1;
    ll maxval=-1;
    forl(i,0,n)
    {
    if(arr[i+1]-arr[i]>maxval)
    {
        maxval=arr[i+1]-arr[i];
        maxi=i;
    }

    }
    forl(i,0,n)
    {
        if(i==maxi) continue;
        else{
            sum+=arr[i+1]-arr[i];
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
     
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
#define mod2 998244353  

int solve(){
    int n;
    cin>>n;
    n=n%10;
    if(n==3) cout<<"bon";
    else if(n==1||n==0||n==6||n==8) cout<<"pon";
    else cout<<"hon";
    
    return 0;
}   
     
signed main(){
    IOS;
    ///freopen("input.txt", "r" , stdin);
   // freopen("output4.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<"\n";
      // cout<<" * "<<t<<"\n";
    }
//    return 0;
} 

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
typedef long long int64;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	int a = int(N / 500);
	int b = N%500/5;
	cout << a * 1000 + b * 5;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdlib>
 
using namespace std;
 
int p,n;
 
struct data{
  double a,b; // a/b
  data(){}
  data(double a, double b):a(a),b(b){}
  double getValue(){return a/b;}
  bool operator < (const data& d) const { return a/b < d.a/d.b;}
};
 
int gcd(int a, int b){
  if(b == 0) return a;
  return gcd(b,a%b);
}
 
void solve(){
 
  data up((1<<20),1),low(-1,1);
 
  for(int i = 1; i <= n; i++)
    for(int j = 1; j <= n; j++){
      data tmp(i,j);
      if(tmp.getValue() < sqrt(p) && gcd(i,j) == 1){
        if(low < tmp) low = tmp; 
        break;
      }
 
      if(up.getValue() > tmp.getValue() && gcd(i,j) == 1) up = tmp; 
    }
 
  cout << up.a << "/" << up.b << " " << low.a << "/" << low.b << endl;
}
 
int main(){
  while(cin >> p >> n && p+n) solve();
  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = INF;
  rep(i, max(x, y)+1) {
    int j = max(x-i, 0), k = max(y-i, 0);
    chmin(ans, j*a+k*b+i*2*c);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

from collections import deque

h, w = na()
s = [ns() for i in range(h)]
maze = [[s[i][j] for j in range(w)] for i in range(h)]
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]

def bfs(sx, sy):
    q = deque()
    inf = 1 << 60
    d = [[inf for i in range(w)] for i in range(h)]
    d[sy][sx] = 0
    q.append((sx, sy))
    mx = 0
    while len(q):
        p = q.popleft()
        for i in range(4):
            nx, ny = p[0] + dx[i], p[1] + dy[i]
            if 0 <= nx and nx < w and 0 <= ny and ny < h and maze[ny][nx] != '#' and d[ny][nx] == inf:
                q.append((nx, ny))
                update = d[p[1]][p[0]] + 1
                d[ny][nx] = update
                mx = max(mx, update)
    return mx

ans = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] != '#':
            ans = max(ans, bfs(j, i))

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;
 
 
int main() {
    int n, x, d = 0, l, ans = 1;
    cin >> n >> x;
    for (int i = 0; i < n; i++){
        cin >> l;
        d = d + l;
        if (d <= x){
            ans++;
        }
    }
    cout << ans << endl;
}

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

const long long INF = 1LL << 50;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> a(M+1), b(M+1), c(M+1);
    for( int i = 0; i < M; ++i ){
        cin >> a[i] >> b[i] >> c[i];
        c[i] = - c[i];
    }

    // ベルマンフォード法(経路に負のコストがある場合でも使える唯一の方法)
    // 全ての edge に着目して各頂点の経路を更新していく
    // 最短経路では各頂点を高々1回しか通らないので N-1 回チェックすればよい
    vector<long long> distance(N+1, INF);
    distance[1] = 0;
    for( int loop = 1; loop < N; ++loop ){
        for( int i = 0; i < M; ++i ){
            if( distance[a[i]] == INF ) continue;
            if( distance[b[i]] > distance[a[i]] + c[i] ){
                distance[b[i]] = distance[a[i]] + c[i];
            }
        }
    }
    long long ans = distance[N];

    // 不閉路の検出
    // N 回目以降の更新で distance[N] を小さくできる場合、経路上に不閉路が存在する
    vector<bool> negative(N+1, false);
    for( int loop = 1; loop <= N; ++loop ){
        for( int i = 0; i < M; ++i ){
            if( distance[a[i]] == INF ) continue;
            if( distance[b[i]] > distance[a[i]] + c[i] ){
                distance[b[i]] = distance[a[i]] + c[i];
                negative[b[i]] = true;
            }
            if( negative[a[i]] == true ) negative[b[i]] = true;
        }
    }

    if( negative[N] ) cout << "inf" << endl;
    else cout << - ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int f, b, r, v, n;
	int i, j;
	int v1[3][10], v2[3][10], v3[3][10], v4[3][10];

	for (i = 0; i < 3; i++)
		for (j = 0; j < 10; j++)
		{
			v1[i][j] = 0;
			v2[i][j] = 0;
			v3[i][j] = 0;
			v4[i][j] = 0;
		}

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d%d%d%d", &f, &b, &r, &v);

		b--; r--;

		switch (f)
		{
			case 1: v1[b][r] += v; break;
			case 2: v2[b][r] += v; break;
			case 3: v3[b][r] += v; break;
			case 4: v4[b][r] += v; break;
		}
	}

	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 10; j++)
			printf(" %d", v1[i][j]);	
		putchar('\n');
	}
	
	for (i = 0; i < 20; i++)
		putchar('#');
	putchar('\n');

	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 10; j++)
			printf(" %d", v2[i][j]);
		putchar('\n');
	}
	
	for (i = 0; i < 20; i++)
		putchar('#');
	putchar('\n');

	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 10; j++)
			printf(" %d", v3[i][j]);
		putchar('\n'); 
	}
	
	for (i = 0; i < 20; i++)
		putchar('#');
	putchar('\n');

	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 10; j++)
			printf(" %d", v4[i][j]);
		putchar('\n');
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
long long a,b,k;
int main()
{
    cin>>a>>b>>k;
    while (k--)
    {
        if (a%2!=0)
        {
            a--;
        }
        b+=(a/2);
        a/=2;
        if (k!=0)
        {
            k--;
            if (b%2!=0)
            {
                b--;
            }
            a+=(b/2);
            b/=2;
        }
    }
    cout<<a<<' '<<b;
    return 0;
}


Measured memory_bytes: 256
def main():
    h = int(input())

    if h == 1:
        minimum = 1
    else:
        if h % 2 == 1:
            h -= 1

        minimum = 0
        power = 0
        while True:
            minimum += 2 ** power
            power += 1

            if 2 ** power > h:
                break

    print(minimum)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9124
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,a[101010],ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	ans=a[n-1]-a[0];
	for(int i=1;i<n-1;i++)
	{
		ans+=abs(a[i]);
	}
	cout<<ans<<endl;
	for(int i=1;i<n-1;i++)
	{
		if(a[i]<0)
		{
			cout<<a[n-1]<<' '<<a[i]<<endl;
			a[n-1]-=a[i];
		}
		else
		{
			cout<<a[0]<<' '<<a[i]<<endl;
			a[0]-=a[i];
		}
	}
	cout<<a[n-1]<<' '<<a[0]<<endl;
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b;
    cin >> a>>b;

    int ans = a+b;
    if(ans >= 24)    ans -= 24;
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256