akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define rep(i, b) for( int i = 0; i < b; i++ )

int main(){
	int n, w;
	while( cin >> n >> w, n ){
		int num = (101 % w == 0) ? num = 101/w : num = 101/w+1;
		vector<double> hist(num);
		fill( hist.begin(), hist.end(), 0 );
		double max = 0;
		rep(i, n){
			int v;
			cin >> v;
			hist[v/w]++;
			if( max < hist[v/w] ) max = hist[v/w];
		}
		double sum = 0;
		rep(i, hist.size()) if( hist[i] != 0 ) num = i+1;
		//cout << num << endl;
		rep(i, num){
			sum += (double)(num-i-1) * hist[i] / (max * (double)(num-1));
		}
		sum += 0.01;
		printf("%.5f\n", sum);
	}
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L[i];

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

    ll ans = 0;
    rep(i, N) {
        int a = L[i];
        rep2(j, i + 1, N) {
            int b = L[j];
            int x = a + b;
            int cnt = upper_bound(L.begin(), L.end(), x - 1) - L.begin();
            ans += cnt - (j + 1);
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

int main() {
	bool hantei = false;
	int n;
	while (cin >> n) {
		if (hantei) {
			cout << endl;
		}
		hantei = true;
		int hyou[4][13];
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 13; j++) {
				cin >> hyou[i][j];
			}
		}
		int data[9];
		for (int i = 0; i < 9; i++) {
			cin >> data[i];
		}
		string a;
		string abc = "SCHD";
		for (int i = 0; i < n; i++) {
			int counter = 0;
			bool hantei2 = true;
			int p;
			priority_queue<int, vector<int>, greater<int> > pq;
			for (int j = 0; j < 5; j++) {
				cin >> a;
				int b;
				if (a[0] == 'A') {
					b = 1;
				} else if (a[0] == 'T') {
					b = 10;
				} else if (a[0] == 'J') {
					b = 11;
				} else if (a[0] == 'Q') {
					b = 12;
				} else if (a[0] == 'K') {
					b = 13;
				} else {
					b = a[0]-'0';
				}
				for (int k = 0; k < 4; k++) {
					if (a[1] == abc[k]) {
						if (j == 0) {
							p = k;
						} else {
							if (p != k) {
								hantei2 = false;
							}
						}
						counter += hyou[k][b-1];
						break;
					}
				}
				pq.push(b);
			}
			int cdata[5];
			for (int j = 0; j < 5; j++) {
				cdata[j] = pq.top();
				pq.pop();
			}
			if (cdata[0] == 1 && cdata[1] == 10 && cdata[2] == 11 && cdata[3] == 12 && cdata[4] == 13) {
				if (hantei2) {
					counter *= data[8];
				} else {
					counter *= data[3];
				}
			} else {
				if (cdata[0]+1 == cdata[1] && cdata[1]+1 == cdata[2] && cdata[2]+1 == cdata[3] && cdata[3]+1 == cdata[4]) {
					if (hantei2) {
						counter *= data[7];
					} else {
						counter *= data[3];
					}
				} else if ((cdata[0] == cdata[1] && cdata[0] == cdata[2] && cdata[0] == cdata[3]) || (cdata[1] == cdata[2] && cdata[1] == cdata[3] && cdata[1] == cdata[4])) {
					counter *= data[6];
				} else if ((cdata[0] == cdata[1] && cdata[2] == cdata[3] && cdata[2] == cdata[4]) || (cdata[0] == cdata[1] && cdata[0] == cdata[2] && cdata[3] == cdata[4])) {
					counter *= data[5];
				} else if (hantei2) {
					counter *= data[4];
				} else if ((cdata[0] == cdata[1] && cdata[0] == cdata[2]) || (cdata[1] == cdata[2] && cdata[1] == cdata[3]) || (cdata[2] == cdata[3] && cdata[2] == cdata[4])){
					counter *= data[2];
				} else if ((cdata[0] == cdata[1] && cdata[2] == cdata[3]) || (cdata[0] == cdata[1] && cdata[3] == cdata[4]) || (cdata[1] == cdata[2] && cdata[3] == cdata[4])) {
					counter *= data[1];
				} else if ((cdata[0] == cdata[1]) || (cdata[1] == cdata[2]) || (cdata[2] == cdata[3]) || (cdata[3] == cdata[4])) {
					counter *= data[0];
				} else {
					counter *= 0;
				}
			}
			cout << counter << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int A,B;
int d[11][11];
const int T = 100;
 
int c[T+1][T+1];
 
int main(){
	cin>>A>>B;
	rep1(x,A) rep1(y,B) cin>>d[x][y];
	rep(i,T+1) rep(j,T+1){
		int cij = 0;
		rep1(x,A) rep1(y,B) chmax(cij,d[x][y]-x*i-y*j);
		c[i][j] = cij;
	}
 
	rep1(x,A) rep1(y,B){
		int dxy = 1e9;
		rep(i,T+1) rep(j,T+1) chmin(dxy,x*i+y*j+c[i][j]);
		if(dxy != d[x][y]){
			puts("Impossible");
			return 0;
		}
	}
	puts("Possible");
	int N = (T+1)*2, M = T*2 + (T+1)*(T+1);
	cout<<N<<" "<<M<<endl;
	rep(t,T){
		cout<<1+t<<" "<<2+t<<" X"<<endl;
	}
	rep(t,T){
		cout<<T+3+t<<" "<<T+2+t<<" Y"<<endl;
	}
	rep(i,T+1) rep(j,T+1){
		cout<<1+i<<" "<<T+2+j<<" "<<c[i][j]<<endl;
	}
	cout<<1<<" "<<T+2<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

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

const int MOD=1000000007;
int INF=100100100100100;

int dp[100010][15];
signed main(){
  string s;cin>>s;
  int n=s.length();
  dp[0][0]=1;
  rep(i,n){
    if(s[i]!='?'){
      int x=s[i]-'0';
      rep(j,13){
        dp[i+1][(10*j+x)%13]=dp[i][j];
      }
    }
    else{
      rep(x,10){
        rep(j,13){
          (dp[i+1][(10*j+x)%13]+=dp[i][j])%=MOD;
        } 
      }
    }
  }
  cout<<dp[n][5]<<endl;
  return 0;
}

Measured memory_bytes: 15356
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

using ll = long long;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

#define mp make_pair
#define mt make_tuple

/* ----------- debug ---------- */

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p);

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(ll(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    return b == 0 ? a : gcd(b, a % b);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

template <typename T>
T iceil(T n, T d) {
    return (n + d - 1) / d;
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
    int A, B;
    cin >> A >> B;
    cout << (B % A == 0 ? A + B : B - A) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdint>

int main() {
  int N;
  std::int64_t K;
  std::cin >> N >> K;
  std::vector<double> A(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }
  double lower = 0.0;
  double upper = 1.0e9;
  for (int i = 0; i < 100; ++i) {
    const auto length = 0.5 * (lower + upper);
    std::int64_t count = 0;
    for (const auto log : A) {
      count += static_cast<std::int64_t>(std::ceil(log / length) - 1);
    }
    if (count <= K) {
      upper = length;
    } else {
      lower = length;
    }
  }
  std::cout << static_cast<int>(std::ceil(0.5 * (lower + upper))) << std::endl;
  return 0;
}


Measured memory_bytes: 4772
from collections import deque
n = int(input())
a = list(map(int, input().split()))

q = deque()
t = 0
for i in a:
  if t == 0: q.append(i)
  else: q.appendleft(i)
  t = -1 - t
  
if t == 0: print(*q)
else: print(*reversed(q))

Measured memory_bytes: 32356
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

const INF = 1L << 50;
const P = 100000;

struct Magic {
    int range; /* 0 : single, 1 : all */
    long cost, damage;
}

int N, M;
int[] HP;
Magic[] Ms;

bool input() {
    scanf("%d\n", &N);
    if (N == 0) return false;
    HP = new int[N];
    foreach (i; 0 .. N) {
        scanf("%d\n", &HP[i]);
    }
    scanf("%d\n", &M);
    Ms = new Magic[M];
    foreach (i; 0 .. M) {
        string name, target;
        int mp, damage;
        readf("%s %d %s %d\n", &name, &mp, &target, &damage);
        if (damage >= P) damage = P;
        Ms[i] = Magic(target == "All", mp, damage);
    }
    return true;
}

void solve() {
    Magic[] As, Ss;
    foreach (m; Ms) {
        ( m.range ? As : Ss ) ~= m;
    }

    auto dp = new long[P + 1];
    dp[] = INF;
    dp[0] = 0;
    foreach (i, a; As) {
        foreach (j; 0 .. P + 1) {
            if (j + a.damage > P) {
                dp[P] = min(dp[P], dp[j] + a.cost);
                continue;
            }
            dp[j + a.damage] = min(dp[j + a.damage], dp[j] + a.cost);
        }
    }

    auto dp2 = new long[P + 1];
    dp2[] = INF;
    dp2[0] = 0;
    foreach (s; Ss) {
        foreach (i; 0 .. P + 1) {
            if (i + s.damage > P) {
                dp2[P] = min(dp2[P], dp2[i] + s.cost);
                continue;
            }
            dp2[i + s.damage] = min(dp2[i + s.damage], dp2[i] + s.cost);
        }
    }

    foreach_reverse (i; 0 .. P) {
        dp2[i] = min(dp2[i], dp2[i + 1]);
    }
    //writeln(As);
    //writeln(Ss);
    //writefln("%(%s\n%)", dp);
    //writefln("%(%s\n%)", dp2);

    long ans = INF;
    foreach (i; 0 .. P + 1) {
        long x = dp[i];
        foreach (j; 0 .. N) {
            if (HP[j] <= i) continue;
            x += dp2[ HP[j] - i ];
        }
        ans = min(ans, x);
    }
    writeln(ans);
}

void main() {
    while (input) solve;
}

Measured memory_bytes: 3380
import java.io.*;
import java.util.*;
public class Main implements Runnable {
    public void solve() throws Exception {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        if (a>=k){
            out.println(k);
        }else if(a+b>=k){
            out.println(a);
        }else
            out.println(a+(k-(a+b))*-1);
    }

    //main function//
    public static PrintWriter out;
    public static void main(String[] args) throws Exception {
        new Thread(null, new Main(), "", 1 << 26).start();
    }
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    public void run() {
        try {
           solve();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        } finally {
            out.close();
        }
    }
}


Measured memory_bytes: 32884
import sys
sys.setrecursionlimit(10**8)
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 li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

S = input()

if S == 'ABC':
    print('ARC')
else:
    print('ABC')

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

#define FOR(i,a,b) for(i=(a);i<(b);++i)
#define REP(i,n) for(i=0;i<(n);++i)

using namespace std;

int main() {
	int N;
	vector<int> A(10000);
	cin >> N;
	int i;
	REP(i, N)
		cin >> A[i];
	int ans = 0;
	int sum = 0;
	REP(i, N) {
		while (true) {
			if (A[i] % 2 == 0) {
				++sum;
				A[i] /= 2;
			}
			else
				break;
		}
	}
	cout << sum << endl;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  string s;
  cin>>s;
  int n=s.size();
  vector<int>r(n);
  vector<int>l(n);
  rep(i,n){
    if(s[i]=='R')r[i]=1;
    else l[i]=1;
  }
  rep(i,n){
    if(s[i]=='R'){
      r[i+1]+=r[i];
      r[i]=0;
    }
  }
  for(int i=n-1;i>=0;i--){
    if(s[i]=='L'){
      l[i-1]+=l[i];
      l[i]=0;
    }
  }
  vector<int>ans(n);
  rep(i,n){
    ans[i]+=r[i+1]-r[i+1]/2;
    ans[i+1]+=r[i+1]/2;
  }
  for(int i=n-1;i>=0;i--){
    ans[i]+=l[i-1]-l[i-1]/2;
    ans[i-1]+=l[i-1]/2;
  }
  rep(i,n){
    cout<<ans[i];
    if(i+1==n)cout<<endl;
    else cout<<' ';
  }
  return(0);
}


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

int main(){

  std::string number;
  std::cin >> number;

  while(number[0] != '0'){
    int sum=0;

    for(int i=0; i<number.size(); i++){
      sum += number[i]-'0';
    }
    std::cout << sum << std::endl;
    std::cin >> number;
  }
  return 0;
}



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

int main(){
    int n,m,s=0;
    cin >> n;
    m=n;
    for(int i=0;i<10;i++) {
        s+=m%10;
        m/=10;
    }
if(n%s==0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}

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

long long GCD(long long x,long long y){return y ? GCD(y,x%y) :x;}
long long num(long long n,long long c,long long d){
  long long G =GCD(c,d);
  long long L = c/G*d;
  return n-n/c-n/d+n/L;
}

int main(){
  long long a,b,c,d;
  cin >>a>>b>>c>>d;
  cout<<num(b,c,d)-num(a-1,c,d)<<endl;
}

Measured memory_bytes: 256
def f(x):
    ret = 0
    while(x > 0):
        ret = ret + x % 10
        x = x // 10
    return ret

a,n,m = [int(i) for i in input().split()]

ans = 0
i = 1
ii = 1
while(ii <= m):
    if ii == (f(ii)+a)**n:
        ans += 1
    i += 1
    ii = i**n
#    print(i, ii)

print(ans)



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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a + b > c + d){
    cout << "Left" << endl;
  }else if (a + b < c + d){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int N,K;
    cin >> N >> K;
    vector<int> l(N);
    for (int i = 0; i < N; i++){
        cin >> l[i];
    }
    sort(l.rbegin(),l.rend());
    int sum = 0;
    for (int i = 0; i < K; i++){
        sum += l[i];
    }
    cout << sum << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define x first
#define y second
int mod = 1000 * 1000 * 1000 + 7;
const int MAX = 200005;
int fact[200005];
int inv[200005];
int add(int a , int b)
{
	return a + b >= mod ? a + b - mod : a + b;
}
int mult(int a, int b)
{
	return a * (ll)b % mod;
}
int modPow(int a, int step)
{
	int ans = 1;
	while(step)
	{
		if(step & 1)
		{
			ans = mult(ans , a);
		}
		a = mult(a , a);
		step >>= 1;
	}
	return ans;
}
int c(int n , int k)
{
	return mult(fact[n] , mult(inv[k] , inv[n - k]));
}
vector<int> g[200005];
int sub[200005];
int f[200005];
int dp[200005];
int n;
void dfs(int u, int p = -1)
{
	sub[u] = 0;
	f[u] = 1;
	for(auto v : g[u])
	{
		if(v != p)
		{
			dfs(v, u);
			sub[u] += sub[v];
			f[u] = mult(mult(f[u] , f[v]) , c(sub[u] , sub[v]));
		}
	}
	sub[u]++;
}
void dfs2(int u, int fP , int p = -1)
{
	dp[u] = mult(mult(f[u] , fP) , c(n - 1 , sub[u] - 1));
	for(auto v : g[u])
	{
		if(v == p)
			continue;
		int fS = mult(mult(f[u] , modPow(f[v] , mod - 2)) , modPow(c(sub[u] - 1 , sub[v]) , mod - 2));
		dfs2(v, mult(mult(fP , fS) , c(n - sub[v] - 1 , n - sub[u])) ,  u);
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	fact[0] = inv[0] = 1;
	for(int i = 1; i < MAX; i++)
		fact[i] = mult(fact[i - 1] , i);
	for(int i = 1; i < MAX; i++)
		inv[i] = modPow(fact[i] , mod - 2);
	
	cin >> n;
	for(int i = 1; i < n; i++)
	{
		int u , v;
		cin >> u >> v;
		u--;v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(0);
	dfs2(0 , 1);
	for(int i = 0; i < n; i++)
		cout << dp[i] << endl;
}


Measured memory_bytes: 19072
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 1000000007
  #define N 1000001
  

int32_t main()
{




  int a,b,m;
  cin >> a >> b >> m;

  int arr1[a+1],arr2[b+1];

  for(int i = 1; i <= a; i++)
  {
    cin >> arr1[i];
  }

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


  int ans = 1e17;

  for(int i = 0; i < m; i++)
  {
    int x,y,c;
    cin >> x >> y >> c;
    ans = min(ans,arr1[x] + arr2[y] - c);
   
  }

  sort(arr1+1,arr1+a+1);
  sort(arr2+1,arr2+b+1);


  cout << min(ans,arr1[1] + arr2[1]);


  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// auto mod int
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


// combination mod prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main(){
    int n,k;
    cin >> n >> k;
    combination c(n);
    mint ans = 0;
    k=min(n-1,k);
    for(int i=0;i<=k;i++){
        ans+=c(n,i)*c(n-1,i);
    }
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 6424
while 1:
    a,b=map(int,input().split())
    if a==0 and b==0:
        break
    c=0
    lis=[i+1 for i in range(a)]
    for i in range(a-2):
        for j in range(i+1,a-1):
            for l in range(j+1,a):
                if lis[i]+lis[j]+lis[l]==b:
                    c+=1
    print(c)


Measured memory_bytes: 5604
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

double distance (int *arr_x, int *arr_y, int n, int p);
double distanceInf (int *arr_x, int *arr_y, int n);

int main () {
    // input
    int n;
    cin >> n;
    
    int x, y;
    int arr_x[100], arr_y[100];
    for (int i=0; i<n; i++) {
        cin >> x;
        arr_x[i] = x;
    }
    for (int i=0; i<n; i++) {
        cin >> y;
        arr_y[i] = y;
    }

    // solve
    double d1, d2, d3, di;
    d1 = distance (arr_x, arr_y, n, 1);
    d2 = distance (arr_x, arr_y, n, 2);
    d3 = distance (arr_x, arr_y, n, 3);
    di = distanceInf (arr_x, arr_y, n);

    // output
    cout << fixed;
    cout
        << setprecision(6) << d1 << endl
        << setprecision(6) << d2 << endl
        << setprecision(6) << d3 << endl
        << setprecision(6) << di << endl;
}

double distance (int *arr_x, int *arr_y, int n, int p) {
    double result;

    long sum = 0;
    for (int i=0; i<n; i++) {
        int factor1 = abs( arr_x[i] - arr_y[i] );
        long factor2 = pow(factor1, p);
        sum += factor2;
        /*cout << "factor1: " << factor1 << endl
             << "factor2: " << factor2 << endl
             << "sum: " << sum << endl;*/
    }
    result = pow( double(sum), double(1)/p );

    return result;
}

double distanceInf (int *arr_x, int *arr_y, int n) {
    double result = 0;

    for (int i=0; i<n; i++) {
        int diff;
        diff = abs( arr_x[i] - arr_y[i] );
        if (diff > result) result = diff;
    }

    return result;
}


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

int main() {
	int n, m; cin >> n >> m;
	int a;
	for (int i = 0; i < m; i++) {
		cin >> a;
		n -= a;
	}
	if (n < 0) cout << -1 << endl;
	else cout << n << endl;
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i]=='d'&&s[i+1]=='r'&&s[i+2]=='e'&&s[i+3]=='a'&&s[i+4]=='m') {
      if (s[i+5]=='e'&&s[i+6]=='r'&&s[i+7]!='a') {
        i += 6;
      }
      else {
        i += 4;
      }
    }
    else if (s[i]=='e'&&s[i+1]=='r'&&s[i+2]=='a'&&s[i+3]=='s'&&s[i+4]=='e') {
      if (s[i+5]=='r') {
        i += 5;
      }
      else {
        i += 4;
      }
    }
    else {
      cout << "NO" << endl;
      return 0;
    }
  }
  
  cout << "YES" << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

#define fix(n) cout<<fixed<<setprecision(n);
#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12)

  ll n, p; cin >> n >> p;
  string s; cin >> s;

  if (10 % p == 0) {
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      if ((s[i] - '0') % p == 0) ans += i + 1;
    }
    outl(ans)
    return 0;
  }

  vector<int> d(n + 1);
  int ten = 1;
  for (int i = n-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
  }

  ll ans = 0;
  vector<int> cnt(p);
  for (int i = n; i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }

  outl(ans)
}


Measured memory_bytes: 1404
#include <iostream>
using namespace std;
int main()
{
  int N, M;
  cin >> N >> M;
  char A[N][N], B[M][M];
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
      cin >> A[i][j];
  }
  for (int i = 0; i < M; i++)
  {
    for (int j = 0; j < M; j++)
      cin >> B[i][j];
  }
  for (int i = 0; i < N - M + 1; i++)
  {
    for (int j = 0; j < N - M + 1; j++)
    {
      bool match = true;
      for (int k = 0; k < M; k++)
      {
        for (int l = 0; l < M; l++)
        {
          if (A[i + k][j + l] != B[k][l])
            match = false;
        }
      }
      if (match)
      {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
ps = gets.split.map(&:to_i)
ascending = (1..N).to_a
count = 0
N.times do |i|
  count += 1 unless ps[i] == ascending[i]
end

if count == 0 || count == 2
  puts "YES"
else
  puts "NO"
end


Measured memory_bytes: 3836
from collections import defaultdict

N, Q = map(int, input().split())
edge = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

cnt = [0]*(N+1)
for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

root_node = (1, -1) # (id, value, parent_id)
open_list = [root_node]
closed_list = []
while True:
    if len(open_list) == 0:
        break
    cur_node = open_list.pop()
    cur_id, parent_id = cur_node
    if not(parent_id == -1):
        cnt[cur_id] += cnt[parent_id]
    for child_id in edge[cur_id]:
        if child_id == parent_id:
            continue
        open_list.append((child_id, cur_id))
print(*cnt[1:])

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

typedef long long ll;
const ll MOD = 1000000007;
ll mod;

using namespace std;

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

    int a, b;
    cin >> a >> b;
    cout << (max(a - b, max(a + b, a * b)));

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;

void sout(string* a, string* b) {
	if (*a > * b) {
		string c = *a;
		*a = *b;
		*b = c;
	}
}
int main() {
	int n, l;
	string s[100];
	cin >> n >> l;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n - 1; i++) {
			sout(&s[i], &s[i + 1]);
		}
	}
	for (int i = 0; i < n; i++) {
		cout << s[i];
	}
	cout << endl;
}

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

vvl memo(401, vl(401, -1));
vector<long long> d(1);

long long split_slime(int l, int r) {
	if (l + 1 == r) return 0;
	if (memo[l][r] != -1) return memo[l][r];
	long long mn = (1LL << 60);
	reps(i,l+1,r) mn = min(mn, (d[i] - d[l]) + (d[r] - d[i]) + split_slime(l, i) + split_slime(i, r));
	return memo[l][r] = mn;
}

int main(void) {
	int n;
	cin >> n;
	long long input;
	rep(i,n) {
		cin >> input;
		d.push_back(d[i] + input);
	}
	cout << split_slime(0, n) << endl;
}

Measured memory_bytes: 1536
#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};

const int MAX_N = 110;

vector<vector<int>> dist(MAX_N, vector<int>(MAX_N, 1e9));
void warshall_floyd(int n){
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

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

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

    for(int i=0; i<n; i++){
        int r; cin>>r;
        r--;
        int k; cin>>k;
        while(k--){
            int t; cin>>t;
            t--;
            dist[r][t] = 1;
        }
    }

    warshall_floyd(n);

    int q; cin>>q;
    while(q--){
        int s, d, v; cin>>s>>d>>v;
        s--, d--;
        if(dist[s][d] + 1 <= v){
            cout << dist[s][d] + 1 << endl;
        }
        else{
            cout << "NA" << endl;
        }
    }
}


Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cmath>
#include <cstdio>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
LL MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> C(N, vector<int>(3, 0));
    for(int i=0; i<N; i++) {
        for(int j=0; j<3; j++)
            cin >> C[i][j];

    }
    vector<vector<int>> dp(N, vector<int>(3, 0));
    for(int j=0; j<3; j++) dp[0][j] = C[0][j];
    for(int i=1; i<N; i++) {
        for(int j=0; j<3; j++) {
            for(int k=0; k<3; k++) if(k != j) {
                dp[i][j] = max(dp[i][j], dp[i-1][k] + C[i][j]);
            }
        }

    }
    int maxim = 0;
    for(int j=0; j<3; j++)
        maxim = max(maxim, dp[N-1][j]);
    cout << maxim << endl;
}

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

int main(){

    while(1){
        int n,a,b,c,x; cin>>n>>a>>b>>c>>x;

        if(n ==0  && a == 0 && b == 0 && c == 0 && x == 0) break;

        vector<int> y(n);

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

        int count=0,top=0;

        while(1){

            if(count > 10000) break;

            if(x == y[top]){
                y.erase(y.begin()+top);
            }

            if(y.size() == 0) break;
            count++;
            x = (a*x+b) % c;
        }

        if(y.size() != 0) cout<<-1<<endl;

        else cout<<count<<endl;
    }

    return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> P;
typedef long long int ll;
typedef pair<int,int> Pii;
const int INF=(1<<30)-1;
const ll INFl=9223372036854775807;
const int MAX=310;
const ll MOD=1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int main(void){
	ll k,a,b;
	cin>>k>>a>>b;
	if(b<a+3){
		cout<<1+k<<endl;
		return 0;
	}
	
	if((k-1-a)%2==0){
		cout<<b+(k-a-1)*(b-a)/2<<endl;
		return 0;
	}
	
	
	cout<<b+(k-a-2)*(b-a)/2+1<<endl;
	return 0;
}
	
	

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

int main() {

    int A,B,C,K;
    cin>>A>>B>>C>>K;

    if(A>=K){

        cout<<K<<endl;
    }

    else if (A<K && B>=K-A){

        cout<<A<<endl;
    }

    else if (B<K-A){

        cout<<2*A+B-K<<endl;
    }
    
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	ll N, K;
	cin >> N >> K;
	vl A(N);
	rep(i, N)cin >> A[i];
	map<ll, ll> Aa;
	ll tmp = 1;
	ll t = 0;
	ll tdiff;
	ll ans;
	bool once = 1;
	Aa[1] = t;
	while (1) {
		tmp = A[tmp - 1];
		t++;
		if (t == K) {
			ans = tmp;
			break;
		}
		if (once && (Aa.find(tmp) != Aa.end())) {
			once = 0;
			tdiff = t - Aa[tmp];
			ll trem = K - t;
			t+= tdiff * (ll)(trem / tdiff);
		}
		if (t == K) {
			ans = tmp;
			break;
		}
		Aa[tmp] = t;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14872
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long H, N;
    scan(H, N);
    auto A = new long[](N);
    auto B = new long[](N);
    foreach (i; 0 .. N)
        scan(A[i], B[i]);
    auto dp = new long[](10 ^^ 4 * 2);
    foreach (i; 1 .. dp.length)
        dp[i] = long.max;
    long ans = long.max;
    foreach (i; 0 .. H)
        foreach (j; 0 .. N)
            if (dp[i] != long.max)
            {
                long damage = i + A[j];
                dp[damage] = min(dp[i] + B[j], dp[damage]);
                if (H <= damage)
                {
                    ans = min(ans, dp[damage]);
                }
            }
    writeln(ans);
}


Measured memory_bytes: 2428
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int M = in.nextInt();
            ArrayList<Pair<Integer, Integer>> pairs = new ArrayList<>();
            for (int i = 0; i < M; i++) {
                pairs.add(new Pair<Integer, Integer>(in.nextInt(), in.nextInt()));
            }

            Collections.sort(pairs, new Comparator<Pair<Integer, Integer>>() {
                @Override
                public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) {
                    if (o1.second.intValue() < o2.second.intValue()) {
                        return -1;
                    }
                    if (o1.second.intValue() > o2.second.intValue()) {
                        return 1;
                    }
                    return 0;
                }
            });

            int cut = pairs.get(0).second.intValue() - 1;
            int count = 1;

            for (int i = 1; i < M; i++) {
                if (pairs.get(i).first.intValue() > cut) {
                    cut = pairs.get(i).second.intValue() - 1;
                    count++;
                }
            }
            System.out.println(count);
        }
    }

}

class Pair<T extends Comparable<T>, S> implements Comparable<Pair<T, S>> {
    public T first;
    public S second;

    public Pair(T t, S s) {
        this.first = t;
        this.second = s;
    }

    private int hash = 0;

    @Override
    public int hashCode() {
        if (hash == 0) {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((first == null) ? 0 : first.hashCode());
            result = prime * result + ((second == null) ? 0 : second.hashCode());
            hash = result;
        }
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Pair<T, S> other = (Pair<T, S>) obj;
        if (first == null) {
            if (other.first != null)
                return false;
        } else if (!first.equals(other.first))
            return false;
        if (second == null) {
            if (other.second != null)
                return false;
        } else if (!second.equals(other.second))
            return false;
        return true;
    }

    @Override
    public int compareTo(Pair<T, S> o) {
        return first.compareTo(o.first);
    }
}


Measured memory_bytes: 96904
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 998244353
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

const int N = 8000;
unordered_map <int, bool> dp[N];
vector <int> v[2];
bool func(int i, int csum, int dir, int dest) {
	if(i == (int) v[dir].size()) {
		return (csum == dest);
	}
	if(dp[i].find(csum) != dp[i].end())
		return dp[i][csum];
	bool val = (func(i + 1, csum + v[dir][i], dir, dest) 
				| func(i + 1, csum - v[dir][i], dir, dest));
	return dp[i][csum] = val;
}
int main() {
	string s;
	cin >> s;
	int n = (int) s.size();
	int dx, dy;
	cin >> dx >> dy;
	int pos = 0;
	while(pos < n && s[pos] != 'T')
		pos++;
	int cx = pos;
	int p = 1, c = 0;
	for (int i = pos + 1; i < n; i++) {
		if(s[i] == 'F') {
			c++;
		}
		else {
			v[p].push_back(c);
			c = 0;
			p ^= 1;
		}
	}
	if(c > 0) {
		v[p].push_back(c);
	}
	bool xp = func(0, cx, 0, dx);
	for (int i = 0; i < N; i++)
		dp[i].clear();
	bool yp = func(0, 0, 1, dy);
	if(xp & yp) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}


Measured memory_bytes: 166528
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm> 
using namespace std;
 
# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
 
int main()
{
    long long int x;cin >> x;

    long long int sum=0;
    for(long long int i=1;i<=x;i++){
        sum += i;
        if(sum >= x){
            p(i)
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,b;
	int i;
	int ans=0;
	
	scanf("%d %d",&a,&b);
	
	for(i=1;i<b-a;i++){
		ans+=i;
	}
	
	ans-=a;
	
	printf("%d",ans);
	
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

typedef long long int ll;

std::vector<ll> enum_div(ll n);
long long comb(int n, int r);
bool IsPrime(int num);
bool dp[110][10010];
class UnionFind;
using Graph = vector<vector<int>>;

//自作関数一覧---------------------------
ll gcd(ll a, ll b); //最小公倍数の導出
ll lcm(ll x, ll y); //最大公約数の導出
ll bur(ll N, ll X); //??
//---------------------------------------

//UF木
class UnionFind {
public:
	//親
	vector<int> Parent;

	//初期状態
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//サイズ確認
	int size(int A) {
		return -Parent[root(A)];
	}

	int connect(int A, int B) {
		//root同氏をくっつける
		A = root(A);
		B = root(B);

		//結合済み
		if (A == B) {
			return false;
		}
		//大きいほうに小さいほうをくっつける
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズ更新
		Parent[A] += Parent[B];
		//Bの親をAに
		Parent[B] = A;

		return true;
	}

};

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;


	string S, T;
	char fi[50], fv[50];
	char board[4][4];
	bool start = false;
	ll left = 0, right = 0;
	
	std::vector<char> zo;

	cin >> A >> B >> C >> D;

	cout << std::min(A, B) + std::min(C, D) << endl;

	return 0;
}


std::vector<ll> enum_div(ll n)//nの約数を列挙
{
	vector<ll> res;
	for (int i = 1; i*i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}








bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}



//combination
long long comb(int n, int r) {
	std::vector<std::vector<long long>> v(n + 1, std::vector<long long>(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v[n][r];
}


ll gcd(ll a, ll b) {

	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y / b*x;
}

// 最大公約数を求める関数
ll lcm(ll x, ll y)
{
	if (x == 0 || y == 0)  // 引数チェック
	{
		//fprintf(stderr, "引数エラーです。\n");
		return 0;
	}

	return (x * y / gcd(x, y));
}

ll bur(ll N, ll X) {
	ll pan = 1;
	ll pat = 1;
	ll burg = 0;



	if (X > burg) {
		if (N == 0)
			return pat;


		burg += pan;
		burg += bur(N - 1, X);
		burg += pat;
		burg += bur(N - 1, X);
		burg += pan;


	}

	return burg;

}

Measured memory_bytes: 256
X = int(input())
 
if 400 <= X < 600:
    result = 8
elif X < 800:
    result = 7
elif X < 1000:
    result = 6
elif X < 1200:
    result = 5
elif X < 1400:
    result = 4
elif X < 1600:
    result = 3
elif X < 1800:
    result = 2
elif X < 2000:
    result = 1
 
print(result)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
long long xx,er[2010],n,x[1001],y[1001],mod=998244353,ans;
int main()
{
	scanf("%lld",&n);
	er[0]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&x[i],&y[i]);
		er[i]=(er[i-1]*2)%mod;
	}
	ans=(er[n]-n-1+mod)%mod;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<i;j++)
		{
			int cnt=0;
			for(int k=1;k<j;k++)
			{
				if((y[i]-y[k])*(x[j]-x[k])==(y[j]-y[k])*(x[i]-x[k]))
				{
					cnt++;
				}
			}
			ans=(ans-er[cnt]+mod)%mod;
		}
	}
	printf("%lld",ans);
}

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

int main(){
	int a[102][102] = {};
	int n,u,k,b;
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> u >> k;
		for(int j = 0;j < k;j++){
			cin >> b;
			a[i][b] = 1;
		}
	}

	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			if(j != n){
				cout << a[i][j] << " ";
			}
			else cout << a[i][j] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%d %d",&A,&B);

    /*printf("%d+%d=%d,",A,B,A+B);
    printf("%d-%d=%d & ",A,B,A-B);
    #include<stdio.h>
int main()
{printf("%d*%d=%d ",A,B,A*B);*/
    if(A+B>=A-B &&A+B>=A*B){
    printf("%d",A+B);}
    else if (A-B>=A+B && A-B>=A*B)
    {
    printf("%d",A-B);}
    else if(A*B>=A+B &&A*B>=A-B)
    {
    printf("%d",A*B);}
    return 0;
}


Measured memory_bytes: 128
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#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>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N, M; cin >> N >> M;
    vector<int> A(M);
    vector<string> S(M);
    for(int i=0; i<M; i++) cin >> A[i] >> S[i];
    
    map<int, int> p;
    set<int> AC;
    int pena = 0, ans = 0;
    for(int i=0; i<M; i++) {
        if(S[i] == "WA") {
            if(AC.count(A[i])) continue;
            p[ A[i] ]++;
        }
        if(S[i] == "AC") {
            if(AC.count(A[i])) continue;
            AC.emplace(A[i]);
            pena += p[ A[i] ];
            ans++;
        }
    }

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


Measured memory_bytes: 15488