akhauriyash/Code-Regression huggingface dataset:
n=int(input())
A=[int(i) for i in input().split()]
AA=[A[0]]
for i in range(1,n):
  AA.append(AA[-1]+A[i])
tot=AA[-1]
import bisect
ans=float("inf")
for i in range(1,n-2):
  cur=AA[i]
  l=bisect.bisect_left(AA,cur//2)
  if l==0:
    L1=[0,float("inf")]
  else:
    L1=[AA[l-1],cur-AA[l-1]]
  L2=[AA[l],cur-AA[l]]
  
  r=bisect.bisect_left(AA,cur+(tot-cur)//2)
  if r-1==i:
    R1=[0,float("inf")]
  else:
    R1=[AA[r-1]-cur,tot-AA[r-1]]
  R2=[AA[r]-cur,tot-AA[r]]
  A11=L1+R1
  A12=L1+R2
  A21=L2+R1
  A22=L2+R2
  a11=max(A11)-min(A11)
  a12=max(A12)-min(A12)
  a21=max(A21)-min(A21)
  a22=max(A22)-min(A22)

  ans=min(ans,a11,a12,a21,a22)
print(ans)

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    __int128_t ans = 1;
    static int64_t a[100000];
    for(int i=0;i<n;++i){
        cin >> a[i];
        if(a[i] == 0){ cout << 0 << endl; return 0; }
    }
    for(int i=0;i<n;++i){
        ans = ans * a[i];
        if(ans > 1'000'000'000'000'000'000){ cout << -1 << endl; return 0; }
    }
    cout << (int64_t)ans << endl;
    return 0;
}

Measured memory_bytes: 4448
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, M; 
	cin >> N >> M; 
	int A[100010] = {}; 
	bool B[100010] = {}; 
	for(int i = 1; i <= N; i++){
		A[i] = 1; 
	}
	B[1] = true; 
	for(int i = 1; i <= M; i++){
		int x, y; 
		cin >> x >> y; 
		if(B[x] == false){
			A[x] --; A[y] ++; 
		}
		else if(A[x] == 1){
			B[x] = false; B[y] = true; A[x] --; A[y] ++; 
		}
		else{
			B[y] = true; A[x] --; A[y] ++; 	
		}
	}
	int ans = 0; 
	for(int i = 1; i <= N; i++){
		if(B[i]) ans ++; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=998244353;

int main(void){
    long long n;
    cin>>n;
    stack<int> sta;
    while(n>0){
        sta.push((n-1)%26+1);
        n=(n-1)/26;
    }
    while(!sta.empty()){
        int k=sta.top();
        sta.pop();
        //cout<<k<<endl;
        char c='a'+k-1;
        cout<<c;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		char[][]A = new char[N][N];
		char[][]B = new char[M][M];
		for(int i = 0; i < N; i++) {
			String t = sc.next();
			for(int j = 0; j < N; j++) {
				A[i][j] = t.charAt(j);
			}
		}
		for(int i = 0; i < M; i++) {
			String t = sc.next();
			for(int j = 0; j < M; j++) {
				B[i][j] = t.charAt(j);
			}
		}
		int k = N - M;
		for(int i = 0; i <= k; i++) {
			for(int j = 0; j <= k; j++) {
				boolean flag = true;
				loop: for(int r = 0; r < M; r++) {
					for(int c = 0; c < M; c++) {
						if(A[r + i][c + j] != B[r][c]) {
							flag = false;
							break loop;
						}
					}
				}
				if(flag) {
					System.out.println("Yes");
					System.exit(0);
				}
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 22996
X,Y=input().split()
X=int(X)
Y=int(Y)
prize = [0]*206
prize[1:4] = [300000,200000,100000]
#print(prize)
if X==1 and Y==1:
    ans=1000000
else:
    ans=prize[X]+prize[Y]

print(ans)


Measured memory_bytes: 2940
#include <stdio.h>

int main(void)
{
	float weight;
	
	while (scanf("%f", &weight) != EOF){
		if (weight <= 48.0){
			printf("light fly\n");
		}
		if ((48.0 < weight) && (weight <= 51.0)){
			printf("fly\n");
		}
		if ((51.0 < weight) && (weight <= 54.0)){
			printf("bantam\n");
		}
		if ((54.0 < weight) && (weight <= 57.0)){
			printf("feather\n");
		}
		if ((57.0 < weight) && (weight <= 60.0)){
			printf("light\n");
		}
		if ((60.0 < weight) && (weight <= 64.0)){
			printf("light welter\n");
		}
		if ((64.0 < weight) && (weight <= 69.0)){
			printf("welter\n");
		}
		if ((69.0 < weight) && (weight <= 75.0)){
			printf("light middle\n");
		}
		if ((75.0 < weight) && (weight <= 81.0)){
			printf("middle\n");
		}
		if ((81.0 < weight) && (weight <= 91.0)){
			printf("light heavy\n");
		}
		if (91.00 < weight){
			printf("heavy\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int n;
char s[N];
const int P1=1e9+7,P2=1e9+9;
struct LY
{
	int P;
	int del(int x) { return x>=P?x-P:x; }
	void add(int &x,int y) { x=del(x+y); }
	int ksm (int a,int b)
	{
		int ans=1;
		while (b)
		{
			if (b&1) ans=(LL)ans*a%P;
			a=(LL)a*a%P,b>>=1;
		}
		return ans;
	}
}A,B;
struct pii
{
	int x,y;
	pii (int xx=0,int yy=0) { x=xx,y=yy; }
};
pii operator + (pii a,pii b) { return pii(A.del(a.x+b.x),B.del(a.y+b.y)); }
pii operator - (pii a,pii b) { return pii(A.del(a.x-b.x+P1),B.del(a.y-b.y+P2)); }
pii operator * (pii a,pii b) { return pii((LL)a.x*b.x%P1,(LL)a.y*b.y%P2); }
bool operator < (pii a,pii b) { return a.x!=b.x?a.x< b.x:a.y< b.y; }

pii f[N],g[N],inv,Q=pii(233,233);
void init ()
{
	A.P=P1,B.P=P2;
	inv=pii(A.ksm (Q.x,P1-2),B.ksm (Q.y,P2-2));
	g[0]=pii(1,1);
	for (int i=1; i<=n; i++)
	{
		if (s[i]=='<') f[i]=f[i-1],g[i]=g[i-1]*inv;
		else if (s[i]=='>') f[i]=f[i-1],g[i]=g[i-1]*Q;
		else if (s[i]=='+') g[i]=g[i-1],f[i]=f[i-1]+g[i];
		else g[i]=g[i-1],f[i]=f[i-1]-g[i];
	}
}
map <pii,int> p;
LL solve ()
{
	p.clear ();
	++p[f[n]];
	LL ans=0;
	for (int i=n-1; i>=0; i--)
		ans+=p[f[n]*g[i]+f[i]],++p[f[i]];
	return ans;
}
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
    sc(n),scanf ("%s",s+1);
	init ();
	pr(solve ());

    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
const int mod = 1000000007;

int main() {
    int n;
    string s;
    cin >> n >> s;
    if(n % 2 == 0) {
        for(int i = 0; i < n / 2; i++) {
            if(s[i] != s[i + n / 2]) {
                cout << "No" << endl;
                exit(0);
            }
        }
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string.h>
#include <cmath>

using namespace std;
char table[105][105];
int w,h,ans;

void dfs(int x,int y,char kind){
	if (x>h || y>w || x<=0 || y<=0 ) return;
	if (table[x][y] == kind){
		table[x][y] = 0;
		dfs(x-1,y,kind);
		dfs(x+1,y,kind);
		dfs(x,y-1,kind);
		dfs(x,y+1,kind);
	}
}

int main(){
	while(cin>>h>>w){
		if (h==0 && w==0) break;
		memset(table,0,sizeof(table));
		for (int i=1;i<=h;i++)
		for (int j=1;j<=w;j++)	cin>>table[i][j];
		ans=0;
		for (int i=1;i<=h;i++)
			for (int j=1;j<=w;j++){
				if (table[i][j] != 0){
					dfs(i,j,table[i][j]);
					ans++;
				}
			}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1484
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x 
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
string solve(vector<int>& v, int k)
{
    bool dp[k+1];
    memset(dp, 0, sizeof dp);
 
    for(int i = 1; i <= k; i++)
    {
        for(int move : v)
        {
            if(move > i)
                continue;
            if(dp[i - move] == 0)
                dp[i] = 1;
        }
    }
    
    return dp[k] ? "First" : "Second";
}
 
int main() {
   int n,k;
   cin >> n >> k;
   vector<int> v(n);
   for(int i =0; i<=n; i++)
    cin>>v[i];
   cout<<solve(v, k);
   return 0;
}

Measured memory_bytes: 512
n = int(input())
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
s = input()

ans = 1
last = s[0]
for i in range(1,n):
    if last != s[i]:
        last = s[i]
        ans = ans + 1

print(ans)




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

using namespace std;

const int MOD=1e9+7;
//const int MOD=998244353;

const double PI=3.14159265359;

long long modpow(long long x, long long n, long long m) {
    if (n == 0) return 1%m;
    long long u = modpow(x,n/2,m);
    u = (u*u)%m;
    if (n%2 == 1) u = (u*x)%m;
    return u;
}


int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    vector<long long> v(n+1), hs(n+1), b(n+1), nfact(n+1);
    for(int i=1; i<=n; i++){
        cin>>v[i];
    }
    
    hs[1]=1;
    nfact[1]=1;
    for(int i=2; i<=n; i++){
        hs[i]=hs[i-1]+modpow(i,MOD-2,MOD);
        hs[i]%=MOD;
        nfact[i]=i*nfact[i-1];
        nfact[i]%=MOD;
    }
    
    for(int i=1; i<=n; i++){
        b[i]=hs[n-i+1]+hs[i]-1;
        b[i]%=MOD;
    }
    
    long long ans=0;
    for(int i=1; i<=n; i++){
        ans+=b[i]*v[i];
        ans%=MOD;
    }
    ans*=nfact[n];
    ans%=MOD;
    cout<<ans;
    
    
    
    
    
    return 0;
    
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define ci(n) cin >> n
#define co(n) cout << n << endl
using namespace std;

int main(){
  string s;
  cin >> s;
  int a, b[26]={};
  rep(i,0,s.size()){
    a=s[i];
    b[a-97]++;
  }
  int c=0;
  rep(i,0,26){
    c+=b[i]%2;
  }
  if(c==0) co("Yes");
  else co("No");
    
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	
	if (n % 2 == 0) {
		cout << (n*(n - 1) / 2 - n / 2) << endl;
		for (int i = 1; i <= n; i++) {
			for (int j = i+1; j <= n; j++) {
				if (i + j != n + 1) {
					cout << i << " " << j << endl;
				}
			}
		}
	}
	else {
		cout << (n*(n - 1) / 2 - (n + 1) / 2 + 1) << endl;
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				if (i + j != n) {
					cout << i << " " << j << endl;
				}
			}
		}


	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
	string base;
	string s;
	bool ok;

	cin >> base;
	cin >> s;

	for(int i = 0;i < base.size();i++) {
		ok = true;

		for(int j = 0;j < s.size();j++) {
			if(s.at(j) != base.at((i + j) % base.size())) {
				ok = false;
				break;
			}
		}

		if(ok) 
			break;
	}

	if(ok) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    int a,b,c,d;
    string s,t,u;

    cin>>a>>b>>c>>d;

    double cho,tan;
    cho=2.0*PI*d/60.0;
    tan=2.0*PI*(60.0*c+d)/720.0;
    double dif=cho-tan;
    double ans=sqrt((double)a*a+(double)b*b-2.0*a*b*cos(dif));
    printf("%.15f\n",ans);

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 4160
s = input()
t = input()
slist = list(s)
tlist = list(t)
slen = len(s)
ans = 0
for i in range(slen):
    if slist[i] == tlist[i]:
        pass
    else:
        ans += 1
if ans > 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 61640
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
const lli INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1e9 + 7;
const lli MH1 = 1599614977, MH2 = 2034417103, MH3 = 1090250123, MH4 = 2024491871;
const int K = 1e5 + 10;
const int N = 105;
bool dp[K];
int nums[N];
lli bpow(lli baseee, lli exponenttt) {
	if(exponenttt < 0) return 0;
	lli res = 1;
	baseee %= MOD;
	while (exponenttt > 0) {
		if ((exponenttt & 1) == 1) res = (res*baseee) % MOD;
		baseee = (baseee*baseee) % MOD;
		exponenttt >>= 1;
	}
	return res;
}
lli multInverse(lli a) {//if_mod_is_prime
	return bpow(a, MOD - 2);
}
lli divm(lli a, lli b) {//if_mod_is_prime
	return (a * multInverse(b)) % MOD;
}
lli multm(lli a, lli b) {
	return (a * b) % MOD;
}
lli subm(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli addm(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> nums[i];
	dp[0] = false;
	for(int i = 1; i <= k; i++) {
		for(int j = 1; j <= n; j++) {
			if(i < nums[j]) break;
			if(!dp[i-nums[j]]) 
				dp[i] = true;
		}
	}
	if(dp[k])
		cout << "First\n";
	else	
		cout << "Second\n";
	return 0;
}

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

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

    int j = 1;
    int ans = 0;
    for(int i=0;i<n;i++){
        ans++;
        if(a[i] == j){
            j++;
            ans--;
        }
    }
    if(ans == n){
        ans = -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
def dfs(array: list, index: int, calc: str, result: int):
    if index == len(array):
        if result == 7:
            print("{}=7".format(calc))
            exit(0)

    if index == 0:
        dfs(array, index + 1, array[index], int(array[index]))
    elif index < len(array):
        dfs(array, index + 1, calc + "-" + array[index], result - int(array[index]))
        dfs(array, index + 1, calc + "+" + array[index], result + int(array[index]))

array = list(input())
dfs(array, 0, "", 0)


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define all(c) (c).begin(),(c).end()
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; q > i; i++)
#define rep_one(i,q) for(int i = 1; q >= i; i++)
#define dep(i,q) for(int i = q; 0 < i; i--)
using namespace std; 
int waru_kiriage(int a, int b){//切り上げ割り算をする
  return (a % b == 0 ? a / b : a / b + 1);
}
int abss(int a){//absと一緒
    return (a < 0 ? a * -1 : a);
}
int bai(int k){//引数の数だけ10倍する
  int ans = 1;
  for(int i = 0;k>i;i++){
    ans *= 10;
  }
  return ans;
}
int int_length(int k){//引数の桁数を調べる
  int ans = 0;
  for(int i = 1; k > i; i=i*10)ans++;
  return ans;
}
/*
確認ポイント
to_string() はC++11以降の実装;
length(),size()に括弧をつけ忘れてないか;
*/

int main() { 
    int N,X,mx;
    cin >> N >> X;
    vector<int> x;
    rep(i,N){
      int tmp;
      cin >> tmp;
      x.push_back(tmp);
    }
    x.push_back(X);
    sort(all(x));
    vector<int> xminus;
    rep(i,N) xminus.push_back(x[i+1] - x[i]);
    sort(all(xminus));
    dep(i,xminus[0]){
      bool ok = true;
      rep(j,N){
        if(xminus[j] % i != 0){
          ok = false;
          break;
        }
      }
      if(ok){
         mx = i;
         break;
      }
    }
    cout << mx << endl;
    return 0; 
} 

Measured memory_bytes: 1400
n,l,t=map(int,input().split())
xw=[list(map(int,input().split()))for _ in range(n)]
p=[(xw[i][0]+((1 if xw[i][1]==1 else -1)*t))%l for i in range(n)]
p.sort()
ans=0
for x,w in xw:
  if w==1:
    ans+=(x+t)//l
  else:
    ans-=((l-1)-x+t)//l
ans%=n
p=p[ans:]+p[:ans]
print(*p)

Measured memory_bytes: 30896
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main()
{
	string _S, T;
	int index = -1;

	cin >> _S >> T;
	
	if(_S.size() < T.size()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	for (int i = 0; i <= _S.size() - T.size(); i++) {
		for (int j = 0; j < T.size(); j++) {
			if (_S[i + j] != '?' && _S[i + j] != T[j])
				break;
			if (j == T.size() - 1)
				index = i;
		}
	}

	if (index == -1) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	for (int i = 0; i < _S.size(); i++) {
		if (i >= index && i < index + T.size()) {
			_S[i] = T[i - index];
		}
		else if (_S[i] == '?')
			_S[i] = 'a';
	}

	cout << _S << endl;

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N;
int A[200010];
int c[200010];


signed main(){
    cin >> N;
    rep(i, 0, N) cin >> A[i], c[A[i]]++;

    int s = 0;
    repe(i, 1, N) s += c[i]*(c[i]-1)/2;

    rep(i, 0, N) cout << s-c[A[i]]*(c[A[i]]-1)/2+(c[A[i]]-1)*(c[A[i]]-2)/2 << endl;

    return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,t;
  cin >> n >> t;
  ll res = 0;
  res = pow(10,18);
  for(int i = 0;i < n;i++){
    ll c,time;
    cin >> c >> time;
    if(time <= t)res = min(c,res);
  }
  if(res != pow(10,18))cout << res << endl;
  else cout << "TLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

itn N;
string S;

void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    cin >> S;
    int ans = 0;
    FOR(i, 0, N - 2) {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
            ans++;
    }
    cout << ans << endl;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  vector<pair<ll,ll>> a;
  rep(i,n){
    ll x;
    cin >> x;
    a.emplace_back(x,i);
  }
  sort(a.rbegin(),a.rend());

  vector<vector<ll>> dp(n+1, vector<ll>(n+1,0));
  rep(i,n)rep(j,i+1){
    dp[j+1][i-j] = max(dp[j+1][i-j], dp[j][i-j]+a[i].F*abs(a[i].S-j));
    dp[j][i+1-j] = max(dp[j][i+1-j], dp[j][i-j]+a[i].F*abs(a[i].S-(n-i-1+j)));
  }

  ll ans = 0;
  rep(i,n+1){
    ans = max(ans, dp[i][n-i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 34680
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int a,b;
    cin>>a>>b;
    long long int lb=log10(b);
    a=a*pow(10,lb+1);
    a+=b;//cout<<a<<endl;
    if(floor((double)sqrt(a))==ceil((double)sqrt(a)))cout<<"Yes";else cout<<"No";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3908
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    #a=list(map(int,sys.stdin.readline().split(' ')))
    n,k= map(int, sys.stdin.readline().split(' '))
    h=[]

    for jj in range(n):
        p=int(input())
        h.append(p)

    ans=mod
    h.sort()

    for i in range(n):
        if(i+k-1<n):
            ans=min(ans,abs((h[i+k-1]-h[i])))
            #print(ans)
    print(ans)

    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Measured memory_bytes: 7404
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 1000000007;

vector<vector<ll>> mat_mul(vector<vector<ll>> a, vector<vector<ll>> b) {
	int n = a.size();
	vector<vector<ll>> ans(n, vector<ll>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				ans[i][j] += a[i][k] * b[k][j];
				ans[i][j] %= mod;
			}
		}
	}
	return ans;
}

vector<vector<ll>> mat_pow(vector<vector<ll>> a, ll b) {
	int n = a.size();
	vector<vector<ll>> ans(n, vector<ll>(n));
	for (int i = 0; i < n; i++) ans[i][i] = 1;
	while (b) {
		if (b & 1) ans = mat_mul(ans, a);
		a = mat_mul(a, a);
		b >>= 1;
	}
	return ans;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int h, w; ll k;
	cin >> h >> w >> k;
	k--;
	vector<vector<char>> a(h, vector<char>(w));
	rep(i, h) rep(j, w) cin >> a[i][j];
	int x = 0, y = 0;
	rep(i, h) if (a[i][0] == '#'&&a[i][w - 1] == '#') x++;
	rep(j, w) if (a[0][j] == '#'&&a[h - 1][j] == '#') y++;
	if (x > 0 && y > 0 || k == -1) {
		cout << "1\n";
		return 0;
	}
	ll cnt = 0;
	rep(i, h) rep(j, w) if (a[i][j] == '#') cnt++;
	ll b = 0;
	if (x > 0) rep(i, h) rep(j, w - 1) if (a[i][j] == '#'&&a[i][j + 1] == '#') b++;
	if (y > 0) rep(i, h - 1) rep(j, w) if (a[i][j] == '#'&&a[i + 1][j] == '#') b++;
	vector<vector<ll>> base(2, vector<ll>(2));
	base[0][0] = cnt; base[0][1] = mod - 1; base[1][1] = max(x, y);
	vector<vector<ll>> res = mat_pow(base, k);
	cout << (res[0][0] + res[0][1] * b) % mod << '\n';
}

Measured memory_bytes: 1280
N, M = map(int, input().split())
L = []
id = []

for i in range(M) : 
    tmp = []
    tmp = list(map(int, input().split()))
    tmp.append(i)
    L.append(tmp)
    
LL = sorted(L)
num = []

for i in range(len(LL)) : 
    if i == 0 : 
        cnt = 1

    else : 
        if(LL[i][0] == LL[i-1][0]) : 
            cnt += 1
        else : 
            cnt = 1
        
    id.append(LL[i][2])
    num.append(str(LL[i][0]).zfill(6) + str(cnt).zfill(6))

numnum = [x for _,x in sorted(zip(id, num))] #このコード, なんでちゃんとidが消えて, numだけが残ってるんや? →　i, j for i, j in ～～～ となっていて, iの部分を捨てている感じ

for x in numnum : 
    print(x)

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

long long x,n,R;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    x=100;
    cin>>n;
    while (x<n){
        R++;
        x+=x/100;
    }
    cout<<R<<'\n';
}


Measured memory_bytes: 3652
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //WOOOOOO
 
	public static void main(String[] args) {  
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int T = 0;
		int F = 0; //Two and four
		int bad = 0;
		for (int i = 0; i < N; i++) {
			int x = input.nextInt();
			if (x%4==0) F++;
			else if (x%2==0) T++;
			else bad++;
		}
		if (T>=1&&T<N) { //2 2 2 2... 2 works
			bad++;//2 2 1 4 1 doesn't work
		}  //multiples of two can be joined as one contiguous sub-array since 2^2 = 4
		if (F>=1) {
			F++; //3 4s handle 4 bad slots ---> {bad,4,bad,4,bad,4,bad} --> x 4s handle x+1 bad slots
			bad-=F;
		}
		System.out.println(bad<=0?"Yes":"No");
	}
}

Measured memory_bytes: 48548
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<list>
using namespace std;
typedef long long ll;

int main() {
	string s;
	cin >> s;
	ll ans = 0, sumb = 0;
	for (ll i = 0;i < s.length();i++) {
		if (s[i] == 'B')sumb++;
		else ans += sumb;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  string a, b;
//   cin.ignore();
  getline(cin,a);
  getline(cin,b);
  int n=a.length();
  int m=b.length();
//   cout<<a<<endl;
//   cout<<b<<endl;
  int dp[n+1][m+1];
  for(int i=0;i<n+1;i++) dp[i][0]=0;
  for(int i=0;i<m+1;i++) dp[0][i]=0;
  for(int i=1;i<n+1;i++) {
	for(int j=1;j<m+1;j++) {
      if(a[i-1]==b[j-1]) {dp[i][j]=dp[i-1][j-1]+1;}
      else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    }
  }
  int i=n,j=m;
  string res;
  while(i>0&&j>0){
      if((dp[i][j]==dp[i-1][j-1]+1)&&a[i-1]==b[j-1]) {
          res+=a[i-1];
          i--;j--;
      } 
      else {
          if(dp[i-1][j]>dp[i][j-1]) i--;
          else j--;
      }
  }
//   cout<<endl;
  for(int i=res.length()-1;i>=0;i--) cout<<res[i];
  cout<<endl;
  
}

Measured memory_bytes: 35456
#設定
import sys
input = sys.stdin.buffer.readline

INF = float("inf")

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

#二分探索基本形 L:リスト x:値 n:リスト長
def Binary_Search(A, F, N, K):
	#初期化
	left = 0
	right = 10 ** 12
	ans = INF
	
	#二分探索
	while left <= right:
		mid = (left + right) // 2
		cnt = 0
		for i in range(N):
			if A[i] * F[i] > mid:
				cnt += (A[i] - int(mid // F[i]))
		if cnt <= K:
			right = mid - 1
			ans = min(ans, mid)
		else:
			left = mid + 1

	return ans

#処理内容
def main():
	N, K = getlist()
	A = getlist()
	F = getlist()
	A = sorted(A)
	F = sorted(F)[::-1]
	ans = Binary_Search(A, F, N, K)
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 83736
import sys

sys.stdin.readline()
d = list(map(int, sys.stdin.readline().strip().split()))

x = dict()
for i in d:
    if i not in x:
        x[i] = 1
    else:
        x[i] += 1

y = {i:j for i, j in x.items() if j>=2}

z = sorted(y.keys())


if len(z) >= 2:
    if y[z[-1]] >= 4:
        print(z[-1]**2)
    else:
        print(z[-1] * z[-2])
else:
    print(0)

Measured memory_bytes: 18060
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int n,go_min = 100000000,back_min = 100000000,Table[21][21];

void func(int sum,int current,int goal,bool FLG,int checkTable[21]){
	if(current == goal){
		if(FLG){
			go_min = min(go_min,sum);
		}else{
			back_min = min(back_min,sum);
		}
		return;
	}

	for(int i=1; i <= n; i++){
		if(Table[current][i] != -1 && checkTable[i] == 0){
			int newCheckTable[21];
			for(int k=0; k < 21; k++)newCheckTable[k] = checkTable[k];
			newCheckTable[i] = 1;
			func(sum+Table[current][i],i,goal,FLG,newCheckTable);
		}
	}

}


int main(){

	int m,a,b,c,d,start,end,V,P,checkTable[21];
	scanf("%d",&n);

	for(int i=0; i < 21; i++){
		checkTable[i] = 0;
		for(int k=0; k < 21; k++){
			Table[i][k] = -1;
		}
	}

	scanf("%d",&m);

	for(int i=0; i < m; i++){
		scanf("%d,%d,%d,%d",&a,&b,&c,&d);
		Table[a][b] = c;
		Table[b][a] = d;
	}

	scanf("%d,%d,%d,%d",&start,&end,&V,&P);

	func(0,start,end,true,checkTable);
	func(0,end,start,false,checkTable);

	printf("%d\n",V-(P+go_min+back_min));

	return 0;
}

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

typedef long long ll;

const int N=61;

ll sum,a[N],n,k,b[N];

bool ok()
{
	for(int i=1;i<=n;i++)
		if(b[i]>n-1)
			return true;
	return false;
}

bool check(ll m)
{
	ll tm=0;
	for(int i=1;i<=n;i++)
		b[i]=a[i];
	while(ok())
	{
		ll tmp=0;
		for(int i=1;i<=n;i++)
			tmp+=b[i]/n;
		for(int i=1;i<=n;i++)
			b[i]=(tmp-b[i]/n)+(b[i]%n);
		tm+=tmp;
		if(tm>m)
			return 0;
	}
	return true;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i],sum+=a[i];
	ll l=-1,r=sum;
	while(r-l>1)
	{
		ll mid=(l+r)>>1;
		if(!check(mid))
			l=mid;
		else
			r=mid;
	}
	cout<<r;
}

Measured memory_bytes: 256
// restoring trees. I need to solve the problem !

#include <bits/stdc++.h>
#define ll long long int 
using namespace std;


// Time complexity O(nlogn)

int main() {

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

	sort(arr,arr+n);


	// prefix sum calculation
	ll prefix[n];
	prefix[0] = arr[0];
	for(int i = 1;i<n;i++)
		prefix[i] = arr[i]+prefix[i-1];

	ll cur_max = n-1;

	while(1) {

		ll min_req_sum = (arr[cur_max]+1)/2;

		// Now prefix array me 0- curmax-1 me khojna hai first index where value is >= min_req_sum

		ll* pos = lower_bound(prefix,prefix+cur_max,min_req_sum);

		if(pos==prefix+cur_max){
			break;
			// print (n-cur_max);
		} else {
			cur_max = pos-prefix;
		}

		if(cur_max==0)
			break;

	}

	cout<<(n-cur_max);

}


Measured memory_bytes: 1792
import sys
import itertools
import numpy as np
import networkx as nx

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
S = np.frombuffer(read(), 'S1').reshape(N, -1)[:, :M].astype('U1')

A = []
B = []
E = []

for i, j in itertools.product(range(N), range(M)):
    if S[i, j] == '#':
        continue
    elif (i + j) & 1:
        A.append((i, j))
    else:
        B.append((i, j))

for i, j in A:
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        i1, j1 = i + dx, j + dy
        if 0 <= i1 < N and 0 <= j1 < M and S[i1, j1] != '#':
            E.append(((i, j), (i1, j1)))

G = nx.Graph()
G.add_nodes_from(A, bipartite=0)
G.add_nodes_from(B, bipartite=1)
G.add_edges_from(E)

M = nx.bipartite.eppstein_matching(G, A)
for key, item in M.items():
    i, j = key
    i1, j1 = item
    if i1 == i + 1:
        a, b = 'v', '^'
    elif i1 == i - 1:
        a, b = '^', 'v'
    elif j1 == j + 1:
        a, b = '>', '<'
    else:
        a, b = '<', '>'
    S[i, j], S[i1, j1] = a, b

print(len(M) // 2)
for row in S:
    print(''.join(row))


Measured memory_bytes: 82828
#include <iostream>
#include <vector>
#include <utility>

using namespace std;
typedef pair<int, int> P;

struct op{
	P s, t;
	op(){}
	op(int a, int b, int c, int d){
		s = make_pair(a, b), t = make_pair(c, d);
	}
};

int h, w;
int a[505][505];
vector<op> vec;

int main(void)
{
	cin >> h >> w;
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			cin >> a[x][y];
		}
	}
	
	for(int y = 1; y <= h; y++){
		for(int x = 1; x < w; x++){
			if(a[x][y] % 2){
				a[x+1][y]++, a[x][y]--;
				vec.push_back(op(x, y, x+1, y));
			}
		}
	}
	for(int y = 1; y < h; y++){
		if(a[w][y] % 2){
			a[w][y+1]++, a[w][y]--;
			vec.push_back(op(w, y, w, y+1));
		}
	}
	
	cout << vec.size() << endl;
	for(int i = 0; i < vec.size(); i++){
		op p = vec[i];
		cout << p.s.second << " " << p.s.first << " ";
		cout << p.t.second << " " << p.t.first << endl;
	}
	return 0;
}

Measured memory_bytes: 5232
#include<stdio.h>

int main(){

int N;
scanf("%d",&N);
int H,prev=0,ans=1;
for (int i = 0; i < N; i++){
    scanf("%d",&H);
    if (prev == H){
      prev=H;
    }else if (prev<H){
      prev = --H;
    }else{
      ans = 0;
    }
}

ans == 1 ? puts("Yes") : puts("No");

return 0;

}

Measured memory_bytes: 1648
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

int a[100005];

int main()
{
	int n;
	cin >> n;
	memset(a, 0, sizeof(a));
	int sum = 0;
	for(int i=1; i<=n; i++)
	{
		int x;
		cin >> x;
		if(x==i)
		{
			a[i] = 1;
			sum++;
		}
	}
	for(int i=1; i<n; i++)
	{
		if(a[i]==a[i+1]&&a[i]==1)
		{
			a[i] = 0;
			a[i+1] = 0;
			sum--;
			i++;
			continue;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;
int main()
{
    int n;
    cin>>n;
    set<string> unique;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin>>s;
        unique.insert(s);
    }
    cout<<unique.size();
    
}

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

//絶対値
int abs(int x) {
				return max(x,-x);
}

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0;i<N;i++) {
	cin >>a.at(i);
  }
  int m = 0;
  for (int i=0;i<N;i++) {
	for (int j=0;j<N;j++) {
	  if (abs(a.at(i)-a.at(j)) >= m) {
		m = abs(a.at(i)-a.at(j));
		}
			}
		  }
		  cout << m << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int ret=0, cur=0;
	int n; cin>>n;
	for (int i=0; i<n; i++) {
		int h; cin>>h;
		if (cur<h)
			ret+=h-cur;
		cur=h;
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>

using namespace std;

int main(void) {
    string S;
    cin>>S;
    int T,N,M;
    N=S.size();
    T=0;
    M=0;
    for(int i=0;i<N;i++){
        
    
        if(S[i]=='A' || S[i]=='T'){
            T=T+1;
        }else if(S[i]=='C' || S[i]=='G'){ 
            T=T+1;
        }else{
            T=0;
        }
        
        M=max(M,T);
        
    
    }
    cout<<M<<endl;
   
    return 0;
}

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

dp = list(map(int, input().split()))
for i in range(1, N):
    a, b, c = map(int, input().split())
    newDP = [0] * 3
    newDP[0] = max(dp[1], dp[2]) + a
    newDP[1] = max(dp[0], dp[2]) + b
    newDP[2] = max(dp[0], dp[1]) + c

    dp = newDP[::]

ans = max(dp)
print(ans)


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();

		int[] start = new int[26];
		int[] goal = new int[26];
		Arrays.fill(start, -1);
		Arrays.fill(goal, -1);

		for (int i = 0; i < S.length; i++) {
			int a = S[i] - 'a';
			int b = T[i] - 'a';

			if (start[a] != -1 || goal[b] != -1) {
				if (start[a] != b || goal[b] != a) {
					System.out.println("No");
					return;
				}
			} else {
				start[a] = b;
				goal[b] = a;
			}
		}

		System.out.println("Yes");
	}
}


Measured memory_bytes: 28944
#include <bits/stdc++.h>
#define print(x) cout << x << '\n';

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.in", "r", stdin);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min((n*a), b) << '\n';
    
    
    return 0;
}


Measured memory_bytes: 256
while line = STDIN.gets
  line.chomp!
  is_at=false
  how_many=0
  expanded_text=""
  line.chars.each do |c|
    if c == "@" then
      is_at=true
    elsif is_at then
      how_many=c.to_i
      is_at=false
    elsif how_many > 0 then
      expanded_text+=c*how_many
      how_many=0
    else
      expanded_text+=c
    end 
  end
  puts expanded_text
end

Measured memory_bytes: 8620
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int f(int x, int y) {
    if(x > 0 && x > y && -x <= y) return f(-x, y) + 1;
    if(x >= 0 && abs(x) < abs(y)) return f(x + abs(abs(x) - abs(y)), y) + abs(abs(x) - abs(y));
    if(x < 0 && x > y) return f(x - abs(abs(x) - abs(y)), y) + abs(abs(x) - abs(y)) + 2;
    if(x < 0 && -x <= y) return f(-x, y) + 1;
    if(abs(x) == abs(y)) return x != y;
    int ret = INF;
    if(x <= y) ret = y - x;
    if(x < y && -x > y) {
        ret = min(ret, abs(abs(x) - abs(y)) + 1);  
    }
    return ret;
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    cout << f(x, y) << endl;

    return 0;
}


Measured memory_bytes: 3572
#include<iostream>
using namespace std;
string input;
int len;
struct bit{
	int val[100000] = {};
	int lowbit(const int &a){
		return a & -a;
	}
	int query(int l, int r){
		int res = 0;
		--l;
		while(l){
			res -= val[l];
			l -= lowbit(l);
		}
		while(r){
			res += val[r];
			r -= lowbit(r);
		}
		return res;
	}
	void plus(int i){
		while(i <= 100000){
			++val[i];
			i += lowbit(i);
		}
	}
}tree;
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	int ans = 0, Q;
	cin >> len >> Q >> input;
	for(int i = 1;i < input.size();++i){
		if(input[i] == 'C' and input[i - 1] == 'A')tree.plus(i);
	}
	while(Q--){
		int l, r;
		cin >> l >> r;
		cout << tree.query(l, r - 1) << '\n';
	}
}


Measured memory_bytes: 1488
# -*- coding: utf-8 -*-
S = str(input())
Q = int(input())

rev_flag = 1
head_str = ""
tail_str = ""
for _ in range(Q):
    query = str(input()) # contains spaces
    if query[0] == "1":
        rev_flag *= -1
    else:
        h_or_t_flag = 1 if query[2] == "1" else -1
        h_or_t_flag *= rev_flag
        
        if h_or_t_flag == 1:
            head_str += query[4]
        else:
            tail_str += query[4]

ans = head_str[::-1] + S + tail_str
print(ans if rev_flag == 1 else ans[::-1])

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

int main()
{
    int n;

    cin >> n;

    cout << n << ":";
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            cout << " " << i;
            n /= i;
        }
    }
    if (n != 1){
        cout << " " << n;
    }
    cout << endl;

    return (0);
}

Measured memory_bytes: 3088
#[allow(unused_imports)]
use {
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::ops::*,
};

fn main() {
    input! {
        n: usize,
        k: usize,
        xyc: [(usize, usize, char); n]
    }
    let mut map = vec![vec![0; 2 * k + 1]; k + 1];
    for (x, y, c) in xyc {
        let mut x = x;
        let mut y = y;
        if c == 'W' {
            x += k;
        }
        x %= 2 * k;
        y %= 2 * k;
        if x >= k {
            x -= k;
            y += k;
            y %= 2 * k;
        }
        map[x + 1][y + 1] += 1;
    }
    for x in 0..k {
        for y in 0..2 * k {
            map[x + 1][y + 1] += map[x + 1][y] + map[x][y + 1] - map[x][y];
        }
    }

    let mut ans = 0;
    for x in 0..=k {
        let sum = map[k][k] + map[x][2 * k] - 2 * map[x][k];
        ans = max(ans, max(n - sum, sum));
    }
    for y in 1..=k {
        let sum = map[k][y + k] - map[k][y];
        ans = max(ans, max(sum, n - sum));
        for x in 1..=k {
            let sum = map[k][y + k] - map[k][y] + map[x][2 * k] + 2 * map[x][y] - 2 * map[x][y + k];
            ans = max(ans, max(sum, n - sum));
        }
    }
    println!("{}", ans);
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int N;
string S;
const int INF = 1e9;

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

	cin >> S;
	N = S.size();

	int ans = 0;
	FOR(i,1,N){
		if(S [i] != S [i - 1]){
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include <cstdio>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

////Nayeem Shahriar Joy,Applied Physics &Electronic Engineering,University of Rajshahi.

int main()

{
   int a,b,d;
   while(cin>>a>>b)

   {
       d=a+b;
       int count=0;
       while(d!=0)
       {
           d=d/10;
           count++;
       }
       cout<<count<<endl;
   }
   return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
#define INF 2000000000
#define REP(i,b,n) for(int i = b; i < n; i++)
#define rREP(i,b,n) for(int i = n; i >= b; i--)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const string lowercase = "abcdefghijklmnopqrstuvwxyz";
const string uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int gcd(int a, int b){return b ? gcd(b, a % b): a;}

class UnionFind{
public:
    int *par, *rank;
    UnionFind(int n){
        par = new int[n];
        rank = new int[n];
        REP(i,0,n){
            par[i] = i;
            rank[i] = 0;
        }
    }
    int root(int x){
        return par[x]==x? x: par[x] = root(par[x]);
    }
    bool connected(int x, int y){
        return root(x)==root(y);
    }
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x==y) return;
        if(rank[x] < rank[y]) par[x] = y;
        else {
            par[y] = x;
            if(rank[x]==rank[y]) rank[x]++;
        }
        return;
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    vi p;
    REP(i,0,n){
        int k;
        scanf("%d ", &k);
        p.push_back(k);
    }
    UnionFind uf(n+1);
    REP(i,0,m){
        int x, y;
        scanf("%d %d", &x, &y);
        uf.unite(x, y);
    }

    int count = 0;
    REP(i,0,n) if(uf.connected(i+1, p[i])) count++;
    cout << count << endl;
    return 0;
}


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

int main(){
  int N, x;
  cin >> N >> x;
  int a[N];
  for (int i=0;i<N;i++) cin >> a[i];
  sort(a, a+N);

  int retval = 0, sum = 0;
  for (int i=0;i<N;i++){
    sum += a[i];
    
    if(sum==x){
     retval = i+1;
     break;
    }
    else if (sum > x || i==N-1){
      retval = i;
      break;
    }
  }

  cout << retval << endl;
}

Measured memory_bytes: 256