akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    dp = [[0] * (W+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(1, W+1):
            if j - w[i] >= 0:
                dp[i+1][j] = max(
                    dp[i][j],
                    dp[i+1][j-1],
                    dp[i][j-w[i]] + v[i]
                )
            else:
                dp[i+1][j] = max(dp[i][j], dp[i+1][j-1])

    print(dp[-1][-1])


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
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)


if __name__ == '__main__':
    main()


Measured memory_bytes: 118768
N = int(input())
a = map(int, input().split(' '))
sort_a = sorted(a)

bucket = {}

for i in sort_a:
    if i not in bucket:
        bucket[i] = 1
    else:
        bucket[i] += 1

delete = 0
for key, value in bucket.items():
    if key < value:
        delete += value - key
    elif key > value:
        delete += value

print(delete)

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,n) for(int i=(int)(n-1);i>=0;--i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int H, W;
bool wall[50][50];
bool G[50][50][4];

const int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
const char dirchar[] = {'<', 'v', '>', '^'};

bool lefthand(int sx, int sy) {
    if (0 <= sx && sx < W && 0 <= sy && sy < H) {
        if (wall[sy][sx]) return true;
    } else {
        return true;
    }
    return false;
}

int main() {
    cin >> H >> W;
    int ix, iy, ox, oy, d;
    REP(y, H) REP(x, W) {
        char c;
        cin >> c;
        switch (c) {
        case 'G':
            ox = x;
            oy = y;
            break;
        case '#':
            wall[y][x] = true;
            break;
        case '.':
            break;
        default:
            ix = x;
            iy = y;
            d = find(dirchar, dirchar+4, c)-dirchar;
        }
    }

    set<pii> M;

    G[iy][ix][d] = true;
    M.insert({ix, iy});

    while (1) {
        int sx = ix + dx[d];
        int sy = iy + dy[d];
        if (0 <= sx && sx < W && 0 <= sy && sy < H && !wall[sy][sx]) {
            ix = sx;
            iy = sy;
            int shx = ix + dx[(d+3)%4];
            int shy = iy + dy[(d+3)%4];
            if (!lefthand(shx, shy)) {
                d = (d+3)%4;
            }
        } else {
            int shx = ix + dx[(d+3)%4];
            int shy = iy + dy[(d+3)%4];
            if (lefthand(shx, shy)) {
                d = (d+1)%4;
            } else {
                d = (d+3)%4;
            }
        }

        if (G[iy][ix][d]) {
            cout << -1 << endl;
            return 0;
        }
        G[iy][ix][d] = true;
        M.insert({ix, iy});
//        REP(y, H) {
//            REP(x, W) {
//                if (x == ix && y == iy) {
//                    LOG("%c", dirchar[d]);
//                } else {
//                    LOG("%c", wall[y][x] ? '#' : '.');
//                }
//            }
//            LOG("\n");
//        }
//        LOG("---------\n");
        if (ix == ox && iy == oy) break;
    }
    cout << M.size() << endl;
}

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


using namespace std;

bool chkpal(string s) {
    if (s.size() == 1)return true;
    if (s.front() == s.back())
        return chkpal(s.substr(1, s.size() - 2));
    return false;
}

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

    string hs = s.substr(0, s.size() / 2);

    if (hs != s.substr(s.size() / 2 + 1)) {
        cout << "No" << endl;
        return 0;
    }

    if (chkpal(s)) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 200000
using namespace std;
long long int aa[N], a[N];
long long int bb[N], b[N];
long long int n, m, k;

/** EDITORIAL **/

int main(){
    scanf("%d %d %d", &n, &m, &k);
    int inp;
    for (int i = 0; i < n; i++){
        scanf("%d", &aa[i]);
    }
    for (int i = 0; i < m; i++){
        scanf("%d", &bb[i]);
    }
    for (int i = 0; i < n; i++){
        a[i + 1] = a[i] + aa[i];
    }
    for (int i = 0; i < m; i++){
        b[i + 1] = b[i] + bb[i];
    }
    int ans = 0, j = m;
    for (int i = 0; i <= n; i++){
        if (a[i] > k)
            break;
        while (b[j] > k - a[i])
            j -= 1;
        ans = max(ans, i + j);
    }
    printf("%d", ans);
}


Measured memory_bytes: 10024
#include<stdio.h>
#include <string.h>
#include<algorithm>

using namespace std;

int main(void){
int N,i,j,k,m,cnt;
cnt=0;
  scanf("%d",&N);
int L[N];
for (i=0;i<N;i++){
	scanf("%d",&L[i]);
}
sort(L, L+N);
for(j=0;j<N;j++){
	for(k=j+1;k<N;k++){
		for(m=k+1;m<N;m++){
			if(L[m]<L[k]+L[j]){
				cnt++;
			}
		}
	}
}
printf("%d",cnt);
}

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

int min(int a, int b)
{
	if (a > b){
		return (b);
	}
	return (a);
}

int lose(int *ptr)
{
	int i, j;
	int temp[10];
	int sum;
	
	for (i = 0; i < 1 << 10; i++){
		for (j = 0; j < 10; j++){
			temp[j] = ptr[j];
		}
		for (j = 0; j < 10; j++){
			if (((i >> j) & 1) && (temp[j] >= 3)){
				temp[j] -= 3;
			}
		}
		
		for (j = 1; j <= 7; j++){
			while (temp[j] >= 1 && temp[j + 1] >= 1 && temp[j + 2] >= 1){
				temp[j]--;
				temp[j + 1]--;
				temp[j + 2]--;
			}
		}
		
		sum = 0;
		
		for (j = 1; j <= 9; j++){
			sum += temp[j];
		}
		if (sum == 0){
			return (0);
		}
	}
	
	return (-1);
}

int main(void)
{
	char str[14];
	char flag[10];
	int num[10], memo[10];
	int i, j;
	int ok;
	
	while (scanf("%s", str) != EOF){
		getchar();
		memset(num, 0, sizeof(num));
		memset(flag, 0, sizeof(flag));
		
		for (i = 0; i < 13; i++){
			num[str[i] - '0']++;
		}
		
		memcpy(memo, num, sizeof(num));
		
		for (i = 1; i <= 9; i++){
			memcpy(num, memo, sizeof(memo));
			if (num[i] < 4){
				memo[i]++;
				for (j = 1; j <= 9; j++){
					memcpy(num, memo, sizeof(memo));
					if (num[j] >= 2){
						num[j] -= 2;
						if (lose(num) == 0){
							flag[i] = 1;
							break;
						}
					}
				}
				
				memo[i]--;
			}
		}
		
		ok = 0;
		for (i = 1; i <= 9; i++){
			if (ok == 1 && flag[i] == 1){
				printf(" ");
			}
			if (flag[i] == 1){
				printf("%d", i);
				ok = 1;
			}
		}
		if (ok == 0){
			printf("0");
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<functional>
#include<map>
#include<math.h>
using namespace std;
#define int long long
typedef vector<int> vi;
typedef pair<int,int> pi;
#define pb push_back
#define mp make_pair
#define fr(i,s,e) for(int i=s; i<e; i++)
#define rf(i,s,e) for(int i=e; i>s; i--)
#define vfr(it, g1)  for (auto it = g1.begin(); it != g1.end(); it++)
#define pp pop_back
#define bs binary_search
#define ins insert
#define ln length
#define vsort(a) sort(a.begin(), a.end())
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rea(a,n)  for(int i=0; i<n; i++) cin>>a[i]
#define pra(a,n)  for(int i=0;i<n;i++) cout<<a[i]<<" "
#define lb lower_bound
#define ub upper_bound
#define lss bool operator < (const class_name& rhs) const {return object<rhs.object;}
#define grtr bool operator < (const class_name& rhs) const {return object>rhs.object;}
int32_t main()
{
    IOS;
    int s,w;
    cin>>s>>w;
    if(w>=s)
    cout<<"unsafe";
    else
    {
        cout<<"safe";
    }
    

}




Measured memory_bytes: 3644
n=int(input())
dic=dict()
for i in range(n):
    s=input()
    if s in dic:
        dic[s]+=1
    else:
        dic[s]=1
ans=[]
val=max(dic.values())
for kv in dic.items():
    if kv[1]==val:
        ans.append(kv[0])
ans=sorted(ans)
for a in ans:
    print(a)


Measured memory_bytes: 35536
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>

const int maxn = 1e5 + 20;

char s[maxn];
int n;
bool flag[maxn];
char ch[4][10] = {"dream", "dreamer", "erase", "eraser"};
int len[4] = {5, 7, 5, 6};

bool check(char *s1, char *s2, int l)
{
	for(int i = 0; i < l; i++)
	{
		if(s1[i] != s2[i]) return false;
	}
	
	return true;
}
int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	
	flag[0] = true;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 0; j < 4; j++)
		{
			if(i - len[j] >= 0 && flag[i - len[j]] && check(s + (i - len[j] + 1), ch[j], len[j]))
			{
				flag[i] = true;
				break;
			}
		}
	}
	
	puts(flag[n] ? "YES" : "NO");
	
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

// return x^n % mod
ll mod_pow(ll x, ll n, ll mod) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) {
      ret *= x;
      ret %= mod;
    }
    x = x*x % mod;
    n >>= 1;
  }
  return ret;
}

template< typename T >
T extgcd(T a, T b, T &x, T &y) {
  T d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1; y = 0;
  }
  return d;
}

// mを法としたときのaのモジュラ逆数を求める
template< typename T >
T mod_inverse(T a, T m) {
  T x, y;
  extgcd(a, m, x, y);
  return (m+x%m) % m;
}
// return nCk % mod
template< typename T >
T mod_comb(T n, T k, T mod) {
  T mul = 1, div = 1;
  for (T i = 0; i < k; i++) {
    mul *= (n-i);
    mul %= mod;
    div *= (i+1);
    div %= mod;
  }
  return mul * mod_inverse(div, mod) % mod;
}
int main() {
  const ll mod = (ll)1e9+7; 
  ll n, a, b;
  cin >> n >> a >> b;

  ll ans = mod_pow(2, n, mod)-1;
  ans = (ans-mod_comb(n, a, mod)+mod)%mod; 
  ans = (ans-mod_comb(n, b, mod)+mod)%mod; 
  ans %= mod;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
import java.io.PrintWriter
import java.util.*

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}


fun main() {
    val (N, M) = nextIntList()
    val A = PriorityQueue<Long>(compareByDescending { it })
    A.addAll(nextLongList())
    repeat(M) {
        A.add(A.poll() / 2)
    }
    println(A.sum())
}

Measured memory_bytes: 58504
/*
Original problem: https://atcoder.jp/contests/abc134/tasks/abc134_b
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const ll mod = 1e9+7;

namespace SOLVE {
    void main() {
        int n, d;
		cin >> n >> d;
		int can = 2 * d + 1;
		int ans = n % can == 0 ? n / can : n / can + 1;
		cout << ans << endl;
    }
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
 
	public static void main(String[] args) {
 
		Scanner scan = new Scanner(System.in);
 
		int L = scan.nextInt();
      
      double b = (double) L/3;
      
        double a =0;
        a = b*b*b;
        
        System.out.println(a);
    }
}

Measured memory_bytes: 36004
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long int mult = 1, num, input, status = 0;
    cin >> input;
    for(int i = 0; i < input; i++){
        cin >> num;
        
        if(num == 0){
            mult = 0;
        }
        if( num != 0 && mult > 1000000000000000000 / num ){
            status++;
        }
        if(status == 0){
            mult *= num;
        }


    }

    if( mult > 1000000000000000000 ){
        status++;
    }

    if(status != 0 && mult != 0){
        cout << -1 << endl;
    } else {
        //printf("%lf\n", pow(10, 18));
        cout << mult << endl;
    }

    return 0; 
}


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
ll Mod = 998244353;

int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n) cin >> d[i];
	if (d[0] != 0) { 
		cout << 0 << endl; return 0;
	}
	rep2(i, 1, n) {
		if (d[i] == 0) { cout << 0 << endl; return 0; }
	}
	ll ans = 1;
	sort(d.begin(), d.end());
	rep2(i,1, n) {
		if(d[i]-d[i-1]>1)  {cout << 0 << endl; return 0;}
	}
	vector<int> s(n, 0);
	int j = 0;
	int count = 1;
	
	rep2(i, 2, n) {
		if (d[i] != d[i - 1]) {
			s[j] = count;
			++j;
			count = 1;
		}
		else count++;
		if (i == n - 1) s[j] = count;
	}
	rep2(i, 1, n) {
		if (s[i] == 0) break;
		//ans = ans *ll(powl(s[i - 1], s[i]))% Mod;
		rep(j, s[i]) {
			ans *= s[i - 1];
			ans %= Mod;
		}
	}
	cout << ans << endl;
}
	

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

int main() {
	long long N;
	long long i;
	long long ans;
	//vector<long long> divisor;
	cin >> N;

	/*
	CFileTime cTimeStart, cTimeEnd;
	CFileTimeSpan cTimeSpan;
	cTimeStart = CFileTime::GetCurrentTime();
	*/

	for (i = 1LL; i*i <= N; ++i) {
		if (N%i != 0)
			continue;
		ans = N / i;
	}

	int digit = 0;
	while (ans > 0) {
		ans /= 10;
		digit++;
	}

	/*
	cTimeEnd = CFileTime::GetCurrentTime(); 
	cTimeSpan = cTimeEnd - cTimeStart;
	cout << "Process Time : " << cTimeSpan.GetTimeSpan()/10000 << "[ms]" << endl;
	*/

	cout << digit << endl;

	return 0;
}

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

int main() {
    int N, M;
    cin >> N;
    map<string, int> map;
    for (int i = 0; i < N; i++) {
        string tmp;
        cin >> tmp;
        map[tmp]++;
    }

    cin >> M;
    for (int i = 0; i < M; i++) {
        string tmp;
        cin >> tmp;
        map[tmp]--;
    }

    int ans = 0;
    for (auto i = map.begin(); i != map.end(); i++) {
        ans = max(ans, (*i).second);
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  ll n,k;
  cin>>n>>k;
  ll d=n%k;
  ll e=abs(d-k);
  cout<<min(d,e)<<endl;
return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var (N,T) = readLine()!!.split(" ").map(String::toLong)
    var input = readLine()!!.split(" ").map{x->x.toLong()}
    var ans = 0L
    (0..N-2).map{i->
         if(input[(i+1).toInt()]-input[i.toInt()]<T) ans+= input[(i+1).toInt()]-input[i.toInt()]
         else ans += T
    }
    println(ans+T)
        
}


Measured memory_bytes: 78640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}
int main(){
    ll n;cin >> n;
    ll ans=n*(n+1)/2*(n+2)/3;
    rep(i,n-1){
        ll a,b;cin >>a >> b;
        if(a>b)swap(a,b);
        ans-=a*(n-b+1);
    }
    cout << ans <<endl;
}   

Measured memory_bytes: 3596
N = int(input())
A = list(map(int, input().split()))

B = sorted(A, reverse=True)
C = []
d = len(B)


for i in range(d-1):
  C.append(B[i]-B[i+1])
  
E = sorted(C)

if E[0] == 0:
  print("NO")
  
else:
  print("YES")

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

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            // string s = Console.ReadLine();

            // 整数の入力
            // long n = long.Parse(Console.ReadLine());

            // 文字列配列の入力
            // string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            var a = inputLongArray[0];
            var b = inputLongArray[1];
            var h = inputLongArray[2];
            var m = inputLongArray[3];

            float deg1 = h * 30f + (m / 60f) * 30f;
            float deg2 = m * 6f;
            float diff = deg1 < deg2 ? deg2 - deg1 : deg1 - deg2;
          
            double rad = diff * Math.PI / 180f;
          	double result = a * a + b * b - 2 * a * b * Math.Cos(rad);

            Console.WriteLine(Math.Sqrt(result));

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28564
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 13 17:57:26 2018


N人の名前から 以下の条件を満たす3人を選ぶ

•全ての人の名前が 'M','A','R','C','H' のどれかから始まっている
•同じ文字から始まる名前を持つ人が複数いない

※選ぶ順番は問わない

何通り存在するか

入力
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

出力
7


@author: Yuya
"""

N = int(input())

n = [0, 0, 0, 0, 0]




for i in range(N):
    S = input()
    if S[0] == "M":
        n[0] += 1
    elif S[0] == "A":
        n[1] += 1
    elif S[0] == "R":
        n[2] += 1
    elif S[0] == "C":
        n[3] += 1
    elif S[0] == "H":
        n[4] += 1
    

ans = n[0]*n[1]*n[2] + n[0]*n[1]*n[3] + n[0]*n[1]*n[4] + n[0]*n[2]*n[3] + n[0]*n[2]*n[4] + n[0]*n[3]*n[4] + n[1]*n[2]*n[3] + n[1]*n[2]*n[4] + n[1]*n[3]*n[4] + n[2]*n[3]*n[4]
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun May 10 21:11:24 JST 2020
 **/

signed main() {
    Int a, b, c, K;
    std::cin >> a >> b >> c >> K;
    Int ans = 0;
    {
        Int use = std::min(a, K);
        ans += use;
        K -= use;
    }
    {
        Int use = std::min(b, K);
        K -= use;
    }
    {
        Int use = std::min(c, K);
        ans -= use;
        K -= use;
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3640
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *AB = map(int, read().split())
    vec = [0] * (10 ** 5 + 1)
    for a, b in zip(*[iter(AB)] * 2):
        vec[a] += b

    total = 0
    for i, n in enumerate(vec):
        total += n
        if total >= K:
            ans = i
            break

    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main()
{
    ll k;
    cin>>k;
    ll i;
    string s;
    cin>>s;
    ll n=s.length();
    if(n<=k)
        cout<<s<<'\n';
    else
    {   string str;
        for(i=0; i<k; i++)
        {
          str+=s[i];
        }
        str+="...";
        cout<<str<<'\n';
    }
    
        return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define rrep(i, n) for(long long i = (long long)(n - 1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using ll = long long;

int main()
{
	int A, B;
	cin >> A >> B;

	cout << A * B << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>                        
#define pb push_back                            
#define mp make_pair                            
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define jonathan ios_base::sync_with_stdio(0)
#define livingston cin.tie(0)
using namespace std;                            
                                                
void yes() {cout << "Yes" << endl;}                                               
void no() {cout << "No" << endl;}                                                        
                                                
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};         
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; 

const int INF = 1e9 + 9;
const long long LINF = 1e12 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7; //998244353
const double PI = acos(-1);

long long mult(long long a, long long b) {
    if (min(a, b) == 0) return 0;
    if (LINF / a < b) return LINF;
    return min(LINF, a * b);
}

void solve() {
    long long N, A; cin >> N >> A;
    long long otvet = 1e18;
    for (int k = 1; k < 60; k++) {
        long long L = 1, R = N;
        long long ans = 1e18;
        while (L <= R) {
            long long sum = L + R >> 1;
            long long t = sum / k;
            long long t1 = sum / k + 1;
            long long t_times = k - sum % k;
            long long t1_times = sum % k;
            long long res = 1;
            for (int i = 0; i < t_times; i++) {
                res = mult(res, t);
                if (res == LINF) break;
            }
            for (int i = 0; i < t1_times; i++) {
                res = mult(res, t1);
                if (res == LINF) break;
            }
            if (res >= N) {
                ans = sum;
                R = sum - 1;
            } else {
                L = sum + 1;
            }
        }
        otvet = min(otvet, ans + 1ll * (k - 1) * A);
    }
    cout << otvet << endl;
}

int main() {
    jonathan; 
    livingston;
    solve();
    return 0;
}

Measured memory_bytes: 3652
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sat Jan 18 17:39:17 2020
//
package main

import (
	"fmt"
	"sort"
)

const MOD = 1e9 + 7

var memo []int

func newComb(n int) {
	memo = make([]int, n+1)
	memo[0] = 1
}

func comb(n, k int) int {
	var fact func(n int) int
	fact = func(n int) int {
		if memo[n] > 0 {
			return memo[n]
		}
		memo[n] = n * fact(n-1) % MOD
		return memo[n]
	}

	var pow func(n, k int) int
	pow = func(n, k int) int {
		if k == 0 {
			return 1
		}
		if k%2 == 1 {
			return n * pow(n*n%MOD, k/2) % MOD
		}
		return pow(n*n%MOD, k/2)
	}

	if n == 0 || k == 0 || n-k < 0 {
		return 0
	}
	return fact(n) * pow(fact(k), MOD-2) % MOD * pow(fact(n-k), MOD-2) % MOD
}

var N, K int
var A []int

func main() {
	fmt.Scan(&N, &K)
	A = make([]int, N)
	for i := range A {
		fmt.Scan(&A[i])
	}
	sort.Ints(A)

	newComb(N)
	ans := 0
	for i := 0; i < N; i++ {
		ans += comb(N-1-i, K-1) * A[N-1-i] % MOD
		ans -= comb(N-1-i, K-1) * A[i] % MOD
		ans += MOD
		ans %= MOD
	}
	fmt.Println(ans)
}


Measured memory_bytes: 12544
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;

// calc digit-dp
// dp[(桁)][(num of leading-zero)][smaller][15 で割ったあまり] :＝ 個数
long long dp[21][21][3][16];
long long calc(long long num) {
  memset(dp, 0, sizeof(dp));
  dp[0][0][0][0] = 1;
  stringstream ss; ss << num;
  string str = ss.str(); ss >> str;
  for (int i = 0; i < str.size(); ++i) {
	int cur = (int)(str[i] - '0');
	for (int mod = 0; mod < 15; ++mod) {
	  // (leading zero = i, exact(0)) ->
	  if (cur == 0) dp[i+1][i+1][0][mod*10%15] += dp[i][i][0][mod];
	  else dp[i+1][i+1][1][mod*10%15] += dp[i][i][0][mod];
	  if (cur != 0) dp[i+1][i][0][(mod*10+cur)%15] += dp[i][i][0][mod];
	  for (int c = 1; c < cur; ++c) {
		dp[i+1][i][1][(mod*10+c)%15] += dp[i][i][0][mod];
	  }

	  // (leading zero = i, smaller(1)) ->
	  dp[i+1][i+1][1][mod*10%15] += dp[i][i][1][mod];
	  for (int c = 1; c < 10; ++c) {
		dp[i+1][i][1][(mod*10+c)%15] += dp[i][i][1][mod];
	  }

	  // (leading zero < i, exact(0)) ->
	  for (int j = 0; j < i; ++j) {
		dp[i+1][j][0][(mod*10+cur)%15] += dp[i][j][0][mod];
		for (int c = 0; c < cur; ++c) {
		  dp[i+1][j][1][(mod*10+c)%15] += dp[i][j][0][mod];
		}
	  }

	  // (leading zero < i, smaller(1)) ->
	  for (int j = 0; j < i; ++j) {
		for (int c = 0; c < 10; ++c) {
		  dp[i+1][j][1][(mod*10+c)%15] += dp[i][j][1][mod];
		}
	  }
	}
  }

  // num
  long long res = 0;
  for (int j = 0; j < str.size(); ++j) {
	for (int mod = 0; mod < 15; ++mod) {
	  if (mod % 3 == 0) continue;
	  if (mod % 5 == 0) continue;
	  long long num = dp[str.size()][j][0][mod] + dp[str.size()][j][1][mod];
	  res += num * ((long long)str.size() - j);
	}
  }

  // fizzbuzz
  long long fizzbuzz = (num/3) * 4 + (num/5) * 4;

  return res + fizzbuzz;
}

int main() {
  long long s; cin >> s;
  
  // 1 から x までの文字列の総数が s 未満となる最大の x を求める
  long long low = 0, high = 1LL<<58;
  while (high - low > 1) {
	long long mid = (high + low) / 2;
	long long all = calc(mid);
	if (all >= s) high = mid;
	else low = mid;
  }

  long long rem = s - calc(low) - 1;
  stringstream ss;
  for (long long i = high; i < high + 20; ++i) {
	if (i % 15 == 0) ss << "FizzBuzz";
	else if (i % 3 == 0) ss << "Fizz";
	else if (i % 5 == 0) ss << "Buzz";
	else ss << i;
  }
  string res = ss.str();
  cout << res.substr(rem, 20) << endl;
}



Measured memory_bytes: 3364
#include"bits/stdc++.h"
	using namespace std;

int main() {
	int a;
	cin >> a;
	if (a == 000) {
		cout << 0;
	}
	if (a == 100 || a == 10 || a == 1) {
		cout << 1;
	}
	if (a == 110 || a == 101 || a == 11) {
		cout << 2;
	}
	if(a==111){
		cout << 3;
	}
}

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

const int N = 1e5+21;
const int mod = 1e9+7;
int ways[N];
int broken[N];

int32_t main(){
    
    int n;  cin >> n;
    int m;  cin >> m;

    for(int x=1,t;x<=m;x++)   cin >> t , broken[t] = 1;


    if(broken[1])   ways[1] = 0;
    else ways[1] = 1;

    if(broken[2]){

        if(broken[1]) ways[2] = 0;


    }else{
        if(broken[1]) ways[2] = 1;
        else ways[2] = 2;
    }


    for(int x=3;x<=n;x++){
        if(broken[x]){
            ways[x] = 0;
            continue;
        }

        ways[x] = (ways[x-1] % mod + ways[x-2] % mod) % mod;

    }

    cout << ways[n];
    

    return 0;
}

Measured memory_bytes: 1792
def solve():
    n = int(input())
    s = [0,0,0,0,0]
    for i in range(n):
        name = input()
        if name[0] == 'M':
            s[0] += 1
        if name[0] == 'A':
            s[1] += 1
        if name[0] == 'R':
            s[2] += 1
        if name[0] == 'C':
            s[3] += 1
        if name[0] == 'H':
            s[4] += 1

    u = []
    for i in range(5):
        if s[i] > 0:
            u.append(i)

    import itertools
    ans = 0

    if len(u) < 3:
        print(ans)
        return
    # print(s)
    # print(u)
    for com in itertools.combinations(u, 3):
        # print(com)
        ans += s[com[0]]*s[com[1]]*s[com[2]]
    print(ans)

solve()

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

int keta(int N){
  string s = to_string(N);
  return s.size();
}

int main(){
  int64_t N;
  cin >> N;
  int64_t x = sqrt(N);
  vector<int> A(0);
  while(x >= 1){
    if(N % x == 0) A.push_back(x);
    x--;
  }
  vector<int> B(A.size());
  for(int i = 0; i < A.size(); i++){
    B.at(i) = N / A.at(i);
  }
  int result = max(keta(A.at(0)), keta(B.at(0)));
  for(int i = 1; i < A.size(); i++){
    if(result > max(keta(A.at(i)), keta(B.at(i)))) result = max(keta(A.at(i)), keta(B.at(i)));
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize(3,"Ofast")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

#define f(i, l, r) for (int i = l; i <= r; i++)
#define rf(i, r, l) for (int i = r; i >= l; i--)
#define all(x) (x).begin(), (x).end()
#define sf(a) scanf("%d", &a)
#define llsf(a) scanf("%lld", &a)
#define l l
#define r r
#define lch (o << 1)
#define rch (o << 1 | 1)
//#define mid ((l + r) >> 1)
#define mem(x, y) memset(x, y, sizeof(x))
#define mod1(x) ((x>=mod)&&(x-=mod))
#define mod2(x) ((x<0)&&(x+=mod))

const int inf = 2e9 + 7;
const ll INF = INT64_MAX;
double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const double pi = acos(-1.0);

char s[N];
int main() {
#ifdef local
	int start = clock();
	freopen("in.txt", "r", stdin);
#endif
	
	cin >> s + 1;
	int w=strlen(s + 1);
	f(i, 1, w) {
		if (s[i] == '?')s[i] = 'D';
	}
	cout << s + 1;
#ifdef local
		int end = clock();
		cout << '\n' << end - start << "ms";
#endif* /
	}

Measured memory_bytes: 3784
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
 
public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
        	List<Integer> list = new ArrayList<>();
		int x = 1;
 		while(!(x == 0))
		{
			x = scanner.nextInt();
			if(x == 0)
			{
				break;
			} 
			list.add(x);
		}
		int i = 1;
		for(Iterator it = list.iterator(); it.hasNext();) 
		{
            		System.out.println("Case" + " " + i + ":" + " " + it.next());
			i++;
       		}
	}
}	


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

const int MAXN = 1e5+10;
const ll inf = 1e15;

struct EDGE{
    int u,v;
    ll w;
}edge[MAXN];

bool cmp(EDGE x,EDGE y)
{
    return x.u == y.u?x.v < y.v:x.u<y.u;
}

struct node{
    int l,r;
    ll minn,lazy,maxn;
    int mid(){return (r + l) / 2;}
};

struct seg_tree{
    node tree[MAXN<<2];
    inline void pushup(int x)
    {
        tree[x].minn = min(tree[x<<1].minn,tree[x<<1|1].minn);
        tree[x].maxn = max(tree[x<<1].maxn,tree[x<<1|1].maxn);
    }
    void pushdown(int x)
    {
        if (tree[x].lazy == 0) return;
        tree[x<<1].minn = min(tree[x<<1].minn,tree[x].lazy);
        tree[x<<1|1].minn = min(tree[x<<1|1].minn,tree[x].lazy);
        if (tree[x<<1].maxn > tree[x].lazy)
        {
            tree[x<<1].maxn = tree[x].lazy;
            tree[x<<1].lazy = tree[x].lazy;
        }
        if (tree[x<<1|1].maxn > tree[x].lazy)
        {
            tree[x<<1|1].maxn = tree[x].lazy;
            tree[x<<1|1].lazy = tree[x].lazy;
        }
        tree[x].lazy = 0;
    }
    void build(int l,int r,int x)
    {
        tree[x].l = l,tree[x].r = r;
        if (l == r)
        {
            if (l == 1) tree[x].minn = tree[x].maxn = 0;
            else tree[x].minn = tree[x].maxn = inf;
            return;
        }
        int mid = tree[x].mid();
        build(l,mid,x<<1);
        build(mid+1,r,x<<1|1);
        pushup(x);
    }
    void add(int st,int ed,int x,ll v)
    {
        if (st<=tree[x].l && ed>=tree[x].r)
        {
            if (tree[x].minn > v)
            {
                tree[x].minn = v;
            }
            if (tree[x].maxn > v)
            {
                tree[x].maxn = v;
                tree[x].lazy = v;
            }
            return;
        }
        pushdown(x);
        int mid = tree[x].mid();
        if (st <= mid) add(st,ed,x<<1,v);
        if (ed > mid) add(st,ed,x<<1|1,v);
        pushup(x);
    }
    ll query(int st,int ed,int x)
    {
        if (st<=tree[x].l && ed>=tree[x].r) return tree[x].minn;
        pushdown(x);
        int mid = tree[x].mid();
        ll res = inf;
        if (st <= mid) res = min(res,query(st,ed,x<<1));
        if (ed > mid) res = min(res,query(st,ed,x<<1|1));
        pushup(x);
        return res;
    }
}seg;

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for (int i = 1;i<=m;i++)
    {
        scanf("%d%d%lld",&edge[i].u,&edge[i].v,&edge[i].w);
    }
    sort(edge+1,edge+m,cmp);
    seg.build(1,n,1);
    for (int i = 1;i<=m;i++)
    {
        ll dis = seg.query(edge[i].u,edge[i].v,1);
        seg.add(edge[i].u,edge[i].v,1,dis+edge[i].w);
    }
    ll dis = seg.query(n,n,1);
    if (dis == inf) cout<<-1;
    else cout<<dis;
    return 0;
}

Measured memory_bytes: 12032
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var s = next(1);
  var n = s.length;
  var ss = s.split("").reverse().join("");
  var s1 = s.slice(0,n>>1);
  var ss1 = s1.split("").reverse().join("");
  var s2 = s.slice(n+1>>1);
  var ss2 = s2.split("").reverse().join("");
  return s === ss && s1 === ss1 && s2 === ss2 ? "Yes" : "No";
}

Measured memory_bytes: 21064
# -*- coding: utf-8 -*-
from collections import Counter
import sys
# sys.setrecursionlimit(10**6)
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def slv(N, K, A):
    B = [0]
    for i, a in enumerate(A, start=0):
        B.append((B[-1] + a) % K)

    for i in range(len(B)):
        B[i] = (B[i] - i) % K

    ans = 0
    C = Counter()
    n = 0
    for i, b in enumerate(B):
        C[b] += 1
        n += 1
        if n > K:
            C[B[i-K]] -= 1
            n -= 1
        ans += C[b] - 1

    return ans


def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 83728
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
#define itn int
#define all(c) c.begin(),c.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define ll long long
#define ull unsigned long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std; 

const double PI = 3.1415926536;
int days[13] = {0, 31, 28, 31, 30, 31,30, 31, 31, 30, 31, 30, 31};

template<typename T>
ostream& operator <<(ostream& out, const vector<T>& mas) {
    for (const auto& x : mas) {
        out << x << ' ';
    }
    return out;
}

void ok() {
    cout << "YES" << '\n';
}

void no() {
    cout << "NO" << '\n';
}

inline ll nxt() {
    ll x;
    cin >> x;
    return x;
}

bool is_palindrom(string s) {
    string t = s;
    reverse(all(t));
    return t == s;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    string s;
    cin >> s;
    int n = s.size();
    string t1 = s.substr(0, n / 2);
    string t2 = s.substr(n / 2 + 1);
    if (is_palindrom(s) && is_palindrom(t1) && is_palindrom(t2)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <deque>
#include <queue>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<vector<int> > g(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }
    queue<int> q;
    vector<bool> usd(n, false);
    usd[0] = true;
    q.push(0);
    vector<int> pr(n, -1);
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        for (auto i : g[cur]) {
            if (!usd[i]) {
                pr[i] = cur;
                q.push(i);
                usd[i] = true;
            }
        }
    }
    vector<int> ans;
    for (int i = 1; i < n; ++i) {
        if (usd[i]) {
            ans.push_back(pr[i] + 1);
        } else {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    for (auto i : ans) {
        cout << i << '\n';
    }
    return 0;
}


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

typedef long long LL;

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


    LL n, ans = 1LL<<62;
    cin >> n;
    vector <LL> arr(n+1);

    for (int i = 1; i <= n; i++)
        cin >> arr[i],
        arr[i] += arr[i-1];

    for (int i = 1; i < n; i++)
        ans = min(ans, abs(arr[n] - 2*arr[i]));

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

// Union find : O(α(V))
// verified : 
class UnionFind {
	typedef ll U;
	// v[i] : i番目の頂点が根 ? i番目の頂点の属する木のサイズ * -1
	//                       : i番目の頂点の親のindex
	vector<ll> v;
public:
	UnionFind(U n) : v(n, -1) {}
	U find(U x) { return v[x] < 0 ? x : (v[x] = find(v[x])); }
	bool same(U x, U y) { return find(x) == find(y); }
	U size(U x) { return (U)-v[find(x)]; }
	void unite(U x, U y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (-v[x] < -v[y]) swap(x, y);
			v[x] += v[y];
			v[y] = x;
		}
	}
};

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n, m; cin >> n >> m;
	vvl path(n);
	UnionFind uf(n);
	REP(i, m) {
		ll u, v;
		cin >> u >> v;
		u--, v--;
		uf.unite(u, v);
		path[u].push_back(v);
		path[v].push_back(u);
	}
	vector<ll> cnt(5, 0);
	vl dist(n, -1);
	REP(i, n) if (uf.find(i) == i) {
		if (uf.size(i) <= 2) cnt[uf.size(i)]++;
		else {
			dist[i] = 0;
			if ([&] {
				deque<pair<ll, ll>> q;
				q.push_back({ i, 0 });
				while (!q.empty()) {
					auto p = q.front();
					q.pop_front();
					for (auto&& e : path[p.first]) {
						if (dist[e] != -1) {
							if ((p.second + 1 - dist[e]) % 2 == 1) {
								return true;
							}
						} else {
							dist[e] = p.second + 1;
							q.push_back({ e, dist[e] });
						}
					}
				}
				return false;
			}()) {
				cnt[3]++;
			} else {
				cnt[4]++;
			}
		}
	 }
	ll ans = cnt[3] * cnt[3];
	ans += (cnt[2] + cnt[4]) * cnt[3] * 2;
	ans += cnt[4] * cnt[4] * 2;
	ans += cnt[4] * cnt[2] * 4;

	ans += cnt[1] * (n - cnt[1]) * 2;
	ans += cnt[1] * cnt[1];
	ans += cnt[2] * cnt[2] * 2;
	cout << ans << endl;
}

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

int main(void) {

    int N, A, B;

    scanf("%d %d %d", &N, &A, &B);

    /*printf("N:%d\n", N);
    printf("A:%d\n", A);
    printf("B:%d\n", B);*/

    if( N<1 || N>20 || A<1 || A>50 || B<1 || B>50){
        printf("The number is inappropriate\n");
        exit(0);
    }

    int train = N*A;

    if(train>B){
        printf("%d\n", B);
    }else{
        printf("%d\n", train);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;
using namespace std;

const int N = 1e5 + 10, INF = 0x3f3f3f3f , MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    ll a[100];
    a[0] = 2;
    a[1] = 1;
    int n;cin>>n;
    if(n <= 1) {
        cout<<a[n]<<endl;
        return 0;
    }
    for(int i = 2;i <= n;i++) {
        a[i] = a[i-1] + a[i-2];
    }
    cout<<a[n]<<endl;
    return 0;
}


Measured memory_bytes: 256
N, M = [int(x) for x in input().split()]
bridge = [[int(x) for x in input().split()] for x in range(M)]

par = [int(x) for x in range(N+1)]  # 所属グループ
gn = [1 for _ in range(N+1)]        # 各グループサイズ


def group(i):
    if par[i] == i:
        return i
    else:
        par[i] = group(par[i])
        return par[i]


ans = [int(N*(N-1)/2)]

for i, b in enumerate(bridge[::-1]):  # O(M)
    g0 = group(b[0])
    g1 = group(b[1])
    if g0 > g1:
        ans.append(int(ans[-1] - gn[g0]*gn[g1]))
        par[g0] = g1
        gn[g1] += gn[g0]
        gn[g0] = 0
    elif g0 < g1:
        ans.append(int(ans[-1] - gn[g0]*gn[g1]))
        par[g1] = g0
        gn[g0] += gn[g1]
        gn[g1] = 0
    else:
        ans.append(ans[-1])

for x in ans[::-1][1:]:
    print(x)


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

bool checkpalin(string s,int len)
{
  for(int i=0;i<len/2;i++)
  {
    if(s[i]!=s[len-i-1])
      return false;
  }
  return true;
}
int main()
{
  string s;
  cin>>s;
  if(checkpalin(s,s.length()) && checkpalin(s,(s.length()-1)/2))
    cout<<"Yes\n";
  else
    cout<<"No\n";
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		long sum = 0;
		long squareSum = 0;
		int MOD = 1000000007;
		for(int i = 0; i < n; i++){
		    long a = sc.nextLong();
		    sum += a;
		    sum %= MOD;
		    squareSum += a*a%MOD;
		    squareSum %= MOD;
		}
		
		// 計算
		long result = 0;
		result = (sum*sum - squareSum + MOD)%MOD*inv(2, MOD)%MOD;
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
	
	public static long pow(long a, long n, long MOD) {
		long res=1;
		while (n>0) {
			if ((n-n/2*2)==1) {
				res=(res*a)%MOD;
			}
			a=(a*a)%MOD;
			n>>=1;
		}
		return res%MOD;
	}

	public static long inv(long a, long MOD) {
		return pow(a, MOD - 2, MOD);
	}


}


Measured memory_bytes: 52808
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
inline int read()
{
    int sum=0,t=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-') t=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        sum=sum*10+ch-'0';
        ch=getchar();
    }
    return sum*t;
}
int n,m;
struct city
{
    int pos,year,num;
}h[100005];
struct ans
{
    int pos,num;
}zn[100005];
bool cmp(const city &a,const city &b)
{
    if(a.pos==b.pos)
        return a.year<b.year;
    return a.pos<b.pos;
}
int getbit(int x)
{
    int sum=0;
    while(x)
    {
        ++sum;
        x/=10;
    }
    return sum;
}
int main()
{
    n=read();
    m=read();
    for(register int i=1;i<=m;++i)
    {
        h[i].pos=read();
        zn[i].pos=h[i].pos;
        h[i].year=read();
        h[i].num=i;
    }
    sort(h+1,h+m+1,cmp);
    int cnt=0;
    for(register int i=1;i<=m;++i)
    {
        if(cnt==0||h[i].pos==h[i-1].pos)
            zn[h[i].num].num=++cnt;
        else
        {
            cnt=1;
            zn[h[i].num].num=cnt;
        }
    }
    for(register int i=1;i<=m;++i)
    {
        int citybit=getbit(zn[i].pos),numbit=getbit(zn[i].num);
        for(register int j=1;j<=6-citybit;++j)
            putchar('0');
        printf("%d",zn[i].pos);
        for(register int j=1;j<=6-numbit;++j)
            putchar('0');
        printf("%d",zn[i].num);
        putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll cur = 1, ans = 0;
    rep(i, n) {
        if (cur != a[i]) {
            ans++;
        }
        else {
            cur++;
        }
    }
    if (ans == n) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792