akhauriyash/Code-Regression huggingface dataset:
import sys
 
sys.setrecursionlimit(10**6)


def lake_counting(field):

  lake_count = 0

  def dfs(x,y):
    field[x][y] = 0
    dx = [-1,-1,-1,0,0,1,1,1]
    dy = [-1,0,1,-1,1,1,0,-1]
    

    for i in range(8):
        nx = x + dx[i]
        ny = y + dy[i]
        if (0 <= nx < h and 0 <= ny < w and field[nx][ny] == 1):
          dfs(nx,ny)

  for i in range(h):
    for j in range(w):
      if field[i][j] == 1:
        dfs(i,j)
        lake_count += 1

  return lake_count

while True:
  w, h = map(int,input().split())
  if w == h == 0:
    break
  A = []
  for i in range(h):
    c = list(map(int,input().split()))
    A.append(c)
  print(lake_counting(A))
  
       


Measured memory_bytes: 9160
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  ll d,n;
  cin >> d >> n;
  ll ans;
  if(n != 100){
    ans = n*pow(100,d);
    cout << ans << endl;
  } else {
    ans = (n+1)*pow(100,d);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import itertools, math
N = int(input())
ls, L = [], 0
for i in range(N):
    x, y = map(int, input().split(' '))
    ls.append([x, y])
perms = itertools.permutations(range(N))
for perm in perms:
    for i in range(N - 1):
        L += math.sqrt((ls[perm[i + 1]][0] - ls[perm[i]][0]) ** 2 + (ls[perm[i + 1]][1] - ls[perm[i]][1]) ** 2)
print(L / math.factorial(N))

Measured memory_bytes: 9048
N = input()
NS = set(N)
if len(N) == 1 or len(NS) == 1:
    print("No")
elif "N" not in N and "S" not in N or "W" not in N and "E" not in N :
    print("Yes")
elif "N" in N and "W" in N and "E" in N and "S" in N:
    print("Yes")
else:
    print("No")

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

int main()
{
    long long int a;
    char ch,s[100];

    scanf("%lld",&a);
    scanf("%s",s);

    int i,len;

    len=strlen(s);

    for(i=0; i<len; i++)
    {
        ch=s[i];

        if(ch>='A'&&ch<='Z')
        {
            s[i]=s[i]+32;

        }

    }

    if(a<3200)
    {
        printf("red\n");
    }

    else if(a>=3200)
    {

        printf("%s\n",s);


    }


    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
using namespace std;


const static int MAX = 100005;
int num[MAX];

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);

    int t1, t2;

    for(int i = 0; i < m; i++) {
        scanf("%d %d", &t1, &t2);

        if(t1 != 1 && t2 != 1) {
            num[t1]++; num[t2]++;
        }

        else if(t1 == 1) {
            num[t2]++;
        }

        else {
            num[t1]++;
        }
    }

    for(int i = 2; i <= n; i++) {
        if(num[i] % 2) {
            printf("NO");
            return 0;
        }
    }

    printf("YES");
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<VV> VVV;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int euclid(int a, int b)
{
	int temp;

	if (a < b) { temp = a; a = b; b = temp; }
	if (b < 1) return -1;

	if (a % b == 0) return b;
	return euclid(b, a % b);
}



int P, Q, N, A, cot = 0;

void dfs(int p,int q,int a,int n,int mini) {
	for (int i = mini; i*a <= A; i++) {
		if (n == N)break;
		if (((i*p - q) == 0)) {
			//cout << "N:" << n+1 << " mini:" << mini << " e:" << (i * p - q) << endl;
			cot++;
			continue;
		}

		if(i*p - q>0)dfs((i*p-q),i*q, i*a, n + 1, i);
		//cout << "N:" << n+1 << " mini:" << mini << " i:" << i <<" e:"<< (i * p - q) / e <<" "<< i * q / e<< endl;
	}
}

int main() {
	cin >> P >> Q >> A >> N;
	while (P != 0) {
		cot = 0;
		dfs(P, Q,1, 0,1);
		cout << cot << endl;
		cin >> P >> Q >> A >> N;
	}
}



Measured memory_bytes: 3080
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;
#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) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;
const int IMAX = 3000;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];
	constexpr unko() : fac(), ifac(), inv() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
		inv[0] = 1;
		rep1(i, IMAX) inv[i] = ll(ifac[i]) * fac[i - 1] % mod;
	}
} f;

int dp[3001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N, S;
	scanf("%d %d", &N, &S);

	int A[3001] = {};
	rep(i, N) {
		int a;
		scanf("%d", &a);
		A[a]++;
	}

	ll k2 = modpow(2, mod - 2);
	dp[0] = modpow(2, N);
	int s = 0;
	ll kotae1 = 0, kotae2 = 0;
	rep1(a, S) {
		if (A[a] == 1) {
			s = min(S - a, s + a);
			if (S >= a) kotae1 += dp[S - a];
			for (int j = s; j >= a; j--) {
				dp[j] = (dp[j] + dp[j - a] * k2) % mod;
			}
		}
		else if (A[a]) {
			int B[3001];
			B[0] = 1;
			rep1(b, A[a]) {
				B[b] = k2 * B[b - 1] % mod * (A[a] - b + 1) % mod * f.inv[b] % mod;
			}

			s = min(S - a, s + a * A[a]);
			if (S >= a) {
				rep1(b, A[a]) {
					if (S - a * b < 0) break;
					kotae2 += ll(dp[S - a * b]) * B[b] % mod;
				}
			}
			for (int j = s; j >= a; j--) {
				ll tmp = dp[j];
				rep1(b, A[a]) {
					if (j - a * b < 0) break;
					tmp += ll(dp[j - a * b]) * B[b] % mod;
				}
				dp[j] = tmp % mod;
			}
		}
	}

	printf("%lld\n", (kotae1 % mod * k2 + kotae2) % mod);

	Would you please return 0;
}

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

char ACGT[4] = {'A','C','G','T'};

int main(){
    string str;
    cin >> str;
    int counter = 0;
    int counter_max = 0;

    for(int i = 0;i < str.size();i++){
        bool can = false;
        for(int j = 0;j < 4;j++){
            if(str[i] == ACGT[j]){
                counter++;
                can = true;
            }
        }
        if(can == false)counter = 0;
        counter_max = max(counter,counter_max);
    }

    cout << counter_max << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = 0
    flag = True
    while flag:
        for i in range(N):
            if A[i] % 2 == 0:
                A[i] /= 2
            else:
                flag = False
                break
        else:
            count += 1
    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  map<char,string> A; 
  rep(i,0,3){
    string S;
    cin>>S;
    reverse(ALL(S));
    A['A'+i]=S;
  }
  char key='A';
  while(1){
    if(A.at(key).size()==0)
      break;
    char X=A.at(key)[A.at(key).size()-1];
    A.at(key).pop_back();
    key=X+'A'-'a';
  }
  cout<<key<<endl;
  }




Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n,k;
    scanf("%d",&n);
    scanf("%d",&k);
    int i = 1;

    while(n>0){
        if(i*2 < i+k){
            i = i*2;
            --n;
        }else{
            i = i+k;
            --n;
        }
    }
    printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define re register
#define LL long long
#define mp std::make_pair
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#pragma GCC optimize(3)
#pragma GCC optimize("-fcse-skip-blocks")
inline int read() {
	char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
const int maxn=1e5+5;
std::set<int> e[2][maxn];
std::set<int>::iterator it;
typedef std::pair<int,int> pii;
std::map<pii,int> ma[2];
int n,tot;
pii q[maxn<<1];
int fa[maxn];
inline int find(int x) {return fa[x]==x?x:fa[x]=find(fa[x]);}
inline pii get(int x,int y) {if(x<y) std::swap(x,y);return mp(x,y);}
inline void merge(int x,int y) {
	x=find(x),y=find(y);
	if(x==y) return;
	if(e[0][x].size()+e[1][x].size()<e[0][y].size()+e[1][y].size()) 
		std::swap(x,y);
	//printf("%d %d\n",x,y);
	e[0][y].erase(x);e[0][x].erase(y);
	for(it=e[0][y].begin();it!=e[0][y].end();++it) {
		int now=(*it);
		ma[0][get(now,y)]=0;ma[0][get(x,now)]=1;
		if(ma[1][get(x,now)]) q[++tot]=mp(x,now);
		e[0][x].insert(now);e[0][now].erase(y);e[0][now].insert(x);
	}
	e[1][y].erase(x);e[1][x].erase(y);
	for(it=e[1][y].begin();it!=e[1][y].end();++it) {
		int now=(*it);
		ma[1][get(y,now)]=0;ma[1][get(x,now)]=1;
		if(ma[0][get(x,now)]) q[++tot]=mp(x,now);
		e[1][x].insert(now);e[1][now].erase(y);e[1][now].insert(x);
	}
	fa[y]=x;
}
int main() {
	n=read();
	for(re int i=1;i<=n;i++) fa[i]=i;
	for(re int x,y,i=1;i<n;i++) {
		x=read(),y=read();
		e[0][x].insert(y),e[0][y].insert(x);
		if(x<y) std::swap(x,y);
		ma[0][mp(x,y)]++;
	}
	for(re int x,y,i=1;i<n;i++) {
		x=read(),y=read();
		e[1][x].insert(y),e[1][y].insert(x);
		if(x<y) std::swap(x,y);
		if(ma[0][mp(x,y)]) q[++tot]=mp(x,y);
		ma[1][mp(x,y)]++;
	}
	for(re int i=1;i<=tot;i++) merge(q[i].first,q[i].second);
	for(re int i=1;i<=n;i++) fa[i]=find(i);
	for(re int i=2;i<=n;i++) if(fa[1]!=fa[i]) {puts("NO");return 0;}
	puts("YES");return 0;
	return 0;
}


Measured memory_bytes: 63872
#include <iostream>

using namespace std;

int main() {
	int n, k;
	string s;
	cin >> n >> s >> k;
	
	for (int i = 0; i < n; ++i) {
		if (s[k - 1] != s[i])
			s[i] = '*';
	}
	
	cout << s << endl;
}

Measured memory_bytes: 256
n = int(input())

divisor_dic = {}

for i in range(1, n+1):
    while i % 2 == 0:
        if not 2 in divisor_dic:
            divisor_dic[2] = 1
        else:
            divisor_dic[2] += 1
        i //= 2
    f = 3
    while f*f <= i:
        if i % f ==0:
            if not f in divisor_dic:
                divisor_dic[f] = 1
            else:
                divisor_dic[f] += 1
        
            i //= f
        
        else:
            f += 2
    
    if i != 1:
        if not i in divisor_dic:
            divisor_dic[i] = 1
        else:
            divisor_dic[i] += 1
                
c = 1          
for v in divisor_dic.values():
    c *= (v+1)
    c %= 10**9+7

print(c)
    

Measured memory_bytes: 3064
var
f:array[0..1000]of longint;
n,t,i,j,k,x1,x2,s,min:longint;
begin
read(n,t);
for i:=0 to 1000 do
f[i]:=0;
s:=0;
min:=maxlongint;
for i:=1 to n do
begin
read(x1,x2);
inc(s,x1);
 for j:=s downto x1 do
 begin
  if f[j-x1]+100*i*x1+x2>f[j] then
  f[j]:=f[j-x1]+100*i*x1+x2;
  if (f[j]>=t) and (j<min) then
  min:=j;
 end;
 for j:=x1-1 downto 1 do
  for k:=x1-1 downto 1 do
  begin
   if f[k-1]+100*i>f[k] then
   f[k]:=f[k-1]+100*i;
   if (f[k]>=t) and (k<min) then
   min:=k;
  end;
end;
writeln(min);
end.


Measured memory_bytes: 128
// Problem : E - Knapsack 2
// Contest : Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define maxm 1e18
#define minm -1e18
#define pr pair<ll,ll>
#define mod 1000000007
 
void solve()
{
	ll n,w,ans=minm,we,va,sum_values=0,i;
	cin>>n>>w;
	// dp[i]=minimum total weight of items with total value exactly i
	vector<ll> weight(n),value(n);
	for(i=0;i<n;i++)
		cin>>weight[i]>>value[i];
	for(auto x:value)
		sum_values+=x;
	vector<ll> dp(sum_values+1,maxm);
	dp[0]=0;
	for(i=0;i<n;i++)
	{
		for(ll j=sum_values-value[i];j>=0;j--)
		{
			dp[j+value[i]]=min(dp[j+value[i]],dp[j]+weight[i]);
		}
	}
	for(i=0;i<=sum_values;i++)
	if(dp[i]<=w)
		ans=max(ans,i);
	cout<<ans<<endl;
}
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
    	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    from collections import defaultdict
    d1 = defaultdict(set)
    d2 = defaultdict(set)
    for s, t in zip(S, T):
        d1[t].add(s)
        d2[s].add(t)
    return YES if max(map(len, d1.values())) < 2 and max(map(len, d2.values())) < 2 else NO

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    print(solve(S, T))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9744
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	static boolean[] prime = new boolean[1000001];

	public static void main(String[] args) {
		ersis();
		while(true){
			int n = si();
			if(n==0) break;

			int cnt = 0;
			for (int i = 2; i <= n/2 ; i++) {
				if(!prime[i] && !prime[n-i]) cnt++;
			}
			out.println(cnt);
		}
		out.flush();
	}

	static void ersis(){
		prime[0] = prime[1] = true;
		for (int i = 0; i*i<1000000 ; i++) {
			if(!prime[i])
				for (int j = i*2; j <= 1000000 ; j+=i) {
					prime[j] = true;
				}
		}
	}

	static int si() {
		return Integer.parseInt(scan.next());
	}
}

Measured memory_bytes: 23148
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
	vector<int> num(3);
	rep(i,3) cin >> num[i];
	sort(num.begin(),num.end());
	int K; cin >> K;
	num[2] *= pow(2,K);
	cout << num[0]+num[1]+num[2] << endl;

}

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];

    /*if(n&1) {
        int a1=0, a2=0;
        for(int i=0;i<n;i++) {
            if(i&1)
                a1+=arr[i];
            else
                a2+=arr[i];
        }
        cout<<max(a1,a2);
        return 0;
    }*/

    int a1=0;
    for(int i=0;i<n;i++) {
        if(i&1)
            a1+=arr[i];
    }

    int dp[n][4];
    for(int i=0;i<n;i++) {
        dp[i][0]=-1e18;
        dp[i][1]=-1e18;
        dp[i][2]=-1e18;
        dp[i][3]=-1e18;
    }
    dp[0][0]=arr[0];
    dp[1][0]=arr[1];
    for(int i=2;i<n;i++) {
        dp[i][0]=dp[i-2][0]+arr[i];
        if(i==2&&n%2==1) {
            dp[i][1]=arr[2];
        }
        if(i>2)
            dp[i][1]=max(dp[i-2][1]+arr[i], dp[i-3][0]+arr[i]);
        if(i>3&&n%2==1) {
            dp[i][2]=max(dp[i-4][0]+arr[i], dp[i-2][2]+arr[i]);
        }
        if(i>4) {
            dp[i][3]=max(dp[i-3][1]+arr[i], dp[i-2][3]+arr[i]);
        }
    }
    int ans=a1;
    ans=max(ans,dp[n-1][0]);
    ans=max(ans,dp[n-1][1]);
    if(n&1) {
        ans=max(ans, dp[n-2][2]);
        ans=max(ans,dp[n-1][3]);
    }
    if(n>1) {
        ans=max(ans,dp[n-2][0]);
    }

    cout<<ans;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x >= y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x <= y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  i64 ans = 0;
  rep(r, 3001) rep(g, 3001) {
    int b = N - (R * r + G * g);
    if (b < 0 || b % B != 0) continue;
    ans++;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

const int nax = 1e3 + 7;
const int mod = 1e9 + 7;
vector<vector<char>> grid(nax, vector<char>(nax));
vector<vector<int>> dp(nax, vector<int>(nax, 0));


signed main() {
 
	crap;

	int h, w;
	cin >> h >> w;

	for (int i = 0; i < h; ++i){
		for (int j = 0; j < w; ++j){
			cin >> grid[i][j];
		}
	}

	for (int i = 0; i < h; ++i){
		for (int j = 0; j < w; ++j){
			if(i == 0 and j == 0)
				dp[i][j] = 1;
			else if(i == 0)
				dp[i][j] = ( grid[i][j] == '.') ? dp[i][j - 1] : 0;
			else if(j == 0)
				dp[i][j] = ( grid[i][j] == '.') ? dp[i - 1][j] : 0;
			else{
				if(grid[i][j] != '.')
					dp[i][j] = 0;
				else
					dp[i][j] = (dp[i-1][j] % mod + dp[i][j - 1] % mod) % mod;
			}
		}
	}

	cout << dp[h-1][w-1] << endl;

	return 0;
}

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

using namespace std;

long long query(vector<long long> & s, vector<long long> & t, long long x){
	long long res = 1e18;

	// last element <= to x
	auto ls = lower_bound(s.rbegin(), s.rend(), x, greater<long long>());
	if(ls != s.rend()){
		auto lt = lower_bound(t.rbegin(), t.rend(), *ls, greater<long long>());
		auto rt = lower_bound(t.begin(), t.end(), *ls);
		if(lt != t.rend()){
			res = min(res, x - (*ls) + (*ls) - (*lt));
		}
		if(rt != t.end()){
			res = min(res, x - (*ls) + (*rt) - (*ls));
		}
	}

	// first element >= to x
	auto rs = lower_bound(s.begin(), s.end(), x);
	if(rs != s.end()){
		auto lt = lower_bound(t.rbegin(), t.rend(), *rs, greater<long long>());
		auto rt = lower_bound(t.begin(), t.end(), *rs);
		if(lt != t.rend()){
			
			res = min(res, (*rs) - x + (*rs) - (*lt));
		}
		if(rt != t.end()){
			res = min(res, (*rs) - x + (*rt) - (*rs));
		}
	}
	
	return res;
}

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int a, b, q;
	cin >> a >> b >> q;
	vector<long long> s(a);
	for(int i = 0; i < a; ++i){
		cin >> s[i];
	}
	vector<long long> t(b);
	for(int i = 0; i < b; ++i){
		cin >> t[i];
	}

	while(q--){
		long long x;
		cin >> x;
		cout << min(query(s, t, x), query(t, s, x)) << endl;
	}
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll n;cin>>n;
    ll x;cin>>x;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=0;
    rep(i,0,n-1){
        if(a[i]>x){
            ans=ans+(a[i]-x);
            a[i]=x;
        }
    }
    rep(i,1,n-1){
        if(a[i-1]+a[i]>x){
            ans=ans+(a[i]-(x-a[i-1]));
            a[i]=x-a[i-1];
        }
    }
    /*
     rep(i,0,n-1)cout<<a[i]<<' ';
    cout<<endl;*/
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
string s1,s2;

string g="mcxi";
int mcxi(char c){
	if(c=='m')return 1000;
	else if(c=='c')return 100;
	else if(c=='x')return 10;
	else if(c=='i')return 1;

}
int conv(string s){
	int res=0;
	int n=1;
	for(string::iterator it=s.begin();it!=s.end();it++){
		char c=(*it);
		if(c>'0'&&c<='9')n=c-'0';
		else {
			res+=n*mcxi(c);
			n=1;
		}
	}
	return res;
}
string i2mcxi(int n){
	int b=1000;
	string res="";
	for(int i=0;i<4;i++,b/=10){
		int t=n/b;
		if(t==0)continue;
		else if(t>1)res+=t+'0';
		res+=g[i];
		n=n%b;
	}
	return res;
}
void solve(){
	cout<<i2mcxi(conv(s1)+conv(s2))<<endl;
}
int main(){
	int n;
	cin>>n;
	for(;n>0;n--){
		cin>>s1>>s2;

		solve();
	}
	return 0;
}

Measured memory_bytes: 0
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n)
	sum, max := 0, 0
	for i := 0; i < n; i++ {
		fmt.Scan(&m)
		if max < m {
			max = m
		}
		sum += m
	}
	if max < sum-max {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}


Measured memory_bytes: 512
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int K;
	cin >> K;
	vector<int> A(K);
	for (int i = 0; i < K; i++) cin >> A[i];


	auto judge1 = [&](auto x) {
		auto res = x;
		for (int i = 0; i < K; i++) {
			x -= x % A[i];
		}
		return x >= 2;
	};

	auto judge2 = [&](auto x) {
		auto res = x;
		for (int i = 0; i < K; i++) {
			x -= x % A[i];
		}
		return x == 2;
	};

	auto binary_search = [&](auto f, auto min, auto max) {

		auto ng = min;
		auto ok = max;

		while (abs(ok - ng) > 1) {
			auto mid = (ok + ng) / 2;

			if (f(mid)) ok = mid;
			else ng = mid;
		}

		return ok;
	};

	auto mid = binary_search(judge1, 0LL, LINF);
	if (!judge2(mid)) {
		cout << -1 << "\n";
		return 0;
	}

	cout << binary_search(judge2, 0LL, mid) << endl;
	cout << binary_search(judge2, LINF, mid) << endl;

	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,answer;
    cin>>a;

    if(a%2==0){
        answer=(a/2)*(a/2);
    }
    else {
        answer=(a/2)*(a/2+1);
    }

    cout<<answer<<endl;
}

Measured memory_bytes: 256
N = int(input())
list = []
for i in range(N):
    S, P = input().split()
    P = int(P)
    list.append([S, 100-P, i+1])

new_list = sorted(list, key=lambda x: (x[0], x[1]))
for k in new_list:
    print(k[2])


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <climits>
#include <map>
using namespace std;

int l[51];

int main() {
    int n, k;
    
    cin >> n >> k;
    
    for ( int i = 0; i < n; i++ ) {
        cin >> l[i];
    }
    
    sort(l, l + n);
    
    int sum = 0;
    for ( int i = n - 1, j = 0; j < k; i--, j++ ) {
        sum += l[i];
    }
    
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}

vector<int> dis_(int n,vector<int> &a,vector<int> &b,int start){
  vector<int> G[n];
  FOR(i,0,a.size()){
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }
  vector<int> res(n,-1);
  queue<int> nex;
  nex.push(start);
  res[start] = 0;
  while(nex.size()){
    int from = nex.front();
    nex.pop();
    for(auto to:G[from]){
      if(res[to]>=0)continue;
      res[to] = res[from] + 1;
      nex.push(to);
    }
  }
  return res;
}




int main(){

  int n,m;
  cin >> n >> m;
  vector<int> a(m),b(m),ans(n),min_d(n,MOD);

  FOR(i,0,m) cin >> a[i] >> b[i];
  FOR(i,0,m) a[i]--,b[i]--;

  auto dis = dis_(n,a,b,0);
  if(count(dis.begin(), dis.end(),-1)){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  FOR(i,0,m){
    if(min_d[a[i]] > dis[b[i]]){
      min_d[a[i]] = dis[b[i]];
      ans[a[i]] = b[i];
    }
    if(min_d[b[i]] > dis[a[i]]){
      min_d[b[i]] = dis[a[i]];
      ans[b[i]] = a[i];
    }
  }
  FOR(i,1,n){
    cout << ans[i]+1 << endl;
  }


}



Measured memory_bytes: 12460
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) 1e9
#define tt ll testcase; cin>>testcase; while(testcase--)
 
int main(){
	fast;
	int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0; i<n; i++){
		cin>>h[i];
	}
	vector <int> dp(n, (int)1e9);
	dp[0]=0;
	for(int i=1; i<n; i++){
		for(int j=1; j<=min(i, k); j++){
			if(dp[i-j] + abs(h[i]-h[i-j]) < dp[i]){
				dp[i] = dp[i-j] + abs(h[i]-h[i-j]);
			}
		}
	} 
	cout<<dp[n-1];

}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2 4");
            WillReturn.Add("0 3");
            //7
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2 4");
            WillReturn.Add("0 5");
            //8
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("4 1000000000");
            WillReturn.Add("0 1000 1000000 1000000000");
            //2000000000
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("1 1");
            WillReturn.Add("0");
            //1
        }
        else if (InputPattern == "Input5") {
            WillReturn.Add("9 10");
            WillReturn.Add("0 3 5 7 100 110 200 300 311");
            //67
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        SplitAct(InputList[0]);
        int T = wkArr[1];

        SplitAct(InputList[1]);
        int[] TArr = wkArr;

        long Answer = 0;
        int UB = TArr.GetUpperBound(0);
        for (int I = 0; I <= UB; I++) {
            if (I == UB) {
                Answer += T;
            }
            else {
                int AddVal = Math.Min(T, TArr[I + 1] - TArr[I]);
                Answer += AddVal;
            }
        }
        Console.WriteLine(Answer);
    }
}


Measured memory_bytes: 30560
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
using namespace std;


int main() {
  string s,t;
  cin>>s>>t;
  int n = s.size();
  bool ans = false;
  frn(i,n) {
    bool equal = true;
    frn(j,n) {
      if(s[(i+j)%n] != t[j]) {
        equal = false;
        break;
      } 
    }
    if(equal) {ans = true; break;}
  }
  if(ans) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	int m = sum / n;
	if (sum - m * n > (m + 1)*n - sum) {
		m++;
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += (a[i] - m)*(a[i] - m);
	}

	cout << ans << endl;
	

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(cin>>n){
    int ans = 0;
    REP(a,10) REP(b,10) REP(c,10){
      int d = n - a - b - c;
      if( d >= 0 && d <= 9) ans++;  
    }
    cout << ans << endl;
  }
  return 0;
}

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

bool isPalindrome(string str){
  bool palindrome = true;
  for(int i = 0; i < str.size(); i++){
    if (str.at(i) != str.at(str.size() - i - 1)) palindrome = false;
  }

  return palindrome;
}

int main(){
  string S;
  cin >> S;

  string left = S.substr(0, (S.size() - 1) / 2);
  string right = S.substr((S.size() + 3) / 2 - 1);
  
  if (isPalindrome(S) && isPalindrome(left) && isPalindrome(right)){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3616
#include <stdio.h>

#define  N  100
#define INF 10000000

void matrixChainOrder(int*);

int n;

int main(){

  int i;
  int M[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
  scanf("%d%d",&M[i],&M[i+1]);
  }
  
  matrixChainOrder(M);

  return 0;
}

void matrixChainOrder(int *p){

  int i;
  int j;
  int k;
  int l;
  int q;
  int m[N][N];

  for(i=1;i<=n;i++){
    m[i][i] = 0;
  }

  for(l=2;l<=n;l++){
   for(i=1;i<=n-l+1;i++){
     j = i + l -1;
     m[i][j] = INF;
     for(k=i;k<=j-1;k++){
     q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
     if(q < m[i][j]) m[i][j] = q;
   }
  }
 }
     printf("%d\n",m[1][n]);
}

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

using namespace std;

inline bool is_digit(char c) {
	return c <= '9' && c >= '0';
}

inline int read() {
	int tmp = 0, f = 1;
	char c = getchar();
	while(!is_digit(c)) {
		if(c == '-') f = -f;
		c = getchar();
	}
	while(is_digit(c)) tmp = (tmp << 1) + (tmp << 3) + (c ^ 48), c = getchar();
	return tmp * f;
}

inline void write(int x) {
	if(x > 9) write(x / 10);
	putchar((x % 10) ^ 48);
}

long long a, v, b, w, t;

int main() {
	a = 1ll * read(), v = 1ll * read(), b = 1ll * read(), w = 1ll * read(), t = 1ll * read();
	if(a == b) puts("YES");
	else if(a < b) {
		if(b - a <= t * (v - w)) puts("YES");
		else puts("NO");
	} else {
		if(a - b <= t * (v - w)) puts("YES");
		else puts("NO");
	}
	return 0;
}

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


long long int Exp(long long int exp_n,long long int exp_e, long long exp_mod);


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


long long int Exp(long long int exp_n,long long int exp_e, long long int exp_mod){
  long long int exp_o = 1;
  long long int exp_x=exp_n;
  long long int exp_tmp;
  
  while(0<exp_e){
    exp_tmp = exp_e/2;
    if(exp_e - exp_tmp*2 == 1){
      exp_o = exp_o*exp_x;
      if(exp_o>exp_mod){
        exp_o=exp_o%exp_mod;
      }
    }
    
    exp_x = exp_x*exp_x;
    if(exp_x>exp_mod){
      exp_x=exp_x%exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


Measured memory_bytes: 4416
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
n_ = sum(x == a_max for x in a)
if n_ > 1:
    a_max_2 = a_max
    for _ in range(n):
        print(a_max)
else:
    a_max_2=sorted(set(a))[-2]
    for i in a:
        if i == a_max:
            print(a_max_2)
        else:
            print(a_max)

Measured memory_bytes: 17164
N = int(input())
A = list(map(int, input().split()))
B = []
count = 0

for i in A:
    if i % 2 != 0:
        B.append(1)
    else:
        B.append(0)

for i in B:
    if i == 1:
        count += 1
else:
    if count % 2 != 0:
        print("NO")
    else:
        print("YES")


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

int main () {
    int n, k;
    cin >> n >> k;
    long long int ans = k;
    rep (i, n - 1) {
        ans *= (k - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
class hoge
{
    static void Main()
    {
        string input = Console.ReadLine();
        int[] numbers = new int[] 
            {
            int.Parse(input.Split(' ')[0]),
            int.Parse(input.Split(' ')[1]),
            int.Parse(input.Split(' ')[2])
            };
        Array.Sort(numbers);
        Console.WriteLine("{0} {1} {2}", numbers[0], numbers[1], numbers[2]);
    }
}

Measured memory_bytes: 9320
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    string S,SS;
    cin >> N >> SS;
    ll ans = 0;
    rep(ii,N){
        S = SS.substr(ii,N-ii);
        vector<ll> A(S.size());
        A[0] = S.size();
        int i = 1, j = 0;
        while (i < S.size()) {
            while (i+j < S.size() && S[j] == S[i+j]) ++j; // 右向きにjを伸ばしていく
            A[i] = j;
            if (j == 0) { ++i; continue;}
            int k = 1;
            while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k; // i~j間にkを走らせる
            i += k; j -= k;
        }
        REP(l,1,A.size()){
            if(A[l] > l) continue;
            cmax(ans,A[l]);
        }
    }
    cout << ans << endl;
}

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

long long gcd(long long a, long long b) {return b ? gcd(b, a % b) : abs(a);}
long long lcm(long long a, long long b) {return abs(a / gcd(a, b) * b);}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int k;
  cin >> k;
  long long res = 0;
  for (int i = 1; i < k + 1; i++) {
    for (int j = 1; j < k + 1; j++) {
      int g = gcd(i, j);
      for (int l = 1; l < k + 1; l++) {
        res += gcd(g, l);
      }
    }
  }
  cout << res << '\n';
  return 0;
}

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

double dp[301][301][301];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  int c[4] = {};
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    c[a]++;
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j+i <= n; j++)
      for (int k = 0; i+j+k <= n; k++) {
	int s = i+j+k;
	if (s)
	  dp[i][j][k] += n*1./s;
	if (k)
	  dp[i][j][k] += dp[i][j][k-1]*k/s;
	if (j)
	  dp[i][j][k] += dp[i][j-1][k+1]*j/s;
	if (i)
	  dp[i][j][k] += dp[i-1][j+1][k]*i/s;
      }
  cout << setprecision(20) << dp[c[3]][c[2]][c[1]] << endl;
}


Measured memory_bytes: 213248
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<pair<int, int> > a(n);
  priority_queue<int> b;
  for(int i=0;i<n;i++)cin>>a[i].first>>a[i].second;
  sort(a.begin(),a.end());
  int sum=0,j=0;
  for(int i=1;i<=m;i++){
    for(;a[j].first<=i&&j<n;j++)b.push(a[j].second);
    if(!b.empty()){
      sum+=b.top();
      b.pop();
    }
  }
  cout << sum << endl;
}

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

using namespace std;

/* alias */
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pii>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

/* repetition */
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define repr(i, n) for(int i=(n-1);i>=0;--i)
#define repre(i, n) for(int i=(n);i>=0;--i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define FORR(i, a, b) for(int i=(b-1);i>=(a);--i)
#define FORRE(i, a, b) for(int i=(b);i>=(a);--i)

int main() {
    int N,M,p;
    ll ans;
    cin >> N >> M;
    priority_queue<ll> price;
    rep(i,N){
        cin >> p;
        price.push(p);
    }

    rep(i,M){
        int a = price.top()/2;
        price.pop();
        price.push(a);
    }


    while(!price.empty()){
        ans+=price.top();
        price.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 1400
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a = rl()
t = sum(a)/2
if t in a:
  print('Yes')
else:
  print('No')









Measured memory_bytes: 27008
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()
#define MOD 86400

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> wake;
	wake.reserve(n);
	int sum = 0;
	rep(i,n) {
		int a,b;
		std::cin >> a >> b;
		sum=(sum+a)%MOD;
		wake.emplace_back(sum);
		sum=(sum+b)%MOD;
	}
	std::sort(all(wake));
	int max = 0;
	int j=0;
	for(int i=0;i<n;i++) {
		for(;j<2*n;j++) {
			if(j<=n) {if(wake[j]>wake[i]+10800) break;}
			else {
				int temp = wake[j%n]+MOD;
				if(temp>wake[i] + 10800) break;
			}
		}
		max = std::max(j-i,max);
	}
	print(max);
	return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
ans = a[0]

if(0 in a):
  print(0)
  exit()
else:
  for i in range(1,n):
    if(ans <= 10**18):
      ans = ans*a[i]
    else:
      print(-1)
      exit()

if(ans <= 10**18):
  print(ans)
else:
  print(-1)

Measured memory_bytes: 84688
import sys;sys.setrecursionlimit(100000);n,k=map(int,input().split());x,t,e,c=10**9+7,[set()for _ in range(n)],enumerate,k
for i in range(n-1):a,b=map(int,input().split());t[a-1].add(b);t[b-1].add(a)
def b(o):
  global c
  for i,j in e(t[o-1]):c=(c*(k-2-i))%x;t[j-1].discard(o);b(j)
for i,j in e(t[0]):c=(c*(k-1-i))%x;t[j-1].discard(1);b(j)
print(c)

Measured memory_bytes: 109900
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int i = 0; i < n; i++ ){ cout << x[i] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second
     
using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ ll x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n;
ll a[100010];
vi p;

char op[100010];
ll sum[100010];

ll ans;

int main(){

  n = in();
  a[0] = in();
  op[0] = '+';
  FOR( i , 1 , n ){
    string s = stin();
    a[i] = in();
    op[i] = s[0];
    if( op[i] == '-' ){
      p.pb( i );
    }
  }
  p.pb( n );

  REP( i , n ){
    sum[i+1] = sum[i] + a[i];
  }

  ll cur = 0;
  REP( i , n ){
    if( op[i] == '-' ){
      int ne = *upper_bound( ALL(p) , i );

      ll res = cur - ( sum[ne] - sum[i] ) + ( sum[n] - sum[ne] );

      chmax( ans , res );
      
      cur -= a[i];
    } else {
      cur += a[i];
    }
  }

  chmax( ans , cur );

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


Measured memory_bytes: 2424
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
	int q;cin>>q;
	list<int> l;
	int a,b;
	list<int>::iterator it=l.end();
	for (int i = 0; i < q; i++) {
		cin>>a;
		if (a == 0) {
			cin>>b;
			it = l.insert(it, b);
		}
		else if (a == 1) {
			cin >> b;
			if (b > 0) {
				rep(i, b) it++;
			}
			else {
				rep(i, -b) it--;
			}
		}
		else {
			it = l.erase(it);
		}
	}
	for (int i : l)cout << i << endl;
}



Measured memory_bytes: 18624