akhauriyash/Code-Regression huggingface dataset:
s=gets.chomp
t=gets.chomp
s.reverse!
t.reverse!
result=100
0.upto((s.length)-(t.length)) do |i|
    cnt=0
    chk="true"
    t.each_char do |char|
        if s[i+cnt] == "?" || s[i+cnt]=="#{char}" 
            cnt +=1
        else
            chk="false"
            break
        end
    end
    if chk=="true"
        result=i
        break
    end
end

if result==100
    puts "UNRESTORABLE"
else
    s[result,t.length]="#{t}"
    if s["?"]
    s.gsub!(/\?/,"a")
    end
    s.reverse!
    puts s
end

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

#define sz size

const int N = 1e3 + 123;

int n, a[N][N];
bool usd[N];

bool check(int v) {
	int cnt = 0;
	for(int i = 1; i <= 3; ++i) {
		if(usd[a[v][i]]) ++cnt;
	}
	if(cnt == 3) return 1;
	cnt = 0;
	for(int i = 1; i <= 3; ++i) {
		if(usd[a[i][v]]) ++cnt;
	}
	if(cnt == 3) return 1;
	return 0;
}
int main() {
	//freopen("input.txt", "r", stdin);
	for(int i = 1; i <= 3; ++i) {
		for(int j = 1; j <= 3; ++j) {
			cin >> a[i][j];
		}
	}
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		int k;
		cin >> k;
		usd[k] = 1;
	}
	for(int i = 1; i <= 3; ++i) {
		if(check(i)) {
			cout << "Yes";
			return 0;
		}
	}
	int cnt = 0;
	for(int i = 1; i <= 3; ++i) {
		if(usd[a[i][i]]) ++cnt;
	}	
	if(cnt == 3) {
		cout << "Yes";
		return 0;
	}
	cnt = 0;
	for(int i = 1; i <= 3; ++i) {
		if(usd[a[3 - i + 1][i]]) ++cnt;
	}	
	if(cnt == 3) {
		cout << "Yes";
		return 0;
	}
	cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> vec(50);

int solve(int i,int m,int n){
  if(m == 0) return 1;
  if(i >= n) return 0;

  int res = solve(i+1,m,n) || solve(i+1,m-vec.at(i),n);
  return res;
}

int main(){
  int q,m,i,n;

  cin >> n;
  for(i=0;i<n;++i){
    cin >> vec.at(i);
  }

  cin >> q;
  for(i=0;i<q;++i){
    cin >> m;
    if(solve(0,m,n)){
      cout << "yes" << endl;
    }else{
      cout << "no" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main(){
	string s;
	int a[26]={0},i,f=0;
	cin >> s;
	for(i=0;i<s.size();i++){
		a[s[i]-'a']++;
		if(a[s[i]-'a']>1){
			f=1;
			break;
		}
	}
	if(f)
		cout << "no\n";
	else
		cout << "yes\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include "math.h"

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int A,B;
string S;





int main()
{

	cin >> A >> B;
	cin >> S;


	REP(i,A+B+1){
		if(i==A){
			if(S[i]!='-'){
				cout << "No";
				return 0;
			}
		}else if(!isdigit(S[i])){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";




}





Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll ans = 0;
	string s;
	cin >> s;
	rep(i, 0, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i]) {
			ans++;
		}
	}
	outn(ans);
	
	return 0;

}


Measured memory_bytes: 256
H, W, A, B = map(int, input().split())

m = 10**9 + 7

import functools
@functools.lru_cache(maxsize=None)
def cr(c, r):
    return fc[c + r] * ic[c] * ic[r] % m

fc = [1] * (H + W)
for i in range(2, H+W):
    fc[i] = fc[i - 1] * i % m
ic = [pow(x, m-2, m) for x in fc]

ans = 0
for c in range(B, W):
    ans += cr(c, H - 1 - A) * cr(W - 1 - c, A - 1) % m
print(ans % m)

Measured memory_bytes: 81912
#include<iostream>
bool count=false;
int student;
bool sdnt[30]={false};
int main(){
for(int i=0;i<28;i++){
		std::cin>>student;
		for(int j=1;j<=30;j++){
			if(student==j)
				sdnt[j]=true;
		}
	}
	for(int i=1;i<31;i++){
		if(sdnt[i]==false)
			std::cout<<i<<std::endl;
	}
}

Measured memory_bytes: 1164
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as BS

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile (== ' ')) <$> BS.getLine

mod' :: Integral a => a -> a
mod' n = if n < 1000000007 then n else n `mod` 1000000007

f :: V.Vector Int -> [Int] -> Int
f cs (a:aa:as) = if (a+1) == aa then (cs V.! (a-1)) + (f cs (aa:as)) else f cs (aa:as)
f _ _ = 0

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- getIntList
  bs <- getIntList
  cs <- V.fromList <$> getIntList
  print $ (f cs as) + (sum bs)


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

#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 998244353 
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

int main(){
	boost;

	int n;
	cin>>n;
	int arr[n],b[n],c[n];

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

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

	for (int i = 0; i < n-1; ++i)
	{
		cin>>c[i];
	}
	ll ans = 0;

	for(int i=0;i<n;i++){
		if(i==0){
			ans = ans + b[arr[i]-1];
		}else{
			if(arr[i]-1==arr[i-1]){
				ans = ans + c[arr[i-1]-1] + b[arr[i]-1];
			}else{
				ans = ans + b[arr[i]-1];
			}
		}
		//cout<<ans<<endl;
	}

	cout<<ans;


	return 0;
}

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

#define Int long long int
#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ma=max(a,max(b,c));
    int en;
    if(a%2==b%2 && b%2==c%2){
        en=0;
    }else if(ma%2==(a+b+c)%2){
        en=1;
    }else{
        ma++;
        en=1;
    }

   en+=(ma-a)/2;
   en+=(ma-b)/2;
   en+=(ma-c)/2;

   cout << en << endl;

}


Measured memory_bytes: 256
#include <stdio.h>

struct vector {
	double x;
	double y;
};

void arePerpendicular(struct vector a, struct vector b, struct vector c, struct vector d);

int main(int argc, const char *argv[])
{
	struct vector a, b, c, d;

	while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &d.x, &d.y)!=EOF)
		arePerpendicular(a, b, c, d);

	return 0;
}

void arePerpendicular(struct vector a, struct vector b, struct vector c, struct vector d)
{
	if((a.x-b.x)*(c.x-d.x)+(a.y-b.y)*(c.y-d.y)) printf("NO\n");
	else printf("YES\n");
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define LLI long long int
#define pii pair<int,int>
#define fst first
#define sec second
#define ULTRA 2134567890
#define MOD 1000000007
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

LLI a[107][57][57] = {};
LLI dp[57] = {};
LLI M[107][57][57] = {};
LLI N,K;

void prepare() {
    int i,j;

    for( i=0; i<64; i++) {
        for( j=0; j<N; j++) {
            for( int k=0; k<N; k++) {
                for( int h=0; h<N; h++) {
                    a[i+1][j][k] += a[i][j][h] * a[i][h][k];
                    a[i+1][j][k] %= MOD;
                }
            }
        }
    }
    for( i=0; i<N; i++)
        dp[i] = 1;
}

void mul( LLI mtx[57][57], LLI arr[]) {

    int i,j;
    LLI tmp[57] = {};
    for( i=0; i<N; i++) {
        for( j=0; j<N; j++) {
            tmp[i] += mtx[i][j] * arr[j];
            tmp[i] %= MOD;
        }
    }

    for( i=0; i<N; i++) {
        arr[i] = tmp[i];
    }
}

int main() {

    int i,j;

    cin >> N >> K;
    for( i=0; i<N; i++) {
        for( j=0; j<N; j++)
            cin >> a[0][i][j];
    }
    prepare();
    for( i=0; i<64; i++) {
        if( K & (1LL<<i)) {
            mul( a[i], dp);
        }
    }

    LLI ans = 0;
    for( i=0; i<N; i++) {
        ans = ( ans + dp[i]) % MOD;
    }
    printf("%lld\n", ans);

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<bool>> graph(n, vector<bool>(n, true));
    for (int i = 0; i < n; i++)graph[i][i] = false;
    for (int i = 0; n / 2 * 2 - (i + 1) >= 0; i++) graph[i][n / 2 * 2 - (i + 1)] = false;
    int count = 0;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            if (graph[i][j])count++;
    cout << count << endl;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            if (graph[i][j])cout << i + 1 << " " << j + 1 << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n>>m;
    cout << max(0LL,n-2*m) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200001;
int n;
int a[N];
long long suma,sumb,j;//要用long long
long long s;//要用long long，因为最多可能性为20000100000
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		while(suma+a[j+1]==(sumb^a[j+1])&&j+1<=n)//位运算加括号，因为运算级别较低 
		{
			suma=suma+a[j+1];
			sumb=(sumb^a[j+1]);
			j++;
		}
		s=s+j-i+1;
		suma=suma-a[i];
		sumb=(sumb^a[i]);
	}
	cout<<s; 
	return 0;
}

Measured memory_bytes: 4516
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;


const int max_n = 100;
const int max_v = 1000;
int main(){
  //input
  ll n, w;
  cin >> n >> w;
  vector<ll> weight(n), value(n);
  rep(i,n) cin >> weight[i] >> value[i];
  
  //initialization
  ll dp[max_n+1][max_n*max_v+1];
  rep(i,max_n+1){
    rep(j,max_n*max_v+1){
      dp[i][j]=INF;
    }
  }
  dp[0][0]=0;
  //compute
  rep(i,n){
    rep(j,max_n*max_v+1){
		if(j-value[i]>=0) dp[i+1][j]=min(dp[i][j],dp[i][j-value[i]]+weight[i]);
        else dp[i+1][j]=dp[i][j];
    }
  }
  
  //output
  ll res=0;
  rep(i,max_n*max_v+1){
    if(dp[n][i]<=w){
      res = i;
    }
  }
  cout << res << endl;
}
    


Measured memory_bytes: 79104
# ABC159 A

import math

def main():
    n, m = map(int, input().split())
    
    if n >= 2 and m >= 2:
        even = math.factorial(n) // (math.factorial(n-2) * math.factorial(2))
        odd = math.factorial(m) // (math.factorial(m-2) * math.factorial(2))
    elif m >= 2:
        even = 0
        odd = math.factorial(m) // (math.factorial(m-2) * math.factorial(2))
    elif n >= 2:
        even = math.factorial(n) // (math.factorial(n-2) * math.factorial(2))
        odd = 0
    else:
        even = 0
        odd = 0

    print(even + odd)

if __name__ == '__main__':
    main()

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

int main() {
  int N, K;
  int t = 1;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    if((t * 2) <= (t + K)){
      t *= 2;
    }else{
      t += K;
    }
  }
  cout << t << endl;
} 


Measured memory_bytes: 256
N = int(input())
a = [int(i) for i in input().split()]
count = 0

while True:
    odd = True
    for i in a:
        if i % 2 != 0:
            odd = False
            break

    if odd:
        for i in range(len(a)):
            a[i] = a[i] / 2
        count += 1
        continue
    else:
        break

print(count)


Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val s = Scanner(System.`in`)
    val a = s.nextLong()
    val b = s.nextLong()


    fun xors(v: Long): Long {
        var d = 0L
        (1..50).forEach { i ->
            val t = 1L shl i
            val mod = v % t
            val count = Math.max(mod - t / 2 + 1, 0) + (if (i == 1) v / t else 0)
            val f = count % 2L

            d = d or (f shl (i - 1))
        }
        return d
    }

    val ret = xors(b) xor xors(Math.max(a - 1, 0))
    println(ret)
}

Measured memory_bytes: 31392
n=int(input())
a=list(map(int,input().split()))
M=max(a)
num=[0]*M
for x in a:
	num[x-1]+=1
for i in range(M):
	if num[i]>=2:
		num[i]=2
ret=num.copy()
for i in range(M):
	if num[i]:
		j=i+i+1
		while j<M:
			ret[j]=0 
			j+=i+1
	if num[i]==2:
		ret[i]=0
print(ret.count(1))


Measured memory_bytes: 34988
h,w = map(int,input().split())
C = [list(map(int,input().split())) for i in range(10)]
A = [list(map(int,input().split())) for i in range(h)]
inf = float('inf')
cost = 0
D = [[inf]*10 for i in range(10)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            D[i][j] = min(C[i][j],C[i][k]+C[k][j])
for k in range(10):
    for i in range(10):
        for j in range(10):
            D[i][j] = min(D[i][j],D[i][k]+D[k][j])

for y in range(h):
    for x in range(w):
        if A[y][x] == -1 or A[y][x] == 1:
            continue
        else:
            cost += D[A[y][x]][1]

print(cost)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	int N, K, d, tempSnuke;
	cin>>N>>K;
	unordered_set<int> st;
	for(int i=0; i<K;i++)
	{
		cin>>d;
		for(int i=0; i<d;i++)
		{
			cin>>tempSnuke;
			st.insert(tempSnuke);
		}
	}
	int ans = abs((int)st.size()-N);
	cout<<max(0, ans);
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int a,b;
	cin >> a >> b;
	int sub = b - a;
	int sum = (sub*(sub+1))/2;
	cout << sum - b << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <deque>
#include <vector>
typedef unsigned int UINT;
using namespace std;

int main(void) {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int area1 = A * B;
    int area2 = C * D;
    int ans = (area1 > area2) ? area1 : area2;
    cout << ans << endl;

    return 0;
}

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

int main() {
	ll N, Ma, Mb;
	ll Max_Ai, Max_Bi, Max_C;
	Max_Ai = Max_Bi = 407;
	Max_C = 5000;

	cin >> N >> Ma >> Mb;

	vector< vector<ll> > dp(Max_Ai + 1, vector<ll>(Max_Bi + 1, Max_C));
	dp[0][0] = 0;
	for (ll i = 0; i < N; ++i) {
		ll a, b, c;
		cin >> a >> b >> c;
		for (ll ai = Max_Ai; ai >= a; --ai) {
			for (ll bi = Max_Bi; bi >= b; --bi) {
				dp[ai][bi] = min(dp[ai][bi], dp[ai - a][bi - b] + c);
			}
		}
	}

	ll ret = Max_C;
	for (ll ai = 1; ai < Max_Ai + 1; ++ai) {
		for (ll bi = 1; bi < Max_Bi + 1; ++bi) {
			if (ai * Mb == bi * Ma && dp[ai][bi] < ret) ret = dp[ai][bi];
		}
	}
	if (ret == Max_C) ret = -1;
	cout << ret << endl;
}


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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define fk first
#define sv second

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

  cin >> str;

  cout << str[0] << str.length() - 2 << str[str.length() - 1] << endl;
}

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

int main() {
    int n, m, k, ans = 0;
    cin >> n >> m;
    vector<int> p(m);
    vector<vector<int>> light(m);
    rep(i, m) {
        cin >> k;
        light.at(i).resize(k);
        rep(j, k) cin >> light.at(i).at(j);
    }
    rep(i, m) cin >> p.at(i);
    rep(i, pow(2, n)) {
        vector<int> temp(n, 0);
        rep(j, n) {
            if(1 & (i >> j)) temp.at(j) = 1;
        }
        bool flag = true;
        rep(j, m) {
            int cnt = 0;
            rep(t, light.at(j).size()) cnt += temp.at(light.at(j).at(t) - 1);
            if(cnt % 2 != p.at(j)) flag = false;
        }
        if(flag) ans++;
    }
    cout << ans << endl;
}

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

int main() {
	long long n, k;
	cin >> n >> k;
	vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		A[i]--;
	}
	int a, b;
	vector<int> order(n, -1);
	for (int i = 0, x = 0; ; i++) {
		if (order[x] != -1) {
			a = order[x];
			b = i;
			break;
		}
		order[x] = i;
		x = A[x];
	}
	const int t = b - a;

	int l = 0, x = 0;
	for (; l < a && l < k; l++) {
		x = A[x];
	}
	k -= l;

	k %= t;
	for (int i = 0; i < k; i++) {
		x = A[x];
	}
	cout << x+1 << endl;
	return 0;
}

Measured memory_bytes: 4468
import itertools
import math
N = int(input())
NL = [i for i in range(N)]
xy = [list(map(int,input().split())) for _ in range(N)]
length = [[0 for _ in range(N)] for i in range(N)]
C = list(itertools.combinations(NL,2))
for c in C:
    length[c[0]][c[1]] = math.sqrt((xy[c[0]][0]-xy[c[1]][0])**2+(xy[c[0]][1]-xy[c[1]][1])**2)
    length[c[1]][c[0]] = length[c[0]][c[1]]
P = list(itertools.permutations(NL,N))
lenglist = []
for p in P:
    leng = 0
    for i in range(len(p)-1):
        leng += length[p[i]][p[i+1]]
    lenglist.append(leng)
print(sum(lenglist)/len(P))

Measured memory_bytes: 9252
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
const int N=1e5+2;
int n,inv[2],flip[2],pos[N],map[3][N];
struct B_I_T{
	int tr[N];
	inline void init(){
		memset(tr,0,sizeof(tr));
	}
	inline void add(int x,int v){
		for(;x<=n;x+=x&-x){
			tr[x]+=v;
		}
	}
	inline int ask(int x){
		int ans=0;
		for(;x;x-=x&-x){
			ans+=tr[x];
		}
		return ans;
	}
	inline void mod(const int x,const int y,const int v){
		if(x>y) return;
		add(x,v);
		add(y+1,-v);
	}
}ad;

inline bool conts(const int x,const int y,const int z){
	if(x<z) return y==x+1&&z==y+1;
	return x==y+1&&y==z+1;
}

inline char get_c(){
	static char buf[20000],*h,*t;
	if(h==t){
		t=(h=buf)+fread(buf,1,20000,stdin);
	}
	return h==t?EOF:*h++;
}

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10+c-48,(c=getchar())>='0'&&c<='9');
	return x;
}

int main(){
#ifndef ONLINE_JUDGE
//	freopen("b.in","r",stdin);
#endif
	n=nxi();
	for(int i=0;i<3;++i){
		for(int j=1;j<=n;++j){
			map[i][j]=nxi();
		}
	}
	for(int i=1;i<=n;++i){
		int x=map[0][i],y=map[1][i],z=map[2][i],w=x>z?x:z;
		if(!conts(x,y,z)||w%3){
			puts("No");
			return 0;
		}
		if((i-w/3)&1){
			puts("No");
			return 0;
		}
		if(z!=w) inv[i&1]^=1;
		pos[w/3]=i;
	}
	for(int i=1;i<=n;i+=2){
		int p=pos[i],add=ad.ask(p);
		flip[1]=(flip[1]+(abs(p+add-i)>>1))&1;
		ad.mod(1,p,2);
	}
	ad.init();
	for(int i=2;i<=n;i+=2){
		int p=pos[i],add=ad.ask(p);
		flip[0]=(flip[0]+(abs(p+add-i)>>1))&1;
		ad.mod(1,p,2);
	}
	if((flip[0]-inv[1])&1||(flip[1]-inv[0])&1) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
#define min(a, b) ((a)<(b) ? (a) : (b))
int main(){
  int n;  scanf("%d", &n);
  int b[103];
  for(int i=0; i<n-1; i++)
    scanf("%d", &b[i]);
  int a[104];
  a[0] = b[0];
  for(int i=1; i<n-1; i++)
    a[i] = min(b[i-1], b[i]);
  a[n-1] = b[n-2];

  int ans = 0;
  for(int i=0; i<n; i++)
    ans += a[i];

  printf("%d\n", ans);
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> B(N);
    for (int i = 0; i < N; i++) cin >> B[i];
    vector<int> ans;
    for (int i = 0; i < N; i++) {
        for (int j = B.size() - 1; j >= 0; j--) {
            if (B[j] == j + 1) {
                ans.push_back(B[j]);
                B.erase(B.begin() + j);
                break;
            }
        }
    }
    if (ans.size() != N) {
        cout << -1 << endl;
        return 0;
    }
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=998244353;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int n;
struct BIT
{
    int n,t[1000005],lg;
    void pre(int nn){
        n = nn;
        while((1<<lg) < n) lg++;
    }
    void update(int x,int y){
        while(x <= n) {
            t[x] += y;
            x += x & (-x);
        }
    }
    int get(int x){
        int res = 0;
        while(x){
            res += t[x];
            x -= x & (-x);
        }
        return res;
    }
    int find(int x){
        int res = 0;
        per(i,lg,0) {
            if(res + (1<<i) > n) continue;
            int cur = t[res + (1<<i)];
            if(x > cur) {
                res += 1<<i;
                x -= cur;
            }
        }
        return res + 1;
    }
}tr;
pii a[200005];
map<int,int> X,Y;
int cntX,cntY;
int ax[200005];
int dl[200005],dr[200005],ul[200005],ur[200005];
int pw[200005];
int ans;
int main()
{
    scanf("%d",&n);
    rep(i,1,n) {
        scanf("%d%d",&a[i].fi,&a[i].se);
        X[a[i].fi] = 0;
        Y[a[i].se] = 0;
    }
    pw[0] = 1;
    rep(i,1,n) pw[i] = pw[i - 1] * 2 % mod;
    itrm(it,X) it->se = ++cntX;
    itrm(it,Y) it->se = ++cntY;
    tr.pre(n+1);
    rep(i,1,n) a[i].fi = X[a[i].fi];
    rep(i,1,n) a[i].se = Y[a[i].se];
    rep(i,1,n) ax[a[i].se] = a[i].fi;
    per(i,n,1) {//y position
        ul[i] = tr.get(ax[i]);
        ur[i] = n - i - ul[i];
        dl[i] = ax[i] - 1 - ul[i];
        dr[i] = i - 1 - dl[i];
        //printf("%d %d %d %d\n",ul[i],ur[i],dl[i],dr[i]);
        tr.update(ax[i], 1);
    }
    rep(i,1,n) {
        rap(j,0,16) {
            if(((j & 5) == 5) || ((j & 10) == 10)) {
                int cur = 1;
                if(j & 1) cur = cur * (pw[ul[i]] - 1);
                if(j & 2) cur = (ll)cur * (pw[ur[i]] - 1) % mod;
                if(j & 4) cur = (ll)cur * (pw[dr[i]] - 1) % mod;
                if(j & 8) cur = (ll)cur * (pw[dl[i]] - 1) % mod;
                //printf("%d %d %d\n",i,j,cur);
                ans += cur;if(ans >= mod) ans -= mod;
            }
        }
        ans += pw[n - 1];if(ans >= mod) ans -= mod;
    }
    printf("%d\n",ans);
    return 0;
}

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

static const int INF = 1145141919;

int main()
{
	int n;
	cin >> n;
	int h[100001];
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}
	int dp[100001];
	for (int i = 0; i < n; ++i)
	{
		dp[i] = INF;
	}
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < n; ++i)
	{
		dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll lcm(ll a, ll b){
  if(a<b) swap(a,b);
  while(true){
    if(a%b==0) return b;
    else{
      ll c=a%b;
      a=b;
      b=c;
    }
  }
}
ll gcd(ll a, ll b){
  return a/lcm(a,b)*b;
}
int main(){
  int n;
  cin>>n;
  ll a,b;
  cin>>a;
  for(int i=1;i<n;i++){
    cin>>b;
    a=gcd(a,b);
  }
  cout<<a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ld long double
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define mp map<ll, ll>
#define um unordered_map<ll, ll>
#define st set<ll> 
#define us unordered_set<ll>
#define vt vector<ll>
#define pll pair<ll, ll>
#define fl(i, x, y) for(ll i=x;i<y;++i)
#define flr(i, x, y) for(ll i=x;i>=y;--i)

int main()
{
    ll n;
    cin>>n;
    ll a[n],ans=0;
    fl(i, 0, n)
    {
        cin>>a[i];
        ans+=(a[i]-1);
    }        
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

#define HW( x, y ) (( ( long long )x << 32 ) + y )

static int s_cmp( const void *lhs, const void *rhs )
{
	long long l = *( const long long * )lhs;
	long long r = *( const long long * )rhs;

	if ( l < r )
	{
		return -1;
	}
	else if ( l > r )
	{
		return 1;
	}

	return 0;
}

#define S_PRIME 9999991

	int H;
	int W;
	int M;
	int h[ 300000+1 ] = { 0, };
	int w[ 300000+1 ] = { 0, };
	vector<long long> hw;
	int max_m = 0;

int main()
{

	cin >> H >> W >> M ;

	int max_h = 0;
	int max_w = 0;
	for ( int i = 1; i <= M; i++ )
	{
		int hi;
		int wi;

		cin >> hi >> wi;
		h[ hi ] ++;
		if ( max_h < h[ hi ] )
		{
			max_h = h[ hi ];
		}
		w[ wi ] ++;
		if ( max_w < w[ wi ] )
		{
			max_w = w[ wi ];
		}

		hw.push_back( HW( hi, wi ) );
	}
	int max_m = max_h + max_w;

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

	vector<int> max_i;
	vector<int> max_j;
	for ( int i = 1; i <= (( H > W ) ? H : W); i++ )
	{
		if ( max_h == h[ i ] )
		{
			max_i.push_back( i );
		}

		if ( max_w == w[ i ] )
		{
			max_j.push_back( i );
		}
	}

	if ( max_i.size() * max_j.size() > M )
	{
		cout << max_m << endl;
		return 0;
	}

	for ( vector<int>::iterator it_i = max_i.begin(); it_i != max_i.end(); it_i++ )
	{
		for ( vector<int>::iterator it_j = max_j.begin(); it_j != max_j.end(); it_j++ )
		{
			if ( !binary_search( hw.begin(), hw.end(), HW( *it_i, *it_j ) ) )
			{
				cout << max_m << endl;
				return 0;
			}
		}
	}

	// bomb on target (add both in h and in w)
	max_m--;

	cout << max_m << endl;

	return 0;
}


Measured memory_bytes: 12656
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI3(A, B, C);
  GI(X);
  int ans = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        if (a * 500 + b * 100 + c * 50 == X) {
          ans++;
        }
      }
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d)
	{
		cout<<"Left"<<endl;
	}
	else if(c+d>a+b)
	{
		cout<<"Right"<<endl;
	}
	else
	{
		cout<<"Balanced"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import numpy as np

n = input()
a = list(map(int, input().split()))
cnt=0
cnt_list = np.zeros(int(n))
for i in range(len(a)):
    while a[i]%2 == 0:
        cnt+=1
        a[i] = a[i]/2
    cnt_list[i]=cnt
    cnt=0


print(int(min(cnt_list)))

Measured memory_bytes: 12424
#include <bits/stdc++.h>
#define maxn 101000
#define intl long long
using namespace std;

intl p[maxn * 2];
intl L[maxn], R[maxn];
intl now, offsetl, offsetr;
int n, top;

struct cmp {
	bool operator () (int a, int b) {
		return (p[a] > p[b] || (p[a] == p[b] && a < b));
	}
};

set<int, cmp> ldot;

struct pmc {
	bool operator () (int a, int b) {
		return (p[a] < p[b] || (p[a] == p[b] && a < b));
	}
};

set<int, pmc> rdot;

int main() {
	scanf("%d",&n);
	for (int i = 1; i <= n; i++)
		scanf("%lld %lld",&L[i], &R[i]);
	p[++top] = L[1]; ldot.insert(top);
	p[++top] = L[1]; rdot.insert(top);
	now = 0;
	for (int i = 2; i <= n; i++) {
		intl pas = now;
		intl x = L[i];
		offsetl -= (R[i] - L[i]);
		offsetr += (R[i - 1] - L[i - 1]);
		if (x >= p[*ldot.begin()] + offsetl && x <= p[*rdot.begin()] + offsetr) {
			p[++top] = x - offsetl;
			ldot.insert(top);
			p[++top] = x - offsetr;
			rdot.insert(top);
			now = pas;
		}
		else if (x < p[*ldot.begin()] + offsetl) {
			p[++top] = x - offsetl;
			ldot.insert(top);
			p[++top] = x - offsetl;
			ldot.insert(top);
			now = pas + (intl) (p[*ldot.begin()] + offsetl - x);
			int k = *ldot.begin();
			ldot.erase(ldot.begin());
			p[k] += offsetl - offsetr;
			rdot.insert(k);
		} else {
			p[++top] = x - offsetr;
			rdot.insert(top);
			p[++top] = x - offsetr;
			rdot.insert(top);
			now = pas + (intl) (x - p[*rdot.begin()] - offsetr);
			int k = *rdot.begin();
			rdot.erase(rdot.begin());
			p[k] += offsetr - offsetl;
			ldot.insert(k);
		}
	}

	cout << now << endl;
	return 0;
}

Measured memory_bytes: 12800
import math

def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n /= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff


def divisor_num(n):
    a = 1
    for _, x in factorization(n):
        a *= x + 1
    return a

N = int(raw_input())

s = math.factorial(N)
x = divisor_num(s)
z = 1000000007

if x > z:
    ans = x%z
else:
    ans = x


print ans


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

int N, M, K;

// Union-Find
vector<int> par(100010); //親の番号
vector<int> sz(100010);

// 初期化
void init(int n){
  for(int i=0; i<n; i++){
    par[i] = i;
    sz[i] = 1;
  }
}

// 頂点xに対応する木の根を見つける
int root(int x){
  if (par[x] == x){
    return x;
  } else {
    return par[x] = root(par[x]);
  }
}

// 頂点xの木と頂点yの木を統合
void unite(int x, int y){
  x = root(x); y = root(y);
  if (x == y) return;

  int total = sz[x]+sz[y];
  sz[x] = total; sz[y] = total;
  
  par[x] = y;
}

bool same(int x, int y){
  return (root(x) == root(y));
}

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

  vector<int> friends(100010, 1);

  for(int i=0; i<M; i++){
    int a, b; cin >> a >> b; a--; b--;
    unite(a,b);
    friends[a]++;
    friends[b]++;
  }

  for(int i=0; i<K; i++){
    int a, b; cin >> a >> b; a--; b--;
    if(same(a,b)){
      friends[a]++;
      friends[b]++;
    }
  }

  for(int i=0; i<N; i++){
    cout << sz[root(i)] - friends[i] << " ";
  }
  cout << endl;
}

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


def solve(N: int, A: "List[int]"):
    l = [None] * N
    for i in range(0, N):
        l[A[i] - 1] = str(i + 1)
    print(" ".join(l))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22064
#include<cstdio>
using namespace std;
int main()
{
	int n,i,k,a,cnt;
	scanf("%d %d",&n,&k);
	cnt=0;
	for(i=0;i<n;i++){
		scanf("%d",&a);
		if(a>=k)	cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cstdio>
#define ll long long int
#define mod 1000000007
#define pi 3.141592653589793
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define vfind(a, e) find(a.begin(), a.end(), e)
#define forr(i, n) for (ll i = 0; i < n; i++)
#define rfor(i, n) for (ll i = n - 1; i >= 0; i--)
#define fors(i, b, e, steps) for(ll i = b; i < e; i += steps)
#define rfors(i, e, b, steps) for(ll i = e; i > b; i -= steps)
#define mp make_pair
using namespace std;


bool isVowel(char c){
    return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}

bool isLower(char c){
    return 97 <= c && c <= 122;
}

void mul(ll a[2][2], ll b[2][2]) {
    ll p = a[0][0] * b[0][0] + a[0][1] * b[1][0];
    ll q = a[0][0] * b[0][1] + a[0][1] * b[1][1];
    ll r = a[1][0] * b[0][0] + a[1][1] * b[1][0];
    ll s = a[1][0] * b[0][1] + a[1][1] * b[1][1];

    a[0][0] = p % mod;
    a[0][1] = q % mod;
    a[1][0] = r % mod;
    a[1][1] = s % mod;
}



int main() {
    // cout << setprecision(30);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll n;
    cin >> n;
    vector<ll> a;
    ll e;
    cin >> e;
    a.pb(e);
    forr(i, n - 1) {
        cin >> e;
        if (e != a.back()) {
            a.pb(e);
        }
    }

    n = a.size();
    ll m = *max_element(a.begin(), a.end()) + 1;

    ll d[m], pre[m];
    fill (d, d + m, 0);
    fill (pre, pre + m, 0);
    pre[a[0]] = 1;
    d[a[0]] = 1;
    ll dp[n];
    dp[0] = 1;

    fors (i, 1, n, 1) {
        if (d[a[i]] == 0) {
            dp[i] = dp[i - 1];
        }

        else {
            dp[i] = dp[i - 1] + pre[a[i]];
            dp[i] %= mod;
        }

        d[a[i]]++;
        pre[a[i]] += dp[i - 1];
        pre[a[i]] %= mod;

    }


    cout << dp[n - 1];
}


//WA
//14
//1 2 3 1 4 5 6 7 4 8 9 10 11 8

//6
//1 2 1 3 4 3


Measured memory_bytes: 6640
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;

template<typename T>
class Heap
{
private:
  void maxHeapfy(int i)
  {
    int l, r, largest;
    l = left(i);
    r = right(i);

    if(l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if(r <= H && A[r] > A[largest]) largest = r;

    if(largest != i)
    {
      swap(A[i], A[largest]);
      maxHeapfy(largest);
    }
  }
public:
  int H; // ??????????????§??????
  vector<T> A;
  Heap(int n)
  {
    H = n;
    A.resize(n+1);
    A[0] = 0;
  }
  ~Heap(){}
  T* operator[](int i)
  {
    return &A[i];
  }
  int parent(int i) {return i/2;}
  int left(int i) {return 2*i;}
  int right(int i) {return 2*i+1;}
  void printInfo(int i)
  {
    cout << "node " << i << ": key = " << A[i] << ", ";
    if(parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
    if(left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
    if(right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }
  void buildMaxHeap(){for(int i = H/2; i >= 1; i--) maxHeapfy(i);}
};

int main()
{
  int H; cin >> H;
  Heap<int> T(H);
  for(int i = 1; i <= H; i++) scanf("%d", T[i]);
  T.buildMaxHeap();
  for(int i = 1; i <= H; i++) cout << " " << *T[i];
  cout << endl;
  return 0;
}

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

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ff first
#define ss second

using namespace std;

const double pi = acos(-1);
const int N = 1e6 + 6, mod = 998244353, M = 1e7 + 7;
const ll MAX = 5e18;

int a, b;

int main()
{
    cin >> a >> b;
    cout << max(0, a - 2 * b);

    return 0;
}


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

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


def solve(S: str):
    if S=='AAA' or S=='BBB':
        print(NO)
    else:
        print(YES)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

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




int main() {
	int n; cin >> n;
	int count = 0,total=0;

	for (int j=1;j<=n;j++){
		count = 0;
		for (int i = 1; i <= 200; i=i+2) {
			if (j % i == 0) count++;
		}
		if (count == 8) total++;
	}

	cout << total << endl;

	return 0;
}

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

const vector<int> dx = {-1, 0, 1, 0};
const vector<int> dy = {0, -1, 0, 1};

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

    vector<tuple<int, int, int>> lx, ly;
    map<int, int> x_to_gx, y_to_gy;

    for (int i = 0; i < N; i++)
    {
        int Ai, Bi, Ci;
        cin >> Ai >> Bi >> Ci;
        x_to_gx[Ai] = 0;
        x_to_gx[Bi] = 0;
        y_to_gy[Ci] = 0;
        lx.push_back({Ai, Bi, Ci});
    }
    for (int i = 0; i < M; i++)
    {
        int Di, Ei, Fi;
        cin >> Di >> Ei >> Fi;
        x_to_gx[Di] = 0;
        y_to_gy[Ei] = 0;
        y_to_gy[Fi] = 0;
        ly.push_back({Di, Ei, Fi});
    }

    x_to_gx[0] = 0;
    y_to_gy[0] = 0;

    map<int, int> gx_to_x, gy_to_y;
    for (auto &&p : x_to_gx)
    {
        p.second = gx_to_x.size() * 2;
        gx_to_x[gx_to_x.size() * 2] = p.first;
    }
    for (auto &&p : y_to_gy)
    {
        p.second = gy_to_y.size() * 2;
        gy_to_y[gy_to_y.size() * 2] = p.first;
    }

    int h = gx_to_x.size() * 2;
    int w = gy_to_y.size() * 2;
    vector<vector<int>> g(h, vector<int>(w));
    for (auto t : lx)
    {
        int Ai = get<0>(t), Bi = get<1>(t), Ci = get<2>(t);
        for (int i = x_to_gx.at(Ai); i <= x_to_gx.at(Bi); i++)
        {
            g.at(i).at(y_to_gy.at(Ci)) = -1;
        }
    }
    for (auto t : ly)
    {
        int Di = get<0>(t), Ei = get<1>(t), Fi = get<2>(t);
        for (int j = y_to_gy.at(Ei); j <= y_to_gy.at(Fi); j++)
        {
            g.at(x_to_gx.at(Di)).at(j) = -1;
        }
    }

    queue<pair<int, int>> q;
    q.push({x_to_gx.at(0), y_to_gy.at(0)});
    while (!q.empty())
    {
        int x = q.front().first, y = q.front().second;
        q.pop();
        for (int d = 0; d < 4; d++)
        {
            int nx = x + dx.at(d), ny = y + dy.at(d);
            if (nx < 0 || h <= nx || ny < 0 || w <= ny)
            {
                continue;
            }
            if (g.at(nx).at(ny) != 0)
            {
                continue;
            }
            g.at(nx).at(ny) = 1;
            q.push({nx, ny});
        }
    }

    // for (int i = 0; i < h; i++)
    // {
    //     for (int j = 0; j < w; j++)
    //     {
    //         if (g.at(i).at(j) == -1)
    //             cout << "#";
    //         else if (g.at(i).at(j) == 1)
    //             cout << "O";
    //         else
    //             cout << ".";
    //     }
    //     cout << endl;
    // }

    int64_t res = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (g.at(i).at(j) <= 0)
            {
                continue;
            }
            if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
            {
                cout << "INF" << endl;
                return 0;
            }
            if (i % 2 == 0 || j % 2 == 0)
            {
                continue;
            }
            int64_t ex = gx_to_x.at(i + 1) - gx_to_x.at(i - 1);
            int64_t ey = gy_to_y.at(j + 1) - gy_to_y.at(j - 1);
            res += ex * ey;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 144792
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;

int main() {
  int N, M;
  cin >> N >> M;
  int a, b;
  map<int, int> mp;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    if (mp.count(a))
      mp[a]++;
    else
      mp[a] = 1;
    if (mp.count(b))
      mp[b]++;
    else
      mp[b] = 1;
  }
  for (auto v : mp) {
    if (v.second % 2 == 1) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 7680
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define N 100010
void solve()
{
  int a,b,c,k;
  cin>>a>>b>>c>>k;
if(k<=a)
{
   cout<<k<<endl;
  return;
}
 else if(k<=a+b)
 {
    cout<<a<<endl;
    return;
 }
  else if(k<=a+b+c)
  {
    cout<<(k-a-b)*(-1)+a;
    return;
  }
    
}

int main()
{
    solve();
}


Measured memory_bytes: 3588
fun main() {
    val num = readLine()!!
    var pow = 1
    var rem = 0
    val rems = IntArray(2019)
    rems[0] = 1
    for (i in num.length - 1 downTo 0) {
        val d = num[i] - '0'
        rem = (rem + pow * d) % 2019
        pow = (pow * 10) % 2019
        rems[rem]++
    }
    var count = 0
    rems.forEach { i ->
        if (i > 1) {
            count += i * (i - 1) / 2
        }
    }
    println(count)
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c){
        cout << 1;
    }else if(a == b || b == c || c == a){
        cout << 2;
    }else{
        cout << 3;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 1e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n;
int a[100010];
vector<int> G[100010];
bool used[100010];

void input() {
    cin >> n;
    REP(i,n-1) {
        cin >> a[i];
        G[a[i]].pb(i + 2);
    }
}

int f(int k) {
    if (used[k]) return inf;
    used[k] = 1;
    if (sz(G[k]) == 0) return 0;
    vector<int> v;
    for (int i = 0; i < G[k].size(); i++) {
        v.pb(f(G[k][i]));
    }
    sort(v.begin(),v.end());
    int cnt = 0;
    for (int i = 0; i < v.size(); i++) {
        if (v[i] > cnt) {
            cnt = v[i] + 1;
        } else {
            cnt++;
        }
    }
    return cnt;
}

void solve() {
    cout << f(1) << endl;
}

int main(int argc, char *argv[]){
    input();
    solve();
    return 0;
}


Measured memory_bytes: 13952
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
r=0
for _ in range(n):
  a=list(map(int,input().split()))
  s=0
  for i in range(m):
    s+=a[i]*b[i]
  if s > -c:
    r+=1
print(r)

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

typedef long long ll;

int main() {
	ll k, a, b;
	scanf("%lld %lld %lld", &k, &a, &b);
	ll ans = k + 1;
	if (a < b && k >= a - 1) {
		ll t = ((k - (a - 1))) / 2;
		ans = max(ans, 1 + (k - t * 2) + (b - a) * t);
	} 
	printf("%lld\n", ans);
}

Measured memory_bytes: 256