akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
	cin>>n>>s;
	int x = 0, mx = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'I') {
			x++;
		}else {
			x--;
		}
		mx = max(mx, x);
	}
	cout<<mx<<endl;
	return 0;
}
/*
5
IIDID
Output:2

7
DDIDDII
Output:0

10
IIIIIDDDDD
Output:5

10
DDDDDIIIII
Output:0
*/

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class EDoubleFactorial {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        lint N;
        in>>N;
        if(N&1) out<<0<<'\n';
        else{
            lint cnt = 0, cur = 1;
            while(cur*5<=N){
                cur *= 5;
                cnt += N / cur / 2;
            }
            out<<cnt<<'\n';
        }
    }
};


int main() {
	EDoubleFactorial solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int n, m;
char s[107][107];
bool vis[107];

int main() {
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%s", s[i]);
	for(int i = 1; i <= n; i++) {
		bool flag = 1;
		for(int j = 0; j < m; j++) {
			if(s[i][j] != '.') {
				flag = 0;
				break;
			}
		}
		if(flag) vis[i] = 1;
	}
	for(int j = 0; j < m; j++) {
		bool flag = 1;
		for(int i = 1; i <= n; i++) {
			if(s[i][j] != '.') {
				flag = 0;
				break;
			}
		}
		if(flag) {
			for(int i = 1; i <= n; i++) s[i][j] = '!';
		}
	}
	for(int i = 1; i <= n; i++) {
		if(!vis[i]) {
			for(int j = 0; j < m; j++) {
				if(s[i][j] != '!') printf("%c", s[i][j]);
				if(j == m - 1) printf("\n");
			}
		}
	}
}

Measured memory_bytes: 256
import math

while True:
    n=int(input())
    if n == 0:
        break
    elif n == 1:
        A=[1]*1
        
    elif n == 2:
        A=[0]*2
        A[0]=1
        A[1]=2
    elif n ==3:
        A=[0]*3
        A[0]=1
        A[1]=2
        A[2]=4
        
    else:
        A=[0]*n
        A[0]=1
        A[1]=2
        A[2]=4
    
        for t in range(3,n):
            A[t]=A[t-1]+A[t-2]+A[t-3]
        
        
    print(math.ceil(A[n-1]/3650))


Measured memory_bytes: 5660
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
	int N;
	cin >> N;
	int A[N+2];
	int B[N+2];
	for (int i = 1; i < N+1; i++) {
		cin >> A[i];
	}	

	for (int i = 1; i < N+1; i++) {
		B[A[i]] = i;
	}	

	for (int i = 1; i < N+1; i++) {
		cout << B[i] << endl;
	}	
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	#ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
	#endif

	int h, w, n;
	cin >> h >> w >> n;
	cout << min((n + h - 1) / h, (n + w - 1) / w);

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define BIT(n, m) (((n) >> (m)) & 1)

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

const ll inf = 1e15;
const ll mod = 1000 * 1000 * 1000 + 7;
const double eps = 1e-9;

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

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}

int memo[2][1010][1010];

int rec(int p, int o, int e){
  if (o + e == 2){
    // cout << p << " " << o << " " << e << " " << (1 - 2 * ((o == 2) ^ p)) << endl;
    return (1 - 2 * ((o != 2) ^ p));
  } else if (memo[p][o][e] != 0){
    return memo[p][o][e];
  } else {
    int &res = memo[p][o][e] = -1;
    if (o > 1) res = max(res, -rec(1 - p, o - 2, e + 1));
    if (e > 1) res = max(res, -rec(1 - p, o, e - 1));
    if (o > 0 && e > 0) res = max(res, -rec(1 - p, o, e - 1));
    // cout << p << " " << o << " " << e << " " << res << endl;
    return res;
  }
}

int main(){
  int V;
  char A[1010];
  while (cin >> V){
    int E = 0;
    vector<vector<int> > G(V);
    REP(i, V){
      scanf(" %s", A);
      REP(j, V) if (A[j] == 'Y'){
        G[i].push_back(j);
        E++;
      }
    }

    int even = 0;
    int odd  = 0;
    vector<int> visit(V);
    REP(i, V) if (!visit[i]){
      int count = 0;
      visit[i] = true;
      queue<int> que;
      que.push(i);
      while (!que.empty()){
        int v = que.front(); que.pop();
        count++;
        for (int w : G[v]){
          if (!visit[w]){
            visit[w] = true;
            que.push(w);
          }
        }
      }
      (count % 2 ? odd : even) += 1;
    }
    E /= 2;
    int p = (V * (V - 1) / 2 - E) % 2;
    // cout << p << " " << odd << " " << even << endl;
    cout << (rec(p, odd, even) >= 0? "Taro" : "Hanako") << endl;
  }
  return 0;
}

Measured memory_bytes: 7828
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(;;){
        int n,m,t,p;
        cin>>n>>m>>t>>p;
        if(!n) return 0;
        vector<vector<ll>> f(700,vector<ll>(700,0));
        int L=0,R=n, U=0,D=m;
        rep(i,0,m){
            rep(j,0,n) f[i][j]=1;
        }
        rep(_,0,t){
            int d,c;
            cin>>d>>c;
            if(d==1){
                rep(i,U,D){
                    rep(j,L+c,2*c+L){
                        f[i][j]+=f[i][2*L+2*c-1-j];
                    }
                }
                L+=c;
                R=max(R,L+2*c);
            }
            else{
                rep(i,U+c,U+2*c){
                    rep(j,L,R){
                        f[i][j]+=f[2*U+2*c-1-i][j];
                    }
                }
                U+=c;
                D=max(D,U+2*c);
            }
        }
        rep(_,0,p){
            int x,y;
            cin>>x>>y;
            x+=L;
            y+=U;
            cout <<f[y][x]<<"\n";
        }
    }
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int MOD = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,m;
        cin>>n>>m;
        int cnt[n+1] = {};
        while(m--)
        {
            int x,y;
            cin>>x;
            while(x--)
            {
                cin>>y;
                cnt[y]++;
            }
        }
        int ans = 0;
        for(int i=1;i<=n;i++)ans+=(cnt[i]==0);
        cout<<ans<<endl;

    }
    return 0;
}


Measured memory_bytes: 3648
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static final int INF = (int)1e9 + 7;
	int N,Ma,Mb,sumA,sumB;
	int[] A,B,C;

	public void solve() {
		N = nextInt();
		Ma = nextInt();
		Mb = nextInt();

		A = new int[N];
		B = new int[N];
		C = new int[N];

		for(int i = 0;i < N;i++){
			A[i] = nextInt();
			B[i] = nextInt();
			C[i] = nextInt();
			sumA += A[i];
			sumB += B[i];
		}

		int[][][] dp = new int[N+1][sumA+10][sumB+10];
		for(int i = 0;i < N + 1;i++){
			for(int j = 0;j < sumA + 10;j++){
				for(int k = 0;k < sumB + 10;k++){
					dp[i][j][k] = INF;
				}
			}
		}

		dp[0][0][0] = 0;
		for(int i = 0;i < N;i++){
			for(int j = 0;j < sumA+1 - A[i];j++){
				for(int k = 0;k < sumB+1 - B[i];k++){
					int a = j + A[i];
					int b = k + B[i];
					dp[i+1][j][k] = Math.min(dp[i+1][j][k], dp[i][j][k]);
					dp[i+1][a][b] = Math.min(dp[i+1][a][b],dp[i][j][k]+C[i]);
				}
			}
		}

		int ans = INF;
		int max = Math.max(Ma,Mb);
		int min = Math.min(sumA, sumB);
		for(int i = 1;i * max <= min;i++){
			ans = Math.min(ans,dp[N][i*Ma][i*Mb]);
		}
		if(ans == INF){
			out.println(-1);
		}else{
			out.println(ans);
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

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

using namespace std;

int lcs(string s1, string s2) {
    int c[1005][1005];
    int m = s1.length();
    int n = s2.length();
    s1 = " " + s1;
    s2 = " " + s2;
    int max1 = 0;
    for (int i = 0; i <= m; i++) {
        c[i][0] = 0;
    }
    for (int i = 0; i <= n; i++) {
        c[0][i] = 0;
    }
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (s1[i] == s2[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            max1 = max(max1, c[i][j]);
        }
    }
    return max1;
}

int main() {
    int q;
    cin >> q;
    string s1, s2;
    for (int k = 0; k < q; k++) {
        cin >> s1;
        cin >> s2;
        cout << lcs(s1, s2) << endl;
    }

    return 0;
}

Measured memory_bytes: 6988
#include <cstdio>
#include <cstdlib>
#include <cstring>
 
#define siz 10000000
 
char buf[siz], *bit = buf;
 
inline int nextInt(void) {
    register int ret = 0;
    register int neg = false;
 
    for (; *bit < '0'; ++bit)
        if (*bit == '-')neg ^= true;
 
    for (; *bit >= '0'; ++bit)
        ret = ret * 10 + *bit - '0';
 
    return neg ? -ret : ret;
}
 
#define inf 2147483647
 
int n, m;
 
int tag[400005];
 
int find(int t, int l, int r, int p) {
    if (~tag[t])
        return tag[t];
    int mid = (l + r) >> 1;
    if (p <= mid)
        return find(t << 1, l, mid, p);
    else
        return find(t << 1 | 1, mid + 1, r, p);
}
 
void update(int t, int l, int r, int x, int y, int k) {
    if (l == x && r == y)
        tag[t] = k;
    else {
        int mid = (l + r) >> 1;
        if (~tag[t])
            tag[t << 1] = tag[t << 1 | 1] = tag[t], tag[t] = -1;
        if (y <= mid)
            update(t << 1, l, mid, x, y, k);
        else if (x > mid)
            update(t << 1 | 1, mid + 1, r, x, y, k);
        else {
            update(t << 1, l, mid, x, mid, k);
            update(t << 1 | 1, mid + 1, r, mid + 1, y, k);
        }
    }
}
 
signed main(void) {
    fread(buf, 1, siz, stdin);
 
    n = nextInt();
    m = nextInt();
 
    for (int i = 0; i < (n << 2); ++i)
        tag[i] = inf;
 
    for (int i = 1; i <= m; ++i) {
        int c = nextInt();
        if (c)  // find(x)
            printf("%d\n", find(1, 1, n, nextInt() + 1));
        else {
            int x = nextInt();
            int y = nextInt();
            int k = nextInt();
            update(1, 1, n, x + 1, y + 1, k);
        }
    }
 
    //system("pause");
}


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

int main() {
    int x, y; cin >> x >> y;
    
    int ans = 0;

    if (x <= 3)
        ans += (4 - x) * 100 * 1000;
    if (y <= 3)
        ans += (4 - y) * 100 * 1000;

    if (x == 1 and y == 1)
        ans += 400 * 1000;

    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

int main() {
    using VertexId = std::uint32_t;
    using EdgeId = std::uint64_t;

    auto n = VertexId(0);
    auto m = EdgeId(0);
    std::cin >> n >> m;

    auto adjacency_list = std::vector<std::vector<VertexId>>(n, std::vector<VertexId>());

    auto in_edge_num = std::vector<VertexId>(n, VertexId(0));

    for (auto i_ = 0; i_ < m; ++i_) {
        auto source = VertexId(0);
        auto target = VertexId(0);
        std::cin >> source >> target;

        adjacency_list[source].emplace_back(target);
        in_edge_num[target]++;
    }

    auto sorted_vertex = std::vector<VertexId>();
    const auto invalid_vertex = std::numeric_limits<VertexId>::max();

    auto q = std::queue<VertexId>();
    for (auto i = 0; i < n; ++i) {
        if (in_edge_num[i] == 0) q.emplace(i);
    }

    while (!q.empty()) {
        const auto v = q.front();
        q.pop();

        in_edge_num[v] = invalid_vertex;

        sorted_vertex.emplace_back(v);

        for (const auto& target_from_v : adjacency_list[v]) {
            if (in_edge_num[target_from_v] != invalid_vertex) {
                in_edge_num[target_from_v]--;

                if (in_edge_num[target_from_v] == 0) q.emplace(target_from_v);
            }
        }
    }

    for (const auto& v : sorted_vertex) {
        std::cout << v << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3808
// AOJ 2008: Dragon Fantasy
// 2017.11.22 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <math.h>

#define dist(x, y)	(hypot(x, y))

int cx[22], cy[22], n, lim;
double dd[22];
double dc[22][22];

int rec(int i, int s, double d)
{
	int j, jj;

	if (s == lim) return 1;
	for (jj = 1, j = 0; j < n; j++, jj <<= 1) {
		if (s & jj) continue;
		if (dd[j] <= d + dc[i][j]) return 0;
	}
	for (jj = 1, j = 0; j < n; j++, jj <<= 1) {
		if (s & jj) continue;
		if (rec(j, s | jj, d + dc[i][j])) return 1;
	}
	return 0;
}

int main()
{
	int i, j, hx, hy, dx, dy;

	while (scanf("%d%d%d%d%d", &n, &hx, &hy, &dx, &dy) && n > 0) {
		n++; lim = (1<<n)-1;
		cx[0] = hx, cy[0] = hy;
		for (i = 1; i < n; i++) scanf("%d%d", cx+i, cy+i);
		for (i = 0; i < n; i++) {
			dd[i] = dist(cx[i]-dx, cy[i]-dy);
			for (j = i+1; j < n; j++) {
				dc[i][j] = dc[j][i] = dist(cx[i]-cx[j], cy[i]-cy[j]);
			}
		}
		puts(rec(0, 0, 0) ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 1812
(defun expt-10-9 (base n)
  (let* ((arr (make-array 100 :element-type 'fixnum :initial-element 0))
         (a (format nil "~b" n)))
    (labels ((expt-f (k)
               (if (= k 1)
                   base
                   (setf (aref arr (floor (log k 2)))
                         (mod (expt (expt-f (/ k 2)) 2) 1000000007))))
             (10-9-* (x y) (mod (* x y) 1000000007)))
    (setf (aref arr 0) base)
    (expt-f (expt 2 (1+ (length a))))
    (mod (reduce #'10-9-* (map 'list (lambda (x y) (if (char= x #\0) 1 y)) (reverse a) arr)) 1000000007))))

(defun !-10-9 (n a ans)
  (if (= n (1- a))
      ans
      (!-10-9 (1- n) a (mod (* n ans) 1000000007))))

(defun c (n a)
  (* (!-10-9 n (- n a -1) 1) (expt-10-9 (!-10-9 a 1 1) 1000000005)))

(let* ((n (read))
       (a (read))
       (b (read)))
  (princ (mod (- (expt-10-9 2 n) 1 (c n a) (c n b)) 1000000007)))


Measured memory_bytes: 20196
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

string s[310], t[310];
bool check[310][310];

bool is_kaibun(string s){
    bool res = true;
    for(int i=0; i < s.size() / 2; i++){
        if(s[i] != s[s.size() - 1 - i]) res = false;
    }
    return res;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(i, 0, n){
        cin >> s[i];
    }
    bool f = true;
    rep(i, 0, n){
        int y = i;
        int x = 0;
        char c = s[y][x];
        t[i] += c;
        rep(j, 1, n){
            y = (y - 1 + n) % n;
            x = (x + 1) % n;
            if(s[y][x] != c) f = false;
            t[i] += s[y][x];
        }
    }
    if(f){
        cout << n * n << endl;
        return 0;
    }
    int ans = 0;
    // if(n < 50){
        rep(i, 0, n){
            rep(j, 0, 1){
                bool g = true;
                rep(k, 0, n){
                    rep(l, 0, k){
                        int y = (i + k) % n;
                        int x = (j + l) % n;
                        int ny = (i + l) % n;
                        int nx = (j + k) % n;
                        if(s[y][x] != s[ny][nx]){
                            g = false;
                            break;
                        }
                    }
                    if(g == false) break;
                }
                if(g){
                    j = n;
                    ans += n;
                }
            }
        }
    // }else{
    //     rep(i, 0, n){
    //         string str = "";
    //         str = t[i] + t[i];
    //         rep(j, 0, n){
    //             string tmp = str.substr(j, j + n);
    //             if(is_kaibun(tmp)){
    //                 check[i][j] = true;
    //             }
    //         }
    //     }
    //     rep(i, 0, n){
    //         rep(j, 0, n){
    //             bool now = true;
    //             rep(k, 0, n){
    //                 if(check[i][k] == false) now = false;
    //             }
    //             if(now) ans++;
    //         }
    //     }
    // // }
    cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int a, b, c;
int main() {
    unordered_set<int> seen;
    cin >> a >> b >> c;
    int d = a % b;
    int r = d;
    while (1) {
        if (r == c) {
            cout << "YES" << endl;
            exit(0);
        }
        if (seen.count(r)) break;
        seen.insert(r);
        r = (r + d) % b;
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, tmp, flag = 0;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> tmp;
        if(tmp%2 == 0){
            if(tmp%3 != 0 && tmp%5 != 0){
                flag = 1;
            }
        }
    }
    if(flag == 0) cout << "APPROVED\n";
    else cout << "DENIED\n";
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

int H, W;
int dx[2] = {0,1};
int dy[2] = {1,0};
vector<vector<bool>> checked(8,vector<bool>(8,false));
vector<string> fmap(8);

int roads = 0;

bool dfs(int x, int y, int distance){
    if((x < 0 || W <= x)||(y < 0 || H <= y)) return false;
    if(checked[y][x]) return false;
    if(fmap[y][x]=='.') return false;
    
    if(x==W-1 && y==H-1 && distance==roads) return true;
    
    checked[y][x] = true;
    rep(i,2) if(dfs(x+dx[i], y+dy[i], distance+1)) return true;
    return false;
}

signed main(){
    cin >> H >> W;
    collect(fmap, H);
    rep(x,W)rep(y,H){
        if(fmap[y][x]=='#') roads++;
    }
    cout << (dfs(0,0,1) ? "Possible" : "Impossible") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d[ohara],tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz");
bool fl;
struct edge{ll to,cost;};
vector<edge> g[ohara];
pair<ll,ll> p[ohara];
pair<ll,ll> pp[ohara];
map<pair<ll,ll>,ll> mp;

//-------------------------↓↓↓↓↓↓------------------------

void dijkstra(ll s){
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>que;
    fill(d,d+n,LINF);
    d[s]=0;
    que.push(pair<ll,ll>(0LL,s));
    while(!que.empty()){
        pair<ll,ll> pp=que.top();que.pop();
        ll v=pp.second;
        if(d[v]<pp.first)continue;
        rep(i,Size(g[v])){
            edge e=g[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pair<ll,ll>(d[e.to],e.to));
            }
        }
    }
}

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

    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)p[i]=make_pair(a[i],i);
    rep(i,n)cin>>b[i];
    rep(i,n)pp[i]=make_pair(b[i],i);
    sort(p,p+n);
    sort(pp,pp+n);
    rep(i,n-1){
        //pos=min(abs(p[i].first-p[i+1].first),abs(pp[i].first-pp[i+1].first));
        if(mp[{p[i].second,p[i+1].second}]!=0)mp[{p[i].second,p[i+1].second}]=min(abs(p[i].first-p[i+1].first),mp[{p[i].second,p[i+1].second}]),mp[{p[i+1].second,p[i].second}]=mp[{p[i].second,p[i+1].second}];
        else mp[{p[i].second,p[i+1].second}]=abs(p[i].first-p[i+1].first),mp[{p[i+1].second,p[i].second}]=mp[{p[i].second,p[i+1].second}];
        if(mp[{pp[i].second,pp[i+1].second}]!=0)mp[{pp[i].second,pp[i+1].second}]=min(abs(pp[i].first-pp[i+1].first),mp[{pp[i].second,pp[i+1].second}]),mp[{pp[i+1].second,pp[i].second}]=mp[{pp[i].second,pp[i+1].second}];
        else mp[{pp[i].second,pp[i+1].second}]=abs(pp[i].first-pp[i+1].first),mp[{pp[i+1].second,pp[i].second}]=mp[{pp[i].second,pp[i+1].second}];
    }
    rep(i,n-1){
        pos=mp[{p[i].second,p[i+1].second}];
        g[p[i].second].push_back({p[i+1].second,pos});
        g[p[i+1].second].push_back({p[i].second,pos});
    }
    rep(i,n-1){
        pos=mp[{pp[i].second,pp[i+1].second}];
        g[pp[i].second].push_back({pp[i+1].second,pos});
        g[pp[i+1].second].push_back({pp[i].second,pos});
    }
    dijkstra(0);
    rep(i,n){
        Cout(d[i]);
    }
    return 0;
}



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

signed main() {
   
   string S , T;
   cin>>S>>T;
   
   // here we have to make changes in the S..
   
   long long unsigned  res = INT_MAX;
   for(int i = 0;i<=S.length() - T.length();i++)
   {
       string str = S.substr(i , T.length());
       
       int count = 0;
       for(int j = 0;j<T.length();j++)
       {
           if(str[j] == T[j])
           count++;
       }
       
       res = min(res , T.length() - count);
   }
   
   cout<<res<<"\n";
}

Measured memory_bytes: 3628
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

using ll = long long;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi L(n);
  VIN(L)
  SORT(L);
  REP(i,n){
    FOR(j,i+1,n){
      FOR(k,j+1,n){
        if((L[i] < L[j] + L[k])&&(L[j] < L[k] + L[i])&&(L[k] < L[i] + L[j])){
          x++;
        } else {
          break;
        }
      }
    }
  }
  OUT(x);
}

Measured memory_bytes: 256
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
  int n, a;
  cin >> n >> a;
  n %= 500;
  if (n <= a) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)

int main(void)
{
	int a,i;
	double b[12],x=0;
	char c[5];
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%lf %s",&b[i],&c);
		if(c[0]=='J'){
			x=x+b[i];
		}else{
			x=x+b[i]*380000;
		}
	}
	printf("%f",x);
	return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <chrono>
#include <random>

using namespace std;

typedef long long ll;

void solve() {
	ll n, q;
	cin >> n >> q;
	set<pair<int, int>> h = { {n,n} }, v = { {n,n} };
	ll ans = (n - 2) * (n - 2);
	for (int i = 0; i < q; i++) {
		int t, x;
		cin >> t >> x;
		if (t == 1) {
			pair<int,int> to = *v.lower_bound(make_pair(x, -1));
			ans -= (to.second - 2);
			h.insert({ to.second - 1, x });
		}
		else {
			pair<int, int> to = *h.lower_bound(make_pair(x, -1));
			ans -= (to.second - 2);
			v.insert({ to.second - 1, x });
		}
	}

	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		//cout << endl;
	}
}

Measured memory_bytes: 12964
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	ull q,h,s,d,sum1,sum2;
	ull n,ans = 0;
	cin >> q >> h >> s >> d >> n;
	
	sum1 = min(s,min(h*2,min(q*4,h+q*2)));
	sum2 = min(d,min(s*2,min(h*4,min(q*8,min(s+(h+q*2),min(s+h*2,min(s+q*4,min(h*2+q*4,min(h*2+(h+q*2),q*4+(h+q*2))))))))));
	
	
	cout << (ull)(((n/2)*sum2)+((n%2)*sum1)) << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
x, y = map(int, input().split())
d = [x - y, x - y, x + y, x + y]
for i in range(1,N):
  x, y = map(int, input().split())
  d[0] = max(d[0], x-y)
  d[1] = min(d[1], x-y)
  d[2] = max(d[2], x+y)
  d[3] = min(d[3], x+y)
print(max(d[0]-d[1], d[2]-d[3]))

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2") 
#pragma GCC optimization ("unroll-loops")

using namespace std;
using ll = long long;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ff first
#define ss second
#define Ceil(x, y) ((x+y-1)/y)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x);
const int mod = (int) 1000000007;


void solve()
{
	int n;
	cin>>n;
	deque<int> freq1(2e5+10), freq2(2e5+10), A(n), B(n);
	for(int i=0; i<n; i++)
	{
		int e;
		cin>>e;
		A[i] = e;
		freq1[e]++;
	}
	for(int i=0; i<n; i++)
	{
		int e;
		cin>>e;
		B[i] = e;
		freq2[e]++;
	}
	for(int i=1; i<=2e5+10; i++)
		if(freq1[i]+freq2[i] > n)
		{
			cout<<"No";
			return;
		}
	cout<<"Yes"<<endl;
	vector<int> res(n);
	for(int i=0; i<n; i++)
		if(A[i]!=B.front())
		{
			res[i] = B.front();
			B.pop_front();
		}
		else
		{
			res[i] = B.back();
			B.pop_back();
		}

	for(int i=0; i<n; i++)
	{
		if(A[i] == res[i])
		{
			for(int j=0; j<n; j++)
				if(A[i] != res[j] && A[j] != res[i])
					swap(res[j], res[i]);
		}
	}
	for(auto i : res)
		cout<<i<<" ";
	
}

int main(int argc, char *argv[])
{
	clock_t clk_start = clock();
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
 
	int cases = 1;
	// cin>>cases;
	for(int i=1; i<=cases; i++)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr<<"Execution Time: "<<fixed<<double(clock() - clk_start)/double(CLOCKS_PER_SEC)<<setprecision(6)<<" sec\n"; 
}


Measured memory_bytes: 7548
N,M = list(map(int,input().split()))
X = [[]*3 for i in range(M)]
for i in range(N):
    A,B = list(map(int,input().split()))
    if A>M:
        continue
    else:
        X[M-A].append(B)

import heapq
out = 0
Y = []
heapq.heapify(Y)
for i in range(M):
    P = M-1-i
    Ls = X[P]
    for L in Ls:
        heapq.heappush(Y, -1*L)
    if len(Y)>0:
        Q = heapq.heappop(Y)
        out += -1*Q
print(out)

Measured memory_bytes: 88600
#include <bits/stdc++.h>
#include <cmath>
#include <functional>
#include <iostream>
using namespace std;

int main() {
  vector<int> L;
  int N, num = 0;
  
  cin >> N;
  if(N < 3){
    cout << 0 << endl;
    return 0;
  }
  
  L.resize(N);
  for(int i = 0; i < N; i++)cin >> L[i];
  
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      for(int k = j+1; k < N; k++){
        if((L[i] == L[j]) || (L[i] == L[k]) || (L[j] == L[k]))continue;
        if(L[i] < L[j] + L[k] &&
           L[j] < L[k] + L[i] && 
           L[k] < L[i] + L[j])num++;
        }
    }
  }
  
  cout << num << endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i,j,vl=100000,msh[200009],pas;
vector <long long> v[200009];
bool bo[200009];
long long fnd(long long q){
	if(msh[q]==q) return q; else return msh[q]=fnd(msh[q]);
}
void mrg(long long q, long long w){
	q=fnd(q);w=fnd(w);
	if(q==w) return;
	if(v[q].size()<v[w].size()) swap(q,w);
	msh[w]=q;
	for(long long h=0; h<v[w].size(); h++){
		v[q].push_back(v[w][h]);
	}
}
int main(){
	cin>>a;
	for(i=1; i<=vl*2; i++){
		v[i].push_back(i);msh[i]=i;
	}
	for(i=1; i<=a; i++){
		cin>>c>>d;
		mrg(c,d+vl);
	}
	for(i=1; i<=vl*2; i++){
		c=fnd(i);
		if(bo[c]==1) continue;
		bo[c]=1;
		d=0;e=0;
		for(j=0; j<v[c].size(); j++){
			if(v[c][j]<=vl) d++; else e++;
		}
		pas+=d*e;
	}
	cout<<pas-a;
	return 0;
}

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

int main() {
    long N;
    cin>>N;
    
    vector<pair<long,long>> r(N),b(N);
    
    for(int i=0;i<N;i++) cin>>r.at(i).first>>r.at(i).second;
    for(int i=0;i<N;i++) cin>>b.at(i).first>>b.at(i).second;
    
    sort(r.begin(),r.end());
    sort(b.begin(),b.end());
    
    
    set<long> avR;
    long fl=0,ans=0;
    for(int i=0;i<N;i++){
        while(fl<N && r.at(fl).first<b.at(i).first) avR.insert(r.at(fl++).second);
        auto ite=avR.lower_bound(b.at(i).second);
        if(ite!=avR.begin()){
            ans++;
            avR.erase(--ite);
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
def make_move
  move = []
  -1.upto(1) do |i|
    [2, -2].each do |j|
      move << [i, j]
      move << [j, i]
    end
  end
  move
end

def sprinkler_range(sprinklers, i)
  x, y = sprinklers[i]
  range = []
  -1.upto(1) do |i|
    -1.upto(1) do |j|
      range << [x+i, y+j]
    end
  end
  range
end

move = make_move

loop do
  x, y = gets.split.map(&:to_i)
  break if [x, y].all?(&:zero?)
  current = [[x, y]]

  n = gets.to_i

  sprinklers = []
  gets.split.map(&:to_i).each_slice(2){|x| sprinklers << x}

  n.times do |i|
    current_range = sprinkler_range(sprinklers, i)
    temp = []
    
    current.each do |c|
      move.each do |m|
        jump_to = [c[0]+m[0], c[1]+m[1]]
        temp << jump_to if current_range.include? jump_to
      end
    end

    if temp.empty?
      puts "NA"
      break
    elsif i == n-1
      puts "OK"
    else
      current = temp
    end
  end
end  

Measured memory_bytes: 6116
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;
const int MAX = (int)1e6 + 1;

int main() {
    // pre
    vector<int> tetras(1, 0);
    for (int i = 1; ; i++) {
        int t = [](int n){ return n * (n + 1) * (n + 2) / 6; }(i);
        if (t > 1e6) break;
        tetras.push_back(t);
    }
    // cout << tetras.size() << endl;  // 180

    // dp_all, dp_odd
    vector<int> dp_all(MAX, INF), dp_odd(MAX, INF);
    dp_all[0] = dp_odd[0] = 0;
    for (int cur : tetras) {
        for (int j = cur; j < MAX; j++) {
            dp_all[j] = min(dp_all[j], dp_all[j - cur] + 1);
            if (cur % 2) dp_odd[j] = min(dp_odd[j], dp_odd[j - cur] + 1);
        }
    }

    // post
    int n;
    while (cin >> n, n) {
        cout << dp_all[n] << " " << dp_odd[n] << endl;
    }
    return 0;
}


Measured memory_bytes: 10604
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
string intToA(int n, int radix) //n是待转数字，radix是指定的进制
{
    string ans = "";
    do
    {
        int t = n % radix;
        if (t >= 0 && t <= 9)
            ans += t + '0';
        else
            ans += t - 10 + 'a';
        n /= radix;
    } while (n != 0); //使用do{}while（）以防止输入为0的情况
    reverse(ans.begin(), ans.end());
    return ans;
}
int main(){
    int a,b;
    cin>>a>>b;
    cout<<intToA(a,b).length();
    return 0;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n,m;
bool h=false;
vs in;
vi used;
int q=-1;
void f(int a){
	if(a==n/2){
		vs t(n);
		rep(i,n)t[used[i]]=in[i];
//		rep(i,n)cout<<" "<<used[i];cout<<endl;
		int co=0,co1=0;
		vi use(m);
		rep(i,m)if(use[i]==0){
			bool w=true;
			loop(j,i+1,m)if(use[i]==0){
				bool H=true;
				rep(k,n)if(t[k][i]!=t[n-1-k][j])H=false;
				if(H){
					use[j]=true;
					goto end;
				}
			}
			co++;
			if(m%2<co)break;
			rep(k,n)if(t[k][i]!=t[n-1-k][i])w=false;
			if(w)co1++;
			if(m%2<co1)break;
			end:;
		}
		if(m%2==co){
			if(co&&co1==0)return;
			h=true;
		}
		return;
	}
	int c=0;
	rep(i,n)if(used[i]==q){
		loop(j,i+1,n)if(used[j]==q){
			used[i]=a;
			used[j]=n-1-a;
			f(a+1);
			used[i]=used[j]=q;
		}
		if(n%2&&!c)c=1;
		else break;
	}
}
int main(){
	cin>>n>>m;
	in=vs(n);
	if(n%2)q=n/2;
	rep(i,n)cin>>in[i];
	used=vi(n,q);
	f(0);
	
	if(h)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<climits>
#include<string>
using namespace std;
#define lli long long int
#define f first
#define s second
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define pr(n) printf("%d",n);
#define prl(n) printf("%lld",n);
#define nl printf("\n");
#define all(c) (c).begin(), (c).end()
#define sz(a) int((a).size())
#define FN(i,n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++))
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
void optimizeIO()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
}
long long int dp[101][100001]={0};

int main()
{
	int n,w;
	cin >> n >> w;
	pair<long long int, long long int> pr[1111];
	for(int i=1;i<=n;i++){
		cin >> pr[i].f >> pr[i].s;
	};
	sort(pr+1, pr + n+1);

	for(int i=1;i<=n;i++){
		for(int j=1;j<=w;j++){
				dp[i][j] = dp[i-1][j];
				if(j - pr[i].f >= 0 ){
				dp[i][j] = max(dp[i][j], dp[i-1][j-pr[i].f] + pr[i].s);
				//cout << dp[i][j] << " ";
				}
			}
//		cout << endl;
	}

	cout << dp[n][w] << endl;

}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P  = pair<int, int>;
int main() {
    ll n, s = 0;
    cin >> n;
    for (int a = 1; a <= n; ++a) {
        // C = N - A*B
        ll l = 1, r = n + 1;
        while (l + 1 < r) {
            ll b = (l + r) / 2;
            if (n - a * b > 0)
                l = b;
            else
                r = b;
        }
        s += l;
    }
    cout << s - 1;
}

Measured memory_bytes: 3620
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

struct Graph{
    struct Node{
        unordered_set<int> dests;
        int c;
    };
    vector<Node> nodes;
    unordered_set<int> leaves;
    Graph(int num): nodes(num){ }
    int id(Node* n){ return n - &nodes[0]; }
    int id(Node& n){ return &n - &nodes[0]; }
    void print(){ for(auto& node : nodes){ prints(id(node), node.dests); } }
    void add1Edge(int from, int dest){
        nodes[from].dests.insert(dest);
    }
    void add2Edge2(int from, int dest){
        add1Edge(from, dest);
        add1Edge(dest, from);
    }
    void dfs(int idx, int c){
        nodes[idx].c = c;
        for(int didx : nodes[idx].dests){
            nodes[didx].dests.erase(idx);
            if(nodes[didx].dests.size() == 1){
                leaves.insert(didx);
            }
        }
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    Graph g(n);
    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g.add2Edge2(a, b);
    }
    vector<int> cs(n); cin >> cs;
    for(int i = 0; i < n; i++){
        if(g.nodes[i].dests.size() == 1){
            g.leaves.insert(i);
        }
    }
    sort(cs.rbegin(), cs.rend());
    int rem = n;
    int acc = 0;
    while(rem){
        auto leaves = g.leaves;
        g.leaves.clear();
        for(auto& li : leaves){
            g.dfs(li, cs.back());
            rem--;
            if(rem){
                acc += cs.back();
            }
            cs.pop_back();
        }
    }
    cout << acc << '\n';
    for(int i = 0; i < n; i++){
        cout << g.nodes[i].c << ' ';
    }
}


Measured memory_bytes: 2688
#include <iostream>
#include <cmath>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
using namespace std;
typedef long long ll;

int dx[8]={1,1,0,-1,-1,-1,0,1}, dy[8]={0,1,1,1,0,-1,-1,-1};
void dfs(int x, int y, int Map[51][51], int h, int w){
    if(!(0<=x && x <=h-1 && 0<=y && y<=w && Map[x][y]==1)) return;
    Map[x][y]=0;
    for(int i=0; i<8; i++)
        dfs(x+dx[i], y+dy[i], Map, h, w);
}

void disp(int Map[51][51], int h, int w){
    cout << "==========" << endl;
    for(int x=0; x<=h-1; x++){
        for(int y=0; y<=w-1; y++) cout << Map[x][y] << "";
        cout << endl;
    }
    cout << "==========" << endl;
}

int main(){
    int Map[51][51]={};
    int h, w;
    while(1){
        cin >> w >> h;
        if(h == 0 && w ==0) break;
        for(int x=0; x<=h-1; x++)
            for(int y=0; y<w; y++)
                cin >> Map[x][y];
        
        int cnt=0;
        for(int x=0; x<=h-1; x++)
            for(int y=0; y<w; y++){
                // cout << "before" << endl;
                // disp(Map, h, w);
                if(Map[x][y]==1) dfs(x, y, Map, h, w), cnt++;
                // cout << "after" << endl;
                // disp(Map, h, w);
            }
                
        
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	int B[110] = {}; 
	B[0] = 1145141919; B[N] = 1145141919; 
	for(int i = 1; i < N; i++){
		cin >> B[i]; 
	}
	int ans = 0; 
	for(int i = 0; i < N; i++){
		ans += min(B[i], B[i+1]); 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256