akhauriyash/Code-Regression huggingface dataset:
/**
 *     author: qodjf
 *     created: 04.21.2020 21:54:50
 */
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

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

  int N, P;
  string s;
  cin >> N >> P;
  cin >> s;

  ll ans = 0;
  if (P == 2 || P == 5) {
    for (int i = 0; i < N; i++) {
      if ((s[i] - '0') % P == 0) {
        ans += i + 1;
      }
    }
  } else {
    vector<int> dp(N + 1, 0);
    int x = 1;
    for (int i = N - 1; i >= 0; i--) {
      dp[i] = ((s[i] - '0') * x + dp[i + 1]) % P;
      x = (x * 10) % P;
    }
    vector<int> cnt(P, 0);
    for (int i = 0; i <= N; i++) {
      ans += cnt[dp[i]];
      cnt[dp[i]]++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1428
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
    _LL n, m;
    cin >> n >> m;
    vector<_LL> *r = new vector<_LL>[n];
    double *dp = new double[n];
    double *p = new double[n];
    rep(i, m)
    {
        _LL s, t;
        cin >> s >> t;
        s--; t--;
        r[s].push_back(t);
    }
    rep(j, n)
    {
        _LL k = n - 1 - j;
        dp[k] = 0;
        if( j > 0 ) 
        {
            _LL rnum = r[k].size();
            double sum = 0;
            vecrep(itr, r[k])
            {
                sum += dp[*itr];
            }
            dp[k] = sum / rnum + 1;
        }
    }

    rep(k, n) p[k] = 0;
    p[0] = 1;
    double bestdiff = 0;
    rep(k, n)
    {
        double worst = 0;
        double sum = 0;
        _LL rnum = r[k].size();
        vecrep(itr, r[k])
        {
            worst = max(worst, dp[*itr]);
            sum += dp[*itr];
            p[*itr] += p[k] / rnum;
        }
        if( rnum > 1 )
        {    
            double diff = (sum / rnum - (sum - worst) / (rnum - 1));
            bestdiff = max( p[k] * diff, bestdiff);
        }
    }
    cout << std::setprecision(15) << dp[0] - bestdiff << endl;
}

Measured memory_bytes: 6080
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a=0,b=0,c=0;
    scanf("%d%d%d",&a,&b,&c);
    if(a==5&&b==5&&c==7||a==5&&b==7&&c==5||a==7&&b==5&&c==5)
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;


class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        Reader.ReadLine();
        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

        Console.WriteLine(inpt.Min() + " " + inpt.Max() + " " + inpt.Sum());
    
    }




    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


5
10 1 5 4 17

";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 10604
#include<bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 10001
#define PI 3.1415926535897932384
#define F first
#define S second
#define elasped_time    1.0 * clock() / CLOCKS_PER_SEC
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
  
// Function to find postorder traversal. 

  
// Driver code 
int main() 
{ 
   
    
ll n,d;
cin>>n>>d;
ll ans=0;
fr(n){
    ll x,y;
    cin>>x>>y;
    if(sqrt(x*x+y*y)<=d) ans++;
}
cout<<ans;

    return 0; 
} 

Measured memory_bytes: 3672
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main() {
	char x[10][10];
	int a;
	for(int i=1;i<=3;i++){
		cin>>x[i];
	}
	cout<<x[1][0]<<x[2][1]<<x[3][2]<<endl;
}

Measured memory_bytes: 256
n = gets.to_i
h = gets.chomp.split.map(&:to_i)
res = 0
while h.max > 0
  l = 0
  while h[l] == 0
    l += 1
  end

  r = l
  s = h[l]
  while r < n - 1 && h[r + 1] > 0
    r += 1
    s = h[r] if h[r] < s
  end
  res += s
  l.step(r) do |i|
    h[i] -= s
  end
end
puts res

Measured memory_bytes: 14204
class SegTree(object):
    """docstring for SegTree."""
    def __init__(self, l, _n):
        n = 1
        while n<_n:
            n *= 2
        self.n = n
        self.dat = [0 for _ in range(2*n)]
        for i in range(_n):
            self.dat[i+n-1] |= 1<<l[i]
        self.init(0)

    def init(self, i):
        if i>=self.n-1:
            return self.dat[i]
        self.dat[i] = self.init(self.left(i)) | self.init(self.right(i))
        return self.dat[i]

    def par(self, i):
        return (i-1)//2

    def left(self, i):
        return 2*i+1

    def right(self, i):
        return 2*i+2

    def update(self, i, x):
        i += self.n-1
        self.dat[i] = 1<<x
        while i>0:
            i = self.par(i)
            self.dat[i] = self.dat[self.left(i)] | self.dat[self.right(i)]

    def q(self,a,b,k,l,r):
        if r<=a or b<=l:
            return 0
        if a<=l and r<=b:
            return self.dat[k]
        return self.q(a,b,self.left(k),l,(l+r)//2) | self.q(a,b,self.right(k),(l+r)//2,r)

    def query(self,a,b):
        return self.q(a,b,0,0,self.n)

n = int(input())
s = [ord(c)-ord("a") for c in input()]
q = int(input())
ql = [input().split() for _ in range(q)]

seg = SegTree(s,n)

for i in range(q):
    if ql[i][0]=="1":
        seg.update(int(ql[i][1])-1, ord(ql[i][2])-ord("a"))
    else:
        r = seg.query(int(ql[i][1])-1, int(ql[i][2]))
        print(bin(r).count("1"))

Measured memory_bytes: 52900
#include<stdio.h>

int main(){
  int i,n,v,minv,maxv;
  
  scanf("%d%d%d",&n,&minv,&v);
  maxv = v-minv;
  if(minv > v) minv = v;
   
  for(i=2;i<n;i++){
    scanf("%d",&v);
    if(maxv < (v-minv)) maxv = v-minv;
    if(minv > v) minv = v;
  }

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

  

  return 0;
}



Measured memory_bytes: 2144
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;




int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<int> a(n*3);
    int i;
    for(i=0; i<n*3; i++) {
        scanf("%d", &a[i]);
    }
    sort( a.rbegin(), a.rend());

    ll sum=0;
    for(i=1; i<n*2; i+=2) {
        sum += a[i];
    }
    printf("%lld\n", sum);
    
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

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

signed main(){
	int N;
	cin>>N;
	int ans=0;
	for(int k=1;k*k<N;k++){
		if((N-k)%k)continue;
		int m=(N-k)/k;
		if(k>=m)continue;
		ans+=m;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
pr=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
l=[0]*15
for i in range(1,N+1):
    for j in range(15):
        while 1:
            if i%pr[j]==0:
                i//=pr[j]
                l[j]+=1
            else:
                break
a,b,c,d,e=0,0,0,0,0
for i in l:
    if i>=2:
        a+=1
    if i>=4:
        b+=1
    if i>=14:
        c+=1
    if i>=24:
        d+=1
    if i>=74:
        e+=1
print((a-2)*b*(b-1)//2+c*(b-1)+d*(a-1)+e)

Measured memory_bytes: 3064
/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-04-19 20:43:14
 * @LastEditTime: 2020-04-19 20:46:28
 * @FilePath: \VSC\C++\Practice\AC abc163 A.cpp
 */
#include<bits/stdc++.h>
using namespace std;
#define Pi 3.14159265358979323846

signed main(){
    long double R;
    cin>>R;
    cout<<Pi*R*2<<'\n';

    return 0;
}

Measured memory_bytes: 3816
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
using namespace std;
int main(void) {
  char c;
  cin >> c;
  if (c == 'A')
    cout << 'T';
  if (c == 'T')
    cout << "A";
  if (c == 'G')
    cout << "C";
  if (c == 'C')
    cout << "G";
  cout << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

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

int main()
{
    int x, y, z;
    cin >> x >> y >> z;

    cout << (x - z) / (y + z) << endl;
    return 0;
}


Measured memory_bytes: 3628
L,A,B,M=map(int,input().split())
MOD=M

#n*n行列の積を繰り返し二乗法で求める
#単位行列
def imat(n):
  ret=[[1 if i==j else 0 for j in range(n)] for i in range(n)]
  return ret

#行列の積A*B
def prod_mat(amat,bmat):
  res_mat = [[sum([amat[i][j]*bmat[j][k] for j in range(len(bmat))]) for k in range(len(bmat[0]))] for i in range(len(amat))]
  return res_mat  

def powmod_mat(amat,p):
  if p==0:
    return imat(len(amat))
  else:
    pow2=powmod_mat(amat,p//2)
    if p%2==0:
      res_mat=prod_mat(pow2,pow2)
    else:
      res_mat=prod_mat(amat,prod_mat(pow2,pow2))

    for i in range(len(amat)):
      for j in range(len(amat)):
        res_mat[i][j]%=MOD
    return res_mat

slist=[]
for d in range(1,19):
  s=-(-(10**d-A)//B)
  if s>=0:
    slist.append(min(s,L))
  else:
    slist.append(0)
#print(slist)

dlist=[slist[0]]
for d in range(1,18):
  dlist.append(slist[d]-slist[d-1])
#print(dlist)

mat=imat(3)
for d in range(18):
  e=dlist[d]
  pmat=powmod_mat([[10**(d+1),1,0],[0,1,B],[0,0,1]],e)
  mat=prod_mat(pmat,mat)
  for i in range(3):
    for j in range(3):
      mat[i][j]%=MOD

#init
vec=[[0],[A],[1]]
vec=prod_mat(mat,vec)
print(vec[0][0]%MOD)

Measured memory_bytes: 3192
k,n=map(int,input().split())
spotlist=list(map(int,input().split()))
roadlist=[]
for i in range(n-1):
  roadlist.append(spotlist[i+1]-spotlist[i])
#print(roadlist)
roadlist.append(spotlist[0]+k-spotlist[n-1])
#print(roadlist)
print(sum(roadlist)-max(roadlist))

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

#define pb push_back
#define S second
#define F first
#define sz size()
#define eps 0.000001
#define oo 2000000007
#define endl '\n'
#define bg begin()
#define nd end()
#define up upper_bound
#define lw lower_bound
#define debug(x) #x << " = " << x << "; "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MAX = 100001;
vector<int> g[MAX];
int dp[MAX];

int f(int u){
	int &ans = dp[u];
	if(dp[u] != -1) return dp[u];
	ans = 0;
	for(auto &v: g[u]){
		ans = max(ans, f(v) + 1);
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,u,v;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> u >> v;
		u--; v--;
		g[u].pb(v);
	}
	int ans = 0;
	memset(dp, -1, sizeof(dp));
	for(int i = 0; i < n; i++){
		ans = max(ans, f(i));
	}
	cout << ans << endl;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef pair<int, int> pii;

double EPS = 1e-9;

int n;
double x[110], y[110], z[110], r[110];

double pow2(double x) { return x * x; }
double dist(double x1, double y1, double z1, double x2, double y2, double z2) {
	return sqrt( pow2(x1 - x2) + pow2(y1 - y2) + pow2(z1 - z2) );
}

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	
	bool sameSet(int x, int y) { return root(x) == root(y); }
	
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	
	int size(int x) { return -data[root(x)]; }
};

struct Edge {
	int f, t; double c;
	Edge(int _f, int _t, double _c) : f(_f), t(_t), c(_c) {}
};
bool operator < (const Edge& a, const Edge& b) { return a.c + EPS < b.c; }

void solve() {
	vector<Edge> edges;
	
	for_(i,0,n) for_(j,i + 1,n) {
		double d = dist(x[i], y[i], z[i], x[j], y[j], z[j]);
		edges.push_back( Edge(i, j, max(0.0, d - r[i] - r[j])) );
	}
	
	sort(allof(edges));
	
	UnionFind uf(n);
	double ans = 0.0;
	int e_size = size_of(edges);
	
	for_(i,0,e_size) {
		Edge e = edges[i];
		if (!uf.sameSet(e.f, e.t)) {
			uf.unionSet(e.f, e.t);
			ans += e.c;
		}
	}
	
	printf("%.3lf\n", ans);
}

int main() {
	while (cin >> n, n) {
		for_(i,0,n) cin >> x[i] >> y[i] >> z[i] >> r[i];
		solve();
	}
	return 0;
}

Measured memory_bytes: 1384
// AOJ 2284: The Legendary Sword
// 2017.12.9

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ABS(a) ((a)>=0?(a):-(a))
#define N 1200
int rpos[3000][N], cpos[3000][N];
int len[3000];
int dp[2][3000];
char buf[500], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int w, h, r, c, i, j, k, n, gr, gc, k1, k2, x;

	while (fgets(p=buf, 10, stdin) && *p != '0') {
		w = getint(), p++, h = getint();
		memset(len, 0, sizeof(len));

		for (n = 0, r = 0; r < h; r++) {
			fgets(p=buf, 500, stdin);
			for (c = 0; c < w; c++, p+=2) {
				if (*p == '.') ;
				else if (*p == 'S') rpos[0][0] = r, cpos[0][0] = c, len[0] = 1;
				else if (*p == 'G') gr = r, gc = c;
				else {
					i = getint(), p--;
					if (i > n) n = i;
					k = len[i]++, rpos[i][k] = r, cpos[i][k] = c;
				}
			}
		}
		rpos[++n][0] = gr, cpos[n][0] = gc;
		len[n++] = 1;

		dp[0][0] = 0;
		for (k1 = 0, k2 = 1, i = 1; i < n; i++, k1 = k2, k2 = !k2) {
			memset(dp[k2], 0x33, sizeof(int)*len[i]);
			for (j = 0; j < len[i-1]; j++) for (k = 0; k < len[i]; k++) {
				x = ABS(rpos[i-1][j]-rpos[i][k]) + ABS(cpos[i-1][j]-cpos[i][k]);
				if (x + dp[k1][j] < dp[k2][k]) dp[k2][k] = x + dp[k1][j];
			}
		}
		printf("%d\n", dp[k1][0]);
	}
	return 0;
}

Measured memory_bytes: 21712
n, q = map(int, input().split())
s = list(input())

cnt = [0] * n
for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        cnt[i] = 1

for i in range(n - 2):
    cnt[i + 1] += cnt[i]

for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    print(cnt[r - 1] - cnt[l - 1])

Measured memory_bytes: 56440
import heapq as hq

T = int(input())
for _ in range(T):
    N = int(input())
    Cp = []
    Cn = []
    ans = 0
    for _ in range(N):
        K, L, R = map(int, input().split())
        D = L-R
        if D>=0:
            ans += R
            Cp.append((K,D))
        else:
            ans += L
            Cn.append((N-K,-D))

    Cp = sorted(Cp, reverse=True)
    Cn = sorted(Cn, reverse=True)
    Np = len(Cp)
    Nn = len(Cn)

    i = 0
    h = []
    for n in range(Np, 0, -1):
        while i<Np:
            k, d = Cp[i]
            if k<n: break
            hq.heappush(h, -d)
            i+=1

        if len(h): ans += -hq.heappop(h)

    i = 0
    h = []
    for n in range(Nn, 0, -1):
        while i<Nn:
            k, d = Cn[i]
            if k<n: break
            hq.heappush(h, -d)
            i+=1

        if len(h): ans += -hq.heappop(h)

    print(ans)


Measured memory_bytes: 37492
a,b=map(int,input().split())
print(2*max(a,b)-1 if a!=b else 2*a)
        
    
    
    
        
        
    
    
    
    
        

        
   
    
    
    
        
        
    
    
    
    
        

      
    
    
        
        
    
    
    
    
        


Measured memory_bytes: 9152
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

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

long long INF = 1LL<<60;
int main(){
    string s;
    cin>>s;
    ll q;
    cin>>q;
    bool state=false;
    string buff,bufb;
    rep(j,q){
        ll t;
        cin>>t;
        if(t==1){
            state^=true;
        }
        else if(t==2){
            int tmp;
            string c;
            cin>>tmp>>c;
            if(tmp==1){
                if(state==false)buff+=c;
                else bufb+=c;
            }
            else if(tmp==2){
                if(state==false)bufb+=c;
                else buff+=c;
            }
        }
    }
        if(state==false){
        reverse(buff.begin(),buff.end());
        cout<<buff<<s<<bufb<<endl;
        }
        else if(state){
        reverse(bufb.begin(),bufb.end());
        reverse(s.begin(),s.end());
        cout<<bufb<<s<<buff<<endl;
        }
    return 0;
}




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

using namespace std;
typedef long long ll;
int inf = (int)1e9 + 7;
ll linf = (ll)1e18 + 7;
ll mod = (ll)1e9 + 7;
ll base = (ll)1e9 + 7;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, a, b;
    cin >> n >> a >> b;
    bool awin = 0;
    if ((b - a) % 2 == 0)
        awin = 1;
    if (awin)
        cout << "Alice";
    else
        cout << "Borys";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		int feld = x * y;
		int round = 2 * x + 2 * y;
		System.out.print(feld + " ");
		System.out.println(round);
	}
}


Measured memory_bytes: 26020
N, A, B = map(int, input().split())
if A != 0:
    if A + B <= N:
        r = N // (A + B)
        m = N % (A + B)
        print(A * r + (A if A <= m else m))
    elif A > N:
        print(N)
    else:
        print(A)
else:
    print(0)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
ll power(ll a,ll n,ll modu = 1e9+7){
  ll res = 1,r = a;
  for (; n > 0;n>>=1,r*=r,r%=modu) res *= (n & 1? r:1),res%=modu;
  return res;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,k;
  cin >> n >> m >> k;
  ll facl = 1;
  FOR(i,1,n*m-2+1){
    facl *= i;
    facl %= MOD;
  }
  ll facr = 1;
  FOR(i,1,k-2+1){
    facr *= i;
    facr %= MOD;
  }
  FOR(i,1,n*m-k+1){
    facr *= i;
    facr %= MOD;
  }
  facr = power(facr,MOD-2);
  facl *= facr;
  facl %= MOD;
  ll sum = 0;
  REP(i,n){
    sum += (n-i)*m%MOD*m*i;
    sum %= MOD;
  }
  //cout << sum <<endl;
  FOR(i,1,m){
    sum += (m-i)*n%MOD*n*i;
    sum %= MOD;
  }
  //cout << sum << endl;
  cout << sum * facl%MOD << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
    int z;
    if(b==0){
        z=1;
        z%=c;
        return z;
    }
    if(b==1){
        z=a;
        z%=c;
        return z;
    }
    else{
        return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
    }
}
 
int main(){
  int n,m;
  cin>>n>>m;
  int vec[n];
  int vecb[n];
  for(int i=0;i<n;i++){
    vec[i]=0;
    vecb[i]=0;
  }
  int p;
  string q;
  int ac=0,wa=0;
  for(int i=0;i<m;i++){
    cin>>p>>q;
    if(vec[p-1]==0){
      if(q=="AC"){
        ac++;
        vec[p-1]=1;
        wa+=vecb[p-1];
      }
      if(q=="WA"){
        vecb[p-1]++;
      }
    }
  }
  cout<<ac<<" "<<wa<<endl;
}


Measured memory_bytes: 1024
s = input()
cnt = 0
ans = 0
flag = False
for i in range(len(s) - 1):
    if flag:
        flag = False
        continue
    if s[i: i + 2] == 'BC':
        ans += cnt
        flag = True
    elif s[i] == 'A':
        cnt += 1
    else:
        cnt = 0
print(ans)

Measured memory_bytes: 3500
n = int(input())
s = input()

ans = float('inf')
w_left = [0]
e_right = [0]*n

for i in range(1,n):
  if s[i-1] == 'W':
    w_left.append(w_left[i-1]+1)
  else :
    w_left.append(w_left[i-1])
      
for i in range(1,n):
  if s[n-i] == 'E':
    e_right[n-i-1] = e_right[n-i]+1
  else :
    e_right[n-i-1] = e_right[n-i]

for i in range(n):
    ans = min(ans , w_left[i]+e_right[i])
print(ans)


Measured memory_bytes: 17872
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    YORN((a == 7 && b == c && b == 5) ||
    (b == 7 && a == c && a == 5) ||
    (c == 7 && a == b && a == 5));
    return 0;
}

Measured memory_bytes: 3536
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;
using LL = long long;


int main() {
	int n, c, k;
	cin >> n >> c >> k;
	vector<int> T;
	int t;
	for (int i = 0; i < n; i++) {
		cin >> t;
		T.emplace_back(t);
	}
	sort(T.begin(), T.end());
	int ans = 0;
	int count = 0;
	int firstpeople = 0;
	if (c == 1) {
		cout << n << endl;
	}
	else {
		for (int i = 0; i < n; i++) {
			if (count == 0) {
				ans++;
				count++;
				firstpeople = T[i];
			}
			if (T[i] <= firstpeople + k&&count < c) {
				count++;
			}
			else {
				ans++;
				count = 1;
				firstpeople = T[i];
			}
		}
		cout << ans << endl;
	}
}

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

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    void Calc()
    {
        cin = new Scanner();

        int n = cin.nextInt();

        if (n <= 999)
        {
            Console.WriteLine("ABC");
            return;
        }

        Console.WriteLine("ABD");
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

// a * x + b = a2 * x + b2
// x = (b2 - b) / (a - a2)

// ax+b
struct Line {
    ll a, b;
    ll value(ll x) {
        return a * x + b;
    }
    pair<ll,ll> inter(const Line& he) const {
        ll one = he.b - b;
        ll two = a - he.a;
        if(two < 0) {
            one *= -1;
            two *= -1;
        }
        assert(two > 0);
        return {one, two};
    }
};

ll square(ll a) {
    return a * a;
}

int main() {
    int n;
    scanf("%d", &n);
    ll C;
    scanf("%lld", &C);
    vector<int> h(n);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &h[i]);
    }
    vector<Line> lines;
    int start = 0;
    for(int i = 0; i < n; ++i) {
        
        while(start <= (int) lines.size() - 2) {
            Line A = lines[start];
            Line B = lines[start+1];
            if(A.value(h[i]) >= B.value(h[i])) {
                ++start;
            }
            else {
                break;
            }
        }
        
        ll best = 0; // dp[i]
        if(i != 0) {
            best = lines[start].value(h[i]) + square(h[i]) + C;
        }
        Line line{-2 * h[i], best + square(h[i])};
        
        while(start <= (int) lines.size() - 2) {
            Line A = lines.end()[-2];
            Line B = lines.end()[-1]; // .back()
            pair<ll,ll> one = A.inter(B);
            pair<ll,ll> two = B.inter(line);
            // one.first/one.second < two.first/two.second
            if((__int128) one.first * two.second >= (__int128) one.second * two.first) {
                lines.pop_back(); // removes B
            }
            else {
                break;
            }
        }
        lines.push_back(line);
        
        if(i == n - 1) {
            printf("%lld\n", best);
        }
    }
}


Measured memory_bytes: 7280
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define cer(x) cerr << x <<endl
#define ALL(a) (a).begin(),(a).end()
#define MOD 1e9+7
typedef long long ll;
using namespace std;

int x,y;

int main()
{
	cin >> x >> y;
	int ans = 0;
	if (x <= 3) ans += 100000 * (4 - x);
	if (y <= 3) ans += 100000 * (4 - y);
	if (x == 1 && y == 1)ans += 400000;
	co(ans);
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0;i<3;i++){
    //cout<<s.at(i)<<endl;
    if(s[i]=='7'){
      cout<<"Yes"<<endl;
      goto OUT;
    }
  }
  cout<<"No"<<endl;
  OUT:;
}

Measured memory_bytes: 3568
n=int(input())
a=list(map(int,input().split()))
l=[]
cur=0
for i in range(n):
    if i==0:
        cur+=1
        continue

    if a[i]==a[i-1]:
        cur+=1
    else:
        l.append(cur)
        cur=1

    if i==n-1:
        if a[i]==a[i-1]:
            l.append(cur)
        else:
            cur=1
            l.append(cur)
ans=0
for ll in l:
    ans+=ll//2

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	char s;
	char S[7];
	int n[200];
	int stack[100];
	
	int num = 0;
	int snum = 0;
	int i = 0,j,k;
	//Input operands and operators
	while(1){
		scanf("%c",&s);
		
		if(s == '\n')break;
		
		switch(s){
			case '+':
				n[num] = -1;
				num++;
				break;
				
			case '-':
				n[num] = -2;
				num++;
				break;
				
			case '*':
				n[num] = -3;
				num++;
				break;
				
			case ' ':
				if(i != 0){
					n[num] = atoi(S);
					num++;
					
					for(i = 0;i < 6;i++){
						S[i] = '\0';
					}
					
					i = 0;
				}
				break;
				
			default:
				S[i] = s;
				i++;
				break;
		}
	}
	
	//Do operation
	for(i = 0;i < num;i++){
		switch(n[i]){
			case -1:
				stack[snum-2] = stack[snum-2]+stack[snum-1];
				snum--;
				break;
			
			case -2:
				stack[snum-2] = stack[snum-2]-stack[snum-1];
				snum--;
				break;
				
			case -3:
				stack[snum-2] = stack[snum-2]*stack[snum-1];
				snum--;
				break;
			
			default:
				stack[snum] = n[i];
				snum++;
		}
	}
	
	//Display result
	printf("%d\n",stack[0]);
	
	return 0;
}

Measured memory_bytes: 552
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  vector<int> A(n), B(n);
  rep(i, n) cin >> A[i] >> B[i];
  bool ok = false;
  rep(i, n - 2){
    if((A[i] == B[i]) && (A[i+1] == B[i+1]) && (A[i+2] == B[i+2])){
      ok = true;
    }
  }
  if(ok){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int main()
{
	int a,b;
	cin>>a>>b;
	if(a-b<0)
	{
		cout<<0;
	}
	else
	{
		cout<<a-b;
	}
}


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

long long gcd(long long a, long long b)
{
	if (a > b) {
		a += b;
		b = a - b;
		a -= b;
	}
	if (b % a == 0) return a;
	else return gcd(b % a, a);
}

int main()
{
	int i, N;
	long long T[101];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%lld", &(T[i]));
	
	long long G = T[1], L = T[1];
	for (i = 2; i <= N; i++) {
		G = gcd(T[i], L);
		L = L / G * T[i];
	}
	
	printf("%lld\n", L);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	long N, M, K;
	cin >> N >> M >> K;
	long A[N], B[M];
	for(long i=0;i<N;i++){
		cin >> A[i];
	}
	for(long i=0;i<M;i++){
		cin >> B[i];
	}
	long sumA[N+1];
	sumA[0] = 0;
	long li = 0;
	for(int i=1;i<N+1;i++){
		sumA[i] = sumA[i-1] + A[i-1];
		if(sumA[i] > K)sumA[i] = K;
		else li = i;
	}
	long ans = li;
	long sumB = 0;
	for(long j=0;j<M;j++){
		sumB += B[j];
		if (sumB > K)break;
		while(sumB + sumA[li] > K && li > 0){
			li--;
		}
		// cout << j + li + 2 << ";" << j << ":" << li << endl;
		ans = max(ans, j + li + 1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 8280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int a[maxn],b[maxn];

int main()
{
	//IOS;
    int n;
    cin>>n;
    REP(i,n) cin>>a[i];
    REP(i,n) a[i]--;
    REP(i,n) b[a[i]]=i;
    
    int pre=-1;
    int cnt=0;
    int ans=0;
    
    REP(i,n){
        if(b[i]>pre){
            cnt++;
            pre=b[i];
        }
        else{
            ans=max(ans,cnt);
            cnt=1;
            pre=b[i];
        }
    }
    ans=max(ans,cnt);
    
    cout<<n-ans;
    
	return 0;
}


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

struct node{int to,next;}e[200010];
int g[100010],f[100010],n,hd[100010],cnt,x,y,rt,sz[100010],sb[100010],ans;
char s[100010];

void addedge(int x,int y)
{
	e[++cnt]=(node){y,hd[x]},hd[x]=cnt;
	e[++cnt]=(node){x,hd[y]},hd[y]=cnt;
}

void dfs(int x,int fa)
{
	int d=0;
	sz[x]=1,sb[x]=(s[x]=='B');
	for (int i=hd[x]; i; i=e[i].next)
		if (e[i].to!=fa) 
		{
			dfs(e[i].to,x),sz[x]+=sz[e[i].to],sb[x]+=sb[e[i].to];
			if (sz[e[i].to]!=sb[e[i].to]) d++,f[x]+=f[e[i].to]+2;
		}
	g[x]=f[x];
	for (int i=hd[x]; i; i=e[i].next)
		if (e[i].to!=fa&&sz[e[i].to]!=sb[e[i].to]) g[x]=min(g[x],g[e[i].to]+f[x]-f[e[i].to]-1);
	if ((d&1)^(s[x]=='B')) f[x]++; else g[x]++;
}

void Dfs(int x,int fa)
{
	int sf=0,d=0,mi1=1000000000,mi2=1000000000;
	for (int i=hd[x]; i; i=e[i].next) 
		if (e[i].to==fa||sz[e[i].to]!=sb[e[i].to]) sf+=f[e[i].to]+2,d++;
	for (int nw,i=hd[x]; i; i=e[i].next)
		if (e[i].to==fa||sz[e[i].to]!=sb[e[i].to]) 
		{
			nw=sf-f[e[i].to]-1+g[e[i].to]+((d&1)^(s[x]=='W'));
			if (nw<mi1) mi2=mi1,mi1=nw; else if (nw<mi2) mi2=nw;
		}
	int nw=sf+((d&1)^(s[x]=='W'));
	if (nw<mi1) mi2=mi1,mi1=nw; else if (nw<mi2) mi2=nw;
	ans=min(ans,mi1);
	for (int i=hd[x]; i; i=e[i].next)
		if (sz[e[i].to]!=sb[e[i].to]&&e[i].to!=fa)
		{
			f[x]=sf-f[e[i].to]-2+((d&1)^(s[x]=='W'));
			g[x]=((sf-f[e[i].to]-1+g[e[i].to]+((d&1)^(s[x]=='W'))==mi1)?mi2:mi1);
			g[x]=g[x]-(f[e[i].to]+2)-((d&1)^(s[x]=='W'))+((d&1)^(s[x]=='B'));
			Dfs(e[i].to,x);
		}
}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<n; i++) scanf("%d%d",&x,&y),addedge(x,y);
	scanf("%s",s+1),rt=0;
	for (int i=1; i<=n; i++) if (s[i]=='W') rt=i;
	if (!rt) return puts("0"),0;
	dfs(rt,0),ans=1000000000,Dfs(rt,0);
	return printf("%d\n",ans),0;
}

Measured memory_bytes: 11648
def resolve():
    '''
    code here
    '''
    import numpy as np
    H, W = [int(item) for item in input().split()]
    grid = [[item for item in input()] for _ in range(H)]

    temp_grid = []
    for line in grid:
        temp = [item == '#' for item in line]
        if any(temp):
            temp_grid.append(line)
            
    temp_grid = np.array(temp_grid)
    temp_grid2 = []
    for j in range(W):
        line = temp_grid[:,j]
        temp = [item == '#' for item in line]
        if any(temp):
            temp_grid2.append(line)

    
    temp_grid2 = np.array(temp_grid2)
    res = np.rot90(temp_grid2, 3)
    
    for line in res:
        print(''.join(line[::-1]))




if __name__ == "__main__":
    resolve()


Measured memory_bytes: 12552
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 3e5+15;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
const int base = 1337;
const int base1 = 1931;
ll pw[MAX+50];
ll pw1[MAX+50];
ll HASH[MAX+50];
ll HASH1[MAX+50];
void pre_power()
{
    pw[0] = 1;
    pw1[0] = 1;
    for(int i = 1; i < MAX; i++)
    {
        pw[i] = (pw[i - 1] * base) % MOD;
        pw1[i] = (pw1[i - 1] * base1) % MOD;
    }
}
ll get_hashval(string str)
{
    int len=str.length();
    ll hash_val=0;
    ll hash_val1=0;
    for(int i = 0; i < len; i++)
    {
        hash_val=((hash_val*base)+str[i])%MOD;
        HASH[i+1]=hash_val;
        hash_val1=((hash_val1*base1)+str[i])%MOD;
        HASH1[i+1]=hash_val1;
    }
    return hash_val;
}
ll SubstringHash(int l, int r)
{
    return (HASH[r] - (HASH[l - 1] * pw[r - l + 1]) % MOD + MOD) % MOD;
}
ll SubstringHash1(int l, int r)
{
    return (HASH1[r] - (HASH1[l - 1] * pw1[r - l + 1]) % MOD + MOD) % MOD;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    pre_power();
    int n;
    string s;
    cin>>n;
    cin>>s;
    ll temp=get_hashval(s);
    int l=1,r=n,ans=0;
    while(l<=r)
    {
        int mid=(l+r)>>1,f=0;
        map<int,int>mp;
        map<int,int>mp1;
        for(int i=1; i<=n-mid+1; i++)
        {
            int cur=SubstringHash(i,i+mid-1);
            int cur1=SubstringHash1(i,i+mid-1);
            //  cout<<mid<<"    "<<i<<" "<<i+mid-1<<" "<<cur<<" "<<cur1<<endl;
            if(mp[cur] && mp[cur]<i && mp1[cur1] && mp[cur1]<i)
            {
                f=1;
                break;
            }
            if(!mp[cur])
                mp[cur]=i+mid-1;
            if(!mp1[cur1])
                mp1[cur1]=i+mid-1;
        }
        if(f)
            l=mid+1,ans=mid;
        else
            r=mid-1;
    }
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 8836
#include<stdio.h>

int main(){

int buf[10],i,j,n;

for(i=0;i<10;i++){
scanf("%d",&buf[i]);
}

for(i=0;i<9;i++){
for(j=0;j<9-i;j++){

if(buf[j]<buf[j+1]){
n=buf[j];
buf[j]=buf[j+1];
buf[j+1]=n;
}


}
}

printf("%d\n",buf[0]);
printf("%d\n",buf[1]);
printf("%d\n",buf[2]);

return 0;

}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int k, s;
    cin >> k >> s;
    int cnt = 0;
    for (int i = 0; i <= k; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            if (0 <= s - i - j && s - i - j <= k)
            {
                cnt++;
            }
        }
    }
    OP(cnt);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
using namespace std;

int main(){
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int dx = x2-x1;
	int dy = y2-y1;
	int x3 = x2-dy;
	int y3 = y2+dx;
	int x4 = x3-dx;
	int y4 = y3-dy;
	
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
	return 0;
}


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

typedef long double ld;
//#define int long long   
#define PB push_back 
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int> 
#define vii vector< ii >
#define F first
#define S second 
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
ld pi= 3.14159265358979;
const int mod = 1e9+7;
const int N = 1e6+7;

void solve()
{  
	int x, n; cin>>x>>n;
	int a[n]; map <int, int> mp; 
	rep(i, 0, n){
		cin>>a[i]; mp[a[i]]=1;
	}
	int mn = INT_MAX;
	int ans=-100;
	rep(i, -100, 200){
		if(mp[i]) continue;
		if(mn > abs(x-i)){
			mn = abs(x-i);
			ans = i;
		}
	}
	cout<<ans;
}
signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //cout<<setprecision(20);
    int tc=1; //cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


ll a[3];

int main(){
	cin >> a[0] >> a[1] >> a[2];
	
	bool b = 1;
	for(int i = 0; i < 3; i++){
		if(a[i] % 2 == 0) b = 0;
	}
	sort(a, a+3);
	
	if(b) cout << a[0] * a[1] << endl;
	else cout << 0 << endl;
	
	return 0;
}

Measured memory_bytes: 256
import numpy as np

now_max = -1
prev_max = 100000000
left_max = -1
right_max = -1
right_max_index = 0

N = int(input())
A_list = [int(input()) for _ in range(N)]
np_A_list = np.array(A_list)
for i, A in enumerate(A_list):
    # 右端
    if i == len(A_list) - 1:
        print(left_max)
        break
    if right_max_index == i:
        slc = np_A_list[i + 1:]
        right_max = slc.max()
        right_max_index = len(np_A_list) - 1 - slc[::-1].argmax()

    if left_max > right_max:
        now_max = left_max
        print(left_max)
    else:
        now_max = right_max
        print(right_max)
    
    if prev_max < now_max:
        left_max = right_max = now_max
        right_max_index = 10000000
    
    prev_max = now_max
    if left_max < A:
        left_max = A


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

int main() {
  int N,M;
  cin >> N >> M;
  if(N >= M){
    for(int i = 0; i < N; i++){
      cout << M;
      if(i == N-1){
        cout << endl;
      }
    }
  }else{
    for(int i = 0; i< M; i++){
      cout << N;
      if(i == M-1){
        cout << endl;
      }
    }
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

struct edge {
    ll to;
    ll cost;
};

int N;
vector<vector<edge>> G;
vector<ll> d(150);

void dijkstra() {
    priority_queue<pll, vector<pll>, greater<pll>> que;
    que.push({0, 0});
    d.assign(N, INF);
    d[0] = 0;
    while (!que.empty()) {
        pll p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;

        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push({d[e.to], e.to});
            }
        }
    }
}

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

    cin >> N;
    G.resize(N);
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        rep(j, b) {
            ll c, d;
            cin >> c >> d;
            G[a].push_back({c, d});
        }
    }

    dijkstra();
    rep(i, N) { cout << i << " " << d[i] << endl; }
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
//const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
const double EPS = 1e-5;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int h,w;
vvector<bool> road;
int mx[]={1,0,-1,0},my[]={0,1,0,-1};
bool isin(int y,int x){
	return y>=0&&x>=0&&y<h&&x<w;
}

int most_dis(int y,int x){
	vvector<int> fast(h,vector<int>(w,INF));
	stack<pii> st;
	st.emplace(y,x);
	fast[y][x] = 0;
	while(st.size()){
		pii d  =st.top();
		st.pop();
		rep(i,4){
			pii np = pii(d.first + my[i],d.second + mx[i]);
			if(!isin(np.first,np.second))continue;
			if(road[np.first][np.second]==false)continue;
			int nt = fast[d.first][d.second] + 1;
			if(nt < fast[np.first][np.second]){
				fast[np.first][np.second] = nt;
				st.emplace(np);
			}
		}
	}	
	int res = 0;
	rep(i,h){
		rep(j,w){
			if(fast[i][j]==INF)continue;
			chmax(res,fast[i][j]);
		}
	}
	return res;
}
int main(){
	cin >> h >> w;
	road = vvector<bool>(h,vector<bool>(w,false));
	rep(i,h){
		rep(j,w){
			char d;
			cin >> d;
			road[i][j] = d == '.';
		}
	}
	int ans = 0;
	rep(i,h){
		rep(j,w){
			if(!road[i][j])continue;
			chmax(ans,most_dis(i,j));
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256