akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <vector>

const int Inf = 0x3f3f3f3f;
const int MN = 100005, MS = 1 << 18 | 7;

int N, ex[MN], ey[MN];
std::vector<int> G[MN];

int par[MN], dep[MN], siz[MN], pref[MN], top[MN], dfn[MN], dfc;
void DFS0(int u, int p) {
	dep[u] = dep[par[u] = p] + 1, siz[u] = 1;
	for (int v : G[u]) if (v != p) {
		DFS0(v, u);
		siz[u] += siz[v];
		if (siz[pref[u]] < siz[v]) pref[u] = v;
	}
}
void DFS1(int u, int t) {
	dfn[u] = ++dfc, top[u] = t;
	if (pref[u]) DFS1(pref[u], t);
	for (int v : G[u]) if (v != par[u] && v != pref[u]) DFS1(v, v);
}

#define li (i << 1)
#define ri (li | 1)
#define mid ((l + r) >> 1)
#define ls li, l, mid
#define rs ri, mid + 1, r
struct dat {
	int mn, v, i;
	dat() { mn = Inf; }
	dat(int z) { mn = v = 0, i = z; }
	dat(int x, int y, int z) { mn = x, v = y, i = z; }
} tr[MS];
struct tag {
	int a, w;
	tag() { a = w = 0; }
	tag(int x, int y) { a = x, w = y; }
} tg[MS];
inline dat operator + (dat a, dat b) { return a.mn < b.mn ? a : b; }
inline void operator += (tag &a, tag b) { a.a += b.a, a.w ^= b.w; }
inline void operator += (dat &a, tag b) { a.mn += b.a, a.v ^= b.w; }
inline void P(int i, tag x) { tr[i] += x, tg[i] += x; }
void Pushdown(int i) { if (tg[i].a || tg[i].w) P(li, tg[i]), P(ri, tg[i]), tg[i] = tag(); }
void Build(int i, int l, int r) {
	if (l == r) return tr[i] = dat(l), void();
	Build(ls), Build(rs);
	tr[i] = tr[li] + tr[ri];
}
void Mdf(int i, int l, int r, int a, int b, tag x) {
	if (r < a || b < l) return ;
	if (a <= l && r <= b) return P(i, x);
	Pushdown(i);
	Mdf(ls, a, b, x), Mdf(rs, a, b, x);
	tr[i] = tr[li] + tr[ri];
}

inline void Modify(int x, int y, tag z) {
	while (top[x] != top[y]) {
		if (dep[top[x]] < dep[top[y]]) std::swap(x, y);
		Mdf(1, 1, N, dfn[top[x]], dfn[x], z);
		x = par[top[x]];
	}
	if (dep[x] > dep[y]) std::swap(x, y);
	if (x != y) Mdf(1, 1, N, dfn[x] + 1, dfn[y], z);
}

int main() {
	scanf("%d", &N);
	for (int i = 1, x, y; i < N; ++i) {
		scanf("%d%d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	DFS0(1, 0), DFS1(1, 1);
	Build(1, 1, N);
	Mdf(1, 1, N, 1, 1, tag(Inf, 0));
	for (int i = 1; i < N; ++i) {
		scanf("%d%d", &ex[i], &ey[i]);
		Modify(ex[i], ey[i], tag(1, i));
	}
	for (int i = 1; i < N; ++i) {
		if (tr[1].mn != 1) return puts("NO"), 0;
		int j = tr[1].v;
		Mdf(1, 1, N, tr[1].i, tr[1].i, tag(Inf, 0));
		Modify(ex[j], ey[j], tag(-1, j));
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 23820
#include<bits/stdc++.h>
#define ll long long
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl;
#define mod 1000000007L
using namespace std;
char s[10005];
ll d,n;
ll memo[105][10005][2][2];
ll dp(ll sum,ll i,ll smaller,ll flag)
{
    //watch(sum)
    //watch(i)
    //watch(smaller)
    //watch(flag)
    ll cnt=0,max_digit;
    if(memo[sum][i][smaller][flag]!=-1)
    {
        return memo[sum][i][smaller][flag];
    }
    if(i==n)
    {
        if(sum==0&&flag)
        {
            return 1;
        }
        return 0;
    }
    if(smaller)
    {
        max_digit=9;
    }
    else
    {
        max_digit=s[i]-'0';
    }
    //watch(max_digit)
    for(ll j=0;j<=max_digit;++j)
    {
        ll temp_smaller=1,temp_flag=flag;
        if(!smaller&&j==max_digit)
        {
            temp_smaller=0;
        }
        if(j)
        {
            temp_flag=1;
        }
        //watch(i)
        //watch(j)
        //watch(temp_smaller)
        cnt=(cnt+dp((sum+j)%d,i+1,temp_smaller,temp_flag))%mod;
        //watch(cnt)
    }
    return memo[sum][i][smaller][flag]=cnt;
}
int main()
{
    scanf("%s%lld",s,&d);
    n=strlen(s);
    memset(memo,-1,sizeof memo);
    printf("%lld",dp(0,0,0,0));
    return 0;
}




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

bool eight(int n) {
    int ans = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) ans++;
    }
    return ans == 4;
}

void solve() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 105; i <= n; i += 2) {
        if (eight(i)) ans++;
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}


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

namespace ABC_074
{
    class Program
    {
        static void Main(string[] args)
        {
            string strX, strA;
            strX = Console.ReadLine();
            strA = Console.ReadLine();

            int X = int.Parse(strX);
            int A = int.Parse(strA);

            X = X * X;
            X = X - A;

            Console.WriteLine(X);
#if Debug
#endif

        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<bitset>
#define ll long long
using namespace std;
int n,m,cnt,ans,sum;
bitset<2000010> f;
int main()
{
	int i,s,a,b,j,k;
	scanf("%d",&n);f[0]=1;
	for(i=1;i<=n;i++)scanf("%d",&a),f|=(f<<a),sum+=a;
	for(i=sum/2;i>=0 && !f[i];i--);
	printf("%d",sum-i);
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, D;
	cin >> N >> M >> D;
	if (D != 0) {
		cout << fixed << setprecision(15) << (double)2 * (N - D) * (M - 1) / ((double)N*N) << endl;
	}
	else {
		cout << fixed << setprecision(15) << (double)(N) * (M - 1) / ((double)N*N) << endl;
	}
	//cout << res << endl;
}

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

int main() {
  int n,k;cin>>n>>k;
  int ans=k;
  k--;
  for(int i=1;i<n;i++){
    ans*=k;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int MN = 2e5+2;
vector<int> inds[MN];
int main () {
	int n;
	scanf ("%d",&n);
	for (int i = 1; i <= n; i++) {
		int a;
		scanf ("%d",&a);
		inds[a].push_back(i);
	}
	int last = 0; int i = 1;
	for (; i <= n; i++) {
		auto it = lower_bound(inds[i].begin(),inds[i].end(),last);
		if (it == inds[i].end()) break;
		else last = *it;
	}
	printf ("%d\n",i==1?-1:n-i+1);
	return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vi = vector<int>;
using vchar = vector<char>;
using vstr = vector<string>;
using pii = pair<int,int>;
using pll =  pair<ll,ll>;

const ll mod = 1000000007;

#define pi acos(-1)
#define pb push_back
#define mp make_pair
#define test int TEST;cin>>TEST;while(TEST--)
#define all(x) x.begin(),x.end()
#define vrevsort(x) sort(x.rbegin(),x.rend())
#define opy cout<<"Yes"
#define opn cout<<"No"
#define flush fflush(stdout)
#define NL cout<<'\n'
#define SP cout<<' '

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;

void solve(){
string s;
cin>>s;
int ans=0;
for(auto x:s) {
	ans+=int(x-'0');
	ans=ans%9;
}
if(ans) opn;
else opy;
 
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
   // test{solve();cout<<'\n';}
	solve();
    
}


Measured memory_bytes: 3708
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int main(){
    ios::sync_with_stdio(false);
    int a,b,c; cin >> a >> b >> c;
    set<int> s;
    for(int i=1;i<=(b);i++){
        s.insert(i*a%b);
    }
    if(s.count(c)==0) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
"use strict";

const Main = args => {
  const input = args.trim().split("\n");
  const pixels = input.slice(1);
  const result = [];
  pixels.forEach(e => {
    result.push(e);
    result.push(e);
  });
  console.log(result.join('\n'));
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 210000


int main(){
	vector<long long>a;
	int n, k;
	long long x, y, z;
	long long s;
	int ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	f(i, n){
		scanf("%lld", &x);
		a.push_back(x);
	}
	s = 0;
	f(i, n){
		scanf("%lld", &x);
		a[i] -= x;
		if (a[i] < 0)ans++;
		s += a[i];
	}
	if (s < 0){
		printf("-1\n");
		return 0;
	}
	sort(a.begin(), a.end(),greater<long long>());
	int r = n - 1;
	s = 0;
	f(i , n){
		if (a[r] >= 0)break;
		s += a[i];
		a[i] = 0;
		ans++;
		while (s > 0){
			if (a[r] >= 0)break;
			if (s + a[r] >= 0){
				s += a[r];
				a[r] = 0;
				r--;
			}
			else{
				a[r] += s;
				s = 0;
			}
		}
	}
	printf("%d\n", ans);


	return 0;
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	ll n ;
	cin >> n ;
	vector<ll> a(n);
	rep(i,n) cin >>a[i];

	ll ans = 100100100;
	for(int i = -100 ; i <= 100 ; i++){
		ll tmp = 0;
		for(int j = 0 ; j < n ; j++){
			tmp += (a[j] - i)*(a[j] - i);
		}
		chmin(ans,tmp);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
from math import ceil

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

"""
操作X: aに1を足す
操作Y: aに2を足す
操作Z: bに1を足す

問題文の操作はXと一致する。
(X = Y + Z)

if Yの回数 <= Zの回数:
    Yes (不足分はXで処理できる)
else:
    No
"""

cnt = 0

for i in range(N):
    a, b = A[i], B[i]

    # 操作Z
    if a > b:
        Z = a - b
        B[i] += Z
        cnt += Z

for i in range(N):
    # 操作Y
    if A[i] < B[i]:
        Y = (B[i] - A[i]) // 2
        A[i] += 2 * Y
        cnt -= Y

        # 操作X
        if A[i] < B[i]:
            A[i] += 2
            B[i] += 1

if cnt <= 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4596
/*A駅とB駅を結ぶ鉄道があり、運賃はX円です。また、B駅とC駅を結ぶバスがあり、運賃はY円です。
joisinoお姉ちゃんは,A駅からB駅まで鉄道で移動し,B駅からC駅までバスで移動すると、
バスの運賃が半額になる特別券を手に入れました。この特別券を用いたとき、A駅から 
C駅まで移動するのにいくらかかるか求めてください。*/

#include <stdio.h>

int main(void){
  int trainfee,basfee,allfee;
  scanf("%d %d",&trainfee,&basfee);
  allfee = trainfee + basfee/2;
  printf("%d",allfee);
  return 0;
}

Measured memory_bytes: 128
n,k=map(int,input().split())
mod=10**9+7
import sys
sys.setrecursionlimit(10**9)
root=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    root[a-1].append(b-1)
    root[b-1].append(a-1)
def perm(k,n):
    x=1
    if k-n+1<=0:
        return 0
    for i in range(k,k-n,-1):
        x=x*i%mod
    return x
def dfs(node,depth,prev): 
    l=len(root[node])
    d=depth
    x=1
    if l==0:
        return 1
    if l==1 and depth>1:
        return 1
    if depth>1:
        x=perm(k-d,l-1)
    else:
        x=perm(k-d,l)
    for y in root[node]:
        if y!=prev:
            x=x*dfs(y,2,node)%mod
    return x%mod
count=dfs(0,1,0)*k%mod
print(count if count>0 else 0)

Measured memory_bytes: 92716
room = [[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]]]
for i in range(4):
    for j in range(3):
        for k in range(10):
            room[i][j].append(0)
n = int(input())
for _ in range(n):
    b, f, r, v = map(int, input().split())
    room[b-1][f-1][r-1] += v

for i in range(4):
    for j in range(3):
        print(" "+" ".join(map(str, room[i][j])))
    if i != 3: print("#"*20)



Measured memory_bytes: 5604
import java.util.Scanner;

public class Main {
	public static void main(String []args){
		//????????£?????????????????????
		Scanner sc = new Scanner (System.in);
		//a?????????
		int a = sc.nextInt();
		//b?????????
		int b = sc.nextInt();
		//?????¶???
		if(a < b){
			System.out.println("a < b");
		}else if(b <a){
			System.out.println("a > b");
		}else if(a == b){
			System.out.println("a == b");
		}
	}
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long long LL;
#define REP(i,N) for (int i=0; i<N; i++)

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if (b - a <= 0) cout << "delicious" << endl;
  else if (b - a > 0 && b - a <= x) cout << "safe" << endl;
  else cout << "dangerous" << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)
	x := make([]int, n)
	for i := range x {
		fmt.Scan(&x[i])
	}

	var sum int
	for i := range x {
		sum += x[i]
	}
	avg := float64(sum) / float64(len(x))
	avgInt, _ := strconv.Atoi(fmt.Sprintf("%.0f", avg))
	var min int
	for i := range x {
		min += (x[i] - avgInt) * (x[i] - avgInt)
	}
	fmt.Println(min)
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
	int H,N,W;
	cin>>H>>W>>N;
	int q=H>W?H:W;
	if(N%q==0)
		cout<<N/q;
	else
	cout<<int(N/q)+1<<endl;
	return 0;
}

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

int main(){

    int n;
    cin >> n;

    vector<long long> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
        v[i] -= i;
    }
    sort(v.begin(), v.end());

    long long sum = 0;
    long long off = v[n/2];
    for(int i = 0; i < n; i++){
        sum += abs(v[i] - off);
    }
    cout << sum << endl;
    
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N = 5;
int ans;
char s[N], t[N];
int main(){
    scanf("%s", s + 1);
    scanf("%s", t + 1);
    for(int i = 1;i <= 3; i++)if(s[i] == t[i])ans++;
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int>vec1(N-1);
  vector<int>vec2(N);
  
  for (int i=0; i<N-1; i++){
    cin >> vec1.at(i);
    vec2.at(vec1.at(i)-1)++;
  }
  
  for (int i=0; i<N; i++){
    cout << vec2.at(i) << endl;
  }
}

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

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

def solve(s: str, t: str):
    s2 = list(s)
    s2.sort()
    s2 = "".join(s2)

    t2 = list(t)
    t2.sort(reverse = True)
    t2 = "".join(t2)

    if s2 < t2:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    t = next(tokens)  # type: str
    solve(s, t)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

ll modpow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = modpow(a, b/2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * modpow(a, b-1)) % MOD;
    }
}

const int MAX_N = 200010;

ll fact[MAX_N], finv[MAX_N];
ll comb(int n, int r){
    if(n < r || r < 0) return 0;
    return fact[n] * finv[n-r] % MOD * finv[r] % MOD;
}

ll calc(int n){
    fact[0] = finv[0] = 1;
    for(int i=1; i<=n; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        finv[i] = modpow(fact[i], MOD-2);
    }
}

int main(){
    ll n, m, k; cin>>n>>m>>k;

    calc(200005);

    ll ans = 0;
    for(ll i=1; i<m; i++){
        ans += (i * (m - i) * n * n % MOD) * comb(n * m - 2, k - 2);
        ans %= MOD;
    }

    for(ll i=1; i<n; i++){
        ans += (i * (n - i) * m * m % MOD) * comb(n * m - 2, k - 2);
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3328
//package cp;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
	long gcd(long a,long b) {if(b==0)return a;else return gcd(b,a%b);}
	void swap(long a,long b) {long temp=a;a=b;b=temp;}
	StringBuilder sb=new StringBuilder();
	Integer[] ARR=new Integer[5];
	//Integer sort-TLE-Initialize object elements i.e a[0].
	long ceil(double n) {
//		System.out.println(n);
		return (long)Math.ceil(1.0*n);}
	void divisor(long n,int start) {
		int cnt=0;for(int i=start;i<=Math.sqrt(n);i++) {
		if(n%i==0) {if(i==n/i)cnt++;else cnt+=2;}}}
	
	public static void main(String[] args) throws IOException {	
		PrintWriter out = new PrintWriter(System.out);
		Readers.init(System.in);
		Main obj=new Main();
		int a = Readers.nextInt();
	    int b = Readers.nextInt();
	    int c = Readers.nextInt();
	    int k = Readers.nextInt();
	    int cnt=0;
	    while(b<=a) {
	    	b=b*2;
	    	cnt++;
	    }
	    while(c<=b) {
	    	c=c*2;
	    	cnt++;
	    }
	    if(cnt<=k)System.out.println("Yes");
	    else System.out.println("No");
		out.flush();
	}
}
class Readers {
 
    static BufferedReader reader;
 
    static StringTokenizer tokenizer;
 
 
 
    /** call this method to initialize reader for InputStream */
 
    static void init(InputStream input) {
 
        reader = new BufferedReader(
 
                     new InputStreamReader(input) );
 
        tokenizer = new StringTokenizer("");
 
    }
 
 
 
    /** get next word */
 
    static String next() throws IOException {
 
        while ( ! tokenizer.hasMoreTokens() ) {
 
            //TODO add check for eof if necessary
 
            tokenizer = new StringTokenizer(
 
                   reader.readLine() );
 
        }
 
        return tokenizer.nextToken();
 
    }
 
 
 
    static int nextInt() throws IOException {
 
        return Integer.parseInt( next() );
 
    }
 
	
 
    static double nextDouble() throws IOException {
 
        return Double.parseDouble( next() );
 
    }
    
    
    static long nextLong() throws IOException{
    	
		return Long.parseLong(next());
	}
 
}


Measured memory_bytes: 32936
from collections import defaultdict, deque, Counter
import sys
import bisect
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7

ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"


def main():
    # N = int(input())
    S = input()

    if S == "SUN": print(7)
    if S == "MON": print(6)
    if S == "TUE": print(5)
    if S == "WED": print(4)
    if S == "THU": print(3)
    if S == "FRI": print(2)
    if S == "SAT": print(1)

    # A, B = [int(a) for a in input().split()]


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#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 <iomanip> // double
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi data(n);
  rep(i,n) cin >> data[i];
  in6 sum = 0;
  rep(i,n) sum += data[i];
  sort(data.begin(), data.end());
  int min = data[0];
  int max = data[n - 1];
  cout << min << " " << max << " " << sum << "\n";
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int INF=1e18;
const int MOD=998244353;
const int MAX=200001;
int fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

int COM(int n,int k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int powMOD(int n,int r){
    if(r==0)return 1;
    if(r%2==0)return powMOD(n,r/2)*powMOD(n,r/2)%MOD;
    if(r%2==1)return powMOD(n,r-1)*n%MOD;
}

void add(int &x,int y){
    x+=y;
    x%=MOD;
}

signed main(){
    int n,s;cin>>n>>s;
    int a[n];
    REP(i,n)cin>>a[i];
    int dp[n+1][s+1];
    REP(i,n+1)REP(j,s+1)dp[i][j]=0;
    dp[0][0]=1;
    REP(i,n) REP(j,s+1)add(dp[i+1][j],(j-a[i]>=0?dp[i][j-a[i]]:0)+2*dp[i][j]);
    cout<<dp[n][s]<<endl;
}

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

int main(void)
{
	int N, K;
	string S;

	cin >> N >> K >> S;

	if (S[K - 1] == 'A') {
		S[K - 1] = 'a';
	}
	else if (S[K - 1] == 'B') {
		S[K - 1] = 'b';
	}
	else S[K - 1] = 'c';

	cout << S << endl;

	return 0;
}

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

int main(){
	int x,y;
	cin >> x >> y;

	if(x==2||y==2||x==11||x==12){
		cout << "No" << endl;
		return 0;
	}else if(y==4||y==6||y==9||y==11){
		if(x==4||x==6||x==9){
			cout << "Yes" << endl;
			return 0;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}else if(x==4||x==6||x==9){
		cout << "No" << endl;
		return 0;
	}else{
		cout << "Yes" << endl;
		return 0;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int a[3];rep(i,0,3)cin>>a[i];
    sort(a,a+3);
    cout<<a[2]-a[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});

function readline() {
    return inputString[currentLine++];
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = parseInt(a[i]);

    return a;
}

function main(){
    let [n,k] = ti(readline().split(' '));
    let w = new Array(n);
    let v = new Array(n);

    for(let i = 0; i < n; i++){
        let [x,y] = ti(readline().split(' '));
        w[i] = x;
        v[i] = y;
    }

    let dp = new Array(k+1);
    for(let i = 0; i < k+1; i++){
        dp[i] = new Array(n);
    }

    for(let i = 0; i < k+1; i++){
        for(let j = 0; j < n; j++){
            if(j === 0){
                dp[i][j] = w[j] <= i ? v[j] : 0;
            }else{
                if(i-w[j] >= 1)
                    dp[i][j] = Math.max(dp[i][j-1], v[j] + dp[i-w[j]][j-1]);
                else
                    dp[i][j] = dp[i][j-1];
            }            
        }
    }

    console.log(dp[k][n-1]);
}

Measured memory_bytes: 231296
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;
typedef deque<bool> db;
typedef deque<deque<bool> > ddb;

// cout pair
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    s << p.first << " " << p.second << "\n"; return s;
}

// cout vector<pair>
template<typename T1, typename T2> ostream& operator<<(ostream& s, const vector<pair<T1, T2> >& vp) {
    int len = vp.size(); s << "\n";
    for (int i = 0; i < len; ++i) { s << vp[i]; }
    s << "\n"; return s;
}

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size(); s << "\n";
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    s << "\n"; return s;
}

// cout deque
template<typename T> ostream& operator<<(ostream& s, const deque<T>& v) {
    int len = v.size(); s << "\n";
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) { s << vv[i]; }
    return s;
}

// cout 2-dimentional deque
template<typename T> ostream& operator<<(ostream& s, const deque< deque<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) { s << vv[i]; }
    return s;
}

int main() {
    vector<string> s(3);
    cin >> s[0];
    cin >> s[1];
    cin >> s[2];
    ddi sim(3);
    rep (i, 3) {
        int len = (int)s[i].length();
        sim[i].resize(len);
        rep (j, len) {
            sim[i][j] = (s[i][j] - 'a');
        }
    }
    int turn = 0;
    while (true) {
        if (sim[turn].empty()) {
            printf("%c\n", ('A' + turn));
            return 0;
        }
        int next = sim[turn].front();
        sim[turn].pop_front();
        turn = next;
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))
y = sorted(x)
med = (y[n//2 - 1] + y[n//2])/2
for i in range(n):
    if x[i] <= med:
        print(y[n//2])
    else:
        print(y[n//2-1])


Measured memory_bytes: 25348
using System;

public class Program
{
    private int N;
    private int[] A;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.IntArray();
        double sum = 0;
        foreach (int i in A)
        {
            sum += 1.0 / i;
        }
        Console.WriteLine(1.0/sum);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

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

int main()
{
  int N, C, K;
  cin >> N >> C >> K;

  vector<int> T(N);
  for (int i = 0; i < N; i++)
    cin >> T[i];
  sort(T.begin(), T.end());

  int time = T[0], count = C, ans = 0;
  for (int i = 0; i < N; i++)
  {
    if (count == C || time + K < T[i])
    {
      count = 1;
      ans++;
      time = T[i];
      continue;
    }
    count++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

ll A[101010];
ll used[101010];

ll next(ll x){
    ll now = A[x] / (1 << used[x]);
    if(now == 0)return 0;
    ll n = A[x] / (1 << (used[x] + 1));
    return now - n;
}

int main(){

    ll N, M;
    cin >> N >> M;
    ll sum = 0;
    priority_queue<P>Q;
    rep(i, N){
        cin >> A[i];
        sum += A[i];
        Q.push(P(next(i), i));
    }
    for(;!Q.empty() && M > 0; M--){
        ll idx = Q.top().second;
        ll bene = Q.top().first;
        Q.pop();
        if(bene == 0)break;
        // cout << idx << " : " << bene << endl;
        sum -= bene;
        used[idx]++;
        Q.push(P(next(idx), idx));
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int pre[maxn];
void init()
{
	memset(pre,0,sizeof(pre));
	pre[2]=0;
	for(int i=2;i*i<=2e5;i++)
	{
		if(pre[i]==0)
		{
			for(int j=i*i;j<=2e5;j+=i)
			{
				pre[j]=1;
			}
		}
	}
 } 
int main()
{
	int x;
	init();
	scanf("%d",&x);
	for(int i=x;i<=2e5;i++)
	{
		if(pre[i]==0)
		{
			printf("%d\n",i);
			break;
		}
	}
	
	
	return 0;
}

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

int kind(string a){
  int p=1;
  if(a.size()==1){
    return 1;
  }
  vector<char> kich = {a.at(0)};
  for(int i=1;i<a.size();i++){
    int x=0;
    for(int j=0;j<kich.size();j++){
      if(a.at(i)!=kich.at(j))
        x++;
    }
    if(x==kich.size()){
      kich.push_back(a.at(i));
    }
  }
  return kich.size();
}

vector<string> answer(int N){
  if(N==1){
    vector<string> yey;
    yey = {"a"};
    return yey;
  }
  
  vector<string> wow=answer(N-1);
  vector<string> wowow;
  for(int i=0;i<wow.size();i++){
    int p = kind(wow.at(i));
    wowow.push_back(wow.at(i)+'a');
    wowow.push_back(wow.at(i)+'b');
    if(p>=2)
      wowow.push_back(wow.at(i)+'c');
    if(p>=3)
      wowow.push_back(wow.at(i)+'d');
    if(p>=4)
      wowow.push_back(wow.at(i)+'e');
    if(p>=5)
      wowow.push_back(wow.at(i)+'f');
    if(p>=6)
      wowow.push_back(wow.at(i)+'g');
    if(p>=7)
      wowow.push_back(wow.at(i)+'h');
    if(p>=8)
      wowow.push_back(wow.at(i)+'i');
    if(p>=9)
      wowow.push_back(wow.at(i)+'j');
  }
  return wowow;
}

int main() {
  int N;
  cin >> N;
  vector<string> wowow = answer(N);
  for(int i=0;i<wowow.size();i++){
    cout << wowow.at(i) << endl;
  }
}

Measured memory_bytes: 9164
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner=new Scanner(System.in);
        while(true){
            String s=scanner.next();
            String[] strings=s.split("");
            if(strings[0].equals("0")){
                return;
            }
            long result=0;
            for(int i=0;i<strings.length;i++){
                int c=Integer.parseInt(strings[i]);
                result+=c;
            }
            System.out.println(result);

        }
    }

}



Measured memory_bytes: 27144
/*************************************************************************
  >         File: A.cc
  >       Author: lyyllyyl
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Sun 23 Oct 2016 09:46:01 PM CST
*************************************************************************/
#include <bits/stdc++.h>

int main() {
  std::ios::sync_with_stdio(0);
  std::string s;
  std::cin >> s;
  auto pos = s.find_first_of('C');
  if (pos == std::string::npos) {
    puts("No");
    return 0;
  }
  pos = s.find('F', pos);
  if (pos == std::string::npos) {
    puts("No");
    return 0;
  }
  puts("Yes");


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string> 
#include <cstdlib>/*絶対値取得*/
using namespace std;
#define MAX 200000

int main(){
    int n,i,k,x,sum=0;
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>x;
        (abs(k-x)>=x) ? sum+=(x*2): sum+=abs(2*(k-x));
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
NM = list(map(int,input().split()))
N = NM[0]
M = NM[1]
SC = []
temp = [0] * N
temp2 = [True] * 9
temp3 = []
test = True
test2 = True
for i in range(M):
    SC.append(list(map(int,input().split())))
    Ldigit = SC[i][0]
    Lnum = SC[i][1]
    if temp2[Ldigit-1]:
        temp[Ldigit-1] = Lnum
        temp2[Ldigit-1] = False
    else:
        test2 = False
for i in SC:
    temp3.append("".join(map(str,i)))
if len(set(temp3)) != len(temp3):
    test2 = True
if "10" in temp3 and not N == 1:
    test2 = False
if N > 0 and temp[0] == 0 and not N == 1:
    temp[0] = 1
tempS = "".join(map(str,temp))
if test2:
    for i in range(999):
        if str(i) == tempS:
            print(i)
            test = False
if test or not test2:
    print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n; string s;
    cin>>n>>s;
    int cnt1=0,cnt2=0;
    rep(i,n){
        if(s[i]=='R')cnt1++;
        if(s[i]=='B')cnt2++;
    }
    if(cnt1>cnt2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

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

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n , m , k;
   cin >> n >> m >> k;
   int a[n] , b[m];
   for(int i = 0 ; i < n ; i++)
      cin >> a[i];
   for(int i = 0 ; i < m ; i++)
      cin >> b[i];
   vector <ll> v;
   ll sum = 0;
   int ans = 0;
   for(int i = 0 ; i < n ; i++){
      sum += a[i];
      v.push_back(sum);
      if(sum <= k)
         ans = max(ans , i + 1);
   }
   sum = 0;
   for(int i = 0 ; i < m ; i++){
      sum += b[i];
      if(sum <= k){
         ans = max(ans , i + 1 + int(upper_bound(v.begin() , v.end() , k - sum) - v.begin()));
      }
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 6892
#include <bits/stdc++.h>
using namespace std;
const int maxN = 8005;
string s;
int x, y;
bool dp1[maxN][maxN];
bool dp2[maxN][maxN];
int a[maxN];
int b[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> s;
    int sz1 = 0;
    int sz2 = 1;
    int cur = 0;
    int mark = false;
    int sum1 = 0;
    int sum2 = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'T') {
            if (mark == false) {
                a[sz1] = cur;
                cur = 0;
                sum1 += a[sz1];
                sz1++;
                mark = true;
            }
            else {
                b[sz2] = cur;
                cur = 0;
                sum2 += b[sz2];
                sz2++;
                mark = false;
            }
         }
         else {
            cur++;
         }
    }
    if (cur > 0) {
        if (mark == false) {
            a[sz1] = cur;
            sum1 += cur;
            sz1++;
        }
        else {
            b[sz2] = cur;
            sum2 += cur;
            sz2++;
        }
    }
    cin >> x >> y;
    int need1 = (x + sum1 - 2 * a[0]);
    if (need1 % 2 != 0 || need1 < 0) {
        cout << "No";
        return 0;
    }
    need1 /= 2;
    dp1[0][0] = true;
    for (int i = 1; i < sz1; i++) {
        for (int j = 0; j <= need1; j++) {
            dp1[j][i] = dp1[j][i - 1];
            if (j >= a[i]) {
                dp1[j][i] |= dp1[j - a[i]][i - 1];
            }
        }
    }
    if (dp1[need1][sz1 - 1] == false) {
        cout << "No";
        return 0;
    }
    dp2[0][0] = true;
    int need2 = (y + sum2);
    if (need2 % 2 == 1 || need2 < 0) {
        cout << "No";
        return 0;
    }
    need2 /= 2;
    dp2[0][0] = true;
    for (int i = 1; i < sz2; i++) {
        for (int j = 0; j <= need2; j++) {
            dp2[j][i] = dp2[j][i - 1];
            if (j >= b[i]) {
                dp2[j][i] |= dp2[j - b[i]][i - 1];
            }
        }
    }
    if (dp2[need2][sz2 - 1] == false) {
        cout << "No";
        return 0;
    }
    cout << "Yes";
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  string s;cin >> s;
  int n = (int)s.size();
  vector<int>xd,yd;
  int x,y; cin >> x >> y;
  {
    bool f = true;
    for(int i = 0; i < n; ++i){
      int cnt = 0;
      while(i < n && s[i] != 'T'){
	cnt++;
	i++;
      }
      if(f)xd.push_back(cnt);
      else yd.push_back(cnt);
      f = !f;
    }
  }
  bool f = true;
  bitset<100000> bs;
  bs[50000] = 1;
  {
    bool fst = true;
    for(auto e:xd){
      bitset<100000> bs2;
      for(int i = 0; i < 100000; ++i){
	if(bs[i])
	  if(fst){
	    bs2[i+e] = true;
	    fst = false;
	  } else {
	    bs2[i+e] = bs2[i-e] = true;
	  }
      }
      bs = bs2;
    }
  }
  f = bs[50000+x];
  if(!f){
    cout << "No" << endl;
    return 0;
  }
  bs = 0;
  bs[50000] = true;
  for(auto e:yd){
    bitset<100000> bs2;
    for(int i = 0; i < 100000; ++i){
      if(bs[i])bs2[i+e] = bs2[i-e] = true;
    }
    bs = bs2;
  }
  f = bs[50000+y];
  cout << (f ? "Yes" : "No") << endl;
}



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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, m, q;

li a[55];
li b[55];
li c[55];
li d[55];

inline li eval(const vector<li>& v) {
    //dumpi(v);
    li res = 0;
    rep(i, q) {
        if (v[b[i]] - v[a[i]] == c[i]) {
            res += d[i];
        }
    }
    return res;
}

inline li dfs(vector<li>& v) {
    if (sz(v) == n) {
        return eval(v);
    }
    vector<li> next = v;
    li res = 0;
    repp(i, (v.empty() ? 1 : v.back()),  m + 1) {
        next.pb(i);
        res = max(res, dfs(next));
        next.pop_back();
    }
    return res;
}

int main() {
    cin >> n >> m >> q;
    rep(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }

    vector<li> tmp;
    cout << dfs(tmp) << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

int next(int u){
  for(int v = nt[u];v < n;v++){
    nt[u] = v + 1;
    if(M[u][v]) return v;
  }
  return -1;
}

void dfs_visit(int r){
  for(int i = 0;i < n;i++) nt[i] = 0;
  stack<int> S;
  S.push(r);
  color[r] = GRAY;
  d[r] = ++tt;

  while(!S.empty()){
    int u = S.top();
    int v = next(u);
    if(v != -1){
      if(color[v] == WHITE){
        color[v] = GRAY;
        d[v] = ++tt;
        S.push(v);
      }
    }else {
      S.pop();
      color[u] = BLACK;
      f[u] = ++tt;
    }
  }
}

void dfs(){
  for(int i = 0;i < n;i++){
    color[i] = WHITE;
    nt[i] = 0;
  }
  tt = 0;
  for(int u = 0;u < n;u++){
    if(color[u] == WHITE) dfs_visit(u);
  }
  for(int i = 0;i < n;i++){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
}

int main(){
  int u,k,v;
  cin >> n;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++) M[i][j] = 0;
  }
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    u--;
    for(int j = 0;j < k;j++){
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }
  dfs();
  return 0;
}



Measured memory_bytes: 3104
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
const long long mod = 1000000007;


int main() {
	int N;
	scanf("%d", &N);
	for (int i = 0; i <= N; i++) {
		if ((int)(i*1.08) == N) {
			printf("%d", i);
			return 0;
		}
	}
	printf(":(");
	return 0;
}

Measured memory_bytes: 128