akhauriyash/Code-Regression huggingface dataset:
N=int(input())
h=list(map(int,input().split()))
dp=[0,abs(h[1]-h[0])]
for i in range(2,N):
    dp.append(min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1])))
print(dp[-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define per(a, b, c) for(int a = (b); a >= (c); -- a)
using namespace std;
template <class T> void rd(T &x){
  x = 0; int f = 1; char ch = getchar();
  while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); }
  while(ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  x *= f;
}

typedef long long ll;
ll n, ans;

int main(){
  rd(n);
  if(n <= 100){
	for(int i = 1; i <= n; ++ i){
	  if(n / i == n % i) ans += i;
	}
  }
  else{
	for(ll i = 1; i <= n / i; ++ i){
	  if(n % i == 0){
		if(i * i == n) continue;
		ans += n / i - 1;
	  }
	}
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define dou double
#define rep(a,b,c) for(register int a = b; a <= c; ++ a)
#define dep(a,b,c) for(register int a = b; a >= c; -- a)
#define Set(a,b) memset(a,b,sizeof a)
#define INF (0x3f3f3f3f)
template<class T> inline T read() {static T x;static char c;static int _;x=0;_=1;while(!isdigit(c=getchar()))if(c=='-')_=-1;while(x=(x<<1)+(x<<3)+(c&15),isdigit(c=getchar()));return x*_;}
template<class T> void write(T x) {if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10^48);}
template<class T> inline bool chikmin(T &a, T b) {return a>b?(a = b,1):0;}
template<class T> inline bool chikmax(T &a, T b)
{return a<b?(a=b,1):0;}
#define N 44
int dp[N][N][N][N], sum[N][N];
int n, m, tx, ty;
inline void Init() {
    char str[N];
    scanf("%d%d", &n, &m);
    rep(i,1,n) {
        scanf("%s", str + 1);
        rep(j,1,m) {
            if(str[j] == 'P') {
                tx = i;
                ty = j;
            } else if(str[j] == '#') {
                sum[i][j] = 1;
            }
        }
    }
    rep(i,1,n) rep(j,1,m) {
        sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
}
inline int Sum(const int &a, const int &b, const int &c, const int &d) {
    return sum[c][d] - sum[c][b - 1] - sum[a - 1][d] + sum[a - 1][b - 1];
}
int work(const int &a, const int &b, const int &c, const int &d) {
    if(dp[a][b][c][d] != -1) return dp[a][b][c][d];
    int &ans = dp[a][b][c][d] = INF;

    chikmin(ans, Sum(a, b, tx, ty));
    chikmin(ans, Sum(tx, b, c, ty));
    chikmin(ans, Sum(a, ty, tx, d));
    chikmin(ans, Sum(tx, ty, c, d));

    rep(i, a + 1, tx) rep(j, b + 1, ty) 
        chikmin(ans, work(i, j, c, d) + Sum(i, b, c, j - 1) +\
                                        Sum(a, j, i - 1, d));
    rep(i, tx, c - 1) rep(j, ty, d - 1) 
        chikmin(ans, work(a, b, i, j) + Sum(a, j + 1, i, d) +\
                                        Sum(i + 1, b, c, j));
    rep(i, tx, c - 1) rep(j, b + 1, ty)
        chikmin(ans, work(a, j, i, d) + Sum(a, b, i, j - 1) +\
                                        Sum(i + 1, j, c, d));
    rep(i, a + 1, tx) rep(j, ty, d - 1)
        chikmin(ans, work(i, b, c, j) + Sum(a, b, i - 1, j) +\
                                        Sum(i, j + 1, c, d));
    return ans;
}
int main()
{
    //freopen("haner.in","r",stdin);
    //freopen("haner.out","w",stdout);
    Init();
    Set(dp,-1);
    printf("%d\n", work(1,1,n,m));
    return 0;   
}


Measured memory_bytes: 14976
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

int main(){
    int n; cin >> n;
    vvi G(n, vi(n));
    rep(i, n)rep(j, n) cin >> G[i][j];

    vvi dp(n + 1, vi(n + 1));
    rep(i, n)rep(j, n){
        dp[i + 1][j + 1] = G[i][j] + dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
    }

    int ans = -(1LL << 31);
    loop(i1, 1, n + 1)loop(i2, 0, i1)loop(j1, 1, n + 1)loop(j2, 0, j1){
        int t = dp[i1][j1] - dp[i1][j2] - dp[i2][j1] + dp[i2][j2];
        ans = max(t, ans);
    }
    cout << ans << endl;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

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

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int X, Y, Z, K; cin >> X >> Y >> Z >> K;
	vll A(X), B(Y), C(Z); cin >> A >> B >> C;
	sort(rbegin(A), rend(A));
	sort(rbegin(B), rend(B));
	sort(rbegin(C), rend(C));

	vll ans;
	for (int i = 0; i < X; i++) {
		for (int j = 0; j < Y; j++) {
			for (int k = 0; k < Z; k++) {
				if ((i+1) * (j+1) * (k+1) > K) break;
				ans.push_back(A[i] + B[j] + C[k]);
			}
		}
	}
	sort(rbegin(ans), rend(ans));
	for (int i = 0; i < K; i++) {
		cout << ans[i] << el;
	}
}

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


Measured memory_bytes: 4256
import java.io.*;
import java.util.*;
public class Main {
	
	static Node tree[];
	static List<Integer> plot;
	
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt();
		tree=new Node[n]; for(int i=0;i<n;i++)tree[i]=new Node();
		
		for(int i=0;i<n;i++) {
			int id=Integer.parseInt(in.next()),l=Integer.parseInt(in.next()),r=Integer.parseInt(in.next());
			tree[id].left=l; tree[id].right=r;
			if(l!=-1)tree[l].parent=id;
			if(r!=-1)tree[r].parent=id;
		}
		
		plot=new ArrayList<>(); String method[]= {"Preorder","Inorder","Postorder"};
		int r=0;
		while(tree[r].parent!=-1)r++;
		
		PrintWriter out=new PrintWriter(System.out);
		for(int i=0;i<3;i++) {
			plot.clear();
			if(i==0)Preoder(r);
			else if(i==1)Inoder(r);
			else Postoder(r);
			out.println(method[i]);
			for(int j=0;j<plot.size();j++)out.print(" "+plot.get(j));
			out.println();
		}
		out.flush();
	}
	
	static void Preoder(int index) {
		plot.add(index);
		if(tree[index].left!=-1)Preoder(tree[index].left);
		if(tree[index].right!=-1)Preoder(tree[index].right);
	}
	
	static void Inoder(int index) {
		if(tree[index].left!=-1)Inoder(tree[index].left);
		plot.add(index);
		if(tree[index].right!=-1)Inoder(tree[index].right);
	}
	
	static void Postoder(int index) {
		if(tree[index].left!=-1)Postoder(tree[index].left);
		if(tree[index].right!=-1)Postoder(tree[index].right);
		plot.add(index);
	}

}

class Node{
	int parent=-1,left=-1,right=-1;
}



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

using namespace std;

const int N = 1e5 + 5;

char s[N];

int main() {
  scanf("%s", s);
  int n = strlen(s);
  int p = 0, g = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'g') {
      if (p + 1 <= g) {
        p++;
        ans++;
      } else {
        g++;
      }
    } else {
      if (p + 1 <= g) {
        p++;
      } else {
        g++;
        ans--;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 384
//Checkpoints

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) int n;cin>>n;vector<int>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,int> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int n,m;cin>>n>>m;
    vector<p>a(n),c(m);
    rep(i,0,n)cin>>a[i].first>>a[i].second;
    rep(i,0,m)cin>>c[i].first>>c[i].second;
    rep(i,0,n){
        int o=inf,k;
        rep(j,0,m){
            if(o>abs(c[j].first-a[i].first)+abs(c[j].second-a[i].second)){
                o=abs(c[j].first-a[i].first)+abs(c[j].second-a[i].second);
                k=j+1;
            }
        }
        cout<<k<<nnn;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int a, b, k;
  cin >> a >> b >> k;
  int t = min(a, k);
  a -= t;
  k -= t;
  b -= k;
  cout << max(0LL, a) << " " << max(0LL, b) << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def dfs(v, p, c):
    color[v] = c
    for e in graph[v]:
        if e[0] == p: continue
        if e[1] % 2: dfs(e[0], v, 1-c)
        else: dfs(e[0], v, c)


n = int(input())
color = [-1 for _ in range(n)]
graph = [[] for _ in range(n)]

for i in range(n-1):
    u, v, w = [int(x) for x in input().split()]
    u, v = u - 1, v - 1
    graph[u].append((v, w))
    graph[v].append((u, w))

dfs(0, -1, 1)
for i in range(n):
    print(color[i])

Measured memory_bytes: 147248
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#define mod 1000000007
using namespace std;
long long int solve(int H,int W,vector <vector<char> > &board)
{
    vector <vector<long long int> > dp(H,vector<long long int>(W,0));
    dp[0][0]=1;
    for(int i=1;i<W;i++)
    {
        if(board[0][i]=='.')
        dp[0][i] = dp[0][i-1];
        else
        dp[0][i] = 0;
    }
    for(int i=1;i<H;i++)
    {
        if(board[i][0]=='.')
        dp[i][0] = dp[i-1][0];
        else
        dp[i][0] = 0;
    }
    for(int i=1;i<H;i++)
    {
        for(int j=1;j<W;j++)
        {
            if(board[i][j]=='#')
            {
                dp[i][j]=0;
            }
            else
            {
                dp[i][j] = (dp[i-1][j]%mod + dp[i][j-1]%mod)%mod;
            }
        }
    }
    return dp[H-1][W-1]%mod;
}
int main()
{
    int H,W;
    cin>>H>>W;
    vector <vector<char> > board(H,vector<char>(W));
    for(int i=0;i<H;i++)
    {
        for(int j=0;j<W;j++)
        {
            char c;
            cin>>c;
            board[i][j]= c;
        }
    }
    long long int ans = solve(H,W,board);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12132
n, k, q = list(map(int, input().split()))
answer = [0 for i in range(n)]
 
for i in range(q):
  answer[int(input()) - 1] += 1
  
for i in range(n):
  if q - answer[i] < k:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 4748
N = int(input())
ac, re, wa, tle = 0,0,0,0
for i in range(N):
  line = input()
  if line == "AC":
    ac += 1
  elif line == "TLE":
    tle += 1
  elif line == "WA":
    wa += 1
  elif line == "RE":
    re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 9140
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    N, K, Q = map(int, input().split())
    A = []
    points = []
    for _ in range(N):
        points.append(0)

    for _ in range(Q):
        winner = int(input())
        points[winner-1] += 1
    
    for i in points:
        if i > Q - K:
            print("Yes")
        else:
            print("No")

    


if __name__ == '__main__':
    main()

Measured memory_bytes: 21648
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

h,w = iim()
l = [['.']*(w+2)]
for i in range(h):
    l.append(list('.'+input()+'.'))
l.append(['.']*(w+2))
'''
for i in l:
    print(i)
'''
for row in range(1,h+1):
    for col in range(1,w+1):
        if l[row][col] != '#':
            li = [l[row-1][col-1],l[row-1][col],l[row-1][col+1],l[row][col-1],l[row][col+1],l[row+1][col-1],l[row+1][col],l[row+1][col+1]]
            l[row][col] = li.count('#')

for i in range(1,h+1):
    print(''.join(map(str,l[i][1:w+1])))

Measured memory_bytes: 3064
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)

AB = []
for a in A:
  for b in B:
    AB.append(a + b)

AB.sort(reverse=True)
AB = AB[:min(3001, X * Y * Z + 1)]
ABC = []
for c in C:
  for ab in AB:
    ABC.append(ab + c)
ABC.sort(reverse=True)

for i in range(K):
  print(ABC[i])


Measured memory_bytes: 161392
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    ostringstream os;
    while(1){
        string num;
        int sum = 0;
        getline(cin, num);
        if(num == "0")
            break;
        REP(i, num.size()){
            sum += (num[i] - '0');
        }
        os << sum << endl;
    }
    cout << os.str();
    return 0;
}

Measured memory_bytes: 1204
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
		int t =0;
		Scanner sc = new Scanner(System.in);
		while(true){
			int x =sc.nextInt();
			if(x == 0) break;
			t++;
			System.out.println("Case "+ t + ": " + x );
		}
        
        
	}
}

Measured memory_bytes: 32976
#include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;

int main(){
    char ch;
    int list[26] = {};
    
    while(cin >> ch){
        ch = tolower(ch);
        if (isalpha(ch)){
            list[ch-'a']++;
        }
    }

    for (int i = 0; i < 26; i++){
        printf("%c : %d\n", i+'a', list[i]);
    }

}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
const int MOD = 1000000007;
const int MAX = 1000010;
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;
}

void prime_decomposition(ll n, map<ll, ll>& mp){
  ll a = 2;
  while(n > 1){
    if(a*a > n){
      mp[n]++;
      return;
    }
    if(n%a == 0){
      while(n%a == 0){
        mp[a]++;
        n /= a;
      }
      a = 2;
    }else{
      a++;
    }
  }
}

int main() {
  ll n,m; cin >> n >> m;
  if(m==1){
    cout << 1 << endl;
    return 0;
  }

  map<ll, ll> mp;
  prime_decomposition(m, mp);
  // FOREACH(x,mp){
  //   cout << "prime = " << x.first << ", exp = " << x.second << endl; 
  // }
  COMinit();
  ll ans = 1;
  FOREACH(x,mp){
    ll e = x.second;
    (ans *= COM(e+n-1, e)) %= MOD; 
  }
  cout << ans << endl;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf =1 << 30;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int h, w; cin >> h >> w;
    vector<string> f(h);
    int wcnt = 0;
    for(auto& l : f) { cin >> l; for(auto& e : l) if(e == '.') wcnt++; }

    vector<vi> min_dist(h, vi(w, inf));
    using Elem = tuple<int, int>;
    queue<Elem> q;
    q.push(Elem(0, 0));
    min_dist[0][0] = 1;

    int res = -1;
    while(q.size()){
        int x, y; tie(x, y) = q.front(); q.pop();
        int c = min_dist[y][x];

        rep(i, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];

            if(nx < 0 or w <= nx or 
               ny < 0 or h <= ny or f[ny][nx] == '#') continue;

            if(y == h - 1 and x == w - 1){
                res = wcnt - c;
                break;
            }

            if(chmin(min_dist[ny][nx], c + 1)){
                q.push(Elem(nx, ny));
            }
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n, k =map(int,input().split())
    A = list(map(int,input().split())) + [0]
    while k > 0:
        B = [0] * (n + 1) 
        for i, a in enumerate(A):
            B[max(0, i - a)] += 1
            B[min(n, i + a + 1)]  -= 1
        if B[0] == n:
            flag = True
        for i in range(1, n+1):
            B[i] += B[i-1]
            if B[i] != n and i < n:
                flag = False
        A = B[:]
        if flag:
            break
        k -= 1
    print(" ".join(map(str, B[:-1])))

if __name__=='__main__':
    main()

Measured memory_bytes: 173796
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A=LIN(2)
    if 1 not in A:
        print(1)
    elif 2 not in A:
        print(2)
    else:
        print(3)
if __name__ == '__main__':
    main()

Measured memory_bytes: 38484
def matrixChainMultiplication(M):
    # P ??????
    n = len(M)
    P = [M[0][0]]
    P += [M[i][1] for i in range(n)]
    # ?¨???¶?????? m ??????
    m = [[[] for _ in range(n + 1)] for _ in range(n + 1)]
    for i in range(n + 1):
            m[i][i] = 0

    # l???????±???¨?????????????????°
    for l in range(2, n + 1):
        for i in range(1, n - l + 2):
            j = i + l - 1
            m[i][j] = 9999999999999999
            for k in range(i, j):
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + P[i -1] * P[k] * P[j])
    return m[1][n]


if __name__ == '__main__':
    n = int(input())
    M = [list(map(int, input().split())) for _ in range(n)]
    print(matrixChainMultiplication(M))

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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main() {

    long long int r;
    cin >> r;

    cout << fixed << setprecision(10) << 3.14159265358979L * 2 * r << endl;

    return 0;

}


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

int main()
{
  int N, K;

  cin >> N >> K;

  vector<int> p(N);

  for (int i = 0; i < N; i++)
  {
    cin >> p.at(i);
  }

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

  int sum = 0;

  for (int i = 0; i < K; i++)
  {
    sum += p.at(i);
  }

  cout << sum << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
long long sort(int a[],int n)
{
    if(n==1)return 0;
    long long sum=0;
    int mid=n/2;
    sum+=sort(a,mid);
    sum+=sort(a+mid,n-mid);
    int *b=new int[n];
    memcpy(b,a,n*4);
    for(int i1=0,i2=mid,i=0;i1<mid||i2<n;++i)
        if(i2==n)
            a[i]=b[i1++],sum+=i2-mid;
        else if(i1==mid)
            a[i]=b[i2++];
        else if(b[i1]<b[i2])
            a[i]=b[i1++],sum+=i2-mid;
        else
            a[i]=b[i2++];
    delete [] b;
    return sum;
}
long long inversed_pair(int a[],int n)
{
    long long ans=sort(a,n);
    for(long long i=0;i<n;++i)
    {
        long long j=i;
        while(a[j]==a[j+1])
            j++;
        ans-=(j-i+1)*(j-i)/2;
        i=j;
    }
    return ans;
}
long long solve(string s)
{
    int pos = 0;
    long long ret = 0;
    for(;pos<s.size();)
    {
        vector<int> arr;
        while(s[pos]=='A' || pos+1<s.size()&&s[pos]=='B'&&s[pos+1]=='C')
        {
            if(s[pos]=='A')
            {
                pos++;
                arr.push_back(2);
            }else
            {
                pos+=2;
                arr.push_back(1);
            }
        }
        if(arr.size())
        {
            arr.push_back(-1);
            ret += inversed_pair(&arr[0],arr.size()-1);
        }else
        {
            pos++;
        }
    }
    return ret;
}
int main()
{
    string s;
    cin>>s;
    cout<<solve(s)<<endl;
}

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

typedef long long ll;

void couting_sort(const vector<int> &a,vector<int> &b,int k){
    vector<int> cou(k,0);
    for(int i=0;i<a.size();i++)cou[a[i]]++;
    for(int i=1;i<k;i++)cou[i]+=cou[i-1];
    for(int i=a.size()-1;i>=0;i--){
        b[cou[a[i]]-1]=a[i];
        cou[a[i]]--;
    }
}

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

    int n,ma=0;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        ma=max(ma,a[i]);
    }
    couting_sort(a,b,ma+1);
    for(int i=0;i<b.size();i++)cout << b[i] <<(i!=b.size()-1?" ":"\n");
}



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

using namespace std;

long long dp[100005][2];
vector<int> graph[100005];
long long MOD = 1000000007;

void dfs(int n, int p){
    dp[n][0] = dp[n][1] = 1;
    for(int e : graph[n]){
        if(e != p){
            dfs(e, n);
            dp[n][0] = (dp[n][0]*(dp[e][0]+dp[e][1])%MOD)%MOD;
            dp[n][1] = (dp[n][1]*dp[e][0])%MOD;
        }
    }
}

int main(){
    int N;
    cin >> N;
    for(int i = 1; i<N; i++){
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(1, 0);
    cout << (dp[1][0] + dp[1][1])%MOD << endl;
}


Measured memory_bytes: 12800
using System;
using System.IO;

namespace Contest
{
    class Program
    {
        public void Solve()
        {
            var sc = new Scanner();
            Console.WriteLine(180 * (sc.NextInt()-2));
        }




        static void Main() => new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
        _separator = ' ';
    }
    private char _separator;
    private StreamReader _stream;
    private int _pos;
    private string[] _line;
    #region get a element
    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(_separator);
            _pos = 0;
        }
        return _line[_pos++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    #endregion
    #region convert array
    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }
    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }
    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }
    #endregion
    #region get array
    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(_separator);
        _pos = _line.Length;
        return _line;
    }
    public int[] IntArray()
    {
        return ToIntArray(Array());
    }
    public long[] LongArray()
    {
        return ToLongArray(Array());
    }
    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }
    #endregion
}

Measured memory_bytes: 11092
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <deque>
#define ll long long

using namespace std;

int n, q;
vector<int> A;

bool solve(int left, int weight) {
	if (weight == 0) {
		return true;
	}
	else {
		if (left == n || weight < 0) {
			return false;
		}
		return 
			solve(left + 1, weight)
			|| solve(left + 1, weight - A[left]);
	}
}

int main() {
	cin >> n;
	A.assign(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	cin >> q;
	for (int i = 0; i < q; i++) {
		int qry; cin >> qry;
		if (solve(0, qry)) {
			cout << "yes" << endl;
		}
		else cout << "no" << endl;
	}

	return 0;
}





Measured memory_bytes: 3164
if ARGV[0]=="LOCAL_DEV"
  define_method("debug") do |var|
    p var
  end
else
  define_method("debug") do |var|
  end
end

S = STDIN.gets.strip

if S =~ /^(dream|dreamer|erase|eraser)+$/
  puts 'YES'
else
  puts 'NO'
end




Measured memory_bytes: 3964
import sys

n=int(input())
A=list(map(int,input().split()))
p=10**9+7

status=[1,0,0]
ans=3

if A[0]!=0:
    print(0)
    sys.exit()

for i in range(1,n):
    count=status.count(A[i])
    if count==0:
        print(0)
        sys.exit()
    
    ans=(ans*count)%p
    status[status.index(A[i])]+=1

print(ans)

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


int main() {
    int N;
    cin >> N;
    vector<ll> S(N);
    for (int i = 0; i < N; i++) cin >> S[i];
    
    ll ans = 0;
    for (int i = 1; i <= N-2; i++) {
        set<int> st;
        st.insert(0);
        st.insert(N-1);
        int l = 0, r = N-1;
        ll cand = 0;
        while (l < N-1) {
            l += i;
            r -= i;
            if (r <= i) break;
            if (l >= N-1 || r <= 0) break;
            if (st.find(l) != st.end()) break;
            st.insert(l);
            if (st.find(r) != st.end()) break;
            st.insert(r);
            cand += S[l];
            cand += S[r];
            ans = max(ans, cand);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8812
n,x = map(int, input().split())
city = []
sub = []
city = list(map(int, input().split()))

for i in range(len(city)):
	sub.append(abs(x - city[i]))

def gcd(a,b):
	if b == 0:
		return a
	return gcd(b, a%b)


if len(sub) == 1:
	print(sub[0])
elif len(sub) == 2:
	print(gcd(sub[0],sub[1]))
else:
	p = gcd(sub[0], sub[1])
	for i in range(2,len(sub)):
		p = gcd(p,sub[i])
	print(p)

Measured memory_bytes: 14480
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[]
for i in range(n):
    A=list(map(int,input().split()))
    a.append(A)
    A=[]
#print(a)
sum=0
ans=[]
for i in range(n):
    for j in range(m):
        sum+=a[i][j]*b[j]
    ans.append(sum)
    sum=0
#print(ans)
for i in range(len(ans)):
    ans[i]+=c
#print(ans)
c=0
for i in range(len(ans)):
    if ans[i]>0:
        c+=1
print(c)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#define Max(x,y) ((x>y)?x:y)
typedef struct card{
	int s,t,n;
}card;
card x[10500],y[10500];
int main(){
	int i,j,n,m,p,q,r,a,b,c,d;//(a,b)cut c,d:absolute point
	int xn,yn,e,f,g;//f:flag g:
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		scanf("%d%d%d%d",&m,&p,&q,&r);
		xn=1;
		x[0]=(card){1,n+1,n};
		while(m--){
			scanf("%d%d",&a,&b);
			d=n+1;c=d-x[xn-1].n;
			f=0;yn=0;
			//for(i=0;i<xn;i++)printf("(%d-%d)",x[i].s,x[i].t);
			//printf("\n");
			for(i=xn-1;i>=0;){
				//printf("c:%d  d:%d\n",c,d);
				if(f==0){
					if(c==b+1){
						for(j=i;j<xn;j++)y[yn++]=x[j];
						f=1;g=i-1;i--;
					}else if(c<b+1 && b+1<d){
						y[yn++]=(card){x[i].s+b+1-c,x[i].t,x[i].t-x[i].s-b-1+c};
						for(j=i+1;j<xn;j++)y[yn++]=x[j];
						x[i]=(card){x[i].s,x[i].s+b+1-c,b+1-c};
						//for(j=0;j<=i;j++)printf("(%d-%d)",x[j].s,x[j].t);
						//printf("\n");
						f=1;g=i;d=c+x[i].n;
						continue;
					}else i--;
				}else{
					if(c==a+1){
						for(j=i;j<=g;j++)y[yn++]=x[j];
						for(j=0;j<i;j++)y[yn++]=x[j];
						break;
					}else if(c<a+1 && a+1<d){
						y[yn++]=(card){x[i].s+a+1-c,x[i].t,x[i].t-x[i].s-a-1+c};
						for(j=i+1;j<=g;j++)y[yn++]=x[j];
						x[i]=(card){x[i].s,x[i].s+a+1-c,a+1-c};
						for(j=0;j<=i;j++)y[yn++]=x[j];
						break;
					}else i--;
				}
				d=c;
				c=d-x[i].n;
			}
			//for(i=0;i<yn;i++)printf("(%d-%d)",y[i].s,y[i].t);
			//printf("\n");
			memcpy(x,y,sizeof(card)*yn);
			xn=yn;
		}
		//printf("\n");
		//for(i=0;i<xn;i++)printf("(%d - %d)",x[i].s,x[i].t);
		//printf("\n\n");
		a=0;b=1;
		for(i=0;i<xn;i++){
			//printf("%d ",b);
			if(p<b+x[i].n && b<=q){
				c=x[i].s;
				d=x[i].t;
				if(b<p)c+=p-b;
				if(b+x[i].n>q)d+=q-b-x[i].n+1;
				if(d>r)d=r+1;
				if(c>r)c=d+1;
				//printf("%d %d",c,d);
				
				a+=Max(0,d-c);
			}
			//printf("\n");
			b+=x[i].n;
		}
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 552
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int a[3];
    REP(i, 3)
    {
        cin >> a[i];
    }
    sort(a, a + sizeof(a) / sizeof(int));
    printf("%d %d %d\n", a[0], a[1], a[2]);
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=0,m=0,f=0;
    n=(s[2]-'0')*10 + (s[3]-'0');
    m=(s[0]-'0')*10 + (s[1]-'0');

    if(n!=0 && n<=12 && m!=0 && m<=12)
        cout<<"AMBIGUOUS"<<endl;

    else if(n!=0 && n<=12)
        cout<<"YYMM"<<endl;
    else if(m!=0 && m<=12)
        cout<<"MMYY"<<endl;
    else cout<<"NA"<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int sum;
	scanf("%d",&sum);
	for(int i=1;i<10;i++)
	{
		for(int j=1;j<10;j++)
		{
			if(i*j==sum){printf("Yes"); return 0;
			}
		}
	}
	printf("No");
	return 0;
 } 

Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int r,g,b;
int main(){
	scanf("%d%d%d",&r,&g,&b);
	if (!((g*10+b)&3)) printf("YES\n");else printf("NO\n");
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    unsigned int N;
    cin >> N;
    vector<long long> a(N);
    rep(i,N){
        cin >> a[i];
    }
    cout << accumulate(a.begin(),a.end(),0LL)-N <<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 200010, INF = 1ll << 45;
int n,q,a,b,que[N];
struct node {
  pair<int,int> lmn,rmn;
  int l,r,tag;
} t[N << 2];
void puttag(int x,int val) {
  t[x].tag += val;
  t[x].lmn.first += val;
  t[x].rmn.first += val;
}
void push_down(int x) {
  puttag(x<<1,t[x].tag);
  puttag(x<<1|1,t[x].tag);
  t[x].tag = 0;
}
void push_up(int x) {
  if (t[x].tag) push_down(x);
  t[x].lmn = min(t[x<<1].lmn,t[x<<1|1].lmn);
  t[x].rmn = min(t[x<<1].rmn,t[x<<1|1].rmn);
}
void build(int l,int r,int x) {
  t[x].l = l, t[x].r = r;
  if (l == r) {
    t[x].lmn = make_pair(l,l);
    t[x].rmn = make_pair(n-l+1,l);
    return;
  }
  int mid = (l + r) >> 1;
  build(l,mid,x<<1);
  build(mid+1,r,x<<1|1);
  push_up(x);
}
int query(int p,int x) {
  if (t[x].l == t[x].r)
    return t[x].lmn.first - t[x].l;
  if (t[x].tag) push_down(x);
  int mid = (t[x].l + t[x].r) >> 1;
  if (p <= mid) return query(p,x<<1);
  else return query(p,x<<1|1);
}
void modify(int l,int r,int x,int val) {
  if (l > t[x].r || r < t[x].l) return;
  if (t[x].l >= l && t[x].r <= r) {
    t[x].lmn.first += val;
    t[x].rmn.first += val;
    t[x].tag += val;
    return;
  }
  if (t[x].tag) push_down(x);
  modify(l,r,x<<1,val);
  modify(l,r,x<<1|1,val);
  push_up(x);
}
pair<int,int> askl(int l,int r,int x) {
  if (l > t[x].r || r < t[x].l) return make_pair(INF,0);
  if (t[x].l >= l && t[x].r <= r)
    return t[x].lmn;
  if (t[x].tag) push_down(x);
  return min(askl(l,r,x<<1),askl(l,r,x<<1|1));
}
pair<int,int> askr(int l,int r,int x) {
  if (l > t[x].r || r < t[x].l) return make_pair(INF,0);
  if (t[x].l >= l && t[x].r <= r)
    return t[x].rmn;
  if (t[x].tag) push_down(x);
  return min(askr(l,r,x<<1),askr(l,r,x<<1|1));
}
void setval(int p,int x,int val) {
  if (t[x].l == t[x].r) {
    t[x].lmn.first = val + t[x].l;
    t[x].rmn.first = val + n - t[x].l + 1;
    return;
  }
  int mid = (t[x].l + t[x].r) >> 1;
  if (t[x].tag) push_down(x);
  if (p <= mid) setval(p,x<<1,val);
  else setval(p,x<<1|1,val);
  push_up(x);
}
signed main() {
  int tmp,t;
  scanf("%lld%lld%lld%lld",&n,&q,&a,&b);
  que[0] = a;
  build(1,n,1);
  for (int i = 1 ; i <= n ; ++ i)
    setval(i,1,abs(i-b));
  for (int i = 1 ; i <= q ; ++ i) {
    scanf("%lld",&que[i]);
    tmp = askl(que[i],n,1).first - que[i];
    t = askr(1,que[i],1).first - n + que[i] - 1;
    tmp = min(tmp,t);
    modify(1,n,1,abs(que[i-1] - que[i]));
    t = query(que[i-1],1);
    tmp = min(tmp,t);
    setval(que[i-1],1,tmp);
  }
  int ans = INF;
  for (int i = 1 ; i <= n ; ++ i)
    ans = min(ans,query(i,1));
  printf("%lld\n",ans);
  return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  string s;
  cin >> s;
  vl found(26,-1);
  vl cost(26,-1);
  REP(i,s.length()){
    CHMAX(cost[s[i]-'a'],i-found[s[i]-'a']-1);
    found[s[i]-'a'] = i;
  }
  REP(i,cost.size()) CHMAX(cost[i],(ll)s.length()-found[i]-1);
  sort(cost.begin(),cost.end());
  cout << cost[0] << endl;
  return 0;
}


Measured memory_bytes: 256
h, w, d = map(int, input().split())
a_array = [[int(x) for x in input().split()] for y in range(h)]
q = int(input())
lr_array = [[int(x) for x in input().split()] for y in range(q)]

whole = []
for i in range(h):
    for j in range(w):
        whole.append([a_array[i][j], i + 1, j + 1])
whole = [[x[1], x[2]] for x in sorted(whole, key=lambda x: x[0])]
diff = [0 for x in range(h * w)]
for i in range(d, h * w):
    if diff[i] != 0:
        continue
    if i == 0:
        continue
    for j in range(i, h * w, d):
        base_x, base_y = whole[j]
        next_x, next_y = whole[j-d]
        diff[j] = diff[j-d]+abs(base_x - next_x) + abs(base_y - next_y)

for l, r in lr_array:
    print(diff[r-1]-diff[l-1])


Measured memory_bytes: 44788
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;

    int array[n];
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>array[i];
    }

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            sum+=array[i]*array[j];
        }
    }

    cout<<sum<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;


int main(){
	int a,b;
	cin >> a >> b;
	for(int i = 1; i<10*(b+1); i++){
		if((double)b <= 0.1*i && 0.1*i < (double)b+1.0
			 && (double)a <= 0.08*i && 0.08*i < (double)a+1.0){
			cout << i << endl;
			return 0;
		}
	}
	
	cout << "-1\n";
	return 0;
}

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

clock_t present = clock();
void complexiti(){
	present = clock() - present;
	cerr << "TIME : " << float(present)/CLOCKS_PER_SEC << '\n';
}

void solver(){
	//~ type your code here
	int r;
	cin >> r;
	cout << r * r * 3 << endl;
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int queries = 1;
	//~ cin >> queries;
	for(int i = 0 ; i < queries ; ++i){
		solver();
	}
	complexiti();
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder178
{
    class Program
    {
        static int[] RI()
        {
            return Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        }

        static long[] RL()
        {
            return Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
        }

        static string RS()
        {
            return Console.ReadLine();
        }

        static void W(object msg)
        {
            Console.WriteLine(msg);
        }

        static void Main(string[] args)
        {
            QB();
        }

        static void QA()
        {
            W("0".Equals(RS()) ? "1" : "0");
        }

        static void QB()
        {
            long[] num = RL();

            long ac = num[0] * num[2];
            long ad = num[0] * num[3];
            long bc = num[1] * num[2];
            long bd = num[1] * num[3];

            W(Math.Max(Math.Max(ac, ad), Math.Max(bc, bd)));
        }

        static void QC()
        {

        }

        static void QD()
        {

        }

        static void QE()
        {

        }
    }
}


Measured memory_bytes: 19020
N,A,B = [int(i) for i in input().split()]
S = list(input())

count_b = 0
count = 0
ans = ['No']*N
for j,i in enumerate(S):
    if i == 'a':
        if count < A+B:
            ans[j] = 'Yes'
            count += 1
    elif i == 'b':
        if count < A+B and count_b < B:
            ans[j] = 'Yes'
            count += 1
            count_b += 1

[print(i) for i in ans]


Measured memory_bytes: 56440
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int top,A[200];

void push(int x);
int pop();


int main(int argc,char *argv[]){
  char a[100];
  int x,y;

  top =0;
  
  while( scanf("%s",a)!=EOF){
    if(a[0]=='+'){
      x = pop();
      y = pop();
        push(x+y); 
    }

  else if(a[0]=='-'){
      y = pop();
      x = pop();
     push(x-y);
    }

   else if(a[0]=='*'){
      x = pop();
      y = pop();
      push(x*y);
    }

    else{
      push(atoi(a));
    }
  }

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

  return 0;
  
}

void push(int x){
  A[++top] = x;
}

int pop(){
  top--;
  return A[top+1] ;
}



Measured memory_bytes: 2108
import java.util.Scanner;
import java.io.*;

public class Main {
    public static void main(String[] args)throws IOException{
        int[] blood = new int[4];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String buf;
        while((buf = br.readLine())!=null){
            String b = buf.split(",")[1];
                if("A".equals(b))
                    blood[0]++;
                else if("B".equals(b))
                    blood[1]++;
                else if("AB".equals(b))
                    blood[2]++;
                else
                    blood[3]++;
        }
        for(int i =0; i<blood.length;i++){
            System.out.println(blood[i]);
        }
    }
}

Measured memory_bytes: 9336
import sys
readline = sys.stdin.readline
from collections import Counter
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    c = Counter(A)
    if N % 2 == 1:
        if c[0] != 1:
            print(0)
            return
        for i in range(2, N, 2):
            if c[i] != 2:
                print(0)
                return

    else:
        for i in range(1, N, 2):
            if c[i] != 2:
                print(0)
                return

    print(pow(2, N//2, MOD))

if __name__ == '__main__':
    main()

Measured memory_bytes: 14820
import numpy as np


def main():
    h, w, k = map(int, input().split())
    cs = np.array([list(input()) for _ in range(h)])

    ans = 0
    for paint_h in range(2 ** h):
        for paint_w in range(2 ** w):
            cnt = 0
            for j in range(h):
                for l in range(w):
                    if ((paint_h >> j) & 1) == 0 and ((paint_w >> l) & 1) == 0:
                        if cs[j][l] == '#':
                            cnt += 1
            if cnt == k:
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
  int N; cin >> N;
  string s = to_string(N);
  int ans = 0;
  for (int i = 0; i < s.size(); ++i) ans += s[i] - '0';
  cout << ( (ans == 1) ? 10 : ans ) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=510;
typedef long long ll;
const ll inf=1e18;

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,a[N][N];
ll f[N][N],s1[N][N],s2[N][N];

ll getsum(ll s[N][N],int x1,int x2,int y1,int y2) {
	return s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1];
}

int main() {
	cin>>n;n+=4;
	for(int i=3;i<=n-2;i++)
		for(int j=3;j<=n-2;j++)
			if(i!=j) a[i][j]=gi();
	memset(f,0x3f,sizeof(f)),f[1][2]=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++) {
			s1[i][j]=s1[i-1][j]+s1[i][j-1]-s1[i-1][j-1];
			if(i>j) s1[i][j]+=a[i][j];
			s2[i][j]=s2[i-1][j]+s2[i][j-1]-s2[i-1][j-1];
			if(i<j) s2[i][j]+=a[i][j];
		}
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++) {
			if(f[i][j]>=inf) continue;
			for(int k=j+1;k<=n;k++) {
				f[j][k]=min(f[j][k],f[i][j]+getsum(s1,k+1,n,i+1,j)+getsum(s2,j+1,k,j+1,k));
			}
		}
	cout<<f[n-1][n];
	return 0;
}


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

#define ll long long

using namespace std;

const int mod = (int)1e9 + 7;

int a[22][22];
int n;
int musk[22];
int dp[1 << 21];
int bt[1 << 21];

int add(int a, int b) {
	return (a + b) % mod;
}

int go(int mask) {
	if (mask == 0) return 1;
	int &res = dp[mask];
	if (res != -1) return res;
	int qwe = n - __builtin_popcount(mask);
	int asd = mask & musk[qwe];
	res = 0;
	while (asd > 0) {
		int bit = bt[asd & -asd];
		res = add(res, go(mask ^ (1 << bit)));
		asd -= (1 << bit);
	}
	return res;
}

main() {
	memset(dp, -1, sizeof dp);
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int res = 0;
		for (int j = 0, x; j < n; j++) {
			scanf("%d", &x);
			res += (x << j);
		}
		musk[i] = res;
	}
	for (int i = 0; i < n; i++) {
		bt[1 << i] = i;
	}
	printf("%d", go((1 << n) - 1));
}


Measured memory_bytes: 12544