akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
using namespace std;

#define ll long long 
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define MOD 1000000007

vt permutation(vt n, vt k) { //modなし順列
	if (k == 1) return n;
	return permutation(n, k - 1) * (n - k + 1);
}

vt comb(vt n, vt k) { //modなし二項係数
	if (n < k) return 0;
	if (k == 0) return 1;
	return permutation(n, k) / permutation(k, k);
}


int main() {
	ll n;
	cin >> n;
	vector<ll> a(n), b(n);
	map<ll, ll> mp;
	rep(i, n) cin >> a.at(i);
	rep(i, n) b.at(i) = a.at(i);
	sort(b.begin(), b.end());
	ll sum = 0;
	for (ll i = 0; i < n;) {
		ll value = b.at(i), cnt = 1;
		for (i = i + 1; i < n; i++) {
			if (b.at(i) == value) cnt++;
			else break;
		}
		mp[value] = cnt;
		sum += comb(cnt, 2);
	}
	rep(i, n) {
		cout << sum - comb(mp[a.at(i)], 2) + comb(mp[a.at(i)] - 1, 2) << endl;
	}
	return 0;
}

Measured memory_bytes: 12672
#include<iostream>
#include<string>
#include<algorithm>
#include <sstream>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include <vector>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
int main()
{

 	ll n;
 	scanf("%lld",&n);
    int t=1;

    for(int i=1;i<=n/i;i++)
    {
        if(n%i==0)t=i;
    }
    n=n/t;
    stringstream s1;
    s1<<n;
   // cout<<"n = "<<n<<" t = "<<t<<endl;
    string str1,str2;
    s1>>str1;
    s1<<t;
    s1>>str2;
    cout<<max(str1.size(),str2.size())<<endl;
	return 0;
}


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

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

const double EPS = 1e-10;

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

struct Combination{
    vector<long long> _fac,_finv,_inv;
    const int m = MOD;

    Combination(int sz) : _fac(sz),_finv(sz),_inv(sz){
        _fac[0] = _fac[1] = 1;
        _finv[0] = _finv[1] = 1;
        _inv[1] = 1;
        for(int i = 2; i <= sz; i++){
            _fac[i] = _fac[i-1]*i%m;
            _inv[i] = m-_inv[m%i]*(m/i)%m;
            _finv[i] = _finv[i-1]*_inv[i]%m;
        }
    }

    inline long long fac(int n){return _fac[n];}
    inline long long inv(int n){return _inv[n];}
    inline long long finv(int n){return _finv[n];}

    long long comb(int n,int k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return _fac[n]*(_finv[k]*_finv[n-k]%m)%m;
    }
};

int main(){
    int N,M,K; cin >> N >> M >> K;
    Combination C(200010);
    ll ans = 0;
    repr(i,1,M){
        ans += (ll)N*N*(M-i)*i%MOD;
        ans %= MOD;
    }
    repr(i,1,N){
        ans += (ll)M*M*(N-i)*i%MOD;
        ans %= MOD;
    }
    ans *= C.comb(N*M-2,K-2);
    ans %= MOD;
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)
const int INF = 1001001001;

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    --x, --y;
    vector<vector<int>> list(n+1);
    vector<int> ans(n);
    list[x].push_back(y);
    rep(i, 0, n) {
        vector<int> dist(n, INF);
        queue<int> q;
        auto push = [&](int v, int d) {
            if(dist[v] != INF) return;
            dist[v] = d;
            q.push(v);
        };
        push(i, 0);
        while(!q.empty()) {
            int v = q.front(); q.pop();
            int d = dist[v];
            if(v-1 >= 0) push(v-1, d+1);
            if(v+1 < n) push(v+1, d+1);
            if(v == x) push(y, d+1);
            if(v == y) push(x, d+1);
        }
        rep(i, 0, n) ans[dist[i]]++;
    }
    rep(i, 0, n) ans[i] /= 2;
    for(int i = 1; i < n; i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = 1001001001

H, W, K = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(H)]
# print(S)

ans = INF
for b in range(1<<(H-1)):
    g = 0
    idx = [0]*H
    for i in range(H-1):
        if b>>i&1:
            g += 1
        idx[i+1] = g
    g += 1
    cnt = [[0]*W for _ in range(g)]
    for i in range(H):
        for j in range(W):
            cnt[idx[i]][j] += S[i][j]
    num = g-1
    now = [0]*g

    def add(j):
        global now
        for i in range(g):
            now[i] += cnt[i][j]
            if now[i] > K:
                return False
        return True

    for j in range(W):
        if add(j)==False:
            num += 1
            now = [0]*g
            if add(j)==False:
                num = INF
                break
    ans = min(ans, num)

print(ans)


Measured memory_bytes: 52444
#include <stdio.h>
 
int hantei(int[5]);
 
int main(void) {
    int cards[5];
    int i,j,temp;
    int yaku;
    char yakuname[7][11]={"null","one pair","two pair","three card",
                        "straight","full house","four card"};
    while(1) {
        if(scanf("%d,%d,%d,%d,%d",
            &cards[0],&cards[1],&cards[2],&cards[3],&cards[4])==-1)break;
        for(i=4;i>0;i--) {
            for(j=0;j<i;j++) {
                if(cards[j]>cards[j+1]) {
                    temp=cards[j];
                    cards[j]=cards[j+1];
                    cards[j+1]=temp;
                }
            }
        }

        yaku=0;

		if(cards[1]==cards[2] && cards[2]==cards[3]) {
            if(cards[0]==cards[1] || cards[3]==cards[4]){
					yaku=6;
			}
            else{ 
				yaku=3;
			}
        } 
		else if(cards[0]==cards[1] && cards[1]==cards[2]) 
		{
            if(cards[3]==cards[4]){
				yaku=5;
			}
			else{
				yaku=3;
			}

        } 
		else if(cards[2]==cards[3] && cards[3]==cards[4]) {
            if(cards[0]==cards[1]){
				yaku=5;
			}
			else{
				yaku=3;
			}
        } 
		else if(hantei(cards)){
			yaku=4;
		}
        else {
            for(i=0;i<4;i++) {
                if(cards[i]==cards[i+1]){
					yaku++;
				}
            }
        }
        printf("%s\n",yakuname[yaku]);
    }
    return 0;
}
 
int hantei(int cards[5]) {
    int i;
    for(i=0;i<4;i++) {
        if(cards[i]+1!=cards[i+1]){
			break;
		}
    }
    if(i<4) {
        if(cards[0]==1 && cards[1]==10 && cards[2]==11 &&
            cards[3]==12 && cards[4]==13){
				return 1; 
		}
		else{
			return 0;
		}
    } 
	else{ 
		return 1;
	}
}

Measured memory_bytes: 1004
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int ans1 = 0;
        int ans2 = 0;
        for (int i = 0; i < s.length; i++) {
            if(i % 2 == 0 && s[i] == '0') {
                ans1++;
            } else if(i % 2 == 0 && s[i] == '1'){
                ans2++;
            } else if(i % 2 != 0 && s[i] == '0') {
                ans2++;
            } else if(i % 2 != 0 && s[i] == '1') {
                ans1++;
            }
        }
        System.out.println(Math.min(ans1, ans2));
    }
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

int main(void){
    int K; cin >> K;
    K--;
    VI ans{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << ans[K] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(3005)
#define fim '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << fim
#define debug2(x, y) cout << "DEBUG " << x << " " << y << fim
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< fim
#define max3(x, y, z) max(x, max(y, z))
using namespace std;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, pair<int, int> > piii;
ll dp[MAXN][MAXN], n, vet[MAXN], paro;

ll solve(int l, int r) {

    if(l > r)
        return 0;
    if(dp[l][r] != -INF)
        return dp[l][r];

    if( ((l+r) % 2) == paro ) return dp[l][r] = max(solve(l+1, r)+vet[l], solve(l, r-1)+vet[r]);
    else return dp[l][r] = min(solve(l+1, r)-vet[l], solve(l, r-1)-vet[r]);

}

int main() {
    FAST;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> vet[i];
    paro = (n%2 == 0 ? 1 : 0);
    for(int i = n; i >= 1; i--) {
        for(int j = 1; j <= n; j++) {
            if(i > j) continue;
            if( ((i+j) % 2) == paro ) dp[i][j] = max(dp[i+1][j]+vet[i], dp[i][j-1]+vet[j]);
            else dp[i][j] = min(dp[i+1][j]-vet[i], dp[i][j-1]-vet[j]);
        }
    }
    cout << dp[1][n] << fim;
}



Measured memory_bytes: 70016
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

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

def solve(a: int, b: int, c: int):
    from decimal import Decimal
    from math import sqrt
    a,b,c = Decimal(a), Decimal(b), Decimal(c)

    if a.sqrt() + b.sqrt() < c.sqrt():
        print(YES)
    else:
        print(NO)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    solve(a, b, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5332
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)

int main() {
  int n,k;cin >> n>>k;
  vector<bool> v(n,false);
  int out = n;
  for(int i=0;i<k;++i){
    int d; cin >>d;
    for(int j=0;j<d;++j){
      int t;cin >>t;
      if(!v[t-1]){
        --out;
        v[t-1] = true;
      }
    }
  }
  cout << out << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define INF (1 << 30)
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
const long long mod = 1e9+7;

using namespace std;
using ll = __int64_t;
using ull = unsigned long long;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

bool comp(const pair<int, ll>& p1, const pair<int, ll>& p2){
    return p1.second > p2.second;
}

void solve(){
    int n;
    int h[100001];
    cin >> n;
    rep(i, n) cin >> h[i];

    int dp[n+1];
    rep(i, n) dp[i] = (1<<30);
    dp[0] = 0;
    for(int now = 0; now < n; now++){
        for(int next = now+1; next <= min(n-1, now+2); next++){
            dp[next] = min(dp[now] + abs(h[now] - h[next]), dp[next]);
        }
    }
    cout << dp[n-1] << endl;
}

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

Measured memory_bytes: 1024
###参考 https://ei1333.hateblo.jp/entry/2017/04/10/224413
# 非負の重みをもつ無向の木 T の直径
def main():
    N = I()
    if N==1:
        print(0)
        return
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        s, t, w = LI()
        V[s].append((t,w))
        V[t].append((s,w))
    dist = [0]*N

    def dfs1(start,parent):
        for i,w in V[start]:
            if i==parent:
                continue
            dfs1(i,start)
            dist[start] = max(dist[start],dist[i]+w)
        return
    def dfs2(s,d_p,p):
        child = [(0,-1)]
        for i,w in V[s]:
            if i==p:
                child.append((d_p+w,i))
            else:
                child.append((w+dist[i],i))
        child.sort(reverse=True)
        rep = child[0][0] + child[1][0]
        for i,w in V[s]:
            if i==p:
                continue
            rep = max(rep,dfs2(i,child[child[0][1]==i][0],s))
        return rep
    dfs1(N//2,-1)
    #print(dist)
    ans = dfs2(N//2,0,-1)
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(2*10**6)

if __name__ == '__main__':
    main()

"""


"""


Measured memory_bytes: 133332
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define mp(x,y) 	     make_pair(x,y)
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto& i: a)
#define loop(n,i,a)      for(int i=a;i<n;i++)
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        loop(n,i,0){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i;
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define pp               pop_back
#define endl              "\n"
#define copy(a,b)         copy(all(a),back_inserter(b));
#define intersect(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
//int m=10000009;
//int arr[100000];
#define M 					1000000007 
int isprime(int n)
{
        if(n<=1) return 0;
        if(n<=3) return 1;
        if(n%2==0 ||n%3==0)
        return 0;
    for(int i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)
        return 0;
    }
    return 1;
}
signed main(){
				fast
				//	freopen("input.txt","r",stdin);
				//	freopen("output.txt","w",stdout);
				int n;
				cin>>n;
				for(int i=1;i<=9;i++)
				{
					if(n%i==0)
					{
						if(n/i<=9)
						{
							cout<< "Yes";
							return 0;
						}
					}
				}
				cout<<"No";
			}
			
				
		
		 
		 


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

vector<Int> a;//段数
vector<Int> p;//パティ数

Int solve(Int n, Int x) {
	if (n == 0)return 1;

	if (x == 1)return 0;
	else if (x == a[n])return  p[n];
	else if (x == a[n] / 2 + 1)return p[n - 1] + 1;
	else if (1 < x && x < a[n] / 2 + 1)return solve(n - 1, x-1);
	else return 1 + p[n - 1] + solve(n - 1, x - a[n] / 2 - 1);
}


int main() {

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

	Int N, X;
	cin >> N >> X;

	for (Int i = 0; i <= N; i++) {
		a.push_back((1LL << (i + 2)) - 3);
		p.push_back((1LL << (i + 1)) - 1);
	}

	Int ans = solve(N, X);

	cout << ans << "\n";




}

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

int main() {
string S;
cin>>S;
long long N=S.size();
long long a[100010]={};
long long rcounter=0;
for(long long i=0; i<N-1; i++){
    if (S[i]=='R'){rcounter++;}
    if(S[i]=='L'){rcounter=0;}
    if(S[i]=='R' && S[i+1]=='L'){
        a[i+1]+=(rcounter/2);
        a[i]+=rcounter-(rcounter/2);
        rcounter=0;
    }
}
long long lcounter=0;
for(long long i=N-1; i>0; i--){
    if (S[i]=='L'){lcounter++;}
    if(S[i]=='R'){lcounter=0;}
    if(S[i]=='L' && S[i-1]=='R'){
        a[i-1]+=(lcounter/2);
        a[i]+=lcounter-(lcounter/2);
        lcounter=0;
    }
}

for(long long i=0; i<N; i++) cout<<a[i]<<" ";

}

Measured memory_bytes: 1408
import heapq

def func():
    N = int(input())
    L_list = []
    L_ind = [[]for i in range(N)]
    R_list = []
    R_ind = [[]for i in range(N+1)]
    ans = 0
    for i in range(N):
        k,l,r = map(int,input().split())
        if l > r:
            L_list.append(l-r)
            L_ind[k-1].append(len(L_list)-1)
            ans += r
        elif r > l:
            R_list.append(r-l)
            R_ind[N-k].append(len(R_list)-1)
            ans += l
        else:
            ans += l

    L_heap = []
    for i in range(N):
        for j in L_ind[i]:
            heapq.heappush(L_heap,L_list[j])
        while len(L_heap) > i+1:
            heapq.heappop(L_heap)
    R_heap = []
    for i in range(N):
        for j in R_ind[i+1]:
            heapq.heappush(R_heap,R_list[j])
        while len(R_heap) > i+1:
            heapq.heappop(R_heap)
    return(ans+sum(L_heap)+sum(R_heap))
    

T= int(input())
for i in range(T):
    print(func())

Measured memory_bytes: 117632
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    h, w = MI()
    s = []
    for _ in range(h):
        s.append(list(input()))
    for i in range(h):
        for j in range(w):
            flag = False
            if s[i][j] == '.':
                continue
            if i == 0 and j == 0:
                flag |= s[i][j+1] == '#'
                flag |= s[i+1][j] == '#'
            elif i == 0 and j == w-1:
                flag |= s[i+1][j] == '#'
                flag |= s[i][j-1] == '#'
            elif i == h-1 and j == 0:
                flag |= s[i-1][j] == '#'
                flag |= s[i][j+1] == '#'
            elif i == h-1 and j == w-1:
                flag |= s[i-1][j] == '#'
                flag |= s[i][j-1] == '#'
            elif i == 0:
                flag |= s[i][j+1] == '#'
                flag |= s[i+1][j] == '#'
                flag |= s[i][j-1] == '#'
            elif i == h-1:
                flag |= s[i-1][j] == '#'
                flag |= s[i][j+1] == '#'
                flag |= s[i][j-1] == '#'
            elif j == 0:
                flag |= s[i-1][j] == '#'
                flag |= s[i][j+1] == '#'
                flag |= s[i+1][j] == '#'
            elif j == w-1:
                flag |= s[i-1][j] == '#'
                flag |= s[i+1][j] == '#'
                flag |= s[i][j-1] == '#'
            else:
                flag |= s[i-1][j] == '#'
                flag |= s[i][j+1] == '#'
                flag |= s[i+1][j] == '#'
                flag |= s[i][j-1] == '#'
            if not flag:
                print("No")
                sys.exit()
    print("Yes")

if __name__ == '__main__':
    main()

Measured memory_bytes: 9348
#coding: UTF-8

import copy
class Algo:
  @staticmethod
  def bubbleSort(r, c, n):
    flag = 1
    while flag:
      flag = 0
      for j in range(n-1, 0, -1):
        if c[j] < c[j-1]:
          c[j], c[j-1] = c[j-1], c[j]
          r[j], r[j-1] = r[j-1], r[j]
          flag = 1
    return r

  def selectionSort(r, c, n):
    for i in range(0,n):
      minj = i
      for j in range(i,n):
        if c[j] < c[minj]:
          minj = j
      if c[i] != c[minj]:
        c[i], c[minj] = c[minj], c[i]
        r[i], r[minj] = r[minj], r[i]
    return r

  def createIntList(r, n):
    c = []
    for i in range(0,n):
      c.append(r[i][1])
    return c

  def printList(r, n):
    for i in range(0,n):
      if i == n-1:
        print(r[i])
      else:
        print(r[i], " ", sep="", end="")

n = int(input())
r = list(map(str,input().split()))
c = Algo.createIntList(r, n)
br = Algo.bubbleSort(copy.deepcopy(r), copy.deepcopy(c), n)
ir = Algo.selectionSort(copy.deepcopy(r), copy.deepcopy(c), n)
Algo.printList(br, n)
print("Stable")
Algo.printList(ir, n)
if br == ir:
  print("Stable")
else:
  print("Not stable")

Measured memory_bytes: 6348
#include <iostream>
#include <cstdio>
#include <cstring>
typedef long long lint;
const int N=2005;
const int N2=N*N;
const int mod=1e9+7;
int n,m,fac[N2],inv[N2],dp[N][N];

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

template <class T> inline void twk(T &x){
	x<mod?0:x-=mod;
}

inline int fpow(int x,int t){
	int ans=1;
	for(; t; x=(lint)x*x%mod,t>>=1){
		if(t&1) ans=(lint)ans*x%mod;
	}
	return ans;
}

inline void init(){
	fac[0]=1;
	for(int i=1; i<N2; ++i){
		fac[i]=(lint)fac[i-1]*i%mod;
	}
	inv[N2-1]=fpow(fac[N2-1],mod-2);
	for(int i=N2-1; i; --i){
		inv[i-1]=(lint)inv[i]*i%mod;
	}
}

inline int C(const int x,const int y){
	if(x<y) return 0;
	return (lint)fac[x]*inv[y]%mod*inv[x-y]%mod;
}

int main(){
	n=nxi(),m=nxi();
	if(m==1){
		puts("1");
		return 0;
	}
	init();
	dp[0][0]=1;
	for(int i=1; i<=n; ++i){
		dp[i][0]=dp[i-1][0];
		for(int j=1; j<=i; ++j){
			dp[i][j]=dp[i-1][j];
			const int rest=n*m-i-(j-1)*(m-1)-1;
			//make sequence unique
			dp[i][j]=(dp[i][j]+(lint)dp[i][j-1]*C(rest,m-2))%mod;
		}
	}
	printf("%lld\n",(lint)dp[n][n]*fac[n]%mod);
	return 0;
}

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

double W, H, x, y;

signed main() {
    cin >> W >> H >> x >> y;
    printf("%.12f ", W * H / 2);
    if(x == W / 2 && y == H / 2) {
        cout << 1 << "\n";
    } else {
        cout << 0 << "\n";
    }
}


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


int main(){
  
  string N;
  cin >> N;
  if(N.at(1) == N.at(2)){
    if(N.at(1) == N.at(0) || N.at(3) == N.at(2)){
      cout << "Yes" << endl;
    }
    else{
    cout << "No" << endl;
    }
  }
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j;
    cin>>n;
    for(i=n;;i++)
    {
        int f=0;
        for(j=2;j<=sqrt(i);j++)
        {
            if(i%j==0) f=1;
        }
        if(f==0) break;
    }
    cout<<i;
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>

int main()
{
  int x,a,b;
  
  scanf("%d%d%d",&x,&a,&b);
  
  a=a*(-1);
  
  if(a+b<=0)
  {
    printf("delicious\n");
  }
  else if(a+b<=x)
  {
    printf("safe\n");
  }
  else if(a+b>=x+1)
  {
    printf("dangerous\n");
  }
  
  return 0;
}
  

Measured memory_bytes: 128
n = int(input())
for i in range(n):
    x1,y1,x2,y2,x3,y3,x4,y4 = map(float, input().split())
    if abs((y1-y2)*(x4-x3) - (y4-y3)*(x1-x2)) < 1e-10:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 7500
#[allow(unused)]
use proconio::marker::*;
use proconio::{fastout, input};
#[allow(unused)]
use std::cmp::{max, min, Reverse};
#[allow(unused)]
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        l: usize,
        pq: [(Usize1, Usize1); k],
        rs: [(Usize1, Usize1); l],
    }

    let mut pq_uf = UnionFind::new(n);
    for &(p, q) in pq.iter() {
        pq_uf.unite(p, q);
    }

    let mut rs_uf = UnionFind::new(n);
    for &(r, s) in rs.iter() {
        rs_uf.unite(r, s);
    }

    let mut map = HashMap::new();
    for i in 0..n {
        let a = pq_uf.find(i);
        let b = rs_uf.find(i);
        let cnt = map.entry((a, b)).or_insert(0);
        *cnt += 1;
    }

    for i in 0..n {
        let a = pq_uf.find(i);
        let b = rs_uf.find(i);
        print!("{}", map.get(&(a, b)).unwrap());
        if i < n - 1 {
            print!(" ");
        }
    }
    println!("");
}

struct UnionFind {
    parents: Vec<usize>,
    rank: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut vec = vec![0; n];
        for i in 0..n {
            vec[i] = i;
        }
        UnionFind {
            parents: vec,
            rank: vec![0; n],
        }
    }

    fn find(&self, x: usize) -> usize {
        if x == self.parents[x] {
            x
        } else {
            self.find(self.parents[x])
        }
    }

    fn unite(&mut self, x: usize, y: usize) {
        let px = self.find(x);
        let py = self.find(y);
        if px == py {
            return;
        }

        if self.rank[px] < self.rank[py] {
            self.parents[px] = py;
        } else {
            self.parents[py] = px;
            if self.rank[px] == self.rank[py] {
                self.rank[px] += 1;
            }
        }
    }

    fn same(&self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
}


Measured memory_bytes: 22164
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

int MOD=1000000007;

int main()
{
    string S,T,s = "~";
    cin >> S >> T;
    int n = S.size();
 
    for(int i=0; i<n-T.size()+1; i++){
        string tmp = S;
        bool ans = true;
        for(int j=i; j<i+T.size(); j++){
            if(tmp[j]!='?' && tmp[j]!=T[j-i])ans = false;
        }
        if(ans==true){
            for(int j=i; j<i+T.size(); j++){
            tmp[j]=T[j-i];
            }
            for(int j=0; j<n; j++){
                if(tmp[j]=='?')tmp[j] = 'a';
            }
            s=min(tmp,s);
        }        
    }
    if(s == "~"){
        cout << "UNRESTORABLE" << endl;
    }else{
        cout << s << endl;
    }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"reflect"
	"sort"
	"strings"
)

func rotate(s string) string {
	if s == "" {
		return s
	}
	if len(s) == 1 {
		return s
	}
	b := []rune(s)

	return string(append(b[1:], b[0]))
}

func main() {
	var S, T string

	fmt.Scan(&S)
	fmt.Scan(&T)

	if S == T {
		fmt.Println("Yes")
		return
	}

	if len(S) != len(T) {
		fmt.Println("No")
		return
	}

	as := strings.Split(S, "")
	at := strings.Split(T, "")

	sort.Strings(as)
	sort.Strings(at)

	if !reflect.DeepEqual(as, at) {
		fmt.Println("No")
		return
	}
	for i := 0; i < len([]rune(S)); i++ {
		S = rotate(S)

		if S == T {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}


Measured memory_bytes: 640
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

long long const MOD = 1000000007LL;

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

    if (n == 1) cout << "Hello World" << endl;
    else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 1000000000


int main(){

	ull N,T;
	scanf("%llu %llu",&N,&T);

	char buf[100];
	scanf("%s",buf);

	ull sum = 0;

	for(int i = 0; buf[i] != '\0' && buf[i] == 'n'; ){
		ull tmp = N;

		int count = buf[i+2]-'0';

		if(count == 0){
			tmp = 1;
		}else{

			for(int k = 0; k < count-1; k++){
				if(tmp*N > NUM){
					printf("TLE\n");
					return 0;
				}
				tmp *= N;
			}
		}
		sum += tmp;
		if(sum > NUM){
			printf("TLE\n");
			return 0;
		}
		i += 4;
	}

	if(sum*T > NUM){
		printf("TLE\n");
		return 0;
	}else{
		sum *= T;
	}

	printf("%llu\n",sum);

	return 0;
}

Measured memory_bytes: 3180
A = int(input())
B = int(input()) 
C = int(input())
X = int(input())
ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k==X:
                ans += 1
print(ans)

Measured memory_bytes: 3060
N=int(input())
H=[[0,0,0] for _ in range(110000)]
dp=[[0,0,0] for _ in range(110000)]

for i in range(1,N+1):
    H[i][0],H[i][1],H[i][2]=map(int,input().split())

for i in range(1,N+1):
    for p in range(3):
        for y in range(3):
            if (p!=y):
                dp[i][p]=max(dp[i][p],dp[i-1][y]+H[i][p])

print(max(dp[N]))

Measured memory_bytes: 44588
// ABC169A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
int main()
{
    int A,B;
    cin >> A >> B;
    cout << A * B << endl;
}

Measured memory_bytes: 3192
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		p: [usize; n],
	}

	let mut count = 0;
	let mut i = 0;
	loop {
		if i >= n {
			break;
		}
		if p[i] == i+1 {
			count += 1;
			i += 2;
		}
		else {
			i += 1;
		}
	}
	println!("{}", count);
}



Measured memory_bytes: 3280
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	n,k = MI()
	tmp = 0
	n = n%k
	while True:
		tmp = n
		n = min(n, abs(n-k))
		if(tmp == n):
			break
	print(tmp)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;


const ull mod = ull(998244353);

ull my_plus(ull a, ull b) {
    return ((a % mod + b % mod) % mod);
}

ull my_minus(ull a, ull b) {
    ll ans;
    ans = (a % mod - b % mod);

    if (ans < 0) {
        ans += mod;
    }

    return ull(ans);
}


ull my_mult(ull a, ull b) {
    return ((a % mod * b % mod) % mod);
}


ull A, B, C, D;
const ull LMAX = 3001;

ull map1[LMAX][LMAX] = { 0, };
ull map0[LMAX][LMAX] = { 0, };


int main() {
    cin >> A >> B >> C >> D;

    ull i, j;

    map1[A][B] = 0;
    map0[A][B] = 1;
    for (ull i = A+1; i <= C; i++) {
        map0[i][B] = my_mult(map0[i - 1][B], B);
    }
    for (ull j = B+1; j <= D; j++) {
        map0[A][j] = my_mult(map0[A][j-1], A);
    }

    for (ull i = A + 1; i <= C; i++) {
        for (ull j = B + 1; j <= D; j++) {
            map0[i][j] = my_mult(my_plus(map0[i - 1][j], map1[i - 1][j]), j);

            map1[i][j] = my_plus(map0[i][j-1], my_mult(map1[i][j-1], i));
        }
    }


    ull ans = my_plus(map0[C][D],  map1[C][D]);
    cout << ans << endl;
}

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

int main() {
  int n,m;
  cin >> n;
  vector<int> t(n);
  int total = 0;
  for(int i=0; i<n; i++){
    cin >> t[i];
    total += t[i];
  }
  cin >> m;
  vector<vector<int>> p(2,vector<int>(m));
  for(int i=0; i<m; i++){
    cin >> p[0][i] >> p[1][i];
    cout << total - t[p[0][i]-1] + p[1][i] << endl;
  }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  int x = -1, y = -1;
  for (int i = 1; i < 1000; i++) {
    if (i * (i + 1) == 2 * n) {
      x = i;
      y = i + 1;
      break;
    }
  }
  
  if (x == -1) {
    cout << "No\n";
    return 0;
  }
  
  vector<int> v[y];
  int now = 1;
  for (int i = 0; i < y - 1; i++) {
    for (int j = 0; j < x - i; j++) {
      v[i].emplace_back(now);
      now++;
    }
  }
  now = 1;
  for (int i = 1; i < y; i++) {
    for (int j = 0; j + i < y; j++) {
      v[i + j].emplace_back(now);
      now++;
    }
  }
  
  cout << "Yes\n" << y << '\n';
  for (int i = 0; i < y; i++) {
    cout << x;
    for (int j = 0; j < x; j++) {
      cout << " " << v[i][j];
    }
    cout << '\n';
  }
}

Measured memory_bytes: 2304
n = int(input())
d = []
for i in range(n):
  t = [int(x) for x in input().split()]
  d.append(t)

for i in range(n-2):
  if d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]:
    print('Yes')
    exit()

print('No')    

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int n;
  cin >> n;
  string s="No";

  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      if(i*j==n) s="Yes";
    }
  }

  cout << s << endl;
  
  return 0;
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    const times = arg.split("\n")[0].split(" ");
  	let start = Math.max(times[0],times[2]);
  	let end = Math.min(times[1],times[3]);
  	let ans = 0;
  	end - start > 0? ans = end - start:'';
    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int main(){
    int n;
    scanf("%d", &n);
    unordered_map<int, int> m;
    while(n--){
        int k;
        scanf("%d", &k);
        if(m[k]==0){
            m[k]++;
        }else{
            m.erase(k);
        }
    }
    printf("%d\n", m.size());
}

Measured memory_bytes: 4388
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f(A, B, C) :- A =< C , C =< B.

main :-
    get_number(A, B, C),
    f(A, B, C) -> writeln("Yes") ; writeln("No").


Measured memory_bytes: 8000
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

void main_()
{
    const unordered_map<char, int> c2i = { { 'M', 0 }, { 'A', 1 }, { 'R', 2 }, { 'C', 3 }, { 'H', 4 } };

    ll N;
    array<ll, 5> ss = {};
    cin >> N;
    for (ll i = 0; i < N; ++i) {
        string s;
        cin >> s;
        auto it = c2i.find(s[0]);
        if (it != end(c2i)) {
            ss[it->second]++;
        }
    }

    ll ans = 0;
    for (ll i = 0; i < 3; ++i) {
        for (ll j = i + 1; j < 4; ++j) {
            for (ll k = j + 1; k < 5; ++k) {
                ans += ss[i] * ss[j] * ss[k];
            }
        }
    }

    cout << ans << "\n";
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String[] str = new String[n];
      boolean count = true;
      for(int i = 0;i < n;i++){
      	str[i] = sc.next();
      }
      for(int i = 1;i < n;i++){
      	for(int j = 0;j < i;j++){
        	if( str[i].equals(str[j]) ) count = false;
        }
      }
      for(int i = 1;i < n;i++){
      	if(!(str[i-1].substring(str[i-1].length()-1,str[i-1].length()).equals(str[i].substring(0,1)) ))
          count = false;
      }
      if(count)System.out.println("Yes");
      else System.out.println("No");
    }
}


Measured memory_bytes: 21844
class Shop():
    def __init__(self, a, b):
        self.a = a
        self.b = b

N, M = [ int(x) for x in input().split(' ')]
shops = []
for i in range(N):
    a, b = [int(x) for x in input().split(' ')]
    shops.append(Shop(a, b))

shops.sort(key=lambda x: x.a)

cost = 0
bought = 0
for i in range(N):
    shop = shops[i]
    if (shop.b <= M - bought):
        cost += shop.a * shop.b
        bought += shop.b
    else:
        cost += shop.a * (M - bought)
        bought += (M - bought)
    if (bought == M):
        break

print(cost)


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

int main(){
    ll h, w;
    cin >> h >> w;

    ll ans;
    if (min(h, w) == 1) ans = 1;
    else if (w % 2 == 0){
        ans = w / 2 * h;
    }
    else {
        if (h % 2 == 0){
            ans = (w + 1) / 2 * ((h + 1) / 2) + ((w + 1) / 2 - 1) * ((h + 1) / 2);
        }
        else {
            ans = (w + 1) / 2 * ((h + 1) / 2) + ((w + 1) / 2 - 1) * ((h + 1) / 2 - 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
   
int main(){
  
int a=0,b=0; 
scanf("%d %d",&a,&b);
if(a<b) {printf("a < b\n");}
else if(a>b) {printf("a > b\n");}
else{printf("a == b\n");}
  
return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,j;
    cin>>n;
    long long int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    long long int dp[n][n];
    memset(dp, 0, sizeof(dp));
    for(i=n-1;i>=0;i--)
        for(j=i;j<n;j++)
        {
            if(i==j)
                dp[i][j] = a[i];
            else
            {
                dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1]);
            }
        }
    cout<<dp[0][n-1];
}

Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
int main(void){
    ll n,m;cin>>n>>m;
    if(n*2>=m)cout<<m/2;
    else{
        ll x=m-n*2;
        cout<<n+x/4;
    }
}

Measured memory_bytes: 256
import java.util.*;

class Main{           
  
   public static void main(String[] args){
       Scanner sc = new Scanner(System.in);  
  
       int N = sc.nextInt();
       String s = sc.next();
       String t = sc.next();
       int index = -1;
       for(int i = 0;i < N;i++){
         String sub  =  s.substring(i);   
         String sub2 = t.substring(0,N-i);
         if(sub.equals(sub2)){
             index = i;
             break;
         }
       }
       
       if(index == -1){
           index = N;
       }
     
       System.out.println(N + index);
   }         
         
 }
  

        
        


        
        
        
        
        
        

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;

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

  int n; cin >> n;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];

  if(n == 1) {
    cout << "Yes" << '\n';
    return 0;
  }

  bool flag = true;
  for(int i = n-1; i > 0; i--) {
    ll tmp = h[i-1]-h[i];
    if(tmp <= 0) continue;
    else if(tmp == 1) h[i-1]--;
    else flag = false;
  }

  cout << (flag ? "Yes" : "No") << '\n';
  return 0;
}


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

#define ll long long

ll N, K, G[5000], C[5000];
vector < ll > costs, vis;

void dfs(ll u){
	vis[u] = true;
	costs.push_back(C[u]);
	if (!vis[G[u]])
		dfs(G[u]);
	else
		return;
}

int main(){
	cin >> N >> K;
	for (ll i = 0; i < N; i ++){
		ll X; cin >> X; X -= 1;
		G[i] = X;
	}
	for (ll i = 0; i < N; i ++)
		cin >> C[i];
	
	long long result = -2e18;


	for (ll i = 0; i < N; i ++){
		vis = vector < ll > (N, 0);
		costs.clear();
		dfs(G[i]);
		// for (auto x : costs) cout << x << " "; cout << "\n";
		// cout << "A\n";

		ll sz = costs.size();
		ll p0 = K / sz, p1 = K % sz;
		long long curr1 = 0;
		for (ll i = 0; i < costs.size() && i < K; i ++){
			curr1 += costs[i];
			// cout << curr1 << "\n";
			result = max(curr1, result);
		}
		// cout << "B\n";
		// cout << curr1 << "\n";

		if (p0 > 0){
			// cout << "A " << p0 << "\n";
			long long curr2 = accumulate(costs.begin(), costs.end(), 0ll) * (p0);
			// cout << curr2 << "\n";	
			for (ll i = 0; i < costs.size() && i < p1; i ++){
				curr2 += costs[i];
				result = max(curr2, result);
			}
		}
		if (p0 > 1){
			long long curr3 = accumulate(costs.begin(), costs.end(), 0ll) * (p0 - 1);
			for (ll i = 0; i < costs.size() && i < K; i ++){
				curr3 += costs[i];
				result = max(curr3, result);
			}
		}
	}

	cout << result << "\n";
	// cout << moves << "\n";
	// for (auto x : costs){
	// 	cout << x << " ";
	// }	cout << "\n";

}


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

int main() {
	ll a, v;
	ll b, w;
	ll t;
	cin >> a >> v >> b >> w >> t;
	ll dif = abs(a - b);
	if ((v - w) * t >= dif)cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i*4 + j*7 == n) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 35392
#include<stdio.h>
#include<math.h>
int isprime(int);
int main(){
  int count,prime=0;
  int i,res;
  int num[10000];

  scanf("%d",&count);

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

  for(i=0;i<count;++i){
	  prime+=isprime(num[i]);
  }
  printf("%d\n",prime);

  return 0;
}
    
int isprime(int x){
  int j=3;
  int N;

  if(x==2) return 1;
  if(x<2||x%2==0) return 0;
  

  N=(int)sqrt((double)x);

    while(j<=N){ 
	
	if(x%j==0) return 0;
	
	j+=2;
    }

    return 1;
  }

Measured memory_bytes: 632