akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  stack<char> stack;
  for (int i = 0; i < s.size(); i ++) {
    if (s.at(i) == 'S') {
      stack.push('S');
    } else if (s.at(i) == 'T' && (stack.empty() || stack.top() == 'T')) {
      stack.push('T');
    } else {
      stack.pop();
    }
  }

  cout << stack.size() << endl;
}


Measured memory_bytes: 644
import java.util.Scanner;

public class Main {
	private void calc(){
		Scanner scanner = new Scanner(System.in);
		int Leng =scanner.nextInt();
		int High =scanner.nextInt();
		
		int S=Leng*High;
		int P=(Leng+High)*2;
		
		System.out.print(S+" ");
		System.out.println(P);
	}
	
	public static void main(String[] args) {
		Main run =new Main ();
		run.calc();

	}
}

Measured memory_bytes: 17156
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <deque>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int N, M, Q;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> Q;
    vector<int> a(M), q(Q);
    for(int i = 0; i < M; i++) cin >> a[i];
    for(int i = 0; i < Q; i++) cin >> q[i];
    int now = 0;
    deque<int> deq;
    for(int i = 0; i < N; i++) deq.push_back(i);
    for(int i = 0; i < M; i++)
    {
        int k = a[i] % int(deq.size());
        for(int j = 0; j < k; j++)
        {
            if(a[i] % 2 == 0)
            {
                deq.push_back(deq.front());
                deq.pop_front();
            }
            else
            {
                deq.push_front(deq.back());
                deq.pop_back();
            }
        }
        deq.pop_front();
    }
    vector<int> isOut(N, 1);
    for(int i = 0; i < deq.size(); i++) isOut[deq[i]] = 0;
    for(int i = 0; i < Q; i++) cout << (not isOut[q[i]]) << endl;
    return 0;
}


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

int main(void) 
{
    int n;
    cin >> n;
    std::vector<long long> a(n);
    long long sum = 0;
    std::vector<std::vector<int>> pos(100001);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
        pos[a[i]].push_back(i);
    }

    int q;
    cin >> q;
    std::vector<long long>b(q), c(q);
    for (int i = 0; i < q; i++)
    {
        cin >> b[i] >> c[i];
        sum = sum - b[i] * pos[b[i]].size() + c[i] * pos[b[i]].size();

        std::vector<int> tmp = pos[b[i]];
        pos[b[i]].clear();
        for (int j = 0; j < tmp.size(); j++)
        {
            a[tmp[j]] = c[i];
            pos[c[i]].push_back(tmp[j]);
        }

        cout << sum << endl;
    }

    return 0;
}

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

int main(){
  char str[1000];
  int num[1000];
  int sum[1000];
  int i = 0, j = 0, k = 0;

  while(1){
    scanf("%s", str);
    if(!strcmp(str, "0")) break;
    for(j = 0;j < strlen(str); j++){
      for(i = 0;i < 10;i++){
	if(str[j] == 48 + i){
	  num[j] = i;
	}
      }
      sum[k] += num[j];
    }
    k++;
  }

  for(i = 0;i < k;i++){
    printf("%d\n", sum[i]);
  }
  
  return 0;
}


Measured memory_bytes: 2044
#include <cstdio>

int abs(int n) { return n > 0 ? n : -n; }
int main()
{
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);

	if (abs(a - b) <= d && abs(b - c) <= d || abs(a - c) <= d) puts("Yes");
	else puts("No");

	return 0;
}

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

using namespace std;

int main() {
   priority_queue<int>num;
   string command;

   int n;

   while(1){
    cin>>command;
    if(command.compare("insert") == 0){
        cin>>n;
        num.push(n);
    }
    if(command.compare("extract") == 0){
        cout<<num.top()<<endl;
        num.pop();
    }
    if(command.compare("end") == 0){
        break;
    }
   }
   return 0;
}



Measured memory_bytes: 7016
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,j;
  cin>>h>>w;
  vector<string> x(h);
  for(j=0;j<h;j++) cin>>x.at(j);
  for(j=0;j<w+2;j++) cout<<'#';
  cout<<endl;
  for(j=0;j<h;j++) cout<<'#'<<x.at(j)<<'#'<<endl;
  for(j=0;j<w+2;j++) cout<<'#';
  cout<<endl;
}

Measured memory_bytes: 3588
import java.io.*;
import java.util.*;

public class Main {
    private static class Solver {
        static class Edge {
            static int n;
            int u, v, w;
            private int correct(int u) {
                if (u == n + 1) {
                    return 1;
                }
                return u + 1;
            }
            public Edge(int u, int v, int w) {
//                u = correct(u);
//                v = correct(v);
                this.u = u;
                this.v = v;
                this.w = w;
            }
        }
        private void Solve() {
            int L = inp.nextInt();
            int n = 0;
            int[] a = new int[30];
            for (int d = L; d > 0; d /= 2) {
                a[++n] = d % 2;
            }
            for (int i = 1; i <= n / 2; ++i) {
                int tmp = a[i];
                a[i] = a[n - i + 1];
                a[n - i + 1] = tmp;
            }

            Edge.n = n;
            List<Edge> ans = new ArrayList<>();
            for (int i = 1; i <= n - 1; ++i) {
                ans.add(new Edge(i, i + 1, 0));
                ans.add(new Edge(i, i + 1, 1 << (n - i - 1)));
            }
            for (int i = 1, t = 0; i <= n; ++i) {
                if (i > 1 && a[i] == 1) {
                    ans.add(new Edge(1, i, t));
                }
                t = t + (a[i] << (n - i));
            }

            out.println(n + " " + ans.size());
            for (Edge e: ans) {
                out.println(e.u + " " + e.v + " " + e.w);
            }
        }

        static InputReader inp;
        static PrintWriter out;
    }

    private static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        private InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        private String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

    }

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Solver.inp = new InputReader(inputStream);
        Solver.out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.Solve();
        Solver.out.close();
    }
}

Measured memory_bytes: 21460
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#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
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {

	ll N, M;
	cin >> N >> M;
	vector<ll> fo(M);
	rep(i, N) {
		ll K;
		cin >> K;
		rep(j, K) {
			ll A;
			cin >> A;
			fo.at(A - 1)++;
		}
	}
	ll an = 0;
	rep(i, M) {
		if (fo.at(i) == N) {
			an++;
		}
	}
	cout << an << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int N;
    cin>>N;
    vector<vector<int>> edges(N);
    rep(i, N - 1) {
        int e1, e2;
        cin>>e1>>e2; e1--; e2--;
        edges[e1].push_back(e2);
        edges[e2].push_back(e1);
    }

    queue<P> q;
    vector<int> color(N, -1);
    q.push(P(0, 0));
    while (!q.empty()) {
        P p = q.front(); q.pop();
        int e = p.first;
        int w = p.second;
        if (color[e] != -1) continue;

        color[e] = w;
        for (auto i : edges[e]) {
            q.push(P(i, (w + 1) % 2));
        }
    }
    int cr = 0;
    int cb = 0;
    rep(i, N) {
        if (color[i] == 0) cr++;
        else cb++;
    }

    int n0 = 3;
    int n1 = 1;
    int n2 = 2;
    vector<int> ans(N);
    if (cr > N / 3 && cb > N / 3) {
        rep(i, N) {
            if (color[i] == 0 && n1 <= N) {
                ans[i] = n1;
                n1 += 3;
            }
            else if (color[i] == 1 && n2 <= N) {
                ans[i] = n2;
                n2 += 3;
            }
            else {
                ans[i] = n0;
                n0 += 3;
            }
        }
    }
    else if (cr <= N / 3) {
        rep(i, N) {
            if (color[i] == 0) {
                ans[i] = n0;
                n0 += 3;
            }
            else if (n1 <= N) {
                ans[i] = n1;
                n1 += 3;
            }
            else if (n2 <= N) {
                ans[i] = n2;
                n2 += 3;
            }
            else {
                ans[i] = n0;
                n0 += 3;
            }
        }
    }
    else {
        rep(i, N) {
            if (color[i] == 1) {
                ans[i] = n0;
                n0 += 3;
            }
            else if (n1 <= N) {
                ans[i] = n1;
                n1 += 3;
            }
            else if (n2 <= N) {
                ans[i] = n2;
                n2 += 3;
            }
            else {
                ans[i] = n0;
                n0 += 3;
            }
        }        
    }
    rep(i, N - 1) cout<<ans[i]<<" ";
    cout<<ans[N - 1]<<endl;
}

Measured memory_bytes: 15472
def reads(offset = 0):
	return [int(i) - offset for i in input().split(' ')]
def Judge(vector):
	length = len(vector)-1
	for i in range(length):
		if(vector[i] > vector[i+1]):		
			return 0
	return 1
(N, M) = reads()
Q = int(input())
A = reads(1)
pos = [-1] * M
pat = []
freq = [0] * (M+1)
freq[0] = N
found = set()
counter = 0
for i in A[::-1]:
	if (i not in found):
		pat.append(i)
		found.add(i)
		pos[i] = counter
		freq[counter] -= 1
		counter += 1
		freq[counter] += 1
	elif (freq[pos[i]] > 0):
		freq[pos[i]] -= 1
		freq[pos[i]+1] += 1
for i in range(M):
	if (pos[i] == -1):
		pat.append(i)
for i in range(M+1):
	if (freq[i] != 0):
		start = i
		break
print("Yes") if Judge(pat[start:]) else print("No")

Measured memory_bytes: 19556
#include <iostream>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>

int main()
{
	unsigned long long N;
	std::cin >> N;

	unsigned long long P = 0;
	for (int j = 0; j < N; ++j) {
		int p = 0;
		std::cin >> p;

		P *= 10;
		P += p;
	}

	unsigned long long Q = 0;
	for (int j = 0; j < N; ++j) {
		int q = 0;
		std::cin >> q;

		Q *= 10;
		Q += q;
	}


	std::vector<int> permutation(N);
	std::iota(permutation.begin(), permutation.end(), 1);

	int p = 0;
	int q = 0;
	int i = 0;

	do {
		int number = 0;
		for (auto x : permutation) {
			number *= 10;
			number += x;
		}

		if (number == P) {
			p = i + 1;
		}

		if (number == Q) {
			q = i + 1;
		}

		++i;

	} while (std::next_permutation(permutation.begin(), permutation.end()));     // 次の順列を生成

	const int distance = p < q ? q - p : p - q;

	std::cout << distance << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
double d;
int main()
{
  cin >> n >> d;
  int cnt = 0;
  for (int i = 1; i <= n; i+=1)
  {
    double x, y; cin >> x >> y;
    if (sqrt(x * x + y * y) < d + 1e-10) ++cnt;
  }
  cout << cnt << endl;
}


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

const int N_MAX = 100000;
const int Q_MAX = 50000;

int main() {
  int n, q;
  int s[N_MAX + 1], t[Q_MAX + 1];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  cin >> q;
  for (int i = 0; i < q; i++) cin >> t[i];

  int ans = 0;
  for (int i = 0; i < q; i++) {
    s[n] = t[i];
    int j = 0;
    while (s[j] != t[i]) j++;
    if (j < n) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3556
//解法②

#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
//to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

int main(void) {

	string s;
	cin >> s;
	sort(s);
	rep(i, s.size() - 1) {
		if (s[i] == s[i + 1]) {
			cout << "no" << rt;
			return 0;
		}
	}
	cout << "yes" << rt;

	please AC;
}
//参考：---;

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll powLL(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res *= a;
            res %= mod;
        }
        a = a*a;
        a %= mod;
        n >>= 1;
    }
    return res;
}

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

    ll N;
    cin >> N;
    vector<ll> x(N), y(N);
    REP(i, N){
    	cin >> x[i] >> y[i];
    }

    ll res = 0;

    res += powLL(2, N);
    res -= N;
    res -= 1;
    res += mod;
    res %= mod;

    ll check[N][N] = {};


    REP(i, N){
    	REP(j, N){
    		if(i==j) continue;
    		if(check[i][j]) continue;
    		vector<ll> cand;
    		REP(k, N){
    			if(check[i][k]) continue;
    			if(check[j][k]) continue;
    			if(i==k) continue;
    			if(j==k) continue;
    			ll dx1 = x[j] - x[i];
    			ll dx2 = x[k] - x[i];
    			ll dy1 = y[j] - y[i];
    			ll dy2 = y[k] - y[i];
    			if(dx1 * dy2 == dx2 * dy1){
    				cand.push_back(k);
    			}
    		}
    		cand.push_back(i);
			cand.push_back(j);

    		ll q = cand.size();
			ll tmp = 0;

			tmp += powLL(2, q);
			tmp -= 1;
			tmp -= q;
			tmp += mod;
			tmp %= mod;

			res -= tmp;
			res += mod;
			res %= mod;

			REP(k, q)REP(l, q) check[cand[k]][cand[l]] = 1;
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    cout<<n+(n*n)+(n*n*n)<<'\n';
    return 0;

}

//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   ****

//     ****  *   *  *   *   ***   *   *  *****  *   *
//    *     *   *  *   *  *   *  *   *  *      *   *
//    ***  *****  *   *  *****  * * *  ****   *   *
//      *   *    *   *  *   *  * * *  *      *   *
//  ****   *     ***   *   *   * *   *****   ***



Measured memory_bytes: 3648
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#define gc getchar()
#define N 200010
using namespace std;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
int a[N],p[N],f[N];
int main()
{
	int n=inn(),ans=0;
	for(int i=1;i<=n;i++) p[a[i]=inn()]=i;
	for(int i=1;i<=n;i++)
		ans=max(ans,f[i]=f[p[a[i]-1]]+1);
	return !printf("%d\n",n-ans);
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>

std::vector<std::vector<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;
}

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

  std::vector<std::vector<long long int> > v(N+M,std::vector<long long int>(2,0));
  v=comb(N+M, 2);
  std::cout << v[N+M][2]-(M*N) << "\n";

  return 0;
}

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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b+c) cout << "Yes" << endl;
    else if(b== a+c) cout << "Yes" << endl;
    else if(c == b+a) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {
	private static int[][] nArray = new int[201][201];
	private static int[] rArray = new int[9];
	private static boolean[] usedArray = new boolean[9];
	private static int N = 0;
	private static int M = 0;
	private static int R = 0;
	private static int result = 999999999;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		R = sc.nextInt();
		
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				nArray[i][j] = 999999999;
			}
		}
		for (int i = 1; i <= R; i++) {
			rArray[i] = sc.nextInt();
		}
		for (int i = 1; i <= M; i++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int C = sc.nextInt();
			nArray[A][B] = C;
			nArray[B][A] = C;
		}
		sc.close();
		for (int k = 1; k <= N; k++) {
			for (int i = 1; i <= N; i++) {
				for (int j = 1; j <= N; j++) {
					if (nArray[i][k] != 999999999 && nArray[k][j] != 999999999) {
						if (nArray[i][j] == 999999999 || nArray[i][j] > nArray[i][k] + nArray[k][j]) {
							nArray[i][j] = nArray[i][k] + nArray[k][j];
						}
					}
				}
			}
		}
		
		dfs(1, -1, 0);
		System.out.println(result);
	}
	
	private static void dfs(int c, int las, int dist) {
		if (c == R + 1) {
			if (result > dist)
				result = dist;
			return;
		}
		for (int i = 1; i <= R; i++)
			if (!usedArray[i]) {
				usedArray[i] = true;
				if (las == -1)
					dfs(c + 1, i, 0);
				else
					dfs(c + 1, i, dist + nArray[rArray[las]][rArray[i]]);
				usedArray[i] = false;
			}
	}
}

Measured memory_bytes: 46040
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    string S;
    cin >> S;
    int N = S.size();
    int dp[N+1][13]{};
    dp[0][0] = 1;
    rep(i,N){
        rep(j,13){
            if(S[i] == '?'){
                rep(k,10){
                    dp[i+1][(j*10+k)%13] += dp[i][j];
                    dp[i+1][(j*10+k)%13] %= MOD;
                }
            }
            else{
                int x = S[i] - '0';
                dp[i+1][(j*10+x)%13] += dp[i][j];
                dp[i+1][(j*10+x)%13] %= MOD;
            }
        }
    }
    cout << dp[N][5] << endl;
}

Measured memory_bytes: 10704
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
string s;
cin >> s;
if(s=="Sunny"){
   cout << "Cloudy" << endl;
}
else if(s=="Cloudy"){
   cout << "Rainy" << endl;
}
else if(s=="Rainy"){
   cout << "Sunny" << endl;
}

////////////////////////////////////////////////////////
return 0;}

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

int main(void){
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    int a[3];
    int b[3];
    a[0]=0;
    for(int i=0;i<3;i++){
        b[i]=c[0][i]-a[0];
    }
    for(int i=1;i<3;i++){
        a[i]=c[i][0]-b[0];
    }
    bool ok=true;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(c[i][j]!=a[i]+b[j]){
                ok=false;
                break;
            }
        }
    }
    if(ok){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> >v[53];
vector<int>path;
bool ispth[23][53];
long long n,m,dp[53][1048576],x[53],y[53];
void dfs(int x,int p,int t,int y){
	if(x==t)
		for(int i=0;i<path.size();i++)
			ispth[y][path[i]]=1;
	for(int i=0;i<v[x].size();i++)
		if(v[x][i].first!=p){
			path.push_back(v[x][i].second);
			dfs(v[x][i].first,x,t,y);
			path.pop_back();
		}
}
int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>x[i]>>y[i];x[i]--;y[i]--;
		v[x[i]].push_back(make_pair(y[i],i));
		v[y[i]].push_back(make_pair(x[i],i));
	}cin>>m;
	for(int i=0;i<m;i++){
		int s,t;
		cin>>s>>t;
		s--;t--;
		dfs(s,-1,t,i);
	}
	dp[0][0]=1;
	for(int i=1;i<n;i++)
		for(int j=0;j<(1<<m);j++){
			dp[i][j]+=dp[i-1][j];
			int x=0;
			for(int k=0;k<m;k++)
				if(ispth[k][i]==1)
					x+=(1<<k);
			dp[i][j|x]+=dp[i-1][j];
		}
	cout<<dp[n-1][(1<<m)-1];
}

Measured memory_bytes: 404888
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
typedef int long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){

    int n;
    string s;
    cin>>n>>s;
    int e[n];
    int w[n];
    rep(i,n){
        e[i]=0;w[i]=0;
    }

    for(int i=1;i<n;i++){
        if(s[i-1]=='W')w[i]+=w[i-1]+1;
        else w[i]+=w[i-1];
    }
    for(int i=n-2;i>=0;i--){
        if(s[i+1]=='E'){e[i]+=e[i+1]+1;}else{
            e[i]+=e[i+1];
        }
    }
    int ans=1e+7;

    rep(i,n){
        ans=min(ans,e[i]+w[i]);

    }
    cout<<ans<<endl;




}

Measured memory_bytes: 3076
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (a (read))
         (b (read))
         (c (read))
         (d (read))
         (e (read))
         (min (min a b c d e)))
    (println (+ 4 (ceiling n min)))))

#-swank(main)


Measured memory_bytes: 18020
#include <iostream>

using namespace std;

int partition(int A[],int p,int r){
    int i=p-1,x=A[r];
    for(int j=p;j<r;j++)
    {
        if(A[j]<=x){
            i++;
            int temp=A[i];
            A[i]=A[j];
            A[j]=temp;
        }
    }
    A[r]=A[i+1];
    A[i+1]=x;
    return i+1;
}

int main(){
    int n,A[100000];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>A[i];
    int q = partition(A,0,n-1);
    int isn=0;
    for(int i=0;i<n;i++)
    {
        if(isn++>0)cout<<' ';
        if(i==q)cout<<'['<<A[i]<<']';
        else cout<<A[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3480
#include<cstdio>
#include<algorithm>
using namespace std;
int n,x,a[105];
int main()
{
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i) {
		x-=a[i];if(!x) {printf("%d\n",i);return 0;}
		else if(x<0) {printf("%d\n",i-1);return 0;}
	}
	printf("%d\n",n-1);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
a_input = list(map(int,input().split()))

ans_li=[]
if n%2==0:
    for i in range(n,0,-2):
        ans_li.append(a_input[i-1])
    for i in range(1,n,2):
        ans_li.append(a_input[i-1])
else:
    for i in range(n,0,-2):
        ans_li.append(a_input[i-1])
    for i in range(2,n,2):
        ans_li.append(a_input[i-1])
print(' '.join(map(str,ans_li)))


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

    using namespace std;
    typedef long long ll;
    # define M_PI  3.14159265358979323846
    const int MOD=1e9+7;

    bool isPrime(int n){
        for(int i=2;i*i<=n;i++){
            if(n%i==0)
                return false;
        }
        return true;
    }

    void solve(){
        int x;
        cin>>x;
        for(int i=x;i<=200000;i++){
            if(isPrime(i)){
                cout<<i;
                return;
            }
        }
        return;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


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

using namespace std;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
       if(i==n){cout << "...";
           break;}
       else cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3592
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func rev(s []byte) string {
	N := len(s)
	for i := 0; i < N/2; i++ {
		s[i], s[N-1-i] = s[N-1-i], s[i]
	}
	return string(s)
}

func check(a, b string) bool {
	for _, e := range a {
		if byte(e) == b[0] {
			return true
		}
	}
	return false
}

type pair struct {
	pre  string
	post byte
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N := getInt()
	s := make([]string, N)
	for i := 0; i < N; i++ {
		s[i] = rev([]byte(getString()))
	}
	sort.Slice(s, func(i, j int) bool {
		return len(s[i]) < len(s[j])
	})
	ans := 0
	mp := make(map[int]int)
	off := 100007
	for _, x := range s {
		hash := make([]int, len(x))
		hash[0] = int(x[0])
		for i := 1; i < len(x); i++ {
			hash[i] = hash[i-1]*off + int(x[i])
		}
		cnt := make([]int, 26)
		for i := 0; i < len(x); i++ {
			cnt[int(x[i]-'a')]++
		}
		for c := 0; c < 26; c++ {
			if cnt[c] == 0 {
				continue
			}
			h := c + 'a'
			// _, ok := mp[h]
			// if ok {
			ans += mp[h]
			// }
		}
		for i := 0; i < len(x)-1; i++ {
			h := hash[i] * off
			cnt[x[i]-'a']--
			for c := 0; c < 26; c++ {
				if cnt[c] == 0 {
					continue
				}
				h += c + 'a'
				// _, ok := mp[h]
				// if ok {
				ans += mp[h]
				// }
				h -= c + 'a'
			}
		}
		// _, ok := mp[hash[len(x)-1]]
		// if !ok {
		// 	mp[hash[len(x)-1]] = 1
		// } else {
		mp[hash[len(x)-1]]++
		// }
	}
	out(ans)
}


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

int main() {

  int N;
  cin >> N;

  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  
  int stop_flag = 1;
  int count = 0;
  do{
    for(int i=0; i<N; i++){
      if(A.at(i)%2!=0){
        stop_flag = 0;
      }else{
        A.at(i) = A.at(i)>>1;
      }
      if((i==N-1)&&(stop_flag==1)){
        count++;
      }
    }
  }while(stop_flag);
  
  cout << count << endl;
}



Measured memory_bytes: 256
N=int(input())
S=list(map(int,input().split()))

counter=0
for E in range(0,N):
    for i in range(N-1,E,-1):
        if S[i]<S[i-1]:
            this_value=S[i]
            S[i]=S[i-1]
            S[i-1]=this_value
            counter+=1
        else:pass

print(*S)
print(counter)


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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  static const int MAX = 100010;
  int N, x, as[MAX], bs[MAX];

  void init() {
    cin >> N >> x;
    rep(i, N) {
      cin >> as[i];
    }
  }

  void solve() {
    rep(i, N) bs[i] = min(as[i], x);
    rep(i, N-1) bs[i+1] -= max(0, bs[i] + bs[i+1] - x);
    ll ans = 0;
    rep(i, N) ans += as[i] - bs[i];
    cout << ans << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a,b;
  cin >> a >> b;
  vector<vector<char>> c(a,vector<char>(a)),d(b,vector<char>(b));
  rep(i,a){
    string s;
    cin >> s;
    rep(j,a) c[j][i]=s[j];
  }
  rep(i,b){
    string s;
    cin >> s;
    rep(j,b) d[j][i]=s[j];
  }
  bool tt=false;
  rep(i,a-b+1){
    rep(j,a-b+1){
      bool t=true;
      for (int k=i;k<i+b;k++){
        for (int ii=j;ii<j+b;ii++){
          if (c[ii][k]!=d[ii-j][k-i]) t=false;
        }
      }
      if (t) tt=true;
    }
  }
  if (tt) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
now = 0
used = [False] * 60
while True:
    sleep_start = now + a
    if now % 60 < sleep_start % 60:
        if now % 60 <= c <= sleep_start % 60:
            print(now // 60 * 60 + c)
            break
        now = sleep_start + b
    else:
        if now % 60 <= c < 60 or 0 < c <= sleep_start % 60:
            print(now // 60 * 60 + c)
            break
        now = sleep_start + b
    if now % 60 == 0:
        print(-1)
        break

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

using namespace std;


bool check_exsit(int vals[], int N, int target){
    for (int i = 0; i < N; i++) {
        if( vals[i] == target){
            return true;                
        }
    }
    return false;

}

int main(){
    int X, N;
    cin >> X >> N;
    int p_vals[N];
    for (int i=0; i<N; i++){
        cin >> p_vals[i];
    }

    int diff = 0;

    while(true){
        if(!check_exsit(p_vals, N, X - diff)){
            cout << X - diff << endl;
            return 0;
        }

        if(!check_exsit(p_vals, N, X + diff)){
            cout << X + diff << endl;
            return 0;
        }

        diff += 1;

    }
}



Measured memory_bytes: 3612
#include <cstdio>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)


int hist[2][100];
char buf[100];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, 26) {
    hist[0][i] = 1111111;
  }
  REP(i, n) {
    scanf("%s", buf);
    for(int j = 0; buf[j]; ++j) {
      hist[1][buf[j]-'a']++;
    }
    REP(j, 26) {
      hist[0][j] = min(hist[0][j], hist[1][j]);
      hist[1][j] = 0;
    }
  }
  REP(i, 26) {
    REP(j, hist[0][i]) {
      putchar('a'+i);
    }
  }
  putchar('\n');
  return 0;
}


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

int main() {
    int a,b,c ,ans(0);

    cin >> a >> b >> c;
    if (a == b && b != c) ans= 1;
    if (b == c && c != a) ans = 1;
    if (c == a && a != b) ans = 1;
    
    if(ans == 1){
        cout << "Yes";
    }else{
        cout << "No";
    }

}

   


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

long long gcd(long long a, long long b){
    while(b != 0){
        long long tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

void findPrime(int N, vector<bool>& isPrime)
{
    isPrime.assign(N+1, true);
    isPrime[0] = isPrime[1] = false;
    for(int i=2; i*i<=N; i++){
        if(isPrime[i]){
            for(int j=i; i*j<=N; j++){
                isPrime[i*j] = false;
            }
        }
    }
}

void findPrime(int N, vector<int>& prime)
{
    vector<bool> isPrime;
    findPrime(N, isPrime);

    prime.clear();
    for(int i=0; i<=N; ++i){
        if(isPrime[i])
            prime.push_back(i);
    }
}

const int MAX = 300;
const int MAX_SQRT = 17;
vector<bool> isPrime;
vector<int> prime;
vector<int> score;

int solve(long long curr, int k)
{
    int ans = 0;
    if(k == prime.size()){
        vector<int> add(MAX+1, 0);
        for(int i=1; i<=MAX; ++i){
            int a = (int)(i / gcd(i, curr));
            if(a == 1 || (a > MAX_SQRT && isPrime[a]))
                add[a] += score[i];
        }
        for(int i=1; i<=MAX; ++i){
            if(i == 1 || add[i] > 0)
                ans += add[i];
        }
        return ans;
    }
    else{
        int tmp = 1;
        ans = INT_MIN;
        while(tmp <= MAX){
            ans = max(ans, solve(curr, k+1));
            curr *= prime[k];
            tmp *= prime[k];
        }
    }

    return ans;
}

int main()
{
    findPrime(MAX, isPrime);
    findPrime(MAX_SQRT, prime);

    int q;
    cin >> q;
    score.assign(MAX+1, 0);
    for(int i=0; i<q; ++i){
        int m, x;
        cin >> m >> x;
        score[m] = x;
    }
    cout << solve(1, 0) << endl;

    return 0;
}


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

long long n, k, m;
vector<vector<vector<long long>>> dp;

long long solve();

int main() {
  cin >> n >> k >> m;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  dp.assign(2 * n + 1,
            vector<vector<long long>>(
                n + 1, vector<long long>(1LL << k, 0)));
  dp[1][1][1] = 1;
  for(int i = 1; i < 2 * n; ++i) {
    for(int j = 1; j <= n; ++j) {
      for(int s = 0; s < (1LL << k); ++s)
        if(j >= i - j && j - (i - j) <= k) {
          int up = -100, upright = -1, down = 1, id = j;
          for(int l = 0; l < min(k, (long long)i); ++l) {
            if(!(s >> l & 1) && down == 1) down = i - l;
            if(s >> l & 1) {
              if(upright == -1) upright = i - l;
              if(id == i - j + 1) up = i - l;
              --id;
            }
          }
          if(i + 1 - upright <= k && j < n)
            (dp[i + 1][j + 1][(s << 1) % (1LL << k) + 1] +=
             dp[i][j][s]) %= m;
          if(i + 1 - min(up, down) <= k)
            (dp[i + 1][j][(s << 1) % (1LL << k)] +=
             dp[i][j][s]) %= m;
        }
    }
  }
  long long res = 0;
  for(int i = 0; i < (1LL << k); ++i)
    (res += dp[2 * n][n][i]) %= m;
  return res;
}


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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int a,b;
    cin>>a>>b;
    long long int c=a+b;
    if(c%2==0){
    	cout<<c/2;
	}
	else{
		cout<<"IMPOSSIBLE";
	}
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
string s;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s;
    bool y = true;
    F0R(i, sz(s))
    {
        if(i%2 && s[i] == 'R') y = false;
        if(!(i%2) && s[i] == 'L') y = false; 
    }
    cout << (y ? "Yes" : "No");
    return 0;
}

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

int main(){
    int n,S[1001000],q,k,sum=0;
    cin>>n;
    for(int i=0;i<n;i++) cin>>S[i];
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>k;
        if(*lower_bound(S,S+n,k)==k) sum++;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3376
from itertools import product

def convert(x, pt):
    return sum(e if p else -e for e, p in zip(x, pt))

def submit():
    n, m = (int(a) for a in input().split())
    cakes = [tuple(map(int, input().split())) for _ in range(n)]


    ans = 0
    for pt in product([0, 1], repeat=3):
        pt_cakes = [convert(c, pt) for c in cakes]
        pt_cakes.sort(reverse=True)
        pt_sum = sum(pt_cakes[:m])
        if pt_sum > ans:
            ans = pt_sum

    print(ans)        

submit()


Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;


signed main(){
	//cout << fixed << setprecision(10);
	ll x,k,d; cin>>x>>k>>d;
	if(abs(x)/k>=d){
		cout<<abs(x)-(d*k)<<endl;
		return 0;
	}
	ll y=abs(x)/d+(abs(x)%d!=0);
	k-=y;
	ll a=abs(x)-(d*y);
	if((k)%2==0)cout<<abs(a)<<endl;
	else{
		if(a<0)cout<<abs(a+d);
		else cout<<abs(a-d)<<endl;
	}

	return 0;
}

Measured memory_bytes: 3536
#include <stdio.h>
#include <math.h>

int main(void)
{
	int x, h;
	double S;
	
	while (1){
		scanf("%d %d", &x, &h);
		if (!x && !h)return (0);
		
		S = x * sqrt(4 * h * h + x * x) + x * x;
		
		printf("%lf\n", S);
	}
	return (0);
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k; cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) cin >> v[i];
    sort(v.begin(), v.end());
    int ans = 1e9;
    for (int i = 0; i <= n-k; ++i) {
        ans = min(ans, v[i+k-1]-v[i]);
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#include <cmath>
#include <iomanip>
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};


struct point{
	int x, y;
	point(){
		x = 0;
		y = 0;
	}
	point(int x, int y){
		this->x = x;
		this->y = y;
	}
	bool operator < (const point& p) const{
		if(p.x == this->x){
			return p.y > this->y;
		}
		else{
			return p.x > this->x;
		}
	}
	
};

int prod(point & a, point & b){
	return a.x*b.y - a.y*b.x;
}

int type(vector<ll> & v){
	if(v[0] == v[1] && v[0] == v[2] && v[0] == v[3] && v[0] == v[4])
		return 1;
	if(v[0] == v[2] && v[0] == v[4] && v[1] == v[3])
		return 2;
	else 
		return 3;
}

int main(){
	vector<ll> v;
	string s; cin>> s;
	ll k = (int)s.size();
	s = s + s + s+ s+ s;
	
	ll n,cont; cin>> n;
	
	for(int i = 0; i < (int)s.size()-1; i++){
		if(s[i] == s[i+1]){
			s[i+1] = '#';	
		}
	}
	
	cont = 0;
	int r = 0;
	for(int i = 0; i < (int)s.size(); i++, r++){
		if(s[i] == '#'){
			cont++;
		}
		if(r == k-1){
			r = -1;
			v.push_back(cont);
			cont = 0;
		}
	}
	
	if(n >= 5){
		int t = type(v);
		if(t == 1){
			cout<<n*v[0];
		}
		else if(t == 2){
			ll a = v[0];
			ll b = v[1];
			if(n%2 == 0){
				cout<< n/2*a + n/2*b;
			}
			else
				cout<< (n/2 + 1)*a + n/2*b;
		}
		else
			cout<< v[0] + (n-1)*v[1];
	}
	else{
		ll sum = 0; 
		for(int i = 0; i < n; i++)
			sum += v[i];
		cout<<sum;
	}
	//~ cout<<endl;
	//~ cout<<s<<endl;
	//~ for(int x: v){
		//~ cout<<x<<" ";
	//~ }
	return 0;
}




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        int[] list = new int[T];
        for(int i = 0 ; i < T ; i++)
            list[i] = sc.nextInt();
        int[] path = new int[T];
        path[0] = 0;
        path[1] = Math.abs(list[0]-list[1]);
        for(int i = 2 ; i < T ; i ++)
        {
            path[i] = Math.min(path[i-2]+(Math.abs(list[i]-list[i-2])),path[i-1]+(Math.abs(list[i-1]-list[i])));
        }
        
        System.out.println(path[T-1]);
    }
}


Measured memory_bytes: 52504